1*f8e07b45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f8e07b45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f8e07b45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f8e07b45SAndrew Rist * distributed with this work for additional information 6*f8e07b45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f8e07b45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f8e07b45SAndrew Rist * "License"); you may not use this file except in compliance 9*f8e07b45SAndrew Rist * with the License. You may obtain a copy of the License at 10*f8e07b45SAndrew Rist * 11*f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f8e07b45SAndrew Rist * 13*f8e07b45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f8e07b45SAndrew Rist * software distributed under the License is distributed on an 15*f8e07b45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f8e07b45SAndrew Rist * KIND, either express or implied. See the License for the 17*f8e07b45SAndrew Rist * specific language governing permissions and limitations 18*f8e07b45SAndrew Rist * under the License. 19*f8e07b45SAndrew Rist * 20*f8e07b45SAndrew Rist *************************************************************/ 21*f8e07b45SAndrew Rist 22*f8e07b45SAndrew Rist 23cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 24cdf0e10cSrcweir #define __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 25cdf0e10cSrcweir 26cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 27cdf0e10cSrcweir // interface includes 28cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 35cdf0e10cSrcweir // includes of other projects 36cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <vcl/menu.hxx> 39cdf0e10cSrcweir #include <framework/fwedllapi.h> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #define ADDONMENU_ITEMID_START 2000 42cdf0e10cSrcweir #define ADDONMENU_ITEMID_END 3000 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace framework 45cdf0e10cSrcweir { 46cdf0e10cSrcweir 47cdf0e10cSrcweir class FWE_DLLPUBLIC AddonMenu : public PopupMenu 48cdf0e10cSrcweir { 49cdf0e10cSrcweir public: 50cdf0e10cSrcweir AddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ); 51cdf0e10cSrcweir ~AddonMenu(); 52cdf0e10cSrcweir 53cdf0e10cSrcweir protected: 54cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir 57cdf0e10cSrcweir class AddonMenuManager; 58cdf0e10cSrcweir class FWE_DLLPUBLIC AddonPopupMenu : public AddonMenu 59cdf0e10cSrcweir { 60cdf0e10cSrcweir public: 61cdf0e10cSrcweir ~AddonPopupMenu(); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Check if command URL string has the unique prefix to identify addon popup menus 64cdf0e10cSrcweir static sal_Bool IsCommandURLPrefix( const rtl::OUString& aCmdURL ); 65cdf0e10cSrcweir SetCommandURL(const rtl::OUString & aCmdURL)66cdf0e10cSrcweir void SetCommandURL( const rtl::OUString& aCmdURL ) { m_aCommandURL = aCmdURL; } GetCommandURL() const67cdf0e10cSrcweir const rtl::OUString& GetCommandURL() const { return m_aCommandURL; } 68cdf0e10cSrcweir 69cdf0e10cSrcweir protected: 70cdf0e10cSrcweir void Initialize( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonPopupMenuDefinition ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir private: 73cdf0e10cSrcweir AddonPopupMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir rtl::OUString m_aCommandURL; 76cdf0e10cSrcweir 77cdf0e10cSrcweir friend class AddonMenuManager; 78cdf0e10cSrcweir }; 79cdf0e10cSrcweir 80cdf0e10cSrcweir class FWE_DLLPUBLIC AddonMenuManager 81cdf0e10cSrcweir { 82cdf0e10cSrcweir public: 83cdf0e10cSrcweir enum MenuType 84cdf0e10cSrcweir { 85cdf0e10cSrcweir ADDON_MENU, 86cdf0e10cSrcweir ADDON_POPUPMENU 87cdf0e10cSrcweir }; 88cdf0e10cSrcweir 89cdf0e10cSrcweir static sal_Bool HasAddonMenuElements(); 90cdf0e10cSrcweir static sal_Bool HasAddonHelpMenuElements(); 91cdf0e10cSrcweir IsAddonMenuId(sal_uInt16 nId)92cdf0e10cSrcweir static sal_Bool IsAddonMenuId( sal_uInt16 nId ) { return (( nId >= ADDONMENU_ITEMID_START ) && ( nId < ADDONMENU_ITEMID_END )); } 93cdf0e10cSrcweir 94cdf0e10cSrcweir // Check if the context string matches the provided xModel context 95cdf0e10cSrcweir static sal_Bool IsCorrectContext( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rModel, const rtl::OUString& aContext ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir // Factory method to create different Add-On menu types 98cdf0e10cSrcweir static PopupMenu* CreatePopupMenuType( MenuType eMenuType, const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // Create the Add-Ons menu 101cdf0e10cSrcweir static AddonMenu* CreateAddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir // Merge the Add-Ons help menu items into the given menu bar at a defined pos 104cdf0e10cSrcweir static void MergeAddonHelpMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 105cdf0e10cSrcweir MenuBar* pMergeMenuBar ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // Merge the addon popup menus into the given menu bar at the provided pos. 108cdf0e10cSrcweir static void MergeAddonPopupMenus( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 109cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel, 110cdf0e10cSrcweir sal_uInt16 nMergeAtPos, 111cdf0e10cSrcweir MenuBar* pMergeMenuBar ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir // Returns the next position to insert a menu item/sub menu 114cdf0e10cSrcweir static sal_uInt16 GetNextPos( sal_uInt16 nPos ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir // Build up the menu item and sub menu into the provided pCurrentMenu. The sub menus should be of type nSubMenuType. 117cdf0e10cSrcweir static void BuildMenu( PopupMenu* pCurrentMenu, 118cdf0e10cSrcweir MenuType nSubMenuType, 119cdf0e10cSrcweir sal_uInt16 nInsPos, 120cdf0e10cSrcweir sal_uInt16& nUniqueMenuId, 121cdf0e10cSrcweir com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > > aAddonMenuDefinition, 122cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, 123cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // Retrieve the menu entry property values from a sequence 126cdf0e10cSrcweir static void GetMenuEntry( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonMenuEntry, 127cdf0e10cSrcweir ::rtl::OUString& rTitle, 128cdf0e10cSrcweir ::rtl::OUString& rURL, 129cdf0e10cSrcweir ::rtl::OUString& rTarget, 130cdf0e10cSrcweir ::rtl::OUString& rImageId, 131cdf0e10cSrcweir ::rtl::OUString& rContext, 132cdf0e10cSrcweir com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > >& rAddonSubMenu ); 133cdf0e10cSrcweir }; 134cdf0e10cSrcweir 135cdf0e10cSrcweir } // namespace framework 136cdf0e10cSrcweir 137cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_ 138