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 "tbunocontroller.hxx"
22 :
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>
26 :
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>
34 :
35 : #include <memory>
36 :
37 : #define LOGICAL_EDIT_HEIGHT 12
38 :
39 : using namespace ::com::sun::star;
40 :
41 : namespace svx
42 : {
43 :
44 : class FontHeightToolBoxControl;
45 1064 : class SvxFontSizeBox_Impl : public FontSizeBox
46 : {
47 : public:
48 : SvxFontSizeBox_Impl( Window* pParent,
49 : const uno::Reference< frame::XDispatchProvider >& rDispatchProvider,
50 : const uno::Reference< frame::XFrame >& _xFrame,
51 : FontHeightToolBoxControl& rCtrl );
52 :
53 : void statusChanged_Impl( long nHeight, bool bErase = false );
54 : void UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont );
55 :
56 : virtual long Notify( NotifyEvent& rNEvt );
57 :
58 : protected:
59 : virtual void Select();
60 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
61 :
62 : private:
63 : FontHeightToolBoxControl* m_pCtrl;
64 : String m_aCurText;
65 : Size m_aLogicalSize;
66 : bool m_bRelease;
67 : uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
68 : uno::Reference< frame::XFrame > m_xFrame;
69 : uno::Reference< awt::XWindow > m_xOldFocusWindow;
70 :
71 : void ReleaseFocus_Impl();
72 : };
73 :
74 : //========================================================================
75 : // class SvxFontSizeBox_Impl --------------------------------------------------
76 : //========================================================================
77 :
78 532 : SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
79 : Window* _pParent,
80 : const uno::Reference< frame::XDispatchProvider >& _rDispatchProvider,
81 : const uno::Reference< frame::XFrame >& _xFrame,
82 : FontHeightToolBoxControl& _rCtrl ) :
83 :
84 : FontSizeBox( _pParent, WinBits( WB_DROPDOWN ) ),
85 :
86 : m_pCtrl ( &_rCtrl ),
87 : m_aLogicalSize ( 30,100 ),
88 : m_bRelease ( true ),
89 : m_xDispatchProvider ( _rDispatchProvider ),
90 532 : m_xFrame ( _xFrame )
91 : {
92 532 : SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
93 532 : SetValue( 0 );
94 532 : SetText( String() );
95 532 : }
96 :
97 : // -----------------------------------------------------------------------
98 :
99 0 : void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
100 : {
101 0 : if ( !m_bRelease )
102 : {
103 0 : m_bRelease = true;
104 0 : return;
105 : }
106 :
107 0 : if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
108 0 : m_xFrame->getContainerWindow()->setFocus();
109 : }
110 :
111 : // -----------------------------------------------------------------------
112 :
113 0 : void SvxFontSizeBox_Impl::Select()
114 : {
115 0 : FontSizeBox::Select();
116 :
117 0 : if ( !IsTravelSelect() )
118 : {
119 0 : sal_Int64 nSelVal = GetValue();
120 0 : float fSelVal = float( nSelVal ) / 10;
121 :
122 0 : uno::Sequence< beans::PropertyValue > aArgs( 1 );
123 0 : aArgs[0].Name = OUString( "FontHeight.Height" );
124 0 : aArgs[0].Value = uno::makeAny( fSelVal );
125 :
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. */
129 0 : ReleaseFocus_Impl();
130 :
131 0 : m_pCtrl->dispatchCommand( aArgs );
132 : }
133 0 : }
134 :
135 : // -----------------------------------------------------------------------
136 :
137 777 : void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase )
138 : {
139 777 : if ( !bErase )
140 : {
141 : // Metric Umrechnen
142 777 : long nVal = nPoint;
143 :
144 : // ge"andert => neuen Wert setzen
145 777 : if ( GetValue() != nVal )
146 520 : SetValue( nVal );
147 : }
148 : else
149 : {
150 : // Wert in der Anzeige l"oschen
151 0 : SetValue( -1L );
152 0 : SetText( String() );
153 : }
154 777 : SaveValue();
155 777 : }
156 :
157 : // -----------------------------------------------------------------------
158 :
159 777 : void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont )
160 : {
161 : // Sizes-Liste auff"ullen
162 777 : sal_Int64 nOldVal = GetValue(); // alten Wert merken
163 777 : const FontList* _pFontList = NULL;
164 777 : ::std::auto_ptr<FontList> aHold( new FontList( this ));
165 777 : _pFontList = aHold.get();
166 :
167 777 : if ( !rCurrentFont.Name.isEmpty() )
168 : {
169 777 : FontInfo _aFontInfo;
170 777 : _aFontInfo.SetName( rCurrentFont.Name );
171 777 : _aFontInfo.SetStyleName( rCurrentFont.StyleName );
172 777 : _aFontInfo.SetHeight( rCurrentFont.Height );
173 777 : Fill( &_aFontInfo, _pFontList );
174 : }
175 : else
176 : {
177 0 : Fill( NULL, _pFontList );
178 : }
179 777 : SetValue( nOldVal ); // alten Wert wiederherstellen
180 777 : m_aCurText = GetText(); // zum R"ucksetzen bei ESC merken
181 777 : }
182 :
183 : // -----------------------------------------------------------------------
184 :
185 0 : long SvxFontSizeBox_Impl::Notify( NotifyEvent& rNEvt )
186 : {
187 0 : long nHandled = 0;
188 :
189 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
190 : {
191 0 : sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
192 :
193 0 : switch ( nCode )
194 : {
195 : case KEY_RETURN:
196 : case KEY_TAB:
197 : {
198 0 : if ( KEY_TAB == nCode )
199 0 : m_bRelease = false;
200 : else
201 0 : nHandled = 1;
202 0 : Select();
203 0 : break;
204 : }
205 :
206 : case KEY_ESCAPE:
207 0 : SetText( m_aCurText );
208 0 : ReleaseFocus_Impl();
209 0 : nHandled = 1;
210 0 : break;
211 : }
212 : }
213 0 : else if( EVENT_LOSEFOCUS == rNEvt.GetType() )
214 : {
215 0 : Window* pFocusWin = Application::GetFocusWindow();
216 0 : if(!HasFocus() && GetSubEdit() != pFocusWin)
217 0 : SetText(GetSavedValue());
218 : }
219 :
220 0 : return nHandled ? nHandled : FontSizeBox::Notify( rNEvt );
221 : }
222 :
223 : // ---------------------------------------------------------------------------
224 :
225 0 : void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
226 : {
227 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
228 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
229 : {
230 0 : SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
231 0 : Size aDropSize( m_aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT );
232 0 : SetDropDownSizePixel( LogicToPixel( aDropSize, MAP_APPFONT ));
233 : }
234 :
235 0 : FontSizeBox::DataChanged( rDCEvt );
236 0 : }
237 :
238 : //========================================================================
239 : // class FontHeightToolBoxControl
240 : //========================================================================
241 :
242 532 : FontHeightToolBoxControl::FontHeightToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
243 : : svt::ToolboxController( rxContext,
244 : uno::Reference< frame::XFrame >(),
245 : OUString( ".uno:FontHeight" ) ),
246 532 : m_pBox( NULL )
247 : {
248 532 : addStatusListener( OUString( ".uno:CharFontName" ));
249 532 : }
250 :
251 1064 : FontHeightToolBoxControl::~FontHeightToolBoxControl()
252 : {
253 1064 : }
254 :
255 : // XInterface
256 5822 : ::com::sun::star::uno::Any SAL_CALL FontHeightToolBoxControl::queryInterface( const ::com::sun::star::uno::Type& aType )
257 : throw (::com::sun::star::uno::RuntimeException)
258 : {
259 5822 : uno::Any a = ToolboxController::queryInterface( aType );
260 5822 : if ( a.hasValue() )
261 5290 : return a;
262 :
263 532 : return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
264 : }
265 :
266 22926 : void SAL_CALL FontHeightToolBoxControl::acquire() throw ()
267 : {
268 22926 : ToolboxController::acquire();
269 22926 : }
270 :
271 22926 : void SAL_CALL FontHeightToolBoxControl::release() throw ()
272 : {
273 22926 : ToolboxController::release();
274 22926 : }
275 :
276 : // XServiceInfo
277 0 : sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService( const OUString& ServiceName )
278 : throw(uno::RuntimeException)
279 : {
280 0 : const uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
281 0 : const OUString * pArray = aSNL.getConstArray();
282 :
283 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
284 0 : if( pArray[i] == ServiceName )
285 0 : return true;
286 :
287 0 : return false;
288 : }
289 :
290 0 : OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
291 : throw( uno::RuntimeException )
292 : {
293 0 : return getImplementationName_Static();
294 : }
295 :
296 0 : uno::Sequence< OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
297 : throw( uno::RuntimeException )
298 : {
299 0 : return getSupportedServiceNames_Static();
300 : }
301 :
302 26 : uno::Sequence< OUString > FontHeightToolBoxControl::getSupportedServiceNames_Static()
303 : throw()
304 : {
305 26 : uno::Sequence< OUString > aSNS( 1 );
306 26 : aSNS.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
307 26 : return aSNS;
308 : }
309 :
310 : // XComponent
311 532 : void SAL_CALL FontHeightToolBoxControl::dispose()
312 : throw (uno::RuntimeException)
313 : {
314 532 : svt::ToolboxController::dispose();
315 :
316 532 : SolarMutexGuard aSolarMutexGuard;
317 532 : delete m_pBox;
318 532 : m_pBox = 0;
319 532 : }
320 :
321 : // XStatusListener
322 1554 : void SAL_CALL FontHeightToolBoxControl::statusChanged(
323 : const frame::FeatureStateEvent& rEvent )
324 : throw ( uno::RuntimeException )
325 : {
326 1554 : if ( m_pBox )
327 : {
328 1554 : SolarMutexGuard aSolarMutexGuard;
329 1554 : if ( rEvent.FeatureURL.Path == "FontHeight" )
330 : {
331 777 : if ( rEvent.IsEnabled )
332 : {
333 777 : m_pBox->Enable();
334 777 : frame::status::FontHeight aFontHeight;
335 777 : if ( rEvent.State >>= aFontHeight )
336 777 : m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false );
337 : else
338 0 : m_pBox->statusChanged_Impl( long( -1 ), true );
339 : }
340 : else
341 0 : m_pBox->Disable();
342 : }
343 777 : else if ( rEvent.FeatureURL.Path == "CharFontName" )
344 : {
345 777 : if ( rEvent.State >>= m_aCurrentFont )
346 777 : m_pBox->UpdateFont( m_aCurrentFont );
347 1554 : }
348 : }
349 1554 : }
350 :
351 : // XToolbarController
352 0 : void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
353 : throw (::com::sun::star::uno::RuntimeException)
354 : {
355 0 : }
356 :
357 0 : void SAL_CALL FontHeightToolBoxControl::click()
358 : throw (::com::sun::star::uno::RuntimeException)
359 : {
360 0 : }
361 :
362 0 : void SAL_CALL FontHeightToolBoxControl::doubleClick()
363 : throw (::com::sun::star::uno::RuntimeException)
364 : {
365 0 : }
366 :
367 0 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
368 : throw (::com::sun::star::uno::RuntimeException)
369 : {
370 0 : return uno::Reference< awt::XWindow >();
371 : }
372 :
373 532 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
374 : const uno::Reference< awt::XWindow >& Parent )
375 : throw (::com::sun::star::uno::RuntimeException)
376 : {
377 532 : uno::Reference< awt::XWindow > xItemWindow;
378 1064 : uno::Reference< awt::XWindow > xParent( Parent );
379 :
380 532 : Window* pParent = VCLUnoHelper::GetWindow( xParent );
381 532 : if ( pParent )
382 : {
383 532 : SolarMutexGuard aSolarMutexGuard;
384 : m_pBox = new SvxFontSizeBox_Impl(
385 : pParent,
386 : uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ),
387 : m_xFrame,
388 532 : *this );
389 532 : xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
390 : }
391 :
392 1064 : return xItemWindow;
393 : }
394 :
395 0 : void FontHeightToolBoxControl::dispatchCommand(
396 : const uno::Sequence< beans::PropertyValue >& rArgs )
397 : {
398 0 : uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
399 0 : if ( xDispatchProvider.is() )
400 : {
401 0 : util::URL aURL;
402 0 : uno::Reference< frame::XDispatch > xDispatch;
403 0 : uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
404 :
405 0 : aURL.Complete = OUString( ".uno:FontHeight" );
406 0 : xURLTransformer->parseStrict( aURL );
407 0 : xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
408 0 : if ( xDispatch.is() )
409 0 : xDispatch->dispatch( aURL, rArgs );
410 0 : }
411 0 : }
412 :
413 532 : uno::Reference< uno::XInterface > SAL_CALL FontHeightToolBoxControl_createInstance(
414 : const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
415 : {
416 532 : return *new FontHeightToolBoxControl( comphelper::getComponentContext(rSMgr) );
417 : }
418 :
419 216 : }
420 :
421 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|