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 24 #ifndef __FRAMEWORK_UIELEMENT_MENUBARMERGER_HXX_ 25 #define __FRAMEWORK_UIELEMENT_MENUBARMERGER_HXX_ 26 27 #include <com/sun/star/beans/PropertyValue.hpp> 28 29 #include <rtl/ustring.hxx> 30 #include <vcl/menu.hxx> 31 32 namespace framework 33 { 34 35 struct AddonMenuItem; 36 typedef ::std::vector< AddonMenuItem > AddonMenuContainer; 37 38 struct AddonMenuItem 39 { 40 ::rtl::OUString aTitle; 41 ::rtl::OUString aURL; 42 ::rtl::OUString aTarget; 43 ::rtl::OUString aImageId; 44 ::rtl::OUString aContext; 45 AddonMenuContainer aSubMenu; 46 }; 47 48 enum RPResultInfo 49 { 50 RP_OK, 51 RP_POPUPMENU_NOT_FOUND, 52 RP_MENUITEM_NOT_FOUND, 53 RP_MENUITEM_INSTEAD_OF_POPUPMENU_FOUND 54 }; 55 56 struct ReferencePathInfo 57 { 58 Menu* pPopupMenu; 59 sal_uInt16 nPos; 60 sal_Int32 nLevel; 61 RPResultInfo eResult; 62 }; 63 64 class MenuBarMerger 65 { 66 public: 67 static bool IsCorrectContext( const ::rtl::OUString& aContext, const ::rtl::OUString& aModuleIdentifier ); 68 69 static void RetrieveReferencePath( const ::rtl::OUString&, 70 std::vector< ::rtl::OUString >& aReferencePath ); 71 static ReferencePathInfo FindReferencePath( const std::vector< ::rtl::OUString >& aReferencePath, Menu* pMenu ); 72 static sal_uInt16 FindMenuItem( const ::rtl::OUString& rCmd, 73 Menu* pMenu ); 74 static void GetMenuEntry( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rAddonMenuEntry, 75 AddonMenuItem& aAddonMenu ); 76 static void GetSubMenu( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& rSubMenuEntries, 77 AddonMenuContainer& rSubMenu ); 78 static bool ProcessMergeOperation( Menu* pMenu, 79 sal_uInt16 nPos, 80 sal_uInt16& rItemId, 81 const ::rtl::OUString& rMergeCommand, 82 const ::rtl::OUString& rMergeCommandParameter, 83 const ::rtl::OUString& rModuleIdentifier, 84 const AddonMenuContainer& rAddonMenuItems ); 85 static bool ProcessFallbackOperation( const ReferencePathInfo& aRefPathInfo, 86 sal_uInt16& rItemId, 87 const ::rtl::OUString& rMergeCommand, 88 const ::rtl::OUString& rMergeFallback, 89 const ::std::vector< ::rtl::OUString >& rReferencePath, 90 const ::rtl::OUString& rModuleIdentifier, 91 const AddonMenuContainer& rAddonMenuItems ); 92 static bool ProcessFallbackOperation(); 93 static bool MergeMenuItems( Menu* pMenu, 94 sal_uInt16 nPos, 95 sal_uInt16 nModIndex, 96 sal_uInt16& rItemId, 97 const ::rtl::OUString& rModuleIdentifier, 98 const AddonMenuContainer& rAddonMenuItems ); 99 static bool ReplaceMenuItem( Menu* pMenu, 100 sal_uInt16 nPos, 101 sal_uInt16& rItemId, 102 const ::rtl::OUString& rModuleIdentifier, 103 const AddonMenuContainer& rAddonMenuItems ); 104 static bool RemoveMenuItems( Menu* pMenu, 105 sal_uInt16 nPos, 106 const ::rtl::OUString& rMergeCommandParameter ); 107 static bool CreateSubMenu( Menu* pSubMenu, 108 sal_uInt16& nItemId, 109 const ::rtl::OUString& rModuleIdentifier, 110 const AddonMenuContainer& rAddonSubMenu ); 111 112 private: 113 MenuBarMerger(); 114 MenuBarMerger( const MenuBarMerger& ); 115 MenuBarMerger& operator=( const MenuBarMerger& ); 116 }; 117 118 } // namespace framework 119 120 #endif // __FRAMEWORK_UIELEMENT_MENUBARMERGER_HXX_ 121