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

Last change on this file since 21461 was 21461, checked in by dmik, 15 years ago

Fixed: Title bar in OS/2 look and feel mode displayed text with national characters in wrong encoding.

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