LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/control - toolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 133 4.5 %
Date: 2013-07-09 Functions: 5 18 27.8 %
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/ModuleUIConfigurationManagerSupplier.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             : 
      42           4 : extern "C" void SAL_CALL createRegistryInfo_OToolboxController()
      43             : {
      44           4 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OToolboxController> aAutoRegistration;
      45           4 : }
      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             :     // -----------------------------------------------------------------------------
      80           8 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(OToolboxController, "com.sun.star.sdb.ApplicationToolboxController")
      81           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(OToolboxController)
      82           4 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(OToolboxController, "com.sun.star.frame.ToolboxController")
      83             : 
      84             :     Reference< XInterface >
      85           0 :         SAL_CALL OToolboxController::Create(const Reference< XMultiServiceFactory >& _rxORB)
      86             :     {
      87           0 :         return static_cast< XServiceInfo* >(new OToolboxController( comphelper::getComponentContext(_rxORB) ));
      88             :     }
      89             : 
      90             : 
      91             :     // -----------------------------------------------------------------------------
      92             :     // XInterface
      93           0 :     Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException)
      94             :     {
      95           0 :         Any aReturn = ToolboxController::queryInterface(_rType);
      96           0 :         if (!aReturn.hasValue())
      97           0 :             aReturn = TToolboxController_BASE::queryInterface(_rType);
      98           0 :         return aReturn;
      99             :     }
     100             :     // -----------------------------------------------------------------------------
     101           0 :     void SAL_CALL OToolboxController::acquire() throw ()
     102             :     {
     103           0 :         ToolboxController::acquire();
     104           0 :     }
     105             :     // -----------------------------------------------------------------------------
     106           0 :     void SAL_CALL OToolboxController::release() throw ()
     107             :     {
     108           0 :         ToolboxController::release();
     109           0 :     }
     110             :     // -----------------------------------------------------------------------------
     111           0 :     void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
     112             :     {
     113           0 :         ToolboxController::initialize(_rArguments);
     114           0 :         SolarMutexGuard aSolarMutexGuard;
     115           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     116             : 
     117           0 :         if ( m_aCommandURL == ".uno:DBNewForm" )
     118             :         {
     119           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewForm")           ,sal_True));
     120           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewView")           ,sal_True));
     121           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewViewSQL")        ,sal_True));
     122           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewQuery")          ,sal_True));
     123           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewQuerySql")       ,sal_True));
     124           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewReport")         ,sal_True));
     125           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewReportAutoPilot"),sal_True));
     126           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBNewTable")          ,sal_True));
     127             :         }
     128             :         else
     129             :         {
     130           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:Refresh")         ,sal_True));
     131           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:DBRebuildData")   ,sal_True));
     132             :         }
     133             : 
     134           0 :         TCommandState::iterator aIter = m_aStates.begin();
     135           0 :         TCommandState::iterator aEnd = m_aStates.end();
     136           0 :         for (; aIter != aEnd; ++aIter)
     137           0 :             addStatusListener(aIter->first);
     138             : 
     139           0 :         ToolBox*    pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     140           0 :         if ( pToolBox )
     141             :         {
     142           0 :             sal_uInt16 nCount = pToolBox->GetItemCount();
     143           0 :             for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
     144             :             {
     145           0 :                 sal_uInt16 nItemId = pToolBox->GetItemId(nPos);
     146           0 :                 if ( pToolBox->GetItemCommand(nItemId) == String(m_aCommandURL) )
     147             :                 {
     148           0 :                     m_nToolBoxId = nItemId;
     149           0 :                     break;
     150             :                 }
     151             :             }
     152             : 
     153             :             // check if paste special is allowed, when not don't add DROPDOWN
     154           0 :             pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | TIB_DROPDOWN);
     155           0 :         }
     156           0 :     }
     157             :     // -----------------------------------------------------------------------------
     158           0 :     void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
     159             :     {
     160           0 :         SolarMutexGuard aSolarMutexGuard;
     161           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     162           0 :         TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     163           0 :         if ( aFind != m_aStates.end() )
     164             :         {
     165           0 :             aFind->second = Event.IsEnabled;
     166           0 :             if ( m_aCommandURL == aFind->first && !Event.IsEnabled )
     167             :             {
     168             :                 SAL_WNODEPRECATED_DECLARATIONS_PUSH
     169           0 :                 ::std::auto_ptr<PopupMenu> pMenu = getMenu();
     170             :                 SAL_WNODEPRECATED_DECLARATIONS_POP
     171           0 :                 sal_uInt16 nCount = pMenu->GetItemCount();
     172           0 :                 for (sal_uInt16 i = 0; i < nCount; ++i)
     173             :                 {
     174           0 :                     sal_uInt16 nItemId = pMenu->GetItemId(i);
     175           0 :                     aFind = m_aStates.find(pMenu->GetItemCommand(nItemId));
     176           0 :                     if ( aFind != m_aStates.end() && aFind->second )
     177             :                     {
     178           0 :                         m_aCommandURL = aFind->first;
     179             : 
     180           0 :                         ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     181           0 :                         lcl_copy(pMenu.get(),nItemId,i,pToolBox,m_nToolBoxId, m_aCommandURL);
     182           0 :                         break;
     183             :                     }
     184           0 :                 }
     185             :             }
     186           0 :         }
     187           0 :     }
     188             :     // -----------------------------------------------------------------------------
     189             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     190           0 :     ::std::auto_ptr<PopupMenu> OToolboxController::getMenu()
     191             :     {
     192           0 :         ::std::auto_ptr<PopupMenu> pMenu;
     193           0 :         if ( m_aStates.size() > 2 )
     194             :         {
     195           0 :             pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_APP_NEW ) ) );
     196             : 
     197             :             try
     198             :             {
     199           0 :                 Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier = ModuleUIConfigurationManagerSupplier::create( getContext() );
     200           0 :                 Reference<XUIConfigurationManager> xUIConfigMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( OUString("com.sun.star.sdb.OfficeDatabaseDocument") );
     201           0 :                 Reference<XImageManager> xImageMgr(xUIConfigMgr->getImageManager(),UNO_QUERY);
     202             : 
     203           0 :                 short nImageType = hasBigImages() ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT;
     204             : 
     205           0 :                 Sequence< OUString> aSeq(1);
     206           0 :                 sal_uInt16 nCount = pMenu->GetItemCount();
     207           0 :                 for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
     208             :                 {
     209           0 :                     if ( pMenu->GetItemType( nPos ) == MENUITEM_SEPARATOR )
     210           0 :                         continue;
     211             : 
     212           0 :                     sal_uInt16 nItemId = pMenu->GetItemId(nPos);
     213           0 :                     aSeq[0] = pMenu->GetItemCommand(nItemId);
     214           0 :                     Sequence< Reference<XGraphic> > aImages = xImageMgr->getImages(nImageType,aSeq);
     215             : 
     216           0 :                     Image aImage(aImages[0]);
     217           0 :                     pMenu->SetItemImage(nItemId,aImage);
     218           0 :                     TCommandState::iterator aFind = m_aStates.find( aSeq[0] );
     219           0 :                     if ( aFind != m_aStates.end() )
     220             :                     {
     221           0 :                         pMenu->EnableItem(nItemId,aFind->second);
     222             :                     }
     223           0 :                 }
     224             :             }
     225           0 :             catch(const Exception&)
     226             :             {
     227             :                 DBG_UNHANDLED_EXCEPTION();
     228             :             }
     229             :         }
     230             :         else
     231             :         {
     232           0 :             pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_REFRESH_DATA ) ) );
     233             :         }
     234           0 :         return pMenu;
     235             :     }
     236             :     SAL_WNODEPRECATED_DECLARATIONS_POP
     237             :     // -----------------------------------------------------------------------------
     238           0 :     Reference< ::com::sun::star::awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException)
     239             :     {
     240             :         // execute the menu
     241           0 :         SolarMutexGuard aSolarMutexGuard;
     242           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     243             : 
     244           0 :         ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     245             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     246           0 :         ::std::auto_ptr<PopupMenu> pMenu = getMenu();
     247             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     248             : 
     249           0 :         sal_uInt16 nSelected = pMenu->Execute(pToolBox, pToolBox->GetItemRect( m_nToolBoxId ),POPUPMENU_EXECUTE_DOWN);
     250             :         // "cleanup" the toolbox state
     251           0 :         Point aPoint = pToolBox->GetItemRect( m_nToolBoxId ).TopLeft();
     252           0 :         MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
     253           0 :         pToolBox->MouseMove( aLeave );
     254           0 :         pToolBox->SetItemDown( m_nToolBoxId, sal_False);
     255             : 
     256           0 :         if ( nSelected )
     257             :         {
     258           0 :             m_aCommandURL = pMenu->GetItemCommand(nSelected);
     259           0 :             lcl_copy(pMenu.get(),nSelected,pMenu->GetItemPos(nSelected),pToolBox,m_nToolBoxId, m_aCommandURL);
     260             : 
     261           0 :             Reference<XDispatch> xDispatch = m_aListenerMap.find(m_aCommandURL)->second;
     262           0 :             if ( xDispatch.is() )
     263             :             {
     264           0 :                 URL aUrl;
     265           0 :                 Sequence < PropertyValue > aArgs;
     266           0 :                 aUrl.Complete = m_aCommandURL;
     267             :                 OSL_ENSURE(!aUrl.Complete.isEmpty(),"Command is empty!");
     268           0 :                 if ( getURLTransformer().is() )
     269           0 :                     getURLTransformer()->parseStrict(aUrl);
     270           0 :                 xDispatch->dispatch(aUrl,aArgs);
     271             : 
     272           0 :             }
     273             :         }
     274           0 :         return Reference< ::com::sun::star::awt::XWindow >();
     275             :     }
     276             :     // -----------------------------------------------------------------------------
     277             :     // -----------------------------------------------------------------------------
     278             : //..........................................................................
     279          12 : } // dbaui
     280             : //..........................................................................
     281             : 
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10