/************************************************************************* * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: SalAquaPicker.cxx,v $ * * $Revision: 1.12 $ * * last change: $Author: vg $ $Date: 2006/08/07 13:59:37 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. * * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2005 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * ************************************************************************/ //------------------------------------------------------------------------ // includes //------------------------------------------------------------------------ #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include #endif #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include #endif #ifndef _CPPUHELPER_INTERFACECONTAINER_H_ #include #endif #ifndef _OSL_DIAGNOSE_H_ #include #endif #ifndef _COM_SUN_STAR_UNO_ANY_HXX_ #include #endif #ifndef _FPSERVICEINFO_HXX_ #include #endif #ifndef _VOS_MUTEX_HXX_ #include #endif #ifndef _SV_SVAPP_HXX #include #endif #ifndef _SALAQUAPICKER_HXX_ #include "SalAquaPicker.hxx" #endif #ifndef _URLOBJ_HXX #include #endif #ifndef _OSL_FILE_HXX_ #include #endif #include //------------------------------------------------------------------------ // namespace directives //------------------------------------------------------------------------ using namespace ::rtl; using namespace ::com::sun::star; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; void eventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *callBackUserData) { NavReplyRecord reply; NavUserAction userAction = 0; SalAquaPicker *pSalAquaPicker = (SalAquaPicker *) callBackUserData; switch (callBackSelector) { // We are ignoring several callbackSelectors here... case kNavCBEvent: // fprintf(stderr, "PJ: callBackSelector = kNavCBCEvent\n"); break; case kNavCBCustomize: // fprintf(stderr, "PJ: callBackSelector = kNavCBCustomize\n"); break; case kNavCBStart: fprintf(stderr, "PJ: callBackSelector = kNavCBStart\n"); if (pSalAquaPicker->m_sDisplayDirectory) { // Setting the default location of the dialog... // http://developer.apple.com/qa/qa2001/qa1151.html fprintf(stderr, "PJ: setting the default location of the dialog...\n"); OSStatus status; AEDesc location = {typeNull, NULL}; FSRef theFSRef; ::rtl::OUString aDirectory; char *path; osl::FileBase::getSystemPathFromFileURL(pSalAquaPicker->m_sDisplayDirectory, aDirectory); path = ::rtl::OUStringToOString (aDirectory, RTL_TEXTENCODING_UTF8).pData->buffer; status = FSPathMakeRef ( (UInt8 *) path, &theFSRef, NULL); AECreateDesc(typeFSRef, &theFSRef, sizeof(FSRef), &location); status = NavCustomControl(pSalAquaPicker->m_pDialog, kNavCtlSetLocation, (void*) &location); } break; case kNavCBAdjustRect: fprintf(stderr, "PJ: callBackSelector = kNavCBAdjustRect\n"); break; case kNavCBNewLocation: fprintf(stderr, "PJ: callBackSelector = kNavCBNewLocation\n"); break; case kNavCBAccept: fprintf(stderr, "PJ: callBackSelector = kNavCBAccept\n"); break; case kNavCBCancel: fprintf(stderr, "PJ: callBackSelector = kNavCBCancel\n"); break; case kNavCBAdjustPreview: fprintf(stderr, "PJ: callBackSelector = kNavCBAdjustPreview\n"); break; case kNavCBUserAction: fprintf(stderr, "PJ: callBackSelector = kNavCBUserAction\n"); // if (NavDialogGetReply (callBackParms->context, &reply) == noErr ) // { // userAction = NavDialogGetUserAction (callBackParms->context); // switch (userAction) { // case kNavUserActionSaveAs: // fprintf (stderr, "PJ: userAction = knavUserActionSaveAs\n"); // break; // case kNavUserActionOpen: // fprintf (stderr, "PJ: userAction = knavUserActionOpen\n"); // break; // case kNavUserActionCancel: // fprintf (stderr, "PJ: userAction = knavUserActionCancel\n"); // break; // case kNavUserActionNewFolder: // fprintf (stderr, "PJ: userAction = knavUserActionNewFolder\n"); // break; // default: // fprintf (stderr, "PJ: userAction is UNKNOWN %d\n", userAction); // break; // } // NavDisposeReply (&reply); // } break; case kNavCBTerminate: fprintf(stderr, "PJ: callBackSelector = kNavCBTerminate\n"); break; case kNavCBSelectEntry: fprintf(stderr, "PJ: callBackSelector = kNavCBSelectEntry\n"); break; case kNavCBOpenSelection: fprintf(stderr, "PJ: callBackSelector = kNavCBOpenSelection\n"); break; default: fprintf(stderr, "PJ: callBackSelector = %d\n", callBackSelector); break; } // fprintf(stderr, "PJ: callBackParms->userAction = %d\n", callBackParms->userAction); } void SalAquaPicker::run() { fprintf(stderr, "PJ: >>>> SalAquaPicker::run\n"); NavEventUPP pNavEventHandlerPtr = NewNavEventUPP( eventHandler ); m_pDialogOptions.modality = kWindowModalityAppModal; // Create the corresponding dialog // pass the pointer to SalAquaPicker as an userData switch (m_nDialogType) { case NAVIGATIONSERVICES_OPEN: fprintf(stderr, "PJ: NAVIGATIONSERVICES_OPEN\n"); NavCreateGetFileDialog (&m_pDialogOptions, NULL, pNavEventHandlerPtr, NULL, NULL, (void *) this, &m_pDialog); break; case NAVIGATIONSERVICES_SAVE: fprintf(stderr, "PJ: NAVIGATIONSERVICES_SAVE\n"); NavCreatePutFileDialog (&m_pDialogOptions, kUnknownType, kUnknownType, pNavEventHandlerPtr, (void *) this, &m_pDialog); break; case NAVIGATIONSERVICES_DIRECTORY: fprintf(stderr, "PJ: NAVIGATIONSERVICES_DIRECTORY\n"); NavCreateChooseFolderDialog (&m_pDialogOptions, pNavEventHandlerPtr, NULL, (void *) this, &m_pDialog); break; default: fprintf(stderr, "PJ: m_nDialogType is UNKNOWN: %d\n", m_nDialogType); // FIXME exit(-1); } fprintf(stderr, "PJ: m_pDialog created is %p\n", m_pDialog); // ? // Application::Yield(); fprintf(stderr, "PJ: SalAquaPicker::run - before NavDialogRun\n"); NavDialogRun (m_pDialog); fprintf(stderr, "PJ: SalAquaPicker::run - after NavDialogRun\n"); // mnStatus = gtk_dialog_run( GTK_DIALOG( m_pDialog ) ); // gtk_widget_hide( m_pDialog ); // maLock.acquire(); // mbFinished = true; // maLock.release(); // Application::EndYield(); fprintf(stderr, "PJ: <<<< SalAquaPicker::run\n"); } OSStatus SalAquaPicker::runandwaitforresult() { fprintf(stderr, "PJ: >>>> SalAquaPicker::runandwaitforresult\n"); // while (1) // { // maLock.acquire(); // if (mbFinished) // break; // maLock.release(); // Application::Yield(); // } // return mnStatus; this->run(); OSStatus status = NavDialogGetReply (m_pDialog, &m_pReplyRecord); fprintf(stderr, "PJ: <<<< SalAquaPicker::runandwaitforresult\n"); return status; } // constructor SalAquaPicker::SalAquaPicker() { fprintf(stderr, "PJ: constructor of SalAquaPicker\n"); m_pDialog = NULL; // set the standard set of dialog options OSStatus status = NavGetDefaultDialogCreationOptions(&m_pDialogOptions); fprintf(stderr, "PJ: leaving constructor of SalAquaPicker\n"); } SalAquaPicker::~SalAquaPicker() { fprintf(stderr, "PJ: destructor of SalAquaPicker\n"); if (m_pDialog) NavDialogDispose (m_pDialog); fprintf(stderr, "PJ: leaving destructor of SalAquaPicker\n"); } void SAL_CALL SalAquaPicker::implsetDisplayDirectory( const rtl::OUString& aDirectory ) throw( lang::IllegalArgumentException, uno::RuntimeException ) { ::rtl::OString aString = OUStringToOString( aDirectory, RTL_TEXTENCODING_UTF8 ); fprintf(stderr, "PJ: >>>> SalAquaPicker::implsetDisplayDirectory (aDirectory = %s)\n", aString.getStr()); m_sDisplayDirectory = rtl::OUString (aDirectory); fprintf(stderr, "PJ: <<<< SalAquaPicker::implsetDisplayDirectory\n"); } rtl::OUString SAL_CALL SalAquaPicker::implgetDisplayDirectory() throw( uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaPicker::implgetDisplayDirectory\n"); // OSL_ASSERT( m_pDialog != NULL ); // ::vos::OGuard aGuard( Application::GetSolarMutex() ); // gchar* pCurrentFolder = // gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) ); // ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder); // g_free( pCurrentFolder ); // return aCurrentFolderName; // FIXME OUString m_sDisplayDirectory = OUString::createFromAscii("/tmp"); OUString displayDirectoryURL; if ( m_sDisplayDirectory.getLength() ) { fprintf(stderr, "PJ: here 1\n"); fprintf(stderr, "PJ: returncode = %d\n", ::osl::FileBase::getFileURLFromSystemPath( m_sDisplayDirectory, displayDirectoryURL )); } fprintf(stderr, "PJ: here 2, returning: %s\n", rtl::OUStringToOString( displayDirectoryURL, RTL_TEXTENCODING_ASCII_US ).getStr()); fprintf(stderr, "PJ: >>>> SalAquaPicker::implgetDisplayDirectory\n"); return OUString(displayDirectoryURL); // rtl::OUString tmp = OUString::createFromAscii("nejakacesta"); // return tmp; //m_sDisplayDirectory; } void SAL_CALL SalAquaPicker::implsetTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaPicker::implsetTitle (aTitle = %s)\n", aTitle.getStr()); // OSL_ASSERT( m_pDialog != NULL ); ::vos::OGuard aGuard( Application::GetSolarMutex() ); ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ); m_pDialogOptions.windowTitle = CFStringCreateWithCString ( NULL, aWindowTitle.getStr(), kCFStringEncodingUTF8); // gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() ); fprintf(stderr, "PJ: <<<< SalAquaPicker::implsetTitle (aTitle = %s)\n", aTitle.getStr()); }