nss: upgrade to release 3.73
[LibreOffice.git] / editeng / source / items / justifyitem.cxx
blob7fe699cb2c36666bebe9045c45ba30bc6d4bdb35
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 <editeng/justifyitem.hxx>
21 #include <editeng/memberids.h>
22 #include <editeng/eerdll.hxx>
24 #include <com/sun/star/table/CellHoriJustify.hpp>
25 #include <com/sun/star/style/ParagraphAdjust.hpp>
26 #include <com/sun/star/table/CellJustifyMethod.hpp>
27 #include <com/sun/star/table/CellVertJustify2.hpp>
28 #include <com/sun/star/style/VerticalAlignment.hpp>
30 #include <strings.hrc>
32 SfxPoolItem* SvxHorJustifyItem::CreateDefault() { return new SvxHorJustifyItem(SvxCellHorJustify::Standard, 0) ;}
33 SfxPoolItem* SvxVerJustifyItem::CreateDefault() { return new SvxVerJustifyItem(SvxCellVerJustify::Standard, 0) ;}
35 using namespace ::com::sun::star;
38 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
39 SfxEnumItem( nId, SvxCellHorJustify::Standard )
43 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
44 const sal_uInt16 nId ) :
45 SfxEnumItem( nId, eJustify )
50 bool SvxHorJustifyItem::GetPresentation
52 SfxItemPresentation /*ePres*/,
53 MapUnit /*eCoreUnit*/,
54 MapUnit /*ePresUnit*/,
55 OUString& rText, const IntlWrapper&) const
57 rText = GetValueText(GetValue());
58 return true;
62 bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
64 nMemberId &= ~CONVERT_TWIPS;
65 switch ( nMemberId )
67 case MID_HORJUST_HORJUST:
69 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
70 switch ( GetValue() )
72 case SvxCellHorJustify::Standard: eUno = table::CellHoriJustify_STANDARD; break;
73 case SvxCellHorJustify::Left: eUno = table::CellHoriJustify_LEFT; break;
74 case SvxCellHorJustify::Center: eUno = table::CellHoriJustify_CENTER; break;
75 case SvxCellHorJustify::Right: eUno = table::CellHoriJustify_RIGHT; break;
76 case SvxCellHorJustify::Block: eUno = table::CellHoriJustify_BLOCK; break;
77 case SvxCellHorJustify::Repeat: eUno = table::CellHoriJustify_REPEAT; break;
79 rVal <<= eUno;
81 break;
82 case MID_HORJUST_ADJUST:
84 // ParagraphAdjust values, as in SvxAdjustItem
85 // (same value for ParaAdjust and ParaLastLineAdjust)
87 style::ParagraphAdjust nAdjust = style::ParagraphAdjust_LEFT;
88 switch ( GetValue() )
90 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
91 case SvxCellHorJustify::Standard:
92 case SvxCellHorJustify::Repeat:
93 case SvxCellHorJustify::Left: nAdjust = style::ParagraphAdjust_LEFT; break;
94 case SvxCellHorJustify::Center: nAdjust = style::ParagraphAdjust_CENTER; break;
95 case SvxCellHorJustify::Right: nAdjust = style::ParagraphAdjust_RIGHT; break;
96 case SvxCellHorJustify::Block: nAdjust = style::ParagraphAdjust_BLOCK; break;
98 rVal <<= static_cast<sal_Int16>(nAdjust); // as sal_Int16
100 break;
102 return true;
105 bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
107 nMemberId &= ~CONVERT_TWIPS;
108 switch ( nMemberId )
110 case MID_HORJUST_HORJUST:
112 table::CellHoriJustify eUno;
113 if(!(rVal >>= eUno))
115 sal_Int32 nValue = 0;
116 if(!(rVal >>= nValue))
117 return false;
118 eUno = static_cast<table::CellHoriJustify>(nValue);
120 SvxCellHorJustify eSvx = SvxCellHorJustify::Standard;
121 switch (eUno)
123 case table::CellHoriJustify_STANDARD: eSvx = SvxCellHorJustify::Standard; break;
124 case table::CellHoriJustify_LEFT: eSvx = SvxCellHorJustify::Left; break;
125 case table::CellHoriJustify_CENTER: eSvx = SvxCellHorJustify::Center; break;
126 case table::CellHoriJustify_RIGHT: eSvx = SvxCellHorJustify::Right; break;
127 case table::CellHoriJustify_BLOCK: eSvx = SvxCellHorJustify::Block; break;
128 case table::CellHoriJustify_REPEAT: eSvx = SvxCellHorJustify::Repeat; break;
129 default: ; //prevent warning
131 SetValue( eSvx );
133 break;
134 case MID_HORJUST_ADJUST:
136 // property contains ParagraphAdjust values as sal_Int16
137 sal_Int16 nVal = sal_Int16();
138 if(!(rVal >>= nVal))
139 return false;
141 SvxCellHorJustify eSvx = SvxCellHorJustify::Standard;
142 switch (static_cast<style::ParagraphAdjust>(nVal))
144 // STRETCH is treated as BLOCK
145 case style::ParagraphAdjust_LEFT: eSvx = SvxCellHorJustify::Left; break;
146 case style::ParagraphAdjust_RIGHT: eSvx = SvxCellHorJustify::Right; break;
147 case style::ParagraphAdjust_STRETCH:
148 case style::ParagraphAdjust_BLOCK: eSvx = SvxCellHorJustify::Block; break;
149 case style::ParagraphAdjust_CENTER: eSvx = SvxCellHorJustify::Center; break;
150 default: break;
152 SetValue( eSvx );
155 return true;
158 OUString SvxHorJustifyItem::GetValueText(SvxCellHorJustify nVal)
160 assert(nVal <= SvxCellHorJustify::Repeat && "enum overflow!");
161 return EditResId(RID_SVXITEMS_HORJUST[static_cast<size_t>(nVal)]);
164 SvxHorJustifyItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
166 return new SvxHorJustifyItem( *this );
169 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
171 return sal_uInt16(SvxCellHorJustify::Repeat) + 1; // Last Enum value + 1
175 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
176 SfxEnumItem( nId, SvxCellVerJustify::Standard )
180 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
181 const sal_uInt16 nId ) :
182 SfxEnumItem( nId, eJustify )
187 bool SvxVerJustifyItem::GetPresentation
189 SfxItemPresentation /*ePres*/,
190 MapUnit /*eCoreUnit*/,
191 MapUnit /*ePresUnit*/,
192 OUString& rText,
193 const IntlWrapper& ) const
195 rText = GetValueText( GetValue() );
196 return true;
200 bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
202 nMemberId &= ~CONVERT_TWIPS;
203 switch ( nMemberId )
205 case MID_HORJUST_ADJUST:
207 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
208 switch ( GetValue() )
210 case SvxCellVerJustify::Top: eUno = style::VerticalAlignment_TOP; break;
211 case SvxCellVerJustify::Center: eUno = style::VerticalAlignment_MIDDLE; break;
212 case SvxCellVerJustify::Bottom: eUno = style::VerticalAlignment_BOTTOM; break;
213 default: ; //prevent warning
215 rVal <<= eUno;
216 break;
218 default:
220 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
221 switch ( GetValue() )
223 case SvxCellVerJustify::Standard: nUno = table::CellVertJustify2::STANDARD; break;
224 case SvxCellVerJustify::Top: nUno = table::CellVertJustify2::TOP; break;
225 case SvxCellVerJustify::Center: nUno = table::CellVertJustify2::CENTER; break;
226 case SvxCellVerJustify::Bottom: nUno = table::CellVertJustify2::BOTTOM; break;
227 case SvxCellVerJustify::Block: nUno = table::CellVertJustify2::BLOCK; break;
228 default: ; //prevent warning
230 rVal <<= nUno;
231 break;
234 return true;
237 bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
239 nMemberId &= ~CONVERT_TWIPS;
240 switch ( nMemberId )
242 case MID_HORJUST_ADJUST:
244 // property contains ParagraphAdjust values as sal_Int16
245 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
246 if(!(rVal >>= nVal))
247 return false;
249 SvxCellVerJustify eSvx = SvxCellVerJustify::Standard;
250 switch (nVal)
252 case style::VerticalAlignment_TOP: eSvx = SvxCellVerJustify::Top; break;
253 case style::VerticalAlignment_MIDDLE: eSvx = SvxCellVerJustify::Center; break;
254 case style::VerticalAlignment_BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
255 default:;
257 SetValue( eSvx );
258 break;
260 default:
262 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
263 rVal >>= eUno;
265 SvxCellVerJustify eSvx = SvxCellVerJustify::Standard;
266 switch (eUno)
268 case table::CellVertJustify2::STANDARD: eSvx = SvxCellVerJustify::Standard; break;
269 case table::CellVertJustify2::TOP: eSvx = SvxCellVerJustify::Top; break;
270 case table::CellVertJustify2::CENTER: eSvx = SvxCellVerJustify::Center; break;
271 case table::CellVertJustify2::BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
272 case table::CellVertJustify2::BLOCK: eSvx = SvxCellVerJustify::Block; break;
273 default: ; //prevent warning
275 SetValue( eSvx );
276 break;
280 return true;
283 OUString SvxVerJustifyItem::GetValueText( SvxCellVerJustify nVal )
285 assert(nVal <= SvxCellVerJustify::Block && "enum overflow!");
286 return EditResId(RID_SVXITEMS_VERJUST[static_cast<size_t>(nVal)]);
289 SvxVerJustifyItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
291 return new SvxVerJustifyItem( *this );
294 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
296 return static_cast<sal_uInt16>(SvxCellVerJustify::Bottom) + 1; // Last Enum value + 1
299 SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
300 const sal_uInt16 nId ) :
301 SfxEnumItem( nId, eJustify )
305 bool SvxJustifyMethodItem::GetPresentation
307 SfxItemPresentation /*ePres*/,
308 MapUnit /*eCoreUnit*/,
309 MapUnit /*ePresUnit*/,
310 OUString& rText,
311 const IntlWrapper& ) const
313 rText = GetValueText( GetValue() );
314 return true;
318 bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
320 sal_Int32 nUno = table::CellJustifyMethod::AUTO;
321 switch (GetValue())
323 case SvxCellJustifyMethod::Auto: nUno = table::CellJustifyMethod::AUTO; break;
324 case SvxCellJustifyMethod::Distribute: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
325 default:;
327 rVal <<= nUno;
328 return true;
331 bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
333 sal_Int32 nVal = table::CellJustifyMethod::AUTO;
334 if (!(rVal >>= nVal))
335 return false;
337 SvxCellJustifyMethod eSvx = SvxCellJustifyMethod::Auto;
338 switch (nVal)
340 case table::CellJustifyMethod::AUTO:
341 eSvx = SvxCellJustifyMethod::Auto;
342 break;
343 case table::CellJustifyMethod::DISTRIBUTE:
344 eSvx = SvxCellJustifyMethod::Distribute;
345 break;
346 default:;
348 SetValue(eSvx);
349 return true;
352 OUString SvxJustifyMethodItem::GetValueText( SvxCellJustifyMethod nVal )
354 assert(nVal <= SvxCellJustifyMethod::Distribute && "enum overflow!");
355 return EditResId(RID_SVXITEMS_JUSTMETHOD[static_cast<size_t>(nVal)]);
358 SvxJustifyMethodItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
360 return new SvxJustifyMethodItem( *this );
363 sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
365 return static_cast<sal_uInt16>(SvxCellJustifyMethod::Distribute) + 1; // Last Enum value + 1
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */