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  OSL_ENSURE( Which() == rAttr.Which(), "no equal attributes" );
55  return ( aFootnoteInfo == static_cast<const SwPageFootnoteInfoItem&>(rAttr).GetPageFootnoteInfo());
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  assert(SfxPoolItem::operator==(rAttr));
208  const SwPtrItem& rItem = static_cast<const SwPtrItem&>(rAttr);
209  return ( pMisc == rItem.pMisc );
210 }
211 
212 // SwUINumRuleItem for the NumTabPages of the FormatNumRule/Styleists
213 
215  : SfxPoolItem( FN_PARAM_ACT_NUMBER ), pRule( new SwNumRule( rRul ) )
216 {
217 }
218 
220  : SfxPoolItem( rItem ),
221  pRule( new SwNumRule( *rItem.pRule ))
222 {
223 }
224 
226 {
227 }
228 
230 {
231  return new SwUINumRuleItem( *this );
232 }
233 
234 bool SwUINumRuleItem::operator==( const SfxPoolItem& rAttr ) const
235 {
236  assert(SfxPoolItem::operator==(rAttr));
237  return *pRule == *static_cast<const SwUINumRuleItem&>(rAttr).pRule;
238 }
239 
240 bool SwUINumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
241 {
242  uno::Reference< container::XIndexReplace >xRules = new SwXNumberingRules(*pRule);
243  rVal <<= xRules;
244  return true;
245 }
246 bool SwUINumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
247 {
248  uno::Reference< container::XIndexReplace> xRulesRef;
249  if(rVal >>= xRulesRef)
250  {
251  uno::Reference< lang::XUnoTunnel > xTunnel(xRulesRef, uno::UNO_QUERY);
252  SwXNumberingRules* pSwXRules = xTunnel.is() ? reinterpret_cast<SwXNumberingRules*>(
253  xTunnel->getSomething(SwXNumberingRules::getUnoTunnelId())) : nullptr;
254  if(pSwXRules)
255  {
256  *pRule = *pSwXRules->GetNumRule();
257  }
258  }
259  return true;
260 }
261 
262 SwPaMItem::SwPaMItem( const sal_uInt16 nId, SwPaM* pPaM ) :
263  SfxPoolItem( nId ),
264  m_pPaM(pPaM)
265 {
266 }
267 
269 {
270  return new SwPaMItem( *this );
271 }
272 
273 bool SwPaMItem::operator==( const SfxPoolItem& rAttr ) const
274 {
275  assert(SfxPoolItem::operator==(rAttr));
276  const SwPaMItem& rItem = static_cast<const SwPaMItem&>(rAttr);
277  return ( m_pPaM == rItem.m_pPaM );
278 }
279 
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetTopDist(SwTwips const nNew)
Definition: pagedesc.hxx:75
void SetLineStyle(SvxBorderLineStyle const eSet)
Definition: pagedesc.hxx:71
signed char sal_Int8
void SetBottomDist(SwTwips const nNew)
Definition: pagedesc.hxx:76
SwTwips GetBottomDist() const
Definition: pagedesc.hxx:67
long SwTwips
Definition: swtypes.hxx:49
void *const pMisc
Definition: uiitems.hxx:64
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:246
void SetHeight(SwTwips const nNew)
Definition: pagedesc.hxx:69
SwPaMItem(const sal_uInt16 nId, SwPaM *pPaM)
Definition: uiitems.cxx:262
SwTwips GetTopDist() const
Definition: pagedesc.hxx:66
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:229
#define FN_PARAM_FTN_INFO
Definition: cmdid.h:743
SwTwips GetHeight() const
Definition: pagedesc.hxx:60
#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:240
#define MID_FTN_HEIGHT
Definition: unomid.h:103
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const SwNumRule * GetNumRule()
Definition: unosett.hxx:205
SwPageFootnoteInfo aFootnoteInfo
Definition: uiitems.hxx:35
SfxItemPresentation
#define MID_FTN_LINE_STYLE
Definition: unomid.h:110
void SetAdj(css::text::HorizontalAdjust const eNew)
Definition: pagedesc.hxx:74
void SetWidth(const Fraction &rNew)
Definition: pagedesc.hxx:73
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:774
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:273
#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:191
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unosett.cxx:1035
std::unique_ptr< SwNumRule > pRule
Definition: uiitems.hxx:77
const char * GetMetricId(MapUnit eUnit)
virtual ~SwUINumRuleItem() override
Definition: uiitems.cxx:225
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:234
Footnote information.
Definition: pagedesc.hxx:47
const Fraction & GetWidth() const
Definition: pagedesc.hxx:64
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:72
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: uiitems.cxx:200
css::text::HorizontalAdjust GetAdj() const
Definition: pagedesc.hxx:65
SwPaM *const m_pPaM
Definition: uiitems.hxx:96
sal_uLong GetLineWidth() const
Definition: pagedesc.hxx:61
void SetLineWidth(sal_uLong const nSet)
Definition: pagedesc.hxx:70
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
MapUnit
SvxBorderLineStyle GetLineStyle() const
Definition: pagedesc.hxx:63
SwUINumRuleItem(const SwNumRule &rRule)
Definition: uiitems.cxx:214
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:268
#define MID_LINE_COLOR
Definition: unomid.h:105
sal_uInt16 Which() const
const Color & GetLineColor() const
Definition: pagedesc.hxx:62
#define CONVERT_TWIPS
virtual bool operator==(const SfxPoolItem &) const override
Definition: uiitems.cxx:52