LCOV - code coverage report
Current view: top level - framework/source/uielement - recentfilesmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 209 0.5 %
Date: 2012-08-25 Functions: 1 28 3.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 350 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <uielement/recentfilesmenucontroller.hxx>
      30                 :            : 
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : 
      34                 :            : #include <classes/resource.hrc>
      35                 :            : #include <classes/fwkresid.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/awt/XDevice.hpp>
      38                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      39                 :            : #include <com/sun/star/awt/MenuItemStyle.hpp>
      40                 :            : #include <com/sun/star/util/XStringWidth.hpp>
      41                 :            : 
      42                 :            : #include <vcl/menu.hxx>
      43                 :            : #include <vcl/svapp.hxx>
      44                 :            : #include <vcl/i18nhelp.hxx>
      45                 :            : #include <tools/urlobj.hxx>
      46                 :            : #include <rtl/ustrbuf.hxx>
      47                 :            : #include <unotools/historyoptions.hxx>
      48                 :            : #include <cppuhelper/implbase1.hxx>
      49                 :            : #include <osl/file.hxx>
      50                 :            : #ifdef WNT
      51                 :            : #define GradientStyle_RECT BLA_GradientStyle_RECT
      52                 :            : #include <windows.h>
      53                 :            : #undef GradientStyle_RECT
      54                 :            : #include <odma_lib.hxx>
      55                 :            : #endif
      56                 :            : #include <osl/mutex.hxx>
      57                 :            : 
      58                 :            : //_________________________________________________________________________________________________________________
      59                 :            : //  Defines
      60                 :            : //_________________________________________________________________________________________________________________
      61                 :            : 
      62                 :            : using namespace com::sun::star::uno;
      63                 :            : using namespace com::sun::star::lang;
      64                 :            : using namespace com::sun::star::frame;
      65                 :            : using namespace com::sun::star::beans;
      66                 :            : using namespace com::sun::star::util;
      67                 :            : using namespace com::sun::star::container;
      68                 :            : 
      69                 :            : static const char SFX_REFERER_USER[] = "private:user";
      70                 :            : 
      71                 :            : namespace framework
      72                 :            : {
      73                 :            : 
      74                 :            : class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
      75                 :            : {
      76                 :            :     public:
      77                 :          0 :         RecentFilesStringLength() {}
      78         [ #  # ]:          0 :         virtual ~RecentFilesStringLength() {}
      79                 :            : 
      80                 :            :         // XStringWidth
      81                 :          0 :         sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
      82                 :            :             throw (::com::sun::star::uno::RuntimeException)
      83                 :            :         {
      84                 :          0 :             return aString.getLength();
      85                 :            :         }
      86                 :            : };
      87                 :            : 
      88 [ #  # ][ #  # ]:        841 : DEFINE_XSERVICEINFO_MULTISERVICE        (   RecentFilesMenuController                   ,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      89                 :            :                                             OWeakObject                                 ,
      90                 :            :                                             SERVICENAME_POPUPMENUCONTROLLER             ,
      91                 :            :                                             IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER
      92                 :            :                                         )
      93                 :            : 
      94                 :          0 : DEFINE_INIT_SERVICE                     (   RecentFilesMenuController, {} )
      95                 :            : 
      96                 :          0 : RecentFilesMenuController::RecentFilesMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      97                 :            :     svt::PopupMenuControllerBase( xServiceManager ),
      98         [ #  # ]:          0 :     m_bDisabled( sal_False )
      99                 :            : {
     100                 :          0 : }
     101                 :            : 
     102                 :          0 : RecentFilesMenuController::~RecentFilesMenuController()
     103                 :            : {
     104         [ #  # ]:          0 : }
     105                 :            : 
     106                 :            : // private function
     107                 :          0 : void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
     108                 :            : {
     109                 :          0 :     VCLXPopupMenu*                                     pPopupMenu        = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
     110                 :          0 :     PopupMenu*                                         pVCLPopupMenu     = 0;
     111                 :            : 
     112         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
     113                 :            : 
     114         [ #  # ]:          0 :     resetPopupMenu( rPopupMenu );
     115         [ #  # ]:          0 :     if ( pPopupMenu )
     116                 :          0 :         pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
     117                 :            : 
     118         [ #  # ]:          0 :     if ( pVCLPopupMenu )
     119                 :            :     {
     120 [ #  # ][ #  # ]:          0 :         Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
                 [ #  # ]
     121 [ #  # ][ #  # ]:          0 :         Reference< XStringWidth > xStringLength( new RecentFilesStringLength );
                 [ #  # ]
     122                 :            : 
     123         [ #  # ]:          0 :         int nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
     124                 :            : 
     125                 :            :         // New vnd.sun.star.popup: command URL to support direct dispatches
     126                 :          0 :         const rtl::OUString aCmdPrefix( "vnd.sun.star.popup:RecentFileList?entry=" );
     127                 :            : 
     128                 :          0 :         m_aRecentFilesItems.clear();
     129 [ #  # ][ #  # ]:          0 :         if (( nPickListMenuItems > 0 ) && !m_bDisabled )
     130                 :            :         {
     131         [ #  # ]:          0 :             for ( int i = 0; i < nPickListMenuItems; i++ )
     132                 :            :             {
     133         [ #  # ]:          0 :                 Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
     134                 :          0 :                 RecentFile aRecentFile;
     135                 :            : 
     136         [ #  # ]:          0 :                 for ( int j = 0; j < rPickListEntry.getLength(); j++ )
     137                 :            :                 {
     138         [ #  # ]:          0 :                     Any a = rPickListEntry[j].Value;
     139                 :            : 
     140 [ #  # ][ #  # ]:          0 :                     if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
                 [ #  # ]
     141                 :          0 :                         a >>= aRecentFile.aURL;
     142 [ #  # ][ #  # ]:          0 :                     else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
                 [ #  # ]
     143                 :          0 :                         a >>= aRecentFile.aTitle;
     144 [ #  # ][ #  # ]:          0 :                     else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD )
                 [ #  # ]
     145                 :          0 :                         a >>= aRecentFile.aPassword;
     146                 :          0 :                 }
     147                 :            : 
     148         [ #  # ]:          0 :                 m_aRecentFilesItems.push_back( aRecentFile );
     149                 :          0 :             }
     150                 :            :         }
     151                 :            : 
     152         [ #  # ]:          0 :         if ( !m_aRecentFilesItems.empty() )
     153                 :            :         {
     154                 :          0 :             URL aTargetURL;
     155                 :            : 
     156                 :          0 :             const sal_uInt32 nCount = m_aRecentFilesItems.size();
     157         [ #  # ]:          0 :             for ( sal_uInt32 i = 0; i < nCount; i++ )
     158                 :            :             {
     159                 :          0 :                 char menuShortCut[5] = "~n: ";
     160                 :            : 
     161                 :          0 :                 ::rtl::OUString aMenuShortCut;
     162         [ #  # ]:          0 :                 if ( i <= 9 )
     163                 :            :                 {
     164         [ #  # ]:          0 :                     if ( i == 9 )
     165                 :          0 :                         aMenuShortCut = rtl::OUString( "1~0: " );
     166                 :            :                     else
     167                 :            :                     {
     168                 :          0 :                         menuShortCut[1] = (char)( '1' + i );
     169         [ #  # ]:          0 :                         aMenuShortCut = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(menuShortCut) );
     170                 :            :                     }
     171                 :            :                 }
     172                 :            :                 else
     173                 :            :                 {
     174                 :          0 :                     aMenuShortCut = rtl::OUString::valueOf((sal_Int32)( i + 1 ));
     175                 :          0 :                     aMenuShortCut += rtl::OUString( ": " );
     176                 :            :                 }
     177                 :            : 
     178                 :            :                 // Abbreviate URL
     179                 :          0 :                 rtl::OUString   aURLString( aCmdPrefix + rtl::OUString::valueOf( sal_Int32( i )));
     180                 :          0 :                 rtl::OUString   aTipHelpText;
     181                 :          0 :                 rtl::OUString   aMenuTitle;
     182         [ #  # ]:          0 :                 INetURLObject   aURL( m_aRecentFilesItems[i].aURL );
     183                 :            : 
     184         [ #  # ]:          0 :                 if ( aURL.GetProtocol() == INET_PROT_FILE )
     185                 :            :                 {
     186                 :            :                     // Do handle file URL differently => convert it to a system
     187                 :            :                     // path and abbreviate it with a special function:
     188 [ #  # ][ #  # ]:          0 :                     String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
     189                 :            : 
     190         [ #  # ]:          0 :                     ::rtl::OUString aSystemPath( aFileSystemPath );
     191                 :          0 :                     ::rtl::OUString aCompactedSystemPath;
     192                 :            : 
     193                 :          0 :                     aTipHelpText = aSystemPath;
     194         [ #  # ]:          0 :                     oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
     195         [ #  # ]:          0 :                     if ( !nError )
     196 [ #  # ][ #  # ]:          0 :                         aMenuTitle = String( aCompactedSystemPath );
                 [ #  # ]
     197                 :            :                     else
     198         [ #  # ]:          0 :                         aMenuTitle = aSystemPath;
     199                 :            :                 }
     200                 :            : #if 0 // Please don't remove this commented-out code just yet,
     201                 :            :       // we can try to resurrect it later in case somebody complains
     202                 :            : #ifdef WNT
     203                 :            :                 else if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_ODMA && ::odma::DMSsAvailable ())
     204                 :            :                 {
     205                 :            :                     String aShortTitle = m_aRecentFilesItems.at( i ).aTitle;
     206                 :            : 
     207                 :            :                     // This is against all rules for using
     208                 :            :                     // proper abstraction layers and whatnot.
     209                 :            :                     // But figuring out how to do it "right"
     210                 :            :                     // would have taken the whole week.
     211                 :            :                     // So just call the odma_lib functions...
     212                 :            :                     // (odma_lib is a thin layer on
     213                 :            :                     // top of the ODMA32 DLL)
     214                 :            : 
     215                 :            :                     static ODMHANDLE handle = NULL;
     216                 :            :                     static sal_Bool beenhere = sal_False;
     217                 :            :                     ODMSTATUS status;
     218                 :            : 
     219                 :            :                     if ( ! beenhere )
     220                 :            :                     {
     221                 :            :                         status = NODMRegisterApp( &handle, ODM_API_VERSION, "sodma", NULL, NULL );
     222                 :            :                         beenhere = sal_True;
     223                 :            :                     }
     224                 :            : 
     225                 :            :                     if ( handle != NULL )
     226                 :            :                     {
     227                 :            :                         rtl::OUString s = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_MS_1252 );
     228                 :            :                         s = s.copy( strlen ( "vnd.sun.star.odma:/" ) );
     229                 :            :                         char title[47];
     230                 :            :                         status = NODMGetDocInfo( handle, rtl::OUStringToOString( s, RTL_TEXTENCODING_MS_1252 ).pData->buffer, ODM_NAME, title, sizeof ( title ) );
     231                 :            :                         aShortTitle = String::CreateFromAscii( title );
     232                 :            :                     }
     233                 :            :                     aMenuTitle += aShortTitle;
     234                 :            :                     aTipHelpText = aURLString;
     235                 :            :                 }
     236                 :            : #endif
     237                 :            : #endif
     238                 :            :                 else
     239                 :            :                 {
     240                 :            :                     // Use INetURLObject to abbreviate all other URLs
     241         [ #  # ]:          0 :                     String  aShortURL;
     242 [ #  # ][ #  # ]:          0 :                     aShortURL = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
     243         [ #  # ]:          0 :                     aMenuTitle += aShortURL;
     244         [ #  # ]:          0 :                     aTipHelpText = aURLString;
     245                 :            :                 }
     246                 :            : 
     247                 :          0 :                 ::rtl::OUString aTitle( aMenuShortCut + aMenuTitle );
     248                 :            : 
     249 [ #  # ][ #  # ]:          0 :                 pVCLPopupMenu->InsertItem( sal_uInt16( i+1 ), aTitle );
                 [ #  # ]
     250 [ #  # ][ #  # ]:          0 :                 pVCLPopupMenu->SetTipHelpText( sal_uInt16( i+1 ), aTipHelpText );
                 [ #  # ]
     251 [ #  # ][ #  # ]:          0 :                 pVCLPopupMenu->SetItemCommand( sal_uInt16( i+1 ), aURLString );
                 [ #  # ]
     252         [ #  # ]:          0 :             }
     253                 :            :         }
     254                 :            :         else
     255                 :            :         {
     256                 :            :             // No recent documents => insert "no document" string
     257 [ #  # ][ #  # ]:          0 :             String aNoDocumentStr = String( FwkResId( STR_NODOCUMENT ));
     258         [ #  # ]:          0 :             pVCLPopupMenu->InsertItem( 1, aNoDocumentStr );
     259 [ #  # ][ #  # ]:          0 :             pVCLPopupMenu->EnableItem( 1, sal_False );
     260         [ #  # ]:          0 :         }
     261         [ #  # ]:          0 :     }
     262                 :          0 : }
     263                 :            : 
     264                 :          0 : void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
     265                 :            : {
     266                 :          0 :     Reference< css::awt::XPopupMenu > xPopupMenu;
     267                 :          0 :     Reference< XDispatch >            xDispatch;
     268                 :          0 :     Reference< XDispatchProvider >    xDispatchProvider;
     269                 :          0 :     Reference< XMultiServiceFactory > xServiceManager;
     270                 :            : 
     271         [ #  # ]:          0 :     osl::ClearableMutexGuard aLock( m_aMutex );
     272         [ #  # ]:          0 :     xPopupMenu          = m_xPopupMenu;
     273 [ #  # ][ #  # ]:          0 :     xDispatchProvider   = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
     274         [ #  # ]:          0 :     xServiceManager     = m_xServiceManager;
     275         [ #  # ]:          0 :     aLock.clear();
     276                 :            : 
     277                 :          0 :     css::util::URL            aTargetURL;
     278         [ #  # ]:          0 :     Sequence< PropertyValue > aArgsList;
     279                 :            : 
     280   [ #  #  #  # ]:          0 :     if (( nIndex >= 0 ) &&
                 [ #  # ]
     281                 :          0 :         ( nIndex < sal::static_int_cast<sal_Int32>( m_aRecentFilesItems.size() )))
     282                 :            :     {
     283                 :          0 :         const RecentFile& rRecentFile = m_aRecentFilesItems[ nIndex ];
     284                 :            : 
     285                 :          0 :         aTargetURL.Complete = rRecentFile.aURL;
     286 [ #  # ][ #  # ]:          0 :         m_xURLTransformer->parseStrict( aTargetURL );
     287                 :            : 
     288                 :          0 :         sal_Int32 nSize = 2;
     289         [ #  # ]:          0 :         aArgsList.realloc(nSize);
     290         [ #  # ]:          0 :         aArgsList[0].Name = ::rtl::OUString( "Referer" );
     291 [ #  # ][ #  # ]:          0 :         aArgsList[0].Value = makeAny( ::rtl::OUString(SFX_REFERER_USER ));
     292                 :            : 
     293                 :            :         // documents in the picklist will never be opened as templates
     294         [ #  # ]:          0 :         aArgsList[1].Name = ::rtl::OUString( "AsTemplate" );
     295 [ #  # ][ #  # ]:          0 :         aArgsList[1].Value = makeAny( (sal_Bool) sal_False );
     296                 :            : 
     297         [ #  # ]:          0 :         if (!m_aModuleName.isEmpty())
     298                 :            :         {
     299                 :            :             // Type detection needs to know which app we are opening it from.
     300         [ #  # ]:          0 :             aArgsList.realloc(++nSize);
     301         [ #  # ]:          0 :             aArgsList[nSize-1].Name = "DocumentService";
     302 [ #  # ][ #  # ]:          0 :             aArgsList[nSize-1].Value <<= m_aModuleName;
     303                 :            :         }
     304                 :            : 
     305 [ #  # ][ #  # ]:          0 :         xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString("_default"), 0 );
                 [ #  # ]
     306                 :            :     }
     307                 :            : 
     308         [ #  # ]:          0 :     if ( xDispatch.is() )
     309                 :            :     {
     310                 :            :         // Call dispatch asychronously as we can be destroyed while dispatch is
     311                 :            :         // executed. VCL is not able to survive this as it wants to call listeners
     312                 :            :         // after select!!!
     313 [ #  # ][ #  # ]:          0 :         LoadRecentFile* pLoadRecentFile = new LoadRecentFile;
     314         [ #  # ]:          0 :         pLoadRecentFile->xDispatch  = xDispatch;
     315                 :          0 :         pLoadRecentFile->aTargetURL = aTargetURL;
     316         [ #  # ]:          0 :         pLoadRecentFile->aArgSeq    = aArgsList;
     317 [ #  # ][ #  # ]:          0 :         Application::PostUserEvent( STATIC_LINK(0, RecentFilesMenuController, ExecuteHdl_Impl), pLoadRecentFile );
     318 [ #  # ][ #  # ]:          0 :     }
     319                 :          0 : }
     320                 :            : 
     321                 :            : // XEventListener
     322                 :          0 : void SAL_CALL RecentFilesMenuController::disposing( const EventObject& ) throw ( RuntimeException )
     323                 :            : {
     324         [ #  # ]:          0 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     325                 :            : 
     326         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     327                 :          0 :     m_xFrame.clear();
     328                 :          0 :     m_xDispatch.clear();
     329                 :          0 :     m_xServiceManager.clear();
     330                 :            : 
     331         [ #  # ]:          0 :     if ( m_xPopupMenu.is() )
     332 [ #  # ][ #  # ]:          0 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
                 [ #  # ]
     333         [ #  # ]:          0 :     m_xPopupMenu.clear();
     334                 :          0 : }
     335                 :            : 
     336                 :            : // XStatusListener
     337                 :          0 : void SAL_CALL RecentFilesMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
     338                 :            : {
     339         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     340         [ #  # ]:          0 :     m_bDisabled = !Event.IsEnabled;
     341                 :          0 : }
     342                 :            : 
     343                 :          0 : void SAL_CALL RecentFilesMenuController::select( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
     344                 :            : {
     345                 :          0 :     Reference< css::awt::XPopupMenu > xPopupMenu;
     346                 :          0 :     Reference< XDispatch >            xDispatch;
     347                 :          0 :     Reference< XDispatchProvider >    xDispatchProvider;
     348                 :          0 :     Reference< XMultiServiceFactory > xServiceManager;
     349                 :            : 
     350         [ #  # ]:          0 :     osl::ClearableMutexGuard aLock( m_aMutex );
     351         [ #  # ]:          0 :     xPopupMenu          = m_xPopupMenu;
     352 [ #  # ][ #  # ]:          0 :     xDispatchProvider   = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
     353         [ #  # ]:          0 :     xServiceManager     = m_xServiceManager;
     354         [ #  # ]:          0 :     aLock.clear();
     355                 :            : 
     356                 :          0 :     css::util::URL aTargetURL;
     357         [ #  # ]:          0 :     Sequence< PropertyValue > aArgsList;
     358                 :            : 
     359 [ #  # ][ #  # ]:          0 :     if ( xPopupMenu.is() && xDispatchProvider.is() )
                 [ #  # ]
     360                 :            :     {
     361                 :          0 :         VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu );
     362         [ #  # ]:          0 :         if ( pPopupMenu )
     363         [ #  # ]:          0 :             executeEntry( rEvent.MenuId-1 );
     364 [ #  # ][ #  # ]:          0 :     }
     365                 :          0 : }
     366                 :            : 
     367                 :          0 : void SAL_CALL RecentFilesMenuController::activate( const css::awt::MenuEvent& ) throw (RuntimeException)
     368                 :            : {
     369         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     370 [ #  # ][ #  # ]:          0 :     impl_setPopupMenu();
     371                 :          0 : }
     372                 :            : 
     373                 :            : // XPopupMenuController
     374                 :          0 : void RecentFilesMenuController::impl_setPopupMenu()
     375                 :            : {
     376         [ #  # ]:          0 :     if ( m_xPopupMenu.is() )
     377                 :          0 :         fillPopupMenu( m_xPopupMenu );
     378                 :          0 : }
     379                 :            : 
     380                 :          0 : void SAL_CALL RecentFilesMenuController::updatePopupMenu() throw (RuntimeException)
     381                 :            : {
     382         [ #  # ]:          0 :     osl::ClearableMutexGuard aLock( m_aMutex );
     383                 :            : 
     384         [ #  # ]:          0 :     throwIfDisposed();
     385                 :            : 
     386         [ #  # ]:          0 :     Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
     387                 :          0 :     Reference< XDispatch > xDispatch( m_xDispatch );
     388                 :          0 :     com::sun::star::util::URL aTargetURL;
     389                 :          0 :     aTargetURL.Complete = m_aCommandURL;
     390 [ #  # ][ #  # ]:          0 :     m_xURLTransformer->parseStrict( aTargetURL );
     391         [ #  # ]:          0 :     aLock.clear();
     392                 :            : 
     393                 :            :     // Add/remove status listener to get a status update once
     394         [ #  # ]:          0 :     if ( xDispatch.is() )
     395                 :            :     {
     396 [ #  # ][ #  # ]:          0 :         xDispatch->addStatusListener( xStatusListener, aTargetURL );
     397 [ #  # ][ #  # ]:          0 :         xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     398         [ #  # ]:          0 :     }
     399                 :          0 : }
     400                 :            : 
     401                 :            : // XDispatchProvider
     402                 :          0 : Reference< XDispatch > SAL_CALL RecentFilesMenuController::queryDispatch(
     403                 :            :     const URL& aURL,
     404                 :            :     const ::rtl::OUString& /*sTarget*/,
     405                 :            :     sal_Int32 /*nFlags*/ )
     406                 :            : throw( RuntimeException )
     407                 :            : {
     408         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     409                 :            : 
     410         [ #  # ]:          0 :     throwIfDisposed();
     411                 :            : 
     412         [ #  # ]:          0 :     if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 )
     413         [ #  # ]:          0 :         return Reference< XDispatch >( static_cast< OWeakObject* >( this ), UNO_QUERY );
     414                 :            :     else
     415         [ #  # ]:          0 :         return Reference< XDispatch >();
     416                 :            : }
     417                 :            : 
     418                 :            : // XDispatch
     419                 :          0 : void SAL_CALL RecentFilesMenuController::dispatch(
     420                 :            :     const URL& aURL,
     421                 :            :     const Sequence< PropertyValue >& /*seqProperties*/ )
     422                 :            : throw( RuntimeException )
     423                 :            : {
     424         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     425                 :            : 
     426         [ #  # ]:          0 :     throwIfDisposed();
     427                 :            : 
     428         [ #  # ]:          0 :     if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 )
     429                 :            :     {
     430                 :            :         // Parse URL to retrieve entry argument and its value
     431                 :          0 :         sal_Int32 nQueryPart = aURL.Complete.indexOf( '?', m_aBaseURL.getLength() );
     432         [ #  # ]:          0 :         if ( nQueryPart > 0 )
     433                 :            :         {
     434                 :          0 :             const rtl::OUString aEntryArgStr( "entry=" );
     435                 :          0 :             sal_Int32 nEntryArg = aURL.Complete.indexOf( aEntryArgStr, nQueryPart );
     436                 :          0 :             sal_Int32 nEntryPos = nEntryArg + aEntryArgStr.getLength();
     437 [ #  # ][ #  # ]:          0 :             if (( nEntryArg > 0 ) && ( nEntryPos < aURL.Complete.getLength() ))
                 [ #  # ]
     438                 :            :             {
     439                 :          0 :                 sal_Int32 nAddArgs = aURL.Complete.indexOf( '&', nEntryPos );
     440                 :          0 :                 rtl::OUString aEntryArg;
     441                 :            : 
     442         [ #  # ]:          0 :                 if ( nAddArgs < 0 )
     443                 :          0 :                     aEntryArg = aURL.Complete.copy( nEntryPos );
     444                 :            :                 else
     445                 :          0 :                     aEntryArg = aURL.Complete.copy( nEntryPos, nAddArgs-nEntryPos );
     446                 :            : 
     447                 :          0 :                 sal_Int32 nEntry = aEntryArg.toInt32();
     448         [ #  # ]:          0 :                 executeEntry( nEntry );
     449                 :          0 :             }
     450                 :            :         }
     451         [ #  # ]:          0 :     }
     452                 :          0 : }
     453                 :            : 
     454                 :          0 : void SAL_CALL RecentFilesMenuController::addStatusListener(
     455                 :            :     const Reference< XStatusListener >& xControl,
     456                 :            :     const URL& aURL )
     457                 :            : throw( RuntimeException )
     458                 :            : {
     459         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     460                 :            : 
     461         [ #  # ]:          0 :     throwIfDisposed();
     462                 :            : 
     463 [ #  # ][ #  # ]:          0 :     svt::PopupMenuControllerBase::addStatusListener( xControl, aURL );
     464                 :          0 : }
     465                 :            : 
     466                 :          0 : void SAL_CALL RecentFilesMenuController::removeStatusListener(
     467                 :            :     const Reference< XStatusListener >& xControl,
     468                 :            :     const URL& aURL )
     469                 :            : throw( RuntimeException )
     470                 :            : {
     471                 :          0 :     svt::PopupMenuControllerBase::removeStatusListener( xControl, aURL );
     472                 :          0 : }
     473                 :            : 
     474                 :          0 : IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile*, pLoadRecentFile )
     475                 :            : {
     476                 :            :     try
     477                 :            :     {
     478                 :            :         // Asynchronous execution as this can lead to our own destruction!
     479                 :            :         // Framework can recycle our current frame and the layout manager disposes all user interface
     480                 :            :         // elements if a component gets detached from its frame!
     481 [ #  # ][ #  # ]:          0 :         pLoadRecentFile->xDispatch->dispatch( pLoadRecentFile->aTargetURL, pLoadRecentFile->aArgSeq );
     482                 :            :     }
     483                 :          0 :     catch ( const Exception& )
     484                 :            :     {
     485                 :            :     }
     486                 :            : 
     487         [ #  # ]:          0 :     delete pLoadRecentFile;
     488         [ #  # ]:          0 :     return 0;
     489                 :            : }
     490                 :            : 
     491                 :            : }
     492                 :            : 
     493                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10