1 | /* $Id: win32wnd.cpp,v 1.1 1999-07-14 08:35:37 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Code for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | * Parts based on Wine Windows code (windows\win.c)
|
---|
9 | *
|
---|
10 | * Copyright 1993, 1994 Alexandre Julliard
|
---|
11 | *
|
---|
12 | *
|
---|
13 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
14 | *
|
---|
15 | */
|
---|
16 | #include <os2win.h>
|
---|
17 | #include <win.h>
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdarg.h>
|
---|
21 | #include <assert.h>
|
---|
22 | #include <misc.h>
|
---|
23 | #include <handlemanager.h>
|
---|
24 | #include <win32wnd.h>
|
---|
25 | #include <spy.h>
|
---|
26 | #include "wndmsg.h"
|
---|
27 | #include "hooks.h"
|
---|
28 | #include <oslibwin.h>
|
---|
29 |
|
---|
30 | #define HAS_DLGFRAME(style,exStyle) \
|
---|
31 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
---|
32 | (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
|
---|
33 |
|
---|
34 | #define HAS_THICKFRAME(style) \
|
---|
35 | (((style) & WS_THICKFRAME) && \
|
---|
36 | !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
|
---|
37 |
|
---|
38 | //******************************************************************************
|
---|
39 | //******************************************************************************
|
---|
40 | Win32Window::Win32Window(DWORD objType) : GenericObject(&windows, objType)
|
---|
41 | {
|
---|
42 | Init();
|
---|
43 | }
|
---|
44 | //******************************************************************************
|
---|
45 | //******************************************************************************
|
---|
46 | Win32Window::Win32Window(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
---|
47 | : GenericObject(&windows, OBJTYPE_WINDOW)
|
---|
48 | {
|
---|
49 | Init();
|
---|
50 | this->isUnicode = isUnicode;
|
---|
51 | CreateWindowExA(lpCreateStructA, classAtom);
|
---|
52 | }
|
---|
53 | //******************************************************************************
|
---|
54 | //******************************************************************************
|
---|
55 | void Win32Window::Init()
|
---|
56 | {
|
---|
57 | isUnicode = FALSE;
|
---|
58 |
|
---|
59 | *windowName = NULL;
|
---|
60 | wndNameLength = 0;
|
---|
61 |
|
---|
62 | *windowText = NULL;;
|
---|
63 | wndTextLength = 0;
|
---|
64 |
|
---|
65 | *userWindowLong = NULL;;
|
---|
66 | nrUserWindowLong = 0;
|
---|
67 |
|
---|
68 | magic = WIN32PM_MAGIC;
|
---|
69 | OS2Hwnd = 0;
|
---|
70 | Win32Hwnd = 0;
|
---|
71 | if(HMHandleAllocate(&Win32Hwnd, (ULONG)this) != 0)
|
---|
72 | {
|
---|
73 | dprintf(("Win32Window::Init HMHandleAllocate failed!!"));
|
---|
74 | DebugInt3();
|
---|
75 | }
|
---|
76 | posx = posy = 0;
|
---|
77 | width = height = 0;
|
---|
78 |
|
---|
79 | dwExStyle = 0;
|
---|
80 | dwStyle = 0;
|
---|
81 | win32wndproc = 0;
|
---|
82 | hInstance = 0;
|
---|
83 | parent = 0;
|
---|
84 | windowId = 0xFFFFFFFF; //default = -1
|
---|
85 | userData = 0;
|
---|
86 |
|
---|
87 | hwndLinkAfter = HWND_BOTTOM;
|
---|
88 | flags = 0;
|
---|
89 | owner = NULL;
|
---|
90 | windowClass = 0;
|
---|
91 | }
|
---|
92 | //******************************************************************************
|
---|
93 | //******************************************************************************
|
---|
94 | Win32Window::~Win32Window()
|
---|
95 | {
|
---|
96 | if(Win32Hwnd)
|
---|
97 | HMHandleFree(Win32Hwnd);
|
---|
98 | if(windowName)
|
---|
99 | free(windowName);
|
---|
100 | if(windowText)
|
---|
101 | free(windowText);
|
---|
102 | if(userWindowLong)
|
---|
103 | free(userWindowLong);
|
---|
104 | }
|
---|
105 | //******************************************************************************
|
---|
106 | //******************************************************************************
|
---|
107 | BOOL Win32Window::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
---|
108 | {
|
---|
109 | char buffer[256];
|
---|
110 | DWORD tmp;
|
---|
111 | INT sw = SW_SHOW;
|
---|
112 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
113 |
|
---|
114 | SetLastError(0);
|
---|
115 |
|
---|
116 | /* Find the parent window */
|
---|
117 | if (cs->hwndParent)
|
---|
118 | {
|
---|
119 | /* Make sure parent is valid */
|
---|
120 | if (!IsWindow( cs->hwndParent ))
|
---|
121 | {
|
---|
122 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
123 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
124 | return FALSE;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | else
|
---|
128 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
---|
129 | dprintf(("No parent for child window\n" ));
|
---|
130 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
131 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* Find the window class */
|
---|
135 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
---|
136 | if (!windowClass)
|
---|
137 | {
|
---|
138 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
139 | dprintf(("Bad class '%s'\n", buffer ));
|
---|
140 | return 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
---|
144 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
---|
145 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
---|
146 | */
|
---|
147 | if (!HIWORD(cs->lpszClass) ) {
|
---|
148 | if (isUnicode) {
|
---|
149 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
---|
150 | }
|
---|
151 | else {
|
---|
152 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
153 | }
|
---|
154 | cs->lpszClass = buffer;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /* Fix the coordinates */
|
---|
158 | if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
|
---|
159 | {
|
---|
160 | // PDB *pdb = PROCESS_Current();
|
---|
161 |
|
---|
162 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
---|
163 | * that if an overlapped window is created with WS_VISIBLE style bit
|
---|
164 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
---|
165 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
---|
166 | * reveals that
|
---|
167 | *
|
---|
168 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
---|
169 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
---|
170 | * uses it as second parameter to ShowWindow() unless y is either
|
---|
171 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
---|
172 | *
|
---|
173 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
---|
174 | * was running apps that were using this obscure feature. Example -
|
---|
175 | * calc.exe that comes with Win98 (only Win98, it's different from
|
---|
176 | * the one that comes with Win95 and NT)
|
---|
177 | */
|
---|
178 | if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
|
---|
179 |
|
---|
180 | /* We have saved cs->y, now we can trash it */
|
---|
181 | #if 0
|
---|
182 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
183 | && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
|
---|
184 | {
|
---|
185 | cs->x = pdb->env_db->startup_info->dwX;
|
---|
186 | cs->y = pdb->env_db->startup_info->dwY;
|
---|
187 | }
|
---|
188 | #endif
|
---|
189 | cs->x = 0;
|
---|
190 | cs->y = 0;
|
---|
191 | // }
|
---|
192 | }
|
---|
193 | if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
|
---|
194 | {
|
---|
195 | #if 0
|
---|
196 | PDB *pdb = PROCESS_Current();
|
---|
197 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
198 | && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
|
---|
199 | {
|
---|
200 | cs->cx = pdb->env_db->startup_info->dwXSize;
|
---|
201 | cs->cy = pdb->env_db->startup_info->dwYSize;
|
---|
202 | }
|
---|
203 | else
|
---|
204 | {
|
---|
205 | #endif
|
---|
206 | cs->cx = 600; /* FIXME */
|
---|
207 | cs->cy = 400;
|
---|
208 | // }
|
---|
209 | }
|
---|
210 |
|
---|
211 | //Allocate window words
|
---|
212 | nrUserWindowLong = windowClass->getExtraWndWords();
|
---|
213 | if(nrUserWindowLong) {
|
---|
214 | userWindowLong = (ULONG *)malloc(nrUserWindowLong);
|
---|
215 | memset(userWindowLong, 0, nrUserWindowLong);
|
---|
216 | }
|
---|
217 |
|
---|
218 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
---|
219 | {
|
---|
220 | if(HMHandleTranslateToOS2(cs->hwndParent, &tmp) != NO_ERROR)
|
---|
221 | {
|
---|
222 | dprintf(("HMHandleTranslateToOS2 couldn't find parent window %x!!!", cs->hwndParent));
|
---|
223 | return FALSE;
|
---|
224 | }
|
---|
225 | parent = (Win32Window *)tmp;
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | parent = NULL; //desktop
|
---|
230 | if (!cs->hwndParent) {
|
---|
231 | owner = NULL;
|
---|
232 | }
|
---|
233 | else
|
---|
234 | {
|
---|
235 | if(HMHandleTranslateToOS2(cs->hwndParent, &tmp) != NO_ERROR)
|
---|
236 | {
|
---|
237 | dprintf(("HMHandleTranslateToOS2 couldn't find owner window %x!!!", cs->hwndParent));
|
---|
238 | return FALSE;
|
---|
239 | }
|
---|
240 | owner = (Win32Window *)tmp;
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | setWindowProc(windowClass->getWindowProc());
|
---|
245 | hInstance = cs->hInstance;
|
---|
246 | dwStyle = cs->style & ~WS_VISIBLE;
|
---|
247 | dwExStyle = cs->dwExStyle;
|
---|
248 |
|
---|
249 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
|
---|
250 | ? HWND_BOTTOM : HWND_TOP;
|
---|
251 |
|
---|
252 | /* Increment class window counter */
|
---|
253 | windowClass->IncreaseWindowCount();
|
---|
254 |
|
---|
255 | /* Correct the window style */
|
---|
256 | if (!(cs->style & WS_CHILD))
|
---|
257 | {
|
---|
258 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
259 | if (!(cs->style & WS_POPUP))
|
---|
260 | {
|
---|
261 | dwStyle |= WS_CAPTION;
|
---|
262 | flags |= WIN_NEED_SIZE;
|
---|
263 | }
|
---|
264 | }
|
---|
265 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
---|
266 |
|
---|
267 | //TODO?
|
---|
268 | #if 0
|
---|
269 | /* Get class or window DC if needed */
|
---|
270 | if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
|
---|
271 | else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
|
---|
272 | else wndPtr->dce = NULL;
|
---|
273 | #endif
|
---|
274 |
|
---|
275 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
---|
276 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
---|
277 | {
|
---|
278 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
279 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
---|
280 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
---|
281 | if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
|
---|
282 | if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
|
---|
283 | }
|
---|
284 |
|
---|
285 | if(cs->style & WS_CHILD)
|
---|
286 | {
|
---|
287 | if(cs->cx < 0) cs->cx = 0;
|
---|
288 | if(cs->cy < 0) cs->cy = 0;
|
---|
289 | }
|
---|
290 | else
|
---|
291 | {
|
---|
292 | if (cs->cx <= 0) cs->cx = 1;
|
---|
293 | if (cs->cy <= 0) cs->cy = 1;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /* Set the window menu */
|
---|
297 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
---|
298 | {
|
---|
299 | if (cs->hMenu) SetMenu(getWindowHandle(), cs->hMenu);
|
---|
300 | else
|
---|
301 | {
|
---|
302 | if (windowClass->getMenuNameA()) {
|
---|
303 | cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
|
---|
304 | if (cs->hMenu) SetMenu( getWindowHandle(), cs->hMenu );
|
---|
305 | }
|
---|
306 | }
|
---|
307 | }
|
---|
308 | else windowId = (UINT)cs->hMenu;
|
---|
309 |
|
---|
310 | DWORD dwOSWinStyle, dwOSFrameStyle;
|
---|
311 |
|
---|
312 | OSLibWinConvertStyle(cs->style, &dwOSWinStyle, &dwOSFrameStyle);
|
---|
313 |
|
---|
314 | OS2Hwnd = OSLibWinCreateWindow((parent) ? parent->getOS2WindowHandle() : 0,
|
---|
315 | dwOSWinStyle, dwOSFrameStyle, (char *)cs->lpszName,
|
---|
316 | cs->x, cs->y, cs->cx, cs->cy,
|
---|
317 | (owner) ? owner->getOS2WindowHandle() : 0,
|
---|
318 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE);
|
---|
319 |
|
---|
320 | if(OS2Hwnd == 0) {
|
---|
321 | dprintf(("Window creation failed!!"));
|
---|
322 | return FALSE;
|
---|
323 | }
|
---|
324 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
325 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
326 | return FALSE;
|
---|
327 | }
|
---|
328 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
329 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
330 | return FALSE;
|
---|
331 | }
|
---|
332 |
|
---|
333 | }
|
---|
334 | /*******************************************************************
|
---|
335 | * GetMinMaxInfo
|
---|
336 | *
|
---|
337 | * Get the minimized and maximized information for a window.
|
---|
338 | */
|
---|
339 | void Win32Window::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
|
---|
340 | POINT *minTrack, POINT *maxTrack )
|
---|
341 | {
|
---|
342 | MINMAXINFO MinMax;
|
---|
343 | INT xinc, yinc;
|
---|
344 |
|
---|
345 | /* Compute default values */
|
---|
346 |
|
---|
347 | MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
|
---|
348 | MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
|
---|
349 | MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
|
---|
350 | MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
|
---|
351 | MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
|
---|
352 | MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
|
---|
353 |
|
---|
354 | if (flags & WIN_MANAGED) xinc = yinc = 0;
|
---|
355 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
356 | {
|
---|
357 | xinc = GetSystemMetrics(SM_CXDLGFRAME);
|
---|
358 | yinc = GetSystemMetrics(SM_CYDLGFRAME);
|
---|
359 | }
|
---|
360 | else
|
---|
361 | {
|
---|
362 | xinc = yinc = 0;
|
---|
363 | if (HAS_THICKFRAME(dwStyle))
|
---|
364 | {
|
---|
365 | xinc += GetSystemMetrics(SM_CXFRAME);
|
---|
366 | yinc += GetSystemMetrics(SM_CYFRAME);
|
---|
367 | }
|
---|
368 | if (dwStyle & WS_BORDER)
|
---|
369 | {
|
---|
370 | xinc += GetSystemMetrics(SM_CXBORDER);
|
---|
371 | yinc += GetSystemMetrics(SM_CYBORDER);
|
---|
372 | }
|
---|
373 | }
|
---|
374 | MinMax.ptMaxSize.x += 2 * xinc;
|
---|
375 | MinMax.ptMaxSize.y += 2 * yinc;
|
---|
376 |
|
---|
377 | #if 0
|
---|
378 | lpPos = (LPINTERNALPOS)GetPropA( wndPtr->hwndSelf, atomInternalPos );
|
---|
379 | if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
|
---|
380 | CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
|
---|
381 | else
|
---|
382 | {
|
---|
383 | #endif
|
---|
384 | MinMax.ptMaxPosition.x = -xinc;
|
---|
385 | MinMax.ptMaxPosition.y = -yinc;
|
---|
386 | // }
|
---|
387 |
|
---|
388 | SendMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
|
---|
389 |
|
---|
390 | /* Some sanity checks */
|
---|
391 |
|
---|
392 | dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
|
---|
393 | MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
|
---|
394 | MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
|
---|
395 | MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
|
---|
396 | MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
|
---|
397 | MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
|
---|
398 | MinMax.ptMinTrackSize.x );
|
---|
399 | MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
|
---|
400 | MinMax.ptMinTrackSize.y );
|
---|
401 |
|
---|
402 | if (maxSize) *maxSize = MinMax.ptMaxSize;
|
---|
403 | if (maxPos) *maxPos = MinMax.ptMaxPosition;
|
---|
404 | if (minTrack) *minTrack = MinMax.ptMinTrackSize;
|
---|
405 | if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
|
---|
406 | }
|
---|
407 | //******************************************************************************
|
---|
408 | //******************************************************************************
|
---|
409 | ULONG Win32Window::MsgCreate(HWND hwndOS2, ULONG initParam)
|
---|
410 | {
|
---|
411 | OS2Hwnd = hwndOS2;
|
---|
412 | return SendMessageA(WM_CREATE, 0, initParam);
|
---|
413 | }
|
---|
414 | //******************************************************************************
|
---|
415 | //******************************************************************************
|
---|
416 | ULONG Win32Window::MsgQuit()
|
---|
417 | {
|
---|
418 | return SendMessageA(WM_QUIT, 0, 0);
|
---|
419 | }
|
---|
420 | //******************************************************************************
|
---|
421 | //******************************************************************************
|
---|
422 | ULONG Win32Window::MsgClose()
|
---|
423 | {
|
---|
424 | return SendMessageA(WM_CLOSE, 0, 0);
|
---|
425 | }
|
---|
426 | //******************************************************************************
|
---|
427 | //******************************************************************************
|
---|
428 | ULONG Win32Window::MsgDestroy()
|
---|
429 | {
|
---|
430 | return SendMessageA(WM_DESTROY, 0, 0);
|
---|
431 | }
|
---|
432 | //******************************************************************************
|
---|
433 | //******************************************************************************
|
---|
434 | ULONG Win32Window::MsgEnable(BOOL fEnable)
|
---|
435 | {
|
---|
436 | return SendMessageA(WM_ENABLE, fEnable, 0);
|
---|
437 | }
|
---|
438 | //******************************************************************************
|
---|
439 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
---|
440 | //******************************************************************************
|
---|
441 | ULONG Win32Window::MsgShow(BOOL fShow)
|
---|
442 | {
|
---|
443 | return SendMessageA(WM_SHOWWINDOW, fShow, 0);
|
---|
444 | }
|
---|
445 | //******************************************************************************
|
---|
446 | //******************************************************************************
|
---|
447 | ULONG Win32Window::MsgMove(ULONG xScreen, ULONG yScreen, ULONG xParent, ULONG yParent)
|
---|
448 | {
|
---|
449 | return 0;
|
---|
450 | }
|
---|
451 | //******************************************************************************
|
---|
452 | //******************************************************************************
|
---|
453 | ULONG Win32Window::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
|
---|
454 | {
|
---|
455 | WORD fwSizeType = 0;
|
---|
456 |
|
---|
457 | if(fMinimize) {
|
---|
458 | fwSizeType = SIZE_MINIMIZED;
|
---|
459 | }
|
---|
460 | else
|
---|
461 | if(fMaximize) {
|
---|
462 | fwSizeType = SIZE_MAXIMIZED;
|
---|
463 | }
|
---|
464 | else fwSizeType = SIZE_RESTORED;
|
---|
465 |
|
---|
466 | return SendMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
|
---|
467 | }
|
---|
468 | //******************************************************************************
|
---|
469 | //******************************************************************************
|
---|
470 | ULONG Win32Window::MsgActivate(BOOL fActivate, HWND hwnd)
|
---|
471 | {
|
---|
472 | return SendMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
|
---|
473 | }
|
---|
474 | //******************************************************************************
|
---|
475 | //******************************************************************************
|
---|
476 | ULONG Win32Window::MsgSetFocus(HWND hwnd)
|
---|
477 | {
|
---|
478 | return SendMessageA(WM_SETFOCUS, hwnd, 0);
|
---|
479 | }
|
---|
480 | //******************************************************************************
|
---|
481 | //******************************************************************************
|
---|
482 | ULONG Win32Window::MsgKillFocus(HWND hwnd)
|
---|
483 | {
|
---|
484 | return SendMessageA(WM_KILLFOCUS, hwnd, 0);
|
---|
485 | }
|
---|
486 | //******************************************************************************
|
---|
487 | //******************************************************************************
|
---|
488 | ULONG Win32Window::MsgButton(ULONG msg, ULONG x, ULONG y)
|
---|
489 | {
|
---|
490 | ULONG win32msg;
|
---|
491 |
|
---|
492 | switch(msg) {
|
---|
493 | case BUTTON_LEFTDOWN:
|
---|
494 | win32msg = WM_LBUTTONDOWN;
|
---|
495 | break;
|
---|
496 | case BUTTON_LEFTUP:
|
---|
497 | win32msg = WM_LBUTTONUP;
|
---|
498 | break;
|
---|
499 | case BUTTON_LEFTDBLCLICK:
|
---|
500 | win32msg = WM_LBUTTONDBLCLK;
|
---|
501 | break;
|
---|
502 | case BUTTON_RIGHTUP:
|
---|
503 | win32msg = WM_RBUTTONUP;
|
---|
504 | break;
|
---|
505 | case BUTTON_RIGHTDOWN:
|
---|
506 | win32msg = WM_RBUTTONDOWN;
|
---|
507 | break;
|
---|
508 | case BUTTON_RIGHTDBLCLICK:
|
---|
509 | win32msg = WM_RBUTTONDBLCLK;
|
---|
510 | break;
|
---|
511 | default:
|
---|
512 | dprintf(("Win32Window::Button: invalid msg!!!!"));
|
---|
513 | return 1;
|
---|
514 | }
|
---|
515 | return SendMessageA(win32msg, 0, MAKELONG(x, OS2TOWIN32POINT(height, y)));
|
---|
516 | }
|
---|
517 | //******************************************************************************
|
---|
518 | //******************************************************************************
|
---|
519 | ULONG Win32Window::MsgPaint(ULONG tmp1, ULONG tmp2)
|
---|
520 | {
|
---|
521 | return SendMessageA(WM_PAINT, 0, 0);
|
---|
522 | }
|
---|
523 | //******************************************************************************
|
---|
524 | //******************************************************************************
|
---|
525 | ULONG Win32Window::MsgEraseBackGround(ULONG hps)
|
---|
526 | {
|
---|
527 | return SendMessageA(WM_ERASEBKGND, hps, 0);
|
---|
528 | }
|
---|
529 | //******************************************************************************
|
---|
530 | //******************************************************************************
|
---|
531 | LRESULT Win32Window::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
532 | {
|
---|
533 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
---|
534 | dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
---|
535 |
|
---|
536 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
537 | return(0);
|
---|
538 | }
|
---|
539 | switch(Msg)
|
---|
540 | {
|
---|
541 | case WM_CREATE:
|
---|
542 | {
|
---|
543 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
---|
544 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
---|
545 | return(0); //don't create window
|
---|
546 | }
|
---|
547 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
---|
548 | dprintf(("WM_CREATE returned FALSE\n"));
|
---|
549 | return(0); //don't create window
|
---|
550 | }
|
---|
551 | NotifyParent(Msg, wParam, lParam);
|
---|
552 |
|
---|
553 | return(1);
|
---|
554 | }
|
---|
555 | case WM_LBUTTONDOWN:
|
---|
556 | case WM_MBUTTONDOWN:
|
---|
557 | case WM_RBUTTONDOWN:
|
---|
558 | NotifyParent(Msg, wParam, lParam);
|
---|
559 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
560 |
|
---|
561 | case WM_DESTROY:
|
---|
562 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
---|
563 | NotifyParent(Msg, wParam, lParam);
|
---|
564 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
565 | default:
|
---|
566 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
567 | }
|
---|
568 | }
|
---|
569 | //******************************************************************************
|
---|
570 | //******************************************************************************
|
---|
571 | void Win32Window::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
572 | {
|
---|
573 | Win32Window *window = this;
|
---|
574 | Win32Window *parentwindow;
|
---|
575 |
|
---|
576 | while(window)
|
---|
577 | {
|
---|
578 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
579 | {
|
---|
580 | /* Notify the parent window only */
|
---|
581 | parentwindow = window->getParent();
|
---|
582 | if(parentwindow) {
|
---|
583 | if(Msg == WM_CREATE || Msg == WM_DESTROY) {
|
---|
584 | parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
|
---|
585 | }
|
---|
586 | else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
|
---|
587 | }
|
---|
588 | }
|
---|
589 | else break;
|
---|
590 |
|
---|
591 | window = parentwindow;
|
---|
592 | }
|
---|
593 | }
|
---|
594 | //******************************************************************************
|
---|
595 | //******************************************************************************
|
---|
596 | LONG Win32Window::SetWindowLongA(int index, ULONG value)
|
---|
597 | {
|
---|
598 | LONG oldval;
|
---|
599 |
|
---|
600 | switch(index) {
|
---|
601 | case GWL_EXSTYLE:
|
---|
602 | oldval = dwExStyle;
|
---|
603 | dwExStyle = value;
|
---|
604 | return oldval;
|
---|
605 | case GWL_STYLE:
|
---|
606 | oldval = dwStyle;
|
---|
607 | dwStyle = value;
|
---|
608 | return oldval;
|
---|
609 | case GWL_WNDPROC:
|
---|
610 | oldval = (LONG)getWindowProc();
|
---|
611 | setWindowProc((WNDPROC)value);
|
---|
612 | return oldval;
|
---|
613 | case GWL_HINSTANCE:
|
---|
614 | oldval = hInstance;
|
---|
615 | hInstance = value;
|
---|
616 | return oldval;
|
---|
617 | case GWL_HWNDPARENT:
|
---|
618 | {
|
---|
619 | ULONG tmp;
|
---|
620 |
|
---|
621 | if(getParent()) {
|
---|
622 | oldval = getParent()->getWindowHandle();
|
---|
623 | }
|
---|
624 | else oldval = 0;
|
---|
625 |
|
---|
626 | if(value == 0) {//desktop window = parent
|
---|
627 | setParent(NULL);
|
---|
628 | OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
|
---|
629 | return oldval;
|
---|
630 | }
|
---|
631 | if(HMHandleTranslateToOS2(value, &tmp) == NO_ERROR)
|
---|
632 | {
|
---|
633 | setParent((Win32Window *)tmp);
|
---|
634 | OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
|
---|
635 | return oldval;
|
---|
636 | }
|
---|
637 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
638 | return 0;
|
---|
639 | }
|
---|
640 | case GWL_ID:
|
---|
641 | oldval = getWindowId();
|
---|
642 | setWindowId(value);
|
---|
643 | return oldval;
|
---|
644 | case GWL_USERDATA:
|
---|
645 | oldval = userData;
|
---|
646 | userData = value;
|
---|
647 | return oldval;
|
---|
648 | default:
|
---|
649 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
650 | {
|
---|
651 | oldval = userWindowLong[index/4];
|
---|
652 | userWindowLong[index/4] = value;
|
---|
653 | return oldval;
|
---|
654 | }
|
---|
655 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
656 | return 0;
|
---|
657 | }
|
---|
658 | }
|
---|
659 | //******************************************************************************
|
---|
660 | //******************************************************************************
|
---|
661 | ULONG Win32Window::GetWindowLongA(int index)
|
---|
662 | {
|
---|
663 | switch(index) {
|
---|
664 | case GWL_EXSTYLE:
|
---|
665 | return dwExStyle;
|
---|
666 | case GWL_STYLE:
|
---|
667 | return dwStyle;
|
---|
668 | case GWL_WNDPROC:
|
---|
669 | return (ULONG)getWindowProc();
|
---|
670 | case GWL_HINSTANCE:
|
---|
671 | return hInstance;
|
---|
672 | case GWL_HWNDPARENT:
|
---|
673 | if(getParent()) {
|
---|
674 | return getParent()->getWindowHandle();
|
---|
675 | }
|
---|
676 | else return 0;
|
---|
677 | case GWL_ID:
|
---|
678 | return getWindowId();
|
---|
679 | case GWL_USERDATA:
|
---|
680 | return userData;
|
---|
681 | default:
|
---|
682 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
683 | {
|
---|
684 | return userWindowLong[index/4];
|
---|
685 | }
|
---|
686 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
687 | return 0;
|
---|
688 | }
|
---|
689 | }
|
---|
690 | //******************************************************************************
|
---|
691 | //******************************************************************************
|
---|
692 | WORD Win32Window::SetWindowWord(int index, WORD value)
|
---|
693 | {
|
---|
694 | WORD oldval;
|
---|
695 |
|
---|
696 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
697 | {
|
---|
698 | oldval = ((WORD *)userWindowLong)[index/2];
|
---|
699 | ((WORD *)userWindowLong)[index/2] = value;
|
---|
700 | return oldval;
|
---|
701 | }
|
---|
702 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
703 | return 0;
|
---|
704 | }
|
---|
705 | //******************************************************************************
|
---|
706 | //******************************************************************************
|
---|
707 | WORD Win32Window::GetWindowWord(int index)
|
---|
708 | {
|
---|
709 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
710 | {
|
---|
711 | return ((WORD *)userWindowLong)[index/2];
|
---|
712 | }
|
---|
713 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
714 | return 0;
|
---|
715 | }
|
---|
716 | //******************************************************************************
|
---|
717 | //******************************************************************************
|
---|
718 | GenericObject *Win32Window::windows = NULL;
|
---|