1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "tbunocontroller.hxx"
23 #include <com/sun/star/frame/status/FontHeight.hpp>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <vcl/svapp.hxx>
28 #include <vcl/window.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <svtools/ctrltool.hxx>
31 #include <svtools/ctrlbox.hxx>
32 #include <osl/mutex.hxx>
33 #include <comphelper/processfactory.hxx>
37 #define LOGICAL_EDIT_HEIGHT 12
39 using namespace ::com::sun::star
;
44 class FontHeightToolBoxControl
;
45 class SvxFontSizeBox_Impl
: public FontSizeBox
48 SvxFontSizeBox_Impl( Window
* pParent
,
49 const uno::Reference
< frame::XDispatchProvider
>& rDispatchProvider
,
50 const uno::Reference
< frame::XFrame
>& _xFrame
,
51 FontHeightToolBoxControl
& rCtrl
);
53 void statusChanged_Impl( long nHeight
, bool bErase
= false );
54 void UpdateFont( const ::com::sun::star::awt::FontDescriptor
& rCurrentFont
);
56 virtual long Notify( NotifyEvent
& rNEvt
);
59 virtual void Select();
60 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
63 FontHeightToolBoxControl
* m_pCtrl
;
67 uno::Reference
< frame::XDispatchProvider
> m_xDispatchProvider
;
68 uno::Reference
< frame::XFrame
> m_xFrame
;
69 uno::Reference
< awt::XWindow
> m_xOldFocusWindow
;
71 void ReleaseFocus_Impl();
74 //========================================================================
75 // class SvxFontSizeBox_Impl --------------------------------------------------
76 //========================================================================
78 SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
80 const uno::Reference
< frame::XDispatchProvider
>& _rDispatchProvider
,
81 const uno::Reference
< frame::XFrame
>& _xFrame
,
82 FontHeightToolBoxControl
& _rCtrl
) :
84 FontSizeBox( _pParent
, WinBits( WB_DROPDOWN
) ),
87 m_aLogicalSize ( 30,100 ),
89 m_xDispatchProvider ( _rDispatchProvider
),
92 SetSizePixel( LogicToPixel( m_aLogicalSize
, MAP_APPFONT
));
97 // -----------------------------------------------------------------------
99 void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
107 if ( m_xFrame
.is() && m_xFrame
->getContainerWindow().is() )
108 m_xFrame
->getContainerWindow()->setFocus();
111 // -----------------------------------------------------------------------
113 void SvxFontSizeBox_Impl::Select()
115 FontSizeBox::Select();
117 if ( !IsTravelSelect() )
119 sal_Int64 nSelVal
= GetValue();
120 float fSelVal
= float( nSelVal
) / 10;
122 uno::Sequence
< beans::PropertyValue
> aArgs( 1 );
123 aArgs
[0].Name
= OUString( "FontHeight.Height" );
124 aArgs
[0].Value
= uno::makeAny( fSelVal
);
126 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
127 This instance may be deleted in the meantime (i.e. when a dialog is opened
128 while in Dispatch()), accessing members will crash in this case. */
131 m_pCtrl
->dispatchCommand( aArgs
);
135 // -----------------------------------------------------------------------
137 void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint
, bool bErase
)
144 // ge"andert => neuen Wert setzen
145 if ( GetValue() != nVal
)
150 // Wert in der Anzeige l"oschen
157 // -----------------------------------------------------------------------
159 void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor
& rCurrentFont
)
161 // Sizes-Liste auff"ullen
162 sal_Int64 nOldVal
= GetValue(); // alten Wert merken
163 const FontList
* _pFontList
= NULL
;
164 ::std::auto_ptr
<FontList
> aHold( new FontList( this ));
165 _pFontList
= aHold
.get();
167 if ( !rCurrentFont
.Name
.isEmpty() )
170 _aFontInfo
.SetName( rCurrentFont
.Name
);
171 _aFontInfo
.SetStyleName( rCurrentFont
.StyleName
);
172 _aFontInfo
.SetHeight( rCurrentFont
.Height
);
173 Fill( &_aFontInfo
, _pFontList
);
177 Fill( NULL
, _pFontList
);
179 SetValue( nOldVal
); // alten Wert wiederherstellen
180 m_aCurText
= GetText(); // zum R"ucksetzen bei ESC merken
183 // -----------------------------------------------------------------------
185 long SvxFontSizeBox_Impl::Notify( NotifyEvent
& rNEvt
)
189 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
191 sal_uInt16 nCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
198 if ( KEY_TAB
== nCode
)
207 SetText( m_aCurText
);
213 else if( EVENT_LOSEFOCUS
== rNEvt
.GetType() )
215 Window
* pFocusWin
= Application::GetFocusWindow();
216 if(!HasFocus() && GetSubEdit() != pFocusWin
)
217 SetText(GetSavedValue());
220 return nHandled
? nHandled
: FontSizeBox::Notify( rNEvt
);
223 // ---------------------------------------------------------------------------
225 void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent
& rDCEvt
)
227 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
228 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
230 SetSizePixel( LogicToPixel( m_aLogicalSize
, MAP_APPFONT
));
231 Size
aDropSize( m_aLogicalSize
.Width(), LOGICAL_EDIT_HEIGHT
);
232 SetDropDownSizePixel( LogicToPixel( aDropSize
, MAP_APPFONT
));
235 FontSizeBox::DataChanged( rDCEvt
);
238 //========================================================================
239 // class FontHeightToolBoxControl
240 //========================================================================
242 FontHeightToolBoxControl::FontHeightToolBoxControl( const uno::Reference
< uno::XComponentContext
>& rxContext
)
243 : svt::ToolboxController( rxContext
,
244 uno::Reference
< frame::XFrame
>(),
245 OUString( ".uno:FontHeight" ) ),
248 addStatusListener( OUString( ".uno:CharFontName" ));
251 FontHeightToolBoxControl::~FontHeightToolBoxControl()
256 ::com::sun::star::uno::Any SAL_CALL
FontHeightToolBoxControl::queryInterface( const ::com::sun::star::uno::Type
& aType
)
257 throw (::com::sun::star::uno::RuntimeException
)
259 uno::Any a
= ToolboxController::queryInterface( aType
);
263 return ::cppu::queryInterface( aType
, static_cast< lang::XServiceInfo
* >( this ));
266 void SAL_CALL
FontHeightToolBoxControl::acquire() throw ()
268 ToolboxController::acquire();
271 void SAL_CALL
FontHeightToolBoxControl::release() throw ()
273 ToolboxController::release();
277 sal_Bool SAL_CALL
FontHeightToolBoxControl::supportsService( const OUString
& ServiceName
)
278 throw(uno::RuntimeException
)
280 const uno::Sequence
< OUString
> aSNL( getSupportedServiceNames() );
281 const OUString
* pArray
= aSNL
.getConstArray();
283 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
284 if( pArray
[i
] == ServiceName
)
290 OUString SAL_CALL
FontHeightToolBoxControl::getImplementationName()
291 throw( uno::RuntimeException
)
293 return getImplementationName_Static();
296 uno::Sequence
< OUString
> SAL_CALL
FontHeightToolBoxControl::getSupportedServiceNames( )
297 throw( uno::RuntimeException
)
299 return getSupportedServiceNames_Static();
302 uno::Sequence
< OUString
> FontHeightToolBoxControl::getSupportedServiceNames_Static()
305 uno::Sequence
< OUString
> aSNS( 1 );
306 aSNS
.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
311 void SAL_CALL
FontHeightToolBoxControl::dispose()
312 throw (uno::RuntimeException
)
314 svt::ToolboxController::dispose();
316 SolarMutexGuard aSolarMutexGuard
;
322 void SAL_CALL
FontHeightToolBoxControl::statusChanged(
323 const frame::FeatureStateEvent
& rEvent
)
324 throw ( uno::RuntimeException
)
328 SolarMutexGuard aSolarMutexGuard
;
329 if ( rEvent
.FeatureURL
.Path
== "FontHeight" )
331 if ( rEvent
.IsEnabled
)
334 frame::status::FontHeight aFontHeight
;
335 if ( rEvent
.State
>>= aFontHeight
)
336 m_pBox
->statusChanged_Impl( long( 10. * aFontHeight
.Height
), false );
338 m_pBox
->statusChanged_Impl( long( -1 ), true );
343 else if ( rEvent
.FeatureURL
.Path
== "CharFontName" )
345 if ( rEvent
.State
>>= m_aCurrentFont
)
346 m_pBox
->UpdateFont( m_aCurrentFont
);
351 // XToolbarController
352 void SAL_CALL
FontHeightToolBoxControl::execute( sal_Int16
/*KeyModifier*/ )
353 throw (::com::sun::star::uno::RuntimeException
)
357 void SAL_CALL
FontHeightToolBoxControl::click()
358 throw (::com::sun::star::uno::RuntimeException
)
362 void SAL_CALL
FontHeightToolBoxControl::doubleClick()
363 throw (::com::sun::star::uno::RuntimeException
)
367 uno::Reference
< awt::XWindow
> SAL_CALL
FontHeightToolBoxControl::createPopupWindow()
368 throw (::com::sun::star::uno::RuntimeException
)
370 return uno::Reference
< awt::XWindow
>();
373 uno::Reference
< awt::XWindow
> SAL_CALL
FontHeightToolBoxControl::createItemWindow(
374 const uno::Reference
< awt::XWindow
>& Parent
)
375 throw (::com::sun::star::uno::RuntimeException
)
377 uno::Reference
< awt::XWindow
> xItemWindow
;
378 uno::Reference
< awt::XWindow
> xParent( Parent
);
380 Window
* pParent
= VCLUnoHelper::GetWindow( xParent
);
383 SolarMutexGuard aSolarMutexGuard
;
384 m_pBox
= new SvxFontSizeBox_Impl(
386 uno::Reference
< frame::XDispatchProvider
>( m_xFrame
, uno::UNO_QUERY
),
389 xItemWindow
= VCLUnoHelper::GetInterface( m_pBox
);
395 void FontHeightToolBoxControl::dispatchCommand(
396 const uno::Sequence
< beans::PropertyValue
>& rArgs
)
398 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider( m_xFrame
, uno::UNO_QUERY
);
399 if ( xDispatchProvider
.is() )
402 uno::Reference
< frame::XDispatch
> xDispatch
;
403 uno::Reference
< util::XURLTransformer
> xURLTransformer
= getURLTransformer();
405 aURL
.Complete
= OUString( ".uno:FontHeight" );
406 xURLTransformer
->parseStrict( aURL
);
407 xDispatch
= xDispatchProvider
->queryDispatch( aURL
, OUString(), 0 );
408 if ( xDispatch
.is() )
409 xDispatch
->dispatch( aURL
, rArgs
);
413 uno::Reference
< uno::XInterface
> SAL_CALL
FontHeightToolBoxControl_createInstance(
414 const uno::Reference
< lang::XMultiServiceFactory
>& rSMgr
)
416 return *new FontHeightToolBoxControl( comphelper::getComponentContext(rSMgr
) );
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */