source: trunk/src/user32/new/win32wnd.cpp@ 309

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

Send/PostMessage changes

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