xref: /aoo41x/main/vcl/os2/source/app/salinst.cxx (revision f98951f3)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #define INCL_DOSMISC
25cdf0e10cSrcweir #define INCL_DOSMODULEMGR
26cdf0e10cSrcweir #define INCL_DOSPROCESS
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <string.h>
29cdf0e10cSrcweir #include <svpm.h>
30cdf0e10cSrcweir #include <process.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #define _SV_SALINST_CXX
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX
35cdf0e10cSrcweir #include <vos/mutex.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef _SV_SALIDS_HRC
40fc9fd3f1SPedro Giffuni #include <os2/salids.hrc>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include <vcl/apptypes.hxx>
43fc9fd3f1SPedro Giffuni #include <os2/saldata.hxx>
44fc9fd3f1SPedro Giffuni #include <os2/salinst.h>
45fc9fd3f1SPedro Giffuni #include <os2/salframe.h>
46fc9fd3f1SPedro Giffuni #include <os2/salobj.h>
47fc9fd3f1SPedro Giffuni #include <os2/saltimer.h>
48fc9fd3f1SPedro Giffuni #include <os2/salbmp.h>
49fc9fd3f1SPedro Giffuni #include <salimestatus.hxx>
50cdf0e10cSrcweir #include <vcl/timer.hxx>
51cdf0e10cSrcweir #include <tools/solarmutex.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // =======================================================================
54cdf0e10cSrcweir 
SalAbort(const XubString & rErrorText)55cdf0e10cSrcweir void SalAbort( const XubString& rErrorText )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	ImplFreeSalGDI();
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	if( !rErrorText.Len() )
60cdf0e10cSrcweir 		fprintf( stderr, "Application Error " );
61cdf0e10cSrcweir 	else
62cdf0e10cSrcweir 		fprintf( stderr, "%s ",
63cdf0e10cSrcweir 			ByteString( rErrorText, gsl_getSystemTextEncoding() ).GetBuffer() );
64cdf0e10cSrcweir 	abort();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // =======================================================================
68cdf0e10cSrcweir 
GetCurrentThreadId()69cdf0e10cSrcweir ULONG GetCurrentThreadId()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	PTIB pptib = NULL;
72cdf0e10cSrcweir 	PPIB pppib = NULL;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	DosGetInfoBlocks( &pptib, &pppib );
75cdf0e10cSrcweir 	return pptib->tib_ptib2->tib2_ultid;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // =======================================================================
79cdf0e10cSrcweir 
80cdf0e10cSrcweir MRESULT EXPENTRY SalComWndProc( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // =======================================================================
83cdf0e10cSrcweir 
84cdf0e10cSrcweir class SalYieldMutex : public vos::OMutex
85cdf0e10cSrcweir {
86cdf0e10cSrcweir public:
87cdf0e10cSrcweir 	Os2SalInstance*			mpInstData;
88cdf0e10cSrcweir 	ULONG					mnCount;
89cdf0e10cSrcweir 	ULONG					mnThreadId;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir 							SalYieldMutex( Os2SalInstance* pInstData );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	virtual void SAL_CALL       acquire();
95cdf0e10cSrcweir 	virtual void SAL_CALL       release();
96cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL   tryToAcquire();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	ULONG					GetAcquireCount( ULONG nThreadId );
99cdf0e10cSrcweir };
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // -----------------------------------------------------------------------
102cdf0e10cSrcweir 
SalYieldMutex(Os2SalInstance * pInstData)103cdf0e10cSrcweir SalYieldMutex::SalYieldMutex( Os2SalInstance* pInstData )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	mpInstData	= pInstData;
106cdf0e10cSrcweir 	mnCount 	= 0;
107cdf0e10cSrcweir 	mnThreadId	= 0;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // -----------------------------------------------------------------------
111cdf0e10cSrcweir 
acquire()112cdf0e10cSrcweir void SalYieldMutex::acquire()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	OMutex::acquire();
115cdf0e10cSrcweir 	mnCount++;
116cdf0e10cSrcweir 	mnThreadId = GetCurrentThreadId();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // -----------------------------------------------------------------------
120cdf0e10cSrcweir 
release()121cdf0e10cSrcweir void SalYieldMutex::release()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	ULONG nThreadId = GetCurrentThreadId();
124cdf0e10cSrcweir 	if ( mnThreadId != nThreadId )
125cdf0e10cSrcweir 		OMutex::release();
126cdf0e10cSrcweir 	else
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		SalData* pSalData = GetSalData();
129cdf0e10cSrcweir 		if ( pSalData->mnAppThreadId != nThreadId )
130cdf0e10cSrcweir 		{
131cdf0e10cSrcweir 			if ( mnCount == 1 )
132cdf0e10cSrcweir 			{
133cdf0e10cSrcweir                 mpInstData->mpSalWaitMutex->acquire();
134cdf0e10cSrcweir 				if ( mpInstData->mnYieldWaitCount )
135cdf0e10cSrcweir 					WinPostMsg( mpInstData->mhComWnd, SAL_MSG_RELEASEWAITYIELD, 0, 0 );
136cdf0e10cSrcweir 				mnThreadId = 0;
137cdf0e10cSrcweir                 mnCount--;
138cdf0e10cSrcweir                 OMutex::release();
139cdf0e10cSrcweir                 mpInstData->mpSalWaitMutex->release();
140cdf0e10cSrcweir             }
141cdf0e10cSrcweir             else
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 mnCount--;
144cdf0e10cSrcweir                 OMutex::release();
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir 		else
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			if ( mnCount == 1 )
150cdf0e10cSrcweir 				mnThreadId = 0;
151cdf0e10cSrcweir 			mnCount--;
152cdf0e10cSrcweir 			OMutex::release();
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // -----------------------------------------------------------------------
158cdf0e10cSrcweir 
tryToAcquire()159cdf0e10cSrcweir sal_Bool SalYieldMutex::tryToAcquire()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	if ( OMutex::tryToAcquire() )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		mnCount++;
164cdf0e10cSrcweir 		mnThreadId = GetCurrentThreadId();
165cdf0e10cSrcweir 		return sal_True;
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 	else
168cdf0e10cSrcweir 		return sal_False;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // -----------------------------------------------------------------------
172cdf0e10cSrcweir 
GetAcquireCount(ULONG nThreadId)173cdf0e10cSrcweir ULONG SalYieldMutex::GetAcquireCount( ULONG nThreadId )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	if ( nThreadId == mnThreadId )
176cdf0e10cSrcweir 		return mnCount;
177cdf0e10cSrcweir 	else
178cdf0e10cSrcweir 		return 0;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // -----------------------------------------------------------------------
182cdf0e10cSrcweir 
ImplSalYieldMutexAcquireWithWait()183cdf0e10cSrcweir void ImplSalYieldMutexAcquireWithWait()
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
186cdf0e10cSrcweir     if ( !pInst )
187cdf0e10cSrcweir         return;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     // If we are the main thread, then we must wait with wait, because
190cdf0e10cSrcweir     // in if we don't reschedule, then we create deadlocks if a Windows
191cdf0e10cSrcweir     // Function is called from another thread. If we arn't the main thread,
192cdf0e10cSrcweir     // than we call qcquire directly.
193cdf0e10cSrcweir     ULONG nThreadId = GetCurrentThreadId();
194cdf0e10cSrcweir     SalData* pSalData = GetSalData();
195cdf0e10cSrcweir     if ( pSalData->mnAppThreadId == nThreadId )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         // Wenn wir den Mutex nicht bekommen, muessen wir solange
198cdf0e10cSrcweir         // warten, bis wir Ihn bekommen
199fc9fd3f1SPedro Giffuni         sal_Bool bAcquire = FALSE;
200cdf0e10cSrcweir         do
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir             if ( pInst->mpSalYieldMutex->tryToAcquire() )
203cdf0e10cSrcweir                 bAcquire = TRUE;
204cdf0e10cSrcweir             else
205cdf0e10cSrcweir             {
206cdf0e10cSrcweir                 pInst->mpSalWaitMutex->acquire();
207cdf0e10cSrcweir                 if ( pInst->mpSalYieldMutex->tryToAcquire() )
208cdf0e10cSrcweir                 {
209cdf0e10cSrcweir                     bAcquire = TRUE;
210cdf0e10cSrcweir                     pInst->mpSalWaitMutex->release();
211cdf0e10cSrcweir                 }
212cdf0e10cSrcweir                 else
213cdf0e10cSrcweir                 {
214cdf0e10cSrcweir                     pInst->mnYieldWaitCount++;
215cdf0e10cSrcweir                     pInst->mpSalWaitMutex->release();
216cdf0e10cSrcweir 					QMSG aTmpMsg;
217cdf0e10cSrcweir 					WinGetMsg( pSalData->mhAB, &aTmpMsg, pInst->mhComWnd, SAL_MSG_RELEASEWAITYIELD, SAL_MSG_RELEASEWAITYIELD );
218cdf0e10cSrcweir                     pInst->mnYieldWaitCount--;
219cdf0e10cSrcweir                     if ( pInst->mnYieldWaitCount )
220cdf0e10cSrcweir 						WinPostMsg( pInst->mhComWnd, SAL_MSG_RELEASEWAITYIELD, 0 , 0 );
221cdf0e10cSrcweir                 }
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir         while ( !bAcquire );
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir     else
227cdf0e10cSrcweir         pInst->mpSalYieldMutex->acquire();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // -----------------------------------------------------------------------
231cdf0e10cSrcweir 
ImplSalYieldMutexTryToAcquire()232fc9fd3f1SPedro Giffuni sal_Bool ImplSalYieldMutexTryToAcquire()
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
235cdf0e10cSrcweir     if ( pInst )
236cdf0e10cSrcweir         return pInst->mpSalYieldMutex->tryToAcquire();
237cdf0e10cSrcweir     else
238cdf0e10cSrcweir         return FALSE;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir // -----------------------------------------------------------------------
242cdf0e10cSrcweir 
ImplSalYieldMutexAcquire()243cdf0e10cSrcweir void ImplSalYieldMutexAcquire()
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
246cdf0e10cSrcweir     if ( pInst )
247cdf0e10cSrcweir         pInst->mpSalYieldMutex->acquire();
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // -----------------------------------------------------------------------
251cdf0e10cSrcweir 
ImplSalYieldMutexRelease()252cdf0e10cSrcweir void ImplSalYieldMutexRelease()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
255cdf0e10cSrcweir     if ( pInst )
256cdf0e10cSrcweir         pInst->mpSalYieldMutex->release();
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -----------------------------------------------------------------------
260cdf0e10cSrcweir 
ImplSalReleaseYieldMutex()261cdf0e10cSrcweir ULONG ImplSalReleaseYieldMutex()
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
264cdf0e10cSrcweir     if ( !pInst )
265cdf0e10cSrcweir         return 0;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     SalYieldMutex*  pYieldMutex = pInst->mpSalYieldMutex;
268cdf0e10cSrcweir     ULONG           nCount = pYieldMutex->GetAcquireCount( GetCurrentThreadId() );
269cdf0e10cSrcweir     ULONG           n = nCount;
270cdf0e10cSrcweir     while ( n )
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         pYieldMutex->release();
273cdf0e10cSrcweir         n--;
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     return nCount;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // -----------------------------------------------------------------------
280cdf0e10cSrcweir 
ImplSalAcquireYieldMutex(ULONG nCount)281cdf0e10cSrcweir void ImplSalAcquireYieldMutex( ULONG nCount )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
284cdf0e10cSrcweir     if ( !pInst )
285cdf0e10cSrcweir         return;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     SalYieldMutex*  pYieldMutex = pInst->mpSalYieldMutex;
288cdf0e10cSrcweir     while ( nCount )
289cdf0e10cSrcweir     {
290cdf0e10cSrcweir         pYieldMutex->acquire();
291cdf0e10cSrcweir         nCount--;
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir // -----------------------------------------------------------------------
296cdf0e10cSrcweir 
CheckYieldMutex()297cdf0e10cSrcweir bool Os2SalInstance::CheckYieldMutex()
298cdf0e10cSrcweir {
299cdf0e10cSrcweir     bool bRet = true;
300cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
301cdf0e10cSrcweir 	ULONG		nCurThreadId = GetCurrentThreadId();
302cdf0e10cSrcweir 	if ( pSalData->mnAppThreadId != nCurThreadId )
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir 		if ( pSalData->mpFirstInstance )
305cdf0e10cSrcweir 		{
306cdf0e10cSrcweir             SalYieldMutex* pYieldMutex = pSalData->mpFirstInstance->mpSalYieldMutex;
307cdf0e10cSrcweir 			if ( pYieldMutex->mnThreadId != nCurThreadId )
308cdf0e10cSrcweir 			{
309cdf0e10cSrcweir 				bRet = false;
310cdf0e10cSrcweir 			}
311cdf0e10cSrcweir 		}
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir 	else
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		if ( pSalData->mpFirstInstance )
316cdf0e10cSrcweir 		{
317cdf0e10cSrcweir             SalYieldMutex* pYieldMutex = pSalData->mpFirstInstance->mpSalYieldMutex;
318cdf0e10cSrcweir 			if ( pYieldMutex->mnThreadId != nCurThreadId )
319cdf0e10cSrcweir 			{
320cdf0e10cSrcweir 				bRet = false;
321cdf0e10cSrcweir 			}
322cdf0e10cSrcweir 		}
323cdf0e10cSrcweir 	}
324cdf0e10cSrcweir 	return bRet;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir // =======================================================================
328cdf0e10cSrcweir 
InitSalData()329cdf0e10cSrcweir void InitSalData()
330cdf0e10cSrcweir {
331cdf0e10cSrcweir 	SalData* pSalData = new SalData;
332cdf0e10cSrcweir 	memset( pSalData, 0, sizeof( SalData ) );
333cdf0e10cSrcweir 	SetSalData( pSalData );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir // -----------------------------------------------------------------------
337cdf0e10cSrcweir 
DeInitSalData()338cdf0e10cSrcweir void DeInitSalData()
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	SalData* pSalData = GetSalData();
341cdf0e10cSrcweir 	if ( pSalData->mpFontMetrics )
342cdf0e10cSrcweir 		delete pSalData->mpFontMetrics;
343cdf0e10cSrcweir 	delete pSalData;
344cdf0e10cSrcweir 	SetSalData( NULL );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // -----------------------------------------------------------------------
348cdf0e10cSrcweir 
InitSalMain()349cdf0e10cSrcweir void InitSalMain()
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	PPIB pib;
352cdf0e10cSrcweir 	PTIB tib;
353cdf0e10cSrcweir 	HAB hAB;
354cdf0e10cSrcweir 	HMQ hMQ;
355cdf0e10cSrcweir 	SalData* pData = GetAppSalData();
356cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
357*f98951f3SYuri Dario 	debug_printf("InitSalMain\n");
358cdf0e10cSrcweir #endif
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	// morph application to PM
361cdf0e10cSrcweir 	DosGetInfoBlocks(&tib, &pib);
362cdf0e10cSrcweir 	// Change flag from VIO to PM:
363cdf0e10cSrcweir 	if (pib->pib_ultype==2) pib->pib_ultype = 3;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	// create anchor block
366cdf0e10cSrcweir 	hAB = WinInitialize( 0 );
367cdf0e10cSrcweir 	if ( !hAB )
368cdf0e10cSrcweir 		return;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// create message queue
371cdf0e10cSrcweir 	hMQ = WinCreateMsgQueue( hAB, 60 );
372cdf0e10cSrcweir 	if ( !hMQ )
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		WinTerminate( hAB );
375cdf0e10cSrcweir 		return;
376cdf0e10cSrcweir 	}
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	if ( pData ) // Im AppServer NULL
379cdf0e10cSrcweir 	{
380cdf0e10cSrcweir 		// Ankerblock und Messagequeue merken
381cdf0e10cSrcweir 		pData->mhAB = hAB;
382cdf0e10cSrcweir 		pData->mhMQ = hMQ;
383cdf0e10cSrcweir 	}
384cdf0e10cSrcweir 
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
DeInitSalMain()387cdf0e10cSrcweir void DeInitSalMain()
388cdf0e10cSrcweir {
389cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
390cdf0e10cSrcweir printf("DeInitSalMain\n");
391cdf0e10cSrcweir #endif
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 	SalData* pData = GetAppSalData();
394cdf0e10cSrcweir 	// destroy message queue and anchor block
395cdf0e10cSrcweir 	WinDestroyMsgQueue( pData->mhMQ );
396cdf0e10cSrcweir 	WinTerminate( pData->mhAB );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir // -----------------------------------------------------------------------
401cdf0e10cSrcweir 
CreateSalInstance()402cdf0e10cSrcweir SalInstance* CreateSalInstance()
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	SalData*		pSalData = GetSalData();
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 	// determine the os2 version
407cdf0e10cSrcweir 	ULONG nMayor;
408cdf0e10cSrcweir 	ULONG nMinor;
409cdf0e10cSrcweir 	DosQuerySysInfo( QSV_VERSION_MAJOR, QSV_VERSION_MAJOR, &nMayor, sizeof( nMayor ) );
410cdf0e10cSrcweir 	DosQuerySysInfo( QSV_VERSION_MINOR, QSV_VERSION_MINOR, &nMinor, sizeof( nMinor ) );
411cdf0e10cSrcweir 	aSalShlData.mnVersion = (USHORT)(nMayor*10 + nMinor);
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 	pSalData->mnAppThreadId = GetCurrentThreadId();
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	// register frame class
416cdf0e10cSrcweir 	if ( !WinRegisterClass( pSalData->mhAB, (PSZ)SAL_FRAME_CLASSNAME,
417cdf0e10cSrcweir 							(PFNWP)SalFrameWndProc, CS_MOVENOTIFY /* 17/08 CS_HITTEST | CS_MOVENOTIFY */,
418cdf0e10cSrcweir 							SAL_FRAME_WNDEXTRA ) )
419cdf0e10cSrcweir 	{
420cdf0e10cSrcweir 		return NULL;
421cdf0e10cSrcweir 	}
422cdf0e10cSrcweir 	// register subframe class
423cdf0e10cSrcweir 	if ( !WinRegisterClass( pSalData->mhAB, (PSZ)SAL_SUBFRAME_CLASSNAME,
424cdf0e10cSrcweir 							(PFNWP)SalFrameWndProc, CS_SAVEBITS| CS_MOVENOTIFY,
425cdf0e10cSrcweir 							SAL_FRAME_WNDEXTRA ) )
426cdf0e10cSrcweir 	{
427cdf0e10cSrcweir 		return NULL;
428cdf0e10cSrcweir 	}
429cdf0e10cSrcweir 	// register object class
430cdf0e10cSrcweir 	if ( !WinRegisterClass( pSalData->mhAB, (PSZ)SAL_COM_CLASSNAME,
431cdf0e10cSrcweir 							(PFNWP)SalComWndProc, 0, 0 ))
432cdf0e10cSrcweir 	{
433cdf0e10cSrcweir 		return NULL;
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	HWND hComWnd = WinCreateWindow( HWND_OBJECT, (PCSZ)SAL_COM_CLASSNAME,
437cdf0e10cSrcweir 									(PCSZ)"", 0, 0, 0, 0, 0,
438cdf0e10cSrcweir 									HWND_OBJECT, HWND_TOP,
439cdf0e10cSrcweir 									222, NULL, NULL);
440cdf0e10cSrcweir     if ( !hComWnd )
441cdf0e10cSrcweir         return NULL;
442cdf0e10cSrcweir 
443cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
444cdf0e10cSrcweir 	debug_printf("CreateSalInstance hComWnd %x\n", hComWnd);
445cdf0e10cSrcweir #endif
446cdf0e10cSrcweir     Os2SalInstance* pInst = new Os2SalInstance;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 	// init instance (only one instance in this version !!!)
449cdf0e10cSrcweir 	pSalData->mpFirstInstance	= pInst;
450cdf0e10cSrcweir 	pInst->mhAB		= pSalData->mhAB;
451cdf0e10cSrcweir 	pInst->mhMQ		= pSalData->mhMQ;
452cdf0e10cSrcweir 	pInst->mnArgc	= pSalData->mnArgc;
453cdf0e10cSrcweir 	pInst->mpArgv	= pSalData->mpArgv;
454cdf0e10cSrcweir 	pInst->mhComWnd	= hComWnd;
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 	// AppIcon ermitteln
457cdf0e10cSrcweir 	ImplLoadSalIcon( SAL_RESID_ICON_DEFAULT, pInst->mhAppIcon);
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	// init static GDI Data
460cdf0e10cSrcweir 	ImplInitSalGDI();
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	return pInst;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir // -----------------------------------------------------------------------
466cdf0e10cSrcweir 
DestroySalInstance(SalInstance * pInst)467cdf0e10cSrcweir void DestroySalInstance( SalInstance* pInst )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	SalData* pSalData = GetSalData();
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	//	(only one instance in this version !!!)
472cdf0e10cSrcweir 	ImplFreeSalGDI();
473cdf0e10cSrcweir 
474cdf0e10cSrcweir #ifdef ENABLE_IME
475cdf0e10cSrcweir 	// IME-Daten freigeben
476cdf0e10cSrcweir 	if ( pSalData->mpIMEData )
477cdf0e10cSrcweir 		ImplReleaseSALIMEData();
478cdf0e10cSrcweir #endif
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	// reset instance
481cdf0e10cSrcweir 	if ( pSalData->mpFirstInstance == pInst )
482cdf0e10cSrcweir 		pSalData->mpFirstInstance = NULL;
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 	delete pInst;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir // -----------------------------------------------------------------------
488cdf0e10cSrcweir 
Os2SalInstance()489cdf0e10cSrcweir Os2SalInstance::Os2SalInstance()
490cdf0e10cSrcweir {
491cdf0e10cSrcweir 	mhComWnd				= 0;
492cdf0e10cSrcweir 	mpSalYieldMutex			= new SalYieldMutex( this );
493cdf0e10cSrcweir 	mpSalWaitMutex			= new vos::OMutex;
494cdf0e10cSrcweir     mnYieldWaitCount         = 0;
495cdf0e10cSrcweir 	mpSalYieldMutex->acquire();
496cdf0e10cSrcweir 	::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex );
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir // -----------------------------------------------------------------------
500cdf0e10cSrcweir 
~Os2SalInstance()501cdf0e10cSrcweir Os2SalInstance::~Os2SalInstance()
502cdf0e10cSrcweir {
503cdf0e10cSrcweir 	::tools::SolarMutex::SetSolarMutex( 0 );
504cdf0e10cSrcweir 	mpSalYieldMutex->release();
505cdf0e10cSrcweir 	delete mpSalYieldMutex;
506cdf0e10cSrcweir 	delete mpSalWaitMutex;
507cdf0e10cSrcweir 	WinDestroyWindow( mhComWnd);
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir // -----------------------------------------------------------------------
511cdf0e10cSrcweir 
GetYieldMutex()512cdf0e10cSrcweir vos::IMutex* Os2SalInstance::GetYieldMutex()
513cdf0e10cSrcweir {
514cdf0e10cSrcweir     return mpSalYieldMutex;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir // -----------------------------------------------------------------------
517cdf0e10cSrcweir 
ReleaseYieldMutex()518cdf0e10cSrcweir ULONG Os2SalInstance::ReleaseYieldMutex()
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     return ImplSalReleaseYieldMutex();
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir // -----------------------------------------------------------------------
524cdf0e10cSrcweir 
AcquireYieldMutex(ULONG nCount)525cdf0e10cSrcweir void Os2SalInstance::AcquireYieldMutex( ULONG nCount )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir     ImplSalAcquireYieldMutex( nCount );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir // -----------------------------------------------------------------------
531cdf0e10cSrcweir 
ImplSalYield(sal_Bool bWait,sal_Bool bHandleAllCurrentEvents)532fc9fd3f1SPedro Giffuni static void ImplSalYield( sal_Bool bWait, sal_Bool bHandleAllCurrentEvents )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	QMSG			aMsg;
535cdf0e10cSrcweir 	bool bWasMsg = false, bOneEvent = false;
536cdf0e10cSrcweir 	bool bQuit = false;
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
539cdf0e10cSrcweir     int nMaxEvents = bHandleAllCurrentEvents ? 100 : 1;
540cdf0e10cSrcweir     do
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir         if ( WinPeekMsg( pInst->mhAB, &aMsg, 0, 0, 0, PM_REMOVE ) )
543cdf0e10cSrcweir         {
544cdf0e10cSrcweir 			WinDispatchMsg( pInst->mhAB, &aMsg );
545cdf0e10cSrcweir 			bOneEvent = bWasMsg = true;
546cdf0e10cSrcweir 			if (aMsg.msg == WM_QUIT)
547cdf0e10cSrcweir 				bQuit = true;
548cdf0e10cSrcweir         }
549cdf0e10cSrcweir         else
550cdf0e10cSrcweir             bOneEvent = false;
551cdf0e10cSrcweir     } while( --nMaxEvents && bOneEvent );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 	if ( bWait && ! bWasMsg )
554cdf0e10cSrcweir 	{
555cdf0e10cSrcweir 		if ( WinGetMsg( pInst->mhAB, &aMsg, 0, 0, 0 ) )
556cdf0e10cSrcweir 			WinDispatchMsg( pInst->mhAB, &aMsg );
557cdf0e10cSrcweir 		else
558cdf0e10cSrcweir 			bQuit = true;
559cdf0e10cSrcweir 	}
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	if (bQuit)
562cdf0e10cSrcweir 	{
563cdf0e10cSrcweir 		ImplSalYieldMutexAcquireWithWait();
564cdf0e10cSrcweir 		Os2SalFrame*   pFrame = GetSalData()->mpFirstFrame;
565cdf0e10cSrcweir 		if ( pFrame )
566cdf0e10cSrcweir 		{
567cdf0e10cSrcweir 			if (pFrame->CallCallback( SALEVENT_SHUTDOWN, 0 ))
568cdf0e10cSrcweir 				WinCancelShutdown( pFrame->mhAB, FALSE );
569cdf0e10cSrcweir 		}
570cdf0e10cSrcweir 		ImplSalYieldMutexRelease();
571cdf0e10cSrcweir 	}
572cdf0e10cSrcweir 
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir // -----------------------------------------------------------------------
576cdf0e10cSrcweir 
Yield(bool bWait,bool bHandleAllCurrentEvents)577cdf0e10cSrcweir void Os2SalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir 	SalYieldMutex*	pYieldMutex = mpSalYieldMutex;
580cdf0e10cSrcweir 	SalData*		pSalData = GetSalData();
581cdf0e10cSrcweir 	ULONG			nCurThreadId = GetCurrentThreadId();
582cdf0e10cSrcweir 	ULONG			nCount = pYieldMutex->GetAcquireCount( nCurThreadId );
583cdf0e10cSrcweir 	ULONG			n = nCount;
584cdf0e10cSrcweir 	while ( n )
585cdf0e10cSrcweir 	{
586cdf0e10cSrcweir 		pYieldMutex->release();
587cdf0e10cSrcweir 		n--;
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir 	if ( pSalData->mnAppThreadId != nCurThreadId )
590cdf0e10cSrcweir 	{
591cdf0e10cSrcweir 		// #97739# A SendMessage call blocks until the called thread (here: the main thread)
592cdf0e10cSrcweir 		// returns. During a yield however, messages are processed in the main thread that might
593cdf0e10cSrcweir 		// result in a new message loop due to opening a dialog. Thus, SendMessage would not
594cdf0e10cSrcweir 		// return which will block this thread!
595cdf0e10cSrcweir 		// Solution: just give up the time slice and hope that messages are processed
596cdf0e10cSrcweir 		// by the main thread anyway (where all windows are created)
597cdf0e10cSrcweir 		// If the mainthread is not currently handling messages, then our SendMessage would
598cdf0e10cSrcweir 		// also do nothing, so this seems to be reasonable.
599cdf0e10cSrcweir 
600cdf0e10cSrcweir         // #i18883# only sleep if potential deadlock scenario, ie, when a dialog is open
601cdf0e10cSrcweir         if( ImplGetSVData()->maAppData.mnModalMode )
602cdf0e10cSrcweir             DosSleep(1);
603cdf0e10cSrcweir         else
604cdf0e10cSrcweir 			WinSendMsg( mhComWnd, SAL_MSG_THREADYIELD, (MPARAM)bWait, (MPARAM)bHandleAllCurrentEvents );
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 		n = nCount;
607cdf0e10cSrcweir 		while ( n )
608cdf0e10cSrcweir 		{
609cdf0e10cSrcweir 			pYieldMutex->acquire();
610cdf0e10cSrcweir 			n--;
611cdf0e10cSrcweir 		}
612cdf0e10cSrcweir 	}
613cdf0e10cSrcweir 	else
614cdf0e10cSrcweir 	{
615cdf0e10cSrcweir 		ImplSalYield( bWait, bHandleAllCurrentEvents );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 		n = nCount;
618cdf0e10cSrcweir 		while ( n )
619cdf0e10cSrcweir 		{
620cdf0e10cSrcweir             ImplSalYieldMutexAcquireWithWait();
621cdf0e10cSrcweir             n--;
622cdf0e10cSrcweir 		}
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir // -----------------------------------------------------------------------
627cdf0e10cSrcweir 
SalComWndProc(HWND hWnd,ULONG nMsg,MPARAM nMP1,MPARAM nMP2)628cdf0e10cSrcweir MRESULT EXPENTRY SalComWndProc( HWND hWnd, ULONG nMsg,
629cdf0e10cSrcweir 								MPARAM nMP1, MPARAM nMP2 )
630cdf0e10cSrcweir {
631cdf0e10cSrcweir 	//debug_printf( "SalComWndProc hWnd 0x%x nMsg %d\n", hWnd, nMsg);
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 	switch ( nMsg )
634cdf0e10cSrcweir 	{
635cdf0e10cSrcweir         case SAL_MSG_PRINTABORTJOB:
636cdf0e10cSrcweir             //ImplSalPrinterAbortJobAsync( (HDC)wParam );
637cdf0e10cSrcweir             break;
638cdf0e10cSrcweir 		case SAL_MSG_THREADYIELD:
639cdf0e10cSrcweir 			ImplSalYield( (bool)nMP1, (bool) nMP2);
640cdf0e10cSrcweir 			return 0;
641cdf0e10cSrcweir         // If we get this message, because another GetMessage() call
642cdf0e10cSrcweir         // has recieved this message, we must post this message to
643cdf0e10cSrcweir         // us again, because in the other case we wait forever.
644cdf0e10cSrcweir         case SAL_MSG_RELEASEWAITYIELD:
645cdf0e10cSrcweir             {
646cdf0e10cSrcweir             Os2SalInstance* pInst = GetSalData()->mpFirstInstance;
647cdf0e10cSrcweir             if ( pInst && pInst->mnYieldWaitCount )
648cdf0e10cSrcweir                 WinPostMsg( hWnd, SAL_MSG_RELEASEWAITYIELD, nMP1, nMP2 );
649cdf0e10cSrcweir             }
650cdf0e10cSrcweir             return 0;
651cdf0e10cSrcweir 		case SAL_MSG_STARTTIMER:
652cdf0e10cSrcweir 			ImplSalStartTimer( (ULONG)nMP2, FALSE);
653cdf0e10cSrcweir 			return 0;
654cdf0e10cSrcweir 		case SAL_MSG_CREATEFRAME:
655cdf0e10cSrcweir 			return (MRESULT)ImplSalCreateFrame( GetSalData()->mpFirstInstance, (HWND)nMP2, (ULONG)nMP1 );
656cdf0e10cSrcweir         case SAL_MSG_DESTROYFRAME:
657cdf0e10cSrcweir             delete (SalFrame*)nMP2;
658cdf0e10cSrcweir             return 0;
659cdf0e10cSrcweir         case SAL_MSG_DESTROYHWND:
660cdf0e10cSrcweir             //We only destroy the native window here. We do NOT destroy the SalFrame contained
661cdf0e10cSrcweir 			//in the structure (GetWindowPtr()).
662cdf0e10cSrcweir 			if (WinDestroyWindow((HWND)nMP2) == 0)
663cdf0e10cSrcweir 			{
664cdf0e10cSrcweir 				OSL_ENSURE(0, "DestroyWindow failed!");
665cdf0e10cSrcweir 				//Failure: We remove the SalFrame from the window structure. So we avoid that
666cdf0e10cSrcweir 				// the window structure may contain an invalid pointer, once the SalFrame is deleted.
667cdf0e10cSrcweir 	           SetWindowPtr((HWND)nMP2, 0);
668cdf0e10cSrcweir 			}
669cdf0e10cSrcweir 			return 0;
670cdf0e10cSrcweir 		case SAL_MSG_CREATEOBJECT:
671cdf0e10cSrcweir 			return (MRESULT)ImplSalCreateObject( GetSalData()->mpFirstInstance, (Os2SalFrame*)(ULONG)nMP2 );
672cdf0e10cSrcweir         case SAL_MSG_DESTROYOBJECT:
673cdf0e10cSrcweir             delete (SalObject*)nMP2;
674cdf0e10cSrcweir 			return 0;
675cdf0e10cSrcweir         case SAL_MSG_CREATESOUND:
676cdf0e10cSrcweir             //return (MRESULT)((Os2SalSound*)nMP2)->ImplCreate();
677cdf0e10cSrcweir 			return 0;
678cdf0e10cSrcweir         case SAL_MSG_DESTROYSOUND:
679cdf0e10cSrcweir             //((Os2SalSound*)nMP2)->ImplDestroy();
680cdf0e10cSrcweir 			return 0;
681cdf0e10cSrcweir         case SAL_MSG_POSTTIMER:
682cdf0e10cSrcweir 			SalTimerProc( 0, 0, SALTIMERPROC_RECURSIVE, (ULONG)nMP2 );
683cdf0e10cSrcweir 			break;
684cdf0e10cSrcweir         case WM_TIMER:
685cdf0e10cSrcweir 			SalTimerProc( hWnd, 0, 0, 0 );
686cdf0e10cSrcweir             break;
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 	return WinDefWindowProc( hWnd, nMsg, nMP1, nMP2 );
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir // -----------------------------------------------------------------------
693cdf0e10cSrcweir 
AnyInput(USHORT nType)694cdf0e10cSrcweir bool Os2SalInstance::AnyInput( USHORT nType )
695cdf0e10cSrcweir {
696cdf0e10cSrcweir 	SalData* pSalData = GetSalData();
697cdf0e10cSrcweir 	QMSG	aQMSG;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 	if ( (nType & (INPUT_ANY)) == INPUT_ANY )
700cdf0e10cSrcweir 	{
701cdf0e10cSrcweir 		// Any Input
702cdf0e10cSrcweir 		if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0, 0, 0, PM_NOREMOVE ) )
703cdf0e10cSrcweir 			return TRUE;
704cdf0e10cSrcweir 	}
705cdf0e10cSrcweir 	else
706cdf0e10cSrcweir 	{
707cdf0e10cSrcweir 		if ( nType & INPUT_MOUSE )
708cdf0e10cSrcweir 		{
709cdf0e10cSrcweir 			// Test auf Mouseinput
710cdf0e10cSrcweir 			if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0,
711cdf0e10cSrcweir 							 WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE ) )
712cdf0e10cSrcweir 				return TRUE;
713cdf0e10cSrcweir 		}
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 		if ( nType & INPUT_KEYBOARD )
716cdf0e10cSrcweir 		{
717cdf0e10cSrcweir 			// Test auf Keyinput
718cdf0e10cSrcweir 			if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0,
719cdf0e10cSrcweir 							 WM_CHAR, WM_CHAR, PM_NOREMOVE ) )
720cdf0e10cSrcweir 				return !(SHORT1FROMMP( aQMSG.mp1 ) & KC_KEYUP);
721cdf0e10cSrcweir 		}
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 		if ( nType & INPUT_PAINT )
724cdf0e10cSrcweir 		{
725cdf0e10cSrcweir 			// Test auf Paintinput
726cdf0e10cSrcweir 			if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0,
727cdf0e10cSrcweir 							 WM_PAINT, WM_PAINT, PM_NOREMOVE ) )
728cdf0e10cSrcweir 				return TRUE;
729cdf0e10cSrcweir 		}
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 		if ( nType & INPUT_TIMER )
732cdf0e10cSrcweir 		{
733cdf0e10cSrcweir 			// Test auf Timerinput
734cdf0e10cSrcweir 			if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0,
735cdf0e10cSrcweir 							 WM_TIMER, WM_TIMER, PM_NOREMOVE ) )
736cdf0e10cSrcweir 				return TRUE;
737cdf0e10cSrcweir 		}
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 		if ( nType & INPUT_OTHER )
740cdf0e10cSrcweir 		{
741cdf0e10cSrcweir 			// Test auf sonstigen Input
742cdf0e10cSrcweir 			if ( WinPeekMsg( pSalData->mhAB, &aQMSG, 0, 0, 0, PM_NOREMOVE ) )
743cdf0e10cSrcweir 				return TRUE;
744cdf0e10cSrcweir 		}
745cdf0e10cSrcweir 	}
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 	return FALSE;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir // -----------------------------------------------------------------------
751cdf0e10cSrcweir 
CreateChildFrame(SystemParentData * pSystemParentData,ULONG nSalFrameStyle)752cdf0e10cSrcweir SalFrame* Os2SalInstance::CreateChildFrame( SystemParentData* pSystemParentData, ULONG nSalFrameStyle )
753cdf0e10cSrcweir {
754cdf0e10cSrcweir     // Um auf Main-Thread umzuschalten
755cdf0e10cSrcweir     return (SalFrame*)WinSendMsg( mhComWnd, SAL_MSG_CREATEFRAME, (MPARAM)nSalFrameStyle, (MPARAM)pSystemParentData->hWnd );
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir // -----------------------------------------------------------------------
759cdf0e10cSrcweir 
CreateFrame(SalFrame * pParent,ULONG nSalFrameStyle)760cdf0e10cSrcweir SalFrame* Os2SalInstance::CreateFrame( SalFrame* pParent, ULONG nSalFrameStyle )
761cdf0e10cSrcweir {
762cdf0e10cSrcweir     // Um auf Main-Thread umzuschalten
763cdf0e10cSrcweir     HWND mhWndClient;
764cdf0e10cSrcweir //31/05/06 YD use client as owner(parent) so positioning will not need to
765cdf0e10cSrcweir // take care of borders and captions
766cdf0e10cSrcweir     if ( pParent )
767cdf0e10cSrcweir         mhWndClient = static_cast<Os2SalFrame*>(pParent)->mhWndClient;
768cdf0e10cSrcweir     else
769cdf0e10cSrcweir         mhWndClient = 0;
770cdf0e10cSrcweir     return (SalFrame*)WinSendMsg( mhComWnd, SAL_MSG_CREATEFRAME, (MPARAM)nSalFrameStyle, (MPARAM)mhWndClient );
771cdf0e10cSrcweir }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 
774cdf0e10cSrcweir // -----------------------------------------------------------------------
775cdf0e10cSrcweir 
DestroyFrame(SalFrame * pFrame)776cdf0e10cSrcweir void Os2SalInstance::DestroyFrame( SalFrame* pFrame )
777cdf0e10cSrcweir {
778cdf0e10cSrcweir     WinSendMsg( mhComWnd, SAL_MSG_DESTROYFRAME, 0, (MPARAM)pFrame );
779cdf0e10cSrcweir }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir // -----------------------------------------------------------------------
782cdf0e10cSrcweir 
CreateObject(SalFrame * pParent,SystemWindowData *,sal_Bool)783cdf0e10cSrcweir SalObject* Os2SalInstance::CreateObject( SalFrame* pParent,
784cdf0e10cSrcweir                                          SystemWindowData* /*pWindowData*/, // SystemWindowData meaningless on Windows
785fc9fd3f1SPedro Giffuni                                          sal_Bool /*bShow*/ )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir 	// Um auf Main-Thread umzuschalten
788cdf0e10cSrcweir 	return (SalObject*)WinSendMsg( mhComWnd, SAL_MSG_CREATEOBJECT, 0, (MPARAM)pParent );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 
792cdf0e10cSrcweir // -----------------------------------------------------------------------
793cdf0e10cSrcweir 
DestroyObject(SalObject * pObject)794cdf0e10cSrcweir void Os2SalInstance::DestroyObject( SalObject* pObject )
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     WinSendMsg( mhComWnd, SAL_MSG_DESTROYOBJECT, 0, (MPARAM)pObject );
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir // -----------------------------------------------------------------------
800cdf0e10cSrcweir 
GetConnectionIdentifier(ConnectionIdentifierType & rReturnedType,int & rReturnedBytes)801cdf0e10cSrcweir void* Os2SalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes )
802cdf0e10cSrcweir {
803cdf0e10cSrcweir 	rReturnedBytes	= 1;
804cdf0e10cSrcweir 	rReturnedType	= AsciiCString;
805cdf0e10cSrcweir 	return (void*) "";
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
AddToRecentDocumentList(const rtl::OUString &,const rtl::OUString &)808cdf0e10cSrcweir void Os2SalInstance::AddToRecentDocumentList(const rtl::OUString& /*rFileUrl*/, const rtl::OUString& /*rMimeType*/)
809cdf0e10cSrcweir {
810cdf0e10cSrcweir }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir // -----------------------------------------------------------------------
813cdf0e10cSrcweir 
CreateSalTimer()814cdf0e10cSrcweir SalTimer* Os2SalInstance::CreateSalTimer()
815cdf0e10cSrcweir {
816cdf0e10cSrcweir     return new Os2SalTimer();
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir // -----------------------------------------------------------------------
820cdf0e10cSrcweir 
CreateSalBitmap()821cdf0e10cSrcweir SalBitmap* Os2SalInstance::CreateSalBitmap()
822cdf0e10cSrcweir {
823cdf0e10cSrcweir     return new Os2SalBitmap();
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir // -----------------------------------------------------------------------
827cdf0e10cSrcweir 
828cdf0e10cSrcweir class Os2ImeStatus : public SalI18NImeStatus
829cdf0e10cSrcweir {
830cdf0e10cSrcweir   public:
Os2ImeStatus()831cdf0e10cSrcweir     Os2ImeStatus() {}
~Os2ImeStatus()832cdf0e10cSrcweir     virtual ~Os2ImeStatus() {}
833cdf0e10cSrcweir 
834cdf0e10cSrcweir     // asks whether there is a status window available
835cdf0e10cSrcweir     // to toggle into menubar
canToggle()836cdf0e10cSrcweir     virtual bool canToggle() { return false; }
toggle()837cdf0e10cSrcweir     virtual void toggle() {}
838cdf0e10cSrcweir };
839cdf0e10cSrcweir 
CreateI18NImeStatus()840cdf0e10cSrcweir SalI18NImeStatus* Os2SalInstance::CreateI18NImeStatus()
841cdf0e10cSrcweir {
842cdf0e10cSrcweir     return new Os2ImeStatus();
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir // -----------------------------------------------------------------------
846cdf0e10cSrcweir 
SalGetDesktopEnvironment()847cdf0e10cSrcweir const ::rtl::OUString& SalGetDesktopEnvironment()
848cdf0e10cSrcweir {
849cdf0e10cSrcweir     static ::rtl::OUString aDesktopEnvironment( RTL_CONSTASCII_USTRINGPARAM( "OS/2" ) );
850cdf0e10cSrcweir     return aDesktopEnvironment;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
CreateSalSession()853cdf0e10cSrcweir SalSession* Os2SalInstance::CreateSalSession()
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     return NULL;
856cdf0e10cSrcweir }
857