xref: /AOO41X/main/fpicker/source/aqua/SalAquaFilePicker.cxx (revision b557fc96600fce3029f73c89748b6c08fd00b34d)
1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b557fc96SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b557fc96SAndrew Rist  * distributed with this work for additional information
6*b557fc96SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b557fc96SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist  * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b557fc96SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist  * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b557fc96SAndrew Rist  * specific language governing permissions and limitations
18*b557fc96SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //------------------------------------------------------------------------
25cdf0e10cSrcweir // includes
26cdf0e10cSrcweir //------------------------------------------------------------------------
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
33cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h>
34cdf0e10cSrcweir #include <osl/diagnose.h>
35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ControlActions.hpp>
37cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
38cdf0e10cSrcweir #include <FPServiceInfo.hxx>
39cdf0e10cSrcweir #include <vos/mutex.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #ifndef _TOOLS_URLOBJ_HXX
43cdf0e10cSrcweir #include <tools/urlobj.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #include "resourceprovider.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #ifndef _SV_RC_H
48cdf0e10cSrcweir #include <tools/rc.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #include <osl/file.hxx>
51cdf0e10cSrcweir #include "CFStringUtilities.hxx"
52cdf0e10cSrcweir #include "NSString_OOoAdditions.hxx"
53cdf0e10cSrcweir #include "NSURL_OOoAdditions.hxx"
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <iostream>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include "SalAquaFilePicker.hxx"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #pragma mark DEFINES
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #define LABEL_TOGGLE( elem ) \
63cdf0e10cSrcweir case elem : \
64cdf0e10cSrcweir aLabel = aResProvider.getResString( CHECKBOX_##elem ); \
65cdf0e10cSrcweir     setLabel( CHECKBOX_##elem, aLabel ); \
66cdf0e10cSrcweir     break
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #define CLASS_NAME "SalAquaFilePicker"
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //------------------------------------------------------------------------
71cdf0e10cSrcweir // namespace directives
72cdf0e10cSrcweir //------------------------------------------------------------------------
73cdf0e10cSrcweir 
74cdf0e10cSrcweir using namespace ::com::sun::star;
75cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
76cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
77cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
78cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
79cdf0e10cSrcweir using namespace ::com::sun::star::lang;
80cdf0e10cSrcweir using namespace ::com::sun::star::beans;
81cdf0e10cSrcweir using namespace ::com::sun::star::uno;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //------------------------------------------------------------------------
84cdf0e10cSrcweir // helper functions
85cdf0e10cSrcweir //------------------------------------------------------------------------
86cdf0e10cSrcweir 
87cdf0e10cSrcweir namespace
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     // controling event notifications
90cdf0e10cSrcweir     const bool STARTUP_SUSPENDED = true;
91cdf0e10cSrcweir     const bool STARTUP_ALIVE     = false;
92cdf0e10cSrcweir 
FilePicker_getSupportedServiceNames()93cdf0e10cSrcweir     uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         uno::Sequence<rtl::OUString> aRet(3);
96cdf0e10cSrcweir         aRet[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" );
97cdf0e10cSrcweir         aRet[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFilePicker" );
98cdf0e10cSrcweir         aRet[2] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.AquaFilePicker" );
99cdf0e10cSrcweir         return aRet;
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir #pragma mark Constructor
104cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
105cdf0e10cSrcweir // constructor
106cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
107cdf0e10cSrcweir 
SalAquaFilePicker(const uno::Reference<lang::XMultiServiceFactory> & xServiceMgr)108cdf0e10cSrcweir SalAquaFilePicker::SalAquaFilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
109cdf0e10cSrcweir cppu::WeakComponentImplHelper8<XFilterManager, XFilterGroupManager, XFilePickerControlAccess, XFilePickerNotifier,
110cdf0e10cSrcweir  lang::XInitialization, util::XCancellable, lang::XEventListener, lang::XServiceInfo>( m_rbHelperMtx )
111cdf0e10cSrcweir , m_xServiceMgr( xServiceMgr )
112cdf0e10cSrcweir , m_pFilterHelper( NULL )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     m_pDelegate = [[AquaFilePickerDelegate alloc] initWithFilePicker:this];
117cdf0e10cSrcweir     m_pControlHelper->setFilePickerDelegate(m_pDelegate);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
~SalAquaFilePicker()122cdf0e10cSrcweir SalAquaFilePicker::~SalAquaFilePicker()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     if (NULL != m_pFilterHelper)
127cdf0e10cSrcweir         delete m_pFilterHelper;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     [m_pDelegate release];
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir #pragma mark XFilePickerNotifier
136cdf0e10cSrcweir //------------------------------------------------------------------------------------
137cdf0e10cSrcweir // XFilePickerNotifier
138cdf0e10cSrcweir //------------------------------------------------------------------------------------
139cdf0e10cSrcweir 
addFilePickerListener(const uno::Reference<XFilePickerListener> & xListener)140cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
141cdf0e10cSrcweir     throw( uno::RuntimeException )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
146cdf0e10cSrcweir     m_xListener = xListener;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
removeFilePickerListener(const uno::Reference<XFilePickerListener> &)151cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
152cdf0e10cSrcweir     throw( uno::RuntimeException )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
157cdf0e10cSrcweir     m_xListener.clear();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir #pragma mark XAsynchronousExecutableDialog
163cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
164cdf0e10cSrcweir // XExecutableDialog functions
165cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
setTitle(const rtl::OUString & aTitle)166cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
171cdf0e10cSrcweir     implsetTitle(aTitle);
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
execute()176cdf0e10cSrcweir sal_Int16 SAL_CALL SalAquaFilePicker::execute() throw( uno::RuntimeException )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     sal_Int16 retVal = 0;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     implInitialize();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     // if m_pDialog is nil after initialization, something must have gone wrong before
187cdf0e10cSrcweir     // or there was no initialization (see issue http://www.openoffice.org/issues/show_bug.cgi?id=100214)
188cdf0e10cSrcweir     if (m_pDialog == nil) {
189cdf0e10cSrcweir         //throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog was not properly initialized!"), static_cast< XFilePicker* >( this ));
190cdf0e10cSrcweir         m_nDialogType = NAVIGATIONSERVICES_OPEN;
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     if (m_pFilterHelper) {
194cdf0e10cSrcweir         m_pFilterHelper->SetFilters();
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
198cdf0e10cSrcweir         if (m_sSaveFileName.getLength() == 0) {
199cdf0e10cSrcweir             //if no filename is set, NavigationServices will set the name to "untitled". We don't want this!
200cdf0e10cSrcweir             //So let's try to get the window title to get the real untitled name
201cdf0e10cSrcweir             NSWindow *frontWindow = [NSApp keyWindow];
202cdf0e10cSrcweir             if (NULL != frontWindow) {
203cdf0e10cSrcweir                 NSString *windowTitle = [frontWindow title];
204cdf0e10cSrcweir                 if (windowTitle != nil) {
205cdf0e10cSrcweir                     rtl::OUString ouName = [windowTitle OUString];
206cdf0e10cSrcweir                     //a window title will typically be something like "Untitled1 - OpenOffice.org Writer"
207cdf0e10cSrcweir                     //but we only want the "Untitled1" part of it
208cdf0e10cSrcweir                     sal_Int32 indexOfDash = ouName.indexOf(rtl::OUString::createFromAscii(" - "));
209cdf0e10cSrcweir                     if (indexOfDash > -1) {
210cdf0e10cSrcweir                         m_sSaveFileName = ouName.copy(0,indexOfDash);
211cdf0e10cSrcweir                         if (m_sSaveFileName.getLength() > 0) {
212cdf0e10cSrcweir                             setDefaultName(m_sSaveFileName);
213cdf0e10cSrcweir                         }
214cdf0e10cSrcweir                     } else {
215cdf0e10cSrcweir                         OSL_TRACE("no dash present in window title");
216cdf0e10cSrcweir                     }
217cdf0e10cSrcweir                 } else {
218cdf0e10cSrcweir                     OSL_TRACE("couldn't get window title");
219cdf0e10cSrcweir                 }
220cdf0e10cSrcweir             } else {
221cdf0e10cSrcweir                 OSL_TRACE("no front window found");
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     //Set the delegate to be notified of certain events
227cdf0e10cSrcweir     [m_pDialog setDelegate:m_pDelegate];
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     int nStatus = runandwaitforresult();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     [m_pDialog setDelegate:nil];
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     switch( nStatus )
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         case NSOKButton:
236cdf0e10cSrcweir             OSL_TRACE("The dialog returned OK");
237cdf0e10cSrcweir             retVal = ExecutableDialogResults::OK;
238cdf0e10cSrcweir             break;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         case NSCancelButton:
241cdf0e10cSrcweir             OSL_TRACE("The dialog was cancelled by the user!");
242cdf0e10cSrcweir             retVal = ExecutableDialogResults::CANCEL;
243cdf0e10cSrcweir             break;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         default:
246cdf0e10cSrcweir             throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog returned with an unknown result!"), static_cast< XFilePicker* >( this ));
247cdf0e10cSrcweir             break;
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     return retVal;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir #pragma mark XFilePicker
257cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
258cdf0e10cSrcweir // XFilePicker functions
259cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
260cdf0e10cSrcweir 
setMultiSelectionMode(sal_Bool bMode)261cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setMultiSelectionMode( sal_Bool bMode ) throw( uno::RuntimeException )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "multiSelectable?", bMode);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
268cdf0e10cSrcweir         [(NSOpenPanel*)m_pDialog setAllowsMultipleSelection:YES];
269cdf0e10cSrcweir         OSL_TRACE("dialog allows multi-selection? %d", [(NSOpenPanel*)m_pDialog allowsMultipleSelection]);
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
setDefaultName(const rtl::OUString & aName)275cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setDefaultName( const rtl::OUString& aName )
276cdf0e10cSrcweir throw( uno::RuntimeException )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "name", aName);
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     m_sSaveFileName = aName;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
setDisplayDirectory(const rtl::OUString & rDirectory)287cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setDisplayDirectory( const rtl::OUString& rDirectory )
288cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", rDirectory);
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     implsetDisplayDirectory(rDirectory);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
getDisplayDirectory()299cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFilePicker::getDisplayDirectory() throw( uno::RuntimeException )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     rtl::OUString retVal = implgetDisplayDirectory();
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
306cdf0e10cSrcweir     return retVal;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
getFiles()309cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getFiles() throw( uno::RuntimeException )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     // OSL_TRACE("starting work");
316cdf0e10cSrcweir     /*
317cdf0e10cSrcweir      * If more than one file is selected in an OpenDialog, then the first result
318cdf0e10cSrcweir      * is the directory and the remaining results contain just the files' names
319cdf0e10cSrcweir      * without the basedir path.
320cdf0e10cSrcweir      */
321cdf0e10cSrcweir     NSArray *files = nil;
322cdf0e10cSrcweir     if (m_nDialogType == NAVIGATIONSERVICES_OPEN) {
323cdf0e10cSrcweir         files = [(NSOpenPanel*)m_pDialog URLs];
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir     else if (m_nDialogType == NAVIGATIONSERVICES_SAVE) {
326cdf0e10cSrcweir         files = [NSArray arrayWithObjects:[m_pDialog URL], nil];
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     long nFiles = [files count];
330cdf0e10cSrcweir     OSL_TRACE("# of items: %d", nFiles);
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSelectedFiles(nFiles > 1 ? nFiles + 1 : nFiles);
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     for(int nIndex = 0; nIndex < nFiles; nIndex += 1)
335cdf0e10cSrcweir     {
336cdf0e10cSrcweir         NSURL *url = [files objectAtIndex:nIndex];
337cdf0e10cSrcweir         OSL_TRACE("handling %s", [[url description] UTF8String]);
338cdf0e10cSrcweir         InfoType info = FULLPATH;
339cdf0e10cSrcweir         if (nFiles > 1) {
340cdf0e10cSrcweir             //just get the file's name (only in OpenDialog)
341cdf0e10cSrcweir             info = FILENAME;
342cdf0e10cSrcweir         }
343cdf0e10cSrcweir         OUString sFileOrDirURL = [url OUStringForInfo:info];
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         //get the directory information, only on the first file processed
346cdf0e10cSrcweir         if (nIndex == 0) {
347cdf0e10cSrcweir             OUString sDirectoryURL = [url OUStringForInfo:PATHWITHOUTLASTCOMPONENT];
348cdf0e10cSrcweir 
349cdf0e10cSrcweir             if (nFiles > 1) {
350cdf0e10cSrcweir                 aSelectedFiles[0] = OUString(sDirectoryURL);
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         short nSequenceIndex = nFiles > 1 ? nIndex + 1 : nIndex;
355cdf0e10cSrcweir         aSelectedFiles[nSequenceIndex] = sFileOrDirURL;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         OSL_TRACE("Returned file in getFiles: \"%s\".", OUStringToOString(sFileOrDirURL, RTL_TEXTENCODING_UTF8).getStr());
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
361cdf0e10cSrcweir     return aSelectedFiles;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir #pragma mark XFilterManager
365cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
366cdf0e10cSrcweir // XFilterManager functions
367cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
368cdf0e10cSrcweir 
appendFilter(const rtl::OUString & aTitle,const rtl::OUString & aFilter)369cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::appendFilter( const rtl::OUString& aTitle, const rtl::OUString& aFilter )
370cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     ensureFilterHelper();
377cdf0e10cSrcweir     m_pFilterHelper->appendFilter( aTitle, aFilter );
378cdf0e10cSrcweir     m_pControlHelper->setFilterControlNeeded(YES);
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
setCurrentFilter(const rtl::OUString & aTitle)383cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setCurrentFilter( const rtl::OUString& aTitle )
384cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
387cdf0e10cSrcweir     OSL_TRACE( "Setting current filter to %s",
388cdf0e10cSrcweir                OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     ensureFilterHelper();
393cdf0e10cSrcweir     m_pFilterHelper->setCurrentFilter(aTitle);
394cdf0e10cSrcweir     updateFilterUI();
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     updateSaveFileNameExtension();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
getCurrentFilter()401cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFilePicker::getCurrentFilter() throw( uno::RuntimeException )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
404cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     ensureFilterHelper();
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
409cdf0e10cSrcweir     return m_pFilterHelper->getCurrentFilter();
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir #pragma mark XFilterGroupManager
413cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
414cdf0e10cSrcweir // XFilterGroupManager functions
415cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
416cdf0e10cSrcweir 
appendFilterGroup(const rtl::OUString & sGroupTitle,const uno::Sequence<beans::StringPair> & aFilters)417cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::appendFilterGroup( const rtl::OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters )
418cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
421cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     ensureFilterHelper();
424cdf0e10cSrcweir     m_pFilterHelper->appendFilterGroup(sGroupTitle, aFilters);
425cdf0e10cSrcweir     m_pControlHelper->setFilterControlNeeded(YES);
426cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir #pragma mark XFilePickerControlAccess
430cdf0e10cSrcweir //------------------------------------------------------------------------------------
431cdf0e10cSrcweir // XFilePickerControlAccess functions
432cdf0e10cSrcweir //------------------------------------------------------------------------------------
433cdf0e10cSrcweir 
setValue(sal_Int16 nControlId,sal_Int16 nControlAction,const uno::Any & rValue)434cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue )
435cdf0e10cSrcweir throw( uno::RuntimeException )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     m_pControlHelper->setValue(nControlId, nControlAction, rValue);
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     if (nControlId == ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION && m_nDialogType == NAVIGATIONSERVICES_SAVE) {
444cdf0e10cSrcweir         updateSaveFileNameExtension();
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
getValue(sal_Int16 nControlId,sal_Int16 nControlAction)450cdf0e10cSrcweir uno::Any SAL_CALL SalAquaFilePicker::getValue( sal_Int16 nControlId, sal_Int16 nControlAction )
451cdf0e10cSrcweir throw( uno::RuntimeException )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     uno::Any aValue = m_pControlHelper->getValue(nControlId, nControlAction);
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
458cdf0e10cSrcweir     return aValue;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
enableControl(sal_Int16 nControlId,sal_Bool bEnable)461cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::enableControl( sal_Int16 nControlId, sal_Bool bEnable )
462cdf0e10cSrcweir throw( uno::RuntimeException )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     m_pControlHelper->enableControl(nControlId, bEnable);
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
setLabel(sal_Int16 nControlId,const::rtl::OUString & aLabel)471cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
472cdf0e10cSrcweir throw( uno::RuntimeException )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
475cdf0e10cSrcweir 
476cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     NSString* sLabel = [NSString stringWithOUString:aLabel];
479cdf0e10cSrcweir     m_pControlHelper->setLabel( nControlId, sLabel ) ;
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
getLabel(sal_Int16 nControlId)484cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFilePicker::getLabel( sal_Int16 nControlId )
485cdf0e10cSrcweir throw( uno::RuntimeException )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
488cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     return m_pControlHelper->getLabel(nControlId);
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir #pragma mark XInitialization
494cdf0e10cSrcweir //------------------------------------------------------------------------------------
495cdf0e10cSrcweir // XInitialization
496cdf0e10cSrcweir //------------------------------------------------------------------------------------
497cdf0e10cSrcweir 
initialize(const uno::Sequence<uno::Any> & aArguments)498cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::initialize( const uno::Sequence<uno::Any>& aArguments )
499cdf0e10cSrcweir throw( uno::Exception, uno::RuntimeException )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "arguments size", aArguments.getLength());
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     // parameter checking
506cdf0e10cSrcweir     uno::Any aAny;
507cdf0e10cSrcweir     if( 0 == aArguments.getLength() )
508cdf0e10cSrcweir         throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "no arguments" ),
509cdf0e10cSrcweir                                              static_cast<XFilePicker*>( this ), 1 );
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     aAny = aArguments[0];
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     if( ( aAny.getValueType() != ::getCppuType( ( sal_Int16* )0 ) ) &&
514cdf0e10cSrcweir         (aAny.getValueType() != ::getCppuType( ( sal_Int8* )0 ) ) )
515cdf0e10cSrcweir         throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "invalid argument type" ),
516cdf0e10cSrcweir                                              static_cast<XFilePicker*>( this ), 1 );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     sal_Int16 templateId = -1;
519cdf0e10cSrcweir     aAny >>= templateId;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     switch( templateId )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         case FILEOPEN_SIMPLE:
524cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_OPEN;
525cdf0e10cSrcweir             OSL_TRACE( "Template: FILEOPEN_SIMPLE" );
526cdf0e10cSrcweir             break;
527cdf0e10cSrcweir         case FILESAVE_SIMPLE:
528cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
529cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_SIMPLE" );
530cdf0e10cSrcweir             break;
531cdf0e10cSrcweir         case FILESAVE_AUTOEXTENSION_PASSWORD:
532cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
533cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD" );
534cdf0e10cSrcweir             break;
535cdf0e10cSrcweir         case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
536cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
537cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS" );
538cdf0e10cSrcweir             break;
539cdf0e10cSrcweir         case FILESAVE_AUTOEXTENSION_SELECTION:
540cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
541cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_SELECTION" );
542cdf0e10cSrcweir             break;
543cdf0e10cSrcweir         case FILESAVE_AUTOEXTENSION_TEMPLATE:
544cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
545cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION_TEMPLATE" );
546cdf0e10cSrcweir             break;
547cdf0e10cSrcweir         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
548cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_OPEN;
549cdf0e10cSrcweir             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE" );
550cdf0e10cSrcweir             break;
551cdf0e10cSrcweir         case FILEOPEN_PLAY:
552cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_OPEN;
553cdf0e10cSrcweir             OSL_TRACE( "Template: FILEOPEN_PLAY" );
554cdf0e10cSrcweir             break;
555cdf0e10cSrcweir         case FILEOPEN_READONLY_VERSION:
556cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_OPEN;
557cdf0e10cSrcweir             OSL_TRACE( "Template: FILEOPEN_READONLY_VERSION" );
558cdf0e10cSrcweir             break;
559cdf0e10cSrcweir         case FILEOPEN_LINK_PREVIEW:
560cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_OPEN;
561cdf0e10cSrcweir             OSL_TRACE( "Template: FILEOPEN_LINK_PREVIEW" );
562cdf0e10cSrcweir             break;
563cdf0e10cSrcweir         case FILESAVE_AUTOEXTENSION:
564cdf0e10cSrcweir             m_nDialogType = NAVIGATIONSERVICES_SAVE;
565cdf0e10cSrcweir             OSL_TRACE( "Template: FILESAVE_AUTOEXTENSION" );
566cdf0e10cSrcweir             break;
567cdf0e10cSrcweir         default:
568cdf0e10cSrcweir             throw lang::IllegalArgumentException(rtl::OUString::createFromAscii( "Unknown template" ),
569cdf0e10cSrcweir                                                  static_cast< XFilePicker* >( this ),
570cdf0e10cSrcweir                                                  1 );
571cdf0e10cSrcweir     }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     m_pControlHelper->initialize(templateId);
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     implInitialize();
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir #pragma mark XCancellable
581cdf0e10cSrcweir //------------------------------------------------------------------------------------
582cdf0e10cSrcweir // XCancellable
583cdf0e10cSrcweir //------------------------------------------------------------------------------------
584cdf0e10cSrcweir 
cancel()585cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::cancel() throw( uno::RuntimeException )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     if (m_pDialog != nil) {
592cdf0e10cSrcweir         [m_pDialog cancel:nil];
593cdf0e10cSrcweir     }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
598cdf0e10cSrcweir #pragma mark XEventListener
599cdf0e10cSrcweir //------------------------------------------------
600cdf0e10cSrcweir // XEventListener
601cdf0e10cSrcweir //------------------------------------------------
602cdf0e10cSrcweir 
disposing(const lang::EventObject & aEvent)603cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     uno::Reference<XFilePickerListener> xFilePickerListener( aEvent.Source, ::com::sun::star::uno::UNO_QUERY );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     if( xFilePickerListener.is() )
612cdf0e10cSrcweir         removeFilePickerListener( xFilePickerListener );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir #pragma mark XServiceInfo
618cdf0e10cSrcweir // -------------------------------------------------
619cdf0e10cSrcweir // XServiceInfo
620cdf0e10cSrcweir // -------------------------------------------------
621cdf0e10cSrcweir 
getImplementationName()622cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFilePicker::getImplementationName()
623cdf0e10cSrcweir throw( uno::RuntimeException )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     rtl::OUString retVal = rtl::OUString::createFromAscii( FILE_PICKER_IMPL_NAME );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
630cdf0e10cSrcweir 
631cdf0e10cSrcweir     return retVal;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
supportsService(const rtl::OUString & sServiceName)634cdf0e10cSrcweir sal_Bool SAL_CALL SalAquaFilePicker::supportsService( const rtl::OUString& sServiceName )
635cdf0e10cSrcweir throw( uno::RuntimeException )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "service name", sServiceName);
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     sal_Bool retVal = sal_False;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     uno::Sequence <rtl::OUString> supportedServicesNames = FilePicker_getSupportedServiceNames();
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     for( sal_Int32 n = supportedServicesNames.getLength(); n--; ) {
644cdf0e10cSrcweir         if( supportedServicesNames[n].compareTo( sServiceName ) == 0) {
645cdf0e10cSrcweir             retVal = sal_True;
646cdf0e10cSrcweir             break;
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     return retVal;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
getSupportedServiceNames()655cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getSupportedServiceNames()
656cdf0e10cSrcweir throw( uno::RuntimeException )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
659cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     return FilePicker_getSupportedServiceNames();
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir #pragma mark Misc/Private
665cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
666cdf0e10cSrcweir // FilePicker Event functions
667cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
668cdf0e10cSrcweir 
fileSelectionChanged(FilePickerEvent aEvent)669cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::fileSelectionChanged( FilePickerEvent aEvent )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir     OSL_TRACE( "file selection changed");
672cdf0e10cSrcweir     if (m_xListener.is())
673cdf0e10cSrcweir         m_xListener->fileSelectionChanged( aEvent );
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
directoryChanged(FilePickerEvent aEvent)676cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::directoryChanged( FilePickerEvent aEvent )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir     OSL_TRACE("directory changed");
679cdf0e10cSrcweir     if (m_xListener.is())
680cdf0e10cSrcweir         m_xListener->directoryChanged( aEvent );
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
controlStateChanged(FilePickerEvent aEvent)683cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::controlStateChanged( FilePickerEvent aEvent )
684cdf0e10cSrcweir {
685cdf0e10cSrcweir     OSL_TRACE("control state changed");
686cdf0e10cSrcweir     if (m_xListener.is())
687cdf0e10cSrcweir         m_xListener->controlStateChanged( aEvent );
688cdf0e10cSrcweir }
689cdf0e10cSrcweir 
dialogSizeChanged()690cdf0e10cSrcweir void SAL_CALL SalAquaFilePicker::dialogSizeChanged()
691cdf0e10cSrcweir {
692cdf0e10cSrcweir     OSL_TRACE("dialog size changed");
693cdf0e10cSrcweir     if (m_xListener.is())
694cdf0e10cSrcweir         m_xListener->dialogSizeChanged();
695cdf0e10cSrcweir }
696cdf0e10cSrcweir 
697cdf0e10cSrcweir //------------------------------------------------------------------------------------
698cdf0e10cSrcweir 
699cdf0e10cSrcweir #define MAP_TOGGLE( elem ) \
700cdf0e10cSrcweir case ExtendedFilePickerElementIds::CHECKBOX_##elem: \
701cdf0e10cSrcweir     pWidget = m_pToggles[elem]; \
702cdf0e10cSrcweir     break
703cdf0e10cSrcweir 
704cdf0e10cSrcweir #define MAP_BUTTON( elem ) \
705cdf0e10cSrcweir case ExtendedFilePickerElementIds::PUSHBUTTON_##elem: \
706cdf0e10cSrcweir     pWidget = m_pButtons[elem]; \
707cdf0e10cSrcweir     break
708cdf0e10cSrcweir #undef MAP_LIST
709cdf0e10cSrcweir #define MAP_LIST( elem ) \
710cdf0e10cSrcweir case ExtendedFilePickerElementIds::LISTBOX_##elem: \
711cdf0e10cSrcweir     pWidget = m_pListControls[elem]; if (isAList != NULL) *isAList = sal_True; \
712cdf0e10cSrcweir     break
713cdf0e10cSrcweir 
714cdf0e10cSrcweir #define MAP_LIST_LABEL( elem ) \
715cdf0e10cSrcweir case ExtendedFilePickerElementIds::LISTBOX_##elem##_LABEL: \
716cdf0e10cSrcweir     pWidget = m_pListControls[elem]; \
717cdf0e10cSrcweir     break
718cdf0e10cSrcweir 
719cdf0e10cSrcweir //--------------------------------------------------
720cdf0e10cSrcweir // Misc
721cdf0e10cSrcweir //-------------------------------------------------
ensureFilterHelper()722cdf0e10cSrcweir void SalAquaFilePicker::ensureFilterHelper() {
723cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
726cdf0e10cSrcweir 
727cdf0e10cSrcweir     if (NULL == m_pFilterHelper) {
728cdf0e10cSrcweir         m_pFilterHelper = new FilterHelper;
729cdf0e10cSrcweir         m_pControlHelper->setFilterHelper(m_pFilterHelper);
730cdf0e10cSrcweir         [m_pDelegate setFilterHelper:m_pFilterHelper];
731cdf0e10cSrcweir     }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
implInitialize()736cdf0e10cSrcweir void SalAquaFilePicker::implInitialize()
737cdf0e10cSrcweir {
738cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
739cdf0e10cSrcweir 
740cdf0e10cSrcweir     //call super
741cdf0e10cSrcweir     SalAquaPicker::implInitialize();
742cdf0e10cSrcweir 
743cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
updateFilterUI()746cdf0e10cSrcweir void SalAquaFilePicker::updateFilterUI() {
747cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
748cdf0e10cSrcweir 
749cdf0e10cSrcweir     m_pControlHelper->updateFilterUI();
750cdf0e10cSrcweir 
751cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
752cdf0e10cSrcweir }
753cdf0e10cSrcweir 
updateSaveFileNameExtension()754cdf0e10cSrcweir void SalAquaFilePicker::updateSaveFileNameExtension() {
755cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
756cdf0e10cSrcweir 
757cdf0e10cSrcweir     if (m_nDialogType != NAVIGATIONSERVICES_SAVE) {
758cdf0e10cSrcweir         return;
759cdf0e10cSrcweir     }
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     // we need to set this here again because initial setting does
762cdf0e10cSrcweir     //[m_pDialog setExtensionHidden:YES];
763cdf0e10cSrcweir 
764cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
765cdf0e10cSrcweir 
766cdf0e10cSrcweir     if (m_pControlHelper->isAutoExtensionEnabled() == false) {
767cdf0e10cSrcweir         OSL_TRACE("allowing other file types");
768cdf0e10cSrcweir         [m_pDialog setAllowedFileTypes:nil];
769cdf0e10cSrcweir         [m_pDialog setAllowsOtherFileTypes:YES];
770cdf0e10cSrcweir     } else {
771cdf0e10cSrcweir         ensureFilterHelper();
772cdf0e10cSrcweir 
773cdf0e10cSrcweir         OUStringList aStringList = m_pFilterHelper->getCurrentFilterSuffixList();
774cdf0e10cSrcweir         if( aStringList.empty()) // #i9328#
775cdf0e10cSrcweir             return;
776cdf0e10cSrcweir 
777cdf0e10cSrcweir         rtl::OUString suffix = (*(aStringList.begin())).copy(1);
778cdf0e10cSrcweir         NSString *requiredFileType = [NSString stringWithOUString:suffix];
779cdf0e10cSrcweir 
780cdf0e10cSrcweir         [m_pDialog setRequiredFileType:requiredFileType];
781cdf0e10cSrcweir 
782cdf0e10cSrcweir         OSL_TRACE("disallowing other file types");
783cdf0e10cSrcweir         [m_pDialog setAllowsOtherFileTypes:NO];
784cdf0e10cSrcweir     }
785cdf0e10cSrcweir 
786cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
filterControlChanged()789cdf0e10cSrcweir void SalAquaFilePicker::filterControlChanged() {
790cdf0e10cSrcweir     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
791cdf0e10cSrcweir 
792cdf0e10cSrcweir     if (m_pDialog == nil) {
793cdf0e10cSrcweir         return;
794cdf0e10cSrcweir     }
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
797cdf0e10cSrcweir 
798cdf0e10cSrcweir     updateSaveFileNameExtension();
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     [m_pDialog validateVisibleColumns];
801cdf0e10cSrcweir 
802cdf0e10cSrcweir     FilePickerEvent evt;
803cdf0e10cSrcweir     evt.ElementId = LISTBOX_FILTER;
804cdf0e10cSrcweir     controlStateChanged( evt );
805cdf0e10cSrcweir 
806cdf0e10cSrcweir     DBG_PRINT_EXIT(CLASS_NAME, __func__);
807cdf0e10cSrcweir }
808cdf0e10cSrcweir 
809