16d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 266d5620bcSAriel Constenla-Haile 27cdf0e10cSrcweir #include <uielement/recentfilesmenucontroller.hxx> 28cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 29cdf0e10cSrcweir #include <classes/resource.hrc> 30cdf0e10cSrcweir #include <classes/fwkresid.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/util/XStringWidth.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 35cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx> 366d5620bcSAriel Constenla-Haile #include <osl/file.hxx> 376d5620bcSAriel Constenla-Haile #include <tools/urlobj.hxx> 386d5620bcSAriel Constenla-Haile #include <unotools/historyoptions.hxx> 396d5620bcSAriel Constenla-Haile #include <vcl/menu.hxx> 406d5620bcSAriel Constenla-Haile #include <vcl/svapp.hxx> 41cdf0e10cSrcweir #include <vos/mutex.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace com::sun::star::uno; 44cdf0e10cSrcweir using namespace com::sun::star::lang; 45cdf0e10cSrcweir using namespace com::sun::star::frame; 46cdf0e10cSrcweir using namespace com::sun::star::beans; 47cdf0e10cSrcweir using namespace com::sun::star::util; 486d5620bcSAriel Constenla-Haile 496d5620bcSAriel Constenla-Haile #define MAX_STR_WIDTH 46 506d5620bcSAriel Constenla-Haile #define MAX_MENU_ITEMS 99 51cdf0e10cSrcweir 52cdf0e10cSrcweir static const char SFX_REFERER_USER[] = "private:user"; 536d5620bcSAriel Constenla-Haile static const char CMD_CLEAR_LIST[] = ".uno:ClearRecentFileList"; 546d5620bcSAriel Constenla-Haile static const char CMD_PREFIX[] = "vnd.sun.star.popup:RecentFileList?entry="; 556d5620bcSAriel Constenla-Haile static const char MENU_SHOTCUT[] = "~N: "; 56cdf0e10cSrcweir 57cdf0e10cSrcweir namespace framework 58cdf0e10cSrcweir { 59cdf0e10cSrcweir 60cdf0e10cSrcweir class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth > 61cdf0e10cSrcweir { 62cdf0e10cSrcweir public: 63cdf0e10cSrcweir RecentFilesStringLength() {} 64cdf0e10cSrcweir virtual ~RecentFilesStringLength() {} 65cdf0e10cSrcweir 66cdf0e10cSrcweir // XStringWidth 67cdf0e10cSrcweir sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString ) 68cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return aString.getLength(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( RecentFilesMenuController , 75cdf0e10cSrcweir OWeakObject , 76cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER , 77cdf0e10cSrcweir IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER 78cdf0e10cSrcweir ) 79cdf0e10cSrcweir 80cdf0e10cSrcweir DEFINE_INIT_SERVICE ( RecentFilesMenuController, {} ) 81cdf0e10cSrcweir 82cdf0e10cSrcweir RecentFilesMenuController::RecentFilesMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : 83cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ), 84cdf0e10cSrcweir m_bDisabled( sal_False ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir RecentFilesMenuController::~RecentFilesMenuController() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir // private function 93cdf0e10cSrcweir void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu ); 96cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = 0; 97cdf0e10cSrcweir 98cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir resetPopupMenu( rPopupMenu ); 101cdf0e10cSrcweir if ( pPopupMenu ) 102cdf0e10cSrcweir pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir if ( pVCLPopupMenu ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST ); 107cdf0e10cSrcweir Reference< XStringWidth > xStringLength( new RecentFilesStringLength ); 108cdf0e10cSrcweir 1096d5620bcSAriel Constenla-Haile int nPickListMenuItems = ( aHistoryList.getLength() > MAX_MENU_ITEMS ) ? MAX_MENU_ITEMS : aHistoryList.getLength(); 110cdf0e10cSrcweir 111cdf0e10cSrcweir m_aRecentFilesItems.clear(); 112cdf0e10cSrcweir if (( nPickListMenuItems > 0 ) && !m_bDisabled ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir for ( int i = 0; i < nPickListMenuItems; i++ ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir Sequence< PropertyValue >& rPickListEntry = aHistoryList[i]; 117cdf0e10cSrcweir RecentFile aRecentFile; 118cdf0e10cSrcweir 119cdf0e10cSrcweir for ( int j = 0; j < rPickListEntry.getLength(); j++ ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir Any a = rPickListEntry[j].Value; 122cdf0e10cSrcweir 123cdf0e10cSrcweir if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL ) 124cdf0e10cSrcweir a >>= aRecentFile.aURL; 125cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER ) 126cdf0e10cSrcweir a >>= aRecentFile.aFilter; 127cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE ) 128cdf0e10cSrcweir a >>= aRecentFile.aTitle; 129cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD ) 130cdf0e10cSrcweir a >>= aRecentFile.aPassword; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir m_aRecentFilesItems.push_back( aRecentFile ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir if ( !m_aRecentFilesItems.empty() ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir const sal_uInt32 nCount = m_aRecentFilesItems.size(); 140cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 141cdf0e10cSrcweir { 1426d5620bcSAriel Constenla-Haile rtl::OUStringBuffer aMenuShortCut; 143cdf0e10cSrcweir if ( i <= 9 ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if ( i == 9 ) 1466d5620bcSAriel Constenla-Haile aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( "1~0: " ) ); 147cdf0e10cSrcweir else 148cdf0e10cSrcweir { 1496d5620bcSAriel Constenla-Haile aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( MENU_SHOTCUT ) ); 1506d5620bcSAriel Constenla-Haile aMenuShortCut.setCharAt( 1, sal_Unicode( i + '1' ) ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir else 154cdf0e10cSrcweir { 1556d5620bcSAriel Constenla-Haile aMenuShortCut.append( sal_Int32( i + 1 ) ); 1566d5620bcSAriel Constenla-Haile aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 1596d5620bcSAriel Constenla-Haile rtl::OUStringBuffer aStrBuffer; 1606d5620bcSAriel Constenla-Haile aStrBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( CMD_PREFIX ) ); 1616d5620bcSAriel Constenla-Haile aStrBuffer.append( sal_Int32( i ) ); 1626d5620bcSAriel Constenla-Haile rtl::OUString aURLString( aStrBuffer.makeStringAndClear() ); 1636d5620bcSAriel Constenla-Haile 164cdf0e10cSrcweir // Abbreviate URL 165cdf0e10cSrcweir rtl::OUString aTipHelpText; 166cdf0e10cSrcweir rtl::OUString aMenuTitle; 167cdf0e10cSrcweir INetURLObject aURL( m_aRecentFilesItems[i].aURL ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir // Do handle file URL differently => convert it to a system 172cdf0e10cSrcweir // path and abbreviate it with a special function: 1736d5620bcSAriel Constenla-Haile rtl::OUString aSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) ); 174cdf0e10cSrcweir aTipHelpText = aSystemPath; 1756d5620bcSAriel Constenla-Haile 1766d5620bcSAriel Constenla-Haile ::rtl::OUString aCompactedSystemPath; 1776d5620bcSAriel Constenla-Haile if ( osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, MAX_STR_WIDTH, NULL ) == osl_File_E_None ) 1786d5620bcSAriel Constenla-Haile aMenuTitle = aCompactedSystemPath; 179cdf0e10cSrcweir else 180cdf0e10cSrcweir aMenuTitle = aSystemPath; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir else 183cdf0e10cSrcweir { 184cdf0e10cSrcweir // Use INetURLObject to abbreviate all other URLs 1856d5620bcSAriel Constenla-Haile aMenuTitle = aURL.getAbbreviated( xStringLength, MAX_STR_WIDTH, INetURLObject::DECODE_UNAMBIGUOUS ); 186cdf0e10cSrcweir aTipHelpText = aURLString; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 1896d5620bcSAriel Constenla-Haile aMenuShortCut.append( aMenuTitle ); 190cdf0e10cSrcweir 1916d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( sal_uInt16( i+1 ), aMenuShortCut.makeStringAndClear() ); 192cdf0e10cSrcweir pVCLPopupMenu->SetTipHelpText( sal_uInt16( i+1 ), aTipHelpText ); 193cdf0e10cSrcweir pVCLPopupMenu->SetItemCommand( sal_uInt16( i+1 ), aURLString ); 194cdf0e10cSrcweir } 1956d5620bcSAriel Constenla-Haile 1966d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertSeparator(); 1976d5620bcSAriel Constenla-Haile // Clear List menu entry 1986d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( sal_uInt16( nCount + 1 ), 1996d5620bcSAriel Constenla-Haile String( FwkResId( STR_CLEAR_RECENT_FILES ) ) ); 2006d5620bcSAriel Constenla-Haile pVCLPopupMenu->SetItemCommand( sal_uInt16( nCount + 1 ), 2016d5620bcSAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_CLEAR_LIST ) ) ); 2026d5620bcSAriel Constenla-Haile pVCLPopupMenu->SetHelpText( sal_uInt16( nCount + 1 ), 2036d5620bcSAriel Constenla-Haile String( FwkResId( STR_CLEAR_RECENT_FILES_HELP ) ) ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir else 206cdf0e10cSrcweir { 207cdf0e10cSrcweir // No recent documents => insert "no document" string 2086d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( 1, String( FwkResId( STR_NODOCUMENT ) ) ); 209cdf0e10cSrcweir pVCLPopupMenu->EnableItem( 1, sal_False ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void RecentFilesMenuController::executeEntry( sal_Int32 nIndex ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir static int NUM_OF_PICKLIST_ARGS = 3; 217cdf0e10cSrcweir 218cdf0e10cSrcweir Reference< XDispatch > xDispatch; 219cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider; 220cdf0e10cSrcweir css::util::URL aTargetURL; 221cdf0e10cSrcweir Sequence< PropertyValue > aArgsList; 222cdf0e10cSrcweir 2236d5620bcSAriel Constenla-Haile osl::ClearableMutexGuard aLock( m_aMutex ); 2246d5620bcSAriel Constenla-Haile xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY ); 2256d5620bcSAriel Constenla-Haile aLock.clear(); 2266d5620bcSAriel Constenla-Haile 227cdf0e10cSrcweir if (( nIndex >= 0 ) && 228cdf0e10cSrcweir ( nIndex < sal::static_int_cast<sal_Int32>( m_aRecentFilesItems.size() ))) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir const RecentFile& rRecentFile = m_aRecentFilesItems[ nIndex ]; 231cdf0e10cSrcweir 232cdf0e10cSrcweir aTargetURL.Complete = rRecentFile.aURL; 233cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 234cdf0e10cSrcweir 235cdf0e10cSrcweir aArgsList.realloc( NUM_OF_PICKLIST_ARGS ); 236cdf0e10cSrcweir aArgsList[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" )); 2376d5620bcSAriel Constenla-Haile aArgsList[0].Value = makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ))); 238cdf0e10cSrcweir 239cdf0e10cSrcweir // documents in the picklist will never be opened as templates 240cdf0e10cSrcweir aArgsList[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" )); 241cdf0e10cSrcweir aArgsList[1].Value = makeAny( (sal_Bool) sal_False ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir ::rtl::OUString aFilter( rRecentFile.aFilter ); 244cdf0e10cSrcweir sal_Int32 nPos = aFilter.indexOf( '|' ); 245cdf0e10cSrcweir if ( nPos >= 0 ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir ::rtl::OUString aFilterOptions; 248cdf0e10cSrcweir 249cdf0e10cSrcweir if ( nPos < ( aFilter.getLength() - 1 ) ) 250cdf0e10cSrcweir aFilterOptions = aFilter.copy( nPos+1 ); 251cdf0e10cSrcweir 252cdf0e10cSrcweir aArgsList[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" )); 253cdf0e10cSrcweir aArgsList[2].Value <<= aFilterOptions; 254cdf0e10cSrcweir 255cdf0e10cSrcweir aFilter = aFilter.copy( 0, nPos-1 ); 256cdf0e10cSrcweir aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); 260cdf0e10cSrcweir aArgsList[NUM_OF_PICKLIST_ARGS-1].Value <<= aFilter; 261cdf0e10cSrcweir 2626d5620bcSAriel Constenla-Haile xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), 0 ); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir if ( xDispatch.is() ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir // Call dispatch asychronously as we can be destroyed while dispatch is 268cdf0e10cSrcweir // executed. VCL is not able to survive this as it wants to call listeners 269cdf0e10cSrcweir // after select!!! 270cdf0e10cSrcweir LoadRecentFile* pLoadRecentFile = new LoadRecentFile; 271cdf0e10cSrcweir pLoadRecentFile->xDispatch = xDispatch; 272cdf0e10cSrcweir pLoadRecentFile->aTargetURL = aTargetURL; 273cdf0e10cSrcweir pLoadRecentFile->aArgSeq = aArgsList; 2746d5620bcSAriel Constenla-Haile 275cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 2766d5620bcSAriel Constenla-Haile UiEventLogHelper(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RecentFilesMenuController"))).log(m_xServiceManager, m_xFrame, aTargetURL, aArgsList); 2776d5620bcSAriel Constenla-Haile 278cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK(0, RecentFilesMenuController, ExecuteHdl_Impl), pLoadRecentFile ); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir // XEventListener 283cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::disposing( const EventObject& ) throw ( RuntimeException ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY ); 286cdf0e10cSrcweir 287cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 288cdf0e10cSrcweir m_xFrame.clear(); 289cdf0e10cSrcweir m_xDispatch.clear(); 290cdf0e10cSrcweir m_xServiceManager.clear(); 291cdf0e10cSrcweir 292cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 293cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY )); 294cdf0e10cSrcweir m_xPopupMenu.clear(); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir // XStatusListener 298cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 301cdf0e10cSrcweir m_bDisabled = !Event.IsEnabled; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304*d026be40SAriel Constenla-Haile void SAL_CALL RecentFilesMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir Reference< css::awt::XPopupMenu > xPopupMenu; 307cdf0e10cSrcweir 308cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 309cdf0e10cSrcweir xPopupMenu = m_xPopupMenu; 310cdf0e10cSrcweir aLock.clear(); 311cdf0e10cSrcweir 312*d026be40SAriel Constenla-Haile if ( xPopupMenu.is() ) 313cdf0e10cSrcweir { 314*d026be40SAriel Constenla-Haile const rtl::OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) ); 315*d026be40SAriel Constenla-Haile OSL_TRACE( "RecentFilesMenuController::itemSelected() - Command : %s", 3166d5620bcSAriel Constenla-Haile rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); 3176d5620bcSAriel Constenla-Haile 3186d5620bcSAriel Constenla-Haile if ( aCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_CLEAR_LIST ) ) ) 3196d5620bcSAriel Constenla-Haile SvtHistoryOptions().Clear( ePICKLIST ); 3206d5620bcSAriel Constenla-Haile else 321cdf0e10cSrcweir executeEntry( rEvent.MenuId-1 ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325*d026be40SAriel Constenla-Haile void SAL_CALL RecentFilesMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 328cdf0e10cSrcweir impl_setPopupMenu(); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir // XPopupMenuController 332cdf0e10cSrcweir void RecentFilesMenuController::impl_setPopupMenu() 333cdf0e10cSrcweir { 334cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 335cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir // XDispatchProvider 339cdf0e10cSrcweir Reference< XDispatch > SAL_CALL RecentFilesMenuController::queryDispatch( 340cdf0e10cSrcweir const URL& aURL, 341cdf0e10cSrcweir const ::rtl::OUString& /*sTarget*/, 342cdf0e10cSrcweir sal_Int32 /*nFlags*/ ) 343cdf0e10cSrcweir throw( RuntimeException ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 346cdf0e10cSrcweir 347cdf0e10cSrcweir throwIfDisposed(); 348cdf0e10cSrcweir 349cdf0e10cSrcweir if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 ) 350cdf0e10cSrcweir return Reference< XDispatch >( static_cast< OWeakObject* >( this ), UNO_QUERY ); 351cdf0e10cSrcweir else 352cdf0e10cSrcweir return Reference< XDispatch >(); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir // XDispatch 356cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::dispatch( 357cdf0e10cSrcweir const URL& aURL, 358cdf0e10cSrcweir const Sequence< PropertyValue >& /*seqProperties*/ ) 359cdf0e10cSrcweir throw( RuntimeException ) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 362cdf0e10cSrcweir 363cdf0e10cSrcweir throwIfDisposed(); 364cdf0e10cSrcweir 365cdf0e10cSrcweir if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir // Parse URL to retrieve entry argument and its value 368cdf0e10cSrcweir sal_Int32 nQueryPart = aURL.Complete.indexOf( '?', m_aBaseURL.getLength() ); 369cdf0e10cSrcweir if ( nQueryPart > 0 ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir const rtl::OUString aEntryArgStr( RTL_CONSTASCII_USTRINGPARAM( "entry=" )); 372cdf0e10cSrcweir sal_Int32 nEntryArg = aURL.Complete.indexOf( aEntryArgStr, nQueryPart ); 373cdf0e10cSrcweir sal_Int32 nEntryPos = nEntryArg + aEntryArgStr.getLength(); 374cdf0e10cSrcweir if (( nEntryArg > 0 ) && ( nEntryPos < aURL.Complete.getLength() )) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir sal_Int32 nAddArgs = aURL.Complete.indexOf( '&', nEntryPos ); 377cdf0e10cSrcweir rtl::OUString aEntryArg; 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( nAddArgs < 0 ) 380cdf0e10cSrcweir aEntryArg = aURL.Complete.copy( nEntryPos ); 381cdf0e10cSrcweir else 382cdf0e10cSrcweir aEntryArg = aURL.Complete.copy( nEntryPos, nAddArgs-nEntryPos ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir sal_Int32 nEntry = aEntryArg.toInt32(); 385cdf0e10cSrcweir executeEntry( nEntry ); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir } 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile*, pLoadRecentFile ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir try 394cdf0e10cSrcweir { 395cdf0e10cSrcweir // Asynchronous execution as this can lead to our own destruction! 396cdf0e10cSrcweir // Framework can recycle our current frame and the layout manager disposes all user interface 397cdf0e10cSrcweir // elements if a component gets detached from its frame! 398cdf0e10cSrcweir pLoadRecentFile->xDispatch->dispatch( pLoadRecentFile->aTargetURL, pLoadRecentFile->aArgSeq ); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir catch ( Exception& ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir delete pLoadRecentFile; 405cdf0e10cSrcweir return 0; 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir } 409