update dev300-m57
[ooovba.git] / svtools / inc / contextmenuhelper.hxx
blobad8bae1de760c4be14382d88deb900cbb03de99b
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: contextmenuhelper.hxx,v $
10 * $Revision: 1.3 $
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 #ifndef INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
32 #define INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/awt/XPopupMenu.hpp>
36 #include <com/sun/star/util/XURLTransformer.hpp>
37 #include <com/sun/star/ui/XImageManager.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <rtl/ustring.hxx>
41 #include <cppuhelper/weak.hxx>
42 #include <vcl/menu.hxx>
43 #include "svtools/svtdllapi.h"
45 namespace svt
48 /**
49 Context menu helper class.
51 Fills images and labels for a provided popup menu or
52 com.sun.star.awt.XPopupMenu.
54 PRECONDITION:
55 All commands must be set via SetItemCommand and are part
56 of the configuration files
57 (see org.openoffice.Office.UI.[Module]Commands.xcu)
59 struct ExecuteInfo;
60 class SVT_DLLPUBLIC ContextMenuHelper
62 public:
63 // create context menu helper
64 // ARGS: xFrame = frame defines the context of the context menu
65 // bAutoRefresh = specifies that the context will be constant or not
66 ContextMenuHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, bool bAutoRefresh=true );
67 ~ContextMenuHelper();
69 // methods to complete a popup menu (set images, labels, enable/disable states)
70 // ATTENTION: The item ID's must be unique for the whole popup (inclusive the sub menus!)
71 void completeAndExecute( const Point& aPos, PopupMenu& aPopupMenu );
72 void completeAndExecute( const Point& aPos, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& xPopupMenu );
74 // methods to create a popup menu referenced by resource URL
75 // NOT IMPLEMENTED YET!
76 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > create( const ::rtl::OUString& aPopupMenuResourceURL );
78 // method to create and execute a popup menu referenced by a resource URL
79 // NOT IMPLEMENTED YET!
80 bool createAndExecute( const Point& aPos, const ::rtl::OUString& aPopupMenuResourceURL );
82 private:
83 // asynchronous link to prevent destruction while on stack
84 DECL_STATIC_LINK( ContextMenuHelper, ExecuteHdl_Impl, ExecuteInfo* );
86 // no copy-ctor and operator=
87 ContextMenuHelper( const ContextMenuHelper& );
88 const ContextMenuHelper& operator=( const ContextMenuHelper& );
90 // show context menu and dispatch command automatically
91 void executePopupMenu( const Point& aPos, PopupMenu* pMenu );
93 // fill image and label for every menu item on the provided menu
94 void completeMenuProperties( Menu* pMenu );
96 // dispatch provided command
97 bool dispatchCommand( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& aCommandURL );
100 // methods to retrieve a single command URL dependent value from a
101 // ui configuratin manager
102 Image getImageFromCommandURL( const ::rtl::OUString& aCmdURL, bool bHiContrast ) const;
103 rtl::OUString getLabelFromCommandURL( const ::rtl::OUString& aCmdURL ) const;
105 // creates an association between current module/controller bound to the
106 // provided frame and their ui configuration managers.
107 bool associateUIConfigurationManagers();
109 // resets associations to create associations again on-demand.
110 // Usefull for implementations which recycle frames. Normal
111 // implementations can profit from caching and should set
112 // auto refresh on ctor to false (default).
113 void resetAssociations()
115 if ( m_bAutoRefresh )
116 m_bUICfgMgrAssociated = false;
119 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > m_xWeakFrame;
120 ::rtl::OUString m_aModuleIdentifier;
121 ::rtl::OUString m_aSelf;
122 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
123 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aDefaultArgs;
124 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageMgr;
125 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageMgr;
126 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xUICommandLabels;
127 bool m_bAutoRefresh;
128 bool m_bUICfgMgrAssociated;
131 } // namespace svt
133 #endif // INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX