1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
30 
31 #include <com/sun/star/util/XURLTransformer.hpp>
32 #include <com/sun/star/awt/MenuItemStyle.hpp>
33 #include <com/sun/star/awt/XPopupMenuExtended.hpp>
34 #include <com/sun/star/graphic/XGraphic.hpp>
35 
36 #include <vos/mutex.hxx>
37 
38 #include <svtools/toolbarmenu.hxx>
39 #include <vcl/toolbox.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/objsh.hxx>
43 #include <svl/eitem.hxx>
44 #include <vcl/settings.hxx>
45 #include <svl/intitem.hxx>
46 #include <editeng/colritem.hxx>
47 #include <tools/urlobj.hxx>
48 
49 #include <svx/dialogs.hrc>
50 #include <svx/svdtrans.hxx>
51 #include <svx/sdasitm.hxx>
52 #include <svx/dialmgr.hxx>
53 #include "svx/extrusioncolorcontrol.hxx"
54 
55 //#include "chrtitem.hxx"
56 #include "helpid.hrc"
57 #include "extrusioncontrols.hxx"
58 #include "extrusioncontrols.hrc"
59 #include "colorwindow.hxx"
60 #include "extrusiondepthdialog.hxx"
61 
62 ////////////
63 
64 using ::rtl::OUString;
65 //using ::svtools::ToolbarMenu;
66 
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::util;
72 using namespace ::com::sun::star::graphic;
73 
74 namespace svx
75 {
76 
77 /*************************************************************************
78 |*
79 |* ExtrusionDirectionWindow
80 |*
81 \************************************************************************/
82 
83 static sal_Int32 gSkewList[] = { 135, 90, 45, 180, 0, -360, -135, -90, -45 };
84 
85 ExtrusionDirectionWindow::ExtrusionDirectionWindow( svt::ToolboxController& rController, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, Window* pParentWindow )
86 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_EXTRUSION_DIRECTION ))
87 , mrController( rController )
88 , maImgPerspective( SVX_RES( IMG_PERSPECTIVE ) )
89 , maImgPerspectiveH( SVX_RES( IMG_PERSPECTIVE_H ) )
90 , maImgParallel( SVX_RES( IMG_PARALLEL ) )
91 , maImgParallelH( SVX_RES( IMG_PARALLEL_H ) )
92 , msExtrusionDirection( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDirection" ) )
93 , msExtrusionProjection( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionProjection" ) )
94 {
95 	SetHelpId( HID_MENU_EXTRUSION_DIRECTION );
96 
97 	sal_uInt16 i;
98 	for( i = DIRECTION_NW; i <= DIRECTION_SE; i++ )
99 	{
100 		maImgDirection[i] = Image( SVX_RES( IMG_DIRECTION + i ) );
101 		maImgDirectionH[i] = Image( SVX_RES( IMG_DIRECTION_H + i ) );
102 	}
103 
104 	SetSelectHdl( LINK( this, ExtrusionDirectionWindow, SelectHdl ) );
105 	mpDirectionSet = createEmptyValueSetControl();
106 	mpDirectionSet->SetHelpId( HID_VALUESET_EXTRUSION_DIRECTION );
107 
108 	mpDirectionSet->SetSelectHdl( LINK( this, ExtrusionDirectionWindow, SelectHdl ) );
109 	mpDirectionSet->SetColCount( 3 );
110 	mpDirectionSet->EnableFullItemMode( sal_False );
111 
112 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
113 
114 	for( i = DIRECTION_NW; i <= DIRECTION_SE; i++ )
115 	{
116 		String aText( SVX_RES( STR_DIRECTION + i ) );
117 		mpDirectionSet->InsertItem( i+1, bHighContrast ? maImgDirectionH[ i ] : maImgDirection[ i ], aText );
118 	}
119 
120 	mpDirectionSet->SetOutputSizePixel( Size( 72, 72 ) );
121 
122 	appendEntry( 2, mpDirectionSet );
123 	appendSeparator();
124 	appendEntry( 0, String( SVX_RES( STR_PERSPECTIVE ) ), bHighContrast ? maImgPerspectiveH : maImgPerspective );
125 	appendEntry( 1, String( SVX_RES( STR_PARALLEL ) ), bHighContrast ? maImgParallelH : maImgParallel );
126 
127 	SetOutputSizePixel( getMenuSize() );
128 
129 	FreeResource();
130 
131     AddStatusListener( msExtrusionDirection );
132     AddStatusListener( msExtrusionProjection );
133 }
134 
135 void ExtrusionDirectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
136 {
137 	ToolbarMenu::DataChanged( rDCEvt );
138 
139 	if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
140 	{
141 		bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
142 
143 		for( sal_uInt16 i = DIRECTION_NW; i <= DIRECTION_SE; i++ )
144 		{
145 			mpDirectionSet->SetItemImage( i+1, bHighContrast ? maImgDirectionH[ i ] : maImgDirection[ i ] );
146 		}
147 
148 		setEntryImage( 0, bHighContrast ? maImgPerspectiveH : maImgPerspective );
149 		setEntryImage( 1, bHighContrast ? maImgParallelH : maImgParallel );
150 	}
151 }
152 
153 // -----------------------------------------------------------------------
154 
155 void ExtrusionDirectionWindow::implSetDirection( sal_Int32 nSkew, bool bEnabled )
156 {
157 	if( mpDirectionSet )
158 	{
159 		sal_uInt16 nItemId;
160 		for( nItemId = DIRECTION_NW; nItemId <= DIRECTION_SE; nItemId++ )
161 		{
162 			if( gSkewList[nItemId] == nSkew )
163 				break;
164 		}
165 
166 		if( nItemId <= DIRECTION_SE )
167 		{
168 			mpDirectionSet->SelectItem( nItemId+1 );
169 		}
170 		else
171 		{
172 			mpDirectionSet->SetNoSelection();
173 		}
174 	}
175 	enableEntry( 2, bEnabled );
176 }
177 
178 // -----------------------------------------------------------------------
179 
180 void ExtrusionDirectionWindow::implSetProjection( sal_Int32 nProjection, bool bEnabled )
181 {
182 	checkEntry( 0, (nProjection == 0) && bEnabled );
183 	checkEntry( 1, (nProjection == 1 ) && bEnabled );
184 	enableEntry( 0, bEnabled );
185 	enableEntry( 1, bEnabled );
186 }
187 
188 // -----------------------------------------------------------------------
189 
190 void SAL_CALL ExtrusionDirectionWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
191 {
192 	if( Event.FeatureURL.Main.equals( msExtrusionDirection ) )
193 	{
194 		if( !Event.IsEnabled )
195 		{
196 			implSetDirection( -1, false );
197 		}
198 		else
199 		{
200 			sal_Int32 nValue = 0;
201 			if( Event.State >>= nValue )
202 				implSetDirection( nValue, true );
203 		}
204 	}
205 	else if( Event.FeatureURL.Main.equals( msExtrusionProjection ) )
206 	{
207 		if( !Event.IsEnabled )
208 		{
209 			implSetProjection( -1, false );
210 		}
211 		else
212 		{
213 			sal_Int32 nValue = 0;
214 			if( Event.State >>= nValue )
215 				implSetProjection( nValue, true );
216 		}
217 	}
218 }
219 
220 // -----------------------------------------------------------------------
221 
222 IMPL_LINK( ExtrusionDirectionWindow, SelectHdl, void *, pControl )
223 {
224 	if ( IsInPopupMode() )
225 		EndPopupMode();
226 
227 	if( pControl == mpDirectionSet )
228 	{
229         Sequence< PropertyValue > aArgs( 1 );
230         aArgs[0].Name = msExtrusionDirection.copy(5);
231         aArgs[0].Value <<= (sal_Int32)gSkewList[mpDirectionSet->GetSelectItemId()-1];
232 
233 		mrController.dispatchCommand( msExtrusionDirection, aArgs );
234 	}
235 	else
236 	{
237 		int nProjection = getSelectedEntryId();
238 		if( (nProjection >= 0) && (nProjection < 2 ) )
239 		{
240             Sequence< PropertyValue > aArgs( 1 );
241             aArgs[0].Name = msExtrusionProjection.copy(5);
242             aArgs[0].Value <<= (sal_Int32)nProjection;
243 
244 			mrController.dispatchCommand( msExtrusionProjection, aArgs );
245             implSetProjection( nProjection, true );
246 		}
247 	}
248 
249 	return 0;
250 }
251 
252 // =======================================================================
253 // ExtrusionDirectionControl
254 // =======================================================================
255 
256 ExtrusionDirectionControl::ExtrusionDirectionControl( const Reference< lang::XMultiServiceFactory >& rServiceManager )
257 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDirectionFloater" ) ) )
258 {
259 }
260 
261 // -----------------------------------------------------------------------
262 
263 ::Window* ExtrusionDirectionControl::createPopupWindow( ::Window* pParent )
264 {
265     return new ExtrusionDirectionWindow( *this, m_xFrame, pParent );
266 }
267 
268 // -----------------------------------------------------------------------
269 // XServiceInfo
270 // -----------------------------------------------------------------------
271 
272 OUString SAL_CALL ExtrusionDirectionControl_getImplementationName()
273 {
274 	return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.ExtrusionDirectionController" ));
275 }
276 
277 // --------------------------------------------------------------------
278 
279 Sequence< OUString > SAL_CALL ExtrusionDirectionControl_getSupportedServiceNames() throw( RuntimeException )
280 {
281     Sequence< OUString > aSNS( 1 );
282     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
283     return aSNS;
284 }
285 
286 // --------------------------------------------------------------------
287 
288 Reference< XInterface > SAL_CALL SAL_CALL ExtrusionDirectionControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
289 {
290 	return *new ExtrusionDirectionControl( rSMgr );
291 }
292 
293 // --------------------------------------------------------------------
294 
295 OUString SAL_CALL ExtrusionDirectionControl::getImplementationName(  ) throw (RuntimeException)
296 {
297 	return ExtrusionDirectionControl_getImplementationName();
298 }
299 
300 // --------------------------------------------------------------------
301 
302 Sequence< OUString > SAL_CALL ExtrusionDirectionControl::getSupportedServiceNames(  ) throw (RuntimeException)
303 {
304 	return ExtrusionDirectionControl_getSupportedServiceNames();
305 }
306 
307 // ####################################################################
308 
309 ExtrusionDepthDialog::ExtrusionDepthDialog( Window* pParent, double fDepth, FieldUnit eDefaultUnit )
310 :	ModalDialog( pParent, SVX_RES( RID_SVX_MDLG_EXTRUSION_DEPTH ) ),
311 	maFLDepth( this, SVX_RES( FL_DEPTH ) ),
312 	maMtrDepth( this, SVX_RES( MTR_DEPTH ) ),
313 	maOKButton( this, SVX_RES( BTN_OK ) ),
314 	maCancelButton( this, SVX_RES( BTN_CANCEL ) ),
315 	maHelpButton( this, SVX_RES( BTN_HELP ) )
316 {
317 	bool bMetric = IsMetric( eDefaultUnit );
318 	maMtrDepth.SetUnit( bMetric ? FUNIT_CM : FUNIT_INCH );
319 	maMtrDepth.SetValue( (int) fDepth * 100, FUNIT_100TH_MM );
320 
321 	FreeResource();
322 }
323 
324 ExtrusionDepthDialog::~ExtrusionDepthDialog()
325 {
326 }
327 
328 double ExtrusionDepthDialog::getDepth() const
329 {
330 //	bool bMetric = IsMetric( meDefaultUnit );
331 	return (double)( maMtrDepth.GetValue( FUNIT_100TH_MM ) ) / 100.0;
332 }
333 
334 // ####################################################################
335 
336 double aDepthListInch[] = { 0, 1270,2540,5080,10160 };
337 double aDepthListMM[] = { 0, 1000, 2500, 5000, 10000 };
338 
339 ExtrusionDepthWindow::ExtrusionDepthWindow( svt::ToolboxController& rController, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, Window* pParentWindow )
340 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_EXTRUSION_DEPTH ))
341 , mrController( rController )
342 , maImgDepth0( SVX_RES( IMG_DEPTH_0 ) )
343 , maImgDepth1( SVX_RES( IMG_DEPTH_1 ) )
344 , maImgDepth2( SVX_RES( IMG_DEPTH_2 ) )
345 , maImgDepth3( SVX_RES( IMG_DEPTH_3 ) )
346 , maImgDepth4( SVX_RES( IMG_DEPTH_4 ) )
347 , maImgDepthInfinity( SVX_RES( IMG_DEPTH_INFINITY ) )
348 , maImgDepth0h( SVX_RES( IMG_DEPTH_0_H ) )
349 , maImgDepth1h( SVX_RES( IMG_DEPTH_1_H ) )
350 , maImgDepth2h( SVX_RES( IMG_DEPTH_2_H ) )
351 , maImgDepth3h( SVX_RES( IMG_DEPTH_3_H ) )
352 , maImgDepth4h( SVX_RES( IMG_DEPTH_4_H ) )
353 , maImgDepthInfinityh( SVX_RES( IMG_DEPTH_INFINITY_H ) )
354 , mfDepth( -1.0 )
355 , msExtrusionDepth( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDepth" ) )
356 , msMetricUnit( RTL_CONSTASCII_USTRINGPARAM( ".uno:MetricUnit" ) )
357 {
358 	SetHelpId( HID_MENU_EXTRUSION_DEPTH );
359 
360 	SetSelectHdl( LINK( this, ExtrusionDepthWindow, SelectHdl ) );
361 
362 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
363 
364 	String aEmpty;
365 	appendEntry( 0, aEmpty, bHighContrast ? maImgDepth0h : maImgDepth0 );
366 	appendEntry( 1, aEmpty, bHighContrast ? maImgDepth1h : maImgDepth1 );
367 	appendEntry( 2, aEmpty, bHighContrast ? maImgDepth2h : maImgDepth2 );
368 	appendEntry( 3, aEmpty, bHighContrast ? maImgDepth3h : maImgDepth3 );
369 	appendEntry( 4, aEmpty, bHighContrast ? maImgDepth4h : maImgDepth4 );
370 	appendEntry( 5, String( SVX_RES( STR_INFINITY ) ), bHighContrast ? maImgDepthInfinityh : maImgDepthInfinity );
371 	appendEntry( 6, String( SVX_RES( STR_CUSTOM ) ) );
372 
373 	SetOutputSizePixel( getMenuSize() );
374 
375 	FreeResource();
376 
377     AddStatusListener( msExtrusionDepth );
378     AddStatusListener( msMetricUnit );
379 }
380 
381 // -----------------------------------------------------------------------
382 
383 void ExtrusionDepthWindow::implSetDepth( double fDepth )
384 {
385 	mfDepth = fDepth;
386 	int i;
387 	for( i = 0; i < 7; i++ )
388 	{
389 		if( i == 5 )
390 		{
391 			checkEntry( i, fDepth >= 338666 );
392 		}
393 		else if( i != 6 )
394 		{
395 			checkEntry( i, (fDepth == (IsMetric( meUnit ) ? aDepthListMM[i] : aDepthListInch[i]) ) );
396 		}
397 	}
398 }
399 
400 // -----------------------------------------------------------------------
401 
402 void ExtrusionDepthWindow::implFillStrings( FieldUnit eUnit )
403 {
404 	meUnit = eUnit;
405 	sal_uInt16 nResource = IsMetric( eUnit ) ? RID_SVXSTR_DEPTH_0 : RID_SVXSTR_DEPTH_0_INCH;
406 
407 	for( int i = 0; i < 5; i++ )
408 	{
409 		String aStr( SVX_RES( nResource + i ) );
410 		setEntryText( i, aStr );
411 	};
412 }
413 
414 // -----------------------------------------------------------------------
415 
416 void SAL_CALL ExtrusionDepthWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
417 {
418 	if( Event.FeatureURL.Main.equals( msExtrusionDepth ) )
419 	{
420 		if( !Event.IsEnabled )
421 		{
422 			implSetDepth( 0 );
423 		}
424 		else
425 		{
426 			double fValue = 0.0;
427 			if( Event.State >>= fValue )
428 				implSetDepth( fValue );
429 		}
430 	}
431 	else if( Event.FeatureURL.Main.equals( msMetricUnit ) )
432 	{
433 		if( Event.IsEnabled )
434 		{
435 			sal_Int32 nValue = 0;
436 			if( Event.State >>= nValue )
437 			{
438 				implFillStrings( static_cast<FieldUnit>(nValue) );
439 				if( mfDepth >= 0.0 )
440 					implSetDepth( mfDepth );
441 			}
442 		}
443 	}
444 }
445 
446 // -----------------------------------------------------------------------
447 
448 void ExtrusionDepthWindow::DataChanged( const DataChangedEvent& rDCEvt )
449 {
450 	ToolbarMenu::DataChanged( rDCEvt );
451 
452 	if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
453 	{
454 		bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
455 
456 		setEntryImage( 0, bHighContrast ? maImgDepth0h : maImgDepth0 );
457 		setEntryImage( 1, bHighContrast ? maImgDepth1h : maImgDepth1 );
458 		setEntryImage( 2, bHighContrast ? maImgDepth2h : maImgDepth2 );
459 		setEntryImage( 3, bHighContrast ? maImgDepth3h : maImgDepth3 );
460 		setEntryImage( 4, bHighContrast ? maImgDepth4h : maImgDepth4 );
461 		setEntryImage( 5, bHighContrast ? maImgDepthInfinityh : maImgDepthInfinity );
462 	}
463 }
464 
465 
466 // -----------------------------------------------------------------------
467 
468 IMPL_LINK( ExtrusionDepthWindow, SelectHdl, void *, EMPTYARG )
469 {
470 	int nSelected = getSelectedEntryId();
471 	if( nSelected != -1 )
472 	{
473 		if( nSelected == 6 )
474 		{
475 			if ( IsInPopupMode() )
476 				EndPopupMode();
477 
478             const rtl::OUString aCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDepthDialog" ));
479 
480             Any a;
481             Sequence< PropertyValue > aArgs( 2 );
482             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Depth" ));
483             aArgs[0].Value <<= mfDepth;
484             aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Metric" ));
485             aArgs[1].Value <<= static_cast<sal_Int32>( meUnit );
486 
487             mrController.dispatchCommand( aCommand, aArgs );
488 		}
489 		else
490 		{
491 			double fDepth;
492 
493 			if( nSelected == 5 )
494 			{
495 				fDepth = 338666.6;
496 			}
497 			else
498 			{
499 				fDepth = IsMetric( meUnit ) ? aDepthListMM[nSelected] : aDepthListInch[nSelected];
500 			}
501 
502             Sequence< PropertyValue > aArgs( 1 );
503             aArgs[0].Name = msExtrusionDepth.copy(5);
504             aArgs[0].Value <<= fDepth;
505 
506             mrController.dispatchCommand( msExtrusionDepth,  aArgs );
507 			implSetDepth( fDepth );
508 
509 			if ( IsInPopupMode() )
510 				EndPopupMode();
511 		}
512 	}
513 	return 0;
514 }
515 
516 // =======================================================================
517 // ExtrusionDirectionControl
518 // =======================================================================
519 
520 ExtrusionDepthController::ExtrusionDepthController( const Reference< lang::XMultiServiceFactory >& rServiceManager )
521 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDepthFloater" ) ) )
522 {
523 }
524 
525 // -----------------------------------------------------------------------
526 
527 ::Window* ExtrusionDepthController::createPopupWindow( ::Window* pParent )
528 {
529     return new ExtrusionDepthWindow( *this, m_xFrame, pParent );
530 }
531 
532 
533 // -----------------------------------------------------------------------
534 // XServiceInfo
535 // -----------------------------------------------------------------------
536 
537 OUString SAL_CALL ExtrusionDepthController_getImplementationName()
538 {
539 	return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.ExtrusionDepthController" ));
540 }
541 
542 // --------------------------------------------------------------------
543 
544 Sequence< OUString > SAL_CALL ExtrusionDepthController_getSupportedServiceNames() throw( RuntimeException )
545 {
546     Sequence< OUString > aSNS( 1 );
547     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.PopupMenuController" ));
548     return aSNS;
549 }
550 
551 // --------------------------------------------------------------------
552 
553 Reference< XInterface > SAL_CALL SAL_CALL ExtrusionDepthController_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
554 {
555 	return *new ExtrusionDepthController( rSMgr );
556 }
557 
558 // --------------------------------------------------------------------
559 
560 OUString SAL_CALL ExtrusionDepthController::getImplementationName(  ) throw (RuntimeException)
561 {
562 	return ExtrusionDepthController_getImplementationName();
563 }
564 
565 // --------------------------------------------------------------------
566 
567 Sequence< OUString > SAL_CALL ExtrusionDepthController::getSupportedServiceNames(  ) throw (RuntimeException)
568 {
569 	return ExtrusionDepthController_getSupportedServiceNames();
570 }
571 
572 
573 // ####################################################################
574 
575 // -------------------------------------------------------------------------
576 
577 ExtrusionLightingWindow::ExtrusionLightingWindow( svt::ToolboxController& rController, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, Window* pParentWindow )
578 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_EXTRUSION_LIGHTING ))
579 , mrController( rController )
580 , maImgBright( SVX_RES( IMG_LIGHTING_BRIGHT ) )
581 , maImgNormal( SVX_RES( IMG_LIGHTING_NORMAL ) )
582 , maImgDim( SVX_RES( IMG_LIGHTING_DIM ) )
583 , maImgBrighth( SVX_RES( IMG_LIGHTING_BRIGHT_H ) )
584 , maImgNormalh( SVX_RES( IMG_LIGHTING_NORMAL_H ) )
585 , maImgDimh( SVX_RES( IMG_LIGHTING_DIM_H ) )
586 , mnLevel( 0 )
587 , mbLevelEnabled( false )
588 , mnDirection( FROM_FRONT )
589 , mbDirectionEnabled( false )
590 , msExtrusionLightingDirection( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionLightingDirection" ))
591 , msExtrusionLightingIntensity( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionLightingIntensity" ))
592 {
593 	sal_uInt16 i;
594 	for( i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; i++ )
595 	{
596 		if( i != FROM_FRONT )
597 		{
598 			maImgLightingOff[i] = Image( SVX_RES( IMG_LIGHT_OFF + i ) );
599 			maImgLightingOn[i] = Image( SVX_RES( IMG_LIGHT_ON + i ) );
600 			maImgLightingOffh[i] = Image( SVX_RES( IMG_LIGHT_OFF_H + i ) );
601 			maImgLightingOnh[i] = Image( SVX_RES( IMG_LIGHT_ON_H + i ) );
602 		}
603 		maImgLightingPreview[i] = Image( SVX_RES( IMG_LIGHT_PREVIEW + i ) );
604 		maImgLightingPreviewh[i] = Image( SVX_RES( IMG_LIGHT_PREVIEW_H + i ) );
605 	}
606 
607 	SetHelpId( HID_MENU_EXTRUSION_LIGHTING );
608 	SetSelectHdl( LINK( this, ExtrusionLightingWindow, SelectHdl ) );
609 
610 	mpLightingSet = createEmptyValueSetControl();
611 	mpLightingSet->SetHelpId( HID_VALUESET_EXTRUSION_LIGHTING );
612 
613 	mpLightingSet->SetSelectHdl( LINK( this, ExtrusionLightingWindow, SelectHdl ) );
614 	mpLightingSet->SetColCount( 3 );
615 	mpLightingSet->EnableFullItemMode( sal_False );
616 
617 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
618 
619 	for( i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; i++ )
620 	{
621 		if( i != FROM_FRONT )
622 		{
623 			mpLightingSet->InsertItem( i+1, bHighContrast ? maImgLightingOffh[i] : maImgLightingOff[i] );
624 		}
625 		else
626 		{
627 			mpLightingSet->InsertItem( 5, bHighContrast ? maImgLightingPreviewh[FROM_FRONT] : maImgLightingPreview[FROM_FRONT] );
628 		}
629 	}
630 	mpLightingSet->SetOutputSizePixel( Size( 72, 72 ) );
631 
632 	appendEntry( 3, mpLightingSet );
633 	appendSeparator();
634 	appendEntry( 0, String( SVX_RES( STR_BRIGHT ) ), bHighContrast ? maImgBrighth : maImgBright );
635 	appendEntry( 1, String( SVX_RES( STR_NORMAL ) ), bHighContrast ? maImgNormalh : maImgNormal );
636 	appendEntry( 2, String( SVX_RES( STR_DIM ) ), bHighContrast ? maImgDimh : maImgDim );
637 
638 	SetOutputSizePixel( getMenuSize() );
639 
640 	FreeResource();
641 
642     AddStatusListener( msExtrusionLightingDirection );
643     AddStatusListener( msExtrusionLightingIntensity );
644 }
645 
646 // -----------------------------------------------------------------------
647 
648 void ExtrusionLightingWindow::implSetIntensity( int nLevel, bool bEnabled )
649 {
650 	mnLevel = nLevel;
651 	mbLevelEnabled = bEnabled;
652 	int i = 0;
653 	for( i = 0; i < 3; i++ )
654 	{
655 		checkEntry( i, (i == nLevel) && bEnabled );
656 		enableEntry( i, bEnabled );
657 	}
658 }
659 
660 // -----------------------------------------------------------------------
661 
662 void ExtrusionLightingWindow::implSetDirection( int nDirection, bool bEnabled )
663 {
664 	mnDirection = nDirection;
665 	mbDirectionEnabled = bEnabled;
666 
667 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
668 
669 	if( !bEnabled )
670 		nDirection = FROM_FRONT;
671 
672 	sal_uInt16 nItemId;
673 	for( nItemId = FROM_TOP_LEFT; nItemId <= FROM_BOTTOM_RIGHT; nItemId++ )
674 	{
675 		if( nItemId == FROM_FRONT )
676 		{
677 			mpLightingSet->SetItemImage( nItemId + 1, bHighContrast ? maImgLightingPreviewh[ nDirection ] : maImgLightingPreview[ nDirection ] );
678 		}
679 		else
680 		{
681 			if( bHighContrast )
682 			{
683 				mpLightingSet->SetItemImage( nItemId + 1, (sal_uInt16)nDirection == nItemId ? maImgLightingOnh[nItemId] : maImgLightingOffh[nItemId] );
684 			}
685 			else
686 			{
687 				mpLightingSet->SetItemImage( nItemId + 1, (sal_uInt16)nDirection == nItemId ? maImgLightingOn[nItemId] : maImgLightingOff[nItemId] );
688 			}
689 		}
690 	}
691 
692 	enableEntry( 3, bEnabled );
693 }
694 
695 // -----------------------------------------------------------------------
696 
697 void SAL_CALL ExtrusionLightingWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
698 {
699 	if( Event.FeatureURL.Main.equals( msExtrusionLightingIntensity ) )
700 	{
701 		if( !Event.IsEnabled )
702 		{
703 			implSetIntensity( 0, false );
704 		}
705 		else
706 		{
707 			sal_Int32 nValue = 0;
708 			if( Event.State >>= nValue )
709 				implSetIntensity( nValue, true );
710 		}
711 	}
712 	else if( Event.FeatureURL.Main.equals( msExtrusionLightingDirection ) )
713 	{
714 		if( !Event.IsEnabled )
715 		{
716 			implSetDirection( 0, false );
717 		}
718 		else
719 		{
720 			sal_Int32 nValue = 0;
721 			if( Event.State >>= nValue )
722 				implSetDirection( nValue, true );
723 		}
724 	}
725 }
726 
727 // -----------------------------------------------------------------------
728 
729 void ExtrusionLightingWindow::DataChanged( const DataChangedEvent& rDCEvt )
730 {
731 	ToolbarMenu::DataChanged( rDCEvt );
732 
733 	if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
734 	{
735 		bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
736 
737 		implSetDirection( mnDirection, mbDirectionEnabled );
738 		setEntryImage( 0, bHighContrast ? maImgBrighth : maImgBright );
739 		setEntryImage( 1, bHighContrast ? maImgNormalh : maImgNormal );
740 		setEntryImage( 2, bHighContrast ? maImgDimh : maImgDim );
741 	}
742 }
743 
744 // -----------------------------------------------------------------------
745 
746 IMPL_LINK( ExtrusionLightingWindow, SelectHdl, void *, pControl )
747 {
748 	if ( IsInPopupMode() )
749 		EndPopupMode();
750 
751 	if( pControl == this )
752 	{
753 		int nLevel = getSelectedEntryId();
754 		if( nLevel >= 0 )
755 		{
756 			if( nLevel != 3 )
757 			{
758                 Sequence< PropertyValue > aArgs( 1 );
759                 aArgs[0].Name = msExtrusionLightingIntensity.copy(5);
760                 aArgs[0].Value <<= (sal_Int32)nLevel;
761 
762 				mrController.dispatchCommand( msExtrusionLightingIntensity, aArgs );
763 
764 				implSetIntensity( nLevel, true );
765 			}
766 		}
767 	}
768 	else
769 	{
770 		sal_Int32 nDirection = mpLightingSet->GetSelectItemId();
771 
772 		if( (nDirection > 0) && (nDirection < 10) )
773 		{
774 			nDirection--;
775 
776             Sequence< PropertyValue > aArgs( 1 );
777             aArgs[0].Name = msExtrusionLightingDirection.copy(5);
778             aArgs[0].Value <<= (sal_Int32)nDirection;
779 
780 			mrController.dispatchCommand( msExtrusionLightingDirection, aArgs );
781 
782 			implSetDirection( nDirection, true );
783 		}
784 
785 	}
786 
787 	return 0;
788 }
789 
790 // ========================================================================
791 
792 ExtrusionLightingControl::ExtrusionLightingControl( const Reference< lang::XMultiServiceFactory >& rServiceManager )
793 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionDirectionFloater" ) ) )
794 {
795 }
796 
797 // -----------------------------------------------------------------------
798 
799 ::Window* ExtrusionLightingControl::createPopupWindow( ::Window* pParent )
800 {
801     return new ExtrusionLightingWindow( *this, m_xFrame, pParent );
802 }
803 
804 // -----------------------------------------------------------------------
805 // XServiceInfo
806 // -----------------------------------------------------------------------
807 
808 OUString SAL_CALL ExtrusionLightingControl_getImplementationName()
809 {
810 	return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.ExtrusionLightingController" ));
811 }
812 
813 // --------------------------------------------------------------------
814 
815 Sequence< OUString > SAL_CALL ExtrusionLightingControl_getSupportedServiceNames() throw( RuntimeException )
816 {
817     Sequence< OUString > aSNS( 1 );
818     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
819     return aSNS;
820 }
821 
822 // --------------------------------------------------------------------
823 
824 Reference< XInterface > SAL_CALL SAL_CALL ExtrusionLightingControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
825 {
826 	return *new ExtrusionLightingControl( rSMgr );
827 }
828 
829 // --------------------------------------------------------------------
830 
831 OUString SAL_CALL ExtrusionLightingControl::getImplementationName(  ) throw (RuntimeException)
832 {
833 	return ExtrusionLightingControl_getImplementationName();
834 }
835 
836 // --------------------------------------------------------------------
837 
838 Sequence< OUString > SAL_CALL ExtrusionLightingControl::getSupportedServiceNames(  ) throw (RuntimeException)
839 {
840 	return ExtrusionLightingControl_getSupportedServiceNames();
841 }
842 
843 // ####################################################################
844 
845 ExtrusionSurfaceWindow::ExtrusionSurfaceWindow( svt::ToolboxController& rController, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, Window* pParentWindow )
846 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_EXTRUSION_SURFACE ))
847 , mrController( rController )
848 , maImgSurface1( SVX_RES( IMG_WIRE_FRAME ) )
849 , maImgSurface2( SVX_RES( IMG_MATTE ) )
850 , maImgSurface3( SVX_RES( IMG_PLASTIC ) )
851 , maImgSurface4( SVX_RES( IMG_METAL ) )
852 , maImgSurface1h( SVX_RES( IMG_WIRE_FRAME_H ) )
853 , maImgSurface2h( SVX_RES( IMG_MATTE_H ) )
854 , maImgSurface3h( SVX_RES( IMG_PLASTIC_H ) )
855 , maImgSurface4h( SVX_RES( IMG_METAL_H ) )
856 , msExtrusionSurface( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionSurface" ))
857 {
858 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
859 
860 	SetHelpId( HID_MENU_EXTRUSION_SURFACE );
861 	SetSelectHdl( LINK( this, ExtrusionSurfaceWindow, SelectHdl ) );
862 
863 	appendEntry( 0, String( SVX_RES( STR_WIREFRAME ) ), bHighContrast ? maImgSurface1h : maImgSurface1 );
864 	appendEntry( 1, String( SVX_RES( STR_MATTE ) ), bHighContrast ? maImgSurface2h : maImgSurface2 );
865 	appendEntry( 2, String( SVX_RES( STR_PLASTIC ) ), bHighContrast ? maImgSurface3h : maImgSurface3 );
866 	appendEntry( 3, String( SVX_RES( STR_METAL ) ), bHighContrast ? maImgSurface4h : maImgSurface4 );
867 
868 	SetOutputSizePixel( getMenuSize() );
869 
870 	FreeResource();
871 
872     AddStatusListener( msExtrusionSurface );
873 }
874 
875 // -----------------------------------------------------------------------
876 
877 void ExtrusionSurfaceWindow::implSetSurface( int nSurface, bool bEnabled )
878 {
879 //	if( mpMenu )
880 	{
881 		int i;
882 		for( i = 0; i < 4; i++ )
883 		{
884 			checkEntry( i, (i == nSurface) && bEnabled );
885 			enableEntry( i, bEnabled );
886 		}
887 	}
888 }
889 
890 // -----------------------------------------------------------------------
891 
892 void SAL_CALL ExtrusionSurfaceWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
893 {
894 	if( Event.FeatureURL.Main.equals( msExtrusionSurface ) )
895 	{
896 		if( !Event.IsEnabled )
897 		{
898 			implSetSurface( 0, false );
899 		}
900 		else
901 		{
902 			sal_Int32 nValue = 0;
903 			if( Event.State >>= nValue )
904 				implSetSurface( nValue, true );
905 		}
906 	}
907 }
908 
909 // -----------------------------------------------------------------------
910 
911 IMPL_LINK( ExtrusionSurfaceWindow, SelectHdl, void *, EMPTYARG )
912 {
913 	if ( IsInPopupMode() )
914 		EndPopupMode();
915 
916 	sal_Int32 nSurface = getSelectedEntryId();
917 	if( nSurface >= 0 )
918 	{
919         Sequence< PropertyValue > aArgs( 1 );
920         aArgs[0].Name = msExtrusionSurface.copy(5);
921         aArgs[0].Value <<= (sal_Int32)nSurface;
922 
923 		mrController.dispatchCommand( msExtrusionSurface, aArgs );
924 
925 		implSetSurface( nSurface, true );
926 	}
927 
928 	return 0;
929 }
930 
931 // ========================================================================
932 
933 ExtrusionSurfaceControl::ExtrusionSurfaceControl( const Reference< lang::XMultiServiceFactory >& rServiceManager )
934 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ExtrusionSurfaceFloater" ) ) )
935 {
936 }
937 
938 // -----------------------------------------------------------------------
939 
940 ::Window* ExtrusionSurfaceControl::createPopupWindow( ::Window* pParent )
941 {
942     return new ExtrusionSurfaceWindow( *this, m_xFrame, pParent );
943 }
944 
945 // -----------------------------------------------------------------------
946 // XServiceInfo
947 // -----------------------------------------------------------------------
948 
949 OUString SAL_CALL ExtrusionSurfaceControl_getImplementationName()
950 {
951 	return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.ExtrusionSurfaceController" ));
952 }
953 
954 // --------------------------------------------------------------------
955 
956 Sequence< OUString > SAL_CALL ExtrusionSurfaceControl_getSupportedServiceNames() throw( RuntimeException )
957 {
958     Sequence< OUString > aSNS( 1 );
959     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
960     return aSNS;
961 }
962 
963 // --------------------------------------------------------------------
964 
965 Reference< XInterface > SAL_CALL SAL_CALL ExtrusionSurfaceControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
966 {
967 	return *new ExtrusionSurfaceControl( rSMgr );
968 }
969 
970 // --------------------------------------------------------------------
971 
972 OUString SAL_CALL ExtrusionSurfaceControl::getImplementationName(  ) throw (RuntimeException)
973 {
974 	return ExtrusionSurfaceControl_getImplementationName();
975 }
976 
977 // --------------------------------------------------------------------
978 
979 Sequence< OUString > SAL_CALL ExtrusionSurfaceControl::getSupportedServiceNames(  ) throw (RuntimeException)
980 {
981 	return ExtrusionSurfaceControl_getSupportedServiceNames();
982 }
983 
984 //========================================================================
985 
986 SFX_IMPL_TOOLBOX_CONTROL( ExtrusionColorControl, SvxColorItem );
987 
988 ExtrusionColorControl::ExtrusionColorControl(
989 	sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
990 : SfxToolBoxControl	( nSlotId, nId, rTbx )
991 {
992 	rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
993     mpBtnUpdater = new ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox(), TBX_UPDATER_MODE_CHAR_COLOR_NEW );
994 }
995 
996 // -----------------------------------------------------------------------
997 
998 ExtrusionColorControl::~ExtrusionColorControl()
999 {
1000 	delete mpBtnUpdater;
1001 }
1002 
1003 // -----------------------------------------------------------------------
1004 
1005 SfxPopupWindowType ExtrusionColorControl::GetPopupWindowType() const
1006 {
1007 	return SFX_POPUPWINDOW_ONCLICK;
1008 }
1009 
1010 // -----------------------------------------------------------------------
1011 
1012 SfxPopupWindow*	ExtrusionColorControl::CreatePopupWindow()
1013 {
1014     SvxColorWindow_Impl* pColorWin = new SvxColorWindow_Impl(
1015 		rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Extrusion3DColor" )),
1016 		SID_EXTRUSION_3D_COLOR,
1017 		m_xFrame,
1018 		SVX_RESSTR( RID_SVXSTR_EXTRUSION_COLOR ),
1019         &GetToolBox() );
1020     pColorWin->StartPopupMode( &GetToolBox(), FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF );
1021 	pColorWin->StartSelection();
1022     SetPopupWindow( pColorWin );
1023 	return pColorWin;
1024 }
1025 
1026 // -----------------------------------------------------------------------
1027 
1028 void ExtrusionColorControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1029 {
1030 	sal_uInt16 nId = GetId();
1031 	ToolBox& rTbx = GetToolBox();
1032 
1033 	if( nSID == SID_EXTRUSION_3D_COLOR )
1034 	{
1035 		const SvxColorItem*	pItem = 0;
1036 
1037 		if( SFX_ITEM_DONTCARE != eState )
1038 			pItem = PTR_CAST( SvxColorItem, pState );
1039 
1040 		if ( pItem )
1041 			mpBtnUpdater->Update( pItem->GetValue());
1042 	}
1043 
1044 	rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
1045 	rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
1046 }
1047 
1048 }
1049