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