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

Generated by: LCOV version 1.11