Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / algitem.cxx
blob917edb1f6203b1af147045015905591bb3401d3b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
32 #include <climits>
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 )
48 if( bStacked )
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*/,
66 OUString& rText,
67 const IntlWrapper& ) const
69 rText = GetValueText( GetValue() );
70 return true;
74 bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
76 table::CellOrientation eUno = table::CellOrientation_STANDARD;
77 switch ( GetValue() )
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;
84 rVal <<= eUno;
85 return true;
88 bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
90 table::CellOrientation eOrient;
91 if(!(rVal >>= eOrient))
93 sal_Int32 nValue = 0;
94 if(!(rVal >>= nValue))
95 return false;
96 eOrient = static_cast<table::CellOrientation>(nValue);
98 SvxCellOrientation eSvx = SvxCellOrientation::Standard;
99 switch (eOrient)
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
107 SetValue( eSvx );
108 return true;
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;
135 switch( GetValue() )
137 case SvxCellOrientation::BottomUp: nAngle = 9000_deg100; break;
138 case SvxCellOrientation::TopBottom: nAngle = 27000_deg100; break;
139 default: ; //prevent warning
141 return nAngle;
144 SvxMarginItem::SvxMarginItem( const TypedWhichId<SvxMarginItem> nId ) :
146 SfxPoolItem( nId ),
148 nLeftMargin ( 20 ),
149 nTopMargin ( 20 ),
150 nRightMargin ( 20 ),
151 nBottomMargin( 20 )
156 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
157 sal_Int16 nTop,
158 sal_Int16 nRight,
159 sal_Int16 nBottom,
160 const TypedWhichId<SvxMarginItem> nId ) :
161 SfxPoolItem( nId ),
163 nLeftMargin ( nLeft ),
164 nTopMargin ( nTop ),
165 nRightMargin ( nRight ),
166 nBottomMargin( nBottom )
171 bool SvxMarginItem::GetPresentation
173 SfxItemPresentation ePres,
174 MapUnit eCoreUnit,
175 MapUnit ePresUnit,
176 OUString& rText, const IntlWrapper& rIntl
177 ) const
179 OUString cpDelimTmp(cpDelim);
181 switch ( ePres )
183 case SfxItemPresentation::Nameless:
185 rText = GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
186 cpDelimTmp +
187 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
188 cpDelimTmp +
189 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
190 cpDelimTmp +
191 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
192 return true;
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)) +
199 cpDelimTmp +
200 SvxResId(RID_SVXITEMS_MARGIN_TOP) +
201 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
202 " " + EditResId(GetMetricId(ePresUnit)) +
203 cpDelimTmp +
204 SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
205 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
206 " " + EditResId(GetMetricId(ePresUnit)) +
207 cpDelimTmp +
208 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
209 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
210 " " + EditResId(GetMetricId(ePresUnit));
211 return true;
213 default: ; //prevent warning
215 return false;
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;
238 switch ( nMemberId )
240 // now sign everything
241 case MID_MARGIN_L_MARGIN:
242 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
243 break;
244 case MID_MARGIN_R_MARGIN:
245 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
246 break;
247 case MID_MARGIN_UP_MARGIN:
248 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
249 break;
250 case MID_MARGIN_LO_MARGIN:
251 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
252 break;
253 default:
254 OSL_FAIL("unknown MemberId");
255 return false;
257 return true;
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
265 sal_Int32 nVal = 0;
266 if(!(rVal >>= nVal) || (nVal > nMaxVal))
267 return false;
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 );
273 break;
274 case MID_MARGIN_R_MARGIN:
275 nRightMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
276 break;
277 case MID_MARGIN_UP_MARGIN:
278 nTopMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
279 break;
280 case MID_MARGIN_LO_MARGIN:
281 nBottomMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
282 break;
283 default:
284 OSL_FAIL("unknown MemberId");
285 return false;
287 return true;
291 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
293 nLeftMargin = nLeft;
297 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
299 nTopMargin = 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: */