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
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_framework.hxx"
246d5620bcSAriel Constenla-Haile
25cdf0e10cSrcweir #include <uielement/recentfilesmenucontroller.hxx>
26cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
27cdf0e10cSrcweir #include <classes/resource.hrc>
28cdf0e10cSrcweir #include <classes/fwkresid.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <com/sun/star/util/XStringWidth.hpp>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
33cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx>
346d5620bcSAriel Constenla-Haile #include <osl/file.hxx>
356d5620bcSAriel Constenla-Haile #include <tools/urlobj.hxx>
366d5620bcSAriel Constenla-Haile #include <unotools/historyoptions.hxx>
376d5620bcSAriel Constenla-Haile #include <vcl/menu.hxx>
386d5620bcSAriel Constenla-Haile #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <vos/mutex.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace com::sun::star::uno;
42cdf0e10cSrcweir using namespace com::sun::star::lang;
43cdf0e10cSrcweir using namespace com::sun::star::frame;
44cdf0e10cSrcweir using namespace com::sun::star::beans;
45cdf0e10cSrcweir using namespace com::sun::star::util;
466d5620bcSAriel Constenla-Haile
476d5620bcSAriel Constenla-Haile #define MAX_STR_WIDTH 46
486d5620bcSAriel Constenla-Haile #define MAX_MENU_ITEMS 99
49cdf0e10cSrcweir
50cdf0e10cSrcweir static const char SFX_REFERER_USER[] = "private:user";
516d5620bcSAriel Constenla-Haile static const char CMD_CLEAR_LIST[] = ".uno:ClearRecentFileList";
526d5620bcSAriel Constenla-Haile static const char CMD_PREFIX[] = "vnd.sun.star.popup:RecentFileList?entry=";
53caeabaabSmseidel static const char MENU_SHORTCUT[] = "~N: ";
54cdf0e10cSrcweir
55cdf0e10cSrcweir namespace framework
56cdf0e10cSrcweir {
57cdf0e10cSrcweir
58cdf0e10cSrcweir class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
59cdf0e10cSrcweir {
60cdf0e10cSrcweir public:
RecentFilesStringLength()61cdf0e10cSrcweir RecentFilesStringLength() {}
~RecentFilesStringLength()62cdf0e10cSrcweir virtual ~RecentFilesStringLength() {}
63cdf0e10cSrcweir
64cdf0e10cSrcweir // XStringWidth
queryStringWidth(const::rtl::OUString & aString)65cdf0e10cSrcweir sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
66cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir return aString.getLength();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir };
71cdf0e10cSrcweir
DEFINE_XSERVICEINFO_MULTISERVICE(RecentFilesMenuController,OWeakObject,SERVICENAME_POPUPMENUCONTROLLER,IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER)72cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( RecentFilesMenuController ,
73cdf0e10cSrcweir OWeakObject ,
74cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER ,
75cdf0e10cSrcweir IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER
76cdf0e10cSrcweir )
77cdf0e10cSrcweir
78cdf0e10cSrcweir DEFINE_INIT_SERVICE ( RecentFilesMenuController, {} )
79cdf0e10cSrcweir
80cdf0e10cSrcweir RecentFilesMenuController::RecentFilesMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
81cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ),
82cdf0e10cSrcweir m_bDisabled( sal_False )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
~RecentFilesMenuController()86cdf0e10cSrcweir RecentFilesMenuController::~RecentFilesMenuController()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir // private function
fillPopupMenu(Reference<css::awt::XPopupMenu> & rPopupMenu)91cdf0e10cSrcweir void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
94cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = 0;
95cdf0e10cSrcweir
96cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
97cdf0e10cSrcweir
98cdf0e10cSrcweir resetPopupMenu( rPopupMenu );
99cdf0e10cSrcweir if ( pPopupMenu )
100cdf0e10cSrcweir pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
101cdf0e10cSrcweir
102cdf0e10cSrcweir if ( pVCLPopupMenu )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
105cdf0e10cSrcweir Reference< XStringWidth > xStringLength( new RecentFilesStringLength );
106cdf0e10cSrcweir
1076d5620bcSAriel Constenla-Haile int nPickListMenuItems = ( aHistoryList.getLength() > MAX_MENU_ITEMS ) ? MAX_MENU_ITEMS : aHistoryList.getLength();
108cdf0e10cSrcweir
109cdf0e10cSrcweir m_aRecentFilesItems.clear();
110cdf0e10cSrcweir if (( nPickListMenuItems > 0 ) && !m_bDisabled )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir for ( int i = 0; i < nPickListMenuItems; i++ )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
115cdf0e10cSrcweir RecentFile aRecentFile;
116cdf0e10cSrcweir
117cdf0e10cSrcweir for ( int j = 0; j < rPickListEntry.getLength(); j++ )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir Any a = rPickListEntry[j].Value;
120cdf0e10cSrcweir
121cdf0e10cSrcweir if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
122cdf0e10cSrcweir a >>= aRecentFile.aURL;
123cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
124cdf0e10cSrcweir a >>= aRecentFile.aFilter;
125cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
126cdf0e10cSrcweir a >>= aRecentFile.aTitle;
127cdf0e10cSrcweir else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD )
128cdf0e10cSrcweir a >>= aRecentFile.aPassword;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir m_aRecentFilesItems.push_back( aRecentFile );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir if ( !m_aRecentFilesItems.empty() )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir const sal_uInt32 nCount = m_aRecentFilesItems.size();
138cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ )
139cdf0e10cSrcweir {
1406d5620bcSAriel Constenla-Haile rtl::OUStringBuffer aMenuShortCut;
141cdf0e10cSrcweir if ( i <= 9 )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir if ( i == 9 )
1446d5620bcSAriel Constenla-Haile aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( "1~0: " ) );
145cdf0e10cSrcweir else
146cdf0e10cSrcweir {
147caeabaabSmseidel aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( MENU_SHORTCUT ) );
1486d5620bcSAriel Constenla-Haile aMenuShortCut.setCharAt( 1, sal_Unicode( i + '1' ) );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir else
152cdf0e10cSrcweir {
1536d5620bcSAriel Constenla-Haile aMenuShortCut.append( sal_Int32( i + 1 ) );
1546d5620bcSAriel Constenla-Haile aMenuShortCut.appendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
1576d5620bcSAriel Constenla-Haile rtl::OUStringBuffer aStrBuffer;
1586d5620bcSAriel Constenla-Haile aStrBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( CMD_PREFIX ) );
1596d5620bcSAriel Constenla-Haile aStrBuffer.append( sal_Int32( i ) );
1606d5620bcSAriel Constenla-Haile rtl::OUString aURLString( aStrBuffer.makeStringAndClear() );
1616d5620bcSAriel Constenla-Haile
162cdf0e10cSrcweir // Abbreviate URL
163cdf0e10cSrcweir rtl::OUString aTipHelpText;
164cdf0e10cSrcweir rtl::OUString aMenuTitle;
165cdf0e10cSrcweir INetURLObject aURL( m_aRecentFilesItems[i].aURL );
166cdf0e10cSrcweir
167cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir // Do handle file URL differently => convert it to a system
170cdf0e10cSrcweir // path and abbreviate it with a special function:
1716d5620bcSAriel Constenla-Haile rtl::OUString aSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
172cdf0e10cSrcweir aTipHelpText = aSystemPath;
1736d5620bcSAriel Constenla-Haile
1746d5620bcSAriel Constenla-Haile ::rtl::OUString aCompactedSystemPath;
1756d5620bcSAriel Constenla-Haile if ( osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, MAX_STR_WIDTH, NULL ) == osl_File_E_None )
1766d5620bcSAriel Constenla-Haile aMenuTitle = aCompactedSystemPath;
177cdf0e10cSrcweir else
178cdf0e10cSrcweir aMenuTitle = aSystemPath;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir else
181cdf0e10cSrcweir {
182cdf0e10cSrcweir // Use INetURLObject to abbreviate all other URLs
1836d5620bcSAriel Constenla-Haile aMenuTitle = aURL.getAbbreviated( xStringLength, MAX_STR_WIDTH, INetURLObject::DECODE_UNAMBIGUOUS );
184cdf0e10cSrcweir aTipHelpText = aURLString;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
1876d5620bcSAriel Constenla-Haile aMenuShortCut.append( aMenuTitle );
188cdf0e10cSrcweir
1896d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( sal_uInt16( i+1 ), aMenuShortCut.makeStringAndClear() );
190cdf0e10cSrcweir pVCLPopupMenu->SetTipHelpText( sal_uInt16( i+1 ), aTipHelpText );
191cdf0e10cSrcweir pVCLPopupMenu->SetItemCommand( sal_uInt16( i+1 ), aURLString );
192cdf0e10cSrcweir }
1936d5620bcSAriel Constenla-Haile
1946d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertSeparator();
1956d5620bcSAriel Constenla-Haile // Clear List menu entry
1966d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( sal_uInt16( nCount + 1 ),
1976d5620bcSAriel Constenla-Haile String( FwkResId( STR_CLEAR_RECENT_FILES ) ) );
1986d5620bcSAriel Constenla-Haile pVCLPopupMenu->SetItemCommand( sal_uInt16( nCount + 1 ),
1996d5620bcSAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_CLEAR_LIST ) ) );
2006d5620bcSAriel Constenla-Haile pVCLPopupMenu->SetHelpText( sal_uInt16( nCount + 1 ),
2016d5620bcSAriel Constenla-Haile String( FwkResId( STR_CLEAR_RECENT_FILES_HELP ) ) );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir else
204cdf0e10cSrcweir {
205cdf0e10cSrcweir // No recent documents => insert "no document" string
2066d5620bcSAriel Constenla-Haile pVCLPopupMenu->InsertItem( 1, String( FwkResId( STR_NODOCUMENT ) ) );
2072f6b3599SAriel Constenla-Haile // Do not disable it, otherwise the Toolbar controller and MenuButton
2082f6b3599SAriel Constenla-Haile // will display SV_RESID_STRING_NOSELECTIONPOSSIBLE instead of STR_NODOCUMENT
2092f6b3599SAriel Constenla-Haile pVCLPopupMenu->SetItemBits( 1, pVCLPopupMenu->GetItemBits( 1 ) | MIB_NOSELECT );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
executeEntry(sal_Int32 nIndex)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 {
26730acf5e8Spfg // Call dispatch asynchronously 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
disposing(const EventObject &)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
statusChanged(const FeatureStateEvent & Event)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
itemSelected(const css::awt::MenuEvent & rEvent)304d026be40SAriel 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
312d026be40SAriel Constenla-Haile if ( xPopupMenu.is() )
313cdf0e10cSrcweir {
314d026be40SAriel Constenla-Haile const rtl::OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) );
315d026be40SAriel Constenla-Haile OSL_TRACE( "RecentFilesMenuController::itemSelected() - Command : %s",
3166d5620bcSAriel Constenla-Haile rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
3176d5620bcSAriel Constenla-Haile
318*8eeb065fSArrigo Marchiori if ( aCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_CLEAR_LIST ) ) ) {
3196d5620bcSAriel Constenla-Haile SvtHistoryOptions().Clear( ePICKLIST );
320*8eeb065fSArrigo Marchiori SvtHistoryOptions().Clear( eHISTORY );
321*8eeb065fSArrigo Marchiori }
3226d5620bcSAriel Constenla-Haile else
323cdf0e10cSrcweir executeEntry( rEvent.MenuId-1 );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
itemActivated(const css::awt::MenuEvent &)327d026be40SAriel Constenla-Haile void SAL_CALL RecentFilesMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex );
330cdf0e10cSrcweir impl_setPopupMenu();
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir // XPopupMenuController
impl_setPopupMenu()334cdf0e10cSrcweir void RecentFilesMenuController::impl_setPopupMenu()
335cdf0e10cSrcweir {
336cdf0e10cSrcweir if ( m_xPopupMenu.is() )
337cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu );
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir // XDispatchProvider
queryDispatch(const URL & aURL,const::rtl::OUString &,sal_Int32)341cdf0e10cSrcweir Reference< XDispatch > SAL_CALL RecentFilesMenuController::queryDispatch(
342cdf0e10cSrcweir const URL& aURL,
343cdf0e10cSrcweir const ::rtl::OUString& /*sTarget*/,
344cdf0e10cSrcweir sal_Int32 /*nFlags*/ )
345cdf0e10cSrcweir throw( RuntimeException )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex );
348cdf0e10cSrcweir
349cdf0e10cSrcweir throwIfDisposed();
350cdf0e10cSrcweir
351cdf0e10cSrcweir if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 )
352cdf0e10cSrcweir return Reference< XDispatch >( static_cast< OWeakObject* >( this ), UNO_QUERY );
353cdf0e10cSrcweir else
354cdf0e10cSrcweir return Reference< XDispatch >();
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir // XDispatch
dispatch(const URL & aURL,const Sequence<PropertyValue> &)358cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::dispatch(
359cdf0e10cSrcweir const URL& aURL,
360cdf0e10cSrcweir const Sequence< PropertyValue >& /*seqProperties*/ )
361cdf0e10cSrcweir throw( RuntimeException )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex );
364cdf0e10cSrcweir
365cdf0e10cSrcweir throwIfDisposed();
366cdf0e10cSrcweir
367cdf0e10cSrcweir if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir // Parse URL to retrieve entry argument and its value
370cdf0e10cSrcweir sal_Int32 nQueryPart = aURL.Complete.indexOf( '?', m_aBaseURL.getLength() );
371cdf0e10cSrcweir if ( nQueryPart > 0 )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir const rtl::OUString aEntryArgStr( RTL_CONSTASCII_USTRINGPARAM( "entry=" ));
374cdf0e10cSrcweir sal_Int32 nEntryArg = aURL.Complete.indexOf( aEntryArgStr, nQueryPart );
375cdf0e10cSrcweir sal_Int32 nEntryPos = nEntryArg + aEntryArgStr.getLength();
376cdf0e10cSrcweir if (( nEntryArg > 0 ) && ( nEntryPos < aURL.Complete.getLength() ))
377cdf0e10cSrcweir {
378cdf0e10cSrcweir sal_Int32 nAddArgs = aURL.Complete.indexOf( '&', nEntryPos );
379cdf0e10cSrcweir rtl::OUString aEntryArg;
380cdf0e10cSrcweir
381cdf0e10cSrcweir if ( nAddArgs < 0 )
382cdf0e10cSrcweir aEntryArg = aURL.Complete.copy( nEntryPos );
383cdf0e10cSrcweir else
384cdf0e10cSrcweir aEntryArg = aURL.Complete.copy( nEntryPos, nAddArgs-nEntryPos );
385cdf0e10cSrcweir
386cdf0e10cSrcweir sal_Int32 nEntry = aEntryArg.toInt32();
387cdf0e10cSrcweir executeEntry( nEntry );
388cdf0e10cSrcweir }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir }
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
IMPL_STATIC_LINK_NOINSTANCE(RecentFilesMenuController,ExecuteHdl_Impl,LoadRecentFile *,pLoadRecentFile)393cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile*, pLoadRecentFile )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir try
396cdf0e10cSrcweir {
397cdf0e10cSrcweir // Asynchronous execution as this can lead to our own destruction!
398cdf0e10cSrcweir // Framework can recycle our current frame and the layout manager disposes all user interface
399cdf0e10cSrcweir // elements if a component gets detached from its frame!
400cdf0e10cSrcweir pLoadRecentFile->xDispatch->dispatch( pLoadRecentFile->aTargetURL, pLoadRecentFile->aArgSeq );
401cdf0e10cSrcweir }
402cdf0e10cSrcweir catch ( Exception& )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir }
405cdf0e10cSrcweir
406cdf0e10cSrcweir delete pLoadRecentFile;
407cdf0e10cSrcweir return 0;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir }
411caeabaabSmseidel
412caeabaabSmseidel /* vim: set noet sw=4 ts=4: */
413