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