update dev300-m58
[ooovba.git] / svx / source / tbxctrls / tbunocontroller.cxx
blobd00ea447382c862b5af7713df591ec1f6bc0184e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbunocontroller.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "tbunocontroller.hxx"
36 #include <com/sun/star/frame/status/FontHeight.hpp>
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <vcl/svapp.hxx>
41 #include <vcl/window.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <svtools/ctrltool.hxx>
44 #include <svtools/ctrlbox.hxx>
45 #include <vos/mutex.hxx>
47 #include <memory>
49 #define LOGICAL_EDIT_HEIGHT 12
51 using namespace ::com::sun::star;
53 namespace svx
56 class FontHeightToolBoxControl;
57 class SvxFontSizeBox_Impl : public FontSizeBox
59 public:
60 SvxFontSizeBox_Impl( Window* pParent,
61 const uno::Reference< frame::XDispatchProvider >& rDispatchProvider,
62 const uno::Reference< frame::XFrame >& _xFrame,
63 FontHeightToolBoxControl& rCtrl );
65 void statusChanged_Impl( long nHeight, bool bErase = false );
66 void UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont );
68 virtual long Notify( NotifyEvent& rNEvt );
70 protected:
71 virtual void Select();
72 virtual void DataChanged( const DataChangedEvent& rDCEvt );
74 private:
75 FontHeightToolBoxControl* m_pCtrl;
76 String m_aCurText;
77 Size m_aLogicalSize;
78 BOOL m_bRelease;
79 uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
80 uno::Reference< frame::XFrame > m_xFrame;
81 uno::Reference< awt::XWindow > m_xOldFocusWindow;
83 void ReleaseFocus_Impl();
86 //========================================================================
87 // class SvxFontSizeBox_Impl --------------------------------------------------
88 //========================================================================
90 SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
91 Window* _pParent,
92 const uno::Reference< frame::XDispatchProvider >& _rDispatchProvider,
93 const uno::Reference< frame::XFrame >& _xFrame,
94 FontHeightToolBoxControl& _rCtrl ) :
96 FontSizeBox( _pParent, WinBits( WB_DROPDOWN ) ),
98 m_pCtrl ( &_rCtrl ),
99 m_aLogicalSize ( 30,100 ),
100 m_bRelease ( TRUE ),
101 m_xDispatchProvider ( _rDispatchProvider ),
102 m_xFrame ( _xFrame )
104 SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
105 SetValue( 0 );
106 SetText( String() );
109 // -----------------------------------------------------------------------
111 void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
113 if ( !m_bRelease )
115 m_bRelease = TRUE;
116 return;
119 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
120 m_xFrame->getContainerWindow()->setFocus();
123 // -----------------------------------------------------------------------
125 void SvxFontSizeBox_Impl::Select()
127 FontSizeBox::Select();
129 if ( !IsTravelSelect() )
131 sal_Int64 nSelVal = GetValue();
132 float fSelVal = float( nSelVal ) / 10;
134 uno::Sequence< beans::PropertyValue > aArgs( 1 );
135 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight.Height" ));
136 aArgs[0].Value = uno::makeAny( fSelVal );
138 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
139 This instance may be deleted in the meantime (i.e. when a dialog is opened
140 while in Dispatch()), accessing members will crash in this case. */
141 ReleaseFocus_Impl();
143 m_pCtrl->dispatchCommand( aArgs );
147 // -----------------------------------------------------------------------
149 void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase )
151 if ( !bErase )
153 // Metric Umrechnen
154 long nVal = nPoint;
156 // ge"andert => neuen Wert setzen
157 if ( GetValue() != nVal )
158 SetValue( nVal );
160 else
162 // Wert in der Anzeige l"oschen
163 SetValue( -1L );
164 SetText( String() );
166 SaveValue();
169 // -----------------------------------------------------------------------
171 void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont )
173 // Sizes-Liste auff"ullen
174 sal_Int64 nOldVal = GetValue(); // alten Wert merken
175 const FontList* _pFontList = NULL;
176 ::std::auto_ptr<FontList> aHold( new FontList( this ));
177 _pFontList = aHold.get();
179 if ( rCurrentFont.Name.getLength() > 0 )
181 FontInfo _aFontInfo;
182 _aFontInfo.SetName( rCurrentFont.Name );
183 _aFontInfo.SetStyleName( rCurrentFont.StyleName );
184 _aFontInfo.SetHeight( rCurrentFont.Height );
185 Fill( &_aFontInfo, _pFontList );
187 else
189 Fill( NULL, _pFontList );
191 SetValue( nOldVal ); // alten Wert wiederherstellen
192 m_aCurText = GetText(); // zum R"ucksetzen bei ESC merken
195 // -----------------------------------------------------------------------
197 long SvxFontSizeBox_Impl::Notify( NotifyEvent& rNEvt )
199 long nHandled = 0;
201 if ( rNEvt.GetType() == EVENT_KEYINPUT )
203 USHORT nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
205 switch ( nCode )
207 case KEY_RETURN:
208 case KEY_TAB:
210 if ( KEY_TAB == nCode )
211 m_bRelease = FALSE;
212 else
213 nHandled = 1;
214 Select();
215 break;
218 case KEY_ESCAPE:
219 SetText( m_aCurText );
220 ReleaseFocus_Impl();
221 nHandled = 1;
222 break;
225 else if( EVENT_LOSEFOCUS == rNEvt.GetType() )
227 Window* pFocusWin = Application::GetFocusWindow();
228 if(!HasFocus() && GetSubEdit() != pFocusWin)
229 SetText(GetSavedValue());
232 return nHandled ? nHandled : FontSizeBox::Notify( rNEvt );
235 // ---------------------------------------------------------------------------
237 void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
239 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
240 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
242 SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
243 Size aDropSize( m_aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT );
244 SetDropDownSizePixel( LogicToPixel( aDropSize, MAP_APPFONT ));
247 FontSizeBox::DataChanged( rDCEvt );
250 //========================================================================
251 // class FontHeightToolBoxControl
252 //========================================================================
254 FontHeightToolBoxControl::FontHeightToolBoxControl(
255 const uno::Reference< lang::XMultiServiceFactory >& rServiceManager ) :
256 svt::ToolboxController( rServiceManager,
257 uno::Reference< frame::XFrame >(),
258 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontHeight" )) ),
259 m_pBox( NULL )
261 addStatusListener( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )));
264 FontHeightToolBoxControl::~FontHeightToolBoxControl()
268 // XInterface
269 ::com::sun::star::uno::Any SAL_CALL FontHeightToolBoxControl::queryInterface( const ::com::sun::star::uno::Type& aType )
270 throw (::com::sun::star::uno::RuntimeException)
272 uno::Any a = ToolboxController::queryInterface( aType );
273 if ( a.hasValue() )
274 return a;
276 return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
279 void SAL_CALL FontHeightToolBoxControl::acquire() throw ()
281 ToolboxController::acquire();
284 void SAL_CALL FontHeightToolBoxControl::release() throw ()
286 ToolboxController::release();
289 // XServiceInfo
290 sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService( const ::rtl::OUString& ServiceName )
291 throw(uno::RuntimeException)
293 const uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
294 const ::rtl::OUString * pArray = aSNL.getConstArray();
296 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
297 if( pArray[i] == ServiceName )
298 return true;
300 return false;
303 ::rtl::OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
304 throw( uno::RuntimeException )
306 return getImplementationName_Static();
309 uno::Sequence< ::rtl::OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
310 throw( uno::RuntimeException )
312 return getSupportedServiceNames_Static();
315 uno::Sequence< ::rtl::OUString > FontHeightToolBoxControl::getSupportedServiceNames_Static()
316 throw()
318 uno::Sequence< ::rtl::OUString > aSNS( 1 );
319 aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
320 return aSNS;
323 // XComponent
324 void SAL_CALL FontHeightToolBoxControl::dispose()
325 throw (uno::RuntimeException)
327 svt::ToolboxController::dispose();
329 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
330 delete m_pBox;
331 m_pBox = 0;
334 // XStatusListener
335 void SAL_CALL FontHeightToolBoxControl::statusChanged(
336 const frame::FeatureStateEvent& rEvent )
337 throw ( uno::RuntimeException )
339 if ( m_pBox )
341 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
342 if ( rEvent.FeatureURL.Path.equalsAscii( "FontHeight" ))
344 if ( rEvent.IsEnabled )
346 m_pBox->Enable();
347 frame::status::FontHeight aFontHeight;
348 if ( rEvent.State >>= aFontHeight )
349 m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false );
350 else
351 m_pBox->statusChanged_Impl( long( -1 ), true );
353 else
354 m_pBox->Disable();
356 else if ( rEvent.FeatureURL.Path.equalsAscii( "CharFontName" ))
358 if ( rEvent.State >>= m_aCurrentFont )
359 m_pBox->UpdateFont( m_aCurrentFont );
364 // XToolbarController
365 void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
366 throw (::com::sun::star::uno::RuntimeException)
370 void SAL_CALL FontHeightToolBoxControl::click()
371 throw (::com::sun::star::uno::RuntimeException)
375 void SAL_CALL FontHeightToolBoxControl::doubleClick()
376 throw (::com::sun::star::uno::RuntimeException)
380 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
381 throw (::com::sun::star::uno::RuntimeException)
383 return uno::Reference< awt::XWindow >();
386 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
387 const uno::Reference< awt::XWindow >& Parent )
388 throw (::com::sun::star::uno::RuntimeException)
390 uno::Reference< awt::XWindow > xItemWindow;
391 uno::Reference< awt::XWindow > xParent( Parent );
393 Window* pParent = VCLUnoHelper::GetWindow( xParent );
394 if ( pParent )
396 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
397 m_pBox = new SvxFontSizeBox_Impl(
398 pParent,
399 uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ),
400 m_xFrame,
401 *this );
402 xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
405 return xItemWindow;
408 void FontHeightToolBoxControl::dispatchCommand(
409 const uno::Sequence< beans::PropertyValue >& rArgs )
411 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
412 if ( xDispatchProvider.is() )
414 util::URL aURL;
415 uno::Reference< frame::XDispatch > xDispatch;
416 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
418 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontHeight" ));
419 xURLTransformer->parseStrict( aURL );
420 xDispatch = xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
421 if ( xDispatch.is() )
422 xDispatch->dispatch( aURL, rArgs );
426 uno::Reference< uno::XInterface > SAL_CALL FontHeightToolBoxControl_createInstance(
427 const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
429 return *new FontHeightToolBoxControl( rSMgr );