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 bool SvxHorJustifyItem::GetPresentation
55 SfxItemPresentation
/*ePres*/,
56 SfxMapUnit
/*eCoreUnit*/,
57 SfxMapUnit
/*ePresUnit*/,
58 OUString
& rText
, const IntlWrapper
*) const
60 rText
= GetValueText( GetValue() );
65 bool SvxHorJustifyItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
67 nMemberId
&= ~CONVERT_TWIPS
;
70 case MID_HORJUST_HORJUST
:
72 table::CellHoriJustify eUno
= table::CellHoriJustify_STANDARD
;
73 switch ( (SvxCellHorJustify
)GetValue() )
75 case SVX_HOR_JUSTIFY_STANDARD
: eUno
= table::CellHoriJustify_STANDARD
; break;
76 case SVX_HOR_JUSTIFY_LEFT
: eUno
= table::CellHoriJustify_LEFT
; break;
77 case SVX_HOR_JUSTIFY_CENTER
: eUno
= table::CellHoriJustify_CENTER
; break;
78 case SVX_HOR_JUSTIFY_RIGHT
: eUno
= table::CellHoriJustify_RIGHT
; break;
79 case SVX_HOR_JUSTIFY_BLOCK
: eUno
= table::CellHoriJustify_BLOCK
; break;
80 case SVX_HOR_JUSTIFY_REPEAT
: eUno
= table::CellHoriJustify_REPEAT
; break;
85 case MID_HORJUST_ADJUST
:
87 // ParagraphAdjust values, as in SvxAdjustItem
88 // (same value for ParaAdjust and ParaLastLineAdjust)
90 sal_Int16 nAdjust
= style::ParagraphAdjust_LEFT
;
91 switch ( (SvxCellHorJustify
)GetValue() )
93 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
94 case SVX_HOR_JUSTIFY_STANDARD
:
95 case SVX_HOR_JUSTIFY_REPEAT
:
96 case SVX_HOR_JUSTIFY_LEFT
: nAdjust
= style::ParagraphAdjust_LEFT
; break;
97 case SVX_HOR_JUSTIFY_CENTER
: nAdjust
= style::ParagraphAdjust_CENTER
; break;
98 case SVX_HOR_JUSTIFY_RIGHT
: nAdjust
= style::ParagraphAdjust_RIGHT
; break;
99 case SVX_HOR_JUSTIFY_BLOCK
: nAdjust
= style::ParagraphAdjust_BLOCK
; break;
101 rVal
<<= nAdjust
; // as sal_Int16
108 bool SvxHorJustifyItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
110 nMemberId
&= ~CONVERT_TWIPS
;
113 case MID_HORJUST_HORJUST
:
115 table::CellHoriJustify eUno
;
118 sal_Int32 nValue
= 0;
119 if(!(rVal
>>= nValue
))
121 eUno
= (table::CellHoriJustify
)nValue
;
123 SvxCellHorJustify eSvx
= SVX_HOR_JUSTIFY_STANDARD
;
126 case table::CellHoriJustify_STANDARD
: eSvx
= SVX_HOR_JUSTIFY_STANDARD
; break;
127 case table::CellHoriJustify_LEFT
: eSvx
= SVX_HOR_JUSTIFY_LEFT
; break;
128 case table::CellHoriJustify_CENTER
: eSvx
= SVX_HOR_JUSTIFY_CENTER
; break;
129 case table::CellHoriJustify_RIGHT
: eSvx
= SVX_HOR_JUSTIFY_RIGHT
; break;
130 case table::CellHoriJustify_BLOCK
: eSvx
= SVX_HOR_JUSTIFY_BLOCK
; break;
131 case table::CellHoriJustify_REPEAT
: eSvx
= SVX_HOR_JUSTIFY_REPEAT
; break;
132 default: ; //prevent warning
134 SetValue( (sal_uInt16
)eSvx
);
137 case MID_HORJUST_ADJUST
:
139 // property contains ParagraphAdjust values as sal_Int16
140 sal_Int16 nVal
= sal_Int16();
144 SvxCellHorJustify eSvx
= SVX_HOR_JUSTIFY_STANDARD
;
147 // STRETCH is treated as BLOCK
148 case style::ParagraphAdjust_LEFT
: eSvx
= SVX_HOR_JUSTIFY_LEFT
; break;
149 case style::ParagraphAdjust_RIGHT
: eSvx
= SVX_HOR_JUSTIFY_RIGHT
; break;
150 case style::ParagraphAdjust_STRETCH
:
151 case style::ParagraphAdjust_BLOCK
: eSvx
= SVX_HOR_JUSTIFY_BLOCK
; break;
152 case style::ParagraphAdjust_CENTER
: eSvx
= SVX_HOR_JUSTIFY_CENTER
; break;
154 SetValue( (sal_uInt16
)eSvx
);
161 OUString
SvxHorJustifyItem::GetValueText( sal_uInt16 nVal
)
163 DBG_ASSERT( nVal
<= SVX_HOR_JUSTIFY_REPEAT
, "enum overflow!" );
164 return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD
+ nVal
);
168 SfxPoolItem
* SvxHorJustifyItem::Clone( SfxItemPool
* ) const
170 return new SvxHorJustifyItem( *this );
174 SfxPoolItem
* SvxHorJustifyItem::Create( SvStream
& rStream
, sal_uInt16
) const
177 rStream
.ReadUInt16( nVal
);
178 return new SvxHorJustifyItem( (SvxCellHorJustify
)nVal
, Which() );
182 sal_uInt16
SvxHorJustifyItem::GetValueCount() const
184 return SVX_HOR_JUSTIFY_REPEAT
+ 1; // Last Enum value + 1
188 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId
) :
189 SfxEnumItem( nId
, (sal_uInt16
)SVX_VER_JUSTIFY_STANDARD
)
193 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify
,
194 const sal_uInt16 nId
) :
195 SfxEnumItem( nId
, (sal_uInt16
)eJustify
)
200 bool SvxVerJustifyItem::GetPresentation
202 SfxItemPresentation
/*ePres*/,
203 SfxMapUnit
/*eCoreUnit*/,
204 SfxMapUnit
/*ePresUnit*/,
206 const IntlWrapper
* ) const
208 rText
= GetValueText( GetValue() );
213 bool SvxVerJustifyItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
215 nMemberId
&= ~CONVERT_TWIPS
;
218 case MID_HORJUST_ADJUST
:
220 style::VerticalAlignment eUno
= style::VerticalAlignment_TOP
;
221 switch ( (SvxCellVerJustify
)GetValue() )
223 case SVX_VER_JUSTIFY_TOP
: eUno
= style::VerticalAlignment_TOP
; break;
224 case SVX_VER_JUSTIFY_CENTER
: eUno
= style::VerticalAlignment_MIDDLE
; break;
225 case SVX_VER_JUSTIFY_BOTTOM
: eUno
= style::VerticalAlignment_BOTTOM
; break;
226 default: ; //prevent warning
233 sal_Int32 nUno
= table::CellVertJustify2::STANDARD
;
234 switch ( (SvxCellVerJustify
)GetValue() )
236 case SVX_VER_JUSTIFY_STANDARD
: nUno
= table::CellVertJustify2::STANDARD
; break;
237 case SVX_VER_JUSTIFY_TOP
: nUno
= table::CellVertJustify2::TOP
; break;
238 case SVX_VER_JUSTIFY_CENTER
: nUno
= table::CellVertJustify2::CENTER
; break;
239 case SVX_VER_JUSTIFY_BOTTOM
: nUno
= table::CellVertJustify2::BOTTOM
; break;
240 case SVX_VER_JUSTIFY_BLOCK
: nUno
= table::CellVertJustify2::BLOCK
; break;
241 default: ; //prevent warning
250 bool SvxVerJustifyItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
252 nMemberId
&= ~CONVERT_TWIPS
;
255 case MID_HORJUST_ADJUST
:
257 // property contains ParagraphAdjust values as sal_Int16
258 style::VerticalAlignment nVal
= style::VerticalAlignment_TOP
;
262 SvxCellVerJustify eSvx
= SVX_VER_JUSTIFY_STANDARD
;
265 case style::VerticalAlignment_TOP
: eSvx
= SVX_VER_JUSTIFY_TOP
; break;
266 case style::VerticalAlignment_MIDDLE
: eSvx
= SVX_VER_JUSTIFY_CENTER
; break;
267 case style::VerticalAlignment_BOTTOM
: eSvx
= SVX_VER_JUSTIFY_BOTTOM
; break;
270 SetValue( (sal_uInt16
)eSvx
);
275 sal_Int32 eUno
= table::CellVertJustify2::STANDARD
;
278 SvxCellVerJustify eSvx
= SVX_VER_JUSTIFY_STANDARD
;
281 case table::CellVertJustify2::STANDARD
: eSvx
= SVX_VER_JUSTIFY_STANDARD
; break;
282 case table::CellVertJustify2::TOP
: eSvx
= SVX_VER_JUSTIFY_TOP
; break;
283 case table::CellVertJustify2::CENTER
: eSvx
= SVX_VER_JUSTIFY_CENTER
; break;
284 case table::CellVertJustify2::BOTTOM
: eSvx
= SVX_VER_JUSTIFY_BOTTOM
; break;
285 case table::CellVertJustify2::BLOCK
: eSvx
= SVX_VER_JUSTIFY_BLOCK
; break;
286 default: ; //prevent warning
288 SetValue( (sal_uInt16
)eSvx
);
297 OUString
SvxVerJustifyItem::GetValueText( sal_uInt16 nVal
)
299 DBG_ASSERT( nVal
<= SVX_VER_JUSTIFY_BOTTOM
, "enum overflow!" );
300 return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD
+ nVal
);
304 SfxPoolItem
* SvxVerJustifyItem::Clone( SfxItemPool
* ) const
306 return new SvxVerJustifyItem( *this );
310 SfxPoolItem
* SvxVerJustifyItem::Create( SvStream
& rStream
, sal_uInt16
) const
313 rStream
.ReadUInt16( nVal
);
314 return new SvxVerJustifyItem( (SvxCellVerJustify
)nVal
, Which() );
318 sal_uInt16
SvxVerJustifyItem::GetValueCount() const
320 return SVX_VER_JUSTIFY_BOTTOM
+ 1; // Last Enum value + 1
324 SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify
,
325 const sal_uInt16 nId
) :
326 SfxEnumItem( nId
, (sal_uInt16
)eJustify
)
331 bool SvxJustifyMethodItem::GetPresentation
333 SfxItemPresentation
/*ePres*/,
334 SfxMapUnit
/*eCoreUnit*/,
335 SfxMapUnit
/*ePresUnit*/,
337 const IntlWrapper
* ) const
339 rText
= GetValueText( GetValue() );
344 bool SvxJustifyMethodItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
346 sal_Int32 nUno
= table::CellJustifyMethod::AUTO
;
347 switch (static_cast<SvxCellJustifyMethod
>(GetValue()))
349 case SVX_JUSTIFY_METHOD_AUTO
: nUno
= table::CellJustifyMethod::AUTO
; break;
350 case SVX_JUSTIFY_METHOD_DISTRIBUTE
: nUno
= table::CellJustifyMethod::DISTRIBUTE
; break;
357 bool SvxJustifyMethodItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
359 sal_Int32 nVal
= table::CellJustifyMethod::AUTO
;
360 if (!(rVal
>>= nVal
))
363 SvxCellJustifyMethod eSvx
= SVX_JUSTIFY_METHOD_AUTO
;
366 case table::CellJustifyMethod::AUTO
:
367 eSvx
= SVX_JUSTIFY_METHOD_AUTO
;
369 case table::CellJustifyMethod::DISTRIBUTE
:
370 eSvx
= SVX_JUSTIFY_METHOD_DISTRIBUTE
;
374 SetValue(static_cast<sal_uInt16
>(eSvx
));
379 OUString
SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal
)
381 DBG_ASSERT( nVal
<= SVX_VER_JUSTIFY_BOTTOM
, "enum overflow!" );
382 return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO
+ nVal
);
386 SfxPoolItem
* SvxJustifyMethodItem::Clone( SfxItemPool
* ) const
388 return new SvxJustifyMethodItem( *this );
392 SfxPoolItem
* SvxJustifyMethodItem::Create( SvStream
& rStream
, sal_uInt16
) const
395 rStream
.ReadUInt16( nVal
);
396 return new SvxJustifyMethodItem( (SvxCellJustifyMethod
)nVal
, Which() );
400 sal_uInt16
SvxJustifyMethodItem::GetValueCount() const
402 return SVX_JUSTIFY_METHOD_DISTRIBUTE
+ 1; // Last Enum value + 1
405 SvxJustifyMethodItem
& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem
& r
)
407 SetValue( r
.GetValue() );
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */