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

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

Combobox + windowpos changes + fixes

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