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

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

user32: Fixed incorrect code page translation of window title text (seen if the target window PM thread is already switched to the Windows ANSI code page as in case of windows created on threads other than main, like in Java). See #24.

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