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 <grfatr.hxx>
24 #include <swunohelper.hxx>
25 #include <osl/diagnose.h>
26 
27 #include <unomid.h>
28 
29 using namespace ::com::sun::star;
30 
31 
33 {
34  return new SwMirrorGrf( *this );
35 }
36 
37 sal_uInt16 SwMirrorGrf::GetValueCount() const
38 {
39  return 4;
40 }
41 
42 bool SwMirrorGrf::operator==( const SfxPoolItem& rItem) const
43 {
44  return SfxEnumItem::operator==(static_cast<const SfxEnumItem<MirrorGraph>&>(rItem)) &&
45  static_cast<const SwMirrorGrf&>(rItem).IsGrfToggle() == IsGrfToggle();
46 }
47 
48 static 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 
62 bool 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:
77  bVal = GetValue() == MirrorGraph::Horizontal ||
79  break;
80  default:
81  OSL_ENSURE( false, "unknown MemberId" );
82  bRet = false;
83  }
84  rVal <<= bVal;
85  return bRet;
86 }
87 
88 bool 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 ?
102  lcl_IsHoriOnOddPages(GetValue()) : bVal;
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  {
116  if ( GetValue() == MirrorGraph::Vertical )
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 
140 SwCropGrf::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 
149 sal_Int16 SwRotationGrf::checkAndCorrectValue(sal_Int16 nValue)
150 {
151  if(nValue < 0)
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 + (nValue % 3600);
156  }
157  else if (nValue >= 3600)
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;
162  }
163 
164  return nValue;
165 }
166 
167 SwRotationGrf::SwRotationGrf( sal_Int16 nVal, const Size& rSz )
168  // tdf#115529 check and evtl. correct value
169 : SfxUInt16Item( RES_GRFATR_ROTATION, checkAndCorrectValue(nVal) ),
170  m_aUnrotatedSize( rSz )
171 {
172 }
173 
175 {
176  return new SwRotationGrf( *this );
177 }
178 
179 bool 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
202  SetValue(static_cast<sal_uInt16>(checkAndCorrectValue(nValue)));
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 
244 bool 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_Int16 nRet = GetValue();
280  OSL_ENSURE( 0 <= nRet && nRet <= 100, "value out of range" );
281  rVal <<= nRet;
282  return true;
283 }
284 
286  sal_uInt8 )
287 {
288  //temporary conversion until this is a SfxInt16Item!
289  OSL_ENSURE(dynamic_cast<const SfxByteItem*>( this ) != nullptr,"Put/QueryValue should be removed!");
290  sal_Int16 nVal = 0;
291  if(!(rVal >>= nVal) || nVal < -100 || nVal > 100)
292  return false;
293  if(nVal < 0)
294  {
295  // for compatibility with old documents
296  // introduce rounding as for SO 6.0 PP2
297  nVal = ( ( nVal * 128 ) - (99/2) ) / 100;
298  nVal += 128;
299  }
300  OSL_ENSURE( 0 <= nVal && nVal <= 100, "value out of range" );
301  SetValue(static_cast<sal_uInt8>(nVal));
302  return true;
303 }
304 
305 // Sw___Grf::Clone(..) cont'd
306 
308 {
309  return new SwDrawModeGrf( *this );
310 }
311 
312 // SwDrawModeGrf
313 
315 {
316  return sal_uInt16(GraphicDrawMode::Watermark) + 1;
317 }
318 
320  sal_uInt8 ) const
321 {
322  drawing::ColorMode eRet = static_cast<drawing::ColorMode>(GetEnumValue());
323  rVal <<= eRet;
324  return true;
325 }
326 
328  sal_uInt8 )
329 {
330  sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal );
331  if(eVal >= 0 && eVal <= sal_uInt16(GraphicDrawMode::Watermark))
332  {
333  SetEnumValue(static_cast<sal_uInt16>(eVal));
334  return true;
335  }
336  return false;
337 }
338 
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt16 GetValueCount() const override
Definition: grfatr.cxx:314
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:179
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:237
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:275
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:37
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:227
sal_uInt16 GetValue() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:144
MirrorGraph
Definition: grfatr.hxx:31
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:62
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:307
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:185
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:193
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:88
static bool lcl_IsHoriOnOddPages(MirrorGraph nEnum)
Definition: grfatr.cxx:55
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:244
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:285
#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:327
SwCropGrf()
Definition: grfatr.cxx:136
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfatr.cxx:256
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:217
SwDrawModeGrf(GraphicDrawMode nMode=GraphicDrawMode::Standard)
Definition: grfatr.hxx:258
double m_nValue
Definition: grfatr.hxx:186
#define DBG_ASSERT(sCon, aError)
void SetValue(EnumT nTheValue)
#define RES_GRFATR_ROTATION
Definition: hintids.hxx:244
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:32
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:232
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfatr.cxx:42
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:268
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:149
static bool lcl_IsHoriOnEvenPages(MirrorGraph nEnum, bool bToggle)
Definition: grfatr.cxx:48
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:242
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:263
SwGammaGrf()
Definition: grfatr.hxx:188
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:174
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfatr.cxx:319
sal_uInt8 GetValue() const
void SetValue(sal_uInt8 nTheValue)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:222
#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:250
#define CONVERT_TWIPS
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grfatr.cxx:212