update ooo310-m15
[ooovba.git] / fpicker / source / aqua / SalAquaPicker.cxx
blob0324a8de114b3f885df3e68ba1674b111c345b76
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SalAquaPicker.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <cppuhelper/interfacecontainer.h>
38 #include <osl/diagnose.h>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <FPServiceInfo.hxx>
41 #include <vos/mutex.hxx>
42 #include <vcl/svapp.hxx>
43 #ifndef _SALAQUAPICKER_HXX_
44 #include "SalAquaPicker.hxx"
45 #endif
46 #include <tools/urlobj.hxx>
47 #include <osl/file.hxx>
48 #include "CFStringUtilities.hxx"
49 #include "NSString_OOoAdditions.hxx"
51 #include "SalAquaFilePicker.hxx"
53 #include <stdio.h>
55 #pragma mark DEFINES
56 #define CLASS_NAME "SalAquaPicker"
58 //------------------------------------------------------------------------
59 // namespace directives
60 //------------------------------------------------------------------------
62 using namespace ::rtl;
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::uno;
67 // constructor
68 SalAquaPicker::SalAquaPicker()
69 : m_pDialog(NULL)
70 , m_pControlHelper(new ControlHelper())
72 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
73 DBG_PRINT_EXIT(CLASS_NAME, __func__);
76 SalAquaPicker::~SalAquaPicker()
78 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
80 ::vos::OGuard aGuard( Application::GetSolarMutex() );
82 NSAutoreleasePool *pool = [NSAutoreleasePool new];
84 if (NULL != m_pControlHelper)
85 delete m_pControlHelper;
87 if (NULL != m_pDialog)
88 [m_pDialog release];
90 [pool release];
92 DBG_PRINT_EXIT(CLASS_NAME, __func__);
95 void SAL_CALL SalAquaPicker::implInitialize()
97 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
99 ::vos::OGuard aGuard( Application::GetSolarMutex() );
101 if (m_pDialog != nil) {
102 return;
105 switch (m_nDialogType)
107 case NAVIGATIONSERVICES_OPEN:
108 OSL_TRACE("NAVIGATIONSERVICES_OPEN");
109 m_pDialog = [NSOpenPanel openPanel];
110 [(NSOpenPanel*)m_pDialog setCanChooseDirectories:NO];
111 [(NSOpenPanel*)m_pDialog setCanChooseFiles:YES];
112 break;
114 case NAVIGATIONSERVICES_SAVE:
115 OSL_TRACE("NAVIGATIONSERVICES_SAVE");
116 m_pDialog = [NSSavePanel savePanel];
117 [(NSSavePanel*)m_pDialog setCanSelectHiddenExtension:YES];
118 [(NSSavePanel*)m_pDialog setExtensionHidden:NO];
119 break;
121 case NAVIGATIONSERVICES_DIRECTORY:
122 OSL_TRACE("NAVIGATIONSERVICES_DIRECTORY");
123 m_pDialog = [NSOpenPanel openPanel];
124 [(NSOpenPanel*)m_pDialog setCanChooseDirectories:YES];
125 [(NSOpenPanel*)m_pDialog setCanChooseFiles:NO];
126 break;
128 default:
129 OSL_TRACE("m_nDialogType is UNKNOWN: %d", m_nDialogType);
130 break;
133 if (m_pDialog == nil) {
134 OSL_TRACE("An error occurred while creating the dialog!");
136 else {
137 [(NSOpenPanel*)m_pDialog setCanCreateDirectories:YES];
138 //Retain the dialog instance or it will go away immediately
139 [m_pDialog retain];
142 DBG_PRINT_EXIT(CLASS_NAME, __func__);
145 int SalAquaPicker::run()
147 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
149 ::vos::OGuard aGuard( Application::GetSolarMutex() );
151 NSAutoreleasePool *pool = [NSAutoreleasePool new];
153 if (m_pDialog == NULL) {
154 //this is the case e.g. for the folder picker at this stage
155 implInitialize();
158 NSView *userPane = m_pControlHelper->getUserPane();
159 if (userPane != NULL) {
160 [m_pDialog setAccessoryView:userPane];
163 int retVal = 0;
165 NSString *startDirectory;
166 if (m_sDisplayDirectory.getLength() > 0) {
167 NSString *temp = [NSString stringWithOUString:m_sDisplayDirectory];
168 NSURL *url = [NSURL URLWithString:temp];
169 startDirectory = [url path];
171 OSL_TRACE("start dir: %s", [startDirectory UTF8String]);
172 // NSLog(@"%@", startDirectory);
174 else {
175 startDirectory = NSHomeDirectory();
178 switch(m_nDialogType) {
179 case NAVIGATIONSERVICES_DIRECTORY:
180 case NAVIGATIONSERVICES_OPEN:
181 retVal = [(NSOpenPanel*)m_pDialog runModalForDirectory:startDirectory file:nil types:nil];
182 break;
183 case NAVIGATIONSERVICES_SAVE:
184 retVal = [m_pDialog runModalForDirectory:startDirectory file:[NSString stringWithOUString:((SalAquaFilePicker*)this)->getSaveFileName()]/*[m_pDialog saveFilename]*/];
185 break;
186 // [m_pDialog beginSheetForDirectory:startDirectory file:[m_pDialog saveFilename] modalForWindow:[NSApp keyWindow] modalDelegate:((SalAquaFilePicker*)this)->getDelegate() didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
187 default:
188 break;
192 DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
194 [pool release];
196 return retVal;
199 int SalAquaPicker::runandwaitforresult()
201 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
203 ::vos::OGuard aGuard( Application::GetSolarMutex() );
205 int status = this->run();
207 DBG_PRINT_EXIT(CLASS_NAME, __func__, status);
208 return status;
211 void SAL_CALL SalAquaPicker::implsetDisplayDirectory( const rtl::OUString& aDirectory )
212 throw( lang::IllegalArgumentException, uno::RuntimeException )
214 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory);
216 ::vos::OGuard aGuard( Application::GetSolarMutex() );
218 if (aDirectory != m_sDisplayDirectory) {
219 m_sDisplayDirectory = aDirectory;
221 if (m_pDialog != nil) {
222 //NSLog(@"would change now to:%@", [NSString stringWithOUString:aDirectory]);
223 // [m_pDialog setDirectory:[NSString stringWithOUString:aDirectory]];
227 DBG_PRINT_EXIT(CLASS_NAME, __func__);
230 rtl::OUString SAL_CALL SalAquaPicker::implgetDisplayDirectory() throw( uno::RuntimeException )
232 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
233 DBG_PRINT_EXIT(CLASS_NAME, __func__, m_sDisplayDirectory);
235 return m_sDisplayDirectory;
238 void SAL_CALL SalAquaPicker::implsetTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
240 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
242 ::vos::OGuard aGuard( Application::GetSolarMutex() );
244 if (m_pDialog != nil) {
245 [m_pDialog setTitle:[NSString stringWithOUString:aTitle]];
248 DBG_PRINT_EXIT(CLASS_NAME, __func__);