1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5d119d52dSAndrew Rist * distributed with this work for additional information
6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at
10d119d52dSAndrew Rist *
11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist *
13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist * software distributed under the License is distributed on an
15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the
17d119d52dSAndrew Rist * specific language governing permissions and limitations
18d119d52dSAndrew Rist * under the License.
19d119d52dSAndrew Rist *
20d119d52dSAndrew Rist *************************************************************/
21d119d52dSAndrew Rist
22d119d52dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifdef SOLARIS
28cdf0e10cSrcweir // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
29cdf0e10cSrcweir #include <ctime>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop includes
33cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
34cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
37cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
39cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
43cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
44cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #include <tools/urlobj.hxx>
47cdf0e10cSrcweir #include <svl/eitem.hxx>
48cdf0e10cSrcweir #include <svl/stritem.hxx>
49cdf0e10cSrcweir #include <svtools/imagemgr.hxx>
50cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
51cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
52cdf0e10cSrcweir #ifndef GCC
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir
55cdf0e10cSrcweir #include <sfx2/app.hxx>
56cdf0e10cSrcweir #include <sfx2/sfx.hrc>
57cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
58cdf0e10cSrcweir #include <sfx2/msg.hxx>
59cdf0e10cSrcweir #include <sfx2/bindings.hxx>
60cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
61cdf0e10cSrcweir #include "idpool.hxx"
62cdf0e10cSrcweir #include "sfxtypes.hxx"
63cdf0e10cSrcweir #include "virtmenu.hxx"
64cdf0e10cSrcweir #include <sfx2/mnuitem.hxx>
65cdf0e10cSrcweir #include <sfx2/tbxctrl.hxx>
66cdf0e10cSrcweir #include "arrdecl.hxx"
67cdf0e10cSrcweir #include <sfx2/module.hxx>
68cdf0e10cSrcweir #include <sfx2/unoctitm.hxx>
69cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
70cdf0e10cSrcweir #include "sfx2/imgmgr.hxx"
71cdf0e10cSrcweir #include "sfx2/imagemgr.hxx"
72cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
73cdf0e10cSrcweir #include "../doc/doc.hrc"
74cdf0e10cSrcweir
75cdf0e10cSrcweir using namespace ::com::sun::star::uno;
76cdf0e10cSrcweir using namespace ::com::sun::star::frame;
77cdf0e10cSrcweir using namespace ::com::sun::star::beans;
78cdf0e10cSrcweir using namespace ::com::sun::star::util;
79cdf0e10cSrcweir
80cdf0e10cSrcweir //====================================================================
81cdf0e10cSrcweir
82cdf0e10cSrcweir class SfxEnumMenu: public PopupMenu
83cdf0e10cSrcweir {
84cdf0e10cSrcweir sal_uInt16 nSlot;
85cdf0e10cSrcweir SfxEnumItem *pItem;
86cdf0e10cSrcweir SfxBindings* pBindings;
87cdf0e10cSrcweir
88cdf0e10cSrcweir protected:
89cdf0e10cSrcweir virtual void Select();
90cdf0e10cSrcweir
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir SfxEnumMenu( sal_uInt16 nSlot, SfxBindings* pBind, const SfxEnumItem &rItem );
93cdf0e10cSrcweir ~SfxEnumMenu();
94cdf0e10cSrcweir };
95cdf0e10cSrcweir
96cdf0e10cSrcweir //=========================================================================
97cdf0e10cSrcweir
SfxEnumMenu(sal_uInt16 nSlotId,SfxBindings * pBind,const SfxEnumItem & rItem)98cdf0e10cSrcweir SfxEnumMenu::SfxEnumMenu( sal_uInt16 nSlotId, SfxBindings* pBind, const SfxEnumItem &rItem ):
99cdf0e10cSrcweir nSlot( nSlotId ),
100cdf0e10cSrcweir pItem( (SfxEnumItem*) rItem.Clone() ),
101cdf0e10cSrcweir pBindings( pBind )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir for ( sal_uInt16 nVal = 0; nVal < pItem->GetValueCount(); ++nVal )
104cdf0e10cSrcweir InsertItem( nVal+1, pItem->GetValueTextByPos(nVal) );
105cdf0e10cSrcweir CheckItem( pItem->GetValue() + 1, sal_True );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir //-------------------------------------------------------------------------
109cdf0e10cSrcweir
~SfxEnumMenu()110cdf0e10cSrcweir SfxEnumMenu::~SfxEnumMenu()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir delete pItem;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir //-------------------------------------------------------------------------
116cdf0e10cSrcweir
Select()117cdf0e10cSrcweir void SfxEnumMenu::Select()
118cdf0e10cSrcweir {
119cdf0e10cSrcweir pItem->SetValue( GetCurItemId()-1 );
120cdf0e10cSrcweir pBindings->GetDispatcher()->Execute( nSlot,
121cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD,
122cdf0e10cSrcweir pItem, 0L, 0L );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir //--------------------------------------------------------------------
126cdf0e10cSrcweir
SetOwnMenu(SfxVirtualMenu * pMenu)127cdf0e10cSrcweir void SfxMenuControl::SetOwnMenu( SfxVirtualMenu* pMenu )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir pOwnMenu = pMenu;
130cdf0e10cSrcweir if ( pSubMenu )
131cdf0e10cSrcweir pSubMenu->SetParentMenu( pMenu );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir //--------------------------------------------------------------------
136cdf0e10cSrcweir
137cdf0e10cSrcweir // binds the instance to the specified id and assignes the title
138cdf0e10cSrcweir
Bind(SfxVirtualMenu * pOwn,sal_uInt16 nSlotId,const String & rTitle,const String & rHelpText,SfxBindings & rBindings)139cdf0e10cSrcweir void SfxMenuControl::Bind(
140cdf0e10cSrcweir SfxVirtualMenu* pOwn,
141cdf0e10cSrcweir sal_uInt16 nSlotId,
142cdf0e10cSrcweir const String& rTitle,
143cdf0e10cSrcweir const String &rHelpText,
144cdf0e10cSrcweir SfxBindings &rBindings )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir DBG_MEMTEST();
147cdf0e10cSrcweir
148cdf0e10cSrcweir aTitle = rTitle;
149cdf0e10cSrcweir aHelpText = rHelpText;
150cdf0e10cSrcweir pOwnMenu = pOwn;
151cdf0e10cSrcweir pSubMenu = 0;
152cdf0e10cSrcweir if ( pOwn )
153cdf0e10cSrcweir SfxControllerItem::Bind(nSlotId, &rBindings);
154cdf0e10cSrcweir else
155cdf0e10cSrcweir SetId( nSlotId );
156cdf0e10cSrcweir
157cdf0e10cSrcweir DBG( CheckConfigure_Impl(SFX_SLOT_MENUCONFIG) );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir
161cdf0e10cSrcweir //--------------------------------------------------------------------
162cdf0e10cSrcweir
163cdf0e10cSrcweir // binds the item to the specified menu and assignes the title
164cdf0e10cSrcweir
Bind(SfxVirtualMenu * pOwn,sal_uInt16 nSlotId,SfxVirtualMenu & rMenu,const String & rTitle,const String & rHelpText,SfxBindings & rBindings)165cdf0e10cSrcweir void SfxMenuControl::Bind(
166cdf0e10cSrcweir SfxVirtualMenu* pOwn,
167cdf0e10cSrcweir sal_uInt16 nSlotId,
168cdf0e10cSrcweir SfxVirtualMenu& rMenu,
169cdf0e10cSrcweir const String& rTitle,
170cdf0e10cSrcweir const String &rHelpText,
171cdf0e10cSrcweir SfxBindings &rBindings )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir DBG_MEMTEST();
174cdf0e10cSrcweir SetId( nSlotId );
175cdf0e10cSrcweir SetBindings(rBindings);
176cdf0e10cSrcweir pOwnMenu = pOwn;
177cdf0e10cSrcweir pSubMenu = &rMenu;
178cdf0e10cSrcweir aTitle = rTitle;
179cdf0e10cSrcweir aHelpText = rHelpText;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir //--------------------------------------------------------------------
183cdf0e10cSrcweir
184cdf0e10cSrcweir // ctor for explicit registration
185cdf0e10cSrcweir
SfxMenuControl(sal_Bool bShowStrings)186cdf0e10cSrcweir SfxMenuControl::SfxMenuControl( sal_Bool bShowStrings )
187cdf0e10cSrcweir : pOwnMenu(0),
188cdf0e10cSrcweir pSubMenu(0),
189cdf0e10cSrcweir b_ShowStrings(bShowStrings)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir DBG_MEMTEST();
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir //--------------------------------------------------------------------
195cdf0e10cSrcweir
196cdf0e10cSrcweir // ctor for array
197cdf0e10cSrcweir
SfxMenuControl()198cdf0e10cSrcweir SfxMenuControl::SfxMenuControl():
199cdf0e10cSrcweir pOwnMenu(0),
200cdf0e10cSrcweir pSubMenu(0),
201cdf0e10cSrcweir b_ShowStrings(sal_False)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir DBG_MEMTEST();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir //--------------------------------------------------------------------
207cdf0e10cSrcweir
SfxMenuControl(sal_uInt16 nSlotId,SfxBindings & rBindings)208cdf0e10cSrcweir SfxMenuControl::SfxMenuControl(sal_uInt16 nSlotId, SfxBindings& rBindings):
209cdf0e10cSrcweir SfxControllerItem(nSlotId, rBindings),
210cdf0e10cSrcweir pOwnMenu(0),
211cdf0e10cSrcweir pSubMenu(0),
212cdf0e10cSrcweir b_ShowStrings(sal_False)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir DBG_MEMTEST();
215cdf0e10cSrcweir
216cdf0e10cSrcweir // Dieser Ctor soll es erm"oglichen, w"ahrend der Konstruktion schon
217cdf0e10cSrcweir // auf die Bindings zur"uckgreifen zu k"onnen, aber gebunden wird
218cdf0e10cSrcweir // wie immer erst sp"ater. Anwendung z.B. wenn im ctor der abgeleiteten
219cdf0e10cSrcweir // Klasse z.B. ein StatusForwarder erzeugt werden soll.
220cdf0e10cSrcweir UnBind();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223cdf0e10cSrcweir
224cdf0e10cSrcweir //--------------------------------------------------------------------
225cdf0e10cSrcweir
226cdf0e10cSrcweir // dtor
227cdf0e10cSrcweir
~SfxMenuControl()228cdf0e10cSrcweir SfxMenuControl::~SfxMenuControl()
229cdf0e10cSrcweir {
230cdf0e10cSrcweir delete pSubMenu;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
RemovePopup()233cdf0e10cSrcweir void SfxMenuControl::RemovePopup()
234cdf0e10cSrcweir {
235cdf0e10cSrcweir DELETEZ( pSubMenu );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir //--------------------------------------------------------------------
239cdf0e10cSrcweir
240cdf0e10cSrcweir // changes the state in the virtual menu
241cdf0e10cSrcweir
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)242cdf0e10cSrcweir void SfxMenuControl::StateChanged
243cdf0e10cSrcweir (
244cdf0e10cSrcweir sal_uInt16 nSID,
245cdf0e10cSrcweir SfxItemState eState,
246cdf0e10cSrcweir const SfxPoolItem* pState
247cdf0e10cSrcweir )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir (void)nSID; //unused
250cdf0e10cSrcweir DBG_MEMTEST();
251cdf0e10cSrcweir DBG_ASSERT( nSID == GetId(), "strange SID" );
252cdf0e10cSrcweir DBG_ASSERT( pOwnMenu != 0, "setting state to dangling SfxMenuControl" );
253cdf0e10cSrcweir
254cdf0e10cSrcweir bool bIsObjMenu =
255cdf0e10cSrcweir GetId() >= SID_OBJECTMENU0 && GetId() < SID_OBJECTMENU_LAST;
256cdf0e10cSrcweir
257cdf0e10cSrcweir // enabled/disabled-Flag pauschal korrigieren
258cdf0e10cSrcweir
259cdf0e10cSrcweir #ifdef UNIX
260cdf0e10cSrcweir if (nSID == SID_PASTE)
261cdf0e10cSrcweir pOwnMenu->EnableItem( GetId(), sal_True );
262cdf0e10cSrcweir else
263cdf0e10cSrcweir #endif
264cdf0e10cSrcweir pOwnMenu->EnableItem( GetId(), bIsObjMenu
265cdf0e10cSrcweir ? 0 != pOwnMenu->GetSVMenu()->GetPopupMenu( GetId() )
266cdf0e10cSrcweir : eState != SFX_ITEM_DISABLED );
267cdf0e10cSrcweir
268cdf0e10cSrcweir if ( eState != SFX_ITEM_AVAILABLE )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir // checken nur bei nicht-Object-Menus
271cdf0e10cSrcweir if ( !bIsObjMenu )
272cdf0e10cSrcweir pOwnMenu->CheckItem( GetId(), sal_False );
273cdf0e10cSrcweir
274cdf0e10cSrcweir // SetItemText flackert in MenuBar insbes. unter OS/2 (Bug #20658)
275cdf0e10cSrcweir if ( // !bIsObjMenu && nicht wegen "Format/Datenbank"
276cdf0e10cSrcweir pOwnMenu->GetSVMenu()->GetItemText( GetId() ) != GetTitle() )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir DBG_WARNING("Title of menu item changed - please check if this needs correction!");
279cdf0e10cSrcweir // pOwnMenu->SetItemText( GetId(), GetTitle() );
280cdf0e10cSrcweir }
281cdf0e10cSrcweir return;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir // ggf. das alte Enum-Menu entfernen/loeschen
285cdf0e10cSrcweir //! delete pOwnMenu->GetMenu().ChangePopupMenu( GetId(), 0 );
286cdf0e10cSrcweir
287cdf0e10cSrcweir bool bCheck = false;
288cdf0e10cSrcweir if ( pState->ISA(SfxBoolItem) )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir // BoolItem fuer checken
291cdf0e10cSrcweir DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
292cdf0e10cSrcweir "SfxBoolItem not allowed for SID_OBJECTMENUx" );
293cdf0e10cSrcweir bCheck = ((const SfxBoolItem*)pState)->GetValue();
294*0deba7fbSSteve Yin Menu* pMenu = pOwnMenu->GetSVMenu();
295*0deba7fbSSteve Yin pMenu->SetItemBits( GetId() , pMenu->GetItemBits( GetId() ) | MIB_CHECKABLE);
296cdf0e10cSrcweir }
297cdf0e10cSrcweir else if ( pState->ISA(SfxEnumItemInterface) &&
298cdf0e10cSrcweir ((SfxEnumItemInterface *)pState)->HasBoolValue() )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir // EnumItem wie Bool behandeln
301cdf0e10cSrcweir DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
302cdf0e10cSrcweir "SfxEnumItem not allowed for SID_OBJECTMENUx" );
303cdf0e10cSrcweir bCheck = ((SfxEnumItemInterface *)pState)->GetBoolValue();
304*0deba7fbSSteve Yin Menu* pMenu = pOwnMenu->GetSVMenu();
305*0deba7fbSSteve Yin pMenu->SetItemBits( GetId() , pMenu->GetItemBits( GetId() ) | MIB_CHECKABLE);
306cdf0e10cSrcweir }
307cdf0e10cSrcweir else if ( ( b_ShowStrings || bIsObjMenu ) && pState->ISA(SfxStringItem) )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir // MenuText aus SfxStringItem holen
310cdf0e10cSrcweir String aStr( ((const SfxStringItem*)pState)->GetValue() );
311cdf0e10cSrcweir if ( aStr.CompareToAscii("($1)",4) == COMPARE_EQUAL )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir String aEntry(SfxResId(STR_UPDATEDOC));
314cdf0e10cSrcweir aEntry += ' ';
315cdf0e10cSrcweir aEntry += aStr.Copy(4);
316cdf0e10cSrcweir aStr = aEntry;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir else if ( aStr.CompareToAscii("($2)",4) == COMPARE_EQUAL )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir String aEntry(SfxResId(STR_CLOSEDOC_ANDRETURN));
321cdf0e10cSrcweir aEntry += aStr.Copy(4);
322cdf0e10cSrcweir aStr = aEntry;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
325cdf0e10cSrcweir pOwnMenu->SetItemText( GetId(), aStr );
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
328cdf0e10cSrcweir #ifdef enum_item_menu_ok
329cdf0e10cSrcweir else if ( aType == TYPE(SfxEnumItem) )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
332cdf0e10cSrcweir "SfxEnumItem not allowed for SID_OBJECTMENUx" );
333cdf0e10cSrcweir pOwnMenu->GetMenu().ChangePopupMenu( GetId(), &GetBindings(),
334cdf0e10cSrcweir new SfxEnumMenu( GetId(), *(const SfxEnumItem*)pState ) );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir #endif
337cdf0e10cSrcweir
338cdf0e10cSrcweir pOwnMenu->CheckItem( GetId(), bCheck );
339cdf0e10cSrcweir }
340cdf0e10cSrcweir
341cdf0e10cSrcweir //--------------------------------------------------------------------
342cdf0e10cSrcweir
CreateImpl(sal_uInt16,Menu &,SfxBindings &)343cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateImpl( sal_uInt16 /*nId*/, Menu& /*rMenu*/, SfxBindings& /*rBindings*/ )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir return new SfxMenuControl( sal_True );
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348cdf0e10cSrcweir //--------------------------------------------------------------------
349cdf0e10cSrcweir
RegisterControl(sal_uInt16 nSlotId,SfxModule * pMod)350cdf0e10cSrcweir void SfxMenuControl::RegisterControl( sal_uInt16 nSlotId, SfxModule *pMod )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir RegisterMenuControl( pMod, new SfxMenuCtrlFactory(
353cdf0e10cSrcweir SfxMenuControl::CreateImpl, TYPE(SfxStringItem), nSlotId ) );
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir //--------------------------------------------------------------------
RegisterMenuControl(SfxModule * pMod,SfxMenuCtrlFactory * pFact)357cdf0e10cSrcweir void SfxMenuControl::RegisterMenuControl(SfxModule* pMod, SfxMenuCtrlFactory* pFact)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir SFX_APP()->RegisterMenuControl_Impl( pMod, pFact );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
CreateControl(sal_uInt16 nId,Menu & rMenu,SfxBindings & rBindings)362cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateControl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir TypeId aSlotType = SFX_SLOTPOOL().GetSlotType(nId);
365cdf0e10cSrcweir if ( aSlotType )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir SfxApplication *pApp = SFX_APP();
368cdf0e10cSrcweir SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
369cdf0e10cSrcweir SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
370cdf0e10cSrcweir if ( pMod )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
373cdf0e10cSrcweir if ( pFactories )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
376cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
377cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType &&
378cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) ||
379cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) )
380cdf0e10cSrcweir return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir }
383cdf0e10cSrcweir
384cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = pApp->GetMenuCtrlFactories_Impl();
385cdf0e10cSrcweir
386cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
387cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType &&
388cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) ||
389cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) )
390cdf0e10cSrcweir return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
391cdf0e10cSrcweir }
392cdf0e10cSrcweir return 0;
393cdf0e10cSrcweir }
394cdf0e10cSrcweir
IsSpecialControl(sal_uInt16 nId,SfxModule * pMod)395cdf0e10cSrcweir sal_Bool SfxMenuControl::IsSpecialControl( sal_uInt16 nId, SfxModule* pMod )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir TypeId aSlotType = SFX_SLOTPOOL().GetSlotType( nId );
398cdf0e10cSrcweir if ( aSlotType )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir if ( pMod )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
403cdf0e10cSrcweir if ( pFactories )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
406cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
407cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType &&
408cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) ||
409cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) )
410cdf0e10cSrcweir return sal_True;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = SFX_APP()->GetMenuCtrlFactories_Impl();
415cdf0e10cSrcweir
416cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
417cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType &&
418cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) ||
419cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) )
420cdf0e10cSrcweir return sal_True;
421cdf0e10cSrcweir }
422cdf0e10cSrcweir return 0;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir //--------------------------------------------------------------------
426cdf0e10cSrcweir
GetPopup() const427cdf0e10cSrcweir PopupMenu* SfxMenuControl::GetPopup () const
428cdf0e10cSrcweir {
429cdf0e10cSrcweir if (GetPopupMenu())
430cdf0e10cSrcweir return (PopupMenu*)GetPopupMenu()->GetSVMenu();
431cdf0e10cSrcweir else
432cdf0e10cSrcweir return 0;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
435cdf0e10cSrcweir long Select_Impl( void* pHdl, void* pVoid );
436cdf0e10cSrcweir
437cdf0e10cSrcweir SFX_IMPL_MENU_CONTROL( SfxAppMenuControl_Impl, SfxStringItem );
438cdf0e10cSrcweir
SfxAppMenuControl_Impl(sal_uInt16 nPos,Menu & rMenu,SfxBindings & rBindings)439cdf0e10cSrcweir SfxAppMenuControl_Impl::SfxAppMenuControl_Impl(
440cdf0e10cSrcweir sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings )
441cdf0e10cSrcweir : SfxMenuControl( nPos, rBindings ), pMenu(0)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir String aText = rMenu.GetItemText( nPos );
444cdf0e10cSrcweir
445cdf0e10cSrcweir // Determine the current background color setting for menus
446cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
447cdf0e10cSrcweir m_nSymbolsStyle = rSettings.GetSymbolsStyle();
448cdf0e10cSrcweir m_bWasHiContrastMode = rSettings.GetHighContrastMode();
449cdf0e10cSrcweir m_bShowMenuImages = rSettings.GetUseImagesInMenus();
450cdf0e10cSrcweir
451cdf0e10cSrcweir Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
452cdf0e10cSrcweir ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
453cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> aXFrame( GetBindings().GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
454cdf0e10cSrcweir pMenu = aConf.CreateBookmarkMenu( aXFrame, GetId() == SID_NEWDOCDIRECT ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU );
455cdf0e10cSrcweir if( pMenu )
456cdf0e10cSrcweir {
457cdf0e10cSrcweir pMenu->SetSelectHdl( Link( &(this->GetBindings()), Select_Impl ) );
458cdf0e10cSrcweir pMenu->SetActivateHdl( LINK(this, SfxAppMenuControl_Impl, Activate) );
459cdf0e10cSrcweir rMenu.SetPopupMenu( nPos, pMenu );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir }
462cdf0e10cSrcweir
~SfxAppMenuControl_Impl()463cdf0e10cSrcweir SfxAppMenuControl_Impl::~SfxAppMenuControl_Impl()
464cdf0e10cSrcweir {
465cdf0e10cSrcweir delete pMenu;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
IMPL_LINK(SfxAppMenuControl_Impl,Activate,Menu *,pActMenu)468cdf0e10cSrcweir IMPL_LINK( SfxAppMenuControl_Impl, Activate, Menu *, pActMenu )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir if ( pActMenu )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
473cdf0e10cSrcweir sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle();
474cdf0e10cSrcweir sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode();
475cdf0e10cSrcweir sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
476cdf0e10cSrcweir
477cdf0e10cSrcweir if (( nSymbolsStyle != m_nSymbolsStyle ) ||
478cdf0e10cSrcweir ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
479cdf0e10cSrcweir ( bShowMenuImages != m_bShowMenuImages ))
480cdf0e10cSrcweir {
481cdf0e10cSrcweir m_nSymbolsStyle = nSymbolsStyle;
482cdf0e10cSrcweir m_bWasHiContrastMode = bIsHiContrastMode;
483cdf0e10cSrcweir m_bShowMenuImages = bShowMenuImages;
484cdf0e10cSrcweir
485cdf0e10cSrcweir sal_uInt16 nCount = pActMenu->GetItemCount();
486cdf0e10cSrcweir for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ )
487cdf0e10cSrcweir {
488cdf0e10cSrcweir sal_uInt16 nItemId = pActMenu->GetItemId( nSVPos );
489cdf0e10cSrcweir if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir if ( bShowMenuImages )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir sal_Bool bImageSet = sal_False;
494cdf0e10cSrcweir ::rtl::OUString aImageId;
495cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes =
496cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
497cdf0e10cSrcweir
498cdf0e10cSrcweir if ( pMenuAttributes )
499cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
500cdf0e10cSrcweir
501cdf0e10cSrcweir if ( aImageId.getLength() > 0 )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir Reference< ::com::sun::star::frame::XFrame > xFrame;
504cdf0e10cSrcweir Image aImage = GetImage( xFrame, aImageId, sal_False, bIsHiContrastMode );
505cdf0e10cSrcweir if ( !!aImage )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir bImageSet = sal_True;
508cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, aImage );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir String aCmd( pActMenu->GetItemCommand( nItemId ) );
513cdf0e10cSrcweir if ( !bImageSet && aCmd.Len() )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir Image aImage = SvFileInformationManager::GetImage(
516cdf0e10cSrcweir INetURLObject(aCmd), sal_False, bIsHiContrastMode );
517cdf0e10cSrcweir if ( !!aImage )
518cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, aImage );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir else
522cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, Image() );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir }
525cdf0e10cSrcweir }
526cdf0e10cSrcweir
527cdf0e10cSrcweir return sal_True;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
530cdf0e10cSrcweir return sal_False;
531cdf0e10cSrcweir }
532cdf0e10cSrcweir
CreateControl(const String & rCmd,sal_uInt16 nId,Menu & rMenu,SfxBindings & rBindings,SfxVirtualMenu * pVirt)533cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
534cdf0e10cSrcweir sal_uInt16 nId, Menu& rMenu, SfxBindings &rBindings, SfxVirtualMenu* pVirt )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir return new SfxUnoMenuControl( rCmd, nId, rMenu, rBindings, pVirt );
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
CreateControl(const String & rCmd,sal_uInt16 nId,Menu & rMenu,const String & sItemText,const String & sHelpText,SfxBindings & rBindings,SfxVirtualMenu * pVirt)539cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
540cdf0e10cSrcweir sal_uInt16 nId, Menu& rMenu, const String& sItemText, const String& sHelpText,
541cdf0e10cSrcweir SfxBindings& rBindings, SfxVirtualMenu* pVirt)
542cdf0e10cSrcweir {
543cdf0e10cSrcweir return new SfxUnoMenuControl( rCmd, nId, rMenu, sItemText, sHelpText, rBindings, pVirt);
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
SfxUnoMenuControl(const String & rCmd,sal_uInt16 nSlotId,Menu & rMenu,SfxBindings & rBindings,SfxVirtualMenu * pVirt)546cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl( const String& rCmd, sal_uInt16 nSlotId,
547cdf0e10cSrcweir Menu& rMenu, SfxBindings& rBindings, SfxVirtualMenu* pVirt )
548cdf0e10cSrcweir : SfxMenuControl( nSlotId, rBindings )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir Bind( pVirt, nSlotId, rMenu.GetItemText(nSlotId),
551cdf0e10cSrcweir rMenu.GetHelpText(nSlotId), rBindings);
552cdf0e10cSrcweir UnBind();
553cdf0e10cSrcweir pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
554cdf0e10cSrcweir pUnoCtrl->acquire();
555cdf0e10cSrcweir pUnoCtrl->GetNewDispatch();
556cdf0e10cSrcweir }
557cdf0e10cSrcweir
SfxUnoMenuControl(const String & rCmd,sal_uInt16 nSlotId,Menu &,const String & rItemText,const String & rHelpText,SfxBindings & rBindings,SfxVirtualMenu * pVirt)558cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl(
559cdf0e10cSrcweir const String& rCmd, sal_uInt16 nSlotId, Menu& /*rMenu*/,
560cdf0e10cSrcweir const String& rItemText, const String& rHelpText,
561cdf0e10cSrcweir SfxBindings& rBindings, SfxVirtualMenu* pVirt)
562cdf0e10cSrcweir : SfxMenuControl( nSlotId, rBindings )
563cdf0e10cSrcweir {
564cdf0e10cSrcweir Bind( pVirt, nSlotId, rItemText, rHelpText, rBindings);
565cdf0e10cSrcweir UnBind();
566cdf0e10cSrcweir pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
567cdf0e10cSrcweir pUnoCtrl->acquire();
568cdf0e10cSrcweir pUnoCtrl->GetNewDispatch();
569cdf0e10cSrcweir }
570cdf0e10cSrcweir
~SfxUnoMenuControl()571cdf0e10cSrcweir SfxUnoMenuControl::~SfxUnoMenuControl()
572cdf0e10cSrcweir {
573cdf0e10cSrcweir pUnoCtrl->UnBind();
574cdf0e10cSrcweir pUnoCtrl->release();
575cdf0e10cSrcweir }
576cdf0e10cSrcweir
Select()577cdf0e10cSrcweir void SfxUnoMenuControl::Select()
578cdf0e10cSrcweir {
579cdf0e10cSrcweir pUnoCtrl->Execute();
580cdf0e10cSrcweir }
581595fd105SAriel Constenla-Haile
Select_Impl(void *,void * pVoid)582595fd105SAriel Constenla-Haile long Select_Impl( void* /*pHdl*/, void* pVoid )
583595fd105SAriel Constenla-Haile {
584595fd105SAriel Constenla-Haile Menu* pMenu = (Menu*)pVoid;
585595fd105SAriel Constenla-Haile String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
586595fd105SAriel Constenla-Haile
587595fd105SAriel Constenla-Haile if( !aURL.Len() )
588595fd105SAriel Constenla-Haile return 0;
589595fd105SAriel Constenla-Haile
590595fd105SAriel Constenla-Haile Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop =
591595fd105SAriel Constenla-Haile Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
592595fd105SAriel Constenla-Haile DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
593595fd105SAriel Constenla-Haile Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
594595fd105SAriel Constenla-Haile
595595fd105SAriel Constenla-Haile URL aTargetURL;
596595fd105SAriel Constenla-Haile aTargetURL.Complete = aURL;
597595fd105SAriel Constenla-Haile Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
598595fd105SAriel Constenla-Haile rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
599595fd105SAriel Constenla-Haile UNO_QUERY );
600595fd105SAriel Constenla-Haile xTrans->parseStrict( aTargetURL );
601595fd105SAriel Constenla-Haile
602595fd105SAriel Constenla-Haile Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
603595fd105SAriel Constenla-Haile Reference < XDispatch > xDisp;
604595fd105SAriel Constenla-Haile if ( xProv.is() )
605595fd105SAriel Constenla-Haile {
606595fd105SAriel Constenla-Haile if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
607595fd105SAriel Constenla-Haile xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
608595fd105SAriel Constenla-Haile else
609595fd105SAriel Constenla-Haile {
610595fd105SAriel Constenla-Haile ::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
611595fd105SAriel Constenla-Haile ::framework::MenuConfiguration::Attributes* pMenuAttributes =
612595fd105SAriel Constenla-Haile (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
613595fd105SAriel Constenla-Haile
614595fd105SAriel Constenla-Haile if ( pMenuAttributes )
615595fd105SAriel Constenla-Haile aTargetFrame = pMenuAttributes->aTargetFrame;
616595fd105SAriel Constenla-Haile
617595fd105SAriel Constenla-Haile xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
618595fd105SAriel Constenla-Haile }
619595fd105SAriel Constenla-Haile }
620595fd105SAriel Constenla-Haile
621595fd105SAriel Constenla-Haile if ( xDisp.is() )
622595fd105SAriel Constenla-Haile {
623595fd105SAriel Constenla-Haile SfxAppMenuControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppMenuControl_Impl::ExecuteInfo;
624595fd105SAriel Constenla-Haile pExecuteInfo->xDispatch = xDisp;
625595fd105SAriel Constenla-Haile pExecuteInfo->aTargetURL = aTargetURL;
626595fd105SAriel Constenla-Haile pExecuteInfo->aArgs = Sequence< PropertyValue >();
627595fd105SAriel Constenla-Haile Application::PostUserEvent( STATIC_LINK( 0, SfxAppMenuControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
628595fd105SAriel Constenla-Haile }
629595fd105SAriel Constenla-Haile
630595fd105SAriel Constenla-Haile return sal_True;
631595fd105SAriel Constenla-Haile }
632595fd105SAriel Constenla-Haile
633595fd105SAriel Constenla-Haile
IMPL_STATIC_LINK_NOINSTANCE(SfxAppMenuControl_Impl,ExecuteHdl_Impl,ExecuteInfo *,pExecuteInfo)634595fd105SAriel Constenla-Haile IMPL_STATIC_LINK_NOINSTANCE( SfxAppMenuControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
635595fd105SAriel Constenla-Haile {
636595fd105SAriel Constenla-Haile pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
637595fd105SAriel Constenla-Haile delete pExecuteInfo;
638595fd105SAriel Constenla-Haile return 0;
639595fd105SAriel Constenla-Haile }
640