source: trunk/src/user32/win32wbase.cpp@ 2084

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

sendmessage + hook updates + misc fixes

File size: 115.5 KB
Line 
1/* $Id: win32wbase.cpp,v 1.111 1999-12-16 00:11:46 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include "wndmsg.h"
28#include "oslibwin.h"
29#include "oslibutil.h"
30#include "oslibgdi.h"
31#include "oslibres.h"
32#include "oslibmenu.h"
33#include "oslibdos.h"
34#include "syscolor.h"
35#include "win32wndhandle.h"
36#include "dc.h"
37#include "pmframe.h"
38#include "win32wdesktop.h"
39#include "pmwindow.h"
40#include "controls.h"
41#include <wprocess.h>
42#include "winmouse.h"
43#include <win\hook.h>
44
45#define HAS_DLGFRAME(style,exStyle) \
46 (((exStyle) & WS_EX_DLGMODALFRAME) || \
47 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
48
49#define HAS_THICKFRAME(style,exStyle) \
50 (((style) & WS_THICKFRAME) && \
51 !((exStyle) & WS_EX_DLGMODALFRAME))
52
53#define HAS_THINFRAME(style) \
54 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
55
56#define HAS_BIGFRAME(style,exStyle) \
57 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
58 ((exStyle) & WS_EX_DLGMODALFRAME))
59
60#define HAS_ANYFRAME(style,exStyle) \
61 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
62 ((exStyle) & WS_EX_DLGMODALFRAME) || \
63 !((style) & (WS_CHILD | WS_POPUP)))
64
65#define HAS_3DFRAME(exStyle) \
66 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
67
68#define HAS_BORDER(style, exStyle) \
69 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
70
71#define IS_OVERLAPPED(style) \
72 !(style & (WS_CHILD | WS_POPUP))
73
74/* bits in the dwKeyData */
75#define KEYDATA_ALT 0x2000
76#define KEYDATA_PREVSTATE 0x4000
77
78void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
79
80static fDestroyAll = FALSE;
81//For quick lookup of current process id
82static ULONG currentProcessId = -1;
83
84//******************************************************************************
85//******************************************************************************
86Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
87{
88 Init();
89}
90//******************************************************************************
91//******************************************************************************
92Win32BaseWindow::Win32BaseWindow(HWND os2Handle,VOID* win32WndProc) : GenericObject(&windows,OBJTYPE_WINDOW)
93{
94 Init();
95 OS2Hwnd = OS2HwndFrame = os2Handle;
96 dwStyle = WS_VISIBLE;
97 setWindowProc((WNDPROC)win32WndProc);
98 fIsSubclassedOS2Wnd = TRUE;
99 fFirstShow = FALSE;
100
101 SetLastError(0);
102
103 //CB: replace by a secure method
104
105 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
106 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
107 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
108 return;
109 }
110 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
111 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
112 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
113 return;
114 }
115
116 OSLibWinQueryWindowRect(OS2Hwnd,&rectWindow);
117 rectClient = rectWindow;
118 rectClient.bottom -= rectClient.top;
119 rectClient.top = 0;
120 rectClient.right -= rectClient.left;
121 rectClient.left = 0;
122
123 setOldWndProc(SubclassWithDefHandler(OS2Hwnd));
124}
125//******************************************************************************
126//******************************************************************************
127Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
128 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
129{
130 Init();
131 this->isUnicode = isUnicode;
132 CreateWindowExA(lpCreateStructA, classAtom);
133}
134//******************************************************************************
135//******************************************************************************
136void Win32BaseWindow::Init()
137{
138 isUnicode = FALSE;
139 fIsSubclassedOS2Wnd = FALSE;
140 fFirstShow = TRUE;
141 fIsDialog = FALSE;
142 fIsModalDialogOwner = FALSE;
143 OS2HwndModalDialog = 0;
144 fInternalMsg = FALSE;
145 fNoSizeMsg = FALSE;
146 fIsDestroyed = FALSE;
147 fDestroyWindowCalled = FALSE;
148 fCreated = FALSE;
149 fTaskList = FALSE;
150 fParentDC = FALSE;
151
152 windowNameA = NULL;
153 windowNameW = NULL;
154 wndNameLength = 0;
155
156 userWindowLong = NULL;;
157 nrUserWindowLong = 0;
158
159 magic = WIN32PM_MAGIC;
160 OS2Hwnd = 0;
161 OS2HwndFrame = 0;
162 OS2HwndMenu = 0;
163 Win32Hwnd = 0;
164
165 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
166 {
167 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
168 DebugInt3();
169 }
170
171 posx = posy = 0;
172 width = height = 0;
173
174 dwExStyle = 0;
175 dwStyle = 0;
176 win32wndproc = 0;
177 hInstance = 0;
178 windowId = 0xFFFFFFFF; //default = -1
179 userData = 0;
180 contextHelpId = 0;
181
182 pOldFrameProc = NULL;
183 borderWidth = 0;
184 borderHeight = 0;
185
186 hwndLinkAfter = HWND_BOTTOM;
187 flags = 0;
188 isIcon = FALSE;
189 lastHitTestVal = 0;
190 owner = NULL;
191 windowClass = 0;
192
193 acceltableResource = NULL;
194 iconResource = NULL;
195
196 EraseBkgndFlag = TRUE;
197 PSEraseFlag = FALSE;
198 SupressEraseFlag = FALSE;
199
200 horzScrollInfo = NULL;
201 vertScrollInfo = NULL;
202 hwndHorzScroll = 0;
203 hwndVertScroll = 0;
204
205 ownDC = 0;
206
207 if(currentProcessId == -1)
208 {
209 currentProcessId = GetCurrentProcessId();
210 }
211 dwThreadId = GetCurrentThreadId();
212 dwProcessId = currentProcessId;
213}
214//******************************************************************************
215//todo get rid of resources (menu, accel, icon etc)
216//******************************************************************************
217Win32BaseWindow::~Win32BaseWindow()
218{
219 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
220 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
221
222 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
223 {
224 //if we're the last child that's being destroyed and our
225 //parent window was also destroyed, then we delete the parent object
226 if(getParent()->IsWindowDestroyed())
227 {
228 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
229 delete getParent();
230 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
231 }
232 }
233 else
234 if(fDestroyAll) {
235 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
236 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
237 }
238
239 if (isOwnDC())
240 releaseOwnDC (ownDC);
241
242 if(Win32Hwnd)
243 HwFreeWindowHandle(Win32Hwnd);
244
245 if(userWindowLong)
246 free(userWindowLong);
247 if(windowNameA) {
248 free(windowNameA);
249 windowNameA = NULL;
250 }
251 if(windowNameW) {
252 free(windowNameW);
253 windowNameW = NULL;
254 }
255 if(vertScrollInfo) {
256 free(vertScrollInfo);
257 vertScrollInfo = NULL;
258 }
259 if(horzScrollInfo) {
260 free(horzScrollInfo);
261 horzScrollInfo = NULL;
262 }
263}
264//******************************************************************************
265//******************************************************************************
266void Win32BaseWindow::DestroyAll()
267{
268 fDestroyAll = TRUE;
269 GenericObject::DestroyAll(windows);
270}
271//******************************************************************************
272//******************************************************************************
273BOOL Win32BaseWindow::isChild()
274{
275 return ((dwStyle & WS_CHILD) != 0);
276}
277//******************************************************************************
278//******************************************************************************
279BOOL Win32BaseWindow::IsWindowUnicode()
280{
281// dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
282 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
283}
284//******************************************************************************
285//******************************************************************************
286BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
287{
288 char buffer[256];
289 POINT maxSize, maxPos, minTrack, maxTrack;
290
291#ifdef DEBUG
292 PrintWindowStyle(cs->style, cs->dwExStyle);
293#endif
294
295 sw = SW_SHOW;
296 SetLastError(0);
297
298 /* Find the parent window */
299 if (cs->hwndParent)
300 {
301 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
302 if(!window) {
303 dprintf(("Bad parent %04x\n", cs->hwndParent ));
304 SetLastError(ERROR_INVALID_PARAMETER);
305 return FALSE;
306 }
307 /* Make sure parent is valid */
308 if (!window->IsWindow() )
309 {
310 dprintf(("Bad parent %04x\n", cs->hwndParent ));
311 SetLastError(ERROR_INVALID_PARAMETER);
312 return FALSE;
313 }
314 }
315 else
316 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
317 dprintf(("No parent for child window\n" ));
318 SetLastError(ERROR_INVALID_PARAMETER);
319 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
320 }
321
322 /* Find the window class */
323 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
324 if (!windowClass)
325 {
326 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
327 dprintf(("Bad class '%s'\n", buffer ));
328 SetLastError(ERROR_INVALID_PARAMETER);
329 return 0;
330 }
331#ifdef DEBUG
332 if(HIWORD(cs->lpszClass))
333 {
334 char *astring;
335
336 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
337 else astring = (char *)cs->lpszClass;
338
339 dprintf(("Window class %s", astring));
340 if(isUnicode) FreeAsciiString(astring);
341 }
342 else dprintf(("Window class %x", cs->lpszClass));
343#endif
344
345 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
346 * with an atom as the class name, put some programs expect to have a *REAL* string in
347 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
348 */
349 if (!HIWORD(cs->lpszClass) ) {
350 if (isUnicode) {
351 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
352 }
353 else {
354 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
355 }
356 cs->lpszClass = buffer;
357 }
358
359 /* Fix the coordinates */
360 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
361 {
362// PDB *pdb = PROCESS_Current();
363
364 /* Never believe Microsoft's documentation... CreateWindowEx doc says
365 * that if an overlapped window is created with WS_VISIBLE style bit
366 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
367 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
368 * reveals that
369 *
370 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
371 * 2) it does not ignore the y parameter as the docs claim; instead, it
372 * uses it as second parameter to ShowWindow() unless y is either
373 * CW_USEDEFAULT or CW_USEDEFAULT16.
374 *
375 * The fact that we didn't do 2) caused bogus windows pop up when wine
376 * was running apps that were using this obscure feature. Example -
377 * calc.exe that comes with Win98 (only Win98, it's different from
378 * the one that comes with Win95 and NT)
379 */
380 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
381
382 /* We have saved cs->y, now we can trash it */
383#if 0
384 if ( !(cs->style & (WS_CHILD | WS_POPUP))
385 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
386 {
387 cs->x = pdb->env_db->startup_info->dwX;
388 cs->y = pdb->env_db->startup_info->dwY;
389 }
390#endif
391 cs->x = 0;
392 cs->y = 0;
393// }
394 }
395 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
396 {
397#if 0
398 PDB *pdb = PROCESS_Current();
399 if ( !(cs->style & (WS_CHILD | WS_POPUP))
400 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
401 {
402 cs->cx = pdb->env_db->startup_info->dwXSize;
403 cs->cy = pdb->env_db->startup_info->dwYSize;
404 }
405 else
406 {
407#endif
408 cs->cx = 600; /* FIXME */
409 cs->cy = 400;
410// }
411 }
412
413 if (cs->x < 0) cs->x = 0;
414 if (cs->y < 0) cs->y = 0;
415
416 //Allocate window words
417 nrUserWindowLong = windowClass->getExtraWndWords();
418 if(nrUserWindowLong) {
419 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
420 memset(userWindowLong, 0, nrUserWindowLong);
421 }
422
423 if ((cs->style & WS_CHILD) && cs->hwndParent)
424 {
425 SetParent(cs->hwndParent);
426 owner = GetWindowFromHandle(cs->hwndParent);
427 if(owner == NULL)
428 {
429 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
430 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
431 return FALSE;
432 }
433 }
434 else
435 {
436 SetParent(0);
437 if (!cs->hwndParent || cs->hwndParent == windowDesktop->getWindowHandle()) {
438 owner = NULL;
439 }
440 else
441 {
442 owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
443 if(owner == NULL)
444 {
445 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
446 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
447 return FALSE;
448 }
449 }
450 }
451
452 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
453 hInstance = cs->hInstance;
454 dwStyle = cs->style & ~WS_VISIBLE;
455 dwExStyle = cs->dwExStyle;
456
457 hwndLinkAfter = HWND_TOP;
458 if(WIDGETS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))
459 {
460 hwndLinkAfter = HWND_BOTTOM;
461 dwStyle |= WS_CLIPSIBLINGS;
462 }
463 else
464 if(WIDGETS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {
465 dwStyle |= WS_CLIPSIBLINGS;
466 }
467
468 /* Increment class window counter */
469 windowClass->IncreaseWindowCount();
470
471 if (HOOK_IsHooked( WH_CBT ))
472 {
473 CBT_CREATEWNDA cbtc;
474 LRESULT ret;
475
476 cbtc.lpcs = cs;
477 cbtc.hwndInsertAfter = hwndLinkAfter;
478 ret = HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
479 if(ret)
480 {
481 dprintf(("CBT-hook returned 0!!"));
482 SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
483 return FALSE;
484 }
485 }
486
487 /* Correct the window style */
488 if (!(cs->style & WS_CHILD))
489 {
490 dwStyle |= WS_CLIPSIBLINGS;
491 if (!(cs->style & WS_POPUP))
492 {
493 dwStyle |= WS_CAPTION;
494 flags |= WIN_NEED_SIZE;
495 }
496 }
497 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
498
499 if (cs->style & WS_HSCROLL)
500 {
501 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
502 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
503 horzScrollInfo->MaxVal = 100;
504 horzScrollInfo->flags = ESB_ENABLE_BOTH;
505 }
506
507 if (cs->style & WS_VSCROLL)
508 {
509 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
510 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
511 vertScrollInfo->MaxVal = 100;
512 vertScrollInfo->flags = ESB_ENABLE_BOTH;
513 }
514
515 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
516 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
517 {
518 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
519 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
520 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
521 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
522 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
523 }
524
525 if(cs->style & WS_CHILD)
526 {
527 if(cs->cx < 0) cs->cx = 0;
528 if(cs->cy < 0) cs->cy = 0;
529 }
530 else
531 {
532 if (cs->cx <= 0) cs->cx = 1;
533 if (cs->cy <= 0) cs->cy = 1;
534 }
535
536 if(((dwStyle & 0xC0000000) == WS_OVERLAPPED) && ((dwStyle & WS_CAPTION) == WS_CAPTION) && owner == NULL
537 && dwStyle & WS_SYSMENU)
538 {
539 fTaskList = TRUE;
540 }
541
542 DWORD dwOSWinStyle, dwOSFrameStyle;
543
544 OSLibWinConvertStyle(dwStyle, &dwExStyle, &dwOSWinStyle, &dwOSFrameStyle, &borderWidth, &borderHeight);
545
546 rectWindow.left = cs->x;
547 rectWindow.top = cs->y;
548 rectWindow.right = cs->x + cs->cx;
549 rectWindow.bottom = cs->y + cs->cy;
550 rectClient = rectWindow;
551
552 if(HIWORD(cs->lpszName))
553 {
554 if (!isUnicode)
555 {
556 wndNameLength = strlen(cs->lpszName);
557 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
558 strcpy(windowNameA,cs->lpszName);
559 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
560 lstrcpyAtoW(windowNameW,windowNameA);
561 windowNameA[wndNameLength] = 0;
562 windowNameW[wndNameLength] = 0;
563 }
564 else
565 {
566 wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
567 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
568 lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
569 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
570 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
571 windowNameA[wndNameLength] = 0;
572 windowNameW[wndNameLength] = 0;
573 }
574 }
575
576 //copy pointer of CREATESTRUCT for usage in MsgCreate method
577 tmpcs = cs;
578
579 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
580 THDB *thdb = GetThreadTHDB();
581
582 if(thdb == NULL) {
583 dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
584 ExitProcess(666);
585 return FALSE;
586 }
587
588 thdb->newWindow = (ULONG)this;
589
590 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
591 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
592 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
593 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
594 &OS2HwndFrame, 0, fTaskList);
595
596 if(OS2Hwnd == 0) {
597 dprintf(("Window creation failed!!"));
598 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
599 return FALSE;
600 }
601
602 SetLastError(0);
603 return TRUE;
604}
605//******************************************************************************
606//******************************************************************************
607BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
608{
609 POINT maxPos;
610 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
611 RECT rectWndTmp, rectClientTmp;
612
613 OS2Hwnd = hwndClient;
614 OS2HwndFrame = hwndFrame;
615
616 //make backup copy of rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
617 //set our window size just yet)
618 rectWndTmp = rectWindow;
619 rectClientTmp = rectClient;
620
621 fNoSizeMsg = TRUE;
622
623 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
624 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
625 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
626 return FALSE;
627 }
628 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
629 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
630 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
631 return FALSE;
632 }
633#if 0
634 if(OS2Hwnd != OS2HwndFrame) {
635 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
636 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
637 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
638 return FALSE;
639 }
640 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
641 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
642 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
643 return FALSE;
644 }
645 }
646#endif
647
648 OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
649
650 FrameGetScrollBarHandles(this,dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
651 subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
652
653 fakeWinBase.hwndThis = OS2Hwnd;
654 fakeWinBase.pWindowClass = windowClass;
655
656 //Set icon from class
657 if(windowClass->getIcon())
658 SetIcon(windowClass->getIcon());
659
660 /* Get class or window DC if needed */
661 if(windowClass->getStyle() & CS_OWNDC) {
662 dprintf(("Class with CS_OWNDC style"));
663// ownDC = GetWindowDC(getWindowHandle());
664 }
665 else
666 if (windowClass->getStyle() & CS_PARENTDC) {
667 dprintf(("ERROR: Class with CS_PARENTDC style -> NOT IMPLEMENTED!"));
668 fParentDC = TRUE;
669 ownDC = 0;
670 }
671 else
672 if (windowClass->getStyle() & CS_CLASSDC) {
673 dprintf(("ERROR: Class with CS_CLASSDC style -> NOT IMPLEMENTED!"));
674 ownDC = 0;
675 }
676 /* Set the window menu */
677 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
678 {
679 if (cs->hMenu) {
680 SetMenu(cs->hMenu);
681 }
682 else {
683 if (windowClass->getMenuNameA()) {
684 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
685 if (cs->hMenu) SetMenu(cs->hMenu );
686 }
687 }
688 }
689 else
690 {
691 setWindowId((DWORD)cs->hMenu);
692 }
693
694 // Subclass frame
695 pOldFrameProc = FrameSubclassFrameWindow(this);
696 if (isChild()) FrameSetBorderSize(this,TRUE);
697
698 //restore rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
699 //set our window size just yet)
700 rectWindow = rectWndTmp;
701 rectClient = rectClientTmp;
702
703 /* Send the WM_CREATE message
704 * Perhaps we shouldn't allow width/height changes as well.
705 * See p327 in "Internals".
706 */
707 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
708
709 if(getParent()) {
710 SetWindowPos(hwndLinkAfter, rectClient.left, rectClient.top,
711 rectClient.right-rectClient.left,
712 rectClient.bottom-rectClient.top,
713 SWP_NOACTIVATE | SWP_NOREDRAW);
714 }
715 else {
716 SetWindowPos(hwndLinkAfter, rectClient.left, rectClient.top,
717 rectClient.right-rectClient.left,
718 rectClient.bottom-rectClient.top,
719 SWP_NOACTIVATE | SWP_NOREDRAW);
720 }
721 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
722 fNoSizeMsg = FALSE;
723
724 if(SendInternalMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
725 {
726 fCreated = TRUE;
727
728 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
729
730// OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
731 if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
732 {
733 if(!(flags & WIN_NEED_SIZE)) {
734 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
735 MAKELONG(rectClient.right-rectClient.left,
736 rectClient.bottom-rectClient.top));
737 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
738 }
739
740 if( getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
741 {
742 /* Notify the parent window only */
743 SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
744 if(!::IsWindow(getWindowHandle()))
745 {
746 dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
747 goto end;
748 }
749 }
750
751 if (cs->style & WS_VISIBLE) ShowWindow( sw );
752
753 /* Call WH_SHELL hook */
754 if (!(getStyle() & WS_CHILD) && !owner)
755 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0 );
756
757 SetLastError(0);
758 return TRUE;
759 }
760 }
761 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
762 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
763end:
764 return FALSE;
765}
766//******************************************************************************
767//******************************************************************************
768ULONG Win32BaseWindow::MsgQuit()
769{
770 return SendInternalMessageA(WM_QUIT, 0, 0);
771}
772//******************************************************************************
773//******************************************************************************
774ULONG Win32BaseWindow::MsgClose()
775{
776 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
777 dprintf(("Win32BaseWindow::MsgClose, app handles msg"));
778 return 0; //app handles this message
779 }
780 return 1;
781}
782//******************************************************************************
783//******************************************************************************
784ULONG Win32BaseWindow::MsgDestroy()
785{
786 ULONG rc;
787 Win32BaseWindow *child;
788
789 if (isSubclassedOS2Wnd) OSLibWinSubclassWindow(OS2Hwnd,pOldWndProc);
790
791 fIsDestroyed = TRUE;
792
793 if(fDestroyWindowCalled == FALSE)
794 {//this window was destroyed because DestroyWindow was called for it's parent
795 //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
796 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
797 {
798 if(getParent())
799 {
800 /* Notify the parent window only */
801 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
802 }
803 else DebugInt3();
804 }
805 }
806 SendInternalMessageA(WM_DESTROY, 0, 0);
807 SendInternalMessageA(WM_NCDESTROY, 0, 0);
808
809 if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLibWinQueryObjectWindow()) OSLibWinDestroyWindow(hwndHorzScroll);
810 if (hwndVertScroll && OSLibWinQueryWindow(hwndVertScroll,QWOS_PARENT) == OSLibWinQueryObjectWindow()) OSLibWinDestroyWindow(hwndVertScroll);
811
812 if(getFirstChild() == NULL) {
813 delete this;
814 }
815 return 1;
816}
817//******************************************************************************
818//******************************************************************************
819ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
820{
821 if(fEnable) {
822 dwStyle &= ~WS_DISABLED;
823 }
824 else dwStyle |= WS_DISABLED;
825
826 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
827}
828//******************************************************************************
829//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
830//******************************************************************************
831ULONG Win32BaseWindow::MsgShow(BOOL fShow)
832{
833 if(fNoSizeMsg) {
834 return 1;
835 }
836
837 if(fShow) {
838 setStyle(getStyle() | WS_VISIBLE);
839 }
840 else setStyle(getStyle() & ~WS_VISIBLE);
841
842 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
843}
844//******************************************************************************
845//******************************************************************************
846ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
847{
848 if(fNoSizeMsg)
849 return 1;
850
851 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
852}
853//******************************************************************************
854//******************************************************************************
855ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
856{
857 if(fNoSizeMsg)
858 return 1;
859
860 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
861}
862//******************************************************************************
863//******************************************************************************
864ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
865{
866 dprintf(("MsgMove to (%d,%d)", x, y));
867 if(fNoSizeMsg)
868 return 1;
869
870 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
871}
872//******************************************************************************
873//******************************************************************************
874#if 0
875ULONG Win32BaseWindow::MsgMinMax()
876{
877
878}
879#endif
880//******************************************************************************
881//******************************************************************************
882ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
883{
884 // TODO: call TIMERPROC if not NULL
885 return SendInternalMessageA(WM_TIMER, TimerID, 0);
886}
887//******************************************************************************
888//******************************************************************************
889ULONG Win32BaseWindow::MsgSysTimer(ULONG TimerID)
890{
891 // TODO: call TIMERPROC if not NULL
892 return SendInternalMessageA(WM_SYSTIMER, TimerID, 0);
893}
894//******************************************************************************
895//******************************************************************************
896ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
897{
898 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
899 //window scrollbars send these messages
900 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
901}
902//******************************************************************************
903//******************************************************************************
904ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
905{
906 switch(cmd) {
907 case CMD_MENU:
908 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
909 case CMD_CONTROL:
910 return 0; //todo
911 case CMD_ACCELERATOR:
912 // this fit not really windows behavior.
913 // maybe TranslateAccelerator() is better
914 dprintf(("accelerator command"));
915 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
916 }
917 return 0;
918}
919//******************************************************************************
920//******************************************************************************
921ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
922{
923 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
924 dprintf(("MsgHitTest returned %x", lastHitTestVal));
925 return 1; //TODO: May need to change this
926}
927//******************************************************************************
928//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
929//******************************************************************************
930ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
931{
932 WORD fwSizeType = 0;
933
934 dwStyle &= ~(WS_MINIMIZE|WS_MAXIMIZE);
935 if(fMinimize) {
936 fwSizeType = SIZE_MINIMIZED;
937 dwStyle |= WS_MINIMIZE;
938 }
939 else
940 if(fMaximize) {
941 fwSizeType = SIZE_MAXIMIZED;
942 dwStyle |= WS_MAXIMIZE;
943 }
944 else fwSizeType = SIZE_RESTORED;
945
946 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
947}
948//******************************************************************************
949//******************************************************************************
950ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
951{
952 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
953
954
955 //According to SDK docs, if app returns FALSE & window is being deactivated,
956 //default processing is cancelled
957 //TODO: According to Wine we should proceed anyway if window is sysmodal
958 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
959 {
960 return 0;
961 }
962 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
963
964 curprocid = GetCurrentProcessId();
965 if(hwnd) {
966 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
967 }
968
969 if(curprocid != procidhwnd && fActivate) {
970 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
971 }
972 return rc;
973}
974//******************************************************************************
975//******************************************************************************
976ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
977{
978 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
979}
980//******************************************************************************
981//TODO: Is this correct and complete?
982//Add print screen, break & numlock
983//******************************************************************************
984void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
985{
986 switch(virtualkey) {
987 case VK_DOWN:
988 case VK_UP:
989 case VK_PRIOR:
990 case VK_NEXT:
991 case VK_END:
992 case VK_DIVIDE:
993 case VK_DELETE:
994 case VK_EXECUTE: //Numeric enter key?
995 case VK_HOME:
996 case VK_INSERT:
997 case VK_RCONTROL:
998 case VK_RMENU: //is this the right alt???
999 *lParam = *lParam | (1<<24);
1000 }
1001}
1002//******************************************************************************
1003//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
1004//******************************************************************************
1005ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
1006{
1007 ULONG lParam = 0;
1008
1009 lParam = repeatcnt;
1010 lParam |= (scancode << 16);
1011 setExtendedKey(vkey, &lParam);
1012
1013 if(keyflags & KEY_ALTDOWN)
1014 lParam |= (1<<29);
1015 if(keyflags & KEY_PREVDOWN)
1016 lParam |= (1<<30);
1017 if(keyflags & KEY_UP)
1018 lParam |= (1<<31);
1019 if(keyflags & KEY_DEADKEY) {
1020 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
1021 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
1022 }
1023 else {
1024 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
1025 return SendInternalMessageA(WM_CHAR, cmd, lParam);
1026 }
1027}
1028//******************************************************************************
1029//******************************************************************************
1030ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
1031{
1032 ULONG lParam=0;
1033
1034 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1035 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1036 // bit 24, 1=extended key
1037 // bit 25-28, reserved
1038 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
1039 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
1040 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
1041
1042 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
1043
1044 setExtendedKey(virtualKey, &lParam);
1045 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
1046}
1047//******************************************************************************
1048//******************************************************************************
1049ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1050{
1051 ULONG lParam=0;
1052
1053 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1054 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1055 // bit 24, 1=extended key
1056 // bit 25-28, reserved
1057 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
1058 if (keyWasPressed)
1059 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1060 // bit 31, transition state, always 0 for WM_KEYDOWN
1061
1062 setExtendedKey(virtualKey, &lParam);
1063
1064 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1065
1066 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
1067}
1068//******************************************************************************
1069//******************************************************************************
1070ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
1071{
1072 ULONG lParam=0;
1073
1074 lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
1075 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1076 // bit 24, 1=extended key
1077 // bit 25-28, reserved
1078 lParam |= 0 << 29; // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
1079 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
1080 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
1081
1082 setExtendedKey(virtualKey, &lParam);
1083 dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
1084
1085 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
1086}
1087//******************************************************************************
1088//******************************************************************************
1089ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1090{
1091 ULONG lParam=0;
1092
1093 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1094 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1095 // bit 24, 1=extended key
1096 // bit 25-28, reserved
1097 // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
1098 if (keyWasPressed)
1099 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1100 // bit 31, transition state, always 0 for WM_KEYDOWN
1101
1102 setExtendedKey(virtualKey, &lParam);
1103 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1104
1105 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
1106}
1107//******************************************************************************
1108//******************************************************************************
1109ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1110{
1111 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1112}
1113//******************************************************************************
1114//******************************************************************************
1115ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1116{
1117 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1118}
1119//******************************************************************************
1120//******************************************************************************
1121ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
1122{
1123 ULONG win32msg;
1124 ULONG win32ncmsg;
1125 BOOL fClick = FALSE;
1126
1127 if(ISMOUSE_CAPTURED()) {
1128 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_BUTTON, ncx, ncy, msg))
1129 return 0;
1130 }
1131
1132 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1133 switch(msg) {
1134 case BUTTON_LEFTDOWN:
1135 win32msg = WM_LBUTTONDOWN;
1136 win32ncmsg = WM_NCLBUTTONDOWN;
1137 fClick = TRUE;
1138 break;
1139 case BUTTON_LEFTUP:
1140 win32msg = WM_LBUTTONUP;
1141 win32ncmsg = WM_NCLBUTTONUP;
1142 break;
1143 case BUTTON_LEFTDBLCLICK:
1144 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1145 {
1146 win32msg = WM_LBUTTONDBLCLK;
1147 win32ncmsg = WM_NCLBUTTONDBLCLK;
1148 } else
1149 {
1150 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1151 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1152 }
1153 break;
1154 case BUTTON_RIGHTUP:
1155 win32msg = WM_RBUTTONUP;
1156 win32ncmsg = WM_NCRBUTTONUP;
1157 break;
1158 case BUTTON_RIGHTDOWN:
1159 win32msg = WM_RBUTTONDOWN;
1160 win32ncmsg = WM_NCRBUTTONDOWN;
1161 fClick = TRUE;
1162 break;
1163 case BUTTON_RIGHTDBLCLICK:
1164 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1165 {
1166 win32msg = WM_RBUTTONDBLCLK;
1167 win32ncmsg = WM_NCRBUTTONDBLCLK;
1168 } else
1169 {
1170 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1171 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1172 }
1173 break;
1174 case BUTTON_MIDDLEUP:
1175 win32msg = WM_MBUTTONUP;
1176 win32ncmsg = WM_NCMBUTTONUP;
1177 break;
1178 case BUTTON_MIDDLEDOWN:
1179 win32msg = WM_MBUTTONDOWN;
1180 win32ncmsg = WM_NCMBUTTONDOWN;
1181 fClick = TRUE;
1182 break;
1183 case BUTTON_MIDDLEDBLCLICK:
1184 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1185 {
1186 win32msg = WM_MBUTTONDBLCLK;
1187 win32ncmsg = WM_NCMBUTTONDBLCLK;
1188 } else
1189 {
1190 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1191 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1192 }
1193 break;
1194 default:
1195 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1196 return 1;
1197 }
1198
1199 if(fClick)
1200 {
1201 HWND hwndTop;
1202
1203 /* Activate the window if needed */
1204 if(isSubclassedOS2Wnd()) {
1205 Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
1206 if(parentwnd) {
1207 hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
1208 }
1209 else hwndTop = 0;
1210 }
1211 else hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
1212
1213 if (hwndTop && getWindowHandle() != GetActiveWindow())
1214 {
1215 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
1216 MAKELONG( HTCLIENT, win32msg ) );
1217
1218#if 0
1219 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1220 eatMsg = TRUE;
1221#endif
1222 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
1223 && hwndTop != GetForegroundWindow() )
1224 {
1225 ::SetActiveWindow(hwndTop);
1226 }
1227 }
1228 }
1229
1230 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1231
1232 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1233 if(lastHitTestVal != HTCLIENT) {
1234 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1235 }
1236 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1237}
1238//******************************************************************************
1239//******************************************************************************
1240ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1241{
1242 ULONG winstate = 0;
1243 ULONG setcursormsg = WM_MOUSEMOVE;
1244
1245 if(ISMOUSE_CAPTURED()) {
1246 POINT point = {x,y};
1247
1248 MapWindowPoints(getWindowHandle(), HWND_DESKTOP, &point, 1);
1249 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_MOVE, point.x, point.y, keystate))
1250 return 0;
1251 }
1252
1253 if(keystate & WMMOVE_LBUTTON)
1254 winstate |= MK_LBUTTON;
1255 if(keystate & WMMOVE_RBUTTON)
1256 winstate |= MK_RBUTTON;
1257 if(keystate & WMMOVE_MBUTTON)
1258 winstate |= MK_MBUTTON;
1259 if(keystate & WMMOVE_SHIFT)
1260 winstate |= MK_SHIFT;
1261 if(keystate & WMMOVE_CTRL)
1262 winstate |= MK_CONTROL;
1263
1264 if(lastHitTestVal != HTCLIENT) {
1265 setcursormsg = WM_NCMOUSEMOVE;
1266 }
1267 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1268 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1269
1270 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1271 if(lastHitTestVal != HTCLIENT) {
1272 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1273 }
1274 return SendInternalMessageA(WM_MOUSEMOVE, winstate, MAKELONG(x, y));
1275}
1276//******************************************************************************
1277//TODO: Depending on menu type, we should send WM_INITMENU or WM_INITPOPUPMENU
1278//TODO: PM sends it for each submenu that gets activated; Windows only for the first
1279// submenu; once the menu bar is active, moving the cursor doesn't generate other
1280// WM_INITMENU msgs. Not really a problem, but might need to fix this later on.
1281//******************************************************************************
1282void Win32BaseWindow::MsgInitMenu(HWND hMenu)
1283{
1284 SendInternalMessageA(WM_INITMENU, (WPARAM)hMenu, 0);
1285}
1286//******************************************************************************
1287//******************************************************************************
1288ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1289{
1290 if (select && isIcon)
1291 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1292 else
1293 return SendInternalMessageA(WM_PAINT, 0, 0);
1294}
1295//******************************************************************************
1296//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1297// (or are we simply erasing too much here)
1298//******************************************************************************
1299ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1300{
1301 ULONG rc;
1302 HDC hdcErase = hdc;
1303
1304 if (hdcErase == 0)
1305 hdcErase = O32_GetDC(OS2Hwnd);
1306
1307 if(isIcon)
1308 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1309 else
1310 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1311 if (hdc == 0)
1312 O32_ReleaseDC(OS2Hwnd, hdcErase);
1313 return (rc);
1314}
1315//******************************************************************************
1316//******************************************************************************
1317ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1318{
1319 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1320}
1321//******************************************************************************
1322//******************************************************************************
1323ULONG Win32BaseWindow::MsgGetTextLength()
1324{
1325 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1326}
1327//******************************************************************************
1328//******************************************************************************
1329char *Win32BaseWindow::MsgGetText()
1330{
1331 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1332 return windowNameA;
1333}
1334//******************************************************************************
1335//******************************************************************************
1336ULONG Win32BaseWindow::MsgContextMenu(ULONG x,ULONG y)
1337{
1338 return SendInternalMessageA(WM_CONTEXTMENU,Win32Hwnd,MAKELPARAM(x,y));
1339}
1340//******************************************************************************
1341//******************************************************************************
1342BOOL Win32BaseWindow::isMDIClient()
1343{
1344 return FALSE;
1345}
1346//******************************************************************************
1347//******************************************************************************
1348BOOL Win32BaseWindow::isMDIChild()
1349{
1350 return FALSE;
1351}
1352//******************************************************************************
1353//TODO: Not complete
1354//******************************************************************************
1355BOOL Win32BaseWindow::isFrameWindow()
1356{
1357// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1358 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1359 return TRUE;
1360
1361 return FALSE;
1362}
1363//******************************************************************************
1364//******************************************************************************
1365SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1366{
1367 switch(nBar)
1368 {
1369 case SB_HORZ:
1370 return horzScrollInfo;
1371
1372 case SB_VERT:
1373 return vertScrollInfo;
1374 }
1375
1376 return NULL;
1377}
1378//******************************************************************************
1379//******************************************************************************
1380VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1381{
1382 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1383}
1384//******************************************************************************
1385//******************************************************************************
1386BOOL Win32BaseWindow::showScrollBars(BOOL changeHorz,BOOL changeVert,BOOL fShow)
1387{
1388 BOOL rc = TRUE;
1389 DWORD flags = 0;
1390
1391 if (fShow)
1392 {
1393 BOOL createHorz = FALSE,createVert = FALSE;
1394 BOOL showHorz = FALSE,showVert = FALSE;
1395
1396 if (changeHorz)
1397 {
1398 if (!hwndHorzScroll)
1399 createHorz = TRUE;
1400 else
1401 showHorz = TRUE;
1402 }
1403
1404 if (changeVert)
1405 {
1406 if (!hwndVertScroll)
1407 createVert = TRUE;
1408 else
1409 showVert = TRUE;
1410 }
1411
1412 if (createHorz || createVert)
1413 {
1414 if (createHorz && !horzScrollInfo)
1415 {
1416 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1417 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1418 horzScrollInfo->MaxVal = 100;
1419 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1420 }
1421
1422 if (createVert && !vertScrollInfo)
1423 {
1424 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1425 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1426 vertScrollInfo->MaxVal = 100;
1427 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1428 }
1429
1430 rc = FrameCreateScrollBars(this,createHorz,createVert,FALSE,&flags);
1431
1432 if (!rc) return FALSE;
1433 if (createHorz) dwStyle |= WS_HSCROLL;
1434 if (createVert) dwStyle |= WS_VSCROLL;
1435 }
1436
1437 if (showVert || showHorz)
1438 {
1439 DWORD newFlags;
1440
1441 rc = FrameShowScrollBars(this,showHorz,showVert,fShow,FALSE,&newFlags);
1442 flags |= newFlags;
1443 if (rc)
1444 {
1445 if (showHorz) dwStyle |= WS_HSCROLL;
1446 if (showVert) dwStyle |= WS_VSCROLL;
1447 }
1448 }
1449
1450 if (flags) FrameUpdateFrame(this,flags);
1451 } else
1452 {
1453 rc = FrameShowScrollBars(this,changeHorz && hwndHorzScroll,changeVert && hwndVertScroll,fShow,TRUE);
1454
1455 if (rc)
1456 {
1457 if (changeHorz) dwStyle &= ~WS_HSCROLL;
1458 if (changeVert) dwStyle &= ~WS_VSCROLL;
1459 }
1460 }
1461
1462 return rc;
1463}
1464/***********************************************************************
1465 * NC_HandleSysCommand
1466 *
1467 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1468 *
1469 * TODO: Not done (see #if 0)
1470 */
1471LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1472{
1473 UINT uCommand = wParam & 0xFFF0;
1474
1475 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1476 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1477
1478 switch (uCommand)
1479 {
1480#if 0
1481 case SC_SIZE:
1482 case SC_MOVE:
1483 NC_DoSizeMove( hwnd, wParam );
1484 break;
1485#endif
1486
1487 case SC_MINIMIZE:
1488 ShowWindow(SW_MINIMIZE);
1489 break;
1490
1491 case SC_MAXIMIZE:
1492 ShowWindow(SW_MAXIMIZE);
1493 break;
1494
1495 case SC_RESTORE:
1496 ShowWindow(SW_RESTORE);
1497 break;
1498
1499 case SC_CLOSE:
1500 return SendInternalMessageA(WM_CLOSE, 0, 0);
1501
1502#if 0
1503 case SC_VSCROLL:
1504 case SC_HSCROLL:
1505 NC_TrackScrollBar( hwnd, wParam, pt32 );
1506 break;
1507
1508 case SC_MOUSEMENU:
1509 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1510 break;
1511
1512 case SC_KEYMENU:
1513 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1514 break;
1515
1516 case SC_TASKLIST:
1517 WinExec( "taskman.exe", SW_SHOWNORMAL );
1518 break;
1519
1520 case SC_SCREENSAVE:
1521 if (wParam == SC_ABOUTWINE)
1522 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1523 else
1524 if (wParam == SC_PUTMARK)
1525 dprintf(("Mark requested by user\n"));
1526 break;
1527
1528 case SC_HOTKEY:
1529 case SC_ARRANGE:
1530 case SC_NEXTWINDOW:
1531 case SC_PREVWINDOW:
1532 break;
1533#endif
1534 }
1535 return 0;
1536}
1537//******************************************************************************
1538//******************************************************************************
1539LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1540{
1541 //SvL: Set background color to default button color (not window (white))
1542 if(ctlType == CTLCOLOR_BTN)
1543 {
1544 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1545 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1546 return GetSysColorBrush(COLOR_BTNFACE);
1547 }
1548 //SvL: Set background color to default dialog color if window is dialog
1549 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1550 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1551 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1552 return GetSysColorBrush(COLOR_BTNFACE);
1553 }
1554
1555 if( ctlType == CTLCOLOR_SCROLLBAR)
1556 {
1557 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1558 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1559 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1560 SetBkColor( hdc, bk);
1561
1562//TODO?
1563#if 0
1564 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1565 * we better use 0x55aa bitmap brush to make scrollbar's background
1566 * look different from the window background.
1567 */
1568 if (bk == GetSysColor(COLOR_WINDOW)) {
1569 return CACHE_GetPattern55AABrush();
1570 }
1571#endif
1572 UnrealizeObject( hb );
1573 return (LRESULT)hb;
1574 }
1575
1576 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1577
1578 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1579 {
1580 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1581 }
1582 else
1583 {
1584 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1585 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1586 }
1587 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1588}
1589//******************************************************************************
1590//******************************************************************************
1591LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1592{
1593 switch(Msg)
1594 {
1595 case WM_CLOSE:
1596 DestroyWindow();
1597 return 0;
1598
1599 case WM_GETTEXTLENGTH:
1600 return wndNameLength;
1601
1602 case WM_GETTEXT:
1603 if (!lParam || !wParam) return 0;
1604 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1605 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1606 return min(wndNameLength, wParam);
1607
1608 case WM_SETTEXT:
1609 {
1610 LPCSTR lpsz = (LPCSTR)lParam;
1611
1612 if(windowNameA) free(windowNameA);
1613 if(windowNameW) free(windowNameW);
1614
1615 if (lParam)
1616 {
1617 wndNameLength = strlen(lpsz);
1618 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1619 strcpy(windowNameA, lpsz);
1620 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1621 lstrcpyAtoW(windowNameW, windowNameA);
1622 }
1623 else
1624 {
1625 windowNameA = NULL;
1626 windowNameW = NULL;
1627 wndNameLength = 0;
1628 }
1629 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1630
1631 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1632 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1633
1634 return TRUE;
1635 }
1636
1637 case WM_SETREDRAW:
1638 {
1639 DWORD oldStyle = getStyle();
1640
1641 if(wParam)
1642 setStyle(getStyle() | WS_VISIBLE);
1643 else setStyle(getStyle() & ~WS_VISIBLE);
1644
1645 updateWindowStyle(getExStyle(), oldStyle);
1646
1647 return 0; //TODO
1648 }
1649 case WM_NCCREATE:
1650 return(TRUE);
1651
1652 case WM_NCCALCSIZE:
1653 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1654
1655 case WM_CTLCOLORMSGBOX:
1656 case WM_CTLCOLOREDIT:
1657 case WM_CTLCOLORLISTBOX:
1658 case WM_CTLCOLORBTN:
1659 case WM_CTLCOLORDLG:
1660 case WM_CTLCOLORSTATIC:
1661 case WM_CTLCOLORSCROLLBAR:
1662 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1663
1664 case WM_CTLCOLOR:
1665 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1666
1667 case WM_VKEYTOITEM:
1668 case WM_CHARTOITEM:
1669 return -1;
1670
1671 case WM_PARENTNOTIFY:
1672 return 0;
1673
1674 case WM_MOUSEACTIVATE:
1675 {
1676 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1677 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1678 {
1679 if(getParent()) {
1680 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1681 if(rc) return rc;
1682 }
1683 }
1684 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1685 }
1686 case WM_SETCURSOR:
1687 {
1688 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1689 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1690 {
1691 if(getParent()) {
1692 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1693 if(rc) return rc;
1694 }
1695 }
1696 if (wParam == Win32Hwnd)
1697 {
1698 HCURSOR hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1699
1700 if (hCursor) SetCursor(hCursor);
1701 return 1;
1702 } else return 0;
1703 }
1704 case WM_MOUSEMOVE:
1705 return 0; //we do our own cursor handling
1706
1707 case WM_WINDOWPOSCHANGED:
1708 {
1709
1710/* undocumented SWP flags - from SDK 3.1 */
1711#define SWP_NOCLIENTSIZE 0x0800
1712#define SWP_NOCLIENTMOVE 0x1000
1713
1714 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1715 WPARAM wp = SIZE_RESTORED;
1716
1717 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1718 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1719
1720 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1721 {
1722 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1723 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1724
1725 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1726 rectClient.bottom - rectClient.top));
1727 }
1728 return 0;
1729 }
1730 case WM_WINDOWPOSCHANGING:
1731 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1732
1733 case WM_ERASEBKGND:
1734 case WM_ICONERASEBKGND:
1735 {
1736 RECT rect;
1737 int rc;
1738
1739 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1740
1741 rc = GetClipBox( (HDC)wParam, &rect );
1742 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1743 {
1744 HBRUSH hBrush = windowClass->getBackgroundBrush();
1745
1746 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1)) hBrush = GetSysColorBrush(hBrush-1);
1747
1748 FillRect( (HDC)wParam, &rect, hBrush);
1749 }
1750
1751 return 1;
1752 }
1753 case WM_PAINTICON:
1754 case WM_PAINT:
1755 {
1756 PAINTSTRUCT ps;
1757 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1758 if( hdc )
1759 {
1760 if( (getStyle() & WS_MINIMIZE) && getWindowClass()->getIcon())
1761 {
1762 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1763 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1764 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1765 DrawIcon(hdc, x, y, getWindowClass()->getIcon() );
1766 }
1767 EndPaint(getWindowHandle(), &ps );
1768 }
1769 return 0;
1770 }
1771
1772 case WM_GETDLGCODE:
1773 return 0;
1774
1775 case WM_NCLBUTTONDOWN:
1776 case WM_NCLBUTTONUP:
1777 case WM_NCLBUTTONDBLCLK:
1778 case WM_NCRBUTTONUP:
1779 case WM_NCRBUTTONDOWN:
1780 case WM_NCRBUTTONDBLCLK:
1781 case WM_NCMBUTTONDOWN:
1782 case WM_NCMBUTTONUP:
1783 case WM_NCMBUTTONDBLCLK:
1784 return 0; //TODO: Send WM_SYSCOMMAND if required
1785
1786 case WM_NCHITTEST: //TODO: Calculate position of
1787 return HTCLIENT;
1788
1789 case WM_SYSCOMMAND:
1790 {
1791 POINT point;
1792
1793 point.x = LOWORD(lParam);
1794 point.y = HIWORD(lParam);
1795 return HandleSysCommand(wParam, &point);
1796 }
1797
1798 case WM_SYSKEYDOWN:
1799 if(wParam == VK_F4) /* try to close the window */
1800 {
1801 Win32BaseWindow *window = GetTopParent();
1802 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1803 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1804 }
1805
1806 Win32BaseWindow *siblingWindow;
1807 HWND sibling;
1808 char nameBuffer [40], mnemonic;
1809 int nameLength;
1810
1811 GetWindowTextA (nameBuffer, 40);
1812
1813 // search all sibling to see it this key is their mnemonic
1814 sibling = GetWindow (GW_HWNDFIRST);
1815 while (sibling != 0) {
1816 siblingWindow = GetWindowFromHandle (sibling);
1817 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1818
1819 // find the siblings mnemonic
1820 mnemonic = '\0';
1821 for (int i=0 ; i<nameLength ; i++) {
1822 if (nameBuffer [i] == '&') {
1823 mnemonic = nameBuffer [i+1];
1824 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1825 mnemonic -= 32; // make it uppercase
1826 break; // stop searching
1827 }
1828 }
1829
1830 // key matches siblings mnemonic, send mouseclick
1831 if (mnemonic == (char) wParam) {
1832 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1833 }
1834
1835 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1836 }
1837
1838 return 0;
1839
1840 case WM_QUERYOPEN:
1841 case WM_QUERYENDSESSION:
1842 return 1;
1843
1844 case WM_NOTIFYFORMAT:
1845 if (IsWindowUnicode()) return NFR_UNICODE;
1846 else return NFR_ANSI;
1847
1848 case WM_SETICON:
1849 case WM_GETICON:
1850 {
1851 LRESULT result = 0;
1852 if (!windowClass) return result;
1853 int index = GCL_HICON;
1854
1855 if (wParam == ICON_SMALL)
1856 index = GCL_HICONSM;
1857
1858 result = windowClass->getClassLongA(index);
1859
1860 if (Msg == WM_SETICON)
1861 windowClass->setClassLongA(index, lParam);
1862
1863 return result;
1864 }
1865 case WM_NOTIFY:
1866 return 0; //comctl32 controls expect this
1867
1868 default:
1869 if(Msg > WM_USER) {
1870 return 0;
1871 }
1872 return 1;
1873 }
1874}
1875//******************************************************************************
1876//******************************************************************************
1877LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1878{
1879 switch(Msg)
1880 {
1881 case WM_GETTEXTLENGTH:
1882 return wndNameLength;
1883
1884 case WM_GETTEXT:
1885 if (!lParam || !wParam) return 0;
1886 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1887 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1888 return min(wndNameLength,wParam);
1889
1890 case WM_SETTEXT:
1891 {
1892 LPWSTR lpsz = (LPWSTR)lParam;
1893
1894 if(windowNameA) free(windowNameA);
1895 if(windowNameW) free(windowNameW);
1896
1897 if (lParam)
1898 {
1899 wndNameLength = lstrlenW(lpsz);
1900 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1901 lstrcpyWtoA(windowNameA,lpsz);
1902 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1903 lstrcpyW(windowNameW,lpsz);
1904 }
1905 else
1906 {
1907 windowNameA = NULL;
1908 windowNameW = NULL;
1909 wndNameLength = 0;
1910 }
1911
1912 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1913 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1914
1915 return TRUE;
1916 }
1917
1918 default:
1919 return DefWindowProcA(Msg, wParam, lParam);
1920 }
1921}
1922//******************************************************************************
1923//******************************************************************************
1924LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1925{
1926 POSTMSG_PACKET *packet;
1927
1928 //if the destination window is created by this process & thread, call window proc directly
1929 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1930 return SendInternalMessageA(Msg, wParam, lParam);
1931 }
1932 //otherwise use WinSendMsg to send it to the right process/thread
1933 packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
1934 packet->Msg = Msg;
1935 packet->wParam = wParam;
1936 packet->lParam = lParam;
1937 packet->fUnicode = FALSE;
1938 return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
1939}
1940//******************************************************************************
1941//******************************************************************************
1942LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1943{
1944 POSTMSG_PACKET *packet;
1945
1946 //if the destination window is created by this process & thread, call window proc directly
1947 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1948 return SendInternalMessageA(Msg, wParam, lParam);
1949 }
1950 //otherwise use WinSendMsg to send it to the right process/thread
1951 packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
1952 packet->Msg = Msg;
1953 packet->wParam = wParam;
1954 packet->lParam = lParam;
1955 packet->fUnicode = TRUE;
1956 return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
1957}
1958//******************************************************************************
1959//Called as a result of an OS/2 message or called from a class method
1960//******************************************************************************
1961LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1962{
1963 LRESULT rc;
1964 BOOL fInternalMsgBackup = fInternalMsg;
1965
1966 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1967
1968 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1969
1970 fInternalMsg = TRUE;
1971 switch(Msg)
1972 {
1973 case WM_CREATE:
1974 {
1975 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1976 dprintf(("WM_CREATE returned -1\n"));
1977 rc = -1; //don't create window
1978 break;
1979 }
1980 rc = 0;
1981 break;
1982 }
1983 case WM_LBUTTONDOWN:
1984 case WM_MBUTTONDOWN:
1985 case WM_RBUTTONDOWN:
1986 NotifyParent(Msg, wParam, lParam);
1987 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1988 break;
1989
1990 case WM_DESTROY:
1991 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1992 break;
1993
1994 default:
1995 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1996 break;
1997 }
1998 fInternalMsg = fInternalMsgBackup;
1999 return rc;
2000}
2001//******************************************************************************
2002//Called as a result of an OS/2 message or called from a class method
2003//******************************************************************************
2004LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2005{
2006 LRESULT rc;
2007 BOOL fInternalMsgBackup = fInternalMsg;
2008
2009 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2010
2011 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2012
2013 fInternalMsg = TRUE;
2014 switch(Msg)
2015 {
2016 case WM_CREATE:
2017 {
2018 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2019 dprintf(("WM_CREATE returned -1\n"));
2020 rc = -1; //don't create window
2021 break;
2022 }
2023 rc = 0;
2024 break;
2025 }
2026 case WM_LBUTTONDOWN:
2027 case WM_MBUTTONDOWN:
2028 case WM_RBUTTONDOWN:
2029 NotifyParent(Msg, wParam, lParam);
2030 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2031 break;
2032
2033 case WM_DESTROY:
2034 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2035 break;
2036 default:
2037 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2038 break;
2039 }
2040 fInternalMsg = fInternalMsgBackup;
2041 return rc;
2042}
2043//******************************************************************************
2044//******************************************************************************
2045void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2046{
2047 CWPSTRUCT cwp;
2048
2049 cwp.lParam = lParam;
2050 cwp.wParam = wParam;
2051 cwp.message = Msg;
2052 cwp.hwnd = getWindowHandle();
2053
2054 switch(hooktype) {
2055 case WH_CALLWNDPROC:
2056 if(fUnicode) {
2057 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2058 }
2059 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2060 break;
2061 }
2062}
2063//******************************************************************************
2064//******************************************************************************
2065BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
2066{
2067 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2068
2069 packet->Msg = msg;
2070 packet->wParam = wParam;
2071 packet->lParam = lParam;
2072 packet->fUnicode = FALSE;
2073 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2074}
2075//******************************************************************************
2076//******************************************************************************
2077BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
2078{
2079 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2080
2081 packet->Msg = msg;
2082 packet->wParam = wParam;
2083 packet->lParam = lParam;
2084 packet->fUnicode = TRUE;
2085 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2086}
2087//******************************************************************************
2088//******************************************************************************
2089BOOL Win32BaseWindow::PostThreadMessageA(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2090{
2091 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2092
2093 packet->Msg = msg;
2094 packet->wParam = wParam;
2095 packet->lParam = lParam;
2096 packet->fUnicode = FALSE;
2097 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2098}
2099//******************************************************************************
2100//******************************************************************************
2101BOOL Win32BaseWindow::PostThreadMessageW(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2102{
2103 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2104
2105 packet->Msg = msg;
2106 packet->wParam = wParam;
2107 packet->lParam = lParam;
2108 packet->fUnicode = TRUE;
2109 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2110}
2111//******************************************************************************
2112//******************************************************************************
2113ULONG Win32BaseWindow::PostMessage(POSTMSG_PACKET *packet)
2114{
2115 ULONG rc;
2116
2117 if(packet == NULL)
2118 return 0;
2119
2120 if(packet->fUnicode) {
2121 rc = SendInternalMessageW(packet->Msg, packet->wParam, packet->lParam);
2122 }
2123 else rc = SendInternalMessageA(packet->Msg, packet->wParam, packet->lParam);
2124
2125 free(packet);
2126 return rc;
2127}
2128//******************************************************************************
2129//TODO: Do this more efficiently
2130//******************************************************************************
2131LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2132{
2133 Win32BaseWindow *window;
2134 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2135
2136 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2137
2138 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2139 window = GetWindowFromHandle(hwnd++);
2140 if(window) {
2141 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2142 {
2143
2144 if(type == BROADCAST_SEND) {
2145 window->SendInternalMessageA(msg, wParam, lParam);
2146 }
2147 else window->PostMessageA(msg, wParam, lParam);
2148 }
2149 }
2150 }
2151 return 0;
2152}
2153//******************************************************************************
2154//TODO: Do this more efficiently
2155//******************************************************************************
2156LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2157{
2158 Win32BaseWindow *window;
2159 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2160
2161
2162 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2163
2164 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2165 window = GetWindowFromHandle(hwnd++);
2166 if(window) {
2167 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2168 {
2169
2170 if(type == BROADCAST_SEND) {
2171 window->SendInternalMessageW(msg, wParam, lParam);
2172 }
2173 else window->PostMessageW(msg, wParam, lParam);
2174 }
2175 }
2176 }
2177 return 0;
2178}
2179//******************************************************************************
2180//******************************************************************************
2181void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2182{
2183 Win32BaseWindow *window = this;
2184 Win32BaseWindow *parentwindow;
2185
2186 while(window)
2187 {
2188 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2189 {
2190 /* Notify the parent window only */
2191 parentwindow = window->getParent();
2192 if(parentwindow) {
2193 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2194 }
2195 }
2196 else break;
2197
2198 window = parentwindow;
2199 }
2200}
2201//******************************************************************************
2202//******************************************************************************
2203BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
2204{
2205
2206 dprintf(("SetMenu %x", hMenu));
2207 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
2208 if(OS2HwndMenu == 0) {
2209 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
2210 return FALSE;
2211 }
2212 return TRUE;
2213}
2214//******************************************************************************
2215//******************************************************************************
2216BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
2217{
2218 Win32Resource *winres = (Win32Resource *)hAccel;
2219 HANDLE accelhandle;
2220
2221 if(HIWORD(hAccel) == 0) {
2222 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
2223 SetLastError(ERROR_INVALID_PARAMETER);
2224 return FALSE;
2225 }
2226 acceltableResource = winres;
2227 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
2228 winres->setOS2Handle(accelhandle);
2229 return(accelhandle != 0);
2230}
2231//******************************************************************************
2232//******************************************************************************
2233BOOL Win32BaseWindow::SetIcon(HICON hIcon)
2234{
2235 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
2236 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
2237//TODO: Wine does't send these. Correct?
2238// SendInternalMessageA(WM_SETICON, ICON_BIG, hIcon);
2239 return TRUE;
2240 }
2241 return FALSE;
2242}
2243//******************************************************************************
2244//******************************************************************************
2245BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2246{
2247 ULONG showstate = 0;
2248 HWND hWinAfter;
2249
2250 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2251#if 1
2252 if (flags & WIN_NEED_SIZE)
2253 {
2254 /* should happen only in CreateWindowEx() */
2255 int wParam = SIZE_RESTORED;
2256
2257 flags &= ~WIN_NEED_SIZE;
2258 if (dwStyle & WS_MAXIMIZE)
2259 wParam = SIZE_MAXIMIZED;
2260 else
2261 if (dwStyle & WS_MINIMIZE)
2262 wParam = SIZE_MINIMIZED;
2263
2264 SendInternalMessageA(WM_SIZE, wParam,
2265 MAKELONG(rectClient.right-rectClient.left,
2266 rectClient.bottom-rectClient.top));
2267 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2268 }
2269#else
2270 if(fFirstShow) {
2271 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
2272 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
2273 MAKELONG(rectClient.right-rectClient.left,
2274 rectClient.bottom-rectClient.top));
2275 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2276
2277 }
2278 fFirstShow = FALSE;
2279 }
2280#endif
2281 switch(nCmdShow)
2282 {
2283 case SW_SHOW:
2284 case SW_SHOWDEFAULT: //todo
2285 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2286 break;
2287 case SW_HIDE:
2288 showstate = SWPOS_HIDE;
2289 break;
2290 case SW_RESTORE:
2291 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2292 break;
2293 case SW_MINIMIZE:
2294 showstate = SWPOS_MINIMIZE;
2295 break;
2296 case SW_SHOWMAXIMIZED:
2297 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2298 break;
2299 case SW_SHOWMINIMIZED:
2300 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2301 break;
2302 case SW_SHOWMINNOACTIVE:
2303 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2304 break;
2305 case SW_SHOWNA:
2306 showstate = SWPOS_SHOW;
2307 break;
2308 case SW_SHOWNOACTIVATE:
2309 showstate = SWPOS_SHOW;
2310 break;
2311 case SW_SHOWNORMAL:
2312 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2313 break;
2314 }
2315
2316 /* We can't activate a child window (WINE) */
2317 if(getStyle() & WS_CHILD)
2318 showstate &= ~SWPOS_ACTIVATE;
2319
2320 if(showstate & SWPOS_SHOW) {
2321 setStyle(getStyle() | WS_VISIBLE);
2322 }
2323 else setStyle(getStyle() & ~WS_VISIBLE);
2324
2325 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2326
2327 return rc;
2328}
2329//******************************************************************************
2330//******************************************************************************
2331BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2332{
2333 BOOL rc = FALSE;
2334 Win32BaseWindow *window;
2335 HWND hParent = 0;
2336
2337 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2338
2339 if (fuFlags &
2340 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2341 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2342 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2343 SWP_NOOWNERZORDER))
2344 {
2345 return FALSE;
2346 }
2347
2348 WINDOWPOS wpos;
2349 SWP swp, swpOld;
2350
2351 wpos.flags = fuFlags;
2352 wpos.cy = cy;
2353 wpos.cx = cx;
2354 wpos.x = x;
2355 wpos.y = y;
2356 wpos.hwndInsertAfter = hwndInsertAfter;
2357 wpos.hwnd = getWindowHandle();
2358
2359 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2360 {
2361 if (isChild())
2362 {
2363 Win32BaseWindow *windowParent = getParent();
2364 if(windowParent) {
2365 hParent = getParent()->getOS2WindowHandle();
2366 }
2367 else dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2368 }
2369 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2370 }
2371
2372 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2373 if (swp.fl == 0)
2374 return TRUE;
2375
2376// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2377 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2378 {
2379 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2380 if(wndBehind) {
2381 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2382 }
2383 else {
2384 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2385 swp.hwndInsertBehind = 0;
2386 }
2387 }
2388#if 0
2389 if (isFrameWindow())
2390 {
2391 if (!isChild())
2392 {
2393 POINT maxSize, maxPos, minTrack, maxTrack;
2394
2395 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2396
2397 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2398 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2399 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2400 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2401 }
2402 swp.hwnd = OS2HwndFrame;
2403 }
2404 else
2405#endif
2406 swp.hwnd = OS2HwndFrame;
2407
2408 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2409
2410 rc = OSLibWinSetMultWindowPos(&swp, 1);
2411
2412 if (rc == FALSE)
2413 {
2414 dprintf(("OSLibWinSetMultWindowPos failed!"));
2415 }
2416 else
2417 {
2418 if (fuFlags & SWP_FRAMECHANGED_W)
2419 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2420 }
2421
2422 return (rc);
2423}
2424//******************************************************************************
2425//TODO: WPF_RESTOREMAXIMIZED
2426//******************************************************************************
2427BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2428{
2429 if(isFrameWindow())
2430 {
2431 // Set the minimized position
2432 if (winpos->flags & WPF_SETMINPOSITION)
2433 {
2434 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2435 }
2436
2437 //TODO: Max position
2438
2439 // Set the new restore position.
2440 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2441 }
2442
2443 return ShowWindow(winpos->showCmd);
2444}
2445//******************************************************************************
2446//Also destroys all the child windows (destroy children first, parent last)
2447//******************************************************************************
2448BOOL Win32BaseWindow::DestroyWindow()
2449{
2450 /* Call hooks */
2451 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2452 {
2453 return FALSE;
2454 }
2455
2456 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2457 {
2458 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2459 /* FIXME: clean up palette - see "Internals" p.352 */
2460 }
2461
2462 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2463 {
2464 if(getParent())
2465 {
2466 /* Notify the parent window only */
2467 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2468 if( !::IsWindow(getWindowHandle()) )
2469 {
2470 return TRUE;
2471 }
2472 }
2473 else DebugInt3();
2474 }
2475 fDestroyWindowCalled = TRUE;
2476 return OSLibWinDestroyWindow(OS2HwndFrame);
2477}
2478//******************************************************************************
2479//******************************************************************************
2480Win32BaseWindow *Win32BaseWindow::getParent()
2481{
2482 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
2483 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2484}
2485//******************************************************************************
2486//******************************************************************************
2487HWND Win32BaseWindow::GetParent()
2488{
2489 Win32BaseWindow *wndparent;
2490
2491 if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
2492 {
2493 return 0;
2494 }
2495 wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
2496
2497 return (wndparent) ? wndparent->getWindowHandle() : 0;
2498}
2499//******************************************************************************
2500//******************************************************************************
2501HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2502{
2503 HWND oldhwnd;
2504 Win32BaseWindow *newparent;
2505
2506 if(getParent()) {
2507 oldhwnd = getParent()->getWindowHandle();
2508 getParent()->RemoveChild(this);
2509 }
2510 else oldhwnd = 0;
2511
2512 newparent = GetWindowFromHandle(hwndNewParent);
2513 if(newparent)
2514 {
2515 setParent(newparent);
2516 getParent()->AddChild(this);
2517 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2518 return oldhwnd;
2519 }
2520 else {
2521 setParent(windowDesktop);
2522 windowDesktop->AddChild(this);
2523 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2524 return oldhwnd;
2525 }
2526}
2527//******************************************************************************
2528//******************************************************************************
2529BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2530{
2531 if(getParent()) {
2532 return getParent()->getWindowHandle() == hwndParent;
2533 }
2534 else return 0;
2535}
2536//******************************************************************************
2537//******************************************************************************
2538HWND Win32BaseWindow::GetTopWindow()
2539{
2540 return GetWindow(GW_CHILD);
2541}
2542//******************************************************************************
2543// Get the top-level parent for a child window.
2544//******************************************************************************
2545Win32BaseWindow *Win32BaseWindow::GetTopParent()
2546{
2547 Win32BaseWindow *window = this;
2548
2549 while(window && (window->getStyle() & WS_CHILD))
2550 {
2551 window = window->getParent();
2552 }
2553 return window;
2554}
2555//******************************************************************************
2556//Don't call WinUpdateWindow as that one also updates the child windows
2557//Also need to send WM_PAINT directly to the window procedure, which doesn't
2558//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2559//******************************************************************************
2560BOOL Win32BaseWindow::UpdateWindow()
2561{
2562 RECT rect;
2563
2564 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2565 {//update region not empty
2566 HDC hdc;
2567
2568 hdc = O32_GetDC(OS2Hwnd);
2569 if (isIcon)
2570 {
2571 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2572 SendInternalMessageA(WM_PAINTICON, 0, 0);
2573 }
2574 else
2575 {
2576 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2577 SendInternalMessageA(WM_PAINT, 0, 0);
2578 }
2579 O32_ReleaseDC(OS2Hwnd, hdc);
2580 }
2581 return TRUE;
2582}
2583//******************************************************************************
2584//******************************************************************************
2585BOOL Win32BaseWindow::IsIconic()
2586{
2587 return OSLibWinIsIconic(OS2Hwnd);
2588}
2589//******************************************************************************
2590//TODO: Should not enumerate children that are created during the enumeration!
2591//******************************************************************************
2592BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2593{
2594 BOOL rc = TRUE;
2595 HWND hwnd;
2596 Win32BaseWindow *prevchild = 0, *child = 0;
2597
2598 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2599 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2600 {
2601 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2602 hwnd = child->getWindowHandle();
2603 if(child->getOwner()) {
2604 continue; //shouldn't have an owner (Wine)
2605 }
2606 if(lpfn(hwnd, lParam) == FALSE)
2607 {
2608 rc = FALSE;
2609 break;
2610 }
2611 //check if the window still exists
2612 if(!::IsWindow(hwnd))
2613 {
2614 child = prevchild;
2615 continue;
2616 }
2617 if(child->getFirstChild() != NULL)
2618 {
2619 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2620 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2621 {
2622 rc = FALSE;
2623 break;
2624 }
2625 }
2626 prevchild = child;
2627 }
2628 return rc;
2629}
2630//******************************************************************************
2631//Enumerate first-level children only and check thread id
2632//******************************************************************************
2633BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2634{
2635 Win32BaseWindow *child = 0;
2636 ULONG tid, pid;
2637 BOOL rc;
2638 HWND hwnd;
2639
2640 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2641
2642 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2643 {
2644 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2645
2646 if(dwThreadId == tid) {
2647 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2648 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2649 break;
2650 }
2651 }
2652 }
2653 return TRUE;
2654}
2655//******************************************************************************
2656//Enumerate first-level children only
2657//******************************************************************************
2658BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2659{
2660 Win32BaseWindow *child = 0;
2661 BOOL rc;
2662 HWND hwnd;
2663
2664 dprintf(("EnumWindows %x %x", lpfn, lParam));
2665
2666 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2667 {
2668 hwnd = child->getWindowHandle();
2669
2670 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2671 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2672 break;
2673 }
2674 }
2675 return TRUE;
2676}
2677//******************************************************************************
2678//******************************************************************************
2679Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2680{
2681 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2682 {
2683 if (child->getWindowId() == id)
2684 {
2685 return child;
2686 }
2687 }
2688 return 0;
2689}
2690//******************************************************************************
2691//TODO:
2692//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2693//the current process owns them.
2694//******************************************************************************
2695HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2696 BOOL fUnicode)
2697{
2698 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2699 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2700
2701 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2702 (hwndChildAfter != 0 && !child) ||
2703 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2704 {
2705 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2706 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2707 return 0;
2708 }
2709 if(hwndParent != OSLIB_HWND_DESKTOP)
2710 {//if the current process owns the window, just do a quick search
2711 child = (Win32BaseWindow *)parent->getFirstChild();
2712 if(hwndChildAfter != 0)
2713 {
2714 while(child)
2715 {
2716 if(child->getWindowHandle() == hwndChildAfter)
2717 {
2718 child = (Win32BaseWindow *)child->getNextChild();
2719 break;
2720 }
2721 child = (Win32BaseWindow *)child->getNextChild();
2722 }
2723 }
2724 while(child)
2725 {
2726 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2727 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2728 {
2729 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2730 return child->getWindowHandle();
2731 }
2732 child = (Win32BaseWindow *)child->getNextChild();
2733 }
2734 }
2735 else {
2736 Win32BaseWindow *wnd;
2737 HWND henum, hwnd;
2738
2739 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2740 hwnd = OSLibWinGetNextWindow(henum);
2741
2742 while(hwnd)
2743 {
2744 wnd = GetWindowFromOS2Handle(hwnd);
2745 if(wnd == NULL) {
2746 hwnd = OSLibWinQueryClientWindow(hwnd);
2747 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2748 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2749 }
2750
2751 if(wnd) {
2752 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2753 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2754 {
2755 OSLibWinEndEnumWindows(henum);
2756 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2757 return wnd->getWindowHandle();
2758 }
2759 }
2760 hwnd = OSLibWinGetNextWindow(henum);
2761 }
2762 OSLibWinEndEnumWindows(henum);
2763 }
2764 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2765 return 0;
2766}
2767//******************************************************************************
2768//******************************************************************************
2769HWND Win32BaseWindow::GetWindow(UINT uCmd)
2770{
2771 HWND hwndRelated = 0;
2772 Win32BaseWindow *window;
2773
2774 switch(uCmd)
2775 {
2776 case GW_HWNDFIRST:
2777 if(getParent()) {
2778 window = (Win32BaseWindow *)getParent()->getFirstChild();
2779 hwndRelated = window->getWindowHandle();
2780 }
2781 break;
2782
2783 case GW_HWNDLAST:
2784 if(!getParent())
2785 {
2786 goto end;
2787 }
2788
2789 window = this;
2790 while(window->getNextChild())
2791 {
2792 window = (Win32BaseWindow *)window->getNextChild();
2793 }
2794 hwndRelated = window->getWindowHandle();
2795 break;
2796
2797 case GW_HWNDNEXT:
2798 window = (Win32BaseWindow *)getNextChild();
2799 if(window) {
2800 hwndRelated = window->getWindowHandle();
2801 }
2802 break;
2803
2804 case GW_HWNDPREV:
2805 if(!getParent())
2806 {
2807 goto end;
2808 }
2809 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2810 if(window == this)
2811 {
2812 hwndRelated = 0; /* First in list */
2813 goto end;
2814 }
2815 while(window->getNextChild())
2816 {
2817 if (window->getNextChild() == this)
2818 {
2819 hwndRelated = window->getWindowHandle();
2820 goto end;
2821 }
2822 window = (Win32BaseWindow *)window->getNextChild();
2823 }
2824 break;
2825
2826 case GW_OWNER:
2827 if(getOwner()) {
2828 hwndRelated = getOwner()->getWindowHandle();
2829 }
2830 break;
2831
2832 case GW_CHILD:
2833 if(getFirstChild()) {
2834 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2835 }
2836 break;
2837 }
2838end:
2839 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2840 return hwndRelated;
2841}
2842//******************************************************************************
2843//******************************************************************************
2844HWND Win32BaseWindow::SetActiveWindow()
2845{
2846 HWND hwndActive;
2847 Win32BaseWindow *win32wnd;
2848 ULONG magic;
2849
2850 hwndActive = OSLibWinSetActiveWindow(OS2HwndFrame);
2851 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2852 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2853 if(CheckMagicDword(magic) && win32wnd)
2854 {
2855 return win32wnd->getWindowHandle();
2856 }
2857 return 0;
2858}
2859//******************************************************************************
2860//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2861//******************************************************************************
2862BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2863{
2864 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2865}
2866//******************************************************************************
2867//******************************************************************************
2868BOOL Win32BaseWindow::CloseWindow()
2869{
2870 return OSLibWinMinimizeWindow(OS2HwndFrame);
2871}
2872//******************************************************************************
2873//******************************************************************************
2874HWND Win32BaseWindow::GetActiveWindow()
2875{
2876 HWND hwndActive;
2877 Win32BaseWindow *win32wnd;
2878 ULONG magic;
2879
2880 hwndActive = OSLibWinQueryActiveWindow();
2881
2882 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2883 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2884 if(CheckMagicDword(magic) && win32wnd)
2885 {
2886 return win32wnd->getWindowHandle();
2887 }
2888 return 0;
2889// return hwndActive;
2890}
2891//******************************************************************************
2892//******************************************************************************
2893BOOL Win32BaseWindow::IsWindowEnabled()
2894{
2895 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2896}
2897//******************************************************************************
2898//******************************************************************************
2899BOOL Win32BaseWindow::IsWindowVisible()
2900{
2901#if 1
2902 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2903#else
2904 return OSLibWinIsWindowVisible(OS2HwndFrame);
2905#endif
2906}
2907//******************************************************************************
2908//******************************************************************************
2909BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2910{
2911 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2912}
2913//******************************************************************************
2914//******************************************************************************
2915BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2916{
2917 if(wndname == NULL)
2918 return FALSE;
2919
2920 if(fUnicode) {
2921 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2922 }
2923 else return (strcmp(windowNameA, wndname) == 0);
2924}
2925//******************************************************************************
2926//******************************************************************************
2927int Win32BaseWindow::GetWindowTextLength()
2928{
2929 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2930}
2931//******************************************************************************
2932//******************************************************************************
2933int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2934{
2935 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2936}
2937//******************************************************************************
2938//******************************************************************************
2939int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2940{
2941 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2942}
2943//******************************************************************************
2944//******************************************************************************
2945BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2946{
2947 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2948}
2949//******************************************************************************
2950//******************************************************************************
2951BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2952{
2953 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2954}
2955//******************************************************************************
2956//******************************************************************************
2957VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
2958{
2959 if(IsWindowDestroyed()) return;
2960
2961 if (dwStyle != oldStyle) OSLibSetWindowStyle(OS2HwndFrame, dwStyle, fTaskList);
2962}
2963//******************************************************************************
2964//******************************************************************************
2965LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
2966{
2967 LONG oldval;
2968
2969 dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
2970 switch(index) {
2971 case GWL_EXSTYLE:
2972 {
2973 STYLESTRUCT ss;
2974
2975 if(dwExStyle == value)
2976 return value;
2977
2978 ss.styleOld = dwExStyle;
2979 ss.styleNew = value;
2980 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2981 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2982 setExStyle(ss.styleNew);
2983 updateWindowStyle(ss.styleOld,getStyle());
2984 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2985 return ss.styleOld;
2986 }
2987 case GWL_STYLE:
2988 {
2989 STYLESTRUCT ss;
2990
2991 if(dwStyle == value)
2992 return value;
2993
2994 value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
2995 ss.styleOld = getStyle();
2996 ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
2997 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), getStyle(), value));
2998 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2999 setStyle(ss.styleNew);
3000 updateWindowStyle(dwExStyle,ss.styleOld);
3001 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3002#ifdef DEBUG
3003 PrintWindowStyle(ss.styleNew, 0);
3004#endif
3005 return ss.styleOld;
3006 }
3007 case GWL_WNDPROC:
3008 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3009 //WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
3010 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
3011 return oldval;
3012 case GWL_HINSTANCE:
3013 oldval = hInstance;
3014 hInstance = value;
3015 return oldval;
3016 case GWL_HWNDPARENT:
3017 return SetParent((HWND)value);
3018 case GWL_ID:
3019 oldval = getWindowId();
3020 setWindowId(value);
3021 return oldval;
3022 case GWL_USERDATA:
3023 oldval = userData;
3024 userData = value;
3025 return oldval;
3026 default:
3027 if(index >= 0 && index/4 < nrUserWindowLong)
3028 {
3029 oldval = userWindowLong[index/4];
3030 userWindowLong[index/4] = value;
3031 return oldval;
3032 }
3033 SetLastError(ERROR_INVALID_PARAMETER);
3034 return 0;
3035 }
3036}
3037//******************************************************************************
3038//******************************************************************************
3039ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3040{
3041 ULONG value;
3042
3043 switch(index) {
3044 case GWL_EXSTYLE:
3045 value = dwExStyle;
3046 break;
3047 case GWL_STYLE:
3048 value = dwStyle;
3049 break;
3050 case GWL_WNDPROC:
3051 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3052 break;
3053 case GWL_HINSTANCE:
3054 value = hInstance;
3055 break;
3056 case GWL_HWNDPARENT:
3057 if(getParent()) {
3058 value = getParent()->getWindowHandle();
3059 }
3060 else value = 0;
3061 break;
3062 case GWL_ID:
3063 value = getWindowId();
3064 break;
3065 case GWL_USERDATA:
3066 value = userData;
3067 break;
3068 default:
3069 if(index >= 0 && index/4 < nrUserWindowLong)
3070 {
3071 value = userWindowLong[index/4];
3072 break;
3073 }
3074 SetLastError(ERROR_INVALID_PARAMETER);
3075 return 0;
3076 }
3077 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3078 return value;
3079}
3080//******************************************************************************
3081//******************************************************************************
3082WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3083{
3084 WORD oldval;
3085
3086 if(index >= 0 && index/4 < nrUserWindowLong)
3087 {
3088 oldval = ((WORD *)userWindowLong)[index/2];
3089 ((WORD *)userWindowLong)[index/2] = value;
3090 return oldval;
3091 }
3092 SetLastError(ERROR_INVALID_PARAMETER);
3093 return 0;
3094}
3095//******************************************************************************
3096//******************************************************************************
3097WORD Win32BaseWindow::GetWindowWord(int index)
3098{
3099 if(index >= 0 && index/4 < nrUserWindowLong)
3100 {
3101 return ((WORD *)userWindowLong)[index/2];
3102 }
3103 SetLastError(ERROR_INVALID_PARAMETER);
3104 return 0;
3105}
3106//******************************************************************************
3107//******************************************************************************
3108void Win32BaseWindow::setWindowId(DWORD id)
3109{
3110 windowId = id;
3111 dprintf(("Set window ID to %x", id));
3112 OSLibSetWindowID(OS2HwndFrame, id);
3113}
3114//******************************************************************************
3115//******************************************************************************
3116Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3117{
3118 Win32BaseWindow *window;
3119
3120 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3121 return window;
3122 }
3123// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3124 return NULL;
3125}
3126//******************************************************************************
3127//******************************************************************************
3128Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3129{
3130 Win32BaseWindow *win32wnd;
3131 DWORD magic;
3132
3133 if(hwnd == OSLIB_HWND_DESKTOP)
3134 {
3135 return windowDesktop;
3136 }
3137
3138 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3139 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3140
3141 if(win32wnd && CheckMagicDword(magic)) {
3142 return win32wnd;
3143 }
3144// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3145 return 0;
3146}
3147//******************************************************************************
3148//******************************************************************************
3149Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3150{
3151 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3152}
3153//******************************************************************************
3154//******************************************************************************
3155HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3156{
3157 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3158
3159 if(window) {
3160 return window->getOS2WindowHandle();
3161 }
3162// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3163 return hwnd;
3164}
3165//******************************************************************************
3166//******************************************************************************
3167HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3168{
3169 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3170
3171 if(window) {
3172 return window->getOS2FrameWindowHandle();
3173 }
3174// dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
3175 return hwnd;
3176}
3177//******************************************************************************
3178//******************************************************************************
3179HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3180{
3181 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3182
3183 if(window) {
3184 return window->getWindowHandle();
3185 }
3186 window = GetWindowFromOS2FrameHandle(hwnd);
3187 if(window) {
3188 return window->getWindowHandle();
3189 }
3190// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3191 return 0;
3192// else return hwnd; //OS/2 window handle
3193}
3194//******************************************************************************
3195// GetNextDlgTabItem32 (USER32.276)
3196//******************************************************************************
3197HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3198{
3199 Win32BaseWindow *child, *nextchild, *lastchild;
3200 HWND retvalue;
3201
3202 if (hwndCtrl)
3203 {
3204 child = GetWindowFromHandle(hwndCtrl);
3205 if (!child)
3206 {
3207 retvalue = 0;
3208 goto END;
3209 }
3210 /* Make sure hwndCtrl is a top-level child */
3211 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3212 {
3213 child = child->getParent();
3214 if(child == NULL) break;
3215 }
3216
3217 if (!child || child->getParent() != this)
3218 {
3219 retvalue = 0;
3220 goto END;
3221 }
3222 }
3223 else
3224 {
3225 /* No ctrl specified -> start from the beginning */
3226 child = (Win32BaseWindow *)getFirstChild();
3227 if (!child)
3228 {
3229 retvalue = 0;
3230 goto END;
3231 }
3232
3233 if (!fPrevious)
3234 {
3235 while (child->getNextChild())
3236 {
3237 child = (Win32BaseWindow *)child->getNextChild();
3238 }
3239 }
3240 }
3241
3242 lastchild = child;
3243 nextchild = (Win32BaseWindow *)child->getNextChild();
3244 while (TRUE)
3245 {
3246 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3247
3248 if (child == nextchild) break;
3249
3250 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3251 !(nextchild->getStyle() & WS_DISABLED))
3252 {
3253 lastchild = nextchild;
3254 if (!fPrevious) break;
3255 }
3256 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3257 }
3258 retvalue = lastchild->getWindowHandle();
3259
3260END:
3261 return retvalue;
3262}
3263//******************************************************************************
3264//******************************************************************************
3265HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3266{
3267 Win32BaseWindow *child, *nextchild, *lastchild;
3268 HWND retvalue;
3269
3270 if (hwndCtrl)
3271 {
3272 child = GetWindowFromHandle(hwndCtrl);
3273 if (!child)
3274 {
3275 retvalue = 0;
3276 goto END;
3277 }
3278 /* Make sure hwndCtrl is a top-level child */
3279 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3280 {
3281 child = child->getParent();
3282 if(child == NULL) break;
3283 }
3284
3285 if (!child || child->getParent() != this)
3286 {
3287 retvalue = 0;
3288 goto END;
3289 }
3290 }
3291 else
3292 {
3293 /* No ctrl specified -> start from the beginning */
3294 child = (Win32BaseWindow *)getFirstChild();
3295 if (!child)
3296 {
3297 retvalue = 0;
3298 goto END;
3299 }
3300
3301 if (fPrevious)
3302 {
3303 while (child->getNextChild())
3304 {
3305 child = (Win32BaseWindow *)child->getNextChild();
3306 }
3307 }
3308 }
3309
3310 lastchild = child;
3311 nextchild = (Win32BaseWindow *)child->getNextChild();
3312 while (TRUE)
3313 {
3314 if (!nextchild || nextchild->getStyle() & WS_GROUP)
3315 {
3316 /* Wrap-around to the beginning of the group */
3317 Win32BaseWindow *pWndTemp;
3318
3319 nextchild = (Win32BaseWindow *)getFirstChild();
3320
3321 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3322 {
3323 if (pWndTemp->getStyle() & WS_GROUP)
3324 nextchild = pWndTemp;
3325
3326 if (pWndTemp == child)
3327 break;
3328 }
3329
3330 }
3331 if (nextchild == child)
3332 break;
3333
3334 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3335 {
3336 lastchild = nextchild;
3337
3338 if (!fPrevious)
3339 break;
3340 }
3341
3342 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3343 }
3344 retvalue = lastchild->getWindowHandle();
3345END:
3346 return retvalue;
3347}
3348//******************************************************************************
3349//******************************************************************************
3350#ifdef DEBUG
3351void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3352{
3353 char style[256] = "";
3354 char exstyle[256] = "";
3355
3356 /* Window styles */
3357 if(dwStyle & WS_CHILD)
3358 strcat(style, "WS_CHILD ");
3359 if(dwStyle & WS_POPUP)
3360 strcat(style, "WS_POPUP ");
3361 if(dwStyle & WS_VISIBLE)
3362 strcat(style, "WS_VISIBLE ");
3363 if(dwStyle & WS_DISABLED)
3364 strcat(style, "WS_DISABLED ");
3365 if(dwStyle & WS_CLIPSIBLINGS)
3366 strcat(style, "WS_CLIPSIBLINGS ");
3367 if(dwStyle & WS_CLIPCHILDREN)
3368 strcat(style, "WS_CLIPCHILDREN ");
3369 if(dwStyle & WS_MAXIMIZE)
3370 strcat(style, "WS_MAXIMIZE ");
3371 if(dwStyle & WS_MINIMIZE)
3372 strcat(style, "WS_MINIMIZE ");
3373 if(dwStyle & WS_GROUP)
3374 strcat(style, "WS_GROUP ");
3375 if(dwStyle & WS_TABSTOP)
3376 strcat(style, "WS_TABSTOP ");
3377
3378 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3379 strcat(style, "WS_CAPTION ");
3380 if(dwStyle & WS_DLGFRAME)
3381 strcat(style, "WS_DLGFRAME ");
3382 if(dwStyle & WS_BORDER)
3383 strcat(style, "WS_BORDER ");
3384
3385 if(dwStyle & WS_VSCROLL)
3386 strcat(style, "WS_VSCROLL ");
3387 if(dwStyle & WS_HSCROLL)
3388 strcat(style, "WS_HSCROLL ");
3389 if(dwStyle & WS_SYSMENU)
3390 strcat(style, "WS_SYSMENU ");
3391 if(dwStyle & WS_THICKFRAME)
3392 strcat(style, "WS_THICKFRAME ");
3393 if(dwStyle & WS_MINIMIZEBOX)
3394 strcat(style, "WS_MINIMIZEBOX ");
3395 if(dwStyle & WS_MAXIMIZEBOX)
3396 strcat(style, "WS_MAXIMIZEBOX ");
3397
3398 if(dwExStyle & WS_EX_DLGMODALFRAME)
3399 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3400 if(dwExStyle & WS_EX_ACCEPTFILES)
3401 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3402 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3403 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3404 if(dwExStyle & WS_EX_TOPMOST)
3405 strcat(exstyle, "WS_EX_TOPMOST ");
3406 if(dwExStyle & WS_EX_TRANSPARENT)
3407 strcat(exstyle, "WS_EX_TRANSPARENT ");
3408
3409 if(dwExStyle & WS_EX_MDICHILD)
3410 strcat(exstyle, "WS_EX_MDICHILD ");
3411 if(dwExStyle & WS_EX_TOOLWINDOW)
3412 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3413 if(dwExStyle & WS_EX_WINDOWEDGE)
3414 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3415 if(dwExStyle & WS_EX_CLIENTEDGE)
3416 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3417 if(dwExStyle & WS_EX_CONTEXTHELP)
3418 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3419 if(dwExStyle & WS_EX_RIGHT)
3420 strcat(exstyle, "WS_EX_RIGHT ");
3421 if(dwExStyle & WS_EX_LEFT)
3422 strcat(exstyle, "WS_EX_LEFT ");
3423 if(dwExStyle & WS_EX_RTLREADING)
3424 strcat(exstyle, "WS_EX_RTLREADING ");
3425 if(dwExStyle & WS_EX_LTRREADING)
3426 strcat(exstyle, "WS_EX_LTRREADING ");
3427 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3428 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3429 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3430 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3431 if(dwExStyle & WS_EX_CONTROLPARENT)
3432 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3433 if(dwExStyle & WS_EX_STATICEDGE)
3434 strcat(exstyle, "WS_EX_STATICEDGE ");
3435 if(dwExStyle & WS_EX_APPWINDOW)
3436 strcat(exstyle, "WS_EX_APPWINDOW ");
3437
3438 dprintf(("Window style: %x %s", dwStyle, style));
3439 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3440}
3441#endif
3442//******************************************************************************
3443//******************************************************************************
3444
3445GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.