Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / editeng / source / items / justifyitem.cxx
blobc92220346e3373e2c458f0b149442ab840b5e298
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.hrc"
22 #include "editeng/editrids.hrc"
23 #include "editeng/eerdll.hxx"
25 #include <tools/stream.hxx>
27 #include <com/sun/star/table/CellHoriJustify.hpp>
28 #include <com/sun/star/style/ParagraphAdjust.hpp>
29 #include <com/sun/star/table/CellJustifyMethod.hpp>
30 #include <com/sun/star/table/CellVertJustify2.hpp>
31 #include <com/sun/star/style/VerticalAlignment.hpp>
34 TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0) );
35 TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
37 using namespace ::com::sun::star;
41 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
42 SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
46 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
47 const sal_uInt16 nId ) :
48 SfxEnumItem( nId, (sal_uInt16)eJustify )
53 SfxItemPresentation SvxHorJustifyItem::GetPresentation
55 SfxItemPresentation ePres,
56 SfxMapUnit /*eCoreUnit*/,
57 SfxMapUnit /*ePresUnit*/,
58 XubString& rText, const IntlWrapper *) const
60 switch ( ePres )
62 case SFX_ITEM_PRESENTATION_NONE:
63 rText.Erase();
64 return SFX_ITEM_PRESENTATION_NONE;
65 case SFX_ITEM_PRESENTATION_NAMELESS:
66 case SFX_ITEM_PRESENTATION_COMPLETE:
67 rText = GetValueText( GetValue() );
68 return SFX_ITEM_PRESENTATION_COMPLETE;
69 default: ; //prevent warning
71 return SFX_ITEM_PRESENTATION_NONE;
75 bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
77 nMemberId &= ~CONVERT_TWIPS;
78 switch ( nMemberId )
80 case MID_HORJUST_HORJUST:
82 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
83 switch ( (SvxCellHorJustify)GetValue() )
85 case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
86 case SVX_HOR_JUSTIFY_LEFT: eUno = table::CellHoriJustify_LEFT; break;
87 case SVX_HOR_JUSTIFY_CENTER: eUno = table::CellHoriJustify_CENTER; break;
88 case SVX_HOR_JUSTIFY_RIGHT: eUno = table::CellHoriJustify_RIGHT; break;
89 case SVX_HOR_JUSTIFY_BLOCK: eUno = table::CellHoriJustify_BLOCK; break;
90 case SVX_HOR_JUSTIFY_REPEAT: eUno = table::CellHoriJustify_REPEAT; break;
92 rVal <<= eUno;
94 break;
95 case MID_HORJUST_ADJUST:
97 // ParagraphAdjust values, as in SvxAdjustItem
98 // (same value for ParaAdjust and ParaLastLineAdjust)
100 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
101 switch ( (SvxCellHorJustify)GetValue() )
103 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
104 case SVX_HOR_JUSTIFY_STANDARD:
105 case SVX_HOR_JUSTIFY_REPEAT:
106 case SVX_HOR_JUSTIFY_LEFT: nAdjust = style::ParagraphAdjust_LEFT; break;
107 case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
108 case SVX_HOR_JUSTIFY_RIGHT: nAdjust = style::ParagraphAdjust_RIGHT; break;
109 case SVX_HOR_JUSTIFY_BLOCK: nAdjust = style::ParagraphAdjust_BLOCK; break;
111 rVal <<= nAdjust; // as sal_Int16
113 break;
115 return true;
118 bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
120 nMemberId &= ~CONVERT_TWIPS;
121 switch ( nMemberId )
123 case MID_HORJUST_HORJUST:
125 table::CellHoriJustify eUno;
126 if(!(rVal >>= eUno))
128 sal_Int32 nValue = 0;
129 if(!(rVal >>= nValue))
130 return false;
131 eUno = (table::CellHoriJustify)nValue;
133 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
134 switch (eUno)
136 case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
137 case table::CellHoriJustify_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
138 case table::CellHoriJustify_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
139 case table::CellHoriJustify_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
140 case table::CellHoriJustify_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
141 case table::CellHoriJustify_REPEAT: eSvx = SVX_HOR_JUSTIFY_REPEAT; break;
142 default: ; //prevent warning
144 SetValue( (sal_uInt16)eSvx );
146 break;
147 case MID_HORJUST_ADJUST:
149 // property contains ParagraphAdjust values as sal_Int16
150 sal_Int16 nVal = sal_Int16();
151 if(!(rVal >>= nVal))
152 return false;
154 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
155 switch (nVal)
157 // STRETCH is treated as BLOCK
158 case style::ParagraphAdjust_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
159 case style::ParagraphAdjust_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
160 case style::ParagraphAdjust_STRETCH:
161 case style::ParagraphAdjust_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
162 case style::ParagraphAdjust_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
164 SetValue( (sal_uInt16)eSvx );
167 return true;
171 XubString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
173 DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
174 return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
178 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
180 return new SvxHorJustifyItem( *this );
184 SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
186 sal_uInt16 nVal;
187 rStream >> nVal;
188 return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
192 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
194 return SVX_HOR_JUSTIFY_REPEAT + 1; // Last Enum value + 1
198 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
199 SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
203 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
204 const sal_uInt16 nId ) :
205 SfxEnumItem( nId, (sal_uInt16)eJustify )
210 SfxItemPresentation SvxVerJustifyItem::GetPresentation
212 SfxItemPresentation ePres,
213 SfxMapUnit /*eCoreUnit*/,
214 SfxMapUnit /*ePresUnit*/,
215 XubString& rText,
216 const IntlWrapper * ) const
218 switch ( ePres )
220 case SFX_ITEM_PRESENTATION_NONE:
221 rText.Erase();
222 return SFX_ITEM_PRESENTATION_NONE;
223 case SFX_ITEM_PRESENTATION_NAMELESS:
224 case SFX_ITEM_PRESENTATION_COMPLETE:
225 rText = GetValueText( GetValue() );
226 return SFX_ITEM_PRESENTATION_COMPLETE;
227 default: ; //prevent warning
229 return SFX_ITEM_PRESENTATION_NONE;
233 bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
235 nMemberId &= ~CONVERT_TWIPS;
236 switch ( nMemberId )
238 case MID_HORJUST_ADJUST:
240 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
241 switch ( (SvxCellVerJustify)GetValue() )
243 case SVX_VER_JUSTIFY_TOP: eUno = style::VerticalAlignment_TOP; break;
244 case SVX_VER_JUSTIFY_CENTER: eUno = style::VerticalAlignment_MIDDLE; break;
245 case SVX_VER_JUSTIFY_BOTTOM: eUno = style::VerticalAlignment_BOTTOM; break;
246 default: ; //prevent warning
248 rVal <<= eUno;
249 break;
251 default:
253 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
254 switch ( (SvxCellVerJustify)GetValue() )
256 case SVX_VER_JUSTIFY_STANDARD: nUno = table::CellVertJustify2::STANDARD; break;
257 case SVX_VER_JUSTIFY_TOP: nUno = table::CellVertJustify2::TOP; break;
258 case SVX_VER_JUSTIFY_CENTER: nUno = table::CellVertJustify2::CENTER; break;
259 case SVX_VER_JUSTIFY_BOTTOM: nUno = table::CellVertJustify2::BOTTOM; break;
260 case SVX_VER_JUSTIFY_BLOCK: nUno = table::CellVertJustify2::BLOCK; break;
261 default: ; //prevent warning
263 rVal <<= nUno;
264 break;
267 return true;
270 bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
272 nMemberId &= ~CONVERT_TWIPS;
273 switch ( nMemberId )
275 case MID_HORJUST_ADJUST:
277 // property contains ParagraphAdjust values as sal_Int16
278 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
279 if(!(rVal >>= nVal))
280 return false;
282 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
283 switch (nVal)
285 case style::VerticalAlignment_TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
286 case style::VerticalAlignment_MIDDLE: eSvx = SVX_VER_JUSTIFY_CENTER; break;
287 case style::VerticalAlignment_BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
288 default:;
290 SetValue( (sal_uInt16)eSvx );
291 break;
293 default:
295 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
296 rVal >>= eUno;
298 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
299 switch (eUno)
301 case table::CellVertJustify2::STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD; break;
302 case table::CellVertJustify2::TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
303 case table::CellVertJustify2::CENTER: eSvx = SVX_VER_JUSTIFY_CENTER; break;
304 case table::CellVertJustify2::BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
305 case table::CellVertJustify2::BLOCK: eSvx = SVX_VER_JUSTIFY_BLOCK; break;
306 default: ; //prevent warning
308 SetValue( (sal_uInt16)eSvx );
309 break;
313 return true;
317 XubString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
319 DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
320 return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
324 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
326 return new SvxVerJustifyItem( *this );
330 SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
332 sal_uInt16 nVal;
333 rStream >> nVal;
334 return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
338 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
340 return SVX_VER_JUSTIFY_BOTTOM + 1; // Last Enum value + 1
344 SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
345 const sal_uInt16 nId ) :
346 SfxEnumItem( nId, (sal_uInt16)eJustify )
351 SfxItemPresentation SvxJustifyMethodItem::GetPresentation
353 SfxItemPresentation ePres,
354 SfxMapUnit /*eCoreUnit*/,
355 SfxMapUnit /*ePresUnit*/,
356 XubString& rText,
357 const IntlWrapper * ) const
359 switch ( ePres )
361 case SFX_ITEM_PRESENTATION_NONE:
362 rText.Erase();
363 return SFX_ITEM_PRESENTATION_NONE;
364 case SFX_ITEM_PRESENTATION_NAMELESS:
365 case SFX_ITEM_PRESENTATION_COMPLETE:
366 rText = GetValueText( GetValue() );
367 return SFX_ITEM_PRESENTATION_COMPLETE;
368 default: ; //prevent warning
370 return SFX_ITEM_PRESENTATION_NONE;
374 bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
376 sal_Int32 nUno = table::CellJustifyMethod::AUTO;
377 switch (static_cast<SvxCellJustifyMethod>(GetValue()))
379 case SVX_JUSTIFY_METHOD_AUTO: nUno = table::CellJustifyMethod::AUTO; break;
380 case SVX_JUSTIFY_METHOD_DISTRIBUTE: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
381 default:;
383 rVal <<= nUno;
384 return true;
387 bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
389 sal_Int32 nVal = table::CellJustifyMethod::AUTO;
390 if (!(rVal >>= nVal))
391 return false;
393 SvxCellJustifyMethod eSvx = SVX_JUSTIFY_METHOD_AUTO;
394 switch (nVal)
396 case table::CellJustifyMethod::AUTO:
397 eSvx = SVX_JUSTIFY_METHOD_AUTO;
398 break;
399 case table::CellJustifyMethod::DISTRIBUTE:
400 eSvx = SVX_JUSTIFY_METHOD_DISTRIBUTE;
401 break;
402 default:;
404 SetValue(static_cast<sal_uInt16>(eSvx));
405 return true;
409 XubString SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal ) const
411 DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
412 return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO + nVal);
416 SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
418 return new SvxJustifyMethodItem( *this );
422 SfxPoolItem* SvxJustifyMethodItem::Create( SvStream& rStream, sal_uInt16 ) const
424 sal_uInt16 nVal;
425 rStream >> nVal;
426 return new SvxJustifyMethodItem( (SvxCellJustifyMethod)nVal, Which() );
430 sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
432 return SVX_JUSTIFY_METHOD_DISTRIBUTE + 1; // Last Enum value + 1
435 SvxJustifyMethodItem& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem& r)
437 SetValue( r.GetValue() );
438 return *this;
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */