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

Generated by: LCOV version 1.10