source: trunk/src/user32/oslibwin.cpp@ 8706

Last change on this file since 8706 was 8512, checked in by sandervl, 23 years ago

Fix for ToAscii(Ex) & GetKeyboardState (WinTranslateChar2 call)

File size: 42.9 KB
Line 
1/* $Id: oslibwin.cpp,v 1.121 2002-05-29 09:56:43 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_WIN
14#define INCL_PM
15#define INCL_WINSWITCHLIST
16#include <os2wrap.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <misc.h>
21#include <win32type.h>
22#include <winconst.h>
23#include <winuser32.h>
24#include <wprocess.h>
25#include "oslibwin.h"
26#include "oslibutil.h"
27#include "oslibmsg.h"
28#include "oslibgdi.h"
29#include "pmwindow.h"
30#include "initterm.h"
31
32#define DBG_LOCALLOG DBG_oslibwin
33#include "dbglocal.h"
34
35//******************************************************************************
36//******************************************************************************
37BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
38{
39 if(hwndParent == OSLIB_HWND_DESKTOP)
40 {
41 hwndParent = HWND_DESKTOP;
42 }
43 else
44 if(hwndParent == OSLIB_HWND_OBJECT) {
45 hwndParent = HWND_OBJECT;
46 }
47 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
48}
49//******************************************************************************
50//******************************************************************************
51BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
52{
53 return WinSetOwner(hwnd, hwndOwner);
54}
55//******************************************************************************
56//******************************************************************************
57HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
58 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
59 ULONG id, BOOL fTaskList,BOOL fShellPosition,
60 int classStyle, HWND *hwndFrame)
61{
62 HWND hwndClient;
63 ULONG dwFrameStyle = 0;
64
65 if(pszName && *pszName == 0) {
66 pszName = NULL;
67 }
68 if(hwndParent == OSLIB_HWND_DESKTOP) {
69 hwndParent = HWND_DESKTOP;
70 }
71 if(Owner == OSLIB_HWND_DESKTOP) {
72 Owner = HWND_DESKTOP;
73 }
74
75 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
76 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
77
78 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
79
80 if(fTaskList)
81 {
82 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
83 }
84 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
85
86 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
87 FCData.flCreateFlags = dwFrameStyle;
88
89 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
90
91 //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise.
92 //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds
93 // a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border
94 *hwndFrame = WinCreateWindow(hwndParent,
95 WIN32_STDFRAMECLASS,
96 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
97 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
98 id, (PVOID)&FCData, NULL);
99 if(fOS2Look && *hwndFrame) {
100 FCData.flCreateFlags = dwOSFrameStyle;
101// FCData.flCreateFlags = FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX;
102 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
103 }
104 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
105 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
106 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
107
108 return hwndClient;
109}
110//******************************************************************************
111//Note: Also check OSLibSetWindowStyle when changing this!!
112//******************************************************************************
113BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
114{
115 *OSWinStyle = 0;
116 *OSFrameStyle = 0;
117
118 /* Window styles */
119 if(dwStyle & WS_DISABLED_W)
120 *OSWinStyle |= WS_DISABLED;
121 if(dwStyle & WS_CLIPSIBLINGS_W)
122 *OSWinStyle |= WS_CLIPSIBLINGS;
123 if(dwStyle & WS_CLIPCHILDREN_W)
124 *OSWinStyle |= WS_CLIPCHILDREN;
125
126 if(fOS2Look) {
127 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
128 *OSFrameStyle = FCF_TITLEBAR;
129 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
130 {
131 *OSFrameStyle |= FCF_SYSMENU;
132 }
133 if(dwStyle & WS_MINIMIZEBOX_W) {
134 *OSFrameStyle |= FCF_MINBUTTON;
135 }
136 if(dwStyle & WS_MAXIMIZEBOX_W) {
137 *OSFrameStyle |= FCF_MAXBUTTON;
138 }
139 if(dwStyle & WS_SYSMENU_W) {
140 *OSFrameStyle |= FCF_CLOSEBUTTON;
141 }
142 }
143 }
144 return TRUE;
145}
146//******************************************************************************
147//******************************************************************************
148BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
149 DWORD dwExStyle, HICON hSysMenuIcon)
150{
151 SWP swp[3];
152 HWND hwndControl;
153 int i = 0;
154 static int minmaxwidth = 0;
155 static int minmaxheight = 0;
156
157 if(minmaxwidth == 0) {
158 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
159 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
160 }
161
162 if(fOS2Look == OS2_APPEARANCE_SYSMENU) {
163 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
164 if(hwndControl) {
165 swp[i].hwnd = hwndControl;
166 swp[i].hwndInsertBehind = HWND_TOP;
167 swp[i].x = pRect->xLeft;
168 swp[i].y = pRect->yBottom;
169 if(pRect->yTop - pRect->yBottom > minmaxheight) {
170 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
171 }
172 swp[i].cx = minmaxwidth/2;
173 swp[i].cy = minmaxheight;;
174 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
175 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
176 pRect->xLeft += minmaxwidth/2;
177 i++;
178 }
179 }
180 else
181 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) && hSysMenuIcon) {
182 pRect->xLeft += minmaxwidth/2;
183 }
184
185 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
186 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
187 if(hwndControl) {
188 swp[i].hwnd = hwndControl;
189 swp[i].hwndInsertBehind = HWND_TOP;
190 swp[i].x = pRect->xLeft;
191 swp[i].y = pRect->yBottom;
192 if(pRect->yTop - pRect->yBottom > minmaxheight) {
193 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
194 }
195 swp[i].cx = pRect->xRight - pRect->xLeft;
196 if((dwStyle & WS_MINIMIZEBOX_W)) {
197 swp[i].cx -= minmaxwidth/2;
198 }
199 if((dwStyle & WS_MAXIMIZEBOX_W)) {
200 swp[i].cx -= minmaxwidth/2;
201 }
202 //there is no close button in warp 3
203 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
204 swp[i].cx -= minmaxwidth/2;
205 }
206 swp[i].cy = minmaxheight;
207 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
208 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
209 pRect->xLeft += swp[i].cx;
210 i++;
211 }
212 else return FALSE; //no titlebar -> no frame controls
213 }
214 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
215 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
216 if(hwndControl) {
217 swp[i].hwnd = hwndControl;
218 swp[i].hwndInsertBehind = HWND_TOP;
219 swp[i].x = pRect->xLeft;
220 swp[i].y = pRect->yBottom;
221 if(pRect->yTop - pRect->yBottom > minmaxheight) {
222 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
223 }
224 swp[i].cx = 0;
225 if((dwStyle & WS_MINIMIZEBOX_W)) {
226 swp[i].cx += minmaxwidth/2;
227 }
228 if((dwStyle & WS_MAXIMIZEBOX_W)) {
229 swp[i].cx += minmaxwidth/2;
230 }
231 //there is no close button in warp 3
232 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
233 swp[i].cx += minmaxwidth/2;
234 }
235 swp[i].cy = minmaxheight;
236 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
237 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
238 pRect->xLeft += swp[i].cx;
239 i++;
240 }
241 }
242 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
243}
244//******************************************************************************
245//******************************************************************************
246BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
247{
248 if(offset == OSLIB_QWL_USER)
249 offset = QWL_USER;
250
251 return WinSetWindowULong(hwnd, offset, value);
252}
253//******************************************************************************
254//******************************************************************************
255BOOL OSLibWinGetMinPosition(HWND hwnd, PSWP pswp, PPOINTL pointl)
256{
257 return WinGetMinPosition(hwnd, pswp, pointl);
258}
259
260//******************************************************************************
261//******************************************************************************
262ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
263{
264 if(offset == OSLIB_QWL_USER)
265 offset = QWL_USER;
266
267 return WinQueryWindowULong(hwnd, offset);
268}
269//******************************************************************************
270//******************************************************************************
271BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
272{
273 return WinAlarm(hwndDeskTop,flStyle);
274}
275//******************************************************************************
276HWND OSLibWinQueryFocus(HWND hwndDeskTop)
277{
278 return WinQueryFocus(hwndDeskTop);
279}
280//******************************************************************************
281//******************************************************************************
282HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
283{
284 return WinWindowFromID(hwndParent,id);
285}
286//******************************************************************************
287//******************************************************************************
288BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
289{
290 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
291}
292//******************************************************************************
293//******************************************************************************
294BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
295{
296 return WinIsChild (hwnd, hwndOf);
297}
298//******************************************************************************
299//******************************************************************************
300ULONG OSLibGetWindowHeight(HWND hwnd)
301{
302 RECTL rect;
303
304 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
305}
306//******************************************************************************
307//******************************************************************************
308LONG OSLibWinQuerySysValue(LONG iSysValue)
309{
310 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
311}
312//******************************************************************************
313//******************************************************************************
314BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
315{
316 return WinQuerySysValue(iSysValue, val);
317}
318//******************************************************************************
319//******************************************************************************
320ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
321{
322 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
323}
324//******************************************************************************
325//******************************************************************************
326BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
327{
328 return WinSetDlgItemText(hwndDlg,idItem,pszText);
329}
330//******************************************************************************
331//******************************************************************************
332BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
333{
334 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
335}
336//******************************************************************************
337//******************************************************************************
338BOOL OSLibWinSetPointerPos(int x, int y)
339{
340 return WinSetPointerPos(HWND_DESKTOP, x, y);
341}
342//******************************************************************************
343//******************************************************************************
344HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
345{
346 return WinQueryWindow(hwnd, lCode);
347}
348//******************************************************************************
349//******************************************************************************
350BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
351{
352 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
353}
354//******************************************************************************
355//******************************************************************************
356BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
357{
358 BOOL rc = 1;
359
360 if(fl & SWP_SHOW) {
361 rc = WinShowWindow(hwnd, TRUE);
362 }
363 if(rc == 0)
364 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
365 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
366 if(rc == 0)
367 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
368 return rc;
369}
370//******************************************************************************
371//******************************************************************************
372BOOL OSLibWinDestroyWindow(HWND hwnd)
373{
374 return WinDestroyWindow(hwnd);
375}
376//******************************************************************************
377//******************************************************************************
378BOOL OSLibWinQueryWindowClientRect(HWND hwndOS2, PRECT pRect)
379{
380 BOOL rc;
381 RECTLOS2 rectl;
382
383 rc = WinQueryWindowRect(hwndOS2, (PRECTL)&rectl);
384 if(rc) {
385 pRect->left = 0;
386 pRect->right = rectl.xRight - rectl.xLeft;
387 pRect->top = 0;
388 pRect->bottom = rectl.yTop - rectl.yBottom;
389 }
390 else memset(pRect, 0, sizeof(RECT));
391 return rc;
392}
393//******************************************************************************
394//******************************************************************************
395BOOL OSLibQueryWindowRectAbsolute (HWND hwndOS2, PRECT pRect)
396{
397 BOOL rc;
398 RECTLOS2 rectl;
399
400 rc = WinQueryWindowRect (hwndOS2, (RECTL *)&rectl);
401 if (rc)
402 {
403 rc = WinMapWindowPoints (hwndOS2, HWND_DESKTOP, (POINTL *)&rectl, 2);
404 if (rc)
405 {
406 pRect->left = rectl.xLeft;
407 pRect->right = rectl.xRight;
408 pRect->top = mapScreenY (rectl.yTop);
409 pRect->bottom = mapScreenY (rectl.yBottom);
410 }
411 }
412 if (!rc)
413 {
414 memset(pRect, 0, sizeof(*pRect));
415 }
416 return rc;
417}
418//******************************************************************************
419//******************************************************************************
420#if 0
421BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
422{
423 BOOL rc;
424 RECTLOS2 rectl;
425
426 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
427 if(rc) {
428 if(RelativeTo == RELATIVE_TO_SCREEN) {
429 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
430 }
431 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
432 }
433 else memset(pRect, 0, sizeof(RECT));
434 return rc;
435}
436#endif
437//******************************************************************************
438//******************************************************************************
439BOOL OSLibWinIsIconic(HWND hwnd)
440{
441 SWP swp;
442 BOOL rc;
443
444 rc = WinQueryWindowPos(hwnd, &swp);
445 if(rc == FALSE) {
446 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
447 return FALSE;
448 }
449
450 if(swp.fl & SWP_MINIMIZE)
451 return TRUE;
452 else return FALSE;
453}
454//******************************************************************************
455//******************************************************************************
456BOOL OSLibWinSetActiveWindow(HWND hwnd)
457{
458 BOOL rc;
459
460 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
461 if(rc == FALSE) {
462 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
463 }
464 return rc;
465}
466//******************************************************************************
467//******************************************************************************
468BOOL OSLibWinSetFocus(HWND hwnd)
469{
470 return WinSetFocus(HWND_DESKTOP, hwnd);
471}
472//******************************************************************************
473//******************************************************************************
474BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
475{
476 BOOL rc;
477 HWND hwndClient;
478
479 rc = WinEnableWindow(hwnd, fEnable);
480 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
481 if(hwndClient) {
482 WinEnableWindow(hwndClient, fEnable);
483 }
484 return rc;
485}
486//******************************************************************************
487//******************************************************************************
488BOOL OSLibWinIsWindowEnabled(HWND hwnd)
489{
490 return WinIsWindowEnabled(hwnd);
491}
492//******************************************************************************
493//******************************************************************************
494BOOL OSLibWinIsWindowVisible(HWND hwnd)
495{
496 return WinIsWindowVisible(hwnd);
497}
498//******************************************************************************
499//******************************************************************************
500HWND OSLibWinQueryActiveWindow()
501{
502 return WinQueryActiveWindow(HWND_DESKTOP);
503}
504//******************************************************************************
505//******************************************************************************
506LONG OSLibWinQueryWindowTextLength(HWND hwnd)
507{
508 return WinQueryWindowTextLength(hwnd);
509}
510//******************************************************************************
511//******************************************************************************
512LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
513{
514 return WinQueryWindowText(hwnd, length, lpsz);
515}
516//******************************************************************************
517//******************************************************************************
518BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
519{
520 return WinSetWindowText(hwnd, lpsz);
521}
522//******************************************************************************
523//******************************************************************************
524BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
525{
526 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
527}
528//******************************************************************************
529//******************************************************************************
530BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
531{
532 return WinFlashWindow(hwnd, fFlash);
533}
534//******************************************************************************
535//******************************************************************************
536HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
537{
538 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
539}
540//******************************************************************************
541//******************************************************************************
542BOOL OSLibWinMinimizeWindow(HWND hwnd)
543{
544 /* @@PF The reason for this weird minimize algorithm is that we are not fully
545 using PM for minimization. I.e. we respect all PM messages yet we do mess
546 so much with some messages that minimization is based partly on vodoo.
547 That is if you try minimize and deactivate in one call it will fail.
548 Here we deactivate yourselves and give focus to next window that is
549 on desktop, this func also works with MDI */
550
551 BOOL rc;
552 HWND hwndNext;
553
554 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
555 if (rc) {
556 rc = WinSetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_DEACTIVATE | SWP_ZORDER);
557 if (rc)
558 {
559 HENUM henum;
560 henum = WinBeginEnumWindows(HWND_DESKTOP);
561 while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)
562 {
563 if (WinIsWindowVisible(hwndNext) && WinIsWindowShowing(hwndNext)) break;
564 }
565 WinEndEnumWindows (henum);
566 rc = WinSetWindowPos(hwndNext, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
567 }
568 }
569 return (rc);
570}
571//******************************************************************************
572//******************************************************************************
573BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
574{
575 pointl->x = 0;
576 pointl->y = 0;
577 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
578}
579//******************************************************************************
580//******************************************************************************
581BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
582{
583 ULONG hIconOS2 = GetOS2Icon(hIcon);
584 if(hIconOS2)
585 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
586 return FALSE;
587}
588//******************************************************************************
589//******************************************************************************
590BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
591{
592 return WinQueryWindowPos(hwnd, pswp);
593}
594//******************************************************************************
595//******************************************************************************
596void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
597 int parentHeight, HWND hwnd)
598{
599 HWND hWindow = pswp->hwnd;
600 HWND hWndInsertAfter = pswp->hwndInsertBehind;
601 long x = pswp->x;
602 long y = pswp->y;
603 long cx = pswp->cx;
604 long cy = pswp->cy;
605 UINT fuFlags = (UINT)pswp->fl;
606
607 HWND hWinAfter;
608 ULONG flags = 0;
609
610 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
611
612 if (hWndInsertAfter == HWND_TOP)
613 hWinAfter = HWND_TOP_W;
614 else if (hWndInsertAfter == HWND_BOTTOM)
615 hWinAfter = HWND_BOTTOM_W;
616 else
617 hWinAfter = (HWND) hWndInsertAfter;
618
619 //***********************************
620 // convert PM flags to Windows flags
621 //***********************************
622 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
623 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
624 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
625 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
626 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
627 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
628 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
629 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
630
631 if(fuFlags & (SWP_MOVE | SWP_SIZE))
632 {
633 y = parentHeight - y - pswp->cy;
634
635 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
636 flags |= SWP_NOMOVE_W;
637
638 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
639 flags |= SWP_NOSIZE_W;
640
641 if (fuFlags & SWP_SIZE)
642 {
643 if (pswp->cy != pswpOld->cy)
644 {
645 flags &= ~SWP_NOMOVE_W;
646 }
647 }
648 }
649
650 pswpOld->x = pswp->x;
651 pswpOld->y = parentHeight-pswp->y-pswp->cy;
652 pswpOld->cx = pswp->cx;
653 pswpOld->cy = pswp->cy;
654
655 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
656 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
657
658 pwpos->flags = (UINT)flags;
659 pwpos->cy = cy;
660 pwpos->cx = cx;
661 pwpos->x = x;
662 pwpos->y = y;
663 pwpos->hwndInsertAfter = hWinAfter;
664 pwpos->hwnd = hWindow;
665}
666//******************************************************************************
667//******************************************************************************
668void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
669 int parentHeight, HWND hFrame)
670{
671 BOOL fCvt = FALSE;
672
673 HWND hWnd = pwpos->hwnd;
674 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
675 long x = pwpos->x;
676 long y = pwpos->y;
677 long cx = pwpos->cx;
678 long cy = pwpos->cy;
679 UINT fuFlags = pwpos->flags;
680
681 HWND hWinAfter;
682 ULONG flags = 0;
683 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
684
685 if (hWndInsertAfter == HWND_TOPMOST_W)
686// hWinAfter = HWND_TOPMOST;
687 hWinAfter = HWND_TOP;
688 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
689// hWinAfter = HWND_NOTOPMOST;
690 hWinAfter = HWND_TOP;
691 else if (hWndInsertAfter == HWND_TOP_W)
692 hWinAfter = HWND_TOP;
693 else if (hWndInsertAfter == HWND_BOTTOM_W)
694 hWinAfter = HWND_BOTTOM;
695 else
696 hWinAfter = (HWND) hWndInsertAfter;
697
698 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
699 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
700 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
701 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
702 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
703 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
704 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
705 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
706
707 if(flags & (SWP_MOVE | SWP_SIZE))
708 {
709 if((flags & SWP_MOVE) == 0)
710 {
711 x = pswpOld->x;
712 y = pswpOld->y;
713
714 y = parentHeight - y - pswpOld->cy;
715 }
716
717 if(flags & SWP_SIZE)
718 {
719 if (cy != pswpOld->cy)
720 flags |= SWP_MOVE;
721 }
722 else
723 {
724 cx = pswpOld->cx;
725 cy = pswpOld->cy;
726 }
727 y = parentHeight - y - cy;
728
729 if ((pswpOld->x == x) && (pswpOld->y == y))
730 flags &= ~SWP_MOVE;
731
732 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
733 flags &= ~SWP_SIZE;
734 }
735
736 pswp->fl = flags;
737 pswp->cy = cy;
738 pswp->cx = cx;
739 pswp->x = x;
740 pswp->y = y;
741 pswp->hwndInsertBehind = hWinAfter;
742 pswp->hwnd = hWindow;
743 pswp->ulReserved1 = 0;
744 pswp->ulReserved2 = 0;
745}
746//******************************************************************************
747//******************************************************************************
748void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
749{
750 SWP swp;
751 BOOL rc;
752
753 swp.hwnd = hwnd;
754 swp.hwndInsertBehind = 0;
755 swp.x = x;
756 swp.y = parentHeight - y - cy;
757 swp.cx = cx;
758 swp.cy = cy;
759 swp.fl = SWP_MOVE | SWP_SIZE;
760
761 dprintf(("OSLibWinSetClientPos (%d,%d) (%d,%d) -> (%d,%d) (%d,%d)", x, y, x+cx, y+cy, swp.x, swp.y, swp.x+swp.cx, swp.y+swp.cy));
762
763 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
764 if(rc == FALSE) {
765 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
766 }
767}
768//******************************************************************************
769//******************************************************************************
770BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
771{
772 BOOL rc;
773
774 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
775
776 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
777 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
778
779 return rc;
780}
781//******************************************************************************
782//******************************************************************************
783BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
784{
785 TRACKINFO tinfo;
786
787 memset(&tinfo, 0, sizeof(TRACKINFO));
788 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
789
790 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
791 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
792 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
793 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
794 return TRUE;
795}
796//******************************************************************************
797//******************************************************************************
798HWND OSLibWinBeginEnumWindows(HWND hwnd)
799{
800 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
801 else
802 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
803
804 return WinBeginEnumWindows(hwnd);
805}
806//******************************************************************************
807//******************************************************************************
808HWND OSLibWinGetNextWindow(HWND hwndEnum)
809{
810 return WinGetNextWindow(hwndEnum);
811}
812//******************************************************************************
813//******************************************************************************
814HWND OSLibWinQueryClientWindow(HWND hwndFrame)
815{
816 HWND hwndClient = 0;
817
818 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
819 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
820
821 return hwndClient;
822}
823//******************************************************************************
824//******************************************************************************
825BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
826{
827 return WinEndEnumWindows(hwndEnum);
828}
829//******************************************************************************
830//******************************************************************************
831BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
832{
833 BOOL ret;
834
835 ret = WinQueryWindowProcess(hwnd, pid, tid);
836 *tid = MAKE_THREADID(*pid, *tid);
837 return ret;
838}
839//******************************************************************************
840//******************************************************************************
841BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
842{
843 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
844}
845//******************************************************************************
846//******************************************************************************
847HWND OSLibWinQueryObjectWindow(VOID)
848{
849 return WinQueryObjectWindow(HWND_DESKTOP);
850}
851//******************************************************************************
852//******************************************************************************
853HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
854{
855 HWND hwndNext, hwndFound=0;
856 HENUM henum;
857
858 henum = WinBeginEnumWindows(HWND_OBJECT);
859 while ((hwndNext = WinGetNextWindow(henum)) != 0)
860 {
861 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
862 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
863 {
864 hwndFound = hwndNext;
865 break;
866 }
867 }
868 WinEndEnumWindows(henum);
869 return hwndFound;
870}
871//******************************************************************************
872//******************************************************************************
873BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
874{
875 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
876 return WinSetWindowULong(hwnd, QWS_ID, value);
877}
878//******************************************************************************
879//******************************************************************************
880PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
881{
882 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
883}
884//******************************************************************************
885//******************************************************************************
886BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
887{
888 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
889
890 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
891 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
892 (pRect->bottom - pRect->top)));
893 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
894 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
895 return TRUE;
896}
897//******************************************************************************
898//******************************************************************************
899BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
900{
901 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
902
903 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
904 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
905 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
906 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
907 return TRUE;
908}
909//******************************************************************************
910//******************************************************************************
911BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
912{
913 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE );
914}
915//******************************************************************************
916//******************************************************************************
917BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
918{
919 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE );
920}
921//******************************************************************************
922//******************************************************************************
923USHORT APIENTRY WinTranslateChar2( USHORT /* Codepage (currently ignored) */
924 , PUSHORT /* Ptr to char to translate */
925 , PULONG /* Ptr to deadkey save info */
926 , USHORT /* Translation option (TC_xxx) */
927 , PUSHORT /* Ptr to shift state (TCF_xxx) */
928 );
929//******************************************************************************
930//******************************************************************************
931USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate)
932{
933 USHORT usResult;
934 USHORT sel = GetFS();
935
936 usResult = WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate);
937 SetFS(sel);
938 return usScanCode;
939}
940//******************************************************************************
941//******************************************************************************
942BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
943{
944 WinEnableWindowUpdate(hwndFrame, fEnable);
945 return WinEnableWindowUpdate(hwndClient, fEnable);
946}
947//******************************************************************************
948//******************************************************************************
949ULONG OSLibWinGetLastError()
950{
951 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
952}
953//******************************************************************************
954//******************************************************************************
955void OSLibWinShowTaskList(HWND hwndFrame)
956{
957 //CB: don't know if this works on all machines
958 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
959}
960//******************************************************************************
961//******************************************************************************
962void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle)
963{
964 ULONG dwWinStyle;
965 ULONG dwOldWinStyle;
966
967 //client window:
968 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
969 dwOldWinStyle = dwWinStyle;
970
971 if(dwStyle & WS_CLIPCHILDREN_W) {
972 dwWinStyle |= WS_CLIPCHILDREN;
973 }
974 else dwWinStyle &= ~WS_CLIPCHILDREN;
975
976 if(dwWinStyle != dwOldWinStyle) {
977 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
978 }
979
980 //Frame window
981 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
982 dwOldWinStyle = dwWinStyle;
983 if(dwStyle & WS_DISABLED_W) {
984 dwWinStyle |= WS_DISABLED;
985 }
986 else dwWinStyle &= ~WS_DISABLED;
987
988 if(dwStyle & WS_CLIPSIBLINGS_W) {
989 dwWinStyle |= WS_CLIPSIBLINGS;
990 }
991 else dwWinStyle &= ~WS_CLIPSIBLINGS;
992
993 if(dwStyle & WS_MINIMIZE_W) {
994 dwWinStyle |= WS_MINIMIZED;
995 }
996 else dwWinStyle &= ~WS_MINIMIZED;
997
998 if(dwStyle & WS_MAXIMIZE_W) {
999 dwWinStyle |= WS_MAXIMIZED;
1000 }
1001 else dwWinStyle &= ~WS_MAXIMIZED;
1002
1003 if(dwWinStyle != dwOldWinStyle) {
1004 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
1005 }
1006 if(fOS2Look) {
1007 ULONG OSFrameStyle = 0;
1008 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
1009 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
1010 OSFrameStyle = FCF_TITLEBAR;
1011 }
1012 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
1013 {
1014 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
1015 OSFrameStyle |= FCF_SYSMENU;
1016 }
1017 }
1018 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
1019 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
1020 OSFrameStyle |= FCF_MINMAX;
1021 }
1022 }
1023 else
1024 if(dwStyle & WS_SYSMENU_W) {
1025 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
1026 OSFrameStyle |= FCF_CLOSEBUTTON;
1027 }
1028 }
1029 }
1030 if(OSFrameStyle) {
1031 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
1032
1033 FCData.flCreateFlags = OSFrameStyle;
1034 WinCreateFrameControls(hwndFrame, &FCData, NULL);
1035 }
1036 }
1037}
1038//******************************************************************************
1039//******************************************************************************
1040DWORD OSLibQueryWindowStyle(HWND hwnd)
1041{
1042 return WinQueryWindowULong(hwnd, QWL_STYLE);
1043}
1044//******************************************************************************
1045//******************************************************************************
1046void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
1047{
1048 WinSetVisibleRegionNotify(hwnd, fNotify);
1049}
1050//******************************************************************************
1051//******************************************************************************
1052HWND OSLibWinQueryCapture()
1053{
1054 return WinQueryCapture(HWND_DESKTOP);
1055}
1056//******************************************************************************
1057//******************************************************************************
1058BOOL OSLibWinSetCapture(HWND hwnd)
1059{
1060 return WinSetCapture(HWND_DESKTOP, hwnd);
1061}
1062//******************************************************************************
1063//******************************************************************************
1064BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
1065{
1066 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
1067}
1068//******************************************************************************
1069//******************************************************************************
1070HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
1071{
1072 SWCNTRL swctrl;
1073 ULONG tid;
1074
1075 swctrl.hwnd = hwndFrame;
1076 swctrl.hwndIcon = 0;
1077 swctrl.hprog = 0;
1078 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1079 swctrl.idSession = 0;
1080 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1081 swctrl.fbJump = SWL_JUMPABLE;
1082 swctrl.bProgType = PROG_PM;
1083 if(title) {
1084// strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1085 CharToOemBuffA( title, swctrl.szSwtitle, MAXNAMEL+4 );
1086 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1087 }
1088 else {
1089 swctrl.szSwtitle[0] = 0;
1090 swctrl.uchVisibility = SWL_INVISIBLE;
1091 }
1092 return WinAddSwitchEntry(&swctrl);
1093}
1094//******************************************************************************
1095//******************************************************************************
1096BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1097{
1098 SWCNTRL swctrl;
1099 ULONG tid;
1100
1101 swctrl.hwnd = hwndFrame;
1102 swctrl.hwndIcon = 0;
1103 swctrl.hprog = 0;
1104 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1105 swctrl.idSession = 0;
1106 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1107 swctrl.fbJump = SWL_JUMPABLE;
1108 swctrl.bProgType = PROG_PM;
1109 if(title) {
1110// strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1111 CharToOemBuffA( title, swctrl.szSwtitle, MAXNAMEL+4 );
1112 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1113 }
1114 else {
1115 swctrl.szSwtitle[0] = 0;
1116 swctrl.uchVisibility = SWL_INVISIBLE;
1117 }
1118 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1119}
1120//******************************************************************************
1121//******************************************************************************
1122BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1123{
1124 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1125}
1126//******************************************************************************
1127//******************************************************************************
1128ULONG OSLibGetScreenHeight()
1129{
1130 return ScreenHeight;
1131}
1132//******************************************************************************
1133//******************************************************************************
1134ULONG OSLibGetScreenWidth()
1135{
1136 return ScreenWidth;
1137}
1138//******************************************************************************
1139//Returns the maximum position for a window
1140//Should only be used from toplevel windows
1141//******************************************************************************
1142BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1143{
1144 SWP swp;
1145
1146 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1147 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1148 return FALSE;
1149 }
1150 rect->left = swp.x;
1151 rect->right = swp.x + swp.cx;
1152 rect->top = ScreenHeight - (swp.y + swp.cy);
1153 rect->bottom = ScreenHeight - swp.y;
1154 return TRUE;
1155}
1156//******************************************************************************
1157//******************************************************************************
1158BOOL OSLibWinShowPointer(BOOL fShow)
1159{
1160 return WinShowPointer(HWND_DESKTOP, fShow);
1161}
1162//******************************************************************************
1163//******************************************************************************
1164ULONG OSLibWinQuerySysColor(int index)
1165{
1166 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
1167}
1168//******************************************************************************
1169//******************************************************************************
Note: See TracBrowser for help on using the repository browser.