1*01aa44aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*01aa44aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*01aa44aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*01aa44aaSAndrew Rist  * distributed with this work for additional information
6*01aa44aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*01aa44aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*01aa44aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*01aa44aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*01aa44aaSAndrew Rist  *
11*01aa44aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*01aa44aaSAndrew Rist  *
13*01aa44aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*01aa44aaSAndrew Rist  * software distributed under the License is distributed on an
15*01aa44aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*01aa44aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*01aa44aaSAndrew Rist  * specific language governing permissions and limitations
18*01aa44aaSAndrew Rist  * under the License.
19*01aa44aaSAndrew Rist  *
20*01aa44aaSAndrew Rist  *************************************************************/
21*01aa44aaSAndrew Rist 
22*01aa44aaSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
25cdf0e10cSrcweir #define INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
28cdf0e10cSrcweir #include <com/sun/star/awt/XPopupMenu.hpp>
29cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ui/XImageManager.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <rtl/ustring.hxx>
34cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
35cdf0e10cSrcweir #include <vcl/menu.hxx>
36cdf0e10cSrcweir #include "svtools/svtdllapi.h"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace svt
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /**
42cdf0e10cSrcweir     Context menu helper class.
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     Fills images and labels for a provided popup menu or
45cdf0e10cSrcweir     com.sun.star.awt.XPopupMenu.
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     PRECONDITION:
48cdf0e10cSrcweir     All commands must be set via SetItemCommand and are part
49cdf0e10cSrcweir     of the configuration files
50cdf0e10cSrcweir     (see org.openoffice.Office.UI.[Module]Commands.xcu)
51cdf0e10cSrcweir */
52cdf0e10cSrcweir struct ExecuteInfo;
53cdf0e10cSrcweir class SVT_DLLPUBLIC ContextMenuHelper
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     public:
56cdf0e10cSrcweir         // create context menu helper
57cdf0e10cSrcweir         // ARGS: xFrame = frame defines the context of the context menu
58cdf0e10cSrcweir         //       bAutoRefresh = specifies that the context will be constant or not
59cdf0e10cSrcweir         ContextMenuHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, bool bAutoRefresh=true );
60cdf0e10cSrcweir         ~ContextMenuHelper();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         // methods to complete a popup menu (set images, labels, enable/disable states)
63cdf0e10cSrcweir         // ATTENTION: The item ID's must be unique for the whole popup (inclusive the sub menus!)
64cdf0e10cSrcweir         void completeAndExecute( const Point& aPos, PopupMenu& aPopupMenu );
65cdf0e10cSrcweir         void completeAndExecute( const Point& aPos, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& xPopupMenu );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         // methods to create a popup menu referenced by resource URL
68cdf0e10cSrcweir         // NOT IMPLEMENTED YET!
69cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > create( const ::rtl::OUString& aPopupMenuResourceURL );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         // method to create and execute a popup menu referenced by a resource URL
72cdf0e10cSrcweir         // NOT IMPLEMENTED YET!
73cdf0e10cSrcweir         bool createAndExecute( const Point& aPos, const ::rtl::OUString& aPopupMenuResourceURL );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     private:
76cdf0e10cSrcweir         // asynchronous link to prevent destruction while on stack
77cdf0e10cSrcweir         DECL_STATIC_LINK( ContextMenuHelper, ExecuteHdl_Impl, ExecuteInfo* );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         // no copy-ctor and operator=
80cdf0e10cSrcweir         ContextMenuHelper( const ContextMenuHelper& );
81cdf0e10cSrcweir         const ContextMenuHelper& operator=( const ContextMenuHelper& );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // show context menu and dispatch command automatically
84cdf0e10cSrcweir         void            executePopupMenu( const Point& aPos, PopupMenu* pMenu );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         // fill image and label for every menu item on the provided menu
87cdf0e10cSrcweir         void            completeMenuProperties( Menu* pMenu );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         // dispatch provided command
90cdf0e10cSrcweir         bool            dispatchCommand( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& aCommandURL );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         // methods to retrieve a single command URL dependent value from a
94cdf0e10cSrcweir         // ui configuratin manager
95cdf0e10cSrcweir         Image           getImageFromCommandURL( const ::rtl::OUString& aCmdURL, bool bHiContrast ) const;
96cdf0e10cSrcweir         rtl::OUString   getLabelFromCommandURL( const ::rtl::OUString& aCmdURL ) const;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         // creates an association between current module/controller bound to the
99cdf0e10cSrcweir         // provided frame and their ui configuration managers.
100cdf0e10cSrcweir         bool            associateUIConfigurationManagers();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         // resets associations to create associations again on-demand.
103cdf0e10cSrcweir         // Usefull for implementations which recycle frames. Normal
104cdf0e10cSrcweir         // implementations can profit from caching and should set
105cdf0e10cSrcweir         // auto refresh on ctor to false (default).
resetAssociations()106cdf0e10cSrcweir         void            resetAssociations()
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             if ( m_bAutoRefresh )
109cdf0e10cSrcweir                 m_bUICfgMgrAssociated = false;
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame >         m_xWeakFrame;
113cdf0e10cSrcweir         ::rtl::OUString                                                                 m_aModuleIdentifier;
114cdf0e10cSrcweir         ::rtl::OUString                                                                 m_aSelf;
115cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >     m_xURLTransformer;
116cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >       m_aDefaultArgs;
117cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >         m_xDocImageMgr;
118cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >         m_xModuleImageMgr;
119cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    m_xUICommandLabels;
120cdf0e10cSrcweir         bool                                                                            m_bAutoRefresh;
121cdf0e10cSrcweir         bool                                                                            m_bUICfgMgrAssociated;
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir } // namespace svt
125cdf0e10cSrcweir 
126cdf0e10cSrcweir #endif // INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
127