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

Last change on this file since 2211 was 2211, checked in by cbratschi, 26 years ago

SetWindowPos fixed, edit: refresh only if visible

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