1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_
28 #define __FRAMEWORK_CLASSES_ADDONMENU_HXX_
29 
30 //_________________________________________________________________________________________________________________
31 //	interface includes
32 //_________________________________________________________________________________________________________________
33 
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 //_________________________________________________________________________________________________________________
39 //	includes of other projects
40 //_________________________________________________________________________________________________________________
41 
42 #include <vcl/menu.hxx>
43 #include <framework/fwedllapi.h>
44 
45 #define ADDONMENU_ITEMID_START       2000
46 #define ADDONMENU_ITEMID_END         3000
47 
48 namespace framework
49 {
50 
51 class FWE_DLLPUBLIC AddonMenu : public PopupMenu
52 {
53 	public:
54                         AddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame );
55                         ~AddonMenu();
56 
57 	protected:
58 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
59 };
60 
61 class AddonMenuManager;
62 class FWE_DLLPUBLIC AddonPopupMenu : public AddonMenu
63 {
64 	public:
65 								~AddonPopupMenu();
66 
67 		// Check if command URL string has the unique prefix to identify addon popup menus
68 		static sal_Bool			IsCommandURLPrefix( const rtl::OUString& aCmdURL );
69 
70 		void                    SetCommandURL( const rtl::OUString& aCmdURL ) { m_aCommandURL = aCmdURL; }
71 		const rtl::OUString&    GetCommandURL() const { return m_aCommandURL; }
72 
73 	protected:
74 		void					Initialize( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonPopupMenuDefinition );
75 
76 	private:
77 								AddonPopupMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame );
78 
79 	rtl::OUString               m_aCommandURL;
80 
81 	friend class AddonMenuManager;
82 };
83 
84 class FWE_DLLPUBLIC AddonMenuManager
85 {
86     public:
87         enum MenuType
88         {
89             ADDON_MENU,
90             ADDON_POPUPMENU
91         };
92 
93         static sal_Bool   HasAddonMenuElements();
94         static sal_Bool   HasAddonHelpMenuElements();
95 
96         static sal_Bool   IsAddonMenuId( sal_uInt16 nId ) { return (( nId >= ADDONMENU_ITEMID_START ) && ( nId < ADDONMENU_ITEMID_END )); }
97 
98         // Check if the context string matches the provided xModel context
99         static sal_Bool	  IsCorrectContext( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rModel, const rtl::OUString& aContext );
100 
101         // Factory method to create different Add-On menu types
102         static PopupMenu* CreatePopupMenuType( MenuType eMenuType, const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame );
103 
104         // Create the Add-Ons menu
105         static AddonMenu* CreateAddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame );
106 
107 		// Merge the Add-Ons help menu items into the given menu bar at a defined pos
108 		static void		  MergeAddonHelpMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
109 											  MenuBar* pMergeMenuBar );
110 
111 		// Merge the addon popup menus into the given menu bar at the provided pos.
112 		static void       MergeAddonPopupMenus( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
113 											    const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel,
114 												sal_uInt16	 nMergeAtPos,
115 											    MenuBar* pMergeMenuBar );
116 
117         // Returns the next position to insert a menu item/sub menu
118         static sal_uInt16     GetNextPos( sal_uInt16 nPos );
119 
120         // Build up the menu item and sub menu into the provided pCurrentMenu. The sub menus should be of type nSubMenuType.
121         static void       BuildMenu( PopupMenu*  pCurrentMenu,
122                                      MenuType    nSubMenuType,
123                                      sal_uInt16      nInsPos,
124                                      sal_uInt16&     nUniqueMenuId,
125                                      com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > > aAddonMenuDefinition,
126                                      const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
127                                      const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rModel );
128 
129         // Retrieve the menu entry property values from a sequence
130         static void       GetMenuEntry( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonMenuEntry,
131 	                                    ::rtl::OUString& rTitle,
132 	                                    ::rtl::OUString& rURL,
133 	                                    ::rtl::OUString& rTarget,
134 	                                    ::rtl::OUString& rImageId,
135 	                                    ::rtl::OUString& rContext,
136 	                                    com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > >&	rAddonSubMenu );
137 };
138 
139 } // namespace framework
140 
141 #endif // #ifndef __FRAMEWORK_CLASSES_ADDONMENU_HXX_
142