--- /dev/null	2006-03-04 20:11:20.000000000 +0000
+++ offapi/com/sun/star/ui/dialogs/XFilePickerWorkaround.idl	2006-03-14 13:12:17.000000000 +0000
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  
+ *
+ *  
+ *
+ *  
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+#ifndef __com_sun_star_ui_dialogs_XFilePickerWorkaround_idl__
+#define __com_sun_star_ui_dialogs_XFilePickerWorkaround_idl__
+
+#ifndef __com_sun_star_uno_XInterface_idl__
+#include <com/sun/star/uno/XInterface.idl>
+#endif
+
+//=============================================================================
+
+module com { module sun { module star { module ui { module dialogs {
+
+//=============================================================================
+/** It's an "internal" interface to solve the problems behind XFilePicker.getFiles()
+    in combination with multiselection.
+
+    This additional interface will be implemented by some dialogs only.
+    But it must be preferred if it exists and multiselection is used.
+*/
+
+interface XFilePickerWorkaround : ::com::sun::star::uno::XInterface
+{
+	//-------------------------------------------------------------------------
+	/**	Does the same then XFilePicker.getFiles() does ... excepting
+        that independend from an single/multiselection mode every item of
+        the returned list is a value containing path and file name.
+
+        This is needed because some dialogs (e.g. system dialogs) knows
+        additional features to return e.g. the results of a file search or
+        items of a recent files list. And in such case (in combination with multiselection)
+        every item of the resulting list can have another path.
+	*/
+	sequence< string > getFilesAsURIs();
+};
+
+//=============================================================================
+
+}; }; }; }; };
+
+
+#endif
+
Index: offapi/com/sun/star/ui/dialogs/makefile.mk
===================================================================
RCS file: /cvs/api/offapi/com/sun/star/ui/dialogs/makefile.mk,v
retrieving revision 1.9
diff -u -p -u -r1.9 makefile.mk
--- offapi/com/sun/star/ui/dialogs/makefile.mk	8 Sep 2005 08:41:20 -0000	1.9
+++ offapi/com/sun/star/ui/dialogs/makefile.mk	14 Mar 2006 13:46:14 -0000
@@ -63,6 +63,7 @@ IDLFILES=\
 	XFilePickerControlAccess.idl	\
 	XFilePickerListener.idl\
 	XFilePickerNotifier.idl\
+	XFilePickerWorkaround.idl\
 	XFilePreview.idl\
 	XFilterGroupManager.idl\
 	XFilterManager.idl\




--- fpicker/source/unx/gnome/SalGtkFilePicker.cxx	2006-03-07 08:52:03.000000000 +0000
+++ fpicker/source/unx/gnome/SalGtkFilePicker.cxx	2006-03-15 13:05:27.482339864 +0000
@@ -157,12 +157,13 @@
 }
 
 SalGtkFilePicker::SalGtkFilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) : 
-	cppu::WeakComponentImplHelper9< 		
+	cppu::WeakComponentImplHelper10< 		
 		XFilterManager, 
-	        XFilterGroupManager,
-	        XFilePickerControlAccess,
+	    XFilterGroupManager,
+	    XFilePickerControlAccess,
 		XFilePickerNotifier,
-	        XFilePreview,
+	    XFilePreview,
+        XFilePickerWorkaround,
 		lang::XInitialization,
 		util::XCancellable,
 		lang::XEventListener, 
@@ -877,55 +878,41 @@
 	return implgetDisplayDirectory();
 }
 
+// Obsoleted by XFilePickerWorkaround::getFilesAsURIs
 uno::Sequence<rtl::OUString> SAL_CALL SalGtkFilePicker::getFiles() throw( uno::RuntimeException )
 {
+		uno::Sequence<rtl::OUString> aFiles = getFilesAsURIs();
+		/*
+		  The previous multiselection API design was completely broken
+		  and unimplementable for some hetrogenous pseudo-URIs eg. search://
+		  Thus crop unconditionally to a single selection.
+		*/
+		aFiles.realloc (1);
+		return aFiles;
+}
+
+uno::Sequence<rtl::OUString> SAL_CALL SalGtkFilePicker::getFilesAsURIs() throw( uno::RuntimeException )
+{
 	OSL_ASSERT( m_pDialog != NULL );
 	::vos::OGuard aGuard( Application::GetSolarMutex() );
 
 	GSList* pPathList = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER(m_pDialog) );
 	
-	int nFromCount = g_slist_length( pPathList );
-	OSL_TRACE( "GETFILES called %d files\n", nFromCount );
+	int nCount = g_slist_length( pPathList );
+	int nIndex = 0;
+	OSL_TRACE( "GETFILES called %d files\n", nCount );
 
 	// get the current action setting
 	GtkFileChooserAction eAction = gtk_file_chooser_get_action(
         GTK_FILE_CHOOSER( m_pDialog ));
 	
-    /*
-    This is insane, if its one file then return the URL, 
-    If its its more return the URL of the dir as the first entry, 
-    and then list each seperate entry (relative to the base URL) after it
-    */
-    bool bMultiple = nFromCount > 1;
-    int nToCount = bMultiple ? nFromCount + 1 : nFromCount;
-    int nURLOffset = 0;
-	uno::Sequence< rtl::OUString > aSelectedFiles(nToCount);
-
-    if (bMultiple)
-    {
-		gchar *path = gtk_file_chooser_get_current_folder_uri( 
-            GTK_FILE_CHOOSER( m_pDialog ));
-		if (!path)
-		{
-		    g_warning ("unusual (NULL) file chooser URI");
-			path = g_strdup ("");
-			nURLOffset = 0;
-		}
-		else
-			nURLOffset = strlen (path) + 1;
-        aSelectedFiles[0] = uritounicode(path);
-        g_free(path);
-    }
+	uno::Sequence< rtl::OUString > aSelectedFiles(nCount);
 
 	// Convert to OOo
-	for( int nToIndex = bMultiple ? 1 : 0;
-        ((nToIndex < nToCount) && pPathList); 
-        ++nToIndex, pPathList = g_slist_next(pPathList) 
-       )
-	{
-		const gchar *path = reinterpret_cast<gchar*>(pPathList->data) 
-            + nURLOffset;
-		aSelectedFiles[ nToIndex ] = uritounicode(path);
+	for( GSList *pElem = pPathList; pElem; pElem = pElem->next)
+	{
+		gchar *pURI = reinterpret_cast<gchar*>(pElem->data);
+		aSelectedFiles[ nIndex ] = uritounicode(pURI);
 
 		if( GTK_FILE_CHOOSER_ACTION_SAVE == eAction )
 		{
@@ -945,12 +932,12 @@
             }
             else
             {
-                if( aSelectedFiles[nToIndex].indexOf('.') > 0 )
+                if( aSelectedFiles[nIndex].indexOf('.') > 0 )
                 {
                     rtl::OUString sExtension;
                     nTokenIndex = 0;
                     do
-                        sExtension = aSelectedFiles[nToIndex].getToken( 0, '.', nTokenIndex );
+                        sExtension = aSelectedFiles[nIndex].getToken( 0, '.', nTokenIndex );
                     while( nTokenIndex >= 0 );
 
                     if( sExtension.getLength() >= 3 ) // 3 = typical/minimum extension length
@@ -1017,7 +1004,7 @@
 			{
 				//if the filename does not already have the auto extension, stick it on
 				OUString sExtension = OUString::createFromAscii( "." ) + sToken;
-				OUString &rBase = aSelectedFiles[nToIndex];
+				OUString &rBase = aSelectedFiles[nIndex];
 				sal_Int32 nExtensionIdx = rBase.getLength() - sExtension.getLength();
 				OSL_TRACE( "idx are %d %d\n", rBase.lastIndexOf( sExtension ), nExtensionIdx );
 
@@ -1027,7 +1014,8 @@
 
 		}
 
-		g_free( ( char* )( pPathList->data ) );
+		nIndex++;
+		g_free( pURI );
 	}
 
 	g_slist_free( pPathList );
Index: fpicker/source/unx/gnome/SalGtkFilePicker.hxx
===================================================================
RCS file: /cvs/gsl/fpicker/source/unx/gnome/SalGtkFilePicker.hxx,v
retrieving revision 1.7
diff -u -r1.7 SalGtkFilePicker.hxx
--- fpicker/source/unx/gnome/SalGtkFilePicker.hxx	8 Sep 2005 23:35:03 -0000	1.7
+++ fpicker/source/unx/gnome/SalGtkFilePicker.hxx	15 Mar 2006 14:50:44 -0000
@@ -40,8 +40,8 @@
 //	includes of other projects
 //_______________________________________________________________________________________________________________________
 
-#ifndef _CPPUHELPER_COMPBASE9_HXX_
-#include <cppuhelper/compbase9.hxx>
+#ifndef _CPPUHELPER_COMPBASE10_HXX_
+#include <cppuhelper/compbase10.hxx>
 #endif
 
 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
@@ -108,17 +108,18 @@
 //----------------------------------------------------------
 
 class SalGtkFilePicker : 
-        public SalGtkPicker,
-	public cppu::WeakComponentImplHelper9<         
+    public SalGtkPicker,
+	public cppu::WeakComponentImplHelper10<
         ::com::sun::star::ui::dialogs::XFilterManager,
         ::com::sun::star::ui::dialogs::XFilterGroupManager,
         ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
         ::com::sun::star::ui::dialogs::XFilePickerNotifier,
         ::com::sun::star::ui::dialogs::XFilePreview,
-	::com::sun::star::lang::XInitialization,
+        ::com::sun::star::ui::dialogs::XFilePickerWorkaround,
+		::com::sun::star::lang::XInitialization,
         ::com::sun::star::util::XCancellable,
-	::com::sun::star::lang::XEventListener,
-	::com::sun::star::lang::XServiceInfo >		
+		::com::sun::star::lang::XEventListener,
+		::com::sun::star::lang::XServiceInfo >		
 {
 	public:
 
@@ -161,10 +162,17 @@
 		virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  ) 
 			throw( ::com::sun::star::uno::RuntimeException );
 
-		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  ) 
+		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles()
 			throw( ::com::sun::star::uno::RuntimeException );
 
 		//------------------------------------------------------------------------------------
+		// XFilePickerWorkaround functions
+		//------------------------------------------------------------------------------------
+
+		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFilesAsURIs()
+				throw (::com::sun::star::uno::RuntimeException);
+
+		//------------------------------------------------------------------------------------
 		// XFilterManager functions
 		//------------------------------------------------------------------------------------
 
Index: fpicker/source/unx/gnome/SalGtkPicker.hxx
===================================================================
RCS file: /cvs/gsl/fpicker/source/unx/gnome/SalGtkPicker.hxx,v
retrieving revision 1.6
diff -u -r1.6 SalGtkPicker.hxx
--- fpicker/source/unx/gnome/SalGtkPicker.hxx	8 Sep 2005 23:36:05 -0000	1.6
+++ fpicker/source/unx/gnome/SalGtkPicker.hxx	15 Mar 2006 14:50:45 -0000
@@ -48,6 +48,10 @@
 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
 #endif
 
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERWORKAROUND_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerWorkaround.hpp>
+#endif
+
 #ifndef _COM_SUN_STAR_UI_XFOLDERPICKER_HPP_
 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
 #endif
Index: sfx2/source/dialog/filedlghelper.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/dialog/filedlghelper.cxx,v
retrieving revision 1.119
diff -u -r1.119 filedlghelper.cxx
--- sfx2/source/dialog/filedlghelper.cxx	21 Dec 2005 13:45:27 -0000	1.119
+++ sfx2/source/dialog/filedlghelper.cxx	16 Mar 2006 15:41:06 -0000
@@ -69,6 +69,9 @@
 #ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERNOTIFIER_HPP_
 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
 #endif
+#ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERWORKAROUND_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerWorkaround.hpp>
+#endif
 #ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPREVIEW_HPP_
 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
 #endif
@@ -1549,10 +1559,30 @@
 		getRealFilter( rFilter );
 
 		// fill the rpURLList
-		Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
+		Reference<XFilePickerWorkaround> xFileWorkarounds(mxFileDlg, UNO_QUERY);
+		Sequence < OUString > aPathSeq;
+		if (xFileWorkarounds.is())
+		{
+			aPathSeq = xFileWorkarounds->getFilesAsURIs();
+			if ( !aPathSeq.getLength() )
+				return ERRCODE_ABORT;
 
-		if ( aPathSeq.getLength() )
+			rpURLList = new SvStringsDtor;
+
+			for ( USHORT i = 0; i < aPathSeq.getLength(); ++i )
+			{
+				String* pURL = new String( aPathSeq[i] );
+				rpURLList->Insert( pURL, rpURLList->Count() );
+			}
+		}
+		else
 		{
+			OSL_TRACE("Obsolete & broken multiselect code path");
+			aPathSeq = mxFileDlg->getFiles();
+
+			if ( !aPathSeq.getLength() )
+				return ERRCODE_ABORT;
+
 			rpURLList = new SvStringsDtor;
 
 			if ( aPathSeq.getLength() == 1 )
@@ -1578,11 +1608,9 @@
 					rpURLList->Insert( pURL, rpURLList->Count() );
 				}
 			}
-			SaveLastUsedFilter();
-			return ERRCODE_NONE;
 		}
-		else
-			return ERRCODE_ABORT;
+		SaveLastUsedFilter();
+		return ERRCODE_NONE;
 	}
 	else
 		return ERRCODE_ABORT;

Index: fpicker/source/office/OfficeFilePicker.cxx
===================================================================
RCS file: /cvs/gsl/fpicker/source/office/OfficeFilePicker.cxx,v
retrieving revision 1.4
diff -u -r1.4 OfficeFilePicker.cxx
--- fpicker/source/office/OfficeFilePicker.cxx	11 Nov 2005 11:39:08 -0000	1.4
+++ fpicker/source/office/OfficeFilePicker.cxx	16 Mar 2006 15:42:52 -0000
@@ -545,6 +546,33 @@
 }
 
 //------------------------------------------------------------------------------------
+// XFilePickerWorkaround functions
+//------------------------------------------------------------------------------------
+
+// Obsoletes getFiles
+Sequence< rtl::OUString > SAL_CALL SvtFilePicker::getFilesAsURIs() throw (RuntimeException)
+{
+	checkAlive();
+
+    ::vos::OGuard aGuard( Application::GetSolarMutex() );
+	if ( ! getDialog() )
+	{
+		Sequence< rtl::OUString > aEmpty;
+		return aEmpty;
+	}
+
+	SvStringsDtor* pPathList = getDialog()->GetPathList();
+	USHORT i, nCount = pPathList->Count();
+
+	Sequence< rtl::OUString > aPath( nCount );
+	for ( i = 0; i < nCount; i++)
+		aPath[i] = rtl::OUString( *pPathList->GetObject( i ) );
+
+	delete pPathList;
+	return aPath;	
+}
+
+//------------------------------------------------------------------------------------
 // XFilePicker functions
 //------------------------------------------------------------------------------------
 

Index: fpicker/source/office/OfficeFilePicker.hxx
===================================================================
RCS file: /cvs/gsl/fpicker/source/office/OfficeFilePicker.hxx,v
retrieving revision 1.3
diff -u -r1.3 OfficeFilePicker.hxx
--- fpicker/source/office/OfficeFilePicker.hxx	8 Sep 2005 23:28:56 -0000	1.3
+++ fpicker/source/office/OfficeFilePicker.hxx	16 Mar 2006 15:42:54 -0000
@@ -35,8 +35,8 @@
 #ifndef INCLUDED_SVT_FILEPICKER_HXX
 #define INCLUDED_SVT_FILEPICKER_HXX
 
-#ifndef  _CPPUHELPER_IMPLBASE6_HXX_
-#include <cppuhelper/implbase6.hxx>
+#ifndef  _CPPUHELPER_IMPLBASE7_HXX_
+#include <cppuhelper/implbase7.hxx>
 #endif
 
 #ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
@@ -45,6 +45,9 @@
 #ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERNOTIFIER_HPP_
 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
 #endif
+#ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERWORKAROUND_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerWorkaround.hpp>
+#endif
 #ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPREVIEW_HPP_
 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
 #endif
@@ -93,10 +96,11 @@
 
 // class SvtFilePicker ---------------------------------------------------
 
-typedef ::cppu::ImplHelper6	<	::com::sun::star::ui::dialogs::XFilePickerControlAccess
+typedef ::cppu::ImplHelper7	<	::com::sun::star::ui::dialogs::XFilePickerControlAccess
 							,	::com::sun::star::ui::dialogs::XFilePickerNotifier
 							,	::com::sun::star::ui::dialogs::XFilePreview
 							,	::com::sun::star::ui::dialogs::XFilterManager
+							,	::com::sun::star::ui::dialogs::XFilePickerWorkaround
 							,	::com::sun::star::ui::dialogs::XFilterGroupManager
 							,	::com::sun::star::lang::XServiceInfo
 							>	SvtFilePicker_Base;
@@ -181,7 +185,13 @@
     virtual sal_Bool SAL_CALL       getShowState() throw ( ::com::sun::star::uno::RuntimeException );
 
 	//------------------------------------------------------------------------------------
+	// XFilePickerWorkaround functions
+	//------------------------------------------------------------------------------------
+
+	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFilesAsURIs() throw (::com::sun::star::uno::RuntimeException);
+
+	//------------------------------------------------------------------------------------
 	// XFilterManager functions
 	//------------------------------------------------------------------------------------
 
