LCOV - code coverage report
Current view: top level - svtools/source/uno - popupwindowcontroller.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 93 0.0 %
Date: 2014-04-14 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             : #include <cppuhelper/supportsservice.hxx>
      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           0 : PopupWindowControllerImpl::PopupWindowControllerImpl()
      54             : : mpPopupWindow( 0 )
      55           0 : , mpToolBox( 0 )
      56             : {
      57           0 : }
      58             : 
      59           0 : PopupWindowControllerImpl::~PopupWindowControllerImpl()
      60             : {
      61           0 :     if( mpPopupWindow )
      62           0 :         SetPopupWindow(0,0);
      63           0 : }
      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           0 : PopupWindowController::PopupWindowController( const Reference< uno::XComponentContext >& rxContext,
     137             :                                               const Reference< frame::XFrame >& xFrame,
     138             :                                               const OUString& aCommandURL )
     139             : : svt::ToolboxController( rxContext, xFrame, aCommandURL )
     140           0 : , mpImpl( new PopupWindowControllerImpl() )
     141             : {
     142           0 : }
     143             : 
     144           0 : PopupWindowController::~PopupWindowController()
     145             : {
     146           0 : }
     147             : 
     148             : // XInterface
     149           0 : Any SAL_CALL PopupWindowController::queryInterface( const Type& aType )
     150             : throw (RuntimeException, std::exception)
     151             : {
     152           0 :     Any a( ToolboxController::queryInterface( aType ) );
     153           0 :     if ( a.hasValue() )
     154           0 :         return a;
     155             : 
     156           0 :     return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
     157             : }
     158             : 
     159           0 : void SAL_CALL PopupWindowController::acquire() throw ()
     160             : {
     161           0 :     ToolboxController::acquire();
     162           0 : }
     163             : 
     164           0 : void SAL_CALL PopupWindowController::release() throw ()
     165             : {
     166           0 :     ToolboxController::release();
     167           0 : }
     168             : 
     169             : // XServiceInfo
     170           0 : sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
     171             : {
     172           0 :     return cppu::supportsService(this, ServiceName);
     173             : }
     174             : 
     175             : // XInitialization
     176           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, std::exception)
     177             : {
     178           0 :     svt::ToolboxController::initialize( aArguments );
     179           0 :     if( !m_aCommandURL.isEmpty() )
     180           0 :         addStatusListener( m_aCommandURL );
     181           0 : }
     182             : 
     183             : // XComponent
     184           0 : void SAL_CALL PopupWindowController::dispose() throw (RuntimeException, std::exception)
     185             : {
     186           0 :     if( !m_aCommandURL.isEmpty() )
     187           0 :         removeStatusListener( m_aCommandURL );
     188             : 
     189           0 :     svt::ToolboxController::dispose();
     190           0 : }
     191             : 
     192             : 
     193             : // XStatusListener
     194           0 : void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException, std::exception )
     195             : {
     196           0 :     svt::ToolboxController::statusChanged(rEvent);
     197           0 :     enable( rEvent.IsEnabled );
     198           0 : }
     199             : 
     200             : // XToolbarController
     201           0 : void SAL_CALL PopupWindowController::execute( sal_Int16 KeyModifier ) throw (RuntimeException, std::exception)
     202             : {
     203           0 :     svt::ToolboxController::execute( KeyModifier );
     204           0 : }
     205             : 
     206           0 : void SAL_CALL PopupWindowController::click() throw (RuntimeException, std::exception)
     207             : {
     208           0 :     svt::ToolboxController::click();
     209           0 : }
     210             : 
     211           0 : void SAL_CALL PopupWindowController::doubleClick() throw (RuntimeException, std::exception)
     212             : {
     213           0 :     svt::ToolboxController::doubleClick();
     214           0 : }
     215             : 
     216           0 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createPopupWindow() throw (RuntimeException, std::exception)
     217             : {
     218           0 :     ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     219           0 :     if( pToolBox )
     220             :     {
     221           0 :         ::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
     222           0 :         ::Window* pWin = createPopupWindow( pItemWindow ? pItemWindow : pToolBox );
     223           0 :         if( pWin )
     224             :         {
     225           0 :                pWin->EnableDocking(true);
     226           0 :             mpImpl->SetPopupWindow(pWin,pToolBox);
     227             :             ::Window::GetDockingManager()->StartPopupMode( pToolBox, pWin,
     228             :                                                            FLOATWIN_POPUPMODE_GRABFOCUS |
     229             :                                                            FLOATWIN_POPUPMODE_NOFOCUSCLOSE |
     230             :                                                            FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE |
     231           0 :                                                            FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE );
     232             :         }
     233             :     }
     234           0 :     return Reference< awt::XWindow >();
     235             : }
     236             : 
     237           0 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )
     238             :     throw (RuntimeException, std::exception)
     239             : {
     240           0 :     return Reference< awt::XWindow >();
     241             : }
     242             : 
     243             : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10