20#include <com/sun/star/lang/XComponent.hpp>
21#include <com/sun/star/registry/XSimpleRegistry.hpp>
22#include <osl/file.hxx>
24#include <cppuhelper/servicefactory.hxx>
25#include <rtl/ustring.hxx>
27#include <osl/diagnose.h>
28#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
29#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
31#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
33#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
34#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
35#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
36#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
37#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
38#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
39#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
40#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
42#include <osl/thread.h>
45#if !defined WIN32_LEAN_AND_MEAN
46# define WIN32_LEAN_AND_MEAN
50#include "..\FPServiceInfo.hxx"
56using namespace ::
cppu ;
60using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
62using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
63using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
64using namespace ::com::sun::star::ui::dialogs::ListboxControlActions;
73#define RDB_SYSPATH "D:\\Projects\\gsl\\sysui\\wntmsci7\\bin\\applicat.rdb"
93 throw(css::uno::RuntimeException);
97 throw(css::uno::RuntimeException);
100 throw(css::uno::RuntimeException);
103 throw(css::uno::RuntimeException);
106 throw(css::uno::RuntimeException);
109 throw (css::uno::RuntimeException);
113 throw(css::uno::RuntimeException)
118 throw(css::uno::RuntimeException)
122 Reference< XFilePicker > rXFilePicker(
aEvent.Source, UNO_QUERY );
123 Reference< XFilePreview > rXFilePreview( rXFilePicker, UNO_QUERY );
125 if ( !rXFilePreview.is( ) )
128 Sequence< OUString > aFileList = rXFilePicker->getFiles( );
129 if ( 1 == aFileList.getLength( ) )
131 OUString FilePath = aFileList[0];
135 if ( (FilePath.getLength( ) - 3) ==
nIndex )
137 OUString FileSysPath;
138 ::osl::FileBase::getSystemPathFromFileURL(
139 FilePath, FileSysPath );
141 HANDLE hFile = CreateFileW(
142 FileSysPath.getStr( ),
143 GENERIC_READ, FILE_SHARE_READ,
NULL,
144 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
NULL) ;
146 if (hFile == INVALID_HANDLE_VALUE)
150 DWORD dwFileSize = GetFileSize (hFile, &dwHighSize) ;
154 CloseHandle (hFile) ;
161 sal_Bool bSuccess = ReadFile (hFile, aDIB.getArray( ), dwFileSize, &dwBytesRead,
NULL) ;
164 BITMAPFILEHEADER* pbmfh = (BITMAPFILEHEADER*)aDIB.getConstArray( );
165 if (!bSuccess || (dwBytesRead != dwFileSize)
166 || (pbmfh->bfType != * (
WORD *)
"BM")
167 || (pbmfh->bfSize != dwFileSize))
175 rXFilePreview->setImage( 1, aAny );
179 catch( IllegalArgumentException& )
185 throw(css::uno::RuntimeException)
187 Reference< XFilePickerControlAccess > rFilePickerCtrlAccess(
aEvent.Source, UNO_QUERY );
191 throw(css::uno::RuntimeException)
197 throw(css::uno::RuntimeException)
201 Reference< XFilePickerControlAccess > rFPCtrlAccess(
aEvent.Source, UNO_QUERY );
205 OUString lbString( L
"Ein Eintrag 1" );
207 rFPCtrlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aValue );
209 lbString = L
"Ein Eintrag 2";
211 rFPCtrlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aValue );
213 lbString = L
"Ein Eintrag 3";
215 rFPCtrlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aValue );
219 rFPCtrlAccess->setValue( LISTBOX_VERSION, SET_SELECT_ITEM, aValue );
223 rFPCtrlAccess->setValue( LISTBOX_VERSION, DELETE_ITEM, aValue );
239int SAL_CALL
main(
int nArgc,
char* Argv[],
char* Env[] )
241 printf(
"Starting test of FPS-Service\n");
253 OSL_FAIL(
"Can't create RegistryServiceFactory");
261 Sequence< Any > arguments(1);
262 arguments[0] =
makeAny( FILEOPEN_READONLY_VERSION );
264 Reference< XFilePicker > xFilePicker(
266 "com.sun.star.ui.dialogs.SystemFilePicker", arguments ), UNO_QUERY );
269 Reference< XFilePickerListener > xFPListener(
272 Reference< XFilePickerNotifier > xFPNotifier( xFilePicker, UNO_QUERY );
273 if ( xFPNotifier.is( ) )
274 xFPNotifier->addFilePickerListener( xFPListener );
276 xFilePicker->setTitle( OUString(
"FileOpen Simple..."));
277 xFilePicker->setMultiSelectionMode(
sal_True );
278 xFilePicker->setDefaultName( OUString(
"d:\\test2.sxw"));
281 OUString aSysPath = OStringToOUString(
"d:\\ueaeoe", osl_getThreadTextEncoding( ) );
282 ::osl::FileBase::getFileURLFromSystemPath( aSysPath, aDirURL );
283 xFilePicker->setDisplayDirectory( aDirURL );
285 Reference< XFilterManager > xFilterMgr( xFilePicker, UNO_QUERY );
286 if ( xFilterMgr.is( ) )
288 xFilterMgr->appendFilter( L
"Alle", L
"*.*" );
289 xFilterMgr->appendFilter( L
"BMP", L
"*.bmp" );
290 xFilterMgr->appendFilter( L
"SDW", L
"*.sdw;*.sdc;*.sdi" );
291 xFilterMgr->appendFilter( L
"SXW", L
"*.sxw;*.sxi" );
294 Reference< XFilePickerControlAccess > xFPControlAccess( xFilePicker, UNO_QUERY );
300 xFPControlAccess->setValue( CHECKBOX_AUTOEXTENSION, 0, aAny );
302 OUString aVersion( L
"Version 1" );
304 xFPControlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aAny );
305 xFPControlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aAny );
306 xFPControlAccess->setValue( LISTBOX_VERSION, ADD_ITEM, aAny );
308 xFilePicker->execute( );
311 aAny = xFPControlAccess->getValue( CHECKBOX_AUTOEXTENSION, 0 );
312 if ( aAny.hasValue( ) )
313 bCheckState = *
reinterpret_cast< const sal_Bool*
>( aAny.getValue( ) );
315 aAny = xFPControlAccess->getValue( CHECKBOX_READONLY, 0 );
316 if ( aAny.hasValue( ) )
317 bCheckState = *
reinterpret_cast< const sal_Bool*
>( aAny.getValue( ) );
319 aAny = xFPControlAccess->getValue( LISTBOX_VERSION, GET_SELECTED_ITEM );
321 if ( aAny.hasValue( ) )
324 aDirURL = xFilePicker->getDisplayDirectory( );
325 Sequence< OUString > aFileList = xFilePicker->getFiles( );
326 for (
int i = 0;
i < aFileList.getLength( );
i++ )
328 OUString nextPath = aFileList[
i];
331 if ( xFPNotifier.is( ) )
332 xFPNotifier->removeFilePickerListener( xFPListener );
339 Reference< XComponent > xComponent(
g_xFactory, UNO_QUERY );
344 OSL_FAIL(
"Error shutting down");
348 xComponent->dispose();
351 printf(
"Test successful\n");
void TestFilterManager(Reference< XFilePicker > xFilePicker)
Reference< XMultiServiceFactory > g_xFactory
static constexpr OUStringLiteral BMP_EXTENSION(u"bmp")
int SAL_CALL main(int nArgc, char *Argv[], char *Env[])
virtual void SAL_CALL fileSelectionChanged(const css::ui::dialogs::FilePickerEvent &aEvent)
virtual OUString SAL_CALL helpRequested(const css::ui::dialogs::FilePickerEvent &aEvent)
virtual void SAL_CALL controlStateChanged(const css::ui::dialogs::FilePickerEvent &aEvent)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source)
virtual void SAL_CALL dialogSizeChanged()
virtual void SAL_CALL directoryChanged(const css::ui::dialogs::FilePickerEvent &aEvent)
SAL_DLLPUBLIC_EXPORT css::uno::Reference< css::lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(OUString const &, OUString const &, sal_Bool, OUString const &)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)