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
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
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.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
276d5620bcSAriel Constenla-Haile #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:
RecentFilesStringLength()63cdf0e10cSrcweir 		RecentFilesStringLength() {}
~RecentFilesStringLength()64cdf0e10cSrcweir 		virtual ~RecentFilesStringLength() {}
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 		// XStringWidth
queryStringWidth(const::rtl::OUString & aString)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 
DEFINE_XSERVICEINFO_MULTISERVICE(RecentFilesMenuController,OWeakObject,SERVICENAME_POPUPMENUCONTROLLER,IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER)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 
~RecentFilesMenuController()88cdf0e10cSrcweir RecentFilesMenuController::~RecentFilesMenuController()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // private function
fillPopupMenu(Reference<css::awt::XPopupMenu> & rPopupMenu)93cdf0e10cSrcweir void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
94cdf0e10cSrcweir {
956d5620bcSAriel Constenla-Haile     VCLXPopupMenu* pPopupMenu    = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
966d5620bcSAriel Constenla-Haile     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 ) );
1746d5620bcSAriel Constenla-Haile                     aTipHelpText = aSystemPath;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 					::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 ) ) );
209*2f6b3599SAriel Constenla-Haile             // Do not disable it, otherwise the Toolbar controller and MenuButton
210*2f6b3599SAriel Constenla-Haile             // will display SV_RESID_STRING_NOSELECTIONPOSSIBLE instead of STR_NODOCUMENT
211*2f6b3599SAriel Constenla-Haile             pVCLPopupMenu->SetItemBits( 1, pVCLPopupMenu->GetItemBits( 1 ) | MIB_NOSELECT );
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
executeEntry(sal_Int32 nIndex)216cdf0e10cSrcweir void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     static int NUM_OF_PICKLIST_ARGS = 3;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     Reference< XDispatch >            xDispatch;
221cdf0e10cSrcweir     Reference< XDispatchProvider >    xDispatchProvider;
2226d5620bcSAriel Constenla-Haile     css::util::URL                    aTargetURL;
2236d5620bcSAriel Constenla-Haile     Sequence< PropertyValue >         aArgsList;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     osl::ClearableMutexGuard aLock( m_aMutex );
2266d5620bcSAriel Constenla-Haile     xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
227cdf0e10cSrcweir     aLock.clear();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     if (( nIndex >= 0 ) &&
230cdf0e10cSrcweir         ( nIndex < sal::static_int_cast<sal_Int32>( m_aRecentFilesItems.size() )))
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         const RecentFile& rRecentFile = m_aRecentFilesItems[ nIndex ];
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         aTargetURL.Complete = rRecentFile.aURL;
235cdf0e10cSrcweir         m_xURLTransformer->parseStrict( aTargetURL );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         aArgsList.realloc( NUM_OF_PICKLIST_ARGS );
238cdf0e10cSrcweir         aArgsList[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
2396d5620bcSAriel Constenla-Haile         aArgsList[0].Value = makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER )));
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         // documents in the picklist will never be opened as templates
242cdf0e10cSrcweir         aArgsList[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" ));
243cdf0e10cSrcweir         aArgsList[1].Value = makeAny( (sal_Bool) sal_False );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         ::rtl::OUString  aFilter( rRecentFile.aFilter );
246cdf0e10cSrcweir         sal_Int32 nPos = aFilter.indexOf( '|' );
247cdf0e10cSrcweir         if ( nPos >= 0 )
248cdf0e10cSrcweir         {
249cdf0e10cSrcweir 	        ::rtl::OUString aFilterOptions;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	        if ( nPos < ( aFilter.getLength() - 1 ) )
252cdf0e10cSrcweir 		        aFilterOptions = aFilter.copy( nPos+1 );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	        aArgsList[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" ));
255cdf0e10cSrcweir 	        aArgsList[2].Value <<= aFilterOptions;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	        aFilter = aFilter.copy( 0, nPos-1 );
258cdf0e10cSrcweir 	        aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS );
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
262cdf0e10cSrcweir         aArgsList[NUM_OF_PICKLIST_ARGS-1].Value <<= aFilter;
263cdf0e10cSrcweir 
2646d5620bcSAriel Constenla-Haile         xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), 0 );
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     if ( xDispatch.is() )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         // Call dispatch asychronously as we can be destroyed while dispatch is
270cdf0e10cSrcweir         // executed. VCL is not able to survive this as it wants to call listeners
271cdf0e10cSrcweir         // after select!!!
272cdf0e10cSrcweir         LoadRecentFile* pLoadRecentFile = new LoadRecentFile;
273cdf0e10cSrcweir         pLoadRecentFile->xDispatch  = xDispatch;
274cdf0e10cSrcweir         pLoadRecentFile->aTargetURL = aTargetURL;
275cdf0e10cSrcweir         pLoadRecentFile->aArgSeq    = aArgsList;
2766d5620bcSAriel Constenla-Haile 
277cdf0e10cSrcweir         if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
2786d5620bcSAriel Constenla-Haile             UiEventLogHelper(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RecentFilesMenuController"))).log(m_xServiceManager, m_xFrame, aTargetURL, aArgsList);
2796d5620bcSAriel Constenla-Haile 
280cdf0e10cSrcweir         Application::PostUserEvent( STATIC_LINK(0, RecentFilesMenuController, ExecuteHdl_Impl), pLoadRecentFile );
281cdf0e10cSrcweir     }
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir // XEventListener
disposing(const EventObject &)285cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::disposing( const EventObject& ) throw ( RuntimeException )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     osl::MutexGuard aLock( m_aMutex );
290cdf0e10cSrcweir     m_xFrame.clear();
291cdf0e10cSrcweir     m_xDispatch.clear();
292cdf0e10cSrcweir     m_xServiceManager.clear();
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     if ( m_xPopupMenu.is() )
295cdf0e10cSrcweir         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
296cdf0e10cSrcweir     m_xPopupMenu.clear();
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir // XStatusListener
statusChanged(const FeatureStateEvent & Event)300cdf0e10cSrcweir void SAL_CALL RecentFilesMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     osl::MutexGuard aLock( m_aMutex );
303cdf0e10cSrcweir     m_bDisabled = !Event.IsEnabled;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
itemSelected(const css::awt::MenuEvent & rEvent)306d026be40SAriel Constenla-Haile void SAL_CALL RecentFilesMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
307cdf0e10cSrcweir {
308d026be40SAriel Constenla-Haile     Reference< css::awt::XPopupMenu > xPopupMenu;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     osl::ClearableMutexGuard aLock( m_aMutex );
311d026be40SAriel Constenla-Haile     xPopupMenu = m_xPopupMenu;
312cdf0e10cSrcweir     aLock.clear();
313cdf0e10cSrcweir 
314d026be40SAriel Constenla-Haile     if ( xPopupMenu.is() )
315cdf0e10cSrcweir     {
316d026be40SAriel Constenla-Haile         const rtl::OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) );
317d026be40SAriel Constenla-Haile         OSL_TRACE( "RecentFilesMenuController::itemSelected() - Command : %s",
3186d5620bcSAriel Constenla-Haile                    rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
3196d5620bcSAriel Constenla-Haile 
3206d5620bcSAriel Constenla-Haile         if ( aCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_CLEAR_LIST ) ) )
3216d5620bcSAriel Constenla-Haile             SvtHistoryOptions().Clear( ePICKLIST );
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 }
411