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

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

non-client fixes, DefWndProc enhancements, several other bugs fixed

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