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>
29 #include <tools/UnitConversion.hxx>
30 
31 using 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  if( m_pDefinedIn )
76  {
77  if( dynamic_cast< const SwFormat *>( m_pDefinedIn ) == nullptr)
78  m_pDefinedIn->ModifyNotification( this, this );
79  else if( m_pDefinedIn->HasWriterListeners() &&
81  {
82  // Notify those who are dependent on the format on our own.
83  // The format itself wouldn't pass on the notify as it does not get past the check.
84  m_pDefinedIn->ModifyBroadcast( this, this );
85  }
86  }
87 }
88 
90 {
91  return true; // Continue
92 }
93 
94 bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const
95 {
96  assert(SfxPoolItem::operator==(rAttr));
97  return ( m_nLines == static_cast<const SwFormatDrop&>(rAttr).GetLines() &&
98  m_nChars == static_cast<const SwFormatDrop&>(rAttr).GetChars() &&
99  m_nDistance == static_cast<const SwFormatDrop&>(rAttr).GetDistance() &&
100  m_bWholeWord == static_cast<const SwFormatDrop&>(rAttr).GetWholeWord() &&
101  GetCharFormat() == static_cast<const SwFormatDrop&>(rAttr).GetCharFormat() &&
102  m_pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).m_pDefinedIn );
103 }
104 
106 {
107  return new SwFormatDrop( *this );
108 }
109 
110 bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
111 {
112  switch(nMemberId&~CONVERT_TWIPS)
113  {
114  case MID_DROPCAP_LINES : rVal <<= static_cast<sal_Int16>(m_nLines); break;
115  case MID_DROPCAP_COUNT : rVal <<= static_cast<sal_Int16>(m_nChars); break;
116  case MID_DROPCAP_DISTANCE : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(m_nDistance)); break;
117  case MID_DROPCAP_FORMAT:
118  {
119  style::DropCapFormat aDrop;
120  aDrop.Lines = m_nLines ;
121  aDrop.Count = m_nChars ;
122  aDrop.Distance = convertTwipToMm100(m_nDistance);
123  rVal <<= aDrop;
124  }
125  break;
127  rVal <<= m_bWholeWord;
128  break;
130  {
131  OUString sName;
132  if(GetCharFormat())
135  rVal <<= sName;
136  }
137  break;
138  }
139  return true;
140 }
141 
142 bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
143 {
144  switch(nMemberId&~CONVERT_TWIPS)
145  {
146  case MID_DROPCAP_LINES :
147  {
148  sal_Int8 nTemp = 0;
149  rVal >>= nTemp;
150  if(nTemp >=1 && nTemp < 0x7f)
151  m_nLines = static_cast<sal_uInt8>(nTemp);
152  }
153  break;
154  case MID_DROPCAP_COUNT :
155  {
156  sal_Int16 nTemp = 0;
157  rVal >>= nTemp;
158  if(nTemp >=1 && nTemp < 0x7f)
159  m_nChars = static_cast<sal_uInt8>(nTemp);
160  }
161  break;
162  case MID_DROPCAP_DISTANCE :
163  {
164  sal_Int16 nVal = 0;
165  if ( rVal >>= nVal )
166  m_nDistance = static_cast<sal_Int16>(convertMm100ToTwip(static_cast<sal_Int32>(nVal)));
167  else
168  return false;
169  break;
170  }
171  case MID_DROPCAP_FORMAT:
172  {
173  if(rVal.getValueType() == ::cppu::UnoType<style::DropCapFormat>::get())
174  {
175  auto pDrop = o3tl::doAccess<style::DropCapFormat>(rVal);
176  m_nLines = pDrop->Lines;
177  m_nChars = pDrop->Count;
178  m_nDistance = convertMm100ToTwip(pDrop->Distance);
179  }
180  }
181  break;
183  m_bWholeWord = *o3tl::doAccess<bool>(rVal);
184  break;
186  OSL_FAIL("char format cannot be set in PutValue()!");
187  break;
188  }
189  return true;
190 }
191 
193 {
194  return new SwRegisterItem( *this );
195 }
196 
198 {
199  return new SwNumRuleItem( *this );
200 }
201 
202 bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
203 {
204  assert(SfxPoolItem::operator==(rAttr));
205 
206  return GetValue() == static_cast<const SwNumRuleItem&>(rAttr).GetValue();
207 }
208 
210 {
212  rVal <<= sRet;
213  return true;
214 }
215 
217 {
218  OUString uName;
219  rVal >>= uName;
221  return true;
222 }
223 
225 {
226  xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem"));
227  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
228  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
229  xmlTextWriterEndElement(pWriter);
230 }
231 
233 {
234  return new SwParaConnectBorderItem( *this );
235 }
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:110
virtual bool GetInfo(SfxPoolItem &) const override
Get information from Client.
Definition: paratr.cxx:89
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
bool GetWholeWord() const
Definition: paratr.hxx:92
sal_uInt16 m_nDistance
Distance to beginning of text.
Definition: paratr.hxx:54
SwParaConnectBorderItem(const bool bConnect=true)
Definition: paratr.hxx:173
bool IsDefault() const
Definition: format.hxx:109
SwRegisterItem(const bool bRegister=false)
Definition: paratr.hxx:126
signed char sal_Int8
sal_uInt8 m_nChars
Character count.
Definition: paratr.hxx:56
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:36
sal_uInt8 GetLines() const
Definition: paratr.hxx:86
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:209
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: paratr.cxx:224
virtual SwNumRuleItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:197
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:94
virtual SwParaConnectBorderItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:232
bool HasWriterListeners() const
Definition: calbck.hxx:208
#define MID_DROPCAP_CHAR_STYLE_NAME
Definition: unomid.h:65
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: paratr.cxx:216
void SetValue(const OUString &rTheValue)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
constexpr TypedWhichId< SwFormatDrop > RES_PARATR_DROP(70)
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:34
sal_uInt16 GetDistance() const
Definition: paratr.hxx:95
const char * sName
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:154
void EndListeningAll()
Definition: calbck.cxx:124
struct _xmlTextWriter * xmlTextWriterPtr
virtual ~SwFormatDrop() override
Definition: paratr.cxx:60
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: paratr.cxx:73
void ModifyBroadcast(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:198
sal_uInt8 m_nLines
Line count.
Definition: paratr.hxx:55
const OUString & GetValue() const
css::uno::Type const & get()
sal_uInt8 GetChars() const
Definition: paratr.hxx:89
#define MID_DROPCAP_DISTANCE
Definition: unomid.h:68
bool IsModifyLocked() const
Definition: calbck.hxx:218
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
#define MID_DROPCAP_COUNT
Definition: unomid.h:67
unsigned char sal_uInt8
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:202
#define MID_DROPCAP_FORMAT
Definition: unomid.h:63
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:35
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
virtual SwRegisterItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:192
SwModify * m_pDefinedIn
Modify-Object, that contains DropCaps.
Definition: paratr.hxx:52
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
const SwCharFormat * GetCharFormat() const
Definition: paratr.hxx:98
SwFormatDrop()
Definition: paratr.cxx:38
#define MID_DROPCAP_LINES
Definition: unomid.h:66
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps...
Definition: paratr.hxx:50
#define MID_DROPCAP_WHOLE_WORD
Definition: unomid.h:64
bool m_bWholeWord
First word with initials.
Definition: paratr.hxx:57
virtual SwFormatDrop * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:105
sal_uInt16 Which() const
void SetCharFormat(SwCharFormat *pNew)
Definition: paratr.cxx:64
#define CONVERT_TWIPS
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: paratr.cxx:142
static const OUString & GetProgName(const OUString &rName, SwGetPoolIdFromName)