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_svx.hxx"
26 
27 #ifndef _COM_SUN_STAR_DRAWING_ENHANCEDCUSTOMSHAPEPARAMETERPARIR_HPP_
28 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
29 #endif
30 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
31 #include <com/sun/star/drawing/ShadeMode.hpp>
32 #include <com/sun/star/drawing/Position3D.hpp>
33 #include <com/sun/star/drawing/Direction3D.hpp>
34 #include <com/sun/star/drawing/ProjectionMode.hpp>
35 #include <svx/svdundo.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/request.hxx>
38 #include <sfx2/objface.hxx>
39 #include <sfx2/viewsh.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <svx/xsflclit.hxx>
42 #include <svx/dialmgr.hxx>
43 #include <svx/svdoashp.hxx>
44 #ifndef _SVX_DIALOGS_HRC
45 #include <svx/dialogs.hrc>
46 #endif
47 #include <svx/svdview.hxx>
48 #include <editeng/colritem.hxx>
49 #include "svx/chrtitem.hxx"
50 
51 #include <svx/extrusionbar.hxx>
52 #include "extrusiondepthdialog.hxx"
53 
54 
55 using namespace ::svx;
56 using namespace ::rtl;
57 using namespace ::cppu;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::drawing;
60 using namespace ::com::sun::star::uno;
61 
62 /*************************************************************************
63 |* Standardinterface deklarieren (Die Slotmap darf nicht leer sein, also
64 |* tragen wir etwas ein, was hier (hoffentlich) nie vorkommt).
65 \************************************************************************/
66 
67 #define ShellClass ExtrusionBar
68 
SFX_SLOTMAP(ExtrusionBar)69 SFX_SLOTMAP(ExtrusionBar)
70 {
71 			{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
72 };
73 
SFX_IMPL_INTERFACE(ExtrusionBar,SfxShell,SVX_RES (RID_SVX_EXTRUSION_BAR))74 SFX_IMPL_INTERFACE(ExtrusionBar, SfxShell, SVX_RES(RID_SVX_EXTRUSION_BAR))
75 {
76 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT, SVX_RES(RID_SVX_EXTRUSION_BAR) );
77 }
78 
79 TYPEINIT1( ExtrusionBar, SfxShell );
80 
81 
82 /*************************************************************************
83 |* Standard-Konstruktor
84 \************************************************************************/
85 
ExtrusionBar(SfxViewShell * pViewShell)86 ExtrusionBar::ExtrusionBar(SfxViewShell* pViewShell )
87 : SfxShell(pViewShell)
88 {
89 	DBG_ASSERT( pViewShell, "svx::ExtrusionBar::ExtrusionBar(), I need a viewshell!" );
90 	if( pViewShell )
91 		SetPool(&pViewShell->GetPool());
92 
93 	SetHelpId( SVX_INTERFACE_EXTRUSION_BAR );
94 	SetName( String( SVX_RES( RID_SVX_EXTRUSION_BAR )));
95 }
96 
97 
98 /*************************************************************************
99 |* Destruktor
100 \************************************************************************/
101 
~ExtrusionBar()102 ExtrusionBar::~ExtrusionBar()
103 {
104 	SetRepeatTarget(NULL);
105 }
106 
getLightingDirectionDefaults(const Direction3D ** pLighting1Defaults,const Direction3D ** pLighting2Defaults)107 void getLightingDirectionDefaults( const Direction3D **pLighting1Defaults, const Direction3D **pLighting2Defaults )
108 {
109 
110 	static const Direction3D aLighting1Defaults[9] =
111 	{
112 		Direction3D( -50000, -50000, 10000 ),
113 		Direction3D( 0, -50000, 10000 ),
114 		Direction3D( 50000, -50000, 10000 ),
115 		Direction3D( -50000, 0, 10000 ),
116 		Direction3D( 0, 0, 10000 ),
117 		Direction3D( 50000, 0, 10000 ),
118 		Direction3D( -50000, 50000, 10000 ),
119 		Direction3D( 0, 50000, 10000 ),
120 		Direction3D( 50000, 50000, 10000 )
121 	};
122 
123 	static const Direction3D aLighting2Defaults[9] =
124 	{
125 		Direction3D( 50000,0, 10000 ),
126 		Direction3D( 0, 50000, 10000 ),
127 		Direction3D( -50000, 0, 10000 ),
128 		Direction3D( 50000, 0, 10000 ),
129 		Direction3D( 0, 0, 10000 ),
130 		Direction3D( -50000, 0, 10000 ),
131 		Direction3D( 50000, 0, 10000 ),
132 		Direction3D( 0, -50000, 10000 ),
133 		Direction3D( -50000, 0, 10000 )
134 	};
135 
136 	*pLighting1Defaults = (const Direction3D *)aLighting1Defaults;
137 	*pLighting2Defaults = (const Direction3D *)aLighting2Defaults;
138 };
139 
impl_execute(SdrView *,SfxRequest & rReq,SdrCustomShapeGeometryItem & rGeometryItem,SdrObject * pObj)140 static void impl_execute( SdrView*, SfxRequest& rReq, SdrCustomShapeGeometryItem& rGeometryItem, SdrObject* pObj )
141 {
142 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
143 	static const rtl::OUString	sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
144 	static const rtl::OUString	sRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "RotateAngle" ) );
145 	static const rtl::OUString	sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
146 	static const rtl::OUString	sOrigin( RTL_CONSTASCII_USTRINGPARAM ( "Origin" ) );
147 	static const rtl::OUString	sSkew( RTL_CONSTASCII_USTRINGPARAM ( "Skew" ) );
148 	static const rtl::OUString	sDepth( RTL_CONSTASCII_USTRINGPARAM ( "Depth" ) );
149 
150 	sal_uInt16 nSID = rReq.GetSlot();
151 	switch( nSID )
152 	{
153 	case SID_EXTRUSION_TOOGLE:
154 	{
155 		com::sun::star::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
156 
157 		if( pAny )
158 		{
159 			sal_Bool bOn;
160 			(*pAny) >>= bOn;
161 			bOn = !bOn;
162 			(*pAny) <<= bOn;
163 		}
164 		else
165 		{
166 			com::sun::star::beans::PropertyValue aPropValue;
167 			aPropValue.Name = sExtrusion;
168 			aPropValue.Value <<= sal_True;
169 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
170 		}
171 	}
172 	break;
173 
174 	case SID_EXTRUSION_TILT_DOWN:
175 	case SID_EXTRUSION_TILT_UP:
176 	case SID_EXTRUSION_TILT_LEFT:
177 	case SID_EXTRUSION_TILT_RIGHT:
178 	{
179 		sal_Bool bHorizontal = ( nSID == SID_EXTRUSION_TILT_DOWN ) || ( nSID == SID_EXTRUSION_TILT_UP );
180 		sal_Int32 nDiff = ( nSID == SID_EXTRUSION_TILT_LEFT ) || ( nSID == SID_EXTRUSION_TILT_UP ) ? 5 : -5;
181 		EnhancedCustomShapeParameterPair aRotateAnglePropPair;
182 		double fX = 0.0;
183 		double fY = 0.0;
184 		aRotateAnglePropPair.First.Value <<= fX;
185 		aRotateAnglePropPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
186 		aRotateAnglePropPair.Second.Value <<= fY;
187 		aRotateAnglePropPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
188 		com::sun::star::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, sRotateAngle );
189 		if( pAny && ( *pAny >>= aRotateAnglePropPair ) )
190 		{
191 			aRotateAnglePropPair.First.Value >>= fX;
192 			aRotateAnglePropPair.Second.Value >>= fY;
193 		}
194 		if ( bHorizontal )
195 			fX += nDiff;
196 		else
197 			fY += nDiff;
198 		aRotateAnglePropPair.First.Value <<= fX;
199 		aRotateAnglePropPair.Second.Value <<= fY;
200 		com::sun::star::beans::PropertyValue aPropValue;
201 		aPropValue.Name = sRotateAngle;
202 		aPropValue.Value <<= aRotateAnglePropPair;
203 		rGeometryItem.SetPropertyValue( sExtrusion,	aPropValue );
204 	}
205 	break;
206 
207 	case SID_EXTRUSION_DIRECTION:
208 	{
209 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_DIRECTION ) == SFX_ITEM_SET )
210 		{
211 			sal_Int32 nSkew = ((const SfxInt32Item*)rReq.GetArgs()->GetItem(SID_EXTRUSION_DIRECTION))->GetValue();
212 
213 			Position3D	aViewPoint( 3472, -3472, 25000 );
214 			double		fOriginX = 0.50;
215 			double		fOriginY = -0.50;
216 			double		fSkewAngle = nSkew;
217 			double		fSkew = 50.0;
218 
219 			switch( nSkew )
220 			{
221 			case 135:
222 				aViewPoint.PositionY = 3472;
223 				fOriginY = 0.50;
224 				break;
225 			case 90:
226 				aViewPoint.PositionX = 0;
227 				aViewPoint.PositionY = 3472;
228 				fOriginX = 0;
229 				fOriginY = -0.50;
230 				break;
231 			case 45:
232 				aViewPoint.PositionX = -3472;
233 				aViewPoint.PositionY = 3472;
234 				fOriginX = -0.50;
235 				fOriginY = 0.50;
236 				break;
237 			case 180:
238 				aViewPoint.PositionY = 0;
239 				fOriginY = 0;
240 				break;
241 			case 0:
242 				aViewPoint.PositionX = 0;
243 				aViewPoint.PositionY = 0;
244 				fOriginX = 0;
245 				fOriginY = 0;
246 				fSkew = 0.0;
247 				break;
248 			case -360:
249 				aViewPoint.PositionX = -3472;
250 				aViewPoint.PositionY = 0;
251 				fOriginX = -0.50;
252 				fOriginY = 0;
253 				break;
254 			case -90:
255 				aViewPoint.PositionX = 0;
256 				fOriginX = 0;
257 				break;
258 			case -45:
259 				aViewPoint.PositionX = -3472;
260 				fOriginX = -0.50;
261 				break;
262 			}
263 
264 			com::sun::star::beans::PropertyValue aPropValue;
265 
266 			aPropValue.Name = sViewPoint;
267 			aPropValue.Value <<= aViewPoint;
268 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
269 
270 
271 			EnhancedCustomShapeParameterPair aOriginPropPair;
272 			aOriginPropPair.First.Value <<= fOriginX;
273 			aOriginPropPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
274 			aOriginPropPair.Second.Value <<= fOriginY;
275 			aOriginPropPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
276 			aPropValue.Name = sOrigin;
277 			aPropValue.Value <<= aOriginPropPair;
278 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
279 
280 			EnhancedCustomShapeParameterPair aSkewPropPair;
281 			aSkewPropPair.First.Value <<= fSkew;
282 			aSkewPropPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
283 			aSkewPropPair.Second.Value <<= fSkewAngle;
284 			aSkewPropPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
285 			aPropValue.Name = sSkew;
286 			aPropValue.Value <<= aSkewPropPair;
287 			rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
288 		}
289 	}
290 	break;
291 	case SID_EXTRUSION_PROJECTION:
292 	{
293 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_PROJECTION ) == SFX_ITEM_SET )
294 		{
295 			sal_Int32 nProjection = ((const SfxInt32Item*)rReq.GetArgs()->GetItem(SID_EXTRUSION_PROJECTION))->GetValue();
296 			ProjectionMode eProjectionMode = nProjection == 1 ? ProjectionMode_PARALLEL : ProjectionMode_PERSPECTIVE;
297 			com::sun::star::beans::PropertyValue aPropValue;
298 			aPropValue.Name = sProjectionMode;
299 			aPropValue.Value <<= eProjectionMode;
300 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
301 		}
302 	}
303 	break;
304 	case SID_EXTRUSION_DEPTH:
305 	{
306 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_DEPTH ) == SFX_ITEM_SET)
307 		{
308 			double fDepth = ((const SvxDoubleItem*)rReq.GetArgs()->GetItem(SID_EXTRUSION_DEPTH))->GetValue();
309 			double fFraction = 0.0;
310 			EnhancedCustomShapeParameterPair aDepthPropPair;
311 			aDepthPropPair.First.Value <<= fDepth;
312 			aDepthPropPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
313 			aDepthPropPair.Second.Value <<= fFraction;
314 			aDepthPropPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
315 
316 			com::sun::star::beans::PropertyValue aPropValue;
317 			aPropValue.Name = sDepth;
318 			aPropValue.Value <<= aDepthPropPair;
319 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
320 		}
321 	}
322 	break;
323 	case SID_EXTRUSION_3D_COLOR:
324 	{
325 		static const rtl::OUString	sExtrusionColor( RTL_CONSTASCII_USTRINGPARAM ( "Color" ) );
326 
327 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_3D_COLOR ) == SFX_ITEM_SET)
328 		{
329 			Color aColor( ((const SvxColorItem&)rReq.GetArgs()->Get(SID_EXTRUSION_3D_COLOR)).GetValue() );
330 
331 			const bool bAuto = aColor == COL_AUTO;
332 
333 			com::sun::star::beans::PropertyValue aPropValue;
334 			aPropValue.Name = sExtrusionColor;
335 			aPropValue.Value <<= bAuto ? sal_False : sal_True;
336 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
337 
338 			if( bAuto )
339 			{
340 				pObj->ClearMergedItem( XATTR_SECONDARYFILLCOLOR );
341 			}
342 			else
343 			{
344 				pObj->SetMergedItem( XSecondaryFillColorItem( String(), aColor ) );
345 			}
346 			pObj->BroadcastObjectChange();
347 		}
348 	}
349 	break;
350 	case SID_EXTRUSION_SURFACE:
351 	{
352 		static const rtl::OUString sShadeMode( RTL_CONSTASCII_USTRINGPARAM ( "ShadeMode" ) );
353 		static const rtl::OUString sSpecularity( RTL_CONSTASCII_USTRINGPARAM ( "Specularity" ) );
354 		static const rtl::OUString sDiffusion( RTL_CONSTASCII_USTRINGPARAM ( "Diffusion" ) );
355 		static const rtl::OUString sMetal( RTL_CONSTASCII_USTRINGPARAM ( "Metal" ) );
356 
357 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_SURFACE ) == SFX_ITEM_SET)
358 		{
359 			sal_Int32 nSurface = ((const SfxInt32Item*)rReq.GetArgs()->GetItem(SID_EXTRUSION_SURFACE))->GetValue();
360 
361 			ShadeMode eShadeMode( ShadeMode_FLAT );
362 			sal_Bool bMetal = sal_False;
363 			double fSpecularity = 0;
364 			double fDiffusion = 0;
365 
366 			switch( nSurface )
367 			{
368 			case 0:	// wireframe
369 				eShadeMode = ShadeMode_DRAFT;
370 				break;
371 			case 1: // matte
372 				break;
373 			case 2: // plastic
374 				fSpecularity = 122.0;
375 				break;
376 			case 3: // metal
377 				bMetal = true;
378 				fSpecularity = 122.0;
379 				fDiffusion = 122.0;
380 				break;
381 			}
382 
383 			com::sun::star::beans::PropertyValue aPropValue;
384 			aPropValue.Name = sShadeMode;
385 			aPropValue.Value <<= eShadeMode;
386 			rGeometryItem.SetPropertyValue( sExtrusion,	aPropValue );
387 
388 			aPropValue.Name = sMetal;
389 			aPropValue.Value <<= bMetal;
390 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
391 
392 			aPropValue.Name = sSpecularity;
393 			aPropValue.Value <<= fSpecularity;
394 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
395 
396 			aPropValue.Name = sDiffusion;
397 			aPropValue.Value <<= fDiffusion;
398 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
399 		}
400 	}
401 	break;
402 	case SID_EXTRUSION_LIGHTING_INTENSITY:
403 	{
404 		static const rtl::OUString sBrightness( RTL_CONSTASCII_USTRINGPARAM ( "Brightness" ) );
405 		static const rtl::OUString sLightFace( RTL_CONSTASCII_USTRINGPARAM ( "LightFace" ) );
406 		static const rtl::OUString sFirstLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightHarsh" ) );
407 		static const rtl::OUString sSecondLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightHarsh" ) );
408 		static const rtl::OUString sFirstLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightLevel" ) );
409 		static const rtl::OUString sSecondLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightLevel" ) );
410 
411 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_LIGHTING_INTENSITY ) == SFX_ITEM_SET)
412 		{
413 			sal_Int32 nLevel = ((const SfxInt32Item*)rReq.GetArgs()->GetItem(SID_EXTRUSION_LIGHTING_INTENSITY))->GetValue();
414 
415 			double fBrightness;
416 			sal_Bool bHarsh2;
417 			double fLevel1;
418 			double fLevel2;
419 
420 			switch( nLevel )
421 			{
422 			case 0: // bright
423 				fBrightness = 34.0;
424 				bHarsh2 = sal_False;
425 				fLevel1 = 66.0;
426 				fLevel2 = 66.0;
427 				break;
428 			case 1: // normal
429 				fBrightness = 15.0;
430 				bHarsh2 = sal_False;
431 				fLevel1 = 67.0;
432 				fLevel2 = 37.0;
433 				break;
434 			case 2: // dim
435 				fBrightness = 6.0;
436 				bHarsh2 = sal_True;
437 				fLevel1 = 79.0;
438 				fLevel2 = 21.0;
439 				break;
440 			}
441 
442 			com::sun::star::beans::PropertyValue aPropValue;
443 			aPropValue.Name = sBrightness;
444 			aPropValue.Value <<= fBrightness;
445 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
446 
447 			aPropValue.Name = sLightFace;
448 			aPropValue.Value <<= sal_True;
449 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
450 
451 			aPropValue.Name = sFirstLightHarsh;
452 			aPropValue.Value <<= sal_True;
453 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
454 
455 			aPropValue.Name = sSecondLightHarsh;
456 			aPropValue.Value <<= bHarsh2;
457 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
458 
459 			aPropValue.Name = sFirstLightLevel;
460 			aPropValue.Value <<= fLevel1;
461 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
462 
463 			aPropValue.Name = sSecondLightLevel;
464 			aPropValue.Value <<= fLevel2;
465 			rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
466 		}
467 	}
468 	break;
469 	case SID_EXTRUSION_LIGHTING_DIRECTION:
470 	{
471 		if( rReq.GetArgs() && rReq.GetArgs()->GetItemState( SID_EXTRUSION_LIGHTING_DIRECTION ) == SFX_ITEM_SET)
472 		{
473 			sal_Int32 nDirection = ((const SfxInt32Item*)rReq.GetArgs()->GetItem(SID_EXTRUSION_LIGHTING_DIRECTION))->GetValue();
474 
475 			if((nDirection >= 0) && (nDirection < 9))
476 			{
477 				const rtl::OUString	sFirstLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightDirection" ) );
478 				const rtl::OUString	sSecondLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightDirection" ) );
479 
480 				const Direction3D * pLighting1Defaults;
481 				const Direction3D * pLighting2Defaults;
482 
483 				getLightingDirectionDefaults( &pLighting1Defaults, &pLighting2Defaults );
484 
485 				com::sun::star::beans::PropertyValue aPropValue;
486 				aPropValue.Name = sFirstLightDirection;
487 				aPropValue.Value <<= pLighting1Defaults[nDirection];
488 				rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
489 
490 				aPropValue.Name = sSecondLightDirection;
491 				aPropValue.Value <<= pLighting2Defaults[nDirection];
492 				rGeometryItem.SetPropertyValue( sExtrusion,	 aPropValue );
493 			}
494 		}
495 	}
496 	break;
497 
498 	}
499 }
500 
execute(SdrView * pSdrView,SfxRequest & rReq,SfxBindings & rBindings)501 void ExtrusionBar::execute( SdrView* pSdrView, SfxRequest& rReq, SfxBindings& rBindings )
502 {
503 	sal_uInt16 nSID = rReq.GetSlot();
504 	sal_uInt16 nStrResId = 0;
505 
506 	const bool bUndo = pSdrView && pSdrView->IsUndoEnabled();
507 
508 	switch( nSID )
509 	{
510 		case SID_EXTRUSION_TOOGLE:
511 		{
512 			if ( !nStrResId )
513 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ON_OFF;
514 		}	// PASSTROUGH
515 		case SID_EXTRUSION_TILT_DOWN:
516 		{
517 			if ( !nStrResId )
518 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ROTATE_DOWN;
519 		}	// PASSTROUGH
520 		case SID_EXTRUSION_TILT_UP:
521 		{
522 			if ( !nStrResId )
523 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ROTATE_UP;
524 		}	// PASSTROUGH
525 		case SID_EXTRUSION_TILT_LEFT:
526 		{
527 			if ( !nStrResId )
528 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ROTATE_LEFT;
529 		}	// PASSTROUGH
530 		case SID_EXTRUSION_TILT_RIGHT:
531 		{
532 			if ( !nStrResId )
533 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ROTATE_RIGHT;
534 		}	// PASSTROUGH
535 		case SID_EXTRUSION_DIRECTION:
536 		{
537 			if ( !nStrResId )
538 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_ORIENTATION;
539 		}	// PASSTROUGH
540 		case SID_EXTRUSION_PROJECTION:
541 		{
542 			if ( !nStrResId )
543 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_PROJECTION;
544 		}	// PASSTROUGH
545 		case SID_EXTRUSION_DEPTH:
546 		{
547 			if ( !nStrResId )
548 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_DEPTH;
549 		}	// PASSTROUGH
550 		case SID_EXTRUSION_3D_COLOR:
551 		{
552 			if ( !nStrResId )
553 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_COLOR;
554 		}	// PASSTROUGH
555 		case SID_EXTRUSION_SURFACE:
556 		{
557 			if ( !nStrResId )
558 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_SURFACE;
559 		}	// PASSTROUGH
560 		case SID_EXTRUSION_LIGHTING_INTENSITY:
561 		{
562 			if ( !nStrResId )
563 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_BRIGHTNESS;
564 		}	// PASSTROUGH
565 		case SID_EXTRUSION_LIGHTING_DIRECTION:
566 		{
567 			if ( !nStrResId )
568 				nStrResId = RID_SVXSTR_UNDO_APPLY_EXTRUSION_LIGHTING;
569 
570 			const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
571 			sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
572 
573 			for(i=0; i<nCount; i++)
574 			{
575 				SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
576 				if( pObj->ISA(SdrObjCustomShape) )
577 				{
578 					if( bUndo )
579 					{
580 						String aStr( SVX_RES( nStrResId ) );
581 						pSdrView->BegUndo( aStr );
582 						pSdrView->AddUndo( pSdrView->GetModel()->GetSdrUndoFactory().CreateUndoAttrObject( *pObj ) );
583 					}
584 					SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
585 					impl_execute( pSdrView, rReq, aGeometryItem, pObj );
586 					pObj->SetMergedItem( aGeometryItem );
587 					pObj->BroadcastObjectChange();
588 					if( bUndo )
589 						pSdrView->EndUndo();
590 
591 					// simulate a context change:
592 					// force SelectionHasChanged() being called
593 					// so that extrusion bar will be visible/hidden
594 					pSdrView->MarkListHasChanged();
595 				}
596 			}
597 		}
598 		break;
599 
600 		case SID_EXTRUSION_DEPTH_DIALOG:
601 			if( rReq.GetArgs() &&
602 				(rReq.GetArgs()->GetItemState( SID_EXTRUSION_DEPTH ) == SFX_ITEM_SET) &&
603 				(rReq.GetArgs()->GetItemState( SID_ATTR_METRIC ) == SFX_ITEM_SET))
604 			{
605 				double fDepth = ((const SvxDoubleItem*)rReq.GetArgs()->GetItem(SID_EXTRUSION_DEPTH))->GetValue();
606 				FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)rReq.GetArgs()->GetItem(SID_ATTR_METRIC))->GetValue();
607 
608 				ExtrusionDepthDialog aDlg( 0L, fDepth, eUnit );
609 				sal_uInt16 nRet = aDlg.Execute();
610 				if( nRet != 0 )
611 				{
612 					fDepth = aDlg.getDepth();
613 
614 					SvxDoubleItem aItem( fDepth, SID_EXTRUSION_DEPTH );
615 					SfxPoolItem* aItems[] = { &aItem, 0 };
616 					rBindings.Execute( SID_EXTRUSION_DEPTH, (const SfxPoolItem**)aItems );
617 				}
618 			}
619 			break;
620 	}
621 
622 	if( nSID == SID_EXTRUSION_TOOGLE )
623 	{
624 			static sal_uInt16 SidArray[] = {
625 				SID_EXTRUSION_TILT_DOWN,
626 				SID_EXTRUSION_TILT_UP,
627 				SID_EXTRUSION_TILT_LEFT,
628 				SID_EXTRUSION_TILT_RIGHT,
629 				SID_EXTRUSION_DEPTH_FLOATER,
630 				SID_EXTRUSION_DIRECTION_FLOATER,
631 				SID_EXTRUSION_LIGHTING_FLOATER,
632 				SID_EXTRUSION_SURFACE_FLOATER,
633 				SID_EXTRUSION_3D_COLOR,
634 				SID_EXTRUSION_DEPTH,
635 				SID_EXTRUSION_DIRECTION,
636 				SID_EXTRUSION_PROJECTION,
637 				SID_EXTRUSION_LIGHTING_DIRECTION,
638 				SID_EXTRUSION_LIGHTING_INTENSITY,
639 				SID_EXTRUSION_SURFACE,
640 				0 };
641 
642 		rBindings.Invalidate( SidArray );
643 	}
644 }
645 
getExtrusionDirectionState(SdrView * pSdrView,SfxItemSet & rSet)646 void getExtrusionDirectionState( SdrView* pSdrView, SfxItemSet& rSet )
647 {
648 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
649 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
650 
651 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
652 	static const rtl::OUString	sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
653 	static const rtl::OUString	sOrigin( RTL_CONSTASCII_USTRINGPARAM ( "Origin" ) );
654 	static const rtl::OUString	sSkew( RTL_CONSTASCII_USTRINGPARAM ( "Skew" ) );
655 	static const rtl::OUString	sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
656 
657 	com::sun::star::uno::Any* pAny;
658 
659 	double fFinalSkewAngle = -1;
660 	bool bHasCustomShape = false;
661 
662 	for(i=0;i<nCount; i++)
663 	{
664 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
665 		if( pObj->ISA(SdrObjCustomShape) )
666 		{
667 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
668 
669 			// see if this is an extruded customshape
670 			if( !bHasCustomShape )
671 			{
672 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
673 				if( pAny_ )
674 					*pAny_ >>= bHasCustomShape;
675 
676 				if( !bHasCustomShape )
677 					continue;
678 			}
679 
680 			sal_Bool	bParallel = sal_True;
681 			Position3D	aViewPoint( 3472, -3472, 25000 );
682 			double		fOriginX = 0.50;
683 			double		fOriginY = -0.50;
684 			double		fSkewAngle = -135;
685 			double		fSkew = 50.0;
686 
687 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
688 			sal_Int16 nProjectionMode = sal_Int16();
689 			if( pAny && ( *pAny >>= nProjectionMode ) )
690 				bParallel = nProjectionMode == ProjectionMode_PARALLEL;
691 
692 			if( bParallel )
693 			{
694 				EnhancedCustomShapeParameterPair aSkewPropPair;
695 				pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSkew );
696 				if( pAny && ( *pAny >>= aSkewPropPair ) )
697 				{
698 					aSkewPropPair.First.Value >>= fSkew;
699 					aSkewPropPair.Second.Value >>= fSkewAngle;
700 				}
701 				if ( fSkew == 0.0 )
702 					fSkewAngle = 0.0;
703 				else if ( fSkewAngle == 0.0 )
704 					fSkewAngle = -360.0;
705 			}
706 			else
707 			{
708 				pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sViewPoint );
709 				if( pAny )
710 					*pAny >>= aViewPoint;
711 
712 				EnhancedCustomShapeParameterPair aOriginPropPair;
713 				pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sOrigin );
714 				if( pAny && ( *pAny >>= aOriginPropPair ) )
715 				{
716 					aOriginPropPair.First.Value >>= fOriginX;
717 					aOriginPropPair.Second.Value >>= fOriginY;
718 				}
719 				fSkewAngle = -1;
720 				const double e = 0.0001;
721 				if( aViewPoint.PositionX > e )
722 				{
723 					if( aViewPoint.PositionY > e )
724 					{
725 						if( (fOriginX > e ) && ( fOriginY > e ) )
726 							fSkewAngle = 135.0;
727 					}
728 					else if( aViewPoint.PositionY < -e )
729 					{
730 						if( ( fOriginX > e ) && ( fOriginY < -e ) )
731 							fSkewAngle = -135.0;
732 					}
733 					else
734 					{
735 						if( ( fOriginX > e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
736 							fSkewAngle = 180.0;
737 					}
738 				}
739 				else if( aViewPoint.PositionX < -e )
740 				{
741 					if( aViewPoint.PositionY < -e )
742 					{
743 						if( ( fOriginX < -e ) && ( fOriginY < -e ) )
744 							fSkewAngle = -45.0;
745 					}
746 					else if( aViewPoint.PositionY > e )
747 					{
748 						if( ( fOriginX < -e ) && ( fOriginY > e ) )
749 							fSkewAngle = 45.0;
750 					}
751 					else
752 					{
753 						if( ( fOriginX < e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
754 							fSkewAngle = -360.0;
755 					}
756 				}
757 				else
758 				{
759 					if( aViewPoint.PositionY < -e )
760 					{
761 						if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY < -e ) )
762 							fSkewAngle = -90.0;
763 					}
764 					else if( aViewPoint.PositionY > e )
765 					{
766 						if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY > e ) )
767 							fSkewAngle = 90.0;
768 					}
769 					else
770 					{
771 						if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
772 							fSkewAngle = 0.0;
773 					}
774 				}
775 			}
776 
777 			if( fFinalSkewAngle == -1.0 )
778 			{
779 				fFinalSkewAngle = fSkewAngle;
780 			}
781 			else if( fSkewAngle != fFinalSkewAngle )
782 			{
783 				fFinalSkewAngle = -1.0;
784 			}
785 
786 			if( fFinalSkewAngle == -1.0 )
787 				break;
788 		}
789 	}
790 
791 	if( bHasCustomShape )
792 		rSet.Put( SfxInt32Item( SID_EXTRUSION_DIRECTION, (sal_Int32)fFinalSkewAngle ) );
793 	else
794 		rSet.DisableItem( SID_EXTRUSION_DIRECTION );
795 }
796 
getExtrusionProjectionState(SdrView * pSdrView,SfxItemSet & rSet)797 void getExtrusionProjectionState( SdrView* pSdrView, SfxItemSet& rSet )
798 {
799 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
800 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
801 
802 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
803 	static const rtl::OUString	sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
804 
805 	com::sun::star::uno::Any* pAny;
806 
807 	sal_Int32 nFinalProjection = -1;
808 	bool bHasCustomShape = false;
809 
810 	for(i=0;i<nCount; i++)
811 	{
812 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
813 		if( pObj->ISA(SdrObjCustomShape) )
814 		{
815 			// see if this is an extruded customshape
816 			if( !bHasCustomShape )
817 			{
818 				SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
819 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
820 				if( pAny_ )
821 					*pAny_ >>= bHasCustomShape;
822 
823 				if( !bHasCustomShape )
824 					continue;
825 			}
826 
827 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
828 
829 			sal_Bool	bParallel = sal_True;
830 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
831 			ProjectionMode eProjectionMode;
832 			if( pAny && ( *pAny >>= eProjectionMode ) )
833 				bParallel = eProjectionMode == ProjectionMode_PARALLEL;
834 
835 			if( nFinalProjection == -1 )
836 			{
837 				nFinalProjection = bParallel;
838 			}
839 			else if( nFinalProjection != bParallel )
840 			{
841 				nFinalProjection = -1;
842 				break;
843 			}
844 		}
845 	}
846 
847 	if( bHasCustomShape )
848 		rSet.Put( SfxInt32Item( SID_EXTRUSION_PROJECTION, nFinalProjection ) );
849 	else
850 		rSet.DisableItem( SID_EXTRUSION_PROJECTION );
851 }
852 
getExtrusionSurfaceState(SdrView * pSdrView,SfxItemSet & rSet)853 void getExtrusionSurfaceState( SdrView* pSdrView, SfxItemSet& rSet )
854 {
855 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
856 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
857 
858 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
859 	static const rtl::OUString	sShadeMode( RTL_CONSTASCII_USTRINGPARAM ( "ShadeMode" ) );
860 	static const rtl::OUString	sSpecularity( RTL_CONSTASCII_USTRINGPARAM ( "Specularity" ) );
861 	static const rtl::OUString	sDiffusion( RTL_CONSTASCII_USTRINGPARAM ( "Diffusion" ) );
862 	static const rtl::OUString	sMetal( RTL_CONSTASCII_USTRINGPARAM ( "Metal" ) );
863 
864 	com::sun::star::uno::Any* pAny;
865 
866 	sal_Int32 nFinalSurface = -1;
867 	bool bHasCustomShape = false;
868 
869 	for(i=0;i<nCount; i++)
870 	{
871 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
872 		if( pObj->ISA(SdrObjCustomShape) )
873 		{
874 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
875 
876 			// see if this is an extruded customshape
877 			if( !bHasCustomShape )
878 			{
879 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
880 				if( pAny_ )
881 					*pAny_ >>= bHasCustomShape;
882 
883 				if( !bHasCustomShape )
884 					continue;
885 			}
886 
887 			sal_Int32 nSurface = 0; // wireframe
888 
889 			ShadeMode eShadeMode( ShadeMode_FLAT );
890 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sShadeMode );
891 			if( pAny )
892 				*pAny >>= eShadeMode;
893 
894 			if( eShadeMode == ShadeMode_FLAT )
895 			{
896 				sal_Bool bMetal = sal_False;
897 				pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sMetal );
898 				if( pAny )
899 					*pAny >>= bMetal;
900 
901 				if( bMetal )
902 				{
903 					nSurface = 3; // metal
904 				}
905 				else
906 				{
907 					double fSpecularity = 0;
908 					pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSpecularity );
909 					if( pAny )
910 						*pAny >>= fSpecularity;
911 
912 					const double e = 0.0001;
913 					if( (fSpecularity > -e) && (fSpecularity < e) )
914 					{
915 						nSurface = 1; // matte
916 					}
917 					else
918 					{
919 						nSurface = 2; // plastic
920 					}
921 				}
922 			}
923 
924 			if( nFinalSurface == -1 )
925 			{
926 				nFinalSurface = nSurface;
927 			}
928 			else if( nFinalSurface != nSurface )
929 			{
930 				nFinalSurface = -1;
931 				break;
932 			}
933 		}
934 	}
935 
936 	if( bHasCustomShape )
937 		rSet.Put( SfxInt32Item( SID_EXTRUSION_SURFACE, nFinalSurface ) );
938 	else
939 		rSet.DisableItem( SID_EXTRUSION_SURFACE );
940 }
941 
getExtrusionDepthState(SdrView * pSdrView,SfxItemSet & rSet)942 void getExtrusionDepthState( SdrView* pSdrView, SfxItemSet& rSet )
943 {
944 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
945 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
946 
947 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
948 	static const rtl::OUString	sDepth( RTL_CONSTASCII_USTRINGPARAM ( "Depth" ) );
949 
950 	com::sun::star::uno::Any* pAny;
951 
952 	double fFinalDepth = -1;
953 	bool bHasCustomShape = false;
954 
955 	for(i=0;i<nCount; i++)
956 	{
957 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
958 		if( pObj->ISA(SdrObjCustomShape) )
959 		{
960 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
961 
962 			// see if this is an extruded customshape
963 			if( !bHasCustomShape )
964 			{
965 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
966 				if( pAny_ )
967 					*pAny_ >>= bHasCustomShape;
968 
969 				if( !bHasCustomShape )
970 					continue;
971 			}
972 
973 			double fDepth = 1270.0;
974 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sDepth );
975 			if( pAny )
976 			{
977 				EnhancedCustomShapeParameterPair aDepthPropPair;
978 				if ( *pAny >>= aDepthPropPair )
979 					aDepthPropPair.First.Value >>= fDepth;
980 			}
981 
982 			if( fFinalDepth == -1 )
983 			{
984 				fFinalDepth = fDepth;
985 			}
986 			else if( fFinalDepth != fDepth )
987 			{
988 				fFinalDepth = -1;
989 				break;
990 			}
991 		}
992 	}
993 
994 	if( pSdrView->GetModel() )
995 	{
996 		FieldUnit eUnit = pSdrView->GetModel()->GetUIUnit();
997 		rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)eUnit ) );
998 	}
999 
1000 	if( bHasCustomShape )
1001 		rSet.Put( SvxDoubleItem( fFinalDepth, SID_EXTRUSION_DEPTH ) );
1002 	else
1003 		rSet.DisableItem( SID_EXTRUSION_DEPTH );
1004 }
1005 
compare_direction(const Direction3D & d1,const Direction3D & d2)1006 static bool compare_direction( const Direction3D& d1, const Direction3D& d2 )
1007 {
1008 	if( ((d1.DirectionX < 0) && (d2.DirectionX < 0)) || ((d1.DirectionX == 0) && (d2.DirectionX == 0)) || ((d1.DirectionX > 0) && (d2.DirectionX > 0)) )
1009 	{
1010 		if( ((d1.DirectionY < 0) && (d2.DirectionY < 0)) || ((d1.DirectionY == 0) && (d2.DirectionY == 0)) || ((d1.DirectionY > 0) && (d2.DirectionY > 0)) )
1011 		{
1012 			if( ((d1.DirectionZ < 0) && (d2.DirectionZ < 0)) || ((d1.DirectionZ == 0) && (d2.DirectionZ == 0)) || ((d1.DirectionZ > 0) && (d2.DirectionZ > 0)) )
1013 			{
1014 				return true;
1015 			}
1016 		}
1017 	}
1018 
1019 	return false;
1020 }
1021 
getExtrusionLightingDirectionState(SdrView * pSdrView,SfxItemSet & rSet)1022 void getExtrusionLightingDirectionState( SdrView* pSdrView, SfxItemSet& rSet )
1023 {
1024 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1025 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1026 
1027 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1028 	static const rtl::OUString	sFirstLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightDirection" ) );
1029 	static const rtl::OUString	sSecondLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightDirection" ) );
1030 
1031 	const Direction3D * pLighting1Defaults;
1032 	const Direction3D * pLighting2Defaults;
1033 
1034 	getLightingDirectionDefaults( &pLighting1Defaults, &pLighting2Defaults );
1035 
1036 	com::sun::star::uno::Any* pAny;
1037 
1038 	int nFinalDirection = -1;
1039 	bool bHasCustomShape = false;
1040 
1041 	for(i=0;i<nCount; i++)
1042 	{
1043 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1044 		if( pObj->ISA(SdrObjCustomShape) )
1045 		{
1046 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1047 
1048 			// see if this is an extruded customshape
1049 			if( !bHasCustomShape )
1050 			{
1051 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1052 				if( pAny_ )
1053 					*pAny_ >>= bHasCustomShape;
1054 
1055 				if( !bHasCustomShape )
1056 					continue;
1057 			}
1058 
1059 			Direction3D aFirstLightDirection( 50000, 0, 10000 );
1060 			Direction3D aSecondLightDirection( -50000, 0, 10000 );
1061 
1062 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sFirstLightDirection );
1063 			if( pAny )
1064 				*pAny >>= aFirstLightDirection;
1065 
1066 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSecondLightDirection );
1067 			if( pAny )
1068 				*pAny >>= aSecondLightDirection;
1069 
1070 			int nDirection = -1;
1071 
1072 			int j;
1073 			for( j = 0; j < 9; j++ )
1074 			{
1075 				if( compare_direction( aFirstLightDirection, pLighting1Defaults[j] ) &&
1076 					compare_direction( aSecondLightDirection, pLighting2Defaults[j] ))
1077 				{
1078 					nDirection = j;
1079 					break;
1080 				}
1081 			}
1082 
1083 			if( nFinalDirection == -1 )
1084 			{
1085 				nFinalDirection = nDirection;
1086 			}
1087 			else if( nDirection != nFinalDirection )
1088 			{
1089 				nFinalDirection = -1;
1090 			}
1091 
1092 			if( nFinalDirection == -1 )
1093 				break;
1094 		}
1095 	}
1096 
1097 	if( bHasCustomShape )
1098 		rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_DIRECTION, (sal_Int32)nFinalDirection ) );
1099 	else
1100 		rSet.DisableItem( SID_EXTRUSION_LIGHTING_DIRECTION );
1101 }
1102 
getExtrusionLightingIntensityState(SdrView * pSdrView,SfxItemSet & rSet)1103 void getExtrusionLightingIntensityState( SdrView* pSdrView, SfxItemSet& rSet )
1104 {
1105 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1106 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1107 
1108 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1109 	static const rtl::OUString	sBrightness( RTL_CONSTASCII_USTRINGPARAM ( "Brightness" ) );
1110 
1111 	com::sun::star::uno::Any* pAny;
1112 
1113 	int nFinalLevel = -1;
1114 	bool bHasCustomShape = false;
1115 
1116 	for(i=0;i<nCount; i++)
1117 	{
1118 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1119 		if( pObj->ISA(SdrObjCustomShape) )
1120 		{
1121 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1122 
1123 			// see if this is an extruded customshape
1124 			if( !bHasCustomShape )
1125 			{
1126 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1127 				if( pAny_ )
1128 					*pAny_ >>= bHasCustomShape;
1129 
1130 				if( !bHasCustomShape )
1131 					continue;
1132 			}
1133 
1134 			double fBrightness = 22178.0 / 655.36;
1135 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sBrightness );
1136 			if( pAny )
1137 				*pAny >>= fBrightness;
1138 
1139 			int nLevel;
1140 			if( fBrightness >= 30.0 )
1141 			{
1142 				nLevel = 0; // Bright
1143 			}
1144 			else if( fBrightness >= 10.0 )
1145 			{
1146 				nLevel = 1; // Normal
1147 			}
1148 			else
1149 			{
1150 				nLevel = 2; // Dim
1151 			}
1152 
1153 			if( nFinalLevel == -1 )
1154 			{
1155 				nFinalLevel = nLevel;
1156 			}
1157 			else if( nFinalLevel != nLevel )
1158 			{
1159 				nFinalLevel = -1;
1160 				break;
1161 			}
1162 		}
1163 	}
1164 
1165 	if( bHasCustomShape )
1166 		rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_INTENSITY, nFinalLevel ) );
1167 	else
1168 		rSet.DisableItem( SID_EXTRUSION_LIGHTING_INTENSITY );
1169 }
1170 
getExtrusionColorState(SdrView * pSdrView,SfxItemSet & rSet)1171 void getExtrusionColorState( SdrView* pSdrView, SfxItemSet& rSet )
1172 {
1173 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1174 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1175 
1176 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1177 	static const rtl::OUString	sExtrusionColor( RTL_CONSTASCII_USTRINGPARAM ( "Color" ) );
1178 
1179 	com::sun::star::uno::Any* pAny;
1180 
1181 	bool bInit = false;
1182 	bool bAmbigius = false;
1183 	Color aFinalColor;
1184 	bool bHasCustomShape = false;
1185 
1186 	for(i=0;i<nCount; i++)
1187 	{
1188 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1189 		if( pObj->ISA(SdrObjCustomShape) )
1190 		{
1191 			SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1192 
1193 			// see if this is an extruded customshape
1194 			if( !bHasCustomShape )
1195 			{
1196 				Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1197 				if( pAny_ )
1198 					*pAny_ >>= bHasCustomShape;
1199 
1200 				if( !bHasCustomShape )
1201 					continue;
1202 			}
1203 
1204 			Color aColor;
1205 
1206 			bool bUseColor = false;
1207 			pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusionColor );
1208 			if( pAny )
1209 				*pAny >>= bUseColor;
1210 
1211 			if( bUseColor )
1212 			{
1213 				const XSecondaryFillColorItem& rItem = *(XSecondaryFillColorItem*)&(pObj->GetMergedItem( XATTR_SECONDARYFILLCOLOR ));
1214 				aColor = rItem.GetColorValue();
1215 			}
1216 			else
1217 			{
1218 				aColor = COL_AUTO;
1219 			}
1220 
1221 			if( !bInit )
1222 			{
1223 				aFinalColor = aColor;
1224 				bInit = true;
1225 			}
1226 			else if( aFinalColor != aColor )
1227 			{
1228 				bAmbigius = true;
1229 				break;
1230 			}
1231 		}
1232 	}
1233 
1234 	if( bAmbigius )
1235 		aFinalColor = COL_AUTO;
1236 
1237 	if( bHasCustomShape )
1238 		rSet.Put( SvxColorItem( aFinalColor, SID_EXTRUSION_3D_COLOR ) );
1239 	else
1240 		rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
1241 }
1242 
1243 namespace svx {
checkForSelectedCustomShapes(SdrView * pSdrView,bool bOnlyExtruded)1244 bool checkForSelectedCustomShapes( SdrView* pSdrView, bool bOnlyExtruded )
1245 {
1246 	static const rtl::OUString	sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1247 
1248 	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1249 	sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1250 	bool bFound = false;
1251 
1252 	for(i=0;(i<nCount) && !bFound ; i++)
1253 	{
1254 		SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1255 		if( pObj->ISA(SdrObjCustomShape) )
1256 		{
1257 			if( bOnlyExtruded )
1258 			{
1259 				SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1260 				Any* pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1261 				if( pAny )
1262 					*pAny >>= bFound;
1263 			}
1264 			else
1265 			{
1266 				bFound = true;
1267 			}
1268 		}
1269 	}
1270 
1271 	return bFound;
1272 }
1273 }
1274 
getState(SdrView * pSdrView,SfxItemSet & rSet)1275 void ExtrusionBar::getState( SdrView* pSdrView, SfxItemSet& rSet )
1276 {
1277 	if (rSet.GetItemState(SID_EXTRUSION_DIRECTION) != SFX_ITEM_UNKNOWN)
1278 	{
1279 		getExtrusionDirectionState( pSdrView, rSet );
1280 	}
1281 	if (rSet.GetItemState(SID_EXTRUSION_PROJECTION) != SFX_ITEM_UNKNOWN)
1282 	{
1283 		getExtrusionProjectionState( pSdrView, rSet );
1284 	}
1285 	const bool bOnlyExtrudedCustomShapes =
1286 		checkForSelectedCustomShapes( pSdrView, true );
1287 	if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
1288 	{
1289 		if (! bOnlyExtrudedCustomShapes)
1290 			rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
1291 	}
1292 	if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
1293 	{
1294 		if (! bOnlyExtrudedCustomShapes)
1295 			rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
1296 	}
1297 	if (rSet.GetItemState(SID_EXTRUSION_TILT_UP) != SFX_ITEM_UNKNOWN)
1298 	{
1299 		if (! bOnlyExtrudedCustomShapes)
1300 			rSet.DisableItem( SID_EXTRUSION_TILT_UP );
1301 	}
1302 	if (rSet.GetItemState(SID_EXTRUSION_TILT_LEFT) != SFX_ITEM_UNKNOWN)
1303 	{
1304 		if (! bOnlyExtrudedCustomShapes)
1305 			rSet.DisableItem( SID_EXTRUSION_TILT_LEFT );
1306 	}
1307 	if (rSet.GetItemState(SID_EXTRUSION_TILT_RIGHT) != SFX_ITEM_UNKNOWN)
1308 	{
1309 		if (! bOnlyExtrudedCustomShapes)
1310 			rSet.DisableItem( SID_EXTRUSION_TILT_RIGHT );
1311 	}
1312 	if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
1313 	{
1314 		if (! bOnlyExtrudedCustomShapes)
1315 			rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
1316 	}
1317 	if (rSet.GetItemState(SID_EXTRUSION_DEPTH_FLOATER) != SFX_ITEM_UNKNOWN)
1318 	{
1319 		if (! bOnlyExtrudedCustomShapes)
1320 			rSet.DisableItem( SID_EXTRUSION_DEPTH_FLOATER );
1321 	}
1322 	if (rSet.GetItemState(SID_EXTRUSION_DIRECTION_FLOATER) != SFX_ITEM_UNKNOWN)
1323 	{
1324 		if (! bOnlyExtrudedCustomShapes)
1325 			rSet.DisableItem( SID_EXTRUSION_DIRECTION_FLOATER );
1326 	}
1327 	if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_FLOATER) != SFX_ITEM_UNKNOWN)
1328 	{
1329 		if (! bOnlyExtrudedCustomShapes)
1330 			rSet.DisableItem( SID_EXTRUSION_LIGHTING_FLOATER );
1331 	}
1332 	if (rSet.GetItemState(SID_EXTRUSION_SURFACE_FLOATER) != SFX_ITEM_UNKNOWN)
1333 	{
1334 		if(! bOnlyExtrudedCustomShapes)
1335 			rSet.DisableItem( SID_EXTRUSION_SURFACE_FLOATER );
1336 	}
1337 	if (rSet.GetItemState(SID_EXTRUSION_TOOGLE) != SFX_ITEM_UNKNOWN)
1338 	{
1339 		if( !checkForSelectedCustomShapes( pSdrView, false ) )
1340 			rSet.DisableItem( SID_EXTRUSION_TOOGLE );
1341 	}
1342 	if (rSet.GetItemState(SID_EXTRUSION_DEPTH) != SFX_ITEM_UNKNOWN)
1343 	{
1344 		getExtrusionDepthState( pSdrView, rSet );
1345 	}
1346 	if (rSet.GetItemState(SID_EXTRUSION_SURFACE) != SFX_ITEM_UNKNOWN)
1347 	{
1348 		getExtrusionSurfaceState( pSdrView, rSet );
1349 	}
1350 	if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_INTENSITY) != SFX_ITEM_UNKNOWN)
1351 	{
1352 		getExtrusionLightingIntensityState( pSdrView, rSet );
1353 	}
1354 
1355 	if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_DIRECTION) != SFX_ITEM_UNKNOWN)
1356 	{
1357 		getExtrusionLightingDirectionState( pSdrView, rSet );
1358 	}
1359 
1360 	if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
1361 	{
1362 		getExtrusionColorState( pSdrView, rSet );
1363 	}
1364 }
1365