bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / uiitems.cxx
blobaa15e18d05b1eed0ab388fa6ad7c17d9c5028768
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <editeng/itemtype.hxx>
21 #include <unosett.hxx>
23 #include "swtypes.hxx"
24 #include "cmdid.h"
25 #include "uiitems.hxx"
27 #include "utlui.hrc"
28 #include "attrdesc.hrc"
29 #include <unomid.h>
30 #include <numrule.hxx>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
35 SwPageFtnInfoItem::SwPageFtnInfoItem( const sal_uInt16 nId, SwPageFtnInfo& rInfo) :
36 SfxPoolItem( nId ),
37 aFtnInfo(rInfo)
41 SwPageFtnInfoItem::SwPageFtnInfoItem( const SwPageFtnInfoItem& rItem ) :
42 SfxPoolItem( rItem ),
43 aFtnInfo(rItem.GetPageFtnInfo())
47 SwPageFtnInfoItem::~SwPageFtnInfoItem()
51 SfxPoolItem* SwPageFtnInfoItem::Clone( SfxItemPool * /*pPool*/ ) const
53 return new SwPageFtnInfoItem( *this );
56 int SwPageFtnInfoItem::operator==( const SfxPoolItem& rAttr ) const
58 OSL_ENSURE( Which() == rAttr.Which(), "no equal attributes" );
59 return ( aFtnInfo == ((SwPageFtnInfoItem&)rAttr).GetPageFtnInfo());
62 SfxItemPresentation SwPageFtnInfoItem::GetPresentation
64 SfxItemPresentation ePres,
65 SfxMapUnit eCoreUnit,
66 SfxMapUnit ePresUnit,
67 OUString& rText,
68 const IntlWrapper* pIntl
69 ) const
71 switch ( ePres )
73 case SFX_ITEM_PRESENTATION_NONE:
74 rText = OUString();
75 return SFX_ITEM_PRESENTATION_NONE;
76 case SFX_ITEM_PRESENTATION_NAMELESS:
77 case SFX_ITEM_PRESENTATION_COMPLETE:
79 sal_uInt16 nHght = (sal_uInt16) GetPageFtnInfo().GetHeight();
80 if ( nHght )
82 rText = SW_RESSTR( STR_MAX_FTN_HEIGHT ) + " " +
83 ::GetMetricText( nHght, eCoreUnit, ePresUnit, pIntl ) +
84 ::GetSvxString( ::GetMetricId( ePresUnit ) );
86 return ePres;
88 default:; //prevent warning
90 return SFX_ITEM_PRESENTATION_NONE;
93 bool SwPageFtnInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
95 bool bRet = true;
96 switch(nMemberId & ~CONVERT_TWIPS)
98 case MID_FTN_HEIGHT : rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetHeight());break;
99 case MID_LINE_WEIGHT : rVal <<= (sal_Int16)TWIP_TO_MM100_UNSIGNED(aFtnInfo.GetLineWidth());break;
100 case MID_LINE_COLOR : rVal <<= (sal_Int32)aFtnInfo.GetLineColor().GetColor();break;
101 case MID_LINE_RELWIDTH :
103 Fraction aTmp( 100, 1 );
104 aTmp *= aFtnInfo.GetWidth();
105 rVal <<= (sal_Int8)(long)aTmp;
107 break;
108 case MID_LINE_ADJUST : rVal <<= (sal_Int16)aFtnInfo.GetAdj();break;//text::HorizontalAdjust
109 case MID_LINE_TEXT_DIST : rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetTopDist());break;
110 case MID_LINE_FOOTNOTE_DIST: rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetBottomDist());break;
111 case MID_FTN_LINE_STYLE :
113 switch ( aFtnInfo.GetLineStyle( ) )
115 default:
116 case table::BorderLineStyle::NONE : rVal <<= sal_Int8(0); break;
117 case table::BorderLineStyle::SOLID: rVal <<= sal_Int8(1); break;
118 case table::BorderLineStyle::DOTTED: rVal <<= sal_Int8(2); break;
119 case table::BorderLineStyle::DASHED: rVal <<= sal_Int8(3); break;
121 break;
123 default:
124 bRet = false;
126 return bRet;
129 bool SwPageFtnInfoItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
131 sal_Int32 nSet32 = 0;
132 bool bRet = true;
133 switch(nMemberId & ~CONVERT_TWIPS)
135 case MID_LINE_COLOR :
136 rVal >>= nSet32;
137 aFtnInfo.SetLineColor(nSet32);
138 break;
139 case MID_FTN_HEIGHT:
140 case MID_LINE_TEXT_DIST :
141 case MID_LINE_FOOTNOTE_DIST:
142 rVal >>= nSet32;
143 if(nSet32 < 0)
144 bRet = false;
145 else
147 nSet32 = MM100_TO_TWIP(nSet32);
148 switch(nMemberId & ~CONVERT_TWIPS)
150 case MID_FTN_HEIGHT: aFtnInfo.SetHeight(nSet32); break;
151 case MID_LINE_TEXT_DIST: aFtnInfo.SetTopDist(nSet32);break;
152 case MID_LINE_FOOTNOTE_DIST: aFtnInfo.SetBottomDist(nSet32);break;
155 break;
156 case MID_LINE_WEIGHT :
158 sal_Int16 nSet = 0;
159 rVal >>= nSet;
160 if(nSet >= 0)
161 aFtnInfo.SetLineWidth(MM100_TO_TWIP(nSet));
162 else
163 bRet = false;
165 break;
166 case MID_LINE_RELWIDTH :
168 sal_Int8 nSet = 0;
169 rVal >>= nSet;
170 if(nSet < 0)
171 bRet = false;
172 else
173 aFtnInfo.SetWidth(Fraction(nSet, 100));
175 break;
176 case MID_LINE_ADJUST :
178 sal_Int16 nSet = 0;
179 rVal >>= nSet;
180 if(nSet >= 0 && nSet < 3) //text::HorizontalAdjust
181 aFtnInfo.SetAdj((SwFtnAdj)nSet);
182 else
183 bRet = false;
185 case MID_FTN_LINE_STYLE:
187 ::editeng::SvxBorderStyle eStyle = table::BorderLineStyle::NONE;
188 sal_Int8 nSet = 0;
189 rVal >>= nSet;
190 switch ( nSet )
192 case 1: eStyle = table::BorderLineStyle::SOLID; break;
193 case 2: eStyle = table::BorderLineStyle::DOTTED; break;
194 case 3: eStyle = table::BorderLineStyle::DASHED; break;
195 default: break;
197 aFtnInfo.SetLineStyle( eStyle );
199 break;
200 default:
201 bRet = false;
203 return bRet;
206 SwPtrItem::SwPtrItem( const sal_uInt16 nId, void* pPtr ) :
207 SfxPoolItem( nId ),
208 pMisc(pPtr)
212 // Copy constructor
214 SwPtrItem::SwPtrItem( const SwPtrItem& rItem ) : SfxPoolItem( rItem )
216 pMisc = rItem.pMisc;
219 // Cloning
221 SfxPoolItem* SwPtrItem::Clone( SfxItemPool * /*pPool*/ ) const
223 return new SwPtrItem( *this );
226 int SwPtrItem::operator==( const SfxPoolItem& rAttr ) const
228 OSL_ENSURE( SfxPoolItem::operator==(rAttr), "unequal types" );
229 const SwPtrItem& rItem = (SwPtrItem&)rAttr;
230 return ( pMisc == rItem.pMisc );
233 // SwUINumRuleItem for the NumTabPages of the FormatNumRule/Styleists
235 SwUINumRuleItem::SwUINumRuleItem( const SwNumRule& rRul, const sal_uInt16 nId )
236 : SfxPoolItem( nId ), pRule( new SwNumRule( rRul ) )
240 SwUINumRuleItem::SwUINumRuleItem( const SwUINumRuleItem& rItem )
241 : SfxPoolItem( rItem ),
242 pRule( new SwNumRule( *rItem.pRule ))
246 SwUINumRuleItem::~SwUINumRuleItem()
248 delete pRule;
251 SfxPoolItem* SwUINumRuleItem::Clone( SfxItemPool * /*pPool*/ ) const
253 return new SwUINumRuleItem( *this );
256 int SwUINumRuleItem::operator==( const SfxPoolItem& rAttr ) const
258 OSL_ENSURE( SfxPoolItem::operator==(rAttr), "unequal types" );
259 return *pRule == *((SwUINumRuleItem&)rAttr).pRule;
262 bool SwUINumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
264 uno::Reference< container::XIndexReplace >xRules = new SwXNumberingRules(*pRule);
265 rVal.setValue(&xRules, ::getCppuType((uno::Reference< container::XIndexReplace>*)0));
266 return true;
268 bool SwUINumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
270 uno::Reference< container::XIndexReplace> xRulesRef;
271 if(rVal >>= xRulesRef)
273 uno::Reference< lang::XUnoTunnel > xTunnel(xRulesRef, uno::UNO_QUERY);
274 SwXNumberingRules* pSwXRules = xTunnel.is() ? reinterpret_cast<SwXNumberingRules*>(
275 xTunnel->getSomething(SwXNumberingRules::getUnoTunnelId())) : 0;
276 if(pSwXRules)
278 *pRule = *pSwXRules->GetNumRule();
281 return true;
284 SwBackgroundDestinationItem::SwBackgroundDestinationItem(sal_uInt16 _nWhich, sal_uInt16 nValue) :
285 SfxUInt16Item(_nWhich, nValue)
289 SfxPoolItem* SwBackgroundDestinationItem::Clone( SfxItemPool * /*pPool*/ ) const
291 return new SwBackgroundDestinationItem(Which(), GetValue());
294 SwPaMItem::SwPaMItem( const sal_uInt16 nId, SwPaM* pPaM ) :
295 SfxPoolItem( nId ),
296 m_pPaM(pPaM)
300 SwPaMItem::SwPaMItem( const SwPaMItem& rItem ) : SfxPoolItem( rItem )
302 m_pPaM = rItem.m_pPaM;
305 SfxPoolItem* SwPaMItem::Clone( SfxItemPool * /*pPool*/ ) const
307 return new SwPaMItem( *this );
310 int SwPaMItem::operator==( const SfxPoolItem& rAttr ) const
312 OSL_ENSURE( SfxPoolItem::operator==(rAttr), "unequal types" );
313 const SwPaMItem& rItem = (SwPaMItem&)rAttr;
314 return ( m_pPaM == rItem.m_pPaM );
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */