1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/strings.hrc>
#include <osl/diagnose.h>
#include <tools/mapunit.hxx>
#include <com/sun/star/table/CellOrientation.hpp>
#include <svx/algitem.hxx>
#include <svx/dialmgr.hxx>
#include <editeng/itemtype.hxx>
#include <editeng/eerdll.hxx>
#include <svx/unomid.hxx>
#include <climits>
using namespace ::com::sun::star;
SfxPoolItem* SvxMarginItem::CreateDefault() { return new SvxMarginItem(0) ;}
SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
const sal_uInt16 nId):
SfxEnumItem( nId, eOrientation )
{
}
SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, bool bStacked, const sal_uInt16 nId ) :
SfxEnumItem( nId, SvxCellOrientation::Standard )
{
if( bStacked )
{
SetValue( SvxCellOrientation::Stacked );
}
else switch( nRotation )
{
case 9000: SetValue( SvxCellOrientation::BottomUp ); break;
case 27000: SetValue( SvxCellOrientation::TopBottom ); break;
default: SetValue( SvxCellOrientation::Standard );
}
}
bool SvxOrientationItem::GetPresentation
(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText,
const IntlWrapper& ) const
{
rText = GetValueText( GetValue() );
return true;
}
bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
{
table::CellOrientation eUno = table::CellOrientation_STANDARD;
switch ( GetValue() )
{
case SvxCellOrientation::Standard: eUno = table::CellOrientation_STANDARD; break;
case SvxCellOrientation::TopBottom: eUno = table::CellOrientation_TOPBOTTOM; break;
case SvxCellOrientation::BottomUp: eUno = table::CellOrientation_BOTTOMTOP; break;
case SvxCellOrientation::Stacked: eUno = table::CellOrientation_STACKED; break;
}
rVal <<= eUno;
return true;
}
bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
{
table::CellOrientation eOrient;
if(!(rVal >>= eOrient))
{
sal_Int32 nValue = 0;
if(!(rVal >>= nValue))
return false;
eOrient = static_cast<table::CellOrientation>(nValue);
}
SvxCellOrientation eSvx = SvxCellOrientation::Standard;
switch (eOrient)
{
case table::CellOrientation_STANDARD: eSvx = SvxCellOrientation::Standard; break;
case table::CellOrientation_TOPBOTTOM: eSvx = SvxCellOrientation::TopBottom; break;
case table::CellOrientation_BOTTOMTOP: eSvx = SvxCellOrientation::BottomUp; break;
case table::CellOrientation_STACKED: eSvx = SvxCellOrientation::Stacked; break;
default: ; //prevent warning
}
SetValue( eSvx );
return true;
}
OUString SvxOrientationItem::GetValueText( SvxCellOrientation nVal )
{
return SvxResId(RID_SVXITEMS_ORI_STANDARD + static_cast<int>(nVal));
}
SvxOrientationItem* SvxOrientationItem::Clone( SfxItemPool* ) const
{
return new SvxOrientationItem( *this );
}
sal_uInt16 SvxOrientationItem::GetValueCount() const
{
return static_cast<sal_uInt16>(SvxCellOrientation::Stacked) + 1; // last enum value + 1
}
bool SvxOrientationItem::IsStacked() const
{
return GetValue() == SvxCellOrientation::Stacked;
}
sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
{
sal_Int32 nAngle = nStdAngle;
switch( GetValue() )
{
case SvxCellOrientation::BottomUp: nAngle = 9000;break;
case SvxCellOrientation::TopBottom: nAngle = 27000;break;
default: ; //prevent warning
}
return nAngle;
}
SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
SfxPoolItem( nId ),
nLeftMargin ( 20 ),
nTopMargin ( 20 ),
nRightMargin ( 20 ),
nBottomMargin( 20 )
{
}
SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
sal_Int16 nTop,
sal_Int16 nRight,
sal_Int16 nBottom,
const sal_uInt16 nId ) :
SfxPoolItem( nId ),
nLeftMargin ( nLeft ),
nTopMargin ( nTop ),
nRightMargin ( nRight ),
nBottomMargin( nBottom )
{
}
bool SvxMarginItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
OUString cpDelimTmp(cpDelim);
switch ( ePres )
{
case SfxItemPresentation::Nameless:
{
rText = GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
cpDelimTmp +
GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
cpDelimTmp +
GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
cpDelimTmp +
GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
return true;
}
case SfxItemPresentation::Complete:
{
rText = SvxResId(RID_SVXITEMS_MARGIN_LEFT) +
GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit)) +
cpDelimTmp +
SvxResId(RID_SVXITEMS_MARGIN_TOP) +
GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit)) +
cpDelimTmp +
SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit)) +
cpDelimTmp +
SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit));
return true;
}
default: ; //prevent warning
}
return false;
}
bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
{
assert(SfxPoolItem::operator==(rItem));
return ( ( nLeftMargin == static_cast<const SvxMarginItem&>(rItem).nLeftMargin ) &&
( nTopMargin == static_cast<const SvxMarginItem&>(rItem).nTopMargin ) &&
( nRightMargin == static_cast<const SvxMarginItem&>(rItem).nRightMargin ) &&
( nBottomMargin == static_cast<const SvxMarginItem&>(rItem).nBottomMargin ) );
}
SvxMarginItem* SvxMarginItem::Clone( SfxItemPool* ) const
{
return new SvxMarginItem(*this);
}
bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
// now sign everything
case MID_MARGIN_L_MARGIN:
rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
break;
case MID_MARGIN_R_MARGIN:
rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
break;
case MID_MARGIN_UP_MARGIN:
rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
break;
case MID_MARGIN_LO_MARGIN:
rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
break;
default:
OSL_FAIL("unknown MemberId");
return false;
}
return true;
}
bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
long nMaxVal = bConvert ? convertTwipToMm100(SHRT_MAX) : SHRT_MAX; // members are sal_Int16
sal_Int32 nVal = 0;
if(!(rVal >>= nVal) || (nVal > nMaxVal))
return false;
switch ( nMemberId & ~CONVERT_TWIPS )
{
case MID_MARGIN_L_MARGIN:
nLeftMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
break;
case MID_MARGIN_R_MARGIN:
nRightMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
break;
case MID_MARGIN_UP_MARGIN:
nTopMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
break;
case MID_MARGIN_LO_MARGIN:
nBottomMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
break;
default:
OSL_FAIL("unknown MemberId");
return false;
}
return true;
}
void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
{
nLeftMargin = nLeft;
}
void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
{
nTopMargin = nTop;
}
void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
{
nRightMargin = nRight;
}
void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
{
nBottomMargin = nBottom;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|