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