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>
31 #include <o3tl/hash_combine.hxx>
35 using namespace ::com::sun::star
;
38 SfxPoolItem
* SvxMarginItem::CreateDefault() { return new SvxMarginItem(TypedWhichId
<SvxMarginItem
>(0)) ;}
40 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation
,
41 const TypedWhichId
<SvxOrientationItem
> nId
):
42 SfxEnumItem( nId
, eOrientation
)
46 SvxOrientationItem::SvxOrientationItem( Degree100 nRotation
, bool bStacked
, const TypedWhichId
<SvxOrientationItem
> nId
) :
47 SfxEnumItem( nId
, SvxCellOrientation::Standard
)
51 SetValue( SvxCellOrientation::Stacked
);
53 else switch( nRotation
.get() )
55 case 9000: SetValue( SvxCellOrientation::BottomUp
); break;
56 case 27000: SetValue( SvxCellOrientation::TopBottom
); break;
57 default: SetValue( SvxCellOrientation::Standard
);
62 bool SvxOrientationItem::GetPresentation
64 SfxItemPresentation
/*ePres*/,
65 MapUnit
/*eCoreUnit*/,
66 MapUnit
/*ePresUnit*/,
68 const IntlWrapper
& ) const
70 rText
= GetValueText( GetValue() );
75 bool SvxOrientationItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
77 table::CellOrientation eUno
= table::CellOrientation_STANDARD
;
80 case SvxCellOrientation::Standard
: eUno
= table::CellOrientation_STANDARD
; break;
81 case SvxCellOrientation::TopBottom
: eUno
= table::CellOrientation_TOPBOTTOM
; break;
82 case SvxCellOrientation::BottomUp
: eUno
= table::CellOrientation_BOTTOMTOP
; break;
83 case SvxCellOrientation::Stacked
: eUno
= table::CellOrientation_STACKED
; break;
89 bool SvxOrientationItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
91 table::CellOrientation eOrient
;
92 if(!(rVal
>>= eOrient
))
95 if(!(rVal
>>= nValue
))
97 eOrient
= static_cast<table::CellOrientation
>(nValue
);
99 SvxCellOrientation eSvx
= SvxCellOrientation::Standard
;
102 case table::CellOrientation_STANDARD
: eSvx
= SvxCellOrientation::Standard
; break;
103 case table::CellOrientation_TOPBOTTOM
: eSvx
= SvxCellOrientation::TopBottom
; break;
104 case table::CellOrientation_BOTTOMTOP
: eSvx
= SvxCellOrientation::BottomUp
; break;
105 case table::CellOrientation_STACKED
: eSvx
= SvxCellOrientation::Stacked
; break;
106 default: ; //prevent warning
112 OUString
SvxOrientationItem::GetValueText( SvxCellOrientation nVal
)
114 OString id
= OString::Concat(RID_SVXITEMS_ORI_STANDARD
.getId()) + OString::number(static_cast<int>(nVal
));
115 return SvxResId(TranslateId(RID_SVXITEMS_ORI_STANDARD
.mpContext
, id
.getStr()));
118 SvxOrientationItem
* SvxOrientationItem::Clone( SfxItemPool
* ) const
120 return new SvxOrientationItem( *this );
123 sal_uInt16
SvxOrientationItem::GetValueCount() const
125 return static_cast<sal_uInt16
>(SvxCellOrientation::Stacked
) + 1; // last enum value + 1
128 bool SvxOrientationItem::IsStacked() const
130 return GetValue() == SvxCellOrientation::Stacked
;
133 Degree100
SvxOrientationItem::GetRotation( Degree100 nStdAngle
) const
135 Degree100 nAngle
= nStdAngle
;
138 case SvxCellOrientation::BottomUp
: nAngle
= 9000_deg100
; break;
139 case SvxCellOrientation::TopBottom
: nAngle
= 27000_deg100
; break;
140 default: ; //prevent warning
145 SvxMarginItem::SvxMarginItem( const TypedWhichId
<SvxMarginItem
> nId
) :
157 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft
,
161 const TypedWhichId
<SvxMarginItem
> nId
) :
164 nLeftMargin ( nLeft
),
166 nRightMargin ( nRight
),
167 nBottomMargin( nBottom
)
172 bool SvxMarginItem::GetPresentation
174 SfxItemPresentation ePres
,
177 OUString
& rText
, const IntlWrapper
& rIntl
180 OUString
cpDelimTmp(cpDelim
);
184 case SfxItemPresentation::Nameless
:
186 rText
= GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
188 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
190 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
192 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
);
195 case SfxItemPresentation::Complete
:
197 rText
= SvxResId(RID_SVXITEMS_MARGIN_LEFT
) +
198 GetMetricText( static_cast<tools::Long
>(nLeftMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
199 " " + EditResId(GetMetricId(ePresUnit
)) +
201 SvxResId(RID_SVXITEMS_MARGIN_TOP
) +
202 GetMetricText( static_cast<tools::Long
>(nTopMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
203 " " + EditResId(GetMetricId(ePresUnit
)) +
205 SvxResId(RID_SVXITEMS_MARGIN_RIGHT
) +
206 GetMetricText( static_cast<tools::Long
>(nRightMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
207 " " + EditResId(GetMetricId(ePresUnit
)) +
209 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM
) +
210 GetMetricText( static_cast<tools::Long
>(nBottomMargin
), eCoreUnit
, ePresUnit
, &rIntl
) +
211 " " + EditResId(GetMetricId(ePresUnit
));
214 default: ; //prevent warning
220 bool SvxMarginItem::operator==( const SfxPoolItem
& rItem
) const
222 assert(SfxPoolItem::operator==(rItem
));
224 return ( ( nLeftMargin
== static_cast<const SvxMarginItem
&>(rItem
).nLeftMargin
) &&
225 ( nTopMargin
== static_cast<const SvxMarginItem
&>(rItem
).nTopMargin
) &&
226 ( nRightMargin
== static_cast<const SvxMarginItem
&>(rItem
).nRightMargin
) &&
227 ( nBottomMargin
== static_cast<const SvxMarginItem
&>(rItem
).nBottomMargin
) );
230 SvxMarginItem
* SvxMarginItem::Clone( SfxItemPool
* ) const
232 return new SvxMarginItem(*this);
235 bool SvxMarginItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
237 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
238 nMemberId
&= ~CONVERT_TWIPS
;
241 // now sign everything
242 case MID_MARGIN_L_MARGIN
:
243 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
245 case MID_MARGIN_R_MARGIN
:
246 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
248 case MID_MARGIN_UP_MARGIN
:
249 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nTopMargin
) : nTopMargin
);
251 case MID_MARGIN_LO_MARGIN
:
252 rVal
<<= static_cast<sal_Int32
>( bConvert
? convertTwipToMm100(nBottomMargin
) : nBottomMargin
);
255 OSL_FAIL("unknown MemberId");
262 bool SvxMarginItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
264 ASSERT_CHANGE_REFCOUNTED_ITEM
;
265 bool bConvert
= ( ( nMemberId
& CONVERT_TWIPS
) != 0 );
266 tools::Long nMaxVal
= bConvert
? convertTwipToMm100(SHRT_MAX
) : SHRT_MAX
; // members are sal_Int16
268 if(!(rVal
>>= nVal
) || (nVal
> nMaxVal
))
271 switch ( nMemberId
& ~CONVERT_TWIPS
)
273 case MID_MARGIN_L_MARGIN
:
274 nLeftMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
276 case MID_MARGIN_R_MARGIN
:
277 nRightMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
279 case MID_MARGIN_UP_MARGIN
:
280 nTopMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
282 case MID_MARGIN_LO_MARGIN
:
283 nBottomMargin
= static_cast<sal_Int16
>( bConvert
? o3tl::toTwips(nVal
, o3tl::Length::mm100
) : nVal
);
286 OSL_FAIL("unknown MemberId");
293 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft
)
295 ASSERT_CHANGE_REFCOUNTED_ITEM
;
300 void SvxMarginItem::SetTopMargin( sal_Int16 nTop
)
302 ASSERT_CHANGE_REFCOUNTED_ITEM
;
307 void SvxMarginItem::SetRightMargin( sal_Int16 nRight
)
309 ASSERT_CHANGE_REFCOUNTED_ITEM
;
310 nRightMargin
= nRight
;
314 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom
)
316 ASSERT_CHANGE_REFCOUNTED_ITEM
;
317 nBottomMargin
= nBottom
;
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */