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

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

Use WC_FRAME for the Odin frame window and subclass it; Updates for new keyboard hook

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