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.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() );
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
;
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;
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
;
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
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
= static_cast<table::CellHoriJustify
>(nValue
);
123 SvxCellHorJustify eSvx
= SvxCellHorJustify::Standard
;
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
137 case MID_HORJUST_ADJUST
:
139 // property contains ParagraphAdjust values as sal_Int16
140 sal_Int16 nVal
= sal_Int16();
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;
162 OUString
SvxHorJustifyItem::GetValueText( SvxCellHorJustify nVal
)
164 DBG_ASSERT( nVal
<= SvxCellHorJustify::Repeat
, "enum overflow!" );
169 case SvxCellHorJustify::Standard
:
170 sRet
= EditResId(RID_SVXITEMS_HORJUST_STANDARD
);
172 case SvxCellHorJustify::Left
:
173 sRet
= EditResId(RID_SVXITEMS_HORJUST_LEFT
);
175 case SvxCellHorJustify::Center
:
176 sRet
= EditResId(RID_SVXITEMS_HORJUST_CENTER
);
178 case SvxCellHorJustify::Right
:
179 sRet
= EditResId(RID_SVXITEMS_HORJUST_RIGHT
);
181 case SvxCellHorJustify::Block
:
182 sRet
= EditResId(RID_SVXITEMS_HORJUST_BLOCK
);
184 case SvxCellHorJustify::Repeat
:
185 sRet
= EditResId(RID_SVXITEMS_HORJUST_REPEAT
);
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*/,
221 const IntlWrapper
& ) const
223 rText
= GetValueText( GetValue() );
228 bool SvxVerJustifyItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
230 nMemberId
&= ~CONVERT_TWIPS
;
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
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
265 bool SvxVerJustifyItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
267 nMemberId
&= ~CONVERT_TWIPS
;
270 case MID_HORJUST_ADJUST
:
272 // property contains ParagraphAdjust values as sal_Int16
273 style::VerticalAlignment nVal
= style::VerticalAlignment_TOP
;
277 SvxCellVerJustify eSvx
= SvxCellVerJustify::Standard
;
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;
290 sal_Int32 eUno
= table::CellVertJustify2::STANDARD
;
293 SvxCellVerJustify eSvx
= SvxCellVerJustify::Standard
;
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
312 OUString
SvxVerJustifyItem::GetValueText( SvxCellVerJustify nVal
)
314 DBG_ASSERT( nVal
<= SvxCellVerJustify::Bottom
, "enum overflow!" );
319 case SvxCellVerJustify::Standard
:
320 sRet
= EditResId(RID_SVXITEMS_VERJUST_STANDARD
);
322 case SvxCellVerJustify::Top
:
323 sRet
= EditResId(RID_SVXITEMS_VERJUST_TOP
);
325 case SvxCellVerJustify::Center
:
326 sRet
= EditResId(RID_SVXITEMS_VERJUST_CENTER
);
328 case SvxCellVerJustify::Bottom
:
329 sRet
= EditResId(RID_SVXITEMS_VERJUST_BOTTOM
);
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*/,
363 const IntlWrapper
& ) const
365 rText
= GetValueText( GetValue() );
370 bool SvxJustifyMethodItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
372 sal_Int32 nUno
= table::CellJustifyMethod::AUTO
;
375 case SvxCellJustifyMethod::Auto
: nUno
= table::CellJustifyMethod::AUTO
; break;
376 case SvxCellJustifyMethod::Distribute
: nUno
= table::CellJustifyMethod::DISTRIBUTE
; break;
383 bool SvxJustifyMethodItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
385 sal_Int32 nVal
= table::CellJustifyMethod::AUTO
;
386 if (!(rVal
>>= nVal
))
389 SvxCellJustifyMethod eSvx
= SvxCellJustifyMethod::Auto
;
392 case table::CellJustifyMethod::AUTO
:
393 eSvx
= SvxCellJustifyMethod::Auto
;
395 case table::CellJustifyMethod::DISTRIBUTE
:
396 eSvx
= SvxCellJustifyMethod::Distribute
;
405 OUString
SvxJustifyMethodItem::GetValueText( SvxCellJustifyMethod nVal
)
410 case SvxCellJustifyMethod::Auto
:
411 sRet
= EditResId(RID_SVXITEMS_JUSTMETHOD_AUTO
);
413 case SvxCellJustifyMethod::Distribute
:
414 sRet
= EditResId(RID_SVXITEMS_JUSTMETHOD_DISTRIBUTE
);
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: */