Line data Source code
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 :
21 : #include <svx/svxitems.hrc>
22 :
23 :
24 : #include <tools/stream.hxx>
25 : #include <com/sun/star/table/BorderLine.hpp>
26 : #include <com/sun/star/table/ShadowLocation.hpp>
27 : #include <com/sun/star/table/TableBorder.hpp>
28 : #include <com/sun/star/table/ShadowFormat.hpp>
29 : #include <com/sun/star/table/CellRangeAddress.hpp>
30 : #include <com/sun/star/table/CellContentType.hpp>
31 : #include <com/sun/star/table/TableOrientation.hpp>
32 : #include <com/sun/star/util/SortField.hpp>
33 : #include <com/sun/star/util/SortFieldType.hpp>
34 : #include <com/sun/star/table/CellOrientation.hpp>
35 : #include <com/sun/star/table/CellAddress.hpp>
36 :
37 : #include <svx/algitem.hxx>
38 : #include <svx/dialmgr.hxx>
39 : #include <editeng/itemtype.hxx>
40 : #include <svx/unomid.hxx>
41 :
42 : using namespace ::rtl;
43 : using namespace ::com::sun::star;
44 :
45 : // Konvertierung fuer UNO
46 : #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
47 : #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
48 :
49 : // STATIC DATA -----------------------------------------------------------
50 :
51 : //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
52 0 : TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
53 58133 : TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
54 :
55 : // class SvxOrientationItem ----------------------------------------------
56 :
57 514 : SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
58 : const sal_uInt16 nId):
59 514 : SfxEnumItem( nId, (sal_uInt16)eOrientation )
60 : {
61 514 : }
62 :
63 592 : SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, bool bStacked, const sal_uInt16 nId ) :
64 592 : SfxEnumItem( nId )
65 : {
66 592 : SetFromRotation( nRotation, bStacked );
67 592 : }
68 :
69 :
70 :
71 0 : SfxItemPresentation SvxOrientationItem::GetPresentation
72 : (
73 : SfxItemPresentation ePres,
74 : SfxMapUnit /*eCoreUnit*/,
75 : SfxMapUnit /*ePresUnit*/,
76 : OUString& rText, const IntlWrapper * ) const
77 : {
78 0 : switch ( ePres )
79 : {
80 : case SFX_ITEM_PRESENTATION_NONE:
81 0 : rText = OUString();
82 0 : return SFX_ITEM_PRESENTATION_NONE;
83 : case SFX_ITEM_PRESENTATION_NAMELESS:
84 : case SFX_ITEM_PRESENTATION_COMPLETE:
85 0 : rText = GetValueText( GetValue() );
86 0 : return SFX_ITEM_PRESENTATION_COMPLETE;
87 : default: ; //prevent warning
88 : }
89 0 : return SFX_ITEM_PRESENTATION_NONE;
90 : }
91 :
92 :
93 :
94 64 : bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
95 : {
96 64 : table::CellOrientation eUno = table::CellOrientation_STANDARD;
97 64 : switch ( (SvxCellOrientation)GetValue() )
98 : {
99 32 : case SVX_ORIENTATION_STANDARD: eUno = table::CellOrientation_STANDARD; break;
100 14 : case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
101 9 : case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
102 9 : case SVX_ORIENTATION_STACKED: eUno = table::CellOrientation_STACKED; break;
103 : }
104 64 : rVal <<= eUno;
105 64 : return true;
106 : }
107 :
108 0 : bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
109 : {
110 : table::CellOrientation eOrient;
111 0 : if(!(rVal >>= eOrient))
112 : {
113 0 : sal_Int32 nValue = 0;
114 0 : if(!(rVal >>= nValue))
115 0 : return false;
116 0 : eOrient = (table::CellOrientation)nValue;
117 : }
118 0 : SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
119 0 : switch (eOrient)
120 : {
121 0 : case table::CellOrientation_STANDARD: eSvx = SVX_ORIENTATION_STANDARD; break;
122 0 : case table::CellOrientation_TOPBOTTOM: eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
123 0 : case table::CellOrientation_BOTTOMTOP: eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
124 0 : case table::CellOrientation_STACKED: eSvx = SVX_ORIENTATION_STACKED; break;
125 : default: ; //prevent warning
126 : }
127 0 : SetValue( (sal_uInt16)eSvx );
128 0 : return true;
129 : }
130 :
131 :
132 :
133 0 : OUString SvxOrientationItem::GetValueText( sal_uInt16 nVal ) const
134 : {
135 : DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
136 0 : return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
137 : }
138 :
139 :
140 :
141 0 : SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
142 : {
143 0 : return new SvxOrientationItem( *this );
144 : }
145 :
146 :
147 :
148 256 : SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
149 : {
150 : sal_uInt16 nVal;
151 256 : rStream.ReadUInt16( nVal );
152 256 : return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
153 : }
154 :
155 :
156 :
157 0 : sal_uInt16 SvxOrientationItem::GetValueCount() const
158 : {
159 0 : return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
160 : }
161 :
162 :
163 :
164 256 : bool SvxOrientationItem::IsStacked() const
165 : {
166 256 : return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
167 : }
168 :
169 256 : sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
170 : {
171 256 : sal_Int32 nAngle = nStdAngle;
172 256 : switch( static_cast< SvxCellOrientation >( GetValue() ) )
173 : {
174 0 : case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;break;
175 0 : case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;break;
176 : default: ; //prevent warning
177 : }
178 256 : return nAngle;
179 : }
180 :
181 592 : void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, bool bStacked )
182 : {
183 592 : if( bStacked )
184 : {
185 9 : SetValue( SVX_ORIENTATION_STACKED );
186 : }
187 583 : else switch( nRotation )
188 : {
189 9 : case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP ); break;
190 14 : case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM ); break;
191 560 : default: SetValue( SVX_ORIENTATION_STANDARD );
192 : }
193 592 : }
194 :
195 : // class SvxMarginItem ---------------------------------------------------
196 :
197 1295 : SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
198 :
199 : SfxPoolItem( nId ),
200 :
201 : nLeftMargin ( 20 ),
202 : nTopMargin ( 20 ),
203 : nRightMargin ( 20 ),
204 1295 : nBottomMargin( 20 )
205 : {
206 1295 : }
207 :
208 :
209 :
210 2003 : SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
211 : sal_Int16 nTop,
212 : sal_Int16 nRight,
213 : sal_Int16 nBottom,
214 : const sal_uInt16 nId ) :
215 : SfxPoolItem( nId ),
216 :
217 : nLeftMargin ( nLeft ),
218 : nTopMargin ( nTop ),
219 : nRightMargin ( nRight ),
220 2003 : nBottomMargin( nBottom )
221 : {
222 2003 : }
223 :
224 :
225 :
226 :
227 333 : SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
228 :
229 333 : SfxPoolItem( rItem.Which() )
230 : {
231 333 : nLeftMargin = rItem.nLeftMargin;
232 333 : nTopMargin = rItem.nTopMargin;
233 333 : nRightMargin = rItem.nRightMargin;
234 333 : nBottomMargin = rItem.nBottomMargin;
235 333 : }
236 :
237 :
238 :
239 0 : SfxItemPresentation SvxMarginItem::GetPresentation
240 : (
241 : SfxItemPresentation ePres,
242 : SfxMapUnit eCoreUnit,
243 : SfxMapUnit ePresUnit,
244 : OUString& rText, const IntlWrapper *pIntl
245 : ) const
246 : {
247 0 : OUString cpDelimTmp = OUString(cpDelim);
248 :
249 0 : switch ( ePres )
250 : {
251 : case SFX_ITEM_PRESENTATION_NONE:
252 0 : rText = OUString();
253 0 : return SFX_ITEM_PRESENTATION_NONE;
254 : case SFX_ITEM_PRESENTATION_NAMELESS:
255 : {
256 0 : rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
257 0 : cpDelimTmp +
258 0 : GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
259 0 : cpDelimTmp +
260 0 : GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
261 0 : cpDelimTmp +
262 0 : GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
263 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
264 : }
265 : case SFX_ITEM_PRESENTATION_COMPLETE:
266 : {
267 0 : rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT) +
268 0 : GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
269 0 : " " + EE_RESSTR(GetMetricId(ePresUnit)) +
270 0 : cpDelimTmp +
271 0 : SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP) +
272 0 : GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
273 0 : " " + EE_RESSTR(GetMetricId(ePresUnit)) +
274 0 : cpDelimTmp +
275 0 : SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT) +
276 0 : GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
277 0 : " " + EE_RESSTR(GetMetricId(ePresUnit)) +
278 0 : cpDelimTmp +
279 0 : SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM) +
280 0 : GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl ) +
281 0 : " " + EE_RESSTR(GetMetricId(ePresUnit));
282 0 : return SFX_ITEM_PRESENTATION_COMPLETE;
283 : }
284 : default: ; //prevent warning
285 : }
286 0 : return SFX_ITEM_PRESENTATION_NONE;
287 : }
288 :
289 :
290 :
291 2116 : bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
292 : {
293 : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
294 :
295 4121 : return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin ) &&
296 3851 : ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin ) &&
297 5772 : ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin ) &&
298 3926 : ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
299 : }
300 :
301 :
302 :
303 301 : SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
304 : {
305 301 : return new SvxMarginItem(*this);
306 : }
307 :
308 :
309 :
310 256 : SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
311 : {
312 : sal_Int16 nLeft;
313 : sal_Int16 nTop;
314 : sal_Int16 nRight;
315 : sal_Int16 nBottom;
316 256 : rStream.ReadInt16( nLeft );
317 256 : rStream.ReadInt16( nTop );
318 256 : rStream.ReadInt16( nRight );
319 256 : rStream.ReadInt16( nBottom );
320 256 : return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
321 : }
322 :
323 :
324 :
325 528 : SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
326 : {
327 528 : rStream.WriteInt16( nLeftMargin );
328 528 : rStream.WriteInt16( nTopMargin );
329 528 : rStream.WriteInt16( nRightMargin );
330 528 : rStream.WriteInt16( nBottomMargin );
331 528 : return rStream;
332 : }
333 :
334 :
335 :
336 :
337 100 : bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
338 : {
339 100 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
340 100 : nMemberId &= ~CONVERT_TWIPS;
341 100 : switch ( nMemberId )
342 : {
343 : // jetzt alles signed
344 : case MID_MARGIN_L_MARGIN:
345 25 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
346 25 : break;
347 : case MID_MARGIN_R_MARGIN:
348 25 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
349 25 : break;
350 : case MID_MARGIN_UP_MARGIN:
351 25 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
352 25 : break;
353 : case MID_MARGIN_LO_MARGIN:
354 25 : rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
355 25 : break;
356 : default:
357 : OSL_FAIL("unknown MemberId");
358 0 : return false;
359 : }
360 100 : return true;
361 : }
362 :
363 :
364 :
365 180 : bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
366 : {
367 180 : bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
368 180 : long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX; // Members sind sal_Int16
369 180 : sal_Int32 nVal = 0;
370 180 : if(!(rVal >>= nVal) || (nVal > nMaxVal))
371 0 : return false;
372 :
373 180 : switch ( nMemberId & ~CONVERT_TWIPS )
374 : {
375 : case MID_MARGIN_L_MARGIN:
376 45 : nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
377 45 : break;
378 : case MID_MARGIN_R_MARGIN:
379 45 : nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
380 45 : break;
381 : case MID_MARGIN_UP_MARGIN:
382 45 : nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
383 45 : break;
384 : case MID_MARGIN_LO_MARGIN:
385 45 : nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
386 45 : break;
387 : default:
388 : OSL_FAIL("unknown MemberId");
389 0 : return false;
390 : }
391 180 : return true;
392 : }
393 :
394 :
395 :
396 0 : void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
397 : {
398 0 : nLeftMargin = nLeft;
399 0 : }
400 :
401 :
402 :
403 0 : void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
404 : {
405 0 : nTopMargin = nTop;
406 0 : }
407 :
408 :
409 :
410 0 : void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
411 : {
412 0 : nRightMargin = nRight;
413 0 : }
414 :
415 :
416 :
417 0 : void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
418 : {
419 0 : nBottomMargin = nBottom;
420 0 : }
421 :
422 :
423 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|