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

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

Owndc changes

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