1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
62 case SFX_ITEM_PRESENTATION_NONE
:
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
;
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;
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
118 bool SvxHorJustifyItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
120 nMemberId
&= ~CONVERT_TWIPS
;
123 case MID_HORJUST_HORJUST
:
125 table::CellHoriJustify eUno
;
128 sal_Int32 nValue
= 0;
129 if(!(rVal
>>= nValue
))
131 eUno
= (table::CellHoriJustify
)nValue
;
133 SvxCellHorJustify eSvx
= SVX_HOR_JUSTIFY_STANDARD
;
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
);
147 case MID_HORJUST_ADJUST
:
149 // property contains ParagraphAdjust values as sal_Int16
150 sal_Int16 nVal
= sal_Int16();
154 SvxCellHorJustify eSvx
= SVX_HOR_JUSTIFY_STANDARD
;
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
);
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
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*/,
216 const IntlWrapper
* ) const
220 case SFX_ITEM_PRESENTATION_NONE
:
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
;
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
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
270 bool SvxVerJustifyItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
272 nMemberId
&= ~CONVERT_TWIPS
;
275 case MID_HORJUST_ADJUST
:
277 // property contains ParagraphAdjust values as sal_Int16
278 style::VerticalAlignment nVal
= style::VerticalAlignment_TOP
;
282 SvxCellVerJustify eSvx
= SVX_VER_JUSTIFY_STANDARD
;
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;
290 SetValue( (sal_uInt16
)eSvx
);
295 sal_Int32 eUno
= table::CellVertJustify2::STANDARD
;
298 SvxCellVerJustify eSvx
= SVX_VER_JUSTIFY_STANDARD
;
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
);
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
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*/,
357 const IntlWrapper
* ) const
361 case SFX_ITEM_PRESENTATION_NONE
:
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;
387 bool SvxJustifyMethodItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
389 sal_Int32 nVal
= table::CellJustifyMethod::AUTO
;
390 if (!(rVal
>>= nVal
))
393 SvxCellJustifyMethod eSvx
= SVX_JUSTIFY_METHOD_AUTO
;
396 case table::CellJustifyMethod::AUTO
:
397 eSvx
= SVX_JUSTIFY_METHOD_AUTO
;
399 case table::CellJustifyMethod::DISTRIBUTE
:
400 eSvx
= SVX_JUSTIFY_METHOD_DISTRIBUTE
;
404 SetValue(static_cast<sal_uInt16
>(eSvx
));
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
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() );
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */