Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_FRAMEWORK_ADDONMENU_HXX
20 : #define INCLUDED_FRAMEWORK_ADDONMENU_HXX
21 :
22 : #include <com/sun/star/frame/XFrame.hpp>
23 : #include <com/sun/star/beans/PropertyValue.hpp>
24 : #include <com/sun/star/uno/Sequence.hxx>
25 : #include <com/sun/star/uno/XComponentContext.hpp>
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 :
28 : #include <vcl/menu.hxx>
29 : #include <framework/fwedllapi.h>
30 :
31 : #define ADDONMENU_ITEMID_START 2000
32 : #define ADDONMENU_ITEMID_END 3000
33 :
34 : namespace framework
35 : {
36 :
37 : class FWE_DLLPUBLIC AddonMenu : public PopupMenu
38 : {
39 : public:
40 : AddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame );
41 : virtual ~AddonMenu();
42 :
43 : protected:
44 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
45 : };
46 :
47 : class AddonMenuManager;
48 :
49 : class FWE_DLLPUBLIC AddonPopupMenu : public AddonMenu
50 : {
51 : public:
52 : virtual ~AddonPopupMenu();
53 :
54 : // Check if command URL string has the unique prefix to identify addon popup menus
55 : static bool IsCommandURLPrefix( const OUString& aCmdURL );
56 :
57 0 : void SetCommandURL( const OUString& aCmdURL ) { m_aCommandURL = aCmdURL; }
58 : const OUString& GetCommandURL() const { return m_aCommandURL; }
59 :
60 : protected:
61 : void Initialize( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonPopupMenuDefinition );
62 :
63 : private:
64 : AddonPopupMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame );
65 :
66 : OUString m_aCommandURL;
67 :
68 : friend class AddonMenuManager;
69 : };
70 :
71 : class FWE_DLLPUBLIC AddonMenuManager
72 : {
73 : public:
74 : enum MenuType
75 : {
76 : ADDON_MENU,
77 : ADDON_POPUPMENU
78 : };
79 :
80 : static bool HasAddonMenuElements();
81 :
82 197907 : static bool IsAddonMenuId( sal_uInt16 nId ) { return (( nId >= ADDONMENU_ITEMID_START ) && ( nId < ADDONMENU_ITEMID_END )); }
83 :
84 : // Check if the context string matches the provided xModel context
85 : static bool IsCorrectContext(const OUString& rModuleIdentifier, const OUString& rContext);
86 :
87 : // Factory method to create different Add-On menu types
88 : static PopupMenu* CreatePopupMenuType( MenuType eMenuType, const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame );
89 :
90 : // Create the Add-Ons menu
91 : static AddonMenu* CreateAddonMenu( const css::uno::Reference< css::frame::XFrame >& rFrame,
92 : const css::uno::Reference< css::uno::XComponentContext >& rContext );
93 :
94 : // Merge the Add-Ons help menu items into the given menu bar at a defined pos
95 : static void MergeAddonHelpMenu( const css::uno::Reference< css::frame::XFrame >& rFrame,
96 : MenuBar* pMergeMenuBar,
97 : const css::uno::Reference< css::uno::XComponentContext >& rContext );
98 :
99 : // Merge the addon popup menus into the given menu bar at the provided pos.
100 : static void MergeAddonPopupMenus( const css::uno::Reference< css::frame::XFrame >& rFrame,
101 : sal_uInt16 nMergeAtPos,
102 : MenuBar* pMergeMenuBar,
103 : const css::uno::Reference< css::uno::XComponentContext >& rContext );
104 :
105 : // Returns the next position to insert a menu item/sub menu
106 : static sal_uInt16 GetNextPos( sal_uInt16 nPos );
107 :
108 : // Build up the menu item and sub menu into the provided pCurrentMenu. The sub menus should be of type nSubMenuType.
109 : static void BuildMenu( PopupMenu* pCurrentMenu,
110 : MenuType nSubMenuType,
111 : sal_uInt16 nInsPos,
112 : sal_uInt16& nUniqueMenuId,
113 : const com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > >& aAddonMenuDefinition,
114 : const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
115 : const ::rtl::OUString& rModuleIdentifier );
116 :
117 : // Retrieve the menu entry property values from a sequence
118 : static void GetMenuEntry( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rAddonMenuEntry,
119 : OUString& rTitle,
120 : OUString& rURL,
121 : OUString& rTarget,
122 : OUString& rImageId,
123 : OUString& rContext,
124 : com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > >& rAddonSubMenu );
125 : };
126 :
127 : } // namespace framework
128 :
129 : #endif // INCLUDED_FRAMEWORK_ADDONMENU_HXX
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|