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 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <uielement/menubarmerger.hxx> 32*cdf0e10cSrcweir #include <framework/addonsoptions.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace ::com::sun::star; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir static const char SEPARATOR_STRING[] = "private:separator"; 37*cdf0e10cSrcweir static const sal_uInt32 SEPARATOR_STRING_LEN = 17; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir static const char MERGECOMMAND_ADDAFTER[] = "AddAfter"; 40*cdf0e10cSrcweir static const sal_uInt32 MERGECOMMAND_ADDAFTER_LEN = 8; 41*cdf0e10cSrcweir static const char MERGECOMMAND_ADDBEFORE[] = "AddBefore"; 42*cdf0e10cSrcweir static const sal_uInt32 MERGECOMMAND_ADDBEFORE_LEN = 9; 43*cdf0e10cSrcweir static const char MERGECOMMAND_REPLACE[] = "Replace"; 44*cdf0e10cSrcweir static const sal_uInt32 MERGECOMMAND_REPLACE_LEN = 7; 45*cdf0e10cSrcweir static const char MERGECOMMAND_REMOVE[] = "Remove"; 46*cdf0e10cSrcweir static const sal_uInt32 MERGECOMMAND_REMOVE_LEN = 6; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir static const char MERGEFALLBACK_ADDPATH[] = "AddPath"; 49*cdf0e10cSrcweir static const char MERGEFALLBACK_ADDPATH_LEN = 7; 50*cdf0e10cSrcweir static const char MERGEFALLBACK_IGNORE[] = "Ignore"; 51*cdf0e10cSrcweir static const char MERGEFALLBACK_IGNORE_LEN = 6; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir namespace framework 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /** 58*cdf0e10cSrcweir Check whether a module identifier is part of a context 59*cdf0e10cSrcweir defined by a colon separated list of module identifier. 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir @param 62*cdf0e10cSrcweir rContext 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir Describes a context string list where all contexts 65*cdf0e10cSrcweir are delimited by a colon. For more information about 66*cdf0e10cSrcweir the module identifier used as context strings see the 67*cdf0e10cSrcweir IDL description of com::sun::star::frame::XModuleManager 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir @param 70*cdf0e10cSrcweir rModuleIdentifier 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir A string describing a module identifier. See IDL 73*cdf0e10cSrcweir description of com::sun::star::frame::XModuleManager. 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir */ 76*cdf0e10cSrcweir bool MenuBarMerger::IsCorrectContext( const ::rtl::OUString& rContext, const ::rtl::OUString& rModuleIdentifier ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir return (( rContext.getLength() == 0 ) || ( rContext.indexOf( rModuleIdentifier ) >= 0 )); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void MenuBarMerger::RetrieveReferencePath( 82*cdf0e10cSrcweir const ::rtl::OUString& rReferencePathString, 83*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >& rReferencePath ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir const sal_Char aDelimiter = '\\'; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir rReferencePath.clear(); 88*cdf0e10cSrcweir sal_Int32 nIndex( 0 ); 89*cdf0e10cSrcweir do 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir ::rtl::OUString aToken = rReferencePathString.getToken( 0, aDelimiter, nIndex ); 92*cdf0e10cSrcweir if ( aToken.getLength() > 0 ) 93*cdf0e10cSrcweir rReferencePath.push_back( aToken ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir while ( nIndex >= 0 ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir ReferencePathInfo MenuBarMerger::FindReferencePath( 99*cdf0e10cSrcweir const ::std::vector< ::rtl::OUString >& rReferencePath, 100*cdf0e10cSrcweir Menu* pMenu ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir sal_uInt32 i( 0 ); 103*cdf0e10cSrcweir const sal_uInt32 nCount( rReferencePath.size() ); 104*cdf0e10cSrcweir Menu* pCurrMenu( pMenu ); 105*cdf0e10cSrcweir RPResultInfo eResult( RP_OK ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir sal_Int32 nLevel( - 1 ); 108*cdf0e10cSrcweir sal_uInt16 nPos( MENU_ITEM_NOTFOUND ); 109*cdf0e10cSrcweir do 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ++nLevel; 112*cdf0e10cSrcweir ::rtl::OUString aCmd( rReferencePath[i] ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir if ( i == nCount-1 ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // Check last reference path element. Must be a leave (menu item). 117*cdf0e10cSrcweir sal_uInt16 nTmpPos = FindMenuItem( aCmd, pCurrMenu ); 118*cdf0e10cSrcweir if ( nTmpPos != MENU_ITEM_NOTFOUND ) 119*cdf0e10cSrcweir nPos = nTmpPos; 120*cdf0e10cSrcweir eResult = ( nTmpPos != MENU_ITEM_NOTFOUND ) ? RP_OK : RP_MENUITEM_NOT_FOUND; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir else 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir // Check reference path element. Must be a node (popup menu)! 125*cdf0e10cSrcweir sal_uInt16 nTmpPos = FindMenuItem( aCmd, pCurrMenu ); 126*cdf0e10cSrcweir if ( nTmpPos != MENU_ITEM_NOTFOUND ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir sal_uInt16 nItemId = pCurrMenu->GetItemId( nTmpPos ); 129*cdf0e10cSrcweir Menu* pTmpMenu = pCurrMenu->GetPopupMenu( nItemId ); 130*cdf0e10cSrcweir if ( pTmpMenu != 0 ) 131*cdf0e10cSrcweir pCurrMenu = pTmpMenu; 132*cdf0e10cSrcweir else 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir nPos = nTmpPos; 135*cdf0e10cSrcweir eResult = RP_MENUITEM_INSTEAD_OF_POPUPMENU_FOUND; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir else 139*cdf0e10cSrcweir eResult = RP_POPUPMENU_NOT_FOUND; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir i++; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir while (( pCurrMenu != 0 ) && ( i < nCount ) && ( eResult == RP_OK )); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ReferencePathInfo aResult; 146*cdf0e10cSrcweir aResult.pPopupMenu = pCurrMenu; 147*cdf0e10cSrcweir aResult.nPos = nPos; 148*cdf0e10cSrcweir aResult.nLevel = nLevel; 149*cdf0e10cSrcweir aResult.eResult = eResult; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir return aResult; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir sal_uInt16 MenuBarMerger::FindMenuItem( const ::rtl::OUString& rCmd, Menu* pCurrMenu ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < pCurrMenu->GetItemCount(); i++ ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir const sal_uInt16 nItemId = pCurrMenu->GetItemId( i ); 159*cdf0e10cSrcweir if ( nItemId > 0 ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if ( rCmd == ::rtl::OUString( pCurrMenu->GetItemCommand( nItemId ))) 162*cdf0e10cSrcweir return i; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir return MENU_ITEM_NOTFOUND; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir bool MenuBarMerger::CreateSubMenu( 170*cdf0e10cSrcweir Menu* pSubMenu, 171*cdf0e10cSrcweir sal_uInt16& nItemId, 172*cdf0e10cSrcweir const ::rtl::OUString& rModuleIdentifier, 173*cdf0e10cSrcweir const AddonMenuContainer& rAddonSubMenu ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir const sal_uInt32 nSize = rAddonSubMenu.size(); 176*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nSize; i++ ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir const AddonMenuItem& rMenuItem = rAddonSubMenu[i]; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if ( IsCorrectContext( rMenuItem.aContext, rModuleIdentifier )) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir if ( rMenuItem.aURL.equalsAsciiL( SEPARATOR_STRING, SEPARATOR_STRING_LEN )) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir pSubMenu->InsertSeparator( MENU_APPEND ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir else 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir pSubMenu->InsertItem( nItemId, rMenuItem.aTitle, 0, MENU_APPEND ); 189*cdf0e10cSrcweir pSubMenu->SetItemCommand( nItemId, rMenuItem.aURL ); 190*cdf0e10cSrcweir if ( !rMenuItem.aSubMenu.empty() ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir PopupMenu* pPopupMenu = new PopupMenu(); 193*cdf0e10cSrcweir pSubMenu->SetPopupMenu( nItemId, pPopupMenu ); 194*cdf0e10cSrcweir ++nItemId; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir CreateSubMenu( pPopupMenu, nItemId, rModuleIdentifier, rMenuItem.aSubMenu ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir else 199*cdf0e10cSrcweir ++nItemId; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return true; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir bool MenuBarMerger::MergeMenuItems( 208*cdf0e10cSrcweir Menu* pMenu, 209*cdf0e10cSrcweir sal_uInt16 nPos, 210*cdf0e10cSrcweir sal_uInt16 nModIndex, 211*cdf0e10cSrcweir sal_uInt16& nItemId, 212*cdf0e10cSrcweir const ::rtl::OUString& rModuleIdentifier, 213*cdf0e10cSrcweir const AddonMenuContainer& rAddonMenuItems ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir sal_uInt16 nIndex( 0 ); 216*cdf0e10cSrcweir const sal_uInt32 nSize = rAddonMenuItems.size(); 217*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nSize; i++ ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir const AddonMenuItem& rMenuItem = rAddonMenuItems[i]; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if ( IsCorrectContext( rMenuItem.aContext, rModuleIdentifier )) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir if ( rMenuItem.aURL.equalsAsciiL( SEPARATOR_STRING, SEPARATOR_STRING_LEN )) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir pMenu->InsertSeparator( nPos+nModIndex+nIndex ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir else 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir pMenu->InsertItem( nItemId, rMenuItem.aTitle, 0, nPos+nModIndex+nIndex ); 230*cdf0e10cSrcweir pMenu->SetItemCommand( nItemId, rMenuItem.aURL ); 231*cdf0e10cSrcweir if ( !rMenuItem.aSubMenu.empty() ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir PopupMenu* pSubMenu = new PopupMenu(); 234*cdf0e10cSrcweir pMenu->SetPopupMenu( nItemId, pSubMenu ); 235*cdf0e10cSrcweir ++nItemId; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir CreateSubMenu( pSubMenu, nItemId, rModuleIdentifier, rMenuItem.aSubMenu ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir else 240*cdf0e10cSrcweir ++nItemId; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir ++nIndex; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir return true; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir bool MenuBarMerger::ReplaceMenuItem( 250*cdf0e10cSrcweir Menu* pMenu, 251*cdf0e10cSrcweir sal_uInt16 nPos, 252*cdf0e10cSrcweir sal_uInt16& rItemId, 253*cdf0e10cSrcweir const ::rtl::OUString& rModuleIdentifier, 254*cdf0e10cSrcweir const AddonMenuContainer& rAddonMenuItems ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir // There is no replace available. Therfore we first have to 257*cdf0e10cSrcweir // remove the old menu entry, 258*cdf0e10cSrcweir pMenu->RemoveItem( nPos ); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir return MergeMenuItems( pMenu, nPos, 0, rItemId, rModuleIdentifier, rAddonMenuItems ); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir bool MenuBarMerger::RemoveMenuItems( 264*cdf0e10cSrcweir Menu* pMenu, 265*cdf0e10cSrcweir sal_uInt16 nPos, 266*cdf0e10cSrcweir const ::rtl::OUString& rMergeCommandParameter ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir const sal_uInt16 nParam( sal_uInt16( rMergeCommandParameter.toInt32() )); 269*cdf0e10cSrcweir sal_uInt16 nCount( 1 ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir nCount = std::max( nParam, nCount ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir sal_uInt16 i = 0; 274*cdf0e10cSrcweir while (( nPos < pMenu->GetItemCount() ) && ( i < nCount )) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir pMenu->RemoveItem( nPos ); 277*cdf0e10cSrcweir ++i; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir return true; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir bool MenuBarMerger::ProcessMergeOperation( 284*cdf0e10cSrcweir Menu* pMenu, 285*cdf0e10cSrcweir sal_uInt16 nPos, 286*cdf0e10cSrcweir sal_uInt16& nItemId, 287*cdf0e10cSrcweir const ::rtl::OUString& rMergeCommand, 288*cdf0e10cSrcweir const ::rtl::OUString& rMergeCommandParameter, 289*cdf0e10cSrcweir const ::rtl::OUString& rModuleIdentifier, 290*cdf0e10cSrcweir const AddonMenuContainer& rAddonMenuItems ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir sal_uInt16 nModIndex( 0 ); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN )) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir nModIndex = 0; 297*cdf0e10cSrcweir return MergeMenuItems( pMenu, nPos, nModIndex, nItemId, rModuleIdentifier, rAddonMenuItems ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN )) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir nModIndex = 1; 302*cdf0e10cSrcweir return MergeMenuItems( pMenu, nPos, nModIndex, nItemId, rModuleIdentifier, rAddonMenuItems ); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir return ReplaceMenuItem( pMenu, nPos, nItemId, rModuleIdentifier, rAddonMenuItems ); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN )) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir return RemoveMenuItems( pMenu, nPos, rMergeCommandParameter ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir return false; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir bool MenuBarMerger::ProcessFallbackOperation( 317*cdf0e10cSrcweir const ReferencePathInfo& aRefPathInfo, 318*cdf0e10cSrcweir sal_uInt16& rItemId, 319*cdf0e10cSrcweir const ::rtl::OUString& rMergeCommand, 320*cdf0e10cSrcweir const ::rtl::OUString& rMergeFallback, 321*cdf0e10cSrcweir const ::std::vector< ::rtl::OUString >& rReferencePath, 322*cdf0e10cSrcweir const ::rtl::OUString& rModuleIdentifier, 323*cdf0e10cSrcweir const AddonMenuContainer& rAddonMenuItems ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir if (( rMergeFallback.equalsAsciiL( MERGEFALLBACK_IGNORE, MERGEFALLBACK_IGNORE_LEN )) || 326*cdf0e10cSrcweir ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) || 327*cdf0e10cSrcweir ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN )) ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir return true; 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir else if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDPATH, MERGEFALLBACK_ADDPATH_LEN )) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir Menu* pCurrMenu( aRefPathInfo.pPopupMenu ); 334*cdf0e10cSrcweir sal_Int32 nLevel( aRefPathInfo.nLevel ); 335*cdf0e10cSrcweir const sal_Int32 nSize( rReferencePath.size() ); 336*cdf0e10cSrcweir bool bFirstLevel( true ); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir while ( nLevel < nSize ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir if ( nLevel == nSize-1 ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir const sal_uInt32 nCount = rAddonMenuItems.size(); 343*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; ++i ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir const AddonMenuItem& rMenuItem = rAddonMenuItems[i]; 346*cdf0e10cSrcweir if ( IsCorrectContext( rMenuItem.aContext, rModuleIdentifier )) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir if ( rMenuItem.aURL.equalsAsciiL( SEPARATOR_STRING, SEPARATOR_STRING_LEN )) 349*cdf0e10cSrcweir pCurrMenu->InsertSeparator( MENU_APPEND ); 350*cdf0e10cSrcweir else 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir pCurrMenu->InsertItem( rItemId, rMenuItem.aTitle, 0, MENU_APPEND ); 353*cdf0e10cSrcweir pCurrMenu->SetItemCommand( rItemId, rMenuItem.aURL ); 354*cdf0e10cSrcweir ++rItemId; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir else 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir const ::rtl::OUString aCmd( rReferencePath[nLevel] ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir sal_uInt16 nInsPos( MENU_APPEND ); 364*cdf0e10cSrcweir PopupMenu* pPopupMenu( new PopupMenu ); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir if ( bFirstLevel && ( aRefPathInfo.eResult == RP_MENUITEM_INSTEAD_OF_POPUPMENU_FOUND )) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir // special case: menu item without popup 369*cdf0e10cSrcweir nInsPos = aRefPathInfo.nPos; 370*cdf0e10cSrcweir sal_uInt16 nSetItemId = pCurrMenu->GetItemId( nInsPos ); 371*cdf0e10cSrcweir pCurrMenu->SetItemCommand( nSetItemId, aCmd ); 372*cdf0e10cSrcweir pCurrMenu->SetPopupMenu( nSetItemId, pPopupMenu ); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir else 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir // normal case: insert a new item with popup 377*cdf0e10cSrcweir pCurrMenu->InsertItem( rItemId, ::rtl::OUString(), 0, MENU_APPEND ); 378*cdf0e10cSrcweir pCurrMenu->SetItemCommand( rItemId, aCmd ); 379*cdf0e10cSrcweir pCurrMenu->SetPopupMenu( rItemId, pPopupMenu ); 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir pCurrMenu = pPopupMenu; 383*cdf0e10cSrcweir ++rItemId; 384*cdf0e10cSrcweir bFirstLevel = false; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir ++nLevel; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir return true; 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir return false; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir void MenuBarMerger::GetMenuEntry( 395*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rAddonMenuEntry, 396*cdf0e10cSrcweir AddonMenuItem& rAddonMenuItem ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir // Reset submenu member 399*cdf0e10cSrcweir rAddonMenuItem.aSubMenu.clear(); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rAddonMenuEntry.getLength(); i++ ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir ::rtl::OUString aMenuEntryPropName = rAddonMenuEntry[i].Name; 404*cdf0e10cSrcweir if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_URL, ADDONSMENUITEM_URL_LEN )) 405*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonMenuItem.aURL; 406*cdf0e10cSrcweir else if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_TITLE, ADDONSMENUITEM_TITLE_LEN )) 407*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonMenuItem.aTitle; 408*cdf0e10cSrcweir else if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_TARGET, ADDONSMENUITEM_TARGET_LEN )) 409*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonMenuItem.aTarget; 410*cdf0e10cSrcweir else if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_SUBMENU, ADDONSMENUITEM_SUBMENU_LEN )) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::PropertyValue > > aSubMenu; 413*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= aSubMenu; 414*cdf0e10cSrcweir GetSubMenu( aSubMenu, rAddonMenuItem.aSubMenu ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir else if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_CONTEXT, ADDONSMENUITEM_CONTEXT_LEN )) 417*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonMenuItem.aContext; 418*cdf0e10cSrcweir else if ( aMenuEntryPropName.equalsAsciiL( ADDONSMENUITEM_STRING_IMAGEIDENTIFIER, ADDONSMENUITEM_IMAGEIDENTIFIER_LEN )) 419*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonMenuItem.aImageId; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir void MenuBarMerger::GetSubMenu( 424*cdf0e10cSrcweir const uno::Sequence< uno::Sequence< beans::PropertyValue > >& rSubMenuEntries, 425*cdf0e10cSrcweir AddonMenuContainer& rSubMenu ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir rSubMenu.clear(); 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir const sal_Int32 nCount = rSubMenuEntries.getLength(); 430*cdf0e10cSrcweir rSubMenu.reserve(rSubMenu.size() + nCount); 431*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; i++ ) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rMenuEntry = rSubMenuEntries[ i ]; 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir AddonMenuItem aMenuItem; 436*cdf0e10cSrcweir GetMenuEntry( rMenuEntry, aMenuItem ); 437*cdf0e10cSrcweir rSubMenu.push_back( aMenuItem ); 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir } // namespace framework 442