Update ooo320-m1
[ooovba.git] / sw / source / core / graphic / grfatr.cxx
blob66c1fd5f6401ad3e79e86bb23d75db22504e1b82
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grfatr.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <com/sun/star/text/RelOrientation.hpp>
36 #include <com/sun/star/text/VertOrientation.hpp>
37 #include <com/sun/star/text/HorizontalAdjust.hpp>
38 #include <com/sun/star/text/DocumentStatistic.hpp>
39 #include <com/sun/star/text/HoriOrientation.hpp>
40 #include <com/sun/star/text/HoriOrientationFormat.hpp>
41 #include <com/sun/star/text/NotePrintMode.hpp>
42 #include <com/sun/star/text/SizeType.hpp>
43 #include <com/sun/star/text/VertOrientationFormat.hpp>
44 #include <com/sun/star/text/WrapTextMode.hpp>
45 #include <com/sun/star/text/GraphicCrop.hpp>
46 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
47 #include <com/sun/star/drawing/ColorMode.hpp>
48 #include <goodies/grfmgr.hxx>
49 #include <swtypes.hxx>
50 #include <grfatr.hxx>
51 #include <swunohelper.hxx>
53 #ifndef _CMDID_H
54 #include <cmdid.h>
55 #endif
56 #ifndef _UNOMID_H
57 #include <unomid.h>
58 #endif
60 using namespace ::com::sun::star;
62 TYPEINIT1_AUTOFACTORY(SwCropGrf, SfxPoolItem)
63 TYPEINIT1_AUTOFACTORY(SwGammaGrf, SfxPoolItem)
65 /******************************************************************************
66 * Implementierung class SwMirrorGrf
67 ******************************************************************************/
69 SfxPoolItem* SwMirrorGrf::Clone( SfxItemPool* ) const
71 return new SwMirrorGrf( *this );
74 sal_uInt16 SwMirrorGrf::GetValueCount() const
76 return RES_MIRROR_GRAPH_END - RES_MIRROR_GRAPH_BEGIN;
79 int SwMirrorGrf::operator==( const SfxPoolItem& rItem) const
81 return SfxEnumItem::operator==(rItem) &&
82 ((SwMirrorGrf&)rItem).IsGrfToggle() == IsGrfToggle();
85 BOOL lcl_IsHoriOnEvenPages(int nEnum, BOOL bToggle)
87 BOOL bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
88 nEnum == RES_MIRROR_GRAPH_BOTH;
89 return bEnum != bToggle;
91 BOOL lcl_IsHoriOnOddPages(int nEnum)
93 BOOL bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
94 nEnum == RES_MIRROR_GRAPH_BOTH;
95 return bEnum;
97 BOOL SwMirrorGrf::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
99 sal_Bool bRet = sal_True,
100 bVal;
101 // Vertikal und Horizontal sind mal getauscht worden!
102 nMemberId &= ~CONVERT_TWIPS;
103 switch ( nMemberId )
105 case MID_MIRROR_HORZ_EVEN_PAGES:
106 bVal = lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle());
107 break;
108 case MID_MIRROR_HORZ_ODD_PAGES:
109 bVal = lcl_IsHoriOnOddPages(GetValue());
110 break;
111 case MID_MIRROR_VERT:
112 bVal = GetValue() == RES_MIRROR_GRAPH_HOR ||
113 GetValue() == RES_MIRROR_GRAPH_BOTH;
114 break;
115 default:
116 ASSERT( !this, "unknown MemberId" );
117 bRet = sal_False;
119 rVal.setValue( &bVal, ::getBooleanCppuType() );
120 return bRet;
123 BOOL SwMirrorGrf::PutValue( const uno::Any& rVal, BYTE nMemberId )
125 sal_Bool bRet = sal_True;
126 sal_Bool bVal = *(sal_Bool*)rVal.getValue();
127 // Vertikal und Horizontal sind mal getauscht worden!
128 nMemberId &= ~CONVERT_TWIPS;
129 switch ( nMemberId )
131 case MID_MIRROR_HORZ_EVEN_PAGES:
132 case MID_MIRROR_HORZ_ODD_PAGES:
134 BOOL bIsVert = GetValue() == RES_MIRROR_GRAPH_HOR ||
135 GetValue() == RES_MIRROR_GRAPH_BOTH;
136 BOOL bOnOddPages = nMemberId == MID_MIRROR_HORZ_EVEN_PAGES ?
137 lcl_IsHoriOnOddPages(GetValue()) : bVal;
138 BOOL bOnEvenPages = nMemberId == MID_MIRROR_HORZ_ODD_PAGES ?
139 lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle()) : bVal;
140 MirrorGraph nEnum = bOnOddPages ?
141 bIsVert ? RES_MIRROR_GRAPH_BOTH : RES_MIRROR_GRAPH_VERT :
142 bIsVert ? RES_MIRROR_GRAPH_HOR : RES_MIRROR_GRAPH_DONT;
143 BOOL bToggle = bOnOddPages != bOnEvenPages;
144 SetValue(static_cast<USHORT>(nEnum));
145 SetGrfToggle( bToggle );
147 break;
148 case MID_MIRROR_VERT:
149 if ( bVal )
151 if ( GetValue() == RES_MIRROR_GRAPH_VERT )
152 SetValue( RES_MIRROR_GRAPH_BOTH );
153 else if ( GetValue() != RES_MIRROR_GRAPH_BOTH )
154 SetValue( RES_MIRROR_GRAPH_HOR );
156 else
158 if ( GetValue() == RES_MIRROR_GRAPH_BOTH )
159 SetValue( RES_MIRROR_GRAPH_VERT );
160 else if ( GetValue() == RES_MIRROR_GRAPH_HOR )
161 SetValue( RES_MIRROR_GRAPH_DONT );
163 break;
164 default:
165 ASSERT( !this, "unknown MemberId" );
166 bRet = sal_False;
168 return bRet;
172 /******************************************************************************
173 * Implementierung class SwCropGrf
174 ******************************************************************************/
176 SwCropGrf::SwCropGrf()
177 : SvxGrfCrop( RES_GRFATR_CROPGRF )
180 SwCropGrf::SwCropGrf(sal_Int32 nL, sal_Int32 nR, sal_Int32 nT, sal_Int32 nB )
181 : SvxGrfCrop( nL, nR, nT, nB, RES_GRFATR_CROPGRF )
184 SfxPoolItem* SwCropGrf::Clone( SfxItemPool* ) const
186 return new SwCropGrf( *this );
189 // ------------------------------------------------------------------
191 SfxPoolItem* SwRotationGrf::Clone( SfxItemPool * ) const
193 return new SwRotationGrf( GetValue(), aUnrotatedSize );
197 int SwRotationGrf::operator==( const SfxPoolItem& rCmp ) const
199 return SfxUInt16Item::operator==( rCmp ) &&
200 GetUnrotatedSize() == ((SwRotationGrf&)rCmp).GetUnrotatedSize();
204 BOOL SwRotationGrf::QueryValue( uno::Any& rVal, BYTE ) const
206 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
207 // where we still want this to be a sal_Int16
208 rVal <<= (sal_Int16)GetValue();
209 return TRUE;
212 BOOL SwRotationGrf::PutValue( const uno::Any& rVal, BYTE )
214 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
215 // where we still want this to be a sal_Int16
216 sal_Int16 nValue = 0;
217 if (rVal >>= nValue)
219 // UINT16 argument needed
220 SetValue( (UINT16) nValue );
221 return TRUE;
224 DBG_ERROR( "SwRotationGrf::PutValue - Wrong type!" );
225 return FALSE;
228 // ------------------------------------------------------------------
230 SfxPoolItem* SwLuminanceGrf::Clone( SfxItemPool * ) const
232 return new SwLuminanceGrf( *this );
235 // ------------------------------------------------------------------
237 SfxPoolItem* SwContrastGrf::Clone( SfxItemPool * ) const
239 return new SwContrastGrf( *this );
242 // ------------------------------------------------------------------
244 SfxPoolItem* SwChannelRGrf::Clone( SfxItemPool * ) const
246 return new SwChannelRGrf( *this );
249 // ------------------------------------------------------------------
251 SfxPoolItem* SwChannelGGrf::Clone( SfxItemPool * ) const
253 return new SwChannelGGrf( *this );
256 // ------------------------------------------------------------------
258 SfxPoolItem* SwChannelBGrf::Clone( SfxItemPool * ) const
260 return new SwChannelBGrf( *this );
263 // ------------------------------------------------------------------
265 SfxPoolItem* SwGammaGrf::Clone( SfxItemPool * ) const
267 return new SwGammaGrf( *this );
270 int SwGammaGrf::operator==( const SfxPoolItem& rCmp ) const
272 return SfxPoolItem::operator==( rCmp ) &&
273 nValue == ((SwGammaGrf&)rCmp).GetValue();
276 BOOL SwGammaGrf::QueryValue( uno::Any& rVal, BYTE ) const
278 rVal <<= nValue;
279 return sal_True;
282 BOOL SwGammaGrf::PutValue( const uno::Any& rVal, BYTE )
284 return rVal >>= nValue;
287 // ------------------------------------------------------------------
289 SfxPoolItem* SwInvertGrf::Clone( SfxItemPool * ) const
291 return new SwInvertGrf( *this );
294 // ------------------------------------------------------------------
296 SfxPoolItem* SwTransparencyGrf::Clone( SfxItemPool * ) const
298 return new SwTransparencyGrf( *this );
300 // ------------------------------------------------------------------
301 BOOL SwTransparencyGrf::QueryValue( uno::Any& rVal,
302 BYTE ) const
304 DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
305 sal_Int16 nRet = GetValue();
306 DBG_ASSERT( 0 <= nRet && nRet <= 100, "value out of range" );
307 rVal <<= nRet;
308 return TRUE;
310 // ------------------------------------------------------------------
311 BOOL SwTransparencyGrf::PutValue( const uno::Any& rVal,
312 BYTE )
314 //temporary conversion until this is a SfxInt16Item!
315 DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
316 sal_Int16 nVal = 0;
317 if(!(rVal >>= nVal) || nVal < -100 || nVal > 100)
318 return FALSE;
319 if(nVal < 0)
321 // for compatibility with old documents
322 // OD 05.11.2002 #104308# - introduce rounding as for SO 6.0 PP2
323 // introduced by fix of #104293#.
324 nVal = ( ( nVal * 128 ) - (99/2) ) / 100;
325 nVal += 128;
327 DBG_ASSERT( 0 <= nVal && nVal <= 100, "value out of range" );
328 SetValue(static_cast<BYTE>(nVal));
329 return TRUE;
332 // ------------------------------------------------------------------
334 SfxPoolItem* SwDrawModeGrf::Clone( SfxItemPool * ) const
336 return new SwDrawModeGrf( *this );
339 USHORT SwDrawModeGrf::GetValueCount() const
341 // GRAPHICDRAWMODE_STANDARD = 0,
342 // GRAPHICDRAWMODE_GREYS = 1,
343 // GRAPHICDRAWMODE_MONO = 2,
344 // GRAPHICDRAWMODE_WATERMARK = 3
345 return GRAPHICDRAWMODE_WATERMARK + 1;
348 BOOL SwDrawModeGrf::QueryValue( uno::Any& rVal,
349 BYTE ) const
351 drawing::ColorMode eRet = (drawing::ColorMode)GetEnumValue();
352 rVal <<= eRet;
353 return TRUE;
356 BOOL SwDrawModeGrf::PutValue( const uno::Any& rVal,
357 BYTE )
359 sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal );
360 if(eVal >= 0 && eVal <= GRAPHICDRAWMODE_WATERMARK)
362 SetEnumValue((USHORT)eVal);
363 return TRUE;
365 return FALSE;