1 | /* $Id: oslibwin.cpp,v 1.24 1999-08-25 15:08:50 dengert 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 | //******************************************************************************
|
---|
31 | BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
|
---|
32 | {
|
---|
33 | if(hwndParent == OSLIB_HWND_DESKTOP)
|
---|
34 | {
|
---|
35 | hwndParent = HWND_DESKTOP;
|
---|
36 | }
|
---|
37 |
|
---|
38 | return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
|
---|
39 | }
|
---|
40 | //******************************************************************************
|
---|
41 | //******************************************************************************
|
---|
42 | HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
|
---|
43 | char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
|
---|
44 | {
|
---|
45 | HWND hwndClient;
|
---|
46 |
|
---|
47 | dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
|
---|
48 |
|
---|
49 | if(pszName && *pszName == 0) {
|
---|
50 | pszName = NULL;
|
---|
51 | }
|
---|
52 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
53 | hwndParent = HWND_DESKTOP;
|
---|
54 | }
|
---|
55 | if(Owner == OSLIB_HWND_DESKTOP) {
|
---|
56 | Owner = HWND_DESKTOP;
|
---|
57 | }
|
---|
58 |
|
---|
59 | if(dwFrameStyle) {
|
---|
60 | ULONG dwClientStyle;
|
---|
61 |
|
---|
62 | dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
|
---|
63 | if(pszName)
|
---|
64 | dwFrameStyle |= FCF_TITLEBAR;
|
---|
65 |
|
---|
66 | dwFrameStyle |= FCF_TASKLIST;
|
---|
67 | *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
|
---|
68 | &dwFrameStyle, WIN32_STDCLASS,
|
---|
69 | "", dwClientStyle, 0, 0, &hwndClient);
|
---|
70 | if(*hwndFrame) {
|
---|
71 | if(pszName) {
|
---|
72 | WinSetWindowText(*hwndFrame, pszName);
|
---|
73 | }
|
---|
74 | return hwndClient;
|
---|
75 | }
|
---|
76 | dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
|
---|
77 | return 0;
|
---|
78 | }
|
---|
79 | hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
|
---|
80 | Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
|
---|
81 | NULL);
|
---|
82 | *hwndFrame = hwndClient;
|
---|
83 | return hwndClient;
|
---|
84 | }
|
---|
85 | //******************************************************************************
|
---|
86 | //******************************************************************************
|
---|
87 | BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
|
---|
88 | {
|
---|
89 | *OSWinStyle = 0;
|
---|
90 | *OSFrameStyle = 0;
|
---|
91 |
|
---|
92 | /* Window styles */
|
---|
93 | if(dwStyle & WS_MINIMIZE_W)
|
---|
94 | *OSWinStyle |= WS_MINIMIZED;
|
---|
95 | //Done explicitely in CreateWindowExA
|
---|
96 | #if 0
|
---|
97 | if(dwStyle & WS_VISIBLE_W)
|
---|
98 | *OSWinStyle |= WS_VISIBLE;
|
---|
99 | #endif
|
---|
100 | if(dwStyle & WS_DISABLED_W)
|
---|
101 | *OSWinStyle |= WS_DISABLED;
|
---|
102 | if(dwStyle & WS_CLIPSIBLINGS_W)
|
---|
103 | *OSWinStyle |= WS_CLIPSIBLINGS;
|
---|
104 | if(dwStyle & WS_CLIPCHILDREN_W)
|
---|
105 | *OSWinStyle |= WS_CLIPCHILDREN;
|
---|
106 | if(dwStyle & WS_MAXIMIZE_W)
|
---|
107 | *OSWinStyle |= WS_MAXIMIZED;
|
---|
108 | if(dwStyle & WS_GROUP_W)
|
---|
109 | *OSWinStyle |= WS_GROUP;
|
---|
110 | if(dwStyle & WS_TABSTOP_W)
|
---|
111 | *OSWinStyle |= WS_TABSTOP;
|
---|
112 |
|
---|
113 | if(dwStyle & WS_CAPTION_W)
|
---|
114 | *OSFrameStyle |= FCF_TITLEBAR;
|
---|
115 | if(dwStyle & WS_DLGFRAME_W)
|
---|
116 | *OSFrameStyle |= FCF_DLGBORDER;
|
---|
117 | else
|
---|
118 | if(dwStyle & WS_BORDER_W)
|
---|
119 | *OSFrameStyle |= FCF_BORDER;
|
---|
120 |
|
---|
121 | if(dwStyle & WS_VSCROLL_W)
|
---|
122 | *OSFrameStyle |= FCF_VERTSCROLL;
|
---|
123 | if(dwStyle & WS_HSCROLL_W)
|
---|
124 | *OSFrameStyle |= FCF_HORZSCROLL;
|
---|
125 | if(dwStyle & WS_SYSMENU_W)
|
---|
126 | *OSFrameStyle |= FCF_SYSMENU;
|
---|
127 | if(dwStyle & WS_THICKFRAME_W)
|
---|
128 | *OSFrameStyle |= FCF_SIZEBORDER; //??
|
---|
129 | if(dwStyle & WS_MINIMIZEBOX_W)
|
---|
130 | *OSFrameStyle |= FCF_MINBUTTON;
|
---|
131 | if(dwStyle & WS_MAXIMIZEBOX_W)
|
---|
132 | *OSFrameStyle |= FCF_MAXBUTTON;
|
---|
133 |
|
---|
134 | if(dwExStyle & WS_EX_DLGMODALFRAME_W)
|
---|
135 | *OSFrameStyle |= FCF_DLGBORDER;
|
---|
136 |
|
---|
137 | return TRUE;
|
---|
138 | }
|
---|
139 | //******************************************************************************
|
---|
140 | //******************************************************************************
|
---|
141 | BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
|
---|
142 | {
|
---|
143 | return WinSetWindowULong(hwnd, offset, value);
|
---|
144 | }
|
---|
145 | //******************************************************************************
|
---|
146 | //******************************************************************************
|
---|
147 | ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
|
---|
148 | {
|
---|
149 | return WinQueryWindowULong(hwnd, offset);
|
---|
150 | }
|
---|
151 | //******************************************************************************
|
---|
152 | //******************************************************************************
|
---|
153 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
---|
154 | {
|
---|
155 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
---|
156 | }
|
---|
157 | //******************************************************************************
|
---|
158 | //******************************************************************************
|
---|
159 | //******************************************************************************
|
---|
160 | //******************************************************************************
|
---|
161 | BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
|
---|
162 | {
|
---|
163 | return WinAlarm(hwndDeskTop,flStyle);
|
---|
164 | }
|
---|
165 | //******************************************************************************
|
---|
166 | //******************************************************************************
|
---|
167 | APIRET OSLibDosBeep(ULONG freg,ULONG dur)
|
---|
168 | {
|
---|
169 | return DosBeep(freg,dur);
|
---|
170 | }
|
---|
171 | //******************************************************************************
|
---|
172 | //******************************************************************************
|
---|
173 | HWND OSLibWinQueryFocus(HWND hwndDeskTop)
|
---|
174 | {
|
---|
175 | return WinQueryFocus(hwndDeskTop);
|
---|
176 | }
|
---|
177 | //******************************************************************************
|
---|
178 | //******************************************************************************
|
---|
179 | HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
|
---|
180 | {
|
---|
181 | return WinWindowFromID(hwndParent,id);
|
---|
182 | }
|
---|
183 | //******************************************************************************
|
---|
184 | //******************************************************************************
|
---|
185 | BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
|
---|
186 | {
|
---|
187 | return WinSetFocus(hwndDeskTop,hwndNewFocus);
|
---|
188 | }
|
---|
189 | //******************************************************************************
|
---|
190 | //******************************************************************************
|
---|
191 | ULONG OSLibGetWindowHeight(HWND hwnd)
|
---|
192 | {
|
---|
193 | RECTL rect;
|
---|
194 |
|
---|
195 | return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
|
---|
196 | }
|
---|
197 | //******************************************************************************
|
---|
198 | //******************************************************************************
|
---|
199 | LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
|
---|
200 | {
|
---|
201 | return WinQuerySysValue(hwndDeskTop,iSysValue);
|
---|
202 | }
|
---|
203 | //******************************************************************************
|
---|
204 | //******************************************************************************
|
---|
205 | ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
|
---|
206 | {
|
---|
207 | return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
|
---|
208 | }
|
---|
209 | //******************************************************************************
|
---|
210 | //******************************************************************************
|
---|
211 | BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
|
---|
212 | {
|
---|
213 | return WinSetDlgItemText(hwndDlg,idItem,pszText);
|
---|
214 | }
|
---|
215 | //******************************************************************************
|
---|
216 | //******************************************************************************
|
---|
217 | BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
|
---|
218 | {
|
---|
219 | return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
|
---|
220 | }
|
---|
221 | //******************************************************************************
|
---|
222 | //******************************************************************************
|
---|
223 | HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
|
---|
224 | {
|
---|
225 | return WinQueryWindow(hwnd, lCode);
|
---|
226 | }
|
---|
227 | //******************************************************************************
|
---|
228 | //******************************************************************************
|
---|
229 | BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
|
---|
230 | LONG cy, ULONG fl)
|
---|
231 | {
|
---|
232 | HWND hwndParent = hwndInsertBehind;
|
---|
233 | BOOL rc;
|
---|
234 |
|
---|
235 | if(fl & SWP_MOVE) {
|
---|
236 | switch(hwndParent)
|
---|
237 | {
|
---|
238 | case HWNDOS_TOP:
|
---|
239 | case HWNDOS_BOTTOM:
|
---|
240 | hwndParent = HWND_DESKTOP;
|
---|
241 | break;
|
---|
242 | }
|
---|
243 | y = MapOS2ToWin32Y(hwndParent, cy, y);
|
---|
244 | }
|
---|
245 | rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
|
---|
246 | dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
|
---|
247 | return rc;
|
---|
248 | }
|
---|
249 | //******************************************************************************
|
---|
250 | //******************************************************************************
|
---|
251 | BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
|
---|
252 | {
|
---|
253 | return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
|
---|
254 | }
|
---|
255 | //******************************************************************************
|
---|
256 | //******************************************************************************
|
---|
257 | BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
|
---|
258 | {
|
---|
259 | BOOL rc;
|
---|
260 |
|
---|
261 | if(fl & SWP_SHOW) {
|
---|
262 | rc = WinShowWindow(hwnd, TRUE);
|
---|
263 | }
|
---|
264 | if(rc == 0)
|
---|
265 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
---|
266 | rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
|
---|
267 | if(rc == 0)
|
---|
268 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
---|
269 | return rc;
|
---|
270 | }
|
---|
271 | //******************************************************************************
|
---|
272 | //******************************************************************************
|
---|
273 | BOOL OSLibWinDestroyWindow(HWND hwnd)
|
---|
274 | {
|
---|
275 | return WinDestroyWindow(hwnd);
|
---|
276 | }
|
---|
277 | //******************************************************************************
|
---|
278 | //******************************************************************************
|
---|
279 | BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
|
---|
280 | {
|
---|
281 | BOOL rc;
|
---|
282 | RECTLOS2 rectl;
|
---|
283 |
|
---|
284 | rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
|
---|
285 | if(rc) {
|
---|
286 | if(RelativeTo == RELATIVE_TO_SCREEN) {
|
---|
287 | MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
|
---|
288 | }
|
---|
289 | else MapOS2ToWin32Rectl(&rectl, pRect);
|
---|
290 | }
|
---|
291 | else memset(pRect, 0, sizeof(RECT));
|
---|
292 | return rc;
|
---|
293 | }
|
---|
294 | //******************************************************************************
|
---|
295 | //******************************************************************************
|
---|
296 | BOOL OSLibWinIsIconic(HWND hwnd)
|
---|
297 | {
|
---|
298 | SWP swp;
|
---|
299 | BOOL rc;
|
---|
300 |
|
---|
301 | rc = WinQueryWindowPos(hwnd, &swp);
|
---|
302 | if(rc == FALSE) {
|
---|
303 | dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
|
---|
304 | return FALSE;
|
---|
305 | }
|
---|
306 |
|
---|
307 | if(swp.fl & SWP_MINIMIZE)
|
---|
308 | return TRUE;
|
---|
309 | else return FALSE;
|
---|
310 | }
|
---|
311 | //******************************************************************************
|
---|
312 | //******************************************************************************
|
---|
313 | BOOL OSLibWinSetActiveWindow(HWND hwnd)
|
---|
314 | {
|
---|
315 | return WinSetActiveWindow(HWND_DESKTOP, hwnd);
|
---|
316 | }
|
---|
317 | //******************************************************************************
|
---|
318 | //******************************************************************************
|
---|
319 | BOOL OSLibWinSetFocus(HWND hwnd)
|
---|
320 | {
|
---|
321 | return WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
322 | }
|
---|
323 | //******************************************************************************
|
---|
324 | //******************************************************************************
|
---|
325 | BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
|
---|
326 | {
|
---|
327 | return WinEnableWindow(hwnd, fEnable);
|
---|
328 | }
|
---|
329 | //******************************************************************************
|
---|
330 | //******************************************************************************
|
---|
331 | BOOL OSLibWinIsWindowEnabled(HWND hwnd)
|
---|
332 | {
|
---|
333 | return WinIsWindowEnabled(hwnd);
|
---|
334 | }
|
---|
335 | //******************************************************************************
|
---|
336 | //******************************************************************************
|
---|
337 | BOOL OSLibWinIsWindowVisible(HWND hwnd)
|
---|
338 | {
|
---|
339 | return WinIsWindowVisible(hwnd);
|
---|
340 | }
|
---|
341 | //******************************************************************************
|
---|
342 | //******************************************************************************
|
---|
343 | BOOL OSLibWinQueryActiveWindow()
|
---|
344 | {
|
---|
345 | return WinQueryActiveWindow(HWND_DESKTOP);
|
---|
346 | }
|
---|
347 | //******************************************************************************
|
---|
348 | //******************************************************************************
|
---|
349 | LONG OSLibWinQueryWindowTextLength(HWND hwnd)
|
---|
350 | {
|
---|
351 | return WinQueryWindowTextLength(hwnd);
|
---|
352 | }
|
---|
353 | //******************************************************************************
|
---|
354 | //******************************************************************************
|
---|
355 | LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
|
---|
356 | {
|
---|
357 | return WinQueryWindowText(hwnd, length, lpsz);
|
---|
358 | }
|
---|
359 | //******************************************************************************
|
---|
360 | //******************************************************************************
|
---|
361 | BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
|
---|
362 | {
|
---|
363 | return WinSetWindowText(hwnd, lpsz);
|
---|
364 | }
|
---|
365 | //******************************************************************************
|
---|
366 | //******************************************************************************
|
---|
367 | BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
|
---|
368 | {
|
---|
369 | return WinFlashWindow(hwnd, fFlash);
|
---|
370 | }
|
---|
371 | //******************************************************************************
|
---|
372 | //******************************************************************************
|
---|
373 | HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
|
---|
374 | {
|
---|
375 | return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
|
---|
376 | }
|
---|
377 | //******************************************************************************
|
---|
378 | //******************************************************************************
|
---|
379 | BOOL OSLibWinMinimizeWindow(HWND hwnd)
|
---|
380 | {
|
---|
381 | return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
|
---|
382 | }
|
---|
383 | //******************************************************************************
|
---|
384 | //******************************************************************************
|
---|
385 | BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
|
---|
386 | {
|
---|
387 | pointl->x = 0;
|
---|
388 | pointl->y = 0;
|
---|
389 | return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
|
---|
390 | }
|
---|
391 | //******************************************************************************
|
---|
392 | //******************************************************************************
|
---|
393 | BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
|
---|
394 | {
|
---|
395 | return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
|
---|
396 | }
|
---|
397 | //******************************************************************************
|
---|
398 | //******************************************************************************
|
---|
399 | BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
|
---|
400 | {
|
---|
401 | return WinQueryWindowPos(hwnd, pswp);
|
---|
402 | }
|
---|
403 | //******************************************************************************
|
---|
404 | //******************************************************************************
|
---|
405 | void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, ULONG parentHeight)
|
---|
406 | {
|
---|
407 | HWND hWindow = pswp->hwnd;
|
---|
408 | HWND hWndInsertAfter = pswp->hwndInsertBehind;
|
---|
409 | long x = pswp->x;
|
---|
410 | long y = pswp->y;
|
---|
411 | long cx = pswp->cx;
|
---|
412 | long cy = pswp->cy;
|
---|
413 | UINT fuFlags = (UINT)pswp->fl;
|
---|
414 |
|
---|
415 | HWND hWinAfter;
|
---|
416 | ULONG flags = 0;
|
---|
417 |
|
---|
418 | //***************************************************
|
---|
419 | // Map constant HWNDs (e.g. HWND_DESKTOP, HWND_TOP)
|
---|
420 | //***************************************************
|
---|
421 | HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
|
---|
422 |
|
---|
423 | if ( hWndInsertAfter == HWND_TOP )
|
---|
424 | hWinAfter = HWND_TOP_W;
|
---|
425 | else if ( hWndInsertAfter == HWND_BOTTOM )
|
---|
426 | hWinAfter = HWND_BOTTOM_W;
|
---|
427 | else
|
---|
428 | hWinAfter = (HWND) hWndInsertAfter;
|
---|
429 |
|
---|
430 | //***********************************
|
---|
431 | // convert PM flags to Windows flags
|
---|
432 | //***********************************
|
---|
433 | if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
|
---|
434 | if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
|
---|
435 | if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
|
---|
436 | if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
|
---|
437 | if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
|
---|
438 | if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
|
---|
439 | if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
|
---|
440 |
|
---|
441 | //**************************************************************************
|
---|
442 | // When moving or sizing we'll have to do some calculations for Y inversion.
|
---|
443 | //
|
---|
444 | // If moving - invert Y coord.
|
---|
445 | //
|
---|
446 | // If sizing - if the height is changing, have to move the window to
|
---|
447 | // maintain correct windows position. If we just size then the
|
---|
448 | // TR corner will extend. The Windows behaviour should be to
|
---|
449 | // extend the BR corner.
|
---|
450 | //
|
---|
451 | // If this is a child window then we'll have to move within the client
|
---|
452 | // area of the parent.
|
---|
453 | //
|
---|
454 | // If this is an overlapped or popup window we'll have to move around
|
---|
455 | // within the desktop.
|
---|
456 | //**************************************************************************
|
---|
457 | if ( fuFlags & (SWP_MOVE | SWP_SIZE) )
|
---|
458 | {
|
---|
459 | if (fuFlags & SWP_SIZE)
|
---|
460 | {
|
---|
461 | // If height is changing we MUST move to maintain top-left alignment
|
---|
462 | if (cy != pswpOld->cy)
|
---|
463 | {
|
---|
464 | flags &= ~SWP_NOMOVE_W;
|
---|
465 | }
|
---|
466 | }
|
---|
467 | else
|
---|
468 | {
|
---|
469 | cx = pswpOld->cx;
|
---|
470 | cy = pswpOld->cy;
|
---|
471 | }
|
---|
472 |
|
---|
473 | //**********************************************************
|
---|
474 | // We'll need both a y and cy for the Y inversion code.
|
---|
475 | // If either wasn't passed in, calculate the current value.
|
---|
476 | //**********************************************************
|
---|
477 | if ((fuFlags & SWP_MOVE) == 0)
|
---|
478 | {
|
---|
479 | x = pswpOld->x;
|
---|
480 | y = pswpOld->y;
|
---|
481 | }
|
---|
482 |
|
---|
483 | //********************************************************
|
---|
484 | // Y inversion here... old Y is top left corner of window
|
---|
485 | // relative to top left of parent.
|
---|
486 | //********************************************************
|
---|
487 | y = parentHeight - y - cy;
|
---|
488 |
|
---|
489 | LONG oldY = parentHeight - pswpOld->y - pswpOld->cy;
|
---|
490 |
|
---|
491 | // Set the SWP_NOMOVE_W flag if the window has not moved in windows
|
---|
492 | // coordinates.
|
---|
493 | if ( ( pswpOld->x == x ) && ( oldY == y ) )
|
---|
494 | flags |= SWP_NOMOVE_W;
|
---|
495 |
|
---|
496 | // Set the SWP_NOSIZE_W flag if the window is not really being sized.
|
---|
497 | if ( ( pswpOld->cx == cx ) && ( pswpOld->cy == cy ) )
|
---|
498 | flags |= SWP_NOSIZE_W;
|
---|
499 | }
|
---|
500 |
|
---|
501 | // Fill in the WINDOWPOS structure with the now calculated PM values.
|
---|
502 | pwpos->flags = (UINT)flags;
|
---|
503 | pwpos->cy = (int)cy;
|
---|
504 | pwpos->cx = (int)cx;
|
---|
505 | pwpos->x = (int)x;
|
---|
506 | pwpos->y = (int)y;
|
---|
507 | pwpos->hwndInsertAfter = hWinAfter;
|
---|
508 | pwpos->hwnd = hWindow;
|
---|
509 | }
|
---|
510 | //******************************************************************************
|
---|
511 | //******************************************************************************
|
---|
512 | void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, ULONG parentHeight)
|
---|
513 | {
|
---|
514 | HWND hWnd = pwpos->hwnd;
|
---|
515 | HWND hWndInsertAfter = pwpos->hwndInsertAfter;
|
---|
516 | long x = pwpos->x;
|
---|
517 | long y = pwpos->y;
|
---|
518 | long cx = pwpos->cx;
|
---|
519 | long cy = pwpos->cy;
|
---|
520 | UINT fuFlags = pwpos->flags;
|
---|
521 |
|
---|
522 | HWND hWinAfter;
|
---|
523 | ULONG flags = 0;
|
---|
524 |
|
---|
525 | //***************************************************
|
---|
526 | // Map constant HWNDs (e.g. HWND_DESKTOP, HWND_TOP)
|
---|
527 | //***************************************************
|
---|
528 | HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
|
---|
529 |
|
---|
530 | if ( hWndInsertAfter == HWND_TOPMOST_W )
|
---|
531 | // hWinAfter = HWND_TOPMOST;
|
---|
532 | hWinAfter = HWND_TOP;
|
---|
533 | else if ( hWndInsertAfter == HWND_NOTOPMOST_W )
|
---|
534 | // hWinAfter = HWND_NOTOPMOST;
|
---|
535 | hWinAfter = HWND_TOP;
|
---|
536 | else if ( hWndInsertAfter == HWND_TOP_W )
|
---|
537 | hWinAfter = HWND_TOP;
|
---|
538 | else if ( hWndInsertAfter == HWND_BOTTOM_W )
|
---|
539 | hWinAfter = HWND_BOTTOM;
|
---|
540 | else
|
---|
541 | hWinAfter = (HWND) hWndInsertAfter;
|
---|
542 |
|
---|
543 | //***********************************
|
---|
544 | // convert Windows flags to PM flags
|
---|
545 | //***********************************
|
---|
546 | if ( ! ( fuFlags & SWP_NOSIZE_W ) ) flags |= SWP_SIZE;
|
---|
547 | if ( ! ( fuFlags & SWP_NOMOVE_W ) ) flags |= SWP_MOVE;
|
---|
548 | if ( ! ( fuFlags & SWP_NOZORDER_W ) ) flags |= SWP_ZORDER;
|
---|
549 | if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
|
---|
550 | if ( ! ( fuFlags & SWP_NOACTIVATE_W ) ) flags |= SWP_ACTIVATE;
|
---|
551 | if ( fuFlags & SWP_SHOWWINDOW_W ) flags |= SWP_SHOW;
|
---|
552 | if ( fuFlags & SWP_HIDEWINDOW_W ) flags |= SWP_HIDE;
|
---|
553 | /* no PM equivalent for SWP_FRAMECHANGED_W, SWP_NOCOPYBITS_W and SWP_NOOWNERZORDER_W */
|
---|
554 |
|
---|
555 | //**************************************************************************
|
---|
556 | // When moving or sizing we'll have to do some calculations for Y inversion.
|
---|
557 | //
|
---|
558 | // If moving - invert Y coord.
|
---|
559 | //
|
---|
560 | // If sizing - if the height is changing, have to move the window to
|
---|
561 | // maintain correct windows position. If we just size then the
|
---|
562 | // TR corner will extend. The Windows behaviour should be to
|
---|
563 | // extend the BR corner.
|
---|
564 | //
|
---|
565 | // If this is a child window then we'll have to move within the client
|
---|
566 | // area of the parent.
|
---|
567 | //
|
---|
568 | // If this is an overlapped or popup window we'll have to move around
|
---|
569 | // within the desktop.
|
---|
570 | //**************************************************************************
|
---|
571 | if ( flags & (SWP_MOVE | SWP_SIZE) )
|
---|
572 | {
|
---|
573 | //**********************************************************
|
---|
574 | // We'll need both a y and cy for the Y inversion code.
|
---|
575 | // If either wasn't passed in, calculate the current value.
|
---|
576 | //**********************************************************
|
---|
577 | if ((flags & SWP_MOVE) == 0)
|
---|
578 | {
|
---|
579 | x = pswpOld->x;
|
---|
580 | y = pswpOld->y;
|
---|
581 |
|
---|
582 | // If the window is at (x,0) with a height of zero then this calculation
|
---|
583 | // won't quite work. Instead of calculating the Windows y coord, we set
|
---|
584 | // it at (x,0).
|
---|
585 | if (!(y == 0 && pswpOld->cy == 0))
|
---|
586 | {
|
---|
587 | // convert Y coordinate back to Windows's for later conversion with new size
|
---|
588 | y = parentHeight - y - pswpOld->cy;
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | if (flags & SWP_SIZE)
|
---|
593 | {
|
---|
594 | // If height is changing we MUST move to maintain top-left alignment
|
---|
595 | if (cy != pswpOld->cy)
|
---|
596 | flags |= SWP_MOVE;
|
---|
597 | }
|
---|
598 | else
|
---|
599 | {
|
---|
600 | cx = pswpOld->cx;
|
---|
601 | cy = pswpOld->cy;
|
---|
602 | }
|
---|
603 |
|
---|
604 | //********************************************************
|
---|
605 | // Y inversion here... old Y is top left corner of window
|
---|
606 | // relative to top left of parent.
|
---|
607 | //********************************************************
|
---|
608 | y = parentHeight - y - cy;
|
---|
609 |
|
---|
610 | // Clear the SWP_MOVE flag if the window is not really being moved.
|
---|
611 | if ( ( pswpOld->x == x ) && ( pswpOld->y == y ) )
|
---|
612 | flags &= ~SWP_MOVE;
|
---|
613 |
|
---|
614 | // Clear the SWP_SIZE flag if the window is not really being sized.
|
---|
615 | if ( ( pswpOld->cx == cx ) && ( pswpOld->cy == cy ) )
|
---|
616 | flags &= ~SWP_SIZE;
|
---|
617 | }
|
---|
618 |
|
---|
619 | // Fill in the WINDOWPOS structure with the now calculated PM values.
|
---|
620 | pswp->fl = flags;
|
---|
621 | pswp->cy = cy;
|
---|
622 | pswp->cx = cx;
|
---|
623 | pswp->x = x;
|
---|
624 | pswp->y = y;
|
---|
625 | pswp->hwndInsertBehind = hWinAfter;
|
---|
626 | pswp->hwnd = hWindow;
|
---|
627 | pswp->ulReserved1 = 0;
|
---|
628 | pswp->ulReserved2 = 0;
|
---|
629 | }
|
---|
630 | //******************************************************************************
|
---|
631 | //******************************************************************************
|
---|
632 |
|
---|