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