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