fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / tbxctrls / tbunocontroller.cxx
blobeb25ce945b3ffeb6ef15980b19f543f649c24b38
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <com/sun/star/awt/FontDescriptor.hpp>
21 #include <com/sun/star/frame/status/FontHeight.hpp>
22 #include <com/sun/star/frame/XDispatchProvider.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <rtl/ref.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/window.hxx>
29 #include <vcl/settings.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <svtools/ctrltool.hxx>
32 #include <svtools/ctrlbox.hxx>
33 #include <svtools/toolboxcontroller.hxx>
34 #include <osl/mutex.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <cppuhelper/queryinterface.hxx>
37 #include <cppuhelper/supportsservice.hxx>
39 #include <boost/scoped_ptr.hpp>
41 using namespace ::com::sun::star;
43 namespace {
45 class SvxFontSizeBox_Impl;
46 class FontHeightToolBoxControl : public svt::ToolboxController,
47 public lang::XServiceInfo
49 public:
50 FontHeightToolBoxControl(
51 const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rServiceManager );
52 virtual ~FontHeightToolBoxControl();
54 // XInterface
55 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
56 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
57 virtual void SAL_CALL release() throw () SAL_OVERRIDE;
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
61 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
62 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
64 // XComponent
65 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
67 // XStatusListener
68 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
70 // XToolbarController
71 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
74 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& Parent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
77 void dispatchCommand( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
78 using svt::ToolboxController::dispatchCommand;
80 private:
81 VclPtr<SvxFontSizeBox_Impl> m_pBox;
82 ::com::sun::star::awt::FontDescriptor m_aCurrentFont;
85 class SvxFontSizeBox_Impl : public FontSizeBox
87 public:
88 SvxFontSizeBox_Impl( vcl::Window* pParent,
89 const uno::Reference< frame::XDispatchProvider >& rDispatchProvider,
90 const uno::Reference< frame::XFrame >& _xFrame,
91 FontHeightToolBoxControl& rCtrl );
93 void statusChanged_Impl( long nHeight, bool bErase = false );
94 void UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont );
95 void SetOptimalSize();
97 virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
99 protected:
100 virtual void Select() SAL_OVERRIDE;
101 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
103 private:
104 FontHeightToolBoxControl* m_pCtrl;
105 OUString m_aCurText;
106 Size m_aLogicalSize;
107 bool m_bRelease;
108 uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
109 uno::Reference< frame::XFrame > m_xFrame;
110 uno::Reference< awt::XWindow > m_xOldFocusWindow;
112 void ReleaseFocus_Impl();
115 SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
116 vcl::Window* _pParent,
117 const uno::Reference< frame::XDispatchProvider >& _rDispatchProvider,
118 const uno::Reference< frame::XFrame >& _xFrame,
119 FontHeightToolBoxControl& _rCtrl ) :
121 FontSizeBox( _pParent, WinBits( WB_DROPDOWN ) ),
123 m_pCtrl ( &_rCtrl ),
124 m_aLogicalSize ( 0,100 ),
125 m_bRelease ( true ),
126 m_xDispatchProvider ( _rDispatchProvider ),
127 m_xFrame ( _xFrame )
129 SetValue( 0 );
130 SetText( "" );
133 void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
135 if ( !m_bRelease )
137 m_bRelease = true;
138 return;
141 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
142 m_xFrame->getContainerWindow()->setFocus();
147 void SvxFontSizeBox_Impl::Select()
149 FontSizeBox::Select();
151 if ( !IsTravelSelect() )
153 sal_Int64 nSelVal = GetValue();
154 float fSelVal = float( nSelVal ) / 10;
156 uno::Sequence< beans::PropertyValue > aArgs( 1 );
157 aArgs[0].Name = "FontHeight.Height";
158 aArgs[0].Value = uno::makeAny( fSelVal );
160 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
161 This instance may be deleted in the meantime (i.e. when a dialog is opened
162 while in Dispatch()), accessing members will crash in this case. */
163 ReleaseFocus_Impl();
165 m_pCtrl->dispatchCommand( aArgs );
171 void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase )
173 if ( !bErase )
175 // Metric Umrechnen
176 long nVal = nPoint;
178 // ge"andert => neuen Wert setzen
179 if ( GetValue() != nVal )
180 SetValue( nVal );
182 else
184 // Wert in der Anzeige l"oschen
185 SetValue( -1L );
186 SetText( "" );
188 SaveValue();
193 void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont )
195 // Sizes-Liste auff"ullen
196 sal_Int64 nOldVal = GetValue(); // alten Wert merken
197 const FontList* _pFontList = NULL;
198 boost::scoped_ptr<FontList> aHold( new FontList( this ));
199 _pFontList = aHold.get();
201 if ( !rCurrentFont.Name.isEmpty() )
203 vcl::FontInfo _aFontInfo;
204 _aFontInfo.SetName( rCurrentFont.Name );
205 _aFontInfo.SetStyleName( rCurrentFont.StyleName );
206 _aFontInfo.SetHeight( rCurrentFont.Height );
207 Fill( &_aFontInfo, _pFontList );
209 else
211 Fill( NULL, _pFontList );
213 SetValue( nOldVal ); // alten Wert wiederherstellen
214 m_aCurText = GetText(); // zum R"ucksetzen bei ESC merken
219 bool SvxFontSizeBox_Impl::Notify( NotifyEvent& rNEvt )
221 bool nHandled = false;
223 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
225 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
227 switch ( nCode )
229 case KEY_RETURN:
230 case KEY_TAB:
232 if ( KEY_TAB == nCode )
233 m_bRelease = false;
234 else
235 nHandled = true;
236 Select();
237 break;
240 case KEY_ESCAPE:
241 SetText( m_aCurText );
242 ReleaseFocus_Impl();
243 nHandled = true;
244 break;
247 else if( MouseNotifyEvent::LOSEFOCUS == rNEvt.GetType() )
249 vcl::Window* pFocusWin = Application::GetFocusWindow();
250 if(!HasFocus() && GetSubEdit() != pFocusWin)
251 SetText(GetSavedValue());
254 return nHandled || FontSizeBox::Notify( rNEvt );
257 void SvxFontSizeBox_Impl::SetOptimalSize()
259 Size aPrefSize(LogicToPixel(m_aLogicalSize, MAP_APPFONT));
260 aPrefSize.Width() = get_preferred_size().Width();
261 SetSizePixel(aPrefSize);
264 void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
266 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
267 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
269 SetOptimalSize();
272 FontSizeBox::DataChanged( rDCEvt );
275 FontHeightToolBoxControl::FontHeightToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
276 : svt::ToolboxController( rxContext,
277 uno::Reference< frame::XFrame >(),
278 OUString( ".uno:FontHeight" ) ),
279 m_pBox( NULL )
281 addStatusListener( OUString( ".uno:CharFontName" ));
284 FontHeightToolBoxControl::~FontHeightToolBoxControl()
288 // XInterface
289 ::com::sun::star::uno::Any SAL_CALL FontHeightToolBoxControl::queryInterface( const ::com::sun::star::uno::Type& aType )
290 throw (::com::sun::star::uno::RuntimeException, std::exception)
292 uno::Any a = ToolboxController::queryInterface( aType );
293 if ( a.hasValue() )
294 return a;
296 return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
299 void SAL_CALL FontHeightToolBoxControl::acquire() throw ()
301 ToolboxController::acquire();
304 void SAL_CALL FontHeightToolBoxControl::release() throw ()
306 ToolboxController::release();
309 // XServiceInfo
310 sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService( const OUString& ServiceName )
311 throw(uno::RuntimeException, std::exception)
313 return cppu::supportsService(this, ServiceName);
316 OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
317 throw( uno::RuntimeException, std::exception )
319 return OUString("com.sun.star.svx.FontHeightToolBoxController");
322 uno::Sequence< OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
323 throw( uno::RuntimeException, std::exception )
325 uno::Sequence< OUString > aSNS( 1 );
326 aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
327 return aSNS;
330 // XComponent
331 void SAL_CALL FontHeightToolBoxControl::dispose()
332 throw (uno::RuntimeException, std::exception)
334 svt::ToolboxController::dispose();
336 SolarMutexGuard aSolarMutexGuard;
337 m_pBox.disposeAndClear();
340 // XStatusListener
341 void SAL_CALL FontHeightToolBoxControl::statusChanged(
342 const frame::FeatureStateEvent& rEvent )
343 throw ( uno::RuntimeException, std::exception )
345 if ( m_pBox )
347 SolarMutexGuard aSolarMutexGuard;
348 if ( rEvent.FeatureURL.Path == "FontHeight" )
350 if ( rEvent.IsEnabled )
352 m_pBox->Enable();
353 frame::status::FontHeight aFontHeight;
354 if ( rEvent.State >>= aFontHeight )
355 m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false );
356 else
357 m_pBox->statusChanged_Impl( long( -1 ), true );
359 else
360 m_pBox->Disable();
362 else if ( rEvent.FeatureURL.Path == "CharFontName" )
364 if ( rEvent.State >>= m_aCurrentFont )
365 m_pBox->UpdateFont( m_aCurrentFont );
370 // XToolbarController
371 void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
372 throw (::com::sun::star::uno::RuntimeException, std::exception)
376 void SAL_CALL FontHeightToolBoxControl::click()
377 throw (::com::sun::star::uno::RuntimeException, std::exception)
381 void SAL_CALL FontHeightToolBoxControl::doubleClick()
382 throw (::com::sun::star::uno::RuntimeException, std::exception)
386 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
387 throw (::com::sun::star::uno::RuntimeException, std::exception)
389 return uno::Reference< awt::XWindow >();
392 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
393 const uno::Reference< awt::XWindow >& Parent )
394 throw (::com::sun::star::uno::RuntimeException, std::exception)
396 uno::Reference< awt::XWindow > xItemWindow;
397 uno::Reference< awt::XWindow > xParent( Parent );
399 vcl::Window* pParent = VCLUnoHelper::GetWindow( xParent );
400 if ( pParent )
402 SolarMutexGuard aSolarMutexGuard;
403 m_pBox = VclPtr<SvxFontSizeBox_Impl>::Create(
405 pParent,
406 uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ),
407 m_xFrame,
408 *this );
409 //Get the box to fill itself with all its sizes
410 m_pBox->UpdateFont(m_aCurrentFont);
411 //Make it size itself to its optimal size re above sizes
412 m_pBox->SetOptimalSize();
413 xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
416 return xItemWindow;
419 void FontHeightToolBoxControl::dispatchCommand(
420 const uno::Sequence< beans::PropertyValue >& rArgs )
422 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
423 if ( xDispatchProvider.is() )
425 util::URL aURL;
426 uno::Reference< frame::XDispatch > xDispatch;
427 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
429 aURL.Complete = ".uno:FontHeight";
430 xURLTransformer->parseStrict( aURL );
431 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
432 if ( xDispatch.is() )
433 xDispatch->dispatch( aURL, rArgs );
439 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
440 com_sun_star_svx_FontHeightToolBoxController_get_implementation(
441 css::uno::XComponentContext *rxContext,
442 css::uno::Sequence<css::uno::Any> const &)
444 return cppu::acquire(new FontHeightToolBoxControl(rxContext));
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */