LCOV - code coverage report
Current view: top level - svtools/source/uno - popupwindowcontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 38 91 41.8 %
Date: 2015-06-13 12:38:46 Functions: 11 20 55.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 <cppuhelper/queryinterface.hxx>
      22             : #include <toolkit/helper/vclunohelper.hxx>
      23             : 
      24             : #include <vcl/toolbox.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : 
      27             : #include <svtools/popupwindowcontroller.hxx>
      28             : #include <svtools/toolbarmenu.hxx>
      29             : 
      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( vcl::Window* pPopupWindow, ToolBox* pToolBox );
      45             :     DECL_LINK( WindowEventListener, VclSimpleEvent* );
      46             : 
      47             : private:
      48             :     VclPtr<vcl::Window> mpPopupWindow;
      49             :     VclPtr<ToolBox>     mpToolBox;
      50             : };
      51             : 
      52        1393 : PopupWindowControllerImpl::PopupWindowControllerImpl()
      53             : : mpPopupWindow( 0 )
      54        1393 : , mpToolBox( 0 )
      55             : {
      56        1393 : }
      57             : 
      58        2786 : PopupWindowControllerImpl::~PopupWindowControllerImpl()
      59             : {
      60        1393 :     if( mpPopupWindow )
      61           0 :         SetPopupWindow(0,0);
      62        1393 : }
      63             : 
      64           0 : void PopupWindowControllerImpl::SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox )
      65             : {
      66           0 :     if( mpPopupWindow )
      67             :     {
      68           0 :         mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
      69           0 :         mpPopupWindow.disposeAndClear();
      70             :     }
      71           0 :     mpPopupWindow = pPopupWindow;
      72           0 :     mpToolBox = pToolBox;
      73             : 
      74           0 :     if( mpPopupWindow )
      75             :     {
      76           0 :         mpPopupWindow->AddEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ));
      77             :     }
      78           0 : }
      79             : 
      80           0 : IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclSimpleEvent*, pEvent )
      81             : {
      82           0 :     VclWindowEvent* pWindowEvent = dynamic_cast< VclWindowEvent* >( pEvent );
      83           0 :     if( pWindowEvent )
      84             :     {
      85           0 :         switch( pWindowEvent->GetId() )
      86             :         {
      87             :         case VCLEVENT_WINDOW_CLOSE:
      88             :         case VCLEVENT_WINDOW_ENDPOPUPMODE:
      89           0 :             SetPopupWindow(0,0);
      90           0 :             break;
      91             : 
      92             :         case VCLEVENT_WINDOW_SHOW:
      93             :         {
      94           0 :             if( mpPopupWindow )
      95             :             {
      96           0 :                 if( mpToolBox )
      97           0 :                     mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_OPEN, static_cast<void*>(mpPopupWindow) );
      98           0 :                 mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_GETFOCUS, 0 );
      99             : 
     100           0 :                 svtools::ToolbarMenu* pToolbarMenu = dynamic_cast< svtools::ToolbarMenu* >( mpPopupWindow.get() );
     101           0 :                 if( pToolbarMenu )
     102           0 :                     pToolbarMenu->highlightFirstEntry();
     103           0 :                 break;
     104             :             }
     105           0 :             break;
     106             :         }
     107             :         case VCLEVENT_WINDOW_HIDE:
     108             :         {
     109           0 :             if( mpPopupWindow )
     110             :             {
     111           0 :                 mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS, 0 );
     112           0 :                 if( mpToolBox )
     113           0 :                     mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE, static_cast<void*>(mpPopupWindow) );
     114             :             }
     115           0 :             break;
     116             :         }
     117             :         }
     118             :     }
     119           0 :     return 1;
     120             : }
     121             : 
     122             : 
     123             : // class PopupWindowController
     124             : 
     125             : 
     126        1393 : PopupWindowController::PopupWindowController( const Reference< uno::XComponentContext >& rxContext,
     127             :                                               const Reference< frame::XFrame >& xFrame,
     128             :                                               const OUString& aCommandURL )
     129             : : svt::ToolboxController( rxContext, xFrame, aCommandURL )
     130        1393 : , mxImpl( new PopupWindowControllerImpl() )
     131             : {
     132        1393 : }
     133             : 
     134        1393 : PopupWindowController::~PopupWindowController()
     135             : {
     136        1393 : }
     137             : 
     138             : // XInterface
     139       14592 : Any SAL_CALL PopupWindowController::queryInterface( const Type& aType )
     140             : throw (RuntimeException, std::exception)
     141             : {
     142       14592 :     Any a( ToolboxController::queryInterface( aType ) );
     143       14592 :     if ( a.hasValue() )
     144       13875 :         return a;
     145             : 
     146         717 :     return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
     147             : }
     148             : 
     149       52666 : void SAL_CALL PopupWindowController::acquire() throw ()
     150             : {
     151       52666 :     ToolboxController::acquire();
     152       52666 : }
     153             : 
     154       52666 : void SAL_CALL PopupWindowController::release() throw ()
     155             : {
     156       52666 :     ToolboxController::release();
     157       52666 : }
     158             : 
     159             : // XServiceInfo
     160           0 : sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
     161             : {
     162           0 :     return cppu::supportsService(this, ServiceName);
     163             : }
     164             : 
     165             : // XInitialization
     166        2060 : 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)
     167             : {
     168        2060 :     svt::ToolboxController::initialize( aArguments );
     169        2060 :     if( !m_aCommandURL.isEmpty() )
     170        2060 :         addStatusListener( m_aCommandURL );
     171        2060 : }
     172             : 
     173             : // XComponent
     174        1393 : void SAL_CALL PopupWindowController::dispose() throw (RuntimeException, std::exception)
     175             : {
     176        1393 :     if( !m_aCommandURL.isEmpty() )
     177        1392 :         removeStatusListener( m_aCommandURL );
     178             : 
     179        1393 :     svt::ToolboxController::dispose();
     180        1393 : }
     181             : 
     182             : 
     183             : // XStatusListener
     184          24 : void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException, std::exception )
     185             : {
     186          24 :     svt::ToolboxController::statusChanged(rEvent);
     187          24 :     enable( rEvent.IsEnabled );
     188          24 : }
     189             : 
     190             : // XToolbarController
     191           0 : void SAL_CALL PopupWindowController::execute( sal_Int16 KeyModifier ) throw (RuntimeException, std::exception)
     192             : {
     193           0 :     svt::ToolboxController::execute( KeyModifier );
     194           0 : }
     195             : 
     196           0 : void SAL_CALL PopupWindowController::click() throw (RuntimeException, std::exception)
     197             : {
     198           0 :     svt::ToolboxController::click();
     199           0 : }
     200             : 
     201           0 : void SAL_CALL PopupWindowController::doubleClick() throw (RuntimeException, std::exception)
     202             : {
     203           0 :     svt::ToolboxController::doubleClick();
     204           0 : }
     205             : 
     206           0 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createPopupWindow() throw (RuntimeException, std::exception)
     207             : {
     208           0 :     VclPtr< ToolBox > pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
     209           0 :     if( pToolBox )
     210             :     {
     211           0 :         vcl::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
     212           0 :         vcl::Window* pWin = createPopupWindow( pItemWindow ? pItemWindow : pToolBox );
     213           0 :         if( pWin )
     214             :         {
     215           0 :             pWin->EnableDocking(true);
     216           0 :             mxImpl->SetPopupWindow(pWin,pToolBox);
     217             :             vcl::Window::GetDockingManager()->StartPopupMode( pToolBox, pWin,
     218             :                                                            FloatWinPopupFlags::GrabFocus |
     219             :                                                            FloatWinPopupFlags::NoFocusClose |
     220           0 :                                                            FloatWinPopupFlags::AllMouseButtonClose |
     221           0 :                                                            FloatWinPopupFlags::NoMouseUpClose );
     222             :         }
     223             :     }
     224           0 :     return Reference< awt::XWindow >();
     225             : }
     226             : 
     227        1384 : Reference< awt::XWindow > SAL_CALL PopupWindowController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )
     228             :     throw (RuntimeException, std::exception)
     229             : {
     230        1384 :     return Reference< awt::XWindow >();
     231             : }
     232             : 
     233             : }
     234             : 
     235             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11