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