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

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

removed CS_SIZEREDRAW

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