1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbunocontroller.cxx,v $
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>
49 #define LOGICAL_EDIT_HEIGHT 12
51 using namespace ::com::sun::star
;
56 class FontHeightToolBoxControl
;
57 class SvxFontSizeBox_Impl
: public FontSizeBox
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
);
71 virtual void Select();
72 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
75 FontHeightToolBoxControl
* m_pCtrl
;
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(
92 const uno::Reference
< frame::XDispatchProvider
>& _rDispatchProvider
,
93 const uno::Reference
< frame::XFrame
>& _xFrame
,
94 FontHeightToolBoxControl
& _rCtrl
) :
96 FontSizeBox( _pParent
, WinBits( WB_DROPDOWN
) ),
99 m_aLogicalSize ( 30,100 ),
101 m_xDispatchProvider ( _rDispatchProvider
),
104 SetSizePixel( LogicToPixel( m_aLogicalSize
, MAP_APPFONT
));
109 // -----------------------------------------------------------------------
111 void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
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. */
143 m_pCtrl
->dispatchCommand( aArgs
);
147 // -----------------------------------------------------------------------
149 void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint
, bool bErase
)
156 // ge"andert => neuen Wert setzen
157 if ( GetValue() != nVal
)
162 // Wert in der Anzeige l"oschen
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 )
182 _aFontInfo
.SetName( rCurrentFont
.Name
);
183 _aFontInfo
.SetStyleName( rCurrentFont
.StyleName
);
184 _aFontInfo
.SetHeight( rCurrentFont
.Height
);
185 Fill( &_aFontInfo
, _pFontList
);
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
)
201 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
203 USHORT nCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
210 if ( KEY_TAB
== nCode
)
219 SetText( m_aCurText
);
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" )) ),
261 addStatusListener( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )));
264 FontHeightToolBoxControl::~FontHeightToolBoxControl()
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
);
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();
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
)
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()
318 uno::Sequence
< ::rtl::OUString
> aSNS( 1 );
319 aSNS
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
324 void SAL_CALL
FontHeightToolBoxControl::dispose()
325 throw (uno::RuntimeException
)
327 svt::ToolboxController::dispose();
329 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
335 void SAL_CALL
FontHeightToolBoxControl::statusChanged(
336 const frame::FeatureStateEvent
& rEvent
)
337 throw ( uno::RuntimeException
)
341 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
342 if ( rEvent
.FeatureURL
.Path
.equalsAscii( "FontHeight" ))
344 if ( rEvent
.IsEnabled
)
347 frame::status::FontHeight aFontHeight
;
348 if ( rEvent
.State
>>= aFontHeight
)
349 m_pBox
->statusChanged_Impl( long( 10. * aFontHeight
.Height
), false );
351 m_pBox
->statusChanged_Impl( long( -1 ), true );
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
);
396 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
397 m_pBox
= new SvxFontSizeBox_Impl(
399 uno::Reference
< frame::XDispatchProvider
>( m_xFrame
, uno::UNO_QUERY
),
402 xItemWindow
= VCLUnoHelper::GetInterface( m_pBox
);
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() )
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
);