defer finding dialog parent until we need it
[LibreOffice.git] / svx / source / items / algitem.cxx
blobe7a784b90b3c3ef603ccce9e82bd5d73d99101c2
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>
31 #include <o3tl/hash_combine.hxx>
33 #include <climits>
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 )
49 if( bStacked )
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*/,
67 OUString& rText,
68 const IntlWrapper& ) const
70 rText = GetValueText( GetValue() );
71 return true;
75 bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
77 table::CellOrientation eUno = table::CellOrientation_STANDARD;
78 switch ( GetValue() )
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;
85 rVal <<= eUno;
86 return true;
89 bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
91 table::CellOrientation eOrient;
92 if(!(rVal >>= eOrient))
94 sal_Int32 nValue = 0;
95 if(!(rVal >>= nValue))
96 return false;
97 eOrient = static_cast<table::CellOrientation>(nValue);
99 SvxCellOrientation eSvx = SvxCellOrientation::Standard;
100 switch (eOrient)
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
108 SetValue( eSvx );
109 return true;
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;
136 switch( GetValue() )
138 case SvxCellOrientation::BottomUp: nAngle = 9000_deg100; break;
139 case SvxCellOrientation::TopBottom: nAngle = 27000_deg100; break;
140 default: ; //prevent warning
142 return nAngle;
145 SvxMarginItem::SvxMarginItem( const TypedWhichId<SvxMarginItem> nId ) :
147 SfxPoolItem( nId ),
149 nLeftMargin ( 20 ),
150 nTopMargin ( 20 ),
151 nRightMargin ( 20 ),
152 nBottomMargin( 20 )
157 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
158 sal_Int16 nTop,
159 sal_Int16 nRight,
160 sal_Int16 nBottom,
161 const TypedWhichId<SvxMarginItem> nId ) :
162 SfxPoolItem( nId ),
164 nLeftMargin ( nLeft ),
165 nTopMargin ( nTop ),
166 nRightMargin ( nRight ),
167 nBottomMargin( nBottom )
172 bool SvxMarginItem::GetPresentation
174 SfxItemPresentation ePres,
175 MapUnit eCoreUnit,
176 MapUnit ePresUnit,
177 OUString& rText, const IntlWrapper& rIntl
178 ) const
180 OUString cpDelimTmp(cpDelim);
182 switch ( ePres )
184 case SfxItemPresentation::Nameless:
186 rText = GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
187 cpDelimTmp +
188 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
189 cpDelimTmp +
190 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
191 cpDelimTmp +
192 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
193 return true;
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)) +
200 cpDelimTmp +
201 SvxResId(RID_SVXITEMS_MARGIN_TOP) +
202 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
203 " " + EditResId(GetMetricId(ePresUnit)) +
204 cpDelimTmp +
205 SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
206 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
207 " " + EditResId(GetMetricId(ePresUnit)) +
208 cpDelimTmp +
209 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
210 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
211 " " + EditResId(GetMetricId(ePresUnit));
212 return true;
214 default: ; //prevent warning
216 return false;
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;
239 switch ( nMemberId )
241 // now sign everything
242 case MID_MARGIN_L_MARGIN:
243 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
244 break;
245 case MID_MARGIN_R_MARGIN:
246 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
247 break;
248 case MID_MARGIN_UP_MARGIN:
249 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
250 break;
251 case MID_MARGIN_LO_MARGIN:
252 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
253 break;
254 default:
255 OSL_FAIL("unknown MemberId");
256 return false;
258 return true;
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
267 sal_Int32 nVal = 0;
268 if(!(rVal >>= nVal) || (nVal > nMaxVal))
269 return false;
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 );
275 break;
276 case MID_MARGIN_R_MARGIN:
277 nRightMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
278 break;
279 case MID_MARGIN_UP_MARGIN:
280 nTopMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
281 break;
282 case MID_MARGIN_LO_MARGIN:
283 nBottomMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
284 break;
285 default:
286 OSL_FAIL("unknown MemberId");
287 return false;
289 return true;
293 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
295 ASSERT_CHANGE_REFCOUNTED_ITEM;
296 nLeftMargin = nLeft;
300 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
302 ASSERT_CHANGE_REFCOUNTED_ITEM;
303 nTopMargin = nTop;
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: */