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

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

PF: focus fix for minimized window

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