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

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

Experimental WM_ERASEBACKGND change

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