1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/lang/DisposedException.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
23 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
25 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
26 #include <cppuhelper/interfacecontainer.h>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <osl/diagnose.h>
29 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <FPServiceInfo.hxx>
32 #include <osl/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include "SalAquaFolderPicker.hxx"
38 #include "resourceprovider.hxx"
40 #include <osl/file.hxx>
41 #include "CFStringUtilities.hxx"
42 #include "NSString_OOoAdditions.hxx"
43 #include "NSURL_OOoAdditions.hxx"
46 #define CLASS_NAME "SalAquaFolderPicker"
49 // namespace directives
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::ui::dialogs;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::uno;
63 // controlling event notifications
64 uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames()
66 uno::Sequence<rtl::OUString> aRet(2);
67 aRet[0] = "com.sun.star.ui.dialogs.SystemFolderPicker";
68 aRet[1] = "com.sun.star.ui.dialogs.AquaFolderPicker";
76 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
77 m_xServiceMgr( xServiceMgr )
79 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
81 m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
83 DBG_PRINT_EXIT(CLASS_NAME, __func__);
87 // XExecutableDialog functions
90 void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
92 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
94 SolarMutexGuard aGuard;
98 DBG_PRINT_EXIT(CLASS_NAME, __func__);
101 sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException )
103 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
105 SolarMutexGuard aGuard;
107 sal_Int16 retVal = 0;
109 int nResult = runandwaitforresult();
113 #if MACOSX_SDK_VERSION >= 101000
114 case NSModalResponseOK:
118 OSL_TRACE("Dialog returned with OK");
119 retVal = ExecutableDialogResults::OK;
122 #if MACOSX_SDK_VERSION >= 101000
123 case NSModalResponseCancel:
127 OSL_TRACE("Dialog was cancelled!");
128 retVal = ExecutableDialogResults::CANCEL;
132 throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
136 DBG_PRINT_EXIT(CLASS_NAME, __func__);
141 // XFolderPicker functions
144 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
145 throw( lang::IllegalArgumentException, uno::RuntimeException )
147 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory);
149 SolarMutexGuard aGuard;
151 implsetDisplayDirectory(aDirectory);
153 DBG_PRINT_EXIT(CLASS_NAME, __func__);
156 rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
158 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
160 SolarMutexGuard aGuard;
162 OUString aDirectory = implgetDisplayDirectory();
164 DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory);
169 rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException )
171 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
173 SolarMutexGuard aGuard;
175 NSArray *files = nil;
176 if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
177 files = [(NSOpenPanel*)m_pDialog URLs];
180 long nFiles = [files count];
181 SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
184 throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
187 rtl::OUString aDirectory;
189 NSURL *url = [files objectAtIndex:0];
190 OSL_TRACE("handling %s", [[url description] UTF8String]);
192 aDirectory = [url OUStringForInfo:FULLPATH];
194 implsetDisplayDirectory(aDirectory);
196 OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr());
198 DBG_PRINT_EXIT(CLASS_NAME, __func__);
202 void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription )
203 throw( uno::RuntimeException )
205 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription);
207 [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
209 DBG_PRINT_EXIT(CLASS_NAME, __func__);
216 rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
217 throw( uno::RuntimeException )
219 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
221 rtl::OUString retVal( FOLDER_PICKER_IMPL_NAME );
223 DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
228 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName )
229 throw( uno::RuntimeException )
231 return cppu::supportsService(this, sServiceName);
234 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
235 throw( uno::RuntimeException )
237 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
238 DBG_PRINT_EXIT(CLASS_NAME, __func__);
240 return FolderPicker_getSupportedServiceNames();
247 void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException )
249 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
251 SolarMutexGuard aGuard;
253 [m_pDialog cancel:nil];
255 DBG_PRINT_EXIT(CLASS_NAME, __func__);
262 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
263 throw( uno::RuntimeException )
265 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
266 DBG_PRINT_EXIT(CLASS_NAME, __func__);
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */