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

Generated by: LCOV version 1.10