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

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

PM windows should have no owner if none is specified. (instead of their parent)

File size: 51.6 KB
Line 
1/* $Id: oslibwin.cpp,v 1.144 2003-10-20 17:17:22 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_WIN
14#define INCL_PM
15#define INCL_WINSWITCHLIST
16#include <os2wrap.h>
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20
21#include <misc.h>
22#include <win32type.h>
23#include <winconst.h>
24#include <winuser32.h>
25#include <wprocess.h>
26#include "oslibwin.h"
27#include "oslibutil.h"
28#include "oslibmsg.h"
29#include "oslibgdi.h"
30#include "pmwindow.h"
31#include "initterm.h"
32
33#define DBG_LOCALLOG DBG_oslibwin
34#include "dbglocal.h"
35
36//Undocumented PM WS_TOPMOST style; similar to WS_EX_TOPMOST in Windows
37#define WS_TOPMOST 0x00200000L
38
39//******************************************************************************
40//******************************************************************************
41BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
42{
43 if(hwndParent == OSLIB_HWND_DESKTOP)
44 {
45 hwndParent = HWND_DESKTOP;
46 }
47 else
48 if(hwndParent == OSLIB_HWND_OBJECT) {
49 hwndParent = HWND_OBJECT;
50 }
51 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
52}
53//******************************************************************************
54//******************************************************************************
55BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
56{
57 return WinSetOwner(hwnd, hwndOwner);
58}
59//******************************************************************************
60//******************************************************************************
61HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
62 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
63 ULONG id, BOOL fTaskList,BOOL fShellPosition,
64 DWORD classStyle, HWND *hwndFrame)
65{
66 HWND hwndClient;
67 ULONG dwFrameStyle = 0;
68
69 if(pszName && *pszName == 0) {
70 pszName = NULL;
71 }
72 if(hwndParent == OSLIB_HWND_DESKTOP) {
73 hwndParent = HWND_DESKTOP;
74 }
75 if(Owner == OSLIB_HWND_DESKTOP) {
76 Owner = HWND_DESKTOP;
77 }
78
79 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
80 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
81
82 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
83
84 if(fTaskList)
85 {
86 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
87 }
88 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
89
90 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
91 FCData.flCreateFlags = dwFrameStyle;
92
93 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
94 dprintf(("WinCreateWindow parent %x, owner %x", hwndParent, Owner));
95
96 //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise.
97 //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds
98 // a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border
99 *hwndFrame = WinCreateWindow(hwndParent,
100 WIN32_STDFRAMECLASS,
101 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
102 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
103 id, (PVOID)&FCData, NULL);
104
105 if(fOS2Look && *hwndFrame) {
106 FCData.flCreateFlags = dwOSFrameStyle;
107 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
108 }
109 if(*hwndFrame == 0) {
110 dprintf(("Frame window creation failed!! OS LastError %0x", WinGetLastError(0)));
111 return 0;
112 }
113 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
114 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
115 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
116 //@PF For all top-level windows we create invisible vertical scroller
117 //to show IBM wheel driver that we need WM_VSCROLL messages
118 if (hwndParent == HWND_DESKTOP && *hwndFrame)
119 OSLibWinCreateInvisibleScroller(*hwndFrame, SBS_VERT);
120
121
122 if(hwndClient == 0) {
123 dprintf(("Client window creation failed!! OS LastError %0x", WinGetLastError(0)));
124 }
125 return hwndClient;
126}
127//******************************************************************************
128//Note: Also check OSLibSetWindowStyle when changing this!!
129//******************************************************************************
130BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle,
131 ULONG *OSFrameStyle)
132{
133 *OSWinStyle = 0;
134 *OSFrameStyle = 0;
135
136 /* Window styles */
137 if(dwStyle & WS_DISABLED_W)
138 *OSWinStyle |= WS_DISABLED;
139 if(dwStyle & WS_CLIPSIBLINGS_W)
140 *OSWinStyle |= WS_CLIPSIBLINGS;
141 if(dwStyle & WS_CLIPCHILDREN_W)
142 *OSWinStyle |= WS_CLIPCHILDREN;
143 if(dwExStyle & WS_EX_TOPMOST_W)
144 *OSWinStyle |= WS_TOPMOST;
145
146 //WS_EX_TOOLWINDOW is incompatible with the OS2Look (titlebar thinner + smaller font)
147 if(fOS2Look && !(dwExStyle & WS_EX_TOOLWINDOW_W))
148 {
149 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
150 *OSFrameStyle = FCF_TITLEBAR;
151
152 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
153 {
154 *OSFrameStyle |= FCF_SYSMENU;
155 }
156 if(dwStyle & WS_MINIMIZEBOX_W) {
157 *OSFrameStyle |= FCF_MINBUTTON;
158 }
159 if(dwStyle & WS_MAXIMIZEBOX_W) {
160 *OSFrameStyle |= FCF_MAXBUTTON;
161 }
162 if(dwStyle & WS_SYSMENU_W) {
163 *OSFrameStyle |= FCF_CLOSEBUTTON;
164 }
165 }
166 }
167 return TRUE;
168}
169//******************************************************************************
170//******************************************************************************
171BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
172 DWORD dwExStyle, HICON hSysMenuIcon,
173 BOOL drawCloseButton, BOOL fClassIcon)
174{
175 SWP swp[3];
176 HWND hwndControl;
177 int i = 0;
178 static int minmaxwidth = 0;
179 static int minmaxheight = 0;
180
181 dprintf(("OSLibWinPositionFrameControls %x (%x,%x) %x %d", hwndFrame, dwStyle, dwExStyle, hSysMenuIcon, drawCloseButton));
182
183 //WS_EX_TOOLWINDOW is incompatible with the OS2Look (titlebar thinner + smaller font)
184 if(dwExStyle & WS_EX_TOOLWINDOW_W) {
185 DebugInt3();
186 return FALSE;
187 }
188
189 if(minmaxwidth == 0) {
190 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
191 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
192 }
193
194 if(fOS2Look == OS2_APPEARANCE_SYSMENU) {
195 //Note: If no class icon *and* WS_EX_DLGMODALFRAME -> no system menu!!
196 // --> TODO
197 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
198 if(hwndControl) {
199 swp[i].hwnd = hwndControl;
200 swp[i].hwndInsertBehind = HWND_TOP;
201 swp[i].x = pRect->xLeft;
202 swp[i].y = pRect->yBottom;
203 if(pRect->yTop - pRect->yBottom > minmaxheight) {
204 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
205 }
206 swp[i].cx = minmaxwidth/2;
207 swp[i].cy = minmaxheight;;
208 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
209 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
210 pRect->xLeft += minmaxwidth/2;
211 i++;
212 }
213 }
214 else
215 //Note: If no class icon *and* WS_EX_DLGMODALFRAME -> no system menu!!
216 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) &&
217 !(!fClassIcon && (dwExStyle & WS_EX_DLGMODALFRAME_W)) && hSysMenuIcon)
218 {
219 pRect->xLeft += minmaxwidth/2;
220 }
221
222 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
223 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
224 if(hwndControl) {
225 swp[i].hwnd = hwndControl;
226 swp[i].hwndInsertBehind = HWND_TOP;
227 swp[i].x = pRect->xLeft;
228 swp[i].y = pRect->yBottom;
229 if(pRect->yTop - pRect->yBottom > minmaxheight) {
230 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
231 }
232 swp[i].cx = pRect->xRight - pRect->xLeft;
233 if((dwStyle & WS_MINIMIZEBOX_W)) {
234 swp[i].cx -= minmaxwidth/2;
235 }
236 if((dwStyle & WS_MAXIMIZEBOX_W)) {
237 swp[i].cx -= minmaxwidth/2;
238 }
239 //there is no close button in warp 3 and sometimes we do not
240 //have close button as well
241 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3 && drawCloseButton) {
242 swp[i].cx -= minmaxwidth/2;
243 }
244 swp[i].cy = minmaxheight;
245 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
246 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
247 pRect->xLeft += swp[i].cx;
248 i++;
249 }
250 else return FALSE; //no titlebar -> no frame controls
251 }
252 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
253 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
254 if(hwndControl) {
255 swp[i].hwnd = hwndControl;
256 swp[i].hwndInsertBehind = HWND_TOP;
257 swp[i].x = pRect->xLeft;
258 swp[i].y = pRect->yBottom;
259 if(pRect->yTop - pRect->yBottom > minmaxheight) {
260 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
261 }
262 swp[i].cx = 0;
263 if((dwStyle & WS_MINIMIZEBOX_W)) {
264 swp[i].cx += minmaxwidth/2;
265 }
266 if((dwStyle & WS_MAXIMIZEBOX_W)) {
267 swp[i].cx += minmaxwidth/2;
268 }
269 //there is no close button in warp 3 and sometimes we do not have
270 //close button as well
271 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3 && drawCloseButton) {
272 swp[i].cx += minmaxwidth/2;
273 }
274 swp[i].cy = minmaxheight;
275 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
276 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
277 pRect->xLeft += swp[i].cx;
278 i++;
279 }
280 }
281 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
282}
283//******************************************************************************
284//******************************************************************************
285BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
286{
287 if(offset == OSLIB_QWL_USER)
288 offset = QWL_USER;
289
290 return WinSetWindowULong(hwnd, offset, value);
291}
292//******************************************************************************
293//******************************************************************************
294BOOL OSLibWinGetMinPosition(HWND hwnd, PSWP pswp, PPOINTL pointl)
295{
296 return WinGetMinPosition(hwnd, pswp, pointl);
297}
298
299//******************************************************************************
300//******************************************************************************
301ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
302{
303 if(offset == OSLIB_QWL_USER)
304 offset = QWL_USER;
305
306 return WinQueryWindowULong(hwnd, offset);
307}
308//******************************************************************************
309//******************************************************************************
310BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
311{
312 return WinAlarm(hwndDeskTop,flStyle);
313}
314//******************************************************************************
315HWND OSLibWinQueryFocus(HWND hwndDeskTop)
316{
317 return WinQueryFocus(hwndDeskTop);
318}
319//******************************************************************************
320//******************************************************************************
321HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
322{
323 return WinWindowFromID(hwndParent,id);
324}
325//******************************************************************************
326//******************************************************************************
327BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
328{
329 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
330}
331//******************************************************************************
332//******************************************************************************
333BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
334{
335 return WinIsChild (hwnd, hwndOf);
336}
337//******************************************************************************
338//******************************************************************************
339ULONG OSLibGetWindowHeight(HWND hwnd)
340{
341 RECTL rect;
342
343 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
344}
345//******************************************************************************
346//******************************************************************************
347LONG OSLibWinQuerySysValue(LONG iSysValue)
348{
349 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
350}
351//******************************************************************************
352//******************************************************************************
353BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
354{
355 return WinSetSysValue(HWND_DESKTOP, iSysValue, val);
356}
357//******************************************************************************
358//******************************************************************************
359ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
360{
361 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
362}
363//******************************************************************************
364//******************************************************************************
365BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
366{
367 return WinSetDlgItemText(hwndDlg,idItem,pszText);
368}
369//******************************************************************************
370//******************************************************************************
371BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
372{
373 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
374}
375//******************************************************************************
376//******************************************************************************
377BOOL OSLibWinSetPointerPos(int x, int y)
378{
379 return WinSetPointerPos(HWND_DESKTOP, x, y);
380}
381//******************************************************************************
382//******************************************************************************
383HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
384{
385 return WinQueryWindow(hwnd, lCode);
386}
387//******************************************************************************
388//******************************************************************************
389BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
390{
391 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
392}
393//******************************************************************************
394//******************************************************************************
395BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
396{
397 BOOL rc = 1;
398
399 if(fl & SWP_SHOW) {
400 rc = WinShowWindow(hwnd, TRUE);
401 }
402 if(rc == 0)
403 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
404 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
405 if(rc == 0)
406 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
407 return rc;
408}
409//******************************************************************************
410//******************************************************************************
411BOOL OSLibWinDestroyWindow(HWND hwnd)
412{
413 return WinDestroyWindow(hwnd);
414}
415//******************************************************************************
416//******************************************************************************
417BOOL OSLibWinQueryWindowClientRect(HWND hwndOS2, PRECT pRect)
418{
419 BOOL rc;
420 RECTLOS2 rectl;
421
422 rc = WinQueryWindowRect(hwndOS2, (PRECTL)&rectl);
423 if(rc) {
424 pRect->left = 0;
425 pRect->right = rectl.xRight - rectl.xLeft;
426 pRect->top = 0;
427 pRect->bottom = rectl.yTop - rectl.yBottom;
428 }
429 else memset(pRect, 0, sizeof(RECT));
430 return rc;
431}
432//******************************************************************************
433//******************************************************************************
434BOOL OSLibQueryWindowRectAbsolute (HWND hwndOS2, PRECT pRect)
435{
436 BOOL rc;
437 RECTLOS2 rectl;
438
439 rc = WinQueryWindowRect (hwndOS2, (RECTL *)&rectl);
440 if (rc)
441 {
442 rc = WinMapWindowPoints (hwndOS2, HWND_DESKTOP, (POINTL *)&rectl, 2);
443 if (rc)
444 {
445 pRect->left = rectl.xLeft;
446 pRect->right = rectl.xRight;
447 pRect->top = mapScreenY (rectl.yTop);
448 pRect->bottom = mapScreenY (rectl.yBottom);
449 }
450 }
451 if (!rc)
452 {
453 memset(pRect, 0, sizeof(*pRect));
454 }
455 return rc;
456}
457//******************************************************************************
458//******************************************************************************
459#if 0
460BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
461{
462 BOOL rc;
463 RECTLOS2 rectl;
464
465 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
466 if(rc) {
467 if(RelativeTo == RELATIVE_TO_SCREEN) {
468 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
469 }
470 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
471 }
472 else memset(pRect, 0, sizeof(RECT));
473 return rc;
474}
475#endif
476//******************************************************************************
477//******************************************************************************
478BOOL OSLibWinIsIconic(HWND hwnd)
479{
480 SWP swp;
481 BOOL rc;
482
483 rc = WinQueryWindowPos(hwnd, &swp);
484 if(rc == FALSE) {
485 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
486 return FALSE;
487 }
488
489 if(swp.fl & SWP_MINIMIZE)
490 return TRUE;
491 else return FALSE;
492}
493//******************************************************************************
494//******************************************************************************
495BOOL OSLibWinSetActiveWindow(HWND hwnd)
496{
497 BOOL rc;
498
499 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
500 if(rc == FALSE) {
501 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
502 }
503 return rc;
504}
505//******************************************************************************
506//******************************************************************************
507BOOL OSLibWinSetFocus(HWND hwnd)
508{
509 return WinSetFocus(HWND_DESKTOP, hwnd);
510}
511//******************************************************************************
512//******************************************************************************
513BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
514{
515 BOOL rc;
516 HWND hwndClient;
517
518 rc = WinEnableWindow(hwnd, fEnable);
519 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
520 if(hwndClient) {
521 WinEnableWindow(hwndClient, fEnable);
522 }
523 return rc;
524}
525//******************************************************************************
526//******************************************************************************
527BOOL OSLibWinIsWindowEnabled(HWND hwnd)
528{
529 return WinIsWindowEnabled(hwnd);
530}
531//******************************************************************************
532//******************************************************************************
533BOOL OSLibWinIsWindowVisible(HWND hwnd)
534{
535 return WinIsWindowVisible(hwnd);
536}
537//******************************************************************************
538//******************************************************************************
539HWND OSLibWinQueryActiveWindow()
540{
541 return WinQueryActiveWindow(HWND_DESKTOP);
542}
543//******************************************************************************
544//******************************************************************************
545LONG OSLibWinQueryWindowTextLength(HWND hwnd)
546{
547 return WinQueryWindowTextLength(hwnd);
548}
549//******************************************************************************
550//******************************************************************************
551LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
552{
553 return WinQueryWindowText(hwnd, length, lpsz);
554}
555//******************************************************************************
556//******************************************************************************
557BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
558{
559 return WinSetWindowText(hwnd, lpsz);
560}
561//******************************************************************************
562//******************************************************************************
563BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
564{
565 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
566}
567//******************************************************************************
568//******************************************************************************
569BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
570{
571 return WinFlashWindow(hwnd, fFlash);
572}
573//******************************************************************************
574//******************************************************************************
575HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
576{
577 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
578}
579
580//******************************************************************************
581//@PF This is exactly that weird message PM sends when we maximize window from
582//icon - this coordinates NEVER surface later and this combination of SWP
583//commands is useless, yet it starts the correct reaction of maximiztion from
584//icon state
585//******************************************************************************
586BOOL OSLibWinRestoreWindow(HWND hwnd)
587{
588 BOOL rc = WinSetWindowPos(hwnd, 0, -32000, 32000, 32000, 32000 , SWP_MAXIMIZE | SWP_RESTORE | SWP_ACTIVATE);
589 return (rc);
590}
591
592//******************************************************************************
593//******************************************************************************
594BOOL OSLibWinMinimizeWindow(HWND hwnd)
595{
596 /* @@PF The reason for this weird minimize algorithm is that we are not fully
597 using PM for minimization. I.e. we respect all PM messages yet we do mess
598 so much with some messages that minimization is based partly on vodoo.
599 That is if you try minimize and deactivate in one call it will fail.
600 Here we deactivate yourselves and give focus to next window that is
601 on desktop, this func also works with MDI */
602
603 BOOL rc;
604 HWND hwndNext;
605
606 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
607
608 if (rc) {
609 rc = WinSetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_DEACTIVATE | SWP_ZORDER);
610 if (rc)
611 {
612 HENUM henum;
613 henum = WinBeginEnumWindows(HWND_DESKTOP);
614 while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)
615 {
616 if (WinIsWindowVisible(hwndNext) && WinIsWindowShowing(hwndNext)) break;
617 }
618 WinEndEnumWindows (henum);
619 rc = WinSetWindowPos(hwndNext, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
620 }
621 }
622
623 return (rc);
624}
625//******************************************************************************
626//******************************************************************************
627BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
628{
629 pointl->x = 0;
630 pointl->y = 0;
631 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
632}
633//******************************************************************************
634//******************************************************************************
635BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
636{
637 ULONG hIconOS2 = GetOS2Icon(hIcon);
638 if(hIconOS2)
639 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
640 return FALSE;
641}
642//******************************************************************************
643//******************************************************************************
644BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
645{
646 return WinQueryWindowPos(hwnd, pswp);
647}
648//******************************************************************************
649//******************************************************************************
650void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
651 int parentHeight, HWND hwnd)
652{
653 HWND hWindow = pswp->hwnd;
654 HWND hWndInsertAfter = pswp->hwndInsertBehind;
655 long x = pswp->x;
656 long y = pswp->y;
657 long cx = pswp->cx;
658 long cy = pswp->cy;
659 UINT fuFlags = (UINT)pswp->fl;
660
661 HWND hWinAfter;
662 ULONG flags = 0;
663
664 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
665
666 if (hWndInsertAfter == HWND_TOP)
667 hWinAfter = HWND_TOP_W;
668 else if (hWndInsertAfter == HWND_BOTTOM)
669 hWinAfter = HWND_BOTTOM_W;
670 else
671 hWinAfter = (HWND) hWndInsertAfter;
672
673 //***********************************
674 // convert PM flags to Windows flags
675 //***********************************
676 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
677 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
678 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
679 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
680 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
681 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
682 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
683 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
684
685 if(fuFlags & (SWP_MOVE | SWP_SIZE))
686 {
687 y = parentHeight - y - pswp->cy;
688
689 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
690 flags |= SWP_NOMOVE_W;
691
692 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
693 flags |= SWP_NOSIZE_W;
694
695 if (fuFlags & SWP_SIZE)
696 {
697 if (pswp->cy != pswpOld->cy)
698 {
699 flags &= ~SWP_NOMOVE_W;
700 }
701 }
702 }
703
704 pswpOld->x = pswp->x;
705 pswpOld->y = parentHeight-pswp->y-pswp->cy;
706 pswpOld->cx = pswp->cx;
707 pswpOld->cy = pswp->cy;
708
709 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
710 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
711
712 pwpos->flags = (UINT)flags;
713 pwpos->cy = cy;
714 pwpos->cx = cx;
715 pwpos->x = x;
716 pwpos->y = y;
717 pwpos->hwndInsertAfter = hWinAfter;
718 pwpos->hwnd = hWindow;
719
720 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));
721}
722//******************************************************************************
723//******************************************************************************
724void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
725 int parentHeight, HWND hFrame)
726{
727 BOOL fCvt = FALSE;
728
729 HWND hWnd = pwpos->hwnd;
730 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
731 long x = pwpos->x;
732 long y = pwpos->y;
733 long cx = pwpos->cx;
734 long cy = pwpos->cy;
735 UINT fuFlags = pwpos->flags;
736
737 HWND hWinAfter;
738 ULONG flags = 0;
739 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
740
741 if (hWndInsertAfter == HWND_TOPMOST_W)
742// hWinAfter = HWND_TOPMOST;
743 hWinAfter = HWND_TOP;
744 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
745// hWinAfter = HWND_NOTOPMOST;
746 hWinAfter = HWND_TOP;
747 else if (hWndInsertAfter == HWND_TOP_W)
748 hWinAfter = HWND_TOP;
749 else if (hWndInsertAfter == HWND_BOTTOM_W)
750 hWinAfter = HWND_BOTTOM;
751 else
752 hWinAfter = (HWND) hWndInsertAfter;
753
754 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
755 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
756 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
757 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
758 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
759 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
760 //SvL: Must also deactivate the window when hiding it or else focus won't
761 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
762 if ( fuFlags & SWP_HIDEWINDOW_W) {
763 flags |= SWP_HIDE|SWP_DEACTIVATE;
764 }
765
766 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
767
768 if(flags & (SWP_MOVE | SWP_SIZE))
769 {
770 if((flags & SWP_MOVE) == 0)
771 {
772 x = pswpOld->x;
773 y = pswpOld->y;
774
775 y = parentHeight - y - pswpOld->cy;
776 }
777
778 if(flags & SWP_SIZE)
779 {
780 if (cy != pswpOld->cy)
781 flags |= SWP_MOVE;
782 }
783 else
784 {
785 cx = pswpOld->cx;
786 cy = pswpOld->cy;
787 }
788 y = parentHeight - y - cy;
789
790 if ((pswpOld->x == x) && (pswpOld->y == y))
791 flags &= ~SWP_MOVE;
792
793 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
794 flags &= ~SWP_SIZE;
795 }
796
797 pswp->fl = flags;
798 pswp->cy = cy;
799 pswp->cx = cx;
800 pswp->x = x;
801 pswp->y = y;
802 pswp->hwndInsertBehind = hWinAfter;
803 pswp->hwnd = hWindow;
804 pswp->ulReserved1 = 0;
805 pswp->ulReserved2 = 0;
806
807 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));
808}
809//******************************************************************************
810//******************************************************************************
811void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
812{
813 SWP swp;
814 BOOL rc;
815
816 swp.hwnd = hwnd;
817 swp.hwndInsertBehind = 0;
818 swp.x = x;
819 swp.y = parentHeight - y - cy;
820 swp.cx = cx;
821 swp.cy = cy;
822 swp.fl = SWP_MOVE | SWP_SIZE;
823
824 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));
825
826 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
827 if(rc == FALSE) {
828 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
829 }
830}
831//******************************************************************************
832//******************************************************************************
833BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
834{
835 BOOL rc;
836
837 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
838
839 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
840 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
841
842 return rc;
843}
844//******************************************************************************
845//******************************************************************************
846BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
847{
848 TRACKINFO tinfo;
849
850 memset(&tinfo, 0, sizeof(TRACKINFO));
851 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
852
853 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
854 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
855 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
856 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
857 return TRUE;
858}
859//******************************************************************************
860//******************************************************************************
861HWND OSLibWinBeginEnumWindows(HWND hwnd)
862{
863 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
864 else
865 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
866
867 return WinBeginEnumWindows(hwnd);
868}
869//******************************************************************************
870//******************************************************************************
871HWND OSLibWinGetNextWindow(HWND hwndEnum)
872{
873 return WinGetNextWindow(hwndEnum);
874}
875//******************************************************************************
876//******************************************************************************
877HWND OSLibWinQueryClientWindow(HWND hwndFrame)
878{
879 HWND hwndClient = 0;
880
881 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
882 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
883
884 return hwndClient;
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(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.