bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / aqua / SalAquaFilePicker.mm
blobe64c4225c5ba12a11dc8afa4ad6993fe24f95946
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
20 #include "sal/config.h"
22 #include <com/sun/star/lang/DisposedException.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
25 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
26 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
27 #include <cppuhelper/interfacecontainer.h>
28 #include <osl/diagnose.h>
29 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <FPServiceInfo.hxx>
33 #include <osl/mutex.hxx>
34 #include <vcl/svapp.hxx>
36 #include "resourceprovider.hxx"
38 #include <osl/file.hxx>
39 #include "CFStringUtilities.hxx"
40 #include "NSString_OOoAdditions.hxx"
41 #include "NSURL_OOoAdditions.hxx"
43 #include <iostream>
45 #include "SalAquaFilePicker.hxx"
47 #include <objc/objc-runtime.h>
49 #pragma mark DEFINES
51 #define CLASS_NAME "SalAquaFilePicker"
53 //------------------------------------------------------------------------
54 // namespace directives
55 //------------------------------------------------------------------------
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::ui::dialogs;
59 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
60 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
61 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::uno;
66 //------------------------------------------------------------------------
67 // helper functions
68 //------------------------------------------------------------------------
70 namespace
72     // controling event notifications
73     const bool STARTUP_SUSPENDED = true;
74     const bool STARTUP_ALIVE     = false;
76     uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
77     {
78         uno::Sequence<rtl::OUString> aRet(3);
79         aRet[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ));
80         aRet[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.SystemFilePicker" ));
81         aRet[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AquaFilePicker" ));
82         return aRet;
83     }
86 #pragma mark Constructor
87 //-----------------------------------------------------------------------------------------
88 // constructor
89 //-----------------------------------------------------------------------------------------
91 SalAquaFilePicker::SalAquaFilePicker()
92   : SalAquaFilePicker_Base( m_rbHelperMtx )
93    , m_pFilterHelper( NULL )
95     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
97     m_pDelegate = [[AquaFilePickerDelegate alloc] initWithFilePicker:this];
98     m_pControlHelper->setFilePickerDelegate(m_pDelegate);
100     DBG_PRINT_EXIT(CLASS_NAME, __func__);
103 SalAquaFilePicker::~SalAquaFilePicker()
105     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
107     if (NULL != m_pFilterHelper)
108         delete m_pFilterHelper;
110     [m_pDelegate release];
112     DBG_PRINT_EXIT(CLASS_NAME, __func__);
116 #pragma mark XFilePickerNotifier
117 //------------------------------------------------------------------------------------
118 // XFilePickerNotifier
119 //------------------------------------------------------------------------------------
121 void SAL_CALL SalAquaFilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
122     throw( uno::RuntimeException )
124     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
126     SolarMutexGuard aGuard;
127     m_xListener = xListener;
129     DBG_PRINT_EXIT(CLASS_NAME, __func__);
132 void SAL_CALL SalAquaFilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
133     throw( uno::RuntimeException )
135     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
137     SolarMutexGuard aGuard;
138     m_xListener.clear();
140     DBG_PRINT_EXIT(CLASS_NAME, __func__);
143 #pragma mark XAsynchronousExecutableDialog
144 //-----------------------------------------------------------------------------------------
145 // XExecutableDialog functions
146 //-----------------------------------------------------------------------------------------
147 void SAL_CALL SalAquaFilePicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
149     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
151     SolarMutexGuard aGuard;
152     implsetTitle(aTitle);
154     DBG_PRINT_EXIT(CLASS_NAME, __func__);
157 sal_Int16 SAL_CALL SalAquaFilePicker::execute() throw( uno::RuntimeException )
159     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
161     SolarMutexGuard aGuard;
163     sal_Int16 retVal = 0;
165     implInitialize();
167     // if m_pDialog is nil after initialization, something must have gone wrong before
168     // or there was no initialization (see issue http://www.openoffice.org/issues/show_bug.cgi?id=100214)
169     if (m_pDialog == nil) {
170         m_nDialogType = NAVIGATIONSERVICES_OPEN;
171     }
173     if (m_pFilterHelper) {
174         m_pFilterHelper->SetFilters();
175     }
177     if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
178         if (m_sSaveFileName.getLength() == 0) {
179             //if no filename is set, NavigationServices will set the name to "untitled". We don't want this!
180             //So let's try to get the window title to get the real untitled name
181             NSWindow *frontWindow = [NSApp keyWindow];
182             if (NULL != frontWindow) {
183                 NSString *windowTitle = [frontWindow title];
184                 if (windowTitle != nil) {
185                     rtl::OUString ouName = [windowTitle OUString];
186                     //a window title will typically be something like "Untitled1 - OpenOffice.org Writer"
187                     //but we only want the "Untitled1" part of it
188                     sal_Int32 indexOfDash = ouName.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")));
189                     if (indexOfDash > -1) {
190                         m_sSaveFileName = ouName.copy(0,indexOfDash);
191                         if (m_sSaveFileName.getLength() > 0) {
192                             setDefaultName(m_sSaveFileName);
193                         }
194                     } else {
195                         OSL_TRACE("no dash present in window title");
196                     }
197                 } else {
198                     OSL_TRACE("couldn't get window title");
199                 }
200             } else {
201                 OSL_TRACE("no front window found");
202             }
203         }
204     }
206     //Set the delegate to be notified of certain events
208     // I don't know why, but with gcc 4.2.1, this line results in the warning:
209     // class 'AquaFilePickerDelegate' does not implement the 'NSOpenSavePanelDelegate' protocol
210     // So instead of:
211     // [m_pDialog setDelegate:m_pDelegate];
212     // do:
213     objc_msgSend(m_pDialog, @selector(setDelegate:), m_pDelegate);
215     int nStatus = runandwaitforresult();
217     [m_pDialog setDelegate:nil];
219     switch( nStatus )
220     {
221         case NSOKButton:
222             OSL_TRACE("The dialog returned OK");
223             retVal = ExecutableDialogResults::OK;
224             break;
226         case NSCancelButton:
227             OSL_TRACE("The dialog was cancelled by the user!");
228             retVal = ExecutableDialogResults::CANCEL;
229             break;
231         default:
232             throw uno::RuntimeException(
233                       rtl::OUString("The dialog returned with an unknown result!"), 
234                       static_cast<XFilePicker*>( static_cast<XFilePicker3*>( this ) ));
235             break;
236     }
238     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
240     return retVal;
244 #pragma mark XFilePicker
245 //-----------------------------------------------------------------------------------------
246 // XFilePicker functions
247 //-----------------------------------------------------------------------------------------
249 void SAL_CALL SalAquaFilePicker::setMultiSelectionMode( sal_Bool bMode ) throw( uno::RuntimeException )
251     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "multiSelectable?", bMode);
253     SolarMutexGuard aGuard;
255     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
256         [(NSOpenPanel*)m_pDialog setAllowsMultipleSelection:YES];
257         OSL_TRACE("dialog allows multi-selection? %d", [(NSOpenPanel*)m_pDialog allowsMultipleSelection]);
258     }
260     DBG_PRINT_EXIT(CLASS_NAME, __func__);
263 void SAL_CALL SalAquaFilePicker::setDefaultName( const rtl::OUString& aName )
264 throw( uno::RuntimeException )
266     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "name", aName);
268     SolarMutexGuard aGuard;
270     m_sSaveFileName = aName;
272     DBG_PRINT_EXIT(CLASS_NAME, __func__);
275 void SAL_CALL SalAquaFilePicker::setDisplayDirectory( const rtl::OUString& rDirectory )
276 throw( lang::IllegalArgumentException, uno::RuntimeException )
278     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", rDirectory);
280     SolarMutexGuard aGuard;
282     implsetDisplayDirectory(rDirectory);
284     DBG_PRINT_EXIT(CLASS_NAME, __func__);
287 rtl::OUString SAL_CALL SalAquaFilePicker::getDisplayDirectory() throw( uno::RuntimeException )
289     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
291     rtl::OUString retVal = implgetDisplayDirectory();
293     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
294     return retVal;
297 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getFiles() throw( uno::RuntimeException )
299     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
301     SolarMutexGuard aGuard;
303     // OSL_TRACE("starting work");
304     /*
305      * If more than one file is selected in an OpenDialog, then the first result
306      * is the directory and the remaining results contain just the files' names
307      * without the basedir path.
308      */
309     NSArray *files = nil;
310     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
311         files = [(NSOpenPanel*)m_pDialog URLs];
312     }
313     else if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
314         files = [NSArray arrayWithObjects:[m_pDialog URL], nil];
315     }
317     long nFiles = [files count];
318     OSL_TRACE("# of items: %d", nFiles);
320     uno::Sequence< rtl::OUString > aSelectedFiles(nFiles > 1 ? nFiles + 1 : nFiles);
322     for(int nIndex = 0; nIndex < nFiles; nIndex += 1)
323     {
324         NSURL *url = [files objectAtIndex:nIndex];
325         OSL_TRACE("handling %s", [[url description] UTF8String]);
326         InfoType info = FULLPATH;
327         if (nFiles > 1) {
328             //just get the file's name (only in OpenDialog)
329             info = FILENAME;
330         }
331         OUString sFileOrDirURL = [url OUStringForInfo:info];
333         //get the directory information, only on the first file processed
334         if (nIndex == 0) {
335             OUString sDirectoryURL = [url OUStringForInfo:PATHWITHOUTLASTCOMPONENT];
337             if (nFiles > 1) {
338                 aSelectedFiles[0] = OUString(sDirectoryURL);
339             }
340         }
342         short nSequenceIndex = nFiles > 1 ? nIndex + 1 : nIndex;
343         aSelectedFiles[nSequenceIndex] = sFileOrDirURL;
345         OSL_TRACE("Returned file in getFiles: \"%s\".", OUStringToOString(sFileOrDirURL, RTL_TEXTENCODING_UTF8).getStr());
346     }
348     DBG_PRINT_EXIT(CLASS_NAME, __func__);
349     return aSelectedFiles;
352 #pragma mark XFilterManager
353 //-----------------------------------------------------------------------------------------
354 // XFilterManager functions
355 //-----------------------------------------------------------------------------------------
357 void SAL_CALL SalAquaFilePicker::appendFilter( const rtl::OUString& aTitle, const rtl::OUString& aFilter )
358 throw( lang::IllegalArgumentException, uno::RuntimeException )
360     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
362     SolarMutexGuard aGuard;
364     ensureFilterHelper();
365     m_pFilterHelper->appendFilter( aTitle, aFilter );
366     m_pControlHelper->setFilterControlNeeded(YES);
368     DBG_PRINT_EXIT(CLASS_NAME, __func__);
371 void SAL_CALL SalAquaFilePicker::setCurrentFilter( const rtl::OUString& aTitle )
372 throw( lang::IllegalArgumentException, uno::RuntimeException )
374     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
375     OSL_TRACE( "Setting current filter to %s",
376                OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
378     SolarMutexGuard aGuard;
380     ensureFilterHelper();
381     m_pFilterHelper->setCurrentFilter(aTitle);
382     updateFilterUI();
384     updateSaveFileNameExtension();
386     DBG_PRINT_EXIT(CLASS_NAME, __func__);
389 rtl::OUString SAL_CALL SalAquaFilePicker::getCurrentFilter() throw( uno::RuntimeException )
391     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
392     SolarMutexGuard aGuard;
394     ensureFilterHelper();
396     DBG_PRINT_EXIT(CLASS_NAME, __func__);
397     return m_pFilterHelper->getCurrentFilter();
400 #pragma mark XFilterGroupManager
401 //-----------------------------------------------------------------------------------------
402 // XFilterGroupManager functions
403 //-----------------------------------------------------------------------------------------
405 void SAL_CALL SalAquaFilePicker::appendFilterGroup( const rtl::OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters )
406 throw( lang::IllegalArgumentException, uno::RuntimeException )
408     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
409     SolarMutexGuard aGuard;
411     ensureFilterHelper();
412     m_pFilterHelper->appendFilterGroup(sGroupTitle, aFilters);
413     m_pControlHelper->setFilterControlNeeded(YES);
414     DBG_PRINT_EXIT(CLASS_NAME, __func__);
417 #pragma mark XFilePickerControlAccess
418 //------------------------------------------------------------------------------------
419 // XFilePickerControlAccess functions
420 //------------------------------------------------------------------------------------
422 void SAL_CALL SalAquaFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue )
423 throw( uno::RuntimeException )
425     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
427     SolarMutexGuard aGuard;
429     m_pControlHelper->setValue(nControlId, nControlAction, rValue);
431     if (nControlId == ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION && m_nDialogType == NAVIGATIONSERVICES_SAVE) {
432         updateSaveFileNameExtension();
433     }
435     DBG_PRINT_EXIT(CLASS_NAME, __func__);
438 uno::Any SAL_CALL SalAquaFilePicker::getValue( sal_Int16 nControlId, sal_Int16 nControlAction )
439 throw( uno::RuntimeException )
441     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
443     uno::Any aValue = m_pControlHelper->getValue(nControlId, nControlAction);
445     DBG_PRINT_EXIT(CLASS_NAME, __func__);
446     return aValue;
449 void SAL_CALL SalAquaFilePicker::enableControl( sal_Int16 nControlId, sal_Bool bEnable )
450 throw( uno::RuntimeException )
452     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
454     m_pControlHelper->enableControl(nControlId, bEnable);
456     DBG_PRINT_EXIT(CLASS_NAME, __func__);
459 void SAL_CALL SalAquaFilePicker::setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
460 throw( uno::RuntimeException )
462     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
464     SolarMutexGuard aGuard;
466     NSString* sLabel = [NSString stringWithOUString:aLabel];
467     m_pControlHelper->setLabel( nControlId, sLabel ) ;
469     DBG_PRINT_EXIT(CLASS_NAME, __func__);
472 rtl::OUString SAL_CALL SalAquaFilePicker::getLabel( sal_Int16 nControlId )
473 throw( uno::RuntimeException )
475     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
476     DBG_PRINT_EXIT(CLASS_NAME, __func__);
478     return m_pControlHelper->getLabel(nControlId);
481 #pragma mark XInitialization
482 //------------------------------------------------------------------------------------
483 // XInitialization
484 //------------------------------------------------------------------------------------
486 void SAL_CALL SalAquaFilePicker::initialize( const uno::Sequence<uno::Any>& aArguments )
487 throw( uno::Exception, uno::RuntimeException )
489     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "arguments size", aArguments.getLength());
491     SolarMutexGuard aGuard;
493     // parameter checking
494     uno::Any aAny;
495     if( 0 == aArguments.getLength() )
496         throw lang::IllegalArgumentException(rtl::OUString("no arguments"),
497                                              static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ), 1 );
499     aAny = aArguments[0];
501     if( ( aAny.getValueType() != ::getCppuType( ( sal_Int16* )0 ) ) &&
502         (aAny.getValueType() != ::getCppuType( ( sal_Int8* )0 ) ) )
503         throw lang::IllegalArgumentException(rtl::OUString( "invalid argument type" ),
504                                              static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ), 1 );
506     sal_Int16 templateId = -1;
507     aAny >>= templateId;
509     switch( templateId )
510     {
511         case FILEOPEN_SIMPLE:
512             m_nDialogType = NAVIGATIONSERVICES_OPEN;
513             OSL_TRACE( "Template: FILEOPEN_SIMPLE" );
514             break;
515         case FILESAVE_SIMPLE:
516             m_nDialogType = NAVIGATIONSERVICES_SAVE;
517             OSL_TRACE( "Template: FILESAVE_SIMPLE" );
518             break;
519         case FILESAVE_AUTOEXTENSION_PASSWORD:
520             m_nDialogType = NAVIGATIONSERVICES_SAVE;
521             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD" );
522             break;
523         case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
524             m_nDialogType = NAVIGATIONSERVICES_SAVE;
525             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS" );
526             break;
527         case FILESAVE_AUTOEXTENSION_SELECTION:
528             m_nDialogType = NAVIGATIONSERVICES_SAVE;
529             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_SELECTION" );
530             break;
531         case FILESAVE_AUTOEXTENSION_TEMPLATE:
532             m_nDialogType = NAVIGATIONSERVICES_SAVE;
533             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_TEMPLATE" );
534             break;
535         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
536             m_nDialogType = NAVIGATIONSERVICES_OPEN;
537             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE" );
538             break;
539         case FILEOPEN_PLAY:
540             m_nDialogType = NAVIGATIONSERVICES_OPEN;
541             OSL_TRACE( "Template: FILEOPEN_PLAY" );
542             break;
543         case FILEOPEN_READONLY_VERSION:
544             m_nDialogType = NAVIGATIONSERVICES_OPEN;
545             OSL_TRACE( "Template: FILEOPEN_READONLY_VERSION" );
546             break;
547         case FILEOPEN_LINK_PREVIEW:
548             m_nDialogType = NAVIGATIONSERVICES_OPEN;
549             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW" );
550             break;
551         case FILESAVE_AUTOEXTENSION:
552             m_nDialogType = NAVIGATIONSERVICES_SAVE;
553             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION" );
554             break;
555         default:
556             throw lang::IllegalArgumentException(rtl::OUString("Unknown template"),
557                                                  static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ),
558                                                  1 );
559     }
561     m_pControlHelper->initialize(templateId);
563     implInitialize();
565     DBG_PRINT_EXIT(CLASS_NAME, __func__);
568 #pragma mark XCancellable
569 //------------------------------------------------------------------------------------
570 // XCancellable
571 //------------------------------------------------------------------------------------
573 void SAL_CALL SalAquaFilePicker::cancel() throw( uno::RuntimeException )
575     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
577     SolarMutexGuard aGuard;
579     if (m_pDialog != nil) {
580         [m_pDialog cancel:nil];
581     }
583     DBG_PRINT_EXIT(CLASS_NAME, __func__);
586 #pragma mark XEventListener
587 //------------------------------------------------
588 // XEventListener
589 //------------------------------------------------
591 void SAL_CALL SalAquaFilePicker::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
593     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
595     SolarMutexGuard aGuard;
597     uno::Reference<XFilePickerListener> xFilePickerListener( aEvent.Source, ::com::sun::star::uno::UNO_QUERY );
599     if( xFilePickerListener.is() )
600         removeFilePickerListener( xFilePickerListener );
602     DBG_PRINT_EXIT(CLASS_NAME, __func__);
605 #pragma mark XServiceInfo
606 // -------------------------------------------------
607 // XServiceInfo
608 // -------------------------------------------------
610 rtl::OUString SAL_CALL SalAquaFilePicker::getImplementationName()
611 throw( uno::RuntimeException )
613     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
615     rtl::OUString retVal(RTL_CONSTASCII_USTRINGPARAM( FILE_PICKER_IMPL_NAME ));
617     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
619     return retVal;
622 sal_Bool SAL_CALL SalAquaFilePicker::supportsService( const rtl::OUString& sServiceName )
623 throw( uno::RuntimeException )
625     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "service name", sServiceName);
627     sal_Bool retVal = sal_False;
629     uno::Sequence <rtl::OUString> supportedServicesNames = FilePicker_getSupportedServiceNames();
631     for( sal_Int32 n = supportedServicesNames.getLength(); n--; ) {
632         if( supportedServicesNames[n] == sServiceName ) {
633             retVal = sal_True;
634             break;
635         }
636     }
638     DBG_PRINT_EXIT(CLASS_NAME, __func__);
640     return retVal;
643 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getSupportedServiceNames()
644 throw( uno::RuntimeException )
646     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
647     DBG_PRINT_EXIT(CLASS_NAME, __func__);
649     return FilePicker_getSupportedServiceNames();
652 #pragma mark Misc/Private
653 //-----------------------------------------------------------------------------------------
654 // FilePicker Event functions
655 //-----------------------------------------------------------------------------------------
657 void SAL_CALL SalAquaFilePicker::fileSelectionChanged( FilePickerEvent aEvent )
659     OSL_TRACE( "file selection changed");
660     if (m_xListener.is())
661         m_xListener->fileSelectionChanged( aEvent );
664 void SAL_CALL SalAquaFilePicker::directoryChanged( FilePickerEvent aEvent )
666     OSL_TRACE("directory changed");
667     if (m_xListener.is())
668         m_xListener->directoryChanged( aEvent );
671 void SAL_CALL SalAquaFilePicker::controlStateChanged( FilePickerEvent aEvent )
673     OSL_TRACE("control state changed");
674     if (m_xListener.is())
675         m_xListener->controlStateChanged( aEvent );
678 void SAL_CALL SalAquaFilePicker::dialogSizeChanged()
680     OSL_TRACE("dialog size changed");
681     if (m_xListener.is())
682         m_xListener->dialogSizeChanged();
685 //--------------------------------------------------
686 // Misc
687 //-------------------------------------------------
688 void SalAquaFilePicker::ensureFilterHelper() {
689     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
691     SolarMutexGuard aGuard;
693     if (NULL == m_pFilterHelper) {
694         m_pFilterHelper = new FilterHelper;
695         m_pControlHelper->setFilterHelper(m_pFilterHelper);
696         [m_pDelegate setFilterHelper:m_pFilterHelper];
697     }
699     DBG_PRINT_EXIT(CLASS_NAME, __func__);
702 void SalAquaFilePicker::implInitialize()
704     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
706     //call super
707     SalAquaPicker::implInitialize();
709     DBG_PRINT_EXIT(CLASS_NAME, __func__);
712 void SalAquaFilePicker::updateFilterUI() {
713     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
715     m_pControlHelper->updateFilterUI();
717     DBG_PRINT_EXIT(CLASS_NAME, __func__);
720 void SalAquaFilePicker::updateSaveFileNameExtension() {
721     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
723     if (m_nDialogType != NAVIGATIONSERVICES_SAVE) {
724         return;
725     }
727     // we need to set this here again because initial setting does
728     //[m_pDialog setExtensionHidden:YES];
730     SolarMutexGuard aGuard;
732     if (m_pControlHelper->isAutoExtensionEnabled() == false) {
733         OSL_TRACE("allowing other file types");
734         [m_pDialog setAllowedFileTypes:nil];
735         [m_pDialog setAllowsOtherFileTypes:YES];
736     } else {
737         ensureFilterHelper();
739         OUStringList aStringList = m_pFilterHelper->getCurrentFilterSuffixList();
740         if( aStringList.empty()) // #i9328#
741             return;
743         rtl::OUString suffix = (*(aStringList.begin())).copy(1);
744         NSString *requiredFileType = [NSString stringWithOUString:suffix];
746 #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE
747 #pragma GCC diagnostic push
748 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
749 #endif
750         [m_pDialog setRequiredFileType:requiredFileType];
751 #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE
752 #pragma GCC diagnostic pop
753 #endif
755         OSL_TRACE("disallowing other file types");
756         [m_pDialog setAllowsOtherFileTypes:NO];
757     }
759     DBG_PRINT_EXIT(CLASS_NAME, __func__);
762 void SalAquaFilePicker::filterControlChanged() {
763     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
765     if (m_pDialog == nil) {
766         return;
767     }
769     SolarMutexGuard aGuard;
771     updateSaveFileNameExtension();
773     [m_pDialog validateVisibleColumns];
775     FilePickerEvent evt;
776     evt.ElementId = LISTBOX_FILTER;
777     controlStateChanged( evt );
779     DBG_PRINT_EXIT(CLASS_NAME, __func__);
782 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */