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