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 #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 24 #define __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 25 26 //_________________________________________________________________________________________________________________ 27 // interface includes 28 //_________________________________________________________________________________________________________________ 29 30 #include <com/sun/star/frame/XFrame.hpp> 31 #include <com/sun/star/beans/PropertyValue.hpp> 32 #include <com/sun/star/uno/Sequence.hxx> 33 34 //_________________________________________________________________________________________________________________ 35 // includes of other projects 36 //_________________________________________________________________________________________________________________ 37 38 #include <vcl/menu.hxx> 39 #include <framework/fwedllapi.h> 40 41 #define ADDONMENU_ITEMID_START 2000 42 #define ADDONMENU_ITEMID_END 3000 43 44 namespace framework 45 { 46 47 class FWE_DLLPUBLIC AddonMenu : public PopupMenu 48 { 49 public: 50 AddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ); 51 ~AddonMenu(); 52 53 protected: 54 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; 55 }; 56 57 class AddonMenuManager; 58 class FWE_DLLPUBLIC AddonPopupMenu : public AddonMenu 59 { 60 public: 61 ~AddonPopupMenu(); 62 63 // Check if command URL string has the unique prefix to identify addon popup menus 64 static sal_Bool IsCommandURLPrefix( const rtl::OUString& aCmdURL ); 65 SetCommandURL(const rtl::OUString & aCmdURL)66 void SetCommandURL( const rtl::OUString& aCmdURL ) { m_aCommandURL = aCmdURL; } GetCommandURL() const67 const rtl::OUString& GetCommandURL() const { return m_aCommandURL; } 68 69 protected: 70 void Initialize( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonPopupMenuDefinition ); 71 72 private: 73 AddonPopupMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame ); 74 75 rtl::OUString m_aCommandURL; 76 77 friend class AddonMenuManager; 78 }; 79 80 class FWE_DLLPUBLIC AddonMenuManager 81 { 82 public: 83 enum MenuType 84 { 85 ADDON_MENU, 86 ADDON_POPUPMENU 87 }; 88 89 static sal_Bool HasAddonMenuElements(); 90 static sal_Bool HasAddonHelpMenuElements(); 91 IsAddonMenuId(sal_uInt16 nId)92 static sal_Bool IsAddonMenuId( sal_uInt16 nId ) { return (( nId >= ADDONMENU_ITEMID_START ) && ( nId < ADDONMENU_ITEMID_END )); } 93 94 // Check if the context string matches the provided xModel context 95 static sal_Bool IsCorrectContext( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rModel, const rtl::OUString& aContext ); 96 97 // Factory method to create different Add-On menu types 98 static PopupMenu* CreatePopupMenuType( MenuType eMenuType, const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame ); 99 100 // Create the Add-Ons menu 101 static AddonMenu* CreateAddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ); 102 103 // Merge the Add-Ons help menu items into the given menu bar at a defined pos 104 static void MergeAddonHelpMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 105 MenuBar* pMergeMenuBar ); 106 107 // Merge the addon popup menus into the given menu bar at the provided pos. 108 static void MergeAddonPopupMenus( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 109 const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel, 110 sal_uInt16 nMergeAtPos, 111 MenuBar* pMergeMenuBar ); 112 113 // Returns the next position to insert a menu item/sub menu 114 static sal_uInt16 GetNextPos( sal_uInt16 nPos ); 115 116 // Build up the menu item and sub menu into the provided pCurrentMenu. The sub menus should be of type nSubMenuType. 117 static void BuildMenu( PopupMenu* pCurrentMenu, 118 MenuType nSubMenuType, 119 sal_uInt16 nInsPos, 120 sal_uInt16& nUniqueMenuId, 121 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > > aAddonMenuDefinition, 122 const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 123 const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel ); 124 125 // Retrieve the menu entry property values from a sequence 126 static void GetMenuEntry( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonMenuEntry, 127 ::rtl::OUString& rTitle, 128 ::rtl::OUString& rURL, 129 ::rtl::OUString& rTarget, 130 ::rtl::OUString& rImageId, 131 ::rtl::OUString& rContext, 132 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > >& rAddonSubMenu ); 133 }; 134 135 } // namespace framework 136 137 #endif // #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 138