diff options
author | Rüdiger Timm <rt@openoffice.org> | 2007-07-05 09:02:46 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2007-07-05 09:02:46 +0000 |
commit | c6b25375522ce9367a02f4a5e5a2635341d3ac89 (patch) | |
tree | caa5a04c66c5ec7f7f3613b485c89ee26ade3281 /vcl | |
parent | 05b4f9b19c5ff6e383b964e58a43eb0f13ad34ca (diff) |
INTEGRATION: CWS aquavcl01 (1.33.110); FILE MERGED
2007/06/28 16:00:52 pl 1.33.110.27: #i77562# improvements from code review session
2007/06/28 08:08:55 hdu 1.33.110.26: #i78924# implement bHandleAllCurrentEvents mode for AquaSalInstance::Yield() and ignore obsoleted timer events
2007/06/27 18:01:40 pl 1.33.110.25: #i77562# initial print implementation
2007/06/20 19:00:27 pl 1.33.110.24: #i78510# enable native focus markers for selected controls
2007/06/18 12:43:14 pl 1.33.110.23: #i78600# change AQUA_LOG default behaviour
2007/06/05 13:23:08 pl 1.33.110.22: CFString <-> OUString conversion
2007/05/24 06:42:00 pjanik 1.33.110.21: Rename AQUALOG to AQUA_LOG to unify with the rest of AQUA_ env. variables.
2007/05/23 13:21:42 pl 1.33.110.20: more convenient logging
2007/05/14 11:39:42 pl 1.33.110.19: protect against dispatching to dead or dying AquaSalFrames
2007/04/25 08:49:13 thb 1.33.110.18: Fixed serious error in UniString constructor, 2nd parameter is encoding, not text len
2007/03/08 08:38:28 pjanik 1.33.110.17: Remove VCLApplication_Run. Clean some warnings.
2006/12/30 19:29:57 pjanik 1.33.110.16: #i72385#: Add Quartz/AQUA specific parts.
2006/10/13 21:54:14 tra 1.33.110.15: RESYNC: (1.33-1.34); FILE MERGED
2006/08/14 21:15:11 cl 1.33.110.14: added basic QUARTZ bitmap support
2006/08/07 18:47:43 pjanik 1.33.110.13: Move native menu related function to separate file.
2006/07/19 10:21:46 pjanik 1.33.110.12: #i10000#: Change the prototype of Yield to reflect the changes done in
SRC680_m176.
2006/04/27 20:47:02 tra 1.33.110.11: *** empty log message ***
2006/03/09 08:04:46 ssa 1.33.110.10: solar mutex test, it is unclear if it should guard all messages or only those processed by vcl, thus the comments...
2006/03/08 21:35:53 tra 1.33.110.9: catch excpetion in case native window creation failes
2006/03/02 00:31:03 ssa 1.33.110.8: provide AquaSalTimer and solar mutex helper
2006/02/27 20:27:55 tra 1.33.110.7: *** empty log message ***
2006/02/19 21:02:32 tra 1.33.110.6: some cleanup
2006/02/18 14:13:33 tra 1.33.110.5: *** empty log message ***
2006/02/16 21:36:34 fheckl 1.33.110.4: Removing Cocoa code and replacing most of it with Carbon calls
2006/01/31 01:14:16 fheckl 1.33.110.3: *** empty log message ***
2005/11/30 00:04:17 fheckl 1.33.110.2: Changing my fixed-path hack to a more normal solution but I am still not sure if we need this whole part anyway
2005/11/27 09:48:33 fheckl 1.33.110.1: Integrating aqua changes for OOo 2.0
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/aqua/source/app/salinst.cxx | 590 |
1 files changed, 428 insertions, 162 deletions
diff --git a/vcl/aqua/source/app/salinst.cxx b/vcl/aqua/source/app/salinst.cxx index 8da7b9718ec5..bed6061830ff 100644 --- a/vcl/aqua/source/app/salinst.cxx +++ b/vcl/aqua/source/app/salinst.cxx @@ -4,9 +4,9 @@ * * $RCSfile: salinst.cxx,v $ * - * $Revision: 1.35 $ + * $Revision: 1.36 $ * - * last change: $Author: hr $ $Date: 2007-06-27 19:51:24 $ + * last change: $Author: rt $ $Date: 2007-07-05 10:02:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -44,41 +44,74 @@ #ifndef _SV_SALINST_HXX #include <vcl/salinst.hxx> #endif -#ifndef _SV_SALFRAME_HXX -#include <vcl/salframe.hxx> +#ifndef _SV_SALINST_H +#include <vcl/salinst.h> +#endif +#ifndef _SV_SALFRAME_H +#include <vcl/salframe.h> #endif #ifndef _SV_SALOBJ_HXX #include <vcl/salobj.hxx> #endif +#include <salobj.h> +#ifndef _SV_SALOBJ_H +#include <salobj.h> +#endif #ifndef _SV_SALSYS_HXX #include <vcl/salsys.hxx> #endif +#ifndef _SV_SALSYS_H +#include <salsys.h> +#endif #ifndef _SV_SALVD_HXX #include <vcl/salvd.hxx> #endif +#ifndef _SV_SALVD_H +#include <salvd.h> +#endif #ifndef _SV_DIALOG_HXX #include <vcl/dialog.hxx> #endif -#ifndef _SV_VCLAPPLICATION_H -#include <VCLApplication.h> -#endif -#ifndef _SV_VCLAUTORELEASEPOOL_H -#include <VCLAutoreleasePool.h> -#endif #ifndef _FSYS_HXX #include <tools/fsys.hxx> #endif +#ifndef _SV_SALIMESTATUS_HXX +#include <salimestatus.hxx> +#endif + +#include <salprn.h> +#include <print.h> + +#include <salogl.h> +#include <saltimer.h> + +#include <osl/process.h> -static VCLAUTORELEASEPOOL hMainAutoreleasePool = NULL; +#include <aquavclevents.hxx> + +using namespace std; + +FILE* SalData::s_pLog = NULL; + +void AquaLog( const char* pFormat, ... ) +{ + if( ! SalData::s_pLog ) + return; + + va_list ap; + va_start( ap, pFormat ); + vfprintf( SalData::s_pLog, pFormat, ap ); + va_end( ap ); +} // ======================================================================= void SalAbort( const XubString& rErrorText ) { if( !rErrorText.Len() ) - fprintf( stderr, "Application Error " ); + AquaLog( "Application Error " ); else - fprintf( stderr, "%s ", + AquaLog( "%s ", ByteString( rErrorText, gsl_getSystemTextEncoding() ).GetBuffer() ); abort(); } @@ -88,12 +121,19 @@ void SalAbort( const XubString& rErrorText ) void InitSalData() { SalData *pSalData = new SalData; - memset( pSalData, 0, sizeof( SalData ) ); SetSalData( pSalData ); } // ----------------------------------------------------------------------- +const ::rtl::OUString& SalGetDesktopEnvironment() +{ + static OUString aDesktopEnvironment(RTL_CONSTASCII_USTRINGPARAM( "MacOSX" )); + return aDesktopEnvironment; +} + +// ----------------------------------------------------------------------- + void DeInitSalData() { SalData *pSalData = GetSalData(); @@ -111,80 +151,59 @@ extern "C" { void InitSalMain() { - // [ed] 5/14/02 We need to use _NSGetEnviron() here and can't use the straight - // environ. This is due to two-level-namespaces not enjoying having funky - // global hack symbols lying around. -#ifdef QUARTZ - char **environ; - char *stackNULL=NULL; - if(_NSGetEnviron()) - environ=*_NSGetEnviron(); - else - environ=&stackNULL; -#else - extern char **environ; -#endif + rtl_uString *urlWorkDir = NULL; + rtl_uString *sysWorkDir = NULL; - char **pEnviron; - - // Get full executable path. We cna't use __progname as that only holds - // the name of the executable and not the path. The full executable path - // is listed after the first NULL in *environ. - pEnviron = environ; - while ( *pEnviron++ ) - ; - - // Need to include the absolute path for this executable in the PATH - // and STAR_RESOURCEPATH environment variables so that the resource manager - // can find resource files and in the DYLD_LIBRARY_PATH environment - // variable so that the dynamic library loader can find shared libraries - ByteString aPath( getenv( "PATH" ) ); - ByteString aResPath( getenv( "STAR_RESOURCEPATH" ) ); - ByteString aLibPath( getenv( "DYLD_LIBRARY_PATH" ) ); - ByteString aCmdPath( *pEnviron ); - ByteString aTmpPath; - // Get absolute path of command's directory - if ( aCmdPath.Len() ) { - DirEntry aCmdDirEntry( aCmdPath ); - aCmdDirEntry.ToAbs(); - aCmdPath = ByteString( aCmdDirEntry.GetPath().GetFull(), RTL_TEXTENCODING_ASCII_US ); - } - // Assign to PATH environment variable - if ( aCmdPath.Len() ) - { - aTmpPath = ByteString( "PATH=" ); - aTmpPath += aCmdPath; - if ( aPath.Len() ) - aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); - aTmpPath += aPath; - putenv( aTmpPath.GetBuffer() ); - } - // Assign to STAR_RESOURCEPATH environment variable - if ( aCmdPath.Len() ) - { - aTmpPath = ByteString( "STAR_RESOURCEPATH=" ); - aTmpPath += aCmdPath; - if ( aResPath.Len() ) - aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); - aTmpPath += aResPath; - putenv( aTmpPath.GetBuffer() ); - } - // Assign to DYLD_LIBRARY_PATH environment variable - if ( aCmdPath.Len() ) + oslProcessError err1 = osl_getProcessWorkingDir(&urlWorkDir); + + if (err1 == osl_Process_E_None) { - aTmpPath = ByteString( "DYLD_LIBRARY_PATH=" ); - aTmpPath += aCmdPath; - if ( aLibPath.Len() ) - aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); - aTmpPath += aLibPath; - putenv( aTmpPath.GetBuffer() ); + oslFileError err2 = osl_getSystemPathFromFileURL(urlWorkDir, &sysWorkDir); + if (err2 == osl_File_E_None) + { + ByteString aPath( getenv( "PATH" ) ); + ByteString aResPath( getenv( "STAR_RESOURCEPATH" ) ); + ByteString aLibPath( getenv( "DYLD_LIBRARY_PATH" ) ); + ByteString aCmdPath( OUStringToOString(OUString(sysWorkDir), RTL_TEXTENCODING_UTF8).getStr() ); + ByteString aTmpPath; + // Get absolute path of command's directory + if ( aCmdPath.Len() ) { + DirEntry aCmdDirEntry( aCmdPath ); + aCmdDirEntry.ToAbs(); + aCmdPath = ByteString( aCmdDirEntry.GetPath().GetFull(), RTL_TEXTENCODING_ASCII_US ); + } + // Assign to PATH environment variable + if ( aCmdPath.Len() ) + { + aTmpPath = ByteString( "PATH=" ); + aTmpPath += aCmdPath; + if ( aPath.Len() ) + aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); + aTmpPath += aPath; + putenv( (char*)aTmpPath.GetBuffer() ); + } + // Assign to STAR_RESOURCEPATH environment variable + if ( aCmdPath.Len() ) + { + aTmpPath = ByteString( "STAR_RESOURCEPATH=" ); + aTmpPath += aCmdPath; + if ( aResPath.Len() ) + aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); + aTmpPath += aResPath; + putenv( (char*)aTmpPath.GetBuffer() ); + } + // Assign to DYLD_LIBRARY_PATH environment variable + if ( aCmdPath.Len() ) + { + aTmpPath = ByteString( "DYLD_LIBRARY_PATH=" ); + aTmpPath += aCmdPath; + if ( aLibPath.Len() ) + aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US ); + aTmpPath += aLibPath; + putenv( (char*)aTmpPath.GetBuffer() ); + } + } } - - // Setup up autorelease pool for Objective-C objects - hMainAutoreleasePool = VCLAutoreleasePool_Init(); - - // Initialize application's connection to the window server - VCLApplication_SharedApplication(); } // ----------------------------------------------------------------------- @@ -192,7 +211,7 @@ void InitSalMain() void DeInitSalMain() { // Release autorelease pool - VCLAutoreleasePool_Release( hMainAutoreleasePool ); + //VCLAutoreleasePool_Release( hMainAutoreleasePool ); } @@ -200,9 +219,9 @@ void DeInitSalMain() void SetFilterCallback( void* pCallback, void* pInst ) { - SalData *pSalData = GetSalData(); - pSalData->mpFirstInstance->maInstData.mpFilterCallback = pCallback; - pSalData->mpFirstInstance->maInstData.mpFilterInst = pInst; + // SalData *pSalData = GetSalData(); + //[fheckl]pSalData->mpFirstInstance->mpFilterCallback = pCallback; + //[fheckl]pSalData->mpFirstInstance->mpFilterInst = pInst; } // ======================================================================= @@ -237,23 +256,66 @@ sal_Bool SalYieldMutex::tryToAcquire() { mnThreadId = NAMESPACE_VOS(OThread)::getCurrentIdentifier(); mnCount++; - return True; + return sal_True; } else - return False; + return sal_False; +} + +// ----------------------------------------------------------------------- + +// some convenience functions regarding the yield mutex, aka solar mutex + +BOOL ImplSalYieldMutexTryToAcquire() +{ + AquaSalInstance* pInst = (AquaSalInstance*) GetSalData()->mpFirstInstance; + if ( pInst ) + return pInst->mpSalYieldMutex->tryToAcquire(); + else + return FALSE; +} + +void ImplSalYieldMutexAcquire() +{ + AquaSalInstance* pInst = (AquaSalInstance*) GetSalData()->mpFirstInstance; + if ( pInst ) + pInst->mpSalYieldMutex->acquire(); +} + +void ImplSalYieldMutexRelease() +{ + AquaSalInstance* pInst = (AquaSalInstance*) GetSalData()->mpFirstInstance; + if ( pInst ) + { + //GdiFlush(); + pInst->mpSalYieldMutex->release(); + } } // ======================================================================= SalInstance* CreateSalInstance() { - SalData* pSalData = GetSalData(); - SalInstance* pInst = new SalInstance; + // FIXME: before integration: conditionalize debugging for DEBUG only + const char* pLogEnv = getenv( "AQUA_LOG" ); + if( ! pLogEnv || ! strcmp( pLogEnv, "off" ) ) + SalData::s_pLog = NULL; + else if( ! strcmp( pLogEnv, "stderr" ) ) + SalData::s_pLog = stderr; + else + SalData::s_pLog = fopen( pLogEnv, "w" ); + + SalData* pSalData = GetSalData(); + AquaSalInstance* pInst = new AquaSalInstance; + + EventLoopTimerUPP eventLoopTimer = NewEventLoopTimerUPP(AquaSalInstance::TimerEventHandler); + InstallEventLoopTimer(GetMainEventLoop(), 1, 0, eventLoopTimer, pInst, &pInst->mEventLoopTimerRef); - // init instance (only one instance in this version !!!) - pSalData->mpFirstInstance = pInst; + // init instance (only one instance in this version !!!) + pSalData->mpFirstInstance = pInst; + ImplGetSVData()->maNWFData.mbNoFocusRects = true; - return pInst; + return pInst; } // ----------------------------------------------------------------------- @@ -261,38 +323,73 @@ SalInstance* CreateSalInstance() void DestroySalInstance( SalInstance* pInst ) { delete pInst; + + if( SalData::s_pLog && SalData::s_pLog != stderr ) + fclose( SalData::s_pLog ); +} + +// ----------------------------------------------------------------------- + +AquaSalInstance::AquaSalInstance() +{ + mpFilterCallback = NULL; + mpFilterInst = NULL; + mpSalYieldMutex = new SalYieldMutex; + mEventLoopTimerRef = NULL; + mbForceDispatchPaintEvents = false; + mpSalYieldMutex->acquire(); } // ----------------------------------------------------------------------- -SalInstance::SalInstance() +AquaSalInstance::~AquaSalInstance() { - maInstData.mpFilterCallback = NULL; - maInstData.mpFilterInst = NULL; - maInstData.mpSalYieldMutex = new SalYieldMutex; - maInstData.mpSalYieldMutex->acquire(); + mpSalYieldMutex->release(); + delete mpSalYieldMutex; } // ----------------------------------------------------------------------- -SalInstance::~SalInstance() +void AquaSalInstance::TimerEventHandler(EventLoopTimerRef inTimer, void* pData) { - maInstData.mpSalYieldMutex->release(); - delete maInstData.mpSalYieldMutex; + AquaSalInstance* pInst = reinterpret_cast<AquaSalInstance*>(pData); + + if (pInst->mbForceDispatchPaintEvents) + { + ULONG nCount = 0; + + // Release all locks so that we don't deadlock when we pull pending + // events from the event queue + nCount = pInst->ReleaseYieldMutex(); + + EventRef theEvent; + EventTargetRef theTarget = GetEventDispatcherTarget(); + + if (ReceiveNextEvent(1, &cOOoSalTimerEvent, 0, true, &theEvent) == noErr) + { + SendEventToEventTarget(theEvent, theTarget); + ReleaseEvent(theEvent); + } + + // Reset all locks + pInst->AcquireYieldMutex(nCount); + + SetEventLoopTimerNextFireTime(inTimer, 1); // restart timer + } } // ----------------------------------------------------------------------- -vos::IMutex* SalInstance::GetYieldMutex() +vos::IMutex* AquaSalInstance::GetYieldMutex() { - return maInstData.mpSalYieldMutex; + return mpSalYieldMutex; } // ----------------------------------------------------------------------- -ULONG SalInstance::ReleaseYieldMutex() +ULONG AquaSalInstance::ReleaseYieldMutex() { - SalYieldMutex* pYieldMutex = maInstData.mpSalYieldMutex; + SalYieldMutex* pYieldMutex = mpSalYieldMutex; if ( pYieldMutex->GetThreadId() == NAMESPACE_VOS(OThread)::getCurrentIdentifier() ) { @@ -312,9 +409,9 @@ ULONG SalInstance::ReleaseYieldMutex() // ----------------------------------------------------------------------- -void SalInstance::AcquireYieldMutex( ULONG nCount ) +void AquaSalInstance::AcquireYieldMutex( ULONG nCount ) { - SalYieldMutex* pYieldMutex = maInstData.mpSalYieldMutex; + SalYieldMutex* pYieldMutex = mpSalYieldMutex; while ( nCount ) { pYieldMutex->acquire(); @@ -324,16 +421,62 @@ void SalInstance::AcquireYieldMutex( ULONG nCount ) // ----------------------------------------------------------------------- -void SalInstance::Yield( BOOL bWait ) +void AquaSalInstance::StartForceDispatchingPaintEvents() { - ULONG nCount = 0; + SetEventLoopTimerNextFireTime(mEventLoopTimerRef, 1); + mbForceDispatchPaintEvents = true; +} +void AquaSalInstance::StopForceDispatchingPaintEvents() +{ + mbForceDispatchPaintEvents = false; +} + +void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents ) +{ + ULONG nCount = 0; // Release all locks so that we don't deadlock when we pull pending // events from the event queue nCount = ReleaseYieldMutex(); - // Pull pending events from the event queue and dispatch them. - VCLApplication_Run( bWait ); + EventTargetRef theTarget = GetEventDispatcherTarget(); + EventTimeout timeout = bWait ? kEventDurationForever : 0; + + EventRef aLastTimerEvent = NULL; + for(;;) + { + EventRef theEvent; + OSStatus eStatus = ReceiveNextEvent( 0, NULL, timeout, kEventRemoveFromQueue, &theEvent ); + if( eStatus != noErr) + break; + if( bHandleAllCurrentEvents + && GetEventClass(theEvent) == cOOoSalUserEventClass + && GetEventKind(theEvent) == cOOoSalEventTimer ) + { + // ignore any timer event except the last one + if( aLastTimerEvent ) + ReleaseEvent( aLastTimerEvent ); + aLastTimerEvent = theEvent; + } + else + { + //ImplSalYieldMutexAcquire(); + eStatus = SendEventToEventTarget(theEvent, theTarget); + //ImplSalYieldMutexRelease(); + + ReleaseEvent(theEvent); + } + + if( !bHandleAllCurrentEvents ) + break; + } + + // send only the latest timer event if any + if( aLastTimerEvent ) + { + SendEventToEventTarget( aLastTimerEvent, theTarget ); + ReleaseEvent( aLastTimerEvent ); + } // Reset all locks AcquireYieldMutex( nCount ); @@ -341,50 +484,54 @@ void SalInstance::Yield( BOOL bWait ) // ----------------------------------------------------------------------- -BOOL SalInstance::AnyInput( USHORT nType ) +bool AquaSalInstance::AnyInput( USHORT nType ) { + // xxx TODO return FALSE; } // ----------------------------------------------------------------------- -SalFrame* SalInstance::CreateChildFrame( SystemParentData* pSystemParentData, ULONG nSalFrameStyle ) +SalFrame* AquaSalInstance::CreateChildFrame( SystemParentData* pSystemParentData, ULONG nSalFrameStyle ) { return NULL; } // ----------------------------------------------------------------------- -SalFrame* SalInstance::CreateFrame( SalFrame* pParent, ULONG nSalFrameStyle ) +SalFrame* AquaSalInstance::CreateFrame( SalFrame* pParent, ULONG nSalFrameStyle ) { - SalFrame *pFrame = new SalFrame; - - pFrame->maFrameData.mpParent = pParent; - - // Create the native window - pFrame->maFrameData.mhWnd = VCLWindow_New( nSalFrameStyle, NULL, - pFrame, &(pFrame->maFrameData) ); + SalFrame* pFrame = NULL; + try + { + pFrame = new AquaSalFrame(pParent, nSalFrameStyle, this); + } + catch(runtime_error&) + { + // frame creation failed + } return pFrame; } // ----------------------------------------------------------------------- -void SalInstance::DestroyFrame( SalFrame* pFrame ) +void AquaSalInstance::DestroyFrame( SalFrame* pFrame ) { delete pFrame; } // ----------------------------------------------------------------------- -SalObject* SalInstance::CreateObject( SalFrame* pParent ) +SalObject* AquaSalInstance::CreateObject( SalFrame* pParent, SystemWindowData* /* pWindowData */ ) { - SalObject *pObject = NULL; + // SystemWindowData is meaningless on Mac OS X + AquaSalObject *pObject = NULL; if ( pParent ) { - pObject = new SalObject; - pObject->maObjectData.mpFrame = pParent; + pObject = new AquaSalObject(); + pObject->mpFrame = (AquaSalFrame*)pParent; } return pObject; @@ -392,116 +539,235 @@ SalObject* SalInstance::CreateObject( SalFrame* pParent ) // ----------------------------------------------------------------------- -void SalInstance::DestroyObject( SalObject* pObject ) +void AquaSalInstance::DestroyObject( SalObject* pObject ) { delete ( pObject ); } // ----------------------------------------------------------------------- -SalVirtualDevice* SalInstance::CreateVirtualDevice( SalGraphics* pGraphics, - long nDX, long nDY, USHORT nBitCount ) +SalPrinter* AquaSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter ) { - SalVirtualDevice *pVirDev = new SalVirtualDevice; + return new AquaSalPrinter( dynamic_cast<AquaSalInfoPrinter*>(pInfoPrinter) ); +} - // Cache values for when SalVirtualDevice::GetGraphics() is invoked - pVirDev->maVirDevData.mnBitCount = nBitCount; - pVirDev->maVirDevData.mnWidth = nDX; - pVirDev->maVirDevData.mnHeight = nDY; +// ----------------------------------------------------------------------- - return pVirDev; +void AquaSalInstance::DestroyPrinter( SalPrinter* pPrinter ) +{ + delete pPrinter; } // ----------------------------------------------------------------------- -void SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice ) +void AquaSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) { - delete pDevice; + CFArrayRef rPrinterList(0); + if( PMServerCreatePrinterList( kPMServerLocal, &rPrinterList ) == noErr ) + { + CFIndex nPrinters = CFArrayGetCount( rPrinterList ); + for( CFIndex n = 0; n < nPrinters; n++ ) + { + PMPrinter aPrinter = reinterpret_cast<PMPrinter>(const_cast<void*>(CFArrayGetValueAtIndex( rPrinterList, n ))); + + SalPrinterQueueInfo* pNewPrinter = new SalPrinterQueueInfo(); + pNewPrinter->maPrinterName = GetOUString( PMPrinterGetName( aPrinter ) ); + pNewPrinter->mnStatus = 0; + pNewPrinter->mnJobs = 0; + // note CFStringRef is a const __CFString * + // so void* is appropriate to hold it + // however we need a little casting to convince the compiler + CFStringRef rID = CFStringCreateCopy( NULL, PMPrinterGetID( aPrinter ) ); + pNewPrinter->mpSysData = + const_cast<void*>(reinterpret_cast<const void*>( rID )); + + pList->Add( pNewPrinter ); + if( PMPrinterIsDefault( aPrinter ) ) + maDefaultPrinter = pNewPrinter->maPrinterName; + } + CFRelease( rPrinterList ); + } } // ----------------------------------------------------------------------- -SalPrinter* SalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter ) +void AquaSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) { - return NULL; } // ----------------------------------------------------------------------- -void SalInstance::DestroyPrinter( SalPrinter* pPrinter ) +void AquaSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) { + if( pInfo->mpSysData ) + CFRelease( reinterpret_cast<CFStringRef>(pInfo->mpSysData) ); + delete pInfo; } // ----------------------------------------------------------------------- -void SalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) +XubString AquaSalInstance::GetDefaultPrinter() { + if( ! maDefaultPrinter.getLength() ) + { + CFArrayRef rPrinterList(0); + if( PMServerCreatePrinterList( kPMServerLocal, &rPrinterList ) == noErr ) + { + CFIndex nPrinters = CFArrayGetCount( rPrinterList ); + for( CFIndex n = 0; n < nPrinters; n++ ) + { + PMPrinter aPrinter = reinterpret_cast<PMPrinter>(const_cast<void*>(CFArrayGetValueAtIndex( rPrinterList, n ))); + if( PMPrinterIsDefault( aPrinter ) ) + maDefaultPrinter = GetOUString( PMPrinterGetName( aPrinter ) ); + } + CFRelease( rPrinterList ); + } + } + return maDefaultPrinter; } // ----------------------------------------------------------------------- -void SalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) +SalInfoPrinter* AquaSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo, + ImplJobSetup* pSetupData ) { + SalInfoPrinter* pNewInfoPrinter = NULL; + if( pQueueInfo ) + { + pNewInfoPrinter = new AquaSalInfoPrinter( *pQueueInfo ); + if( pSetupData ) + pNewInfoPrinter->SetPrinterData( pSetupData ); + } + + return pNewInfoPrinter; } // ----------------------------------------------------------------------- -void SalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) +void AquaSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter ) { + delete pPrinter; } // ----------------------------------------------------------------------- -XubString SalInstance::GetDefaultPrinter() +SalSystem* AquaSalInstance::CreateSystem() { - return XubString(); + return new AquaSalSystem(); } // ----------------------------------------------------------------------- -SalInfoPrinter* SalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo, - ImplJobSetup* pSetupData ) +void AquaSalInstance::DestroySystem( SalSystem* pSystem ) { - return NULL; + delete pSystem; } // ----------------------------------------------------------------------- -void SalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter ) +void AquaSalInstance::SetEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ) { } // ----------------------------------------------------------------------- -SalSystem* SalInstance::CreateSystem() +void AquaSalInstance::SetErrorEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ) { - return new SalSystem(); } // ----------------------------------------------------------------------- -void SalInstance::DestroySystem( SalSystem* pSystem ) +void* AquaSalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes ) { - delete pSystem; + rReturnedBytes = 1; + rReturnedType = AsciiCString; + return (void*)""; } // ----------------------------------------------------------------------- -void SalInstance::SetEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ) +SalSound* AquaSalInstance::CreateSalSound() { + return new AquaSalSound(); } // ----------------------------------------------------------------------- -void SalInstance::SetErrorEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ) +SalTimer* AquaSalInstance::CreateSalTimer() { + return new AquaSalTimer(); } // ----------------------------------------------------------------------- -void* SalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes ) +SalOpenGL* AquaSalInstance::CreateSalOpenGL( SalGraphics* pGraphics ) { - rReturnedBytes = 1; - rReturnedType = AsciiCString; - return ""; + return new AquaSalOpenGL( pGraphics ); +} + +// ----------------------------------------------------------------------- + +SalSystem* AquaSalInstance::CreateSalSystem() +{ + return new AquaSalSystem(); } + +// ----------------------------------------------------------------------- + +SalBitmap* AquaSalInstance::CreateSalBitmap() +{ + return new AquaSalBitmap(); +} + +// ----------------------------------------------------------------------- + +SalSession* AquaSalInstance::CreateSalSession() +{ + return NULL; +} + +// ----------------------------------------------------------------------- + +class MacImeStatus : public SalI18NImeStatus +{ +public: + MacImeStatus() {} + virtual ~MacImeStatus() {} + + // asks whether there is a status window available + // to toggle into menubar + virtual bool canToggle() { return false; } + virtual void toggle() {} +}; + +// ----------------------------------------------------------------------- + +SalI18NImeStatus* AquaSalInstance::CreateI18NImeStatus() +{ + return new MacImeStatus(); +} + +////////////////////////////////////////////////////////////// +rtl::OUString GetOUString( CFStringRef rStr ) +{ + if( rStr == 0 ) + return rtl::OUString(); + CFIndex nLength = CFStringGetLength( rStr ); + if( nLength == 0 ) + return rtl::OUString(); + const UniChar* pConstStr = CFStringGetCharactersPtr( rStr ); + if( pConstStr ) + return rtl::OUString( pConstStr, nLength ); + UniChar* pStr = reinterpret_cast<UniChar*>( rtl_allocateMemory( sizeof(UniChar)*nLength ) ); + CFRange aRange = { 0, nLength }; + CFStringGetCharacters( rStr, aRange, pStr ); + rtl::OUString aRet( pStr, nLength ); + rtl_freeMemory( pStr ); + return aRet; +} + +CFStringRef CreateCFString( const rtl::OUString& rStr ) +{ + return CFStringCreateWithCharacters(kCFAllocatorDefault, rStr.getStr(), rStr.getLength() ); +} + |