LibreOffice Module sw (master)  1
uiitems.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 <editeng/itemtype.hxx>
21 #include <unosett.hxx>
22 
23 #include <swtypes.hxx>
24 #include <cmdid.h>
25 #include <uiitems.hxx>
26 
27 #include <strings.hrc>
28 #include <unomid.h>
29 #include <numrule.hxx>
30 
31 #include <editeng/eerdll.hxx>
32 
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 
38  aFootnoteInfo(rInfo)
39 {
40 }
41 
43 {
44 }
45 
47 {
48  return new SwPageFootnoteInfoItem( *this );
49 }
50 
52 {
53  return SfxPoolItem::operator==(rAttr)
54  && aFootnoteInfo == static_cast<const SwPageFootnoteInfoItem&>(rAttr).aFootnoteInfo;
55 }
56 
58 (
59  SfxItemPresentation /*ePres*/,
60  MapUnit eCoreUnit,
61  MapUnit ePresUnit,
62  OUString& rText,
63  const IntlWrapper& rIntl
64 ) const
65 {
66  const SwTwips nHght = GetPageFootnoteInfo().GetHeight();
67  if ( nHght )
68  {
69  rText = SwResId( STR_MAX_FTN_HEIGHT ) + " " +
70  ::GetMetricText( nHght, eCoreUnit, ePresUnit, &rIntl ) + " " +
71  EditResId( ::GetMetricId( ePresUnit ) );
72  }
73  return true;
74 }
75 
76 bool SwPageFootnoteInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
77 {
78  bool bRet = true;
79  switch(nMemberId & ~CONVERT_TWIPS)
80  {
81  case MID_FTN_HEIGHT : rVal <<= static_cast<sal_Int32>(convertTwipToMm100(aFootnoteInfo.GetHeight()));break;
82  case MID_LINE_WEIGHT : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(aFootnoteInfo.GetLineWidth()));break;
83  case MID_LINE_COLOR : rVal <<= aFootnoteInfo.GetLineColor();break;
84  case MID_LINE_RELWIDTH :
85  {
86  Fraction aTmp( 100, 1 );
87  aTmp *= aFootnoteInfo.GetWidth();
88  rVal <<= static_cast<sal_Int8>(static_cast<long>(aTmp));
89  }
90  break;
91  case MID_LINE_ADJUST : rVal <<= static_cast<sal_Int16>(aFootnoteInfo.GetAdj());break;//text::HorizontalAdjust
92  case MID_LINE_TEXT_DIST : rVal <<= static_cast<sal_Int32>(convertTwipToMm100(aFootnoteInfo.GetTopDist()));break;
93  case MID_LINE_FOOTNOTE_DIST: rVal <<= static_cast<sal_Int32>(convertTwipToMm100(aFootnoteInfo.GetBottomDist()));break;
94  case MID_FTN_LINE_STYLE :
95  {
96  switch ( aFootnoteInfo.GetLineStyle( ) )
97  {
98  default:
99  case SvxBorderLineStyle::NONE : rVal <<= sal_Int8(0); break;
100  case SvxBorderLineStyle::SOLID: rVal <<= sal_Int8(1); break;
101  case SvxBorderLineStyle::DOTTED: rVal <<= sal_Int8(2); break;
102  case SvxBorderLineStyle::DASHED: rVal <<= sal_Int8(3); break;
103  }
104  break;
105  }
106  default:
107  bRet = false;
108  }
109  return bRet;
110 }
111 
112 bool SwPageFootnoteInfoItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
113 {
114  sal_Int32 nSet32 = 0;
115  Color aColor;
116  bool bRet = true;
117  switch(nMemberId & ~CONVERT_TWIPS)
118  {
119  case MID_LINE_COLOR :
120  rVal >>= aColor;
121  aFootnoteInfo.SetLineColor(aColor);
122  break;
123  case MID_FTN_HEIGHT:
124  case MID_LINE_TEXT_DIST :
126  rVal >>= nSet32;
127  if(nSet32 < 0)
128  bRet = false;
129  else
130  {
131  nSet32 = convertMm100ToTwip(nSet32);
132  switch(nMemberId & ~CONVERT_TWIPS)
133  {
134  case MID_FTN_HEIGHT: aFootnoteInfo.SetHeight(nSet32); break;
135  case MID_LINE_TEXT_DIST: aFootnoteInfo.SetTopDist(nSet32);break;
137  }
138  }
139  break;
140  case MID_LINE_WEIGHT :
141  {
142  sal_Int16 nSet = 0;
143  rVal >>= nSet;
144  if(nSet >= 0)
146  else
147  bRet = false;
148  }
149  break;
150  case MID_LINE_RELWIDTH :
151  {
152  sal_Int8 nSet = 0;
153  rVal >>= nSet;
154  if(nSet < 0)
155  bRet = false;
156  else
157  aFootnoteInfo.SetWidth(Fraction(nSet, 100));
158  }
159  break;
160  case MID_LINE_ADJUST :
161  {
162  sal_Int16 nSet = 0;
163  rVal >>= nSet;
164  if(nSet >= 0 && nSet < 3) //text::HorizontalAdjust
165  aFootnoteInfo.SetAdj(static_cast<css::text::HorizontalAdjust>(nSet));
166  else
167  bRet = false;
168  }
169  break;
170  case MID_FTN_LINE_STYLE:
171  {
172  SvxBorderLineStyle eStyle = SvxBorderLineStyle::NONE;
173  sal_Int8 nSet = 0;
174  rVal >>= nSet;
175  switch ( nSet )
176  {
177  case 1: eStyle = SvxBorderLineStyle::SOLID; break;
178  case 2: eStyle = SvxBorderLineStyle::DOTTED; break;
179  case 3: eStyle = SvxBorderLineStyle::DASHED; break;
180  default: break;
181  }
182  aFootnoteInfo.SetLineStyle( eStyle );
183  }
184  break;
185  default:
186  bRet = false;
187  }
188  return bRet;
189 }
190 
191 SwPtrItem::SwPtrItem( const sal_uInt16 nId, void* pPtr ) :
192  SfxPoolItem( nId ),
193  pMisc(pPtr)
194 {
195 }
196 
197 // Cloning
198 
200 {
201  return new SwPtrItem( *this );
202 }
203 
204 bool SwPtrItem::operator==( const SfxPoolItem& rAttr ) const
205 {
206  return SfxPoolItem::operator==(rAttr)
207  && pMisc == static_cast<const SwPtrItem&>(rAttr).pMisc;
208 }
209 
210 // SwUINumRuleItem for the NumTabPages of the FormatNumRule/Styleists
211 
213  : SfxPoolItem( FN_PARAM_ACT_NUMBER ), pRule( new SwNumRule( rRul ) )
214 {
215 }
216 
218  : SfxPoolItem( rItem ),
219  pRule( new SwNumRule( *rItem.pRule ))
220 {
221 }
222 
224 {
225 }
226 
228 {
229  return new SwUINumRuleItem( *this );
230 }
231 
232 bool SwUINumRuleItem::operator==( const SfxPoolItem& rAttr ) const
233 {
234  return SfxPoolItem::operator==(rAttr)
235  && *pRule == *static_cast<const SwUINumRuleItem&>(rAttr).pRule;
236 }
237 
238 bool SwUINumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
239 {
240  uno::Reference< container::XIndexReplace >xRules = new SwXNumberingRules(*pRule);
241  rVal <<= xRules;
242  return true;
243 }
244 bool SwUINumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
245 {
246  uno::Reference< container::XIndexReplace> xRulesRef;
247  if(rVal >>= xRulesRef)
248  {
249  auto pSwXRules = comphelper::getUnoTunnelImplementation<SwXNumberingRules>(xRulesRef);
250  if(pSwXRules)
251  {
252  *pRule = *pSwXRules->GetNumRule();
253  }
254  }
255  return true;
256 }
257 
258 SwPaMItem::SwPaMItem( const sal_uInt16 nId, SwPaM* pPaM ) :
259  SfxPoolItem( nId ),
260  m_pPaM(pPaM)
261 {
262 }
263 
265 {
266  return new SwPaMItem( *this );
267 }
268 
269 bool SwPaMItem::operator==( const SfxPoolItem& rAttr ) const
270 {
271  return SfxPoolItem::operator==(rAttr)
272  && m_pPaM == static_cast<const SwPaMItem&>(rAttr).m_pPaM;
273 }
274 
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetTopDist(SwTwips const nNew)
Definition: pagedesc.hxx:76
void SetLineStyle(SvxBorderLineStyle const eSet)
Definition: pagedesc.hxx:72
virtual bool operator==(const SfxPoolItem &) const =0
virtual SwPtrItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: uiitems.cxx:199
signed char sal_Int8
void SetBottomDist(SwTwips const nNew)
Definition: pagedesc.hxx:77
SwTwips GetBottomDist() const
Definition: pagedesc.hxx:68
long SwTwips
Definition: swtypes.hxx:49
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: uiitems.cxx:244
void SetHeight(SwTwips const nNew)
Definition: pagedesc.hxx:70
SwPaMItem(const sal_uInt16 nId, SwPaM *pPaM)
Definition: uiitems.cxx:258
SwTwips GetTopDist() const
Definition: pagedesc.hxx:67
SvxBorderLineStyle
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &rIntl) const override
Definition: uiitems.cxx:58
void * pMisc
Definition: uiitems.hxx:63
#define FN_PARAM_FTN_INFO
Definition: cmdid.h:763
SwTwips GetHeight() const
Definition: pagedesc.hxx:61
#define MID_LINE_TEXT_DIST
Definition: unomid.h:108
#define MID_LINE_FOOTNOTE_DIST
Definition: unomid.h:109
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: uiitems.cxx:238
#define MID_FTN_HEIGHT
Definition: unomid.h:103
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwPageFootnoteInfo aFootnoteInfo
Definition: uiitems.hxx:34
SfxItemPresentation
virtual SwUINumRuleItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: uiitems.cxx:227
#define MID_FTN_LINE_STYLE
Definition: unomid.h:110
void SetAdj(css::text::HorizontalAdjust const eNew)
Definition: pagedesc.hxx:75
void SetWidth(const Fraction &rNew)
Definition: pagedesc.hxx:74
SwPtrItem(const sal_uInt16 nId, void *pPtr)
Definition: uiitems.cxx:191
#define MID_LINE_RELWIDTH
Definition: unomid.h:106
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: uiitems.cxx:112
#define FN_PARAM_ACT_NUMBER
Definition: cmdid.h:794
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:269
#define MID_LINE_WEIGHT
Definition: unomid.h:104
virtual SwPageFootnoteInfoItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: uiitems.cxx:46
virtual SwPaMItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: uiitems.cxx:264
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: uiitems.cxx:76
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
std::unique_ptr< SwNumRule > pRule
Definition: uiitems.hxx:76
const char * GetMetricId(MapUnit eUnit)
virtual ~SwUINumRuleItem() override
Definition: uiitems.cxx:223
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:232
Footnote information.
Definition: pagedesc.hxx:48
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
const Fraction & GetWidth() const
Definition: pagedesc.hxx:65
unsigned char sal_uInt8
SwPageFootnoteInfoItem(SwPageFootnoteInfo const &rInfo)
Definition: uiitems.cxx:36
OUString EditResId(const char *pId)
void SetLineColor(const Color &rCol)
Definition: pagedesc.hxx:73
css::text::HorizontalAdjust GetAdj() const
Definition: pagedesc.hxx:66
sal_uLong GetLineWidth() const
Definition: pagedesc.hxx:62
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
void SetLineWidth(sal_uLong const nSet)
Definition: pagedesc.hxx:71
MapUnit
SwPaM * m_pPaM
Definition: uiitems.hxx:95
SvxBorderLineStyle GetLineStyle() const
Definition: pagedesc.hxx:64
SwUINumRuleItem(const SwNumRule &rRule)
Definition: uiitems.cxx:212
#define MID_LINE_ADJUST
Definition: unomid.h:107
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:204
virtual ~SwPageFootnoteInfoItem() override
Definition: uiitems.cxx:42
#define MID_LINE_COLOR
Definition: unomid.h:105
const Color & GetLineColor() const
Definition: pagedesc.hxx:63
#define CONVERT_TWIPS
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:51