update emoji autocorrect entries from po-files
[LibreOffice.git] / fpicker / source / aqua / SalAquaFilePicker.mm
bloba760f84158cacbbe52f8006f55cc6d2c430f7aee
1 /* -*- Mode: ObjC; 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 <config_features.h>
22 #include "sal/config.h"
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
27 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
28 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
29 #include <cppuhelper/interfacecontainer.h>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <osl/diagnose.h>
32 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <FPServiceInfo.hxx>
36 #include <osl/mutex.hxx>
37 #include <vcl/svapp.hxx>
39 #include "resourceprovider.hxx"
41 #include <osl/file.hxx>
42 #include "CFStringUtilities.hxx"
43 #include "NSString_OOoAdditions.hxx"
44 #include "NSURL_OOoAdditions.hxx"
46 #include <iostream>
48 #include "SalAquaFilePicker.hxx"
50 #include <objc/objc-runtime.h>
52 #pragma mark DEFINES
54 #define CLASS_NAME "SalAquaFilePicker"
57 // namespace directives
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::ui::dialogs;
62 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
63 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
64 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::uno;
70 // helper functions
73 namespace
75     uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
76     {
77         uno::Sequence<rtl::OUString> aRet(3);
78         aRet[0] = "com.sun.star.ui.dialogs.FilePicker";
79         aRet[1] = "com.sun.star.ui.dialogs.SystemFilePicker";
80         aRet[2] = "com.sun.star.ui.dialogs.AquaFilePicker";
81         return aRet;
82     }
85 #pragma mark Constructor
87 // constructor
90 SalAquaFilePicker::SalAquaFilePicker()
91   : SalAquaFilePicker_Base( m_rbHelperMtx )
92    , m_pFilterHelper( NULL )
94     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
96     m_pDelegate = [[AquaFilePickerDelegate alloc] initWithFilePicker:this];
97     m_pControlHelper->setFilePickerDelegate(m_pDelegate);
99     DBG_PRINT_EXIT(CLASS_NAME, __func__);
102 SalAquaFilePicker::~SalAquaFilePicker()
104     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
106     if (NULL != m_pFilterHelper)
107         delete m_pFilterHelper;
109     [m_pDelegate release];
111     DBG_PRINT_EXIT(CLASS_NAME, __func__);
115 #pragma mark XFilePickerNotifier
117 // XFilePickerNotifier
120 void SAL_CALL SalAquaFilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
121     throw( uno::RuntimeException )
123     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
125     SolarMutexGuard aGuard;
126     m_xListener = xListener;
128     DBG_PRINT_EXIT(CLASS_NAME, __func__);
131 void SAL_CALL SalAquaFilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
132     throw( uno::RuntimeException )
134     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
136     SolarMutexGuard aGuard;
137     m_xListener.clear();
139     DBG_PRINT_EXIT(CLASS_NAME, __func__);
142 #pragma mark XAsynchronousExecutableDialog
144 // XExecutableDialog functions
146 void SAL_CALL SalAquaFilePicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
148     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
150     SolarMutexGuard aGuard;
151     implsetTitle(aTitle);
153     DBG_PRINT_EXIT(CLASS_NAME, __func__);
156 sal_Int16 SAL_CALL SalAquaFilePicker::execute() throw( uno::RuntimeException )
158     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
160     SolarMutexGuard aGuard;
162     sal_Int16 retVal = 0;
164     implInitialize();
166     // if m_pDialog is nil after initialization, something must have gone wrong before
167     // or there was no initialization (see issue http://www.openoffice.org/issues/show_bug.cgi?id=100214)
168     if (m_pDialog == nil) {
169         m_nDialogType = NAVIGATIONSERVICES_OPEN;
170     }
172     if (m_pFilterHelper) {
173         m_pFilterHelper->SetFilters();
174     }
176     if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
177         if (m_sSaveFileName.getLength() == 0) {
178             //if no filename is set, NavigationServices will set the name to "untitled". We don't want this!
179             //So let's try to get the window title to get the real untitled name
180             NSWindow *frontWindow = [NSApp keyWindow];
181             if (NULL != frontWindow) {
182                 NSString *windowTitle = [frontWindow title];
183                 if (windowTitle != nil) {
184                     rtl::OUString ouName = [windowTitle OUString];
185                     //a window title will typically be something like "Untitled1 - OpenOffice.org Writer"
186                     //but we only want the "Untitled1" part of it
187                     sal_Int32 indexOfDash = ouName.indexOf(" - ");
188                     if (indexOfDash > -1) {
189                         m_sSaveFileName = ouName.copy(0,indexOfDash);
190                         if (m_sSaveFileName.getLength() > 0) {
191                             setDefaultName(m_sSaveFileName);
192                         }
193                     } else {
194                         OSL_TRACE("no dash present in window title");
195                     }
196                 } else {
197                     OSL_TRACE("couldn't get window title");
198                 }
199             } else {
200                 OSL_TRACE("no front window found");
201             }
202         }
203     }
205     //Set the delegate to be notified of certain events
207     // I don't know why, but with gcc 4.2.1, this line results in the warning:
208     // class 'AquaFilePickerDelegate' does not implement the 'NSOpenSavePanelDelegate' protocol
209     // So instead of:
210     // [m_pDialog setDelegate:m_pDelegate];
211     // do:
212     objc_msgSend(m_pDialog, @selector(setDelegate:), m_pDelegate);
214     int nStatus = runandwaitforresult();
216     [m_pDialog setDelegate:nil];
218     switch( nStatus )
219     {
220 #if MACOSX_SDK_VERSION >= 101000
221         case NSModalResponseOK:
222 #else
223         case NSOKButton:
224 #endif
225             OSL_TRACE("The dialog returned OK");
226             retVal = ExecutableDialogResults::OK;
227             break;
229 #if MACOSX_SDK_VERSION >= 101000
230         case NSModalResponseCancel:
231 #else
232         case NSCancelButton:
233 #endif
234             OSL_TRACE("The dialog was cancelled by the user!");
235             retVal = ExecutableDialogResults::CANCEL;
236             break;
238         default:
239             throw uno::RuntimeException(
240                       "The dialog returned with an unknown result!", 
241                       static_cast<XFilePicker*>( static_cast<XFilePicker3*>( this ) ));
242             break;
243     }
245     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
247     return retVal;
251 #pragma mark XFilePicker
253 // XFilePicker functions
256 void SAL_CALL SalAquaFilePicker::setMultiSelectionMode( sal_Bool bMode ) throw( uno::RuntimeException )
258     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "multiSelectable?", int(bMode));
260     SolarMutexGuard aGuard;
262     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
263         [(NSOpenPanel*)m_pDialog setAllowsMultipleSelection:YES];
264         OSL_TRACE("dialog allows multi-selection? %d", [(NSOpenPanel*)m_pDialog allowsMultipleSelection]);
265     }
267     DBG_PRINT_EXIT(CLASS_NAME, __func__);
270 void SAL_CALL SalAquaFilePicker::setDefaultName( const rtl::OUString& aName )
271 throw( uno::RuntimeException )
273     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "name", aName);
275     SolarMutexGuard aGuard;
277     m_sSaveFileName = aName;
279     DBG_PRINT_EXIT(CLASS_NAME, __func__);
282 void SAL_CALL SalAquaFilePicker::setDisplayDirectory( const rtl::OUString& rDirectory )
283 throw( lang::IllegalArgumentException, uno::RuntimeException )
285     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", rDirectory);
287     SolarMutexGuard aGuard;
289     implsetDisplayDirectory(rDirectory);
291     DBG_PRINT_EXIT(CLASS_NAME, __func__);
294 rtl::OUString SAL_CALL SalAquaFilePicker::getDisplayDirectory() throw( uno::RuntimeException )
296     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
298     rtl::OUString retVal = implgetDisplayDirectory();
300     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
301     return retVal;
304 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getFiles() throw( uno::RuntimeException )
306     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
308     SolarMutexGuard aGuard;
310 #if HAVE_FEATURE_MACOSX_SANDBOX
311     static NSUserDefaults *userDefaults;
312     static bool triedUserDefaults = false;
314     if (!triedUserDefaults)
315     {
316         userDefaults = [NSUserDefaults standardUserDefaults];
317         triedUserDefaults = true;
318     }
319 #endif
321     // OSL_TRACE("starting work");
322     /*
323      * If more than one file is selected in an OpenDialog, then the first result
324      * is the directory and the remaining results contain just the files' names
325      * without the basedir path.
326      */
327     NSArray *files = nil;
328     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
329         files = [(NSOpenPanel*)m_pDialog URLs];
330     }
331     else if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
332         files = [NSArray arrayWithObjects:[m_pDialog URL], nil];
333     }
335     long nFiles = [files count];
336     SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
338     uno::Sequence< rtl::OUString > aSelectedFiles(nFiles > 1 ? nFiles + 1 : nFiles);
340     for(int nIndex = 0; nIndex < nFiles; nIndex += 1)
341     {
342         NSURL *url = [files objectAtIndex:nIndex];
344 #if HAVE_FEATURE_MACOSX_SANDBOX
345         if (userDefaults != NULL &&
346             [url respondsToSelector:@selector(bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:)])
347         {
348             // In the case of "Save As" when the user has input a new
349             // file name, this call will return nil, as bookmarks can
350             // (naturally) only be created for existing file system
351             // objects. In that case, code at a much lower level, in
352             // sal, takes care of creating a bookmark when a new file
353             // has been created outside the sandbox.
354             NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
355                          includingResourceValuesForKeys:nil
356                                           relativeToURL:nil
357                                                   error:nil];
358             if (data != NULL)
359             {
360                 [userDefaults setObject:data
361                                  forKey:[@"bookmarkFor:" stringByAppendingString:[url absoluteString]]];
362             }
363         }
364 #endif
366         OSL_TRACE("handling %s", [[url description] UTF8String]);
367         InfoType info = FULLPATH;
368         if (nFiles > 1) {
369             //just get the file's name (only in OpenDialog)
370             info = FILENAME;
371         }
372         OUString sFileOrDirURL = [url OUStringForInfo:info];
374         //get the directory information, only on the first file processed
375         if (nIndex == 0) {
376             OUString sDirectoryURL = [url OUStringForInfo:PATHWITHOUTLASTCOMPONENT];
378             if (nFiles > 1) {
379                 aSelectedFiles[0] = OUString(sDirectoryURL);
380             }
381         }
383         short nSequenceIndex = nFiles > 1 ? nIndex + 1 : nIndex;
384         aSelectedFiles[nSequenceIndex] = sFileOrDirURL;
386         OSL_TRACE("Returned file in getFiles: \"%s\".", OUStringToOString(sFileOrDirURL, RTL_TEXTENCODING_UTF8).getStr());
387     }
389     DBG_PRINT_EXIT(CLASS_NAME, __func__);
390     return aSelectedFiles;
393 #pragma mark XFilterManager
395 // XFilterManager functions
398 void SAL_CALL SalAquaFilePicker::appendFilter( const rtl::OUString& aTitle, const rtl::OUString& aFilter )
399 throw( lang::IllegalArgumentException, uno::RuntimeException )
401     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
403     SolarMutexGuard aGuard;
405     ensureFilterHelper();
406     m_pFilterHelper->appendFilter( aTitle, aFilter );
407     m_pControlHelper->setFilterControlNeeded(true);
409     DBG_PRINT_EXIT(CLASS_NAME, __func__);
412 void SAL_CALL SalAquaFilePicker::setCurrentFilter( const rtl::OUString& aTitle )
413 throw( lang::IllegalArgumentException, uno::RuntimeException )
415     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
416     OSL_TRACE( "Setting current filter to %s",
417                OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
419     SolarMutexGuard aGuard;
421     ensureFilterHelper();
422     m_pFilterHelper->setCurrentFilter(aTitle);
423     updateFilterUI();
425     updateSaveFileNameExtension();
427     DBG_PRINT_EXIT(CLASS_NAME, __func__);
430 rtl::OUString SAL_CALL SalAquaFilePicker::getCurrentFilter() throw( uno::RuntimeException )
432     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
433     SolarMutexGuard aGuard;
435     ensureFilterHelper();
437     DBG_PRINT_EXIT(CLASS_NAME, __func__);
438     return m_pFilterHelper->getCurrentFilter();
441 #pragma mark XFilterGroupManager
443 // XFilterGroupManager functions
446 void SAL_CALL SalAquaFilePicker::appendFilterGroup( const rtl::OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters )
447 throw( lang::IllegalArgumentException, uno::RuntimeException )
449     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
450     SolarMutexGuard aGuard;
452     ensureFilterHelper();
453     m_pFilterHelper->appendFilterGroup(sGroupTitle, aFilters);
454     m_pControlHelper->setFilterControlNeeded(true);
455     DBG_PRINT_EXIT(CLASS_NAME, __func__);
458 #pragma mark XFilePickerControlAccess
460 // XFilePickerControlAccess functions
463 void SAL_CALL SalAquaFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue )
464 throw( uno::RuntimeException )
466     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
468     SolarMutexGuard aGuard;
470     m_pControlHelper->setValue(nControlId, nControlAction, rValue);
472     if (nControlId == ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION && m_nDialogType == NAVIGATIONSERVICES_SAVE) {
473         updateSaveFileNameExtension();
474     }
476     DBG_PRINT_EXIT(CLASS_NAME, __func__);
479 uno::Any SAL_CALL SalAquaFilePicker::getValue( sal_Int16 nControlId, sal_Int16 nControlAction )
480 throw( uno::RuntimeException )
482     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
484     uno::Any aValue = m_pControlHelper->getValue(nControlId, nControlAction);
486     DBG_PRINT_EXIT(CLASS_NAME, __func__);
487     return aValue;
490 void SAL_CALL SalAquaFilePicker::enableControl( sal_Int16 nControlId, sal_Bool bEnable )
491 throw( uno::RuntimeException )
493     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
495     m_pControlHelper->enableControl(nControlId, bEnable);
497     DBG_PRINT_EXIT(CLASS_NAME, __func__);
500 void SAL_CALL SalAquaFilePicker::setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
501 throw( uno::RuntimeException )
503     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
505     SolarMutexGuard aGuard;
507     NSString* sLabel = [NSString stringWithOUString:aLabel];
508     m_pControlHelper->setLabel( nControlId, sLabel ) ;
510     DBG_PRINT_EXIT(CLASS_NAME, __func__);
513 rtl::OUString SAL_CALL SalAquaFilePicker::getLabel( sal_Int16 nControlId )
514 throw( uno::RuntimeException )
516     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
517     DBG_PRINT_EXIT(CLASS_NAME, __func__);
519     return m_pControlHelper->getLabel(nControlId);
522 #pragma mark XInitialization
524 // XInitialization
527 void SAL_CALL SalAquaFilePicker::initialize( const uno::Sequence<uno::Any>& aArguments )
528 throw( uno::Exception, uno::RuntimeException )
530     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "arguments size", aArguments.getLength());
532     SolarMutexGuard aGuard;
534     // parameter checking
535     uno::Any aAny;
536     if( 0 == aArguments.getLength() )
537         throw lang::IllegalArgumentException("no arguments",
538                                              static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ), 1 );
540     aAny = aArguments[0];
542     if( ( aAny.getValueType() != ::cppu::UnoType<sal_Int16>::get() ) &&
543         (aAny.getValueType() != ::cppu::UnoType<sal_Int8>::get() ) )
544         throw lang::IllegalArgumentException("invalid argument type",
545                                              static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ), 1 );
547     sal_Int16 templateId = -1;
548     aAny >>= templateId;
550     switch( templateId )
551     {
552         case FILEOPEN_SIMPLE:
553             m_nDialogType = NAVIGATIONSERVICES_OPEN;
554             OSL_TRACE( "Template: FILEOPEN_SIMPLE" );
555             break;
556         case FILESAVE_SIMPLE:
557             m_nDialogType = NAVIGATIONSERVICES_SAVE;
558             OSL_TRACE( "Template: FILESAVE_SIMPLE" );
559             break;
560         case FILESAVE_AUTOEXTENSION_PASSWORD:
561             m_nDialogType = NAVIGATIONSERVICES_SAVE;
562             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD" );
563             break;
564         case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
565             m_nDialogType = NAVIGATIONSERVICES_SAVE;
566             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS" );
567             break;
568         case FILESAVE_AUTOEXTENSION_SELECTION:
569             m_nDialogType = NAVIGATIONSERVICES_SAVE;
570             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_SELECTION" );
571             break;
572         case FILESAVE_AUTOEXTENSION_TEMPLATE:
573             m_nDialogType = NAVIGATIONSERVICES_SAVE;
574             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_TEMPLATE" );
575             break;
576         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
577             m_nDialogType = NAVIGATIONSERVICES_OPEN;
578             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE" );
579             break;
580         case FILEOPEN_PLAY:
581             m_nDialogType = NAVIGATIONSERVICES_OPEN;
582             OSL_TRACE( "Template: FILEOPEN_PLAY" );
583             break;
584         case FILEOPEN_READONLY_VERSION:
585             m_nDialogType = NAVIGATIONSERVICES_OPEN;
586             OSL_TRACE( "Template: FILEOPEN_READONLY_VERSION" );
587             break;
588         case FILEOPEN_LINK_PREVIEW:
589             m_nDialogType = NAVIGATIONSERVICES_OPEN;
590             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW" );
591             break;
592         case FILESAVE_AUTOEXTENSION:
593             m_nDialogType = NAVIGATIONSERVICES_SAVE;
594             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION" );
595             break;
596         default:
597             throw lang::IllegalArgumentException("Unknown template",
598                                                  static_cast<XFilePicker*>( static_cast<XFilePicker3*>(this) ),
599                                                  1 );
600     }
602     m_pControlHelper->initialize(templateId);
604     implInitialize();
606     DBG_PRINT_EXIT(CLASS_NAME, __func__);
609 #pragma mark XCancellable
611 // XCancellable
614 void SAL_CALL SalAquaFilePicker::cancel() throw( uno::RuntimeException )
616     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
618     SolarMutexGuard aGuard;
620     if (m_pDialog != nil) {
621         [m_pDialog cancel:nil];
622     }
624     DBG_PRINT_EXIT(CLASS_NAME, __func__);
627 #pragma mark XEventListener
629 // XEventListener
632 void SAL_CALL SalAquaFilePicker::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
634     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
636     SolarMutexGuard aGuard;
638     uno::Reference<XFilePickerListener> xFilePickerListener( aEvent.Source, ::com::sun::star::uno::UNO_QUERY );
640     if( xFilePickerListener.is() )
641         removeFilePickerListener( xFilePickerListener );
643     DBG_PRINT_EXIT(CLASS_NAME, __func__);
646 #pragma mark XServiceInfo
648 // XServiceInfo
651 rtl::OUString SAL_CALL SalAquaFilePicker::getImplementationName()
652 throw( uno::RuntimeException )
654     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
656     rtl::OUString retVal( FILE_PICKER_IMPL_NAME );
658     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
660     return retVal;
663 sal_Bool SAL_CALL SalAquaFilePicker::supportsService( const rtl::OUString& sServiceName )
664 throw( uno::RuntimeException )
666     return cppu::supportsService(this, sServiceName);
669 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getSupportedServiceNames()
670 throw( uno::RuntimeException )
672     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
673     DBG_PRINT_EXIT(CLASS_NAME, __func__);
675     return FilePicker_getSupportedServiceNames();
678 #pragma mark Misc/Private
680 // FilePicker Event functions
683 void SAL_CALL SalAquaFilePicker::fileSelectionChanged( FilePickerEvent aEvent )
685     OSL_TRACE( "file selection changed");
686     if (m_xListener.is())
687         m_xListener->fileSelectionChanged( aEvent );
690 void SAL_CALL SalAquaFilePicker::directoryChanged( FilePickerEvent aEvent )
692     OSL_TRACE("directory changed");
693     if (m_xListener.is())
694         m_xListener->directoryChanged( aEvent );
697 void SAL_CALL SalAquaFilePicker::controlStateChanged( FilePickerEvent aEvent )
699     OSL_TRACE("control state changed");
700     if (m_xListener.is())
701         m_xListener->controlStateChanged( aEvent );
704 void SAL_CALL SalAquaFilePicker::dialogSizeChanged()
706     OSL_TRACE("dialog size changed");
707     if (m_xListener.is())
708         m_xListener->dialogSizeChanged();
712 // Misc
714 void SalAquaFilePicker::ensureFilterHelper() {
715     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
717     SolarMutexGuard aGuard;
719     if (NULL == m_pFilterHelper) {
720         m_pFilterHelper = new FilterHelper;
721         m_pControlHelper->setFilterHelper(m_pFilterHelper);
722         [m_pDelegate setFilterHelper:m_pFilterHelper];
723     }
725     DBG_PRINT_EXIT(CLASS_NAME, __func__);
728 void SalAquaFilePicker::implInitialize()
730     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
732     //call super
733     SalAquaPicker::implInitialize();
735     DBG_PRINT_EXIT(CLASS_NAME, __func__);
738 void SalAquaFilePicker::updateFilterUI() {
739     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
741     m_pControlHelper->updateFilterUI();
743     DBG_PRINT_EXIT(CLASS_NAME, __func__);
746 void SalAquaFilePicker::updateSaveFileNameExtension() {
747     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
749     if (m_nDialogType != NAVIGATIONSERVICES_SAVE) {
750         return;
751     }
753     // we need to set this here again because initial setting does
754     //[m_pDialog setExtensionHidden:YES];
756     SolarMutexGuard aGuard;
758     if (!m_pControlHelper->isAutoExtensionEnabled()) {
759         OSL_TRACE("allowing other file types");
760         [m_pDialog setAllowedFileTypes:nil];
761         [m_pDialog setAllowsOtherFileTypes:YES];
762     } else {
763         ensureFilterHelper();
765         OUStringList aStringList = m_pFilterHelper->getCurrentFilterSuffixList();
766         if( aStringList.empty()) // #i9328#
767             return;
769         rtl::OUString suffix = (*(aStringList.begin())).copy(1);
770         NSString *requiredFileType = [NSString stringWithOUString:suffix];
772         [m_pDialog setAllowedFileTypes:[NSArray arrayWithObjects:requiredFileType, nil]];
774         OSL_TRACE("disallowing other file types");
775         [m_pDialog setAllowsOtherFileTypes:NO];
776     }
778     DBG_PRINT_EXIT(CLASS_NAME, __func__);
781 void SalAquaFilePicker::filterControlChanged() {
782     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
784     if (m_pDialog == nil) {
785         return;
786     }
788     SolarMutexGuard aGuard;
790     updateSaveFileNameExtension();
792     [m_pDialog validateVisibleColumns];
794     FilePickerEvent evt;
795     evt.ElementId = LISTBOX_FILTER;
796     controlStateChanged( evt );
798     DBG_PRINT_EXIT(CLASS_NAME, __func__);
801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */