LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/dialog - dlgctl3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 612 0.2 %
Date: 2013-07-09 Functions: 2 54 3.7 %
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 <svx/dlgctl3d.hxx>
      22             : #include <svx/dialogs.hrc>
      23             : #include <svx/view3d.hxx>
      24             : #include <svx/fmmodel.hxx>
      25             : #include <svl/itempool.hxx>
      26             : #include <svx/fmpage.hxx>
      27             : #include <svx/polysc3d.hxx>
      28             : #include <svx/sphere3d.hxx>
      29             : #include <svx/cube3d.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <svx/helperhittest3d.hxx>
      32             : #include <basegfx/polygon/b2dpolygontools.hxx>
      33             : #include <svx/polygn3d.hxx>
      34             : #include <svx/xlnclit.hxx>
      35             : #include <svx/xlnwtit.hxx>
      36             : #include "helpid.hrc"
      37             : #include <algorithm>
      38             : #include <svx/dialmgr.hxx>
      39             : 
      40             : //////////////////////////////////////////////////////////////////////////////
      41             : 
      42           0 : Svx3DPreviewControl::Svx3DPreviewControl(Window* pParent, const ResId& rResId)
      43             : :   Control(pParent, rResId),
      44             :     mpModel(0),
      45             :     mpFmPage(0),
      46             :     mp3DView(0),
      47             :     mpScene(0),
      48             :     mp3DObj(0),
      49           0 :     mnObjectType(PREVIEW_OBJECTTYPE_SPHERE)
      50             : {
      51           0 :     Construct();
      52             : 
      53             :     // do not paint background self, DrawingLayer paints this buffered and as page
      54           0 :     SetControlBackground();
      55           0 :     SetBackground();
      56           0 : }
      57             : 
      58           0 : Svx3DPreviewControl::Svx3DPreviewControl(Window* pParent, WinBits nStyle)
      59             : :   Control(pParent, nStyle),
      60             :     mpModel(0),
      61             :     mpFmPage(0),
      62             :     mp3DView(0),
      63             :     mpScene(0),
      64             :     mp3DObj(0),
      65           0 :     mnObjectType(PREVIEW_OBJECTTYPE_SPHERE)
      66             : {
      67           0 :     Construct();
      68             : 
      69             :     // do not paint background self, DrawingLayer paints this buffered and as page
      70           0 :     SetControlBackground();
      71           0 :     SetBackground();
      72           0 : }
      73             : 
      74           0 : Svx3DPreviewControl::~Svx3DPreviewControl()
      75             : {
      76           0 :     delete mp3DView;
      77           0 :     delete mpModel;
      78           0 : }
      79             : 
      80           0 : void Svx3DPreviewControl::Construct()
      81             : {
      82             :     // Do never mirror the preview window.  This explicitly includes right
      83             :     // to left writing environments.
      84           0 :     EnableRTL (sal_False);
      85           0 :     SetMapMode( MAP_100TH_MM );
      86             : 
      87             :     // Model
      88           0 :     mpModel = new FmFormModel();
      89           0 :     mpModel->GetItemPool().FreezeIdRanges();
      90             : 
      91             :     // Page
      92           0 :     mpFmPage = new FmFormPage( *mpModel, NULL );
      93           0 :     mpModel->InsertPage( mpFmPage, 0 );
      94             : 
      95             :     // 3D View
      96           0 :     mp3DView = new E3dView( mpModel, this );
      97           0 :     mp3DView->SetBufferedOutputAllowed(true);
      98           0 :     mp3DView->SetBufferedOverlayAllowed(true);
      99             : 
     100             :     // 3D Scene
     101           0 :     mpScene = new E3dPolyScene(mp3DView->Get3DDefaultAttributes());
     102             : 
     103             :     // initially create object
     104           0 :     SetObjectType(PREVIEW_OBJECTTYPE_SPHERE);
     105             : 
     106             :     // camera and perspective
     107           0 :     Camera3D& rCamera  = (Camera3D&) mpScene->GetCamera();
     108           0 :     const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume();
     109           0 :     double fW = rVolume.getWidth();
     110           0 :     double fH = rVolume.getHeight();
     111           0 :     double fCamZ = rVolume.getMaxZ() + ((fW + fH) / 2.0);
     112             : 
     113           0 :     rCamera.SetAutoAdjustProjection(sal_False);
     114           0 :     rCamera.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
     115           0 :     basegfx::B3DPoint aLookAt;
     116           0 :     double fDefaultCamPosZ = mp3DView->GetDefaultCamPosZ();
     117           0 :     basegfx::B3DPoint aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ);
     118           0 :     rCamera.SetPosAndLookAt(aCamPos, aLookAt);
     119           0 :     double fDefaultCamFocal = mp3DView->GetDefaultCamFocal();
     120           0 :     rCamera.SetFocalLength(fDefaultCamFocal);
     121           0 :     rCamera.SetDefaults(basegfx::B3DPoint(0.0, 0.0, fDefaultCamPosZ), aLookAt, fDefaultCamFocal);
     122             : 
     123           0 :     mpScene->SetCamera( rCamera );
     124           0 :     mpFmPage->InsertObject( mpScene );
     125             : 
     126           0 :     basegfx::B3DHomMatrix aRotation;
     127           0 :     aRotation.rotate(DEG2RAD( 25 ), 0.0, 0.0);
     128           0 :     aRotation.rotate(0.0, DEG2RAD( 40 ), 0.0);
     129           0 :     mpScene->SetTransform(aRotation * mpScene->GetTransform());
     130             : 
     131             :     // invalidate SnapRects of objects
     132           0 :     mpScene->SetRectsDirty();
     133             : 
     134           0 :     SfxItemSet aSet( mpModel->GetItemPool(),
     135             :         XATTR_LINESTYLE, XATTR_LINESTYLE,
     136             :         XATTR_FILL_FIRST, XATTR_FILLBITMAP,
     137           0 :         0, 0 );
     138           0 :     aSet.Put( XLineStyleItem( XLINE_NONE ) );
     139           0 :     aSet.Put( XFillStyleItem( XFILL_SOLID ) );
     140           0 :     aSet.Put( XFillColorItem( String(), Color( COL_WHITE ) ) );
     141             : 
     142           0 :     mpScene->SetMergedItemSet(aSet);
     143             : 
     144             :     // PageView
     145           0 :     SdrPageView* pPageView = mp3DView->ShowSdrPage( mpFmPage );
     146           0 :     mp3DView->hideMarkHandles();
     147             : 
     148             :     // mark scene
     149           0 :     mp3DView->MarkObj( mpScene, pPageView );
     150           0 : }
     151             : 
     152           0 : void Svx3DPreviewControl::Resize()
     153             : {
     154             :     // size of page
     155           0 :     Size aSize( GetSizePixel() );
     156           0 :     aSize = PixelToLogic( aSize );
     157           0 :     mpFmPage->SetSize( aSize );
     158             : 
     159             :     // set size
     160           0 :     Size aObjSize( aSize.Width()*5/6, aSize.Height()*5/6 );
     161           0 :     Point aObjPoint( (aSize.Width() - aObjSize.Width()) / 2,
     162           0 :         (aSize.Height() - aObjSize.Height()) / 2);
     163           0 :     Rectangle aRect( aObjPoint, aObjSize);
     164           0 :     mpScene->SetSnapRect( aRect );
     165           0 : }
     166             : 
     167           0 : void Svx3DPreviewControl::Paint(const Rectangle& rRect)
     168             : {
     169           0 :     mp3DView->CompleteRedraw(this, Region(rRect));
     170           0 : }
     171             : 
     172           0 : void Svx3DPreviewControl::MouseButtonDown(const MouseEvent& rMEvt)
     173             : {
     174           0 :     Control::MouseButtonDown(rMEvt);
     175             : 
     176           0 :     if( rMEvt.IsShift() && rMEvt.IsMod1() )
     177             :     {
     178           0 :         if(PREVIEW_OBJECTTYPE_SPHERE == GetObjectType())
     179             :         {
     180           0 :             SetObjectType(PREVIEW_OBJECTTYPE_CUBE);
     181             :         }
     182             :         else
     183             :         {
     184           0 :             SetObjectType(PREVIEW_OBJECTTYPE_SPHERE);
     185             :         }
     186             :     }
     187           0 : }
     188             : 
     189           0 : void Svx3DPreviewControl::SetObjectType(sal_uInt16 nType)
     190             : {
     191           0 :     if( mnObjectType != nType || !mp3DObj)
     192             :     {
     193           0 :         SfxItemSet aSet(mpModel->GetItemPool(), SDRATTR_START, SDRATTR_END, 0, 0);
     194           0 :         mnObjectType = nType;
     195             : 
     196           0 :         if( mp3DObj )
     197             :         {
     198           0 :             aSet.Put(mp3DObj->GetMergedItemSet());
     199           0 :             mpScene->Remove3DObj( mp3DObj );
     200           0 :             delete mp3DObj;
     201           0 :             mp3DObj = NULL;
     202             :         }
     203             : 
     204           0 :         switch( nType )
     205             :         {
     206             :             case PREVIEW_OBJECTTYPE_SPHERE:
     207             :             {
     208             :                 mp3DObj = new E3dSphereObj(
     209           0 :                     mp3DView->Get3DDefaultAttributes(),
     210             :                     basegfx::B3DPoint( 0, 0, 0 ),
     211           0 :                     basegfx::B3DVector( 5000, 5000, 5000 ));
     212             :             }
     213           0 :             break;
     214             : 
     215             :             case PREVIEW_OBJECTTYPE_CUBE:
     216             :             {
     217             :                 mp3DObj = new E3dCubeObj(
     218           0 :                     mp3DView->Get3DDefaultAttributes(),
     219             :                     basegfx::B3DPoint( -2500, -2500, -2500 ),
     220           0 :                     basegfx::B3DVector( 5000, 5000, 5000 ));
     221             :             }
     222           0 :             break;
     223             :         }
     224             : 
     225           0 :         mpScene->Insert3DObj( mp3DObj );
     226           0 :         mp3DObj->SetMergedItemSet(aSet);
     227             : 
     228           0 :         Resize();
     229             :     }
     230           0 : }
     231             : 
     232           0 : SfxItemSet Svx3DPreviewControl::Get3DAttributes() const
     233             : {
     234           0 :     return mp3DObj->GetMergedItemSet();
     235             : }
     236             : 
     237           0 : void Svx3DPreviewControl::Set3DAttributes( const SfxItemSet& rAttr )
     238             : {
     239           0 :     mp3DObj->SetMergedItemSet(rAttr, true);
     240           0 :     Resize();
     241           0 : }
     242             : 
     243             : //////////////////////////////////////////////////////////////////////////////
     244             : 
     245             : #define RADIUS_LAMP_PREVIEW_SIZE    (4500.0)
     246             : #define RADIUS_LAMP_SMALL           (600.0)
     247             : #define RADIUS_LAMP_BIG             (1000.0)
     248             : #define NO_LIGHT_SELECTED           (0xffffffff)
     249             : #define MAX_NUMBER_LIGHTS              (8)
     250             : 
     251           0 : Svx3DLightControl::Svx3DLightControl(Window* pParent, WinBits nStyle)
     252             : :   Svx3DPreviewControl(pParent, nStyle),
     253             :     maUserInteractiveChangeCallback(),
     254             :     maUserSelectionChangeCallback(),
     255             :     maChangeCallback(),
     256             :     maSelectionChangeCallback(),
     257             :     maSelectedLight(NO_LIGHT_SELECTED),
     258             :     mpExpansionObject(0),
     259             :     mpLampBottomObject(0),
     260             :     mpLampShaftObject(0),
     261             :     maLightObjects(MAX_NUMBER_LIGHTS, (E3dObject*)0),
     262             :     mfRotateX(-20.0),
     263             :     mfRotateY(45.0),
     264             :     mfRotateZ(0.0),
     265             :     maActionStartPoint(),
     266             :     mnInteractionStartDistance(5 * 5 * 2),
     267             :     mfSaveActionStartHor(0.0),
     268             :     mfSaveActionStartVer(0.0),
     269             :     mfSaveActionStartRotZ(0.0),
     270             :     mbMouseMoved(false),
     271           0 :     mbGeometrySelected(false)
     272             : {
     273           0 :     Construct2();
     274           0 : }
     275             : 
     276           0 : Svx3DLightControl::~Svx3DLightControl()
     277             : {
     278             :     // SdrObjects like mpExpansionObject and mpLampBottomObject/mpLampShaftObject get deleted
     279             :     // with deletion of the DrawingLayer and model
     280           0 : }
     281             : 
     282           0 : void Svx3DLightControl::Construct2()
     283             : {
     284             :     {
     285             :         // hide all page stuff, use control background (normally gray)
     286           0 :         const Color aDialogColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
     287           0 :         mp3DView->SetPageVisible(false);
     288           0 :         mp3DView->SetApplicationBackgroundColor(aDialogColor);
     289           0 :         mp3DView->SetApplicationDocumentColor(aDialogColor);
     290             :     }
     291             : 
     292             :     {
     293             :         // create invisible expansion object
     294           0 :         const double fMaxExpansion(RADIUS_LAMP_BIG + RADIUS_LAMP_PREVIEW_SIZE);
     295             :         mpExpansionObject = new E3dCubeObj(
     296           0 :             mp3DView->Get3DDefaultAttributes(),
     297             :             basegfx::B3DPoint(-fMaxExpansion, -fMaxExpansion, -fMaxExpansion),
     298           0 :             basegfx::B3DVector(2.0 * fMaxExpansion, 2.0 * fMaxExpansion, 2.0 * fMaxExpansion));
     299           0 :         mpScene->Insert3DObj( mpExpansionObject );
     300           0 :         SfxItemSet aSet(mpModel->GetItemPool());
     301           0 :         aSet.Put( XLineStyleItem( XLINE_NONE ) );
     302           0 :         aSet.Put( XFillStyleItem( XFILL_NONE ) );
     303           0 :         mpExpansionObject->SetMergedItemSet(aSet);
     304             :     }
     305             : 
     306             :     {
     307             :         // create lamp control object (Yellow lined object)
     308             :         // base circle
     309           0 :         const basegfx::B2DPolygon a2DCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), RADIUS_LAMP_PREVIEW_SIZE));
     310           0 :         basegfx::B3DPolygon a3DCircle(basegfx::tools::createB3DPolygonFromB2DPolygon(a2DCircle));
     311           0 :         basegfx::B3DHomMatrix aTransform;
     312             : 
     313           0 :         aTransform.rotate(F_PI2, 0.0, 0.0);
     314           0 :         aTransform.translate(0.0, -RADIUS_LAMP_PREVIEW_SIZE, 0.0);
     315           0 :         a3DCircle.transform(aTransform);
     316             : 
     317             :         // create object for it
     318             :         mpLampBottomObject = new E3dPolygonObj(
     319           0 :             mp3DView->Get3DDefaultAttributes(),
     320             :             basegfx::B3DPolyPolygon(a3DCircle),
     321           0 :             true);
     322           0 :         mpScene->Insert3DObj( mpLampBottomObject );
     323             : 
     324             :         // half circle with stand
     325           0 :         basegfx::B2DPolygon a2DHalfCircle;
     326           0 :         a2DHalfCircle.append(basegfx::B2DPoint(RADIUS_LAMP_PREVIEW_SIZE, 0.0));
     327           0 :         a2DHalfCircle.append(basegfx::B2DPoint(RADIUS_LAMP_PREVIEW_SIZE, -RADIUS_LAMP_PREVIEW_SIZE));
     328             :         a2DHalfCircle.append(basegfx::tools::createPolygonFromEllipseSegment(
     329           0 :             basegfx::B2DPoint(0.0, 0.0), RADIUS_LAMP_PREVIEW_SIZE, RADIUS_LAMP_PREVIEW_SIZE, F_2PI - F_PI2, F_PI2));
     330           0 :         basegfx::B3DPolygon a3DHalfCircle(basegfx::tools::createB3DPolygonFromB2DPolygon(a2DHalfCircle));
     331             : 
     332             :         // create object for it
     333             :         mpLampShaftObject = new E3dPolygonObj(
     334           0 :             mp3DView->Get3DDefaultAttributes(),
     335             :             basegfx::B3DPolyPolygon(a3DHalfCircle),
     336           0 :             true);
     337           0 :         mpScene->Insert3DObj( mpLampShaftObject );
     338             : 
     339             :         // initially invisible
     340           0 :         SfxItemSet aSet(mpModel->GetItemPool());
     341           0 :         aSet.Put( XLineStyleItem( XLINE_NONE ) );
     342           0 :         aSet.Put( XFillStyleItem( XFILL_NONE ) );
     343             : 
     344           0 :         mpLampBottomObject->SetMergedItemSet(aSet);
     345           0 :         mpLampShaftObject->SetMergedItemSet(aSet);
     346             :     }
     347             : 
     348             :     {
     349             :         // change camera settings
     350           0 :         Camera3D& rCamera  = (Camera3D&) mpScene->GetCamera();
     351           0 :         const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume();
     352           0 :         double fW = rVolume.getWidth();
     353           0 :         double fH = rVolume.getHeight();
     354           0 :         double fCamZ = rVolume.getMaxZ() + ((fW + fH) / 2.0);
     355             : 
     356           0 :         rCamera.SetAutoAdjustProjection(sal_False);
     357           0 :         rCamera.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
     358           0 :         basegfx::B3DPoint aLookAt;
     359           0 :         double fDefaultCamPosZ = mp3DView->GetDefaultCamPosZ();
     360           0 :         basegfx::B3DPoint aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ);
     361           0 :         rCamera.SetPosAndLookAt(aCamPos, aLookAt);
     362           0 :         double fDefaultCamFocal = mp3DView->GetDefaultCamFocal();
     363           0 :         rCamera.SetFocalLength(fDefaultCamFocal);
     364           0 :         rCamera.SetDefaults(basegfx::B3DPoint(0.0, 0.0, fDefaultCamPosZ), aLookAt, fDefaultCamFocal);
     365             : 
     366           0 :         mpScene->SetCamera( rCamera );
     367             : 
     368           0 :         basegfx::B3DHomMatrix aNeutral;
     369           0 :         mpScene->SetTransform(aNeutral);
     370             :     }
     371             : 
     372             :     // invalidate SnapRects of objects
     373           0 :     mpScene->SetRectsDirty();
     374           0 : }
     375             : 
     376           0 : void Svx3DLightControl::ConstructLightObjects()
     377             : {
     378           0 :     for(sal_uInt32 a(0); a < MAX_NUMBER_LIGHTS; a++)
     379             :     {
     380             :         // get rid of possible existing light object
     381           0 :         if(maLightObjects[a])
     382             :         {
     383           0 :             mpScene->Remove3DObj(maLightObjects[a]);
     384           0 :             delete maLightObjects[a];
     385           0 :             maLightObjects[a] = 0;
     386             :         }
     387             : 
     388           0 :         if(GetLightOnOff(a))
     389             :         {
     390           0 :             const bool bIsSelectedLight(a == maSelectedLight);
     391           0 :             basegfx::B3DVector aDirection(GetLightDirection(a));
     392           0 :             aDirection.normalize();
     393           0 :             aDirection *= RADIUS_LAMP_PREVIEW_SIZE;
     394             : 
     395           0 :             const double fLampSize(bIsSelectedLight ? RADIUS_LAMP_BIG : RADIUS_LAMP_SMALL);
     396             :             E3dObject* pNewLight = new E3dSphereObj(
     397           0 :                 mp3DView->Get3DDefaultAttributes(),
     398             :                 basegfx::B3DPoint( 0, 0, 0 ),
     399           0 :                 basegfx::B3DVector( fLampSize, fLampSize, fLampSize));
     400           0 :             mpScene->Insert3DObj(pNewLight);
     401             : 
     402           0 :             basegfx::B3DHomMatrix aTransform;
     403           0 :             aTransform.translate(aDirection.getX(), aDirection.getY(), aDirection.getZ());
     404           0 :             pNewLight->SetTransform(aTransform);
     405             : 
     406           0 :             SfxItemSet aSet(mpModel->GetItemPool());
     407           0 :             aSet.Put( XLineStyleItem( XLINE_NONE ) );
     408           0 :             aSet.Put( XFillStyleItem( XFILL_SOLID ) );
     409           0 :             aSet.Put( XFillColorItem(String(), GetLightColor(a)));
     410           0 :             pNewLight->SetMergedItemSet(aSet);
     411             : 
     412           0 :             maLightObjects[a] = pNewLight;
     413             :         }
     414             :     }
     415           0 : }
     416             : 
     417           0 : void Svx3DLightControl::AdaptToSelectedLight()
     418             : {
     419           0 :     if(NO_LIGHT_SELECTED == maSelectedLight)
     420             :     {
     421             :         // make mpLampBottomObject/mpLampShaftObject invisible
     422           0 :         SfxItemSet aSet(mpModel->GetItemPool());
     423           0 :         aSet.Put( XLineStyleItem( XLINE_NONE ) );
     424           0 :         aSet.Put( XFillStyleItem( XFILL_NONE ) );
     425           0 :         mpLampBottomObject->SetMergedItemSet(aSet);
     426           0 :         mpLampShaftObject->SetMergedItemSet(aSet);
     427             :     }
     428             :     else
     429             :     {
     430           0 :         basegfx::B3DVector aDirection(GetLightDirection(maSelectedLight));
     431           0 :         aDirection.normalize();
     432             : 
     433             :         // make mpLampBottomObject/mpLampShaftObject visible (yellow hairline)
     434           0 :         SfxItemSet aSet(mpModel->GetItemPool());
     435           0 :         aSet.Put( XLineStyleItem( XLINE_SOLID ) );
     436           0 :         aSet.Put( XLineColorItem(String(), COL_YELLOW));
     437           0 :         aSet.Put( XLineWidthItem(0));
     438           0 :         aSet.Put( XFillStyleItem( XFILL_NONE ) );
     439           0 :         mpLampBottomObject->SetMergedItemSet(aSet);
     440           0 :         mpLampShaftObject->SetMergedItemSet(aSet);
     441             : 
     442             :         // adapt transformation of mpLampShaftObject
     443           0 :         basegfx::B3DHomMatrix aTransform;
     444           0 :         double fRotateY(0.0);
     445             : 
     446           0 :         if(!basegfx::fTools::equalZero(aDirection.getZ()) || !basegfx::fTools::equalZero(aDirection.getX()))
     447             :         {
     448           0 :             fRotateY = atan2(-aDirection.getZ(), aDirection.getX());
     449             :         }
     450             : 
     451           0 :         aTransform.rotate(0.0, fRotateY, 0.0);
     452           0 :         mpLampShaftObject->SetTransform(aTransform);
     453             : 
     454             :         // adapt transformation of selected light
     455           0 :         E3dObject* pSelectedLight = maLightObjects[sal_Int32(maSelectedLight)];
     456             : 
     457           0 :         if(pSelectedLight)
     458             :         {
     459           0 :             aTransform.identity();
     460             :             aTransform.translate(
     461           0 :                 aDirection.getX() * RADIUS_LAMP_PREVIEW_SIZE,
     462           0 :                 aDirection.getY() * RADIUS_LAMP_PREVIEW_SIZE,
     463           0 :                 aDirection.getZ() * RADIUS_LAMP_PREVIEW_SIZE);
     464           0 :             pSelectedLight->SetTransform(aTransform);
     465           0 :         }
     466             :     }
     467           0 : }
     468             : 
     469           0 : void Svx3DLightControl::TrySelection(Point aPosPixel)
     470             : {
     471           0 :     if(mpScene)
     472             :     {
     473           0 :         const Point aPosLogic(PixelToLogic(aPosPixel));
     474           0 :         const basegfx::B2DPoint aPoint(aPosLogic.X(), aPosLogic.Y());
     475           0 :         std::vector< const E3dCompoundObject* > aResult;
     476           0 :         getAllHit3DObjectsSortedFrontToBack(aPoint, *mpScene, aResult);
     477             : 
     478           0 :         if(!aResult.empty())
     479             :         {
     480             :             // exclude expansion object which will be part of
     481             :             // the hits. It's invisible, but for HitTest, it's included
     482           0 :             const E3dCompoundObject* pResult = 0;
     483             : 
     484           0 :             for(sal_uInt32 b(0); !pResult && b < aResult.size(); b++)
     485             :             {
     486           0 :                 if(aResult[b] && aResult[b] != mpExpansionObject)
     487             :                 {
     488           0 :                     pResult = aResult[b];
     489             :                 }
     490             :             }
     491             : 
     492           0 :             if(pResult == mp3DObj)
     493             :             {
     494           0 :                 if(!mbGeometrySelected)
     495             :                 {
     496           0 :                     mbGeometrySelected = true;
     497           0 :                     maSelectedLight = NO_LIGHT_SELECTED;
     498           0 :                     ConstructLightObjects();
     499           0 :                     AdaptToSelectedLight();
     500           0 :                     Invalidate();
     501             : 
     502           0 :                     if(maSelectionChangeCallback.IsSet())
     503             :                     {
     504           0 :                         maSelectionChangeCallback.Call(this);
     505             :                     }
     506             :                 }
     507             :             }
     508             :             else
     509             :             {
     510           0 :                 sal_uInt32 aNewSelectedLight(NO_LIGHT_SELECTED);
     511             : 
     512           0 :                 for(sal_uInt32 a(0); a < MAX_NUMBER_LIGHTS; a++)
     513             :                 {
     514           0 :                     if(maLightObjects[a] && maLightObjects[a] == pResult)
     515             :                     {
     516           0 :                         aNewSelectedLight = a;
     517             :                     }
     518             :                 }
     519             : 
     520           0 :                 if(aNewSelectedLight != maSelectedLight)
     521             :                 {
     522           0 :                     SelectLight(aNewSelectedLight);
     523             : 
     524           0 :                     if(maSelectionChangeCallback.IsSet())
     525             :                     {
     526           0 :                         maSelectionChangeCallback.Call(this);
     527             :                     }
     528             :                 }
     529             :             }
     530           0 :         }
     531             :     }
     532           0 : }
     533             : 
     534           0 : void Svx3DLightControl::Paint(const Rectangle& rRect)
     535             : {
     536           0 :     Svx3DPreviewControl::Paint(rRect);
     537           0 : }
     538             : 
     539           0 : void Svx3DLightControl::MouseButtonDown( const MouseEvent& rMEvt )
     540             : {
     541           0 :     bool bCallParent(true);
     542             : 
     543             :     // switch state
     544           0 :     if(rMEvt.IsLeft())
     545             :     {
     546           0 :         if(IsSelectionValid() || mbGeometrySelected)
     547             :         {
     548           0 :             mbMouseMoved = false;
     549           0 :             bCallParent = false;
     550           0 :             maActionStartPoint = rMEvt.GetPosPixel();
     551           0 :             StartTracking();
     552             :         }
     553             :         else
     554             :         {
     555             :             // Single click without moving much trying to do a selection
     556           0 :             TrySelection(rMEvt.GetPosPixel());
     557           0 :             bCallParent = false;
     558             :         }
     559             :     }
     560             : 
     561             :     // call parent
     562           0 :     if(bCallParent)
     563             :     {
     564           0 :         Svx3DPreviewControl::MouseButtonDown(rMEvt);
     565             :     }
     566           0 : }
     567             : 
     568           0 : void Svx3DLightControl::Tracking( const TrackingEvent& rTEvt )
     569             : {
     570           0 :     if(rTEvt.IsTrackingEnded())
     571             :     {
     572           0 :         if(rTEvt.IsTrackingCanceled())
     573             :         {
     574           0 :             if(mbMouseMoved)
     575             :             {
     576             :                 // interrupt tracking
     577           0 :                 mbMouseMoved = false;
     578             : 
     579           0 :                 if(mbGeometrySelected)
     580             :                 {
     581           0 :                     SetRotation(mfSaveActionStartVer, mfSaveActionStartHor, mfSaveActionStartRotZ);
     582             :                 }
     583             :                 else
     584             :                 {
     585           0 :                     SetPosition(mfSaveActionStartHor, mfSaveActionStartVer);
     586             :                 }
     587             : 
     588           0 :                 if(maChangeCallback.IsSet())
     589             :                 {
     590           0 :                     maChangeCallback.Call(this);
     591             :                 }
     592             :             }
     593             :         }
     594             :         else
     595             :         {
     596           0 :             const MouseEvent& rMEvt = rTEvt.GetMouseEvent();
     597             : 
     598           0 :             if(mbMouseMoved)
     599             :             {
     600             :                 // was change dinteractively
     601             :             }
     602             :             else
     603             :             {
     604             :                 // simple click without much movement, try selection
     605           0 :                 TrySelection(rMEvt.GetPosPixel());
     606             :             }
     607             :         }
     608             :     }
     609             :     else
     610             :     {
     611           0 :         const MouseEvent& rMEvt = rTEvt.GetMouseEvent();
     612           0 :         Point aDeltaPos = rMEvt.GetPosPixel() - maActionStartPoint;
     613             : 
     614           0 :         if(!mbMouseMoved)
     615             :         {
     616           0 :             if(sal_Int32(aDeltaPos.X() * aDeltaPos.X() + aDeltaPos.Y() * aDeltaPos.Y()) > mnInteractionStartDistance)
     617             :             {
     618           0 :                 if(mbGeometrySelected)
     619             :                 {
     620           0 :                     GetRotation(mfSaveActionStartVer, mfSaveActionStartHor, mfSaveActionStartRotZ);
     621             :                 }
     622             :                 else
     623             :                 {
     624             :                     // intercation start, save values
     625           0 :                     GetPosition(mfSaveActionStartHor, mfSaveActionStartVer);
     626             :                 }
     627             : 
     628           0 :                 mbMouseMoved = true;
     629             :             }
     630             :         }
     631             : 
     632           0 :         if(mbMouseMoved)
     633             :         {
     634           0 :             if(mbGeometrySelected)
     635             :             {
     636           0 :                 double fNewRotX = mfSaveActionStartVer - ((double)aDeltaPos.Y() * F_PI180);
     637           0 :                 double fNewRotY = mfSaveActionStartHor + ((double)aDeltaPos.X() * F_PI180);
     638             : 
     639             :                 // cut horizontal
     640           0 :                 while(fNewRotY < 0.0)
     641             :                 {
     642           0 :                     fNewRotY += F_2PI;
     643             :                 }
     644             : 
     645           0 :                 while(fNewRotY >= F_2PI)
     646             :                 {
     647           0 :                     fNewRotY -= F_2PI;
     648             :                 }
     649             : 
     650             :                 // cut vertical
     651           0 :                 if(fNewRotX < -F_PI2)
     652             :                 {
     653           0 :                     fNewRotX = -F_PI2;
     654             :                 }
     655             : 
     656           0 :                 if(fNewRotX > F_PI2)
     657             :                 {
     658           0 :                     fNewRotX = F_PI2;
     659             :                 }
     660             : 
     661           0 :                 SetRotation(fNewRotX, fNewRotY, mfSaveActionStartRotZ);
     662             : 
     663           0 :                 if(maChangeCallback.IsSet())
     664             :                 {
     665           0 :                     maChangeCallback.Call(this);
     666             :                 }
     667             :             }
     668             :             else
     669             :             {
     670             :                 // interaction in progress
     671           0 :                 double fNewPosHor = mfSaveActionStartHor + ((double)aDeltaPos.X());
     672           0 :                 double fNewPosVer = mfSaveActionStartVer - ((double)aDeltaPos.Y());
     673             : 
     674             :                 // cut horizontal
     675           0 :                 while(fNewPosHor < 0.0)
     676             :                 {
     677           0 :                     fNewPosHor += 360.0;
     678             :                 }
     679             : 
     680           0 :                 while(fNewPosHor >= 360.0)
     681             :                 {
     682           0 :                     fNewPosHor -= 360.0;
     683             :                 }
     684             : 
     685             :                 // cut vertical
     686           0 :                 if(fNewPosVer < -90.0)
     687             :                 {
     688           0 :                     fNewPosVer = -90.0;
     689             :                 }
     690             : 
     691           0 :                 if(fNewPosVer > 90.0)
     692             :                 {
     693           0 :                     fNewPosVer = 90.0;
     694             :                 }
     695             : 
     696           0 :                 SetPosition(fNewPosHor, fNewPosVer);
     697             : 
     698           0 :                 if(maChangeCallback.IsSet())
     699             :                 {
     700           0 :                     maChangeCallback.Call(this);
     701             :                 }
     702             :             }
     703             :         }
     704             :     }
     705           0 : }
     706             : 
     707           0 : void Svx3DLightControl::Resize()
     708             : {
     709             :     // set size of page
     710           0 :     const Size aSize(PixelToLogic(GetSizePixel()));
     711           0 :     mpFmPage->SetSize(aSize);
     712             : 
     713             :     // set position and size of scene
     714           0 :     mpScene->SetSnapRect(Rectangle(Point(0, 0), aSize));
     715           0 : }
     716             : 
     717           0 : void Svx3DLightControl::SetObjectType(sal_uInt16 nType)
     718             : {
     719             :     // call parent
     720           0 :     Svx3DPreviewControl::SetObjectType(nType);
     721             : 
     722             :     // apply object rotation
     723           0 :     if(mp3DObj)
     724             :     {
     725           0 :         basegfx::B3DHomMatrix aObjectRotation;
     726           0 :         aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ);
     727           0 :         mp3DObj->SetTransform(aObjectRotation);
     728             :     }
     729           0 : }
     730             : 
     731           0 : bool Svx3DLightControl::IsSelectionValid()
     732             : {
     733           0 :     if((NO_LIGHT_SELECTED != maSelectedLight) && (GetLightOnOff(maSelectedLight)))
     734             :     {
     735           0 :         return true;
     736             :     }
     737             : 
     738           0 :     return false;
     739             : }
     740             : 
     741           0 : void Svx3DLightControl::GetPosition(double& rHor, double& rVer)
     742             : {
     743           0 :     if(IsSelectionValid())
     744             :     {
     745           0 :         basegfx::B3DVector aDirection(GetLightDirection(maSelectedLight));
     746           0 :         aDirection.normalize();
     747           0 :         rHor = atan2(-aDirection.getX(), -aDirection.getZ()) + F_PI; // 0..2PI
     748           0 :         rVer = atan2(aDirection.getY(), aDirection.getXZLength()); // -PI2..PI2
     749           0 :         rHor /= F_PI180; // 0..360.0
     750           0 :         rVer /= F_PI180; // -90.0..90.0
     751             :     }
     752           0 :     if(IsGeometrySelected())
     753             :     {
     754           0 :         rHor = mfRotateY / F_PI180; // 0..360.0
     755           0 :         rVer = mfRotateX / F_PI180; // -90.0..90.0
     756             :     }
     757           0 : }
     758             : 
     759           0 : void Svx3DLightControl::SetPosition(double fHor, double fVer)
     760             : {
     761           0 :     if(IsSelectionValid())
     762             :     {
     763             :         // set selected light's direction
     764           0 :         fHor = (fHor * F_PI180) - F_PI; // -PI..PI
     765           0 :         fVer *= F_PI180; // -PI2..PI2
     766           0 :         basegfx::B3DVector aDirection(cos(fVer) * -sin(fHor), sin(fVer), cos(fVer) * -cos(fHor));
     767           0 :         aDirection.normalize();
     768             : 
     769           0 :         if(!aDirection.equal(GetLightDirection(maSelectedLight)))
     770             :         {
     771             :             // set changed light direction at SdrScene
     772           0 :             SfxItemSet aSet(mpModel->GetItemPool());
     773             : 
     774           0 :             switch(maSelectedLight)
     775             :             {
     776           0 :                 case 0: aSet.Put(Svx3DLightDirection1Item(aDirection)); break;
     777           0 :                 case 1: aSet.Put(Svx3DLightDirection2Item(aDirection)); break;
     778           0 :                 case 2: aSet.Put(Svx3DLightDirection3Item(aDirection)); break;
     779           0 :                 case 3: aSet.Put(Svx3DLightDirection4Item(aDirection)); break;
     780           0 :                 case 4: aSet.Put(Svx3DLightDirection5Item(aDirection)); break;
     781           0 :                 case 5: aSet.Put(Svx3DLightDirection6Item(aDirection)); break;
     782           0 :                 case 6: aSet.Put(Svx3DLightDirection7Item(aDirection)); break;
     783             :                 default:
     784           0 :                 case 7: aSet.Put(Svx3DLightDirection8Item(aDirection)); break;
     785             :             }
     786             : 
     787           0 :             mpScene->SetMergedItemSet(aSet);
     788             : 
     789             :             // correct 3D light's and LampFrame's geometries
     790           0 :             AdaptToSelectedLight();
     791           0 :             Invalidate();
     792           0 :         }
     793             :     }
     794           0 :     if(IsGeometrySelected())
     795             :     {
     796           0 :         if(mfRotateX != fVer || mfRotateY != fHor)
     797             :         {
     798           0 :             mfRotateX = fVer * F_PI180;
     799           0 :             mfRotateY = fHor * F_PI180;
     800             : 
     801           0 :             if(mp3DObj)
     802             :             {
     803           0 :                 basegfx::B3DHomMatrix aObjectRotation;
     804           0 :                 aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ);
     805           0 :                 mp3DObj->SetTransform(aObjectRotation);
     806             : 
     807           0 :                 Invalidate();
     808             :             }
     809             :         }
     810             :     }
     811           0 : }
     812             : 
     813           0 : void Svx3DLightControl::SetRotation(double fRotX, double fRotY, double fRotZ)
     814             : {
     815           0 :     if(IsGeometrySelected())
     816             :     {
     817           0 :         if(fRotX != mfRotateX || fRotY != mfRotateY || fRotZ != mfRotateZ)
     818             :         {
     819           0 :             mfRotateX = fRotX;
     820           0 :             mfRotateY = fRotY;
     821           0 :             mfRotateZ = fRotZ;
     822             : 
     823           0 :             if(mp3DObj)
     824             :             {
     825           0 :                 basegfx::B3DHomMatrix aObjectRotation;
     826           0 :                 aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ);
     827           0 :                 mp3DObj->SetTransform(aObjectRotation);
     828             : 
     829           0 :                 Invalidate();
     830             :             }
     831             :         }
     832             :     }
     833           0 : }
     834             : 
     835           0 : void Svx3DLightControl::GetRotation(double& rRotX, double& rRotY, double& rRotZ)
     836             : {
     837           0 :     rRotX = mfRotateX;
     838           0 :     rRotY = mfRotateY;
     839           0 :     rRotZ = mfRotateZ;
     840           0 : }
     841             : 
     842           0 : void Svx3DLightControl::Set3DAttributes( const SfxItemSet& rAttr )
     843             : {
     844             :     // call parent
     845           0 :     Svx3DPreviewControl::Set3DAttributes(rAttr);
     846             : 
     847           0 :     if(maSelectedLight != NO_LIGHT_SELECTED && !GetLightOnOff(maSelectedLight))
     848             :     {
     849             :         // selected light is no more active, select new one
     850           0 :         maSelectedLight = NO_LIGHT_SELECTED;
     851             :     }
     852             : 
     853             :     // local updates
     854           0 :     ConstructLightObjects();
     855           0 :     AdaptToSelectedLight();
     856           0 :     Invalidate();
     857           0 : }
     858             : 
     859           0 : void Svx3DLightControl::SelectLight(sal_uInt32 nLightNumber)
     860             : {
     861           0 :     if(nLightNumber > 7)
     862             :     {
     863           0 :         nLightNumber = NO_LIGHT_SELECTED;
     864             :     }
     865             : 
     866           0 :     if(NO_LIGHT_SELECTED != nLightNumber)
     867             :     {
     868           0 :         if(!GetLightOnOff(nLightNumber))
     869             :         {
     870           0 :             nLightNumber = NO_LIGHT_SELECTED;
     871             :         }
     872             :     }
     873             : 
     874           0 :     if(nLightNumber != maSelectedLight)
     875             :     {
     876           0 :         maSelectedLight = nLightNumber;
     877           0 :         mbGeometrySelected = false;
     878           0 :         ConstructLightObjects();
     879           0 :         AdaptToSelectedLight();
     880           0 :         Invalidate();
     881             :     }
     882           0 : }
     883             : 
     884           0 : bool Svx3DLightControl::GetLightOnOff(sal_uInt32 nNum) const
     885             : {
     886           0 :     if(nNum <= 7)
     887             :     {
     888           0 :         const SfxItemSet aLightItemSet(Get3DAttributes());
     889             : 
     890           0 :         switch(nNum)
     891             :         {
     892           0 :             case 0 : return ((const Svx3DLightOnOff1Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue();
     893           0 :             case 1 : return ((const Svx3DLightOnOff2Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue();
     894           0 :             case 2 : return ((const Svx3DLightOnOff3Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue();
     895           0 :             case 3 : return ((const Svx3DLightOnOff4Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue();
     896           0 :             case 4 : return ((const Svx3DLightOnOff5Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue();
     897           0 :             case 5 : return ((const Svx3DLightOnOff6Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue();
     898           0 :             case 6 : return ((const Svx3DLightOnOff7Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue();
     899           0 :             case 7 : return ((const Svx3DLightOnOff8Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue();
     900           0 :         }
     901             :     }
     902             : 
     903           0 :     return false;
     904             : }
     905             : 
     906           0 : Color Svx3DLightControl::GetLightColor(sal_uInt32 nNum) const
     907             : {
     908           0 :     if(nNum <= 7)
     909             :     {
     910           0 :         const SfxItemSet aLightItemSet(Get3DAttributes());
     911             : 
     912           0 :         switch(nNum)
     913             :         {
     914           0 :             case 0 : return ((const Svx3DLightcolor1Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue();
     915           0 :             case 1 : return ((const Svx3DLightcolor2Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue();
     916           0 :             case 2 : return ((const Svx3DLightcolor3Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue();
     917           0 :             case 3 : return ((const Svx3DLightcolor4Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue();
     918           0 :             case 4 : return ((const Svx3DLightcolor5Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue();
     919           0 :             case 5 : return ((const Svx3DLightcolor6Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue();
     920           0 :             case 6 : return ((const Svx3DLightcolor7Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue();
     921           0 :             case 7 : return ((const Svx3DLightcolor8Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue();
     922           0 :         }
     923             :     }
     924             : 
     925           0 :     return Color(COL_BLACK);
     926             : }
     927             : 
     928           0 : basegfx::B3DVector Svx3DLightControl::GetLightDirection(sal_uInt32 nNum) const
     929             : {
     930           0 :     if(nNum <= 7)
     931             :     {
     932           0 :         const SfxItemSet aLightItemSet(Get3DAttributes());
     933             : 
     934           0 :         switch(nNum)
     935             :         {
     936           0 :             case 0 : return ((const Svx3DLightDirection1Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue();
     937           0 :             case 1 : return ((const Svx3DLightDirection2Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue();
     938           0 :             case 2 : return ((const Svx3DLightDirection3Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue();
     939           0 :             case 3 : return ((const Svx3DLightDirection4Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue();
     940           0 :             case 4 : return ((const Svx3DLightDirection5Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue();
     941           0 :             case 5 : return ((const Svx3DLightDirection6Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue();
     942           0 :             case 6 : return ((const Svx3DLightDirection7Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue();
     943           0 :             case 7 : return ((const Svx3DLightDirection8Item&)aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue();
     944           0 :         }
     945             :     }
     946             : 
     947           0 :     return basegfx::B3DVector();
     948             : }
     949             : 
     950             : //////////////////////////////////////////////////////////////////////////////
     951             : 
     952           0 : SvxLightCtl3D::SvxLightCtl3D( Window* pParent, const ResId& rResId)
     953             : :   Control(pParent, rResId),
     954             :     maLightControl(this, 0),
     955             :     maHorScroller(this, WB_HORZ | WB_DRAG),
     956             :     maVerScroller(this, WB_VERT | WB_DRAG),
     957           0 :     maSwitcher(this, 0)
     958             : {
     959             :     // init members
     960           0 :     Init();
     961           0 : }
     962             : 
     963           0 : void SvxLightCtl3D::Init()
     964             : {
     965             :     // #i58240# set HelpIDs for scrollbars and switcher
     966           0 :     maHorScroller.SetHelpId(HID_CTRL3D_HSCROLL);
     967           0 :     maVerScroller.SetHelpId(HID_CTRL3D_VSCROLL);
     968           0 :     maSwitcher.SetHelpId(HID_CTRL3D_SWITCHER);
     969           0 :     maSwitcher.SetAccessibleName(String(SVX_RES(STR_SWITCH)));
     970             : 
     971             :     // Light preview
     972           0 :     maLightControl.Show();
     973           0 :     maLightControl.SetChangeCallback( LINK(this, SvxLightCtl3D, InternalInteractiveChange) );
     974           0 :     maLightControl.SetSelectionChangeCallback( LINK(this, SvxLightCtl3D, InternalSelectionChange) );
     975             : 
     976             :     // Horiz Scrollbar
     977           0 :     maHorScroller.Show();
     978           0 :     maHorScroller.SetRange(Range(0, 36000));
     979           0 :     maHorScroller.SetLineSize(100);
     980           0 :     maHorScroller.SetPageSize(1000);
     981           0 :     maHorScroller.SetScrollHdl( LINK(this, SvxLightCtl3D, ScrollBarMove) );
     982             : 
     983             :     // Vert Scrollbar
     984           0 :     maVerScroller.Show();
     985           0 :     maVerScroller.SetRange(Range(0, 18000));
     986           0 :     maVerScroller.SetLineSize(100);
     987           0 :     maVerScroller.SetPageSize(1000);
     988           0 :     maVerScroller.SetScrollHdl( LINK(this, SvxLightCtl3D, ScrollBarMove) );
     989             : 
     990             :     // Switch Button
     991           0 :     maSwitcher.Show();
     992           0 :     maSwitcher.SetClickHdl( LINK(this, SvxLightCtl3D, ButtonPress) );
     993             : 
     994             :     // check selection
     995           0 :     CheckSelection();
     996             : 
     997             :     // new layout
     998           0 :     NewLayout();
     999           0 : }
    1000             : 
    1001           0 : SvxLightCtl3D::~SvxLightCtl3D()
    1002             : {
    1003           0 : }
    1004             : 
    1005           0 : void SvxLightCtl3D::Resize()
    1006             : {
    1007             :     // call parent
    1008           0 :     Control::Resize();
    1009             : 
    1010             :     // new layout
    1011           0 :     NewLayout();
    1012           0 : }
    1013             : 
    1014           0 : void SvxLightCtl3D::NewLayout()
    1015             : {
    1016             :     // Layout members
    1017           0 :     const Size aSize(GetOutputSizePixel());
    1018           0 :     const sal_Int32 nScrollSize(maHorScroller.GetSizePixel().Height());
    1019             : 
    1020             :     // Preview control
    1021           0 :     Point aPoint(0, 0);
    1022           0 :     Size aDestSize(aSize.Width() - nScrollSize, aSize.Height() - nScrollSize);
    1023           0 :     maLightControl.SetPosSizePixel(aPoint, aDestSize);
    1024             : 
    1025             :     // hor scrollbar
    1026           0 :     aPoint.Y() = aSize.Height() - nScrollSize;
    1027           0 :     aDestSize.Height() = nScrollSize;
    1028           0 :     maHorScroller.SetPosSizePixel(aPoint, aDestSize);
    1029             : 
    1030             :     // vert scrollbar
    1031           0 :     aPoint.X() = aSize.Width() - nScrollSize;
    1032           0 :     aPoint.Y() = 0;
    1033           0 :     aDestSize.Width() = nScrollSize;
    1034           0 :     aDestSize.Height() = aSize.Height() - nScrollSize;
    1035           0 :     maVerScroller.SetPosSizePixel(aPoint, aDestSize);
    1036             : 
    1037             :     // button
    1038           0 :     aPoint.Y() = aSize.Height() - nScrollSize;
    1039           0 :     aDestSize.Height() = nScrollSize;
    1040           0 :     maSwitcher.SetPosSizePixel(aPoint, aDestSize);
    1041           0 : }
    1042             : 
    1043           0 : void SvxLightCtl3D::CheckSelection()
    1044             : {
    1045           0 :     const bool bSelectionValid(maLightControl.IsSelectionValid() || maLightControl.IsGeometrySelected());
    1046           0 :     maHorScroller.Enable(bSelectionValid);
    1047           0 :     maVerScroller.Enable(bSelectionValid);
    1048             : 
    1049           0 :     if(bSelectionValid)
    1050             :     {
    1051             :         double fHor, fVer;
    1052           0 :         maLightControl.GetPosition(fHor, fVer);
    1053           0 :         maHorScroller.SetThumbPos( sal_Int32(fHor * 100.0) );
    1054           0 :         maVerScroller.SetThumbPos( 18000 - sal_Int32((fVer + 90.0) * 100.0) );
    1055             :     }
    1056           0 : }
    1057             : 
    1058           0 : void SvxLightCtl3D::move( double fDeltaHor, double fDeltaVer )
    1059             : {
    1060             :     double fHor, fVer;
    1061             : 
    1062           0 :     maLightControl.GetPosition(fHor, fVer);
    1063           0 :     fHor += fDeltaHor;
    1064           0 :     fVer += fDeltaVer;
    1065             : 
    1066           0 :     if( fVer > 90.0 )
    1067           0 :         return;
    1068             : 
    1069           0 :     if ( fVer < -90.0 )
    1070           0 :         return;
    1071             : 
    1072           0 :     maLightControl.SetPosition(fHor, fVer);
    1073           0 :     maHorScroller.SetThumbPos( sal_Int32(fHor * 100.0) );
    1074           0 :     maVerScroller.SetThumbPos( 18000 - sal_Int32((fVer + 90.0) * 100.0) );
    1075             : 
    1076           0 :     if(maUserInteractiveChangeCallback.IsSet())
    1077             :     {
    1078           0 :         maUserInteractiveChangeCallback.Call(this);
    1079             :     }
    1080             : }
    1081             : 
    1082           0 : void SvxLightCtl3D::KeyInput( const KeyEvent& rKEvt )
    1083             : {
    1084           0 :     const KeyCode aCode(rKEvt.GetKeyCode());
    1085             : 
    1086           0 :     if( aCode.GetModifier() )
    1087             :     {
    1088           0 :         Control::KeyInput( rKEvt );
    1089           0 :         return;
    1090             :     }
    1091             : 
    1092           0 :     switch ( aCode.GetCode() )
    1093             :     {
    1094             :         case KEY_SPACE:
    1095             :         {
    1096           0 :             break;
    1097             :         }
    1098             :         case KEY_LEFT:
    1099             :         {
    1100           0 :             move(  -4.0,  0.0 ); // #i58242# changed move direction in X
    1101           0 :             break;
    1102             :         }
    1103             :         case KEY_RIGHT:
    1104             :         {
    1105           0 :             move( 4.0,  0.0 ); // #i58242# changed move direction in X
    1106           0 :             break;
    1107             :         }
    1108             :         case KEY_UP:
    1109             :         {
    1110           0 :             move(  0.0,  4.0 );
    1111           0 :             break;
    1112             :         }
    1113             :         case KEY_DOWN:
    1114             :         {
    1115           0 :             move(  0.0, -4.0 );
    1116           0 :             break;
    1117             :         }
    1118             :         case KEY_PAGEUP:
    1119             :         {
    1120           0 :             sal_Int32 nLight(maLightControl.GetSelectedLight() - 1);
    1121             : 
    1122           0 :             while((nLight >= 0) && !maLightControl.GetLightOnOff(nLight))
    1123             :             {
    1124           0 :                 nLight--;
    1125             :             }
    1126             : 
    1127           0 :             if(nLight < 0)
    1128             :             {
    1129           0 :                 nLight = 7;
    1130             : 
    1131           0 :                 while((nLight >= 0) && !maLightControl.GetLightOnOff(nLight))
    1132             :                 {
    1133           0 :                     nLight--;
    1134             :                 }
    1135             :             }
    1136             : 
    1137           0 :             if(nLight >= 0)
    1138             :             {
    1139           0 :                 maLightControl.SelectLight(nLight);
    1140           0 :                 CheckSelection();
    1141             : 
    1142           0 :                 if(maUserSelectionChangeCallback.IsSet())
    1143             :                 {
    1144           0 :                     maUserSelectionChangeCallback.Call(this);
    1145             :                 }
    1146             :             }
    1147             : 
    1148           0 :             break;
    1149             :         }
    1150             :         case KEY_PAGEDOWN:
    1151             :         {
    1152           0 :             sal_Int32 nLight(maLightControl.GetSelectedLight() - 1);
    1153             : 
    1154           0 :             while(nLight <= 7 && !maLightControl.GetLightOnOff(nLight))
    1155             :             {
    1156           0 :                 nLight++;
    1157             :             }
    1158             : 
    1159           0 :             if(nLight > 7)
    1160             :             {
    1161           0 :                 nLight = 0;
    1162             : 
    1163           0 :                 while(nLight <= 7 && !maLightControl.GetLightOnOff(nLight))
    1164             :                 {
    1165           0 :                     nLight++;
    1166             :                 }
    1167             :             }
    1168             : 
    1169           0 :             if(nLight <= 7)
    1170             :             {
    1171           0 :                 maLightControl.SelectLight(nLight);
    1172           0 :                 CheckSelection();
    1173             : 
    1174           0 :                 if(maUserSelectionChangeCallback.IsSet())
    1175             :                 {
    1176           0 :                     maUserSelectionChangeCallback.Call(this);
    1177             :                 }
    1178             :             }
    1179             : 
    1180           0 :             break;
    1181             :         }
    1182             :         default:
    1183             :         {
    1184           0 :             Control::KeyInput( rKEvt );
    1185           0 :             break;
    1186             :         }
    1187             :     }
    1188             : }
    1189             : 
    1190           0 : void SvxLightCtl3D::GetFocus()
    1191             : {
    1192           0 :     Control::GetFocus();
    1193             : 
    1194           0 :     if(HasFocus() && IsEnabled())
    1195             :     {
    1196           0 :         CheckSelection();
    1197             : 
    1198           0 :         Size aFocusSize = maLightControl.GetOutputSizePixel();
    1199             : 
    1200           0 :         aFocusSize.Width() -= 4;
    1201           0 :         aFocusSize.Height() -= 4;
    1202             : 
    1203           0 :         Rectangle aFocusRect( Point( 2, 2 ), aFocusSize );
    1204             : 
    1205           0 :         aFocusRect = maLightControl.PixelToLogic( aFocusRect );
    1206             : 
    1207           0 :         maLightControl.ShowFocus( aFocusRect );
    1208             :     }
    1209           0 : }
    1210             : 
    1211           0 : void SvxLightCtl3D::LoseFocus()
    1212             : {
    1213           0 :     Control::LoseFocus();
    1214             : 
    1215           0 :     maLightControl.HideFocus();
    1216           0 : }
    1217             : 
    1218           0 : IMPL_LINK_NOARG(SvxLightCtl3D, ScrollBarMove)
    1219             : {
    1220           0 :     const sal_Int32 nHor(maHorScroller.GetThumbPos());
    1221           0 :     const sal_Int32 nVer(maVerScroller.GetThumbPos());
    1222             : 
    1223             :     maLightControl.SetPosition(
    1224             :         ((double)nHor) / 100.0,
    1225           0 :         ((double)((18000 - nVer) - 9000)) / 100.0);
    1226             : 
    1227           0 :     if(maUserInteractiveChangeCallback.IsSet())
    1228             :     {
    1229           0 :         maUserInteractiveChangeCallback.Call(this);
    1230             :     }
    1231             : 
    1232           0 :     return 0;
    1233             : }
    1234             : 
    1235           0 : IMPL_LINK_NOARG(SvxLightCtl3D, ButtonPress)
    1236             : {
    1237           0 :     if(PREVIEW_OBJECTTYPE_SPHERE == GetSvx3DLightControl().GetObjectType())
    1238             :     {
    1239           0 :         GetSvx3DLightControl().SetObjectType(PREVIEW_OBJECTTYPE_CUBE);
    1240             :     }
    1241             :     else
    1242             :     {
    1243           0 :         GetSvx3DLightControl().SetObjectType(PREVIEW_OBJECTTYPE_SPHERE);
    1244             :     }
    1245             : 
    1246           0 :     return 0;
    1247             : }
    1248             : 
    1249           0 : IMPL_LINK_NOARG(SvxLightCtl3D, InternalInteractiveChange)
    1250             : {
    1251             :     double fHor, fVer;
    1252             : 
    1253           0 :     maLightControl.GetPosition(fHor, fVer);
    1254           0 :     maHorScroller.SetThumbPos( sal_Int32(fHor * 100.0) );
    1255           0 :     maVerScroller.SetThumbPos( 18000 - sal_Int32((fVer + 90.0) * 100.0) );
    1256             : 
    1257           0 :     if(maUserInteractiveChangeCallback.IsSet())
    1258             :     {
    1259           0 :         maUserInteractiveChangeCallback.Call(this);
    1260             :     }
    1261             : 
    1262           0 :     return 0;
    1263             : }
    1264             : 
    1265           0 : IMPL_LINK_NOARG(SvxLightCtl3D, InternalSelectionChange)
    1266             : {
    1267           0 :     CheckSelection();
    1268             : 
    1269           0 :     if(maUserSelectionChangeCallback.IsSet())
    1270             :     {
    1271           0 :         maUserSelectionChangeCallback.Call(this);
    1272             :     }
    1273             : 
    1274           0 :     return 0;
    1275         216 : }
    1276             : 
    1277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10