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

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

Lots of message fixes

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