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

Last change on this file since 10549 was 10549, checked in by sandervl, 21 years ago

Silently ignored WS_EX_TOPMOST for child windows. This combination causes paint problems in PM when you resize the window.

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