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

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

PF: listbox fix when button clicked outside control (rollup dropdown); minimize fixes (activation + z-order)

File size: 42.5 KB
Line 
1/* $Id: oslibwin.cpp,v 1.118 2002-04-24 08:56:17 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
553 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
554 if (rc) {
555 rc = WinSetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_DEACTIVATE | SWP_ZORDER);
556 }
557 return (rc);
558}
559//******************************************************************************
560//******************************************************************************
561BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
562{
563 pointl->x = 0;
564 pointl->y = 0;
565 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
566}
567//******************************************************************************
568//******************************************************************************
569BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
570{
571 ULONG hIconOS2 = GetOS2Icon(hIcon);
572 if(hIconOS2)
573 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
574 return FALSE;
575}
576//******************************************************************************
577//******************************************************************************
578BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
579{
580 return WinQueryWindowPos(hwnd, pswp);
581}
582//******************************************************************************
583//******************************************************************************
584void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
585 int parentHeight, HWND hwnd)
586{
587 HWND hWindow = pswp->hwnd;
588 HWND hWndInsertAfter = pswp->hwndInsertBehind;
589 long x = pswp->x;
590 long y = pswp->y;
591 long cx = pswp->cx;
592 long cy = pswp->cy;
593 UINT fuFlags = (UINT)pswp->fl;
594
595 HWND hWinAfter;
596 ULONG flags = 0;
597
598 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
599
600 if (hWndInsertAfter == HWND_TOP)
601 hWinAfter = HWND_TOP_W;
602 else if (hWndInsertAfter == HWND_BOTTOM)
603 hWinAfter = HWND_BOTTOM_W;
604 else
605 hWinAfter = (HWND) hWndInsertAfter;
606
607 //***********************************
608 // convert PM flags to Windows flags
609 //***********************************
610 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
611 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
612 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
613 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
614 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
615 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
616 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
617 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
618
619 if(fuFlags & (SWP_MOVE | SWP_SIZE))
620 {
621 y = parentHeight - y - pswp->cy;
622
623 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
624 flags |= SWP_NOMOVE_W;
625
626 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
627 flags |= SWP_NOSIZE_W;
628
629 if (fuFlags & SWP_SIZE)
630 {
631 if (pswp->cy != pswpOld->cy)
632 {
633 flags &= ~SWP_NOMOVE_W;
634 }
635 }
636 }
637
638 pswpOld->x = pswp->x;
639 pswpOld->y = parentHeight-pswp->y-pswp->cy;
640 pswpOld->cx = pswp->cx;
641 pswpOld->cy = pswp->cy;
642
643 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
644 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
645
646 pwpos->flags = (UINT)flags;
647 pwpos->cy = cy;
648 pwpos->cx = cx;
649 pwpos->x = x;
650 pwpos->y = y;
651 pwpos->hwndInsertAfter = hWinAfter;
652 pwpos->hwnd = hWindow;
653}
654//******************************************************************************
655//******************************************************************************
656void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
657 int parentHeight, HWND hFrame)
658{
659 BOOL fCvt = FALSE;
660
661 HWND hWnd = pwpos->hwnd;
662 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
663 long x = pwpos->x;
664 long y = pwpos->y;
665 long cx = pwpos->cx;
666 long cy = pwpos->cy;
667 UINT fuFlags = pwpos->flags;
668
669 HWND hWinAfter;
670 ULONG flags = 0;
671 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
672
673 if (hWndInsertAfter == HWND_TOPMOST_W)
674// hWinAfter = HWND_TOPMOST;
675 hWinAfter = HWND_TOP;
676 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
677// hWinAfter = HWND_NOTOPMOST;
678 hWinAfter = HWND_TOP;
679 else if (hWndInsertAfter == HWND_TOP_W)
680 hWinAfter = HWND_TOP;
681 else if (hWndInsertAfter == HWND_BOTTOM_W)
682 hWinAfter = HWND_BOTTOM;
683 else
684 hWinAfter = (HWND) hWndInsertAfter;
685
686 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
687 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
688 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
689 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
690 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
691 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
692 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
693 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
694
695 if(flags & (SWP_MOVE | SWP_SIZE))
696 {
697 if((flags & SWP_MOVE) == 0)
698 {
699 x = pswpOld->x;
700 y = pswpOld->y;
701
702 y = parentHeight - y - pswpOld->cy;
703 }
704
705 if(flags & SWP_SIZE)
706 {
707 if (cy != pswpOld->cy)
708 flags |= SWP_MOVE;
709 }
710 else
711 {
712 cx = pswpOld->cx;
713 cy = pswpOld->cy;
714 }
715 y = parentHeight - y - cy;
716
717 if ((pswpOld->x == x) && (pswpOld->y == y))
718 flags &= ~SWP_MOVE;
719
720 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
721 flags &= ~SWP_SIZE;
722 }
723
724 pswp->fl = flags;
725 pswp->cy = cy;
726 pswp->cx = cx;
727 pswp->x = x;
728 pswp->y = y;
729 pswp->hwndInsertBehind = hWinAfter;
730 pswp->hwnd = hWindow;
731 pswp->ulReserved1 = 0;
732 pswp->ulReserved2 = 0;
733}
734//******************************************************************************
735//******************************************************************************
736void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
737{
738 SWP swp;
739 BOOL rc;
740
741 swp.hwnd = hwnd;
742 swp.hwndInsertBehind = 0;
743 swp.x = x;
744 swp.y = parentHeight - y - cy;
745 swp.cx = cx;
746 swp.cy = cy;
747 swp.fl = SWP_MOVE | SWP_SIZE;
748
749 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));
750
751 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
752 if(rc == FALSE) {
753 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
754 }
755}
756//******************************************************************************
757//******************************************************************************
758BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
759{
760 BOOL rc;
761
762 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
763
764 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
765 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
766
767 return rc;
768}
769//******************************************************************************
770//******************************************************************************
771BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
772{
773 TRACKINFO tinfo;
774
775 memset(&tinfo, 0, sizeof(TRACKINFO));
776 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
777
778 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
779 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
780 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
781 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
782 return TRUE;
783}
784//******************************************************************************
785//******************************************************************************
786HWND OSLibWinBeginEnumWindows(HWND hwnd)
787{
788 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
789 else
790 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
791
792 return WinBeginEnumWindows(hwnd);
793}
794//******************************************************************************
795//******************************************************************************
796HWND OSLibWinGetNextWindow(HWND hwndEnum)
797{
798 return WinGetNextWindow(hwndEnum);
799}
800//******************************************************************************
801//******************************************************************************
802HWND OSLibWinQueryClientWindow(HWND hwndFrame)
803{
804 HWND hwndClient = 0;
805
806 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
807 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
808
809 return hwndClient;
810}
811//******************************************************************************
812//******************************************************************************
813BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
814{
815 return WinEndEnumWindows(hwndEnum);
816}
817//******************************************************************************
818//******************************************************************************
819BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
820{
821 BOOL ret;
822
823 ret = WinQueryWindowProcess(hwnd, pid, tid);
824 *tid = MAKE_THREADID(*pid, *tid);
825 return ret;
826}
827//******************************************************************************
828//******************************************************************************
829BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
830{
831 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
832}
833//******************************************************************************
834//******************************************************************************
835HWND OSLibWinQueryObjectWindow(VOID)
836{
837 return WinQueryObjectWindow(HWND_DESKTOP);
838}
839//******************************************************************************
840//******************************************************************************
841HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
842{
843 HWND hwndNext, hwndFound=0;
844 HENUM henum;
845
846 henum = WinBeginEnumWindows(HWND_OBJECT);
847 while ((hwndNext = WinGetNextWindow(henum)) != 0)
848 {
849 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
850 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
851 {
852 hwndFound = hwndNext;
853 break;
854 }
855 }
856 WinEndEnumWindows(henum);
857 return hwndFound;
858}
859//******************************************************************************
860//******************************************************************************
861BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
862{
863 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
864 return WinSetWindowULong(hwnd, QWS_ID, value);
865}
866//******************************************************************************
867//******************************************************************************
868PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
869{
870 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
871}
872//******************************************************************************
873//******************************************************************************
874BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
875{
876 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
877
878 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
879 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
880 (pRect->bottom - pRect->top)));
881 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
882 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
883 return TRUE;
884}
885//******************************************************************************
886//******************************************************************************
887BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
888{
889 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
890
891 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
892 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
893 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
894 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
895 return TRUE;
896}
897//******************************************************************************
898//******************************************************************************
899BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
900{
901 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE );
902}
903//******************************************************************************
904//******************************************************************************
905BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
906{
907 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE );
908}
909//******************************************************************************
910//******************************************************************************
911USHORT APIENTRY WinTranslateChar2( USHORT /* Codepage (currently ignored) */
912 , PUSHORT /* Ptr to char to translate */
913 , PULONG /* Ptr to deadkey save info */
914 , USHORT /* Translation option (TC_xxx) */
915 , PUSHORT /* Ptr to shift state (TCF_xxx) */
916 );
917//******************************************************************************
918//******************************************************************************
919USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate)
920{
921 USHORT sel = GetFS();
922 usScanCode = WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate);
923 SetFS(sel);
924 return usScanCode;
925}
926//******************************************************************************
927//******************************************************************************
928BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
929{
930 WinEnableWindowUpdate(hwndFrame, fEnable);
931 return WinEnableWindowUpdate(hwndClient, fEnable);
932}
933//******************************************************************************
934//******************************************************************************
935ULONG OSLibWinGetLastError()
936{
937 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
938}
939//******************************************************************************
940//******************************************************************************
941void OSLibWinShowTaskList(HWND hwndFrame)
942{
943 //CB: don't know if this works on all machines
944 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
945}
946//******************************************************************************
947//******************************************************************************
948void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle)
949{
950 ULONG dwWinStyle;
951 ULONG dwOldWinStyle;
952
953 //client window:
954 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
955 dwOldWinStyle = dwWinStyle;
956
957 if(dwStyle & WS_CLIPCHILDREN_W) {
958 dwWinStyle |= WS_CLIPCHILDREN;
959 }
960 else dwWinStyle &= ~WS_CLIPCHILDREN;
961
962 if(dwWinStyle != dwOldWinStyle) {
963 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
964 }
965
966 //Frame window
967 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
968 dwOldWinStyle = dwWinStyle;
969 if(dwStyle & WS_DISABLED_W) {
970 dwWinStyle |= WS_DISABLED;
971 }
972 else dwWinStyle &= ~WS_DISABLED;
973
974 if(dwStyle & WS_CLIPSIBLINGS_W) {
975 dwWinStyle |= WS_CLIPSIBLINGS;
976 }
977 else dwWinStyle &= ~WS_CLIPSIBLINGS;
978
979 if(dwStyle & WS_MINIMIZE_W) {
980 dwWinStyle |= WS_MINIMIZED;
981 }
982 else dwWinStyle &= ~WS_MINIMIZED;
983
984 if(dwStyle & WS_MAXIMIZE_W) {
985 dwWinStyle |= WS_MAXIMIZED;
986 }
987 else dwWinStyle &= ~WS_MAXIMIZED;
988
989 if(dwWinStyle != dwOldWinStyle) {
990 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
991 }
992 if(fOS2Look) {
993 ULONG OSFrameStyle = 0;
994 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
995 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
996 OSFrameStyle = FCF_TITLEBAR;
997 }
998 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
999 {
1000 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
1001 OSFrameStyle |= FCF_SYSMENU;
1002 }
1003 }
1004 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
1005 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
1006 OSFrameStyle |= FCF_MINMAX;
1007 }
1008 }
1009 else
1010 if(dwStyle & WS_SYSMENU_W) {
1011 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
1012 OSFrameStyle |= FCF_CLOSEBUTTON;
1013 }
1014 }
1015 }
1016 if(OSFrameStyle) {
1017 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
1018
1019 FCData.flCreateFlags = OSFrameStyle;
1020 WinCreateFrameControls(hwndFrame, &FCData, NULL);
1021 }
1022 }
1023}
1024//******************************************************************************
1025//******************************************************************************
1026DWORD OSLibQueryWindowStyle(HWND hwnd)
1027{
1028 return WinQueryWindowULong(hwnd, QWL_STYLE);
1029}
1030//******************************************************************************
1031//******************************************************************************
1032void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
1033{
1034 WinSetVisibleRegionNotify(hwnd, fNotify);
1035}
1036//******************************************************************************
1037//******************************************************************************
1038HWND OSLibWinQueryCapture()
1039{
1040 return WinQueryCapture(HWND_DESKTOP);
1041}
1042//******************************************************************************
1043//******************************************************************************
1044BOOL OSLibWinSetCapture(HWND hwnd)
1045{
1046 return WinSetCapture(HWND_DESKTOP, hwnd);
1047}
1048//******************************************************************************
1049//******************************************************************************
1050BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
1051{
1052 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
1053}
1054//******************************************************************************
1055//******************************************************************************
1056HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
1057{
1058 SWCNTRL swctrl;
1059 ULONG tid;
1060
1061 swctrl.hwnd = hwndFrame;
1062 swctrl.hwndIcon = 0;
1063 swctrl.hprog = 0;
1064 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1065 swctrl.idSession = 0;
1066 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1067 swctrl.fbJump = SWL_JUMPABLE;
1068 swctrl.bProgType = PROG_PM;
1069 if(title) {
1070// strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1071 CharToOemBuffA( title, swctrl.szSwtitle, MAXNAMEL+4 );
1072 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1073 }
1074 else {
1075 swctrl.szSwtitle[0] = 0;
1076 swctrl.uchVisibility = SWL_INVISIBLE;
1077 }
1078 return WinAddSwitchEntry(&swctrl);
1079}
1080//******************************************************************************
1081//******************************************************************************
1082BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1083{
1084 SWCNTRL swctrl;
1085 ULONG tid;
1086
1087 swctrl.hwnd = hwndFrame;
1088 swctrl.hwndIcon = 0;
1089 swctrl.hprog = 0;
1090 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1091 swctrl.idSession = 0;
1092 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1093 swctrl.fbJump = SWL_JUMPABLE;
1094 swctrl.bProgType = PROG_PM;
1095 if(title) {
1096// strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1097 CharToOemBuffA( title, swctrl.szSwtitle, MAXNAMEL+4 );
1098 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1099 }
1100 else {
1101 swctrl.szSwtitle[0] = 0;
1102 swctrl.uchVisibility = SWL_INVISIBLE;
1103 }
1104 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1105}
1106//******************************************************************************
1107//******************************************************************************
1108BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1109{
1110 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1111}
1112//******************************************************************************
1113//******************************************************************************
1114ULONG OSLibGetScreenHeight()
1115{
1116 return ScreenHeight;
1117}
1118//******************************************************************************
1119//******************************************************************************
1120ULONG OSLibGetScreenWidth()
1121{
1122 return ScreenWidth;
1123}
1124//******************************************************************************
1125//Returns the maximum position for a window
1126//Should only be used from toplevel windows
1127//******************************************************************************
1128BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1129{
1130 SWP swp;
1131
1132 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1133 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1134 return FALSE;
1135 }
1136 rect->left = swp.x;
1137 rect->right = swp.x + swp.cx;
1138 rect->top = ScreenHeight - (swp.y + swp.cy);
1139 rect->bottom = ScreenHeight - swp.y;
1140 return TRUE;
1141}
1142//******************************************************************************
1143//******************************************************************************
1144BOOL OSLibWinShowPointer(BOOL fShow)
1145{
1146 return WinShowPointer(HWND_DESKTOP, fShow);
1147}
1148//******************************************************************************
1149//******************************************************************************
1150ULONG OSLibWinQuerySysColor(int index)
1151{
1152 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
1153}
1154//******************************************************************************
1155//******************************************************************************
Note: See TracBrowser for help on using the repository browser.