LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - toolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 131 0.0 %
Date: 2014-04-14 Functions: 0 16 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 "toolboxcontroller.hxx"
      21             : #include <com/sun/star/ui/ImageType.hpp>
      22             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      23             : #include <toolkit/helper/vclunohelper.hxx>
      24             : #include <vcl/menu.hxx>
      25             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      26             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      27             : #include <com/sun/star/ui/XImageManager.hpp>
      28             : #include <com/sun/star/graphic/XGraphic.hpp>
      29             : #include <vcl/svapp.hxx>
      30             : #include <vcl/toolbox.hxx>
      31             : #include "dbu_resource.hrc"
      32             : #include <svtools/miscopt.hxx>
      33             : #include <unotools/moduleoptions.hxx>
      34             : #include <tools/diagnose_ex.h>
      35             : #include <svtools/menuoptions.hxx>
      36             : #include <osl/mutex.hxx>
      37             : #include "dbu_reghelper.hxx"
      38             : #include "UITools.hxx"
      39             : #include <comphelper/processfactory.hxx>
      40             : 
      41           0 : extern "C" void SAL_CALL createRegistryInfo_OToolboxController()
      42             : {
      43           0 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OToolboxController> aAutoRegistration;
      44           0 : }
      45             : 
      46             : namespace dbaui
      47             : {
      48             :     using namespace svt;
      49             :     using namespace ::com::sun::star::graphic;
      50             :     using namespace com::sun::star::uno;
      51             :     using namespace com::sun::star::beans;
      52             :     using namespace com::sun::star::lang;
      53             :     using namespace ::com::sun::star::frame;
      54             :     using namespace ::com::sun::star::util;
      55             :     using namespace ::com::sun::star::ui;
      56             : 
      57             :     namespace
      58             :     {
      59           0 :         void lcl_copy(Menu* _pMenu,sal_uInt16 _nMenuId,sal_uInt16 _nMenuPos,ToolBox* _pToolBox,sal_uInt16 _nToolId,const OUString& _sCommand)
      60             :         {
      61           0 :             if ( _pMenu->GetItemType(_nMenuPos) != MENUITEM_STRING )
      62           0 :                 _pToolBox->SetItemImage(_nToolId, _pMenu->GetItemImage(_nMenuId));
      63           0 :             _pToolBox->SetItemCommand( _nToolId, _sCommand);
      64           0 :             _pToolBox->SetHelpId(_nToolId, _pMenu->GetHelpId(_nMenuId));
      65           0 :             _pToolBox->SetHelpText(_nToolId, _pMenu->GetHelpText(_nMenuId));
      66           0 :             _pToolBox->SetQuickHelpText(_nToolId, _pMenu->GetTipHelpText(_nMenuId));
      67           0 :             _pToolBox->SetItemText(_nToolId, _pMenu->GetItemText(_nMenuId));
      68           0 :         }
      69             :     }
      70             : 
      71           0 :     OToolboxController::OToolboxController(const Reference< XComponentContext >& _rxORB)
      72           0 :         : m_nToolBoxId(1)
      73             :     {
      74           0 :         osl_atomic_increment(&m_refCount);
      75           0 :         m_xContext = _rxORB;
      76           0 :         osl_atomic_decrement(&m_refCount);
      77             : 
      78           0 :     }
      79           0 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(OToolboxController, "com.sun.star.sdb.ApplicationToolboxController")
      80           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(OToolboxController)
      81           0 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(OToolboxController, "com.sun.star.frame.ToolboxController")
      82             : 
      83             :     Reference< XInterface >
      84           0 :         SAL_CALL OToolboxController::Create(const Reference< XMultiServiceFactory >& _rxORB)
      85             :     {
      86           0 :         return static_cast< XServiceInfo* >(new OToolboxController( comphelper::getComponentContext(_rxORB) ));
      87             :     }
      88             : 
      89             :     // XInterface
      90           0 :     Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
      91             :     {
      92           0 :         Any aReturn = ToolboxController::queryInterface(_rType);
      93           0 :         if (!aReturn.hasValue())
      94           0 :             aReturn = TToolboxController_BASE::queryInterface(_rType);
      95           0 :         return aReturn;
      96             :     }
      97           0 :     void SAL_CALL OToolboxController::acquire() throw ()
      98             :     {
      99           0 :         ToolboxController::acquire();
     100           0 :     }
     101           0 :     void SAL_CALL OToolboxController::release() throw ()
     102             :     {
     103           0 :         ToolboxController::release();
     104           0 :     }
     105           0 :     void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException, std::exception)
     106             :     {
     107           0 :         ToolboxController::initialize(_rArguments);
     108           0 :         SolarMutexGuard aSolarMutexGuard;
     109           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     110             : 
     111           0 :         if ( m_aCommandURL == ".uno:DBNewForm" )
     112             :         {
     113           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewForm")           ,sal_True));
     114           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewView")           ,sal_True));
     115           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewViewSQL")        ,sal_True));
     116           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewQuery")          ,sal_True));
     117           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewQuerySql")       ,sal_True));
     118           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewReport")         ,sal_True));
     119           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewReportAutoPilot"),sal_True));
     120           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewTable")          ,sal_True));
     121             :         }
     122             :         else
     123             :         {
     124           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:Refresh")         ,sal_True));
     125           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBRebuildData")   ,sal_True));
     126             :         }
     127             : 
     128           0 :         TCommandState::iterator aIter = m_aStates.begin();
     129           0 :         TCommandState::iterator aEnd = m_aStates.end();
     130           0 :         for (; aIter != aEnd; ++aIter)
     131           0 :             addStatusListener(aIter->first);
     132             : 
     133           0 :         ToolBox*    pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     134           0 :         if ( pToolBox )
     135             :         {
     136           0 :             sal_uInt16 nCount = pToolBox->GetItemCount();
     137           0 :             for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
     138             :             {
     139           0 :                 sal_uInt16 nItemId = pToolBox->GetItemId(nPos);
     140           0 :                 if ( pToolBox->GetItemCommand(nItemId) == m_aCommandURL )
     141             :                 {
     142           0 :                     m_nToolBoxId = nItemId;
     143           0 :                     break;
     144             :                 }
     145             :             }
     146             : 
     147             :             // check if paste special is allowed, when not don't add DROPDOWN
     148           0 :             pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | TIB_DROPDOWN);
     149           0 :         }
     150           0 :     }
     151           0 :     void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException, std::exception )
     152             :     {
     153           0 :         SolarMutexGuard aSolarMutexGuard;
     154           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     155           0 :         TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     156           0 :         if ( aFind != m_aStates.end() )
     157             :         {
     158           0 :             aFind->second = Event.IsEnabled;
     159           0 :             if ( m_aCommandURL == aFind->first && !Event.IsEnabled )
     160             :             {
     161             :                 SAL_WNODEPRECATED_DECLARATIONS_PUSH
     162           0 :                 ::std::auto_ptr<PopupMenu> pMenu = getMenu();
     163             :                 SAL_WNODEPRECATED_DECLARATIONS_POP
     164           0 :                 sal_uInt16 nCount = pMenu->GetItemCount();
     165           0 :                 for (sal_uInt16 i = 0; i < nCount; ++i)
     166             :                 {
     167           0 :                     sal_uInt16 nItemId = pMenu->GetItemId(i);
     168           0 :                     aFind = m_aStates.find(pMenu->GetItemCommand(nItemId));
     169           0 :                     if ( aFind != m_aStates.end() && aFind->second )
     170             :                     {
     171           0 :                         m_aCommandURL = aFind->first;
     172             : 
     173           0 :                         ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     174           0 :                         lcl_copy(pMenu.get(),nItemId,i,pToolBox,m_nToolBoxId, m_aCommandURL);
     175           0 :                         break;
     176             :                     }
     177           0 :                 }
     178             :             }
     179           0 :         }
     180           0 :     }
     181             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     182           0 :     ::std::auto_ptr<PopupMenu> OToolboxController::getMenu()
     183             :     {
     184           0 :         ::std::auto_ptr<PopupMenu> pMenu;
     185           0 :         if ( m_aStates.size() > 2 )
     186             :         {
     187           0 :             pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_APP_NEW ) ) );
     188             : 
     189             :             try
     190             :             {
     191           0 :                 Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier = theModuleUIConfigurationManagerSupplier::get( getContext() );
     192           0 :                 Reference<XUIConfigurationManager> xUIConfigMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( OUString("com.sun.star.sdb.OfficeDatabaseDocument") );
     193           0 :                 Reference<XImageManager> xImageMgr(xUIConfigMgr->getImageManager(),UNO_QUERY);
     194             : 
     195           0 :                 Sequence< OUString> aSeq(1);
     196           0 :                 sal_uInt16 nCount = pMenu->GetItemCount();
     197           0 :                 for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
     198             :                 {
     199           0 :                     if ( pMenu->GetItemType( nPos ) == MENUITEM_SEPARATOR )
     200           0 :                         continue;
     201             : 
     202           0 :                     sal_uInt16 nItemId = pMenu->GetItemId(nPos);
     203           0 :                     aSeq[0] = pMenu->GetItemCommand(nItemId);
     204           0 :                     Sequence< Reference<XGraphic> > aImages = xImageMgr->getImages(ImageType::SIZE_DEFAULT, aSeq);
     205             : 
     206           0 :                     Image aImage(aImages[0]);
     207           0 :                     pMenu->SetItemImage(nItemId,aImage);
     208           0 :                     TCommandState::iterator aFind = m_aStates.find( aSeq[0] );
     209           0 :                     if ( aFind != m_aStates.end() )
     210             :                     {
     211           0 :                         pMenu->EnableItem(nItemId,aFind->second);
     212             :                     }
     213           0 :                 }
     214             :             }
     215           0 :             catch(const Exception&)
     216             :             {
     217             :                 DBG_UNHANDLED_EXCEPTION();
     218             :             }
     219             :         }
     220             :         else
     221             :         {
     222           0 :             pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_REFRESH_DATA ) ) );
     223             :         }
     224           0 :         return pMenu;
     225             :     }
     226             :     SAL_WNODEPRECATED_DECLARATIONS_POP
     227           0 :     Reference< ::com::sun::star::awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException, std::exception)
     228             :     {
     229             :         // execute the menu
     230           0 :         SolarMutexGuard aSolarMutexGuard;
     231           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     232             : 
     233           0 :         ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     234             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     235           0 :         ::std::auto_ptr<PopupMenu> pMenu = getMenu();
     236             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     237             : 
     238           0 :         sal_uInt16 nSelected = pMenu->Execute(pToolBox, pToolBox->GetItemRect( m_nToolBoxId ),POPUPMENU_EXECUTE_DOWN);
     239             :         // "cleanup" the toolbox state
     240           0 :         Point aPoint = pToolBox->GetItemRect( m_nToolBoxId ).TopLeft();
     241           0 :         MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
     242           0 :         pToolBox->MouseMove( aLeave );
     243           0 :         pToolBox->SetItemDown( m_nToolBoxId, false);
     244             : 
     245           0 :         if ( nSelected )
     246             :         {
     247           0 :             m_aCommandURL = pMenu->GetItemCommand(nSelected);
     248           0 :             lcl_copy(pMenu.get(),nSelected,pMenu->GetItemPos(nSelected),pToolBox,m_nToolBoxId, m_aCommandURL);
     249             : 
     250           0 :             Reference<XDispatch> xDispatch = m_aListenerMap.find(m_aCommandURL)->second;
     251           0 :             if ( xDispatch.is() )
     252             :             {
     253           0 :                 URL aUrl;
     254           0 :                 Sequence < PropertyValue > aArgs;
     255           0 :                 aUrl.Complete = m_aCommandURL;
     256             :                 OSL_ENSURE(!aUrl.Complete.isEmpty(),"Command is empty!");
     257           0 :                 if ( getURLTransformer().is() )
     258           0 :                     getURLTransformer()->parseStrict(aUrl);
     259           0 :                 xDispatch->dispatch(aUrl,aArgs);
     260             : 
     261           0 :             }
     262             :         }
     263           0 :         return Reference< ::com::sun::star::awt::XWindow >();
     264             :     }
     265             : } // dbaui
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10