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  return true; // Continue
76 }
77 
78 bool 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 
94 bool 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;
101  case MID_DROPCAP_FORMAT:
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 
126 bool 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;
146  case MID_DROPCAP_DISTANCE :
147  {
148  sal_Int16 nVal = 0;
149  if ( rVal >>= nVal )
150  m_nDistance = static_cast<sal_Int16>(convertMm100ToTwip(static_cast<sal_Int32>(nVal)));
151  else
152  return false;
153  break;
154  }
155  case MID_DROPCAP_FORMAT:
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;
162  m_nDistance = convertMm100ToTwip(pDrop->Distance);
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 
186 bool 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  xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem"));
211  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
212  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
213  xmlTextWriterEndElement(pWriter);
214 }
215 
217 {
218  return new SwParaConnectBorderItem( *this );
219 }
220 
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: paratr.cxx:94
virtual bool GetInfo(SfxPoolItem &) const override
Get information from Client.
Definition: paratr.cxx:73
void Add(SwClient *pDepend)
Definition: calbck.cxx:199
bool GetWholeWord() const
Definition: paratr.hxx:108
sal_uInt16 m_nDistance
Distance to beginning of text.
Definition: paratr.hxx:65
SwParaConnectBorderItem(const bool bConnect=true)
Definition: paratr.hxx:190
bool IsDefault() const
Definition: format.hxx:109
SwRegisterItem(const bool bRegister=false)
Definition: paratr.hxx:143
signed char sal_Int8
sal_uInt8 m_nChars
Character count.
Definition: paratr.hxx:67
static SfxPoolItem * CreateDefault()
Definition: paratr.cxx:36
sal_uInt8 GetLines() const
Definition: paratr.hxx:102
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
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:78
virtual SwParaConnectBorderItem * Clone(SfxItemPool *pPool=nullptr) const override
"pure virtual methods" of SfxPoolItem
Definition: paratr.cxx:216
#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:200
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:111
const char * sName
void EndListeningAll()
Definition: calbck.cxx:127
struct _xmlTextWriter * xmlTextWriterPtr
virtual ~SwFormatDrop() override
Definition: paratr.cxx:60
sal_uInt8 m_nLines
Line count.
Definition: paratr.hxx:66
const OUString & GetValue() const
css::uno::Type const & get()
sal_uInt8 GetChars() const
Definition: paratr.hxx:105
sw::FormatDropDefiner * m_pDefinedIn
TextNode or FormatColl that contains the CapDrops.
Definition: paratr.hxx:64
#define MID_DROPCAP_DISTANCE
Definition: unomid.h:68
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:186
#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:176
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
const SwCharFormat * GetCharFormat() const
Definition: paratr.hxx:114
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:62
#define MID_DROPCAP_WHOLE_WORD
Definition: unomid.h:64
bool m_bWholeWord
First word with initials.
Definition: paratr.hxx:68
virtual SwFormatDrop * Clone(SfxItemPool *pPool=nullptr) const override
Definition: paratr.cxx:89
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:126
static const OUString & GetProgName(const OUString &rName, SwGetPoolIdFromName)