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