LCOV - code coverage report
Current view: top level - svx/source/toolbars - extrusionbar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 36 711 5.1 %
Date: 2014-04-11 Functions: 6 25 24.0 %
Legend: Lines: hit not hit

          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         296 : SFX_IMPL_INTERFACE(ExtrusionBar, SfxShell, SVX_RES(RID_SVX_EXTRUSION_BAR))
      65             : {
      66          74 :     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT, SVX_RES(RID_SVX_EXTRUSION_BAR) );
      67          74 : }
      68             : 
      69          46 : 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(SVX_RESSTR(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( "", 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 :             if (pSdrView)
     565             :             {
     566           0 :                 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     567           0 :                 sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
     568             : 
     569           0 :                 for(i=0; i<nCount; i++)
     570             :                 {
     571           0 :                     SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     572           0 :                     if( pObj->ISA(SdrObjCustomShape) )
     573             :                     {
     574           0 :                         if( bUndo )
     575             :                         {
     576           0 :                             OUString aStr( SVX_RESSTR( nStrResId ) );
     577           0 :                             pSdrView->BegUndo( aStr );
     578           0 :                             pSdrView->AddUndo( pSdrView->GetModel()->GetSdrUndoFactory().CreateUndoAttrObject( *pObj ) );
     579             :                         }
     580           0 :                         SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     581           0 :                         impl_execute( pSdrView, rReq, aGeometryItem, pObj );
     582           0 :                         pObj->SetMergedItem( aGeometryItem );
     583           0 :                         pObj->BroadcastObjectChange();
     584           0 :                         if( bUndo )
     585           0 :                             pSdrView->EndUndo();
     586             : 
     587             :                         // simulate a context change:
     588             :                         // force SelectionHasChanged() being called
     589             :                         // so that extrusion bar will be visible/hidden
     590           0 :                         pSdrView->MarkListHasChanged();
     591             :                     }
     592             :                 }
     593             :             }
     594             :         }
     595           0 :         break;
     596             : 
     597             :         case SID_EXTRUSION_DEPTH_DIALOG:
     598           0 :             if( rReq.GetArgs() &&
     599           0 :                 (rReq.GetArgs()->GetItemState( SID_EXTRUSION_DEPTH ) == SFX_ITEM_SET) &&
     600           0 :                 (rReq.GetArgs()->GetItemState( SID_ATTR_METRIC ) == SFX_ITEM_SET))
     601             :             {
     602           0 :                 double fDepth = ((const SvxDoubleItem*)rReq.GetArgs()->GetItem(SID_EXTRUSION_DEPTH))->GetValue();
     603           0 :                 FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)rReq.GetArgs()->GetItem(SID_ATTR_METRIC))->GetValue();
     604             : 
     605           0 :                 ExtrusionDepthDialog aDlg( 0L, fDepth, eUnit );
     606           0 :                 sal_uInt16 nRet = aDlg.Execute();
     607           0 :                 if( nRet != 0 )
     608             :                 {
     609           0 :                     fDepth = aDlg.getDepth();
     610             : 
     611           0 :                     SvxDoubleItem aItem( fDepth, SID_EXTRUSION_DEPTH );
     612           0 :                     SfxPoolItem* aItems[] = { &aItem, 0 };
     613           0 :                     rBindings.Execute( SID_EXTRUSION_DEPTH, (const SfxPoolItem**)aItems );
     614           0 :                 }
     615             :             }
     616           0 :             break;
     617             :     }
     618             : 
     619           0 :     if( nSID == SID_EXTRUSION_TOOGLE )
     620             :     {
     621             :             static sal_uInt16 SidArray[] = {
     622             :                 SID_EXTRUSION_TILT_DOWN,
     623             :                 SID_EXTRUSION_TILT_UP,
     624             :                 SID_EXTRUSION_TILT_LEFT,
     625             :                 SID_EXTRUSION_TILT_RIGHT,
     626             :                 SID_EXTRUSION_DEPTH_FLOATER,
     627             :                 SID_EXTRUSION_DIRECTION_FLOATER,
     628             :                 SID_EXTRUSION_LIGHTING_FLOATER,
     629             :                 SID_EXTRUSION_SURFACE_FLOATER,
     630             :                 SID_EXTRUSION_3D_COLOR,
     631             :                 SID_EXTRUSION_DEPTH,
     632             :                 SID_EXTRUSION_DIRECTION,
     633             :                 SID_EXTRUSION_PROJECTION,
     634             :                 SID_EXTRUSION_LIGHTING_DIRECTION,
     635             :                 SID_EXTRUSION_LIGHTING_INTENSITY,
     636             :                 SID_EXTRUSION_SURFACE,
     637             :                 0 };
     638             : 
     639           0 :         rBindings.Invalidate( SidArray );
     640             :     }
     641           0 : }
     642             : 
     643           0 : void getExtrusionDirectionState( SdrView* pSdrView, SfxItemSet& rSet )
     644             : {
     645           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     646           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
     647             : 
     648           0 :     static const OUString  sExtrusion( "Extrusion" );
     649           0 :     static const OUString  sViewPoint( "ViewPoint" );
     650           0 :     static const OUString  sOrigin( "Origin" );
     651           0 :     static const OUString  sSkew( "Skew" );
     652           0 :     static const OUString  sProjectionMode( "ProjectionMode" );
     653             : 
     654             :     com::sun::star::uno::Any* pAny;
     655             : 
     656           0 :     double fFinalSkewAngle = -1;
     657           0 :     bool bHasCustomShape = false;
     658             : 
     659           0 :     for(i=0;i<nCount; i++)
     660             :     {
     661           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     662           0 :         if( pObj->ISA(SdrObjCustomShape) )
     663             :         {
     664           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     665             : 
     666             :             // see if this is an extruded customshape
     667           0 :             if( !bHasCustomShape )
     668             :             {
     669           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
     670           0 :                 if( pAny_ )
     671           0 :                     *pAny_ >>= bHasCustomShape;
     672             : 
     673           0 :                 if( !bHasCustomShape )
     674           0 :                     continue;
     675             :             }
     676             : 
     677           0 :             bool        bParallel = true;
     678           0 :             Position3D  aViewPoint( 3472, -3472, 25000 );
     679           0 :             double      fSkewAngle = -135;
     680             : 
     681           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
     682           0 :             sal_Int16 nProjectionMode = sal_Int16();
     683           0 :             if( pAny && ( *pAny >>= nProjectionMode ) )
     684           0 :                 bParallel = nProjectionMode == ProjectionMode_PARALLEL;
     685             : 
     686           0 :             if( bParallel )
     687             :             {
     688           0 :                 double      fSkew = 50.0;
     689           0 :                 EnhancedCustomShapeParameterPair aSkewPropPair;
     690           0 :                 pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSkew );
     691           0 :                 if( pAny && ( *pAny >>= aSkewPropPair ) )
     692             :                 {
     693           0 :                     aSkewPropPair.First.Value >>= fSkew;
     694           0 :                     aSkewPropPair.Second.Value >>= fSkewAngle;
     695             :                 }
     696           0 :                 if ( fSkew == 0.0 )
     697           0 :                     fSkewAngle = 0.0;
     698           0 :                 else if ( fSkewAngle == 0.0 )
     699           0 :                     fSkewAngle = -360.0;
     700             :             }
     701             :             else
     702             :             {
     703           0 :                 double      fOriginX = 0.50;
     704           0 :                 double      fOriginY = -0.50;
     705           0 :                 pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sViewPoint );
     706           0 :                 if( pAny )
     707           0 :                     *pAny >>= aViewPoint;
     708             : 
     709           0 :                 EnhancedCustomShapeParameterPair aOriginPropPair;
     710           0 :                 pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sOrigin );
     711           0 :                 if( pAny && ( *pAny >>= aOriginPropPair ) )
     712             :                 {
     713           0 :                     aOriginPropPair.First.Value >>= fOriginX;
     714           0 :                     aOriginPropPair.Second.Value >>= fOriginY;
     715             :                 }
     716           0 :                 fSkewAngle = -1;
     717           0 :                 const double e = 0.0001;
     718           0 :                 if( aViewPoint.PositionX > e )
     719             :                 {
     720           0 :                     if( aViewPoint.PositionY > e )
     721             :                     {
     722           0 :                         if( (fOriginX > e ) && ( fOriginY > e ) )
     723           0 :                             fSkewAngle = 135.0;
     724             :                     }
     725           0 :                     else if( aViewPoint.PositionY < -e )
     726             :                     {
     727           0 :                         if( ( fOriginX > e ) && ( fOriginY < -e ) )
     728           0 :                             fSkewAngle = -135.0;
     729             :                     }
     730             :                     else
     731             :                     {
     732           0 :                         if( ( fOriginX > e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
     733           0 :                             fSkewAngle = 180.0;
     734             :                     }
     735             :                 }
     736           0 :                 else if( aViewPoint.PositionX < -e )
     737             :                 {
     738           0 :                     if( aViewPoint.PositionY < -e )
     739             :                     {
     740           0 :                         if( ( fOriginX < -e ) && ( fOriginY < -e ) )
     741           0 :                             fSkewAngle = -45.0;
     742             :                     }
     743           0 :                     else if( aViewPoint.PositionY > e )
     744             :                     {
     745           0 :                         if( ( fOriginX < -e ) && ( fOriginY > e ) )
     746           0 :                             fSkewAngle = 45.0;
     747             :                     }
     748             :                     else
     749             :                     {
     750           0 :                         if( ( fOriginX < e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
     751           0 :                             fSkewAngle = -360.0;
     752             :                     }
     753             :                 }
     754             :                 else
     755             :                 {
     756           0 :                     if( aViewPoint.PositionY < -e )
     757             :                     {
     758           0 :                         if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY < -e ) )
     759           0 :                             fSkewAngle = -90.0;
     760             :                     }
     761           0 :                     else if( aViewPoint.PositionY > e )
     762             :                     {
     763           0 :                         if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY > e ) )
     764           0 :                             fSkewAngle = 90.0;
     765             :                     }
     766             :                     else
     767             :                     {
     768           0 :                         if( ( fOriginX > -e ) && ( fOriginX < e ) && ( fOriginY > -e ) && ( fOriginY < e ) )
     769           0 :                             fSkewAngle = 0.0;
     770             :                     }
     771           0 :                 }
     772             :             }
     773             : 
     774           0 :             if( fFinalSkewAngle == -1.0 )
     775             :             {
     776           0 :                 fFinalSkewAngle = fSkewAngle;
     777             :             }
     778           0 :             else if( fSkewAngle != fFinalSkewAngle )
     779             :             {
     780           0 :                 fFinalSkewAngle = -1.0;
     781             :             }
     782             : 
     783           0 :             if( fFinalSkewAngle == -1.0 )
     784           0 :                 break;
     785             :         }
     786             :     }
     787             : 
     788           0 :     if( bHasCustomShape )
     789           0 :         rSet.Put( SfxInt32Item( SID_EXTRUSION_DIRECTION, (sal_Int32)fFinalSkewAngle ) );
     790             :     else
     791           0 :         rSet.DisableItem( SID_EXTRUSION_DIRECTION );
     792           0 : }
     793             : 
     794           0 : void getExtrusionProjectionState( SdrView* pSdrView, SfxItemSet& rSet )
     795             : {
     796           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     797           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
     798             : 
     799           0 :     static const OUString  sExtrusion( "Extrusion" );
     800           0 :     static const OUString  sProjectionMode( "ProjectionMode" );
     801             : 
     802             :     com::sun::star::uno::Any* pAny;
     803             : 
     804           0 :     sal_Int32 nFinalProjection = -1;
     805           0 :     bool bHasCustomShape = false;
     806             : 
     807           0 :     for(i=0;i<nCount; i++)
     808             :     {
     809           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     810           0 :         if( pObj->ISA(SdrObjCustomShape) )
     811             :         {
     812             :             // see if this is an extruded customshape
     813           0 :             if( !bHasCustomShape )
     814             :             {
     815           0 :                 SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     816           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
     817           0 :                 if( pAny_ )
     818           0 :                     *pAny_ >>= bHasCustomShape;
     819             : 
     820           0 :                 if( !bHasCustomShape )
     821           0 :                     continue;
     822             :             }
     823             : 
     824           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     825             : 
     826           0 :             sal_Bool    bParallel = sal_True;
     827           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
     828             :             ProjectionMode eProjectionMode;
     829           0 :             if( pAny && ( *pAny >>= eProjectionMode ) )
     830           0 :                 bParallel = eProjectionMode == ProjectionMode_PARALLEL;
     831             : 
     832           0 :             if( nFinalProjection == -1 )
     833             :             {
     834           0 :                 nFinalProjection = bParallel;
     835             :             }
     836           0 :             else if( nFinalProjection != bParallel )
     837             :             {
     838           0 :                 nFinalProjection = -1;
     839           0 :                 break;
     840           0 :             }
     841             :         }
     842             :     }
     843             : 
     844           0 :     if( bHasCustomShape )
     845           0 :         rSet.Put( SfxInt32Item( SID_EXTRUSION_PROJECTION, nFinalProjection ) );
     846             :     else
     847           0 :         rSet.DisableItem( SID_EXTRUSION_PROJECTION );
     848           0 : }
     849             : 
     850           0 : void getExtrusionSurfaceState( SdrView* pSdrView, SfxItemSet& rSet )
     851             : {
     852           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     853           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
     854             : 
     855           0 :     static const OUString  sExtrusion( "Extrusion" );
     856           0 :     static const OUString  sShadeMode( "ShadeMode" );
     857           0 :     static const OUString  sSpecularity( "Specularity" );
     858           0 :     static const OUString  sMetal( "Metal" );
     859             : 
     860             :     com::sun::star::uno::Any* pAny;
     861             : 
     862           0 :     sal_Int32 nFinalSurface = -1;
     863           0 :     bool bHasCustomShape = false;
     864             : 
     865           0 :     for(i=0;i<nCount; i++)
     866             :     {
     867           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     868           0 :         if( pObj->ISA(SdrObjCustomShape) )
     869             :         {
     870           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     871             : 
     872             :             // see if this is an extruded customshape
     873           0 :             if( !bHasCustomShape )
     874             :             {
     875           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
     876           0 :                 if( pAny_ )
     877           0 :                     *pAny_ >>= bHasCustomShape;
     878             : 
     879           0 :                 if( !bHasCustomShape )
     880           0 :                     continue;
     881             :             }
     882             : 
     883           0 :             sal_Int32 nSurface = 0; // wire frame
     884             : 
     885           0 :             ShadeMode eShadeMode( ShadeMode_FLAT );
     886           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sShadeMode );
     887           0 :             if( pAny )
     888           0 :                 *pAny >>= eShadeMode;
     889             : 
     890           0 :             if( eShadeMode == ShadeMode_FLAT )
     891             :             {
     892           0 :                 sal_Bool bMetal = sal_False;
     893           0 :                 pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sMetal );
     894           0 :                 if( pAny )
     895           0 :                     *pAny >>= bMetal;
     896             : 
     897           0 :                 if( bMetal )
     898             :                 {
     899           0 :                     nSurface = 3; // metal
     900             :                 }
     901             :                 else
     902             :                 {
     903           0 :                     double fSpecularity = 0;
     904           0 :                     pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSpecularity );
     905           0 :                     if( pAny )
     906           0 :                         *pAny >>= fSpecularity;
     907             : 
     908           0 :                     const double e = 0.0001;
     909           0 :                     if( (fSpecularity > -e) && (fSpecularity < e) )
     910             :                     {
     911           0 :                         nSurface = 1; // matte
     912             :                     }
     913             :                     else
     914             :                     {
     915           0 :                         nSurface = 2; // plastic
     916             :                     }
     917             :                 }
     918             :             }
     919             : 
     920           0 :             if( nFinalSurface == -1 )
     921             :             {
     922           0 :                 nFinalSurface = nSurface;
     923             :             }
     924           0 :             else if( nFinalSurface != nSurface )
     925             :             {
     926           0 :                 nFinalSurface = -1;
     927           0 :                 break;
     928           0 :             }
     929             :         }
     930             :     }
     931             : 
     932           0 :     if( bHasCustomShape )
     933           0 :         rSet.Put( SfxInt32Item( SID_EXTRUSION_SURFACE, nFinalSurface ) );
     934             :     else
     935           0 :         rSet.DisableItem( SID_EXTRUSION_SURFACE );
     936           0 : }
     937             : 
     938           0 : void getExtrusionDepthState( SdrView* pSdrView, SfxItemSet& rSet )
     939             : {
     940           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     941           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
     942             : 
     943           0 :     static const OUString  sExtrusion( "Extrusion" );
     944           0 :     static const OUString  sDepth( "Depth" );
     945             : 
     946             :     com::sun::star::uno::Any* pAny;
     947             : 
     948           0 :     double fFinalDepth = -1;
     949           0 :     bool bHasCustomShape = false;
     950             : 
     951           0 :     for(i=0;i<nCount; i++)
     952             :     {
     953           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     954           0 :         if( pObj->ISA(SdrObjCustomShape) )
     955             :         {
     956           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     957             : 
     958             :             // see if this is an extruded customshape
     959           0 :             if( !bHasCustomShape )
     960             :             {
     961           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
     962           0 :                 if( pAny_ )
     963           0 :                     *pAny_ >>= bHasCustomShape;
     964             : 
     965           0 :                 if( !bHasCustomShape )
     966           0 :                     continue;
     967             :             }
     968             : 
     969           0 :             double fDepth = 1270.0;
     970           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sDepth );
     971           0 :             if( pAny )
     972             :             {
     973           0 :                 EnhancedCustomShapeParameterPair aDepthPropPair;
     974           0 :                 if ( *pAny >>= aDepthPropPair )
     975           0 :                     aDepthPropPair.First.Value >>= fDepth;
     976             :             }
     977             : 
     978           0 :             if( fFinalDepth == -1 )
     979             :             {
     980           0 :                 fFinalDepth = fDepth;
     981             :             }
     982           0 :             else if( fFinalDepth != fDepth )
     983             :             {
     984           0 :                 fFinalDepth = -1;
     985           0 :                 break;
     986           0 :             }
     987             :         }
     988             :     }
     989             : 
     990           0 :     if( pSdrView->GetModel() )
     991             :     {
     992           0 :         FieldUnit eUnit = pSdrView->GetModel()->GetUIUnit();
     993           0 :         rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)eUnit ) );
     994             :     }
     995             : 
     996           0 :     if( bHasCustomShape )
     997           0 :         rSet.Put( SvxDoubleItem( fFinalDepth, SID_EXTRUSION_DEPTH ) );
     998             :     else
     999           0 :         rSet.DisableItem( SID_EXTRUSION_DEPTH );
    1000           0 : }
    1001             : 
    1002           0 : static bool compare_direction( const Direction3D& d1, const Direction3D& d2 )
    1003             : {
    1004           0 :     if( ((d1.DirectionX < 0) && (d2.DirectionX < 0)) || ((d1.DirectionX == 0) && (d2.DirectionX == 0)) || ((d1.DirectionX > 0) && (d2.DirectionX > 0)) )
    1005             :     {
    1006           0 :         if( ((d1.DirectionY < 0) && (d2.DirectionY < 0)) || ((d1.DirectionY == 0) && (d2.DirectionY == 0)) || ((d1.DirectionY > 0) && (d2.DirectionY > 0)) )
    1007             :         {
    1008           0 :             if( ((d1.DirectionZ < 0) && (d2.DirectionZ < 0)) || ((d1.DirectionZ == 0) && (d2.DirectionZ == 0)) || ((d1.DirectionZ > 0) && (d2.DirectionZ > 0)) )
    1009             :             {
    1010           0 :                 return true;
    1011             :             }
    1012             :         }
    1013             :     }
    1014             : 
    1015           0 :     return false;
    1016             : }
    1017             : 
    1018           0 : void getExtrusionLightingDirectionState( SdrView* pSdrView, SfxItemSet& rSet )
    1019             : {
    1020           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    1021           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
    1022             : 
    1023           0 :     static const OUString  sExtrusion( "Extrusion" );
    1024           0 :     static const OUString  sFirstLightDirection( "FirstLightDirection" );
    1025           0 :     static const OUString  sSecondLightDirection( "SecondLightDirection" );
    1026             : 
    1027             :     const Direction3D * pLighting1Defaults;
    1028             :     const Direction3D * pLighting2Defaults;
    1029             : 
    1030           0 :     getLightingDirectionDefaults( &pLighting1Defaults, &pLighting2Defaults );
    1031             : 
    1032             :     com::sun::star::uno::Any* pAny;
    1033             : 
    1034           0 :     int nFinalDirection = -1;
    1035           0 :     bool bHasCustomShape = false;
    1036             : 
    1037           0 :     for(i=0;i<nCount; i++)
    1038             :     {
    1039           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
    1040           0 :         if( pObj->ISA(SdrObjCustomShape) )
    1041             :         {
    1042           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1043             : 
    1044             :             // see if this is an extruded customshape
    1045           0 :             if( !bHasCustomShape )
    1046             :             {
    1047           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
    1048           0 :                 if( pAny_ )
    1049           0 :                     *pAny_ >>= bHasCustomShape;
    1050             : 
    1051           0 :                 if( !bHasCustomShape )
    1052           0 :                     continue;
    1053             :             }
    1054             : 
    1055           0 :             Direction3D aFirstLightDirection( 50000, 0, 10000 );
    1056           0 :             Direction3D aSecondLightDirection( -50000, 0, 10000 );
    1057             : 
    1058           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sFirstLightDirection );
    1059           0 :             if( pAny )
    1060           0 :                 *pAny >>= aFirstLightDirection;
    1061             : 
    1062           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sSecondLightDirection );
    1063           0 :             if( pAny )
    1064           0 :                 *pAny >>= aSecondLightDirection;
    1065             : 
    1066           0 :             int nDirection = -1;
    1067             : 
    1068             :             int j;
    1069           0 :             for( j = 0; j < 9; j++ )
    1070             :             {
    1071           0 :                 if( compare_direction( aFirstLightDirection, pLighting1Defaults[j] ) &&
    1072           0 :                     compare_direction( aSecondLightDirection, pLighting2Defaults[j] ))
    1073             :                 {
    1074           0 :                     nDirection = j;
    1075           0 :                     break;
    1076             :                 }
    1077             :             }
    1078             : 
    1079           0 :             if( nFinalDirection == -1 )
    1080             :             {
    1081           0 :                 nFinalDirection = nDirection;
    1082             :             }
    1083           0 :             else if( nDirection != nFinalDirection )
    1084             :             {
    1085           0 :                 nFinalDirection = -1;
    1086             :             }
    1087             : 
    1088           0 :             if( nFinalDirection == -1 )
    1089           0 :                 break;
    1090             :         }
    1091             :     }
    1092             : 
    1093           0 :     if( bHasCustomShape )
    1094           0 :         rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_DIRECTION, (sal_Int32)nFinalDirection ) );
    1095             :     else
    1096           0 :         rSet.DisableItem( SID_EXTRUSION_LIGHTING_DIRECTION );
    1097           0 : }
    1098             : 
    1099           0 : void getExtrusionLightingIntensityState( SdrView* pSdrView, SfxItemSet& rSet )
    1100             : {
    1101           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    1102           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
    1103             : 
    1104           0 :     static const OUString  sExtrusion( "Extrusion" );
    1105           0 :     static const OUString  sBrightness( "Brightness" );
    1106             : 
    1107             :     com::sun::star::uno::Any* pAny;
    1108             : 
    1109           0 :     int nFinalLevel = -1;
    1110           0 :     bool bHasCustomShape = false;
    1111             : 
    1112           0 :     for(i=0;i<nCount; i++)
    1113             :     {
    1114           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
    1115           0 :         if( pObj->ISA(SdrObjCustomShape) )
    1116             :         {
    1117           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1118             : 
    1119             :             // see if this is an extruded customshape
    1120           0 :             if( !bHasCustomShape )
    1121             :             {
    1122           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
    1123           0 :                 if( pAny_ )
    1124           0 :                     *pAny_ >>= bHasCustomShape;
    1125             : 
    1126           0 :                 if( !bHasCustomShape )
    1127           0 :                     continue;
    1128             :             }
    1129             : 
    1130           0 :             double fBrightness = 22178.0 / 655.36;
    1131           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sBrightness );
    1132           0 :             if( pAny )
    1133           0 :                 *pAny >>= fBrightness;
    1134             : 
    1135             :             int nLevel;
    1136           0 :             if( fBrightness >= 30.0 )
    1137             :             {
    1138           0 :                 nLevel = 0; // Bright
    1139             :             }
    1140           0 :             else if( fBrightness >= 10.0 )
    1141             :             {
    1142           0 :                 nLevel = 1; // Noraml;
    1143             :             }
    1144             :             else
    1145             :             {
    1146           0 :                 nLevel = 2; // Dim
    1147             :             }
    1148             : 
    1149           0 :             if( nFinalLevel == -1 )
    1150             :             {
    1151           0 :                 nFinalLevel = nLevel;
    1152             :             }
    1153           0 :             else if( nFinalLevel != nLevel )
    1154             :             {
    1155           0 :                 nFinalLevel = -1;
    1156           0 :                 break;
    1157           0 :             }
    1158             :         }
    1159             :     }
    1160             : 
    1161           0 :     if( bHasCustomShape )
    1162           0 :         rSet.Put( SfxInt32Item( SID_EXTRUSION_LIGHTING_INTENSITY, nFinalLevel ) );
    1163             :     else
    1164           0 :         rSet.DisableItem( SID_EXTRUSION_LIGHTING_INTENSITY );
    1165           0 : }
    1166             : 
    1167           0 : void getExtrusionColorState( SdrView* pSdrView, SfxItemSet& rSet )
    1168             : {
    1169           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    1170           0 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
    1171             : 
    1172           0 :     static const OUString  sExtrusion( "Extrusion" );
    1173           0 :     static const OUString  sExtrusionColor( "Color" );
    1174             : 
    1175             :     com::sun::star::uno::Any* pAny;
    1176             : 
    1177           0 :     bool bInit = false;
    1178           0 :     bool bAmbigius = false;
    1179           0 :     Color aFinalColor;
    1180           0 :     bool bHasCustomShape = false;
    1181             : 
    1182           0 :     for(i=0;i<nCount; i++)
    1183             :     {
    1184           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
    1185           0 :         if( pObj->ISA(SdrObjCustomShape) )
    1186             :         {
    1187           0 :             SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1188             : 
    1189             :             // see if this is an extruded customshape
    1190           0 :             if( !bHasCustomShape )
    1191             :             {
    1192           0 :                 Any* pAny_ = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
    1193           0 :                 if( pAny_ )
    1194           0 :                     *pAny_ >>= bHasCustomShape;
    1195             : 
    1196           0 :                 if( !bHasCustomShape )
    1197           0 :                     continue;
    1198             :             }
    1199             : 
    1200           0 :             Color aColor;
    1201             : 
    1202           0 :             bool bUseColor = false;
    1203           0 :             pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusionColor );
    1204           0 :             if( pAny )
    1205           0 :                 *pAny >>= bUseColor;
    1206             : 
    1207           0 :             if( bUseColor )
    1208             :             {
    1209           0 :                 const XSecondaryFillColorItem& rItem = *(XSecondaryFillColorItem*)&(pObj->GetMergedItem( XATTR_SECONDARYFILLCOLOR ));
    1210           0 :                 aColor = rItem.GetColorValue();
    1211             :             }
    1212             :             else
    1213             :             {
    1214           0 :                 aColor = COL_AUTO;
    1215             :             }
    1216             : 
    1217           0 :             if( !bInit )
    1218             :             {
    1219           0 :                 aFinalColor = aColor;
    1220           0 :                 bInit = true;
    1221             :             }
    1222           0 :             else if( aFinalColor != aColor )
    1223             :             {
    1224           0 :                 bAmbigius = true;
    1225           0 :                 break;
    1226           0 :             }
    1227             :         }
    1228             :     }
    1229             : 
    1230           0 :     if( bAmbigius )
    1231           0 :         aFinalColor = COL_AUTO;
    1232             : 
    1233           0 :     if( bHasCustomShape )
    1234           0 :         rSet.Put( SvxColorItem( aFinalColor, SID_EXTRUSION_3D_COLOR ) );
    1235             :     else
    1236           0 :         rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
    1237           0 : }
    1238             : 
    1239             : namespace svx {
    1240        3162 : bool checkForSelectedCustomShapes( SdrView* pSdrView, bool bOnlyExtruded )
    1241             : {
    1242        3162 :     static const OUString  sExtrusion( "Extrusion" );
    1243             : 
    1244        3162 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    1245        3162 :     sal_uIntPtr nCount = rMarkList.GetMarkCount(), i;
    1246        3162 :     bool bFound = false;
    1247             : 
    1248        3213 :     for(i=0;(i<nCount) && !bFound ; i++)
    1249             :     {
    1250          51 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
    1251          51 :         if( pObj->ISA(SdrObjCustomShape) )
    1252             :         {
    1253           0 :             if( bOnlyExtruded )
    1254             :             {
    1255           0 :                 SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1256           0 :                 Any* pAny = aGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
    1257           0 :                 if( pAny )
    1258           0 :                     *pAny >>= bFound;
    1259             :             }
    1260             :             else
    1261             :             {
    1262           0 :                 bFound = true;
    1263             :             }
    1264             :         }
    1265             :     }
    1266             : 
    1267        3162 :     return bFound;
    1268             : }
    1269             : }
    1270             : 
    1271        2791 : void ExtrusionBar::getState( SdrView* pSdrView, SfxItemSet& rSet )
    1272             : {
    1273        2791 :     if (rSet.GetItemState(SID_EXTRUSION_DIRECTION) != SFX_ITEM_UNKNOWN)
    1274             :     {
    1275           0 :         getExtrusionDirectionState( pSdrView, rSet );
    1276             :     }
    1277        2791 :     if (rSet.GetItemState(SID_EXTRUSION_PROJECTION) != SFX_ITEM_UNKNOWN)
    1278             :     {
    1279           0 :         getExtrusionProjectionState( pSdrView, rSet );
    1280             :     }
    1281             :     const bool bOnlyExtrudedCustomShapes =
    1282        2791 :         checkForSelectedCustomShapes( pSdrView, true );
    1283        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
    1284             :     {
    1285           0 :         if (! bOnlyExtrudedCustomShapes)
    1286           0 :             rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
    1287             :     }
    1288        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TILT_DOWN) != SFX_ITEM_UNKNOWN)
    1289             :     {
    1290           0 :         if (! bOnlyExtrudedCustomShapes)
    1291           0 :             rSet.DisableItem( SID_EXTRUSION_TILT_DOWN );
    1292             :     }
    1293        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TILT_UP) != SFX_ITEM_UNKNOWN)
    1294             :     {
    1295           0 :         if (! bOnlyExtrudedCustomShapes)
    1296           0 :             rSet.DisableItem( SID_EXTRUSION_TILT_UP );
    1297             :     }
    1298        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TILT_LEFT) != SFX_ITEM_UNKNOWN)
    1299             :     {
    1300           0 :         if (! bOnlyExtrudedCustomShapes)
    1301           0 :             rSet.DisableItem( SID_EXTRUSION_TILT_LEFT );
    1302             :     }
    1303        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TILT_RIGHT) != SFX_ITEM_UNKNOWN)
    1304             :     {
    1305           0 :         if (! bOnlyExtrudedCustomShapes)
    1306           0 :             rSet.DisableItem( SID_EXTRUSION_TILT_RIGHT );
    1307             :     }
    1308        2791 :     if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
    1309             :     {
    1310           0 :         if (! bOnlyExtrudedCustomShapes)
    1311           0 :             rSet.DisableItem( SID_EXTRUSION_3D_COLOR );
    1312             :     }
    1313        2791 :     if (rSet.GetItemState(SID_EXTRUSION_DEPTH_FLOATER) != SFX_ITEM_UNKNOWN)
    1314             :     {
    1315           0 :         if (! bOnlyExtrudedCustomShapes)
    1316           0 :             rSet.DisableItem( SID_EXTRUSION_DEPTH_FLOATER );
    1317             :     }
    1318        2791 :     if (rSet.GetItemState(SID_EXTRUSION_DIRECTION_FLOATER) != SFX_ITEM_UNKNOWN)
    1319             :     {
    1320           0 :         if (! bOnlyExtrudedCustomShapes)
    1321           0 :             rSet.DisableItem( SID_EXTRUSION_DIRECTION_FLOATER );
    1322             :     }
    1323        2791 :     if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_FLOATER) != SFX_ITEM_UNKNOWN)
    1324             :     {
    1325           0 :         if (! bOnlyExtrudedCustomShapes)
    1326           0 :             rSet.DisableItem( SID_EXTRUSION_LIGHTING_FLOATER );
    1327             :     }
    1328        2791 :     if (rSet.GetItemState(SID_EXTRUSION_SURFACE_FLOATER) != SFX_ITEM_UNKNOWN)
    1329             :     {
    1330           0 :         if(! bOnlyExtrudedCustomShapes)
    1331           0 :             rSet.DisableItem( SID_EXTRUSION_SURFACE_FLOATER );
    1332             :     }
    1333        2791 :     if (rSet.GetItemState(SID_EXTRUSION_TOOGLE) != SFX_ITEM_UNKNOWN)
    1334             :     {
    1335          80 :         if( !checkForSelectedCustomShapes( pSdrView, false ) )
    1336          80 :             rSet.DisableItem( SID_EXTRUSION_TOOGLE );
    1337             :     }
    1338        2791 :     if (rSet.GetItemState(SID_EXTRUSION_DEPTH) != SFX_ITEM_UNKNOWN)
    1339             :     {
    1340           0 :         getExtrusionDepthState( pSdrView, rSet );
    1341             :     }
    1342        2791 :     if (rSet.GetItemState(SID_EXTRUSION_SURFACE) != SFX_ITEM_UNKNOWN)
    1343             :     {
    1344           0 :         getExtrusionSurfaceState( pSdrView, rSet );
    1345             :     }
    1346        2791 :     if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_INTENSITY) != SFX_ITEM_UNKNOWN)
    1347             :     {
    1348           0 :         getExtrusionLightingIntensityState( pSdrView, rSet );
    1349             :     }
    1350             : 
    1351        2791 :     if (rSet.GetItemState(SID_EXTRUSION_LIGHTING_DIRECTION) != SFX_ITEM_UNKNOWN)
    1352             :     {
    1353           0 :         getExtrusionLightingDirectionState( pSdrView, rSet );
    1354             :     }
    1355             : 
    1356        2791 :     if (rSet.GetItemState(SID_EXTRUSION_3D_COLOR) != SFX_ITEM_UNKNOWN)
    1357             :     {
    1358           0 :         getExtrusionColorState( pSdrView, rSet );
    1359             :     }
    1360        2791 : }
    1361             : 
    1362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10