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