1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objmnctl.cxx,v $
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>
40 #ifndef _SXSTRITEM_HXX //autogen
41 #include <svtools/stritem.hxx>
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
65 SfxObjectVerbsControl::SfxObjectVerbsControl(USHORT nSlotId
, Menu
&rMenu
, SfxBindings
&rBindings
)
66 : SfxMenuControl( nSlotId
, rBindings
)
67 , pMenu(new PopupMenu
)
70 rMenu
.SetPopupMenu(nSlotId
, pMenu
);
71 pMenu
->SetSelectHdl(LINK(this, SfxObjectVerbsControl
, MenuSelect
));
75 //--------------------------------------------------------------------
78 Fuellt das Menu mit den aktuellen Verben aus der ViewShell.
81 void SfxObjectVerbsControl::FillMenu()
84 SfxViewShell
*pView
= GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
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
) )
98 // check for verbs that shouldn't appear in the menu
99 if ( !(aVerbs
[n
].VerbAttributes
& embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU
) )
102 DBG_ASSERT(nSlotId
<= SID_VERB_END
, "Zuviele Verben!");
103 if (nSlotId
> SID_VERB_END
)
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.
120 Ist die Funktionalit"at disabled, wird der entsprechende
121 Menueeintrag im Parentmenu disabled, andernfalls wird er enabled.
124 void SfxObjectVerbsControl::StateChanged(
127 const SfxPoolItem
* /*pState*/ )
129 rParent
.EnableItem(GetId(), SFX_ITEM_AVAILABLE
== eState
);
130 if ( SFX_ITEM_AVAILABLE
== eState
)
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();
145 GetBindings().Execute(nSlotId
);
148 IMPL_LINK_INLINE_END( SfxObjectVerbsControl
, MenuSelect
, Menu
*, pSelMenu
)
150 //--------------------------------------------------------------------
153 Dtor; gibt das Menu frei.
156 SfxObjectVerbsControl::~SfxObjectVerbsControl()
161 //--------------------------------------------------------------------
163 PopupMenu
* SfxObjectVerbsControl::GetPopup() const