xref: /aoo42x/main/sw/source/ui/utlui/uiitems.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <editeng/itemtype.hxx>
33 #include <unosett.hxx>
34 
35 #include "swtypes.hxx"
36 #include "cmdid.h"
37 #include "uiitems.hxx"
38 
39 #include "utlui.hrc"
40 #include "attrdesc.hrc"
41 #ifndef _UNOMID_H
42 #include <unomid.h>
43 #endif
44 #include <numrule.hxx>
45 
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 
49 // Breitenangaben der Fussnotenlinien, mit TabPage abstimmen
50 static const sal_uInt16 __FAR_DATA nFtnLines[] = {
51 	0,
52 	10,
53 	50,
54 	80,
55 	100,
56 	150
57 };
58 
59 #define FTN_LINE_STYLE_COUNT 5
60 
61 
62 SwPageFtnInfoItem::SwPageFtnInfoItem( const sal_uInt16 nId, SwPageFtnInfo& rInfo) :
63 	SfxPoolItem( nId ),
64 	aFtnInfo(rInfo)
65 {
66 }
67 
68 
69 SwPageFtnInfoItem::SwPageFtnInfoItem( const SwPageFtnInfoItem& rItem ) :
70 	SfxPoolItem( rItem ),
71 	aFtnInfo(rItem.GetPageFtnInfo())
72 {
73 }
74 
75 
76  SwPageFtnInfoItem::~SwPageFtnInfoItem()
77 {
78 }
79 
80 
81 SfxPoolItem*  SwPageFtnInfoItem::Clone( SfxItemPool * /*pPool*/ ) const
82 {
83 	return new SwPageFtnInfoItem( *this );
84 }
85 
86 
87 int  SwPageFtnInfoItem::operator==( const SfxPoolItem& rAttr ) const
88 {
89 	DBG_ASSERT( Which() == rAttr.Which(), "keine gleichen Attribute" );
90 	return ( aFtnInfo == ((SwPageFtnInfoItem&)rAttr).GetPageFtnInfo());
91 }
92 
93 
94 SfxItemPresentation  SwPageFtnInfoItem::GetPresentation
95 (
96 	SfxItemPresentation ePres,
97 	SfxMapUnit			eCoreUnit,
98 	SfxMapUnit			ePresUnit,
99 	String& 			rText,
100     const IntlWrapper*    pIntl
101 )	const
102 {
103 	switch ( ePres )
104 	{
105 		case SFX_ITEM_PRESENTATION_NONE:
106 			rText.Erase();
107 			return SFX_ITEM_PRESENTATION_NONE;
108 		case SFX_ITEM_PRESENTATION_NAMELESS:
109 		case SFX_ITEM_PRESENTATION_COMPLETE:
110 		{
111 			sal_uInt16 nHght = (sal_uInt16) GetPageFtnInfo().GetHeight();
112 			if ( nHght )
113 			{
114 				rText = SW_RESSTR( STR_MAX_FTN_HEIGHT );
115 				rText += ' ';
116                 rText += ::GetMetricText( nHght, eCoreUnit, ePresUnit, pIntl );
117 				rText += ::GetSvxString( ::GetMetricId( ePresUnit ) );
118 			}
119 			return ePres;
120 		}
121         default:; //prevent warning
122 	}
123 	return SFX_ITEM_PRESENTATION_NONE;
124 }
125 /* -----------------------------26.04.01 12:25--------------------------------
126 
127  ---------------------------------------------------------------------------*/
128 sal_Bool SwPageFtnInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
129 {
130     sal_Bool bRet = sal_True;
131     switch(nMemberId & ~CONVERT_TWIPS)
132     {
133         case MID_FTN_HEIGHT        :     rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetHeight());break;
134         case MID_LINE_WEIGHT       :     rVal <<= (sal_Int16)TWIP_TO_MM100_UNSIGNED(aFtnInfo.GetLineWidth());break;
135         case MID_LINE_COLOR        :     rVal <<= (sal_Int32)aFtnInfo.GetLineColor().GetColor();break;
136         case MID_LINE_RELWIDTH     :
137         {
138             Fraction aTmp( 100, 1 );
139             aTmp *= aFtnInfo.GetWidth();
140             rVal <<= (sal_Int8)(long)aTmp;
141         }
142         break;
143         case MID_LINE_ADJUST       :     rVal <<= (sal_Int16)aFtnInfo.GetAdj();break;//text::HorizontalAdjust
144         case MID_LINE_TEXT_DIST    :     rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetTopDist());break;
145         case MID_LINE_FOOTNOTE_DIST:     rVal <<= (sal_Int32)TWIP_TO_MM100(aFtnInfo.GetBottomDist());break;
146         default:
147             bRet = sal_False;
148     }
149     return bRet;
150 }
151 /* -----------------------------26.04.01 12:26--------------------------------
152 
153  ---------------------------------------------------------------------------*/
154 sal_Bool SwPageFtnInfoItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
155 {
156     sal_Int32 nSet32 = 0;
157     sal_Bool bRet = sal_True;
158     switch(nMemberId  & ~CONVERT_TWIPS)
159     {
160         case MID_LINE_COLOR        :
161             rVal >>= nSet32;
162             aFtnInfo.SetLineColor(nSet32);
163         break;
164         case MID_FTN_HEIGHT:
165         case MID_LINE_TEXT_DIST    :
166         case MID_LINE_FOOTNOTE_DIST:
167                 rVal >>= nSet32;
168                 if(nSet32 < 0)
169                     bRet = sal_False;
170                 else
171                 {
172                     nSet32 = MM100_TO_TWIP(nSet32);
173                     switch(nMemberId & ~CONVERT_TWIPS)
174                     {
175                         case MID_FTN_HEIGHT:            aFtnInfo.SetHeight(nSet32);    break;
176                         case MID_LINE_TEXT_DIST:        aFtnInfo.SetTopDist(nSet32);break;
177                         case MID_LINE_FOOTNOTE_DIST:    aFtnInfo.SetBottomDist(nSet32);break;
178                     }
179                 }
180         break;
181         case MID_LINE_WEIGHT       :
182         {
183             sal_Int16 nSet = 0;
184             rVal >>= nSet;
185             if(nSet >= 0)
186                 aFtnInfo.SetLineWidth(MM100_TO_TWIP(nSet));
187             else
188                 bRet = sal_False;
189         }
190         break;
191         case MID_LINE_RELWIDTH     :
192         {
193             sal_Int8 nSet = 0;
194             rVal >>= nSet;
195             if(nSet < 0)
196                 bRet = sal_False;
197             else
198                 aFtnInfo.SetWidth(Fraction(nSet, 100));
199         }
200         break;
201         case MID_LINE_ADJUST       :
202         {
203             sal_Int16 nSet = 0;
204             rVal >>= nSet;
205             if(nSet >= 0 && nSet < 3) //text::HorizontalAdjust
206                 aFtnInfo.SetAdj((SwFtnAdj)nSet);
207             else
208                 bRet = sal_False;
209         }
210         break;
211         default:
212             bRet = sal_False;
213     }
214     return bRet;
215 }
216 
217 SwPtrItem::SwPtrItem( const sal_uInt16 nId, void* pPtr ) :
218 	SfxPoolItem( nId ),
219 	pMisc(pPtr)
220 {
221 }
222 
223 /*--------------------------------------------------------------------
224 	Beschreibung: Copy-Konstruktor
225  --------------------------------------------------------------------*/
226 
227 
228 SwPtrItem::SwPtrItem( const SwPtrItem& rItem ) : SfxPoolItem( rItem )
229 {
230 	pMisc = rItem.pMisc;
231 }
232 
233 /*--------------------------------------------------------------------
234 	Beschreibung: Clonen
235  --------------------------------------------------------------------*/
236 
237 
238 SfxPoolItem* SwPtrItem::Clone( SfxItemPool * /*pPool*/ ) const
239 {
240 	return new SwPtrItem( *this );
241 }
242 
243 /*--------------------------------------------------------------------
244 	Beschreibung:
245  --------------------------------------------------------------------*/
246 
247 
248 int SwPtrItem::operator==( const SfxPoolItem& rAttr ) const
249 {
250 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
251 	const SwPtrItem& rItem = (SwPtrItem&)rAttr;
252 	return ( pMisc == rItem.pMisc );
253 }
254 
255 
256 /*-----------------12.11.97 12:55-------------------------------
257  SwUINumRuleItem fuer die NumTabPages der FormatNumRule/Stylisten
258 ---------------------------------------------------------------*/
259 SwUINumRuleItem::SwUINumRuleItem( const SwNumRule& rRul, const sal_uInt16 nId )
260 	: SfxPoolItem( nId ), pRule( new SwNumRule( rRul ) )
261 {
262 }
263 
264 SwUINumRuleItem::SwUINumRuleItem( const SwUINumRuleItem& rItem )
265 	: SfxPoolItem( rItem ),
266 	pRule( new SwNumRule( *rItem.pRule ))
267 {
268 }
269 
270  SwUINumRuleItem::~SwUINumRuleItem()
271 {
272 	delete pRule;
273 }
274 
275 
276 SfxPoolItem*  SwUINumRuleItem::Clone( SfxItemPool * /*pPool*/ ) const
277 {
278 	return new SwUINumRuleItem( *this );
279 }
280 
281 int  SwUINumRuleItem::operator==( const SfxPoolItem& rAttr ) const
282 {
283 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
284 	return *pRule == *((SwUINumRuleItem&)rAttr).pRule;
285 }
286 
287 sal_Bool SwUINumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
288 {
289 	uno::Reference< container::XIndexReplace >xRules = new SwXNumberingRules(*pRule);
290 	rVal.setValue(&xRules, ::getCppuType((uno::Reference< container::XIndexReplace>*)0));
291 	return sal_True;
292 }
293 sal_Bool SwUINumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
294 {
295     uno::Reference< container::XIndexReplace> xRulesRef;
296     if(rVal >>= xRulesRef)
297 	{
298         uno::Reference< lang::XUnoTunnel > xTunnel(xRulesRef, uno::UNO_QUERY);
299         SwXNumberingRules* pSwXRules = xTunnel.is() ? reinterpret_cast<SwXNumberingRules*>(
300                     xTunnel->getSomething(SwXNumberingRules::getUnoTunnelId())) : 0;
301 		if(pSwXRules)
302 		{
303 			*pRule = *pSwXRules->GetNumRule();
304 		}
305 	}
306 	return sal_True;
307 }
308 /* -----------------17.06.98 17:43-------------------
309  *
310  * --------------------------------------------------*/
311 SwBackgroundDestinationItem::SwBackgroundDestinationItem(sal_uInt16  _nWhich, sal_uInt16 nValue) :
312     SfxUInt16Item(_nWhich, nValue)
313 {
314 }
315 /* -----------------17.06.98 17:44-------------------
316  *
317  * --------------------------------------------------*/
318 SfxPoolItem*     SwBackgroundDestinationItem::Clone( SfxItemPool * /*pPool*/ ) const
319 {
320 	return new SwBackgroundDestinationItem(Which(), GetValue());
321 }
322 
323 
324 
325