/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "SalAquaFolderPicker.hxx" #include #include "resourceprovider.hxx" #include #include "CFStringUtilities.hxx" #include "NSString_OOoAdditions.hxx" #include "NSURL_OOoAdditions.hxx" #pragma mark DEFINES #define CLASS_NAME "SalAquaFolderPicker" // namespace directives using namespace ::com::sun::star; using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; // helper functions namespace { // controlling event notifications uno::Sequence SAL_CALL FolderPicker_getSupportedServiceNames() { uno::Sequence aRet(2); aRet[0] = "com.sun.star.ui.dialogs.SystemFolderPicker"; aRet[1] = "com.sun.star.ui.dialogs.AquaFolderPicker"; return aRet; } } // constructor SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference& xServiceMgr ) : m_xServiceMgr( xServiceMgr ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); m_nDialogType = NAVIGATIONSERVICES_DIRECTORY; DBG_PRINT_EXIT(CLASS_NAME, __func__); } // XExecutableDialog functions void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle); SolarMutexGuard aGuard; implsetTitle(aTitle); DBG_PRINT_EXIT(CLASS_NAME, __func__); } sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); SolarMutexGuard aGuard; sal_Int16 retVal = 0; int nResult = runandwaitforresult(); switch( nResult ) { #if MACOSX_SDK_VERSION >= 101000 case NSModalResponseOK: #else case NSOKButton: #endif OSL_TRACE("Dialog returned with OK"); retVal = ExecutableDialogResults::OK; break; #if MACOSX_SDK_VERSION >= 101000 case NSModalResponseCancel: #else case NSCancelButton: #endif OSL_TRACE("Dialog was cancelled!"); retVal = ExecutableDialogResults::CANCEL; break; default: throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this )); break; } DBG_PRINT_EXIT(CLASS_NAME, __func__); return retVal; } // XFolderPicker functions void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory ) throw( lang::IllegalArgumentException, uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory); SolarMutexGuard aGuard; implsetDisplayDirectory(aDirectory); DBG_PRINT_EXIT(CLASS_NAME, __func__); } rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); SolarMutexGuard aGuard; OUString aDirectory = implgetDisplayDirectory(); DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory); return aDirectory; } rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); SolarMutexGuard aGuard; NSArray *files = nil; if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) { files = [(NSOpenPanel*)m_pDialog URLs]; } long nFiles = [files count]; OSL_TRACE("# of items: %d", nFiles); if (nFiles < 1) { throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this )); } rtl::OUString aDirectory; NSURL *url = [files objectAtIndex:0]; OSL_TRACE("handling %s", [[url description] UTF8String]); aDirectory = [url OUStringForInfo:FULLPATH]; implsetDisplayDirectory(aDirectory); OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr()); DBG_PRINT_EXIT(CLASS_NAME, __func__); return aDirectory; } void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription ) throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription); [m_pDialog setMessage:[NSString stringWithOUString:rDescription]]; DBG_PRINT_EXIT(CLASS_NAME, __func__); } // XServiceInfo rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); rtl::OUString retVal( FOLDER_PICKER_IMPL_NAME ); DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal); return retVal; } sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName ) throw( uno::RuntimeException ) { return cppu::supportsService(this, sServiceName); } uno::Sequence SAL_CALL SalAquaFolderPicker::getSupportedServiceNames() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); DBG_PRINT_EXIT(CLASS_NAME, __func__); return FolderPicker_getSupportedServiceNames(); } // XCancellable void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); SolarMutexGuard aGuard; [m_pDialog cancel:nil]; DBG_PRINT_EXIT(CLASS_NAME, __func__); } // XEventListener void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& ) throw( uno::RuntimeException ) { DBG_PRINT_ENTRY(CLASS_NAME, __func__); DBG_PRINT_EXIT(CLASS_NAME, __func__); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */