bump product version to 6.4.0.3
[LibreOffice.git] / editeng / source / items / justifyitem.cxx
blob976226e976711042318e4c61e94a945cf65c011e
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/editrids.hrc>
23 #include <editeng/eerdll.hxx>
25 #include <tools/stream.hxx>
26 #include <tools/debug.hxx>
28 #include <com/sun/star/table/CellHoriJustify.hpp>
29 #include <com/sun/star/style/ParagraphAdjust.hpp>
30 #include <com/sun/star/table/CellJustifyMethod.hpp>
31 #include <com/sun/star/table/CellVertJustify2.hpp>
32 #include <com/sun/star/style/VerticalAlignment.hpp>
35 SfxPoolItem* SvxHorJustifyItem::CreateDefault() { return new SvxHorJustifyItem(SvxCellHorJustify::Standard, 0) ;}
36 SfxPoolItem* SvxVerJustifyItem::CreateDefault() { return new SvxVerJustifyItem(SvxCellVerJustify::Standard, 0) ;}
38 using namespace ::com::sun::star;
41 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
42 SfxEnumItem( nId, SvxCellHorJustify::Standard )
46 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
47 const sal_uInt16 nId ) :
48 SfxEnumItem( nId, eJustify )
53 bool SvxHorJustifyItem::GetPresentation
55 SfxItemPresentation /*ePres*/,
56 MapUnit /*eCoreUnit*/,
57 MapUnit /*ePresUnit*/,
58 OUString& rText, const IntlWrapper&) const
60 rText = GetValueText( GetValue() );
61 return true;
65 bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
67 nMemberId &= ~CONVERT_TWIPS;
68 switch ( nMemberId )
70 case MID_HORJUST_HORJUST:
72 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
73 switch ( GetValue() )
75 case SvxCellHorJustify::Standard: eUno = table::CellHoriJustify_STANDARD; break;
76 case SvxCellHorJustify::Left: eUno = table::CellHoriJustify_LEFT; break;
77 case SvxCellHorJustify::Center: eUno = table::CellHoriJustify_CENTER; break;
78 case SvxCellHorJustify::Right: eUno = table::CellHoriJustify_RIGHT; break;
79 case SvxCellHorJustify::Block: eUno = table::CellHoriJustify_BLOCK; break;
80 case SvxCellHorJustify::Repeat: eUno = table::CellHoriJustify_REPEAT; break;
82 rVal <<= eUno;
84 break;
85 case MID_HORJUST_ADJUST:
87 // ParagraphAdjust values, as in SvxAdjustItem
88 // (same value for ParaAdjust and ParaLastLineAdjust)
90 style::ParagraphAdjust nAdjust = style::ParagraphAdjust_LEFT;
91 switch ( GetValue() )
93 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
94 case SvxCellHorJustify::Standard:
95 case SvxCellHorJustify::Repeat:
96 case SvxCellHorJustify::Left: nAdjust = style::ParagraphAdjust_LEFT; break;
97 case SvxCellHorJustify::Center: nAdjust = style::ParagraphAdjust_CENTER; break;
98 case SvxCellHorJustify::Right: nAdjust = style::ParagraphAdjust_RIGHT; break;
99 case SvxCellHorJustify::Block: nAdjust = style::ParagraphAdjust_BLOCK; break;
101 rVal <<= static_cast<sal_Int16>(nAdjust); // as sal_Int16
103 break;
105 return true;
108 bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
110 nMemberId &= ~CONVERT_TWIPS;
111 switch ( nMemberId )
113 case MID_HORJUST_HORJUST:
115 table::CellHoriJustify eUno;
116 if(!(rVal >>= eUno))
118 sal_Int32 nValue = 0;
119 if(!(rVal >>= nValue))
120 return false;
121 eUno = static_cast<table::CellHoriJustify>(nValue);
123 SvxCellHorJustify eSvx = SvxCellHorJustify::Standard;
124 switch (eUno)
126 case table::CellHoriJustify_STANDARD: eSvx = SvxCellHorJustify::Standard; break;
127 case table::CellHoriJustify_LEFT: eSvx = SvxCellHorJustify::Left; break;
128 case table::CellHoriJustify_CENTER: eSvx = SvxCellHorJustify::Center; break;
129 case table::CellHoriJustify_RIGHT: eSvx = SvxCellHorJustify::Right; break;
130 case table::CellHoriJustify_BLOCK: eSvx = SvxCellHorJustify::Block; break;
131 case table::CellHoriJustify_REPEAT: eSvx = SvxCellHorJustify::Repeat; break;
132 default: ; //prevent warning
134 SetValue( eSvx );
136 break;
137 case MID_HORJUST_ADJUST:
139 // property contains ParagraphAdjust values as sal_Int16
140 sal_Int16 nVal = sal_Int16();
141 if(!(rVal >>= nVal))
142 return false;
144 SvxCellHorJustify eSvx = SvxCellHorJustify::Standard;
145 switch (static_cast<style::ParagraphAdjust>(nVal))
147 // STRETCH is treated as BLOCK
148 case style::ParagraphAdjust_LEFT: eSvx = SvxCellHorJustify::Left; break;
149 case style::ParagraphAdjust_RIGHT: eSvx = SvxCellHorJustify::Right; break;
150 case style::ParagraphAdjust_STRETCH:
151 case style::ParagraphAdjust_BLOCK: eSvx = SvxCellHorJustify::Block; break;
152 case style::ParagraphAdjust_CENTER: eSvx = SvxCellHorJustify::Center; break;
153 default: break;
155 SetValue( eSvx );
158 return true;
162 OUString SvxHorJustifyItem::GetValueText( SvxCellHorJustify nVal )
164 DBG_ASSERT( nVal <= SvxCellHorJustify::Repeat, "enum overflow!" );
166 OUString sRet;
167 switch (nVal)
169 case SvxCellHorJustify::Standard:
170 sRet = EditResId(RID_SVXITEMS_HORJUST_STANDARD);
171 break;
172 case SvxCellHorJustify::Left:
173 sRet = EditResId(RID_SVXITEMS_HORJUST_LEFT);
174 break;
175 case SvxCellHorJustify::Center:
176 sRet = EditResId(RID_SVXITEMS_HORJUST_CENTER);
177 break;
178 case SvxCellHorJustify::Right:
179 sRet = EditResId(RID_SVXITEMS_HORJUST_RIGHT);
180 break;
181 case SvxCellHorJustify::Block:
182 sRet = EditResId(RID_SVXITEMS_HORJUST_BLOCK);
183 break;
184 case SvxCellHorJustify::Repeat:
185 sRet = EditResId(RID_SVXITEMS_HORJUST_REPEAT);
186 break;
188 return sRet;
192 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
194 return new SvxHorJustifyItem( *this );
197 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
199 return sal_uInt16(SvxCellHorJustify::Repeat) + 1; // Last Enum value + 1
203 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
204 SfxEnumItem( nId, SvxCellVerJustify::Standard )
208 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
209 const sal_uInt16 nId ) :
210 SfxEnumItem( nId, eJustify )
215 bool SvxVerJustifyItem::GetPresentation
217 SfxItemPresentation /*ePres*/,
218 MapUnit /*eCoreUnit*/,
219 MapUnit /*ePresUnit*/,
220 OUString& rText,
221 const IntlWrapper& ) const
223 rText = GetValueText( GetValue() );
224 return true;
228 bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
230 nMemberId &= ~CONVERT_TWIPS;
231 switch ( nMemberId )
233 case MID_HORJUST_ADJUST:
235 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
236 switch ( GetValue() )
238 case SvxCellVerJustify::Top: eUno = style::VerticalAlignment_TOP; break;
239 case SvxCellVerJustify::Center: eUno = style::VerticalAlignment_MIDDLE; break;
240 case SvxCellVerJustify::Bottom: eUno = style::VerticalAlignment_BOTTOM; break;
241 default: ; //prevent warning
243 rVal <<= eUno;
244 break;
246 default:
248 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
249 switch ( GetValue() )
251 case SvxCellVerJustify::Standard: nUno = table::CellVertJustify2::STANDARD; break;
252 case SvxCellVerJustify::Top: nUno = table::CellVertJustify2::TOP; break;
253 case SvxCellVerJustify::Center: nUno = table::CellVertJustify2::CENTER; break;
254 case SvxCellVerJustify::Bottom: nUno = table::CellVertJustify2::BOTTOM; break;
255 case SvxCellVerJustify::Block: nUno = table::CellVertJustify2::BLOCK; break;
256 default: ; //prevent warning
258 rVal <<= nUno;
259 break;
262 return true;
265 bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
267 nMemberId &= ~CONVERT_TWIPS;
268 switch ( nMemberId )
270 case MID_HORJUST_ADJUST:
272 // property contains ParagraphAdjust values as sal_Int16
273 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
274 if(!(rVal >>= nVal))
275 return false;
277 SvxCellVerJustify eSvx = SvxCellVerJustify::Standard;
278 switch (nVal)
280 case style::VerticalAlignment_TOP: eSvx = SvxCellVerJustify::Top; break;
281 case style::VerticalAlignment_MIDDLE: eSvx = SvxCellVerJustify::Center; break;
282 case style::VerticalAlignment_BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
283 default:;
285 SetValue( eSvx );
286 break;
288 default:
290 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
291 rVal >>= eUno;
293 SvxCellVerJustify eSvx = SvxCellVerJustify::Standard;
294 switch (eUno)
296 case table::CellVertJustify2::STANDARD: eSvx = SvxCellVerJustify::Standard; break;
297 case table::CellVertJustify2::TOP: eSvx = SvxCellVerJustify::Top; break;
298 case table::CellVertJustify2::CENTER: eSvx = SvxCellVerJustify::Center; break;
299 case table::CellVertJustify2::BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
300 case table::CellVertJustify2::BLOCK: eSvx = SvxCellVerJustify::Block; break;
301 default: ; //prevent warning
303 SetValue( eSvx );
304 break;
308 return true;
312 OUString SvxVerJustifyItem::GetValueText( SvxCellVerJustify nVal )
314 DBG_ASSERT( nVal <= SvxCellVerJustify::Bottom, "enum overflow!" );
316 OUString sRet;
317 switch (nVal)
319 case SvxCellVerJustify::Standard:
320 sRet = EditResId(RID_SVXITEMS_VERJUST_STANDARD);
321 break;
322 case SvxCellVerJustify::Top:
323 sRet = EditResId(RID_SVXITEMS_VERJUST_TOP);
324 break;
325 case SvxCellVerJustify::Center:
326 sRet = EditResId(RID_SVXITEMS_VERJUST_CENTER);
327 break;
328 case SvxCellVerJustify::Bottom:
329 sRet = EditResId(RID_SVXITEMS_VERJUST_BOTTOM);
330 break;
331 default:
332 break;
334 return sRet;
338 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
340 return new SvxVerJustifyItem( *this );
344 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
346 return static_cast<sal_uInt16>(SvxCellVerJustify::Bottom) + 1; // Last Enum value + 1
350 SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
351 const sal_uInt16 nId ) :
352 SfxEnumItem( nId, eJustify )
357 bool SvxJustifyMethodItem::GetPresentation
359 SfxItemPresentation /*ePres*/,
360 MapUnit /*eCoreUnit*/,
361 MapUnit /*ePresUnit*/,
362 OUString& rText,
363 const IntlWrapper& ) const
365 rText = GetValueText( GetValue() );
366 return true;
370 bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
372 sal_Int32 nUno = table::CellJustifyMethod::AUTO;
373 switch (GetValue())
375 case SvxCellJustifyMethod::Auto: nUno = table::CellJustifyMethod::AUTO; break;
376 case SvxCellJustifyMethod::Distribute: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
377 default:;
379 rVal <<= nUno;
380 return true;
383 bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
385 sal_Int32 nVal = table::CellJustifyMethod::AUTO;
386 if (!(rVal >>= nVal))
387 return false;
389 SvxCellJustifyMethod eSvx = SvxCellJustifyMethod::Auto;
390 switch (nVal)
392 case table::CellJustifyMethod::AUTO:
393 eSvx = SvxCellJustifyMethod::Auto;
394 break;
395 case table::CellJustifyMethod::DISTRIBUTE:
396 eSvx = SvxCellJustifyMethod::Distribute;
397 break;
398 default:;
400 SetValue(eSvx);
401 return true;
405 OUString SvxJustifyMethodItem::GetValueText( SvxCellJustifyMethod nVal )
407 OUString sRet;
408 switch (nVal)
410 case SvxCellJustifyMethod::Auto:
411 sRet = EditResId(RID_SVXITEMS_JUSTMETHOD_AUTO);
412 break;
413 case SvxCellJustifyMethod::Distribute:
414 sRet = EditResId(RID_SVXITEMS_JUSTMETHOD_DISTRIBUTE);
415 break;
417 return sRet;
421 SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
423 return new SvxJustifyMethodItem( *this );
427 sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
429 return static_cast<sal_uInt16>(SvxCellJustifyMethod::Distribute) + 1; // Last Enum value + 1
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */