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

Generated by: LCOV version 1.11