Bump for 3.6-28
[LibreOffice.git] / editeng / source / items / justifyitem.cxx
blob0d3024df4d2486dfe0902ca5f9c8f2a6b38b860b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
32 #include "editeng/justifyitem.hxx"
33 #include "editeng/memberids.hrc"
34 #include "editeng/editrids.hrc"
35 #include "editeng/eerdll.hxx"
37 #include <tools/stream.hxx>
39 #include <com/sun/star/table/CellHoriJustify.hpp>
40 #include <com/sun/star/style/ParagraphAdjust.hpp>
41 #include <com/sun/star/table/CellJustifyMethod.hpp>
42 #include <com/sun/star/table/CellVertJustify2.hpp>
43 #include <com/sun/star/style/VerticalAlignment.hpp>
46 TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0) );
47 TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
49 using namespace ::com::sun::star;
53 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
54 SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
58 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
59 const sal_uInt16 nId ) :
60 SfxEnumItem( nId, (sal_uInt16)eJustify )
65 SfxItemPresentation SvxHorJustifyItem::GetPresentation
67 SfxItemPresentation ePres,
68 SfxMapUnit /*eCoreUnit*/,
69 SfxMapUnit /*ePresUnit*/,
70 XubString& rText, const IntlWrapper *) const
72 switch ( ePres )
74 case SFX_ITEM_PRESENTATION_NONE:
75 rText.Erase();
76 return SFX_ITEM_PRESENTATION_NONE;
77 case SFX_ITEM_PRESENTATION_NAMELESS:
78 case SFX_ITEM_PRESENTATION_COMPLETE:
79 rText = GetValueText( GetValue() );
80 return SFX_ITEM_PRESENTATION_COMPLETE;
81 default: ; //prevent warning
83 return SFX_ITEM_PRESENTATION_NONE;
87 bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
89 nMemberId &= ~CONVERT_TWIPS;
90 switch ( nMemberId )
92 case MID_HORJUST_HORJUST:
94 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
95 switch ( (SvxCellHorJustify)GetValue() )
97 case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
98 case SVX_HOR_JUSTIFY_LEFT: eUno = table::CellHoriJustify_LEFT; break;
99 case SVX_HOR_JUSTIFY_CENTER: eUno = table::CellHoriJustify_CENTER; break;
100 case SVX_HOR_JUSTIFY_RIGHT: eUno = table::CellHoriJustify_RIGHT; break;
101 case SVX_HOR_JUSTIFY_BLOCK: eUno = table::CellHoriJustify_BLOCK; break;
102 case SVX_HOR_JUSTIFY_REPEAT: eUno = table::CellHoriJustify_REPEAT; break;
104 rVal <<= eUno;
106 break;
107 case MID_HORJUST_ADJUST:
109 // ParagraphAdjust values, as in SvxAdjustItem
110 // (same value for ParaAdjust and ParaLastLineAdjust)
112 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
113 switch ( (SvxCellHorJustify)GetValue() )
115 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
116 case SVX_HOR_JUSTIFY_STANDARD:
117 case SVX_HOR_JUSTIFY_REPEAT:
118 case SVX_HOR_JUSTIFY_LEFT: nAdjust = style::ParagraphAdjust_LEFT; break;
119 case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
120 case SVX_HOR_JUSTIFY_RIGHT: nAdjust = style::ParagraphAdjust_RIGHT; break;
121 case SVX_HOR_JUSTIFY_BLOCK: nAdjust = style::ParagraphAdjust_BLOCK; break;
123 rVal <<= nAdjust; // as sal_Int16
125 break;
127 return true;
130 bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
132 nMemberId &= ~CONVERT_TWIPS;
133 switch ( nMemberId )
135 case MID_HORJUST_HORJUST:
137 table::CellHoriJustify eUno;
138 if(!(rVal >>= eUno))
140 sal_Int32 nValue = 0;
141 if(!(rVal >>= nValue))
142 return false;
143 eUno = (table::CellHoriJustify)nValue;
145 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
146 switch (eUno)
148 case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
149 case table::CellHoriJustify_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
150 case table::CellHoriJustify_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
151 case table::CellHoriJustify_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
152 case table::CellHoriJustify_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
153 case table::CellHoriJustify_REPEAT: eSvx = SVX_HOR_JUSTIFY_REPEAT; break;
154 default: ; //prevent warning
156 SetValue( (sal_uInt16)eSvx );
158 break;
159 case MID_HORJUST_ADJUST:
161 // property contains ParagraphAdjust values as sal_Int16
162 sal_Int16 nVal = sal_Int16();
163 if(!(rVal >>= nVal))
164 return false;
166 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
167 switch (nVal)
169 // STRETCH is treated as BLOCK
170 case style::ParagraphAdjust_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
171 case style::ParagraphAdjust_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
172 case style::ParagraphAdjust_STRETCH:
173 case style::ParagraphAdjust_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
174 case style::ParagraphAdjust_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
176 SetValue( (sal_uInt16)eSvx );
179 return true;
183 XubString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
185 DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
186 return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
190 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
192 return new SvxHorJustifyItem( *this );
196 SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
198 sal_uInt16 nVal;
199 rStream >> nVal;
200 return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
204 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
206 return SVX_HOR_JUSTIFY_REPEAT + 1; // Last Enum value + 1
210 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
211 SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
215 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
216 const sal_uInt16 nId ) :
217 SfxEnumItem( nId, (sal_uInt16)eJustify )
222 SfxItemPresentation SvxVerJustifyItem::GetPresentation
224 SfxItemPresentation ePres,
225 SfxMapUnit /*eCoreUnit*/,
226 SfxMapUnit /*ePresUnit*/,
227 XubString& rText,
228 const IntlWrapper * ) const
230 switch ( ePres )
232 case SFX_ITEM_PRESENTATION_NONE:
233 rText.Erase();
234 return SFX_ITEM_PRESENTATION_NONE;
235 case SFX_ITEM_PRESENTATION_NAMELESS:
236 case SFX_ITEM_PRESENTATION_COMPLETE:
237 rText = GetValueText( GetValue() );
238 return SFX_ITEM_PRESENTATION_COMPLETE;
239 default: ; //prevent warning
241 return SFX_ITEM_PRESENTATION_NONE;
245 bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
247 nMemberId &= ~CONVERT_TWIPS;
248 switch ( nMemberId )
250 case MID_HORJUST_ADJUST:
252 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
253 switch ( (SvxCellVerJustify)GetValue() )
255 case SVX_VER_JUSTIFY_TOP: eUno = style::VerticalAlignment_TOP; break;
256 case SVX_VER_JUSTIFY_CENTER: eUno = style::VerticalAlignment_MIDDLE; break;
257 case SVX_VER_JUSTIFY_BOTTOM: eUno = style::VerticalAlignment_BOTTOM; break;
258 default: ; //prevent warning
260 rVal <<= eUno;
261 break;
263 default:
265 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
266 switch ( (SvxCellVerJustify)GetValue() )
268 case SVX_VER_JUSTIFY_STANDARD: nUno = table::CellVertJustify2::STANDARD; break;
269 case SVX_VER_JUSTIFY_TOP: nUno = table::CellVertJustify2::TOP; break;
270 case SVX_VER_JUSTIFY_CENTER: nUno = table::CellVertJustify2::CENTER; break;
271 case SVX_VER_JUSTIFY_BOTTOM: nUno = table::CellVertJustify2::BOTTOM; break;
272 case SVX_VER_JUSTIFY_BLOCK: nUno = table::CellVertJustify2::BLOCK; break;
273 default: ; //prevent warning
275 rVal <<= nUno;
276 break;
279 return true;
282 bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
284 nMemberId &= ~CONVERT_TWIPS;
285 switch ( nMemberId )
287 case MID_HORJUST_ADJUST:
289 // property contains ParagraphAdjust values as sal_Int16
290 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
291 if(!(rVal >>= nVal))
292 return false;
294 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
295 switch (nVal)
297 case style::VerticalAlignment_TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
298 case style::VerticalAlignment_MIDDLE: eSvx = SVX_VER_JUSTIFY_CENTER; break;
299 case style::VerticalAlignment_BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
300 default:;
302 SetValue( (sal_uInt16)eSvx );
303 break;
305 default:
307 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
308 rVal >>= eUno;
310 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
311 switch (eUno)
313 case table::CellVertJustify2::STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD; break;
314 case table::CellVertJustify2::TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
315 case table::CellVertJustify2::CENTER: eSvx = SVX_VER_JUSTIFY_CENTER; break;
316 case table::CellVertJustify2::BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
317 case table::CellVertJustify2::BLOCK: eSvx = SVX_VER_JUSTIFY_BLOCK; break;
318 default: ; //prevent warning
320 SetValue( (sal_uInt16)eSvx );
321 break;
325 return true;
329 XubString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
331 DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
332 return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
336 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
338 return new SvxVerJustifyItem( *this );
342 SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
344 sal_uInt16 nVal;
345 rStream >> nVal;
346 return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
350 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
352 return SVX_VER_JUSTIFY_BOTTOM + 1; // Last Enum value + 1
356 SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
357 const sal_uInt16 nId ) :
358 SfxEnumItem( nId, (sal_uInt16)eJustify )
363 SfxItemPresentation SvxJustifyMethodItem::GetPresentation
365 SfxItemPresentation ePres,
366 SfxMapUnit /*eCoreUnit*/,
367 SfxMapUnit /*ePresUnit*/,
368 XubString& rText,
369 const IntlWrapper * ) const
371 switch ( ePres )
373 case SFX_ITEM_PRESENTATION_NONE:
374 rText.Erase();
375 return SFX_ITEM_PRESENTATION_NONE;
376 case SFX_ITEM_PRESENTATION_NAMELESS:
377 case SFX_ITEM_PRESENTATION_COMPLETE:
378 rText = GetValueText( GetValue() );
379 return SFX_ITEM_PRESENTATION_COMPLETE;
380 default: ; //prevent warning
382 return SFX_ITEM_PRESENTATION_NONE;
386 bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
388 sal_Int32 nUno = table::CellJustifyMethod::AUTO;
389 switch (static_cast<SvxCellJustifyMethod>(GetValue()))
391 case SVX_JUSTIFY_METHOD_AUTO: nUno = table::CellJustifyMethod::AUTO; break;
392 case SVX_JUSTIFY_METHOD_DISTRIBUTE: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
393 default:;
395 rVal <<= nUno;
396 return true;
399 bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
401 sal_Int32 nVal = table::CellJustifyMethod::AUTO;
402 if (!(rVal >>= nVal))
403 return false;
405 SvxCellJustifyMethod eSvx = SVX_JUSTIFY_METHOD_AUTO;
406 switch (nVal)
408 case table::CellJustifyMethod::AUTO:
409 eSvx = SVX_JUSTIFY_METHOD_AUTO;
410 break;
411 case table::CellJustifyMethod::DISTRIBUTE:
412 eSvx = SVX_JUSTIFY_METHOD_DISTRIBUTE;
413 break;
414 default:;
416 SetValue(static_cast<sal_uInt16>(eSvx));
417 return true;
421 XubString SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal ) const
423 DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
424 return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO + nVal);
428 SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
430 return new SvxJustifyMethodItem( *this );
434 SfxPoolItem* SvxJustifyMethodItem::Create( SvStream& rStream, sal_uInt16 ) const
436 sal_uInt16 nVal;
437 rStream >> nVal;
438 return new SvxJustifyMethodItem( (SvxCellJustifyMethod)nVal, Which() );
442 sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
444 return SVX_JUSTIFY_METHOD_DISTRIBUTE + 1; // Last Enum value + 1
447 SvxJustifyMethodItem& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem& r)
449 SetValue( r.GetValue() );
450 return *this;
453 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */