LCOV - code coverage report
Current view: top level - svx/source/tbxctrls - tbunocontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 95 159 59.7 %
Date: 2015-06-13 12:38:46 Functions: 19 30 63.3 %
Legend: Lines: hit not hit

          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             : #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>
      25             : 
      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>
      38             : 
      39             : #include <boost/scoped_ptr.hpp>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : 
      43             : namespace {
      44             : 
      45             : class SvxFontSizeBox_Impl;
      46             : class FontHeightToolBoxControl : public svt::ToolboxController,
      47             :                                  public lang::XServiceInfo
      48             : {
      49             :     public:
      50             :         explicit FontHeightToolBoxControl(
      51             :             const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rServiceManager );
      52             :         virtual ~FontHeightToolBoxControl();
      53             : 
      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;
      58             : 
      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;
      63             : 
      64             :         // XComponent
      65             :         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             : 
      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;
      69             : 
      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;
      76             : 
      77             :         void dispatchCommand( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
      78             :         using svt::ToolboxController::dispatchCommand;
      79             : 
      80             :     private:
      81             :         VclPtr<SvxFontSizeBox_Impl>           m_pBox;
      82             :         ::com::sun::star::awt::FontDescriptor m_aCurrentFont;
      83             : };
      84             : 
      85           0 : class SvxFontSizeBox_Impl : public FontSizeBox
      86             : {
      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 );
      92             : 
      93             :     void                statusChanged_Impl( long nHeight, bool bErase = false );
      94             :     void                UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont );
      95             :     void                SetOptimalSize();
      96             : 
      97             :     virtual bool        Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
      98             : 
      99             : protected:
     100             :     virtual void        Select() SAL_OVERRIDE;
     101             :     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     102             : 
     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;
     111             : 
     112             :     void                ReleaseFocus_Impl();
     113             : };
     114             : 
     115         986 : 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 ) :
     120             : 
     121             :     FontSizeBox( _pParent, WinBits( WB_DROPDOWN ) ),
     122             : 
     123             :     m_pCtrl             ( &_rCtrl ),
     124             :     m_aLogicalSize      ( 0,100 ),
     125             :     m_bRelease          ( true ),
     126             :     m_xDispatchProvider ( _rDispatchProvider ),
     127         986 :     m_xFrame            ( _xFrame )
     128             : {
     129         986 :     SetValue( 0 );
     130         986 :     SetText( "" );
     131         986 : }
     132             : 
     133           0 : void SvxFontSizeBox_Impl::ReleaseFocus_Impl()
     134             : {
     135           0 :     if ( !m_bRelease )
     136             :     {
     137           0 :         m_bRelease = true;
     138           0 :         return;
     139             :     }
     140             : 
     141           0 :     if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
     142           0 :         m_xFrame->getContainerWindow()->setFocus();
     143             : }
     144             : 
     145             : 
     146             : 
     147           0 : void SvxFontSizeBox_Impl::Select()
     148             : {
     149           0 :     FontSizeBox::Select();
     150             : 
     151           0 :     if ( !IsTravelSelect() )
     152             :     {
     153           0 :         sal_Int64 nSelVal = GetValue();
     154           0 :         float fSelVal     = float( nSelVal ) / 10;
     155             : 
     156           0 :         uno::Sequence< beans::PropertyValue > aArgs( 1 );
     157           0 :         aArgs[0].Name  = "FontHeight.Height";
     158           0 :         aArgs[0].Value = uno::makeAny( fSelVal );
     159             : 
     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           0 :         ReleaseFocus_Impl();
     164             : 
     165           0 :         m_pCtrl->dispatchCommand( aArgs );
     166             :     }
     167           0 : }
     168             : 
     169             : 
     170             : 
     171        1679 : void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase )
     172             : {
     173        1679 :     if ( !bErase )
     174             :     {
     175             :         // Metric Umrechnen
     176        1679 :         long nVal = nPoint;
     177             : 
     178             :         // ge"andert => neuen Wert setzen
     179        1679 :         if ( GetValue() != nVal )
     180         991 :             SetValue( nVal );
     181             :     }
     182             :     else
     183             :     {
     184             :         // Wert in der Anzeige l"oschen
     185           0 :         SetValue( -1L );
     186           0 :         SetText( "" );
     187             :     }
     188        1679 :     SaveValue();
     189        1679 : }
     190             : 
     191             : 
     192             : 
     193        2659 : void SvxFontSizeBox_Impl::UpdateFont( const ::com::sun::star::awt::FontDescriptor& rCurrentFont )
     194             : {
     195             :     // Sizes-Liste auff"ullen
     196        2659 :     sal_Int64 nOldVal = GetValue(); // alten Wert merken
     197        2659 :     const FontList* _pFontList = NULL;
     198        2659 :     boost::scoped_ptr<FontList> aHold( new FontList( this ));
     199        2659 :     _pFontList = aHold.get();
     200             : 
     201        2659 :     if ( !rCurrentFont.Name.isEmpty() )
     202             :     {
     203        1673 :         vcl::FontInfo _aFontInfo;
     204        1673 :         _aFontInfo.SetName( rCurrentFont.Name );
     205        1673 :         _aFontInfo.SetStyleName( rCurrentFont.StyleName );
     206        1673 :         _aFontInfo.SetHeight( rCurrentFont.Height );
     207        1673 :         Fill( &_aFontInfo, _pFontList );
     208             :     }
     209             :     else
     210             :     {
     211         986 :         Fill( NULL, _pFontList );
     212             :     }
     213        2659 :     SetValue( nOldVal ); // alten Wert wiederherstellen
     214        2659 :     m_aCurText = GetText(); // zum R"ucksetzen bei ESC merken
     215        2659 : }
     216             : 
     217             : 
     218             : 
     219        1972 : bool SvxFontSizeBox_Impl::Notify( NotifyEvent& rNEvt )
     220             : {
     221        1972 :     bool nHandled = false;
     222             : 
     223        1972 :     if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
     224             :     {
     225           0 :         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
     226             : 
     227           0 :         switch ( nCode )
     228             :         {
     229             :             case KEY_RETURN:
     230             :             case KEY_TAB:
     231             :             {
     232           0 :                 if ( KEY_TAB == nCode )
     233           0 :                     m_bRelease = false;
     234             :                 else
     235           0 :                     nHandled = true;
     236           0 :                 Select();
     237           0 :                 break;
     238             :             }
     239             : 
     240             :             case KEY_ESCAPE:
     241           0 :                 SetText( m_aCurText );
     242           0 :                 ReleaseFocus_Impl();
     243           0 :                 nHandled = true;
     244           0 :                 break;
     245             :         }
     246             :     }
     247        1972 :     else if( MouseNotifyEvent::LOSEFOCUS == rNEvt.GetType() )
     248             :     {
     249           0 :         vcl::Window* pFocusWin = Application::GetFocusWindow();
     250           0 :         if(!HasFocus() && GetSubEdit() != pFocusWin)
     251           0 :             SetText(GetSavedValue());
     252             :     }
     253             : 
     254        1972 :     return nHandled || FontSizeBox::Notify( rNEvt );
     255             : }
     256             : 
     257         986 : void SvxFontSizeBox_Impl::SetOptimalSize()
     258             : {
     259         986 :     Size aPrefSize(LogicToPixel(m_aLogicalSize, MAP_APPFONT));
     260         986 :     aPrefSize.Width() = get_preferred_size().Width();
     261         986 :     SetSizePixel(aPrefSize);
     262         986 : }
     263             : 
     264           0 : void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
     265             : {
     266           0 :     if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
     267           0 :          (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
     268             :     {
     269           0 :         SetOptimalSize();
     270             :     }
     271             : 
     272           0 :     FontSizeBox::DataChanged( rDCEvt );
     273           0 : }
     274             : 
     275         987 : FontHeightToolBoxControl::FontHeightToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
     276             :  : svt::ToolboxController( rxContext,
     277             :                            uno::Reference< frame::XFrame >(),
     278             :                            OUString( ".uno:FontHeight" ) ),
     279         987 :    m_pBox( NULL )
     280             : {
     281         987 :     addStatusListener( OUString( ".uno:CharFontName" ));
     282         987 : }
     283             : 
     284        1974 : FontHeightToolBoxControl::~FontHeightToolBoxControl()
     285             : {
     286        1974 : }
     287             : 
     288             : // XInterface
     289        9373 : ::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)
     291             : {
     292        9373 :     uno::Any a = ToolboxController::queryInterface( aType );
     293        9373 :     if ( a.hasValue() )
     294        8875 :         return a;
     295             : 
     296         498 :     return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
     297             : }
     298             : 
     299       36966 : void SAL_CALL FontHeightToolBoxControl::acquire() throw ()
     300             : {
     301       36966 :     ToolboxController::acquire();
     302       36966 : }
     303             : 
     304       36966 : void SAL_CALL FontHeightToolBoxControl::release() throw ()
     305             : {
     306       36966 :     ToolboxController::release();
     307       36966 : }
     308             : 
     309             : // XServiceInfo
     310           0 : sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService( const OUString& ServiceName )
     311             : throw(uno::RuntimeException, std::exception)
     312             : {
     313           0 :     return cppu::supportsService(this, ServiceName);
     314             : }
     315             : 
     316           1 : OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
     317             : throw( uno::RuntimeException, std::exception )
     318             : {
     319           1 :     return OUString("com.sun.star.svx.FontHeightToolBoxController");
     320             : }
     321             : 
     322           1 : uno::Sequence< OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames(  )
     323             : throw( uno::RuntimeException, std::exception )
     324             : {
     325           1 :     uno::Sequence< OUString > aSNS( 1 );
     326           1 :     aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
     327           1 :     return aSNS;
     328             : }
     329             : 
     330             : // XComponent
     331         987 : void SAL_CALL FontHeightToolBoxControl::dispose()
     332             : throw (uno::RuntimeException, std::exception)
     333             : {
     334         987 :     svt::ToolboxController::dispose();
     335             : 
     336         987 :     SolarMutexGuard aSolarMutexGuard;
     337         987 :     m_pBox.disposeAndClear();
     338         987 : }
     339             : 
     340             : // XStatusListener
     341        3362 : void SAL_CALL FontHeightToolBoxControl::statusChanged(
     342             :     const frame::FeatureStateEvent& rEvent )
     343             : throw ( uno::RuntimeException, std::exception )
     344             : {
     345        3362 :     if ( m_pBox )
     346             :     {
     347        3362 :         SolarMutexGuard aSolarMutexGuard;
     348        3362 :         if ( rEvent.FeatureURL.Path == "FontHeight" )
     349             :         {
     350        1684 :             if ( rEvent.IsEnabled )
     351             :             {
     352        1679 :                 m_pBox->Enable();
     353        1679 :                 frame::status::FontHeight aFontHeight;
     354        1679 :                 if ( rEvent.State >>= aFontHeight )
     355        1679 :                     m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false );
     356             :                 else
     357           0 :                     m_pBox->statusChanged_Impl( long( -1 ), true );
     358             :             }
     359             :             else
     360           5 :                 m_pBox->Disable();
     361             :         }
     362        1678 :         else if ( rEvent.FeatureURL.Path == "CharFontName" )
     363             :         {
     364        1678 :             if ( rEvent.State >>= m_aCurrentFont )
     365        1673 :                 m_pBox->UpdateFont( m_aCurrentFont );
     366        3362 :         }
     367             :     }
     368        3362 : }
     369             : 
     370             : // XToolbarController
     371           0 : void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
     372             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     373             : {
     374           0 : }
     375             : 
     376           0 : void SAL_CALL FontHeightToolBoxControl::click()
     377             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     378             : {
     379           0 : }
     380             : 
     381           0 : void SAL_CALL FontHeightToolBoxControl::doubleClick()
     382             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     383             : {
     384           0 : }
     385             : 
     386           0 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
     387             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     388             : {
     389           0 :     return uno::Reference< awt::XWindow >();
     390             : }
     391             : 
     392         986 : uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
     393             :     const uno::Reference< awt::XWindow >& Parent )
     394             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     395             : {
     396         986 :     uno::Reference< awt::XWindow > xItemWindow;
     397        1972 :     uno::Reference< awt::XWindow > xParent( Parent );
     398             : 
     399         986 :     vcl::Window* pParent = VCLUnoHelper::GetWindow( xParent );
     400         986 :     if ( pParent )
     401             :     {
     402         986 :         SolarMutexGuard aSolarMutexGuard;
     403        1972 :         m_pBox = VclPtr<SvxFontSizeBox_Impl>::Create(
     404             : 
     405             :                         pParent,
     406             :                         uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ),
     407             :                         m_xFrame,
     408         986 :                         *this );
     409             :         //Get the box to fill itself with all its sizes
     410         986 :         m_pBox->UpdateFont(m_aCurrentFont);
     411             :         //Make it size itself to its optimal size re above sizes
     412         986 :         m_pBox->SetOptimalSize();
     413         986 :         xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
     414             :     }
     415             : 
     416        1972 :     return xItemWindow;
     417             : }
     418             : 
     419           0 : void FontHeightToolBoxControl::dispatchCommand(
     420             :     const uno::Sequence< beans::PropertyValue >& rArgs )
     421             : {
     422           0 :     uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
     423           0 :     if ( xDispatchProvider.is() )
     424             :     {
     425           0 :         util::URL                               aURL;
     426           0 :         uno::Reference< frame::XDispatch >      xDispatch;
     427           0 :         uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
     428             : 
     429           0 :         aURL.Complete = ".uno:FontHeight";
     430           0 :         xURLTransformer->parseStrict( aURL );
     431           0 :         xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
     432           0 :         if ( xDispatch.is() )
     433           0 :             xDispatch->dispatch( aURL, rArgs );
     434           0 :     }
     435           0 : }
     436             : 
     437             : }
     438             : 
     439             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     440         987 : com_sun_star_svx_FontHeightToolBoxController_get_implementation(
     441             :     css::uno::XComponentContext *rxContext,
     442             :     css::uno::Sequence<css::uno::Any> const &)
     443             : {
     444         987 :     return cppu::acquire(new FontHeightToolBoxControl(rxContext));
     445         390 : }
     446             : 
     447             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11