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

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

KSO: Removed duplicate (and dangerous) checks on framewindows in a couple of enumerations (OSLibWinQueryClientWindow).

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