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 .
20 #include <svx/svxitems.hrc>
22 #include <tools/stream.hxx>
23 #include <tools/mapunit.hxx>
24 #include <com/sun/star/table/BorderLine.hpp>
25 #include <com/sun/star/table/ShadowLocation.hpp>
26 #include <com/sun/star/table/TableBorder.hpp>
27 #include <com/sun/star/table/ShadowFormat.hpp>
28 #include <com/sun/star/table/CellRangeAddress.hpp>
29 #include <com/sun/star/table/CellContentType.hpp>
30 #include <com/sun/star/table/TableOrientation.hpp>
31 #include <com/sun/star/util/SortField.hpp>
32 #include <com/sun/star/util/SortFieldType.hpp>
33 #include <com/sun/star/table/CellOrientation.hpp>
34 #include <com/sun/star/table/CellAddress.hpp>
36 #include <svx/algitem.hxx>
37 #include <svx/dialmgr.hxx>
38 #include <editeng/itemtype.hxx>
39 #include <svx/unomid.hxx>
41 using namespace ::com::sun::star
;
43 TYPEINIT1_FACTORY( SvxOrientationItem
, SfxEnumItem
, new SvxOrientationItem(SVX_ORIENTATION_STANDARD
, 0) );
44 TYPEINIT1_FACTORY( SvxMarginItem
, SfxPoolItem
, new SvxMarginItem(0) );
46 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation
,
47 const sal_uInt16 nId
):
48 SfxEnumItem( nId
, (sal_uInt16
)eOrientation
)
52 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation
, bool bStacked
, const sal_uInt16 nId
) :
55 SetFromRotation( nRotation
, bStacked
);
60 bool SvxOrientationItem::GetPresentation
62 SfxItemPresentation
/*ePres*/,
63 SfxMapUnit
/*eCoreUnit*/,
64 SfxMapUnit
/*ePresUnit*/,
65 OUString
& rText
, const IntlWrapper
* ) const
67 rText
= GetValueText( GetValue() );
73 bool SvxOrientationItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
75 table::CellOrientation eUno
= table::CellOrientation_STANDARD
;
76 switch ( (SvxCellOrientation
)GetValue() )
78 case SVX_ORIENTATION_STANDARD
: eUno
= table::CellOrientation_STANDARD
; break;
79 case SVX_ORIENTATION_TOPBOTTOM
: eUno
= table::CellOrientation_TOPBOTTOM
; break;
80 case SVX_ORIENTATION_BOTTOMTOP
: eUno
= table::CellOrientation_BOTTOMTOP
; break;
81 case SVX_ORIENTATION_STACKED
: eUno
= table::CellOrientation_STACKED
; break;
87 bool SvxOrientationItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
89 table::CellOrientation eOrient
;
90 if(!(rVal
>>= eOrient
))
93 if(!(rVal
>>= nValue
))
95 eOrient
= (table::CellOrientation
)nValue
;
97 SvxCellOrientation eSvx
= SVX_ORIENTATION_STANDARD
;
100 case table::CellOrientation_STANDARD
: eSvx
= SVX_ORIENTATION_STANDARD
; break;
101 case table::CellOrientation_TOPBOTTOM
: eSvx
= SVX_ORIENTATION_TOPBOTTOM
; break;
102 case table::CellOrientation_BOTTOMTOP
: eSvx
= SVX_ORIENTATION_BOTTOMTOP
; break;
103 case table::CellOrientation_STACKED
: eSvx
= SVX_ORIENTATION_STACKED
; break;
104 default: ; //prevent warning
106 SetValue( (sal_uInt16
)eSvx
);
112 OUString
SvxOrientationItem::GetValueText( sal_uInt16 nVal
)
114 DBG_ASSERT( nVal
<= SVX_ORIENTATION_STACKED
, "enum overflow!" );
115 return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD
+ nVal
);
120 SfxPoolItem
* SvxOrientationItem::Clone( SfxItemPool
* ) const
122 return new SvxOrientationItem( *this );
127 SfxPoolItem
* SvxOrientationItem::Create( SvStream
& rStream
, sal_uInt16
) const
130 rStream
.ReadUInt16( nVal
);
131 return new SvxOrientationItem( (SvxCellOrientation
)nVal
, Which() );
136 sal_uInt16
SvxOrientationItem::GetValueCount() const
138 return SVX_ORIENTATION_STACKED
+ 1; // letzter Enum-Wert + 1
143 bool SvxOrientationItem::IsStacked() const
145 return static_cast< SvxCellOrientation
>( GetValue() ) == SVX_ORIENTATION_STACKED
;
148 sal_Int32
SvxOrientationItem::GetRotation( sal_Int32 nStdAngle
) const
150 sal_Int32 nAngle
= nStdAngle
;
151 switch( static_cast< SvxCellOrientation
>( GetValue() ) )
153 case SVX_ORIENTATION_BOTTOMTOP
: nAngle
= 9000;break;
154 case SVX_ORIENTATION_TOPBOTTOM
: nAngle
= 27000;break;
155 default: ; //prevent warning
160 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation
, bool bStacked
)
164 SetValue( SVX_ORIENTATION_STACKED
);
166 else switch( nRotation
)
168 case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP
); break;
169 case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM
); break;
170 default: SetValue( SVX_ORIENTATION_STANDARD
);
174 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId
) :
187 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft
,
191 const sal_uInt16 nId
) :
194 nLeftMargin ( nLeft
),
196 nRightMargin ( nRight
),
197 nBottomMargin( nBottom
)
204 SvxMarginItem::SvxMarginItem( const SvxMarginItem
& rItem
) :
206 SfxPoolItem( rItem
.Which() )
208 nLeftMargin
= rItem
.nLeftMargin
;
209 nTopMargin
= rItem
.nTopMargin
;
210 nRightMargin
= rItem
.nRightMargin
;
211 nBottomMargin
= rItem
.nBottomMargin
;
216 bool SvxMarginItem::GetPresentation
218 SfxItemPresentation ePres
,
219 SfxMapUnit eCoreUnit
,
220 SfxMapUnit ePresUnit
,
221 OUString
& rText
, const IntlWrapper
*pIntl
224 OUString cpDelimTmp
= OUString(cpDelim
);
228 case SFX_ITEM_PRESENTATION_NAMELESS
:
230 rText
= GetMetricText( (long)nLeftMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
232 GetMetricText( (long)nTopMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
234 GetMetricText( (long)nRightMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
236 GetMetricText( (long)nBottomMargin
, eCoreUnit
, ePresUnit
, pIntl
);
239 case SFX_ITEM_PRESENTATION_COMPLETE
:
241 rText
= SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT
) +
242 GetMetricText( (long)nLeftMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
243 " " + EE_RESSTR(GetMetricId(ePresUnit
)) +
245 SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP
) +
246 GetMetricText( (long)nTopMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
247 " " + EE_RESSTR(GetMetricId(ePresUnit
)) +
249 SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT
) +
250 GetMetricText( (long)nRightMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
251 " " + EE_RESSTR(GetMetricId(ePresUnit
)) +
253 SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM
) +
254 GetMetricText( (long)nBottomMargin
, eCoreUnit
, ePresUnit
, pIntl
) +
255 " " + EE_RESSTR(GetMetricId(ePresUnit
));
258 default: ; //prevent warning
265 bool SvxMarginItem::operator==( const SfxPoolItem
& rItem
) const
267 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
269 return ( ( nLeftMargin
== static_cast<const SvxMarginItem
&>(rItem
).nLeftMargin
) &&
270 ( nTopMargin
== static_cast<const SvxMarginItem
&>(rItem
).nTopMargin
) &&
271 ( nRightMargin
== static_cast<const SvxMarginItem
&>(rItem
).nRightMargin
) &&
272 ( nBottomMargin
== static_cast<const SvxMarginItem
&>(rItem
).nBottomMargin
) );
277 SfxPoolItem
* SvxMarginItem::Clone( SfxItemPool
* ) const
279 return new SvxMarginItem(*this);
284 SfxPoolItem
* SvxMarginItem::Create( SvStream
& rStream
, sal_uInt16
) const
290 rStream
.ReadInt16( nLeft
);
291 rStream
.ReadInt16( nTop
);
292 rStream
.ReadInt16( nRight
);
293 rStream
.ReadInt16( nBottom
);
294 return new SvxMarginItem( nLeft
, nTop
, nRight
, nBottom
, Which() );
299 SvStream
& SvxMarginItem::Store( SvStream
&rStream
, sal_uInt16
/*nItemVersion*/) const
301 rStream
.WriteInt16( nLeftMargin
);
302 rStream
.WriteInt16( nTopMargin
);
303 rStream
.WriteInt16( nRightMargin
);
304 rStream
.WriteInt16( nBottomMargin
);
311 bool SvxMarginItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
313 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
314 nMemberId
&= ~CONVERT_TWIPS
;
317 // jetzt alles signed
318 case MID_MARGIN_L_MARGIN
:
319 rVal
<<= (sal_Int32
)( bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
321 case MID_MARGIN_R_MARGIN
:
322 rVal
<<= (sal_Int32
)( bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
324 case MID_MARGIN_UP_MARGIN
:
325 rVal
<<= (sal_Int32
)( bConvert
? convertTwipToMm100(nTopMargin
) : nTopMargin
);
327 case MID_MARGIN_LO_MARGIN
:
328 rVal
<<= (sal_Int32
)( bConvert
? convertTwipToMm100(nBottomMargin
) : nBottomMargin
);
331 OSL_FAIL("unknown MemberId");
339 bool SvxMarginItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
341 bool bConvert
= ( ( nMemberId
& CONVERT_TWIPS
) != 0 );
342 long nMaxVal
= bConvert
? convertTwipToMm100(SHRT_MAX
) : SHRT_MAX
; // Members sind sal_Int16
344 if(!(rVal
>>= nVal
) || (nVal
> nMaxVal
))
347 switch ( nMemberId
& ~CONVERT_TWIPS
)
349 case MID_MARGIN_L_MARGIN
:
350 nLeftMargin
= (sal_Int16
)( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
352 case MID_MARGIN_R_MARGIN
:
353 nRightMargin
= (sal_Int16
)( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
355 case MID_MARGIN_UP_MARGIN
:
356 nTopMargin
= (sal_Int16
)( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
358 case MID_MARGIN_LO_MARGIN
:
359 nBottomMargin
= (sal_Int16
)( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
362 OSL_FAIL("unknown MemberId");
370 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft
)
377 void SvxMarginItem::SetTopMargin( sal_Int16 nTop
)
384 void SvxMarginItem::SetRightMargin( sal_Int16 nRight
)
386 nRightMargin
= nRight
;
391 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom
)
393 nBottomMargin
= nBottom
;
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */