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