Line data Source code
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 :
20 : #include "editeng/justifyitem.hxx"
21 : #include "editeng/memberids.hrc"
22 : #include "editeng/editrids.hrc"
23 : #include "editeng/eerdll.hxx"
24 :
25 : #include <tools/stream.hxx>
26 :
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>
32 :
33 :
34 6844 : TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0) );
35 534589 : TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
36 :
37 : using namespace ::com::sun::star;
38 :
39 :
40 :
41 0 : SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
42 0 : SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
43 : {
44 0 : }
45 :
46 4372 : SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
47 : const sal_uInt16 nId ) :
48 4372 : SfxEnumItem( nId, (sal_uInt16)eJustify )
49 : {
50 4372 : }
51 :
52 :
53 0 : bool SvxHorJustifyItem::GetPresentation
54 : (
55 : SfxItemPresentation /*ePres*/,
56 : SfxMapUnit /*eCoreUnit*/,
57 : SfxMapUnit /*ePresUnit*/,
58 : OUString& rText, const IntlWrapper *) const
59 : {
60 0 : rText = GetValueText( GetValue() );
61 0 : return true;
62 : }
63 :
64 :
65 242 : bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
66 : {
67 242 : nMemberId &= ~CONVERT_TWIPS;
68 242 : switch ( nMemberId )
69 : {
70 : case MID_HORJUST_HORJUST:
71 : {
72 138 : table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
73 138 : switch ( (SvxCellHorJustify)GetValue() )
74 : {
75 35 : case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
76 21 : case SVX_HOR_JUSTIFY_LEFT: eUno = table::CellHoriJustify_LEFT; break;
77 45 : case SVX_HOR_JUSTIFY_CENTER: eUno = table::CellHoriJustify_CENTER; break;
78 22 : case SVX_HOR_JUSTIFY_RIGHT: eUno = table::CellHoriJustify_RIGHT; break;
79 15 : case SVX_HOR_JUSTIFY_BLOCK: eUno = table::CellHoriJustify_BLOCK; break;
80 0 : case SVX_HOR_JUSTIFY_REPEAT: eUno = table::CellHoriJustify_REPEAT; break;
81 : }
82 138 : rVal <<= eUno;
83 : }
84 138 : break;
85 : case MID_HORJUST_ADJUST:
86 : {
87 : // ParagraphAdjust values, as in SvxAdjustItem
88 : // (same value for ParaAdjust and ParaLastLineAdjust)
89 :
90 104 : sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
91 104 : switch ( (SvxCellHorJustify)GetValue() )
92 : {
93 : // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
94 : case SVX_HOR_JUSTIFY_STANDARD:
95 : case SVX_HOR_JUSTIFY_REPEAT:
96 13 : case SVX_HOR_JUSTIFY_LEFT: nAdjust = style::ParagraphAdjust_LEFT; break;
97 62 : case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
98 24 : case SVX_HOR_JUSTIFY_RIGHT: nAdjust = style::ParagraphAdjust_RIGHT; break;
99 5 : case SVX_HOR_JUSTIFY_BLOCK: nAdjust = style::ParagraphAdjust_BLOCK; break;
100 : }
101 104 : rVal <<= nAdjust; // as sal_Int16
102 : }
103 104 : break;
104 : }
105 242 : return true;
106 : }
107 :
108 359 : bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
109 : {
110 359 : nMemberId &= ~CONVERT_TWIPS;
111 359 : switch ( nMemberId )
112 : {
113 : case MID_HORJUST_HORJUST:
114 : {
115 : table::CellHoriJustify eUno;
116 351 : if(!(rVal >>= eUno))
117 : {
118 60 : sal_Int32 nValue = 0;
119 60 : if(!(rVal >>= nValue))
120 60 : return false;
121 0 : eUno = (table::CellHoriJustify)nValue;
122 : }
123 291 : SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
124 291 : switch (eUno)
125 : {
126 13 : case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
127 23 : case table::CellHoriJustify_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
128 215 : case table::CellHoriJustify_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
129 30 : case table::CellHoriJustify_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
130 9 : case table::CellHoriJustify_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
131 1 : case table::CellHoriJustify_REPEAT: eSvx = SVX_HOR_JUSTIFY_REPEAT; break;
132 : default: ; //prevent warning
133 : }
134 291 : SetValue( (sal_uInt16)eSvx );
135 : }
136 291 : break;
137 : case MID_HORJUST_ADJUST:
138 : {
139 : // property contains ParagraphAdjust values as sal_Int16
140 8 : sal_Int16 nVal = sal_Int16();
141 8 : if(!(rVal >>= nVal))
142 0 : return false;
143 :
144 8 : SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
145 8 : switch (nVal)
146 : {
147 : // STRETCH is treated as BLOCK
148 0 : case style::ParagraphAdjust_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
149 5 : case style::ParagraphAdjust_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
150 : case style::ParagraphAdjust_STRETCH:
151 2 : case style::ParagraphAdjust_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
152 1 : case style::ParagraphAdjust_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
153 : }
154 8 : SetValue( (sal_uInt16)eSvx );
155 : }
156 : }
157 299 : return true;
158 : }
159 :
160 :
161 0 : OUString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal )
162 : {
163 : DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
164 0 : return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
165 : }
166 :
167 :
168 1369 : SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
169 : {
170 1369 : return new SvxHorJustifyItem( *this );
171 : }
172 :
173 :
174 512 : SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
175 : {
176 : sal_uInt16 nVal;
177 512 : rStream.ReadUInt16( nVal );
178 512 : return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
179 : }
180 :
181 :
182 0 : sal_uInt16 SvxHorJustifyItem::GetValueCount() const
183 : {
184 0 : return SVX_HOR_JUSTIFY_REPEAT + 1; // Last Enum value + 1
185 : }
186 :
187 :
188 0 : SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
189 0 : SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
190 : {
191 0 : }
192 :
193 3749 : SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
194 : const sal_uInt16 nId ) :
195 3749 : SfxEnumItem( nId, (sal_uInt16)eJustify )
196 : {
197 3749 : }
198 :
199 :
200 0 : bool SvxVerJustifyItem::GetPresentation
201 : (
202 : SfxItemPresentation /*ePres*/,
203 : SfxMapUnit /*eCoreUnit*/,
204 : SfxMapUnit /*ePresUnit*/,
205 : OUString& rText,
206 : const IntlWrapper * ) const
207 : {
208 0 : rText = GetValueText( GetValue() );
209 0 : return true;
210 : }
211 :
212 :
213 62 : bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
214 : {
215 62 : nMemberId &= ~CONVERT_TWIPS;
216 62 : switch ( nMemberId )
217 : {
218 : case MID_HORJUST_ADJUST:
219 : {
220 0 : style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
221 0 : switch ( (SvxCellVerJustify)GetValue() )
222 : {
223 0 : case SVX_VER_JUSTIFY_TOP: eUno = style::VerticalAlignment_TOP; break;
224 0 : case SVX_VER_JUSTIFY_CENTER: eUno = style::VerticalAlignment_MIDDLE; break;
225 0 : case SVX_VER_JUSTIFY_BOTTOM: eUno = style::VerticalAlignment_BOTTOM; break;
226 : default: ; //prevent warning
227 : }
228 0 : rVal <<= eUno;
229 0 : break;
230 : }
231 : default:
232 : {
233 62 : sal_Int32 nUno = table::CellVertJustify2::STANDARD;
234 62 : switch ( (SvxCellVerJustify)GetValue() )
235 : {
236 26 : case SVX_VER_JUSTIFY_STANDARD: nUno = table::CellVertJustify2::STANDARD; break;
237 11 : case SVX_VER_JUSTIFY_TOP: nUno = table::CellVertJustify2::TOP; break;
238 12 : case SVX_VER_JUSTIFY_CENTER: nUno = table::CellVertJustify2::CENTER; break;
239 13 : case SVX_VER_JUSTIFY_BOTTOM: nUno = table::CellVertJustify2::BOTTOM; break;
240 0 : case SVX_VER_JUSTIFY_BLOCK: nUno = table::CellVertJustify2::BLOCK; break;
241 : default: ; //prevent warning
242 : }
243 62 : rVal <<= nUno;
244 62 : break;
245 : }
246 : }
247 62 : return true;
248 : }
249 :
250 69 : bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
251 : {
252 69 : nMemberId &= ~CONVERT_TWIPS;
253 69 : switch ( nMemberId )
254 : {
255 : case MID_HORJUST_ADJUST:
256 : {
257 : // property contains ParagraphAdjust values as sal_Int16
258 0 : style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
259 0 : if(!(rVal >>= nVal))
260 0 : return false;
261 :
262 0 : SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
263 0 : switch (nVal)
264 : {
265 0 : case style::VerticalAlignment_TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
266 0 : case style::VerticalAlignment_MIDDLE: eSvx = SVX_VER_JUSTIFY_CENTER; break;
267 0 : case style::VerticalAlignment_BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
268 : default:;
269 : }
270 0 : SetValue( (sal_uInt16)eSvx );
271 0 : break;
272 : }
273 : default:
274 : {
275 69 : sal_Int32 eUno = table::CellVertJustify2::STANDARD;
276 69 : rVal >>= eUno;
277 :
278 69 : SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
279 69 : switch (eUno)
280 : {
281 11 : case table::CellVertJustify2::STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD; break;
282 7 : case table::CellVertJustify2::TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
283 14 : case table::CellVertJustify2::CENTER: eSvx = SVX_VER_JUSTIFY_CENTER; break;
284 33 : case table::CellVertJustify2::BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
285 0 : case table::CellVertJustify2::BLOCK: eSvx = SVX_VER_JUSTIFY_BLOCK; break;
286 : default: ; //prevent warning
287 : }
288 69 : SetValue( (sal_uInt16)eSvx );
289 69 : break;
290 : }
291 : }
292 :
293 69 : return true;
294 : }
295 :
296 :
297 0 : OUString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal )
298 : {
299 : DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
300 0 : return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
301 : }
302 :
303 :
304 685 : SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
305 : {
306 685 : return new SvxVerJustifyItem( *this );
307 : }
308 :
309 :
310 512 : SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
311 : {
312 : sal_uInt16 nVal;
313 512 : rStream.ReadUInt16( nVal );
314 512 : return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
315 : }
316 :
317 :
318 0 : sal_uInt16 SvxVerJustifyItem::GetValueCount() const
319 : {
320 0 : return SVX_VER_JUSTIFY_BOTTOM + 1; // Last Enum value + 1
321 : }
322 :
323 :
324 5420 : SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
325 : const sal_uInt16 nId ) :
326 5420 : SfxEnumItem( nId, (sal_uInt16)eJustify )
327 : {
328 5420 : }
329 :
330 :
331 0 : bool SvxJustifyMethodItem::GetPresentation
332 : (
333 : SfxItemPresentation /*ePres*/,
334 : SfxMapUnit /*eCoreUnit*/,
335 : SfxMapUnit /*ePresUnit*/,
336 : OUString& rText,
337 : const IntlWrapper * ) const
338 : {
339 0 : rText = GetValueText( GetValue() );
340 0 : return true;
341 : }
342 :
343 :
344 32 : bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
345 : {
346 32 : sal_Int32 nUno = table::CellJustifyMethod::AUTO;
347 32 : switch (static_cast<SvxCellJustifyMethod>(GetValue()))
348 : {
349 32 : case SVX_JUSTIFY_METHOD_AUTO: nUno = table::CellJustifyMethod::AUTO; break;
350 0 : case SVX_JUSTIFY_METHOD_DISTRIBUTE: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
351 : default:;
352 : }
353 32 : rVal <<= nUno;
354 32 : return true;
355 : }
356 :
357 30 : bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
358 : {
359 30 : sal_Int32 nVal = table::CellJustifyMethod::AUTO;
360 30 : if (!(rVal >>= nVal))
361 0 : return false;
362 :
363 30 : SvxCellJustifyMethod eSvx = SVX_JUSTIFY_METHOD_AUTO;
364 30 : switch (nVal)
365 : {
366 : case table::CellJustifyMethod::AUTO:
367 24 : eSvx = SVX_JUSTIFY_METHOD_AUTO;
368 24 : break;
369 : case table::CellJustifyMethod::DISTRIBUTE:
370 0 : eSvx = SVX_JUSTIFY_METHOD_DISTRIBUTE;
371 0 : break;
372 : default:;
373 : }
374 30 : SetValue(static_cast<sal_uInt16>(eSvx));
375 30 : return true;
376 : }
377 :
378 :
379 0 : OUString SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal )
380 : {
381 : DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
382 0 : return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO + nVal);
383 : }
384 :
385 :
386 519 : SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
387 : {
388 519 : return new SvxJustifyMethodItem( *this );
389 : }
390 :
391 :
392 0 : SfxPoolItem* SvxJustifyMethodItem::Create( SvStream& rStream, sal_uInt16 ) const
393 : {
394 : sal_uInt16 nVal;
395 0 : rStream.ReadUInt16( nVal );
396 0 : return new SvxJustifyMethodItem( (SvxCellJustifyMethod)nVal, Which() );
397 : }
398 :
399 :
400 0 : sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
401 : {
402 0 : return SVX_JUSTIFY_METHOD_DISTRIBUTE + 1; // Last Enum value + 1
403 : }
404 :
405 0 : SvxJustifyMethodItem& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem& r)
406 : {
407 0 : SetValue( r.GetValue() );
408 0 : return *this;
409 : }
410 :
411 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|