Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "tbunocontroller.hxx"
31 : :
32 : : #include <com/sun/star/frame/status/FontHeight.hpp>
33 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
34 : : #include <com/sun/star/beans/PropertyValue.hpp>
35 : :
36 : : #include <vcl/svapp.hxx>
37 : : #include <vcl/window.hxx>
38 : : #include <toolkit/helper/vclunohelper.hxx>
39 : : #include <svtools/ctrltool.hxx>
40 : : #include <svtools/ctrlbox.hxx>
41 : : #include <osl/mutex.hxx>
42 : :
43 : : #include <memory>
44 : :
45 : : #define LOGICAL_EDIT_HEIGHT 12
46 : :
47 : : using namespace ::com::sun::star;
48 : :
49 : : namespace svx
50 : : {
51 : :
52 : : class FontHeightToolBoxControl;
53 [ + - ][ - + ]: 1922 : class SvxFontSizeBox_Impl : public FontSizeBox
54 : : {
55 : : public:
56 : : SvxFontSizeBox_Impl( Window* pParent,
57 : : const uno::Reference< frame::XDispatchProvider >& rDispatchProvider,
58 : : const uno::Reference< frame::XFrame >& _xFrame,
59 : : FontHeightToolBoxControl& rCtrl );
60 : :
61 : : void statusChanged_Impl( long nHeight, bool bErase = false );
62 : : void UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont );
63 : :
64 : : virtual long Notify( NotifyEvent& rNEvt );
65 : :
66 : : protected:
67 : : virtual void Select();
68 : : virtual void DataChanged( const DataChangedEvent& rDCEvt );
69 : :
70 : : private:
71 : : FontHeightToolBoxControl* m_pCtrl;
72 : : String m_aCurText;
73 : : Size m_aLogicalSize;
74 : : sal_Bool m_bRelease;
75 : : uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
76 : : uno::Reference< frame::XFrame > m_xFrame;
77 : : uno::Reference< awt::XWindow > m_xOldFocusWindow;
78 : :
79 : : void ReleaseFocus_Impl();
80 : : };
81 : :
82 : : //========================================================================
83 : : // class SvxFontSizeBox_Impl --------------------------------------------------
84 : : //========================================================================
85 : :
86 : 961 : SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
87 : : Window* _pParent,
88 : : const uno::Reference< frame::XDispatchProvider >& _rDispatchProvider,
89 : : const uno::Reference< frame::XFrame >& _xFrame,
90 : : FontHeightToolBoxControl& _rCtrl ) :
91 : :
92 : : FontSizeBox( _pParent, WinBits( WB_DROPDOWN ) ),
93 : :
94 : : m_pCtrl ( &_rCtrl ),
95 : : m_aLogicalSize ( 30,100 ),
96 : : m_bRelease ( sal_True ),
97 : : m_xDispatchProvider ( _rDispatchProvider ),
98 [ + - ]: 961 : m_xFrame ( _xFrame )
99 : : {
100 [ + - ][ + - ]: 961 : SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
[ + - ][ + - ]
101 [ + - ]: 961 : SetValue( 0 );
102 [ + - ][ + - ]: 961 : SetText( String() );
[ + - ]
103 : 961 : }
104 : :
105 : : // -----------------------------------------------------------------------
106 : :
107 : 0 : void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
108 : : {
109 [ # # ]: 0 : if ( !m_bRelease )
110 : : {
111 : 0 : m_bRelease = sal_True;
112 : 0 : return;
113 : : }
114 : :
115 [ # # ][ # # ]: 0 : if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
116 [ # # ][ # # ]: 0 : m_xFrame->getContainerWindow()->setFocus();
117 : : }
118 : :
119 : : // -----------------------------------------------------------------------
120 : :
121 : 0 : void SvxFontSizeBox_Impl::Select()
122 : : {
123 : 0 : FontSizeBox::Select();
124 : :
125 [ # # ]: 0 : if ( !IsTravelSelect() )
126 : : {
127 [ # # ]: 0 : sal_Int64 nSelVal = GetValue();
128 : 0 : float fSelVal = float( nSelVal ) / 10;
129 : :
130 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aArgs( 1 );
131 [ # # ][ # # ]: 0 : aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight.Height" ));
132 [ # # ][ # # ]: 0 : aArgs[0].Value = uno::makeAny( fSelVal );
133 : :
134 : : /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
135 : : This instance may be deleted in the meantime (i.e. when a dialog is opened
136 : : while in Dispatch()), accessing members will crash in this case. */
137 [ # # ]: 0 : ReleaseFocus_Impl();
138 : :
139 [ # # ][ # # ]: 0 : m_pCtrl->dispatchCommand( aArgs );
140 : : }
141 : 0 : }
142 : :
143 : : // -----------------------------------------------------------------------
144 : :
145 : 1482 : void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase )
146 : : {
147 [ + - ]: 1482 : if ( !bErase )
148 : : {
149 : : // Metric Umrechnen
150 : 1482 : long nVal = nPoint;
151 : :
152 : : // ge"andert => neuen Wert setzen
153 [ + + ]: 1482 : if ( GetValue() != nVal )
154 : 945 : SetValue( nVal );
155 : : }
156 : : else
157 : : {
158 : : // Wert in der Anzeige l"oschen
159 : 0 : SetValue( -1L );
160 [ # # ]: 0 : SetText( String() );
161 : : }
162 : 1482 : SaveValue();
163 : 1482 : }
164 : :
165 : : // -----------------------------------------------------------------------
166 : :
167 : 1481 : void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont )
168 : : {
169 : : // Sizes-Liste auff"ullen
170 [ + - ]: 1481 : sal_Int64 nOldVal = GetValue(); // alten Wert merken
171 : 1481 : const FontList* _pFontList = NULL;
172 [ + - ][ + - ]: 1481 : ::std::auto_ptr<FontList> aHold( new FontList( this ));
173 : 1481 : _pFontList = aHold.get();
174 : :
175 [ + - ]: 1481 : if ( !rCurrentFont.Name.isEmpty() )
176 : : {
177 [ + - ]: 1481 : FontInfo _aFontInfo;
178 [ + - ]: 1481 : _aFontInfo.SetName( rCurrentFont.Name );
179 [ + - ][ + - ]: 1481 : _aFontInfo.SetStyleName( rCurrentFont.StyleName );
[ + - ]
180 [ + - ]: 1481 : _aFontInfo.SetHeight( rCurrentFont.Height );
181 [ + - ][ + - ]: 1481 : Fill( &_aFontInfo, _pFontList );
182 : : }
183 : : else
184 : : {
185 [ # # ]: 0 : Fill( NULL, _pFontList );
186 : : }
187 [ + - ]: 1481 : SetValue( nOldVal ); // alten Wert wiederherstellen
188 [ + - ][ + - ]: 1481 : m_aCurText = GetText(); // zum R"ucksetzen bei ESC merken
[ + - ][ + - ]
189 : 1481 : }
190 : :
191 : : // -----------------------------------------------------------------------
192 : :
193 : 0 : long SvxFontSizeBox_Impl::Notify( NotifyEvent& rNEvt )
194 : : {
195 : 0 : long nHandled = 0;
196 : :
197 [ # # ]: 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
198 : : {
199 : 0 : sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
200 : :
201 [ # # # ]: 0 : switch ( nCode )
202 : : {
203 : : case KEY_RETURN:
204 : : case KEY_TAB:
205 : : {
206 [ # # ]: 0 : if ( KEY_TAB == nCode )
207 : 0 : m_bRelease = sal_False;
208 : : else
209 : 0 : nHandled = 1;
210 : 0 : Select();
211 : 0 : break;
212 : : }
213 : :
214 : : case KEY_ESCAPE:
215 : 0 : SetText( m_aCurText );
216 : 0 : ReleaseFocus_Impl();
217 : 0 : nHandled = 1;
218 : 0 : break;
219 : : }
220 : : }
221 [ # # ]: 0 : else if( EVENT_LOSEFOCUS == rNEvt.GetType() )
222 : : {
223 : 0 : Window* pFocusWin = Application::GetFocusWindow();
224 [ # # ][ # # ]: 0 : if(!HasFocus() && GetSubEdit() != pFocusWin)
[ # # ]
225 : 0 : SetText(GetSavedValue());
226 : : }
227 : :
228 [ # # ]: 0 : return nHandled ? nHandled : FontSizeBox::Notify( rNEvt );
229 : : }
230 : :
231 : : // ---------------------------------------------------------------------------
232 : :
233 : 0 : void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
234 : : {
235 [ # # # # ]: 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
[ # # ]
236 : 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
237 : : {
238 [ # # ][ # # ]: 0 : SetSizePixel( LogicToPixel( m_aLogicalSize, MAP_APPFONT ));
[ # # ][ # # ]
239 : 0 : Size aDropSize( m_aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT );
240 [ # # ][ # # ]: 0 : SetDropDownSizePixel( LogicToPixel( aDropSize, MAP_APPFONT ));
[ # # ][ # # ]
241 : : }
242 : :
243 : 0 : FontSizeBox::DataChanged( rDCEvt );
244 : 0 : }
245 : :
246 : : //========================================================================
247 : : // class FontHeightToolBoxControl
248 : : //========================================================================
249 : :
250 : 961 : FontHeightToolBoxControl::FontHeightToolBoxControl(
251 : : const uno::Reference< lang::XMultiServiceFactory >& rServiceManager ) :
252 : : svt::ToolboxController( rServiceManager,
253 : : uno::Reference< frame::XFrame >(),
254 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontHeight" )) ),
255 [ + - ]: 961 : m_pBox( NULL )
256 : : {
257 [ + - ][ + - ]: 961 : addStatusListener( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )));
258 : 961 : }
259 : :
260 : 961 : FontHeightToolBoxControl::~FontHeightToolBoxControl()
261 : : {
262 [ - + ]: 1922 : }
263 : :
264 : : // XInterface
265 : 10527 : ::com::sun::star::uno::Any SAL_CALL FontHeightToolBoxControl::queryInterface( const ::com::sun::star::uno::Type& aType )
266 : : throw (::com::sun::star::uno::RuntimeException)
267 : : {
268 [ + - ]: 10527 : uno::Any a = ToolboxController::queryInterface( aType );
269 [ + + ]: 10527 : if ( a.hasValue() )
270 : 9566 : return a;
271 : :
272 [ + - ]: 10527 : return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
273 : : }
274 : :
275 : 41558 : void SAL_CALL FontHeightToolBoxControl::acquire() throw ()
276 : : {
277 : 41558 : ToolboxController::acquire();
278 : 41558 : }
279 : :
280 : 41558 : void SAL_CALL FontHeightToolBoxControl::release() throw ()
281 : : {
282 : 41558 : ToolboxController::release();
283 : 41558 : }
284 : :
285 : : // XServiceInfo
286 : 0 : sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService( const ::rtl::OUString& ServiceName )
287 : : throw(uno::RuntimeException)
288 : : {
289 [ # # ]: 0 : const uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
290 : 0 : const ::rtl::OUString * pArray = aSNL.getConstArray();
291 : :
292 [ # # ]: 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
293 [ # # ]: 0 : if( pArray[i] == ServiceName )
294 : 0 : return true;
295 : :
296 [ # # ]: 0 : return false;
297 : : }
298 : :
299 : 0 : ::rtl::OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
300 : : throw( uno::RuntimeException )
301 : : {
302 : 0 : return getImplementationName_Static();
303 : : }
304 : :
305 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
306 : : throw( uno::RuntimeException )
307 : : {
308 : 0 : return getSupportedServiceNames_Static();
309 : : }
310 : :
311 : 52 : uno::Sequence< ::rtl::OUString > FontHeightToolBoxControl::getSupportedServiceNames_Static()
312 : : throw()
313 : : {
314 : 52 : uno::Sequence< ::rtl::OUString > aSNS( 1 );
315 [ + - ][ + - ]: 52 : aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ));
316 : 52 : return aSNS;
317 : : }
318 : :
319 : : // XComponent
320 : 961 : void SAL_CALL FontHeightToolBoxControl::dispose()
321 : : throw (uno::RuntimeException)
322 : : {
323 [ + - ]: 961 : svt::ToolboxController::dispose();
324 : :
325 [ + - ]: 961 : SolarMutexGuard aSolarMutexGuard;
326 [ + - ][ + - ]: 961 : delete m_pBox;
327 [ + - ]: 961 : m_pBox = 0;
328 : 961 : }
329 : :
330 : : // XStatusListener
331 : 2963 : void SAL_CALL FontHeightToolBoxControl::statusChanged(
332 : : const frame::FeatureStateEvent& rEvent )
333 : : throw ( uno::RuntimeException )
334 : : {
335 [ + - ]: 2963 : if ( m_pBox )
336 : : {
337 [ + - ]: 2963 : SolarMutexGuard aSolarMutexGuard;
338 [ + + ]: 2963 : if ( rEvent.FeatureURL.Path == "FontHeight" )
339 : : {
340 [ + - ]: 1482 : if ( rEvent.IsEnabled )
341 : : {
342 [ + - ]: 1482 : m_pBox->Enable();
343 : 1482 : frame::status::FontHeight aFontHeight;
344 [ + - ][ + - ]: 1482 : if ( rEvent.State >>= aFontHeight )
345 [ + - ]: 1482 : m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false );
346 : : else
347 [ # # ]: 1482 : m_pBox->statusChanged_Impl( long( -1 ), true );
348 : : }
349 : : else
350 [ # # ]: 0 : m_pBox->Disable();
351 : : }
352 [ + - ]: 1481 : else if ( rEvent.FeatureURL.Path == "CharFontName" )
353 : : {
354 [ + - ][ + - ]: 1481 : if ( rEvent.State >>= m_aCurrentFont )
355 [ + - ]: 1481 : m_pBox->UpdateFont( m_aCurrentFont );
356 [ + - ]: 2963 : }
357 : : }
358 : 2963 : }
359 : :
360 : : // XToolbarController
361 : 0 : void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
362 : : throw (::com::sun::star::uno::RuntimeException)
363 : : {
364 : 0 : }
365 : :
366 : 0 : void SAL_CALL FontHeightToolBoxControl::click()
367 : : throw (::com::sun::star::uno::RuntimeException)
368 : : {
369 : 0 : }
370 : :
371 : 0 : void SAL_CALL FontHeightToolBoxControl::doubleClick()
372 : : throw (::com::sun::star::uno::RuntimeException)
373 : : {
374 : 0 : }
375 : :
376 : 0 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
377 : : throw (::com::sun::star::uno::RuntimeException)
378 : : {
379 : 0 : return uno::Reference< awt::XWindow >();
380 : : }
381 : :
382 : 961 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
383 : : const uno::Reference< awt::XWindow >& Parent )
384 : : throw (::com::sun::star::uno::RuntimeException)
385 : : {
386 : 961 : uno::Reference< awt::XWindow > xItemWindow;
387 : 961 : uno::Reference< awt::XWindow > xParent( Parent );
388 : :
389 [ + - ]: 961 : Window* pParent = VCLUnoHelper::GetWindow( xParent );
390 [ + - ]: 961 : if ( pParent )
391 : : {
392 [ + - ]: 961 : SolarMutexGuard aSolarMutexGuard;
393 : : m_pBox = new SvxFontSizeBox_Impl(
394 : : pParent,
395 : : uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ),
396 : : m_xFrame,
397 [ + - ][ + - ]: 961 : *this );
[ + - ]
398 [ + - ][ + - ]: 961 : xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
[ + - ]
399 : : }
400 : :
401 : 961 : return xItemWindow;
402 : : }
403 : :
404 : 0 : void FontHeightToolBoxControl::dispatchCommand(
405 : : const uno::Sequence< beans::PropertyValue >& rArgs )
406 : : {
407 [ # # ]: 0 : uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
408 [ # # ]: 0 : if ( xDispatchProvider.is() )
409 : : {
410 : 0 : util::URL aURL;
411 : 0 : uno::Reference< frame::XDispatch > xDispatch;
412 [ # # ]: 0 : uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
413 : :
414 [ # # ]: 0 : aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontHeight" ));
415 [ # # ][ # # ]: 0 : xURLTransformer->parseStrict( aURL );
416 [ # # ][ # # ]: 0 : xDispatch = xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
[ # # ]
417 [ # # ]: 0 : if ( xDispatch.is() )
418 [ # # ][ # # ]: 0 : xDispatch->dispatch( aURL, rArgs );
419 : 0 : }
420 : 0 : }
421 : :
422 : 961 : uno::Reference< uno::XInterface > SAL_CALL FontHeightToolBoxControl_createInstance(
423 : : const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
424 : : {
425 [ + - ]: 961 : return *new FontHeightToolBoxControl( rSMgr );
426 : : }
427 : :
428 : : }
429 : :
430 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|