update dev300-m58
[ooovba.git] / sfx2 / source / menu / objmnctl.cxx
blob27b500d7ffd96010e2c71d2030cfbb11af25a4c1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objmnctl.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/embed/VerbDescriptor.hpp>
34 #include <com/sun/star/embed/VerbAttributes.hpp>
36 #include <tools/list.hxx>
37 #ifndef _MENU_HXX //autogen
38 #include <vcl/menu.hxx>
39 #endif
40 #ifndef _SXSTRITEM_HXX //autogen
41 #include <svtools/stritem.hxx>
42 #endif
43 #ifndef GCC
44 #endif
46 #include <sfx2/sfxsids.hrc>
47 #include "objmnctl.hxx"
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/viewsh.hxx>
50 #include <sfx2/viewfrm.hxx>
51 #include <sfx2/objsh.hxx>
53 // STATIC DATA -----------------------------------------------------------
55 SFX_IMPL_MENU_CONTROL(SfxObjectVerbsControl, SfxStringItem);
57 using namespace com::sun::star;
58 //--------------------------------------------------------------------
61 Ctor; setzt Select-Handler am Menu und traegt Menu
62 in seinen Parent ein.
65 SfxObjectVerbsControl::SfxObjectVerbsControl(USHORT nSlotId, Menu &rMenu, SfxBindings &rBindings)
66 : SfxMenuControl( nSlotId, rBindings )
67 , pMenu(new PopupMenu)
68 , rParent(rMenu)
70 rMenu.SetPopupMenu(nSlotId, pMenu);
71 pMenu->SetSelectHdl(LINK(this, SfxObjectVerbsControl, MenuSelect));
72 FillMenu();
75 //--------------------------------------------------------------------
78 Fuellt das Menu mit den aktuellen Verben aus der ViewShell.
81 void SfxObjectVerbsControl::FillMenu()
83 pMenu->Clear();
84 SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
85 if (pView)
87 SfxObjectShell* pDoc = pView->GetObjectShell();
88 const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs = pView->GetVerbs();
89 if ( aVerbs.getLength() )
91 USHORT nSlotId = SID_VERB_START;
92 for (USHORT n=0; n<aVerbs.getLength(); n++)
94 // check for ReadOnly verbs
95 if ( pDoc->IsReadOnly() && !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) )
96 continue;
98 // check for verbs that shouldn't appear in the menu
99 if ( !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) )
100 continue;
102 DBG_ASSERT(nSlotId <= SID_VERB_END, "Zuviele Verben!");
103 if (nSlotId > SID_VERB_END)
104 break;
106 pMenu->InsertItem(nSlotId++, aVerbs[n].VerbName);
111 rParent.EnableItem( GetId(), (BOOL)pMenu->GetItemCount() );
114 //--------------------------------------------------------------------
117 Statusbenachrichtigung;
118 fuellt gfs. das Menu mit den aktuellen Verben aus der ViewShell.
119 der DocumentShell.
120 Ist die Funktionalit"at disabled, wird der entsprechende
121 Menueeintrag im Parentmenu disabled, andernfalls wird er enabled.
124 void SfxObjectVerbsControl::StateChanged(
125 USHORT /*nSID*/,
126 SfxItemState eState,
127 const SfxPoolItem* /*pState*/ )
129 rParent.EnableItem(GetId(), SFX_ITEM_AVAILABLE == eState );
130 if ( SFX_ITEM_AVAILABLE == eState )
131 FillMenu();
134 //--------------------------------------------------------------------
137 Select-Handler des Menus;
138 das selektierte Verb mit ausgef"uhrt,
141 IMPL_LINK_INLINE_START( SfxObjectVerbsControl, MenuSelect, Menu *, pSelMenu )
143 const USHORT nSlotId = pSelMenu->GetCurItemId();
144 if( nSlotId )
145 GetBindings().Execute(nSlotId);
146 return 1;
148 IMPL_LINK_INLINE_END( SfxObjectVerbsControl, MenuSelect, Menu *, pSelMenu )
150 //--------------------------------------------------------------------
153 Dtor; gibt das Menu frei.
156 SfxObjectVerbsControl::~SfxObjectVerbsControl()
158 delete pMenu;
161 //--------------------------------------------------------------------
163 PopupMenu* SfxObjectVerbsControl::GetPopup() const
165 return pMenu;