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

Last change on this file since 1446 was 1446, checked in by sandervl, 26 years ago

menu changes + misc bugfixes

File size: 40.5 KB
Line 
1/* $Id: oslibwin.cpp,v 1.36 1999-10-25 20:17:19 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_WIN
14#define INCL_PM
15#include <os2.h>
16#include <os2wrap.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <misc.h>
21#include "win32type.h"
22#include <winconst.h>
23#include "oslibwin.h"
24#include "oslibutil.h"
25#include "oslibmsg.h"
26#include "oslibgdi.h"
27#include "pmwindow.h"
28
29#define HAS_3DFRAME(exStyle) \
30 ((exStyle & WS_EX_CLIENTEDGE_W) || (exStyle & WS_EX_STATICEDGE_W) || (exStyle & WS_EX_WINDOWEDGE_W))
31
32//******************************************************************************
33//******************************************************************************
34BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
35{
36 if(hwndParent == OSLIB_HWND_DESKTOP)
37 {
38 hwndParent = HWND_DESKTOP;
39 }
40
41 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
42}
43//******************************************************************************
44//******************************************************************************
45BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
46{
47 return WinSetOwner(hwnd, hwndOwner);
48}
49//******************************************************************************
50//******************************************************************************
51HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
52 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame,
53 ULONG id)
54{
55 HWND hwndClient;
56
57 dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
58
59 if(pszName && *pszName == 0) {
60 pszName = NULL;
61 }
62 if(hwndParent == OSLIB_HWND_DESKTOP) {
63 hwndParent = HWND_DESKTOP;
64 }
65 if(Owner == OSLIB_HWND_DESKTOP) {
66 Owner = HWND_DESKTOP;
67 }
68
69 ULONG dwClientStyle;
70
71// if(dwFrameStyle || hwndParent == HWND_DESKTOP) {
72 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
73
74 dwFrameStyle |= FCF_NOBYTEALIGN;
75 if (hwndParent == HWND_DESKTOP && dwFrameStyle & FCF_TITLEBAR)
76 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER;
77
78 dwWinStyle &= ~WS_CLIPCHILDREN;
79
80 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
81 &dwFrameStyle, WIN32_STDCLASS,
82 "", dwClientStyle, 0, id, &hwndClient);
83 if(*hwndFrame) {
84 if(pszName) {
85 WinSetWindowText(*hwndFrame, pszName);
86 }
87 return hwndClient;
88 }
89 dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
90 return 0;
91#if 0
92 }
93 hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
94 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
95 NULL);
96 *hwndFrame = hwndClient;
97 return hwndClient;
98#endif
99}
100//******************************************************************************
101//******************************************************************************
102BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle, ULONG *borderWidth, ULONG *borderHeight)
103{
104 *OSWinStyle = 0;
105 *OSFrameStyle = 0;
106 *borderWidth = 0;
107 *borderHeight = 0;
108
109 /* Window styles */
110 if(dwStyle & WS_MINIMIZE_W)
111 *OSWinStyle |= WS_MINIMIZED;
112//Done explicitely in CreateWindowExA
113#if 1
114 if(dwStyle & WS_VISIBLE_W)
115 *OSWinStyle |= WS_VISIBLE;
116#endif
117 if(dwStyle & WS_DISABLED_W)
118 *OSWinStyle |= WS_DISABLED;
119 if(dwStyle & WS_CLIPSIBLINGS_W)
120 *OSWinStyle |= WS_CLIPSIBLINGS;
121 if(dwStyle & WS_CLIPCHILDREN_W)
122 *OSWinStyle |= WS_CLIPCHILDREN;
123 if(dwStyle & WS_MAXIMIZE_W)
124 *OSWinStyle |= WS_MAXIMIZED;
125 if(dwStyle & WS_GROUP_W)
126 *OSWinStyle |= WS_GROUP;
127 if(dwStyle & WS_TABSTOP_W)
128 *OSWinStyle |= WS_TABSTOP;
129
130 if(dwStyle & WS_CHILD_W && !((dwStyle & WS_CAPTION_W) == WS_CAPTION_W))
131 {
132//SvL: Causes crash in VPBuddy if enabled -> find bug
133#if 0
134 if (!HAS_3DFRAME(*dwExStyle) && (dwStyle & (WS_DLGFRAME_W | WS_THICKFRAME_W))) *dwExStyle |= WS_EX_DLGMODALFRAME_W;
135#endif
136
137 if (*dwExStyle & WS_EX_CLIENTEDGE_W)
138 {
139 *OSFrameStyle |= FCF_SIZEBORDER;
140 *borderHeight = *borderWidth = 2;
141 } else if (*dwExStyle & WS_EX_DLGMODALFRAME_W)
142 {
143 *OSFrameStyle |= FCF_SIZEBORDER;
144 *borderHeight = *borderWidth = 3;
145 } else if (*dwExStyle & WS_EX_STATICEDGE_W)
146 {
147 *OSFrameStyle |= FCF_SIZEBORDER;
148 *borderHeight = *borderWidth = 2;
149 }
150 else
151 if(dwStyle & WS_BORDER_W)
152 {
153 *OSFrameStyle |= FCF_BORDER;
154 *borderHeight = *borderWidth = 1;
155 }
156 else if (*dwExStyle & WS_EX_WINDOWEDGE_W); //no border
157
158 if(dwStyle & WS_VSCROLL_W)
159 *OSFrameStyle |= FCF_VERTSCROLL;
160 if(dwStyle & WS_HSCROLL_W)
161 *OSFrameStyle |= FCF_HORZSCROLL;
162 }
163 else
164 {
165 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
166 *OSFrameStyle |= FCF_TITLEBAR;
167 if(dwStyle & WS_DLGFRAME_W)
168 *OSFrameStyle |= FCF_DLGBORDER;
169 else
170 if(dwStyle & WS_BORDER_W)
171 *OSFrameStyle |= FCF_BORDER;
172
173 if(dwStyle & WS_VSCROLL_W)
174 *OSFrameStyle |= FCF_VERTSCROLL;
175 if(dwStyle & WS_HSCROLL_W)
176 *OSFrameStyle |= FCF_HORZSCROLL;
177
178 if(dwStyle & WS_SYSMENU_W)
179 *OSFrameStyle |= FCF_SYSMENU;
180 if(dwStyle & WS_THICKFRAME_W)
181 *OSFrameStyle |= FCF_SIZEBORDER; //??
182 if(dwStyle & WS_MINIMIZEBOX_W)
183 *OSFrameStyle |= FCF_MINBUTTON;
184 if(dwStyle & WS_MAXIMIZEBOX_W)
185 *OSFrameStyle |= FCF_MAXBUTTON;
186
187 if(*dwExStyle & WS_EX_DLGMODALFRAME_W)
188 *OSFrameStyle |= FCF_DLGBORDER;
189 }
190
191 //Clear certain frame bits when the window doesn't have a titlebar
192 if(!(*OSFrameStyle & FCF_TITLEBAR)) {
193 *OSFrameStyle &= ~(FCF_MINBUTTON|FCF_MAXBUTTON|FCF_SYSMENU);
194 }
195 return TRUE;
196}
197//******************************************************************************
198//******************************************************************************
199BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
200{
201 if(offset == OSLIB_QWL_USER)
202 offset = QWL_USER;
203
204 return WinSetWindowULong(hwnd, offset, value);
205}
206//******************************************************************************
207//******************************************************************************
208ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
209{
210 if(offset == OSLIB_QWL_USER)
211 offset = QWL_USER;
212
213 return WinQueryWindowULong(hwnd, offset);
214}
215//******************************************************************************
216//******************************************************************************
217BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
218{
219 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
220}
221//******************************************************************************
222//******************************************************************************
223ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
224{
225 return (ULONG)WinSendMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
226}
227//******************************************************************************
228//******************************************************************************
229//******************************************************************************
230//******************************************************************************
231BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
232{
233 return WinAlarm(hwndDeskTop,flStyle);
234}
235//******************************************************************************
236//******************************************************************************
237APIRET OSLibDosBeep(ULONG freg,ULONG dur)
238{
239 return DosBeep(freg,dur);
240}
241//******************************************************************************
242//******************************************************************************
243HWND OSLibWinQueryFocus(HWND hwndDeskTop)
244{
245 return WinQueryFocus(hwndDeskTop);
246}
247//******************************************************************************
248//******************************************************************************
249HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
250{
251 return WinWindowFromID(hwndParent,id);
252}
253//******************************************************************************
254//******************************************************************************
255BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
256{
257 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? FC_NOLOSEACTIVE : 0);
258}
259//******************************************************************************
260//******************************************************************************
261BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
262{
263 return WinIsChild (hwnd, hwndOf);
264}
265//******************************************************************************
266//******************************************************************************
267ULONG OSLibGetWindowHeight(HWND hwnd)
268{
269 RECTL rect;
270
271 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
272}
273//******************************************************************************
274//******************************************************************************
275LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
276{
277 return WinQuerySysValue(hwndDeskTop,iSysValue);
278}
279//******************************************************************************
280//******************************************************************************
281ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
282{
283 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
284}
285//******************************************************************************
286//******************************************************************************
287BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
288{
289 return WinSetDlgItemText(hwndDlg,idItem,pszText);
290}
291//******************************************************************************
292//******************************************************************************
293BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
294{
295 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
296}
297//******************************************************************************
298//******************************************************************************
299HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
300{
301 return WinQueryWindow(hwnd, lCode);
302}
303//******************************************************************************
304//******************************************************************************
305BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
306 LONG cy, ULONG fl)
307{
308 HWND hwndParent = hwndInsertBehind;
309 BOOL rc;
310
311 if(fl & SWP_MOVE) {
312 switch(hwndParent)
313 {
314 case HWNDOS_TOP:
315 case HWNDOS_BOTTOM:
316 hwndParent = HWND_DESKTOP;
317 break;
318 }
319 y = MapOS2ToWin32Y(hwndParent, cy, y);
320 }
321 rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
322 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
323 return rc;
324}
325//******************************************************************************
326//******************************************************************************
327BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
328{
329 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
330}
331//******************************************************************************
332//******************************************************************************
333BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
334{
335 BOOL rc = 1;
336
337 if(fl & SWP_SHOW) {
338 rc = WinShowWindow(hwnd, TRUE);
339 }
340 if(rc == 0)
341 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
342 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
343 if(rc == 0)
344 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
345 return rc;
346}
347//******************************************************************************
348//******************************************************************************
349BOOL OSLibWinDestroyWindow(HWND hwnd)
350{
351 return WinDestroyWindow(hwnd);
352}
353//******************************************************************************
354//******************************************************************************
355BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
356{
357 BOOL rc;
358 RECTLOS2 rectl;
359
360 rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
361 if(rc) {
362 if(RelativeTo == RELATIVE_TO_SCREEN) {
363 MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
364 }
365 else MapOS2ToWin32Rectl(&rectl, pRect);
366 }
367 else memset(pRect, 0, sizeof(RECT));
368 return rc;
369}
370//******************************************************************************
371//******************************************************************************
372BOOL OSLibWinIsIconic(HWND hwnd)
373{
374 SWP swp;
375 BOOL rc;
376
377 rc = WinQueryWindowPos(hwnd, &swp);
378 if(rc == FALSE) {
379 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
380 return FALSE;
381 }
382
383 if(swp.fl & SWP_MINIMIZE)
384 return TRUE;
385 else return FALSE;
386}
387//******************************************************************************
388//******************************************************************************
389BOOL OSLibWinSetActiveWindow(HWND hwnd)
390{
391 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
392}
393//******************************************************************************
394//******************************************************************************
395BOOL OSLibWinSetFocus(HWND hwnd)
396{
397 return WinSetFocus(HWND_DESKTOP, hwnd);
398}
399//******************************************************************************
400//******************************************************************************
401BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
402{
403 return WinEnableWindow(hwnd, fEnable);
404}
405//******************************************************************************
406//******************************************************************************
407BOOL OSLibWinIsWindowEnabled(HWND hwnd)
408{
409 return WinIsWindowEnabled(hwnd);
410}
411//******************************************************************************
412//******************************************************************************
413BOOL OSLibWinIsWindowVisible(HWND hwnd)
414{
415 return WinIsWindowVisible(hwnd);
416}
417//******************************************************************************
418//******************************************************************************
419BOOL OSLibWinQueryActiveWindow()
420{
421 return WinQueryActiveWindow(HWND_DESKTOP);
422}
423//******************************************************************************
424//******************************************************************************
425LONG OSLibWinQueryWindowTextLength(HWND hwnd)
426{
427 return WinQueryWindowTextLength(hwnd);
428}
429//******************************************************************************
430//******************************************************************************
431LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
432{
433 return WinQueryWindowText(hwnd, length, lpsz);
434}
435//******************************************************************************
436//******************************************************************************
437BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
438{
439 return WinSetWindowText(hwnd, lpsz);
440}
441//******************************************************************************
442//******************************************************************************
443BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
444{
445 return WinFlashWindow(hwnd, fFlash);
446}
447//******************************************************************************
448//******************************************************************************
449HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
450{
451 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
452}
453//******************************************************************************
454//******************************************************************************
455BOOL OSLibWinMinimizeWindow(HWND hwnd)
456{
457 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
458}
459//******************************************************************************
460//******************************************************************************
461BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
462{
463 pointl->x = 0;
464 pointl->y = 0;
465 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
466}
467//******************************************************************************
468//******************************************************************************
469BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
470{
471 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
472}
473//******************************************************************************
474//******************************************************************************
475BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
476{
477 return WinQueryWindowPos(hwnd, pswp);
478}
479//******************************************************************************
480//******************************************************************************
481void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
482{
483 HWND hWindow = pswp->hwnd;
484 HWND hWndInsertAfter = pswp->hwndInsertBehind;
485 long x = pswp->x;
486 long y = pswp->y;
487 long cx = pswp->cx;
488 long cy = pswp->cy;
489 UINT fuFlags = (UINT)pswp->fl;
490 ULONG parentHeight;
491
492 HWND hWinAfter;
493 ULONG flags = 0;
494 SWP swpFrame, swpClient;
495 POINTL point;
496
497 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
498
499 if (hWndInsertAfter == HWND_TOP)
500 hWinAfter = HWND_TOP_W;
501 else if (hWndInsertAfter == HWND_BOTTOM)
502 hWinAfter = HWND_BOTTOM_W;
503 else
504 hWinAfter = (HWND) hWndInsertAfter;
505
506 //***********************************
507 // convert PM flags to Windows flags
508 //***********************************
509 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
510 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
511 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
512 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
513 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
514 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
515 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
516 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
517
518 WinQueryWindowPos(hFrame, &swpFrame);
519
520 if(fuFlags & (SWP_MOVE | SWP_SIZE))
521 {
522 point.x = swpFrame.x;
523 point.y = swpFrame.y;
524 if(hParent)
525 {
526 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
527 }
528 point.y = OSLibQueryScreenHeight() - point.y - swpFrame.cy;
529
530 cy = swpFrame.cy;
531 cx = swpFrame.cx;
532 x = point.x;
533 y = point.y;
534
535 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
536 flags |= SWP_NOMOVE_W;
537
538 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
539 flags |= SWP_NOSIZE_W;
540
541 if (fuFlags & SWP_SIZE)
542 {
543 if (pswp->cy != pswpOld->cy)
544 {
545 flags &= ~SWP_NOMOVE_W;
546 }
547 }
548 }
549
550 pswpOld->x = pswp->x;
551 pswpOld->y = swpFrame.cy - pswp->y - pswp->cy;
552 pswpOld->cx = pswp->cx;
553 pswpOld->cy = pswp->cy;
554
555 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
556 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
557
558 pwpos->flags = (UINT)flags;
559 pwpos->cy = cy;
560 pwpos->cx = cx;
561 pwpos->x = x;
562 pwpos->y = y;
563 pwpos->hwndInsertAfter = hWinAfter;
564 pwpos->hwnd = hWindow;
565}
566//******************************************************************************
567//******************************************************************************
568void OSLibMapSWPtoWINDOWPOSFrame(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
569{
570 HWND hWindow = pswp->hwnd;
571 HWND hWndInsertAfter = pswp->hwndInsertBehind;
572 long x = pswp->x;
573 long y = pswp->y;
574 long cx = pswp->cx;
575 long cy = pswp->cy;
576 UINT fuFlags = (UINT)pswp->fl;
577 ULONG parentHeight;
578
579 HWND hWinAfter;
580 ULONG flags = 0;
581 SWP swpClient;
582 POINTL point;
583
584 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
585
586 if (hWndInsertAfter == HWND_TOP)
587 hWinAfter = HWND_TOP_W;
588 else if (hWndInsertAfter == HWND_BOTTOM)
589 hWinAfter = HWND_BOTTOM_W;
590 else
591 hWinAfter = (HWND) hWndInsertAfter;
592
593 //***********************************
594 // convert PM flags to Windows flags
595 //***********************************
596 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
597 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
598 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
599 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
600 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
601 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
602 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
603 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
604
605 WinQueryWindowPos(WinWindowFromID(hFrame, FID_CLIENT), &swpClient);
606
607 if(fuFlags & (SWP_MOVE | SWP_SIZE))
608 {
609 point.x = x;
610 point.y = y;
611 if(hParent)
612 {
613 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
614 }
615 point.y = OSLibQueryScreenHeight() - point.y - cy;
616
617 x = point.x;
618 y = point.y;
619
620 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
621 flags |= SWP_NOMOVE_W;
622
623 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
624 flags |= SWP_NOSIZE_W;
625
626 if (fuFlags & SWP_SIZE)
627 {
628 if (pswp->cy != pswpOld->cy)
629 {
630 flags &= ~SWP_NOMOVE_W;
631 }
632 }
633 }
634
635 pswpOld->x = swpClient.x;
636 pswpOld->y = pswp->cy - swpClient.y - swpClient.cy;
637 pswpOld->cx = swpClient.cx;
638 pswpOld->cy = swpClient.cy;
639
640 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
641 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
642
643 pwpos->flags = (UINT)flags;
644 pwpos->cy = cy;
645 pwpos->cx = cx;
646 pwpos->x = x;
647 pwpos->y = y;
648 pwpos->hwndInsertAfter = hWinAfter;
649 pwpos->hwnd = hWindow;
650}
651//******************************************************************************
652//******************************************************************************
653void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
654{
655 BOOL fCvt = FALSE;
656
657 HWND hWnd = pwpos->hwnd;
658 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
659 long x = pwpos->x;
660 long y = pwpos->y;
661 long cx = pwpos->cx;
662 long cy = pwpos->cy;
663 UINT fuFlags = pwpos->flags;
664 ULONG parentHeight;
665
666 HWND hWinAfter;
667 ULONG flags = 0;
668 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
669
670 if (hWndInsertAfter == HWND_TOPMOST_W)
671// hWinAfter = HWND_TOPMOST;
672 hWinAfter = HWND_TOP;
673 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
674// hWinAfter = HWND_NOTOPMOST;
675 hWinAfter = HWND_TOP;
676 else if (hWndInsertAfter == HWND_TOP_W)
677 hWinAfter = HWND_TOP;
678 else if (hWndInsertAfter == HWND_BOTTOM_W)
679 hWinAfter = HWND_BOTTOM;
680 else
681 hWinAfter = (HWND) hWndInsertAfter;
682
683 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
684 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
685 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
686 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
687 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
688 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
689 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
690 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
691
692 if (flags & (SWP_MOVE | SWP_SIZE))
693 {
694 if (hParent == NULLHANDLE)
695 parentHeight = ScreenHeight;
696 else
697 parentHeight = OSLibGetWindowHeight(hParent);
698
699 if ((flags & SWP_MOVE) == 0)
700 {
701 x = pswpOld->x;
702 y = pswpOld->y;
703
704 if (!((y == 0) && (pswpOld->cy == 0)))
705 {
706 y = parentHeight - y - pswpOld->cy;
707 }
708 }
709
710 if (flags & SWP_SIZE)
711 {
712 if (cy != pswpOld->cy)
713 flags |= SWP_MOVE;
714 }
715 else
716 {
717 cx = pswpOld->cx;
718 cy = pswpOld->cy;
719 }
720 y = parentHeight - y - cy;
721
722
723 if ((pswpOld->x == x) && (pswpOld->y == y))
724 flags &= ~SWP_MOVE;
725
726 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
727 flags &= ~SWP_SIZE;
728 }
729
730 pswp->fl = flags;
731 pswp->cy = cy;
732 pswp->cx = cx;
733 pswp->x = x;
734 pswp->y = y;
735 pswp->hwndInsertBehind = hWinAfter;
736 pswp->hwnd = hWindow;
737 pswp->ulReserved1 = 0;
738 pswp->ulReserved2 = 0;
739}
740//******************************************************************************
741//Position in screen coordinates
742//******************************************************************************
743void OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
744{
745 BOOL fCvt = FALSE;
746
747 HWND hWnd = pwpos->hwnd;
748 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
749 long x = pwpos->x;
750 long y = pwpos->y;
751 long cx = pwpos->cx;
752 long cy = pwpos->cy;
753 UINT fuFlags = pwpos->flags;
754 ULONG parentHeight;
755 POINTL point;
756
757 HWND hWinAfter;
758 ULONG flags = 0;
759 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
760
761 if (hWndInsertAfter == HWND_TOPMOST_W)
762// hWinAfter = HWND_TOPMOST;
763 hWinAfter = HWND_TOP;
764 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
765// hWinAfter = HWND_NOTOPMOST;
766 hWinAfter = HWND_TOP;
767 else if (hWndInsertAfter == HWND_TOP_W)
768 hWinAfter = HWND_TOP;
769 else if (hWndInsertAfter == HWND_BOTTOM_W)
770 hWinAfter = HWND_BOTTOM;
771 else
772 hWinAfter = (HWND) hWndInsertAfter;
773
774 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
775 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
776 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
777 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
778 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
779 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
780 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
781 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
782
783 if (flags & (SWP_MOVE | SWP_SIZE))
784 {
785 point.x = x;
786 point.y = y;
787
788 if(hParent) {
789 parentHeight = OSLibGetWindowHeight(hParent);
790
791 point.y = ScreenHeight - point.y - cy;
792 WinMapWindowPoints(HWND_DESKTOP, hParent, &point, 1);
793 point.y = parentHeight - point.y - cy;
794 }
795 else parentHeight = ScreenHeight;
796
797 x = point.x;
798 y = point.y;
799
800 if (flags & SWP_SIZE)
801 {
802 if (cy != pswpOld->cy)
803 flags |= SWP_MOVE;
804 }
805 else
806 {
807 cx = pswpOld->cx;
808 cy = pswpOld->cy;
809 }
810 y = parentHeight - y - cy;
811
812
813 if ((pswpOld->x == x) && (pswpOld->y == y))
814 flags &= ~SWP_MOVE;
815
816 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
817 flags &= ~SWP_SIZE;
818 }
819
820 pswp->fl = flags;
821 pswp->cy = cy;
822 pswp->cx = cx;
823 pswp->x = x;
824 pswp->y = y;
825 pswp->hwndInsertBehind = hWinAfter;
826 pswp->hwnd = hWindow;
827 pswp->ulReserved1 = 0;
828 pswp->ulReserved2 = 0;
829}
830//******************************************************************************
831//******************************************************************************
832BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
833{
834 BOOL rc;
835
836 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
837
838 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
839 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
840
841 return rc;
842}
843//******************************************************************************
844//******************************************************************************
845BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
846{
847 TRACKINFO tinfo;
848
849 memset(&tinfo, 0, sizeof(TRACKINFO));
850 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
851
852 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
853 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
854 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
855 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
856 return TRUE;
857}
858//******************************************************************************
859//******************************************************************************
860HWND OSLibWinBeginEnumWindows(HWND hwnd)
861{
862 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
863 else
864 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
865
866 return WinBeginEnumWindows(hwnd);
867}
868//******************************************************************************
869//******************************************************************************
870HWND OSLibWinGetNextWindow(HWND hwndEnum)
871{
872 return WinGetNextWindow(hwndEnum);
873}
874//******************************************************************************
875//******************************************************************************
876HWND OSLibWinQueryClientWindow(HWND hwndFrame)
877{
878 HWND hwndClient = 0;
879
880 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
881 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
882
883 return hwndClient;
884}
885//******************************************************************************
886//******************************************************************************
887BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
888{
889 return WinEndEnumWindows(hwndEnum);
890}
891//******************************************************************************
892//******************************************************************************
893BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
894{
895 return WinQueryWindowProcess(hwnd, pid, tid);
896}
897//******************************************************************************
898//******************************************************************************
899BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
900{
901 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
902}
903//******************************************************************************
904//******************************************************************************
905BOOL OSLibWinEnableScrollBar(HWND hwndParent, int scrollBar, BOOL fEnable)
906{
907 HWND hwndScroll;
908
909 if(scrollBar == OSLIB_VSCROLL) {
910 hwndScroll = WinWindowFromID(hwndParent, FID_VERTSCROLL);
911 }
912 else hwndScroll = WinWindowFromID(hwndParent, FID_HORZSCROLL);
913
914 if(hwndScroll == NULL)
915 return FALSE;
916
917 return WinEnableWindow(hwndScroll, fEnable);
918}
919//******************************************************************************
920//******************************************************************************
921BOOL OSLibWinShowScrollBar(HWND hwndParent, HWND hwndScroll, int scrollBar,
922 BOOL fShow, BOOL fForceChange)
923{
924 if(hwndScroll == NULL) {
925 dprintf(("OSLibWinShowScrollBar: scrollbar %d (parent %x) not found!", scrollBar, hwndParent));
926 return FALSE;
927 }
928
929 if(fShow != WinIsWindowVisible(hwndScroll) || fForceChange)
930 {
931 WinSetParent(hwndScroll, fShow ? hwndParent : HWND_OBJECT, FALSE);
932 WinSendMsg(hwndParent, WM_UPDATEFRAME,
933 MPFROMLONG( ( scrollBar == OSLIB_VSCROLL ) ? FCF_VERTSCROLL
934 : FCF_HORZSCROLL),
935 MPVOID );
936
937 WinShowWindow(hwndScroll, fShow);
938 }
939 return TRUE;
940}
941//******************************************************************************
942//******************************************************************************
943HWND OSLibWinQueryScrollBarHandle(HWND hwndParent, int scrollBar)
944{
945 if(scrollBar == OSLIB_VSCROLL) {
946 return WinWindowFromID(hwndParent, FID_VERTSCROLL);
947 }
948 else return WinWindowFromID(hwndParent, FID_HORZSCROLL);
949}
950//******************************************************************************
951//******************************************************************************
952ULONG OSLibWinGetScrollPos(HWND hwndParent, HWND hwndScroll)
953{
954 if(hwndScroll == NULL)
955 return 0;
956
957 return (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
958}
959//******************************************************************************
960//******************************************************************************
961ULONG OSLibWinSetScrollPos(HWND hwndParent, HWND hwndScroll, int pos, int fRedraw)
962{
963 ULONG oldPos;
964
965 if(hwndScroll == NULL)
966 return 0;
967
968 oldPos = (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
969
970 if(WinSendMsg(hwndScroll, SBM_SETPOS, MPFROMSHORT(pos), MPFROMLONG(fRedraw)) == FALSE)
971 return 0;
972
973 return oldPos;
974}
975//******************************************************************************
976//******************************************************************************
977BOOL OSLibWinSetScrollRange(HWND hwndParent, HWND hwndScroll, int minpos,
978 int maxpos, int fRedraw)
979{
980 if(hwndScroll == NULL)
981 return 0;
982
983 return (BOOL)WinSendMsg( hwndScroll, SBM_SETSCROLLBAR,
984 MPFROMLONG(WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0)),
985 MPFROM2SHORT( minpos ,maxpos ) );
986}
987//******************************************************************************
988//******************************************************************************
989BOOL OSLibWinSetScrollPageSize(HWND hwndParent, HWND hwndScroll, int pagesize,
990 int totalsize, int fRedraw)
991{
992 if(hwndScroll == NULL)
993 return 0;
994
995 return (BOOL)WinSendMsg( hwndScroll, SBM_SETTHUMBSIZE,
996 MPFROM2SHORT(pagesize, totalsize),
997 0);
998}
999//******************************************************************************
1000//******************************************************************************
1001void OSLibTranslateScrollCmdAndMsg(ULONG *msg, ULONG *scrollcmd)
1002{
1003 switch(*scrollcmd)
1004 {
1005 case SB_LINEUP:
1006 *scrollcmd = SB_LINEUP_W;
1007 break;
1008 case SB_LINEDOWN:
1009 *scrollcmd = SB_LINEDOWN_W;
1010 break;
1011 case SB_PAGEUP:
1012 *scrollcmd = SB_PAGEUP_W;
1013 break;
1014 case SB_PAGEDOWN:
1015 *scrollcmd = SB_PAGEDOWN_W;
1016 break;
1017 case SB_SLIDERTRACK:
1018 *scrollcmd = SB_THUMBTRACK_W;
1019 break;
1020 case SB_SLIDERPOSITION:
1021 *scrollcmd = SB_THUMBPOSITION_W;
1022 break;
1023 case SB_ENDSCROLL:
1024 *scrollcmd = SB_ENDSCROLL_W;
1025 break;
1026 }
1027 *msg = (*msg == WM_HSCROLL) ? WM_HSCROLL_W : WM_VSCROLL_W;
1028 return;
1029}
1030//******************************************************************************
1031//******************************************************************************
1032void OSLibSetWindowStyle(HWND hwnd, ULONG dwStyle)
1033{
1034 ULONG OSWinStyle, OSFrameStyle, borderWidth, borderHeight,dwExStyle;
1035
1036 OSLibWinConvertStyle(dwStyle, &dwExStyle, &OSWinStyle, &OSFrameStyle, &borderWidth, &borderHeight);
1037
1038 OSWinStyle = OSWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPCHILDREN);
1039
1040 WinSetWindowULong(hwnd, QWL_STYLE,
1041 (WinQueryWindowULong(hwnd, QWL_STYLE) & ~0xffff0000) |
1042 OSWinStyle);
1043
1044 //CB: bug: it doesn't work with child windows!
1045
1046 if(OSFrameStyle != 0) // maybe WinQueryClassName == WC_FRAME is better
1047 {
1048 if(OSFrameStyle & FCF_TITLEBAR)
1049 {
1050 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_TITLEBAR), hwnd, FALSE);
1051 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MENU), hwnd, FALSE);
1052 }
1053 else
1054 {
1055 WinSetParent(WinWindowFromID(hwnd, FID_TITLEBAR), HWND_OBJECT, FALSE);
1056 WinSetParent(WinWindowFromID(hwnd, FID_MENU), HWND_OBJECT, FALSE);
1057 }
1058 if(OSFrameStyle & FCF_SYSMENU)
1059 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_SYSMENU), hwnd, FALSE);
1060 else
1061 WinSetParent(WinWindowFromID(hwnd, FID_SYSMENU), HWND_OBJECT, FALSE);
1062
1063 if(OSFrameStyle & FCF_MINBUTTON | OSFrameStyle & FCF_MAXBUTTON)
1064 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MINMAX), hwnd, FALSE);
1065 else
1066 WinSetParent(WinWindowFromID(hwnd, FID_MINMAX), HWND_OBJECT, FALSE);
1067
1068 if(OSFrameStyle & FCF_VERTSCROLL)
1069 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_VERTSCROLL), hwnd, FALSE);
1070 else
1071 WinSetParent(WinWindowFromID(hwnd, FID_VERTSCROLL), HWND_OBJECT, FALSE);
1072
1073 if(OSFrameStyle & FCF_HORZSCROLL)
1074 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_HORZSCROLL), hwnd, FALSE);
1075 else
1076 WinSetParent(WinWindowFromID(hwnd, FID_HORZSCROLL), HWND_OBJECT, FALSE);
1077
1078 WinSendMsg(hwnd, WM_UPDATEFRAME,
1079 MPFROMLONG(FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
1080 FCF_MENU | FCF_VERTSCROLL | FCF_HORZSCROLL),
1081 MPVOID);
1082 }
1083}
1084//******************************************************************************
1085//******************************************************************************
1086HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
1087{
1088 HWND hwndNext, hwndFound=0;
1089 HENUM henum;
1090
1091 henum = WinBeginEnumWindows(HWND_OBJECT);
1092 while ((hwndNext = WinGetNextWindow(henum)) != 0)
1093 {
1094 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
1095 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
1096 {
1097 hwndFound = hwndNext;
1098 break;
1099 }
1100 }
1101 WinEndEnumWindows(henum);
1102 return hwndFound;
1103}
1104//******************************************************************************
1105//******************************************************************************
1106BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
1107{
1108 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
1109 return WinSetWindowULong(hwnd, QWS_ID, value);
1110}
1111//******************************************************************************
1112//******************************************************************************
1113PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
1114{
1115 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
1116}
1117//******************************************************************************
1118//******************************************************************************
1119BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
1120{
1121 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
1122
1123 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
1124 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
1125 (pRect->bottom - pRect->top)));
1126 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
1127 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
1128 return TRUE;
1129}
1130//******************************************************************************
1131//******************************************************************************
1132BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
1133{
1134 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
1135
1136 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
1137 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
1138 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
1139 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
1140 return TRUE;
1141}
1142//******************************************************************************
1143//******************************************************************************
Note: See TracBrowser for help on using the repository browser.