1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <svx/svxitems.hrc>
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>
37 #include <svx/algitem.hxx>
38 #include <svx/dialmgr.hxx>
39 #include <editeng/itemtype.hxx>
40 #include <svx/unomid.hxx>
42 using namespace ::rtl
;
43 using namespace ::com::sun::star
;
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))
49 // STATIC DATA -----------------------------------------------------------
51 //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
52 TYPEINIT1_FACTORY( SvxOrientationItem
, SfxEnumItem
, new SvxOrientationItem(SVX_ORIENTATION_STANDARD
, 0) );
53 TYPEINIT1_FACTORY( SvxMarginItem
, SfxPoolItem
, new SvxMarginItem(0) );
55 // class SvxOrientationItem ----------------------------------------------
57 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation
,
58 const sal_uInt16 nId
):
59 SfxEnumItem( nId
, (sal_uInt16
)eOrientation
)
63 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation
, sal_Bool bStacked
, const sal_uInt16 nId
) :
66 SetFromRotation( nRotation
, bStacked
);
69 //------------------------------------------------------------------------
71 SfxItemPresentation
SvxOrientationItem::GetPresentation
73 SfxItemPresentation ePres
,
74 SfxMapUnit
/*eCoreUnit*/,
75 SfxMapUnit
/*ePresUnit*/,
76 OUString
& rText
, const IntlWrapper
* ) const
80 case SFX_ITEM_PRESENTATION_NONE
:
82 return SFX_ITEM_PRESENTATION_NONE
;
83 case SFX_ITEM_PRESENTATION_NAMELESS
:
84 case SFX_ITEM_PRESENTATION_COMPLETE
:
85 rText
= GetValueText( GetValue() );
86 return SFX_ITEM_PRESENTATION_COMPLETE
;
87 default: ; //prevent warning
89 return SFX_ITEM_PRESENTATION_NONE
;
92 //------------------------------------------------------------------------
94 bool SvxOrientationItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
96 table::CellOrientation eUno
= table::CellOrientation_STANDARD
;
97 switch ( (SvxCellOrientation
)GetValue() )
99 case SVX_ORIENTATION_STANDARD
: eUno
= table::CellOrientation_STANDARD
; break;
100 case SVX_ORIENTATION_TOPBOTTOM
: eUno
= table::CellOrientation_TOPBOTTOM
; break;
101 case SVX_ORIENTATION_BOTTOMTOP
: eUno
= table::CellOrientation_BOTTOMTOP
; break;
102 case SVX_ORIENTATION_STACKED
: eUno
= table::CellOrientation_STACKED
; break;
108 bool SvxOrientationItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
110 table::CellOrientation eOrient
;
111 if(!(rVal
>>= eOrient
))
113 sal_Int32 nValue
= 0;
114 if(!(rVal
>>= nValue
))
116 eOrient
= (table::CellOrientation
)nValue
;
118 SvxCellOrientation eSvx
= SVX_ORIENTATION_STANDARD
;
121 case table::CellOrientation_STANDARD
: eSvx
= SVX_ORIENTATION_STANDARD
; break;
122 case table::CellOrientation_TOPBOTTOM
: eSvx
= SVX_ORIENTATION_TOPBOTTOM
; break;
123 case table::CellOrientation_BOTTOMTOP
: eSvx
= SVX_ORIENTATION_BOTTOMTOP
; break;
124 case table::CellOrientation_STACKED
: eSvx
= SVX_ORIENTATION_STACKED
; break;
125 default: ; //prevent warning
127 SetValue( (sal_uInt16
)eSvx
);
131 //------------------------------------------------------------------------
133 XubString
SvxOrientationItem::GetValueText( sal_uInt16 nVal
) const
135 DBG_ASSERT( nVal
<= SVX_ORIENTATION_STACKED
, "enum overflow!" );
136 return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD
+ nVal
);
139 //------------------------------------------------------------------------
141 SfxPoolItem
* SvxOrientationItem::Clone( SfxItemPool
* ) const
143 return new SvxOrientationItem( *this );
146 //------------------------------------------------------------------------
148 SfxPoolItem
* SvxOrientationItem::Create( SvStream
& rStream
, sal_uInt16
) const
152 return new SvxOrientationItem( (SvxCellOrientation
)nVal
, Which() );
155 //------------------------------------------------------------------------
157 sal_uInt16
SvxOrientationItem::GetValueCount() const
159 return SVX_ORIENTATION_STACKED
+ 1; // letzter Enum-Wert + 1
162 //------------------------------------------------------------------------
164 sal_Bool
SvxOrientationItem::IsStacked() const
166 return static_cast< SvxCellOrientation
>( GetValue() ) == SVX_ORIENTATION_STACKED
;
169 sal_Int32
SvxOrientationItem::GetRotation( sal_Int32 nStdAngle
) const
171 sal_Int32 nAngle
= nStdAngle
;
172 switch( static_cast< SvxCellOrientation
>( GetValue() ) )
174 case SVX_ORIENTATION_BOTTOMTOP
: nAngle
= 9000;break;
175 case SVX_ORIENTATION_TOPBOTTOM
: nAngle
= 27000;break;
176 default: ; //prevent warning
181 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation
, sal_Bool bStacked
)
185 SetValue( SVX_ORIENTATION_STACKED
);
187 else switch( nRotation
)
189 case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP
); break;
190 case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM
); break;
191 default: SetValue( SVX_ORIENTATION_STANDARD
);
195 // class SvxMarginItem ---------------------------------------------------
197 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId
) :
208 //------------------------------------------------------------------------
210 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft
,
214 const sal_uInt16 nId
) :
217 nLeftMargin ( nLeft
),
219 nRightMargin ( nRight
),
220 nBottomMargin( nBottom
)
225 //------------------------------------------------------------------------
227 SvxMarginItem::SvxMarginItem( const SvxMarginItem
& rItem
) :
229 SfxPoolItem( rItem
.Which() )
231 nLeftMargin
= rItem
.nLeftMargin
;
232 nTopMargin
= rItem
.nTopMargin
;
233 nRightMargin
= rItem
.nRightMargin
;
234 nBottomMargin
= rItem
.nBottomMargin
;
237 //------------------------------------------------------------------------
239 SfxItemPresentation
SvxMarginItem::GetPresentation
241 SfxItemPresentation ePres
,
242 SfxMapUnit eCoreUnit
,
243 SfxMapUnit ePresUnit
,
244 OUString
& rText
, const IntlWrapper
*pIntl
247 OUString cpDelimTmp
= OUString(cpDelim
);
251 case SFX_ITEM_PRESENTATION_NONE
:
253 return SFX_ITEM_PRESENTATION_NONE
;
254 case SFX_ITEM_PRESENTATION_NAMELESS
:
256 rText
= GetMetricText( (long)nLeftMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
258 GetMetricText( (long)nTopMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
260 GetMetricText( (long)nRightMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
262 GetMetricText( (long)nBottomMargin
, eCoreUnit
, ePresUnit
, pIntl
);
263 return SFX_ITEM_PRESENTATION_NAMELESS
;
265 case SFX_ITEM_PRESENTATION_COMPLETE
:
267 rText
= SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT
) +
268 GetMetricText( (long)nLeftMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
269 EE_RESSTR(GetMetricId(ePresUnit
)) +
271 SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP
) +
272 GetMetricText( (long)nTopMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
273 EE_RESSTR(GetMetricId(ePresUnit
)) +
275 SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT
) +
276 GetMetricText( (long)nRightMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
277 EE_RESSTR(GetMetricId(ePresUnit
)) +
279 SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM
) +
280 GetMetricText( (long)nBottomMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
281 EE_RESSTR(GetMetricId(ePresUnit
));
282 return SFX_ITEM_PRESENTATION_COMPLETE
;
284 default: ; //prevent warning
286 return SFX_ITEM_PRESENTATION_NONE
;
289 //------------------------------------------------------------------------
291 int SvxMarginItem::operator==( const SfxPoolItem
& rItem
) const
293 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
295 return ( ( nLeftMargin
== ( (SvxMarginItem
&)rItem
).nLeftMargin
) &&
296 ( nTopMargin
== ( (SvxMarginItem
&)rItem
).nTopMargin
) &&
297 ( nRightMargin
== ( (SvxMarginItem
&)rItem
).nRightMargin
) &&
298 ( nBottomMargin
== ( (SvxMarginItem
&)rItem
).nBottomMargin
) );
301 //------------------------------------------------------------------------
303 SfxPoolItem
* SvxMarginItem::Clone( SfxItemPool
* ) const
305 return new SvxMarginItem(*this);
308 //------------------------------------------------------------------------
310 SfxPoolItem
* SvxMarginItem::Create( SvStream
& rStream
, sal_uInt16
) const
320 return new SvxMarginItem( nLeft
, nTop
, nRight
, nBottom
, Which() );
323 //------------------------------------------------------------------------
325 SvStream
& SvxMarginItem::Store( SvStream
&rStream
, sal_uInt16
/*nItemVersion*/) const
327 rStream
<< nLeftMargin
;
328 rStream
<< nTopMargin
;
329 rStream
<< nRightMargin
;
330 rStream
<< nBottomMargin
;
335 //------------------------------------------------------------------------
337 bool SvxMarginItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
339 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
340 nMemberId
&= ~CONVERT_TWIPS
;
343 // jetzt alles signed
344 case MID_MARGIN_L_MARGIN
:
345 rVal
<<= (sal_Int32
)( bConvert
? TWIP_TO_MM100(nLeftMargin
) : nLeftMargin
);
347 case MID_MARGIN_R_MARGIN
:
348 rVal
<<= (sal_Int32
)( bConvert
? TWIP_TO_MM100(nRightMargin
) : nRightMargin
);
350 case MID_MARGIN_UP_MARGIN
:
351 rVal
<<= (sal_Int32
)( bConvert
? TWIP_TO_MM100(nTopMargin
) : nTopMargin
);
353 case MID_MARGIN_LO_MARGIN
:
354 rVal
<<= (sal_Int32
)( bConvert
? TWIP_TO_MM100(nBottomMargin
) : nBottomMargin
);
357 OSL_FAIL("unknown MemberId");
363 //------------------------------------------------------------------------
365 bool SvxMarginItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
367 bool bConvert
= ( ( nMemberId
& CONVERT_TWIPS
) != 0 );
368 long nMaxVal
= bConvert
? TWIP_TO_MM100(SHRT_MAX
) : SHRT_MAX
; // Members sind sal_Int16
370 if(!(rVal
>>= nVal
) || (nVal
> nMaxVal
))
373 switch ( nMemberId
& ~CONVERT_TWIPS
)
375 case MID_MARGIN_L_MARGIN
:
376 nLeftMargin
= (sal_Int16
)( bConvert
? MM100_TO_TWIP(nVal
) : nVal
);
378 case MID_MARGIN_R_MARGIN
:
379 nRightMargin
= (sal_Int16
)( bConvert
? MM100_TO_TWIP(nVal
) : nVal
);
381 case MID_MARGIN_UP_MARGIN
:
382 nTopMargin
= (sal_Int16
)( bConvert
? MM100_TO_TWIP(nVal
) : nVal
);
384 case MID_MARGIN_LO_MARGIN
:
385 nBottomMargin
= (sal_Int16
)( bConvert
? MM100_TO_TWIP(nVal
) : nVal
);
388 OSL_FAIL("unknown MemberId");
394 //------------------------------------------------------------------------
396 sal_Bool
SvxMarginItem::SetLeftMargin( sal_Int16 nLeft
)
402 //------------------------------------------------------------------------
404 sal_Bool
SvxMarginItem::SetTopMargin( sal_Int16 nTop
)
410 //------------------------------------------------------------------------
412 sal_Bool
SvxMarginItem::SetRightMargin( sal_Int16 nRight
)
414 nRightMargin
= nRight
;
418 //------------------------------------------------------------------------
420 sal_Bool
SvxMarginItem::SetBottomMargin( sal_Int16 nBottom
)
422 nBottomMargin
= nBottom
;
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */