fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / svtools / contextmenuhelper.hxx
blob258da5dedbfb47e32ed676cdc93ed6bf5ec315cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
21 #define INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
23 #include <com/sun/star/frame/XFrame.hpp>
24 #include <com/sun/star/awt/XPopupMenu.hpp>
25 #include <com/sun/star/util/XURLTransformer.hpp>
26 #include <com/sun/star/ui/XImageManager.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <rtl/ustring.hxx>
30 #include <cppuhelper/weak.hxx>
31 #include <vcl/menu.hxx>
32 #include "svtools/svtdllapi.h"
34 namespace svt
37 /**
38 Context menu helper class.
40 Fills images and labels for a provided popup menu or
41 com.sun.star.awt.XPopupMenu.
43 PRECONDITION:
44 All commands must be set via SetItemCommand and are part
45 of the configuration files
46 (see org.openoffice.Office.UI.[Module]Commands.xcu)
48 struct ExecuteInfo;
49 class SVT_DLLPUBLIC ContextMenuHelper
51 public:
52 // create context menu helper
53 // ARGS: xFrame = frame defines the context of the context menu
54 // bAutoRefresh = specifies that the context will be constant or not
55 ContextMenuHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, bool bAutoRefresh=true );
56 ~ContextMenuHelper();
58 // methods to complete a popup menu (set images, labels, enable/disable states)
59 // ATTENTION: The item ID's must be unique for the whole popup (inclusive the sub menus!)
60 void completeAndExecute( const Point& aPos, PopupMenu& aPopupMenu );
61 void completeAndExecute( const Point& aPos, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& xPopupMenu );
63 private:
64 // asynchronous link to prevent destruction while on stack
65 DECL_STATIC_LINK( ContextMenuHelper, ExecuteHdl_Impl, ExecuteInfo* );
67 // no copy-ctor and operator=
68 ContextMenuHelper( const ContextMenuHelper& );
69 const ContextMenuHelper& operator=( const ContextMenuHelper& );
71 // show context menu and dispatch command automatically
72 void executePopupMenu( const Point& aPos, PopupMenu* pMenu );
74 // fill image and label for every menu item on the provided menu
75 void completeMenuProperties( Menu* pMenu );
77 // dispatch provided command
78 bool dispatchCommand( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const OUString& aCommandURL );
81 // methods to retrieve a single command URL dependent value from a
82 // ui configuratin manager
83 Image getImageFromCommandURL( const OUString& aCmdURL ) const;
84 OUString getLabelFromCommandURL( const OUString& aCmdURL ) const;
86 // creates an association between current module/controller bound to the
87 // provided frame and their ui configuration managers.
88 bool associateUIConfigurationManagers();
90 // resets associations to create associations again on-demand.
91 // Useful for implementations which recycle frames. Normal
92 // implementations can profit from caching and should set
93 // auto refresh on ctor to false (default).
94 void resetAssociations()
96 if ( m_bAutoRefresh )
97 m_bUICfgMgrAssociated = false;
100 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > m_xWeakFrame;
101 OUString m_aModuleIdentifier;
102 OUString m_aSelf;
103 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
104 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aDefaultArgs;
105 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageMgr;
106 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageMgr;
107 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xUICommandLabels;
108 bool m_bAutoRefresh;
109 bool m_bUICfgMgrAssociated;
112 } // namespace svt
114 #endif // INCLUDED_SVTOOLS_CONTEXTMENUHELPER_HXX
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */