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 72 : SFX_IMPL_INTERFACE(ExtrusionBar, SfxShell, SVX_RES(RID_SVX_EXTRUSION_BAR))
65 : {
66 18 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT, SVX_RES(RID_SVX_EXTRUSION_BAR) );
67 18 : }
68 :
69 4 : 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 rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
137 0 : static const rtl::OUString sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
138 0 : static const rtl::OUString sRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "RotateAngle" ) );
139 0 : static const rtl::OUString sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
140 0 : static const rtl::OUString sOrigin( RTL_CONSTASCII_USTRINGPARAM ( "Origin" ) );
141 0 : static const rtl::OUString sSkew( RTL_CONSTASCII_USTRINGPARAM ( "Skew" ) );
142 0 : static const rtl::OUString sDepth( RTL_CONSTASCII_USTRINGPARAM ( "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 : sal_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 rtl::OUString sExtrusionColor( RTL_CONSTASCII_USTRINGPARAM ( "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 rtl::OUString sShadeMode( RTL_CONSTASCII_USTRINGPARAM ( "ShadeMode" ) );
347 0 : static const rtl::OUString sSpecularity( RTL_CONSTASCII_USTRINGPARAM ( "Specularity" ) );
348 0 : static const rtl::OUString sDiffusion( RTL_CONSTASCII_USTRINGPARAM ( "Diffusion" ) );
349 0 : static const rtl::OUString sMetal( RTL_CONSTASCII_USTRINGPARAM ( "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 rtl::OUString sBrightness( RTL_CONSTASCII_USTRINGPARAM ( "Brightness" ) );
399 0 : static const rtl::OUString sLightFace( RTL_CONSTASCII_USTRINGPARAM ( "LightFace" ) );
400 0 : static const rtl::OUString sFirstLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightHarsh" ) );
401 0 : static const rtl::OUString sSecondLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightHarsh" ) );
402 0 : static const rtl::OUString sFirstLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightLevel" ) );
403 0 : static const rtl::OUString sSecondLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "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 rtl::OUString sFirstLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightDirection" ) );
472 0 : const rtl::OUString sSecondLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "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 rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
646 0 : static const rtl::OUString sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
647 0 : static const rtl::OUString sOrigin( RTL_CONSTASCII_USTRINGPARAM ( "Origin" ) );
648 0 : static const rtl::OUString sSkew( RTL_CONSTASCII_USTRINGPARAM ( "Skew" ) );
649 0 : static const rtl::OUString sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "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 : sal_Bool bParallel = sal_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 rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
797 0 : static const rtl::OUString sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "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 : 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 rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
853 0 : static const rtl::OUString sShadeMode( RTL_CONSTASCII_USTRINGPARAM ( "ShadeMode" ) );
854 0 : static const rtl::OUString sSpecularity( RTL_CONSTASCII_USTRINGPARAM ( "Specularity" ) );
855 0 : static const rtl::OUString sDiffusion( RTL_CONSTASCII_USTRINGPARAM ( "Diffusion" ) );
856 0 : static const rtl::OUString sMetal( RTL_CONSTASCII_USTRINGPARAM ( "Metal" ) );
857 :
858 : com::sun::star::uno::Any* pAny;
859 :
860 0 : sal_Int32 nFinalSurface = -1;
861 0 : bool bHasCustomShape = false;
862 :
863 0 : for(i=0;i<nCount; i++)
864 : {
865 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
866 0 : if( pObj->ISA(SdrObjCustomShape) )
867 : {
868 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
869 :
870 : // see if this is an extruded customshape
871 0 : if( !bHasCustomShape )
872 : {
873 0 : Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
874 0 : if( pAny_ )
875 0 : *pAny_ >>= bHasCustomShape;
876 :
877 0 : if( !bHasCustomShape )
878 0 : continue;
879 : }
880 :
881 0 : sal_Int32 nSurface = 0; // wire frame
882 :
883 0 : ShadeMode eShadeMode( ShadeMode_FLAT );
884 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sShadeMode );
885 0 : if( pAny )
886 0 : *pAny >>= eShadeMode;
887 :
888 0 : if( eShadeMode == ShadeMode_FLAT )
889 : {
890 0 : sal_Bool bMetal = sal_False;
891 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sMetal );
892 0 : if( pAny )
893 0 : *pAny >>= bMetal;
894 :
895 0 : if( bMetal )
896 : {
897 0 : nSurface = 3; // metal
898 : }
899 : else
900 : {
901 0 : double fSpecularity = 0;
902 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSpecularity );
903 0 : if( pAny )
904 0 : *pAny >>= fSpecularity;
905 :
906 0 : const double e = 0.0001;
907 0 : if( (fSpecularity > -e) && (fSpecularity < e) )
908 : {
909 0 : nSurface = 1; // matte
910 : }
911 : else
912 : {
913 0 : nSurface = 2; // plastic
914 : }
915 : }
916 : }
917 :
918 0 : if( nFinalSurface == -1 )
919 : {
920 0 : nFinalSurface = nSurface;
921 : }
922 0 : else if( nFinalSurface != nSurface )
923 : {
924 0 : nFinalSurface = -1;
925 : break;
926 0 : }
927 : }
928 : }
929 :
930 0 : if( bHasCustomShape )
931 0 : rSet.Put( SfxInt32Item( SID_EXTRUSION_SURFACE, nFinalSurface ) );
932 : else
933 0 : rSet.DisableItem( SID_EXTRUSION_SURFACE );
934 0 : }
935 :
936 0 : void getExtrusionDepthState( SdrView* pSdrView, SfxItemSet& rSet )
937 : {
938 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
939 0 : sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
940 :
941 0 : static const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
942 0 : static const rtl::OUString sDepth( RTL_CONSTASCII_USTRINGPARAM ( "Depth" ) );
943 :
944 : com::sun::star::uno::Any* pAny;
945 :
946 0 : double fFinalDepth = -1;
947 0 : bool bHasCustomShape = false;
948 :
949 0 : for(i=0;i<nCount; i++)
950 : {
951 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
952 0 : if( pObj->ISA(SdrObjCustomShape) )
953 : {
954 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
955 :
956 : // see if this is an extruded customshape
957 0 : if( !bHasCustomShape )
958 : {
959 0 : Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
960 0 : if( pAny_ )
961 0 : *pAny_ >>= bHasCustomShape;
962 :
963 0 : if( !bHasCustomShape )
964 0 : continue;
965 : }
966 :
967 0 : double fDepth = 1270.0;
968 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sDepth );
969 0 : if( pAny )
970 : {
971 0 : EnhancedCustomShapeParameterPair aDepthPropPair;
972 0 : if ( *pAny >>= aDepthPropPair )
973 0 : aDepthPropPair.First.Value >>= fDepth;
974 : }
975 :
976 0 : if( fFinalDepth == -1 )
977 : {
978 0 : fFinalDepth = fDepth;
979 : }
980 0 : else if( fFinalDepth != fDepth )
981 : {
982 0 : fFinalDepth = -1;
983 : break;
984 0 : }
985 : }
986 : }
987 :
988 0 : if( pSdrView->GetModel() )
989 : {
990 0 : FieldUnit eUnit = pSdrView->GetModel()->GetUIUnit();
991 0 : rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)eUnit ) );
992 : }
993 :
994 0 : if( bHasCustomShape )
995 0 : rSet.Put( SvxDoubleItem( fFinalDepth, SID_EXTRUSION_DEPTH ) );
996 : else
997 0 : rSet.DisableItem( SID_EXTRUSION_DEPTH );
998 0 : }
999 :
1000 0 : static bool compare_direction( const Direction3D& d1, const Direction3D& d2 )
1001 : {
1002 0 : if( ((d1.DirectionX < 0) && (d2.DirectionX < 0)) || ((d1.DirectionX == 0) && (d2.DirectionX == 0)) || ((d1.DirectionX > 0) && (d2.DirectionX > 0)) )
1003 : {
1004 0 : if( ((d1.DirectionY < 0) && (d2.DirectionY < 0)) || ((d1.DirectionY == 0) && (d2.DirectionY == 0)) || ((d1.DirectionY > 0) && (d2.DirectionY > 0)) )
1005 : {
1006 0 : if( ((d1.DirectionZ < 0) && (d2.DirectionZ < 0)) || ((d1.DirectionZ == 0) && (d2.DirectionZ == 0)) || ((d1.DirectionZ > 0) && (d2.DirectionZ > 0)) )
1007 : {
1008 0 : return true;
1009 : }
1010 : }
1011 : }
1012 :
1013 0 : return false;
1014 : }
1015 :
1016 0 : void getExtrusionLightingDirectionState( SdrView* pSdrView, SfxItemSet& rSet )
1017 : {
1018 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1019 0 : sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1020 :
1021 0 : static const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1022 0 : static const rtl::OUString sFirstLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightDirection" ) );
1023 0 : static const rtl::OUString sSecondLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightDirection" ) );
1024 :
1025 : const Direction3D * pLighting1Defaults;
1026 : const Direction3D * pLighting2Defaults;
1027 :
1028 0 : getLightingDirectionDefaults( &pLighting1Defaults, &pLighting2Defaults );
1029 :
1030 : com::sun::star::uno::Any* pAny;
1031 :
1032 0 : int nFinalDirection = -1;
1033 0 : bool bHasCustomShape = false;
1034 :
1035 0 : for(i=0;i<nCount; i++)
1036 : {
1037 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1038 0 : if( pObj->ISA(SdrObjCustomShape) )
1039 : {
1040 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1041 :
1042 : // see if this is an extruded customshape
1043 0 : if( !bHasCustomShape )
1044 : {
1045 0 : Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1046 0 : if( pAny_ )
1047 0 : *pAny_ >>= bHasCustomShape;
1048 :
1049 0 : if( !bHasCustomShape )
1050 0 : continue;
1051 : }
1052 :
1053 0 : Direction3D aFirstLightDirection( 50000, 0, 10000 );
1054 0 : Direction3D aSecondLightDirection( -50000, 0, 10000 );
1055 :
1056 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sFirstLightDirection );
1057 0 : if( pAny )
1058 0 : *pAny >>= aFirstLightDirection;
1059 :
1060 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSecondLightDirection );
1061 0 : if( pAny )
1062 0 : *pAny >>= aSecondLightDirection;
1063 :
1064 0 : int nDirection = -1;
1065 :
1066 : int j;
1067 0 : for( j = 0; j < 9; j++ )
1068 : {
1069 0 : if( compare_direction( aFirstLightDirection, pLighting1Defaults[j] ) &&
1070 0 : compare_direction( aSecondLightDirection, pLighting2Defaults[j] ))
1071 : {
1072 0 : nDirection = j;
1073 0 : break;
1074 : }
1075 : }
1076 :
1077 0 : if( nFinalDirection == -1 )
1078 : {
1079 0 : nFinalDirection = nDirection;
1080 : }
1081 0 : else if( nDirection != nFinalDirection )
1082 : {
1083 0 : nFinalDirection = -1;
1084 : }
1085 :
1086 0 : if( nFinalDirection == -1 )
1087 0 : break;
1088 : }
1089 : }
1090 :
1091 0 : if( bHasCustomShape )
1092 0 : rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_DIRECTION, (sal_Int32)nFinalDirection ) );
1093 : else
1094 0 : rSet.DisableItem( SID_EXTRUSION_LIGHTING_DIRECTION );
1095 0 : }
1096 :
1097 0 : void getExtrusionLightingIntensityState( SdrView* pSdrView, SfxItemSet& rSet )
1098 : {
1099 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1100 0 : sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1101 :
1102 0 : static const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1103 0 : static const rtl::OUString sBrightness( RTL_CONSTASCII_USTRINGPARAM ( "Brightness" ) );
1104 :
1105 : com::sun::star::uno::Any* pAny;
1106 :
1107 0 : int nFinalLevel = -1;
1108 0 : bool bHasCustomShape = false;
1109 :
1110 0 : for(i=0;i<nCount; i++)
1111 : {
1112 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1113 0 : if( pObj->ISA(SdrObjCustomShape) )
1114 : {
1115 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1116 :
1117 : // see if this is an extruded customshape
1118 0 : if( !bHasCustomShape )
1119 : {
1120 0 : Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1121 0 : if( pAny_ )
1122 0 : *pAny_ >>= bHasCustomShape;
1123 :
1124 0 : if( !bHasCustomShape )
1125 0 : continue;
1126 : }
1127 :
1128 0 : double fBrightness = 22178.0 / 655.36;
1129 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sBrightness );
1130 0 : if( pAny )
1131 0 : *pAny >>= fBrightness;
1132 :
1133 : int nLevel;
1134 0 : if( fBrightness >= 30.0 )
1135 : {
1136 0 : nLevel = 0; // Bright
1137 : }
1138 0 : else if( fBrightness >= 10.0 )
1139 : {
1140 0 : nLevel = 1; // Noraml;
1141 : }
1142 : else
1143 : {
1144 0 : nLevel = 2; // Dim
1145 : }
1146 :
1147 0 : if( nFinalLevel == -1 )
1148 : {
1149 0 : nFinalLevel = nLevel;
1150 : }
1151 0 : else if( nFinalLevel != nLevel )
1152 : {
1153 0 : nFinalLevel = -1;
1154 : break;
1155 0 : }
1156 : }
1157 : }
1158 :
1159 0 : if( bHasCustomShape )
1160 0 : rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_INTENSITY, nFinalLevel ) );
1161 : else
1162 0 : rSet.DisableItem( SID_EXTRUSION_LIGHTING_INTENSITY );
1163 0 : }
1164 :
1165 0 : void getExtrusionColorState( SdrView* pSdrView, SfxItemSet& rSet )
1166 : {
1167 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1168 0 : sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1169 :
1170 0 : static const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1171 0 : static const rtl::OUString sExtrusionColor( RTL_CONSTASCII_USTRINGPARAM ( "Color" ) );
1172 :
1173 : com::sun::star::uno::Any* pAny;
1174 :
1175 0 : bool bInit = false;
1176 0 : bool bAmbigius = false;
1177 0 : Color aFinalColor;
1178 0 : bool bHasCustomShape = false;
1179 :
1180 0 : for(i=0;i<nCount; i++)
1181 : {
1182 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1183 0 : if( pObj->ISA(SdrObjCustomShape) )
1184 : {
1185 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1186 :
1187 : // see if this is an extruded customshape
1188 0 : if( !bHasCustomShape )
1189 : {
1190 0 : Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1191 0 : if( pAny_ )
1192 0 : *pAny_ >>= bHasCustomShape;
1193 :
1194 0 : if( !bHasCustomShape )
1195 0 : continue;
1196 : }
1197 :
1198 0 : Color aColor;
1199 :
1200 0 : bool bUseColor = false;
1201 0 : pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusionColor );
1202 0 : if( pAny )
1203 0 : *pAny >>= bUseColor;
1204 :
1205 0 : if( bUseColor )
1206 : {
1207 0 : const XSecondaryFillColorItem& rItem = *(XSecondaryFillColorItem*)&(pObj->GetMergedItem( XATTR_SECONDARYFILLCOLOR ));
1208 0 : aColor = rItem.GetColorValue();
1209 : }
1210 : else
1211 : {
1212 0 : aColor = COL_AUTO;
1213 : }
1214 :
1215 0 : if( !bInit )
1216 : {
1217 0 : aFinalColor = aColor;
1218 0 : bInit = true;
1219 : }
1220 0 : else if( aFinalColor != aColor )
1221 : {
1222 0 : bAmbigius = true;
1223 : break;
1224 0 : }
1225 : }
1226 : }
1227 :
1228 0 : if( bAmbigius )
1229 0 : aFinalColor = COL_AUTO;
1230 :
1231 0 : if( bHasCustomShape )
1232 0 : rSet.Put( SvxColorItem( aFinalColor, SID_EXTRUSION_3D_COLOR ) );
1233 : else
1234 0 : rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
1235 0 : }
1236 :
1237 : namespace svx {
1238 0 : bool checkForSelectedCustomShapes( SdrView* pSdrView, bool bOnlyExtruded )
1239 : {
1240 0 : static const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
1241 :
1242 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
1243 0 : sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
1244 0 : bool bFound = false;
1245 :
1246 0 : for(i=0;(i<nCount) && !bFound ; i++)
1247 : {
1248 0 : SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
1249 0 : if( pObj->ISA(SdrObjCustomShape) )
1250 : {
1251 0 : if( bOnlyExtruded )
1252 : {
1253 0 : SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1254 0 : Any* pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
1255 0 : if( pAny )
1256 0 : *pAny >>= bFound;
1257 : }
1258 : else
1259 : {
1260 0 : bFound = true;
1261 : }
1262 : }
1263 : }
1264 :
1265 0 : return bFound;
1266 : }
1267 : }
1268 :
1269 0 : void ExtrusionBar::getState( SdrView* pSdrView, SfxItemSet& rSet )
1270 : {
1271 0 : if (rSet.GetItemState(SID_EXTRUSION_DIRECTION) != SFX_ITEM_UNKNOWN)
1272 : {
1273 0 : getExtrusionDirectionState( pSdrView, rSet );
1274 : }
1275 0 : if (rSet.GetItemState(SID_EXTRUSION_PROJECTION) != SFX_ITEM_UNKNOWN)
1276 : {
1277 0 : getExtrusionProjectionState( pSdrView, rSet );
1278 : }
1279 : const bool bOnlyExtrudedCustomShapes =
1280 0 : checkForSelectedCustomShapes( pSdrView, true );
1281 0 : if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
1282 : {
1283 0 : if (! bOnlyExtrudedCustomShapes)
1284 0 : rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
1285 : }
1286 0 : if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
1287 : {
1288 0 : if (! bOnlyExtrudedCustomShapes)
1289 0 : rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
1290 : }
1291 0 : if (rSet.GetItemState(SID_EXTRUSION_TILT_UP) != SFX_ITEM_UNKNOWN)
1292 : {
1293 0 : if (! bOnlyExtrudedCustomShapes)
1294 0 : rSet.DisableItem( SID_EXTRUSION_TILT_UP );
1295 : }
1296 0 : if (rSet.GetItemState(SID_EXTRUSION_TILT_LEFT) != SFX_ITEM_UNKNOWN)
1297 : {
1298 0 : if (! bOnlyExtrudedCustomShapes)
1299 0 : rSet.DisableItem( SID_EXTRUSION_TILT_LEFT );
1300 : }
1301 0 : if (rSet.GetItemState(SID_EXTRUSION_TILT_RIGHT) != SFX_ITEM_UNKNOWN)
1302 : {
1303 0 : if (! bOnlyExtrudedCustomShapes)
1304 0 : rSet.DisableItem( SID_EXTRUSION_TILT_RIGHT );
1305 : }
1306 0 : if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
1307 : {
1308 0 : if (! bOnlyExtrudedCustomShapes)
1309 0 : rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
1310 : }
1311 0 : if (rSet.GetItemState(SID_EXTRUSION_DEPTH_FLOATER) != SFX_ITEM_UNKNOWN)
1312 : {
1313 0 : if (! bOnlyExtrudedCustomShapes)
1314 0 : rSet.DisableItem( SID_EXTRUSION_DEPTH_FLOATER );
1315 : }
1316 0 : if (rSet.GetItemState(SID_EXTRUSION_DIRECTION_FLOATER) != SFX_ITEM_UNKNOWN)
1317 : {
1318 0 : if (! bOnlyExtrudedCustomShapes)
1319 0 : rSet.DisableItem( SID_EXTRUSION_DIRECTION_FLOATER );
1320 : }
1321 0 : if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_FLOATER) != SFX_ITEM_UNKNOWN)
1322 : {
1323 0 : if (! bOnlyExtrudedCustomShapes)
1324 0 : rSet.DisableItem( SID_EXTRUSION_LIGHTING_FLOATER );
1325 : }
1326 0 : if (rSet.GetItemState(SID_EXTRUSION_SURFACE_FLOATER) != SFX_ITEM_UNKNOWN)
1327 : {
1328 0 : if(! bOnlyExtrudedCustomShapes)
1329 0 : rSet.DisableItem( SID_EXTRUSION_SURFACE_FLOATER );
1330 : }
1331 0 : if (rSet.GetItemState(SID_EXTRUSION_TOOGLE) != SFX_ITEM_UNKNOWN)
1332 : {
1333 0 : if( !checkForSelectedCustomShapes( pSdrView, false ) )
1334 0 : rSet.DisableItem( SID_EXTRUSION_TOOGLE );
1335 : }
1336 0 : if (rSet.GetItemState(SID_EXTRUSION_DEPTH) != SFX_ITEM_UNKNOWN)
1337 : {
1338 0 : getExtrusionDepthState( pSdrView, rSet );
1339 : }
1340 0 : if (rSet.GetItemState(SID_EXTRUSION_SURFACE) != SFX_ITEM_UNKNOWN)
1341 : {
1342 0 : getExtrusionSurfaceState( pSdrView, rSet );
1343 : }
1344 0 : if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_INTENSITY) != SFX_ITEM_UNKNOWN)
1345 : {
1346 0 : getExtrusionLightingIntensityState( pSdrView, rSet );
1347 : }
1348 :
1349 0 : if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_DIRECTION) != SFX_ITEM_UNKNOWN)
1350 : {
1351 0 : getExtrusionLightingDirectionState( pSdrView, rSet );
1352 : }
1353 :
1354 0 : if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
1355 : {
1356 0 : getExtrusionColorState( pSdrView, rSet );
1357 : }
1358 0 : }
1359 :
1360 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|