xref: /AOO42X/main/sw/source/core/graphic/grfatr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <com/sun/star/text/RelOrientation.hpp>
33 #include <com/sun/star/text/VertOrientation.hpp>
34 #include <com/sun/star/text/HorizontalAdjust.hpp>
35 #include <com/sun/star/text/DocumentStatistic.hpp>
36 #include <com/sun/star/text/HoriOrientation.hpp>
37 #include <com/sun/star/text/HoriOrientationFormat.hpp>
38 #include <com/sun/star/text/NotePrintMode.hpp>
39 #include <com/sun/star/text/SizeType.hpp>
40 #include <com/sun/star/text/VertOrientationFormat.hpp>
41 #include <com/sun/star/text/WrapTextMode.hpp>
42 #include <com/sun/star/text/GraphicCrop.hpp>
43 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
44 #include <com/sun/star/drawing/ColorMode.hpp>
45 #include <svtools/grfmgr.hxx>
46 #include <swtypes.hxx>
47 #include <grfatr.hxx>
48 #include <swunohelper.hxx>
49 
50 #ifndef _CMDID_H
51 #include <cmdid.h>
52 #endif
53 #ifndef _UNOMID_H
54 #include <unomid.h>
55 #endif
56 
57 using namespace ::com::sun::star;
58 
59 TYPEINIT1_AUTOFACTORY(SwCropGrf, SfxPoolItem)
60 TYPEINIT1_AUTOFACTORY(SwGammaGrf, SfxPoolItem)
61 
62 /******************************************************************************
63  *  Implementierung     class SwMirrorGrf
64  ******************************************************************************/
65 
66 SfxPoolItem* SwMirrorGrf::Clone( SfxItemPool* ) const
67 {
68     return new SwMirrorGrf( *this );
69 }
70 
71 sal_uInt16 SwMirrorGrf::GetValueCount() const
72 {
73     return RES_MIRROR_GRAPH_END - RES_MIRROR_GRAPH_BEGIN;
74 }
75 
76 int SwMirrorGrf::operator==( const SfxPoolItem& rItem) const
77 {
78     return SfxEnumItem::operator==(rItem) &&
79             ((SwMirrorGrf&)rItem).IsGrfToggle() == IsGrfToggle();
80 }
81 
82 sal_Bool lcl_IsHoriOnEvenPages(int nEnum, sal_Bool bToggle)
83 {
84     sal_Bool bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
85                    nEnum == RES_MIRROR_GRAPH_BOTH;
86             return bEnum != bToggle;
87 }
88 sal_Bool lcl_IsHoriOnOddPages(int nEnum)
89 {
90     sal_Bool bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
91                    nEnum == RES_MIRROR_GRAPH_BOTH;
92             return bEnum;
93 }
94 sal_Bool SwMirrorGrf::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
95 {
96     sal_Bool bRet = sal_True,
97          bVal;
98     // Vertikal und Horizontal sind mal getauscht worden!
99     nMemberId &= ~CONVERT_TWIPS;
100     switch ( nMemberId )
101     {
102         case MID_MIRROR_HORZ_EVEN_PAGES:
103             bVal = lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle());
104         break;
105         case MID_MIRROR_HORZ_ODD_PAGES:
106             bVal = lcl_IsHoriOnOddPages(GetValue());
107         break;
108         case MID_MIRROR_VERT:
109             bVal = GetValue() == RES_MIRROR_GRAPH_HOR ||
110                    GetValue() == RES_MIRROR_GRAPH_BOTH;
111             break;
112         default:
113             ASSERT( !this, "unknown MemberId" );
114             bRet = sal_False;
115     }
116     rVal.setValue( &bVal, ::getBooleanCppuType() );
117     return bRet;
118 }
119 
120 sal_Bool SwMirrorGrf::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
121 {
122     sal_Bool bRet = sal_True;
123     sal_Bool bVal = *(sal_Bool*)rVal.getValue();
124     // Vertikal und Horizontal sind mal getauscht worden!
125     nMemberId &= ~CONVERT_TWIPS;
126     switch ( nMemberId )
127     {
128         case MID_MIRROR_HORZ_EVEN_PAGES:
129         case MID_MIRROR_HORZ_ODD_PAGES:
130         {
131             sal_Bool bIsVert = GetValue() == RES_MIRROR_GRAPH_HOR ||
132                                 GetValue() == RES_MIRROR_GRAPH_BOTH;
133             sal_Bool bOnOddPages = nMemberId == MID_MIRROR_HORZ_EVEN_PAGES ?
134                                     lcl_IsHoriOnOddPages(GetValue()) : bVal;
135             sal_Bool bOnEvenPages = nMemberId == MID_MIRROR_HORZ_ODD_PAGES ?
136                                        lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle()) : bVal;
137             MirrorGraph nEnum = bOnOddPages ?
138                     bIsVert ? RES_MIRROR_GRAPH_BOTH : RES_MIRROR_GRAPH_VERT :
139                         bIsVert ? RES_MIRROR_GRAPH_HOR : RES_MIRROR_GRAPH_DONT;
140             sal_Bool bToggle = bOnOddPages != bOnEvenPages;
141             SetValue(static_cast<sal_uInt16>(nEnum));
142             SetGrfToggle( bToggle );
143         }
144         break;
145         case MID_MIRROR_VERT:
146             if ( bVal )
147             {
148                 if ( GetValue() == RES_MIRROR_GRAPH_VERT )
149                     SetValue( RES_MIRROR_GRAPH_BOTH );
150                 else if ( GetValue() != RES_MIRROR_GRAPH_BOTH )
151                     SetValue( RES_MIRROR_GRAPH_HOR );
152             }
153             else
154             {
155                 if ( GetValue() == RES_MIRROR_GRAPH_BOTH )
156                     SetValue( RES_MIRROR_GRAPH_VERT );
157                 else if ( GetValue() == RES_MIRROR_GRAPH_HOR )
158                     SetValue( RES_MIRROR_GRAPH_DONT );
159             }
160             break;
161         default:
162             ASSERT( !this, "unknown MemberId" );
163             bRet = sal_False;
164     }
165     return bRet;
166 }
167 
168 
169 /******************************************************************************
170  *  Implementierung     class SwCropGrf
171  ******************************************************************************/
172 
173 SwCropGrf::SwCropGrf()
174     : SvxGrfCrop( RES_GRFATR_CROPGRF )
175 {}
176 
177 SwCropGrf::SwCropGrf(sal_Int32 nL, sal_Int32 nR, sal_Int32 nT, sal_Int32 nB )
178     : SvxGrfCrop( nL, nR, nT, nB, RES_GRFATR_CROPGRF )
179 {}
180 
181 SfxPoolItem* SwCropGrf::Clone( SfxItemPool* ) const
182 {
183     return new SwCropGrf( *this );
184 }
185 
186 // ------------------------------------------------------------------
187 
188 SfxPoolItem* SwRotationGrf::Clone( SfxItemPool * ) const
189 {
190     return new SwRotationGrf( GetValue(), aUnrotatedSize );
191 }
192 
193 
194 int SwRotationGrf::operator==( const SfxPoolItem& rCmp ) const
195 {
196     return SfxUInt16Item::operator==( rCmp ) &&
197         GetUnrotatedSize() == ((SwRotationGrf&)rCmp).GetUnrotatedSize();
198 }
199 
200 
201 sal_Bool SwRotationGrf::QueryValue( uno::Any& rVal, sal_uInt8 ) const
202 {
203     // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
204     // where we still want this to be a sal_Int16
205     rVal <<= (sal_Int16)GetValue();
206     return sal_True;
207 }
208 
209 sal_Bool SwRotationGrf::PutValue( const uno::Any& rVal, sal_uInt8 )
210 {
211     // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
212     // where we still want this to be a sal_Int16
213     sal_Int16 nValue = 0;
214     if (rVal >>= nValue)
215     {
216         // sal_uInt16 argument needed
217         SetValue( (sal_uInt16) nValue );
218         return sal_True;
219     }
220 
221     DBG_ERROR( "SwRotationGrf::PutValue - Wrong type!" );
222     return sal_False;
223 }
224 
225 // ------------------------------------------------------------------
226 
227 SfxPoolItem* SwLuminanceGrf::Clone( SfxItemPool * ) const
228 {
229     return new SwLuminanceGrf( *this );
230 }
231 
232 // ------------------------------------------------------------------
233 
234 SfxPoolItem* SwContrastGrf::Clone( SfxItemPool * ) const
235 {
236     return new SwContrastGrf( *this );
237 }
238 
239 // ------------------------------------------------------------------
240 
241 SfxPoolItem* SwChannelRGrf::Clone( SfxItemPool * ) const
242 {
243     return new SwChannelRGrf( *this );
244 }
245 
246 // ------------------------------------------------------------------
247 
248 SfxPoolItem* SwChannelGGrf::Clone( SfxItemPool * ) const
249 {
250     return new SwChannelGGrf( *this );
251 }
252 
253 // ------------------------------------------------------------------
254 
255 SfxPoolItem* SwChannelBGrf::Clone( SfxItemPool * ) const
256 {
257     return new SwChannelBGrf( *this );
258 }
259 
260 // ------------------------------------------------------------------
261 
262 SfxPoolItem* SwGammaGrf::Clone( SfxItemPool * ) const
263 {
264     return new SwGammaGrf( *this );
265 }
266 
267 int SwGammaGrf::operator==( const SfxPoolItem& rCmp ) const
268 {
269     return SfxPoolItem::operator==( rCmp ) &&
270         nValue == ((SwGammaGrf&)rCmp).GetValue();
271 }
272 
273 sal_Bool SwGammaGrf::QueryValue( uno::Any& rVal, sal_uInt8 ) const
274 {
275     rVal <<= nValue;
276     return sal_True;
277 }
278 
279 sal_Bool SwGammaGrf::PutValue( const uno::Any& rVal, sal_uInt8 )
280 {
281     return rVal >>= nValue;
282 }
283 
284 // ------------------------------------------------------------------
285 
286 SfxPoolItem* SwInvertGrf::Clone( SfxItemPool * ) const
287 {
288     return new SwInvertGrf( *this );
289 }
290 
291 // ------------------------------------------------------------------
292 
293 SfxPoolItem* SwTransparencyGrf::Clone( SfxItemPool * ) const
294 {
295     return new SwTransparencyGrf( *this );
296 }
297 // ------------------------------------------------------------------
298 sal_Bool SwTransparencyGrf::QueryValue( uno::Any& rVal,
299                                         sal_uInt8 ) const
300 {
301     DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
302     sal_Int16 nRet = GetValue();
303     DBG_ASSERT( 0 <= nRet && nRet <= 100, "value out of range" );
304     rVal <<= nRet;
305     return sal_True;
306 }
307 // ------------------------------------------------------------------
308 sal_Bool SwTransparencyGrf::PutValue( const uno::Any& rVal,
309                                         sal_uInt8 )
310 {
311     //temporary conversion until this is a SfxInt16Item!
312     DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
313     sal_Int16 nVal = 0;
314     if(!(rVal >>= nVal) || nVal < -100 || nVal > 100)
315         return sal_False;
316     if(nVal < 0)
317     {
318         // for compatibility with old documents
319         // OD 05.11.2002 #104308# - introduce rounding as for SO 6.0 PP2
320         // introduced by fix of #104293#.
321         nVal = ( ( nVal * 128 ) - (99/2) ) / 100;
322         nVal += 128;
323     }
324     DBG_ASSERT( 0 <= nVal && nVal <= 100, "value out of range" );
325     SetValue(static_cast<sal_uInt8>(nVal));
326     return sal_True;
327 }
328 
329 // ------------------------------------------------------------------
330 
331 SfxPoolItem* SwDrawModeGrf::Clone( SfxItemPool * ) const
332 {
333     return new SwDrawModeGrf( *this );
334 }
335 
336 sal_uInt16 SwDrawModeGrf::GetValueCount() const
337 {
338     // GRAPHICDRAWMODE_STANDARD = 0,
339     // GRAPHICDRAWMODE_GREYS = 1,
340     // GRAPHICDRAWMODE_MONO = 2,
341     // GRAPHICDRAWMODE_WATERMARK = 3
342     return GRAPHICDRAWMODE_WATERMARK + 1;
343 }
344 
345 sal_Bool SwDrawModeGrf::QueryValue( uno::Any& rVal,
346                                 sal_uInt8 ) const
347 {
348     drawing::ColorMode eRet = (drawing::ColorMode)GetEnumValue();
349     rVal <<= eRet;
350     return sal_True;
351 }
352 
353 sal_Bool SwDrawModeGrf::PutValue( const uno::Any& rVal,
354                                 sal_uInt8 )
355 {
356     sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal );
357     if(eVal >= 0 && eVal <= GRAPHICDRAWMODE_WATERMARK)
358     {
359         SetEnumValue((sal_uInt16)eVal);
360         return sal_True;
361     }
362     return sal_False;
363 }
364 
365 
366 
367