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 <swtypes.hxx>
22 #include <unomid.h>
23 #include <com/sun/star/style/DropCapFormat.hpp>
24 #include <o3tl/any.hxx>
25 #include <unostyle.hxx>
26 #include <SwStyleNameMapper.hxx>
27 #include <paratr.hxx>
28 #include <charfmt.hxx>
29 #include <cmdid.h>
30 #include <libxml/xmlwriter.h>
31 #include <osl/diagnose.h>
32 
33 using namespace ::com::sun::star;
34 
35 
39 
42  SwClient( nullptr ),
43  m_pDefinedIn( nullptr ),
44  m_nDistance( 0 ),
45  m_nLines( 0 ),
46  m_nChars( 0 ),
47  m_bWholeWord( false )
48 {
49 }
50 
53  SwClient( rCpy.GetRegisteredInNonConst() ),
54  m_pDefinedIn( nullptr ),
55  m_nDistance( rCpy.GetDistance() ),
56  m_nLines( rCpy.GetLines() ),
57  m_nChars( rCpy.GetChars() ),
58  m_bWholeWord( rCpy.GetWholeWord() )
59 {
60 }
61 
63 {
64 }
65 
67 {
68  assert(!pNew || !pNew->IsDefault()); // expose cases that lead to use-after-free
69  // Rewire
71  if(pNew)
72  pNew->Add( this );
73 }
74 
76 {
77  if( m_pDefinedIn )
78  {
79  if( dynamic_cast< const SwFormat *>( m_pDefinedIn ) == nullptr)
80  m_pDefinedIn->ModifyNotification( this, this );
81  else if( m_pDefinedIn->HasWriterListeners() &&
83  {
84  // Notify those who are dependent on the format on our own.
85  // The format itself wouldn't pass on the notify as it does not get past the check.
86  m_pDefinedIn->ModifyBroadcast( this, this );
87  }
88  }
89 }
90 
92 {
93  return true; // Continue
94 }
95 
96 bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const
97 {
98  assert(SfxPoolItem::operator==(rAttr));
99  return ( m_nLines == static_cast<const SwFormatDrop&>(rAttr).GetLines() &&
100  m_nChars == static_cast<const SwFormatDrop&>(rAttr).GetChars() &&
101  m_nDistance == static_cast<const SwFormatDrop&>(rAttr).GetDistance() &&
102  m_bWholeWord == static_cast<const SwFormatDrop&>(rAttr).GetWholeWord() &&
103  GetCharFormat() == static_cast<const SwFormatDrop&>(rAttr).GetCharFormat() &&
104  m_pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).m_pDefinedIn );
105 }
106 
108 {
109  return new SwFormatDrop( *this );
110 }
111 
112 bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
113 {
114  switch(nMemberId&~CONVERT_TWIPS)
115  {
116  case MID_DROPCAP_LINES : rVal <<= static_cast<sal_Int16>(m_nLines); break;
117  case MID_DROPCAP_COUNT : rVal <<= static_cast<sal_Int16>(m_nChars); break;
118  case MID_DROPCAP_DISTANCE : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(m_nDistance)); break;
119  case MID_DROPCAP_FORMAT:
120  {
121  style::DropCapFormat aDrop;
122  aDrop.Lines = m_nLines ;
123  aDrop.Count = m_nChars ;
124  aDrop.Distance = convertTwipToMm100(m_nDistance);
125  rVal <<= aDrop;
126  }
127  break;
129  rVal <<= m_bWholeWord;
130  break;
132  {
133  OUString sName;
134  if(GetCharFormat())
137  rVal <<= sName;
138  }
139  break;
140  }
141  return true;
142 }
143 
144 bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
145 {
146  switch(nMemberId&~CONVERT_TWIPS)
147  {
148  case MID_DROPCAP_LINES :
149  {
150  sal_Int8 nTemp = 0;
151  rVal >>= nTemp;
152  if(nTemp >=1 && nTemp < 0x7f)
153  m_nLines = static_cast<sal_uInt8>(nTemp);
154  }
155  break;
156  case MID_DROPCAP_COUNT :
157  {
158  sal_Int16 nTemp = 0;
159  rVal >>= nTemp;
160  if(nTemp >=1 && nTemp < 0x7f)
161  m_nChars = static_cast<sal_uInt8>(nTemp);
162  }
163  break;
164  case MID_DROPCAP_DISTANCE :
165  {
166  sal_Int16 nVal = 0;
167  if ( rVal >>= nVal )
168  m_nDistance = static_cast<sal_Int16>(convertMm100ToTwip(static_cast<sal_Int32>(nVal)));
169  else
170  return false;
171  break;
172  }
173  case MID_DROPCAP_FORMAT:
174  {
175  if(rVal.getValueType() == ::cppu::UnoType<style::DropCapFormat>::get())
176  {
177  auto pDrop = o3tl::doAccess<style::DropCapFormat>(rVal);
178  m_nLines = pDrop->Lines;
179  m_nChars = pDrop->Count;
180  m_nDistance = convertMm100ToTwip(pDrop->Distance);
181  }
182  }
183  break;
185  m_bWholeWord = *o3tl::doAccess<bool>(rVal);
186  break;
188  OSL_FAIL("char format cannot be set in PutValue()!");
189  break;
190  }
191  return true;
192 }
193 
195 {
196  return new SwRegisterItem( *this );
197 }
198 
200 {
201  return new SwNumRuleItem( *this );
202 }
203 bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
204 {
205  assert(SfxPoolItem::operator==(rAttr));
206 
207  return GetValue() == static_cast<const SwNumRuleItem&>(rAttr).GetValue();
208 }
209 
211 {
213  rVal <<= sRet;
214  return true;
215 }
216 
218 {
219  OUString uName;
220  rVal >>= uName;
222  return true;
223 }
224 
226 {
227  xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem"));
228  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
229  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
230  xmlTextWriterEndElement(pWriter);
231 }
232 
234 {
235  return new SwParaConnectBorderItem( *this );
236 }
237 
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:112
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:194
virtual bool GetInfo(SfxPoolItem &) const override
Get information from Client.
Definition: paratr.cxx:91
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:38
sal_uInt8 GetLines() const
Definition: paratr.hxx:86
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:210
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: paratr.cxx:225
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:96
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:217
void SetValue(const OUString &rTheValue)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:233
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:199
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:36
sal_uInt16 GetDistance() const
Definition: paratr.hxx:95
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:62
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: paratr.cxx:75
void ModifyBroadcast(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:198
sal_uInt8 m_nLines
Line count.
Definition: paratr.hxx:55
OUString sName
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
#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:203
#define MID_DROPCAP_FORMAT
Definition: unomid.h:63
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:37
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:107
SwModify * m_pDefinedIn
Modify-Object, that contains DropCaps.
Definition: paratr.hxx:52
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
const SwCharFormat * GetCharFormat() const
Definition: paratr.hxx:98
#define RES_PARATR_DROP
Definition: hintids.hxx:169
SwFormatDrop()
Definition: paratr.cxx:40
#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
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
bool m_bWholeWord
First word with initials.
Definition: paratr.hxx:57
sal_uInt16 Which() const
void SetCharFormat(SwCharFormat *pNew)
Definition: paratr.cxx:66
#define CONVERT_TWIPS
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: paratr.cxx:144
static const OUString & GetProgName(const OUString &rName, SwGetPoolIdFromName)