xref: /aoo42x/main/svx/source/items/algitem.cxx (revision ae2dc0fa)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svxitems.hrc>
28 
29 
30 #include <tools/stream.hxx>
31 #include <com/sun/star/table/BorderLine.hpp>
32 #include <com/sun/star/table/CellVertJustify.hpp>
33 #include <com/sun/star/table/ShadowLocation.hpp>
34 #include <com/sun/star/table/TableBorder.hpp>
35 #include <com/sun/star/table/ShadowFormat.hpp>
36 #include <com/sun/star/table/CellRangeAddress.hpp>
37 #include <com/sun/star/table/CellContentType.hpp>
38 #include <com/sun/star/table/TableOrientation.hpp>
39 #include <com/sun/star/table/CellHoriJustify.hpp>
40 #include <com/sun/star/style/ParagraphAdjust.hpp>
41 #include "com/sun/star/style/VerticalAlignment.hpp"
42 #include <com/sun/star/util/SortField.hpp>
43 #include <com/sun/star/util/SortFieldType.hpp>
44 #include <com/sun/star/table/CellOrientation.hpp>
45 #include <com/sun/star/table/CellAddress.hpp>
46 
47 #include <svx/algitem.hxx>
48 #include <svx/dialmgr.hxx>
49 #include <editeng/itemtype.hxx>
50 #include <svx/unomid.hxx>
51 
52 using namespace ::rtl;
53 using namespace ::com::sun::star;
54 
55 // Konvertierung fuer UNO
56 #define TWIP_TO_MM100(TWIP) 	((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
57 #define MM100_TO_TWIP(MM100)	((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
58 
59 // STATIC DATA -----------------------------------------------------------
60 
61 //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
62 TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0))
63 TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
64 TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
65 TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
66 
67 // class SvxHorJustifyItem -----------------------------------------------
68 
69 
SvxHorJustifyItem(const sal_uInt16 nId)70 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
71     SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
72 {
73 }
74 
SvxHorJustifyItem(const SvxCellHorJustify eJustify,const sal_uInt16 nId)75 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
76 									  const sal_uInt16 nId ) :
77 	SfxEnumItem( nId, (sal_uInt16)eJustify )
78 {
79 }
80 
81 //------------------------------------------------------------------------
82 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const83 SfxItemPresentation SvxHorJustifyItem::GetPresentation
84 (
85 	SfxItemPresentation ePres,
86     SfxMapUnit          /*eCoreUnit*/,
87     SfxMapUnit          /*ePresUnit*/,
88     XubString&              rText, const IntlWrapper *)    const
89 {
90 	switch ( ePres )
91 	{
92 		case SFX_ITEM_PRESENTATION_NONE:
93 			rText.Erase();
94 			return SFX_ITEM_PRESENTATION_NONE;
95 		case SFX_ITEM_PRESENTATION_NAMELESS:
96 		case SFX_ITEM_PRESENTATION_COMPLETE:
97 			rText = GetValueText( GetValue() );
98 			return SFX_ITEM_PRESENTATION_COMPLETE;
99         default: ; //prevent warning
100 	}
101 	return SFX_ITEM_PRESENTATION_NONE;
102 }
103 
104 //------------------------------------------------------------------------
105 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const106 sal_Bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
107 {
108 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
109     nMemberId &= ~CONVERT_TWIPS;
110 	switch ( nMemberId )
111 	{
112 		case MID_HORJUST_HORJUST:
113 			{
114 				table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
115 				switch ( (SvxCellHorJustify)GetValue() )
116 				{
117 					case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
118 					case SVX_HOR_JUSTIFY_LEFT:	   eUno = table::CellHoriJustify_LEFT;	   break;
119 					case SVX_HOR_JUSTIFY_CENTER:   eUno = table::CellHoriJustify_CENTER;   break;
120 					case SVX_HOR_JUSTIFY_RIGHT:	   eUno = table::CellHoriJustify_RIGHT;	   break;
121 					case SVX_HOR_JUSTIFY_BLOCK:	   eUno = table::CellHoriJustify_BLOCK;	   break;
122 					case SVX_HOR_JUSTIFY_REPEAT:   eUno = table::CellHoriJustify_REPEAT;   break;
123 				}
124 				rVal <<= eUno;
125 			}
126 			break;
127 		case MID_HORJUST_ADJUST:
128 			{
129 				//	ParagraphAdjust values, as in SvxAdjustItem
130 				//	(same value for ParaAdjust and ParaLastLineAdjust)
131 
132 				sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
133 				switch ( (SvxCellHorJustify)GetValue() )
134 				{
135 					// ParagraphAdjust_LEFT is used for STANDARD and REPEAT
136 					case SVX_HOR_JUSTIFY_STANDARD:
137 					case SVX_HOR_JUSTIFY_REPEAT:
138 					case SVX_HOR_JUSTIFY_LEFT:	 nAdjust = style::ParagraphAdjust_LEFT;	  break;
139 					case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
140 					case SVX_HOR_JUSTIFY_RIGHT:	 nAdjust = style::ParagraphAdjust_RIGHT;  break;
141 					case SVX_HOR_JUSTIFY_BLOCK:	 nAdjust = style::ParagraphAdjust_BLOCK;  break;
142 				}
143 				rVal <<= nAdjust;		// as sal_Int16
144 			}
145 			break;
146 	}
147 	return sal_True;
148 }
149 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)150 sal_Bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
151 {
152 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
153     nMemberId &= ~CONVERT_TWIPS;
154 	switch ( nMemberId )
155 	{
156 		case MID_HORJUST_HORJUST:
157 			{
158 				table::CellHoriJustify eUno;
159 				if(!(rVal >>= eUno))
160 				{
161 					sal_Int32 nValue = 0;
162 					if(!(rVal >>= nValue))
163 						return sal_False;
164 					eUno = (table::CellHoriJustify)nValue;
165 				}
166 				SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
167 				switch (eUno)
168 				{
169 					case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
170 					case table::CellHoriJustify_LEFT:	  eSvx = SVX_HOR_JUSTIFY_LEFT;	   break;
171 					case table::CellHoriJustify_CENTER:   eSvx = SVX_HOR_JUSTIFY_CENTER;   break;
172 					case table::CellHoriJustify_RIGHT:	  eSvx = SVX_HOR_JUSTIFY_RIGHT;	   break;
173 					case table::CellHoriJustify_BLOCK:	  eSvx = SVX_HOR_JUSTIFY_BLOCK;	   break;
174 					case table::CellHoriJustify_REPEAT:   eSvx = SVX_HOR_JUSTIFY_REPEAT;   break;
175                     default: ; //prevent warning
176                 }
177 				SetValue( (sal_uInt16)eSvx );
178 			}
179 			break;
180 		case MID_HORJUST_ADJUST:
181 			{
182 				//	property contains ParagraphAdjust values as sal_Int16
183 				sal_Int16 nVal = sal_Int16();
184 				if(!(rVal >>= nVal))
185 					return sal_False;
186 
187 				SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
188 				switch (nVal)
189 				{
190 					//	STRETCH is treated as BLOCK
191 					case style::ParagraphAdjust_LEFT:    eSvx = SVX_HOR_JUSTIFY_LEFT;   break;
192 					case style::ParagraphAdjust_RIGHT:   eSvx = SVX_HOR_JUSTIFY_RIGHT;  break;
193 					case style::ParagraphAdjust_STRETCH:
194 					case style::ParagraphAdjust_BLOCK:   eSvx = SVX_HOR_JUSTIFY_BLOCK;  break;
195 					case style::ParagraphAdjust_CENTER:  eSvx = SVX_HOR_JUSTIFY_CENTER; break;
196 				}
197 				SetValue( (sal_uInt16)eSvx );
198 			}
199 	}
200 	return sal_True;
201 }
202 
203 //------------------------------------------------------------------------
204 
GetValueText(sal_uInt16 nVal) const205 XubString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
206 {
207 	DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
208 	return SVX_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
209 }
210 
211 //------------------------------------------------------------------------
212 
Clone(SfxItemPool *) const213 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
214 {
215 	return new SvxHorJustifyItem( *this );
216 }
217 
218 //------------------------------------------------------------------------
219 
Create(SvStream & rStream,sal_uInt16) const220 SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
221 {
222 	sal_uInt16 nVal;
223 	rStream >> nVal;
224 	return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
225 }
226 //------------------------------------------------------------------------
227 
GetValueCount() const228 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
229 {
230 	return SVX_HOR_JUSTIFY_REPEAT + 1;	// letzter Enum-Wert + 1
231 }
232 
233 // class SvxVerJustifyItem -----------------------------------------------
234 
SvxVerJustifyItem(const sal_uInt16 nId)235 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
236     SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
237 {
238 }
239 
SvxVerJustifyItem(const SvxCellVerJustify eJustify,const sal_uInt16 nId)240 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
241 									  const sal_uInt16 nId ) :
242 	SfxEnumItem( nId, (sal_uInt16)eJustify )
243 {
244 }
245 
246 //------------------------------------------------------------------------
247 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const248 SfxItemPresentation SvxVerJustifyItem::GetPresentation
249 (
250 	SfxItemPresentation ePres,
251     SfxMapUnit          /*eCoreUnit*/,
252     SfxMapUnit          /*ePresUnit*/,
253     XubString&              rText,
254     const IntlWrapper * )    const
255 {
256 	switch ( ePres )
257 	{
258 		case SFX_ITEM_PRESENTATION_NONE:
259 			rText.Erase();
260 			return SFX_ITEM_PRESENTATION_NONE;
261 		case SFX_ITEM_PRESENTATION_NAMELESS:
262 		case SFX_ITEM_PRESENTATION_COMPLETE:
263 			rText = GetValueText( GetValue() );
264 			return SFX_ITEM_PRESENTATION_COMPLETE;
265         default: ; //prevent warning
266     }
267 	return SFX_ITEM_PRESENTATION_NONE;
268 }
269 
270 //------------------------------------------------------------------------
271 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const272 sal_Bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
273 {
274     nMemberId &= ~CONVERT_TWIPS;
275 	switch ( nMemberId )
276     {
277 		case MID_HORJUST_ADJUST:
278 			{
279                 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
280 	            switch ( (SvxCellVerJustify)GetValue() )
281 	            {
282 		            case SVX_VER_JUSTIFY_TOP:	   eUno = style::VerticalAlignment_TOP;	    break;
283 		            case SVX_VER_JUSTIFY_CENTER:   eUno = style::VerticalAlignment_MIDDLE;	break;
284 		            case SVX_VER_JUSTIFY_BOTTOM:   eUno = style::VerticalAlignment_BOTTOM;	break;
285                     default: ; //prevent warning
286                 }
287 	            rVal <<= eUno;
288                 break;
289             }
290         default:
291             {
292 	            table::CellVertJustify eUno = table::CellVertJustify_STANDARD;
293 	            switch ( (SvxCellVerJustify)GetValue() )
294 	            {
295 		            case SVX_VER_JUSTIFY_STANDARD: eUno = table::CellVertJustify_STANDARD; break;
296 		            case SVX_VER_JUSTIFY_TOP:	   eUno = table::CellVertJustify_TOP;	    break;
297 		            case SVX_VER_JUSTIFY_CENTER:   eUno = table::CellVertJustify_CENTER;	break;
298 		            case SVX_VER_JUSTIFY_BOTTOM:   eUno = table::CellVertJustify_BOTTOM;	break;
299                     default: ; //prevent warning
300                 }
301 	            rVal <<= eUno;
302                 break;
303             }
304     }
305 	return sal_True;
306 }
307 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)308 sal_Bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
309 {
310     nMemberId &= ~CONVERT_TWIPS;
311 	switch ( nMemberId )
312     {
313 		case MID_HORJUST_ADJUST:
314 			{
315 				//	property contains ParagraphAdjust values as sal_Int16
316 				style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
317 				if(!(rVal >>= nVal))
318 					return sal_False;
319 
320 				SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
321 				switch (nVal)
322 				{
323 					case style::VerticalAlignment_TOP:      eSvx = SVX_VER_JUSTIFY_TOP;     break;
324 					case style::VerticalAlignment_MIDDLE:   eSvx = SVX_VER_JUSTIFY_CENTER;  break;
325 					case style::VerticalAlignment_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;  break;
326                     default:;
327 				}
328 				SetValue( (sal_uInt16)eSvx );
329                 break;
330 			}
331         default:
332             {
333 		        table::CellVertJustify eUno;
334 	            if(!(rVal >>= eUno))
335 	            {
336 		            sal_Int32 nValue = 0;
337 		            if(!(rVal >>= nValue))
338 			            return sal_False;
339 		            eUno = (table::CellVertJustify)nValue;
340 	            }
341 
342 	            SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
343 	            switch (eUno)
344 	            {
345 		            case table::CellVertJustify_STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD;  break;
346 		            case table::CellVertJustify_TOP:	  eSvx = SVX_VER_JUSTIFY_TOP;	  	break;
347 		            case table::CellVertJustify_CENTER:   eSvx = SVX_VER_JUSTIFY_CENTER;	break;
348 		            case table::CellVertJustify_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;	break;
349                     default: ; //prevent warning
350                 }
351 	            SetValue( (sal_uInt16)eSvx );
352                 break;
353             }
354     }
355 
356 	return sal_True;
357 }
358 
359 //------------------------------------------------------------------------
360 
GetValueText(sal_uInt16 nVal) const361 XubString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
362 {
363 	DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
364 	return SVX_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
365 }
366 
367 //------------------------------------------------------------------------
368 
Clone(SfxItemPool *) const369 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
370 {
371 	return new SvxVerJustifyItem( *this );
372 }
373 
374 //------------------------------------------------------------------------
375 
Create(SvStream & rStream,sal_uInt16) const376 SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
377 {
378 	sal_uInt16 nVal;
379 	rStream >> nVal;
380 	return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
381 }
382 
383 //------------------------------------------------------------------------
384 
GetValueCount() const385 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
386 {
387 	return SVX_VER_JUSTIFY_BOTTOM + 1;	// letzter Enum-Wert + 1
388 }
389 
390 // class SvxOrientationItem ----------------------------------------------
391 
SvxOrientationItem(const SvxCellOrientation eOrientation,const sal_uInt16 nId)392 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
393 										const sal_uInt16 nId):
394 	SfxEnumItem( nId, (sal_uInt16)eOrientation )
395 {
396 }
397 
SvxOrientationItem(sal_Int32 nRotation,sal_Bool bStacked,const sal_uInt16 nId)398 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, sal_Bool bStacked, const sal_uInt16 nId ) :
399     SfxEnumItem( nId )
400 {
401     SetFromRotation( nRotation, bStacked );
402 }
403 
404 //------------------------------------------------------------------------
405 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const406 SfxItemPresentation SvxOrientationItem::GetPresentation
407 (
408 	SfxItemPresentation ePres,
409     SfxMapUnit          /*eCoreUnit*/,
410     SfxMapUnit          /*ePresUnit*/,
411     XubString&              rText, const IntlWrapper * ) const
412 {
413 	switch ( ePres )
414 	{
415 		case SFX_ITEM_PRESENTATION_NONE:
416 			rText.Erase();
417 			return SFX_ITEM_PRESENTATION_NONE;
418 		case SFX_ITEM_PRESENTATION_NAMELESS:
419 		case SFX_ITEM_PRESENTATION_COMPLETE:
420 			rText = GetValueText( GetValue() );
421 			return SFX_ITEM_PRESENTATION_COMPLETE;
422         default: ; //prevent warning
423     }
424 	return SFX_ITEM_PRESENTATION_NONE;
425 }
426 
427 //------------------------------------------------------------------------
428 
QueryValue(uno::Any & rVal,sal_uInt8) const429 sal_Bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
430 {
431 	table::CellOrientation eUno = table::CellOrientation_STANDARD;
432 	switch ( (SvxCellOrientation)GetValue() )
433 	{
434 	case SVX_ORIENTATION_STANDARD:	eUno = table::CellOrientation_STANDARD;  break;
435 	case SVX_ORIENTATION_TOPBOTTOM:	eUno = table::CellOrientation_TOPBOTTOM; break;
436 	case SVX_ORIENTATION_BOTTOMTOP:	eUno = table::CellOrientation_BOTTOMTOP; break;
437 	case SVX_ORIENTATION_STACKED:	eUno = table::CellOrientation_STACKED;	  break;
438 	}
439 	rVal <<= eUno;
440 	return sal_True;
441 }
442 
PutValue(const uno::Any & rVal,sal_uInt8)443 sal_Bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
444 {
445 	table::CellOrientation eOrient;
446 	if(!(rVal >>= eOrient))
447 	{
448 		sal_Int32 nValue = 0;
449 		if(!(rVal >>= nValue))
450 			return sal_False;
451 		eOrient = (table::CellOrientation)nValue;
452 	}
453 	SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
454 	switch (eOrient)
455 	{
456 		case table::CellOrientation_STANDARD:	eSvx = SVX_ORIENTATION_STANDARD;  break;
457 		case table::CellOrientation_TOPBOTTOM:	eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
458 		case table::CellOrientation_BOTTOMTOP:	eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
459 		case table::CellOrientation_STACKED:	eSvx = SVX_ORIENTATION_STACKED;	  break;
460         default: ; //prevent warning
461     }
462 	SetValue( (sal_uInt16)eSvx );
463 	return sal_True;
464 }
465 
466 //------------------------------------------------------------------------
467 
GetValueText(sal_uInt16 nVal) const468 XubString SvxOrientationItem::GetValueText( sal_uInt16 nVal ) const
469 {
470 	DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
471 	return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
472 }
473 
474 //------------------------------------------------------------------------
475 
Clone(SfxItemPool *) const476 SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
477 {
478 	return new SvxOrientationItem( *this );
479 }
480 
481 //------------------------------------------------------------------------
482 
Create(SvStream & rStream,sal_uInt16) const483 SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
484 {
485 	sal_uInt16 nVal;
486 	rStream >> nVal;
487 	return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
488 }
489 
490 //------------------------------------------------------------------------
491 
GetValueCount() const492 sal_uInt16 SvxOrientationItem::GetValueCount() const
493 {
494 	return SVX_ORIENTATION_STACKED + 1;	// letzter Enum-Wert + 1
495 }
496 
497 //------------------------------------------------------------------------
498 
IsStacked() const499 sal_Bool SvxOrientationItem::IsStacked() const
500 {
501     return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
502 }
503 
GetRotation(sal_Int32 nStdAngle) const504 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
505 {
506     sal_Int32 nAngle = nStdAngle;
507     switch( static_cast< SvxCellOrientation >( GetValue() ) )
508     {
509         case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;
510         case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;
511         default: ; //prevent warning
512     }
513     return nAngle;
514 }
515 
SetFromRotation(sal_Int32 nRotation,sal_Bool bStacked)516 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, sal_Bool bStacked )
517 {
518     if( bStacked )
519     {
520         SetValue( SVX_ORIENTATION_STACKED );
521     }
522     else switch( nRotation )
523     {
524         case 9000:  SetValue( SVX_ORIENTATION_BOTTOMTOP );  break;
525         case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM );  break;
526         default:    SetValue( SVX_ORIENTATION_STANDARD );
527     }
528 }
529 
530 // class SvxMarginItem ---------------------------------------------------
531 
SvxMarginItem(const sal_uInt16 nId)532 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
533 
534 	SfxPoolItem( nId ),
535 
536 	nLeftMargin	 ( 20 ),
537 	nTopMargin	 ( 20 ),
538 	nRightMargin ( 20 ),
539 	nBottomMargin( 20 )
540 {
541 }
542 
543 //------------------------------------------------------------------------
544 
SvxMarginItem(sal_Int16 nLeft,sal_Int16 nTop,sal_Int16 nRight,sal_Int16 nBottom,const sal_uInt16 nId)545 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
546 							  sal_Int16 nTop,
547 							  sal_Int16 nRight,
548 							  sal_Int16 nBottom,
549 							  const sal_uInt16 nId ) :
550 	SfxPoolItem( nId ),
551 
552 	nLeftMargin	 ( nLeft ),
553 	nTopMargin	 ( nTop ),
554 	nRightMargin ( nRight ),
555 	nBottomMargin( nBottom )
556 {
557 }
558 
559 
560 //------------------------------------------------------------------------
561 
SvxMarginItem(const SvxMarginItem & rItem)562 SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
563 
564 	SfxPoolItem( rItem.Which() )
565 {
566 	nLeftMargin = rItem.nLeftMargin;
567 	nTopMargin = rItem.nTopMargin;
568 	nRightMargin = rItem.nRightMargin;
569 	nBottomMargin = rItem.nBottomMargin;
570 }
571 
572 //------------------------------------------------------------------------
573 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit eCoreUnit,SfxMapUnit ePresUnit,XubString & rText,const IntlWrapper * pIntl) const574 SfxItemPresentation SvxMarginItem::GetPresentation
575 (
576 	SfxItemPresentation ePres,
577 	SfxMapUnit			eCoreUnit,
578 	SfxMapUnit			ePresUnit,
579     XubString&          rText, const IntlWrapper *pIntl
580 )	const
581 {
582 #ifndef SVX_LIGHT
583 	switch ( ePres )
584 	{
585 		case SFX_ITEM_PRESENTATION_NONE:
586 			rText.Erase();
587 			return SFX_ITEM_PRESENTATION_NONE;
588 		case SFX_ITEM_PRESENTATION_NAMELESS:
589 		{
590             rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
591 			rText += cpDelim;
592             rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
593 			rText += cpDelim;
594             rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
595 			rText += cpDelim;
596             rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
597 			return SFX_ITEM_PRESENTATION_NAMELESS;
598 		}
599 		case SFX_ITEM_PRESENTATION_COMPLETE:
600 		{
601 			rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT);
602             rText += GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
603 			rText += sal_Unicode(' ');
604 			rText += SVX_RESSTR(GetMetricId(ePresUnit));
605 			rText += cpDelim;
606 			rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP);
607             rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
608 			rText += sal_Unicode(' ');
609 			rText += SVX_RESSTR(GetMetricId(ePresUnit));
610 			rText += cpDelim;
611 			rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT);
612             rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
613 			rText += sal_Unicode(' ');
614 			rText += SVX_RESSTR(GetMetricId(ePresUnit));
615 			rText += cpDelim;
616 			rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM);
617             rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
618 			rText += sal_Unicode(' ');
619 			rText += SVX_RESSTR(GetMetricId(ePresUnit));
620 			return SFX_ITEM_PRESENTATION_COMPLETE;
621 		}
622         default: ; //prevent warning
623     }
624 #endif
625 	return SFX_ITEM_PRESENTATION_NONE;
626 }
627 
628 //------------------------------------------------------------------------
629 
operator ==(const SfxPoolItem & rItem) const630 int SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
631 {
632 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
633 
634 	return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin )	&&
635 			 ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin )		&&
636 			 ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin )	&&
637 			 ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
638 }
639 
640 //------------------------------------------------------------------------
641 
Clone(SfxItemPool *) const642 SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
643 {
644 	return new SvxMarginItem(*this);
645 }
646 
647 //------------------------------------------------------------------------
648 
Create(SvStream & rStream,sal_uInt16) const649 SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
650 {
651 	sal_Int16   nLeft;
652 	sal_Int16   nTop;
653 	sal_Int16   nRight;
654 	sal_Int16   nBottom;
655 	rStream >> nLeft;
656 	rStream >> nTop;
657 	rStream >> nRight;
658 	rStream >> nBottom;
659 	return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
660 }
661 
662 //------------------------------------------------------------------------
663 
Store(SvStream & rStream,sal_uInt16) const664 SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
665 {
666 	rStream << nLeftMargin;
667 	rStream << nTopMargin;
668 	rStream << nRightMargin;
669 	rStream << nBottomMargin;
670 	return rStream;
671 }
672 
673 
674 //------------------------------------------------------------------------
675 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const676 sal_Bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
677 {
678     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
679     nMemberId &= ~CONVERT_TWIPS;
680     switch ( nMemberId )
681 	{
682 		//	jetzt alles signed
683 		case MID_MARGIN_L_MARGIN:
684 			rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
685 			break;
686 		case MID_MARGIN_R_MARGIN:
687 			rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
688 			break;
689 		case MID_MARGIN_UP_MARGIN:
690 			rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
691 			break;
692 		case MID_MARGIN_LO_MARGIN:
693 			rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
694 			break;
695 		default:
696 			DBG_ERROR("unknown MemberId");
697 			return sal_False;
698 	}
699 	return sal_True;
700 }
701 
702 //------------------------------------------------------------------------
703 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)704 sal_Bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
705 {
706 	sal_Bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
707 	long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX;	// Members sind sal_Int16
708 	sal_Int32 nVal = 0;
709 	if(!(rVal >>= nVal) || (nVal > nMaxVal))
710 		return sal_False;
711 
712 	switch ( nMemberId & ~CONVERT_TWIPS )
713 	{
714 		case MID_MARGIN_L_MARGIN:
715 			nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
716 			break;
717 		case MID_MARGIN_R_MARGIN:
718 			nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
719 			break;
720 		case MID_MARGIN_UP_MARGIN:
721 			nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
722 			break;
723 		case MID_MARGIN_LO_MARGIN:
724 			nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
725 			break;
726 		default:
727 			DBG_ERROR("unknown MemberId");
728 			return sal_False;
729 	}
730 	return sal_True;
731 }
732 
733 //------------------------------------------------------------------------
734 
SetLeftMargin(sal_Int16 nLeft)735 sal_Bool SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
736 {
737 	nLeftMargin = nLeft;
738 	return sal_True;
739 }
740 
741 //------------------------------------------------------------------------
742 
SetTopMargin(sal_Int16 nTop)743 sal_Bool SvxMarginItem::SetTopMargin( sal_Int16 nTop )
744 {
745 	nTopMargin = nTop;
746 	return sal_True;
747 }
748 
749 //------------------------------------------------------------------------
750 
SetRightMargin(sal_Int16 nRight)751 sal_Bool SvxMarginItem::SetRightMargin( sal_Int16 nRight )
752 {
753 	nRightMargin = nRight;
754 	return sal_True;
755 }
756 
757 //------------------------------------------------------------------------
758 
SetBottomMargin(sal_Int16 nBottom)759 sal_Bool SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
760 {
761 	nBottomMargin = nBottom;
762 	return sal_True;
763 }
764 
765 
766