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

Last change on this file since 628 was 628, checked in by dengert, 26 years ago

create windows with correct parent and z-order.

File size: 13.8 KB
Line 
1/* $Id: oslibwin.cpp,v 1.23 1999-08-22 18:29:37 dengert Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_WIN
13#define INCL_PM
14#include <os2.h>
15#include <os2wrap.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <misc.h>
20#include <winconst.h>
21#include "oslibwin.h"
22#include "oslibutil.h"
23#include "oslibmsg.h"
24#include "oslibgdi.h"
25#include "pmwindow.h"
26
27//******************************************************************************
28//******************************************************************************
29BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
30{
31 if(hwndParent == OSLIB_HWND_DESKTOP)
32 {
33 hwndParent = HWND_DESKTOP;
34 }
35
36 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
37}
38//******************************************************************************
39//******************************************************************************
40HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
41 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
42{
43 HWND hwndClient;
44
45 dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
46
47 if(pszName && *pszName == 0) {
48 pszName = NULL;
49 }
50 if(hwndParent == OSLIB_HWND_DESKTOP) {
51 hwndParent = HWND_DESKTOP;
52 }
53 if(Owner == OSLIB_HWND_DESKTOP) {
54 Owner = HWND_DESKTOP;
55 }
56
57 if(dwFrameStyle) {
58 ULONG dwClientStyle;
59
60 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
61 if(pszName)
62 dwFrameStyle |= FCF_TITLEBAR;
63
64 dwFrameStyle |= FCF_TASKLIST;
65 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
66 &dwFrameStyle, WIN32_STDCLASS,
67 "", dwClientStyle, 0, 0, &hwndClient);
68 if(*hwndFrame) {
69 if(pszName) {
70 WinSetWindowText(*hwndFrame, pszName);
71 }
72 return hwndClient;
73 }
74 dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
75 return 0;
76 }
77 hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
78 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
79 NULL);
80 *hwndFrame = hwndClient;
81 return hwndClient;
82}
83//******************************************************************************
84//******************************************************************************
85BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
86{
87 *OSWinStyle = 0;
88 *OSFrameStyle = 0;
89
90 /* Window styles */
91 if(dwStyle & WS_MINIMIZE_W)
92 *OSWinStyle |= WS_MINIMIZED;
93//Done explicitely in CreateWindowExA
94#if 0
95 if(dwStyle & WS_VISIBLE_W)
96 *OSWinStyle |= WS_VISIBLE;
97#endif
98 if(dwStyle & WS_DISABLED_W)
99 *OSWinStyle |= WS_DISABLED;
100 if(dwStyle & WS_CLIPSIBLINGS_W)
101 *OSWinStyle |= WS_CLIPSIBLINGS;
102 if(dwStyle & WS_CLIPCHILDREN_W)
103 *OSWinStyle |= WS_CLIPCHILDREN;
104 if(dwStyle & WS_MAXIMIZE_W)
105 *OSWinStyle |= WS_MAXIMIZED;
106 if(dwStyle & WS_GROUP_W)
107 *OSWinStyle |= WS_GROUP;
108 if(dwStyle & WS_TABSTOP_W)
109 *OSWinStyle |= WS_TABSTOP;
110
111 if(dwStyle & WS_CAPTION_W)
112 *OSFrameStyle |= FCF_TITLEBAR;
113 if(dwStyle & WS_DLGFRAME_W)
114 *OSFrameStyle |= FCF_DLGBORDER;
115 else
116 if(dwStyle & WS_BORDER_W)
117 *OSFrameStyle |= FCF_BORDER;
118
119 if(dwStyle & WS_VSCROLL_W)
120 *OSFrameStyle |= FCF_VERTSCROLL;
121 if(dwStyle & WS_HSCROLL_W)
122 *OSFrameStyle |= FCF_HORZSCROLL;
123 if(dwStyle & WS_SYSMENU_W)
124 *OSFrameStyle |= FCF_SYSMENU;
125 if(dwStyle & WS_THICKFRAME_W)
126 *OSFrameStyle |= FCF_SIZEBORDER; //??
127 if(dwStyle & WS_MINIMIZEBOX_W)
128 *OSFrameStyle |= FCF_MINBUTTON;
129 if(dwStyle & WS_MAXIMIZEBOX_W)
130 *OSFrameStyle |= FCF_MAXBUTTON;
131
132 if(dwExStyle & WS_EX_DLGMODALFRAME_W)
133 *OSFrameStyle |= FCF_DLGBORDER;
134
135 return TRUE;
136}
137//******************************************************************************
138//******************************************************************************
139BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
140{
141 return WinSetWindowULong(hwnd, offset, value);
142}
143//******************************************************************************
144//******************************************************************************
145ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
146{
147 return WinQueryWindowULong(hwnd, offset);
148}
149//******************************************************************************
150//******************************************************************************
151BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
152{
153 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
154}
155//******************************************************************************
156//******************************************************************************
157//******************************************************************************
158//******************************************************************************
159BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
160{
161 return WinAlarm(hwndDeskTop,flStyle);
162}
163//******************************************************************************
164//******************************************************************************
165APIRET OSLibDosBeep(ULONG freg,ULONG dur)
166{
167 return DosBeep(freg,dur);
168}
169//******************************************************************************
170//******************************************************************************
171HWND OSLibWinQueryFocus(HWND hwndDeskTop)
172{
173 return WinQueryFocus(hwndDeskTop);
174}
175//******************************************************************************
176//******************************************************************************
177HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
178{
179 return WinWindowFromID(hwndParent,id);
180}
181//******************************************************************************
182//******************************************************************************
183BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
184{
185 return WinSetFocus(hwndDeskTop,hwndNewFocus);
186}
187//******************************************************************************
188//******************************************************************************
189ULONG OSLibGetWindowHeight(HWND hwnd)
190{
191 RECTL rect;
192
193 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
194}
195//******************************************************************************
196//******************************************************************************
197LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
198{
199 return WinQuerySysValue(hwndDeskTop,iSysValue);
200}
201//******************************************************************************
202//******************************************************************************
203ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
204{
205 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
206}
207//******************************************************************************
208//******************************************************************************
209BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
210{
211 return WinSetDlgItemText(hwndDlg,idItem,pszText);
212}
213//******************************************************************************
214//******************************************************************************
215BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
216{
217 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
218}
219//******************************************************************************
220//******************************************************************************
221HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
222{
223 return WinQueryWindow(hwnd, lCode);
224}
225//******************************************************************************
226//******************************************************************************
227BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
228 LONG cy, ULONG fl)
229{
230 HWND hwndParent = hwndInsertBehind;
231 BOOL rc;
232
233 if(fl & SWP_MOVE) {
234 switch(hwndParent)
235 {
236 case HWNDOS_TOP:
237 case HWNDOS_BOTTOM:
238 hwndParent = HWND_DESKTOP;
239 break;
240 }
241 y = MapOS2ToWin32Y(hwndParent, cy, y);
242 }
243 rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
244 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
245 return rc;
246}
247//******************************************************************************
248//******************************************************************************
249BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
250{
251 BOOL rc;
252
253 if(fl & SWP_SHOW) {
254 rc = WinShowWindow(hwnd, TRUE);
255 }
256 if(rc == 0)
257 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
258 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
259 if(rc == 0)
260 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
261 return rc;
262}
263//******************************************************************************
264//******************************************************************************
265BOOL OSLibWinDestroyWindow(HWND hwnd)
266{
267 return WinDestroyWindow(hwnd);
268}
269//******************************************************************************
270//******************************************************************************
271BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
272{
273 BOOL rc;
274 RECTLOS2 rectl;
275
276 rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
277 if(rc) {
278 if(RelativeTo == RELATIVE_TO_SCREEN) {
279 MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
280 }
281 else MapOS2ToWin32Rectl(&rectl, pRect);
282 }
283 else memset(pRect, 0, sizeof(RECT));
284 return rc;
285}
286//******************************************************************************
287//******************************************************************************
288BOOL OSLibWinIsIconic(HWND hwnd)
289{
290 SWP swp;
291 BOOL rc;
292
293 rc = WinQueryWindowPos(hwnd, &swp);
294 if(rc == FALSE) {
295 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
296 return FALSE;
297 }
298
299 if(swp.fl & SWP_MINIMIZE)
300 return TRUE;
301 else return FALSE;
302}
303//******************************************************************************
304//******************************************************************************
305BOOL OSLibWinSetActiveWindow(HWND hwnd)
306{
307 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
308}
309//******************************************************************************
310//******************************************************************************
311BOOL OSLibWinSetFocus(HWND hwnd)
312{
313 return WinSetFocus(HWND_DESKTOP, hwnd);
314}
315//******************************************************************************
316//******************************************************************************
317BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
318{
319 return WinEnableWindow(hwnd, fEnable);
320}
321//******************************************************************************
322//******************************************************************************
323BOOL OSLibWinIsWindowEnabled(HWND hwnd)
324{
325 return WinIsWindowEnabled(hwnd);
326}
327//******************************************************************************
328//******************************************************************************
329BOOL OSLibWinIsWindowVisible(HWND hwnd)
330{
331 return WinIsWindowVisible(hwnd);
332}
333//******************************************************************************
334//******************************************************************************
335BOOL OSLibWinQueryActiveWindow()
336{
337 return WinQueryActiveWindow(HWND_DESKTOP);
338}
339//******************************************************************************
340//******************************************************************************
341LONG OSLibWinQueryWindowTextLength(HWND hwnd)
342{
343 return WinQueryWindowTextLength(hwnd);
344}
345//******************************************************************************
346//******************************************************************************
347LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
348{
349 return WinQueryWindowText(hwnd, length, lpsz);
350}
351//******************************************************************************
352//******************************************************************************
353BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
354{
355 return WinSetWindowText(hwnd, lpsz);
356}
357//******************************************************************************
358//******************************************************************************
359BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
360{
361 return WinFlashWindow(hwnd, fFlash);
362}
363//******************************************************************************
364//******************************************************************************
365HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
366{
367 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
368}
369//******************************************************************************
370//******************************************************************************
371BOOL OSLibWinMinimizeWindow(HWND hwnd)
372{
373 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
374}
375//******************************************************************************
376//******************************************************************************
377BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
378{
379 pointl->x = 0;
380 pointl->y = 0;
381 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
382}
383//******************************************************************************
384//******************************************************************************
385BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
386{
387 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
388}
389//******************************************************************************
390//******************************************************************************
391
Note: See TracBrowser for help on using the repository browser.