LibreOffice Module sw (master) 1
grfatr.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
20#include <com/sun/star/drawing/ColorMode.hpp>
21#include <o3tl/any.hxx>
23#include <grfatr.hxx>
24#include <swunohelper.hxx>
25#include <osl/diagnose.h>
26#include <sal/log.hxx>
27
28#include <unomid.h>
29
30using namespace ::com::sun::star;
31
33{
34 return new SwMirrorGrf( *this );
35}
36
38{
39 return 4;
40}
41
42bool SwMirrorGrf::operator==( const SfxPoolItem& rItem) const
43{
44 return SfxEnumItem::operator==(rItem) &&
45 static_cast<const SwMirrorGrf&>(rItem).IsGrfToggle() == IsGrfToggle();
46}
47
48static bool lcl_IsHoriOnEvenPages(MirrorGraph nEnum, bool bToggle)
49{
50 bool bEnum = nEnum == MirrorGraph::Vertical ||
51 nEnum == MirrorGraph::Both;
52 return bEnum != bToggle;
53}
54
56{
57 bool bEnum = nEnum == MirrorGraph::Vertical ||
58 nEnum == MirrorGraph::Both;
59 return bEnum;
60}
61
62bool SwMirrorGrf::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
63{
64 bool bRet = true;
65 bool bVal = false;
66 // vertical and horizontal were swapped at some point
67 nMemberId &= ~CONVERT_TWIPS;
68 switch ( nMemberId )
69 {
72 break;
75 break;
76 case MID_MIRROR_VERT:
79 break;
80 default:
81 OSL_ENSURE( false, "unknown MemberId" );
82 bRet = false;
83 }
84 rVal <<= bVal;
85 return bRet;
86}
87
88bool SwMirrorGrf::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
89{
90 bool bRet = true;
91 bool bVal = *o3tl::doAccess<bool>(rVal);
92 // vertical and horizontal were swapped at some point
93 nMemberId &= ~CONVERT_TWIPS;
94 switch ( nMemberId )
95 {
98 {
99 bool bIsVert = GetValue() == MirrorGraph::Horizontal ||
101 bool bOnOddPages = nMemberId == MID_MIRROR_HORZ_EVEN_PAGES ?
103 bool bOnEvenPages = nMemberId == MID_MIRROR_HORZ_ODD_PAGES ?
105 MirrorGraph nEnum = bOnOddPages ?
108 bool bToggle = bOnOddPages != bOnEvenPages;
109 SetValue(nEnum);
110 SetGrfToggle( bToggle );
111 }
112 break;
113 case MID_MIRROR_VERT:
114 if ( bVal )
115 {
118 else if ( GetValue() != MirrorGraph::Both )
120 }
121 else
122 {
123 if ( GetValue() == MirrorGraph::Both )
125 else if ( GetValue() == MirrorGraph::Horizontal )
127 }
128 break;
129 default:
130 OSL_ENSURE( false, "unknown MemberId" );
131 bRet = false;
132 }
133 return bRet;
134}
135
138{}
139
140SwCropGrf::SwCropGrf(sal_Int32 nL, sal_Int32 nR, sal_Int32 nT, sal_Int32 nB )
141 : SvxGrfCrop( nL, nR, nT, nB, RES_GRFATR_CROPGRF )
142{}
143
145{
146 return new SwCropGrf( *this );
147}
148
150{
151 if (nValue < 0_deg10)
152 {
153 // smaller zero, modulo (will keep negative) and add one range
154 DBG_ASSERT(false, "SwRotationGrf: Value is in 10th degree and *has* to be in [0 .. 3600[ (!)");
155 return 3600_deg10 + nValue % 3600_deg10;
156 }
157 else if (nValue >= 3600_deg10)
158 {
159 // bigger range, use modulo
160 DBG_ASSERT(false, "SwRotationGrf: Value is in 10th degree and *has* to be in [0 .. 3600[ (!)");
161 return nValue % 3600_deg10;
162 }
163
164 return nValue;
165}
166
168 // tdf#115529 check and evtl. correct value
169: SfxUInt16Item( RES_GRFATR_ROTATION, checkAndCorrectValue(nVal).get() ),
170 m_aUnrotatedSize( rSz )
171{
172}
173
175{
176 return new SwRotationGrf( *this );
177}
178
179bool SwRotationGrf::operator==( const SfxPoolItem& rCmp ) const
180{
181 return SfxUInt16Item::operator==( rCmp ) &&
182 GetUnrotatedSize() == static_cast<const SwRotationGrf&>(rCmp).GetUnrotatedSize();
183}
184
186{
187 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
188 // where we still want this to be a sal_Int16
189 rVal <<= static_cast<sal_Int16>(GetValue());
190 return true;
191}
192
194{
195 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
196 // where we still want this to be a sal_Int16
197 sal_Int16 nValue = 0;
198 if (rVal >>= nValue)
199 {
200 // sal_uInt16 argument needed
201 // tdf#115529 check and evtl. correct value
203 return true;
204 }
205
206 OSL_FAIL( "SwRotationGrf::PutValue - Wrong type!" );
207 return false;
208}
209
210// Sw___Grf::Clone(..)
211
213{
214 return new SwLuminanceGrf( *this );
215}
216
218{
219 return new SwContrastGrf( *this );
220}
221
223{
224 return new SwChannelRGrf( *this );
225}
226
228{
229 return new SwChannelGGrf( *this );
230}
231
233{
234 return new SwChannelBGrf( *this );
235}
236
238{
239 return new SwGammaGrf( *this );
240}
241
242// SwGammaGrf
243
244bool SwGammaGrf::operator==( const SfxPoolItem& rCmp ) const
245{
246 return SfxPoolItem::operator==( rCmp ) &&
247 m_nValue == static_cast<const SwGammaGrf&>(rCmp).GetValue();
248}
249
251{
252 rVal <<= m_nValue;
253 return true;
254}
255
257{
258 return rVal >>= m_nValue;
259}
260
261// Sw___Grf::Clone(..) cont'd
262
264{
265 return new SwInvertGrf( *this );
266}
267
269{
270 return new SwTransparencyGrf( *this );
271}
272
273// SwTransparencyGrf
274
276 sal_uInt8 ) const
277{
278 //OSL_ENSURE(dynamic_cast<const SfxByteItem*>( this ) != nullptr,"Put/QueryValue should be removed!");
279 SAL_WARN("sw", "Put/QueryValue should be removed!");
280 sal_Int16 nRet = GetValue();
281 OSL_ENSURE( 0 <= nRet && nRet <= 100, "value out of range" );
282 rVal <<= nRet;
283 return true;
284}
285
287 sal_uInt8 )
288{
289 //temporary conversion until this is a SfxInt16Item!
290 //OSL_ENSURE(dynamic_cast<const SfxByteItem*>( this ) != nullptr,"Put/QueryValue should be removed!");
291 SAL_WARN("sw", "Put/QueryValue should be removed!");
292 sal_Int16 nVal = 0;
293 if(!(rVal >>= nVal) || nVal < -100 || nVal > 100)
294 return false;
295 if(nVal < 0)
296 {
297 // for compatibility with old documents
298 // introduce rounding as for SO 6.0 PP2
299 nVal = ( ( nVal * 128 ) - (99/2) ) / 100;
300 nVal += 128;
301 }
302 OSL_ENSURE( 0 <= nVal && nVal <= 100, "value out of range" );
303 SetValue(static_cast<sal_uInt8>(nVal));
304 return true;
305}
306
307// Sw___Grf::Clone(..) cont'd
308
310{
311 return new SwDrawModeGrf( *this );
312}
313
314// SwDrawModeGrf
315
317{
318 return sal_uInt16(GraphicDrawMode::Watermark) + 1;
319}
320
322 sal_uInt8 ) const
323{
324 drawing::ColorMode eRet = static_cast<drawing::ColorMode>(GetEnumValue());
325 rVal <<= eRet;
326 return true;
327}
328
330 sal_uInt8 )
331{
332 sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal );
333 if(eVal >= 0 && eVal <= sal_uInt16(GraphicDrawMode::Watermark))
334 {
335 SetEnumValue(o3tl::narrowing<sal_uInt16>(eVal));
336 return true;
337 }
338 return false;
339}
340
341/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(sal_uInt8 nTheValue)
sal_uInt8 GetValue() const
virtual bool operator==(const SfxPoolItem &rItem) const override
virtual sal_uInt16 GetEnumValue() const override
void SetValue(EnumT nTheValue)
virtual void SetEnumValue(sal_uInt16 nTheValue) override
virtual bool operator==(SfxPoolItem const &other) const override
virtual bool operator==(const SfxPoolItem &) const=0
SwChannelBGrf(sal_Int16 nVal=0)
Definition: grfatr.hxx:180
virtual SwChannelBGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:232
SwChannelGGrf(sal_Int16 nVal=0)
Definition: grfatr.hxx:172
virtual SwChannelGGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:227
SwChannelRGrf(sal_Int16 nVal=0)
Definition: grfatr.hxx:164
virtual SwChannelRGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:222
SwContrastGrf(sal_Int16 nVal=0)
Definition: grfatr.hxx:132
virtual SwContrastGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:217
virtual SwCropGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:144
SwCropGrf()
Definition: grfatr.cxx:136
virtual SwDrawModeGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:309
virtual sal_uInt16 GetValueCount() const override
Definition: grfatr.cxx:316
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:329
SwDrawModeGrf(GraphicDrawMode nMode=GraphicDrawMode::Standard)
Definition: grfatr.hxx:260
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:321
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:244
const double & GetValue() const
Definition: grfatr.hxx:211
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:256
double m_nValue
Definition: grfatr.hxx:188
virtual SwGammaGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:237
SwGammaGrf()
Definition: grfatr.hxx:190
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:250
virtual SwInvertGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:263
SwInvertGrf(bool bVal=false)
Definition: grfatr.hxx:217
virtual SwLuminanceGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:212
SwLuminanceGrf(sal_Int16 nVal=0)
Definition: grfatr.hxx:116
virtual SwMirrorGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:32
SwMirrorGrf(MirrorGraph eMiro=MirrorGraph::Dont)
Definition: grfatr.hxx:44
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:42
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:62
bool IsGrfToggle() const
Definition: grfatr.hxx:65
void SetGrfToggle(bool bNew)
Definition: grfatr.hxx:66
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:88
virtual sal_uInt16 GetValueCount() const override
Definition: grfatr.cxx:37
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:185
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:179
static Degree10 checkAndCorrectValue(Degree10 nValue)
Definition: grfatr.cxx:149
virtual SwRotationGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:174
const Size & GetUnrotatedSize() const
Definition: grfatr.hxx:108
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:193
void SetValue(Degree10 d)
Definition: grfatr.hxx:110
Degree10 GetValue() const
Definition: grfatr.hxx:109
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:275
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:286
SwTransparencyGrf(sal_Int8 nVal=0)
Definition: grfatr.hxx:233
virtual SwTransparencyGrf * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:268
#define DBG_ASSERT(sCon, aError)
sal_Int16 nValue
static bool lcl_IsHoriOnEvenPages(MirrorGraph nEnum, bool bToggle)
Definition: grfatr.cxx:48
static bool lcl_IsHoriOnOddPages(MirrorGraph nEnum)
Definition: grfatr.cxx:55
MirrorGraph
Definition: grfatr.hxx:32
constexpr TypedWhichId< SwCropGrf > RES_GRFATR_CROPGRF(134)
constexpr TypedWhichId< SwRotationGrf > RES_GRFATR_ROTATION(135)
#define SAL_WARN(area, stream)
sal_Int32 GetEnumAsInt32(const css::uno::Any &rVal)
Definition: swunohelper.cxx:50
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
unsigned char sal_uInt8
#define MID_MIRROR_HORZ_ODD_PAGES
Definition: unomid.h:24
#define MID_MIRROR_VERT
Definition: unomid.h:22
#define MID_MIRROR_HORZ_EVEN_PAGES
Definition: unomid.h:23