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

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

replaced strncpy with lstrcpynA

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