xref: /trunk/main/sw/source/core/graphic/grfatr.cxx (revision 870262e3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <com/sun/star/text/RelOrientation.hpp>
29 #include <com/sun/star/text/VertOrientation.hpp>
30 #include <com/sun/star/text/HorizontalAdjust.hpp>
31 #include <com/sun/star/text/DocumentStatistic.hpp>
32 #include <com/sun/star/text/HoriOrientation.hpp>
33 #include <com/sun/star/text/HoriOrientationFormat.hpp>
34 #include <com/sun/star/text/NotePrintMode.hpp>
35 #include <com/sun/star/text/SizeType.hpp>
36 #include <com/sun/star/text/VertOrientationFormat.hpp>
37 #include <com/sun/star/text/WrapTextMode.hpp>
38 #include <com/sun/star/text/GraphicCrop.hpp>
39 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
40 #include <com/sun/star/drawing/ColorMode.hpp>
41 #include <svtools/grfmgr.hxx>
42 #include <swtypes.hxx>
43 #include <grfatr.hxx>
44 #include <swunohelper.hxx>
45 
46 #ifndef _CMDID_H
47 #include <cmdid.h>
48 #endif
49 #ifndef _UNOMID_H
50 #include <unomid.h>
51 #endif
52 
53 using namespace ::com::sun::star;
54 
TYPEINIT1_AUTOFACTORY(SwCropGrf,SfxPoolItem)55 TYPEINIT1_AUTOFACTORY(SwCropGrf, SfxPoolItem)
56 TYPEINIT1_AUTOFACTORY(SwGammaGrf, SfxPoolItem)
57 
58 /******************************************************************************
59  *	Implementierung		class SwMirrorGrf
60  ******************************************************************************/
61 
62 SfxPoolItem* SwMirrorGrf::Clone( SfxItemPool* ) const
63 {
64 	return new SwMirrorGrf( *this );
65 }
66 
GetValueCount() const67 sal_uInt16 SwMirrorGrf::GetValueCount() const
68 {
69     return RES_MIRROR_GRAPH_END - RES_MIRROR_GRAPH_BEGIN;
70 }
71 
operator ==(const SfxPoolItem & rItem) const72 int SwMirrorGrf::operator==( const SfxPoolItem& rItem) const
73 {
74 	return SfxEnumItem::operator==(rItem) &&
75 			((SwMirrorGrf&)rItem).IsGrfToggle() == IsGrfToggle();
76 }
77 
lcl_IsHoriOnEvenPages(int nEnum,sal_Bool bToggle)78 sal_Bool lcl_IsHoriOnEvenPages(int nEnum, sal_Bool bToggle)
79 {
80     sal_Bool bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
81                    nEnum == RES_MIRROR_GRAPH_BOTH;
82 			return bEnum != bToggle;
83 }
lcl_IsHoriOnOddPages(int nEnum)84 sal_Bool lcl_IsHoriOnOddPages(int nEnum)
85 {
86     sal_Bool bEnum = nEnum == RES_MIRROR_GRAPH_VERT ||
87                    nEnum == RES_MIRROR_GRAPH_BOTH;
88 			return bEnum;
89 }
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const90 sal_Bool SwMirrorGrf::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
91 {
92 	sal_Bool bRet = sal_True,
93 		 bVal;
94 	// Vertikal und Horizontal sind mal getauscht worden!
95     nMemberId &= ~CONVERT_TWIPS;
96 	switch ( nMemberId )
97 	{
98 		case MID_MIRROR_HORZ_EVEN_PAGES:
99 			bVal = lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle());
100 		break;
101 		case MID_MIRROR_HORZ_ODD_PAGES:
102 			bVal = lcl_IsHoriOnOddPages(GetValue());
103 		break;
104 		case MID_MIRROR_VERT:
105             bVal = GetValue() == RES_MIRROR_GRAPH_HOR ||
106                    GetValue() == RES_MIRROR_GRAPH_BOTH;
107 			break;
108 		default:
109 			ASSERT( sal_False, "unknown MemberId" );
110 			bRet = sal_False;
111 	}
112 	rVal.setValue( &bVal, ::getBooleanCppuType() );
113 	return bRet;
114 }
115 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)116 sal_Bool SwMirrorGrf::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
117 {
118 	sal_Bool bRet = sal_True;
119 	sal_Bool bVal = *(sal_Bool*)rVal.getValue();
120 	// Vertikal und Horizontal sind mal getauscht worden!
121     nMemberId &= ~CONVERT_TWIPS;
122 	switch ( nMemberId )
123 	{
124 		case MID_MIRROR_HORZ_EVEN_PAGES:
125 		case MID_MIRROR_HORZ_ODD_PAGES:
126 		{
127             sal_Bool bIsVert = GetValue() == RES_MIRROR_GRAPH_HOR ||
128                                 GetValue() == RES_MIRROR_GRAPH_BOTH;
129 			sal_Bool bOnOddPages = nMemberId == MID_MIRROR_HORZ_EVEN_PAGES ?
130 									lcl_IsHoriOnOddPages(GetValue()) : bVal;
131 			sal_Bool bOnEvenPages = nMemberId == MID_MIRROR_HORZ_ODD_PAGES ?
132 									   lcl_IsHoriOnEvenPages(GetValue(), IsGrfToggle()) : bVal;
133             MirrorGraph nEnum = bOnOddPages ?
134                     bIsVert ? RES_MIRROR_GRAPH_BOTH : RES_MIRROR_GRAPH_VERT :
135                         bIsVert ? RES_MIRROR_GRAPH_HOR : RES_MIRROR_GRAPH_DONT;
136 			sal_Bool bToggle = bOnOddPages != bOnEvenPages;
137 			SetValue(static_cast<sal_uInt16>(nEnum));
138 			SetGrfToggle( bToggle );
139 		}
140 		break;
141 		case MID_MIRROR_VERT:
142 			if ( bVal )
143 			{
144                 if ( GetValue() == RES_MIRROR_GRAPH_VERT )
145                     SetValue( RES_MIRROR_GRAPH_BOTH );
146                 else if ( GetValue() != RES_MIRROR_GRAPH_BOTH )
147                     SetValue( RES_MIRROR_GRAPH_HOR );
148 			}
149 			else
150 			{
151                 if ( GetValue() == RES_MIRROR_GRAPH_BOTH )
152                     SetValue( RES_MIRROR_GRAPH_VERT );
153                 else if ( GetValue() == RES_MIRROR_GRAPH_HOR )
154                     SetValue( RES_MIRROR_GRAPH_DONT );
155 			}
156 			break;
157 		default:
158 			ASSERT( sal_False, "unknown MemberId" );
159 			bRet = sal_False;
160 	}
161 	return bRet;
162 }
163 
164 
165 /******************************************************************************
166  *	Implementierung		class SwCropGrf
167  ******************************************************************************/
168 
SwCropGrf()169 SwCropGrf::SwCropGrf()
170 	: SvxGrfCrop( RES_GRFATR_CROPGRF )
171 {}
172 
SwCropGrf(sal_Int32 nL,sal_Int32 nR,sal_Int32 nT,sal_Int32 nB)173 SwCropGrf::SwCropGrf(sal_Int32 nL, sal_Int32 nR, sal_Int32 nT, sal_Int32 nB )
174 	: SvxGrfCrop( nL, nR, nT, nB, RES_GRFATR_CROPGRF )
175 {}
176 
Clone(SfxItemPool *) const177 SfxPoolItem* SwCropGrf::Clone( SfxItemPool* ) const
178 {
179 	return new SwCropGrf( *this );
180 }
181 
182 // ------------------------------------------------------------------
183 
Clone(SfxItemPool *) const184 SfxPoolItem* SwRotationGrf::Clone( SfxItemPool * ) const
185 {
186 	return new SwRotationGrf( GetValue(), aUnrotatedSize );
187 }
188 
189 
operator ==(const SfxPoolItem & rCmp) const190 int	SwRotationGrf::operator==( const SfxPoolItem& rCmp ) const
191 {
192 	return SfxUInt16Item::operator==( rCmp ) &&
193 		GetUnrotatedSize() == ((SwRotationGrf&)rCmp).GetUnrotatedSize();
194 }
195 
196 
QueryValue(uno::Any & rVal,sal_uInt8) const197 sal_Bool SwRotationGrf::QueryValue( uno::Any& rVal, sal_uInt8 ) const
198 {
199     // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
200     // where we still want this to be a sal_Int16
201     rVal <<= (sal_Int16)GetValue();
202     return sal_True;
203 }
204 
PutValue(const uno::Any & rVal,sal_uInt8)205 sal_Bool SwRotationGrf::PutValue( const uno::Any& rVal, sal_uInt8 )
206 {
207     // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
208     // where we still want this to be a sal_Int16
209     sal_Int16 nValue = 0;
210 	if (rVal >>= nValue)
211 	{
212         // sal_uInt16 argument needed
213         SetValue( (sal_uInt16) nValue );
214 		return sal_True;
215 	}
216 
217     DBG_ERROR( "SwRotationGrf::PutValue - Wrong type!" );
218 	return sal_False;
219 }
220 
221 // ------------------------------------------------------------------
222 
Clone(SfxItemPool *) const223 SfxPoolItem* SwLuminanceGrf::Clone( SfxItemPool * ) const
224 {
225 	return new SwLuminanceGrf( *this );
226 }
227 
228 // ------------------------------------------------------------------
229 
Clone(SfxItemPool *) const230 SfxPoolItem* SwContrastGrf::Clone( SfxItemPool * ) const
231 {
232 	return new SwContrastGrf( *this );
233 }
234 
235 // ------------------------------------------------------------------
236 
Clone(SfxItemPool *) const237 SfxPoolItem* SwChannelRGrf::Clone( SfxItemPool * ) const
238 {
239 	return new SwChannelRGrf( *this );
240 }
241 
242 // ------------------------------------------------------------------
243 
Clone(SfxItemPool *) const244 SfxPoolItem* SwChannelGGrf::Clone( SfxItemPool * ) const
245 {
246 	return new SwChannelGGrf( *this );
247 }
248 
249 // ------------------------------------------------------------------
250 
Clone(SfxItemPool *) const251 SfxPoolItem* SwChannelBGrf::Clone( SfxItemPool * ) const
252 {
253 	return new SwChannelBGrf( *this );
254 }
255 
256 // ------------------------------------------------------------------
257 
Clone(SfxItemPool *) const258 SfxPoolItem* SwGammaGrf::Clone( SfxItemPool * ) const
259 {
260 	return new SwGammaGrf( *this );
261 }
262 
operator ==(const SfxPoolItem & rCmp) const263 int	SwGammaGrf::operator==( const SfxPoolItem& rCmp ) const
264 {
265 	return SfxPoolItem::operator==( rCmp ) &&
266 		nValue == ((SwGammaGrf&)rCmp).GetValue();
267 }
268 
QueryValue(uno::Any & rVal,sal_uInt8) const269 sal_Bool SwGammaGrf::QueryValue( uno::Any& rVal, sal_uInt8 ) const
270 {
271 	rVal <<= nValue;
272 	return sal_True;
273 }
274 
PutValue(const uno::Any & rVal,sal_uInt8)275 sal_Bool SwGammaGrf::PutValue( const uno::Any& rVal, sal_uInt8 )
276 {
277 	return rVal >>= nValue;
278 }
279 
280 // ------------------------------------------------------------------
281 
Clone(SfxItemPool *) const282 SfxPoolItem* SwInvertGrf::Clone( SfxItemPool * ) const
283 {
284 	return new SwInvertGrf( *this );
285 }
286 
287 // ------------------------------------------------------------------
288 
Clone(SfxItemPool *) const289 SfxPoolItem* SwTransparencyGrf::Clone( SfxItemPool * ) const
290 {
291 	return new SwTransparencyGrf( *this );
292 }
293 // ------------------------------------------------------------------
QueryValue(uno::Any & rVal,sal_uInt8) const294 sal_Bool SwTransparencyGrf::QueryValue( uno::Any& rVal,
295 										sal_uInt8 ) const
296 {
297 	DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
298 	sal_Int16 nRet = GetValue();
299     DBG_ASSERT( 0 <= nRet && nRet <= 100, "value out of range" );
300     rVal <<= nRet;
301 	return sal_True;
302 }
303 // ------------------------------------------------------------------
PutValue(const uno::Any & rVal,sal_uInt8)304 sal_Bool SwTransparencyGrf::PutValue( const uno::Any& rVal,
305 										sal_uInt8 )
306 {
307 	//temporary conversion until this is a SfxInt16Item!
308 	DBG_ASSERT(ISA(SfxByteItem),"Put/QueryValue should be removed!");
309 	sal_Int16 nVal = 0;
310 	if(!(rVal >>= nVal) || nVal < -100 || nVal > 100)
311 		return sal_False;
312     if(nVal < 0)
313     {
314         // for compatibility with old documents
315         // OD 05.11.2002 #104308# - introduce rounding as for SO 6.0 PP2
316         // introduced by fix of #104293#.
317         nVal = ( ( nVal * 128 ) - (99/2) ) / 100;
318         nVal += 128;
319     }
320     DBG_ASSERT( 0 <= nVal && nVal <= 100, "value out of range" );
321 	SetValue(static_cast<sal_uInt8>(nVal));
322 	return sal_True;
323 }
324 
325 // ------------------------------------------------------------------
326 
Clone(SfxItemPool *) const327 SfxPoolItem* SwDrawModeGrf::Clone( SfxItemPool * ) const
328 {
329 	return new SwDrawModeGrf( *this );
330 }
331 
GetValueCount() const332 sal_uInt16 SwDrawModeGrf::GetValueCount() const
333 {
334 	// GRAPHICDRAWMODE_STANDARD = 0,
335 	// GRAPHICDRAWMODE_GREYS = 1,
336 	// GRAPHICDRAWMODE_MONO = 2,
337 	// GRAPHICDRAWMODE_WATERMARK = 3
338 	return GRAPHICDRAWMODE_WATERMARK + 1;
339 }
340 
QueryValue(uno::Any & rVal,sal_uInt8) const341 sal_Bool SwDrawModeGrf::QueryValue( uno::Any& rVal,
342 								sal_uInt8 ) const
343 {
344 	drawing::ColorMode eRet = (drawing::ColorMode)GetEnumValue();
345 	rVal <<= eRet;
346 	return sal_True;
347 }
348 
PutValue(const uno::Any & rVal,sal_uInt8)349 sal_Bool SwDrawModeGrf::PutValue( const uno::Any& rVal,
350 								sal_uInt8 )
351 {
352 	sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal );
353 	if(eVal >= 0 && eVal <= GRAPHICDRAWMODE_WATERMARK)
354 	{
355 		SetEnumValue((sal_uInt16)eVal);
356 		return sal_True;
357 	}
358 	return sal_False;
359 }
360 
361 
362 
363