LibreOffice Module editeng (master) 1
justifyitem.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <editeng/memberids.h>
22#include <editeng/eerdll.hxx>
23
24#include <com/sun/star/table/CellHoriJustify.hpp>
25#include <com/sun/star/style/ParagraphAdjust.hpp>
26#include <com/sun/star/table/CellJustifyMethod.hpp>
27#include <com/sun/star/table/CellVertJustify2.hpp>
28#include <com/sun/star/style/VerticalAlignment.hpp>
29
30#include <strings.hrc>
31
34
35using namespace ::com::sun::star;
36
37
38SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
40{
41}
42
44 const sal_uInt16 nId ) :
45 SfxEnumItem( nId, eJustify )
46{
47}
48
49
51(
52 SfxItemPresentation /*ePres*/,
53 MapUnit /*eCoreUnit*/,
54 MapUnit /*ePresUnit*/,
55 OUString& rText, const IntlWrapper&) const
56{
57 rText = GetValueText(GetValue());
58 return true;
59}
60
61
62bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
63{
64 nMemberId &= ~CONVERT_TWIPS;
65 switch ( nMemberId )
66 {
68 {
69 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
70 switch ( GetValue() )
71 {
72 case SvxCellHorJustify::Standard: eUno = table::CellHoriJustify_STANDARD; break;
73 case SvxCellHorJustify::Left: eUno = table::CellHoriJustify_LEFT; break;
74 case SvxCellHorJustify::Center: eUno = table::CellHoriJustify_CENTER; break;
75 case SvxCellHorJustify::Right: eUno = table::CellHoriJustify_RIGHT; break;
76 case SvxCellHorJustify::Block: eUno = table::CellHoriJustify_BLOCK; break;
77 case SvxCellHorJustify::Repeat: eUno = table::CellHoriJustify_REPEAT; break;
78 }
79 rVal <<= eUno;
80 }
81 break;
83 {
84 // ParagraphAdjust values, as in SvxAdjustItem
85 // (same value for ParaAdjust and ParaLastLineAdjust)
86
87 style::ParagraphAdjust nAdjust = style::ParagraphAdjust_LEFT;
88 switch ( GetValue() )
89 {
90 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
93 case SvxCellHorJustify::Left: nAdjust = style::ParagraphAdjust_LEFT; break;
94 case SvxCellHorJustify::Center: nAdjust = style::ParagraphAdjust_CENTER; break;
95 case SvxCellHorJustify::Right: nAdjust = style::ParagraphAdjust_RIGHT; break;
96 case SvxCellHorJustify::Block: nAdjust = style::ParagraphAdjust_BLOCK; break;
97 }
98 rVal <<= static_cast<sal_Int16>(nAdjust); // as sal_Int16
99 }
100 break;
101 }
102 return true;
103}
104
105bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
106{
107 nMemberId &= ~CONVERT_TWIPS;
108 switch ( nMemberId )
109 {
111 {
112 table::CellHoriJustify eUno;
113 if(!(rVal >>= eUno))
114 {
115 sal_Int32 nValue = 0;
116 if(!(rVal >>= nValue))
117 return false;
118 eUno = static_cast<table::CellHoriJustify>(nValue);
119 }
121 switch (eUno)
122 {
123 case table::CellHoriJustify_STANDARD: eSvx = SvxCellHorJustify::Standard; break;
124 case table::CellHoriJustify_LEFT: eSvx = SvxCellHorJustify::Left; break;
125 case table::CellHoriJustify_CENTER: eSvx = SvxCellHorJustify::Center; break;
126 case table::CellHoriJustify_RIGHT: eSvx = SvxCellHorJustify::Right; break;
127 case table::CellHoriJustify_BLOCK: eSvx = SvxCellHorJustify::Block; break;
128 case table::CellHoriJustify_REPEAT: eSvx = SvxCellHorJustify::Repeat; break;
129 default: ; //prevent warning
130 }
131 SetValue( eSvx );
132 }
133 break;
135 {
136 // property contains ParagraphAdjust values as sal_Int16
137 sal_Int16 nVal = sal_Int16();
138 if(!(rVal >>= nVal))
139 return false;
140
142 switch (static_cast<style::ParagraphAdjust>(nVal))
143 {
144 // STRETCH is treated as BLOCK
145 case style::ParagraphAdjust_LEFT: eSvx = SvxCellHorJustify::Left; break;
146 case style::ParagraphAdjust_RIGHT: eSvx = SvxCellHorJustify::Right; break;
147 case style::ParagraphAdjust_STRETCH:
148 case style::ParagraphAdjust_BLOCK: eSvx = SvxCellHorJustify::Block; break;
149 case style::ParagraphAdjust_CENTER: eSvx = SvxCellHorJustify::Center; break;
150 default: break;
151 }
152 SetValue( eSvx );
153 }
154 }
155 return true;
156}
157
159{
160 assert(nVal <= SvxCellHorJustify::Repeat && "enum overflow!");
161 return EditResId(RID_SVXITEMS_HORJUST[static_cast<size_t>(nVal)]);
162}
163
165{
166 return new SvxHorJustifyItem( *this );
167}
168
170{
171 return sal_uInt16(SvxCellHorJustify::Repeat) + 1; // Last Enum value + 1
172}
173
174
177{
178}
179
181 const sal_uInt16 nId ) :
182 SfxEnumItem( nId, eJustify )
183{
184}
185
186
188(
189 SfxItemPresentation /*ePres*/,
190 MapUnit /*eCoreUnit*/,
191 MapUnit /*ePresUnit*/,
192 OUString& rText,
193 const IntlWrapper& ) const
194{
195 rText = GetValueText( GetValue() );
196 return true;
197}
198
199
201{
202 nMemberId &= ~CONVERT_TWIPS;
203 switch ( nMemberId )
204 {
206 {
207 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
208 switch ( GetValue() )
209 {
210 case SvxCellVerJustify::Top: eUno = style::VerticalAlignment_TOP; break;
211 case SvxCellVerJustify::Center: eUno = style::VerticalAlignment_MIDDLE; break;
212 case SvxCellVerJustify::Bottom: eUno = style::VerticalAlignment_BOTTOM; break;
213 default: ; //prevent warning
214 }
215 rVal <<= eUno;
216 break;
217 }
218 default:
219 {
220 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
221 switch ( GetValue() )
222 {
223 case SvxCellVerJustify::Standard: nUno = table::CellVertJustify2::STANDARD; break;
224 case SvxCellVerJustify::Top: nUno = table::CellVertJustify2::TOP; break;
225 case SvxCellVerJustify::Center: nUno = table::CellVertJustify2::CENTER; break;
226 case SvxCellVerJustify::Bottom: nUno = table::CellVertJustify2::BOTTOM; break;
228 default: ; //prevent warning
229 }
230 rVal <<= nUno;
231 break;
232 }
233 }
234 return true;
235}
236
237bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
238{
239 nMemberId &= ~CONVERT_TWIPS;
240 switch ( nMemberId )
241 {
243 {
244 // property contains ParagraphAdjust values as sal_Int16
245 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
246 if(!(rVal >>= nVal))
247 return false;
248
250 switch (nVal)
251 {
252 case style::VerticalAlignment_TOP: eSvx = SvxCellVerJustify::Top; break;
253 case style::VerticalAlignment_MIDDLE: eSvx = SvxCellVerJustify::Center; break;
254 case style::VerticalAlignment_BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
255 default:;
256 }
257 SetValue( eSvx );
258 break;
259 }
260 default:
261 {
262 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
263 rVal >>= eUno;
264
266 switch (eUno)
267 {
268 case table::CellVertJustify2::STANDARD: eSvx = SvxCellVerJustify::Standard; break;
269 case table::CellVertJustify2::TOP: eSvx = SvxCellVerJustify::Top; break;
270 case table::CellVertJustify2::CENTER: eSvx = SvxCellVerJustify::Center; break;
271 case table::CellVertJustify2::BOTTOM: eSvx = SvxCellVerJustify::Bottom; break;
273 default: ; //prevent warning
274 }
275 SetValue( eSvx );
276 break;
277 }
278 }
279
280 return true;
281}
282
284{
285 assert(nVal <= SvxCellVerJustify::Block && "enum overflow!");
286 return EditResId(RID_SVXITEMS_VERJUST[static_cast<size_t>(nVal)]);
287}
288
290{
291 return new SvxVerJustifyItem( *this );
292}
293
295{
296 return static_cast<sal_uInt16>(SvxCellVerJustify::Bottom) + 1; // Last Enum value + 1
297}
298
300 const sal_uInt16 nId ) :
301 SfxEnumItem( nId, eJustify )
302{
303}
304
306(
307 SfxItemPresentation /*ePres*/,
308 MapUnit /*eCoreUnit*/,
309 MapUnit /*ePresUnit*/,
310 OUString& rText,
311 const IntlWrapper& ) const
312{
313 rText = GetValueText( GetValue() );
314 return true;
315}
316
317
318bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
319{
320 sal_Int32 nUno = table::CellJustifyMethod::AUTO;
321 switch (GetValue())
322 {
323 case SvxCellJustifyMethod::Auto: nUno = table::CellJustifyMethod::AUTO; break;
324 case SvxCellJustifyMethod::Distribute: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
325 default:;
326 }
327 rVal <<= nUno;
328 return true;
329}
330
331bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
332{
333 sal_Int32 nVal = table::CellJustifyMethod::AUTO;
334 if (!(rVal >>= nVal))
335 return false;
336
338 switch (nVal)
339 {
340 case table::CellJustifyMethod::AUTO:
342 break;
343 case table::CellJustifyMethod::DISTRIBUTE:
345 break;
346 default:;
347 }
348 SetValue(eSvx);
349 return true;
350}
351
353{
354 assert(nVal <= SvxCellJustifyMethod::Distribute && "enum overflow!");
355 return EditResId(RID_SVXITEMS_JUSTMETHOD[static_cast<size_t>(nVal)]);
356}
357
359{
360 return new SvxJustifyMethodItem( *this );
361}
362
364{
365 return static_cast<sal_uInt16>(SvxCellJustifyMethod::Distribute) + 1; // Last Enum value + 1
366}
367
368/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(EnumT nTheValue)
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
static OUString GetValueText(SvxCellHorJustify nVal)
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: justifyitem.cxx:51
static SfxPoolItem * CreateDefault()
Definition: justifyitem.cxx:32
virtual sal_uInt16 GetValueCount() const override
virtual SvxHorJustifyItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: justifyitem.cxx:62
SvxHorJustifyItem(const sal_uInt16 nId)
Definition: justifyitem.cxx:38
virtual sal_uInt16 GetValueCount() const override
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SvxJustifyMethodItem(const SvxCellJustifyMethod eMethod, const sal_uInt16 nId)
virtual SvxJustifyMethodItem * Clone(SfxItemPool *pPool=nullptr) const override
static OUString GetValueText(SvxCellJustifyMethod nVal)
static SfxPoolItem * CreateDefault()
Definition: justifyitem.cxx:33
virtual SvxVerJustifyItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
virtual sal_uInt16 GetValueCount() const override
SvxVerJustifyItem(const sal_uInt16 nId)
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
static OUString GetValueText(SvxCellVerJustify nVal)
OUString EditResId(TranslateId aId)
Definition: eerdll.cxx:192
sal_Int16 nValue
sal_Int16 nAdjust
MapUnit
#define MID_HORJUST_ADJUST
Definition: memberids.h:185
#define MID_HORJUST_HORJUST
Definition: memberids.h:184
sal_Int16 nId
SfxItemPresentation
SvxCellJustifyMethod
Definition: svxenum.hxx:110
SvxCellHorJustify
Definition: svxenum.hxx:100
SvxCellVerJustify
Definition: svxenum.hxx:116
unsigned char sal_uInt8