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/strings.hrc>
21 #include <osl/diagnose.h>
22 #include <tools/mapunit.hxx>
23 #include <tools/UnitConversion.hxx>
24 #include <com/sun/star/table/CellOrientation.hpp>
26 #include <svx/algitem.hxx>
27 #include <svx/dialmgr.hxx>
28 #include <editeng/itemtype.hxx>
29 #include <editeng/eerdll.hxx>
30 #include <svx/unomid.hxx>
34 using namespace ::com::sun::star
;
37 SfxPoolItem
* SvxMarginItem::CreateDefault() { return new SvxMarginItem(0) ;}
39 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation
,
40 const sal_uInt16 nId
):
41 SfxEnumItem( nId
, eOrientation
)
45 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation
, bool bStacked
, const sal_uInt16 nId
) :
46 SfxEnumItem( nId
, SvxCellOrientation::Standard
)
50 SetValue( SvxCellOrientation::Stacked
);
52 else switch( nRotation
)
54 case 9000: SetValue( SvxCellOrientation::BottomUp
); break;
55 case 27000: SetValue( SvxCellOrientation::TopBottom
); break;
56 default: SetValue( SvxCellOrientation::Standard
);
61 bool SvxOrientationItem::GetPresentation
63 SfxItemPresentation
/*ePres*/,
64 MapUnit
/*eCoreUnit*/,
65 MapUnit
/*ePresUnit*/,
67 const IntlWrapper
& ) const
69 rText
= GetValueText( GetValue() );
74 bool SvxOrientationItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
76 table::CellOrientation eUno
= table::CellOrientation_STANDARD
;
79 case SvxCellOrientation::Standard
: eUno
= table::CellOrientation_STANDARD
; break;
80 case SvxCellOrientation::TopBottom
: eUno
= table::CellOrientation_TOPBOTTOM
; break;
81 case SvxCellOrientation::BottomUp
: eUno
= table::CellOrientation_BOTTOMTOP
; break;
82 case SvxCellOrientation::Stacked
: eUno
= table::CellOrientation_STACKED
; break;
88 bool SvxOrientationItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
90 table::CellOrientation eOrient
;
91 if(!(rVal
>>= eOrient
))
94 if(!(rVal
>>= nValue
))
96 eOrient
= static_cast<table::CellOrientation
>(nValue
);
98 SvxCellOrientation eSvx
= SvxCellOrientation::Standard
;
101 case table::CellOrientation_STANDARD
: eSvx
= SvxCellOrientation::Standard
; break;
102 case table::CellOrientation_TOPBOTTOM
: eSvx
= SvxCellOrientation::TopBottom
; break;
103 case table::CellOrientation_BOTTOMTOP
: eSvx
= SvxCellOrientation::BottomUp
; break;
104 case table::CellOrientation_STACKED
: eSvx
= SvxCellOrientation::Stacked
; break;
105 default: ; //prevent warning
111 OUString
SvxOrientationItem::GetValueText( SvxCellOrientation nVal
)
113 return SvxResId(RID_SVXITEMS_ORI_STANDARD
+ static_cast<int>(nVal
));
116 SvxOrientationItem
* SvxOrientationItem::Clone( SfxItemPool
* ) const
118 return new SvxOrientationItem( *this );
121 sal_uInt16
SvxOrientationItem::GetValueCount() const
123 return static_cast<sal_uInt16
>(SvxCellOrientation::Stacked
) + 1; // last enum value + 1
126 bool SvxOrientationItem::IsStacked() const
128 return GetValue() == SvxCellOrientation::Stacked
;
131 sal_Int32
SvxOrientationItem::GetRotation( sal_Int32 nStdAngle
) const
133 sal_Int32 nAngle
= nStdAngle
;
136 case SvxCellOrientation::BottomUp
: nAngle
= 9000;break;
137 case SvxCellOrientation::TopBottom
: nAngle
= 27000;break;
138 default: ; //prevent warning
143 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId
) :
155 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft
,
159 const sal_uInt16 nId
) :
162 nLeftMargin ( nLeft
),
164 nRightMargin ( nRight
),
165 nBottomMargin( nBottom
)
170 bool SvxMarginItem::GetPresentation
172 SfxItemPresentation ePres
,
175 OUString
& rText
, const IntlWrapper
& rIntl
178 OUString
cpDelimTmp(cpDelim
);
182 case SfxItemPresentation::Nameless
:
184 rText
= GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
186 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
188 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
190 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
);
193 case SfxItemPresentation::Complete
:
195 rText
= SvxResId(RID_SVXITEMS_MARGIN_LEFT
) +
196 GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
197 " " + EditResId(GetMetricId(ePresUnit
)) +
199 SvxResId(RID_SVXITEMS_MARGIN_TOP
) +
200 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
201 " " + EditResId(GetMetricId(ePresUnit
)) +
203 SvxResId(RID_SVXITEMS_MARGIN_RIGHT
) +
204 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
205 " " + EditResId(GetMetricId(ePresUnit
)) +
207 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM
) +
208 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
209 " " + EditResId(GetMetricId(ePresUnit
));
212 default: ; //prevent warning
218 bool SvxMarginItem::operator==( const SfxPoolItem
& rItem
) const
220 assert(SfxPoolItem::operator==(rItem
));
222 return ( ( nLeftMargin
== static_cast<const SvxMarginItem
&>(rItem
).nLeftMargin
) &&
223 ( nTopMargin
== static_cast<const SvxMarginItem
&>(rItem
).nTopMargin
) &&
224 ( nRightMargin
== static_cast<const SvxMarginItem
&>(rItem
).nRightMargin
) &&
225 ( nBottomMargin
== static_cast<const SvxMarginItem
&>(rItem
).nBottomMargin
) );
228 SvxMarginItem
* SvxMarginItem::Clone( SfxItemPool
* ) const
230 return new SvxMarginItem(*this);
233 bool SvxMarginItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
235 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
236 nMemberId
&= ~CONVERT_TWIPS
;
239 // now sign everything
240 case MID_MARGIN_L_MARGIN
:
241 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
243 case MID_MARGIN_R_MARGIN
:
244 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
246 case MID_MARGIN_UP_MARGIN
:
247 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nTopMargin
) : nTopMargin
);
249 case MID_MARGIN_LO_MARGIN
:
250 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nBottomMargin
) : nBottomMargin
);
253 OSL_FAIL("unknown MemberId");
260 bool SvxMarginItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
262 bool bConvert
= ( ( nMemberId
& CONVERT_TWIPS
) != 0 );
263 tools::Long nMaxVal
= bConvert
? convertTwipToMm100(SHRT_MAX
) : SHRT_MAX
; // members are sal_Int16
265 if(!(rVal
>>= nVal
) || (nVal
> nMaxVal
))
268 switch ( nMemberId
& ~CONVERT_TWIPS
)
270 case MID_MARGIN_L_MARGIN
:
271 nLeftMargin
= static_cast<sal_Int16
>( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
273 case MID_MARGIN_R_MARGIN
:
274 nRightMargin
= static_cast<sal_Int16
>( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
276 case MID_MARGIN_UP_MARGIN
:
277 nTopMargin
= static_cast<sal_Int16
>( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
279 case MID_MARGIN_LO_MARGIN
:
280 nBottomMargin
= static_cast<sal_Int16
>( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
283 OSL_FAIL("unknown MemberId");
290 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft
)
296 void SvxMarginItem::SetTopMargin( sal_Int16 nTop
)
302 void SvxMarginItem::SetRightMargin( sal_Int16 nRight
)
304 nRightMargin
= nRight
;
308 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom
)
310 nBottomMargin
= nBottom
;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */