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