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 //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir #include "framework/addonmenu.hxx" 35*cdf0e10cSrcweir #include "framework/addonsoptions.hxx" 36*cdf0e10cSrcweir #include <general.h> 37*cdf0e10cSrcweir #include <macros/debug/assertion.hxx> 38*cdf0e10cSrcweir #include <framework/imageproducer.hxx> 39*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir // interface includes 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 45*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 50*cdf0e10cSrcweir // includes of other projects 51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 52*cdf0e10cSrcweir #include <tools/config.hxx> 53*cdf0e10cSrcweir #include <vcl/svapp.hxx> 54*cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 55*cdf0e10cSrcweir #include <svl/solar.hrc> 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir // namespace 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 61*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 62*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 63*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // Please look at sfx2/inc/sfxsids.hrc the values are defined there. Due to build dependencies 66*cdf0e10cSrcweir // we cannot include the header file. 67*cdf0e10cSrcweir const sal_uInt16 SID_HELPMENU = (SID_SFX_START + 410); 68*cdf0e10cSrcweir const sal_uInt16 SID_ONLINE_REGISTRATION = (SID_SFX_START + 1537); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir namespace framework 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir AddonMenu::AddonMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ) : 74*cdf0e10cSrcweir m_xFrame( rFrame ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir AddonMenu::~AddonMenu() 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < GetItemCount(); i++ ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir if ( GetItemType( i ) != MENUITEM_SEPARATOR ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir // delete user attributes created with new! 85*cdf0e10cSrcweir sal_uInt16 nId = GetItemId( i ); 86*cdf0e10cSrcweir MenuConfiguration::Attributes* pUserAttributes = (MenuConfiguration::Attributes*)GetUserValue( nId ); 87*cdf0e10cSrcweir delete pUserAttributes; 88*cdf0e10cSrcweir delete GetPopupMenu( nId ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // ------------------------------------------------------------------------ 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // ------------------------------------------------------------------------ 96*cdf0e10cSrcweir // Check if command URL string has the unique prefix to identify addon popup menus 97*cdf0e10cSrcweir sal_Bool AddonPopupMenu::IsCommandURLPrefix( const ::rtl::OUString& aCmdURL ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir const char aPrefixCharBuf[] = ADDONSPOPUPMENU_URL_PREFIX_STR; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return aCmdURL.matchAsciiL( aPrefixCharBuf, sizeof( aPrefixCharBuf )-1, 0 ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir AddonPopupMenu::AddonPopupMenu( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame ) : 105*cdf0e10cSrcweir AddonMenu( rFrame ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir AddonPopupMenu::~AddonPopupMenu() 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // ------------------------------------------------------------------------ 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir static Reference< XModel > GetModelFromFrame( const Reference< XFrame >& rFrame ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir // Query for the model to get check the context information 118*cdf0e10cSrcweir Reference< XModel > xModel; 119*cdf0e10cSrcweir if ( rFrame.is() ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir Reference< XController > xController( rFrame->getController(), UNO_QUERY ); 122*cdf0e10cSrcweir if ( xController.is() ) 123*cdf0e10cSrcweir xModel = xController->getModel(); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir return xModel; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // ------------------------------------------------------------------------ 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir sal_Bool AddonMenuManager::HasAddonMenuElements() 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return AddonsOptions().HasAddonsMenu(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sal_Bool AddonMenuManager::HasAddonHelpMenuElements() 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir return AddonsOptions().HasAddonsHelpMenu(); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // Factory method to create different Add-On menu types 142*cdf0e10cSrcweir PopupMenu* AddonMenuManager::CreatePopupMenuType( MenuType eMenuType, const Reference< XFrame >& rFrame ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if ( eMenuType == ADDON_MENU ) 145*cdf0e10cSrcweir return new AddonMenu( rFrame ); 146*cdf0e10cSrcweir else if ( eMenuType == ADDON_POPUPMENU ) 147*cdf0e10cSrcweir return new AddonPopupMenu( rFrame ); 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir return NULL; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // Create the Add-Ons menu 153*cdf0e10cSrcweir AddonMenu* AddonMenuManager::CreateAddonMenu( const Reference< XFrame >& rFrame ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir AddonsOptions aOptions; 156*cdf0e10cSrcweir AddonMenu* pAddonMenu = NULL; 157*cdf0e10cSrcweir sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir const Sequence< Sequence< PropertyValue > >& rAddonMenuEntries = aOptions.GetAddonsMenu(); 160*cdf0e10cSrcweir if ( rAddonMenuEntries.getLength() > 0 ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir pAddonMenu = (AddonMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_MENU, rFrame ); 163*cdf0e10cSrcweir Reference< XModel > xModel = GetModelFromFrame( rFrame ); 164*cdf0e10cSrcweir AddonMenuManager::BuildMenu( pAddonMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, rAddonMenuEntries, rFrame, xModel ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // Don't return an empty Add-On menu 167*cdf0e10cSrcweir if ( pAddonMenu->GetItemCount() == 0 ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir delete pAddonMenu; 170*cdf0e10cSrcweir pAddonMenu = NULL; 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir return pAddonMenu; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // Returns the next insert position from nPos. 178*cdf0e10cSrcweir sal_uInt16 AddonMenuManager::GetNextPos( sal_uInt16 nPos ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir return ( nPos == MENU_APPEND ) ? MENU_APPEND : ( nPos+1 ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir static sal_uInt16 FindMenuId( Menu* pMenu, const String aCommand ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir sal_uInt16 nPos = 0; 187*cdf0e10cSrcweir String aCmd; 188*cdf0e10cSrcweir for ( nPos = 0; nPos < pMenu->GetItemCount(); nPos++ ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir sal_uInt16 nId = pMenu->GetItemId( nPos ); 191*cdf0e10cSrcweir aCmd = pMenu->GetItemCommand( nId ); 192*cdf0e10cSrcweir if ( aCmd == aCommand ) 193*cdf0e10cSrcweir return nId; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir return USHRT_MAX; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // Merge the Add-Ons help menu items into the given menu bar at a defined pos 201*cdf0e10cSrcweir void AddonMenuManager::MergeAddonHelpMenu( const Reference< XFrame >& rFrame, MenuBar* pMergeMenuBar ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir if ( pMergeMenuBar ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir PopupMenu* pHelpMenu = pMergeMenuBar->GetPopupMenu( SID_HELPMENU ); 206*cdf0e10cSrcweir if ( !pHelpMenu ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir sal_uInt16 nId = FindMenuId( pMergeMenuBar, String::CreateFromAscii( ".uno:HelpMenu" )); 209*cdf0e10cSrcweir if ( nId != USHRT_MAX ) 210*cdf0e10cSrcweir pHelpMenu = pMergeMenuBar->GetPopupMenu( nId ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir if ( pHelpMenu ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir static const char REFERENCECOMMAND_AFTER[] = ".uno:OnlineRegistrationDlg"; 216*cdf0e10cSrcweir static const char REFERENCECOMMAND_BEFORE[] = ".uno:About"; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // Add-Ons help menu items should be inserted after the "registration" menu item 219*cdf0e10cSrcweir bool bAddAfter = true; 220*cdf0e10cSrcweir sal_uInt16 nItemCount = pHelpMenu->GetItemCount(); 221*cdf0e10cSrcweir sal_uInt16 nRegPos = pHelpMenu->GetItemPos( SID_ONLINE_REGISTRATION ); 222*cdf0e10cSrcweir sal_uInt16 nInsPos = nRegPos; 223*cdf0e10cSrcweir sal_uInt16 nInsSepAfterPos = MENU_APPEND; 224*cdf0e10cSrcweir sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; 225*cdf0e10cSrcweir AddonsOptions aOptions; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if ( nRegPos == USHRT_MAX ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir // try to detect the online registration dialog menu item with the command URL 230*cdf0e10cSrcweir sal_uInt16 nId = FindMenuId( pHelpMenu, String::CreateFromAscii( REFERENCECOMMAND_AFTER )); 231*cdf0e10cSrcweir nRegPos = pHelpMenu->GetItemPos( nId ); 232*cdf0e10cSrcweir nInsPos = nRegPos; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir if ( nRegPos == USHRT_MAX ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir // second try: 238*cdf0e10cSrcweir // try to detect the about menu item with the command URL 239*cdf0e10cSrcweir sal_uInt16 nId = FindMenuId( pHelpMenu, String::CreateFromAscii( REFERENCECOMMAND_BEFORE )); 240*cdf0e10cSrcweir nRegPos = pHelpMenu->GetItemPos( nId ); 241*cdf0e10cSrcweir nInsPos = nRegPos; 242*cdf0e10cSrcweir bAddAfter = false; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aAddonSubMenu; 246*cdf0e10cSrcweir const Sequence< Sequence< PropertyValue > >& rAddonHelpMenuEntries = aOptions.GetAddonsHelpMenu(); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir nInsPos = bAddAfter ? AddonMenuManager::GetNextPos( nInsPos ) : nInsPos; 249*cdf0e10cSrcweir if ( nInsPos < nItemCount && pHelpMenu->GetItemType( nInsPos ) != MENUITEM_SEPARATOR ) 250*cdf0e10cSrcweir nInsSepAfterPos = nInsPos; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir Reference< XModel > xModel = GetModelFromFrame( rFrame ); 253*cdf0e10cSrcweir AddonMenuManager::BuildMenu( pHelpMenu, ADDON_MENU, nInsPos, nUniqueMenuId, rAddonHelpMenuEntries, rFrame, xModel ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if ( pHelpMenu->GetItemCount() > nItemCount ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if ( nInsSepAfterPos < MENU_APPEND ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir nInsSepAfterPos += ( pHelpMenu->GetItemCount() - nItemCount ); 260*cdf0e10cSrcweir if ( pHelpMenu->GetItemType( nInsSepAfterPos ) != MENUITEM_SEPARATOR ) 261*cdf0e10cSrcweir pHelpMenu->InsertSeparator( nInsSepAfterPos ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir if ( nRegPos < MENU_APPEND ) 264*cdf0e10cSrcweir pHelpMenu->InsertSeparator( nRegPos+1 ); 265*cdf0e10cSrcweir else 266*cdf0e10cSrcweir pHelpMenu->InsertSeparator( nItemCount ); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // Merge the addon popup menus into the given menu bar at the provided pos. 273*cdf0e10cSrcweir void AddonMenuManager::MergeAddonPopupMenus( const Reference< XFrame >& rFrame, 274*cdf0e10cSrcweir const Reference< XModel >& rModel, 275*cdf0e10cSrcweir sal_uInt16 nMergeAtPos, 276*cdf0e10cSrcweir MenuBar* pMergeMenuBar ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir if ( pMergeMenuBar ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir AddonsOptions aAddonsOptions; 281*cdf0e10cSrcweir sal_uInt16 nInsertPos = nMergeAtPos; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir ::rtl::OUString aTitle; 284*cdf0e10cSrcweir ::rtl::OUString aURL; 285*cdf0e10cSrcweir ::rtl::OUString aTarget; 286*cdf0e10cSrcweir ::rtl::OUString aImageId; 287*cdf0e10cSrcweir ::rtl::OUString aContext; 288*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aAddonSubMenu; 289*cdf0e10cSrcweir sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir const Sequence< Sequence< PropertyValue > >& rAddonMenuEntries = aAddonsOptions.GetAddonsMenuBarPart(); 292*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rAddonMenuEntries.getLength(); i++ ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir AddonMenuManager::GetMenuEntry( rAddonMenuEntries[i], 295*cdf0e10cSrcweir aTitle, 296*cdf0e10cSrcweir aURL, 297*cdf0e10cSrcweir aTarget, 298*cdf0e10cSrcweir aImageId, 299*cdf0e10cSrcweir aContext, 300*cdf0e10cSrcweir aAddonSubMenu ); 301*cdf0e10cSrcweir if ( aTitle.getLength() > 0 && 302*cdf0e10cSrcweir aURL.getLength() > 0 && 303*cdf0e10cSrcweir aAddonSubMenu.getLength() > 0 && 304*cdf0e10cSrcweir AddonMenuManager::IsCorrectContext( rModel, aContext )) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir sal_uInt16 nId = nUniqueMenuId++; 307*cdf0e10cSrcweir AddonPopupMenu* pAddonPopupMenu = (AddonPopupMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_POPUPMENU, rFrame ); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir AddonMenuManager::BuildMenu( pAddonPopupMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, rModel ); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir if ( pAddonPopupMenu->GetItemCount() > 0 ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir pAddonPopupMenu->SetCommandURL( aURL ); 314*cdf0e10cSrcweir pMergeMenuBar->InsertItem( nId, aTitle, 0, nInsertPos++ ); 315*cdf0e10cSrcweir pMergeMenuBar->SetPopupMenu( nId, pAddonPopupMenu ); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir // Store the command URL into the VCL menu bar for later identification 318*cdf0e10cSrcweir pMergeMenuBar->SetItemCommand( nId, aURL ); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir else 321*cdf0e10cSrcweir delete pAddonPopupMenu; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // Insert the menu and sub menu entries into pCurrentMenu with the aAddonMenuDefinition provided 328*cdf0e10cSrcweir void AddonMenuManager::BuildMenu( PopupMenu* pCurrentMenu, 329*cdf0e10cSrcweir MenuType nSubMenuType, 330*cdf0e10cSrcweir sal_uInt16 nInsPos, 331*cdf0e10cSrcweir sal_uInt16& nUniqueMenuId, 332*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aAddonMenuDefinition, 333*cdf0e10cSrcweir const Reference< XFrame >& rFrame, 334*cdf0e10cSrcweir const Reference< XModel >& rModel ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aAddonSubMenu; 337*cdf0e10cSrcweir sal_Bool bInsertSeparator = sal_False; 338*cdf0e10cSrcweir sal_uInt32 i = 0; 339*cdf0e10cSrcweir sal_uInt32 nElements = 0; 340*cdf0e10cSrcweir sal_uInt32 nCount = aAddonMenuDefinition.getLength(); 341*cdf0e10cSrcweir AddonsOptions aAddonsOptions; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir ::rtl::OUString aTitle; 344*cdf0e10cSrcweir ::rtl::OUString aURL; 345*cdf0e10cSrcweir ::rtl::OUString aTarget; 346*cdf0e10cSrcweir ::rtl::OUString aImageId; 347*cdf0e10cSrcweir ::rtl::OUString aContext; 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir GetMenuEntry( aAddonMenuDefinition[i], aTitle, aURL, aTarget, aImageId, aContext, aAddonSubMenu ); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir if ( !IsCorrectContext( rModel, aContext ) || ( !aTitle.getLength() && !aURL.getLength() )) 354*cdf0e10cSrcweir continue; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" ))) 357*cdf0e10cSrcweir bInsertSeparator = sal_True; 358*cdf0e10cSrcweir else 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir PopupMenu* pSubMenu = NULL; 361*cdf0e10cSrcweir if ( aAddonSubMenu.getLength() > 0 ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir pSubMenu = AddonMenuManager::CreatePopupMenuType( nSubMenuType, rFrame ); 364*cdf0e10cSrcweir AddonMenuManager::BuildMenu( pSubMenu, nSubMenuType, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, rModel ); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // Don't create a menu item for an empty sub menu 367*cdf0e10cSrcweir if ( pSubMenu->GetItemCount() == 0 ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir delete pSubMenu; 370*cdf0e10cSrcweir pSubMenu = NULL; 371*cdf0e10cSrcweir continue; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir if ( bInsertSeparator && nElements > 0 ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir // Insert a separator only when we insert a new element afterwards and we 378*cdf0e10cSrcweir // have already one before us 379*cdf0e10cSrcweir nElements = 0; 380*cdf0e10cSrcweir bInsertSeparator = sal_False; 381*cdf0e10cSrcweir pCurrentMenu->InsertSeparator( nInsPos ); 382*cdf0e10cSrcweir nInsPos = AddonMenuManager::GetNextPos( nInsPos ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir sal_uInt16 nId = nUniqueMenuId++; 386*cdf0e10cSrcweir pCurrentMenu->InsertItem( nId, aTitle, 0, nInsPos ); 387*cdf0e10cSrcweir nInsPos = AddonMenuManager::GetNextPos( nInsPos ); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir ++nElements; 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir // Store values from configuration to the New and Wizard menu entries to enable 392*cdf0e10cSrcweir // sfx2 based code to support high contrast mode correctly! 393*cdf0e10cSrcweir pCurrentMenu->SetUserValue( nId, sal_uIntPtr( new MenuConfiguration::Attributes( aTarget, aImageId )) ); 394*cdf0e10cSrcweir pCurrentMenu->SetItemCommand( nId, aURL ); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if ( pSubMenu ) 397*cdf0e10cSrcweir pCurrentMenu->SetPopupMenu( nId, pSubMenu ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // Retrieve the menu entry property values from a sequence 403*cdf0e10cSrcweir void AddonMenuManager::GetMenuEntry( const Sequence< PropertyValue >& rAddonMenuEntry, 404*cdf0e10cSrcweir ::rtl::OUString& rTitle, 405*cdf0e10cSrcweir ::rtl::OUString& rURL, 406*cdf0e10cSrcweir ::rtl::OUString& rTarget, 407*cdf0e10cSrcweir ::rtl::OUString& rImageId, 408*cdf0e10cSrcweir ::rtl::OUString& rContext, 409*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > >& rAddonSubMenu ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir // Reset submenu parameter 412*cdf0e10cSrcweir rAddonSubMenu = Sequence< Sequence< PropertyValue > >(); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir for ( int i = 0; i < rAddonMenuEntry.getLength(); i++ ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir ::rtl::OUString aMenuEntryPropName = rAddonMenuEntry[i].Name; 417*cdf0e10cSrcweir if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_URL ) 418*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rURL; 419*cdf0e10cSrcweir else if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_TITLE ) 420*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rTitle; 421*cdf0e10cSrcweir else if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_TARGET ) 422*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rTarget; 423*cdf0e10cSrcweir else if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_IMAGEIDENTIFIER ) 424*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rImageId; 425*cdf0e10cSrcweir else if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_SUBMENU ) 426*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rAddonSubMenu; 427*cdf0e10cSrcweir else if ( aMenuEntryPropName == ADDONSMENUITEM_PROPERTYNAME_CONTEXT ) 428*cdf0e10cSrcweir rAddonMenuEntry[i].Value >>= rContext; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir // Check if the context string matches the provided xModel context 433*cdf0e10cSrcweir sal_Bool AddonMenuManager::IsCorrectContext( const Reference< XModel >& rModel, const ::rtl::OUString& aContext ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir if ( rModel.is() ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( rModel, UNO_QUERY ); 438*cdf0e10cSrcweir if ( xServiceInfo.is() ) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir sal_Int32 nIndex = 0; 441*cdf0e10cSrcweir do 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir ::rtl::OUString aToken = aContext.getToken( 0, ',', nIndex ); 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir if ( xServiceInfo->supportsService( aToken )) 446*cdf0e10cSrcweir return sal_True; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir while ( nIndex >= 0 ); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir return ( aContext.getLength() == 0 ); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457