source: trunk/src/user32/new/oslibwin.cpp@ 2437

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

MsgFormat bugfix

File size: 34.7 KB
Line 
1/* $Id: oslibwin.cpp,v 1.37 2000-01-14 14:45:16 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//******************************************************************************
30//******************************************************************************
31BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
32{
33 if(hwndParent == OSLIB_HWND_DESKTOP)
34 {
35 hwndParent = HWND_DESKTOP;
36 }
37 else
38 if(hwndParent == OSLIB_HWND_OBJECT) {
39 hwndParent = HWND_OBJECT;
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,
52 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame,
53 ULONG id, BOOL fTaskList)
54{
55 HWND hwndClient;
56
57 dprintf(("WinCreateWindow %x %s", hwndParent, 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 ULONG dwClientStyle = 0;
69 ULONG dwFrameStyle = 0;
70#if 1
71
72 BOOL TopLevel = hwndParent == HWND_DESKTOP;
73
74 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
75
76 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPSIBLINGS);
77
78 dwFrameStyle |= FCF_NOBYTEALIGN;
79 if(fTaskList)
80 {
81 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER;
82 }
83
84 dwWinStyle &= ~WS_CLIPCHILDREN;
85 FCData.flCreateFlags = dwFrameStyle;
86
87 *hwndFrame = WinCreateWindow (hwndParent,
88 TopLevel ? WC_FRAME : WIN32_INNERFRAME,
89 pszName, dwWinStyle, 0, 0, 0, 0,
90 hwndParent, HWND_TOP,
91 id, &FCData, NULL);
92
93 if (*hwndFrame) {
94 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
95 NULL, dwClientStyle, 0, 0, 0, 0,
96 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
97 return hwndClient;
98 }
99 dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
100 return 0;
101#else
102 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
103
104 dwFrameStyle |= FCF_NOBYTEALIGN;
105 if ((hwndParent == HWND_DESKTOP) && (dwFrameStyle & FCF_TITLEBAR))
106 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER;
107
108 dwWinStyle &= ~WS_CLIPCHILDREN;
109
110 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
111 &dwFrameStyle, WIN32_STDCLASS,
112 "", dwClientStyle, 0, id, &hwndClient);
113 if(*hwndFrame) {
114 if(pszName) {
115 WinSetWindowText(*hwndFrame, pszName);
116 }
117 return hwndClient;
118 }
119 dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
120 return 0;
121#endif
122}
123//******************************************************************************
124//******************************************************************************
125BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle, ULONG *borderWidth, ULONG *borderHeight)
126{
127 *OSWinStyle = 0;
128 *OSFrameStyle = 0;
129 *borderWidth = 0;
130 *borderHeight = 0;
131
132 /* Window styles */
133 if(dwStyle & WS_MINIMIZE_W)
134 *OSWinStyle |= WS_MINIMIZED;
135//Done explicitely in CreateWindowExA
136#if 1
137 if(dwStyle & WS_VISIBLE_W)
138 *OSWinStyle |= WS_VISIBLE;
139#endif
140 if(dwStyle & WS_DISABLED_W)
141 *OSWinStyle |= WS_DISABLED;
142 if(dwStyle & WS_CLIPSIBLINGS_W)
143 *OSWinStyle |= WS_CLIPSIBLINGS;
144 if(dwStyle & WS_CLIPCHILDREN_W)
145 *OSWinStyle |= WS_CLIPCHILDREN;
146 if(dwStyle & WS_MAXIMIZE_W)
147 *OSWinStyle |= WS_MAXIMIZED;
148 if(dwStyle & WS_GROUP_W)
149 *OSWinStyle |= WS_GROUP;
150 if(dwStyle & WS_TABSTOP_W)
151 *OSWinStyle |= WS_TABSTOP;
152
153 if(dwStyle & WS_CHILD_W && !((dwStyle & WS_CAPTION_W) == WS_CAPTION_W))
154 {
155//SvL: Causes crash in VPBuddy if enabled -> find bug
156#if 0
157 if (!HAS_3DFRAME(*dwExStyle) && (dwStyle & (WS_DLGFRAME_W | WS_THICKFRAME_W))) *dwExStyle |= WS_EX_DLGMODALFRAME_W;
158#endif
159
160 if (*dwExStyle & WS_EX_CLIENTEDGE_W)
161 {
162 *OSFrameStyle |= FCF_SIZEBORDER;
163 *borderHeight = *borderWidth = 2;
164 }
165 else
166 if (*dwExStyle & WS_EX_DLGMODALFRAME_W)
167 {
168 *OSFrameStyle |= FCF_SIZEBORDER;
169 *borderHeight = *borderWidth = 3;
170 }
171 else
172 if (*dwExStyle & WS_EX_STATICEDGE_W)
173 {
174 *OSFrameStyle |= FCF_SIZEBORDER;
175 *borderHeight = *borderWidth = 2;
176 }
177 else
178 if(dwStyle & WS_BORDER_W)
179 {
180 *OSFrameStyle |= FCF_BORDER;
181 *borderHeight = *borderWidth = 1;
182 }
183 else if (*dwExStyle & WS_EX_WINDOWEDGE_W); //no border
184
185 if(dwStyle & WS_VSCROLL_W)
186 *OSFrameStyle |= FCF_VERTSCROLL;
187 if(dwStyle & WS_HSCROLL_W)
188 *OSFrameStyle |= FCF_HORZSCROLL;
189 }
190 else
191 {
192 if((dwStyle & WS_CAPTION_W) == WS_DLGFRAME_W)
193 *OSFrameStyle |= FCF_DLGBORDER;
194 else
195 {
196 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
197 *OSFrameStyle |= (FCF_TITLEBAR | FCF_BORDER);
198 else
199 if(dwStyle & WS_BORDER_W)
200 *OSFrameStyle |= FCF_BORDER;
201 }
202
203 if(dwStyle & WS_VSCROLL_W)
204 *OSFrameStyle |= FCF_VERTSCROLL;
205 if(dwStyle & WS_HSCROLL_W)
206 *OSFrameStyle |= FCF_HORZSCROLL;
207
208 if(dwStyle & WS_SYSMENU_W)
209 *OSFrameStyle |= FCF_SYSMENU;
210 if(dwStyle & WS_THICKFRAME_W)
211 *OSFrameStyle |= FCF_SIZEBORDER; //??
212 if(dwStyle & WS_MINIMIZEBOX_W)
213 *OSFrameStyle |= FCF_MINBUTTON;
214 if(dwStyle & WS_MAXIMIZEBOX_W)
215 *OSFrameStyle |= FCF_MAXBUTTON;
216
217 if(*dwExStyle & WS_EX_DLGMODALFRAME_W)
218 *OSFrameStyle |= FCF_DLGBORDER;
219 }
220
221 //Clear certain frame bits when the window doesn't have a titlebar
222 if(!(*OSFrameStyle & FCF_TITLEBAR)) {
223 *OSFrameStyle &= ~(FCF_MINBUTTON|FCF_MAXBUTTON|FCF_SYSMENU);
224 }
225 return TRUE;
226}
227//******************************************************************************
228//******************************************************************************
229BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
230{
231 if(offset == OSLIB_QWL_USER)
232 offset = QWL_USER;
233
234 return WinSetWindowULong(hwnd, offset, value);
235}
236//******************************************************************************
237//******************************************************************************
238ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
239{
240 if(offset == OSLIB_QWL_USER)
241 offset = QWL_USER;
242
243 return WinQueryWindowULong(hwnd, offset);
244}
245//******************************************************************************
246//******************************************************************************
247BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
248{
249 return WinAlarm(hwndDeskTop,flStyle);
250}
251//******************************************************************************
252//******************************************************************************
253APIRET OSLibDosBeep(ULONG freg,ULONG dur)
254{
255 return DosBeep(freg,dur);
256}
257//******************************************************************************
258//******************************************************************************
259HWND OSLibWinQueryFocus(HWND hwndDeskTop)
260{
261 return WinQueryFocus(hwndDeskTop);
262}
263//******************************************************************************
264//******************************************************************************
265HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
266{
267 return WinWindowFromID(hwndParent,id);
268}
269//******************************************************************************
270//******************************************************************************
271BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
272{
273 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? FC_NOLOSEACTIVE : 0);
274}
275//******************************************************************************
276//******************************************************************************
277BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
278{
279 return WinIsChild (hwnd, hwndOf);
280}
281//******************************************************************************
282//******************************************************************************
283ULONG OSLibGetWindowHeight(HWND hwnd)
284{
285 RECTL rect;
286
287 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
288}
289//******************************************************************************
290//******************************************************************************
291LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
292{
293 return WinQuerySysValue(hwndDeskTop,iSysValue);
294}
295//******************************************************************************
296//******************************************************************************
297ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
298{
299 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
300}
301//******************************************************************************
302//******************************************************************************
303BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
304{
305 return WinSetDlgItemText(hwndDlg,idItem,pszText);
306}
307//******************************************************************************
308//******************************************************************************
309BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
310{
311 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
312}
313//******************************************************************************
314//******************************************************************************
315HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
316{
317 return WinQueryWindow(hwnd, lCode);
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, 0, 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 mapOS2ToWin32Rect(hwnd,OSLIB_HWND_DESKTOP,&rectl,pRect);
358 }
359 else mapOS2ToWin32Rect(hwnd,&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 BOOL rc;
398 HWND hwndClient;
399
400 rc = WinEnableWindow(hwnd, fEnable);
401 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
402 if(hwndClient) {
403 WinEnableWindow(hwndClient, fEnable);
404 }
405 return rc;
406}
407//******************************************************************************
408//******************************************************************************
409BOOL OSLibWinIsWindowEnabled(HWND hwnd)
410{
411 return WinIsWindowEnabled(hwnd);
412}
413//******************************************************************************
414//******************************************************************************
415BOOL OSLibWinIsWindowVisible(HWND hwnd)
416{
417 return WinIsWindowVisible(hwnd);
418}
419//******************************************************************************
420//******************************************************************************
421BOOL OSLibWinQueryActiveWindow()
422{
423 return WinQueryActiveWindow(HWND_DESKTOP);
424}
425//******************************************************************************
426//******************************************************************************
427LONG OSLibWinQueryWindowTextLength(HWND hwnd)
428{
429 return WinQueryWindowTextLength(hwnd);
430}
431//******************************************************************************
432//******************************************************************************
433LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
434{
435 return WinQueryWindowText(hwnd, length, lpsz);
436}
437//******************************************************************************
438//******************************************************************************
439BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
440{
441 return WinSetWindowText(hwnd, lpsz);
442}
443//******************************************************************************
444//******************************************************************************
445BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
446{
447 return WinFlashWindow(hwnd, fFlash);
448}
449//******************************************************************************
450//******************************************************************************
451HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
452{
453 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
454}
455//******************************************************************************
456//******************************************************************************
457BOOL OSLibWinMinimizeWindow(HWND hwnd)
458{
459 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
460}
461//******************************************************************************
462//******************************************************************************
463BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
464{
465 pointl->x = 0;
466 pointl->y = 0;
467 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
468}
469//******************************************************************************
470//******************************************************************************
471BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
472{
473 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
474}
475//******************************************************************************
476//******************************************************************************
477BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
478{
479 return WinQueryWindowPos(hwnd, pswp);
480}
481//******************************************************************************
482//******************************************************************************
483void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
484{
485 HWND hWindow = pswp->hwnd;
486 HWND hWndInsertAfter = pswp->hwndInsertBehind;
487 long x = pswp->x;
488 long y = pswp->y;
489 long cx = pswp->cx;
490 long cy = pswp->cy;
491 UINT fuFlags = (UINT)pswp->fl;
492 ULONG parentHeight;
493
494 HWND hWinAfter;
495 ULONG flags = 0;
496 SWP swpFrame, swpClient;
497 POINTL point;
498
499 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
500
501 if (hWndInsertAfter == HWND_TOP)
502 hWinAfter = HWND_TOP_W;
503 else if (hWndInsertAfter == HWND_BOTTOM)
504 hWinAfter = HWND_BOTTOM_W;
505 else
506 hWinAfter = (HWND) hWndInsertAfter;
507
508 //***********************************
509 // convert PM flags to Windows flags
510 //***********************************
511 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
512 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
513 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
514 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
515 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
516 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
517 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
518 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
519
520 WinQueryWindowPos(hFrame, &swpFrame);
521
522 if(fuFlags & (SWP_MOVE | SWP_SIZE))
523 {
524 point.x = swpFrame.x;
525 point.y = swpFrame.y;
526 if(hParent)
527 {
528 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
529 }
530 point.y = ScreenHeight-point.y-swpFrame.cy;
531
532 cy = swpFrame.cy;
533 cx = swpFrame.cx;
534 x = point.x;
535 y = point.y;
536
537 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
538 flags |= SWP_NOMOVE_W;
539
540 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
541 flags |= SWP_NOSIZE_W;
542
543 if (fuFlags & SWP_SIZE)
544 {
545 if (pswp->cy != pswpOld->cy)
546 {
547 flags &= ~SWP_NOMOVE_W;
548 }
549 }
550 }
551
552 pswpOld->x = pswp->x;
553 pswpOld->y = swpFrame.cy-pswp->y-pswp->cy;
554 pswpOld->cx = pswp->cx;
555 pswpOld->cy = pswp->cy;
556
557 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
558 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
559
560 pwpos->flags = (UINT)flags;
561 pwpos->cy = cy;
562 pwpos->cx = cx;
563 pwpos->x = x;
564 pwpos->y = y;
565 pwpos->hwndInsertAfter = hWinAfter;
566 pwpos->hwnd = hWindow;
567}
568//******************************************************************************
569//******************************************************************************
570void OSLibMapSWPtoWINDOWPOSFrame(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
571{
572 HWND hWindow = pswp->hwnd;
573 HWND hWndInsertAfter = pswp->hwndInsertBehind;
574 long x = pswp->x;
575 long y = pswp->y;
576 long cx = pswp->cx;
577 long cy = pswp->cy;
578 UINT fuFlags = (UINT)pswp->fl;
579 ULONG parentHeight;
580
581 HWND hWinAfter;
582 ULONG flags = 0;
583 SWP swpClient;
584 POINTL point;
585
586 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
587
588 if (hWndInsertAfter == HWND_TOP)
589 hWinAfter = HWND_TOP_W;
590 else if (hWndInsertAfter == HWND_BOTTOM)
591 hWinAfter = HWND_BOTTOM_W;
592 else
593 hWinAfter = (HWND) hWndInsertAfter;
594
595 //***********************************
596 // convert PM flags to Windows flags
597 //***********************************
598 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
599 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
600 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
601 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
602 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
603 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
604 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
605 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
606
607 WinQueryWindowPos(WinWindowFromID(hFrame, FID_CLIENT), &swpClient);
608
609 if(fuFlags & (SWP_MOVE | SWP_SIZE))
610 {
611 point.x = x;
612 point.y = y;
613 if(hParent)
614 {
615 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
616 }
617 point.y = ScreenHeight-point.y-cy;
618
619 x = point.x;
620 y = point.y;
621
622 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
623 flags |= SWP_NOMOVE_W;
624
625 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
626 flags |= SWP_NOSIZE_W;
627
628 if (fuFlags & SWP_SIZE)
629 {
630 if (pswp->cy != pswpOld->cy)
631 {
632 flags &= ~SWP_NOMOVE_W;
633 }
634 }
635 }
636
637 pswpOld->x = swpClient.x;
638 pswpOld->y = pswp->cy-swpClient.y-swpClient.cy;
639 pswpOld->cx = swpClient.cx;
640 pswpOld->cy = swpClient.cy;
641
642 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
643 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
644
645 pwpos->flags = (UINT)flags;
646 pwpos->cy = cy;
647 pwpos->cx = cx;
648 pwpos->x = x;
649 pwpos->y = y;
650 pwpos->hwndInsertAfter = hWinAfter;
651 pwpos->hwnd = hWindow;
652}
653//******************************************************************************
654//******************************************************************************
655void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
656{
657 BOOL fCvt = FALSE;
658
659 HWND hWnd = pwpos->hwnd;
660 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
661 long x = pwpos->x;
662 long y = pwpos->y;
663 long cx = pwpos->cx;
664 long cy = pwpos->cy;
665 UINT fuFlags = pwpos->flags;
666 ULONG parentHeight;
667
668 HWND hWinAfter;
669 ULONG flags = 0;
670 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
671
672 if (hWndInsertAfter == HWND_TOPMOST_W)
673// hWinAfter = HWND_TOPMOST;
674 hWinAfter = HWND_TOP;
675 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
676// hWinAfter = HWND_NOTOPMOST;
677 hWinAfter = HWND_TOP;
678 else if (hWndInsertAfter == HWND_TOP_W)
679 hWinAfter = HWND_TOP;
680 else if (hWndInsertAfter == HWND_BOTTOM_W)
681 hWinAfter = HWND_BOTTOM;
682 else
683 hWinAfter = (HWND) hWndInsertAfter;
684
685 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
686 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
687 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
688 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
689 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
690 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
691 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
692 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
693
694 if (flags & (SWP_MOVE | SWP_SIZE))
695 {
696 if (hParent == NULLHANDLE)
697 parentHeight = ScreenHeight;
698 else
699 parentHeight = OSLibGetWindowHeight(hParent);
700
701 if ((flags & SWP_MOVE) == 0)
702 {
703 x = pswpOld->x;
704 y = pswpOld->y;
705
706 if (!((y == 0) && (pswpOld->cy == 0)))
707 {
708 y = parentHeight-y-pswpOld->cy;
709 }
710 }
711
712 if (flags & SWP_SIZE)
713 {
714 if (cy != pswpOld->cy)
715 flags |= SWP_MOVE;
716 }
717 else
718 {
719 cx = pswpOld->cx;
720 cy = pswpOld->cy;
721 }
722 y = parentHeight-y-cy;
723
724
725 if ((pswpOld->x == x) && (pswpOld->y == y))
726 flags &= ~SWP_MOVE;
727
728 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
729 flags &= ~SWP_SIZE;
730 }
731
732 pswp->fl = flags;
733 pswp->cy = cy;
734 pswp->cx = cx;
735 pswp->x = x;
736 pswp->y = y;
737 pswp->hwndInsertBehind = hWinAfter;
738 pswp->hwnd = hWindow;
739 pswp->ulReserved1 = 0;
740 pswp->ulReserved2 = 0;
741}
742//******************************************************************************
743//Position in screen coordinates
744//******************************************************************************
745void OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
746{
747 BOOL fCvt = FALSE;
748
749 HWND hWnd = pwpos->hwnd;
750 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
751 long x = pwpos->x;
752 long y = pwpos->y;
753 long cx = pwpos->cx;
754 long cy = pwpos->cy;
755 UINT fuFlags = pwpos->flags;
756 ULONG parentHeight;
757 POINTL point;
758
759 HWND hWinAfter;
760 ULONG flags = 0;
761 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
762
763 if (hWndInsertAfter == HWND_TOPMOST_W)
764// hWinAfter = HWND_TOPMOST;
765 hWinAfter = HWND_TOP;
766 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
767// hWinAfter = HWND_NOTOPMOST;
768 hWinAfter = HWND_TOP;
769 else if (hWndInsertAfter == HWND_TOP_W)
770 hWinAfter = HWND_TOP;
771 else if (hWndInsertAfter == HWND_BOTTOM_W)
772 hWinAfter = HWND_BOTTOM;
773 else
774 hWinAfter = (HWND) hWndInsertAfter;
775
776 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
777 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
778 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
779 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
780 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
781 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
782 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
783 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
784
785 if (flags & (SWP_MOVE | SWP_SIZE))
786 {
787 point.x = x;
788 point.y = y;
789
790 if(hParent) {
791 parentHeight = OSLibGetWindowHeight(hParent);
792
793 point.y = ScreenHeight-point.y-cy;
794 WinMapWindowPoints(HWND_DESKTOP, hParent, &point, 1);
795 point.y = parentHeight-point.y-cy;
796 }
797 else parentHeight = ScreenHeight;
798
799 x = point.x;
800 y = point.y;
801
802 if (flags & SWP_SIZE)
803 {
804 if (cy != pswpOld->cy)
805 flags |= SWP_MOVE;
806 }
807 else
808 {
809 cx = pswpOld->cx;
810 cy = pswpOld->cy;
811 }
812 y = parentHeight-y-cy;
813
814
815 if ((pswpOld->x == x) && (pswpOld->y == y))
816 flags &= ~SWP_MOVE;
817
818 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
819 flags &= ~SWP_SIZE;
820 }
821
822 pswp->fl = flags;
823 pswp->cy = cy;
824 pswp->cx = cx;
825 pswp->x = x;
826 pswp->y = y;
827 pswp->hwndInsertBehind = hWinAfter;
828 pswp->hwnd = hWindow;
829 pswp->ulReserved1 = 0;
830 pswp->ulReserved2 = 0;
831}
832//******************************************************************************
833//******************************************************************************
834BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
835{
836 BOOL rc;
837
838 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
839
840 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
841 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
842
843 return rc;
844}
845//******************************************************************************
846//******************************************************************************
847BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
848{
849 TRACKINFO tinfo;
850
851 memset(&tinfo, 0, sizeof(TRACKINFO));
852 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
853
854 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
855 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
856 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
857 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
858 return TRUE;
859}
860//******************************************************************************
861//******************************************************************************
862HWND OSLibWinBeginEnumWindows(HWND hwnd)
863{
864 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
865 else
866 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
867
868 return WinBeginEnumWindows(hwnd);
869}
870//******************************************************************************
871//******************************************************************************
872HWND OSLibWinGetNextWindow(HWND hwndEnum)
873{
874 return WinGetNextWindow(hwndEnum);
875}
876//******************************************************************************
877//******************************************************************************
878HWND OSLibWinQueryClientWindow(HWND hwndFrame)
879{
880 HWND hwndClient = 0;
881
882 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
883 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
884
885 return hwndClient;
886}
887//******************************************************************************
888//******************************************************************************
889BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
890{
891 return WinEndEnumWindows(hwndEnum);
892}
893//******************************************************************************
894//******************************************************************************
895BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
896{
897 return WinQueryWindowProcess(hwnd, pid, tid);
898}
899//******************************************************************************
900//******************************************************************************
901BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
902{
903 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
904}
905//******************************************************************************
906//******************************************************************************
907HWND OSLibWinQueryObjectWindow(VOID)
908{
909 return WinQueryObjectWindow(HWND_DESKTOP);
910}
911//******************************************************************************
912//******************************************************************************
913HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
914{
915 HWND hwndNext, hwndFound=0;
916 HENUM henum;
917
918 henum = WinBeginEnumWindows(HWND_OBJECT);
919 while ((hwndNext = WinGetNextWindow(henum)) != 0)
920 {
921 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
922 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
923 {
924 hwndFound = hwndNext;
925 break;
926 }
927 }
928 WinEndEnumWindows(henum);
929 return hwndFound;
930}
931//******************************************************************************
932//******************************************************************************
933BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
934{
935 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
936 return WinSetWindowULong(hwnd, QWS_ID, value);
937}
938//******************************************************************************
939//******************************************************************************
940PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
941{
942 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
943}
944//******************************************************************************
945//******************************************************************************
946BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
947{
948 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
949
950 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
951 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
952 (pRect->bottom - pRect->top)));
953 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
954 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
955 return TRUE;
956}
957//******************************************************************************
958//******************************************************************************
959BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
960{
961 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
962
963 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
964 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
965 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
966 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
967 return TRUE;
968}
969//******************************************************************************
970//******************************************************************************
971BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
972{
973 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, FALSE );
974}
975//******************************************************************************
976//******************************************************************************
977BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
978{
979 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, TRUE );
980}
981//******************************************************************************
982//******************************************************************************
983BOOL OSLibWinEnableWindowUpdate(HWND hwnd,BOOL fEnable)
984{
985 return WinEnableWindowUpdate(hwnd,fEnable);
986}
987//******************************************************************************
988//******************************************************************************
989ULONG OSLibWinGetLastError()
990{
991 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
992}
993//******************************************************************************
994//******************************************************************************
995void OSLibWinShowTaskList(HWND hwndFrame)
996{
997 WinPostMsg(NULLHANDLE, WM_SYSCOMMAND, (MPARAM)SC_TASKMANAGER, MPFROM2SHORT(CMDSRC_MENU, TRUE));
998}
999//******************************************************************************
1000//******************************************************************************
Note: See TracBrowser for help on using the repository browser.