You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2013/05/26 00:10:24 UTC

svn commit: r1486373 - in /openoffice/trunk/main/framework/source/services: backingwindow.cxx backingwindow.hxx

Author: arielch
Date: Sat May 25 22:10:24 2013
New Revision: 1486373

URL: http://svn.apache.org/r1486373
Log:
Recent files menu in the StartModule should be the same as in the menubar

Modified:
    openoffice/trunk/main/framework/source/services/backingwindow.cxx
    openoffice/trunk/main/framework/source/services/backingwindow.hxx

Modified: openoffice/trunk/main/framework/source/services/backingwindow.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/framework/source/services/backingwindow.cxx?rev=1486373&r1=1486372&r2=1486373&view=diff
==============================================================================
--- openoffice/trunk/main/framework/source/services/backingwindow.cxx (original)
+++ openoffice/trunk/main/framework/source/services/backingwindow.cxx Sat May 25 22:10:24 2013
@@ -46,6 +46,8 @@
 #include "comphelper/sequenceashashmap.hxx"
 #include "comphelper/configurationhelper.hxx"
 
+#include <toolkit/awt/vclxmenu.hxx>
+
 #include "cppuhelper/implbase1.hxx"
 
 #include "rtl/strbuf.hxx"
@@ -58,7 +60,7 @@
 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
 #include "com/sun/star/task/XJobExecutor.hpp"
 #include "com/sun/star/util/XStringWidth.hpp"
-
+#include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
 
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::frame;
@@ -66,6 +68,8 @@ using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star;
 using namespace framework;
 
+#define RECENT_FILE_LIST    ".uno:RecentFileList"
+
 #define WRITER_URL      "private:factory/swriter"
 #define CALC_URL        "private:factory/scalc"
 #define IMPRESS_WIZARD_URL     "private:factory/simpress?slot=6686"
@@ -150,15 +154,18 @@ BackingWindow::BackingWindow( Window* i_
     mnLayoutStyle( 0 ),
     mpAccExec( NULL ),
     mnBtnPos( 120 ),
-    mnBtnTop( 150 ),
-    mpRecentMenu( NULL )
+    mnBtnTop( 150 )
 {
     mnColumnWidth[0] = mnColumnWidth[1] = 0;
     mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0;
 
     try
     {
-        Reference<lang::XMultiServiceFactory> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY);
+        mxContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
+
+        Reference<lang::XMultiServiceFactory> xConfig(
+            mxContext->getServiceManager()->createInstanceWithContext(
+                SERVICENAME_CFGPROVIDER, mxContext), UNO_QUERY);
         if( xConfig.is() )
         {
             Sequence<Any> args(1);
@@ -176,9 +183,22 @@ BackingWindow::BackingWindow( Window* i_
                 mnLayoutStyle = value.get<sal_Int32>();
             }
         }
+
+        mxPopupMenuFactory.set(
+            frame::PopupMenuControllerFactory::create( mxContext ) );
+        // TODO If there is no PopupMenuController, the button should be a nomral one not a MenuButton
+        if ( mxPopupMenuFactory->hasController(
+            DECLARE_ASCII( RECENT_FILE_LIST ) , SERVICENAME_STARTMODULE ) )
+        {
+            mxPopupMenu.set( mxContext->getServiceManager()->createInstanceWithContext(
+                DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), mxContext ), uno::UNO_QUERY_THROW );
+        }
     }
-    catch (Exception& )
+    catch (const Exception& e)
     {
+        OSL_TRACE( "BackingWindow - caught an exception! %s",
+                   rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+        (void) e;
     }
 
     String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
@@ -244,8 +264,24 @@ BackingWindow::BackingWindow( Window* i_
 
 BackingWindow::~BackingWindow()
 {
-    delete mpRecentMenu;
     delete mpAccExec;
+
+    if( mxPopupMenuController.is() )
+    {
+        Reference< lang::XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
+        if( xComponent.is() )
+        {
+            try
+            {
+                xComponent->dispose();
+            }
+            catch (...)
+            {}
+        }
+        mxPopupMenuController.clear();
+    }
+    mxPopupMenuFactory.clear();
+    mxPopupMenu.clear();
 }
 
 void BackingWindow::GetFocus()
@@ -275,117 +311,42 @@ void BackingWindow::DataChanged( const D
 
 void BackingWindow::prepareRecentFileMenu()
 {
-    if( ! mpRecentMenu )
-        mpRecentMenu = new PopupMenu();
-    mpRecentMenu->Clear();
-    maRecentFiles.clear();
-    
-    // get recent file list and dispatch arguments
-    Sequence< Sequence< PropertyValue > > aHistoryList( SvtHistoryOptions().GetList( ePICKLIST ) );
+    if( ! mxPopupMenu.is() )
+        return;
 
-    sal_Int32 nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
-        
-    if( ( nPickListMenuItems > 0 ) )
+    if ( !mxPopupMenuController.is() )
     {
-        maRecentFiles.reserve( nPickListMenuItems );
-        for ( sal_Int32 i = 0; i < nPickListMenuItems; i++ )
-        {
-            Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
-            rtl::OUString aURL, aFilter, aFilterOpt, aTitle;
-            
-            for ( sal_Int32 j = 0; j < rPickListEntry.getLength(); j++ )
-            {
-                const Any& a = rPickListEntry[j].Value;
-                
-                if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
-                    a >>= aURL;
-                else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
-                {
-                    a >>= aFilter;
-                    sal_Int32 nPos = aFilter.indexOf( '|' );
-                    if ( nPos >= 0 )
-                    {
-                        if ( nPos < ( aFilter.getLength() - 1 ) )
-                            aFilterOpt = aFilter.copy( nPos+1 );
-                        aFilter = aFilter.copy( 0, nPos-1 );
-                    }
-                }
-                else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
-                    a >>= aTitle;
-            }
-            maRecentFiles.push_back( LoadRecentFile() );
-            maRecentFiles.back().aTargetURL = aURL;
-
-            sal_Int32 nArgs = aFilterOpt.getLength() ? 4 : 3;
-            Sequence< PropertyValue >& rArgsList( maRecentFiles.back().aArgSeq );
-            rArgsList.realloc( nArgs );
-
-            nArgs--;
-            rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
-            rArgsList[nArgs].Value = makeAny( aFilter );
-            
-            if( aFilterOpt.getLength() )
-            {
-                nArgs--;
-                rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" ));
-                rArgsList[nArgs].Value = makeAny( aFilterOpt );
-            }
+        uno::Sequence< uno::Any > aArgs( 2 );
+        beans::PropertyValue aProp;
 
-            // documents in the picklist will never be opened as templates
-            nArgs--;
-            rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" ));
-            rArgsList[nArgs].Value = makeAny( (sal_Bool) sal_False );
-
-            nArgs--;
-            rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
-            rArgsList[nArgs].Value = makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:user" ) ) );
-            
-            // and finally create an entry in the popupmenu
-            rtl::OUString	aMenuTitle;
-            INetURLObject	aURLObj( aURL );
-            
-            if ( aURLObj.GetProtocol() == INET_PROT_FILE )
-            {
-                // Do handle file URL differently => convert it to a system
-                // path and abbreviate it with a special function:
-                String aFileSystemPath( aURLObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
-                
-                rtl::OUString	aSystemPath( aFileSystemPath );
-                rtl::OUString	aCompactedSystemPath;
-                
-                oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
-                if ( !nError )
-                    aMenuTitle = String( aCompactedSystemPath );
-                else
-                    aMenuTitle = aSystemPath;
-            }
-            else
-            {
-                // Use INetURLObject to abbreviate all other URLs
-                Reference< util::XStringWidth > xStringLength( new RecentFilesStringLength() );
-                aMenuTitle = aURLObj.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
-            }
-            rtl::OUStringBuffer aBuf( aMenuTitle.getLength() + 5 );
-            if( i < 9 )
-            {
-                aBuf.append( sal_Unicode( '~' ) );
-                aBuf.append( i+1 );
-            }
-            else if( i == 9 )
-                aBuf.appendAscii( "1~0" );
-            else
-                aBuf.append( i+1 );
-            aBuf.appendAscii( ": " );
-            aBuf.append( aMenuTitle );
-            mpRecentMenu->InsertItem( static_cast<sal_uInt16>(i+1), aBuf.makeStringAndClear() );
+        aProp.Name = DECLARE_ASCII( "Frame" );
+        aProp.Value <<= mxFrame;
+        aArgs[0] <<= aProp;
+
+        aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
+        aProp.Value <<= SERVICENAME_STARTMODULE;
+        aArgs[1] <<= aProp;
+        try
+        {
+            mxPopupMenuController.set(
+                mxPopupMenuFactory->createInstanceWithArgumentsAndContext(
+                    DECLARE_ASCII( RECENT_FILE_LIST ), aArgs, mxContext),
+                        uno::UNO_QUERY_THROW );
+            mxPopupMenuController->setPopupMenu( mxPopupMenu );
         }
+        catch ( const Exception &e )
+        {
+            OSL_TRACE( "BackingWindow - caught an exception! %s",
+                       rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+            (void) e;
+        }
+
+        PopupMenu *pRecentMenu = NULL;
+        VCLXMenu* pTKMenu = VCLXMenu::GetImplementation( mxPopupMenu );
+        if ( pTKMenu )
+            pRecentMenu = dynamic_cast< PopupMenu * >( pTKMenu->GetMenu() );
+        maOpenButton.SetPopupMenu( pRecentMenu );
     }
-    else
-    {
-        String aNoDoc( FwkResId( STR_NODOCUMENT ) );
-        mpRecentMenu->InsertItem( 0xffff, aNoDoc );
-    }
-    maOpenButton.SetPopupMenu( mpRecentMenu );
 }
 
 void BackingWindow::initBackground()
@@ -455,7 +416,6 @@ void BackingWindow::initBackground()
     loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
     
     maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
-    maOpenButton.SetSelectHdl( LINK( this, BackingWindow, SelectHdl ) );
     maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) );
 }
 
@@ -1026,19 +986,6 @@ IMPL_LINK( BackingWindow, ClickHdl, Butt
     return 0;
 }
 
-IMPL_LINK( BackingWindow, SelectHdl, Button*, pButton )
-{
-    if( pButton == &maOpenButton )
-    {
-        sal_Int32 nItem = sal_Int32(maOpenButton.GetCurItemId())-1;
-        if( nItem >= 0 && nItem < sal_Int32(maRecentFiles.size()) )
-        {
-            Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
-            dispatchURL( maRecentFiles[nItem].aTargetURL, rtl::OUString(), xFrame, maRecentFiles[nItem].aArgSeq );
-        }
-    }
-    return 0;
-}
 
 IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton )
 {

Modified: openoffice/trunk/main/framework/source/services/backingwindow.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/framework/source/services/backingwindow.hxx?rev=1486373&r1=1486372&r2=1486373&view=diff
==============================================================================
--- openoffice/trunk/main/framework/source/services/backingwindow.hxx (original)
+++ openoffice/trunk/main/framework/source/services/backingwindow.hxx Sat May 25 22:10:24 2013
@@ -35,6 +35,10 @@
 #include "unotools/moduleoptions.hxx"
 #include "svtools/acceleratorexecute.hxx"
 
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/frame/XUIControllerFactory.hpp>
+#include <com/sun/star/frame/XPopupMenuController.hpp>
+#include <com/sun/star/awt/XPopupMenu.hpp>
 #include "com/sun/star/frame/XDispatchProvider.hpp"
 #include "com/sun/star/frame/XDesktop.hpp"
 #include "com/sun/star/frame/XFrame.hpp"
@@ -74,16 +78,14 @@ namespace framework
 
     class BackingWindow : public Window
     {
-        struct LoadRecentFile
-        {
-            rtl::OUString                                                             aTargetURL;
-            com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >     aArgSeq;
-        };
-        
+
+        com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >         mxContext;
         com::sun::star::uno::Reference<com::sun::star::frame::XDesktop>                  mxDesktop;
         com::sun::star::uno::Reference<com::sun::star::frame::XDispatchProvider >        mxDesktopDispatchProvider;
         com::sun::star::uno::Reference<com::sun::star::frame::XFrame>                    mxFrame;
-        com::sun::star::uno::Reference<com::sun::star::document::XEventBroadcaster>      mxBroadcaster;
+        com::sun::star::uno::Reference< com::sun::star::frame::XUIControllerFactory >    mxPopupMenuFactory;
+        com::sun::star::uno::Reference< com::sun::star::frame::XPopupMenuController >    mxPopupMenuController;
+        com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >                mxPopupMenu;
 
         FixedText                       maWelcome;
         Size                            maWelcomeSize;
@@ -125,9 +127,6 @@ namespace framework
         svt::AcceleratorExecute*        mpAccExec;
         long                            mnBtnPos;
         long                            mnBtnTop;
-        
-        PopupMenu*                      mpRecentMenu;
-        std::vector< LoadRecentFile >   maRecentFiles;
 
         static const int nItemId_Extensions = 1;
         static const int nItemId_Reg = 2;
@@ -154,7 +153,6 @@ namespace framework
                           );
 
         DECL_LINK( ClickHdl, Button* );
-        DECL_LINK( SelectHdl, Button* );
         DECL_LINK( ActivateHdl, Button* );
         DECL_LINK( ToolboxHdl, void* );