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