LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/menu - mnuitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 107 5.6 %
Date: 2012-12-27 Functions: 2 17 11.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             : 
      21             : #ifdef SOLARIS
      22             : #include <ctime>
      23             : #endif
      24             : 
      25             : #include <string>
      26             : #include <com/sun/star/uno/Reference.h>
      27             : #include <com/sun/star/frame/XDispatch.hpp>
      28             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      29             : #include <com/sun/star/frame/XFrame.hpp>
      30             : #include <com/sun/star/util/URL.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <com/sun/star/util/XURLTransformer.hpp>
      34             : #include <tools/urlobj.hxx>
      35             : #include <svl/eitem.hxx>
      36             : #include <svl/stritem.hxx>
      37             : #include <svtools/imagemgr.hxx>
      38             : #include <svtools/menuoptions.hxx>
      39             : #include <framework/menuconfiguration.hxx>
      40             : 
      41             : #include <sfx2/app.hxx>
      42             : #include <sfx2/sfx.hrc>
      43             : #include <sfx2/msgpool.hxx>
      44             : #include <sfx2/msg.hxx>
      45             : #include <sfx2/bindings.hxx>
      46             : #include <sfx2/dispatch.hxx>
      47             : #include "idpool.hxx"
      48             : #include "sfxtypes.hxx"
      49             : #include "virtmenu.hxx"
      50             : #include <sfx2/mnuitem.hxx>
      51             : #include <sfx2/tbxctrl.hxx>
      52             : #include "arrdecl.hxx"
      53             : #include <sfx2/module.hxx>
      54             : #include <sfx2/unoctitm.hxx>
      55             : #include <sfx2/viewfrm.hxx>
      56             : #include "sfx2/imgmgr.hxx"
      57             : #include "sfx2/imagemgr.hxx"
      58             : #include "sfx2/sfxresid.hxx"
      59             : #include "../doc/doc.hrc"
      60             : 
      61             : using namespace ::com::sun::star::uno;
      62             : using namespace ::com::sun::star::frame;
      63             : using namespace ::com::sun::star::beans;
      64             : using namespace ::com::sun::star::util;
      65             : 
      66             : //====================================================================
      67             : 
      68             : // binds the instance to the specified id and assignes the title
      69             : 
      70           0 : void SfxMenuControl::Bind(
      71             :     SfxVirtualMenu* pOwn,
      72             :     sal_uInt16 nSlotId,
      73             :     const String& rTitle,
      74             :     SfxBindings &rBindings )
      75             : {
      76           0 :     aTitle = rTitle;
      77           0 :     pOwnMenu = pOwn;
      78           0 :     pSubMenu = 0;
      79           0 :     if ( pOwn )
      80           0 :         SfxControllerItem::Bind(nSlotId, &rBindings);
      81             :     else
      82           0 :         SetId( nSlotId );
      83             : 
      84             :     DBG( CheckConfigure_Impl(SFX_SLOT_MENUCONFIG) );
      85           0 : }
      86             : 
      87             : 
      88             : //--------------------------------------------------------------------
      89             : 
      90             : // binds the item to the specified menu and assignes the title
      91             : 
      92           0 : void SfxMenuControl::Bind(
      93             :     SfxVirtualMenu* pOwn,
      94             :     sal_uInt16 nSlotId,
      95             :     SfxVirtualMenu& rMenu,
      96             :     const String& rTitle,
      97             :     SfxBindings &rBindings )
      98             : {
      99           0 :     SetId( nSlotId );
     100           0 :     SetBindings(rBindings);
     101           0 :     pOwnMenu = pOwn;
     102           0 :     pSubMenu = &rMenu;
     103           0 :     aTitle = rTitle;
     104           0 : }
     105             : 
     106             : //--------------------------------------------------------------------
     107             : 
     108             : // Constructor for explicit registration
     109             : 
     110           0 : SfxMenuControl::SfxMenuControl( sal_Bool bShowStrings )
     111             : :   pOwnMenu(0),
     112             :     pSubMenu(0),
     113           0 :     b_ShowStrings(bShowStrings)
     114             : {
     115           0 : }
     116             : 
     117             : //--------------------------------------------------------------------
     118             : 
     119             : // Constructor for array
     120           0 : SfxMenuControl::SfxMenuControl():
     121             :     pOwnMenu(0),
     122             :     pSubMenu(0),
     123           0 :     b_ShowStrings(sal_False)
     124             : {
     125           0 : }
     126             : 
     127             : //--------------------------------------------------------------------
     128             : 
     129           0 : SfxMenuControl::SfxMenuControl(sal_uInt16 nSlotId, SfxBindings& rBindings):
     130             :     SfxControllerItem(nSlotId, rBindings),
     131             :     pOwnMenu(0),
     132             :     pSubMenu(0),
     133           0 :     b_ShowStrings(sal_False)
     134             : {
     135             :     // This constructor should make it possible already during the design
     136             :     // to fall back to the bindings, but can as always be bound later.
     137             :     // The usefullness of this is for example if a StatusForwarder should
     138             :     // be created in the constructor of a derived class.
     139           0 :     UnBind();
     140           0 : }
     141             : 
     142             : 
     143             : //--------------------------------------------------------------------
     144             : 
     145           0 : SfxMenuControl::~SfxMenuControl()
     146             : {
     147           0 :     delete pSubMenu;
     148           0 : }
     149             : 
     150             : //--------------------------------------------------------------------
     151             : 
     152             : // changes the state in the virtual menu
     153             : 
     154           0 : void SfxMenuControl::StateChanged
     155             : (
     156             :     sal_uInt16              nSID,
     157             :     SfxItemState        eState,
     158             :     const SfxPoolItem*  pState
     159             : )
     160             : {
     161             :     (void)nSID;
     162             :     DBG_ASSERT( nSID == GetId(), "strange SID" );
     163             :     DBG_ASSERT( pOwnMenu != 0, "setting state to dangling SfxMenuControl" );
     164             : 
     165             :     bool bIsObjMenu =
     166           0 :                 GetId() >= SID_OBJECTMENU0 && GetId() < SID_OBJECTMENU_LAST;
     167             : 
     168             :     // Fix inclusion of enabled/disabled-Flag
     169             : 
     170             : #ifdef UNIX
     171           0 :     if (nSID == SID_PASTE)
     172           0 :         pOwnMenu->EnableItem( GetId(), sal_True );
     173             :     else
     174             : #endif
     175           0 :     pOwnMenu->EnableItem( GetId(), bIsObjMenu
     176           0 :                 ? 0 != pOwnMenu->GetSVMenu()->GetPopupMenu( GetId() )
     177           0 :                 : eState != SFX_ITEM_DISABLED );
     178             : 
     179           0 :     if ( eState != SFX_ITEM_AVAILABLE )
     180             :     {
     181             :         // check only for non-Object Menus
     182           0 :         if ( !bIsObjMenu )
     183           0 :             pOwnMenu->CheckItem( GetId(), sal_False );
     184             : 
     185           0 :         if ( pOwnMenu->GetSVMenu()->GetItemText( GetId() ) != GetTitle() )
     186             :         {
     187             :              DBG_WARNING("Title of menu item changed - please check if this needs correction!");
     188             :         }
     189           0 :         return;
     190             :     }
     191             : 
     192           0 :     bool bCheck = false;
     193           0 :     if ( pState->ISA(SfxBoolItem) )
     194             :     {
     195             :         // BoolItem for check
     196             :         DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
     197             :                     "SfxBoolItem not allowed for SID_OBJECTMENUx" );
     198           0 :         bCheck = ((const SfxBoolItem*)pState)->GetValue();
     199             :     }
     200           0 :     else if ( pState->ISA(SfxEnumItemInterface) &&
     201           0 :               ((SfxEnumItemInterface *)pState)->HasBoolValue() )
     202             :     {
     203             :         // Treat EnumItem as Bool
     204             :         DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
     205             :                     "SfxEnumItem not allowed for SID_OBJECTMENUx" );
     206           0 :         bCheck = ((SfxEnumItemInterface *)pState)->GetBoolValue();
     207             :     }
     208           0 :     else if ( ( b_ShowStrings || bIsObjMenu ) && pState->ISA(SfxStringItem) )
     209             :     {
     210             :         // Get MenuText from SfxStringItem
     211           0 :         String aStr( ((const SfxStringItem*)pState)->GetValue() );
     212           0 :         if ( aStr.CompareToAscii("($1)",4) == COMPARE_EQUAL )
     213             :         {
     214           0 :             String aEntry(SfxResId(STR_UPDATEDOC).toString());
     215           0 :             aEntry += ' ';
     216           0 :             aEntry += aStr.Copy(4);
     217           0 :             aStr = aEntry;
     218             :         }
     219           0 :         else if ( aStr.CompareToAscii("($2)",4) == COMPARE_EQUAL )
     220             :         {
     221           0 :             String aEntry(SfxResId(STR_CLOSEDOC_ANDRETURN).toString());
     222           0 :             aEntry += aStr.Copy(4);
     223           0 :             aStr = aEntry;
     224             :         }
     225             : 
     226           0 :         pOwnMenu->SetItemText( GetId(), aStr );
     227             :     }
     228             : 
     229           0 :     pOwnMenu->CheckItem( GetId(), bCheck );
     230             : }
     231             : 
     232             : //--------------------------------------------------------------------
     233             : 
     234           0 : SfxMenuControl* SfxMenuControl::CreateImpl( sal_uInt16 /*nId*/, Menu& /*rMenu*/, SfxBindings& /*rBindings*/ )
     235             : {
     236           0 :     return new SfxMenuControl( sal_True );
     237             : }
     238             : 
     239           9 : void SfxMenuControl::RegisterControl( sal_uInt16 nSlotId, SfxModule *pMod )
     240             : {
     241             :     RegisterMenuControl( pMod, new SfxMenuCtrlFactory(
     242           9 :                 SfxMenuControl::CreateImpl, TYPE(SfxStringItem), nSlotId ) );
     243           9 : }
     244             : 
     245             : //--------------------------------------------------------------------
     246          73 : void SfxMenuControl::RegisterMenuControl(SfxModule* pMod, SfxMenuCtrlFactory* pFact)
     247             : {
     248          73 :     SFX_APP()->RegisterMenuControl_Impl( pMod, pFact );
     249          73 : }
     250             : 
     251           0 : SfxMenuControl* SfxMenuControl::CreateControl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings )
     252             : {
     253           0 :     TypeId aSlotType = SFX_SLOTPOOL().GetSlotType(nId);
     254           0 :     if ( aSlotType )
     255             :     {
     256           0 :         SfxApplication *pApp = SFX_APP();
     257           0 :         SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
     258           0 :         SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
     259           0 :         if ( pMod )
     260             :         {
     261           0 :             SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
     262           0 :             if ( pFactories )
     263             :             {
     264           0 :                 SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
     265           0 :                 for ( sal_uInt16 nFactory = 0; nFactory < rFactories.size(); ++nFactory )
     266           0 :                     if ( rFactories[nFactory]->nTypeId == aSlotType &&
     267           0 :                          ( ( rFactories[nFactory]->nSlotId == 0 ) ||
     268           0 :                            ( rFactories[nFactory]->nSlotId == nId) ) )
     269           0 :                         return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
     270             :             }
     271             :         }
     272             : 
     273           0 :         SfxMenuCtrlFactArr_Impl &rFactories = pApp->GetMenuCtrlFactories_Impl();
     274             : 
     275           0 :         for ( sal_uInt16 nFactory = 0; nFactory < rFactories.size(); ++nFactory )
     276           0 :             if ( rFactories[nFactory]->nTypeId == aSlotType &&
     277           0 :                  ( ( rFactories[nFactory]->nSlotId == 0 ) ||
     278           0 :                    ( rFactories[nFactory]->nSlotId == nId) ) )
     279           0 :                 return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
     280             :     }
     281           0 :     return 0;
     282             : }
     283             : 
     284             : //--------------------------------------------------------------------
     285             : 
     286           0 : PopupMenu* SfxMenuControl::GetPopup () const
     287             : {
     288           0 :     if (GetPopupMenu())
     289           0 :         return (PopupMenu*)GetPopupMenu()->GetSVMenu();
     290             :     else
     291           0 :         return 0;
     292             : }
     293             : 
     294           0 : SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
     295             :         sal_uInt16 nId, Menu& rMenu, const String& sItemText,
     296             :         SfxBindings& rBindings, SfxVirtualMenu* pVirt)
     297             : {
     298           0 :     return new SfxUnoMenuControl( rCmd, nId, rMenu, sItemText, rBindings, pVirt);
     299             : }
     300             : 
     301           0 : SfxUnoMenuControl::SfxUnoMenuControl(
     302             :     const String& rCmd, sal_uInt16 nSlotId, Menu& /*rMenu*/,
     303             :     const String& rItemText,
     304             :     SfxBindings& rBindings, SfxVirtualMenu* pVirt)
     305           0 :     : SfxMenuControl( nSlotId, rBindings )
     306             : {
     307           0 :     Bind( pVirt, nSlotId, rItemText, rBindings);
     308           0 :     UnBind();
     309           0 :     pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
     310           0 :     pUnoCtrl->acquire();
     311           0 :     pUnoCtrl->GetNewDispatch();
     312           0 : }
     313             : 
     314           0 : SfxUnoMenuControl::~SfxUnoMenuControl()
     315             : {
     316           0 :     pUnoCtrl->UnBind();
     317           0 :     pUnoCtrl->release();
     318           0 : }
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10