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

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

Update

File size: 52.2 KB
Line 
1/* $Id: oslibwin.cpp,v 1.146 2004-01-11 12:03:15 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//******************************************************************************
886HWND OSLibWinQueryClientWindow(HWND hwndFrame)
887{
888 HWND hwndClient = 0;
889
890 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
891 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
892
893 return hwndClient;
894}
895//******************************************************************************
896//******************************************************************************
897BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
898{
899 return WinEndEnumWindows(hwndEnum);
900}
901//******************************************************************************
902//******************************************************************************
903BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
904{
905 BOOL ret;
906
907 ret = WinQueryWindowProcess(hwnd, pid, tid);
908 *tid = MAKE_THREADID(*pid, *tid);
909 return ret;
910}
911//******************************************************************************
912//******************************************************************************
913BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
914{
915 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
916}
917//******************************************************************************
918//******************************************************************************
919HWND OSLibWinQueryObjectWindow(VOID)
920{
921 return WinQueryObjectWindow(HWND_DESKTOP);
922}
923//******************************************************************************
924//******************************************************************************
925HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
926{
927 HWND hwndNext, hwndFound=0;
928 HENUM henum;
929
930 henum = WinBeginEnumWindows(HWND_OBJECT);
931 while ((hwndNext = WinGetNextWindow(henum)) != 0)
932 {
933 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
934 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
935 {
936 hwndFound = hwndNext;
937 break;
938 }
939 }
940 WinEndEnumWindows(henum);
941 return hwndFound;
942}
943//******************************************************************************
944//******************************************************************************
945BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
946{
947 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
948 return WinSetWindowULong(hwnd, QWS_ID, value);
949}
950//******************************************************************************
951//******************************************************************************
952PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
953{
954 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
955}
956//******************************************************************************
957//******************************************************************************
958BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
959{
960 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
961
962 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
963 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
964 (pRect->bottom - pRect->top)));
965 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
966 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
967 return TRUE;
968}
969//******************************************************************************
970//******************************************************************************
971BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
972{
973 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
974
975 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
976 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
977 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
978 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
979 return TRUE;
980}
981//******************************************************************************
982//******************************************************************************
983BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
984{
985 WinEnableWindowUpdate(hwndFrame, fEnable);
986 return WinEnableWindowUpdate(hwndClient, fEnable);
987}
988//******************************************************************************
989//******************************************************************************
990ULONG OSLibWinGetLastError()
991{
992 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
993}
994//******************************************************************************
995//******************************************************************************
996void OSLibWinShowTaskList(HWND hwndFrame)
997{
998 SWBLOCK swblk;
999 // the first entry returned is always the window list itself
1000 if (WinQuerySwitchList(0, &swblk, sizeof(SWBLOCK)) > 0)
1001 WinSetActiveWindow(HWND_DESKTOP, swblk.aswentry[0].swctl.hwnd);
1002// WinShowWindow(swblk.aswentry[0].swctl.hwnd, TRUE);
1003}
1004//******************************************************************************
1005//******************************************************************************
1006//PF: PM Logic approved by numerous testcases shows this:
1007//There is no other way to tweak FID_MINMAX without deleting it
1008//Controls are created with size 0,0, invisible and should be immediately
1009//positioned. MINMAX control can't function properly without FID_SYSMENU
1010//control if it is present, so we need to recreate BOTH controls.
1011//Currently OSLibSetWindowStyle checks for changes and actually do the job
1012//only when it is needed so no additional messages are generated.
1013//TO-DO: There MAY BE some regressions here but I haven't seen them
1014//and yes this code is the only way to do WinCreateFrame controls,
1015//first delete old then create new - all other variants create new and
1016//leave old, WinCreateFrameControls can't tweak anything.
1017
1018void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle,
1019 ULONG dwExStyle, ULONG dwOldWindowsStyle)
1020{
1021 ULONG dwWinStyle;
1022 ULONG dwOldWinStyle;
1023
1024 int checksum, checksum2;
1025 DWORD dest_tid, dest_pid;
1026
1027 static int minmaxwidth = 0;
1028 static int minmaxheight = 0;
1029
1030
1031 //PF We can tweak OS/2 controls ONLY from thread that created them
1032 //in other case heavy PM lockups will follow
1033
1034 dest_tid = GetWindowThreadProcessId(OS2ToWin32Handle(hwndClient) , &dest_pid );
1035
1036 if (dest_tid != GetCurrentThreadId())
1037 {
1038 dprintf(("OSLibSetWindowStyle: Redirecting Change Frame controls to another thread"));
1039 WinSendMsg(hwndFrame, WIN32APP_CHNGEFRAMECTRLS, (MPARAM)dwStyle, (MPARAM)dwOldWindowsStyle);
1040 return;
1041 }
1042 if(minmaxwidth == 0) {
1043 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
1044 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
1045 }
1046
1047 if (hwndClient)
1048 {
1049 //client window:
1050 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
1051 dwOldWinStyle = dwWinStyle;
1052
1053 if(dwStyle & WS_CLIPCHILDREN_W) {
1054 dwWinStyle |= WS_CLIPCHILDREN;
1055 }
1056 else dwWinStyle &= ~WS_CLIPCHILDREN;
1057
1058 if(dwWinStyle != dwOldWinStyle) {
1059 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
1060 }
1061 }
1062
1063 //Frame window
1064 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
1065 dwOldWinStyle = dwWinStyle;
1066
1067 checksum = (dwOldWindowsStyle & WS_MINIMIZEBOX_W) + (dwOldWindowsStyle & WS_MAXIMIZEBOX_W) + (dwOldWindowsStyle & WS_SYSMENU_W);
1068 checksum2 = (dwStyle & WS_MINIMIZEBOX_W) + (dwStyle & WS_MAXIMIZEBOX_W) + (dwStyle & WS_SYSMENU_W);
1069
1070 if(dwStyle & WS_DISABLED_W) {
1071 dwWinStyle |= WS_DISABLED;
1072 }
1073 else dwWinStyle &= ~WS_DISABLED;
1074
1075 if(dwExStyle & WS_EX_TOPMOST_W) {
1076 dwWinStyle |= WS_TOPMOST;
1077 }
1078 else dwWinStyle &= ~WS_TOPMOST;
1079
1080 if(dwStyle & WS_CLIPSIBLINGS_W) {
1081 dwWinStyle |= WS_CLIPSIBLINGS;
1082 }
1083 else dwWinStyle &= ~WS_CLIPSIBLINGS;
1084
1085 if(dwStyle & WS_MINIMIZE_W) {
1086 dwWinStyle |= WS_MINIMIZED;
1087 }
1088 else dwWinStyle &= ~WS_MINIMIZED;
1089
1090 if(dwStyle & WS_MAXIMIZE_W) {
1091 dwWinStyle |= WS_MAXIMIZED;
1092 }
1093 else
1094 dwWinStyle &= ~WS_MAXIMIZED;
1095
1096 //WS_EX_TOOLWINDOW is incompatible with the OS2Look (titlebar thinner + smaller font)
1097 if(fOS2Look && !(dwExStyle & WS_EX_TOOLWINDOW_W)) {
1098 ULONG OSFrameStyle = 0;
1099 SWP rc1,rc2,rc3;
1100 int totalwidth = 0;
1101
1102 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
1103 {
1104 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
1105 OSFrameStyle = FCF_TITLEBAR;
1106 }
1107 else
1108 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR), &rc1);
1109
1110 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
1111 {
1112 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0)
1113 OSFrameStyle |= FCF_SYSMENU;
1114 }
1115 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU), &rc2);
1116 WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX), &rc3);
1117
1118 if (checksum != checksum2)
1119 {
1120 dprintf(("OSLibSetWindowStyle: Min/Max/Close state changed. Creating:"));
1121 if(dwStyle & WS_MINIMIZEBOX_W)
1122 {
1123 OSFrameStyle |= FCF_MINBUTTON;
1124 totalwidth += minmaxwidth/2;
1125 dprintf(("min button"));
1126 }
1127
1128 if(dwStyle & WS_MAXIMIZEBOX_W)
1129 {
1130 OSFrameStyle |= FCF_MAXBUTTON;
1131 totalwidth += minmaxwidth/2;
1132 dprintf(("max button"));
1133 }
1134
1135 if(dwStyle & WS_SYSMENU_W)
1136 {
1137 OSFrameStyle |= FCF_CLOSEBUTTON;
1138 OSFrameStyle |= FCF_SYSMENU;
1139 totalwidth += minmaxwidth/2;
1140 dprintf(("close button"));
1141 }
1142 }
1143 }
1144 else
1145 {
1146 if (WinWindowFromID(hwndFrame, FID_TITLEBAR))
1147 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_TITLEBAR));
1148 }
1149
1150 if (checksum != checksum2)
1151 {
1152 if (WinWindowFromID(hwndFrame, FID_SYSMENU))
1153 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_SYSMENU));
1154 if (WinWindowFromID(hwndFrame, FID_MINMAX))
1155 WinDestroyWindow(WinWindowFromID(hwndFrame, FID_MINMAX));
1156 }
1157
1158 if(OSFrameStyle) {
1159 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
1160 char buffer[255];
1161 dprintf(("Controls will be created %x",OSFrameStyle));
1162 FCData.flCreateFlags = OSFrameStyle;
1163
1164 GetWindowTextA(OS2ToWin32Handle(hwndClient), buffer, sizeof(buffer));
1165 WinCreateFrameControls(hwndFrame, &FCData, buffer );
1166
1167 if (totalwidth != rc3.cx)
1168 {
1169 rc3.cx = totalwidth;
1170 totalwidth = rc3.cx - totalwidth;
1171 rc1.cx = rc1.cx + totalwidth;
1172 rc3.x = rc3.x + totalwidth;
1173 }
1174
1175 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX),0,rc3.x,rc3.y,rc3.cx,rc3.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1176 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU),0,rc2.x,rc2.y,rc2.cx,rc2.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1177 WinSetWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR),0,rc1.x,rc1.y,rc1.cx,rc1.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
1178
1179 if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
1180 WinSendMsg(WinWindowFromID(hwndFrame, FID_TITLEBAR), TBM_SETHILITE, (MPARAM)1, 0);
1181
1182 }
1183 } // os2look
1184
1185 if(dwWinStyle != dwOldWinStyle) {
1186 dprintf(("Setting new window U long"));
1187 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
1188 }
1189
1190}
1191//******************************************************************************
1192//******************************************************************************
1193BOOL OSLibChangeCloseButtonState(HWND hwndFrame, BOOL State)
1194{
1195 dprintf(("OSLibChangeCloseButtonState %x %d", hwndFrame, State));
1196 return WinEnableMenuItem(WinWindowFromID(hwndFrame, FID_SYSMENU), SC_CLOSE, State);
1197}
1198//******************************************************************************
1199//******************************************************************************
1200DWORD OSLibQueryWindowStyle(HWND hwnd)
1201{
1202 return WinQueryWindowULong(hwnd, QWL_STYLE);
1203}
1204//******************************************************************************
1205//******************************************************************************
1206void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
1207{
1208 WinSetVisibleRegionNotify(hwnd, fNotify);
1209}
1210//******************************************************************************
1211//******************************************************************************
1212HWND OSLibWinQueryCapture()
1213{
1214 return WinQueryCapture(HWND_DESKTOP);
1215}
1216//******************************************************************************
1217//******************************************************************************
1218BOOL OSLibWinSetCapture(HWND hwnd)
1219{
1220 return WinSetCapture(HWND_DESKTOP, hwnd);
1221}
1222//******************************************************************************
1223//******************************************************************************
1224BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
1225{
1226 dprintf(("OSLibWinRemoveFromTasklist %x", hTaskList));
1227 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
1228}
1229//******************************************************************************
1230//******************************************************************************
1231HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
1232{
1233 SWCNTRL swctrl;
1234 ULONG tid;
1235
1236 swctrl.hwnd = hwndFrame;
1237 swctrl.hwndIcon = 0;
1238 swctrl.hprog = 0;
1239 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1240 swctrl.idSession = 0;
1241 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1242 swctrl.fbJump = SWL_JUMPABLE;
1243 swctrl.bProgType = PROG_PM;
1244 if(title) {
1245 CharToOemBuffA( title, swctrl.szSwtitle, min(strlen(title)+1,MAXNAMEL+4) );
1246 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1247 }
1248 else {
1249 swctrl.szSwtitle[0] = 0;
1250 swctrl.uchVisibility = SWL_INVISIBLE;
1251 }
1252 HANDLE hTaskList = WinAddSwitchEntry(&swctrl);
1253 dprintf(("OSLibWinAddToTaskList %s %x", swctrl.szSwtitle, hTaskList));
1254 return hTaskList;
1255}
1256//******************************************************************************
1257//******************************************************************************
1258BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1259{
1260 SWCNTRL swctrl;
1261 ULONG tid;
1262
1263 swctrl.hwnd = hwndFrame;
1264 swctrl.hwndIcon = 0;
1265 swctrl.hprog = 0;
1266 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1267 swctrl.idSession = 0;
1268 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1269 swctrl.fbJump = SWL_JUMPABLE;
1270 swctrl.bProgType = PROG_PM;
1271 dprintf(("OSLibWinChangeTaskList %x %s swctrl %x size %d", hTaskList, title, &swctrl, sizeof(swctrl)));
1272 if(title) {
1273 CharToOemBuffA( title, swctrl.szSwtitle, min(strlen(title)+1,MAXNAMEL+4) );
1274 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1275 }
1276 else {
1277 swctrl.szSwtitle[0] = 0;
1278 swctrl.uchVisibility = SWL_INVISIBLE;
1279 }
1280 dprintf(("hwnd %x", swctrl.hwnd));
1281 dprintf(("hwndIcon %x", swctrl.hwndIcon));
1282 dprintf(("hprog %x", swctrl.hprog));
1283 dprintf(("idProcess %x", swctrl.idProcess));
1284 dprintf(("idSession %x", swctrl.idSession));
1285 dprintf(("uchVisibility %x", swctrl.uchVisibility));
1286 dprintf(("fbJump %x", swctrl.fbJump));
1287 dprintf(("bProgType %x", swctrl.bProgType));
1288 dprintf(("szSwtitle %s", swctrl.szSwtitle));
1289
1290 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1291}
1292//******************************************************************************
1293//******************************************************************************
1294BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1295{
1296 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1297}
1298//******************************************************************************
1299//******************************************************************************
1300ULONG OSLibGetScreenHeight()
1301{
1302 return ScreenHeight;
1303}
1304//******************************************************************************
1305//******************************************************************************
1306ULONG OSLibGetScreenWidth()
1307{
1308 return ScreenWidth;
1309}
1310//******************************************************************************
1311//Returns the maximum position for a window
1312//Should only be used from toplevel windows
1313//******************************************************************************
1314BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1315{
1316 SWP swp;
1317
1318 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1319 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1320 return FALSE;
1321 }
1322 rect->left = swp.x;
1323 rect->right = swp.x + swp.cx;
1324 rect->top = ScreenHeight - (swp.y + swp.cy);
1325 rect->bottom = ScreenHeight - swp.y;
1326 return TRUE;
1327}
1328//******************************************************************************
1329//******************************************************************************
1330BOOL OSLibWinShowPointer(BOOL fShow)
1331{
1332 return WinShowPointer(HWND_DESKTOP, fShow);
1333}
1334//******************************************************************************
1335//******************************************************************************
1336ULONG OSLibWinQuerySysColor(int index)
1337{
1338 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
1339}
1340//******************************************************************************
1341//PF This was added for IBM Wheel Mouse driver - it searches for scrollbars and
1342//only if they exist sends WM_VSCROLL messages to the window
1343//******************************************************************************
1344HWND OSLibWinCreateInvisibleScroller(HWND parentHWND, int direction)
1345{
1346 return WinCreateWindow(parentHWND, WC_SCROLLBAR, NULL, direction,
1347 0, 0, 0, 0, parentHWND, HWND_BOTTOM, 1, NULL, NULL);
1348}
1349//******************************************************************************
1350//******************************************************************************
1351void OSLibWinLockVisibleRegions(BOOL fLock)
1352{
1353 WinLockVisRegions(HWND_DESKTOP, fLock);
1354}
1355//******************************************************************************
1356//******************************************************************************
1357
1358/* 'Private' PM property stuff. */
1359PVOID APIENTRY WinQueryProperty(HWND hwnd, PCSZ pszNameOrAtom);
1360PVOID APIENTRY WinRemoveProperty(HWND hwnd, PCSZ pszNameOrAtom);
1361BOOL APIENTRY WinSetProperty(HWND hwnd, PCSZ pszNameOrAtom, PVOID pvData, ULONG ulFlags);
1362
1363/**
1364 * Set Property.
1365 * @returns Success indicator.
1366 * @param hwnd Window the property is associated with.
1367 * @param psz The property atom or name.
1368 * @param pv Property value.
1369 * @param fFlags Flags. Use 0.
1370 */
1371BOOL OSLibSetProperty(HWND hwnd, const char *psz, void *pv, unsigned fFlags)
1372{
1373 USHORT selFS = RestoreOS2FS();
1374 BOOL fRet = WinSetProperty(hwnd, psz, pv, fFlags);
1375 SetFS(selFS);
1376 return fRet;
1377}
1378
1379/**
1380 * Get Property.
1381 * @returns Property value.
1382 * @param hwnd Window the property is associated with.
1383 * @param psz The property atom or name.
1384 */
1385void * OSLibQueryProperty(HWND hwnd, const char *psz)
1386{
1387 USHORT selFS = RestoreOS2FS();
1388 void *pvRet = WinQueryProperty(hwnd, psz);
1389 SetFS(selFS);
1390 return pvRet;
1391}
1392
1393/**
1394 * Remove Property.
1395 * @returns Property value.
1396 * @param hwnd Window the property is associated with.
1397 * @param psz The property atom or name.
1398 */
1399void * OSLibRemoveProperty(HWND hwnd, const char *psz)
1400{
1401 USHORT selFS = RestoreOS2FS();
1402 void *pvRet = WinRemoveProperty(hwnd, psz);
1403 SetFS(selFS);
1404 return pvRet;
1405}
1406
Note: See TracBrowser for help on using the repository browser.