Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
30 : : #define INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
31 : :
32 : : #include <com/sun/star/frame/XFrame.hpp>
33 : : #include <com/sun/star/awt/XPopupMenu.hpp>
34 : : #include <com/sun/star/util/XURLTransformer.hpp>
35 : : #include <com/sun/star/ui/XImageManager.hpp>
36 : : #include <com/sun/star/container/XNameAccess.hpp>
37 : :
38 : : #include <rtl/ustring.hxx>
39 : : #include <cppuhelper/weak.hxx>
40 : : #include <vcl/menu.hxx>
41 : : #include "svtools/svtdllapi.h"
42 : :
43 : : namespace svt
44 : : {
45 : :
46 : : /**
47 : : Context menu helper class.
48 : :
49 : : Fills images and labels for a provided popup menu or
50 : : com.sun.star.awt.XPopupMenu.
51 : :
52 : : PRECONDITION:
53 : : All commands must be set via SetItemCommand and are part
54 : : of the configuration files
55 : : (see org.openoffice.Office.UI.[Module]Commands.xcu)
56 : : */
57 : : struct ExecuteInfo;
58 : : class SVT_DLLPUBLIC ContextMenuHelper
59 : : {
60 : : public:
61 : : // create context menu helper
62 : : // ARGS: xFrame = frame defines the context of the context menu
63 : : // bAutoRefresh = specifies that the context will be constant or not
64 : : ContextMenuHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, bool bAutoRefresh=true );
65 : : ~ContextMenuHelper();
66 : :
67 : : // methods to complete a popup menu (set images, labels, enable/disable states)
68 : : // ATTENTION: The item ID's must be unique for the whole popup (inclusive the sub menus!)
69 : : void completeAndExecute( const Point& aPos, PopupMenu& aPopupMenu );
70 : : void completeAndExecute( const Point& aPos, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& xPopupMenu );
71 : :
72 : : private:
73 : : // asynchronous link to prevent destruction while on stack
74 : : DECL_STATIC_LINK( ContextMenuHelper, ExecuteHdl_Impl, ExecuteInfo* );
75 : :
76 : : // no copy-ctor and operator=
77 : : ContextMenuHelper( const ContextMenuHelper& );
78 : : const ContextMenuHelper& operator=( const ContextMenuHelper& );
79 : :
80 : : // show context menu and dispatch command automatically
81 : : void executePopupMenu( const Point& aPos, PopupMenu* pMenu );
82 : :
83 : : // fill image and label for every menu item on the provided menu
84 : : void completeMenuProperties( Menu* pMenu );
85 : :
86 : : // dispatch provided command
87 : : bool dispatchCommand( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& aCommandURL );
88 : :
89 : :
90 : : // methods to retrieve a single command URL dependent value from a
91 : : // ui configuratin manager
92 : : Image getImageFromCommandURL( const ::rtl::OUString& aCmdURL ) const;
93 : : rtl::OUString getLabelFromCommandURL( const ::rtl::OUString& aCmdURL ) const;
94 : :
95 : : // creates an association between current module/controller bound to the
96 : : // provided frame and their ui configuration managers.
97 : : bool associateUIConfigurationManagers();
98 : :
99 : : // resets associations to create associations again on-demand.
100 : : // Usefull for implementations which recycle frames. Normal
101 : : // implementations can profit from caching and should set
102 : : // auto refresh on ctor to false (default).
103 : 0 : void resetAssociations()
104 : : {
105 [ # # ]: 0 : if ( m_bAutoRefresh )
106 : 0 : m_bUICfgMgrAssociated = false;
107 : 0 : }
108 : :
109 : : ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > m_xWeakFrame;
110 : : ::rtl::OUString m_aModuleIdentifier;
111 : : ::rtl::OUString m_aSelf;
112 : : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
113 : : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aDefaultArgs;
114 : : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageMgr;
115 : : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageMgr;
116 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xUICommandLabels;
117 : : bool m_bAutoRefresh;
118 : : bool m_bUICfgMgrAssociated;
119 : : };
120 : :
121 : : } // namespace svt
122 : :
123 : : #endif // INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
124 : :
125 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|