LCOV - code coverage report
Current view: top level - svtools/source/uno - popupwindowcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 98 38.8 %
Date: 2012-08-25 Functions: 11 21 52.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 68 14.7 %

           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 <toolkit/helper/vclunohelper.hxx>
      31                 :            : 
      32                 :            : #include <vcl/toolbox.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : 
      35                 :            : #include "svtools/popupwindowcontroller.hxx"
      36                 :            : #include "svtools/toolbarmenu.hxx"
      37                 :            : 
      38                 :            : using rtl::OUString;
      39                 :            : using namespace ::com::sun::star;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::lang;
      42                 :            : 
      43                 :            : 
      44                 :            : namespace svt
      45                 :            : {
      46                 :            : 
      47                 :            : class PopupWindowControllerImpl
      48                 :            : {
      49                 :            : public:
      50                 :            :     PopupWindowControllerImpl();
      51                 :            :     ~PopupWindowControllerImpl();
      52                 :            : 
      53                 :            :     void SetPopupWindow( ::Window* pPopupWindow, ToolBox* pToolBox );
      54                 :            : 
      55                 :            :     DECL_LINK( WindowEventListener, VclSimpleEvent* );
      56                 :            :     DECL_STATIC_LINK( PopupWindowControllerImpl, AsyncDeleteWindowHdl, Window* );
      57                 :            : 
      58                 :            : private:
      59                 :            :     ::Window* mpPopupWindow;
      60                 :            :     ToolBox* mpToolBox;
      61                 :            : };
      62                 :            : 
      63                 :         52 : PopupWindowControllerImpl::PopupWindowControllerImpl()
      64                 :            : : mpPopupWindow( 0 )
      65                 :         52 : , mpToolBox( 0 )
      66                 :            : {
      67                 :         52 : }
      68                 :            : 
      69                 :         52 : PopupWindowControllerImpl::~PopupWindowControllerImpl()
      70                 :            : {
      71         [ -  + ]:         52 :     if( mpPopupWindow )
      72                 :          0 :         SetPopupWindow(0,0);
      73                 :         52 : }
      74                 :            : 
      75                 :          0 : void PopupWindowControllerImpl::SetPopupWindow( ::Window* pPopupWindow, ToolBox* pToolBox )
      76                 :            : {
      77         [ #  # ]:          0 :     if( mpPopupWindow )
      78                 :            :     {
      79         [ #  # ]:          0 :         mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
      80         [ #  # ]:          0 :         Application::PostUserEvent( STATIC_LINK( this, PopupWindowControllerImpl, AsyncDeleteWindowHdl ), mpPopupWindow );
      81                 :            :     }
      82                 :          0 :     mpPopupWindow = pPopupWindow;
      83                 :          0 :     mpToolBox = pToolBox;
      84                 :            : 
      85         [ #  # ]:          0 :     if( mpPopupWindow )
      86                 :            :     {
      87         [ #  # ]:          0 :         mpPopupWindow->AddEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ));
      88                 :            :     }
      89                 :          0 : }
      90                 :            : 
      91                 :          0 : IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclSimpleEvent*, pEvent )
      92                 :            : {
      93         [ #  # ]:          0 :     VclWindowEvent* pWindowEvent = dynamic_cast< VclWindowEvent* >( pEvent );
      94         [ #  # ]:          0 :     if( pWindowEvent )
      95                 :            :     {
      96   [ #  #  #  # ]:          0 :         switch( pWindowEvent->GetId() )
      97                 :            :         {
      98                 :            :         case VCLEVENT_WINDOW_CLOSE:
      99                 :            :         case VCLEVENT_WINDOW_ENDPOPUPMODE:
     100                 :          0 :             SetPopupWindow(0,0);
     101                 :          0 :             break;
     102                 :            : 
     103                 :            :         case VCLEVENT_WINDOW_SHOW:
     104                 :            :         {
     105         [ #  # ]:          0 :             if( mpPopupWindow )
     106                 :            :             {
     107         [ #  # ]:          0 :                 if( mpToolBox )
     108                 :          0 :                     mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_OPEN, (void*)mpPopupWindow );
     109                 :          0 :                 mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_GETFOCUS, 0 );
     110                 :            : 
     111         [ #  # ]:          0 :                 svtools::ToolbarMenu* pToolbarMenu = dynamic_cast< svtools::ToolbarMenu* >( mpPopupWindow );
     112         [ #  # ]:          0 :                 if( pToolbarMenu )
     113                 :          0 :                     pToolbarMenu->highlightFirstEntry();
     114                 :          0 :                 break;
     115                 :            :             }
     116                 :          0 :             break;
     117                 :            :         }
     118                 :            :         case VCLEVENT_WINDOW_HIDE:
     119                 :            :         {
     120         [ #  # ]:          0 :             if( mpPopupWindow )
     121                 :            :             {
     122                 :          0 :                 mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS, 0 );
     123         [ #  # ]:          0 :                 if( mpToolBox )
     124                 :          0 :                     mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE, (void*)mpPopupWindow );
     125                 :            :             }
     126                 :          0 :             break;
     127                 :            :         }
     128                 :            :         }
     129                 :            :     }
     130                 :          0 :     return 1;
     131                 :            : }
     132                 :            : 
     133                 :            : //--------------------------------------------------------------------
     134                 :            : 
     135                 :          0 : IMPL_STATIC_LINK( PopupWindowControllerImpl, AsyncDeleteWindowHdl, Window*, pWindow )
     136                 :            : {
     137                 :            :     (void)*pThis;
     138         [ #  # ]:          0 :     delete pWindow;
     139                 :          0 :     return 0;
     140                 :            : }
     141                 :            : 
     142                 :            : //========================================================================
     143                 :            : // class PopupWindowController
     144                 :            : //========================================================================
     145                 :            : 
     146                 :         52 : PopupWindowController::PopupWindowController( const Reference< lang::XMultiServiceFactory >& rServiceManager,
     147                 :            :                                               const Reference< frame::XFrame >& xFrame,
     148                 :            :                                               const OUString& aCommandURL )
     149                 :            : : svt::ToolboxController( rServiceManager, xFrame, aCommandURL )
     150         [ +  - ]:         52 : , mpImpl( new PopupWindowControllerImpl() )
     151                 :            : {
     152                 :         52 : }
     153                 :            : 
     154         [ +  - ]:         52 : PopupWindowController::~PopupWindowController()
     155                 :            : {
     156         [ -  + ]:         52 : }
     157                 :            : 
     158                 :            : // XInterface
     159                 :        588 : Any SAL_CALL PopupWindowController::queryInterface( const Type& aType )
     160                 :            : throw (RuntimeException)
     161                 :            : {
     162         [ +  - ]:        588 :     Any a( ToolboxController::queryInterface( aType ) );
     163         [ +  + ]:        588 :     if ( a.hasValue() )
     164                 :        536 :         return a;
     165                 :            : 
     166         [ +  - ]:        588 :     return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
     167                 :            : }
     168                 :            : 
     169                 :       1980 : void SAL_CALL PopupWindowController::acquire() throw ()
     170                 :            : {
     171                 :       1980 :     ToolboxController::acquire();
     172                 :       1980 : }
     173                 :            : 
     174                 :       1980 : void SAL_CALL PopupWindowController::release() throw ()
     175                 :            : {
     176                 :       1980 :     ToolboxController::release();
     177                 :       1980 : }
     178                 :            : 
     179                 :            : // XServiceInfo
     180                 :          0 : sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName ) throw(RuntimeException)
     181                 :            : {
     182         [ #  # ]:          0 :     const Sequence< OUString > aSNL( getSupportedServiceNames() );
     183                 :          0 :     const OUString * pArray = aSNL.getConstArray();
     184                 :            : 
     185         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     186         [ #  # ]:          0 :         if( pArray[i] == ServiceName )
     187                 :          0 :             return true;
     188                 :            : 
     189         [ #  # ]:          0 :     return false;
     190                 :            : }
     191                 :            : 
     192                 :            : // XInitialization
     193                 :         52 : void SAL_CALL PopupWindowController::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
     194                 :            : {
     195                 :         52 :     svt::ToolboxController::initialize( aArguments );
     196         [ +  - ]:         52 :     if( !m_aCommandURL.isEmpty() )
     197                 :         52 :         addStatusListener( m_aCommandURL );
     198                 :         52 : }
     199                 :            : 
     200                 :            : // XComponent
     201                 :         52 : void SAL_CALL PopupWindowController::dispose() throw (RuntimeException)
     202                 :            : {
     203         [ +  - ]:         52 :     if( !m_aCommandURL.isEmpty() )
     204                 :         52 :         removeStatusListener( m_aCommandURL );
     205                 :            : 
     206                 :         52 :     svt::ToolboxController::dispose();
     207                 :         52 : }
     208                 :            : 
     209                 :            : 
     210                 :            : // XStatusListener
     211                 :         44 : void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
     212                 :            : {
     213                 :         44 :     svt::ToolboxController::statusChanged(rEvent);
     214                 :         44 :     enable( rEvent.IsEnabled );
     215                 :         44 : }
     216                 :            : 
     217                 :            : // XToolbarController
     218                 :          0 : void SAL_CALL PopupWindowController::execute( sal_Int16 KeyModifier ) throw (RuntimeException)
     219                 :            : {
     220                 :          0 :     svt::ToolboxController::execute( KeyModifier );
     221                 :          0 : }
     222                 :            : 
     223                 :          0 : void SAL_CALL PopupWindowController::click() throw (RuntimeException)
     224                 :            : {
     225                 :          0 :     svt::ToolboxController::click();
     226                 :          0 : }
     227                 :            : 
     228                 :          0 : void SAL_CALL PopupWindowController::doubleClick() throw (RuntimeException)
     229                 :            : {
     230                 :          0 :     svt::ToolboxController::doubleClick();
     231                 :          0 : }
     232                 :            : 
     233                 :          0 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createPopupWindow() throw (RuntimeException)
     234                 :            : {
     235 [ #  # ][ #  # ]:          0 :     ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     236         [ #  # ]:          0 :     if( pToolBox )
     237                 :            :     {
     238                 :          0 :         ::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
     239         [ #  # ]:          0 :         ::Window* pWin = createPopupWindow( pItemWindow ? pItemWindow : pToolBox );
     240         [ #  # ]:          0 :         if( pWin )
     241                 :            :         {
     242                 :          0 :                pWin->EnableDocking(true);
     243                 :          0 :             mpImpl->SetPopupWindow(pWin,pToolBox);
     244                 :          0 :             ::Window::GetDockingManager()->StartPopupMode( pToolBox, pWin, FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE |FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE );
     245                 :            :         }
     246                 :            :     }
     247                 :          0 :     return Reference< awt::XWindow >();
     248                 :            : }
     249                 :            : 
     250                 :         52 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )
     251                 :            :     throw (RuntimeException)
     252                 :            : {
     253                 :         52 :     return Reference< awt::XWindow >();
     254                 :            : }
     255                 :            : 
     256                 :            : }
     257                 :            : 
     258                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10