Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/svxitems.hrc>
31 : :
32 : :
33 : : #include <tools/stream.hxx>
34 : : #include <com/sun/star/table/BorderLine.hpp>
35 : : #include <com/sun/star/table/ShadowLocation.hpp>
36 : : #include <com/sun/star/table/TableBorder.hpp>
37 : : #include <com/sun/star/table/ShadowFormat.hpp>
38 : : #include <com/sun/star/table/CellRangeAddress.hpp>
39 : : #include <com/sun/star/table/CellContentType.hpp>
40 : : #include <com/sun/star/table/TableOrientation.hpp>
41 : : #include <com/sun/star/util/SortField.hpp>
42 : : #include <com/sun/star/util/SortFieldType.hpp>
43 : : #include <com/sun/star/table/CellOrientation.hpp>
44 : : #include <com/sun/star/table/CellAddress.hpp>
45 : :
46 : : #include <svx/algitem.hxx>
47 : : #include <svx/dialmgr.hxx>
48 : : #include <editeng/itemtype.hxx>
49 : : #include <svx/unomid.hxx>
50 : :
51 : : using namespace ::rtl;
52 : : using namespace ::com::sun::star;
53 : :
54 : : // Konvertierung fuer UNO
55 : : #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
56 : : #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
57 : :
58 : : // STATIC DATA -----------------------------------------------------------
59 : :
60 : : //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
61 [ # # ][ # # ]: 0 : TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
[ # # ]
62 [ - + ][ - + ]: 10017 : TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
[ # # ]
63 : :
64 : : // class SvxOrientationItem ----------------------------------------------
65 : :
66 : 514 : SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
67 : : const sal_uInt16 nId):
68 : 514 : SfxEnumItem( nId, (sal_uInt16)eOrientation )
69 : : {
70 : 514 : }
71 : :
72 : 562 : SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, sal_Bool bStacked, const sal_uInt16 nId ) :
73 : 562 : SfxEnumItem( nId )
74 : : {
75 [ + - ]: 562 : SetFromRotation( nRotation, bStacked );
76 : 562 : }
77 : :
78 : : //------------------------------------------------------------------------
79 : :
80 : 0 : SfxItemPresentation SvxOrientationItem::GetPresentation
81 : : (
82 : : SfxItemPresentation ePres,
83 : : SfxMapUnit /*eCoreUnit*/,
84 : : SfxMapUnit /*ePresUnit*/,
85 : : XubString& rText, const IntlWrapper * ) const
86 : : {
87 [ # # # ]: 0 : switch ( ePres )
88 : : {
89 : : case SFX_ITEM_PRESENTATION_NONE:
90 : 0 : rText.Erase();
91 : 0 : return SFX_ITEM_PRESENTATION_NONE;
92 : : case SFX_ITEM_PRESENTATION_NAMELESS:
93 : : case SFX_ITEM_PRESENTATION_COMPLETE:
94 [ # # ]: 0 : rText = GetValueText( GetValue() );
95 : 0 : return SFX_ITEM_PRESENTATION_COMPLETE;
96 : : default: ; //prevent warning
97 : : }
98 : 0 : return SFX_ITEM_PRESENTATION_NONE;
99 : : }
100 : :
101 : : //------------------------------------------------------------------------
102 : :
103 : 34 : bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
104 : : {
105 : 34 : table::CellOrientation eUno = table::CellOrientation_STANDARD;
106 [ + + - - : 34 : switch ( (SvxCellOrientation)GetValue() )
- ]
107 : : {
108 : 27 : case SVX_ORIENTATION_STANDARD: eUno = table::CellOrientation_STANDARD; break;
109 : 7 : case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
110 : 0 : case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
111 : 0 : case SVX_ORIENTATION_STACKED: eUno = table::CellOrientation_STACKED; break;
112 : : }
113 [ + - ]: 34 : rVal <<= eUno;
114 : 34 : return true;
115 : : }
116 : :
117 : 0 : bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
118 : : {
119 : : table::CellOrientation eOrient;
120 [ # # ][ # # ]: 0 : if(!(rVal >>= eOrient))
121 : : {
122 : 0 : sal_Int32 nValue = 0;
123 [ # # ]: 0 : if(!(rVal >>= nValue))
124 : 0 : return sal_False;
125 : 0 : eOrient = (table::CellOrientation)nValue;
126 : : }
127 : 0 : SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
128 [ # # # # : 0 : switch (eOrient)
# ]
129 : : {
130 : 0 : case table::CellOrientation_STANDARD: eSvx = SVX_ORIENTATION_STANDARD; break;
131 : 0 : case table::CellOrientation_TOPBOTTOM: eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
132 : 0 : case table::CellOrientation_BOTTOMTOP: eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
133 : 0 : case table::CellOrientation_STACKED: eSvx = SVX_ORIENTATION_STACKED; break;
134 : : default: ; //prevent warning
135 : : }
136 : 0 : SetValue( (sal_uInt16)eSvx );
137 : 0 : return true;
138 : : }
139 : :
140 : : //------------------------------------------------------------------------
141 : :
142 : 0 : XubString SvxOrientationItem::GetValueText( sal_uInt16 nVal ) const
143 : : {
144 : : DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
145 [ # # ][ # # ]: 0 : return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
146 : : }
147 : :
148 : : //------------------------------------------------------------------------
149 : :
150 : 0 : SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
151 : : {
152 [ # # ]: 0 : return new SvxOrientationItem( *this );
153 : : }
154 : :
155 : : //------------------------------------------------------------------------
156 : :
157 : 256 : SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
158 : : {
159 : : sal_uInt16 nVal;
160 [ + - ]: 256 : rStream >> nVal;
161 [ + - ][ + - ]: 256 : return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
162 : : }
163 : :
164 : : //------------------------------------------------------------------------
165 : :
166 : 0 : sal_uInt16 SvxOrientationItem::GetValueCount() const
167 : : {
168 : 0 : return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
169 : : }
170 : :
171 : : //------------------------------------------------------------------------
172 : :
173 : 256 : sal_Bool SvxOrientationItem::IsStacked() const
174 : : {
175 : 256 : return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
176 : : }
177 : :
178 : 256 : sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
179 : : {
180 : 256 : sal_Int32 nAngle = nStdAngle;
181 [ - - + ]: 256 : switch( static_cast< SvxCellOrientation >( GetValue() ) )
182 : : {
183 : 0 : case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;break;
184 : 0 : case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;break;
185 : : default: ; //prevent warning
186 : : }
187 : 256 : return nAngle;
188 : : }
189 : :
190 : 562 : void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, sal_Bool bStacked )
191 : : {
192 [ - + ]: 562 : if( bStacked )
193 : : {
194 : 0 : SetValue( SVX_ORIENTATION_STACKED );
195 : : }
196 [ - + + ]: 562 : else switch( nRotation )
197 : : {
198 : 0 : case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP ); break;
199 : 7 : case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM ); break;
200 : 555 : default: SetValue( SVX_ORIENTATION_STANDARD );
201 : : }
202 : 562 : }
203 : :
204 : : // class SvxMarginItem ---------------------------------------------------
205 : :
206 : 1488 : SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
207 : :
208 : : SfxPoolItem( nId ),
209 : :
210 : : nLeftMargin ( 20 ),
211 : : nTopMargin ( 20 ),
212 : : nRightMargin ( 20 ),
213 : 1488 : nBottomMargin( 20 )
214 : : {
215 : 1488 : }
216 : :
217 : : //------------------------------------------------------------------------
218 : :
219 : 1336 : SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
220 : : sal_Int16 nTop,
221 : : sal_Int16 nRight,
222 : : sal_Int16 nBottom,
223 : : const sal_uInt16 nId ) :
224 : : SfxPoolItem( nId ),
225 : :
226 : : nLeftMargin ( nLeft ),
227 : : nTopMargin ( nTop ),
228 : : nRightMargin ( nRight ),
229 : 1336 : nBottomMargin( nBottom )
230 : : {
231 : 1336 : }
232 : :
233 : :
234 : : //------------------------------------------------------------------------
235 : :
236 : 740 : SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
237 : :
238 : 740 : SfxPoolItem( rItem.Which() )
239 : : {
240 : 740 : nLeftMargin = rItem.nLeftMargin;
241 : 740 : nTopMargin = rItem.nTopMargin;
242 : 740 : nRightMargin = rItem.nRightMargin;
243 : 740 : nBottomMargin = rItem.nBottomMargin;
244 : 740 : }
245 : :
246 : : //------------------------------------------------------------------------
247 : :
248 : 0 : SfxItemPresentation SvxMarginItem::GetPresentation
249 : : (
250 : : SfxItemPresentation ePres,
251 : : SfxMapUnit eCoreUnit,
252 : : SfxMapUnit ePresUnit,
253 : : XubString& rText, const IntlWrapper *pIntl
254 : : ) const
255 : : {
256 [ # # # # ]: 0 : switch ( ePres )
257 : : {
258 : : case SFX_ITEM_PRESENTATION_NONE:
259 : 0 : rText.Erase();
260 : 0 : return SFX_ITEM_PRESENTATION_NONE;
261 : : case SFX_ITEM_PRESENTATION_NAMELESS:
262 : : {
263 [ # # ]: 0 : rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
264 : 0 : rText += cpDelim;
265 [ # # ]: 0 : rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
266 : 0 : rText += cpDelim;
267 [ # # ]: 0 : rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
268 : 0 : rText += cpDelim;
269 [ # # ]: 0 : rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
270 : 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
271 : : }
272 : : case SFX_ITEM_PRESENTATION_COMPLETE:
273 : : {
274 [ # # ][ # # ]: 0 : rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT);
275 [ # # ]: 0 : rText += GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
276 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(GetMetricId(ePresUnit));
277 : 0 : rText += cpDelim;
278 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP);
279 [ # # ]: 0 : rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
280 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(GetMetricId(ePresUnit));
281 : 0 : rText += cpDelim;
282 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT);
283 [ # # ]: 0 : rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
284 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(GetMetricId(ePresUnit));
285 : 0 : rText += cpDelim;
286 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM);
287 [ # # ]: 0 : rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
288 [ # # ][ # # ]: 0 : rText += SVX_RESSTR(GetMetricId(ePresUnit));
289 : 0 : return SFX_ITEM_PRESENTATION_COMPLETE;
290 : : }
291 : : default: ; //prevent warning
292 : : }
293 : 0 : return SFX_ITEM_PRESENTATION_NONE;
294 : : }
295 : :
296 : : //------------------------------------------------------------------------
297 : :
298 : 2105 : int SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
299 : : {
300 : : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
301 : :
302 : : return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin ) &&
303 : : ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin ) &&
304 : : ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin ) &&
305 [ + + ][ + + ]: 2105 : ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
[ + + ][ + + ]
306 : : }
307 : :
308 : : //------------------------------------------------------------------------
309 : :
310 : 708 : SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
311 : : {
312 [ + - ]: 708 : return new SvxMarginItem(*this);
313 : : }
314 : :
315 : : //------------------------------------------------------------------------
316 : :
317 : 256 : SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
318 : : {
319 : : sal_Int16 nLeft;
320 : : sal_Int16 nTop;
321 : : sal_Int16 nRight;
322 : : sal_Int16 nBottom;
323 [ + - ]: 256 : rStream >> nLeft;
324 [ + - ]: 256 : rStream >> nTop;
325 [ + - ]: 256 : rStream >> nRight;
326 [ + - ]: 256 : rStream >> nBottom;
327 [ + - ][ + - ]: 256 : return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
328 : : }
329 : :
330 : : //------------------------------------------------------------------------
331 : :
332 : 528 : SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
333 : : {
334 : 528 : rStream << nLeftMargin;
335 : 528 : rStream << nTopMargin;
336 : 528 : rStream << nRightMargin;
337 : 528 : rStream << nBottomMargin;
338 : 528 : return rStream;
339 : : }
340 : :
341 : :
342 : : //------------------------------------------------------------------------
343 : :
344 : 136 : bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
345 : : {
346 : 136 : sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
347 : 136 : nMemberId &= ~CONVERT_TWIPS;
348 [ + + + + : 136 : switch ( nMemberId )
- ]
349 : : {
350 : : // jetzt alles signed
351 : : case MID_MARGIN_L_MARGIN:
352 [ + - ][ + - ]: 34 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
[ + - ]
353 : 34 : break;
354 : : case MID_MARGIN_R_MARGIN:
355 [ + - ][ + - ]: 34 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
[ + - ]
356 : 34 : break;
357 : : case MID_MARGIN_UP_MARGIN:
358 [ + - ][ + - ]: 34 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
[ + - ]
359 : 34 : break;
360 : : case MID_MARGIN_LO_MARGIN:
361 [ + - ][ + - ]: 34 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
[ + - ]
362 : 34 : break;
363 : : default:
364 : : OSL_FAIL("unknown MemberId");
365 : 0 : return false;
366 : : }
367 : 136 : return true;
368 : : }
369 : :
370 : : //------------------------------------------------------------------------
371 : :
372 : 488 : bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
373 : : {
374 : 488 : sal_Bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
375 [ + - ]: 488 : long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX; // Members sind sal_Int16
376 : 488 : sal_Int32 nVal = 0;
377 [ + - ][ - + ]: 488 : if(!(rVal >>= nVal) || (nVal > nMaxVal))
[ - + ]
378 : 0 : return sal_False;
379 : :
380 [ + + + + : 488 : switch ( nMemberId & ~CONVERT_TWIPS )
- ]
381 : : {
382 : : case MID_MARGIN_L_MARGIN:
383 [ + - ][ + - ]: 122 : nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
384 : 122 : break;
385 : : case MID_MARGIN_R_MARGIN:
386 [ + - ][ + - ]: 122 : nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
387 : 122 : break;
388 : : case MID_MARGIN_UP_MARGIN:
389 [ + - ][ + - ]: 122 : nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
390 : 122 : break;
391 : : case MID_MARGIN_LO_MARGIN:
392 [ + - ][ + - ]: 122 : nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
393 : 122 : break;
394 : : default:
395 : : OSL_FAIL("unknown MemberId");
396 : 0 : return false;
397 : : }
398 : 488 : return true;
399 : : }
400 : :
401 : : //------------------------------------------------------------------------
402 : :
403 : 0 : sal_Bool SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
404 : : {
405 : 0 : nLeftMargin = nLeft;
406 : 0 : return sal_True;
407 : : }
408 : :
409 : : //------------------------------------------------------------------------
410 : :
411 : 0 : sal_Bool SvxMarginItem::SetTopMargin( sal_Int16 nTop )
412 : : {
413 : 0 : nTopMargin = nTop;
414 : 0 : return sal_True;
415 : : }
416 : :
417 : : //------------------------------------------------------------------------
418 : :
419 : 0 : sal_Bool SvxMarginItem::SetRightMargin( sal_Int16 nRight )
420 : : {
421 : 0 : nRightMargin = nRight;
422 : 0 : return sal_True;
423 : : }
424 : :
425 : : //------------------------------------------------------------------------
426 : :
427 : 0 : sal_Bool SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
428 : : {
429 : 0 : nBottomMargin = nBottom;
430 : 0 : return sal_True;
431 : : }
432 : :
433 : :
434 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|