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