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

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

Tool windows don't have minimize or maximize buttons; always draw tool windows in win32 style as they are not compatible with PM frame controls

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