1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SV_SALINST_H 29 #define _SV_SALINST_H 30 31 #include "vos/mutex.hxx" 32 #include "vos/thread.hxx" 33 #include "osl/conditn.h" 34 35 #include "aqua/aquavcltypes.h" 36 37 #include "salinst.hxx" 38 39 #include <list> 40 41 class AquaSalFrame; 42 class ApplicationEvent; 43 class Image; 44 45 // ----------------- 46 // - SalYieldMutex - 47 // ----------------- 48 49 class SalYieldMutex : public vos::OMutex 50 { 51 sal_uLong mnCount; 52 vos::OThread::TThreadIdentifier mnThreadId; 53 54 public: 55 SalYieldMutex(); 56 virtual void acquire(); 57 virtual void release(); 58 virtual sal_Bool tryToAcquire(); 59 sal_uLong GetAcquireCount() const { return mnCount; } 60 vos::OThread::TThreadIdentifier GetThreadId() const { return mnThreadId; } 61 }; 62 63 #define YIELD_GUARD vos::OGuard aGuard( GetSalData()->mpFirstInstance->GetYieldMutex() ) 64 65 66 // ------------------- 67 // - SalInstanceData - 68 // ------------------- 69 70 //struct SalInstanceData 71 //{ 72 //public: 73 //}; 74 75 // ------------------ 76 // - AquaSalInstance - 77 // ------------------ 78 79 class AquaSalInstance : public SalInstance 80 { 81 struct SalUserEvent 82 { 83 AquaSalFrame* mpFrame; 84 void* mpData; 85 sal_uInt16 mnType; 86 87 SalUserEvent( AquaSalFrame* pFrame, void* pData, sal_uInt16 nType ) : 88 mpFrame( pFrame ), mpData( pData ), mnType( nType ) 89 {} 90 }; 91 92 public: 93 SalYieldMutex* mpSalYieldMutex; // Sal-Yield-Mutex 94 rtl::OUString maDefaultPrinter; 95 vos::OThread::TThreadIdentifier maMainThread; 96 bool mbWaitingYield; 97 int mnActivePrintJobs; 98 std::list< SalUserEvent > maUserEvents; 99 oslMutex maUserEventListMutex; 100 oslCondition maWaitingYieldCond; 101 102 typedef std::list<const ApplicationEvent*> AppEventList; 103 static AppEventList aAppEventList; 104 105 public: 106 AquaSalInstance(); 107 virtual ~AquaSalInstance(); 108 109 virtual SalSystem* CreateSystem(); 110 virtual void DestroySystem(SalSystem*); 111 virtual SalFrame* CreateChildFrame( SystemParentData* pParent, sal_uLong nStyle ); 112 virtual SalFrame* CreateFrame( SalFrame* pParent, sal_uLong nStyle ); 113 virtual void DestroyFrame( SalFrame* pFrame ); 114 virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, sal_Bool bShow = sal_True ); 115 virtual void DestroyObject( SalObject* pObject ); 116 virtual SalVirtualDevice* CreateVirtualDevice( SalGraphics* pGraphics, 117 long nDX, long nDY, 118 sal_uInt16 nBitCount, const SystemGraphicsData *pData ); 119 virtual void DestroyVirtualDevice( SalVirtualDevice* pDevice ); 120 121 virtual SalInfoPrinter* CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo, 122 ImplJobSetup* pSetupData ); 123 virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ); 124 virtual SalPrinter* CreatePrinter( SalInfoPrinter* pInfoPrinter ); 125 virtual void DestroyPrinter( SalPrinter* pPrinter ); 126 virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ); 127 virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ); 128 virtual void DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ); 129 virtual String GetDefaultPrinter(); 130 virtual SalTimer* CreateSalTimer(); 131 virtual SalI18NImeStatus* CreateI18NImeStatus(); 132 virtual SalSystem* CreateSalSystem(); 133 virtual SalBitmap* CreateSalBitmap(); 134 virtual vos::IMutex* GetYieldMutex(); 135 virtual sal_uLong ReleaseYieldMutex(); 136 virtual void AcquireYieldMutex( sal_uLong nCount ); 137 virtual bool CheckYieldMutex(); 138 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ); 139 virtual bool AnyInput( sal_uInt16 nType ); 140 virtual SalMenu* CreateMenu( sal_Bool bMenuBar, Menu* pVCLMenu ); 141 virtual void DestroyMenu( SalMenu* ); 142 virtual SalMenuItem* CreateMenuItem( const SalItemParams* pItemData ); 143 virtual void DestroyMenuItem( SalMenuItem* ); 144 virtual SalSession* CreateSalSession(); 145 virtual void* GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes ); 146 virtual void AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType); 147 virtual void SetEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ); 148 virtual void SetErrorEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ); 149 150 // dtrans implementation 151 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > 152 CreateClipboard( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& i_rArguments ); 153 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > CreateDragSource(); 154 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > CreateDropTarget(); 155 156 static void handleAppDefinedEvent( NSEvent* pEvent ); 157 158 // check whether a particular string is passed on the command line 159 // this is needed to avoid duplicate open events through a) command line and b) NSApp's openFile 160 static bool isOnCommandLine( const rtl::OUString& ); 161 162 void wakeupYield(); 163 164 public: 165 friend class AquaSalFrame; 166 167 void PostUserEvent( AquaSalFrame* pFrame, sal_uInt16 nType, void* pData ); 168 void delayedSettingsChanged( bool bInvalidate ); 169 170 bool isNSAppThread() const; 171 172 void startedPrintJob() { mnActivePrintJobs++; } 173 void endedPrintJob() { mnActivePrintJobs--; } 174 175 // event subtypes for NSApplicationDefined events 176 static const short AppExecuteSVMain = 0x7fff; 177 static const short AppEndLoopEvent = 1; 178 static const short AppStartTimerEvent = 10; 179 static const short AppleRemoteEvent = 15; 180 static const short YieldWakeupEvent = 20; 181 182 static NSMenu* GetDynamicDockMenu(); 183 }; 184 185 // helper class: inverted solar guard 186 class YieldMutexReleaser 187 { 188 sal_uLong mnCount; 189 public: 190 YieldMutexReleaser(); 191 ~YieldMutexReleaser(); 192 }; 193 194 // helper class 195 rtl::OUString GetOUString( CFStringRef ); 196 rtl::OUString GetOUString( NSString* ); 197 CFStringRef CreateCFString( const rtl::OUString& ); 198 NSString* CreateNSString( const rtl::OUString& ); 199 200 CGImageRef CreateCGImage( const Image& ); 201 NSImage* CreateNSImage( const Image& ); 202 203 #endif // _SV_SALINST_H 204