1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SV_SALINST_H 25 #define _SV_SALINST_H 26 27 #include "vos/mutex.hxx" 28 #include "vos/thread.hxx" 29 #include "osl/conditn.h" 30 31 #include "aqua/aquavcltypes.h" 32 33 #include "salinst.hxx" 34 35 #include <list> 36 37 class AquaSalFrame; 38 class ApplicationEvent; 39 class Image; 40 41 // ----------------- 42 // - SalYieldMutex - 43 // ----------------- 44 45 class SalYieldMutex : public vos::OMutex 46 { 47 sal_uLong mnCount; 48 vos::OThread::TThreadIdentifier mnThreadId; 49 50 public: 51 SalYieldMutex(); 52 virtual void acquire(); 53 virtual void release(); 54 virtual sal_Bool tryToAcquire(); GetAcquireCount() const55 sal_uLong GetAcquireCount() const { return mnCount; } GetThreadId() const56 vos::OThread::TThreadIdentifier GetThreadId() const { return mnThreadId; } 57 }; 58 59 #define YIELD_GUARD vos::OGuard aGuard( GetSalData()->mpFirstInstance->GetYieldMutex() ) 60 61 62 // ------------------- 63 // - SalInstanceData - 64 // ------------------- 65 66 //struct SalInstanceData 67 //{ 68 //public: 69 //}; 70 71 // ------------------ 72 // - AquaSalInstance - 73 // ------------------ 74 75 class AquaSalInstance : public SalInstance 76 { 77 struct SalUserEvent 78 { 79 AquaSalFrame* mpFrame; 80 void* mpData; 81 sal_uInt16 mnType; 82 SalUserEventAquaSalInstance::SalUserEvent83 SalUserEvent( AquaSalFrame* pFrame, void* pData, sal_uInt16 nType ) : 84 mpFrame( pFrame ), mpData( pData ), mnType( nType ) 85 {} 86 }; 87 88 public: 89 SalYieldMutex* mpSalYieldMutex; // Sal-Yield-Mutex 90 rtl::OUString maDefaultPrinter; 91 vos::OThread::TThreadIdentifier maMainThread; 92 bool mbWaitingYield; 93 int mnActivePrintJobs; 94 std::list< SalUserEvent > maUserEvents; 95 oslMutex maUserEventListMutex; 96 oslCondition maWaitingYieldCond; 97 98 typedef std::list<const ApplicationEvent*> AppEventList; 99 static AppEventList aAppEventList; 100 101 public: 102 AquaSalInstance(); 103 virtual ~AquaSalInstance(); 104 105 virtual SalSystem* CreateSystem(); 106 virtual void DestroySystem(SalSystem*); 107 virtual SalFrame* CreateChildFrame( SystemParentData* pParent, sal_uLong nStyle ); 108 virtual SalFrame* CreateFrame( SalFrame* pParent, sal_uLong nStyle ); 109 virtual void DestroyFrame( SalFrame* pFrame ); 110 virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, sal_Bool bShow = sal_True ); 111 virtual void DestroyObject( SalObject* pObject ); 112 virtual SalVirtualDevice* CreateVirtualDevice( SalGraphics* pGraphics, 113 long nDX, long nDY, 114 sal_uInt16 nBitCount, const SystemGraphicsData *pData ); 115 virtual void DestroyVirtualDevice( SalVirtualDevice* pDevice ); 116 117 virtual SalInfoPrinter* CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo, 118 ImplJobSetup* pSetupData ); 119 virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ); 120 virtual SalPrinter* CreatePrinter( SalInfoPrinter* pInfoPrinter ); 121 virtual void DestroyPrinter( SalPrinter* pPrinter ); 122 virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ); 123 virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ); 124 virtual void DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ); 125 virtual String GetDefaultPrinter(); 126 virtual SalTimer* CreateSalTimer(); 127 virtual SalI18NImeStatus* CreateI18NImeStatus(); 128 virtual SalSystem* CreateSalSystem(); 129 virtual SalBitmap* CreateSalBitmap(); 130 virtual vos::IMutex* GetYieldMutex(); 131 virtual sal_uLong ReleaseYieldMutex(); 132 virtual void AcquireYieldMutex( sal_uLong nCount ); 133 virtual bool CheckYieldMutex(); 134 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ); 135 virtual bool AnyInput( sal_uInt16 nType ); 136 virtual SalMenu* CreateMenu( sal_Bool bMenuBar, Menu* pVCLMenu ); 137 virtual void DestroyMenu( SalMenu* ); 138 virtual SalMenuItem* CreateMenuItem( const SalItemParams* pItemData ); 139 virtual void DestroyMenuItem( SalMenuItem* ); 140 virtual SalSession* CreateSalSession(); 141 virtual void* GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes ); 142 virtual void AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType); 143 virtual void SetEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ); 144 virtual void SetErrorEventCallback( void* pInstance, bool(*pCallback)(void*,void*,int) ); 145 146 // dtrans implementation 147 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > 148 CreateClipboard( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& i_rArguments ); 149 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > CreateDragSource(); 150 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > CreateDropTarget(); 151 152 static void handleAppDefinedEvent( NSEvent* pEvent ); 153 154 // check whether a particular string is passed on the command line 155 // this is needed to avoid duplicate open events through a) command line and b) NSApp's openFile 156 static bool isOnCommandLine( const rtl::OUString& ); 157 158 void wakeupYield(); 159 160 public: 161 friend class AquaSalFrame; 162 163 void PostUserEvent( AquaSalFrame* pFrame, sal_uInt16 nType, void* pData ); 164 void delayedSettingsChanged( bool bInvalidate ); 165 166 bool isNSAppThread() const; 167 startedPrintJob()168 void startedPrintJob() { mnActivePrintJobs++; } endedPrintJob()169 void endedPrintJob() { mnActivePrintJobs--; } 170 171 // event subtypes for NSApplicationDefined events 172 static const short AppExecuteSVMain = 0x7fff; 173 static const short AppEndLoopEvent = 1; 174 static const short AppStartTimerEvent = 10; 175 static const short AppleRemoteEvent = 15; 176 static const short YieldWakeupEvent = 20; 177 178 static NSMenu* GetDynamicDockMenu(); 179 }; 180 181 // helper class: inverted solar guard 182 class YieldMutexReleaser 183 { 184 sal_uLong mnCount; 185 public: 186 YieldMutexReleaser(); 187 ~YieldMutexReleaser(); 188 }; 189 190 // helper class 191 rtl::OUString GetOUString( CFStringRef ); 192 rtl::OUString GetOUString( NSString* ); 193 CFStringRef CreateCFString( const rtl::OUString& ); 194 NSString* CreateNSString( const rtl::OUString& ); 195 196 CGImageRef CreateCGImage( const Image& ); 197 NSImage* CreateNSImage( const Image& ); 198 199 #endif // _SV_SALINST_H 200