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

Last change on this file since 10010 was 9943, checked in by sandervl, 22 years ago

Changes for window tracking (move/size) with full window dragging enabled

File size: 49.9 KB
Line 
1/* $Id: oslibwin.cpp,v 1.141 2003-03-27 11:02:26 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 <stdio.h>
19#include <string.h>
20
21#include <misc.h>
22#include <win32type.h>
23#include <winconst.h>
24#include <winuser32.h>
25#include <wprocess.h>
26#include "oslibwin.h"
27#include "oslibutil.h"
28#include "oslibmsg.h"
29#include "oslibgdi.h"
30#include "pmwindow.h"
31#include "initterm.h"
32
33#define DBG_LOCALLOG DBG_oslibwin
34#include "dbglocal.h"
35
36//Undocumented PM WS_TOPMOST style; similar to WS_EX_TOPMOST in Windows
37#define WS_TOPMOST 0x00200000L
38
39//******************************************************************************
40//******************************************************************************
41BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
42{
43 if(hwndParent == OSLIB_HWND_DESKTOP)
44 {
45 hwndParent = HWND_DESKTOP;
46 }
47 else
48 if(hwndParent == OSLIB_HWND_OBJECT) {
49 hwndParent = HWND_OBJECT;
50 }
51 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
52}
53//******************************************************************************
54//******************************************************************************
55BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
56{
57 return WinSetOwner(hwnd, hwndOwner);
58}
59//******************************************************************************
60//******************************************************************************
61HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
62 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
63 ULONG id, BOOL fTaskList,BOOL fShellPosition,
64 int classStyle, HWND *hwndFrame)
65{
66 HWND hwndClient;
67 ULONG dwFrameStyle = 0;
68
69 if(pszName && *pszName == 0) {
70 pszName = NULL;
71 }
72 if(hwndParent == OSLIB_HWND_DESKTOP) {
73 hwndParent = HWND_DESKTOP;
74 }
75 if(Owner == OSLIB_HWND_DESKTOP) {
76 Owner = HWND_DESKTOP;
77 }
78
79 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
80 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
81
82 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
83
84 if(fTaskList)
85 {
86 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
87 }
88 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
89
90 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
91 FCData.flCreateFlags = dwFrameStyle;
92
93 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
94
95 //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise.
96 //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds
97 // a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border
98 *hwndFrame = WinCreateWindow(hwndParent,
99 WIN32_STDFRAMECLASS,
100 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
101 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
102 id, (PVOID)&FCData, NULL);
103 if(fOS2Look && *hwndFrame) {
104 FCData.flCreateFlags = dwOSFrameStyle;
105 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
106 }
107 if(*hwndFrame == 0) {
108 dprintf(("Frame window creation failed!! OS LastError %0x", WinGetLastError(0)));
109 return 0;
110 }
111 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
112 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
113 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
114 //@PF For all top-level windows we create invisible vertical scroller
115 //to show IBM wheel driver that we need WM_VSCROLL messages
116 if (hwndParent == HWND_DESKTOP && *hwndFrame)
117 OSLibWinCreateInvisibleScroller(*hwndFrame, SBS_VERT);
118
119
120 if(hwndClient == 0) {
121 dprintf(("Client window creation failed!! OS LastError %0x", WinGetLastError(0)));
122 }
123 return hwndClient;
124}
125//******************************************************************************
126//Note: Also check OSLibSetWindowStyle when changing this!!
127//******************************************************************************
128BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle,
129 ULONG *OSFrameStyle)
130{
131 *OSWinStyle = 0;
132 *OSFrameStyle = 0;
133
134 /* Window styles */
135 if(dwStyle & WS_DISABLED_W)
136 *OSWinStyle |= WS_DISABLED;
137 if(dwStyle & WS_CLIPSIBLINGS_W)
138 *OSWinStyle |= WS_CLIPSIBLINGS;
139 if(dwStyle & WS_CLIPCHILDREN_W)
140 *OSWinStyle |= WS_CLIPCHILDREN;
141 if(dwExStyle & WS_EX_TOPMOST_W)
142 *OSWinStyle |= WS_TOPMOST;
143
144 if(fOS2Look) {
145 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
146 *OSFrameStyle = FCF_TITLEBAR;
147
148 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
149 {
150 *OSFrameStyle |= FCF_SYSMENU;
151 }
152 if(dwStyle & WS_MINIMIZEBOX_W) {
153 *OSFrameStyle |= FCF_MINBUTTON;
154 }
155 if(dwStyle & WS_MAXIMIZEBOX_W) {
156 *OSFrameStyle |= FCF_MAXBUTTON;
157 }
158 if(dwStyle & WS_SYSMENU_W) {
159 *OSFrameStyle |= FCF_CLOSEBUTTON;
160 }
161 }
162 }
163 return TRUE;
164}
165//******************************************************************************
166//******************************************************************************
167BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
168 DWORD dwExStyle, HICON hSysMenuIcon,
169 BOOL drawCloseButton, BOOL fClassIcon)
170{
171 SWP swp[3];
172 HWND hwndControl;
173 int i = 0;
174 static int minmaxwidth = 0;
175 static int minmaxheight = 0;
176
177 dprintf(("OSLibWinPositionFrameControls %x (%x,%x) %x %d", hwndFrame, dwStyle, dwExStyle, hSysMenuIcon, drawCloseButton));
178
179 if(minmaxwidth == 0) {
180 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
181 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
182 }
183
184 if(fOS2Look == OS2_APPEARANCE_SYSMENU) {
185 //Note: If no class icon *and* WS_EX_DLGMODALFRAME -> no system menu!!
186 // --> TODO
187 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
188 if(hwndControl) {
189 swp[i].hwnd = hwndControl;
190 swp[i].hwndInsertBehind = HWND_TOP;
191 swp[i].x = pRect->xLeft;
192 swp[i].y = pRect->yBottom;
193 if(pRect->yTop - pRect->yBottom > minmaxheight) {
194 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
195 }
196 swp[i].cx = minmaxwidth/2;
197 swp[i].cy = minmaxheight;;
198 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
199 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
200 pRect->xLeft += minmaxwidth/2;
201 i++;
202 }
203 }
204 else
205 //Note: If no class icon *and* WS_EX_DLGMODALFRAME -> no system menu!!
206 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) &&
207 !(!fClassIcon && (dwExStyle & WS_EX_DLGMODALFRAME_W)) && hSysMenuIcon)
208 {
209 pRect->xLeft += minmaxwidth/2;
210 }
211
212 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
213 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
214 if(hwndControl) {
215 swp[i].hwnd = hwndControl;
216 swp[i].hwndInsertBehind = HWND_TOP;
217 swp[i].x = pRect->xLeft;
218 swp[i].y = pRect->yBottom;
219 if(pRect->yTop - pRect->yBottom > minmaxheight) {
220 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
221 }
222 swp[i].cx = pRect->xRight - pRect->xLeft;
223 if((dwStyle & WS_MINIMIZEBOX_W)) {
224 swp[i].cx -= minmaxwidth/2;
225 }
226 if((dwStyle & WS_MAXIMIZEBOX_W)) {
227 swp[i].cx -= minmaxwidth/2;
228 }
229 //there is no close button in warp 3 and sometimes we do not
230 //have close button as well
231 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3 && drawCloseButton) {
232 swp[i].cx -= minmaxwidth/2;
233 }
234 swp[i].cy = minmaxheight;
235 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
236 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
237 pRect->xLeft += swp[i].cx;
238 i++;
239 }
240 else return FALSE; //no titlebar -> no frame controls
241 }
242 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
243 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
244 if(hwndControl) {
245 swp[i].hwnd = hwndControl;
246 swp[i].hwndInsertBehind = HWND_TOP;
247 swp[i].x = pRect->xLeft;
248 swp[i].y = pRect->yBottom;
249 if(pRect->yTop - pRect->yBottom > minmaxheight) {
250 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
251 }
252 swp[i].cx = 0;
253 if((dwStyle & WS_MINIMIZEBOX_W)) {
254 swp[i].cx += minmaxwidth/2;
255 }
256 if((dwStyle & WS_MAXIMIZEBOX_W)) {
257 swp[i].cx += minmaxwidth/2;
258 }
259 //there is no close button in warp 3 and sometimes we do not have
260 //close button as well
261 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3 && drawCloseButton) {
262 swp[i].cx += minmaxwidth/2;
263 }
264 swp[i].cy = minmaxheight;
265 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
266 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
267 pRect->xLeft += swp[i].cx;
268 i++;
269 }
270 }
271 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
272}
273//******************************************************************************
274//******************************************************************************
275BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
276{
277 if(offset == OSLIB_QWL_USER)
278 offset = QWL_USER;
279
280 return WinSetWindowULong(hwnd, offset, value);
281}
282//******************************************************************************
283//******************************************************************************
284BOOL OSLibWinGetMinPosition(HWND hwnd, PSWP pswp, PPOINTL pointl)
285{
286 return WinGetMinPosition(hwnd, pswp, pointl);
287}
288
289//******************************************************************************
290//******************************************************************************
291ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
292{
293 if(offset == OSLIB_QWL_USER)
294 offset = QWL_USER;
295
296 return WinQueryWindowULong(hwnd, offset);
297}
298//******************************************************************************
299//******************************************************************************
300BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
301{
302 return WinAlarm(hwndDeskTop,flStyle);
303}
304//******************************************************************************
305HWND OSLibWinQueryFocus(HWND hwndDeskTop)
306{
307 return WinQueryFocus(hwndDeskTop);
308}
309//******************************************************************************
310//******************************************************************************
311HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
312{
313 return WinWindowFromID(hwndParent,id);
314}
315//******************************************************************************
316//******************************************************************************
317BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
318{
319 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
320}
321//******************************************************************************
322//******************************************************************************
323BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
324{
325 return WinIsChild (hwnd, hwndOf);
326}
327//******************************************************************************
328//******************************************************************************
329ULONG OSLibGetWindowHeight(HWND hwnd)
330{
331 RECTL rect;
332
333 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
334}
335//******************************************************************************
336//******************************************************************************
337LONG OSLibWinQuerySysValue(LONG iSysValue)
338{
339 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
340}
341//******************************************************************************
342//******************************************************************************
343BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
344{
345 return WinSetSysValue(HWND_DESKTOP, iSysValue, val);
346}
347//******************************************************************************
348//******************************************************************************
349ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
350{
351 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
352}
353//******************************************************************************
354//******************************************************************************
355BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
356{
357 return WinSetDlgItemText(hwndDlg,idItem,pszText);
358}
359//******************************************************************************
360//******************************************************************************
361BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
362{
363 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
364}
365//******************************************************************************
366//******************************************************************************
367BOOL OSLibWinSetPointerPos(int x, int y)
368{
369 return WinSetPointerPos(HWND_DESKTOP, x, y);
370}
371//******************************************************************************
372//******************************************************************************
373HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
374{
375 return WinQueryWindow(hwnd, lCode);
376}
377//******************************************************************************
378//******************************************************************************
379BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
380{
381 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
382}
383//******************************************************************************
384//******************************************************************************
385BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
386{
387 BOOL rc = 1;
388
389 if(fl & SWP_SHOW) {
390 rc = WinShowWindow(hwnd, TRUE);
391 }
392 if(rc == 0)
393 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
394 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
395 if(rc == 0)
396 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
397 return rc;
398}
399//******************************************************************************
400//******************************************************************************
401BOOL OSLibWinDestroyWindow(HWND hwnd)
402{
403 return WinDestroyWindow(hwnd);
404}
405//******************************************************************************
406//******************************************************************************
407BOOL OSLibWinQueryWindowClientRect(HWND hwndOS2, PRECT pRect)
408{
409 BOOL rc;
410 RECTLOS2 rectl;
411
412 rc = WinQueryWindowRect(hwndOS2, (PRECTL)&rectl);
413 if(rc) {
414 pRect->left = 0;
415 pRect->right = rectl.xRight - rectl.xLeft;
416 pRect->top = 0;
417 pRect->bottom = rectl.yTop - rectl.yBottom;
418 }
419 else memset(pRect, 0, sizeof(RECT));
420 return rc;
421}
422//******************************************************************************
423//******************************************************************************
424BOOL OSLibQueryWindowRectAbsolute (HWND hwndOS2, PRECT pRect)
425{
426 BOOL rc;
427 RECTLOS2 rectl;
428
429 rc = WinQueryWindowRect (hwndOS2, (RECTL *)&rectl);
430 if (rc)
431 {
432 rc = WinMapWindowPoints (hwndOS2, HWND_DESKTOP, (POINTL *)&rectl, 2);
433 if (rc)
434 {
435 pRect->left = rectl.xLeft;
436 pRect->right = rectl.xRight;
437 pRect->top = mapScreenY (rectl.yTop);
438 pRect->bottom = mapScreenY (rectl.yBottom);
439 }
440 }
441 if (!rc)
442 {
443 memset(pRect, 0, sizeof(*pRect));
444 }
445 return rc;
446}
447//******************************************************************************
448//******************************************************************************
449#if 0
450BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
451{
452 BOOL rc;
453 RECTLOS2 rectl;
454
455 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
456 if(rc) {
457 if(RelativeTo == RELATIVE_TO_SCREEN) {
458 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
459 }
460 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
461 }
462 else memset(pRect, 0, sizeof(RECT));
463 return rc;
464}
465#endif
466//******************************************************************************
467//******************************************************************************
468BOOL OSLibWinIsIconic(HWND hwnd)
469{
470 SWP swp;
471 BOOL rc;
472
473 rc = WinQueryWindowPos(hwnd, &swp);
474 if(rc == FALSE) {
475 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
476 return FALSE;
477 }
478
479 if(swp.fl & SWP_MINIMIZE)
480 return TRUE;
481 else return FALSE;
482}
483//******************************************************************************
484//******************************************************************************
485BOOL OSLibWinSetActiveWindow(HWND hwnd)
486{
487 BOOL rc;
488
489 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
490 if(rc == FALSE) {
491 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
492 }
493 return rc;
494}
495//******************************************************************************
496//******************************************************************************
497BOOL OSLibWinSetFocus(HWND hwnd)
498{
499 return WinSetFocus(HWND_DESKTOP, hwnd);
500}
501//******************************************************************************
502//******************************************************************************
503BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
504{
505 BOOL rc;
506 HWND hwndClient;
507
508 rc = WinEnableWindow(hwnd, fEnable);
509 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
510 if(hwndClient) {
511 WinEnableWindow(hwndClient, fEnable);
512 }
513 return rc;
514}
515//******************************************************************************
516//******************************************************************************
517BOOL OSLibWinIsWindowEnabled(HWND hwnd)
518{
519 return WinIsWindowEnabled(hwnd);
520}
521//******************************************************************************
522//******************************************************************************
523BOOL OSLibWinIsWindowVisible(HWND hwnd)
524{
525 return WinIsWindowVisible(hwnd);
526}
527//******************************************************************************
528//******************************************************************************
529HWND OSLibWinQueryActiveWindow()
530{
531 return WinQueryActiveWindow(HWND_DESKTOP);
532}
533//******************************************************************************
534//******************************************************************************
535LONG OSLibWinQueryWindowTextLength(HWND hwnd)
536{
537 return WinQueryWindowTextLength(hwnd);
538}
539//******************************************************************************
540//******************************************************************************
541LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
542{
543 return WinQueryWindowText(hwnd, length, lpsz);
544}
545//******************************************************************************
546//******************************************************************************
547BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
548{
549 return WinSetWindowText(hwnd, lpsz);
550}
551//******************************************************************************
552//******************************************************************************
553BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
554{
555 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
556}
557//******************************************************************************
558//******************************************************************************
559BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
560{
561 return WinFlashWindow(hwnd, fFlash);
562}
563//******************************************************************************
564//******************************************************************************
565HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
566{
567 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
568}
569
570//******************************************************************************
571//@PF This is exactly that weird message PM sends when we maximize window from
572//icon - this coordinates NEVER surface later and this combination of SWP
573//commands is useless, yet it starts the correct reaction of maximiztion from
574//icon state
575//******************************************************************************
576BOOL OSLibWinRestoreWindow(HWND hwnd)
577{
578 BOOL rc = WinSetWindowPos(hwnd, 0, -32000, 32000, 32000, 32000 , SWP_MAXIMIZE | SWP_RESTORE | SWP_ACTIVATE);
579 return (rc);
580}
581
582//******************************************************************************
583//******************************************************************************
584BOOL OSLibWinMinimizeWindow(HWND hwnd)
585{
586 /* @@PF The reason for this weird minimize algorithm is that we are not fully
587 using PM for minimization. I.e. we respect all PM messages yet we do mess
588 so much with some messages that minimization is based partly on vodoo.
589 That is if you try minimize and deactivate in one call it will fail.
590 Here we deactivate yourselves and give focus to next window that is
591 on desktop, this func also works with MDI */
592
593 BOOL rc;
594 HWND hwndNext;
595
596 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
597
598 if (rc) {
599 rc = WinSetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_DEACTIVATE | SWP_ZORDER);
600 if (rc)
601 {
602 HENUM henum;
603 henum = WinBeginEnumWindows(HWND_DESKTOP);
604 while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)
605 {
606 if (WinIsWindowVisible(hwndNext) && WinIsWindowShowing(hwndNext)) break;
607 }
608 WinEndEnumWindows (henum);
609 rc = WinSetWindowPos(hwndNext, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
610 }
611 }
612
613 return (rc);
614}
615//******************************************************************************
616//******************************************************************************
617BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
618{
619 pointl->x = 0;
620 pointl->y = 0;
621 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
622}
623//******************************************************************************
624//******************************************************************************
625BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
626{
627 ULONG hIconOS2 = GetOS2Icon(hIcon);
628 if(hIconOS2)
629 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
630 return FALSE;
631}
632//******************************************************************************
633//******************************************************************************
634BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
635{
636 return WinQueryWindowPos(hwnd, pswp);
637}
638//******************************************************************************
639//******************************************************************************
640void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
641 int parentHeight, HWND hwnd)
642{
643 HWND hWindow = pswp->hwnd;
644 HWND hWndInsertAfter = pswp->hwndInsertBehind;
645 long x = pswp->x;
646 long y = pswp->y;
647 long cx = pswp->cx;
648 long cy = pswp->cy;
649 UINT fuFlags = (UINT)pswp->fl;
650
651 HWND hWinAfter;
652 ULONG flags = 0;
653
654 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
655
656 if (hWndInsertAfter == HWND_TOP)
657 hWinAfter = HWND_TOP_W;
658 else if (hWndInsertAfter == HWND_BOTTOM)
659 hWinAfter = HWND_BOTTOM_W;
660 else
661 hWinAfter = (HWND) hWndInsertAfter;
662
663 //***********************************
664 // convert PM flags to Windows flags
665 //***********************************
666 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
667 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
668 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
669 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
670 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
671 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
672 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
673 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
674
675 if(fuFlags & (SWP_MOVE | SWP_SIZE))
676 {
677 y = parentHeight - y - pswp->cy;
678
679 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
680 flags |= SWP_NOMOVE_W;
681
682 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
683 flags |= SWP_NOSIZE_W;
684
685 if (fuFlags & SWP_SIZE)
686 {
687 if (pswp->cy != pswpOld->cy)
688 {
689 flags &= ~SWP_NOMOVE_W;
690 }
691 }
692 }
693
694 pswpOld->x = pswp->x;
695 pswpOld->y = parentHeight-pswp->y-pswp->cy;
696 pswpOld->cx = pswp->cx;
697 pswpOld->cy = pswp->cy;
698
699 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
700 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
701
702 pwpos->flags = (UINT)flags;
703 pwpos->cy = cy;
704 pwpos->cx = cx;
705 pwpos->x = x;
706 pwpos->y = y;
707 pwpos->hwndInsertAfter = hWinAfter;
708 pwpos->hwnd = hWindow;
709
710 dprintf2(("OSLibMapSWPtoWINDOWPOS %x (%d,%d)(%d,%d) -> %x (%d,%d)(%d,%d) parent height %d", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy, flags, x, y, cx, cy, parentHeight));
711}
712//******************************************************************************
713//******************************************************************************
714void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
715 int parentHeight, HWND hFrame)
716{
717 BOOL fCvt = FALSE;
718
719 HWND hWnd = pwpos->hwnd;
720 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
721 long x = pwpos->x;
722 long y = pwpos->y;
723 long cx = pwpos->cx;
724 long cy = pwpos->cy;
725 UINT fuFlags = pwpos->flags;
726
727 HWND hWinAfter;
728 ULONG flags = 0;
729 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
730
731 if (hWndInsertAfter == HWND_TOPMOST_W)
732// hWinAfter = HWND_TOPMOST;
733 hWinAfter = HWND_TOP;
734 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
735// hWinAfter = HWND_NOTOPMOST;
736 hWinAfter = HWND_TOP;
737 else if (hWndInsertAfter == HWND_TOP_W)
738 hWinAfter = HWND_TOP;
739 else if (hWndInsertAfter == HWND_BOTTOM_W)
740 hWinAfter = HWND_BOTTOM;
741 else
742 hWinAfter = (HWND) hWndInsertAfter;
743
744 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
745 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
746 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
747 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
748 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
749 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
750 //SvL: Must also deactivate the window when hiding it or else focus won't
751 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
752 if ( fuFlags & SWP_HIDEWINDOW_W) {
753 flags |= SWP_HIDE|SWP_DEACTIVATE;
754 }
755
756 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
757
758 if(flags & (SWP_MOVE | SWP_SIZE))
759 {
760 if((flags & SWP_MOVE) == 0)
761 {
762 x = pswpOld->x;
763 y = pswpOld->y;
764
765 y = parentHeight - y - pswpOld->cy;
766 }
767
768 if(flags & SWP_SIZE)
769 {
770 if (cy != pswpOld->cy)
771 flags |= SWP_MOVE;
772 }
773 else
774 {
775 cx = pswpOld->cx;
776 cy = pswpOld->cy;
777 }
778 y = parentHeight - y - cy;
779
780 if ((pswpOld->x == x) && (pswpOld->y == y))
781 flags &= ~SWP_MOVE;
782
783 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
784 flags &= ~SWP_SIZE;
785 }
786
787 pswp->fl = flags;
788 pswp->cy = cy;
789 pswp->cx = cx;
790 pswp->x = x;
791 pswp->y = y;
792 pswp->hwndInsertBehind = hWinAfter;
793 pswp->hwnd = hWindow;
794 pswp->ulReserved1 = 0;
795 pswp->ulReserved2 = 0;
796
797 dprintf2(("OSLibMapWINDOWPOStoSWP %x (%d,%d)(%d,%d) -> %x (%d,%d)(%d,%d) parent height %d", pwpos->flags, pwpos->x, pwpos->y, pwpos->cx, pwpos->cy, flags, x, y, cx, cy, parentHeight));
798}
799//******************************************************************************
800//******************************************************************************
801void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
802{
803 SWP swp;
804 BOOL rc;
805
806 swp.hwnd = hwnd;
807 swp.hwndInsertBehind = 0;
808 swp.x = x;
809 swp.y = parentHeight - y - cy;
810 swp.cx = cx;
811 swp.cy = cy;
812 swp.fl = SWP_MOVE | SWP_SIZE;
813
814 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));
815
816 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
817 if(rc == FALSE) {
818 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
819 }
820}
821//******************************************************************************
822//******************************************************************************
823BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
824{
825 BOOL rc;
826
827 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
828
829 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
830 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
831
832 return rc;
833}
834//******************************************************************************
835//******************************************************************************
836BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
837{
838 TRACKINFO tinfo;
839
840 memset(&tinfo, 0, sizeof(TRACKINFO));
841 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
842
843 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
844 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
845 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
846 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
847 return TRUE;
848}
849//******************************************************************************
850//******************************************************************************
851HWND OSLibWinBeginEnumWindows(HWND hwnd)
852{
853 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
854 else
855 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
856
857 return WinBeginEnumWindows(hwnd);
858}
859//******************************************************************************
860//******************************************************************************
861HWND OSLibWinGetNextWindow(HWND hwndEnum)
862{
863 return WinGetNextWindow(hwndEnum);
864}
865//******************************************************************************
866//******************************************************************************
867HWND OSLibWinQueryClientWindow(HWND hwndFrame)
868{
869 HWND hwndClient = 0;
870
871 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
872 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
873
874 return hwndClient;
875}
876//******************************************************************************
877//******************************************************************************
878BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
879{
880 return WinEndEnumWindows(hwndEnum);
881}
882//******************************************************************************
883//******************************************************************************
884BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
885{
886 BOOL ret;
887
888 ret = WinQueryWindowProcess(hwnd, pid, tid);
889 *tid = MAKE_THREADID(*pid, *tid);
890 return ret;
891}
892//******************************************************************************
893//******************************************************************************
894BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
895{
896 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
897}
898//******************************************************************************
899//******************************************************************************
900HWND OSLibWinQueryObjectWindow(VOID)
901{
902 return WinQueryObjectWindow(HWND_DESKTOP);
903}
904//******************************************************************************
905//******************************************************************************
906HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
907{
908 HWND hwndNext, hwndFound=0;
909 HENUM henum;
910
911 henum = WinBeginEnumWindows(HWND_OBJECT);
912 while ((hwndNext = WinGetNextWindow(henum)) != 0)
913 {
914 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
915 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
916 {
917 hwndFound = hwndNext;
918 break;
919 }
920 }
921 WinEndEnumWindows(henum);
922 return hwndFound;
923}
924//******************************************************************************
925//******************************************************************************
926BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
927{
928 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
929 return WinSetWindowULong(hwnd, QWS_ID, value);
930}
931//******************************************************************************
932//******************************************************************************
933PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
934{
935 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
936}
937//******************************************************************************
938//******************************************************************************
939BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
940{
941 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
942
943 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
944 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
945 (pRect->bottom - pRect->top)));
946 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
947 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
948 return TRUE;
949}
950//******************************************************************************
951//******************************************************************************
952BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
953{
954 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
955
956 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
957 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
958 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
959 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
960 return TRUE;
961}
962//******************************************************************************
963//******************************************************************************
964BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
965{
966 WinEnableWindowUpdate(hwndFrame, fEnable);
967 return WinEnableWindowUpdate(hwndClient, fEnable);
968}
969//******************************************************************************
970//******************************************************************************
971ULONG OSLibWinGetLastError()
972{
973 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
974}
975//******************************************************************************
976//******************************************************************************
977void OSLibWinShowTaskList(HWND hwndFrame)
978{
979 SWBLOCK swblk;
980 // the first entry returned is always the window list itself
981 if (WinQuerySwitchList(0, &swblk, sizeof(SWBLOCK)) > 0)
982 WinSetActiveWindow(HWND_DESKTOP, swblk.aswentry[0].swctl.hwnd);
983// WinShowWindow(swblk.aswentry[0].swctl.hwnd, TRUE);
984}
985//******************************************************************************
986//******************************************************************************
987//PF: PM Logic approved by numerous testcases shows this:
988//There is no other way to tweak FID_MINMAX without deleting it
989//Controls are created with size 0,0, invisible and should be immediately
990//positioned. MINMAX control can't function properly without FID_SYSMENU
991//control if it is present, so we need to recreate BOTH controls.
992//Currently OSLibSetWindowStyle checks for changes and actually do the job
993//only when it is needed so no additional messages are generated.
994//TO-DO: There MAY BE some regressions here but I haven't seen them
995//and yes this code is the only way to do WinCreateFrame controls,
996//first delete old then create new - all other variants create new and
997//leave old, WinCreateFrameControls can't tweak anything.
998
999void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle,
1000 ULONG dwExStyle, ULONG dwOldWindowsStyle)
1001{
1002 ULONG dwWinStyle;
1003 ULONG dwOldWinStyle;
1004
1005 int checksum, checksum2;
1006 DWORD dest_tid, dest_pid;
1007
1008 static int minmaxwidth = 0;
1009 static int minmaxheight = 0;
1010
1011
1012 //PF We can tweak OS/2 controls ONLY from thread that created them
1013 //in other case heavy PM lockups will follow
1014
1015 dest_tid = GetWindowThreadProcessId(OS2ToWin32Handle(hwndClient) , &dest_pid );
1016
1017 if (dest_tid != GetCurrentThreadId())
1018 {
1019 dprintf(("OSLibSetWindowStyle: Redirecting Change Frame controls to another thread"));
1020 WinSendMsg(hwndFrame, WIN32APP_CHNGEFRAMECTRLS, (MPARAM)dwStyle, (MPARAM)dwOldWindowsStyle);
1021 return;
1022 }
1023 if(minmaxwidth == 0) {
1024 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
1025 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
1026 }
1027
1028 if (hwndClient)
1029 {
1030 //client window:
1031 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
1032 dwOldWinStyle = dwWinStyle;
1033
1034 if(dwStyle & WS_CLIPCHILDREN_W) {
1035 dwWinStyle |= WS_CLIPCHILDREN;
1036 }
1037 else dwWinStyle &= ~WS_CLIPCHILDREN;
1038
1039 if(dwWinStyle != dwOldWinStyle) {
1040 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
1041 }
1042 }
1043
1044 //Frame window
1045 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
1046 dwOldWinStyle = dwWinStyle;
1047
1048 checksum = (dwOldWindowsStyle & WS_MINIMIZEBOX_W) + (dwOldWindowsStyle & WS_MAXIMIZEBOX_W) + (dwOldWindowsStyle & WS_SYSMENU_W);
1049 checksum2 = (dwStyle & WS_MINIMIZEBOX_W) + (dwStyle & WS_MAXIMIZEBOX_W) + (dwStyle & WS_SYSMENU_W);
1050
1051 if(dwStyle & WS_DISABLED_W) {
1052 dwWinStyle |= WS_DISABLED;
1053 }
1054 else dwWinStyle &= ~WS_DISABLED;
1055
1056 if(dwExStyle & WS_EX_TOPMOST_W) {
1057 dwWinStyle |= WS_TOPMOST;
1058 }
1059 else dwWinStyle &= ~WS_TOPMOST;
1060
1061 if(dwStyle & WS_CLIPSIBLINGS_W) {
1062 dwWinStyle |= WS_CLIPSIBLINGS;
1063 }
1064 else dwWinStyle &= ~WS_CLIPSIBLINGS;
1065
1066 if(dwStyle & WS_MINIMIZE_W) {
1067 dwWinStyle |= WS_MINIMIZED;
1068 }
1069 else dwWinStyle &= ~WS_MINIMIZED;
1070
1071 if(dwStyle & WS_MAXIMIZE_W) {
1072 dwWinStyle |= WS_MAXIMIZED;
1073 }
1074 else
1075 dwWinStyle &= ~WS_MAXIMIZED;
1076
1077 if(fOS2Look) {
1078 ULONG OSFrameStyle = 0;
1079 SWP rc1,rc2,rc3;
1080 int totalwidth = 0;
1081
1082 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
1083 {
1084 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
1085 OSFrameStyle = FCF_TITLEBAR;
1086 }
1087 else
1088 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR), &rc1);
1089
1090 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
1091 {
1092 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0)
1093 OSFrameStyle |= FCF_SYSMENU;
1094 }
1095 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU), &rc2);
1096 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX), &rc3);
1097
1098 if (checksum != checksum2)
1099 {
1100 dprintf(("OSLibSetWindowStyle: Min/Max/Close state changed. Creating:"));
1101 if(dwStyle & WS_MINIMIZEBOX_W)
1102 {
1103 OSFrameStyle |= FCF_MINBUTTON;
1104 totalwidth += minmaxwidth/2;
1105 dprintf(("min button"));
1106 }
1107
1108 if(dwStyle & WS_MAXIMIZEBOX_W)
1109 {
1110 OSFrameStyle |= FCF_MAXBUTTON;
1111 totalwidth += minmaxwidth/2;
1112 dprintf(("max button"));
1113 }
1114
1115 if(dwStyle & WS_SYSMENU_W)
1116 {
1117 OSFrameStyle |= FCF_CLOSEBUTTON;
1118 OSFrameStyle |= FCF_SYSMENU;
1119 totalwidth += minmaxwidth/2;
1120 dprintf(("close button"));
1121 }
1122 }
1123 }
1124 else
1125 {
1126 if (WinWindowFromID(hwndFrame, FID_TITLEBAR))
1127 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_TITLEBAR));
1128 }
1129
1130 if (checksum != checksum2)
1131 {
1132 if (WinWindowFromID(hwndFrame, FID_SYSMENU))
1133 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_SYSMENU));
1134 if (WinWindowFromID(hwndFrame, FID_MINMAX))
1135 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_MINMAX));
1136 }
1137
1138 if(OSFrameStyle) {
1139 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
1140 char buffer[255];
1141 dprintf(("Controls will be created %x",OSFrameStyle));
1142 FCData.flCreateFlags = OSFrameStyle;
1143
1144 GetWindowTextA(OS2ToWin32Handle(hwndClient), buffer, sizeof(buffer));
1145 WinCreateFrameControls(hwndFrame, &FCData, buffer );
1146
1147 if (totalwidth != rc3.cx)
1148 {
1149 rc3.cx = totalwidth;
1150 totalwidth = rc3.cx - totalwidth;
1151 rc1.cx = rc1.cx + totalwidth;
1152 rc3.x = rc3.x + totalwidth;
1153 }
1154
1155 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX),0,rc3.x,rc3.y,rc3.cx,rc3.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1156 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU),0,rc2.x,rc2.y,rc2.cx,rc2.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1157 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR),0,rc1.x,rc1.y,rc1.cx,rc1.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1158
1159 if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
1160 WinSendMsg(WinWindowFromID(hwndFrame, FID_TITLEBAR), TBM_SETHILITE, (MPARAM)1, 0);
1161
1162 }
1163 } // os2look
1164
1165 if(dwWinStyle != dwOldWinStyle) {
1166 dprintf(("Setting new window U long"));
1167 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
1168 }
1169
1170}
1171//******************************************************************************
1172//******************************************************************************
1173BOOL OSLibChangeCloseButtonState(HWND hwndFrame, BOOL State)
1174{
1175 dprintf(("OSLibChangeCloseButtonState %x %d", hwndFrame, State));
1176 return WinEnableMenuItem(WinWindowFromID(hwndFrame, FID_SYSMENU), SC_CLOSE, State);
1177}
1178//******************************************************************************
1179//******************************************************************************
1180DWORD OSLibQueryWindowStyle(HWND hwnd)
1181{
1182 return WinQueryWindowULong(hwnd, QWL_STYLE);
1183}
1184//******************************************************************************
1185//******************************************************************************
1186void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
1187{
1188 WinSetVisibleRegionNotify(hwnd, fNotify);
1189}
1190//******************************************************************************
1191//******************************************************************************
1192HWND OSLibWinQueryCapture()
1193{
1194 return WinQueryCapture(HWND_DESKTOP);
1195}
1196//******************************************************************************
1197//******************************************************************************
1198BOOL OSLibWinSetCapture(HWND hwnd)
1199{
1200 return WinSetCapture(HWND_DESKTOP, hwnd);
1201}
1202//******************************************************************************
1203//******************************************************************************
1204BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
1205{
1206 dprintf(("OSLibWinRemoveFromTasklist %x", hTaskList));
1207 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
1208}
1209//******************************************************************************
1210//******************************************************************************
1211HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
1212{
1213 SWCNTRL swctrl;
1214 ULONG tid;
1215
1216 swctrl.hwnd = hwndFrame;
1217 swctrl.hwndIcon = 0;
1218 swctrl.hprog = 0;
1219 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1220 swctrl.idSession = 0;
1221 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1222 swctrl.fbJump = SWL_JUMPABLE;
1223 swctrl.bProgType = PROG_PM;
1224 if(title) {
1225 CharToOemBuffA( title, swctrl.szSwtitle, min(strlen(title)+1,MAXNAMEL+4) );
1226 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1227 }
1228 else {
1229 swctrl.szSwtitle[0] = 0;
1230 swctrl.uchVisibility = SWL_INVISIBLE;
1231 }
1232 HANDLE hTaskList = WinAddSwitchEntry(&swctrl);
1233 dprintf(("OSLibWinAddToTaskList %s %x", swctrl.szSwtitle, hTaskList));
1234 return hTaskList;
1235}
1236//******************************************************************************
1237//******************************************************************************
1238BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1239{
1240 SWCNTRL swctrl;
1241 ULONG tid;
1242
1243 swctrl.hwnd = hwndFrame;
1244 swctrl.hwndIcon = 0;
1245 swctrl.hprog = 0;
1246 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1247 swctrl.idSession = 0;
1248 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1249 swctrl.fbJump = SWL_JUMPABLE;
1250 swctrl.bProgType = PROG_PM;
1251 dprintf(("OSLibWinChangeTaskList %x %s swctrl %x size %d", hTaskList, title, &swctrl, sizeof(swctrl)));
1252 if(title) {
1253 CharToOemBuffA( title, swctrl.szSwtitle, min(strlen(title)+1,MAXNAMEL+4) );
1254 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1255 }
1256 else {
1257 swctrl.szSwtitle[0] = 0;
1258 swctrl.uchVisibility = SWL_INVISIBLE;
1259 }
1260 dprintf(("hwnd %x", swctrl.hwnd));
1261 dprintf(("hwndIcon %x", swctrl.hwndIcon));
1262 dprintf(("hprog %x", swctrl.hprog));
1263 dprintf(("idProcess %x", swctrl.idProcess));
1264 dprintf(("idSession %x", swctrl.idSession));
1265 dprintf(("uchVisibility %x", swctrl.uchVisibility));
1266 dprintf(("fbJump %x", swctrl.fbJump));
1267 dprintf(("bProgType %x", swctrl.bProgType));
1268 dprintf(("szSwtitle %s", swctrl.szSwtitle));
1269
1270 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1271}
1272//******************************************************************************
1273//******************************************************************************
1274BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1275{
1276 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1277}
1278//******************************************************************************
1279//******************************************************************************
1280ULONG OSLibGetScreenHeight()
1281{
1282 return ScreenHeight;
1283}
1284//******************************************************************************
1285//******************************************************************************
1286ULONG OSLibGetScreenWidth()
1287{
1288 return ScreenWidth;
1289}
1290//******************************************************************************
1291//Returns the maximum position for a window
1292//Should only be used from toplevel windows
1293//******************************************************************************
1294BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1295{
1296 SWP swp;
1297
1298 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1299 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1300 return FALSE;
1301 }
1302 rect->left = swp.x;
1303 rect->right = swp.x + swp.cx;
1304 rect->top = ScreenHeight - (swp.y + swp.cy);
1305 rect->bottom = ScreenHeight - swp.y;
1306 return TRUE;
1307}
1308//******************************************************************************
1309//******************************************************************************
1310BOOL OSLibWinShowPointer(BOOL fShow)
1311{
1312 return WinShowPointer(HWND_DESKTOP, fShow);
1313}
1314//******************************************************************************
1315//******************************************************************************
1316ULONG OSLibWinQuerySysColor(int index)
1317{
1318 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
1319}
1320//******************************************************************************
1321//PF This was added for IBM Wheel Mouse driver - it searches for scrollbars and
1322//only if they exist sends WM_VSCROLL messages to the window
1323//******************************************************************************
1324HWND OSLibWinCreateInvisibleScroller(HWND parentHWND, int direction)
1325{
1326 return WinCreateWindow(parentHWND, WC_SCROLLBAR, NULL, direction,
1327 0, 0, 0, 0, parentHWND, HWND_BOTTOM, 1, NULL, NULL);
1328}
1329//******************************************************************************
1330//******************************************************************************
1331void OSLibWinLockVisibleRegions(BOOL fLock)
1332{
1333 WinLockVisRegions(HWND_DESKTOP, fLock);
1334}
1335//******************************************************************************
1336//******************************************************************************
Note: See TracBrowser for help on using the repository browser.