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(TypedWhichId
<SvxMarginItem
>(0)) ;}
39 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation
,
40 const TypedWhichId
<SvxOrientationItem
> nId
):
41 SfxEnumItem( nId
, eOrientation
)
45 SvxOrientationItem::SvxOrientationItem( Degree100 nRotation
, bool bStacked
, const TypedWhichId
<SvxOrientationItem
> nId
) :
46 SfxEnumItem( nId
, SvxCellOrientation::Standard
)
50 SetValue( SvxCellOrientation::Stacked
);
52 else switch( nRotation
.get() )
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 OString id
= OString::Concat(RID_SVXITEMS_ORI_STANDARD
.mpId
) + OString::number(static_cast<int>(nVal
));
114 return SvxResId(TranslateId(RID_SVXITEMS_ORI_STANDARD
.mpContext
, id
.getStr()));
117 SvxOrientationItem
* SvxOrientationItem::Clone( SfxItemPool
* ) const
119 return new SvxOrientationItem( *this );
122 sal_uInt16
SvxOrientationItem::GetValueCount() const
124 return static_cast<sal_uInt16
>(SvxCellOrientation::Stacked
) + 1; // last enum value + 1
127 bool SvxOrientationItem::IsStacked() const
129 return GetValue() == SvxCellOrientation::Stacked
;
132 Degree100
SvxOrientationItem::GetRotation( Degree100 nStdAngle
) const
134 Degree100 nAngle
= nStdAngle
;
137 case SvxCellOrientation::BottomUp
: nAngle
= 9000_deg100
; break;
138 case SvxCellOrientation::TopBottom
: nAngle
= 27000_deg100
; break;
139 default: ; //prevent warning
144 SvxMarginItem::SvxMarginItem( const TypedWhichId
<SvxMarginItem
> nId
) :
156 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft
,
160 const TypedWhichId
<SvxMarginItem
> nId
) :
163 nLeftMargin ( nLeft
),
165 nRightMargin ( nRight
),
166 nBottomMargin( nBottom
)
171 bool SvxMarginItem::GetPresentation
173 SfxItemPresentation ePres
,
176 OUString
& rText
, const IntlWrapper
& rIntl
179 OUString
cpDelimTmp(cpDelim
);
183 case SfxItemPresentation::Nameless
:
185 rText
= GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
187 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
189 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
191 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
);
194 case SfxItemPresentation::Complete
:
196 rText
= SvxResId(RID_SVXITEMS_MARGIN_LEFT
) +
197 GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
198 " " + EditResId(GetMetricId(ePresUnit
)) +
200 SvxResId(RID_SVXITEMS_MARGIN_TOP
) +
201 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
202 " " + EditResId(GetMetricId(ePresUnit
)) +
204 SvxResId(RID_SVXITEMS_MARGIN_RIGHT
) +
205 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
206 " " + EditResId(GetMetricId(ePresUnit
)) +
208 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM
) +
209 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
210 " " + EditResId(GetMetricId(ePresUnit
));
213 default: ; //prevent warning
219 bool SvxMarginItem::operator==( const SfxPoolItem
& rItem
) const
221 assert(SfxPoolItem::operator==(rItem
));
223 return ( ( nLeftMargin
== static_cast<const SvxMarginItem
&>(rItem
).nLeftMargin
) &&
224 ( nTopMargin
== static_cast<const SvxMarginItem
&>(rItem
).nTopMargin
) &&
225 ( nRightMargin
== static_cast<const SvxMarginItem
&>(rItem
).nRightMargin
) &&
226 ( nBottomMargin
== static_cast<const SvxMarginItem
&>(rItem
).nBottomMargin
) );
229 SvxMarginItem
* SvxMarginItem::Clone( SfxItemPool
* ) const
231 return new SvxMarginItem(*this);
234 bool SvxMarginItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
236 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
237 nMemberId
&= ~CONVERT_TWIPS
;
240 // now sign everything
241 case MID_MARGIN_L_MARGIN
:
242 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
244 case MID_MARGIN_R_MARGIN
:
245 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
247 case MID_MARGIN_UP_MARGIN
:
248 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nTopMargin
) : nTopMargin
);
250 case MID_MARGIN_LO_MARGIN
:
251 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nBottomMargin
) : nBottomMargin
);
254 OSL_FAIL("unknown MemberId");
261 bool SvxMarginItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
263 bool bConvert
= ( ( nMemberId
& CONVERT_TWIPS
) != 0 );
264 tools::Long nMaxVal
= bConvert
? convertTwipToMm100(SHRT_MAX
) : SHRT_MAX
; // members are sal_Int16
266 if(!(rVal
>>= nVal
) || (nVal
> nMaxVal
))
269 switch ( nMemberId
& ~CONVERT_TWIPS
)
271 case MID_MARGIN_L_MARGIN
:
272 nLeftMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
274 case MID_MARGIN_R_MARGIN
:
275 nRightMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
277 case MID_MARGIN_UP_MARGIN
:
278 nTopMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
280 case MID_MARGIN_LO_MARGIN
:
281 nBottomMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
284 OSL_FAIL("unknown MemberId");
291 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft
)
297 void SvxMarginItem::SetTopMargin( sal_Int16 nTop
)
303 void SvxMarginItem::SetRightMargin( sal_Int16 nRight
)
305 nRightMargin
= nRight
;
309 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom
)
311 nBottomMargin
= nBottom
;
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */