1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SalAquaFilePicker.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
39 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
40 #include <cppuhelper/interfacecontainer.h>
41 #include <osl/diagnose.h>
42 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
43 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <FPServiceInfo.hxx>
46 #include <vos/mutex.hxx>
47 #include <vcl/svapp.hxx>
49 #ifndef _TOOLS_URLOBJ_HXX
50 #include <tools/urlobj.hxx>
52 #include "resourceprovider.hxx"
55 #include <tools/rc.hxx>
57 #include <osl/file.hxx>
58 #include "CFStringUtilities.hxx"
59 #include "NSString_OOoAdditions.hxx"
60 #include "NSURL_OOoAdditions.hxx"
64 #include "SalAquaFilePicker.hxx"
69 #define LABEL_TOGGLE( elem ) \
71 aLabel = aResProvider.getResString( CHECKBOX_##elem ); \
72 setLabel( CHECKBOX_##elem, aLabel ); \
75 #define CLASS_NAME "SalAquaFilePicker"
77 //------------------------------------------------------------------------
78 // namespace directives
79 //------------------------------------------------------------------------
81 using namespace ::com::sun::star
;
82 using namespace ::com::sun::star::ui::dialogs
;
83 using namespace ::com::sun::star::ui::dialogs::TemplateDescription
;
84 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds
;
85 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds
;
86 using namespace ::com::sun::star::lang
;
87 using namespace ::com::sun::star::beans
;
88 using namespace ::com::sun::star::uno
;
90 //------------------------------------------------------------------------
92 //------------------------------------------------------------------------
96 // controling event notifications
97 const bool STARTUP_SUSPENDED
= true;
98 const bool STARTUP_ALIVE
= false;
100 uno::Sequence
<rtl::OUString
> SAL_CALL
FilePicker_getSupportedServiceNames()
102 uno::Sequence
<rtl::OUString
> aRet(3);
103 aRet
[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" );
104 aRet
[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFilePicker" );
105 aRet
[2] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.AquaFilePicker" );
110 #pragma mark Constructor
111 //-----------------------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------------------
115 SalAquaFilePicker::SalAquaFilePicker( const uno::Reference
<lang::XMultiServiceFactory
>& xServiceMgr
) :
116 cppu::WeakComponentImplHelper8
<XFilterManager
, XFilterGroupManager
, XFilePickerControlAccess
, XFilePickerNotifier
,
117 lang::XInitialization
, util::XCancellable
, lang::XEventListener
, lang::XServiceInfo
>( m_rbHelperMtx
)
118 , m_xServiceMgr( xServiceMgr
)
119 , m_pFilterHelper( NULL
)
121 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
123 m_pDelegate
= [[AquaFilePickerDelegate alloc
] initWithFilePicker
:this];
124 m_pControlHelper
->setFilePickerDelegate(m_pDelegate
);
126 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
129 SalAquaFilePicker::~SalAquaFilePicker()
131 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
133 if (NULL
!= m_pFilterHelper
)
134 delete m_pFilterHelper
;
136 [m_pDelegate release
];
138 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
142 #pragma mark XFilePickerNotifier
143 //------------------------------------------------------------------------------------
144 // XFilePickerNotifier
145 //------------------------------------------------------------------------------------
147 void SAL_CALL
SalAquaFilePicker::addFilePickerListener( const uno::Reference
<XFilePickerListener
>& xListener
)
148 throw( uno::RuntimeException
)
150 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
152 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
153 m_xListener
= xListener
;
155 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
158 void SAL_CALL
SalAquaFilePicker::removeFilePickerListener( const uno::Reference
<XFilePickerListener
>& )
159 throw( uno::RuntimeException
)
161 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
163 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
166 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
169 #pragma mark XAsynchronousExecutableDialog
170 //-----------------------------------------------------------------------------------------
171 // XExecutableDialog functions
172 //-----------------------------------------------------------------------------------------
173 void SAL_CALL
SalAquaFilePicker::setTitle( const rtl::OUString
& aTitle
) throw( uno::RuntimeException
)
175 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "title", aTitle
);
177 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
178 implsetTitle(aTitle
);
180 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
183 sal_Int16 SAL_CALL
SalAquaFilePicker::execute() throw( uno::RuntimeException
)
185 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
187 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
189 sal_Int16 retVal
= 0;
193 // if m_pDialog is nil after initialization, something must have gone wrong before
194 // or there was no initialization (see issue http://www.openoffice.org/issues/show_bug.cgi?id=100214)
195 if (m_pDialog
== nil
) {
196 //throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog was not properly initialized!"), static_cast< XFilePicker* >( this ));
197 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
200 if (m_pFilterHelper
) {
201 m_pFilterHelper
->SetFilters();
204 if (m_nDialogType
== NAVIGATIONSERVICES_SAVE
) {
205 if (m_sSaveFileName
.getLength() == 0) {
206 //if no filename is set, NavigationServices will set the name to "untitled". We don't want this!
207 //So let's try to get the window title to get the real untitled name
208 NSWindow
*frontWindow
= [NSApp keyWindow
];
209 if (NULL
!= frontWindow
) {
210 NSString
*windowTitle
= [frontWindow title
];
211 if (windowTitle
!= nil
) {
212 rtl::OUString ouName
= [windowTitle OUString
];
213 //a window title will typically be something like "Untitled1 - OpenOffice.org Writer"
214 //but we only want the "Untitled1" part of it
215 sal_Int32 indexOfDash
= ouName
.indexOf(rtl::OUString::createFromAscii(" - "));
216 if (indexOfDash
> -1) {
217 m_sSaveFileName
= ouName
.copy(0,indexOfDash
);
218 if (m_sSaveFileName
.getLength() > 0) {
219 setDefaultName(m_sSaveFileName
);
222 OSL_TRACE("no dash present in window title");
225 OSL_TRACE("couldn't get window title");
228 OSL_TRACE("no front window found");
233 //Set the delegate to be notified of certain events
234 [m_pDialog setDelegate
:m_pDelegate
];
236 int nStatus
= runandwaitforresult();
238 [m_pDialog setDelegate
:nil
];
243 OSL_TRACE("The dialog returned OK");
244 retVal
= ExecutableDialogResults::OK
;
248 OSL_TRACE("The dialog was cancelled by the user!");
249 retVal
= ExecutableDialogResults::CANCEL
;
253 throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog returned with an unknown result!"), static_cast< XFilePicker
* >( this ));
257 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, retVal
);
263 #pragma mark XFilePicker
264 //-----------------------------------------------------------------------------------------
265 // XFilePicker functions
266 //-----------------------------------------------------------------------------------------
268 void SAL_CALL
SalAquaFilePicker::setMultiSelectionMode( sal_Bool bMode
) throw( uno::RuntimeException
)
270 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "multiSelectable?", bMode
);
272 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
274 if (m_nDialogType
== NAVIGATIONSERVICES_OPEN
) {
275 [(NSOpenPanel
*)m_pDialog setAllowsMultipleSelection
:YES
];
276 OSL_TRACE("dialog allows multi-selection? %d", [(NSOpenPanel
*)m_pDialog allowsMultipleSelection
]);
279 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
282 void SAL_CALL
SalAquaFilePicker::setDefaultName( const rtl::OUString
& aName
)
283 throw( uno::RuntimeException
)
285 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "name", aName
);
287 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
289 m_sSaveFileName
= aName
;
291 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
294 void SAL_CALL
SalAquaFilePicker::setDisplayDirectory( const rtl::OUString
& rDirectory
)
295 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
297 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "directory", rDirectory
);
299 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
301 implsetDisplayDirectory(rDirectory
);
303 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
306 rtl::OUString SAL_CALL
SalAquaFilePicker::getDisplayDirectory() throw( uno::RuntimeException
)
308 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
310 rtl::OUString retVal
= implgetDisplayDirectory();
312 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, retVal
);
316 uno::Sequence
<rtl::OUString
> SAL_CALL
SalAquaFilePicker::getFiles() throw( uno::RuntimeException
)
318 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
320 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
322 // OSL_TRACE("starting work");
324 * If more than one file is selected in an OpenDialog, then the first result
325 * is the directory and the remaining results contain just the files' names
326 * without the basedir path.
328 NSArray
*files
= nil
;
329 if (m_nDialogType
== NAVIGATIONSERVICES_OPEN
) {
330 files
= [(NSOpenPanel
*)m_pDialog URLs
];
332 else if (m_nDialogType
== NAVIGATIONSERVICES_SAVE
) {
333 files
= [NSArray arrayWithObjects
:[m_pDialog URL
], nil
];
336 long nFiles
= [files count
];
337 OSL_TRACE("# of items: %d", nFiles
);
339 uno::Sequence
< rtl::OUString
> aSelectedFiles(nFiles
> 1 ? nFiles
+ 1 : nFiles
);
341 for(int nIndex
= 0; nIndex
< nFiles
; nIndex
+= 1)
343 NSURL
*url
= [files objectAtIndex
:nIndex
];
344 OSL_TRACE("handling %s", [[url description
] UTF8String
]);
345 InfoType info
= FULLPATH
;
347 //just get the file's name (only in OpenDialog)
350 OUString sFileOrDirURL
= [url OUStringForInfo
:info
];
352 //get the directory information, only on the first file processed
354 OUString sDirectoryURL
= [url OUStringForInfo
:PATHWITHOUTLASTCOMPONENT
];
357 aSelectedFiles
[0] = OUString(sDirectoryURL
);
361 short nSequenceIndex
= nFiles
> 1 ? nIndex
+ 1 : nIndex
;
362 aSelectedFiles
[nSequenceIndex
] = sFileOrDirURL
;
364 OSL_TRACE("Returned file in getFiles: \"%s\".", OUStringToOString(sFileOrDirURL
, RTL_TEXTENCODING_UTF8
).getStr());
367 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
368 return aSelectedFiles
;
371 #pragma mark XFilterManager
372 //-----------------------------------------------------------------------------------------
373 // XFilterManager functions
374 //-----------------------------------------------------------------------------------------
376 void SAL_CALL
SalAquaFilePicker::appendFilter( const rtl::OUString
& aTitle
, const rtl::OUString
& aFilter
)
377 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
379 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
381 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
383 ensureFilterHelper();
384 m_pFilterHelper
->appendFilter( aTitle
, aFilter
);
385 m_pControlHelper
->setFilterControlNeeded(YES
);
387 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
390 void SAL_CALL
SalAquaFilePicker::setCurrentFilter( const rtl::OUString
& aTitle
)
391 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
393 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
394 OSL_TRACE( "Setting current filter to %s",
395 OUStringToOString( aTitle
, RTL_TEXTENCODING_UTF8
).getStr() );
397 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
399 ensureFilterHelper();
400 m_pFilterHelper
->setCurrentFilter(aTitle
);
403 updateSaveFileNameExtension();
405 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
408 rtl::OUString SAL_CALL
SalAquaFilePicker::getCurrentFilter() throw( uno::RuntimeException
)
410 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
411 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
413 ensureFilterHelper();
415 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
416 return m_pFilterHelper
->getCurrentFilter();
419 #pragma mark XFilterGroupManager
420 //-----------------------------------------------------------------------------------------
421 // XFilterGroupManager functions
422 //-----------------------------------------------------------------------------------------
424 void SAL_CALL
SalAquaFilePicker::appendFilterGroup( const rtl::OUString
& sGroupTitle
, const uno::Sequence
<beans::StringPair
>& aFilters
)
425 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
427 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
428 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
430 ensureFilterHelper();
431 m_pFilterHelper
->appendFilterGroup(sGroupTitle
, aFilters
);
432 m_pControlHelper
->setFilterControlNeeded(YES
);
433 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
436 #pragma mark XFilePickerControlAccess
437 //------------------------------------------------------------------------------------
438 // XFilePickerControlAccess functions
439 //------------------------------------------------------------------------------------
441 void SAL_CALL
SalAquaFilePicker::setValue( sal_Int16 nControlId
, sal_Int16 nControlAction
, const uno::Any
& rValue
)
442 throw( uno::RuntimeException
)
444 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
446 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
448 m_pControlHelper
->setValue(nControlId
, nControlAction
, rValue
);
450 if (nControlId
== ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION
&& m_nDialogType
== NAVIGATIONSERVICES_SAVE
) {
451 updateSaveFileNameExtension();
454 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
457 uno::Any SAL_CALL
SalAquaFilePicker::getValue( sal_Int16 nControlId
, sal_Int16 nControlAction
)
458 throw( uno::RuntimeException
)
460 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
462 uno::Any aValue
= m_pControlHelper
->getValue(nControlId
, nControlAction
);
464 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
468 void SAL_CALL
SalAquaFilePicker::enableControl( sal_Int16 nControlId
, sal_Bool bEnable
)
469 throw( uno::RuntimeException
)
471 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
473 m_pControlHelper
->enableControl(nControlId
, bEnable
);
475 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
478 void SAL_CALL
SalAquaFilePicker::setLabel( sal_Int16 nControlId
, const ::rtl::OUString
& aLabel
)
479 throw( uno::RuntimeException
)
481 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
483 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
485 NSString
* sLabel
= [NSString stringWithOUString
:aLabel
];
486 m_pControlHelper
->setLabel( nControlId
, sLabel
) ;
488 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
491 rtl::OUString SAL_CALL
SalAquaFilePicker::getLabel( sal_Int16 nControlId
)
492 throw( uno::RuntimeException
)
494 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
495 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
497 return m_pControlHelper
->getLabel(nControlId
);
500 #pragma mark XInitialization
501 //------------------------------------------------------------------------------------
503 //------------------------------------------------------------------------------------
505 void SAL_CALL
SalAquaFilePicker::initialize( const uno::Sequence
<uno::Any
>& aArguments
)
506 throw( uno::Exception
, uno::RuntimeException
)
508 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "arguments size", aArguments
.getLength());
510 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
512 // parameter checking
514 if( 0 == aArguments
.getLength() )
515 throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "no arguments" ),
516 static_cast<XFilePicker
*>( this ), 1 );
518 aAny
= aArguments
[0];
520 if( ( aAny
.getValueType() != ::getCppuType( ( sal_Int16
* )0 ) ) &&
521 (aAny
.getValueType() != ::getCppuType( ( sal_Int8
* )0 ) ) )
522 throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "invalid argument type" ),
523 static_cast<XFilePicker
*>( this ), 1 );
525 sal_Int16 templateId
= -1;
530 case FILEOPEN_SIMPLE
:
531 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
532 OSL_TRACE( "Template: FILEOPEN_SIMPLE" );
534 case FILESAVE_SIMPLE
:
535 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
536 OSL_TRACE( "Template: FILESAVE_SIMPLE" );
538 case FILESAVE_AUTOEXTENSION_PASSWORD
:
539 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
540 OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD" );
542 case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
:
543 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
544 OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS" );
546 case FILESAVE_AUTOEXTENSION_SELECTION
:
547 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
548 OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_SELECTION" );
550 case FILESAVE_AUTOEXTENSION_TEMPLATE
:
551 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
552 OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_TEMPLATE" );
554 case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
:
555 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
556 OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE" );
559 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
560 OSL_TRACE( "Template: FILEOPEN_PLAY" );
562 case FILEOPEN_READONLY_VERSION
:
563 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
564 OSL_TRACE( "Template: FILEOPEN_READONLY_VERSION" );
566 case FILEOPEN_LINK_PREVIEW
:
567 m_nDialogType
= NAVIGATIONSERVICES_OPEN
;
568 OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW" );
570 case FILESAVE_AUTOEXTENSION
:
571 m_nDialogType
= NAVIGATIONSERVICES_SAVE
;
572 OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION" );
575 throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "Unknown template" ),
576 static_cast< XFilePicker
* >( this ),
580 m_pControlHelper
->initialize(templateId
);
584 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
587 #pragma mark XCancellable
588 //------------------------------------------------------------------------------------
590 //------------------------------------------------------------------------------------
592 void SAL_CALL
SalAquaFilePicker::cancel() throw( uno::RuntimeException
)
594 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
596 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
598 if (m_pDialog
!= nil
) {
599 [m_pDialog cancel
:nil
];
602 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
605 #pragma mark XEventListener
606 //------------------------------------------------
608 //------------------------------------------------
610 void SAL_CALL
SalAquaFilePicker::disposing( const lang::EventObject
& aEvent
) throw( uno::RuntimeException
)
612 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
614 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
616 uno::Reference
<XFilePickerListener
> xFilePickerListener( aEvent
.Source
, ::com::sun::star::uno::UNO_QUERY
);
618 if( xFilePickerListener
.is() )
619 removeFilePickerListener( xFilePickerListener
);
621 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
624 #pragma mark XServiceInfo
625 // -------------------------------------------------
627 // -------------------------------------------------
629 rtl::OUString SAL_CALL
SalAquaFilePicker::getImplementationName()
630 throw( uno::RuntimeException
)
632 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
634 rtl::OUString retVal
= rtl::OUString::createFromAscii( FILE_PICKER_IMPL_NAME
);
636 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, retVal
);
641 sal_Bool SAL_CALL
SalAquaFilePicker::supportsService( const rtl::OUString
& sServiceName
)
642 throw( uno::RuntimeException
)
644 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "service name", sServiceName
);
646 sal_Bool retVal
= sal_False
;
648 uno::Sequence
<rtl::OUString
> supportedServicesNames
= FilePicker_getSupportedServiceNames();
650 for( sal_Int32 n
= supportedServicesNames
.getLength(); n
--; ) {
651 if( supportedServicesNames
[n
].compareTo( sServiceName
) == 0) {
657 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
662 uno::Sequence
<rtl::OUString
> SAL_CALL
SalAquaFilePicker::getSupportedServiceNames()
663 throw( uno::RuntimeException
)
665 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
666 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
668 return FilePicker_getSupportedServiceNames();
671 #pragma mark Misc/Private
672 //-----------------------------------------------------------------------------------------
673 // FilePicker Event functions
674 //-----------------------------------------------------------------------------------------
676 void SAL_CALL
SalAquaFilePicker::fileSelectionChanged( FilePickerEvent aEvent
)
678 OSL_TRACE( "file selection changed");
679 if (m_xListener
.is())
680 m_xListener
->fileSelectionChanged( aEvent
);
683 void SAL_CALL
SalAquaFilePicker::directoryChanged( FilePickerEvent aEvent
)
685 OSL_TRACE("directory changed");
686 if (m_xListener
.is())
687 m_xListener
->directoryChanged( aEvent
);
690 void SAL_CALL
SalAquaFilePicker::controlStateChanged( FilePickerEvent aEvent
)
692 OSL_TRACE("control state changed");
693 if (m_xListener
.is())
694 m_xListener
->controlStateChanged( aEvent
);
697 void SAL_CALL
SalAquaFilePicker::dialogSizeChanged()
699 OSL_TRACE("dialog size changed");
700 if (m_xListener
.is())
701 m_xListener
->dialogSizeChanged();
704 //------------------------------------------------------------------------------------
706 #define MAP_TOGGLE( elem ) \
707 case ExtendedFilePickerElementIds::CHECKBOX_##elem: \
708 pWidget = m_pToggles[elem]; \
711 #define MAP_BUTTON( elem ) \
712 case ExtendedFilePickerElementIds::PUSHBUTTON_##elem: \
713 pWidget = m_pButtons[elem]; \
716 #define MAP_LIST( elem ) \
717 case ExtendedFilePickerElementIds::LISTBOX_##elem: \
718 pWidget = m_pListControls[elem]; if (isAList != NULL) *isAList = sal_True; \
721 #define MAP_LIST_LABEL( elem ) \
722 case ExtendedFilePickerElementIds::LISTBOX_##elem##_LABEL: \
723 pWidget = m_pListControls[elem]; \
726 //--------------------------------------------------
728 //-------------------------------------------------
729 void SalAquaFilePicker::ensureFilterHelper() {
730 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
732 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
734 if (NULL
== m_pFilterHelper
) {
735 m_pFilterHelper
= new FilterHelper
;
736 m_pControlHelper
->setFilterHelper(m_pFilterHelper
);
737 [m_pDelegate setFilterHelper
:m_pFilterHelper
];
740 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
743 void SalAquaFilePicker::implInitialize()
745 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
748 SalAquaPicker::implInitialize();
750 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
753 void SalAquaFilePicker::updateFilterUI() {
754 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
756 m_pControlHelper
->updateFilterUI();
758 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
761 void SalAquaFilePicker::updateSaveFileNameExtension() {
762 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
764 if (m_nDialogType
!= NAVIGATIONSERVICES_SAVE
) {
768 // we need to set this here again because initial setting does
769 //[m_pDialog setExtensionHidden:YES];
771 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
773 if (m_pControlHelper
->isAutoExtensionEnabled() == false) {
774 OSL_TRACE("allowing other file types");
775 [m_pDialog setAllowedFileTypes
:nil
];
776 [m_pDialog setAllowsOtherFileTypes
:YES
];
778 ensureFilterHelper();
780 OUStringList aStringList
= m_pFilterHelper
->getCurrentFilterSuffixList();
781 if( aStringList
.empty()) // #i9328#
784 rtl::OUString suffix
= (*(aStringList
.begin())).copy(1);
785 NSString
*requiredFileType
= [NSString stringWithOUString
:suffix
];
787 [m_pDialog setRequiredFileType
:requiredFileType
];
789 OSL_TRACE("disallowing other file types");
790 [m_pDialog setAllowsOtherFileTypes
:NO
];
793 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
796 void SalAquaFilePicker::filterControlChanged() {
797 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
799 if (m_pDialog
== nil
) {
803 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
805 updateSaveFileNameExtension();
807 [m_pDialog validateVisibleColumns
];
810 evt
.ElementId
= LISTBOX_FILTER
;
811 controlStateChanged( evt
);
813 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);