xref: /trunk/main/vcl/os2/source/window/salframe.cxx (revision e0343f61)
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 #define INCL_DOS
25 #define INCL_PM
26 #define INCL_WIN
27 #define VCL_OS2
28 #include <svpm.h>
29 
30 #include <string.h>
31 
32 #include <tools/svwin.h>
33 
34 // =======================================================================
35 
36 #define _SV_SALFRAME_CXX
37 
38 #ifndef DEBUG_HXX
39 #include <tools/debug.hxx>
40 #endif
41 
42 #define private public
43 
44 #include "os2/sallang.hxx"
45 #include "os2/salids.hrc"
46 #include "os2/saldata.hxx"
47 #include "os2/salinst.h"
48 #include "os2/salgdi.h"
49 #include "os2/salframe.h"
50 #include "os2/saltimer.h"
51 
52 #include <vcl/timer.hxx>
53 #include <vcl/settings.hxx>
54 #include <vcl/keycodes.hxx>
55 
56 #if OSL_DEBUG_LEVEL>10
57 extern "C" int debug_printf(const char *f, ...);
58 
59 static sal_Bool _bCapture;
60 
61 #else
62 #define debug_printf( ...) { 1; }
63 #endif
64 
65 // =======================================================================
66 
67 #undef WinEnableMenuItem
68 #define WinEnableMenuItem(hwndMenu,id,fEnable) \
69     ((PM_BOOL)WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT (id, TRUE), \
70 		       MPFROM2SHORT (MIA_DISABLED, \
71 				     ((USHORT)(fEnable) ? 0 : MIA_DISABLED))))
72 
73 // =======================================================================
74 
75 HPOINTER ImplLoadPointer( ULONG nId );
76 
77 static void SetMaximizedFrameGeometry( HWND hWnd, Os2SalFrame* pFrame );
78 static void UpdateFrameGeometry( HWND hWnd, Os2SalFrame* pFrame );
79 static void ImplSalCalcFrameSize( HWND hWnd,
80                                   LONG& nFrameX, LONG& nFrameY, LONG& nCaptionY );
81 static void ImplSalCalcFrameSize( const Os2SalFrame* pFrame,
82                                   LONG& nFrameX, LONG& nFrameY, LONG& nCaptionY );
83 MRESULT EXPENTRY SalFrameSubClassWndProc( HWND hWnd, ULONG nMsg,
84                                   MPARAM nMP1, MPARAM nMP2 );
85 
86 // =======================================================================
87 
88 static LanguageType eImplKeyboardLanguage = LANGUAGE_DONTKNOW;
89 sal_Bool Os2SalFrame::mbInReparent = FALSE;
90 ULONG Os2SalFrame::mnInputLang = 0;
91 
92 // =======================================================================
93 
94 // define a new flag
95 #define SWP_CENTER			(SWP_NOAUTOCLOSE<<4)
96 #define SWP_SHOWMAXIMIZED	(SWP_ACTIVATE | SWP_SHOW | SWP_MAXIMIZE)
97 #define SWP_SHOWMINIMIZED	(SWP_ACTIVATE | SWP_SHOW | SWP_MINIMIZE)
98 #define SWP_SHOWNORMAL		(SWP_ACTIVATE | SWP_SHOW | SWP_RESTORE)
99 
100 static LONG nScreenHeight  = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN);
101 static LONG nScreenWidth   = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
102 
_WinQueryWindowRect(HWND hwnd,PRECTL prclDest)103 sal_Bool APIENTRY _WinQueryWindowRect( HWND hwnd, PRECTL prclDest)
104 {
105 	sal_Bool rc = WinQueryWindowRect( hwnd, prclDest);
106 	ULONG tmp = prclDest->yBottom;
107 	prclDest->yBottom = prclDest->yTop;
108 	prclDest->yTop = tmp;
109 	return rc;
110 }
111 
_WinQueryPointerPos(HWND hwndDesktop,PPOINTL pptl)112 sal_Bool APIENTRY _WinQueryPointerPos (HWND hwndDesktop, PPOINTL pptl)
113 {
114 	sal_Bool rc = WinQueryPointerPos( hwndDesktop, pptl);
115 	pptl->y = nScreenHeight - pptl->y;
116 	return rc;
117 }
118 
_WinQueryWindowPos(Os2SalFrame * pFrame,PSWP pswp)119 sal_Bool APIENTRY _WinQueryWindowPos( Os2SalFrame* pFrame, PSWP pswp)
120 {
121 	SWP swpOwner;
122 	sal_Bool rc = WinQueryWindowPos( pFrame->mhWndFrame, pswp);
123 
124 #if OSL_DEBUG_LEVEL>1
125 	debug_printf( "> WinQueryWindowPos hwnd %x at %d,%d (%dx%d)\n",
126 					pFrame->mhWndFrame, pswp->x, pswp->y, pswp->cx, pswp->cy);
127 #endif
128 
129 	Os2SalFrame* pParentFrame = pFrame->mpParentFrame;
130 
131 	//YD adjust to owner coordinates
132 	if ( pParentFrame )
133 	{
134 		POINTL ptlOwner = {0};
135 
136 		// coords are relative to screen, map to parent frame client area
137 		ptlOwner.x = pswp->x;
138 		ptlOwner.y = pswp->y;
139 		WinMapWindowPoints( HWND_DESKTOP, pParentFrame->mhWndClient, &ptlOwner, 1);
140 		pswp->x = ptlOwner.x;
141 		pswp->y = ptlOwner.y;
142 		// get parent client area size
143 		WinQueryWindowPos( pParentFrame->mhWndClient, &swpOwner);
144 	} else
145 	{
146 		// no owner info, use DESKTOP????
147 		swpOwner.cx = nScreenWidth;
148 		swpOwner.cy = nScreenHeight;
149 	}
150 
151 	// invert Y coordinate
152 	pswp->y = swpOwner.cy - (pswp->y + pswp->cy);
153 
154 #if OSL_DEBUG_LEVEL>1
155 	debug_printf( "< WinQueryWindowPos hwnd %x at %d,%d (%dx%d)\n",
156 					pFrame->mhWndFrame, pswp->x, pswp->y, pswp->cx, pswp->cy);
157 #endif
158 	return rc;
159 }
160 
_WinSetWindowPos(Os2SalFrame * pFrame,HWND hwndInsertBehind,LONG x,LONG y,LONG cx,LONG cy,ULONG fl)161 sal_Bool APIENTRY _WinSetWindowPos( Os2SalFrame* pFrame, HWND hwndInsertBehind, LONG x, LONG y,
162     LONG cx, LONG cy, ULONG fl)
163 {
164 	SWP 	swpOwner = {0};
165 	POINTL 	ptlOwner = {0};
166 	HWND	hParent = NULL;
167 
168 #if OSL_DEBUG_LEVEL>1
169 	debug_printf( ">WinSetWindowPos hwnd %x at %d,%d (%dx%d) fl 0x%08x\n",
170 					pFrame->mhWndFrame, x, y, cx, cy, fl);
171 #endif
172 
173 	// first resize window if requested
174 	if ( (fl & SWP_SIZE) ) {
175 		ULONG	flag = SWP_SIZE;
176 		LONG	nX = 0, nY = 0;
177 		LONG	frameFrameX, frameFrameY, frameCaptionY;
178 
179 		ImplSalCalcFrameSize( pFrame, frameFrameX, frameFrameY, frameCaptionY );
180 		// if we change y size, we need to move the window down
181 		// because os2 window origin is lower left corner
182 		if (pFrame->maGeometry.nHeight != cy) {
183 			SWP		aSWP;
184 			WinQueryWindowPos( pFrame->mhWndFrame, &aSWP);
185 			nX = aSWP.x;
186 			nY = aSWP.y - (cy + 2*frameFrameY + frameCaptionY - aSWP.cy);
187 			flag |= SWP_MOVE;
188 		}
189 		WinSetWindowPos( pFrame->mhWndFrame, NULL, nX, nY,
190 			cx+2*frameFrameX, cy+2*frameFrameY+frameCaptionY, flag);
191 		fl = fl & ~SWP_SIZE;
192 	}
193 	else // otherwise get current size
194 	{
195 		SWP swp = {0};
196 		WinQueryWindowPos( pFrame->mhWndClient, &swp);
197 		cx = swp.cx;
198 		cy = swp.cy;
199 	}
200 
201 	// get parent window handle
202 	Os2SalFrame* pParentFrame = pFrame->mpParentFrame;
203 
204 	// use desktop if parent is not defined
205 	hParent = pParentFrame ? pParentFrame->mhWndClient : HWND_DESKTOP;
206 	// if parent is not visible, use desktop as reference
207 	hParent = WinIsWindowVisible( hParent) ? hParent : HWND_DESKTOP;
208 
209 	WinQueryWindowPos( hParent, &swpOwner);
210 
211 	//YD adjust to owner coordinates only when moving and not centering
212 	//if (!(fl & SWP_CENTER) && (fl & SWP_MOVE))
213 	if ((fl & SWP_MOVE))
214 	{
215 
216 		// if SWP_CENTER is specified, change position to parent center
217 		if (fl & SWP_CENTER) {
218 			ptlOwner.x = (swpOwner.cx - cx) / 2;
219 			ptlOwner.y = (swpOwner.cy - cy) / 2;
220 #if OSL_DEBUG_LEVEL>0
221 			debug_printf( "_WinSetWindowPos SWP_CENTER\n");
222 #endif
223 			fl = fl & ~SWP_CENTER;
224 		} else {
225 			// coords are relative to parent frame client area, map to screen
226 			// map Y to OS/2 system coordinates
227 			ptlOwner.x = x;
228 			ptlOwner.y = swpOwner.cy - (y + cy);
229 
230 #if OSL_DEBUG_LEVEL>0
231 			debug_printf( "_WinSetWindowPos owner 0x%x at %d,%d (%dx%d) OS2\n",
232 				hParent, ptlOwner.x, ptlOwner.y, swpOwner.cx, swpOwner.cy);
233 #endif
234 		}
235 		// map from client area to screen
236 		WinMapWindowPoints( hParent, HWND_DESKTOP, &ptlOwner, 1);
237 		x = ptlOwner.x;
238 		y = ptlOwner.y;
239 
240 #if OSL_DEBUG_LEVEL>0
241 		debug_printf( "_WinSetWindowPos owner 0x%x at %d,%d (%dx%d) MAPPED OS2\n",
242 			hParent, ptlOwner.x, ptlOwner.y, swpOwner.cx, swpOwner.cy);
243 #endif
244 	}
245 
246 #if OSL_DEBUG_LEVEL>0
247 	debug_printf( "<WinSetWindowPos hwnd %x at %d,%d (%dx%d) fl=%x\n",
248 					pFrame->mhWndFrame, x, y, cx, cy, fl);
249 #endif
250 	return WinSetWindowPos( pFrame->mhWndFrame, hwndInsertBehind, x, y, 0, 0, fl);
251 }
252 
253 // =======================================================================
254 
255 #if OSL_DEBUG_LEVEL > 0
dumpWindowInfo(char * fnc,HWND hwnd)256 static void dumpWindowInfo( char* fnc, HWND hwnd)
257 {
258 	SWP aSWP;
259 	HWND	hwnd2;
260 	char	szTitle[256];
261 
262 #if 0
263 	_WinQueryWindowPos( hwnd, &aSWP );
264 	strcpy(szTitle,"");
265 	WinQueryWindowText(hwnd, sizeof(szTitle), szTitle);
266 	debug_printf( "%s: window %08x at %d,%d (size %dx%d) '%s'\n", fnc, hwnd,
267 				aSWP.x, aSWP.y, aSWP.cx, aSWP.cy, szTitle);
268 	hwnd2 = WinQueryWindow(hwnd, QW_PARENT);
269 	_WinQueryWindowPos( hwnd2, &aSWP );
270 	strcpy(szTitle,"");
271 	WinQueryWindowText(hwnd2, sizeof(szTitle), szTitle);
272 	debug_printf( "%s: parent %08x at %d,%d (size %dx%d) '%s'\n", fnc, hwnd2,
273 				aSWP.x, aSWP.y, aSWP.cx, aSWP.cy, szTitle);
274 	hwnd2 = WinQueryWindow(hwnd, QW_OWNER);
275 	_WinQueryWindowPos( hwnd2, &aSWP );
276 	strcpy(szTitle,"");
277 	WinQueryWindowText(hwnd2, sizeof(szTitle), szTitle);
278 	debug_printf( "%s: owner %08x at %d,%d (size %dx%d) '%s'\n", fnc, hwnd2,
279 				aSWP.x, aSWP.y, aSWP.cx, aSWP.cy, szTitle);
280 #endif
281 }
282 #endif
283 
284 // =======================================================================
285 
286 #ifdef ENABLE_IME
287 
288 struct ImplSalIMEProc
289 {
290     ULONG       nOrd;
291     PFN*        pProc;
292 };
293 
294 #define SAL_IME_PROC_COUNT          12
295 
296 // -----------------------------------------------------------------------
297 
GetSalIMEData()298 static SalIMEData* GetSalIMEData()
299 {
300     SalData* pSalData = GetSalData();
301 
302     if ( !pSalData->mbIMEInit )
303     {
304         pSalData->mbIMEInit = TRUE;
305 
306         HMODULE hMod = 0;
307         if ( 0 == DosLoadModule( NULL, 0, "OS2IM", &hMod ) )
308         {
309             SalIMEData*     pIMEData = new SalIMEData;
310             sal_Bool            bError = FALSE;
311             ImplSalIMEProc  aProcAry[SAL_IME_PROC_COUNT] =
312             {
313             { 101, (PFN*)&(pIMEData->mpAssocIME) },
314             { 104, (PFN*)&(pIMEData->mpGetIME) },
315             { 106, (PFN*)&(pIMEData->mpReleaseIME) },
316             { 117, (PFN*)&(pIMEData->mpSetConversionFont) },
317             { 144, (PFN*)&(pIMEData->mpSetConversionFontSize) },
318             { 118, (PFN*)&(pIMEData->mpGetConversionString) },
319             { 122, (PFN*)&(pIMEData->mpGetResultString) },
320             { 115, (PFN*)&(pIMEData->mpSetCandidateWin) },
321             { 130, (PFN*)&(pIMEData->mpQueryIMEProperty) },
322             { 131, (PFN*)&(pIMEData->mpRequestIME) },
323             { 128, (PFN*)&(pIMEData->mpSetIMEMode) },
324             { 127, (PFN*)&(pIMEData->mpQueryIMEMode) }
325             };
326 
327             pIMEData->mhModIME = hMod;
328             for ( USHORT i = 0; i < SAL_IME_PROC_COUNT; i++ )
329             {
330                 if ( 0 != DosQueryProcAddr( pIMEData->mhModIME, aProcAry[i].nOrd, 0, aProcAry[i].pProc ) )
331                 {
332                     bError = TRUE;
333                     break;
334                 }
335             }
336 
337             if ( bError )
338             {
339                 DosFreeModule( pIMEData->mhModIME );
340                 delete pIMEData;
341             }
342             else
343                 pSalData->mpIMEData = pIMEData;
344         }
345     }
346 
347     return pSalData->mpIMEData;
348 }
349 
350 // -----------------------------------------------------------------------
351 
ImplReleaseSALIMEData()352 void ImplReleaseSALIMEData()
353 {
354     SalData* pSalData = GetSalData();
355 
356     if ( pSalData->mpIMEData )
357     {
358         DosFreeModule( pSalData->mpIMEData->mhModIME );
359         delete pSalData->mpIMEData;
360     }
361 }
362 
363 #endif
364 
365 // =======================================================================
366 
ImplSaveFrameState(Os2SalFrame * pFrame)367 static void ImplSaveFrameState( Os2SalFrame* pFrame )
368 {
369     // Position, Groesse und Status fuer GetWindowState() merken
370     if ( !pFrame->mbFullScreen )
371     {
372         SWP aSWP;
373         sal_Bool bVisible = WinIsWindowVisible( pFrame->mhWndFrame);
374 
375         // Query actual state (maState uses screen coords)
376         WinQueryWindowPos( pFrame->mhWndFrame, &aSWP );
377 
378         if ( aSWP.fl & SWP_MINIMIZE )
379         {
380 #if OSL_DEBUG_LEVEL>0
381 			debug_printf("Os2SalFrame::GetWindowState %08x SAL_FRAMESTATE_MINIMIZED\n",
382 					pFrame->mhWndFrame);
383 #endif
384             pFrame->maState.mnState |= SAL_FRAMESTATE_MINIMIZED;
385             if ( bVisible )
386                 pFrame->mnShowState = SWP_SHOWMAXIMIZED;
387         }
388         else if ( aSWP.fl & SWP_MAXIMIZE )
389         {
390 #if OSL_DEBUG_LEVEL>0
391 			debug_printf("Os2SalFrame::GetWindowState %08x SAL_FRAMESTATE_MAXIMIZED\n",
392 					pFrame->mhWndFrame);
393 #endif
394             pFrame->maState.mnState &= ~SAL_FRAMESTATE_MINIMIZED;
395             pFrame->maState.mnState |= SAL_FRAMESTATE_MAXIMIZED;
396             if ( bVisible )
397                 pFrame->mnShowState = SWP_SHOWMINIMIZED;
398             pFrame->mbRestoreMaximize = TRUE;
399         }
400         else
401         {
402 			LONG nFrameX, nFrameY, nCaptionY;
403 			ImplSalCalcFrameSize( pFrame, nFrameX, nFrameY, nCaptionY );
404 			// to be consistent with Unix, the frame state is without(!) decoration
405 			long nTopDeco = nFrameY + nCaptionY;
406 			long nLeftDeco = nFrameX;
407 			long nBottomDeco = nFrameY;
408 			long nRightDeco = nFrameX;
409 
410             pFrame->maState.mnState &= ~(SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED);
411             // subtract decoration, store screen coords
412             pFrame->maState.mnX      = aSWP.x+nLeftDeco;
413             pFrame->maState.mnY      = nScreenHeight - (aSWP.y+aSWP.cy)+nTopDeco;
414             pFrame->maState.mnWidth  = aSWP.cx-nLeftDeco-nRightDeco;
415             pFrame->maState.mnHeight = aSWP.cy-nTopDeco-nBottomDeco;
416 #if OSL_DEBUG_LEVEL>0
417 			debug_printf("Os2SalFrame::GetWindowState %08x (%dx%d) at %d,%d VCL\n",
418 					pFrame->mhWndFrame,
419 					pFrame->maState.mnWidth,pFrame->maState.mnHeight,pFrame->maState.mnX,pFrame->maState.mnY);
420 #endif
421             if ( bVisible )
422                 pFrame->mnShowState = SWP_SHOWNORMAL;
423             pFrame->mbRestoreMaximize = FALSE;
424 			//debug_printf( "ImplSaveFrameState: window %08x at %d,%d (size %dx%d)\n",
425 			//	pFrame->mhWndFrame,
426 			//	pFrame->maState.mnX, pFrame->maState.mnY, pFrame->maState.mnWidth, pFrame->maState.mnHeight);
427         }
428     }
429 }
430 
431 // -----------------------------------------------------------------------
432 
ImplSalCallbackDummy(void *,SalFrame *,USHORT,const void *)433 long ImplSalCallbackDummy( void*, SalFrame*, USHORT, const void* )
434 {
435     return 0;
436 }
437 
438 // -----------------------------------------------------------------------
439 
ImplSalCalcFrameSize(HWND hWnd,LONG & nFrameX,LONG & nFrameY,LONG & nCaptionY)440 static void ImplSalCalcFrameSize( HWND hWnd,
441                                   LONG& nFrameX, LONG& nFrameY, LONG& nCaptionY )
442 {
443     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
444     if ( !pFrame )
445         return;
446 	return ImplSalCalcFrameSize( pFrame, nFrameX, nFrameY, nCaptionY );
447 }
448 
ImplSalCalcFrameSize(const Os2SalFrame * pFrame,LONG & nFrameX,LONG & nFrameY,LONG & nCaptionY)449 static void ImplSalCalcFrameSize( const Os2SalFrame* pFrame,
450                                   LONG& nFrameX, LONG& nFrameY, LONG& nCaptionY )
451 {
452     if ( pFrame->mbSizeBorder )
453     {
454         nFrameX = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );
455         nFrameY = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );
456     }
457     else if ( pFrame->mbFixBorder )
458     {
459         nFrameX = WinQuerySysValue( HWND_DESKTOP, SV_CXDLGFRAME );
460         nFrameY = WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME );
461     }
462     else if ( pFrame->mbBorder )
463     {
464         nFrameX = WinQuerySysValue( HWND_DESKTOP, SV_CXBORDER );
465         nFrameY = WinQuerySysValue( HWND_DESKTOP, SV_CYBORDER );
466     }
467     else
468     {
469         nFrameX = 0;
470         nFrameY = 0;
471     }
472     if ( pFrame->mbCaption )
473         nCaptionY = WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR );
474     else
475         nCaptionY = 0;
476 
477 #if OSL_DEBUG_LEVEL>0
478 	//if (_bCapture)
479 		debug_printf("ImplSalCalcFrameSize 0x%08x x=%d y=%d t=%d\n", pFrame->mhWndFrame, nFrameX, nFrameY, nCaptionY);
480 #endif
481 }
482 
483 // -----------------------------------------------------------------------
484 
ImplSalCalcFullScreenSize(const Os2SalFrame * pFrame,LONG & rX,LONG & rY,LONG & rDX,LONG & rDY)485 static void ImplSalCalcFullScreenSize( const Os2SalFrame* pFrame,
486                                        LONG& rX, LONG& rY, LONG& rDX, LONG& rDY )
487 {
488     // set window to screen size
489     LONG nFrameX, nFrameY, nCaptionY;
490     LONG rScreenDX = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
491     LONG rScreenDY = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
492 
493     // Framegroessen berechnen
494     ImplSalCalcFrameSize( pFrame, nFrameX, nFrameY, nCaptionY );
495 
496     rX  = -nFrameX;
497     rY  = -(nFrameY+nCaptionY);
498     rDX = rScreenDX+(nFrameX*2);
499     rDY = rScreenDY+(nFrameY*2)+nCaptionY;
500 }
501 
502 // -----------------------------------------------------------------------
503 
ImplSalFrameFullScreenPos(Os2SalFrame * pFrame,sal_Bool bAlways=FALSE)504 static void ImplSalFrameFullScreenPos( Os2SalFrame* pFrame, sal_Bool bAlways = FALSE )
505 {
506     SWP aSWP;
507     _WinQueryWindowPos( pFrame, &aSWP );
508     if ( bAlways || !(aSWP.fl & SWP_MINIMIZE) )
509     {
510         // set window to screen size
511         LONG nX;
512         LONG nY;
513         LONG nWidth;
514         LONG nHeight;
515         ImplSalCalcFullScreenSize( pFrame, nX, nY, nWidth, nHeight );
516         _WinSetWindowPos( pFrame, 0,
517                          nX, nY, nWidth, nHeight,
518                          SWP_MOVE | SWP_SIZE );
519     }
520 }
521 
522 // -----------------------------------------------------------------------
523 
524 // Uebersetzungstabelle von System-Keycodes in StarView-Keycodes
525 #define KEY_TAB_SIZE     (VK_ENDDRAG+1)
526 
527 static USHORT aImplTranslateKeyTab[KEY_TAB_SIZE] =
528 {
529     // StarView-Code      System-Code                         Index
530     0,                    //                                  0x00
531     0,                    // VK_BUTTON1                       0x01
532     0,                    // VK_BUTTON2                       0x02
533     0,                    // VK_BUTTON3                       0x03
534     0,                    // VK_BREAK                         0x04
535     KEY_BACKSPACE,        // VK_BACKSPACE                     0x05
536     KEY_TAB,              // VK_TAB                           0x06
537     KEY_TAB,              // VK_BACKTAB                       0x07
538     KEY_RETURN,           // VK_NEWLINE                       0x08
539     0,                    // VK_SHIFT                         0x09
540     0,                    // VK_CTRL                          0x0A
541     0,                    // VK_ALT                           0x0B
542     0,                    // VK_ALTGRAF                       0x0C
543     0,                    // VK_PAUSE                         0x0D
544     0,                    // VK_CAPSLOCK                      0x0E
545     KEY_ESCAPE,           // VK_ESC                           0x0F
546     KEY_SPACE,            // VK_SPACE                         0x10
547     KEY_PAGEUP,           // VK_PAGEUP                        0x11
548     KEY_PAGEDOWN,         // VK_PAGEDOWN                      0x12
549     KEY_END,              // VK_END                           0x13
550     KEY_HOME,             // VK_HOME                          0x14
551     KEY_LEFT,             // VK_LEFT                          0x15
552     KEY_UP,               // VK_UP                            0x16
553     KEY_RIGHT,            // VK_RIGHT                         0x17
554     KEY_DOWN,             // VK_DOWN                          0x18
555     0,                    // VK_PRINTSCRN                     0x19
556     KEY_INSERT,           // VK_INSERT                        0x1A
557     KEY_DELETE,           // VK_DELETE                        0x1B
558     0,                    // VK_SCRLLOCK                      0x1C
559     0,                    // VK_NUMLOCK                       0x1D
560     KEY_RETURN,           // VK_ENTER                         0x1E
561     0,                    // VK_SYSRQ                         0x1F
562     KEY_F1,               // VK_F1                            0x20
563     KEY_F2,               // VK_F2                            0x21
564     KEY_F3,               // VK_F3                            0x22
565     KEY_F4,               // VK_F4                            0x23
566     KEY_F5,               // VK_F5                            0x24
567     KEY_F6,               // VK_F6                            0x25
568     KEY_F7,               // VK_F7                            0x26
569     KEY_F8,               // VK_F8                            0x27
570     KEY_F9,               // VK_F9                            0x28
571     KEY_F10,              // VK_F10                           0x29
572     KEY_F11,              // VK_F11                           0x2A
573     KEY_F12,              // VK_F12                           0x2B
574     KEY_F13,              // VK_F13                           0x2C
575     KEY_F14,              // VK_F14                           0x2D
576     KEY_F15,              // VK_F15                           0x2E
577     KEY_F16,              // VK_F16                           0x2F
578     KEY_F17,              // VK_F17                           0x30
579     KEY_F18,              // VK_F18                           0x31
580     KEY_F19,              // VK_F19                           0x32
581     KEY_F20,              // VK_F20                           0x33
582     KEY_F21,              // VK_F21                           0x34
583     KEY_F22,              // VK_F22                           0x35
584     KEY_F23,              // VK_F23                           0x36
585     KEY_F24,              // VK_F24                           0x37
586     0                     // VK_ENDDRAG                       0x38
587 };
588 
589 // =======================================================================
590 
ImplSalCreateFrame(Os2SalInstance * pInst,HWND hWndParent,ULONG nSalFrameStyle)591 SalFrame* ImplSalCreateFrame( Os2SalInstance* pInst, HWND hWndParent, ULONG nSalFrameStyle )
592 {
593     SalData*    	pSalData = GetSalData();
594     Os2SalFrame*   	pFrame = new Os2SalFrame;
595     HWND        	hWndFrame;
596     HWND        	hWndClient;
597     ULONG    		nFrameFlags = FCF_NOBYTEALIGN | FCF_SCREENALIGN;
598     ULONG    		nFrameStyle = 0;
599     ULONG    		nClientStyle = WS_CLIPSIBLINGS;
600     sal_Bool        	bSubFrame = FALSE;
601 
602 #if OSL_DEBUG_LEVEL>0
603     debug_printf(">ImplSalCreateFrame hWndParent 0x%x, nSalFrameStyle 0x%x\n", hWndParent, nSalFrameStyle);
604 #endif
605 
606 	if ( hWndParent )
607 	{
608 		bSubFrame = TRUE;
609 		pFrame->mbNoIcon = TRUE;
610 	}
611 
612     // determine creation data (bei Moveable nehmen wir DLG-Border, damit
613     // es besser aussieht)
614     if ( nSalFrameStyle & SAL_FRAME_STYLE_CLOSEABLE )
615         nFrameFlags |= FCF_CLOSEBUTTON;
616 
617 	if ( nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE ) {
618 		pFrame->mbCaption = TRUE;
619 		nFrameStyle = WS_ANIMATE;
620 		nFrameFlags |= FCF_SYSMENU | FCF_TITLEBAR | FCF_DLGBORDER;
621 		if ( !hWndParent )
622 			nFrameFlags |= FCF_MINBUTTON;
623 
624 		if ( nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE )
625 		{
626 			pFrame->mbSizeBorder = TRUE;
627 			nFrameFlags |= FCF_SIZEBORDER;
628 			if ( !hWndParent )
629 				nFrameFlags |= FCF_MAXBUTTON;
630 		}
631 		else
632 			pFrame->mbFixBorder = TRUE;
633 
634 		// add task list style if not a tool window
635 		if ( !(nSalFrameStyle & SAL_FRAME_STYLE_TOOLWINDOW) ) {
636 			nFrameFlags |= FCF_TASKLIST;
637 		}
638 	}
639 
640 	if( nSalFrameStyle & SAL_FRAME_STYLE_TOOLWINDOW )
641 	{
642 		pFrame->mbNoIcon = TRUE;
643 		// YD gives small caption -> nExSysStyle |= WS_EX_TOOLWINDOW;
644 	}
645 
646     if ( nSalFrameStyle & SAL_FRAME_STYLE_FLOAT )
647     {
648         //nExSysStyle |= WS_EX_TOOLWINDOW;
649         pFrame->mbFloatWin = TRUE;
650     }
651     //if( nSalFrameStyle & SAL_FRAME_STYLE_TOOLTIP )
652     //    nExSysStyle |= WS_EX_TOPMOST;
653 
654     // init frame data
655     pFrame->mnStyle = nSalFrameStyle;
656 
657     // determine show style
658     pFrame->mnShowState = SWP_SHOWNORMAL;
659 
660     // create frame
661 	//YD FIXME this is a potential bug with multiple threads and cuncurrent
662 	//window creation, because this field is accessed in
663 	//WM_CREATE to get window data,
664     pSalData->mpCreateFrame = pFrame;
665 
666 	//YD FIXME if SAL_FRAME_CHILD is specified, use hWndParent as parent handle...
667     hWndFrame = WinCreateStdWindow( HWND_DESKTOP, nFrameStyle, &nFrameFlags,
668 					(PSZ)(bSubFrame ? SAL_SUBFRAME_CLASSNAME : SAL_FRAME_CLASSNAME),
669 					NULL,
670 					nClientStyle, 0, 0, &hWndClient );
671     debug_printf("ImplSalCreateFrame hWndParent 0x%x, hWndFrame 0x%x, hWndClient 0x%x\n", hWndParent, hWndFrame, hWndClient);
672     if ( !hWndFrame )
673     {
674         delete pFrame;
675         return NULL;
676     }
677 
678     // Parent setzen (Owner)
679     if ( hWndParent != 0 && hWndParent != HWND_DESKTOP )
680         WinSetOwner( hWndFrame, hWndParent );
681 
682     Os2SalFrame* pParentFrame = GetWindowPtr( hWndParent );
683     if ( pParentFrame )
684 		pFrame->mpParentFrame = pParentFrame;
685 
686     // since os2 windows always have a close button, always set icon
687     WinSendMsg( hWndFrame, WM_SETICON, (MPARAM)pInst->mhAppIcon, (MPARAM)0 );
688 
689     // If we have an Window with an Caption Bar and without
690     // an MaximizeBox, we change the SystemMenu
691     if ( (nFrameFlags & (FCF_TITLEBAR | FCF_MAXBUTTON)) == (FCF_TITLEBAR) )
692     {
693         HWND hSysMenu = WinWindowFromID( hWndFrame, FID_SYSMENU );
694         if ( hSysMenu )
695         {
696             if ( !(nFrameFlags & (FCF_MINBUTTON | FCF_MAXBUTTON)) )
697 				WinEnableMenuItem(hSysMenu, SC_RESTORE, FALSE);
698             if ( !(nFrameFlags & FCF_MINBUTTON) )
699 				WinEnableMenuItem(hSysMenu, SC_MINIMIZE, FALSE);
700             if ( !(nFrameFlags & FCF_MAXBUTTON) )
701 				WinEnableMenuItem(hSysMenu, SC_MAXIMIZE, FALSE);
702             if ( !(nFrameFlags & FCF_SIZEBORDER) )
703 				WinEnableMenuItem(hSysMenu, SC_SIZE, FALSE);
704         }
705     }
706     if ( (nFrameFlags & FCF_SYSMENU) && !(nSalFrameStyle & SAL_FRAME_STYLE_CLOSEABLE) )
707     {
708         HWND hSysMenu = WinWindowFromID( hWndFrame, FID_SYSMENU );
709         if ( hSysMenu )
710         {
711             WinEnableMenuItem(hSysMenu, SC_CLOSE, FALSE);
712         }
713     }
714 
715     // ticket#124 subclass frame window: we need to intercept TRACK message
716     aSalShlData.mpFrameProc = WinSubclassWindow( hWndFrame, SalFrameSubClassWndProc);
717 
718     // init OS/2 frame data
719     pFrame->mhAB            = pInst->mhAB;
720 
721     // YD 18/08 under OS/2, invisible frames have size 0,0 at 0,0, so
722     // we need to set an initial size/position manually
723     SWP aSWP;
724     memset( &aSWP, 0, sizeof( aSWP ) );
725     WinQueryTaskSizePos( pInst->mhAB, 0, &aSWP );
726     WinSetWindowPos( hWndFrame, NULL, aSWP.x, aSWP.y, aSWP.cx, aSWP.cy,
727                      SWP_MOVE | SWP_SIZE);
728 
729 #ifdef ENABLE_IME
730     // Input-Context einstellen
731     SalIMEData* pIMEData = GetSalIMEData();
732     if ( pIMEData )
733     {
734         pFrame->mhIMEContext = 0;
735         if ( 0 != pIMEData->mpAssocIME( hWndClient, pFrame->mhIMEContext, &pFrame->mhDefIMEContext ) )
736             pFrame->mhDefIMEContext = 0;
737     }
738     else
739     {
740         pFrame->mhIMEContext = 0;
741         pFrame->mhDefIMEContext = 0;
742     }
743 #endif
744 
745     RECTL rectl;
746     _WinQueryWindowRect( hWndClient, &rectl );
747     pFrame->mnWidth  = rectl.xRight;
748     pFrame->mnHeight = rectl.yBottom;
749     debug_printf( "ImplSalCreateFrame %dx%d\n", pFrame->mnWidth, pFrame->mnHeight);
750     ImplSaveFrameState( pFrame );
751     pFrame->mbDefPos = TRUE;
752 
753 	UpdateFrameGeometry( hWndFrame, pFrame );
754 
755     if( pFrame->mnShowState == SWP_SHOWMAXIMIZED )
756 	{
757 		// #96084 set a useful internal window size because
758 		// the window will not be maximized (and the size updated) before show()
759         SetMaximizedFrameGeometry( hWndFrame, pFrame );
760 	}
761 
762 #if OSL_DEBUG_LEVEL > 1
763 	dumpWindowInfo( "<ImplSalCreateFrame (exit)", hWndFrame);
764 #endif
765 
766     return pFrame;
767 }
768 
769 // =======================================================================
770 
Os2SalFrame()771 Os2SalFrame::Os2SalFrame()
772 {
773     SalData* pSalData = GetSalData();
774 
775     mbGraphics          = NULL;
776     mhPointer           = WinQuerySysPointer( HWND_DESKTOP, SPTR_ARROW, FALSE );
777     mpGraphics          = NULL;
778     mpInst              = NULL;
779     mbFullScreen        = FALSE;
780     mbAllwayOnTop       = FALSE;
781     mbVisible           = FALSE;
782     mbMinHide           = FALSE;
783     mbInShow            = FALSE;
784     mbRestoreMaximize   = FALSE;
785     mbInMoveMsg         = FALSE;
786     mbInSizeMsg         = FALSE;
787     mbDefPos            = TRUE;
788     mbOverwriteState    = TRUE;
789     mbHandleIME         = FALSE;
790     mbConversionMode    = FALSE;
791     mbCandidateMode     = FALSE;
792     mbCaption           = FALSE;
793     //mhDefIMEContext     = 0;
794     mpGraphics          = NULL;
795     mnShowState         = SWP_SHOWNORMAL;
796     mnWidth             = 0;
797     mnHeight            = 0;
798     mnMinWidth          = 0;
799     mnMinHeight         = 0;
800     mnMaxWidth          = SHRT_MAX;
801     mnMaxHeight         = SHRT_MAX;
802     mnInputLang         = 0;
803     mnKeyboardHandle    = 0;
804     mbGraphics          = FALSE;
805     mbCaption           = FALSE;
806     mbBorder            = FALSE;
807     mbFixBorder         = FALSE;
808     mbSizeBorder        = FALSE;
809     mbFullScreen        = FALSE;
810     //mbPresentation      = FALSE;
811     mbInShow            = FALSE;
812     mbRestoreMaximize   = FALSE;
813     mbInMoveMsg         = FALSE;
814     mbInSizeMsg         = FALSE;
815     //mbFullScreenToolWin = FALSE;
816     mbDefPos            = TRUE;
817     mbOverwriteState    = TRUE;
818     //mbIME               = FALSE;
819     mbHandleIME         = FALSE;
820     //mbSpezIME           = FALSE;
821     //mbAtCursorIME       = FALSE;
822     mbCandidateMode     = FALSE;
823     mbFloatWin          = FALSE;
824     mbNoIcon            = FALSE;
825     //mSelectedhMenu      = 0;
826     //mLastActivatedhMenu = 0;
827 	mpParentFrame		= NULL;
828 
829     memset( &maState, 0, sizeof( SalFrameState ) );
830     maSysData.nSize     = sizeof( SystemEnvData );
831     memset( &maGeometry, 0, sizeof( maGeometry ) );
832 
833     // insert frame in framelist
834     mpNextFrame = pSalData->mpFirstFrame;
835     pSalData->mpFirstFrame = this;
836 }
837 
838 // -----------------------------------------------------------------------
839 
~Os2SalFrame()840 Os2SalFrame::~Os2SalFrame()
841 {
842     SalData* pSalData = GetSalData();
843 
844     // destroy DC
845     if ( mpGraphics )
846     {
847         ImplSalDeInitGraphics( mpGraphics );
848         WinReleasePS( mpGraphics->mhPS );
849         delete mpGraphics;
850     }
851 
852     // destroy system frame
853     WinDestroyWindow( mhWndFrame );
854 
855     // remove frame from framelist
856     if ( this == pSalData->mpFirstFrame )
857         pSalData->mpFirstFrame = mpNextFrame;
858     else
859     {
860         Os2SalFrame* pTempFrame = pSalData->mpFirstFrame;
861         while ( pTempFrame->mpNextFrame != this )
862             pTempFrame = pTempFrame->mpNextFrame;
863 
864         pTempFrame->mpNextFrame = mpNextFrame;
865     }
866 }
867 
868 // -----------------------------------------------------------------------
869 
ImplWinGetDC(HWND hWnd)870 static HDC ImplWinGetDC( HWND hWnd )
871 {
872     HDC hDC = WinQueryWindowDC( hWnd );
873     if ( !hDC )
874         hDC = WinOpenWindowDC( hWnd );
875     return hDC;
876 }
877 
878 // -----------------------------------------------------------------------
879 
GetGraphics()880 SalGraphics* Os2SalFrame::GetGraphics()
881 {
882     if ( mbGraphics )
883         return NULL;
884 
885     if ( !mpGraphics )
886     {
887         SalData* pSalData = GetSalData();
888         mpGraphics = new Os2SalGraphics;
889         mpGraphics->mhPS      = WinGetPS( mhWndClient );
890         mpGraphics->mhDC      = ImplWinGetDC( mhWndClient );
891         mpGraphics->mhWnd     = mhWndClient;
892         mpGraphics->mnHeight  = mnHeight;
893         mpGraphics->mbPrinter = FALSE;
894         mpGraphics->mbVirDev  = FALSE;
895         mpGraphics->mbWindow  = TRUE;
896         mpGraphics->mbScreen  = TRUE;
897         ImplSalInitGraphics( mpGraphics );
898         mbGraphics = TRUE;
899     }
900     else
901         mbGraphics = TRUE;
902 
903     return mpGraphics;
904 }
905 
906 // -----------------------------------------------------------------------
907 
ReleaseGraphics(SalGraphics *)908 void Os2SalFrame::ReleaseGraphics( SalGraphics* )
909 {
910     mbGraphics = FALSE;
911 }
912 
913 // -----------------------------------------------------------------------
914 
PostEvent(void * pData)915 sal_Bool Os2SalFrame::PostEvent( void* pData )
916 {
917     return (sal_Bool)WinPostMsg( mhWndClient, SAL_MSG_USEREVENT, 0, (MPARAM)pData );
918 }
919 
920 // -----------------------------------------------------------------------
921 
SetTitle(const XubString & rTitle)922 void Os2SalFrame::SetTitle( const XubString& rTitle )
923 {
924     // set window title
925 	ByteString title( rTitle, gsl_getSystemTextEncoding() );
926 	debug_printf("Os2SalFrame::SetTitle %x '%s'\n", mhWndFrame, title.GetBuffer() );
927     WinSetWindowText( mhWndFrame, title.GetBuffer() );
928 }
929 
930 // -----------------------------------------------------------------------
931 
SetIcon(USHORT nIcon)932 void Os2SalFrame::SetIcon( USHORT nIcon )
933 {
934 	debug_printf("Os2SalFrame::SetIcon\n");
935 
936     // If we have a window without an Icon (for example a dialog), ignore this call
937     if ( mbNoIcon )
938         return;
939 
940     // 0 means default (class) icon
941     HPOINTER hIcon = NULL;
942     if ( !nIcon )
943         nIcon = 1;
944 
945     ImplLoadSalIcon( nIcon, hIcon );
946 
947     DBG_ASSERT( hIcon , "Os2SalFrame::SetIcon(): Could not load icon !" );
948 
949     // Icon setzen
950 	WinSendMsg( mhWndFrame, WM_SETICON, (MPARAM)hIcon, (MPARAM)0 );
951 }
952 
953 // -----------------------------------------------------------------------
954 
GetParent() const955 SalFrame* Os2SalFrame::GetParent() const
956 {
957 	//debug_printf("Os2SalFrame::GetParent\n");
958     return GetWindowPtr( WinQueryWindow(mhWndFrame, QW_OWNER) );
959 }
960 
961 // -----------------------------------------------------------------------
962 
ImplSalShow(HWND hWnd,ULONG bVisible,ULONG bNoActivate)963 static void ImplSalShow( HWND hWnd, ULONG bVisible, ULONG bNoActivate )
964 {
965     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
966     if ( !pFrame )
967         return;
968 
969     if ( bVisible )
970     {
971         pFrame->mbDefPos = FALSE;
972         pFrame->mbOverwriteState = TRUE;
973         pFrame->mbInShow = TRUE;
974 
975 #if OSL_DEBUG_LEVEL > 0
976 		debug_printf( "ImplSalShow hwnd %x visible flag %d, no activate: flag %d\n", hWnd, bVisible, bNoActivate);
977 #endif
978 
979         if( bNoActivate )
980 			WinSetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_SHOW);
981         else
982             WinSetWindowPos(hWnd, NULL, 0, 0, 0, 0, pFrame->mnShowState);
983 
984         pFrame->mbInShow = FALSE;
985 
986         // Direct Paint only, if we get the SolarMutx
987         if ( ImplSalYieldMutexTryToAcquire() )
988         {
989             WinUpdateWindow( hWnd );
990             ImplSalYieldMutexRelease();
991         }
992     }
993     else
994     {
995 #if OSL_DEBUG_LEVEL > 0
996 		debug_printf( "ImplSalShow hwnd %x HIDE\n");
997 #endif
998 		WinSetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_HIDE);
999     }
1000 }
1001 
1002 
1003 // -----------------------------------------------------------------------
1004 
1005 
SetExtendedFrameStyle(SalExtStyle nExtStyle)1006 void Os2SalFrame::SetExtendedFrameStyle( SalExtStyle nExtStyle )
1007 {
1008 }
1009 
1010 // -----------------------------------------------------------------------
1011 
Show(sal_Bool bVisible,sal_Bool bNoActivate)1012 void Os2SalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1013 {
1014     // Post this Message to the window, because this only works
1015     // in the thread of the window, which has create this window.
1016     // We post this message to avoid deadlocks
1017     if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1018         WinPostMsg( mhWndFrame, SAL_MSG_SHOW, (MPARAM)bVisible, (MPARAM)bNoActivate );
1019     else
1020         ImplSalShow( mhWndFrame, bVisible, bNoActivate );
1021 }
1022 
1023 // -----------------------------------------------------------------------
1024 
Enable(sal_Bool bEnable)1025 void Os2SalFrame::Enable( sal_Bool bEnable )
1026 {
1027     WinEnableWindow( mhWndFrame, bEnable );
1028 }
1029 
1030 // -----------------------------------------------------------------------
1031 
SetMinClientSize(long nWidth,long nHeight)1032 void Os2SalFrame::SetMinClientSize( long nWidth, long nHeight )
1033 {
1034     debug_printf("Os2SalFrame::SetMinClientSize\n");
1035     mnMinWidth  = nWidth;
1036     mnMinHeight = nHeight;
1037 }
1038 
SetMaxClientSize(long nWidth,long nHeight)1039 void Os2SalFrame::SetMaxClientSize( long nWidth, long nHeight )
1040 {
1041     debug_printf("Os2SalFrame::SetMaxClientSize\n");
1042     mnMaxWidth  = nWidth;
1043     mnMaxHeight = nHeight;
1044 }
1045 
1046 // -----------------------------------------------------------------------
1047 
SetPosSize(long nX,long nY,long nWidth,long nHeight,USHORT nFlags)1048 void Os2SalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight,
1049                                                    USHORT nFlags )
1050 {
1051     // calculation frame size
1052     USHORT 	nEvent = 0;
1053 	ULONG	nPosFlags = 0;
1054 
1055 #if OSL_DEBUG_LEVEL > 0
1056 	//dumpWindowInfo( "-Os2SalFrame::SetPosSize", mhWndFrame);
1057 	debug_printf( ">Os2SalFrame::SetPosSize go to %d,%d (%dx%d) VCL\n",nX,nY,nWidth,nHeight);
1058 #endif
1059 
1060 	SWP aSWP;
1061 	_WinQueryWindowPos( this, &aSWP );
1062     sal_Bool bVisible = WinIsWindowVisible( mhWndFrame );
1063     if ( !bVisible )
1064     {
1065         if ( mbFloatWin )
1066 			mnShowState = SWP_SHOW;
1067         else
1068 			mnShowState = SWP_SHOWNORMAL;
1069     }
1070     else
1071     {
1072         if ( (aSWP.fl & SWP_MINIMIZE) || (aSWP.fl & SWP_MAXIMIZE) )
1073 			WinSetWindowPos(mhWndFrame, NULL, 0, 0, 0, 0, SWP_RESTORE );
1074     }
1075 
1076     if ( (nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y)) ) {
1077         nPosFlags |= SWP_MOVE;
1078 #if OSL_DEBUG_LEVEL > 0
1079 		debug_printf( "-Os2SalFrame::SetPosSize MOVE to %d,%d\n", nX, nY);
1080 #endif
1081         //DBG_ASSERT( nX && nY, " Windowposition of (0,0) requested!" );
1082         nEvent = SALEVENT_MOVE;
1083 	}
1084 
1085     if ( (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) ) {
1086         nPosFlags |= SWP_SIZE;
1087 #if OSL_DEBUG_LEVEL > 0
1088 		debug_printf( "-Os2SalFrame::SetPosSize SIZE to %d,%d\n", nWidth,nHeight);
1089 #endif
1090         nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE;
1091 	}
1092 
1093     // Default-Position, dann zentrieren, ansonsten Position beibehalten
1094     if ( mbDefPos  && !(nPosFlags & SWP_MOVE))
1095     {
1096         // calculate bottom left corner of frame
1097         mbDefPos = FALSE;
1098 		nPosFlags |= SWP_MOVE | SWP_CENTER;
1099         nEvent = SALEVENT_MOVERESIZE;
1100 #if OSL_DEBUG_LEVEL > 10
1101 		debug_printf( "-Os2SalFrame::SetPosSize CENTER\n");
1102 		debug_printf( "-Os2SalFrame::SetPosSize default position to %d,%d\n", nX, nY);
1103 #endif
1104     }
1105 
1106     // Adjust Window in the screen
1107     sal_Bool bCheckOffScreen = TRUE;
1108 
1109     // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1110     if( (mnStyle & SAL_FRAME_STYLE_FLOAT) && !(mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
1111         bCheckOffScreen = FALSE;
1112 
1113     if( mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION )
1114     {
1115         // may be the window is currently being moved (mouse is captured), then no check is required
1116         if( mhWndClient == WinQueryCapture( HWND_DESKTOP) )
1117             bCheckOffScreen = FALSE;
1118         else
1119             bCheckOffScreen = TRUE;
1120     }
1121 
1122     if( bCheckOffScreen )
1123     {
1124         if ( nX+nWidth > nScreenWidth )
1125             nX = nScreenWidth - nWidth;
1126         if ( nY+nHeight > nScreenHeight )
1127             nY = nScreenHeight - nHeight;
1128         if ( nX < 0 )
1129             nX = 0;
1130         if ( nY < 0 )
1131             nY = 0;
1132     }
1133 
1134     // bring floating windows always to top
1135     // do not change zorder, otherwise tooltips will bring main window to top (ticket:14)
1136     //if( (mnStyle & SAL_FRAME_STYLE_FLOAT) )
1137     //    nPosFlags |= SWP_ZORDER; // do not change z-order
1138 
1139     // set new position
1140     _WinSetWindowPos( this, HWND_TOP, nX, nY, nWidth, nHeight, nPosFlags); // | SWP_RESTORE
1141 
1142     UpdateFrameGeometry( mhWndFrame, this );
1143 
1144     // Notification -- really ???
1145     if( nEvent )
1146         CallCallback( nEvent, NULL );
1147 
1148 #if OSL_DEBUG_LEVEL > 0
1149 	dumpWindowInfo( "<Os2SalFrame::SetPosSize (exit)", mhWndFrame);
1150 #endif
1151 
1152 }
1153 
1154 // -----------------------------------------------------------------------
1155 
SetParent(SalFrame * pNewParent)1156 void Os2SalFrame::SetParent( SalFrame* pNewParent )
1157 {
1158     APIRET rc;
1159 #if OSL_DEBUG_LEVEL>0
1160     debug_printf("Os2SalFrame::SetParent mhWndFrame 0x%08x to 0x%08x\n",
1161 			static_cast<Os2SalFrame*>(this)->mhWndFrame,
1162 			static_cast<Os2SalFrame*>(pNewParent)->mhWndClient);
1163 #endif
1164     Os2SalFrame::mbInReparent = TRUE;
1165     //rc = WinSetParent(static_cast<Os2SalFrame*>(this)->mhWndFrame,
1166     //                  static_cast<Os2SalFrame*>(pNewParent)->mhWndClient, TRUE);
1167     rc = WinSetOwner(static_cast<Os2SalFrame*>(this)->mhWndFrame,
1168                       static_cast<Os2SalFrame*>(pNewParent)->mhWndClient);
1169 	mpParentFrame = static_cast<Os2SalFrame*>(pNewParent);
1170     Os2SalFrame::mbInReparent = FALSE;
1171 }
1172 
SetPluginParent(SystemParentData * pNewParent)1173 bool Os2SalFrame::SetPluginParent( SystemParentData* pNewParent )
1174 {
1175     APIRET rc;
1176     if ( pNewParent->hWnd == 0 )
1177     {
1178         pNewParent->hWnd = HWND_DESKTOP;
1179     }
1180 
1181     Os2SalFrame::mbInReparent = TRUE;
1182     rc = WinSetOwner(static_cast<Os2SalFrame*>(this)->mhWndFrame,
1183                       pNewParent->hWnd);
1184     Os2SalFrame::mbInReparent = FALSE;
1185     return true;
1186 }
1187 
1188 
1189 // -----------------------------------------------------------------------
1190 
GetWorkArea(RECTL & rRect)1191 void Os2SalFrame::GetWorkArea( RECTL &rRect )
1192 {
1193     rRect.xLeft     = rRect.yTop = 0;
1194     rRect.xRight    = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN )-1;
1195     rRect.yBottom   = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN )-1;
1196 }
1197 
1198 // -----------------------------------------------------------------------
1199 
GetWorkArea(Rectangle & rRect)1200 void Os2SalFrame::GetWorkArea( Rectangle &rRect )
1201 {
1202     RECTL aRect;
1203 	GetWorkArea( aRect);
1204     rRect.nLeft     = aRect.xLeft;
1205     rRect.nRight    = aRect.xRight; // win -1;
1206     rRect.nTop      = aRect.yTop;
1207     rRect.nBottom   = aRect.yBottom; // win -1;
1208 }
1209 
1210 // -----------------------------------------------------------------------
1211 
GetClientSize(long & rWidth,long & rHeight)1212 void Os2SalFrame::GetClientSize( long& rWidth, long& rHeight )
1213 {
1214     rWidth  = maGeometry.nWidth;
1215     rHeight = maGeometry.nHeight;
1216 }
1217 
1218 // -----------------------------------------------------------------------
1219 
SetWindowState(const SalFrameState * pState)1220 void Os2SalFrame::SetWindowState( const SalFrameState* pState )
1221 {
1222 	LONG	nX;
1223 	LONG 	nY;
1224 	LONG 	nWidth;
1225 	LONG 	nHeight;
1226 	ULONG	nPosSize = 0;
1227 
1228 #if OSL_DEBUG_LEVEL>0
1229 	debug_printf("Os2SalFrame::SetWindowState\n");
1230 	debug_printf("Os2SalFrame::SetWindowState %08x (%dx%d) at %d,%d VCL\n",
1231 		mhWndFrame,
1232 		pState->mnWidth,pState->mnHeight,pState->mnX,pState->mnY);
1233 #endif
1234 
1235     sal_Bool bVisible = WinIsWindowVisible( mhWndFrame );
1236 
1237     // get screen coordinates
1238     SWP	aSWP;
1239     WinQueryWindowPos( mhWndFrame, &aSWP );
1240 	LONG nFrameX, nFrameY, nCaptionY;
1241 	ImplSalCalcFrameSize( this, nFrameX, nFrameY, nCaptionY );
1242 
1243     long nTopDeco = nFrameY + nCaptionY;
1244     long nLeftDeco = nFrameX;
1245     long nBottomDeco = nFrameY;
1246     long nRightDeco = nFrameX;
1247 
1248     // Fenster-Position/Groesse in den Bildschirm einpassen
1249     if ((pState->mnMask & (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y)) )
1250         nPosSize |= SWP_MOVE;
1251     if ((pState->mnMask & (SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)) )
1252         nPosSize |= SWP_SIZE;
1253 
1254     if ( pState->mnMask & SAL_FRAMESTATE_MASK_X )
1255         nX = (int)pState->mnX - nLeftDeco;
1256     else
1257         nX = aSWP.x;
1258 
1259 	// keep Y inverted since height is still unknown, will invert later
1260     if ( pState->mnMask & SAL_FRAMESTATE_MASK_Y )
1261         nY = (int)pState->mnY - nTopDeco;
1262     else
1263         nY = nScreenHeight - (aSWP.y+aSWP.cy);
1264 
1265     if ( pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH )
1266         nWidth = (int)pState->mnWidth + nLeftDeco + nRightDeco;
1267     else
1268         nWidth = aSWP.cx;
1269     if ( pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT )
1270         nHeight = (int)pState->mnHeight + nTopDeco + nBottomDeco;
1271     else
1272         nHeight = aSWP.cy;
1273 
1274 #if OSL_DEBUG_LEVEL>0
1275 	debug_printf("Os2SalFrame::SetWindowState (%dx%d) at %d,%d\n", nWidth,nHeight,nX,nY);
1276 #endif
1277 
1278     // Adjust Window in the screen:
1279     // if it does not fit into the screen do nothing, ie default pos/size will be used
1280     // if there is an overlap with the screen border move the window while keeping its size
1281 
1282     //if( nWidth > nScreenWidth || nHeight > nScreenHeight )
1283     //    nPosSize |= (SWP_NOMOVE | SWP_NOSIZE);
1284 
1285     if ( nX+nWidth > nScreenWidth )
1286         nX = (nScreenWidth) - nWidth;
1287     if ( nY+nHeight > nScreenHeight )
1288         nY = (nScreenHeight) - nHeight;
1289     if ( nX < 0 )
1290         nX = 0;
1291     if ( nY < 0 )
1292         nY = 0;
1293 
1294     // Restore-Position setzen
1295 	SWP aPlacement;
1296 	WinQueryWindowPos( mhWndFrame, &aPlacement );
1297 
1298     // Status setzen
1299 	bVisible = WinIsWindowVisible( mhWndFrame);
1300 	sal_Bool bUpdateHiddenFramePos = FALSE;
1301     if ( !bVisible )
1302     {
1303         aPlacement.fl = SWP_HIDE;
1304 
1305         if ( mbOverwriteState )
1306         {
1307             if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1308             {
1309                 if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1310                     mnShowState = SWP_SHOWMINIMIZED;
1311                 else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1312 				{
1313                     mnShowState = SWP_SHOWMAXIMIZED;
1314 					bUpdateHiddenFramePos = TRUE;
1315 				}
1316                 else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1317                     mnShowState = SWP_SHOWNORMAL;
1318             }
1319         }
1320     }
1321     else
1322     {
1323         if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1324         {
1325             if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1326             {
1327                 //if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1328                 //    aPlacement.flags |= WPF_RESTORETOMAXIMIZED;
1329                 aPlacement.fl = SWP_SHOWMINIMIZED;
1330             }
1331             else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1332                 aPlacement.fl = SWP_SHOWMAXIMIZED;
1333             else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1334                 aPlacement.fl = SWP_RESTORE;
1335         }
1336     }
1337 
1338     // Wenn Fenster nicht minimiert/maximiert ist oder nicht optisch
1339     // umgesetzt werden muss, dann SetWindowPos() benutzen, da
1340     // SetWindowPlacement() die TaskBar mit einrechnet
1341     if ( !(aPlacement.fl & SWP_MINIMIZE)
1342 		 && !( aPlacement.fl & SWP_MAXIMIZE )
1343 	 	 && (!bVisible || (aPlacement.fl == SWP_RESTORE)) )
1344     {
1345 		if( bUpdateHiddenFramePos )
1346 		{
1347 			// #96084 set a useful internal window size because
1348 			// the window will not be maximized (and the size updated) before show()
1349             SetMaximizedFrameGeometry( mhWndFrame, this );
1350 		}
1351 		else
1352 			WinSetWindowPos( mhWndFrame, 0, nX,
1353 				nScreenHeight - (nY+nHeight), nWidth, nHeight, nPosSize);
1354     }
1355     else
1356     {
1357         if( (nPosSize & (SWP_MOVE|SWP_SIZE)) )
1358         {
1359 			aPlacement.x = nX;
1360 			aPlacement.y = nScreenHeight-(nY+nHeight);
1361 			aPlacement.cx = nWidth;
1362 			aPlacement.cy = nHeight;
1363         }
1364 		WinSetWindowPos( mhWndFrame, 0, aPlacement.x, aPlacement.y,
1365 						 aPlacement.cx, aPlacement.cy, aPlacement.fl );
1366     }
1367 
1368 #if OSL_DEBUG_LEVEL>0
1369 	debug_printf("Os2SalFrame::SetWindowState DONE\n");
1370 #endif
1371 }
1372 
1373 // -----------------------------------------------------------------------
1374 
GetWindowState(SalFrameState * pState)1375 sal_Bool Os2SalFrame::GetWindowState( SalFrameState* pState )
1376 {
1377     if ( maState.mnWidth && maState.mnHeight )
1378     {
1379         *pState = maState;
1380         // #94144# allow Minimize again, should be masked out when read from configuration
1381         // 91625 - Don't save minimize
1382         //if ( !(pState->mnState & SAL_FRAMESTATE_MAXIMIZED) )
1383         if ( !(pState->mnState & (SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED)) )
1384             pState->mnState |= SAL_FRAMESTATE_NORMAL;
1385         return TRUE;
1386     }
1387 
1388     return FALSE;
1389 }
1390 
1391 // -----------------------------------------------------------------------
1392 
SetScreenNumber(unsigned int nNewScreen)1393 void Os2SalFrame::SetScreenNumber( unsigned int nNewScreen )
1394 {
1395 #if 0
1396     WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
1397     if( pSys )
1398     {
1399         const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
1400             pSys->getMonitors();
1401         size_t nMon = rMonitors.size();
1402         if( nNewScreen < nMon )
1403         {
1404             Point aOldMonPos, aNewMonPos( rMonitors[nNewScreen].m_aArea.TopLeft() );
1405             Point aCurPos( maGeometry.nX, maGeometry.nY );
1406             for( size_t i = 0; i < nMon; i++ )
1407             {
1408                 if( rMonitors[i].m_aArea.IsInside( aCurPos ) )
1409                 {
1410                     aOldMonPos = rMonitors[i].m_aArea.TopLeft();
1411                     break;
1412                 }
1413             }
1414             mnDisplay = nNewScreen;
1415             maGeometry.nScreenNumber = nNewScreen;
1416             SetPosSize( aNewMonPos.X() + (maGeometry.nX - aOldMonPos.X()),
1417                         aNewMonPos.Y() + (maGeometry.nY - aOldMonPos.Y()),
1418                         0, 0,
1419                         SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
1420         }
1421     }
1422 #endif
1423 }
1424 
1425 // -----------------------------------------------------------------------
1426 
1427 // native menu implementation - currently empty
DrawMenuBar()1428 void Os2SalFrame::DrawMenuBar()
1429 {
1430 }
1431 
SetMenu(SalMenu * pSalMenu)1432 void Os2SalFrame::SetMenu( SalMenu* pSalMenu )
1433 {
1434 }
1435 
1436 // -----------------------------------------------------------------------
1437 
ShowFullScreen(sal_Bool bFullScreen,sal_Int32 nDisplay)1438 void Os2SalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay )
1439 {
1440     if ( mbFullScreen == bFullScreen )
1441         return;
1442 
1443     mbFullScreen = bFullScreen;
1444     if ( bFullScreen )
1445     {
1446         // save old position
1447         memset( &maFullScreenRect, 0, sizeof( SWP ) );
1448         _WinQueryWindowPos( this, &maFullScreenRect );
1449 
1450         // set window to screen size
1451         ImplSalFrameFullScreenPos( this, TRUE );
1452     }
1453     else
1454     {
1455         _WinSetWindowPos( this,
1456                          0,
1457                          maFullScreenRect.x, maFullScreenRect.y,
1458                          maFullScreenRect.cx, maFullScreenRect.cy,
1459                          SWP_MOVE | SWP_SIZE );
1460     }
1461 }
1462 
1463 // -----------------------------------------------------------------------
1464 
StartPresentation(sal_Bool bStart)1465 void Os2SalFrame::StartPresentation( sal_Bool bStart )
1466 {
1467     // SysSetObjectData("<WP_DESKTOP>","Autolockup=no"); oder OS2.INI: PM_Lockup
1468 }
1469 
1470 // -----------------------------------------------------------------------
1471 
SetAlwaysOnTop(sal_Bool bOnTop)1472 void Os2SalFrame::SetAlwaysOnTop( sal_Bool bOnTop )
1473 {
1474     mbAllwayOnTop = bOnTop;
1475 #if 0
1476     HWND hWnd;
1477     if ( bOnTop )
1478         hWnd = HWND_TOPMOST;
1479     else
1480         hWnd = HWND_NOTOPMOST;
1481     SetWindowPos( mhWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
1482 #endif
1483 }
1484 
1485 
1486 // -----------------------------------------------------------------------
1487 
ImplSalToTop(HWND hWnd,ULONG nFlags)1488 static void ImplSalToTop( HWND hWnd, ULONG nFlags )
1489 {
1490     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
1491 #if OSL_DEBUG_LEVEL>0
1492 	debug_printf("ImplSalToTop hWnd %08x, nFlags %x\n", hWnd, nFlags);
1493 #endif
1494 
1495 	// if window is minimized, first restore it
1496 	SWP aSWP;
1497 	WinQueryWindowPos( hWnd, &aSWP );
1498 	if ( aSWP.fl & SWP_MINIMIZE )
1499 		WinSetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_RESTORE );
1500 
1501     if ( nFlags & SAL_FRAME_TOTOP_FOREGROUNDTASK )
1502 		WinSetWindowPos( pFrame->mhWndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
1503 
1504     if ( nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN )
1505     {
1506 		ULONG	nStyle;
1507         if ( pFrame->mbRestoreMaximize )
1508             nStyle = SWP_MAXIMIZE;
1509         else
1510             nStyle = SWP_RESTORE;
1511 
1512 		WinSetWindowPos( pFrame->mhWndFrame, NULL, 0, 0, 0, 0, nStyle );
1513 	}
1514     WinSetFocus( HWND_DESKTOP, pFrame->mhWndClient );
1515 }
1516 
1517 // -----------------------------------------------------------------------
1518 
ToTop(USHORT nFlags)1519 void Os2SalFrame::ToTop( USHORT nFlags )
1520 {
1521 	nFlags &= ~SAL_FRAME_TOTOP_GRABFOCUS;	// this flag is not needed on win32
1522     // Post this Message to the window, because this only works
1523     // in the thread of the window, which has create this window.
1524     // We post this message to avoid deadlocks
1525     if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1526         WinPostMsg( mhWndFrame, SAL_MSG_TOTOP, (MPARAM)nFlags, 0 );
1527     else
1528         ImplSalToTop( mhWndFrame, nFlags );
1529 }
1530 
1531 // -----------------------------------------------------------------------
1532 
SetPointer(PointerStyle ePointerStyle)1533 void Os2SalFrame::SetPointer( PointerStyle ePointerStyle )
1534 {
1535     struct ImplPtrData
1536     {
1537         HPOINTER	mhPointer;
1538         ULONG       mnSysId;
1539         ULONG       mnOwnId;
1540     };
1541 
1542     static ImplPtrData aImplPtrTab[POINTER_COUNT] =
1543     {
1544     { 0, SPTR_ARROW, 0 },                           // POINTER_ARROW
1545     { 0, 0, SAL_RESID_POINTER_NULL },               // POINTER_NULL
1546     { 0, SPTR_WAIT, 0 },                            // POINTER_WAIT
1547     { 0, SPTR_TEXT, 0 },                            // POINTER_BEAM
1548     { 0, 0, SAL_RESID_POINTER_HELP },               // POINTER_HELP
1549     { 0, 0, SAL_RESID_POINTER_CROSS },              // POINTER_CROSS
1550     { 0, 0, SAL_RESID_POINTER_MOVE },               // POINTER_MOVE
1551     { 0, SPTR_SIZENS, 0 },                          // POINTER_NSIZE
1552     { 0, SPTR_SIZENS, 0 },                          // POINTER_SSIZE
1553     { 0, SPTR_SIZEWE, 0 },                          // POINTER_WSIZE
1554     { 0, SPTR_SIZEWE, 0 },                          // POINTER_ESIZE
1555     { 0, SPTR_SIZENWSE, 0 },                        // POINTER_NWSIZE
1556     { 0, SPTR_SIZENESW, 0 },                        // POINTER_NESIZE
1557     { 0, SPTR_SIZENESW, 0 },                        // POINTER_SWSIZE
1558     { 0, SPTR_SIZENWSE, 0 },                        // POINTER_SESIZE
1559     { 0, SPTR_SIZENS, 0 },                          // POINTER_WINDOW_NSIZE
1560     { 0, SPTR_SIZENS, 0 },                          // POINTER_WINDOW_SSIZE
1561     { 0, SPTR_SIZEWE, 0 },                          // POINTER_WINDOW_WSIZE
1562     { 0, SPTR_SIZEWE, 0 },                          // POINTER_WINDOW_ESIZE
1563     { 0, SPTR_SIZENWSE, 0 },                        // POINTER_WINDOW_NWSIZE
1564     { 0, SPTR_SIZENESW, 0 },                        // POINTER_WINDOW_NESIZE
1565     { 0, SPTR_SIZENESW, 0 },                        // POINTER_WINDOW_SWSIZE
1566     { 0, SPTR_SIZENWSE, 0 },                        // POINTER_WINDOW_SESIZE
1567     { 0, 0, SAL_RESID_POINTER_HSPLIT },             // POINTER_HSPLIT
1568     { 0, 0, SAL_RESID_POINTER_VSPLIT },             // POINTER_VSPLIT
1569     { 0, 0, SAL_RESID_POINTER_HSIZEBAR },           // POINTER_HSIZEBAR
1570     { 0, 0, SAL_RESID_POINTER_VSIZEBAR },           // POINTER_VSIZEBAR
1571     { 0, 0, SAL_RESID_POINTER_HAND },               // POINTER_HAND
1572     { 0, 0, SAL_RESID_POINTER_REFHAND },            // POINTER_REFHAND
1573     { 0, 0, SAL_RESID_POINTER_PEN },                // POINTER_PEN
1574     { 0, 0, SAL_RESID_POINTER_MAGNIFY },            // POINTER_MAGNIFY
1575     { 0, 0, SAL_RESID_POINTER_FILL },               // POINTER_FILL
1576     { 0, 0, SAL_RESID_POINTER_ROTATE },             // POINTER_ROTATE
1577     { 0, 0, SAL_RESID_POINTER_HSHEAR },             // POINTER_HSHEAR
1578     { 0, 0, SAL_RESID_POINTER_VSHEAR },             // POINTER_VSHEAR
1579     { 0, 0, SAL_RESID_POINTER_MIRROR },             // POINTER_MIRROR
1580     { 0, 0, SAL_RESID_POINTER_CROOK },              // POINTER_CROOK
1581     { 0, 0, SAL_RESID_POINTER_CROP },               // POINTER_CROP
1582     { 0, 0, SAL_RESID_POINTER_MOVEPOINT },          // POINTER_MOVEPOINT
1583     { 0, 0, SAL_RESID_POINTER_MOVEBEZIERWEIGHT },   // POINTER_MOVEBEZIERWEIGHT
1584     { 0, 0, SAL_RESID_POINTER_MOVEDATA },           // POINTER_MOVEDATA
1585     { 0, 0, SAL_RESID_POINTER_COPYDATA },           // POINTER_COPYDATA
1586     { 0, 0, SAL_RESID_POINTER_LINKDATA },           // POINTER_LINKDATA
1587     { 0, 0, SAL_RESID_POINTER_MOVEDATALINK },       // POINTER_MOVEDATALINK
1588     { 0, 0, SAL_RESID_POINTER_COPYDATALINK },       // POINTER_COPYDATALINK
1589     { 0, 0, SAL_RESID_POINTER_MOVEFILE },           // POINTER_MOVEFILE
1590     { 0, 0, SAL_RESID_POINTER_COPYFILE },           // POINTER_COPYFILE
1591     { 0, 0, SAL_RESID_POINTER_LINKFILE },           // POINTER_LINKFILE
1592     { 0, 0, SAL_RESID_POINTER_MOVEFILELINK },       // POINTER_MOVEFILELINK
1593     { 0, 0, SAL_RESID_POINTER_COPYFILELINK },       // POINTER_COPYFILELINK
1594     { 0, 0, SAL_RESID_POINTER_MOVEFILES },          // POINTER_MOVEFILES
1595     { 0, 0, SAL_RESID_POINTER_COPYFILES },          // POINTER_COPYFILES
1596     { 0, SPTR_ILLEGAL, 0 },                         // POINTER_NOTALLOWED
1597     { 0, 0, SAL_RESID_POINTER_DRAW_LINE },          // POINTER_DRAW_LINE
1598     { 0, 0, SAL_RESID_POINTER_DRAW_RECT },          // POINTER_DRAW_RECT
1599     { 0, 0, SAL_RESID_POINTER_DRAW_POLYGON },       // POINTER_DRAW_POLYGON
1600     { 0, 0, SAL_RESID_POINTER_DRAW_BEZIER },        // POINTER_DRAW_BEZIER
1601     { 0, 0, SAL_RESID_POINTER_DRAW_ARC },           // POINTER_DRAW_ARC
1602     { 0, 0, SAL_RESID_POINTER_DRAW_PIE },           // POINTER_DRAW_PIE
1603     { 0, 0, SAL_RESID_POINTER_DRAW_CIRCLECUT },     // POINTER_DRAW_CIRCLECUT
1604     { 0, 0, SAL_RESID_POINTER_DRAW_ELLIPSE },       // POINTER_DRAW_ELLIPSE
1605     { 0, 0, SAL_RESID_POINTER_DRAW_FREEHAND },      // POINTER_DRAW_FREEHAND
1606     { 0, 0, SAL_RESID_POINTER_DRAW_CONNECT },       // POINTER_DRAW_CONNECT
1607     { 0, 0, SAL_RESID_POINTER_DRAW_TEXT },          // POINTER_DRAW_TEXT
1608     { 0, 0, SAL_RESID_POINTER_DRAW_CAPTION },       // POINTER_DRAW_CAPTION
1609     { 0, 0, SAL_RESID_POINTER_CHART },              // POINTER_CHART
1610     { 0, 0, SAL_RESID_POINTER_DETECTIVE },          // POINTER_DETECTIVE
1611     { 0, 0, SAL_RESID_POINTER_PIVOT_COL },          // POINTER_PIVOT_COL
1612     { 0, 0, SAL_RESID_POINTER_PIVOT_ROW },          // POINTER_PIVOT_ROW
1613     { 0, 0, SAL_RESID_POINTER_PIVOT_FIELD },        // POINTER_PIVOT_FIELD
1614     { 0, 0, SAL_RESID_POINTER_CHAIN },              // POINTER_CHAIN
1615     { 0, 0, SAL_RESID_POINTER_CHAIN_NOTALLOWED },   // POINTER_CHAIN_NOTALLOWED
1616     { 0, 0, SAL_RESID_POINTER_TIMEEVENT_MOVE },     // POINTER_TIMEEVENT_MOVE
1617     { 0, 0, SAL_RESID_POINTER_TIMEEVENT_SIZE },     // POINTER_TIMEEVENT_SIZE
1618     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_N },       // POINTER_AUTOSCROLL_N
1619     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_S },       // POINTER_AUTOSCROLL_S
1620     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_W },       // POINTER_AUTOSCROLL_W
1621     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_E },       // POINTER_AUTOSCROLL_E
1622     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NW },      // POINTER_AUTOSCROLL_NW
1623     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NE },      // POINTER_AUTOSCROLL_NE
1624     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SW },      // POINTER_AUTOSCROLL_SW
1625     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SE },      // POINTER_AUTOSCROLL_SE
1626     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NS },      // POINTER_AUTOSCROLL_NS
1627     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_WE },      // POINTER_AUTOSCROLL_WE
1628     { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NSWE },     // POINTER_AUTOSCROLL_NSWE
1629     { 0, 0, SAL_RESID_POINTER_AIRBRUSH },           // POINTER_AIRBRUSH
1630     { 0, 0, SAL_RESID_POINTER_TEXT_VERTICAL },      // POINTER_TEXT_VERTICAL
1631     { 0, 0, SAL_RESID_POINTER_PIVOT_DELETE },       // POINTER_PIVOT_DELETE
1632 
1633     // --> FME 2004-07-30 #i32329# Enhanced table selection
1634     { 0, 0, SAL_RESID_POINTER_TAB_SELECT_S },       // POINTER_TAB_SELECT_S
1635     { 0, 0, SAL_RESID_POINTER_TAB_SELECT_E },       // POINTER_TAB_SELECT_E
1636     { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SE },      // POINTER_TAB_SELECT_SE
1637     { 0, 0, SAL_RESID_POINTER_TAB_SELECT_W },       // POINTER_TAB_SELECT_W
1638     { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SW },      // POINTER_TAB_SELECT_SW
1639     // <--
1640 
1641     // --> FME 2004-08-16 #i20119# Paintbrush tool
1642     { 0, 0, SAL_RESID_POINTER_PAINTBRUSH }          // POINTER_PAINTBRUSH
1643     // <--
1644     };
1645 
1646 #if POINTER_COUNT != 94
1647 #error New Pointer must be defined!
1648 #endif
1649 
1650 	//debug_printf("Os2SalFrame::SetPointer\n");
1651 
1652     // Mousepointer loaded ?
1653     if ( !aImplPtrTab[ePointerStyle].mhPointer )
1654     {
1655         if ( aImplPtrTab[ePointerStyle].mnOwnId )
1656             aImplPtrTab[ePointerStyle].mhPointer = ImplLoadSalCursor( (ULONG)aImplPtrTab[ePointerStyle].mnOwnId );
1657         else
1658             aImplPtrTab[ePointerStyle].mhPointer = WinQuerySysPointer( HWND_DESKTOP, aImplPtrTab[ePointerStyle].mnSysId, FALSE );
1659     }
1660 	if (aImplPtrTab[ePointerStyle].mhPointer == 0) {
1661 		debug_printf( "SetPointer ePointerStyle %d unknown\n", ePointerStyle);
1662 		aImplPtrTab[ePointerStyle].mhPointer = SPTR_ICONERROR;
1663 	}
1664 
1665     // Unterscheidet sich der Mauspointer, dann den neuen setzen
1666     if ( mhPointer != aImplPtrTab[ePointerStyle].mhPointer )
1667     {
1668         mhPointer = aImplPtrTab[ePointerStyle].mhPointer;
1669         WinSetPointer( HWND_DESKTOP, mhPointer );
1670     }
1671 }
1672 
1673 // -----------------------------------------------------------------------
1674 
CaptureMouse(sal_Bool bCapture)1675 void Os2SalFrame::CaptureMouse( sal_Bool bCapture )
1676 {
1677 #if OSL_DEBUG_LEVEL>10
1678 	_bCapture=bCapture;
1679 	debug_printf("Os2SalFrame::CaptureMouse bCapture %d\n", bCapture);
1680 #endif
1681     if ( bCapture )
1682         WinSetCapture( HWND_DESKTOP, mhWndClient );
1683     else
1684         WinSetCapture( HWND_DESKTOP, 0 );
1685 }
1686 
1687 // -----------------------------------------------------------------------
1688 
SetPointerPos(long nX,long nY)1689 void Os2SalFrame::SetPointerPos( long nX, long nY )
1690 {
1691     POINTL aPt;
1692     aPt.x = nX;
1693     aPt.y = mnHeight - nY - 1;  // convert sal coords to sys
1694     WinMapWindowPoints( mhWndClient, HWND_DESKTOP, &aPt, 1 );
1695     WinSetPointerPos( HWND_DESKTOP, aPt.x, aPt.y );
1696 }
1697 
1698 // -----------------------------------------------------------------------
1699 
Flush()1700 void Os2SalFrame::Flush()
1701 {
1702 }
1703 
1704 // -----------------------------------------------------------------------
1705 
Sync()1706 void Os2SalFrame::Sync()
1707 {
1708 }
1709 
1710 // -----------------------------------------------------------------------
1711 
SetInputContext(SalInputContext * pContext)1712 void Os2SalFrame::SetInputContext( SalInputContext* pContext )
1713 {
1714 #ifdef ENABLE_IME
1715     SalIMEData* pIMEData = GetSalIMEData();
1716     if ( pIMEData )
1717     {
1718         HWND hWnd = mhWndClient;
1719         HIMI hIMI = 0;
1720         pIMEData->mpGetIME( hWnd, &hIMI );
1721         if ( hIMI )
1722         {
1723             ULONG nInputMode;
1724             ULONG nConversionMode;
1725             if ( 0 == pIMEData->mpQueryIMEMode( hIMI, &nInputMode, &nConversionMode ) )
1726             {
1727                 if ( pContext->mnOptions & SAL_INPUTCONTEXT_TEXT )
1728                 {
1729                     nInputMode &= ~IMI_IM_IME_DISABLE;
1730                     if ( pContext->mnOptions & SAL_INPUTCONTEXT_EXTTEXTINPUT_OFF )
1731                         nInputMode &= ~IMI_IM_IME_ON;
1732 // !!! Da derzeit ueber das OS2-IME-UI der IME-Mode nicht einschaltbar ist !!!
1733 //                    if ( SAL_INPUTCONTEXT_EXTTEXTINPUT_ON )
1734                         nInputMode |= IMI_IM_IME_ON;
1735                 }
1736                 else
1737                     nInputMode |= IMI_IM_IME_DISABLE;
1738                 pIMEData->mpSetIMEMode( hIMI, nInputMode, nConversionMode );
1739             }
1740 
1741             pIMEData->mpReleaseIME( hWnd, hIMI );
1742         }
1743     }
1744 #endif
1745 }
1746 
1747 // -----------------------------------------------------------------------
1748 #if 0
1749 void Os2SalFrame::UpdateExtTextInputArea()
1750 {
1751 #ifdef ENABLE_IME
1752 #endif
1753 }
1754 #endif
1755 
1756 // -----------------------------------------------------------------------
1757 
EndExtTextInput(USHORT nFlags)1758 void Os2SalFrame::EndExtTextInput( USHORT nFlags )
1759 {
1760 #ifdef ENABLE_IME
1761     SalIMEData* pIMEData = GetSalIMEData();
1762     if ( pIMEData )
1763     {
1764         HWND hWnd = mhWndClient;
1765         HIMI hIMI = 0;
1766         pIMEData->mpGetIME( hWnd, &hIMI );
1767         if ( hIMI )
1768         {
1769             ULONG nIndex;
1770             if ( nFlags & SAL_FRAME_ENDEXTTEXTINPUT_COMPLETE )
1771                 nIndex = CNV_COMPLETE;
1772             else
1773                 nIndex = CNV_CANCEL;
1774 
1775             pIMEData->mpRequestIME( hIMI, REQ_CONVERSIONSTRING, nIndex, 0 );
1776             pIMEData->mpReleaseIME( hWnd, hIMI );
1777         }
1778     }
1779 #endif
1780 }
1781 
1782 // -----------------------------------------------------------------------
1783 
GetKeyName(USHORT nCode)1784 XubString Os2SalFrame::GetKeyName( USHORT nCode )
1785 {
1786     if ( eImplKeyboardLanguage == LANGUAGE_DONTKNOW )
1787         eImplKeyboardLanguage = MsLangId::getSystemLanguage();
1788 
1789     XubString        aKeyCode;
1790     XubString        aCode;
1791     const sal_Unicode**    pLangTab = ImplGetLangTab( eImplKeyboardLanguage );
1792 
1793     if ( nCode & KEY_SHIFT )
1794         aKeyCode = pLangTab[LSTR_KEY_SHIFT];
1795 
1796     if ( nCode & KEY_MOD1 )
1797     {
1798         if ( aKeyCode.Len() == 0 )
1799             aKeyCode = pLangTab[LSTR_KEY_CTRL];
1800         else
1801         {
1802             aKeyCode += '+';
1803             aKeyCode += pLangTab[LSTR_KEY_CTRL];
1804         }
1805     }
1806 
1807     if ( nCode & KEY_MOD2 )
1808     {
1809         if ( aKeyCode.Len() == 0 )
1810             aKeyCode = pLangTab[LSTR_KEY_ALT];
1811         else
1812         {
1813             aKeyCode += '+';
1814             aKeyCode += pLangTab[LSTR_KEY_ALT];
1815         }
1816     }
1817 
1818     USHORT nKeyCode = nCode & 0x0FFF;
1819     if ( (nKeyCode >= KEY_0) && (nKeyCode <= KEY_9) )
1820         aCode = sal::static_int_cast<sal_Char>('0' + (nKeyCode - KEY_0));
1821     else if ( (nKeyCode >= KEY_A) && (nKeyCode <= KEY_Z) )
1822         aCode = sal::static_int_cast<sal_Char>('A' + (nKeyCode - KEY_A));
1823     else if ( (nKeyCode >= KEY_F1) && (nKeyCode <= KEY_F26) )
1824     {
1825 		aCode += 'F';
1826         if ( (nKeyCode >= KEY_F1) && (nKeyCode <= KEY_F9) )
1827         {
1828             aCode += sal::static_int_cast<sal_Char>('1' + (nKeyCode - KEY_F1));
1829         }
1830         else if ( (nKeyCode >= KEY_F10) && (nKeyCode <= KEY_F19) )
1831         {
1832             aCode += '1';
1833             aCode += sal::static_int_cast<sal_Char>('0' + (nKeyCode - KEY_F10));
1834         }
1835         else
1836         {
1837             aCode += '2';
1838             aCode += sal::static_int_cast<sal_Char>('0' + (nKeyCode - KEY_F20));
1839         }
1840     }
1841     else
1842     {
1843 		switch ( nKeyCode )
1844 		{
1845 			case KEY_DOWN:
1846 				aCode = pLangTab[LSTR_KEY_DOWN];
1847 				break;
1848 			case KEY_UP:
1849 				aCode = pLangTab[LSTR_KEY_UP];
1850 				break;
1851 			case KEY_LEFT:
1852 				aCode = pLangTab[LSTR_KEY_LEFT];
1853 				break;
1854 			case KEY_RIGHT:
1855 				aCode = pLangTab[LSTR_KEY_RIGHT];
1856 				break;
1857 			case KEY_HOME:
1858 				aCode = pLangTab[LSTR_KEY_HOME];
1859 				break;
1860 			case KEY_END:
1861 				aCode = pLangTab[LSTR_KEY_END];
1862 				break;
1863 			case KEY_PAGEUP:
1864 				aCode = pLangTab[LSTR_KEY_PAGEUP];
1865 				break;
1866 			case KEY_PAGEDOWN:
1867 				aCode = pLangTab[LSTR_KEY_PAGEDOWN];
1868 				break;
1869 			case KEY_RETURN:
1870 				aCode = pLangTab[LSTR_KEY_RETURN];
1871 				break;
1872 			case KEY_ESCAPE:
1873 				aCode = pLangTab[LSTR_KEY_ESC];
1874 				break;
1875 			case KEY_TAB:
1876 				aCode = pLangTab[LSTR_KEY_TAB];
1877 				break;
1878 			case KEY_BACKSPACE:
1879 				aCode = pLangTab[LSTR_KEY_BACKSPACE];
1880 				break;
1881 			case KEY_SPACE:
1882 				aCode = pLangTab[LSTR_KEY_SPACE];
1883 				break;
1884 			case KEY_INSERT:
1885 				aCode = pLangTab[LSTR_KEY_INSERT];
1886 				break;
1887 			case KEY_DELETE:
1888 				aCode = pLangTab[LSTR_KEY_DELETE];
1889 				break;
1890 
1891 			case KEY_ADD:
1892 				aCode += '+';
1893 				break;
1894 			case KEY_SUBTRACT:
1895 				aCode += '-';
1896 				break;
1897 			case KEY_MULTIPLY:
1898 				aCode += '*';
1899 				break;
1900 			case KEY_DIVIDE:
1901 				aCode += '/';
1902 				break;
1903 			case KEY_POINT:
1904 				aCode += '.';
1905 				break;
1906 			case KEY_COMMA:
1907 				aCode += ',';
1908 				break;
1909 			case KEY_LESS:
1910 				aCode += '<';
1911 				break;
1912 			case KEY_GREATER:
1913 				aCode += '>';
1914 				break;
1915 			case KEY_EQUAL:
1916 				aCode += '=';
1917 				break;
1918 		}
1919 	}
1920 
1921     if ( aCode.Len() )
1922     {
1923         if ( aKeyCode.Len() == 0 )
1924             aKeyCode = aCode;
1925         else
1926         {
1927             aKeyCode += '+';
1928             aKeyCode += aCode;
1929         }
1930     }
1931 
1932     return aKeyCode;
1933 }
1934 
1935 // -----------------------------------------------------------------------
1936 
GetSymbolKeyName(const XubString &,USHORT nKeyCode)1937 XubString Os2SalFrame::GetSymbolKeyName( const XubString&, USHORT nKeyCode )
1938 {
1939     return GetKeyName( nKeyCode );
1940 }
1941 
1942 // -----------------------------------------------------------------------
1943 
ImplOS2ColorToSal(long nOS2Color)1944 inline long ImplOS2ColorToSal( long nOS2Color )
1945 {
1946     return MAKE_SALCOLOR( (PM_BYTE)( nOS2Color>>16), (PM_BYTE)(nOS2Color>>8), (PM_BYTE)nOS2Color );
1947 }
1948 
1949 // -----------------------------------------------------------------------
1950 
ImplMouseSysValueToSAL(int iSysValue,USHORT & rCode,USHORT & rClicks,sal_Bool & rDown)1951 static USHORT ImplMouseSysValueToSAL( int iSysValue, USHORT& rCode, USHORT& rClicks, sal_Bool& rDown )
1952 {
1953     LONG lValue = WinQuerySysValue( HWND_DESKTOP, iSysValue );
1954 
1955     rCode   = 0;
1956     rClicks = 1;
1957     rDown   = TRUE;
1958 
1959     switch ( lValue & 0xFFFF )
1960     {
1961         case WM_BUTTON1UP:
1962         case WM_BUTTON1CLICK:
1963             rCode = MOUSE_LEFT;
1964             rDown = FALSE;
1965             break;
1966         case WM_BUTTON1DOWN:
1967         case WM_BUTTON1MOTIONSTART:
1968             rCode = MOUSE_LEFT;
1969             break;
1970         case WM_BUTTON1DBLCLK:
1971             rCode = MOUSE_LEFT;
1972             rClicks = 2;
1973             break;
1974 
1975         case WM_BUTTON2UP:
1976         case WM_BUTTON2CLICK:
1977             rCode = MOUSE_RIGHT;
1978             rDown = FALSE;
1979             break;
1980         case WM_BUTTON2DOWN:
1981         case WM_BUTTON2MOTIONSTART:
1982             rCode = MOUSE_RIGHT;
1983             break;
1984         case WM_BUTTON2DBLCLK:
1985             rCode = MOUSE_RIGHT;
1986             rClicks = 2;
1987             break;
1988 
1989         case WM_BUTTON3UP:
1990         case WM_BUTTON3CLICK:
1991             rCode = MOUSE_MIDDLE;
1992             rDown = FALSE;
1993             break;
1994         case WM_BUTTON3DOWN:
1995         case WM_BUTTON3MOTIONSTART:
1996             rCode = MOUSE_MIDDLE;
1997             break;
1998         case WM_BUTTON3DBLCLK:
1999             rCode = MOUSE_MIDDLE;
2000             rClicks = 2;
2001             break;
2002     }
2003 
2004     if ( !rCode )
2005         return FALSE;
2006 
2007     lValue = (lValue & 0xFFFF0000) >> 16;
2008     if ( lValue != 0xFFFF )
2009     {
2010         if ( lValue & KC_SHIFT )
2011             rCode |= KEY_SHIFT;
2012         if ( lValue & KC_CTRL )
2013             rCode |= KEY_MOD1;
2014         if ( lValue & KC_ALT )
2015             rCode |= KEY_MOD2;
2016     }
2017 
2018     return TRUE;
2019 }
2020 
2021 // -----------------------------------------------------------------------
2022 
ImplSalIsSameColor(const Color & rColor1,const Color & rColor2)2023 static sal_Bool ImplSalIsSameColor( const Color& rColor1, const Color& rColor2 )
2024 {
2025     ULONG nWrong = 0;
2026     nWrong += Abs( (short)rColor1.GetRed()-(short)rColor2.GetRed() );
2027     nWrong += Abs( (short)rColor1.GetGreen()-(short)rColor2.GetGreen() );
2028     nWrong += Abs( (short)rColor1.GetBlue()-(short)rColor2.GetBlue() );
2029     return (nWrong < 30);
2030 }
2031 
2032 // -----------------------------------------------------------------------
2033 
ImplOS2NameFontToVCLFont(const char * pFontName,Font & rFont)2034 static sal_Bool ImplOS2NameFontToVCLFont( const char* pFontName, Font& rFont )
2035 {
2036     char aNumBuf[10];
2037     int  nNumBufLen = 0;
2038 
2039     while ( *pFontName && (*pFontName != '.') &&
2040             (nNumBufLen < sizeof(aNumBuf)-1) )
2041     {
2042         aNumBuf[nNumBufLen] = *pFontName;
2043         nNumBufLen++;
2044         pFontName++;
2045     }
2046     aNumBuf[nNumBufLen] = '\0';
2047 
2048     pFontName++;
2049     while ( *pFontName == ' ' )
2050         pFontName++;
2051 
2052     int nFontHeight = atoi( aNumBuf );
2053     int nFontNameLen = strlen( pFontName );
2054     if ( nFontHeight && nFontNameLen )
2055     {
2056         rFont.SetFamily( FAMILY_DONTKNOW );
2057         rFont.SetWeight( WEIGHT_NORMAL );
2058         rFont.SetItalic( ITALIC_NONE );
2059 		// search for a style embedded in the name, e.g. 'WarpSans Bold'
2060 		// because we need to split the style from the family name
2061 		if (strstr( pFontName, " Bold")
2062 			|| strstr( pFontName, " Italic")
2063 			|| strstr( pFontName, "-Normal"))
2064 		{
2065 			char* fontName = strdup( pFontName);
2066 			char* style = strstr( fontName, " Bold");
2067 			if (style)
2068 				rFont.SetWeight( WEIGHT_BOLD );
2069 
2070 			if (!style)
2071 				style = strstr( fontName, " Italic");
2072 			if (style)
2073 				rFont.SetItalic( ITALIC_NORMAL );
2074 
2075 			if (!style)
2076 				style = strstr( fontName, "-Normal");
2077 			// store style, skip whitespace char
2078 			rFont.SetStyleName( ::rtl::OStringToOUString ( style+1, gsl_getSystemTextEncoding()) );
2079 			// truncate name
2080 			*style = 0;
2081 			// store family name
2082 			rFont.SetName( ::rtl::OStringToOUString ( fontName, gsl_getSystemTextEncoding()) );
2083 			free( fontName);
2084 		}
2085 		else
2086 		{
2087 			rFont.SetName( ::rtl::OStringToOUString (pFontName, gsl_getSystemTextEncoding()) );
2088 			rFont.SetStyleName( ::rtl::OStringToOUString ("", gsl_getSystemTextEncoding()) );
2089 		}
2090 
2091         rFont.SetSize( Size( 0, nFontHeight ) );
2092         return TRUE;
2093     }
2094     else
2095         return FALSE;
2096 }
2097 
2098 // -----------------------------------------------------------------------
2099 
UpdateSettings(AllSettings & rSettings)2100 void Os2SalFrame::UpdateSettings( AllSettings& rSettings )
2101 {
2102     static char aControlPanel[] = "PM_ControlPanel";
2103     static char aSystemFonts[]  = "PM_SystemFonts";
2104     char aDummyStr[] = "";
2105 
2106     // --- Mouse setting ---
2107     USHORT  nCode;
2108     USHORT  nClicks;
2109     sal_Bool    bDown;
2110     MouseSettings aMouseSettings = rSettings.GetMouseSettings();
2111     aMouseSettings.SetDoubleClickTime( WinQuerySysValue( HWND_DESKTOP, SV_DBLCLKTIME ) );
2112     if ( ImplMouseSysValueToSAL( SV_BEGINDRAG, nCode, nClicks, bDown ) )
2113         aMouseSettings.SetStartDragCode( nCode );
2114     if ( ImplMouseSysValueToSAL( SV_CONTEXTMENU, nCode, nClicks, bDown ) )
2115     {
2116         aMouseSettings.SetContextMenuCode( nCode );
2117         aMouseSettings.SetContextMenuClicks( nClicks );
2118         aMouseSettings.SetContextMenuDown( bDown );
2119     }
2120     aMouseSettings.SetButtonStartRepeat( WinQuerySysValue( HWND_DESKTOP, SV_FIRSTSCROLLRATE ) );
2121     aMouseSettings.SetButtonRepeat( WinQuerySysValue( HWND_DESKTOP, SV_SCROLLRATE ) );
2122     rSettings.SetMouseSettings( aMouseSettings );
2123 
2124     // --- Style settings ---
2125     StyleSettings aStyleSettings = rSettings.GetStyleSettings();
2126     // General settings
2127     LONG    nDisplayTime = PrfQueryProfileInt( HINI_PROFILE, (PSZ)aControlPanel, (PSZ)"LogoDisplayTime", -1 );
2128     ULONG   nSalDisplayTime;
2129     if ( nDisplayTime < 0 )
2130         nSalDisplayTime = LOGO_DISPLAYTIME_STARTTIME;
2131     else if ( !nDisplayTime )
2132         nSalDisplayTime = LOGO_DISPLAYTIME_NOLOGO;
2133     else
2134         nSalDisplayTime = (ULONG)nDisplayTime;
2135     aStyleSettings.SetLogoDisplayTime( nSalDisplayTime );
2136 
2137     aStyleSettings.SetCursorBlinkTime( WinQuerySysValue( HWND_DESKTOP, SV_CURSORRATE ) );
2138     ULONG nDragFullOptions = aStyleSettings.GetDragFullOptions();
2139     if ( WinQuerySysValue( HWND_DESKTOP, SV_DYNAMICDRAG ) )
2140         nDragFullOptions |= DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT;
2141     else
2142         nDragFullOptions &= ~(DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT);
2143     aStyleSettings.SetDragFullOptions( nDragFullOptions );
2144 
2145     // Size settings
2146     aStyleSettings.SetScrollBarSize( WinQuerySysValue( HWND_DESKTOP, SV_CYHSCROLL ) );
2147     aStyleSettings.SetTitleHeight( WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) );
2148 
2149     // Color settings
2150     aStyleSettings.SetFaceColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_BUTTONMIDDLE, 0 ) ) );
2151     aStyleSettings.SetInactiveTabColor( aStyleSettings.GetFaceColor() );
2152     aStyleSettings.SetLightColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0 ) ) );
2153     aStyleSettings.SetLightBorderColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_BUTTONMIDDLE, 0 ) ) );
2154     aStyleSettings.SetShadowColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_BUTTONDARK, 0 ) ) );
2155     aStyleSettings.SetDarkShadowColor( Color( COL_BLACK ) );
2156     aStyleSettings.SetDialogColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0 ) ) );
2157     aStyleSettings.SetButtonTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUTEXT, 0 ) ) );
2158     aStyleSettings.SetActiveColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_ACTIVETITLE, 0 ) ) );
2159     aStyleSettings.SetActiveTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_ACTIVETITLETEXT, 0 ) ) );
2160     aStyleSettings.SetActiveBorderColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_ACTIVEBORDER, 0 ) ) );
2161     aStyleSettings.SetDeactiveColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_INACTIVETITLE, 0 ) ) );
2162     aStyleSettings.SetDeactiveTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_INACTIVETITLETEXT, 0 ) ) );
2163     aStyleSettings.SetDeactiveBorderColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_INACTIVEBORDER, 0 ) ) );
2164     aStyleSettings.SetMenuColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENU, 0 ) ) );
2165     aStyleSettings.SetMenuTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUTEXT, 0 ) ) );
2166     aStyleSettings.SetMenuBarTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUTEXT, 0 ) ) );
2167     aStyleSettings.SetDialogTextColor( aStyleSettings.GetButtonTextColor() );
2168     aStyleSettings.SetRadioCheckTextColor( aStyleSettings.GetButtonTextColor() );
2169     aStyleSettings.SetGroupTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_WINDOWSTATICTEXT, 0 ) ) );
2170     aStyleSettings.SetLabelTextColor( aStyleSettings.GetGroupTextColor() );
2171     aStyleSettings.SetInfoTextColor( aStyleSettings.GetGroupTextColor() );
2172     aStyleSettings.SetWindowColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_WINDOW, 0 ) ) );
2173     aStyleSettings.SetActiveTabColor( aStyleSettings.GetWindowColor() );
2174     aStyleSettings.SetWindowTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_WINDOWTEXT, 0 ) ) );
2175     aStyleSettings.SetFieldColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_ENTRYFIELD, 0 ) ) );
2176     aStyleSettings.SetFieldTextColor( aStyleSettings.GetWindowTextColor() );
2177     aStyleSettings.SetDisableColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUDISABLEDTEXT, 0 ) ) );
2178     aStyleSettings.SetHighlightColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_HILITEBACKGROUND, 0 ) ) );
2179     aStyleSettings.SetHighlightTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_HILITEFOREGROUND, 0 ) ) );
2180     Color aMenuHighColor = ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUHILITEBGND, 0 ) );
2181     if ( ImplSalIsSameColor( aMenuHighColor, aStyleSettings.GetMenuColor() ) )
2182     {
2183         aStyleSettings.SetMenuHighlightColor( Color( COL_BLUE ) );
2184         aStyleSettings.SetMenuHighlightTextColor( Color( COL_WHITE ) );
2185     }
2186     else
2187     {
2188         aStyleSettings.SetMenuHighlightColor( aMenuHighColor );
2189         aStyleSettings.SetMenuHighlightTextColor( ImplOS2ColorToSal( WinQuerySysColor( HWND_DESKTOP, SYSCLR_MENUHILITE, 0 ) ) );
2190     }
2191     // Checked-Color berechnen
2192     Color   aColor1 = aStyleSettings.GetFaceColor();
2193     Color   aColor2 = aStyleSettings.GetLightColor();
2194     PM_BYTE    nRed    = (PM_BYTE)(((USHORT)aColor1.GetRed()   + (USHORT)aColor2.GetRed())/2);
2195     PM_BYTE    nGreen  = (PM_BYTE)(((USHORT)aColor1.GetGreen() + (USHORT)aColor2.GetGreen())/2);
2196     PM_BYTE    nBlue   = (PM_BYTE)(((USHORT)aColor1.GetBlue()  + (USHORT)aColor2.GetBlue())/2);
2197     aStyleSettings.SetCheckedColor( Color( nRed, nGreen, nBlue ) );
2198 
2199     // Fonts updaten
2200     Font    aFont;
2201     char    aFontNameBuf[255];
2202     aFont = aStyleSettings.GetMenuFont();
2203     if ( PrfQueryProfileString( HINI_PROFILE, (PSZ)aSystemFonts, (PSZ)"Menus", aDummyStr, aFontNameBuf, sizeof( aFontNameBuf ) ) > 5 )
2204     {
2205         if ( ImplOS2NameFontToVCLFont( aFontNameBuf, aFont ) ) {
2206 #if 0
2207 			// Add Workplace Sans if not already listed
2208             if ( aFont.GetName().Search( (sal_Unicode*)L"WorkPlace Sans" ) == STRING_NOTFOUND )
2209             {
2210                 XubString aFontName = aFont.GetName();
2211                 aFontName.Insert( (sal_Unicode*)L"WorkPlace Sans;", 0 );
2212                 aFont.SetName( aFontName );
2213                 aFont.SetSize( Size( 0, 9 ) );
2214             }
2215 #endif
2216             aStyleSettings.SetMenuFont( aFont );
2217 		}
2218     }
2219     aFont = aStyleSettings.GetIconFont();
2220     if ( PrfQueryProfileString( HINI_PROFILE, (PSZ)aSystemFonts, (PSZ)"IconText", aDummyStr, aFontNameBuf, sizeof( aFontNameBuf ) ) > 5 )
2221     {
2222         if ( ImplOS2NameFontToVCLFont( aFontNameBuf, aFont ) )
2223             aStyleSettings.SetIconFont( aFont );
2224     }
2225     aFont = aStyleSettings.GetTitleFont();
2226     if ( PrfQueryProfileString( HINI_PROFILE, (PSZ)aSystemFonts, (PSZ)"WindowTitles", aDummyStr, aFontNameBuf, sizeof( aFontNameBuf ) ) > 5 )
2227     {
2228         if ( ImplOS2NameFontToVCLFont( aFontNameBuf, aFont ) )
2229         {
2230             // Add Workplace Sans if not already listed
2231             if ( aFont.GetName().Search( (sal_Unicode*)L"WorkPlace Sans" ) == STRING_NOTFOUND )
2232             {
2233                 XubString aFontName = aFont.GetName();
2234                 aFontName.Insert( (sal_Unicode*)L"WorkPlace Sans;", 0 );
2235                 aFont.SetName( aFontName );
2236                 aFont.SetSize( Size( 0, 9 ) );
2237 				aFont.SetWeight( WEIGHT_BOLD );
2238 				aFont.SetItalic( ITALIC_NONE );
2239             }
2240             aStyleSettings.SetTitleFont( aFont );
2241             aStyleSettings.SetFloatTitleFont( aFont );
2242         }
2243     }
2244     aFont = aStyleSettings.GetAppFont();
2245     if ( PrfQueryProfileString( HINI_PROFILE, (PSZ)aSystemFonts, (PSZ)"WindowText", aDummyStr, aFontNameBuf, sizeof( aFontNameBuf ) ) > 5 )
2246     {
2247         if ( ImplOS2NameFontToVCLFont( aFontNameBuf, aFont ) )
2248         {
2249             Font aHelpFont = aFont;
2250             aHelpFont.SetName( (sal_Unicode*)L"Helv;WarpSans" );
2251             aHelpFont.SetSize( Size( 0, 8 ) );
2252             aHelpFont.SetWeight( WEIGHT_NORMAL );
2253             aHelpFont.SetItalic( ITALIC_NONE );
2254             aStyleSettings.SetHelpFont( aHelpFont );
2255 
2256             // Add Workplace Sans if not already listed
2257             if ( aFont.GetName().Search( (sal_Unicode*)L"WorkPlace Sans" ) == STRING_NOTFOUND )
2258             {
2259                 XubString aFontName = aFont.GetName();
2260                 aFontName.Insert( (sal_Unicode*)L"WorkPlace Sans;", 0 );
2261                 aFont.SetName( aFontName );
2262                 aFont.SetSize( Size( 0, 9 ) );
2263             }
2264             aStyleSettings.SetAppFont( aFont );
2265             aStyleSettings.SetToolFont( aFont );
2266             aStyleSettings.SetLabelFont( aFont );
2267             aStyleSettings.SetInfoFont( aFont );
2268             aStyleSettings.SetRadioCheckFont( aFont );
2269             aStyleSettings.SetPushButtonFont( aFont );
2270             aStyleSettings.SetFieldFont( aFont );
2271             aStyleSettings.SetGroupFont( aFont );
2272         }
2273     }
2274 
2275     rSettings.SetStyleSettings( aStyleSettings );
2276 }
2277 
2278 // -----------------------------------------------------------------------
2279 
SnapShot()2280 SalBitmap* Os2SalFrame::SnapShot()
2281 {
2282 debug_printf("Os2SalFrame::SnapShot\n");
2283 return NULL;
2284 }
2285 
2286 // -----------------------------------------------------------------------
2287 
GetSystemData() const2288 const SystemEnvData* Os2SalFrame::GetSystemData() const
2289 {
2290     return &maSysData;
2291 }
2292 
2293 // -----------------------------------------------------------------------
2294 
Beep(SoundType eSoundType)2295 void Os2SalFrame::Beep( SoundType eSoundType )
2296 {
2297     static ULONG aImplSoundTab[5] =
2298     {
2299         WA_NOTE,                        // SOUND_DEFAULT
2300         WA_NOTE,                        // SOUND_INFO
2301         WA_WARNING,                     // SOUND_WARNING
2302         WA_ERROR,                       // SOUND_ERROR
2303         WA_NOTE                         // SOUND_QUERY
2304     };
2305 
2306 #if 0
2307 #if SOUND_COUNT != 5
2308 #error New Sound must be defined!
2309 #endif
2310 #endif
2311 
2312 	debug_printf("Os2SalFrame::Beep %d\n", eSoundType);
2313     WinAlarm( HWND_DESKTOP, aImplSoundTab[eSoundType] );
2314 }
2315 
2316 // -----------------------------------------------------------------------
2317 
GetPointerState()2318 SalFrame::SalPointerState Os2SalFrame::GetPointerState()
2319 {
2320     SalPointerState aState;
2321     aState.mnState = 0;
2322 
2323     // MausModus feststellen und setzen
2324     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON1 ) & 0x8000 )
2325         aState.mnState |= MOUSE_LEFT;
2326     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON2 ) & 0x8000 )
2327         aState.mnState |= MOUSE_RIGHT;
2328     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON3 ) & 0x8000 )
2329         aState.mnState |= MOUSE_MIDDLE;
2330     // Modifier-Tasten setzen
2331     if ( WinGetKeyState( HWND_DESKTOP, VK_SHIFT ) & 0x8000 )
2332         aState.mnState |= KEY_SHIFT;
2333     if ( WinGetKeyState( HWND_DESKTOP, VK_CTRL ) & 0x8000 )
2334         aState.mnState |= KEY_MOD1;
2335     if ( WinGetKeyState( HWND_DESKTOP, VK_ALT ) & 0x8000 )
2336         aState.mnState |= KEY_MOD2;
2337 
2338     POINTL pt;
2339     _WinQueryPointerPos( HWND_DESKTOP, &pt );
2340 
2341     aState.maPos = Point( pt.x - maGeometry.nX, pt.y - maGeometry.nY );
2342     return aState;
2343 }
2344 
2345 // -----------------------------------------------------------------------
2346 
SetBackgroundBitmap(SalBitmap *)2347 void Os2SalFrame::SetBackgroundBitmap( SalBitmap* )
2348 {
2349 }
2350 
2351 // -----------------------------------------------------------------------
2352 
SalTestMouseLeave()2353 void SalTestMouseLeave()
2354 {
2355     SalData* pSalData = GetSalData();
2356 
2357     if ( pSalData->mhWantLeaveMsg && !::WinQueryCapture( HWND_DESKTOP ) )
2358     {
2359         POINTL aPt;
2360         WinQueryPointerPos( HWND_DESKTOP, &aPt );
2361         if ( pSalData->mhWantLeaveMsg != WinWindowFromPoint( HWND_DESKTOP, &aPt, TRUE ) )
2362             WinSendMsg( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, MPFROM2SHORT( aPt.x, aPt.y ) );
2363     }
2364 }
2365 
2366 // -----------------------------------------------------------------------
2367 
ImplHandleMouseMsg(HWND hWnd,UINT nMsg,MPARAM nMP1,MPARAM nMP2)2368 static long ImplHandleMouseMsg( HWND hWnd,
2369                                 UINT nMsg, MPARAM nMP1, MPARAM nMP2 )
2370 {
2371     SalMouseEvent   aMouseEvt;
2372     long            nRet;
2373     USHORT          nEvent;
2374     sal_Bool            bCall = TRUE;
2375     USHORT          nFlags = SHORT2FROMMP( nMP2 );
2376     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
2377     if ( !pFrame )
2378         return 0;
2379 
2380     aMouseEvt.mnX       = (short)SHORT1FROMMP( nMP1 );
2381     aMouseEvt.mnY       = pFrame->mnHeight - (short)SHORT2FROMMP( nMP1 ) - 1;
2382     aMouseEvt.mnCode    = 0;
2383     aMouseEvt.mnTime    = WinQueryMsgTime( pFrame->mhAB );
2384 
2385     // MausModus feststellen und setzen
2386     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON1 ) & 0x8000 )
2387         aMouseEvt.mnCode |= MOUSE_LEFT;
2388     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON2 ) & 0x8000 )
2389         aMouseEvt.mnCode |= MOUSE_RIGHT;
2390     if ( WinGetKeyState( HWND_DESKTOP, VK_BUTTON3 ) & 0x8000 )
2391         aMouseEvt.mnCode |= MOUSE_MIDDLE;
2392     // Modifier-Tasten setzen
2393     if ( WinGetKeyState( HWND_DESKTOP, VK_SHIFT ) & 0x8000 )
2394         aMouseEvt.mnCode |= KEY_SHIFT;
2395     if ( WinGetKeyState( HWND_DESKTOP, VK_CTRL ) & 0x8000 )
2396         aMouseEvt.mnCode |= KEY_MOD1;
2397     if ( WinGetKeyState( HWND_DESKTOP, VK_ALT ) & 0x8000 )
2398         aMouseEvt.mnCode |= KEY_MOD2;
2399 
2400     switch ( nMsg )
2401     {
2402         case WM_MOUSEMOVE:
2403             {
2404             SalData* pSalData = GetSalData();
2405 
2406             // Da bei Druecken von Modifier-Tasten die MouseEvents
2407             // nicht zusammengefast werden (da diese durch KeyEvents
2408             // unterbrochen werden), machen wir dieses hier selber
2409             if ( aMouseEvt.mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2) )
2410             {
2411                 QMSG aTempMsg;
2412                 if ( WinPeekMsg( pSalData->mhAB, &aTempMsg,
2413                                  pFrame->mhWndClient,
2414                                  WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE ) )
2415                 {
2416                     if ( (aTempMsg.msg == WM_MOUSEMOVE) &&
2417                          (aTempMsg.mp2 == nMP2) )
2418                         return 1;
2419                 }
2420             }
2421 
2422             // Test for MouseLeave
2423             if ( pSalData->mhWantLeaveMsg &&
2424                 (pSalData->mhWantLeaveMsg != pFrame->mhWndClient) )
2425             {
2426                 POINTL aMousePoint;
2427                 WinQueryMsgPos( pFrame->mhAB, &aMousePoint );
2428                 WinSendMsg( pSalData->mhWantLeaveMsg,
2429                             SAL_MSG_MOUSELEAVE,
2430                             0, MPFROM2SHORT( aMousePoint.x, aMousePoint.y ) );
2431             }
2432             pSalData->mhWantLeaveMsg = pFrame->mhWndClient;
2433             // Start MouseLeave-Timer
2434             if ( !pSalData->mpMouseLeaveTimer )
2435             {
2436                 pSalData->mpMouseLeaveTimer = new AutoTimer;
2437                 pSalData->mpMouseLeaveTimer->SetTimeout( SAL_MOUSELEAVE_TIMEOUT );
2438                 pSalData->mpMouseLeaveTimer->Start();
2439                 // We dont need to set a timeout handler, because we test
2440                 // for mouseleave in the timeout callback
2441             }
2442             aMouseEvt.mnButton = 0;
2443             nEvent = SALEVENT_MOUSEMOVE;
2444             }
2445             break;
2446 
2447         case SAL_MSG_MOUSELEAVE:
2448             {
2449             SalData* pSalData = GetSalData();
2450             if ( pSalData->mhWantLeaveMsg == pFrame->mhWndClient )
2451             {
2452                 pSalData->mhWantLeaveMsg = 0;
2453                 if ( pSalData->mpMouseLeaveTimer )
2454                 {
2455                     delete pSalData->mpMouseLeaveTimer;
2456                     pSalData->mpMouseLeaveTimer = NULL;
2457                 }
2458 
2459                 // Mouse-Coordinaates are relativ to the screen
2460                 POINTL aPt;
2461                 aPt.x = (short)SHORT1FROMMP( nMP2 );
2462                 aPt.y = (short)SHORT2FROMMP( nMP2 );
2463                 WinMapWindowPoints( HWND_DESKTOP, pFrame->mhWndClient, &aPt, 1 );
2464                 aPt.y = pFrame->mnHeight - aPt.y - 1;
2465                 aMouseEvt.mnX = aPt.x;
2466                 aMouseEvt.mnY = aPt.y;
2467                 aMouseEvt.mnButton = 0;
2468                 nEvent = SALEVENT_MOUSELEAVE;
2469             }
2470             else
2471                 bCall = FALSE;
2472             }
2473             break;
2474 
2475         case WM_BUTTON1DBLCLK:
2476         case WM_BUTTON1DOWN:
2477             aMouseEvt.mnButton = MOUSE_LEFT;
2478             nEvent = SALEVENT_MOUSEBUTTONDOWN;
2479             break;
2480 
2481         case WM_BUTTON2DBLCLK:
2482         case WM_BUTTON2DOWN:
2483             aMouseEvt.mnButton = MOUSE_RIGHT;
2484             nEvent = SALEVENT_MOUSEBUTTONDOWN;
2485             break;
2486 
2487         case WM_BUTTON3DBLCLK:
2488         case WM_BUTTON3DOWN:
2489             aMouseEvt.mnButton = MOUSE_MIDDLE;
2490             nEvent = SALEVENT_MOUSEBUTTONDOWN;
2491             break;
2492 
2493         case WM_BUTTON1UP:
2494             aMouseEvt.mnButton = MOUSE_LEFT;
2495             nEvent = SALEVENT_MOUSEBUTTONUP;
2496             break;
2497 
2498         case WM_BUTTON2UP:
2499             aMouseEvt.mnButton = MOUSE_RIGHT;
2500             nEvent = SALEVENT_MOUSEBUTTONUP;
2501             break;
2502 
2503         case WM_BUTTON3UP:
2504             aMouseEvt.mnButton = MOUSE_MIDDLE;
2505             nEvent = SALEVENT_MOUSEBUTTONUP;
2506             break;
2507     }
2508 
2509 	// check if this window was destroyed - this might happen if we are the help window
2510 	// and sent a mouse leave message to the application which killed the help window, ie ourself
2511 	if( !WinIsWindow( pFrame->mhAB, hWnd ) )
2512 		return 0;
2513 
2514 #if OSL_DEBUG_LEVEL>10
2515 	//if (_bCapture)
2516 		debug_printf("ImplHandleMouseMsg mouse %d,%d\n",aMouseEvt.mnX,aMouseEvt.mnY);
2517 #endif
2518 
2519     if ( bCall )
2520     {
2521         if ( nEvent == SALEVENT_MOUSEBUTTONDOWN )
2522             WinUpdateWindow( pFrame->mhWndClient );
2523 
2524         // --- RTL --- (mirror mouse pos)
2525         //if( Application::GetSettings().GetLayoutRTL() )
2526         //    aMouseEvt.mnX = pFrame->maGeometry.nWidth-1-aMouseEvt.mnX;
2527 
2528         nRet = pFrame->CallCallback( nEvent, &aMouseEvt );
2529         if ( nMsg == WM_MOUSEMOVE )
2530         {
2531             WinSetPointer( HWND_DESKTOP, pFrame->mhPointer );
2532             nRet = TRUE;
2533         }
2534     }
2535     else
2536         nRet = 0;
2537 
2538     return nRet;
2539 }
2540 
2541 // -----------------------------------------------------------------------
2542 
ImplHandleWheelMsg(HWND hWnd,UINT nMsg,MPARAM nMP1,MPARAM nMP2)2543 static long ImplHandleWheelMsg( HWND hWnd, UINT nMsg, MPARAM nMP1, MPARAM nMP2 )
2544 {
2545 
2546     ImplSalYieldMutexAcquireWithWait();
2547 
2548     long        nRet = 0;
2549     Os2SalFrame*   pFrame = GetWindowPtr( hWnd );
2550     if ( pFrame )
2551     {
2552 
2553 		// Mouse-Coordinaates are relativ to the screen
2554 		POINTL aPt;
2555 		WinQueryMsgPos( pFrame->mhAB, &aPt );
2556 		WinMapWindowPoints( HWND_DESKTOP, pFrame->mhWndClient, &aPt, 1 );
2557 		aPt.y = pFrame->mnHeight - aPt.y - 1;
2558 
2559         SalWheelMouseEvent aWheelEvt;
2560 		aWheelEvt.mnTime    		= WinQueryMsgTime( pFrame->mhAB );
2561         aWheelEvt.mnX           	= aPt.x;
2562         aWheelEvt.mnY           	= aPt.y;
2563         aWheelEvt.mnCode       	 	= 0;
2564 		bool bNeg = (SHORT2FROMMP(nMP2) == SB_LINEDOWN || SHORT2FROMMP(nMP2) == SB_PAGEDOWN );
2565 		aWheelEvt.mnDelta			= bNeg ? -120 : 120;
2566 		aWheelEvt.mnNotchDelta		= bNeg ? -1 : 1;
2567 		if (SHORT2FROMMP(nMP2) == SB_PAGEUP || SHORT2FROMMP(nMP2) == SB_PAGEDOWN)
2568 			aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
2569 		else
2570 			aWheelEvt.mnScrollLines = 1;
2571 
2572         if( nMsg == WM_HSCROLL )
2573             aWheelEvt.mbHorz        = TRUE;
2574 
2575 		// Modifier-Tasten setzen
2576 		if ( WinGetKeyState( HWND_DESKTOP, VK_SHIFT ) & 0x8000 )
2577 			aWheelEvt.mnCode |= KEY_SHIFT;
2578 		if ( WinGetKeyState( HWND_DESKTOP, VK_CTRL ) & 0x8000 )
2579 			aWheelEvt.mnCode |= KEY_MOD1;
2580 		if ( WinGetKeyState( HWND_DESKTOP, VK_ALT ) & 0x8000 )
2581 			aWheelEvt.mnCode |= KEY_MOD2;
2582 
2583         nRet = pFrame->CallCallback( SALEVENT_WHEELMOUSE, &aWheelEvt );
2584     }
2585 
2586     ImplSalYieldMutexRelease();
2587 
2588     return nRet;
2589 }
2590 
2591 
2592 // -----------------------------------------------------------------------
2593 
ImplSalGetKeyCode(Os2SalFrame * pFrame,MPARAM aMP1,MPARAM aMP2)2594 static USHORT ImplSalGetKeyCode( Os2SalFrame* pFrame, MPARAM aMP1, MPARAM aMP2 )
2595 {
2596     USHORT  nKeyFlags   = SHORT1FROMMP( aMP1 );
2597     UCHAR   nCharCode   = (UCHAR)SHORT1FROMMP( aMP2 );
2598     USHORT  nKeyCode    = (UCHAR)SHORT2FROMMP( aMP2 );
2599     UCHAR   nScanCode   = (UCHAR)CHAR4FROMMP( aMP1 );
2600 	USHORT	rSVCode = 0;
2601 
2602     // Ist virtueller KeyCode gesetzt und befindet sich der KeyCode in der
2603     // Tabelle, dann mappen
2604     if ( (nKeyFlags & KC_VIRTUALKEY) && (nKeyCode < KEY_TAB_SIZE) )
2605         rSVCode = aImplTranslateKeyTab[nKeyCode];
2606 
2607     // Wenn kein KeyCode ermittelt werden konnte, versuchen wir aus dem
2608     // CharCode einen zu erzeugen
2609     if ( !rSVCode && nCharCode )
2610     {
2611         // Bei 0-9, a-z und A-Z auch KeyCode setzen
2612         if ( (nCharCode >= '0') && (nCharCode <= '9') && (!rSVCode || !(nKeyFlags & KC_SHIFT)) )
2613             rSVCode = KEYGROUP_NUM + (nCharCode-'0');
2614         else if ( (nCharCode >= 'a') && (nCharCode <= 'z') )
2615             rSVCode = KEYGROUP_ALPHA + (nCharCode-'a');
2616         else if ( (nCharCode >= 'A') && (nCharCode <= 'Z') )
2617             rSVCode = KEYGROUP_ALPHA + (nCharCode-'A');
2618         else
2619         {
2620             switch ( nCharCode )
2621             {
2622                 case '+':
2623                     rSVCode = KEY_ADD;
2624                     break;
2625                 case '-':
2626                     rSVCode = KEY_SUBTRACT;
2627                     break;
2628                 case '*':
2629                     rSVCode = KEY_MULTIPLY;
2630                     break;
2631                 case '/':
2632                     rSVCode = KEY_DIVIDE;
2633                     break;
2634                 case '.':
2635                     rSVCode = KEY_POINT;
2636                     break;
2637                 case ',':
2638                     rSVCode = KEY_COMMA;
2639                     break;
2640                 case '<':
2641                     rSVCode = KEY_LESS;
2642                     break;
2643                 case '>':
2644                     rSVCode = KEY_GREATER;
2645                     break;
2646                 case '=':
2647                     rSVCode = KEY_EQUAL;
2648                     break;
2649             }
2650         }
2651     }
2652 
2653     // "Numlock-Hack": we want to get correct keycodes from the numpad
2654     if ( (nCharCode >= '0') && (nCharCode <= '9') && !(nKeyFlags & KC_SHIFT) )
2655         rSVCode = KEYGROUP_NUM + (nCharCode-'0');
2656     if ( nCharCode == ',' )
2657         rSVCode = KEY_COMMA;
2658     if ( nCharCode == '.' )
2659         rSVCode = KEY_POINT;
2660 
2661     return rSVCode;
2662 }
2663 
2664 // -----------------------------------------------------------------------
2665 
ImplUpdateInputLang(Os2SalFrame * pFrame)2666 static void ImplUpdateInputLang( Os2SalFrame* pFrame )
2667 {
2668     sal_Bool 	bLanguageChange = FALSE;
2669     ULONG 	nLang = 0;
2670 	APIRET	rc;
2671 	UconvObject  uconv_object = NULL;
2672 	LocaleObject locale_object = NULL;
2673 	UniChar		*pinfo_item;
2674 
2675 	// we do not support change of input language while working,
2676 	// so exit if already defined (mnInputLang is a static class field)
2677 	if (pFrame->mnInputLang)
2678 		return;
2679 
2680 	// get current locale
2681 	rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locale_object);
2682 	// get Win32 locale id and sublanguage (hex uni string)
2683 	rc = UniQueryLocaleItem(locale_object, LOCI_xWinLocale, &pinfo_item);
2684 	// convert uni string to integer
2685 	rc = UniStrtoul(locale_object, pinfo_item, &pinfo_item, 16, &nLang);
2686 	rc = UniFreeMem(pinfo_item);
2687 #if OSL_DEBUG_LEVEL>10
2688 	debug_printf("ImplUpdateInputLang nLang %04x\n", nLang);
2689 	char         char_buffer[256];
2690 	rc = UniCreateUconvObject((UniChar *)L"", &uconv_object);
2691 	rc = UniQueryLocaleItem(locale_object, LOCI_sKeyboard, &pinfo_item);
2692 	rc = UniStrFromUcs(uconv_object, char_buffer, pinfo_item, sizeof(char_buffer));
2693 	debug_printf("Keyboard name is: %s\n", char_buffer );
2694 	rc = UniFreeMem(pinfo_item);
2695 #endif
2696 	rc = UniFreeLocaleObject(locale_object);
2697 
2698 	// keep input lang up-to-date
2699 #if OSL_DEBUG_LEVEL>10
2700 	debug_printf("ImplUpdateInputLang pFrame %08x lang changed from %d to %d\n",
2701 		pFrame, pFrame->mnInputLang, nLang);
2702 #endif
2703 	pFrame->mnInputLang = nLang;
2704 }
2705 
2706 
ImplGetCharCode(Os2SalFrame * pFrame,USHORT nKeyFlags,sal_Char nCharCode,UCHAR nScanCode)2707 static sal_Unicode ImplGetCharCode( Os2SalFrame* pFrame, USHORT nKeyFlags,
2708 									sal_Char nCharCode, UCHAR nScanCode )
2709 {
2710     ImplUpdateInputLang( pFrame );
2711 #if OSL_DEBUG_LEVEL>10
2712     debug_printf("ImplGetCharCode nCharCode %c, %04x\n", nCharCode, nCharCode);
2713 #endif
2714     return OUString( &nCharCode, 1, gsl_getSystemTextEncoding()).toChar();
2715 }
2716 
2717 // -----------------------------------------------------------------------
2718 
GetInputLanguage()2719 LanguageType Os2SalFrame::GetInputLanguage()
2720 {
2721     if( !mnInputLang )
2722         ImplUpdateInputLang( this );
2723 
2724     if( !mnInputLang )
2725         return LANGUAGE_DONTKNOW;
2726     else
2727         return (LanguageType) mnInputLang;
2728 }
2729 
2730 // -----------------------------------------------------------------------
2731 
MapUnicodeToKeyCode(sal_Unicode,LanguageType,KeyCode &)2732 sal_Bool Os2SalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , KeyCode& )
2733 {
2734     // not supported yet
2735     return FALSE;
2736 }
2737 
2738 // -----------------------------------------------------------------------
2739 
ImplConvertKey(Os2SalFrame * pFrame,MPARAM aMP1,MPARAM aMP2)2740 static sal_Unicode ImplConvertKey( Os2SalFrame* pFrame, MPARAM aMP1, MPARAM aMP2 )
2741 {
2742     USHORT  nKeyFlags   = SHORT1FROMMP( aMP1 );
2743     UCHAR   nCharCode   = (UCHAR)SHORT1FROMMP( aMP2 );
2744     USHORT  nKeyCode    = (UCHAR)SHORT2FROMMP( aMP2 );
2745     UCHAR   nScanCode   = (UCHAR)CHAR4FROMMP( aMP1 );
2746 	sal_Unicode	rSVCharCode = 0;
2747 
2748     // Ist Character-Code gesetzt
2749     // !!! Bei CTRL/ALT ist KC_CHAR nicht gesetzt, jedoch moechten wir
2750     // !!! dann auch einen CharCode und machen die Behandlung deshalb
2751     // !!! selber
2752     if ( (nKeyFlags & KC_CHAR) || (nKeyFlags & KC_CTRL) || (nKeyFlags & KC_ALT) )
2753         rSVCharCode = ImplGetCharCode( pFrame, nKeyFlags, nCharCode, nScanCode);
2754 
2755 	// ret unicode
2756 	return rSVCharCode;
2757 }
2758 
2759 // -----------------------------------------------------------------------
2760 
ImplHandleKeyMsg(HWND hWnd,UINT nMsg,MPARAM nMP1,MPARAM nMP2)2761 static long ImplHandleKeyMsg( HWND hWnd,
2762                               UINT nMsg, MPARAM nMP1, MPARAM nMP2 )
2763 {
2764     static USHORT   nLastOS2KeyChar = 0;
2765     static sal_Unicode   nLastChar       = 0;
2766     USHORT          nRepeat         = CHAR3FROMMP( nMP1 ) - 1;
2767     SHORT           nFlags          = SHORT1FROMMP( nMP1 );
2768     USHORT          nModCode        = 0;
2769     USHORT          nSVCode         = 0;
2770     USHORT          nOS2KeyCode     = (UCHAR)SHORT2FROMMP( nMP2 );
2771     sal_Unicode		nSVCharCode     = 0;
2772     long            nRet            = 0;
2773 
2774     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
2775     if ( !pFrame )
2776         return 0;
2777 
2778     // determine modifiers
2779     if ( nFlags & KC_SHIFT )
2780         nModCode |= KEY_SHIFT;
2781     if ( nFlags & KC_CTRL )
2782         nModCode |= KEY_MOD1;
2783     if ( nFlags & KC_ALT )
2784         nModCode |= KEY_MOD2;
2785 
2786     // Bei Shift, Control und Alt schicken wir einen KeyModChange-Event
2787     if ( (nOS2KeyCode == VK_SHIFT) || (nOS2KeyCode == VK_CTRL) ||
2788          (nOS2KeyCode == VK_ALT) || (nOS2KeyCode == VK_ALTGRAF) )
2789     {
2790         SalKeyModEvent aModEvt;
2791         aModEvt.mnTime = WinQueryMsgTime( pFrame->mhAB );
2792         aModEvt.mnCode = nModCode;
2793 #if OSL_DEBUG_LEVEL>10
2794 		debug_printf("SALEVENT_KEYMODCHANGE\n");
2795 #endif
2796         nRet = pFrame->CallCallback( SALEVENT_KEYMODCHANGE, &aModEvt );
2797     }
2798     else
2799     {
2800 		nSVCode = ImplSalGetKeyCode( pFrame, nMP1, nMP2 );
2801         nSVCharCode = ImplConvertKey( pFrame, nMP1, nMP2 );
2802 #if OSL_DEBUG_LEVEL>10
2803 		debug_printf("nSVCode %04x nSVCharCode %04x\n",nSVCode,nSVCharCode );
2804 #endif
2805 
2806         // Fuer Java muessen wir bei KeyUp einen CharCode liefern
2807         if ( nFlags & KC_KEYUP )
2808         {
2809             if ( !nSVCharCode )
2810             {
2811                 if ( nLastOS2KeyChar == nOS2KeyCode )
2812                 {
2813                     nSVCharCode     = nLastChar;
2814                     nLastOS2KeyChar = 0;
2815                     nLastChar       = 0;
2816                 }
2817             }
2818             else
2819             {
2820                 nLastOS2KeyChar = 0;
2821                 nLastChar       = 0;
2822             }
2823         }
2824         else
2825         {
2826             nLastOS2KeyChar = nOS2KeyCode;
2827             nLastChar       = nSVCharCode;
2828         }
2829 
2830         if ( nSVCode || nSVCharCode )
2831         {
2832             SalKeyEvent aKeyEvt;
2833             aKeyEvt.mnCode      = nSVCode;
2834             aKeyEvt.mnTime      = WinQueryMsgTime( pFrame->mhAB );
2835             aKeyEvt.mnCode     |= nModCode;
2836             aKeyEvt.mnCharCode  = nSVCharCode;
2837             aKeyEvt.mnRepeat    = nRepeat;
2838 
2839 #if OSL_DEBUG_LEVEL>10
2840 			debug_printf( (nFlags & KC_KEYUP) ? "SALEVENT_KEYUP\n" : "SALEVENT_KEYINPUT\n");
2841 #endif
2842             nRet = pFrame->CallCallback( (nFlags & KC_KEYUP) ? SALEVENT_KEYUP : SALEVENT_KEYINPUT,
2843                                                &aKeyEvt );
2844         }
2845     }
2846 
2847     return nRet;
2848 }
2849 
2850 // -----------------------------------------------------------------------
2851 
ImplHandlePaintMsg(HWND hWnd)2852 static bool ImplHandlePaintMsg( HWND hWnd )
2853 {
2854     sal_Bool bMutex = FALSE;
2855 
2856     if ( ImplSalYieldMutexTryToAcquire() )
2857         bMutex = TRUE;
2858 
2859     // if we don't get the mutex, we can also change the clip region,
2860     // because other threads doesn't use the mutex from the main
2861     // thread --> see GetGraphics()
2862 
2863     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
2864     if ( pFrame )
2865     {
2866         // Laut Window-Doku soll man erst abfragen, ob ueberhaupt eine
2867         // Paint-Region anliegt
2868         if ( WinQueryUpdateRect( hWnd, NULL ) )
2869         {
2870             // Call BeginPaint/EndPaint to query the rect and send
2871             // this Notofication to rect
2872 			HPS     hPS;
2873 			RECTL   aUpdateRect;
2874 			hPS = WinBeginPaint( hWnd, NULLHANDLE, &aUpdateRect );
2875 			WinEndPaint( hPS );
2876 
2877             // Paint
2878             if ( bMutex )
2879             {
2880 		SalPaintEvent aPEvt( aUpdateRect.xLeft, pFrame->mnHeight - aUpdateRect.yTop, aUpdateRect.xRight- aUpdateRect.xLeft, aUpdateRect.yTop - aUpdateRect.yBottom );
2881 
2882                 pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
2883             }
2884             else
2885             {
2886                 RECTL* pRect = new RECTL;
2887                 WinCopyRect( pFrame->mhAB, pRect, &aUpdateRect );
2888                 WinPostMsg( hWnd, SAL_MSG_POSTPAINT, (MPARAM)pRect, 0 );
2889             }
2890 		}
2891 	}
2892 
2893     if ( bMutex )
2894         ImplSalYieldMutexRelease();
2895 
2896 	return bMutex ? true : false;
2897 }
2898 
2899 // -----------------------------------------------------------------------
2900 
ImplHandlePaintMsg2(HWND hWnd,RECTL * pRect)2901 static void ImplHandlePaintMsg2( HWND hWnd, RECTL* pRect )
2902 {
2903     // Paint
2904     if ( ImplSalYieldMutexTryToAcquire() )
2905     {
2906         Os2SalFrame* pFrame = GetWindowPtr( hWnd );
2907         if ( pFrame )
2908         {
2909             SalPaintEvent aPEvt( pRect->xLeft, pFrame->mnHeight - pRect->yTop, pRect->xRight - pRect->xLeft, pRect->yTop - pRect->yBottom );
2910             pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
2911         }
2912         ImplSalYieldMutexRelease();
2913         delete pRect;
2914     }
2915     else
2916         WinPostMsg( hWnd, SAL_MSG_POSTPAINT, (MPARAM)pRect, 0 );
2917 }
2918 
2919 // -----------------------------------------------------------------------
2920 
SetMaximizedFrameGeometry(HWND hWnd,Os2SalFrame * pFrame)2921 static void SetMaximizedFrameGeometry( HWND hWnd, Os2SalFrame* pFrame )
2922 {
2923     // calculate and set frame geometry of a maximized window - useful if the window is still hidden
2924 
2925     RECTL aRect;
2926     pFrame->GetWorkArea( aRect);
2927 
2928     // a maximized window has no other borders than the caption
2929     pFrame->maGeometry.nLeftDecoration = pFrame->maGeometry.nRightDecoration = pFrame->maGeometry.nBottomDecoration = 0;
2930     pFrame->maGeometry.nTopDecoration = pFrame->mbCaption ? WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) : 0;
2931 
2932     aRect.yTop += pFrame->maGeometry.nTopDecoration;
2933     pFrame->maGeometry.nX = aRect.xLeft;
2934     pFrame->maGeometry.nY = aRect.yBottom;
2935     pFrame->maGeometry.nWidth = aRect.xRight - aRect.xLeft + 1;
2936     pFrame->maGeometry.nHeight = aRect.yBottom - aRect.yTop + 1;
2937 }
2938 
UpdateFrameGeometry(HWND hWnd,Os2SalFrame * pFrame)2939 static void UpdateFrameGeometry( HWND hWnd, Os2SalFrame* pFrame )
2940 {
2941     if( !pFrame )
2942         return;
2943 
2944 	//SalFrame has a
2945 	//maGeometry member that holds absolute screen positions (and needs to be
2946 	//updated if the window is moved by the way).
2947 
2948 	// reset data
2949     memset(&pFrame->maGeometry, 0, sizeof(SalFrameGeometry) );
2950 
2951 	SWP	swp;
2952 	LONG nFrameX, nFrameY, nCaptionY;
2953 
2954 	// get frame size
2955 	WinQueryWindowPos(pFrame->mhWndFrame, &swp);
2956 	if (swp.fl & SWP_MINIMIZE)
2957       return;
2958 
2959 	// map from client area to screen
2960     ImplSalCalcFrameSize( pFrame, nFrameX, nFrameY, nCaptionY);
2961     pFrame->maGeometry.nTopDecoration = nFrameY + nCaptionY;
2962     pFrame->maGeometry.nLeftDecoration = nFrameX;
2963     pFrame->maGeometry.nRightDecoration = nFrameX;
2964 	pFrame->maGeometry.nBottomDecoration = nFrameY;
2965 
2966 	// position of client area, not of frame corner!
2967     pFrame->maGeometry.nX = swp.x + nFrameX;
2968     pFrame->maGeometry.nY = nScreenHeight - (swp.y + swp.cy) + nFrameY + nCaptionY;
2969 
2970     int nWidth  = swp.cx - pFrame->maGeometry.nRightDecoration - pFrame->maGeometry.nLeftDecoration;
2971     int nHeight = swp.cy - pFrame->maGeometry.nBottomDecoration - pFrame->maGeometry.nTopDecoration;
2972 
2973     // clamp to zero
2974     pFrame->maGeometry.nHeight = nHeight < 0 ? 0 : nHeight;
2975     pFrame->maGeometry.nWidth = nWidth < 0 ? 0 : nWidth;
2976 #if OSL_DEBUG_LEVEL>0
2977 	debug_printf( "UpdateFrameGeometry: hwnd %x, frame %x at %d,%d (%dx%d)\n",
2978 		hWnd, pFrame->mhWndFrame,
2979 		pFrame->maGeometry.nX, pFrame->maGeometry.nY,
2980 		pFrame->maGeometry.nWidth,pFrame->maGeometry.nHeight);
2981 #endif
2982 }
2983 
2984 // -----------------------------------------------------------------------
2985 
ImplHandleMoveMsg(HWND hWnd)2986 static void ImplHandleMoveMsg( HWND hWnd)
2987 {
2988     if ( ImplSalYieldMutexTryToAcquire() )
2989     {
2990         Os2SalFrame* pFrame = GetWindowPtr( hWnd );
2991         if ( pFrame )
2992         {
2993             UpdateFrameGeometry( hWnd, pFrame );
2994 
2995             if ( WinIsWindowVisible( hWnd ))
2996 				pFrame->mbDefPos = FALSE;
2997 
2998 			// Gegen moegliche Rekursionen sichern
2999 			if ( !pFrame->mbInMoveMsg )
3000 			{
3001 				// Fenster im FullScreenModus wieder einpassen
3002 				pFrame->mbInMoveMsg = TRUE;
3003 				if ( pFrame->mbFullScreen )
3004 					ImplSalFrameFullScreenPos( pFrame );
3005 				pFrame->mbInMoveMsg = FALSE;
3006 			}
3007 
3008 			// Status merken
3009 			ImplSaveFrameState( pFrame );
3010 
3011             // Call Hdl
3012             //#93851 if we call this handler, VCL floating windows are not updated correctly
3013             //ImplCallMoveHdl( hWnd );
3014 
3015         }
3016 
3017         ImplSalYieldMutexRelease();
3018     }
3019     else
3020 		WinPostMsg( hWnd, SAL_MSG_POSTMOVE, 0, 0 );
3021 }
3022 
3023 // -----------------------------------------------------------------------
3024 
ImplHandleSizeMsg(HWND hWnd,MPARAM nMP2)3025 static void ImplHandleSizeMsg( HWND hWnd, MPARAM nMP2 )
3026 {
3027         Os2SalFrame* pFrame = GetWindowPtr( hWnd );
3028         if ( pFrame )
3029         {
3030             UpdateFrameGeometry( hWnd, pFrame );
3031 			pFrame->mbDefPos = FALSE;
3032 			pFrame->mnWidth  = (short)SHORT1FROMMP( nMP2 );
3033 			pFrame->mnHeight = (short)SHORT2FROMMP( nMP2 );
3034 			if ( pFrame->mpGraphics )
3035 				pFrame->mpGraphics->mnHeight = (int)SHORT2FROMMP(nMP2);
3036 			// Status merken
3037 			ImplSaveFrameState( pFrame );
3038 			pFrame->CallCallback( SALEVENT_RESIZE, 0 );
3039 			if ( WinIsWindowVisible( pFrame->mhWndFrame ) && !pFrame->mbInShow )
3040 				WinUpdateWindow( pFrame->mhWndClient );
3041 		}
3042 }
3043 
3044 // -----------------------------------------------------------------------
3045 
ImplHandleFocusMsg(Os2SalFrame * pFrame,MPARAM nMP2)3046 static long ImplHandleFocusMsg( Os2SalFrame* pFrame, MPARAM nMP2 )
3047 {
3048 if ( pFrame && !Os2SalFrame::mbInReparent )
3049 {
3050     if ( SHORT1FROMMP( nMP2 ) )
3051     {
3052         if ( WinIsWindowVisible( pFrame->mhWndFrame ) && !pFrame->mbInShow )
3053             WinUpdateWindow( pFrame->mhWndClient );
3054         return pFrame->CallCallback( SALEVENT_GETFOCUS, 0 );
3055     }
3056     else
3057     {
3058         return pFrame->CallCallback( SALEVENT_LOSEFOCUS, 0 );
3059     }
3060 }
3061 }
3062 
3063 // -----------------------------------------------------------------------
3064 
ImplHandleCloseMsg(HWND hWnd)3065 static void ImplHandleCloseMsg( HWND hWnd )
3066 {
3067     if ( ImplSalYieldMutexTryToAcquire() )
3068     {
3069         Os2SalFrame* pFrame = GetWindowPtr( hWnd );
3070         if ( pFrame )
3071         {
3072             pFrame->CallCallback( SALEVENT_CLOSE, 0 );
3073         }
3074 
3075         ImplSalYieldMutexRelease();
3076     }
3077     else
3078         WinPostMsg( hWnd, WM_CLOSE, 0, 0 );
3079 }
3080 
3081 // -----------------------------------------------------------------------
3082 
ImplHandleUserEvent(HWND hWnd,MPARAM nMP2)3083 inline void ImplHandleUserEvent( HWND hWnd, MPARAM nMP2 )
3084 {
3085     ImplSalYieldMutexAcquireWithWait();
3086     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
3087     if ( pFrame )
3088     {
3089         pFrame->CallCallback( SALEVENT_USEREVENT, (void*)nMP2 );
3090     }
3091     ImplSalYieldMutexRelease();
3092 }
3093 
3094 // -----------------------------------------------------------------------
3095 
SalImplHandleProcessMenu(Os2SalFrame * pFrame,ULONG nMsg,MPARAM nMP1,MPARAM nMP2)3096 static int SalImplHandleProcessMenu( Os2SalFrame* pFrame, ULONG nMsg, MPARAM nMP1, MPARAM nMP2)
3097 {
3098     long nRet = 0;
3099 debug_printf("SalImplHandleProcessMenu\n");
3100 #if 0
3101     DWORD err=0;
3102     if( !HIWORD(wParam) )
3103     {
3104         // Menu command
3105         WORD nId = LOWORD(wParam);
3106         if( nId )   // zero for separators
3107         {
3108             SalMenuEvent aMenuEvt;
3109             aMenuEvt.mnId   = nId;
3110             WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( pFrame->mSelectedhMenu, nId, FALSE );
3111             if( pSalMenuItem )
3112                 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
3113             else
3114                 aMenuEvt.mpMenu = NULL;
3115 
3116             nRet = pFrame->CallCallback( SALEVENT_MENUCOMMAND, &aMenuEvt );
3117         }
3118     }
3119 #endif
3120     //return (nRet != 0);
3121     return (nRet == 0);
3122 }
3123 
3124 // -----------------------------------------------------------------------
3125 
ImplHandleInputLangChange(HWND hWnd)3126 static void ImplHandleInputLangChange( HWND hWnd )
3127 {
3128     ImplSalYieldMutexAcquireWithWait();
3129 
3130     // Feststellen, ob wir IME unterstuetzen
3131     Os2SalFrame* pFrame = GetWindowPtr( hWnd );
3132 #if 0
3133     if ( pFrame && pFrame->mbIME && pFrame->mhDefIMEContext )
3134     {
3135         HWND    hWnd = pFrame->mhWnd;
3136         HKL     hKL = (HKL)lParam;
3137         UINT    nImeProps = ImmGetProperty( hKL, IGP_PROPERTY );
3138 
3139         pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
3140         pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
3141         pFrame->mbHandleIME = !pFrame->mbSpezIME;
3142     }
3143 #endif
3144 
3145     // trigger input language and codepage update
3146     UINT nLang = pFrame->mnInputLang;
3147     ImplUpdateInputLang( pFrame );
3148 	debug_printf("ImplHandleInputLangChange new language 0x%04x\n",pFrame->mnInputLang);
3149 
3150     // notify change
3151     if( nLang != pFrame->mnInputLang )
3152         pFrame->CallCallback( SALEVENT_INPUTLANGUAGECHANGE, 0 );
3153 
3154     ImplSalYieldMutexRelease();
3155 }
3156 
3157 // -----------------------------------------------------------------------
3158 
3159 #ifdef ENABLE_IME
3160 
ImplHandleIMEStartConversion(Os2SalFrame * pFrame)3161 static long ImplHandleIMEStartConversion( Os2SalFrame* pFrame )
3162 {
3163     long        nRet = FALSE;
3164     SalIMEData* pIMEData = GetSalIMEData();
3165     if ( pIMEData )
3166     {
3167         HWND hWnd = pFrame->mhWndClient;
3168         HIMI hIMI = 0;
3169         pIMEData->mpGetIME( hWnd, &hIMI );
3170         if ( hIMI )
3171         {
3172             ULONG nProp;
3173             if ( 0 != pIMEData->mpQueryIMEProperty( hIMI, QIP_PROPERTY, &nProp ) )
3174                 pFrame->mbHandleIME = FALSE;
3175             else
3176             {
3177                 pFrame->mbHandleIME = !(nProp & PRP_SPECIALUI);
3178 
3179             }
3180             if ( pFrame->mbHandleIME )
3181             {
3182 /* Windows-Code, der noch nicht angepasst wurde !!!
3183                 // Cursor-Position ermitteln und aus der die Default-Position fuer
3184                 // das Composition-Fenster berechnen
3185                 SalCursorPosEvent aCursorPosEvt;
3186                 pFrame->CallCallback( pFrame->mpInst, pFrame,
3187                                             SALEVENT_CURSORPOS, (void*)&aCursorPosEvt );
3188                 COMPOSITIONFORM aForm;
3189                 memset( &aForm, 0, sizeof( aForm ) );
3190                 if ( !aCursorPosEvt.mnWidth || !aCursorPosEvt.mnHeight )
3191                     aForm.dwStyle |= CFS_DEFAULT;
3192                 else
3193                 {
3194                     aForm.dwStyle          |= CFS_POINT;
3195                     aForm.ptCurrentPos.x    = aCursorPosEvt.mnX;
3196                     aForm.ptCurrentPos.y    = aCursorPosEvt.mnY;
3197                 }
3198                 ImmSetCompositionWindow( hIMC, &aForm );
3199 
3200                 // Den InputContect-Font ermitteln und diesem dem Composition-Fenster
3201                 // bekannt machen
3202 */
3203 
3204                 pFrame->mbConversionMode = TRUE;
3205                 pFrame->CallCallback( SALEVENT_STARTEXTTEXTINPUT, (void*)NULL );
3206                 nRet = TRUE;
3207             }
3208 
3209             pIMEData->mpReleaseIME( hWnd, hIMI );
3210         }
3211     }
3212 
3213     return nRet;
3214 }
3215 
3216 // -----------------------------------------------------------------------
3217 
ImplHandleIMEConversion(Os2SalFrame * pFrame,MPARAM nMP2Param)3218 static long ImplHandleIMEConversion( Os2SalFrame* pFrame, MPARAM nMP2Param )
3219 {
3220     long        nRet = FALSE;
3221     SalIMEData* pIMEData = GetSalIMEData();
3222     if ( pIMEData )
3223     {
3224         HWND        hWnd = pFrame->mhWndClient;
3225         HIMI        hIMI = 0;
3226         ULONG    nMP2 = (ULONG)nMP2Param;
3227         pIMEData->mpGetIME( hWnd, &hIMI );
3228         if ( hIMI )
3229         {
3230             if ( nMP2 & (IMR_RESULT_RESULTSTRING |
3231                          IMR_CONV_CONVERSIONSTRING | IMR_CONV_CONVERSIONATTR |
3232                          IMR_CONV_CURSORPOS | IMR_CONV_CURSORATTR) )
3233             {
3234                 SalExtTextInputEvent aEvt;
3235                 aEvt.mnTime             = WinQueryMsgTime( pFrame->mhAB );
3236                 aEvt.mpTextAttr         = NULL;
3237                 aEvt.mnCursorPos        = 0;
3238                 aEvt.mnDeltaStart       = 0;
3239                 aEvt.mbOnlyCursor       = FALSE;
3240                 aEvt.mbCursorVisible    = TRUE;
3241 
3242                 ULONG    nBufLen = 0;
3243                 xub_Unicode*     pBuf = NULL;
3244                 ULONG    nAttrBufLen = 0;
3245                 PM_BYTE*    pAttrBuf = NULL;
3246                 sal_Bool        bLastCursor = FALSE;
3247                 if ( nMP2 & IMR_RESULT_RESULTSTRING )
3248                 {
3249                     pIMEData->mpGetResultString( hIMI, IMR_RESULT_RESULTSTRING, 0, &nBufLen );
3250                     if ( nBufLen > 0 )
3251                     {
3252                         pBuf = new xub_Unicode[nBufLen];
3253                         pIMEData->mpGetResultString( hIMI, IMR_RESULT_RESULTSTRING, pBuf, &nBufLen );
3254                     }
3255 
3256                     bLastCursor = TRUE;
3257                     aEvt.mbCursorVisible = TRUE;
3258                 }
3259                 else if ( nMP2 & (IMR_CONV_CONVERSIONSTRING | IMR_CONV_CONVERSIONATTR |
3260                                   IMR_CONV_CURSORPOS | IMR_CONV_CURSORATTR) )
3261                 {
3262                     pIMEData->mpGetConversionString( hIMI, IMR_CONV_CONVERSIONSTRING, 0, &nBufLen );
3263                     if ( nBufLen > 0 )
3264                     {
3265                         pBuf = new xub_Unicode[nBufLen];
3266                         pIMEData->mpGetConversionString( hIMI, IMR_CONV_CONVERSIONSTRING, pBuf, &nBufLen );
3267                     }
3268 
3269                     pIMEData->mpGetConversionString( hIMI, IMR_CONV_CONVERSIONATTR, 0, &nAttrBufLen );
3270                     if ( nAttrBufLen > 0 )
3271                     {
3272                         pAttrBuf = new PM_BYTE[nAttrBufLen];
3273                         pIMEData->mpGetConversionString( hIMI, IMR_CONV_CONVERSIONATTR, pAttrBuf, &nAttrBufLen );
3274                     }
3275 
3276 /* !!! Wir bekommen derzeit nur falsche Daten, deshalb zeigen wir derzeit
3277    !!! auch keine Cursor an
3278                     ULONG nTempBufLen;
3279                     ULONG nCursorPos = 0;
3280                     ULONG nCursorAttr = 0;
3281                     ULONG nChangePos = 0;
3282                     nTempBufLen = sizeof( ULONG );
3283                     pIMEData->mpGetConversionString( hIMI, IMR_CONV_CURSORPOS, &nCursorPos, &nTempBufLen );
3284                     nTempBufLen = sizeof( ULONG );
3285                     pIMEData->mpGetConversionString( hIMI, IMR_CONV_CURSORATTR, &nCursorAttr, &nTempBufLen );
3286                     nTempBufLen = sizeof( ULONG );
3287                     pIMEData->mpGetConversionString( hIMI, IMR_CONV_CHANGESTART, &nChangePos, &nTempBufLen );
3288 
3289                     aEvt.mnCursorPos = nCursorPos;
3290                     aEvt.mnDeltaStart = nChangePos;
3291                     if ( nCursorAttr & CP_CURSORATTR_INVISIBLE )
3292                         aEvt.mbCursorVisible = FALSE;
3293 */
3294                     aEvt.mnCursorPos = 0;
3295                     aEvt.mnDeltaStart = 0;
3296                     aEvt.mbCursorVisible = FALSE;
3297 
3298                     if ( (nMP2 == IMR_CONV_CURSORPOS) ||
3299                          (nMP2 == IMR_CONV_CURSORATTR) )
3300                         aEvt.mbOnlyCursor = TRUE;
3301                 }
3302 
3303                 USHORT* pSalAttrAry = NULL;
3304                 if ( pBuf )
3305                 {
3306                     aEvt.maText = XubString( pBuf, (USHORT)nBufLen );
3307                     delete [] pBuf;
3308                     if ( pAttrBuf )
3309                     {
3310                         USHORT nTextLen = aEvt.maText.Len();
3311                         if ( nTextLen )
3312                         {
3313                             pSalAttrAry = new USHORT[nTextLen];
3314                             memset( pSalAttrAry, 0, nTextLen*sizeof( USHORT ) );
3315                             for ( USHORT i = 0; (i < nTextLen) && (i < nAttrBufLen); i++ )
3316                             {
3317                                 PM_BYTE nOS2Attr = pAttrBuf[i];
3318                                 USHORT  nSalAttr;
3319                                 if ( nOS2Attr == CP_ATTR_TARGET_CONVERTED )
3320                                     nSalAttr = SAL_EXTTEXTINPUT_ATTR_TARGETCONVERTED | SAL_EXTTEXTINPUT_ATTR_UNDERLINE | SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT;
3321                                 else if ( nOS2Attr == CP_ATTR_CONVERTED )
3322                                     nSalAttr = SAL_EXTTEXTINPUT_ATTR_CONVERTED | SAL_EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE;
3323                                 else if ( nOS2Attr == CP_ATTR_TARGET_NOTCONVERTED )
3324                                     nSalAttr = SAL_EXTTEXTINPUT_ATTR_TARGETNOTCONVERTED | SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
3325                                 else if ( nOS2Attr == CP_ATTR_INPUT_ERROR )
3326                                     nSalAttr = SAL_EXTTEXTINPUT_ATTR_INPUTERROR | SAL_EXTTEXTINPUT_ATTR_REDTEXT | SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
3327                                 else /* ( nOS2Attr == CP_ATTR_INPUT ) */
3328                                     nSalAttr = SAL_EXTTEXTINPUT_ATTR_INPUT | SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
3329                                 pSalAttrAry[i] = nSalAttr;
3330                             }
3331                             aEvt.mpTextAttr = pSalAttrAry;
3332                         }
3333                         delete [] pAttrBuf;
3334                     }
3335                     if ( bLastCursor )
3336                         aEvt.mnCursorPos = aEvt.maText.Len();
3337                 }
3338 
3339                 pIMEData->mpReleaseIME( hWnd, hIMI );
3340 
3341                 // Handler rufen und wenn wir ein Attribute-Array haben, danach
3342                 // wieder zerstoeren
3343                 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
3344                 if ( pSalAttrAry )
3345                     delete [] pSalAttrAry;
3346             }
3347             else
3348                 pIMEData->mpReleaseIME( hWnd, hIMI );
3349         }
3350 
3351         nRet = TRUE;
3352     }
3353 
3354     return nRet;
3355 }
3356 
3357 // -----------------------------------------------------------------------
3358 
ImplHandleIMEEndConversion(Os2SalFrame * pFrame)3359 inline long ImplHandleIMEEndConversion( Os2SalFrame* pFrame )
3360 {
3361     pFrame->mbConversionMode = FALSE;
3362     pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
3363     return TRUE;
3364 }
3365 
3366 // -----------------------------------------------------------------------
3367 
ImplHandleIMEOpenCandidate(Os2SalFrame * pFrame)3368 static void ImplHandleIMEOpenCandidate( Os2SalFrame* pFrame )
3369 {
3370     pFrame->mbCandidateMode = TRUE;
3371 
3372     long        nRet = FALSE;
3373     SalIMEData* pIMEData = GetSalIMEData();
3374     if ( pIMEData )
3375     {
3376         HWND        hWnd = pFrame->mhWndClient;
3377         HIMI        hIMI = 0;
3378         pIMEData->mpGetIME( hWnd, &hIMI );
3379         if ( hIMI )
3380         {
3381             ULONG nBufLen = 0;
3382             pIMEData->mpGetConversionString( hIMI, IMR_CONV_CONVERSIONSTRING, 0, &nBufLen );
3383             if ( nBufLen > 0 )
3384             {
3385 /* !!! Wir bekommen derzeit nur falsche Daten steht der Cursor immer bei 0
3386                 ULONG nTempBufLen = sizeof( ULONG );
3387                 ULONG nCursorPos = 0;
3388                 pIMEData->mpGetConversionString( hIMI, IMR_CONV_CURSORPOS, &nCursorPos, &nTempBufLen );
3389 */
3390                 ULONG nCursorPos = 0;
3391 
3392                 SalExtTextInputPosEvent aEvt;
3393                 aEvt.mnTime         = WinQueryMsgTime( pFrame->mhAB );
3394                 aEvt.mnFirstPos     = nCursorPos;
3395                 aEvt.mnChars        = nBufLen-nCursorPos;
3396                 aEvt.mpPosAry       = new SalExtCharPos[aEvt.mnChars];
3397                 memset( aEvt.mpPosAry, 0, aEvt.mnChars*sizeof(SalExtCharPos) );
3398 
3399                 pFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void*)&aEvt );
3400 
3401                 long nMinLeft   = aEvt.mpPosAry[0].mnX;
3402                 long nMinTop    = aEvt.mpPosAry[0].mnY;
3403                 long nMaxBottom = aEvt.mpPosAry[0].mnY+aEvt.mpPosAry[0].mnHeight;
3404                 long nMaxRight  = nMinLeft;
3405                 USHORT i = 0;
3406                 while ( i < aEvt.mnChars )
3407                 {
3408                     // Solange wir uns auf der gleichen Zeile bewegen,
3409                     // ermitteln wir die Rechteck-Grenzen
3410                     if ( !aEvt.mpPosAry[i].mnHeight ||
3411                          (aEvt.mpPosAry[i].mnY < nMaxBottom-1) )
3412                     {
3413                         if ( aEvt.mpPosAry[i].mnX < nMinLeft )
3414                             nMinLeft = aEvt.mpPosAry[i].mnX;
3415                         if ( aEvt.mpPosAry[i].mnX+aEvt.mpPosAry[0].mnWidth > nMaxRight )
3416                             nMaxRight = aEvt.mpPosAry[i].mnX+aEvt.mpPosAry[0].mnWidth;
3417                         if ( aEvt.mpPosAry[i].mnY < nMinTop )
3418                             nMinTop = aEvt.mpPosAry[i].mnY;
3419                         i++;
3420                     }
3421                     else
3422                         break;
3423                 }
3424 
3425                 CANDIDATEPOS aForm;
3426                 aForm.ulIndex           = 0;
3427                 aForm.ulStyle           = CPS_EXCLUDE;
3428                 aForm.ptCurrentPos.x    = aEvt.mpPosAry[0].mnX;
3429                 aForm.ptCurrentPos.y    = pFrame->mnHeight - (nMaxBottom+1) - 1;
3430                 aForm.rcArea.xLeft      = nMinLeft;
3431                 aForm.rcArea.yBottom    = pFrame->mnHeight - nMaxBottom - 1;
3432                 aForm.rcArea.xRight     = nMaxRight+1;
3433                 aForm.rcArea.yTop       = pFrame->mnHeight - nMinTop - 1;
3434                 pIMEData->mpSetCandidateWin( hIMI, &aForm );
3435 
3436                 delete aEvt.mpPosAry;
3437             }
3438 
3439             pIMEData->mpReleaseIME( hWnd, hIMI );
3440         }
3441     }
3442 }
3443 
3444 // -----------------------------------------------------------------------
3445 
ImplHandleIMECloseCandidate(Os2SalFrame * pFrame)3446 inline void ImplHandleIMECloseCandidate( Os2SalFrame* pFrame )
3447 {
3448     pFrame->mbCandidateMode = FALSE;
3449 }
3450 
3451 #endif
3452 
3453 // -----------------------------------------------------------------------
3454 
SalFrameWndProc(HWND hWnd,ULONG nMsg,MPARAM nMP1,MPARAM nMP2)3455 MRESULT EXPENTRY SalFrameWndProc( HWND hWnd, ULONG nMsg,
3456                                   MPARAM nMP1, MPARAM nMP2 )
3457 {
3458     Os2SalFrame*   	pFrame      = (Os2SalFrame*)GetWindowPtr( hWnd );
3459     MRESULT     	nRet        = (MRESULT)0;
3460     sal_Bool        	bDef     	= TRUE;
3461 	bool 			bCheckTimers= false;
3462 
3463 #if OSL_DEBUG_LEVEL>10
3464     if (nMsg!=WM_TIMER && nMsg!=WM_MOUSEMOVE)
3465         debug_printf( "SalFrameWndProc hWnd 0x%x nMsg 0x%x\n", hWnd, nMsg);
3466 #endif
3467 
3468     switch( nMsg )
3469     {
3470         case WM_MOUSEMOVE:
3471         case WM_BUTTON1DOWN:
3472         case WM_BUTTON2DOWN:
3473         case WM_BUTTON3DOWN:
3474         case WM_BUTTON1DBLCLK:
3475         case WM_BUTTON2DBLCLK:
3476         case WM_BUTTON3DBLCLK:
3477         case WM_BUTTON1UP:
3478         case WM_BUTTON2UP:
3479         case WM_BUTTON3UP:
3480         case SAL_MSG_MOUSELEAVE:
3481             // ButtonUp/Down nie an die WinDefWindowProc weiterleiten, weil sonst
3482             // die Message an den Owner weitergeleitet wird
3483             ImplSalYieldMutexAcquireWithWait();
3484             bDef = !ImplHandleMouseMsg( hWnd, nMsg, nMP1, nMP2 );
3485             ImplSalYieldMutexRelease();
3486             break;
3487 
3488         case WM_CHAR:
3489             if ( pFrame->mbConversionMode )
3490                 bDef = FALSE;
3491             else
3492                 bDef = !ImplHandleKeyMsg( hWnd, nMsg, nMP1, nMP2 );
3493             break;
3494 
3495         case WM_ERASEBACKGROUND:
3496             nRet = (MRESULT)FALSE;
3497             bDef = FALSE;
3498             break;
3499 
3500         case WM_PAINT:
3501             bCheckTimers = ImplHandlePaintMsg( hWnd );
3502             bDef = FALSE;
3503             break;
3504         case SAL_MSG_POSTPAINT:
3505         	ImplHandlePaintMsg2( hWnd, (RECTL*)nMP1 );
3506 			bCheckTimers = true;
3507         	bDef = FALSE;
3508 			break;
3509 
3510         case WM_MOVE:
3511         case SAL_MSG_POSTMOVE:
3512             ImplHandleMoveMsg( hWnd );
3513             bDef = FALSE;
3514             break;
3515 
3516         case WM_SIZE:
3517             if ( ImplSalYieldMutexTryToAcquire() )
3518             {
3519                 ImplHandleSizeMsg( hWnd, nMP2 );
3520                 ImplSalYieldMutexRelease();
3521             }
3522             else
3523                 WinPostMsg( hWnd, SAL_MSG_POSTSIZE, nMP1, nMP2 );
3524             break;
3525         case SAL_MSG_POSTSIZE:
3526             ImplHandleSizeMsg( hWnd, nMP2 );
3527             break;
3528 		case WM_MINMAXFRAME:
3529             if ( ImplSalYieldMutexTryToAcquire() )
3530             {
3531 				PSWP pswp = (PSWP) nMP1;
3532                 ImplHandleSizeMsg( hWnd, MPFROM2SHORT( pswp->cx, pswp->cy) );
3533                 ImplSalYieldMutexRelease();
3534             }
3535             else
3536                 WinPostMsg( hWnd, SAL_MSG_POSTSIZE, 0, nMP2 );
3537 			break;
3538 
3539         case WM_CALCVALIDRECTS:
3540             return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
3541 
3542         case WM_SETFOCUS:
3543             if ( ImplSalYieldMutexTryToAcquire() )
3544             {
3545                 ImplHandleFocusMsg( pFrame, nMP2 );
3546                 ImplSalYieldMutexRelease();
3547             }
3548             else
3549                 WinPostMsg( hWnd, SAL_MSG_POSTFOCUS, 0, nMP2 );
3550             break;
3551         case SAL_MSG_POSTFOCUS:
3552             ImplHandleFocusMsg( pFrame, nMP2 );
3553             break;
3554 
3555         case WM_TRANSLATEACCEL:
3556             {
3557             // Da uns OS/2 zu viele Tasten abfaegnt, unternehmen wir etwas,
3558             // damit wir Shift+F1, Shift+F10 und Shift+Enter bekommen
3559             PQMSG   pMsg        = (PQMSG)nMP1;
3560             USHORT  nKeyFlags   = SHORT1FROMMP( pMsg->mp1 );
3561             USHORT  nKeyCode    = (UCHAR)SHORT2FROMMP( pMsg->mp2 );
3562 
3563             if ( !(nKeyFlags & KC_KEYUP) && (nKeyFlags & KC_VIRTUALKEY) &&
3564                  (nKeyFlags & KC_SHIFT) && (nKeyCode != VK_ESC) )
3565                 return (MRESULT)FALSE;
3566 
3567             if ( nKeyCode == VK_F1 )
3568                 return (MRESULT)FALSE;
3569             }
3570             break;
3571 
3572         case WM_CREATE:
3573             {
3574 				HWND hWndFrame = WinQueryWindow(hWnd, QW_PARENT);
3575 				if (hWndFrame == 0)
3576 					debug_printf(" WARNING NULL FRAME!!\n");
3577 				SalData* pSalData = GetSalData();
3578 				// Window-Instanz am Windowhandle speichern
3579 				pFrame = pSalData->mpCreateFrame;
3580 				pSalData->mpCreateFrame = NULL;
3581 				SetWindowPtr( hWnd, pFrame );
3582 				SetWindowPtr( hWndFrame, pFrame);
3583 				// HWND schon hier setzen, da schon auf den Instanzdaten
3584 				// gearbeitet werden kann, wenn Messages waehrend
3585 				// CreateWindow() gesendet werden
3586 				pFrame->mhWndClient = hWnd;
3587 				pFrame->mhWndFrame = hWndFrame;
3588 				pFrame->maSysData.hWnd = hWnd;
3589             }
3590             break;
3591 
3592         case WM_CLOSE:
3593             ImplHandleCloseMsg( hWnd );
3594             bDef = FALSE;
3595             break;
3596 
3597         case WM_SYSVALUECHANGED:
3598             if ( pFrame->mbFullScreen )
3599                 ImplSalFrameFullScreenPos( pFrame );
3600             // kein break, da der Rest auch noch verarbeitet werden soll
3601         case PL_ALTERED:
3602         case WM_SYSCOLORCHANGE:
3603             ImplSalYieldMutexAcquire();
3604             pFrame->CallCallback( SALEVENT_SETTINGSCHANGED, 0 );
3605             ImplSalYieldMutexRelease();
3606             break;
3607 
3608         case SAL_MSG_USEREVENT:
3609             ImplHandleUserEvent( hWnd, nMP2 );
3610             bDef = FALSE;
3611             break;
3612         case SAL_MSG_TOTOP:
3613             ImplSalToTop( hWnd, (ULONG)nMP1 );
3614             bDef = FALSE;
3615             break;
3616         case SAL_MSG_SHOW:
3617             ImplSalShow( hWnd, (ULONG)nMP1, (ULONG)nMP2 );
3618             bDef = FALSE;
3619             break;
3620 
3621 		case WM_KBDLAYERCHANGED:
3622 			debug_printf("hWnd 0x%08x WM_KBDLAYERCHANGED\n", hWnd);
3623             ImplHandleInputLangChange( hWnd );
3624             break;
3625 
3626 		case WM_HSCROLL:
3627 		case WM_VSCROLL:
3628 			ImplHandleWheelMsg( hWnd, nMsg, nMP1, nMP2 );
3629             bDef = FALSE;
3630 			break;
3631 
3632         case WM_COMMAND:
3633         case SAL_MSG_SYSPROCESSMENU:
3634             if ( SalImplHandleProcessMenu( pFrame, nMsg, nMP1, nMP2 ) )
3635             {
3636                 bDef = FALSE;
3637                 nRet = (MRESULT)1;
3638             }
3639             break;
3640 
3641 #ifdef ENABLE_IME
3642         case WM_IMEREQUEST:
3643             if ( (ULONG)nMP1 == IMR_CONVRESULT )
3644             {
3645                 if ( pFrame->mbHandleIME )
3646                 {
3647                     // Nur im Conversionmodus akzeptieren wir den IME-Input
3648                     if ( pFrame->mbConversionMode )
3649                     {
3650                         ImplSalYieldMutexAcquire();
3651                         if ( ImplHandleIMEConversion( pFrame, nMP2 ) )
3652                         {
3653                             bDef = FALSE;
3654                             nRet = (MRESULT)TRUE;
3655                         }
3656                         ImplSalYieldMutexRelease();
3657                     }
3658                 }
3659             }
3660             else if ( (ULONG)nMP1 == IMR_CANDIDATE )
3661             {
3662                 if ( pFrame->mbHandleIME )
3663                 {
3664                     ImplSalYieldMutexAcquire();
3665                     if ( (ULONG)nMP2 & IMR_CANDIDATE_SHOW )
3666                         ImplHandleIMEOpenCandidate( pFrame );
3667                     else if ( (ULONG)nMP2 & IMR_CANDIDATE_HIDE )
3668                         ImplHandleIMECloseCandidate( pFrame );
3669                     ImplSalYieldMutexRelease();
3670                 }
3671             }
3672             break;
3673 
3674         case WM_IMENOTIFY:
3675             if ( (ULONG)nMP1 == IMN_STARTCONVERSION )
3676             {
3677                 ImplSalYieldMutexAcquire();
3678                 if ( ImplHandleIMEStartConversion( pFrame ) )
3679                 {
3680                     bDef = FALSE;
3681                     nRet = (MRESULT)TRUE;
3682                 }
3683                 ImplSalYieldMutexRelease();
3684             }
3685             else if ( (ULONG)nMP1 == IMN_ENDCONVERSION )
3686             {
3687                 if ( pFrame->mbHandleIME )
3688                 {
3689                     ImplSalYieldMutexAcquire();
3690                     if ( ImplHandleIMEEndConversion( pFrame ) )
3691                     {
3692                         bDef = FALSE;
3693                         nRet = (MRESULT)TRUE;
3694                     }
3695                     ImplSalYieldMutexRelease();
3696                 }
3697             }
3698             break;
3699 #endif
3700     }
3701 
3702 	if( bCheckTimers )
3703 	{
3704 		SalData* pSalData = GetSalData();
3705 		if( pSalData->mnNextTimerTime )
3706 		{
3707 			ULONG nCurTime;
3708 			DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, (PVOID)&nCurTime, sizeof(ULONG));
3709 			if( pSalData->mnNextTimerTime < nCurTime )
3710 			{
3711 				QMSG aMsg;
3712 				if (!WinPeekMsg( pFrame->mhAB, &aMsg, 0, WM_PAINT, WM_PAINT, PM_NOREMOVE ) )
3713 					WinPostMsg( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_POSTTIMER, 0, (MPARAM)nCurTime );
3714 			}
3715 		}
3716 	}
3717 
3718     if ( bDef )
3719         nRet = WinDefWindowProc( hWnd, nMsg, nMP1, nMP2 );
3720 
3721     return nRet;
3722 }
3723 
3724 // -----------------------------------------------------------------------
3725 
ResetClipRegion()3726 void Os2SalFrame::ResetClipRegion()
3727 {
3728 }
3729 
BeginSetClipRegion(ULONG)3730 void Os2SalFrame::BeginSetClipRegion( ULONG )
3731 {
3732 }
3733 
UnionClipRegion(long,long,long,long)3734 void Os2SalFrame::UnionClipRegion( long, long, long, long )
3735 {
3736 }
3737 
EndSetClipRegion()3738 void Os2SalFrame::EndSetClipRegion()
3739 {
3740 }
3741 
3742 // -----------------------------------------------------------------------
3743 
SalFrameSubClassWndProc(HWND hWnd,ULONG nMsg,MPARAM nMP1,MPARAM nMP2)3744 MRESULT EXPENTRY SalFrameSubClassWndProc( HWND hWnd, ULONG nMsg,
3745                                   MPARAM nMP1, MPARAM nMP2 )
3746 {
3747     MRESULT mReturn = 0L;
3748 
3749     // ticket#124 min size of 132 px is too much
3750     if (nMsg == WM_QUERYTRACKINFO) {
3751 	PTRACKINFO pti;
3752 	// first, let PM initialize TRACKINFO
3753 	mReturn = aSalShlData.mpFrameProc( hWnd, nMsg, nMP1, nMP2 );
3754 	// now change default min size
3755 	pti = (PTRACKINFO) nMP2;
3756 	pti->ptlMinTrackSize.x = 64L;
3757 	// now return to PM
3758 	return mReturn;
3759     }
3760 
3761     return aSalShlData.mpFrameProc( hWnd, nMsg, nMP1, nMP2 );
3762 }
3763 
3764 // -----------------------------------------------------------------------
3765