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