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