LibreOffice Module sw (master) 1
paratr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <hintids.hxx>
21#include <unomid.h>
22#include <com/sun/star/style/DropCapFormat.hpp>
23#include <o3tl/any.hxx>
24#include <SwStyleNameMapper.hxx>
25#include <paratr.hxx>
26#include <charfmt.hxx>
27#include <libxml/xmlwriter.h>
28#include <osl/diagnose.h>
30
31using namespace ::com::sun::star;
32
33
37
40 SwClient( nullptr ),
41 m_pDefinedIn( nullptr ),
42 m_nDistance( 0 ),
43 m_nLines( 0 ),
44 m_nChars( 0 ),
45 m_bWholeWord( false )
46{
47}
48
51 SwClient( rCpy.GetRegisteredInNonConst() ),
52 m_pDefinedIn( nullptr ),
53 m_nDistance( rCpy.GetDistance() ),
54 m_nLines( rCpy.GetLines() ),
55 m_nChars( rCpy.GetChars() ),
56 m_bWholeWord( rCpy.GetWholeWord() )
57{
58}
59
61{
62}
63
65{
66 assert(!pNew || !pNew->IsDefault()); // expose cases that lead to use-after-free
67 // Rewire
69 if(pNew)
70 pNew->Add( this );
71}
72
74{
75 return true; // Continue
76}
77
78bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const
79{
80 assert(SfxPoolItem::operator==(rAttr));
81 return ( m_nLines == static_cast<const SwFormatDrop&>(rAttr).GetLines() &&
82 m_nChars == static_cast<const SwFormatDrop&>(rAttr).GetChars() &&
83 m_nDistance == static_cast<const SwFormatDrop&>(rAttr).GetDistance() &&
84 m_bWholeWord == static_cast<const SwFormatDrop&>(rAttr).GetWholeWord() &&
85 GetCharFormat() == static_cast<const SwFormatDrop&>(rAttr).GetCharFormat() &&
86 m_pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).m_pDefinedIn );
87}
88
90{
91 return new SwFormatDrop( *this );
92}
93
94bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
95{
96 switch(nMemberId&~CONVERT_TWIPS)
97 {
98 case MID_DROPCAP_LINES : rVal <<= static_cast<sal_Int16>(m_nLines); break;
99 case MID_DROPCAP_COUNT : rVal <<= static_cast<sal_Int16>(m_nChars); break;
100 case MID_DROPCAP_DISTANCE : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(m_nDistance)); break;
102 {
103 style::DropCapFormat aDrop;
104 aDrop.Lines = m_nLines ;
105 aDrop.Count = m_nChars ;
106 aDrop.Distance = convertTwipToMm100(m_nDistance);
107 rVal <<= aDrop;
108 }
109 break;
111 rVal <<= m_bWholeWord;
112 break;
114 {
115 OUString sName;
116 if(GetCharFormat())
119 rVal <<= sName;
120 }
121 break;
122 }
123 return true;
124}
125
126bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
127{
128 switch(nMemberId&~CONVERT_TWIPS)
129 {
130 case MID_DROPCAP_LINES :
131 {
132 sal_Int8 nTemp = 0;
133 rVal >>= nTemp;
134 if(nTemp >=1 && nTemp < 0x7f)
135 m_nLines = static_cast<sal_uInt8>(nTemp);
136 }
137 break;
138 case MID_DROPCAP_COUNT :
139 {
140 sal_Int16 nTemp = 0;
141 rVal >>= nTemp;
142 if(nTemp >=1 && nTemp < 0x7f)
143 m_nChars = static_cast<sal_uInt8>(nTemp);
144 }
145 break;
147 {
148 sal_Int16 nVal = 0;
149 if ( rVal >>= nVal )
151 else
152 return false;
153 break;
154 }
156 {
157 if(rVal.getValueType() == ::cppu::UnoType<style::DropCapFormat>::get())
158 {
159 auto pDrop = o3tl::doAccess<style::DropCapFormat>(rVal);
160 m_nLines = pDrop->Lines;
161 m_nChars = pDrop->Count;
163 }
164 }
165 break;
167 m_bWholeWord = *o3tl::doAccess<bool>(rVal);
168 break;
170 OSL_FAIL("char format cannot be set in PutValue()!");
171 break;
172 }
173 return true;
174}
175
177{
178 return new SwRegisterItem( *this );
179}
180
182{
183 return new SwNumRuleItem( *this );
184}
185
186bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
187{
188 assert(SfxPoolItem::operator==(rAttr));
189
190 return GetValue() == static_cast<const SwNumRuleItem&>(rAttr).GetValue();
191}
192
194{
196 rVal <<= sRet;
197 return true;
198}
199
201{
202 OUString uName;
203 rVal >>= uName;
205 return true;
206}
207
209{
210 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem"));
211 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
212 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
213 (void)xmlTextWriterEndElement(pWriter);
214}
215
217{
218 return new SwParaConnectBorderItem( *this );
219}
220
221/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
constexpr auto convertTwipToMm100(N n)
const OUString & GetValue() const
void SetValue(const OUString &rTheValue)
sal_uInt16 Which() const
Represents the style of a text portion.
Definition: charfmt.hxx:27
void EndListeningAll()
Definition: calbck.cxx:136
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps.
Definition: paratr.hxx:63
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:34
virtual bool GetInfo(SfxPoolItem &) const override
Get information from Client.
Definition: paratr.cxx:73
SwFormatDrop()
Definition: paratr.cxx:38
sal_uInt8 GetLines() const
Definition: paratr.hxx:101
sal_uInt8 GetChars() const
Definition: paratr.hxx:104
sal_uInt8 m_nChars
Character count.
Definition: paratr.hxx:67
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: paratr.cxx:126
sal_uInt16 m_nDistance
Distance to beginning of text.
Definition: paratr.hxx:65
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:78
sw::FormatDropDefiner * m_pDefinedIn
TextNode or FormatColl that contains the CapDrops.
Definition: paratr.hxx:64
virtual SwFormatDrop * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:89
sal_uInt8 m_nLines
Line count.
Definition: paratr.hxx:66
virtual ~SwFormatDrop() override
Definition: paratr.cxx:60
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:94
void SetCharFormat(SwCharFormat *pNew)
Definition: paratr.cxx:64
const SwCharFormat * GetCharFormat() const
Definition: paratr.hxx:113
sal_uInt16 GetDistance() const
Definition: paratr.hxx:110
bool m_bWholeWord
First word with initials.
Definition: paratr.hxx:68
bool GetWholeWord() const
Definition: paratr.hxx:107
bool IsDefault() const
Definition: format.hxx:129
void Add(SwClient *pDepend)
Definition: calbck.cxx:172
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:186
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: paratr.cxx:200
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:193
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: paratr.cxx:208
virtual SwNumRuleItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:181
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:36
virtual SwParaConnectBorderItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:216
SwParaConnectBorderItem(const bool bConnect=true)
Definition: paratr.hxx:187
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:35
SwRegisterItem(const bool bRegister=false)
Definition: paratr.hxx:140
virtual SwRegisterItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:176
static const OUString & GetProgName(const OUString &rName, SwGetPoolIdFromName)
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
virtual OUString GetName() const override
constexpr TypedWhichId< SwFormatDrop > RES_PARATR_DROP(70)
const char * sName
constexpr auto toTwips(N number, Length from)
#define CONVERT_TWIPS
unsigned char sal_uInt8
signed char sal_Int8
#define MID_DROPCAP_FORMAT
Definition: unomid.h:63
#define MID_DROPCAP_WHOLE_WORD
Definition: unomid.h:64
#define MID_DROPCAP_COUNT
Definition: unomid.h:67
#define MID_DROPCAP_CHAR_STYLE_NAME
Definition: unomid.h:65
#define MID_DROPCAP_LINES
Definition: unomid.h:66
#define MID_DROPCAP_DISTANCE
Definition: unomid.h:68