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

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

Dialog fixes + ported Wine apis

File size: 92.5 KB
Line 
1/* $Id: win32wbase.cpp,v 1.49 1999-10-17 15:46:09 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include <spy.h>
28#include "wndmsg.h"
29#include "hooks.h"
30#include "oslibwin.h"
31#include "oslibutil.h"
32#include "oslibgdi.h"
33#include "oslibres.h"
34#include "oslibmenu.h"
35#include "oslibdos.h"
36#include "syscolor.h"
37#include "win32wndhandle.h"
38#include "heapshared.h"
39#include "dc.h"
40#include "pmframe.h"
41#include "win32wdesktop.h"
42#include "pmwindow.h"
43#include <wprocess.h>
44
45#define HAS_DLGFRAME(style,exStyle) \
46 (((exStyle) & WS_EX_DLGMODALFRAME) || \
47 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
48
49#define HAS_THICKFRAME(style,exStyle) \
50 (((style) & WS_THICKFRAME) && \
51 !((exStyle) & WS_EX_DLGMODALFRAME))
52
53#define HAS_THINFRAME(style) \
54 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
55
56#define HAS_BIGFRAME(style,exStyle) \
57 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
58 ((exStyle) & WS_EX_DLGMODALFRAME))
59
60#define HAS_ANYFRAME(style,exStyle) \
61 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
62 ((exStyle) & WS_EX_DLGMODALFRAME) || \
63 !((style) & (WS_CHILD | WS_POPUP)))
64
65#define HAS_3DFRAME(exStyle) \
66 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
67
68#define HAS_BORDER(style, exStyle) \
69 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
70
71#define IS_OVERLAPPED(style) \
72 !(style & (WS_CHILD | WS_POPUP))
73
74/* bits in the dwKeyData */
75#define KEYDATA_ALT 0x2000
76#define KEYDATA_PREVSTATE 0x4000
77
78void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
79
80//******************************************************************************
81//******************************************************************************
82Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
83{
84 Init();
85}
86//******************************************************************************
87//******************************************************************************
88Win32BaseWindow::Win32BaseWindow(HWND os2Handle,VOID* win32WndProc) : GenericObject(&windows,OBJTYPE_WINDOW)
89{
90 Init();
91 OS2Hwnd = OS2HwndFrame = os2Handle;
92 dwStyle = WS_VISIBLE;
93 setWindowProc((WNDPROC)win32WndProc);
94 fIsSubclassedOS2Wnd = TRUE;
95 fFirstShow = FALSE;
96
97 //CB: replace by a secure method
98
99 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
100 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
101 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
102 return;
103 }
104 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
105 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
106 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
107 return;
108 }
109
110 OSLibWinQueryWindowRect(OS2Hwnd,&rectWindow);
111 rectClient = rectWindow;
112 rectClient.bottom -= rectClient.top;
113 rectClient.top = 0;
114 rectClient.right -= rectClient.left;
115 rectClient.left = 0;
116
117 setOldWndProc(SubclassWithDefHandler(OS2Hwnd));
118}
119//******************************************************************************
120//******************************************************************************
121Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
122 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
123{
124 Init();
125 this->isUnicode = isUnicode;
126 CreateWindowExA(lpCreateStructA, classAtom);
127}
128//******************************************************************************
129//******************************************************************************
130void Win32BaseWindow::Init()
131{
132 isUnicode = FALSE;
133 fIsSubclassedOS2Wnd = FALSE;
134 fFirstShow = TRUE;
135 fIsDialog = FALSE;
136 fInternalMsg = FALSE;
137 fNoSizeMsg = FALSE;
138 fIsDestroyed = FALSE;
139
140 windowNameA = NULL;
141 windowNameW = NULL;
142 wndNameLength = 0;
143
144 userWindowLong = NULL;;
145 nrUserWindowLong = 0;
146
147 magic = WIN32PM_MAGIC;
148 OS2Hwnd = 0;
149 OS2HwndFrame = 0;
150 OS2HwndMenu = 0;
151 Win32Hwnd = 0;
152
153 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
154 {
155 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
156 DebugInt3();
157 }
158
159 posx = posy = 0;
160 width = height = 0;
161
162 dwExStyle = 0;
163 dwStyle = 0;
164 win32wndproc = 0;
165 hInstance = 0;
166 windowId = 0xFFFFFFFF; //default = -1
167 userData = 0;
168
169 pOldFrameProc = NULL;
170 borderWidth = 0;
171 borderHeight = 0;
172
173 hwndLinkAfter = HWND_BOTTOM;
174 flags = 0;
175 isIcon = FALSE;
176 lastHitTestVal = 0;
177 owner = NULL;
178 windowClass = 0;
179
180 acceltableResource = NULL;
181 iconResource = NULL;
182
183 EraseBkgndFlag = TRUE;
184 PSEraseFlag = FALSE;
185 SupressEraseFlag = FALSE;
186
187 horzScrollInfo = NULL;
188 vertScrollInfo = NULL;
189 hwndHorzScroll = 0;
190 hwndVertScroll = 0;
191
192 ownDC = 0;
193}
194//******************************************************************************
195//todo get rid of resources (menu, accel, icon etc)
196//******************************************************************************
197Win32BaseWindow::~Win32BaseWindow()
198{
199 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
200 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
201
202 if(getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
203 {
204 //if we're the last child that's being destroyed and our
205 //parent window was also destroyed, then we delete the parent object
206 if(getParent()->IsWindowDestroyed())
207 {
208 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
209 delete getParent();
210 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
211 }
212 }
213 if (isOwnDC())
214 releaseOwnDC (ownDC);
215
216 if(Win32Hwnd)
217 HwFreeWindowHandle(Win32Hwnd);
218
219 if(userWindowLong)
220 free(userWindowLong);
221 if(windowNameA) {
222 free(windowNameA);
223 windowNameA = NULL;
224 }
225 if(windowNameW) {
226 free(windowNameW);
227 windowNameW = NULL;
228 }
229 if(vertScrollInfo) {
230 free(vertScrollInfo);
231 vertScrollInfo = NULL;
232 }
233 if(horzScrollInfo) {
234 free(horzScrollInfo);
235 horzScrollInfo = NULL;
236 }
237}
238//******************************************************************************
239//******************************************************************************
240BOOL Win32BaseWindow::isChild()
241{
242 return ((dwStyle & WS_CHILD) != 0);
243}
244//******************************************************************************
245//******************************************************************************
246BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
247{
248 char buffer[256];
249 POINT maxSize, maxPos, minTrack, maxTrack;
250
251#ifdef DEBUG
252 PrintWindowStyle(cs->style, cs->dwExStyle);
253#endif
254
255 sw = SW_SHOW;
256 SetLastError(0);
257
258 /* Find the parent window */
259 if (cs->hwndParent)
260 {
261 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
262 if(!window) {
263 dprintf(("Bad parent %04x\n", cs->hwndParent ));
264 SetLastError(ERROR_INVALID_PARAMETER);
265 return FALSE;
266 }
267 /* Make sure parent is valid */
268 if (!window->IsWindow() )
269 {
270 dprintf(("Bad parent %04x\n", cs->hwndParent ));
271 SetLastError(ERROR_INVALID_PARAMETER);
272 return FALSE;
273 }
274 }
275 else
276 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
277 dprintf(("No parent for child window\n" ));
278 SetLastError(ERROR_INVALID_PARAMETER);
279 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
280 }
281
282 /* Find the window class */
283 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
284 if (!windowClass)
285 {
286 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
287 dprintf(("Bad class '%s'\n", buffer ));
288 SetLastError(ERROR_INVALID_PARAMETER);
289 return 0;
290 }
291#ifdef DEBUG
292 if(HIWORD(cs->lpszClass))
293 {
294 char *astring;
295
296 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
297 else astring = (char *)cs->lpszClass;
298
299 dprintf(("Window class %s", astring));
300 if(isUnicode) FreeAsciiString(astring);
301 }
302 else dprintf(("Window class %x", cs->lpszClass));
303#endif
304
305 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
306 * with an atom as the class name, put some programs expect to have a *REAL* string in
307 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
308 */
309 if (!HIWORD(cs->lpszClass) ) {
310 if (isUnicode) {
311 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
312 }
313 else {
314 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
315 }
316 cs->lpszClass = buffer;
317 }
318
319 /* Fix the coordinates */
320 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
321 {
322// PDB *pdb = PROCESS_Current();
323
324 /* Never believe Microsoft's documentation... CreateWindowEx doc says
325 * that if an overlapped window is created with WS_VISIBLE style bit
326 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
327 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
328 * reveals that
329 *
330 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
331 * 2) it does not ignore the y parameter as the docs claim; instead, it
332 * uses it as second parameter to ShowWindow() unless y is either
333 * CW_USEDEFAULT or CW_USEDEFAULT16.
334 *
335 * The fact that we didn't do 2) caused bogus windows pop up when wine
336 * was running apps that were using this obscure feature. Example -
337 * calc.exe that comes with Win98 (only Win98, it's different from
338 * the one that comes with Win95 and NT)
339 */
340 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
341
342 /* We have saved cs->y, now we can trash it */
343#if 0
344 if ( !(cs->style & (WS_CHILD | WS_POPUP))
345 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
346 {
347 cs->x = pdb->env_db->startup_info->dwX;
348 cs->y = pdb->env_db->startup_info->dwY;
349 }
350#endif
351 cs->x = 0;
352 cs->y = 0;
353// }
354 }
355 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
356 {
357#if 0
358 PDB *pdb = PROCESS_Current();
359 if ( !(cs->style & (WS_CHILD | WS_POPUP))
360 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
361 {
362 cs->cx = pdb->env_db->startup_info->dwXSize;
363 cs->cy = pdb->env_db->startup_info->dwYSize;
364 }
365 else
366 {
367#endif
368 cs->cx = 600; /* FIXME */
369 cs->cy = 400;
370// }
371 }
372
373 if (cs->x < 0) cs->x = 0;
374 if (cs->y < 0) cs->y = 0;
375
376 //Allocate window words
377 nrUserWindowLong = windowClass->getExtraWndWords();
378 if(nrUserWindowLong) {
379 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
380 memset(userWindowLong, 0, nrUserWindowLong);
381 }
382
383 if ((cs->style & WS_CHILD) && cs->hwndParent)
384 {
385 SetParent(cs->hwndParent);
386 owner = GetWindowFromHandle(cs->hwndParent);
387 if(owner == NULL)
388 {
389 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
390 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
391 return FALSE;
392 }
393 }
394 else
395 {
396 if (!cs->hwndParent) {
397 owner = NULL;
398 }
399 else
400 {
401 owner = GetWindowFromHandle(cs->hwndParent);
402 if(owner == NULL)
403 {
404 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
405 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
406 return FALSE;
407 }
408 }
409 }
410
411 setWindowProc(windowClass->getWindowProc());
412 hInstance = cs->hInstance;
413 dwStyle = cs->style & ~WS_VISIBLE;
414 dwExStyle = cs->dwExStyle;
415
416#if 1
417 //SvL: Messes up Z-order of dialog controls
418 hwndLinkAfter = HWND_TOP;
419#else
420 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
421 ? HWND_BOTTOM : HWND_TOP;
422#endif
423
424#if 0
425//TODO
426 /* Call the WH_CBT hook */
427
428 if (HOOK_IsHooked( WH_CBT ))
429 {
430 CBT_CREATEWNDA cbtc;
431 LRESULT ret;
432
433 cbtc.lpcs = cs;
434 cbtc.hwndInsertAfter = hwndLinkAfter;
435 ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
436 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
437 if (ret)
438 {
439 TRACE_(win)("CBT-hook returned 0\n");
440 wndPtr->pDriver->pFinalize(wndPtr);
441 retvalue = 0;
442 goto end;
443 }
444 }
445#endif
446
447 /* Increment class window counter */
448 windowClass->IncreaseWindowCount();
449
450 /* Correct the window style */
451 if (!(cs->style & WS_CHILD))
452 {
453 dwStyle |= WS_CLIPSIBLINGS;
454 if (!(cs->style & WS_POPUP))
455 {
456 dwStyle |= WS_CAPTION;
457 flags |= WIN_NEED_SIZE;
458 }
459 }
460 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
461
462 //TODO?
463#if 0
464 /* Get class or window DC if needed */
465 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
466 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
467 else wndPtr->dce = NULL;
468#endif
469
470 if (cs->style & WS_HSCROLL)
471 {
472 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
473 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
474 horzScrollInfo->MaxVal = 100;
475 horzScrollInfo->flags = ESB_ENABLE_BOTH;
476 }
477
478 if (cs->style & WS_VSCROLL)
479 {
480 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
481 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
482 vertScrollInfo->MaxVal = 100;
483 vertScrollInfo->flags = ESB_ENABLE_BOTH;
484 }
485
486 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
487 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
488 {
489 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
490 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
491 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
492 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
493 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
494 }
495
496 if(cs->style & WS_CHILD)
497 {
498 if(cs->cx < 0) cs->cx = 0;
499 if(cs->cy < 0) cs->cy = 0;
500 }
501 else
502 {
503 if (cs->cx <= 0) cs->cx = 1;
504 if (cs->cy <= 0) cs->cy = 1;
505 }
506
507 DWORD dwOSWinStyle, dwOSFrameStyle;
508
509 OSLibWinConvertStyle(cs->style, &cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle, &borderWidth, &borderHeight);
510 dwExStyle = cs->dwExStyle;
511
512 rectWindow.left = cs->x;
513 rectWindow.top = cs->y;
514 rectWindow.right = cs->x + cs->cx;
515 rectWindow.bottom = cs->y + cs->cy;
516 rectClient = rectWindow;
517
518 if(HIWORD(cs->lpszName))
519 {
520 if(isUnicode)
521 SetWindowTextW((LPWSTR)cs->lpszName);
522 else SetWindowTextA((LPSTR)cs->lpszName);
523 }
524
525 //copy pointer of CREATESTRUCT for usage in MsgCreate method
526 tmpcs = cs;
527
528 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
529 THDB *thdb = GetThreadTHDB();
530
531 if(thdb == NULL) {
532 dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
533 ExitProcess(666);
534 return FALSE;
535 }
536
537 thdb->newWindow = (ULONG)this;
538
539 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
540 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
541 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
542 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
543 &OS2HwndFrame, 0);
544
545 if(OS2Hwnd == 0) {
546 dprintf(("Window creation failed!!"));
547 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
548 return FALSE;
549 }
550 SetLastError(0);
551 return TRUE;
552}
553//******************************************************************************
554//******************************************************************************
555BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
556{
557 POINT maxPos;
558 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
559
560 OS2Hwnd = hwndClient;
561 OS2HwndFrame = hwndFrame;
562// if(!isFrameWindow())
563// OS2HwndFrame = hwndClient;
564
565 fNoSizeMsg = TRUE;
566
567 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
568 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
569 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
570 return FALSE;
571 }
572 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
573 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
574 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
575 return FALSE;
576 }
577 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
578 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
579 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
580 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
581 return FALSE;
582 }
583#if 0
584 if(OS2Hwnd != OS2HwndFrame) {
585 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
586 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
587 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
588 return FALSE;
589 }
590 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
591 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
592 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
593 return FALSE;
594 }
595 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
596 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
597 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
598 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
599 return FALSE;
600 }
601 }
602#endif
603
604 OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
605
606 if (dwStyle & WS_HSCROLL)
607 {
608 hwndHorzScroll = OSLibWinQueryScrollBarHandle(OS2HwndFrame, OSLIB_HSCROLL);
609// OSLibWinShowScrollBar(OS2HwndFrame, hwndHorzScroll, OSLIB_HSCROLL, FALSE, TRUE);
610 }
611
612 if (dwStyle & WS_VSCROLL) {
613 hwndVertScroll = OSLibWinQueryScrollBarHandle(OS2HwndFrame, OSLIB_VSCROLL);
614// OSLibWinShowScrollBar(OS2HwndFrame, hwndVertScroll, OSLIB_VSCROLL, FALSE, TRUE);
615 }
616
617 //CB: switch off -> OS/2 scrollbars
618 subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
619
620 fakeWinBase.hwndThis = OS2Hwnd;
621 fakeWinBase.pWindowClass = windowClass;
622// SetFakeOpen32();
623
624 //Set icon from class
625 if(windowClass->getIcon())
626 SetIcon(windowClass->getIcon());
627
628 /* Set the window menu */
629 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
630 {
631 if (cs->hMenu) SetMenu(cs->hMenu);
632 else
633 {
634 if (windowClass->getMenuNameA()) {
635 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
636 if (cs->hMenu) SetMenu(cs->hMenu );
637 }
638 }
639 }
640 else
641 {
642 setWindowId((DWORD)cs->hMenu);
643 }
644
645 //Subclass frame
646// if(isFrameWindow() && (HAS_3DFRAME(dwExStyle) ||
647// (!HAS_DLGFRAME(dwStyle, dwExStyle) && (dwStyle & (WS_DLGFRAME|WS_BORDER|WS_THICKFRAME)) == WS_BORDER)))
648// {
649 pOldFrameProc = FrameSubclassFrameWindow(this);
650 if (isChild()) FrameSetBorderSize(this,TRUE);
651// }
652
653 /* Send the WM_CREATE message
654 * Perhaps we shouldn't allow width/height changes as well.
655 * See p327 in "Internals".
656 */
657 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
658
659 if(getParent()) {
660 SetWindowPos(getParent()->getWindowHandle(), rectClient.left, rectClient.top,
661 rectClient.right-rectClient.left,
662 rectClient.bottom-rectClient.top,
663 SWP_NOACTIVATE | SWP_NOZORDER );
664 }
665 else {
666 SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
667 rectClient.right-rectClient.left,
668 rectClient.bottom-rectClient.top,
669 SWP_NOACTIVATE);
670 }
671 fNoSizeMsg = FALSE;
672
673 if(SendMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
674 {
675 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
676
677// OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
678 dprintf(("Sending WM_CREATE"));
679 if( (SendMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
680 {
681 if(!(flags & WIN_NEED_SIZE)) {
682 SendMessageA(WM_SIZE, SIZE_RESTORED,
683 MAKELONG(rectClient.right-rectClient.left,
684 rectClient.bottom-rectClient.top));
685 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
686 }
687
688 if (cs->style & WS_VISIBLE) ShowWindow( sw );
689
690#if 0
691 /* Call WH_SHELL hook */
692
693 if (!(dwStyle & WS_CHILD) && !owner)
694 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
695#endif
696 SetLastError(0);
697 return TRUE;
698 }
699 }
700 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
701 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
702 return FALSE;
703}
704//******************************************************************************
705//******************************************************************************
706ULONG Win32BaseWindow::MsgQuit()
707{
708 return SendInternalMessageA(WM_QUIT, 0, 0);
709}
710//******************************************************************************
711//******************************************************************************
712ULONG Win32BaseWindow::MsgClose()
713{
714 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
715 return 0; //app handles this message
716 }
717 return 1;
718}
719//******************************************************************************
720//******************************************************************************
721ULONG Win32BaseWindow::MsgDestroy()
722{
723 ULONG rc;
724 Win32BaseWindow *child;
725
726 if (isSubclassedOS2Wnd) OSLibWinSubclassWindow(OS2Hwnd,pOldWndProc);
727
728 //According to the SDK, WM_PARENTNOTIFY messages are sent to the parent (this window)
729 //before any window destruction has begun
730 child = (Win32BaseWindow *)getFirstChild();
731 while(child) {
732 child->NotifyParent(WM_DESTROY, 0, 0);
733
734 child = (Win32BaseWindow *)child->getNextChild();
735 }
736 SendInternalMessageA(WM_DESTROY, 0, 0);
737
738 if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndHorzScroll);
739 if (hwndVertScroll && OSLibWinQueryWindow(hwndVertScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndVertScroll);
740
741 fIsDestroyed = TRUE;
742 if(getFirstChild() == NULL) {
743 delete this;
744 }
745 return 1;
746}
747//******************************************************************************
748//******************************************************************************
749ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
750{
751 if(fEnable) {
752 dwStyle &= ~WS_DISABLED;
753 }
754 else dwStyle |= WS_DISABLED;
755
756 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
757}
758//******************************************************************************
759//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
760//******************************************************************************
761ULONG Win32BaseWindow::MsgShow(BOOL fShow)
762{
763 if(fNoSizeMsg) {
764 return 1;
765 }
766
767 if(fShow) {
768 setStyle(getStyle() | WS_VISIBLE);
769 }
770 else setStyle(getStyle() & ~WS_VISIBLE);
771
772 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
773}
774//******************************************************************************
775//******************************************************************************
776ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
777{
778 if(fNoSizeMsg)
779 return 1;
780
781 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
782}
783//******************************************************************************
784//******************************************************************************
785ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
786{
787 if(fNoSizeMsg)
788 return 1;
789
790 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
791}
792//******************************************************************************
793//******************************************************************************
794ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
795{
796 dprintf(("MsgMove to (%d,%d)", x, y));
797 if(fNoSizeMsg)
798 return 1;
799
800 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
801}
802//******************************************************************************
803//******************************************************************************
804ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
805{
806 // TODO: call TIMERPROC if not NULL
807 return SendInternalMessageA(WM_TIMER, TimerID, 0);
808}
809//******************************************************************************
810//******************************************************************************
811ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
812{
813 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
814 //window scrollbars send these messages
815 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
816}
817//******************************************************************************
818//******************************************************************************
819ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
820{
821 switch(cmd) {
822 case CMD_MENU:
823 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
824 case CMD_CONTROL:
825 return 0; //todo
826 case CMD_ACCELERATOR:
827 // this fit not really windows behavior.
828 // maybe TranslateAccelerator() is better
829 dprintf(("accelerator command"));
830 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
831 }
832 return 0;
833}
834//******************************************************************************
835//******************************************************************************
836ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
837{
838 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
839 return 1; //TODO: May need to change this
840}
841//******************************************************************************
842//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
843//******************************************************************************
844ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
845{
846 WORD fwSizeType = 0;
847
848 if(fMinimize) {
849 fwSizeType = SIZE_MINIMIZED;
850 }
851 else
852 if(fMaximize) {
853 fwSizeType = SIZE_MAXIMIZED;
854 }
855 else fwSizeType = SIZE_RESTORED;
856
857 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
858}
859//******************************************************************************
860//******************************************************************************
861ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
862{
863 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
864
865 //According to SDK docs, if app returns FALSE & window is being deactivated,
866 //default processing is cancelled
867 //TODO: According to Wine we should proceed anyway if window is sysmodal
868 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
869 {
870 return 0;
871 }
872 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
873
874 curprocid = GetCurrentProcessId();
875 if(hwnd) {
876 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
877 }
878
879 if(curprocid != procidhwnd && fActivate) {
880 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
881 }
882 return rc;
883}
884//******************************************************************************
885//******************************************************************************
886ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
887{
888 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
889}
890//******************************************************************************
891//TODO: Is this correct and complete?
892//Add print screen, break & numlock
893//******************************************************************************
894void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
895{
896 switch(virtualkey) {
897 case VK_DOWN:
898 case VK_UP:
899 case VK_PRIOR:
900 case VK_NEXT:
901 case VK_END:
902 case VK_DIVIDE:
903 case VK_DELETE:
904 case VK_EXECUTE: //Numeric enter key?
905 case VK_HOME:
906 case VK_INSERT:
907 case VK_RCONTROL:
908 case VK_RMENU: //is this the right alt???
909 *lParam = *lParam | (1<<24);
910 }
911}
912//******************************************************************************
913//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
914//******************************************************************************
915ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
916{
917 ULONG lParam = 0;
918
919 lParam = repeatcnt;
920 lParam |= (scancode << 16);
921 setExtendedKey(vkey, &lParam);
922
923 if(keyflags & KEY_ALTDOWN)
924 lParam |= (1<<29);
925 if(keyflags & KEY_PREVDOWN)
926 lParam |= (1<<30);
927 if(keyflags & KEY_UP)
928 lParam |= (1<<31);
929 if(keyflags & KEY_DEADKEY) {
930 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
931 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
932 }
933 else {
934 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
935 return SendInternalMessageA(WM_CHAR, cmd, lParam);
936 }
937}
938//******************************************************************************
939//******************************************************************************
940ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
941{
942 ULONG lParam=0;
943
944 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
945 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
946 // bit 24, 1=extended key
947 // bit 25-28, reserved
948 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
949 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
950 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
951
952 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
953
954 setExtendedKey(virtualKey, &lParam);
955 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
956}
957//******************************************************************************
958//******************************************************************************
959ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
960{
961 ULONG lParam=0;
962
963 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
964 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
965 // bit 24, 1=extended key
966 // bit 25-28, reserved
967 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
968 if (keyWasPressed)
969 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
970 // bit 31, transition state, always 0 for WM_KEYDOWN
971
972 setExtendedKey(virtualKey, &lParam);
973
974 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
975
976 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
977}
978//******************************************************************************
979//******************************************************************************
980ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
981{
982 ULONG lParam=0;
983
984 lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
985 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
986 // bit 24, 1=extended key
987 // bit 25-28, reserved
988 lParam |= 0 << 29; // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
989 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
990 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
991
992 setExtendedKey(virtualKey, &lParam);
993 dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
994
995 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
996}
997//******************************************************************************
998//******************************************************************************
999ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1000{
1001 ULONG lParam=0;
1002
1003 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1004 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1005 // bit 24, 1=extended key
1006 // bit 25-28, reserved
1007 // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
1008 if (keyWasPressed)
1009 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1010 // bit 31, transition state, always 0 for WM_KEYDOWN
1011
1012 setExtendedKey(virtualKey, &lParam);
1013 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1014
1015 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
1016}
1017//******************************************************************************
1018//******************************************************************************
1019ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1020{
1021 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1022}
1023//******************************************************************************
1024//******************************************************************************
1025ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1026{
1027 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1028}
1029//******************************************************************************
1030//******************************************************************************
1031//******************************************************************************
1032ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
1033{
1034 ULONG win32msg;
1035 ULONG win32ncmsg;
1036
1037 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1038 switch(msg) {
1039 case BUTTON_LEFTDOWN:
1040 win32msg = WM_LBUTTONDOWN;
1041 win32ncmsg = WM_NCLBUTTONDOWN;
1042 break;
1043 case BUTTON_LEFTUP:
1044 win32msg = WM_LBUTTONUP;
1045 win32ncmsg = WM_NCLBUTTONUP;
1046 break;
1047 case BUTTON_LEFTDBLCLICK:
1048 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1049 {
1050 win32msg = WM_LBUTTONDBLCLK;
1051 win32ncmsg = WM_NCLBUTTONDBLCLK;
1052 } else
1053 {
1054 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1055 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1056 }
1057 break;
1058 case BUTTON_RIGHTUP:
1059 win32msg = WM_RBUTTONUP;
1060 win32ncmsg = WM_NCRBUTTONUP;
1061 break;
1062 case BUTTON_RIGHTDOWN:
1063 win32msg = WM_RBUTTONDOWN;
1064 win32ncmsg = WM_NCRBUTTONDOWN;
1065 break;
1066 case BUTTON_RIGHTDBLCLICK:
1067 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1068 {
1069 win32msg = WM_RBUTTONDBLCLK;
1070 win32ncmsg = WM_NCRBUTTONDBLCLK;
1071 } else
1072 {
1073 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1074 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1075 }
1076 break;
1077 case BUTTON_MIDDLEUP:
1078 win32msg = WM_MBUTTONUP;
1079 win32ncmsg = WM_NCMBUTTONUP;
1080 break;
1081 case BUTTON_MIDDLEDOWN:
1082 win32msg = WM_MBUTTONDOWN;
1083 win32ncmsg = WM_NCMBUTTONDOWN;
1084 break;
1085 case BUTTON_MIDDLEDBLCLICK:
1086 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1087 {
1088 win32msg = WM_MBUTTONDBLCLK;
1089 win32ncmsg = WM_NCMBUTTONDBLCLK;
1090 } else
1091 {
1092 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1093 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1094 }
1095 break;
1096 default:
1097 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1098 return 1;
1099 }
1100
1101 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1102
1103 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1104 if(lastHitTestVal != HTCLIENT) {
1105 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1106 }
1107 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1108}
1109//******************************************************************************
1110//******************************************************************************
1111ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1112{
1113 ULONG winstate = 0;
1114 ULONG setcursormsg = WM_MOUSEMOVE;
1115
1116 if(keystate & WMMOVE_LBUTTON)
1117 winstate |= MK_LBUTTON;
1118 if(keystate & WMMOVE_RBUTTON)
1119 winstate |= MK_RBUTTON;
1120 if(keystate & WMMOVE_MBUTTON)
1121 winstate |= MK_MBUTTON;
1122 if(keystate & WMMOVE_SHIFT)
1123 winstate |= MK_SHIFT;
1124 if(keystate & WMMOVE_CTRL)
1125 winstate |= MK_CONTROL;
1126
1127 if(lastHitTestVal != HTCLIENT) {
1128 setcursormsg = WM_NCMOUSEMOVE;
1129 }
1130 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1131 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1132
1133 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1134 if(lastHitTestVal != HTCLIENT) {
1135 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1136 }
1137 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1138}
1139//******************************************************************************
1140//******************************************************************************
1141ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1142{
1143 if (select && isIcon)
1144 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1145 else
1146 return SendInternalMessageA(WM_PAINT, 0, 0);
1147}
1148//******************************************************************************
1149//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1150// (or are we simply erasing too much here)
1151//******************************************************************************
1152ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1153{
1154 ULONG rc;
1155 HDC hdcErase = hdc;
1156
1157 if (hdcErase == 0)
1158 hdcErase = O32_GetDC(OS2Hwnd);
1159
1160 if(isIcon)
1161 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1162 else
1163 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1164 if (hdc == 0)
1165 O32_ReleaseDC(OS2Hwnd, hdcErase);
1166 return (rc);
1167}
1168//******************************************************************************
1169//******************************************************************************
1170ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1171{
1172 if(isUnicode) {
1173 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1174 }
1175 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1176}
1177//******************************************************************************
1178//TODO: in- or excluding terminating 0?
1179//******************************************************************************
1180ULONG Win32BaseWindow::MsgGetTextLength()
1181{
1182 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1183}
1184//******************************************************************************
1185//******************************************************************************
1186char *Win32BaseWindow::MsgGetText()
1187{
1188 if(isUnicode) {
1189 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1190 }
1191 else {
1192 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1193 }
1194 return windowNameA;
1195}
1196//******************************************************************************
1197//******************************************************************************
1198BOOL Win32BaseWindow::isMDIClient()
1199{
1200 return FALSE;
1201}
1202//******************************************************************************
1203//******************************************************************************
1204BOOL Win32BaseWindow::isMDIChild()
1205{
1206 return FALSE;
1207}
1208//******************************************************************************
1209//TODO: Not complete
1210//******************************************************************************
1211BOOL Win32BaseWindow::isFrameWindow()
1212{
1213// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1214 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1215 return TRUE;
1216
1217 return FALSE;
1218}
1219//******************************************************************************
1220//TODO: Not complete (flags)
1221//******************************************************************************
1222SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1223{
1224 switch(nBar) {
1225 case SB_HORZ:
1226 if(horzScrollInfo) {
1227 //CB:horzScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndHorzScroll);
1228 return horzScrollInfo;
1229 }
1230 break;
1231 case SB_VERT:
1232 if(vertScrollInfo) {
1233 //CB:vertScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndVertScroll);
1234 return vertScrollInfo;
1235 }
1236 break;
1237 }
1238 return NULL;
1239}
1240/***********************************************************************/
1241/***********************************************************************/
1242VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1243{
1244 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1245}
1246/***********************************************************************
1247 * NC_HandleSysCommand
1248 *
1249 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1250 *
1251 * TODO: Not done (see #if 0)
1252 */
1253LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1254{
1255 UINT uCommand = wParam & 0xFFF0;
1256
1257 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1258 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1259
1260 switch (uCommand)
1261 {
1262#if 0
1263 case SC_SIZE:
1264 case SC_MOVE:
1265 NC_DoSizeMove( hwnd, wParam );
1266 break;
1267#endif
1268
1269 case SC_MINIMIZE:
1270 ShowWindow(SW_MINIMIZE);
1271 break;
1272
1273 case SC_MAXIMIZE:
1274 ShowWindow(SW_MAXIMIZE);
1275 break;
1276
1277 case SC_RESTORE:
1278 ShowWindow(SW_RESTORE);
1279 break;
1280
1281 case SC_CLOSE:
1282 return SendMessageA(WM_CLOSE, 0, 0);
1283
1284#if 0
1285 case SC_VSCROLL:
1286 case SC_HSCROLL:
1287 NC_TrackScrollBar( hwnd, wParam, pt32 );
1288 break;
1289
1290 case SC_MOUSEMENU:
1291 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1292 break;
1293
1294 case SC_KEYMENU:
1295 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1296 break;
1297
1298 case SC_TASKLIST:
1299 WinExec( "taskman.exe", SW_SHOWNORMAL );
1300 break;
1301
1302 case SC_SCREENSAVE:
1303 if (wParam == SC_ABOUTWINE)
1304 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1305 else
1306 if (wParam == SC_PUTMARK)
1307 dprintf(("Mark requested by user\n"));
1308 break;
1309
1310 case SC_HOTKEY:
1311 case SC_ARRANGE:
1312 case SC_NEXTWINDOW:
1313 case SC_PREVWINDOW:
1314 break;
1315#endif
1316 }
1317 return 0;
1318}
1319//******************************************************************************
1320//******************************************************************************
1321LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1322{
1323 //SvL: Set background color to default button color (not window (white))
1324 if(ctlType == CTLCOLOR_BTN)
1325 {
1326 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1327 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1328 return GetSysColorBrush(COLOR_BTNFACE);
1329 }
1330 //SvL: Set background color to default dialog color if window is dialog
1331 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1332 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1333 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1334 return GetSysColorBrush(COLOR_BTNFACE);
1335 }
1336
1337 if( ctlType == CTLCOLOR_SCROLLBAR)
1338 {
1339 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1340 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1341 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1342 SetBkColor( hdc, bk);
1343
1344//TODO?
1345#if 0
1346 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1347 * we better use 0x55aa bitmap brush to make scrollbar's background
1348 * look different from the window background.
1349 */
1350 if (bk == GetSysColor(COLOR_WINDOW)) {
1351 return CACHE_GetPattern55AABrush();
1352 }
1353#endif
1354 UnrealizeObject( hb );
1355 return (LRESULT)hb;
1356 }
1357
1358 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1359
1360 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1361 {
1362 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1363 }
1364 else
1365 {
1366 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1367 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1368 }
1369 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1370}
1371//******************************************************************************
1372//******************************************************************************
1373LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1374{
1375 switch(Msg)
1376 {
1377 case WM_CLOSE:
1378 DestroyWindow();
1379 return 0;
1380
1381 case WM_GETTEXTLENGTH:
1382 return wndNameLength;
1383
1384 case WM_GETTEXT: //TODO: SS_ICON controls
1385 strncpy((LPSTR)lParam, windowNameA, wParam);
1386 return min(wndNameLength, wParam);
1387
1388 case WM_SETTEXT:
1389 if(!fInternalMsg) {
1390 return SetWindowTextA((LPSTR)lParam);
1391 }
1392 else return 0;
1393
1394 case WM_SETREDRAW:
1395 if(wParam)
1396 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1397 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1398
1399 return 0; //TODO
1400
1401 case WM_NCCREATE:
1402 return(TRUE);
1403
1404 case WM_NCCALCSIZE:
1405 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1406
1407 case WM_CTLCOLORMSGBOX:
1408 case WM_CTLCOLOREDIT:
1409 case WM_CTLCOLORLISTBOX:
1410 case WM_CTLCOLORBTN:
1411 case WM_CTLCOLORDLG:
1412 case WM_CTLCOLORSTATIC:
1413 case WM_CTLCOLORSCROLLBAR:
1414 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1415
1416 case WM_CTLCOLOR:
1417 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1418
1419 case WM_VKEYTOITEM:
1420 case WM_CHARTOITEM:
1421 return -1;
1422
1423 case WM_PARENTNOTIFY:
1424 return 0;
1425
1426 case WM_MOUSEACTIVATE:
1427 {
1428 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1429 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1430 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1431 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1432 {
1433 if(getParent()) {
1434 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1435 if(rc) return rc;
1436 }
1437 }
1438 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1439 }
1440 case WM_SETCURSOR:
1441 {
1442 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1443 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1444 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1445 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1446 {
1447 if(getParent()) {
1448 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1449 if(rc) return rc;
1450 }
1451 }
1452 return 1;
1453 }
1454 case WM_MOUSEMOVE:
1455 return 1; //Let OS/2 change the mouse cursor back to the default
1456
1457 case WM_WINDOWPOSCHANGED:
1458 {
1459
1460/* undocumented SWP flags - from SDK 3.1 */
1461#define SWP_NOCLIENTSIZE 0x0800
1462#define SWP_NOCLIENTMOVE 0x1000
1463
1464 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1465 WPARAM wp = SIZE_RESTORED;
1466
1467 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1468 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1469
1470 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1471 {
1472 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1473 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1474
1475 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1476 rectClient.bottom - rectClient.top));
1477 }
1478 return 0;
1479 }
1480 case WM_ERASEBKGND:
1481 case WM_ICONERASEBKGND:
1482 {
1483 RECT rect;
1484 int rc;
1485
1486 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1487
1488 rc = GetClipBox( (HDC)wParam, &rect );
1489 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1490 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1491
1492 return 1;
1493 }
1494 case WM_GETDLGCODE:
1495 return 0;
1496
1497 case WM_NCLBUTTONDOWN:
1498 case WM_NCLBUTTONUP:
1499 case WM_NCLBUTTONDBLCLK:
1500 case WM_NCRBUTTONUP:
1501 case WM_NCRBUTTONDOWN:
1502 case WM_NCRBUTTONDBLCLK:
1503 case WM_NCMBUTTONDOWN:
1504 case WM_NCMBUTTONUP:
1505 case WM_NCMBUTTONDBLCLK:
1506 return 0; //TODO: Send WM_SYSCOMMAND if required
1507
1508 case WM_NCHITTEST: //TODO: Calculate position of
1509 return HTCLIENT;
1510
1511 case WM_SYSCOMMAND:
1512 {
1513 POINT point;
1514
1515 point.x = LOWORD(lParam);
1516 point.y = HIWORD(lParam);
1517 return HandleSysCommand(wParam, &point);
1518 }
1519
1520 case WM_SYSKEYDOWN:
1521 if(HIWORD(lParam) & KEYDATA_ALT)
1522 {
1523 if(wParam == VK_F4) /* try to close the window */
1524 {
1525 Win32BaseWindow *window = GetTopParent();
1526 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE) )
1527 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1528 }
1529 }
1530 return 0;
1531
1532 case WM_QUERYOPEN:
1533 case WM_QUERYENDSESSION:
1534 return 1;
1535
1536 case WM_NOTIFYFORMAT:
1537 if (IsUnicode()) return NFR_UNICODE;
1538 else return NFR_ANSI;
1539
1540 case WM_SETICON:
1541 case WM_GETICON:
1542 {
1543 LRESULT result = 0;
1544 if (!windowClass) return result;
1545 int index = GCL_HICON;
1546
1547 if (wParam == ICON_SMALL)
1548 index = GCL_HICONSM;
1549
1550 result = windowClass->getClassLongA(index);
1551
1552 if (Msg == WM_SETICON)
1553 windowClass->setClassLongA(index, lParam);
1554
1555 return result;
1556 }
1557
1558 default:
1559 return 1;
1560 }
1561}
1562//******************************************************************************
1563//******************************************************************************
1564LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1565{
1566 switch(Msg)
1567 {
1568 case WM_GETTEXTLENGTH:
1569 return wndNameLength;
1570
1571 case WM_GETTEXT: //TODO: SS_ICON controls
1572 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1573 return min(wndNameLength, wParam);
1574
1575 case WM_SETTEXT:
1576 if(!fInternalMsg) {
1577 return SetWindowTextW((LPWSTR)lParam);
1578 }
1579 else return 0;
1580
1581 default:
1582 return DefWindowProcA(Msg, wParam, lParam);
1583 }
1584}
1585//******************************************************************************
1586//******************************************************************************
1587LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1588{
1589 LRESULT rc;
1590 BOOL fInternalMsgBackup = fInternalMsg;
1591
1592 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1593 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1594 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1595 }
1596
1597 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1598 return(0);
1599 }
1600 fInternalMsg = FALSE;
1601 switch(Msg)
1602 {
1603 case WM_CREATE:
1604 {
1605 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1606 dprintf(("WM_CREATE returned -1\n"));
1607 rc = -1; //don't create window
1608 break;
1609 }
1610 NotifyParent(Msg, wParam, lParam);
1611
1612 rc = 0;
1613 break;
1614 }
1615 case WM_SETTEXT:
1616 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1617 break;
1618
1619 case WM_LBUTTONDOWN:
1620 case WM_MBUTTONDOWN:
1621 case WM_RBUTTONDOWN:
1622 NotifyParent(Msg, wParam, lParam);
1623 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1624 break;
1625
1626 case WM_DESTROY:
1627 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1628 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1629 break;
1630
1631 default:
1632 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1633 break;
1634 }
1635 fInternalMsg = fInternalMsgBackup;
1636 return rc;
1637}
1638//******************************************************************************
1639//******************************************************************************
1640LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1641{
1642 LRESULT rc;
1643 BOOL fInternalMsgBackup = fInternalMsg;
1644
1645 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1646 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1647 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1648 }
1649
1650 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1651 return(0);
1652 }
1653 fInternalMsg = FALSE;
1654 switch(Msg)
1655 {
1656 case WM_CREATE:
1657 {
1658 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1659 dprintf(("WM_CREATE returned -1\n"));
1660 rc = -1; //don't create window
1661 break;
1662 }
1663 NotifyParent(Msg, wParam, lParam);
1664
1665 rc = 0;
1666 break;
1667 }
1668 case WM_SETTEXT:
1669 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1670 break;
1671
1672 case WM_LBUTTONDOWN:
1673 case WM_MBUTTONDOWN:
1674 case WM_RBUTTONDOWN:
1675 NotifyParent(Msg, wParam, lParam);
1676 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1677 break;
1678
1679 case WM_DESTROY:
1680 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1681 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1682 break;
1683
1684 default:
1685 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1686 break;
1687 }
1688 fInternalMsg = fInternalMsgBackup;
1689 return rc;
1690}
1691//******************************************************************************
1692//Called as a result of an OS/2 message
1693//******************************************************************************
1694LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1695{
1696 LRESULT rc;
1697 BOOL fInternalMsgBackup = fInternalMsg;
1698
1699 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1700 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1701
1702 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1703 return(0);
1704 }
1705 fInternalMsg = TRUE;
1706 switch(Msg)
1707 {
1708 case WM_CREATE:
1709 {
1710 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1711 dprintf(("WM_CREATE returned -1\n"));
1712 rc = -1; //don't create window
1713 break;
1714 }
1715 NotifyParent(Msg, wParam, lParam);
1716 rc = 0;
1717 break;
1718 }
1719 case WM_LBUTTONDOWN:
1720 case WM_MBUTTONDOWN:
1721 case WM_RBUTTONDOWN:
1722 NotifyParent(Msg, wParam, lParam);
1723 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1724 break;
1725
1726 case WM_DESTROY:
1727 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1728 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1729 break;
1730 default:
1731 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1732 break;
1733 }
1734 fInternalMsg = fInternalMsgBackup;
1735 return rc;
1736}
1737//******************************************************************************
1738//Called as a result of an OS/2 message
1739//todo, unicode msgs (WM_SETTEXT etc)
1740//******************************************************************************
1741LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1742{
1743 LRESULT rc;
1744 BOOL fInternalMsgBackup = fInternalMsg;
1745
1746 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1747 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1748
1749 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1750 return(0);
1751 }
1752 fInternalMsg = TRUE;
1753 switch(Msg)
1754 {
1755 case WM_CREATE:
1756 {
1757 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1758 dprintf(("WM_CREATE returned -1\n"));
1759 rc = -1; //don't create window
1760 break;
1761 }
1762 NotifyParent(Msg, wParam, lParam);
1763 rc = 0;
1764 break;
1765 }
1766 case WM_LBUTTONDOWN:
1767 case WM_MBUTTONDOWN:
1768 case WM_RBUTTONDOWN:
1769 NotifyParent(Msg, wParam, lParam);
1770 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1771 break;
1772
1773 case WM_DESTROY:
1774 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1775 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1776 break;
1777 default:
1778 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1779 break;
1780 }
1781 fInternalMsg = fInternalMsgBackup;
1782 return rc;
1783}
1784//******************************************************************************
1785//******************************************************************************
1786BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1787{
1788 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1789}
1790//******************************************************************************
1791//******************************************************************************
1792BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1793{
1794 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1795}
1796//******************************************************************************
1797//TODO: do we need to inform the parent of the parent (etc) of the child window?
1798//******************************************************************************
1799void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1800{
1801 Win32BaseWindow *window = this;
1802 Win32BaseWindow *parentwindow;
1803
1804 while(window)
1805 {
1806 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1807 {
1808 /* Notify the parent window only */
1809 parentwindow = window->getParent();
1810 if(parentwindow) {
1811 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1812 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1813 }
1814 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1815 }
1816 }
1817 else break;
1818
1819 window = parentwindow;
1820 }
1821}
1822//******************************************************************************
1823//******************************************************************************
1824Win32BaseWindow *Win32BaseWindow::getTopParent()
1825{
1826 Win32BaseWindow *tmpWnd = this;
1827
1828 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1829 {
1830 tmpWnd = tmpWnd->getParent();
1831 }
1832 return tmpWnd;
1833}
1834//******************************************************************************
1835//******************************************************************************
1836BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1837{
1838
1839 dprintf(("SetMenu %x", hMenu));
1840 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1841 if(OS2HwndMenu == 0) {
1842 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1843 return FALSE;
1844 }
1845 return TRUE;
1846}
1847//******************************************************************************
1848//******************************************************************************
1849BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1850{
1851 Win32Resource *winres = (Win32Resource *)hAccel;
1852 HANDLE accelhandle;
1853
1854 if(HIWORD(hAccel) == 0) {
1855 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1856 SetLastError(ERROR_INVALID_PARAMETER);
1857 return FALSE;
1858 }
1859 acceltableResource = winres;
1860 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1861 winres->setOS2Handle(accelhandle);
1862 return(accelhandle != 0);
1863}
1864//******************************************************************************
1865//******************************************************************************
1866BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1867{
1868 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1869 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1870 SendMessageA(WM_SETICON, hIcon, 0);
1871 return TRUE;
1872 }
1873 return FALSE;
1874}
1875//******************************************************************************
1876//******************************************************************************
1877BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1878{
1879 ULONG showstate = 0;
1880
1881 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
1882#if 1
1883 if (flags & WIN_NEED_SIZE)
1884 {
1885 /* should happen only in CreateWindowEx() */
1886 int wParam = SIZE_RESTORED;
1887
1888 flags &= ~WIN_NEED_SIZE;
1889 if (dwStyle & WS_MAXIMIZE)
1890 wParam = SIZE_MAXIMIZED;
1891 else
1892 if (dwStyle & WS_MINIMIZE)
1893 wParam = SIZE_MINIMIZED;
1894
1895 SendMessageA(WM_SIZE, wParam,
1896 MAKELONG(rectClient.right-rectClient.left,
1897 rectClient.bottom-rectClient.top));
1898 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1899 }
1900#else
1901 if(fFirstShow) {
1902 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
1903 SendMessageA(WM_SIZE, SIZE_RESTORED,
1904 MAKELONG(rectClient.right-rectClient.left,
1905 rectClient.bottom-rectClient.top));
1906 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1907
1908 }
1909 fFirstShow = FALSE;
1910 }
1911#endif
1912 switch(nCmdShow)
1913 {
1914 case SW_SHOW:
1915 case SW_SHOWDEFAULT: //todo
1916 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1917 break;
1918 case SW_HIDE:
1919 showstate = SWPOS_HIDE;
1920 break;
1921 case SW_RESTORE:
1922 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1923 break;
1924 case SW_MINIMIZE:
1925 showstate = SWPOS_MINIMIZE;
1926 break;
1927 case SW_SHOWMAXIMIZED:
1928 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1929 break;
1930 case SW_SHOWMINIMIZED:
1931 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1932 break;
1933 case SW_SHOWMINNOACTIVE:
1934 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1935 break;
1936 case SW_SHOWNA:
1937 showstate = SWPOS_SHOW;
1938 break;
1939 case SW_SHOWNOACTIVATE:
1940 showstate = SWPOS_SHOW;
1941 break;
1942 case SW_SHOWNORMAL:
1943 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1944 break;
1945 }
1946
1947#if 0
1948 if(showstate & SWPOS_SHOW && (getStyle() & WS_VISIBLE) == 0) {
1949 SetWindowLongA(GWL_STYLE, getStyle() | WS_VISIBLE);
1950 }
1951#endif
1952 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
1953 return rc;
1954}
1955//******************************************************************************
1956//******************************************************************************
1957BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1958{
1959 BOOL rc = FALSE;
1960 Win32BaseWindow *window;
1961 HWND hParent = 0;
1962
1963 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1964
1965 if (fuFlags &
1966 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1967 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1968 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1969 SWP_NOOWNERZORDER))
1970 {
1971 return FALSE;
1972 }
1973
1974 WINDOWPOS wpos;
1975 SWP swp, swpOld;
1976
1977 wpos.flags = fuFlags;
1978 wpos.cy = cy;
1979 wpos.cx = cx;
1980 wpos.x = x;
1981 wpos.y = y;
1982 wpos.hwndInsertAfter = hwndInsertAfter;
1983 wpos.hwnd = getWindowHandle();
1984
1985 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
1986 {
1987 if (isChild())
1988 {
1989 hParent = getParent()->getOS2WindowHandle();
1990 }
1991 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1992 }
1993
1994 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1995 if (swp.fl == 0)
1996 return TRUE;
1997
1998// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1999 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2000 {
2001 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2002 if(wndBehind) {
2003 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2004 }
2005 else {
2006 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2007 swp.hwndInsertBehind = 0;
2008 }
2009 }
2010#if 0
2011 if (isFrameWindow())
2012 {
2013 if (!isChild())
2014 {
2015 POINT maxSize, maxPos, minTrack, maxTrack;
2016
2017 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2018
2019 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2020 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2021 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2022 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2023 }
2024 swp.hwnd = OS2HwndFrame;
2025 }
2026 else
2027#endif
2028 swp.hwnd = OS2HwndFrame;
2029
2030 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2031
2032 rc = OSLibWinSetMultWindowPos(&swp, 1);
2033
2034 if (rc == FALSE)
2035 {
2036 dprintf(("OSLibWinSetMultWindowPos failed!"));
2037 }
2038 else
2039 {
2040 if (fuFlags & SWP_FRAMECHANGED_W)
2041 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2042 }
2043
2044 return (rc);
2045}
2046//******************************************************************************
2047//Also destroys all the child windows (destroy parent, destroy children)
2048//******************************************************************************
2049BOOL Win32BaseWindow::DestroyWindow()
2050{
2051 return OSLibWinDestroyWindow(OS2HwndFrame);
2052}
2053//******************************************************************************
2054//******************************************************************************
2055HWND Win32BaseWindow::GetParent()
2056{
2057 if(getParent()) {
2058 return getParent()->getWindowHandle();
2059 }
2060 else return 0;
2061}
2062//******************************************************************************
2063//******************************************************************************
2064HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2065{
2066 HWND oldhwnd;
2067 Win32BaseWindow *newparent;
2068
2069 if(getParent()) {
2070 oldhwnd = getParent()->getWindowHandle();
2071 getParent()->RemoveChild(this);
2072 }
2073 else oldhwnd = 0;
2074
2075 if(hwndNewParent == 0) {//desktop window = parent
2076 setParent(NULL);
2077 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2078 return oldhwnd;
2079 }
2080 newparent = GetWindowFromHandle(hwndNewParent);
2081 if(newparent)
2082 {
2083 setParent(newparent);
2084 getParent()->AddChild(this);
2085 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2086 return oldhwnd;
2087 }
2088 SetLastError(ERROR_INVALID_PARAMETER);
2089 return 0;
2090}
2091//******************************************************************************
2092//******************************************************************************
2093BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2094{
2095 if(getParent()) {
2096 return getParent()->getWindowHandle() == hwndParent;
2097 }
2098 else return 0;
2099}
2100//******************************************************************************
2101//******************************************************************************
2102HWND Win32BaseWindow::GetTopWindow()
2103{
2104 return GetWindow(GW_CHILD);
2105}
2106//******************************************************************************
2107// Get the top-level parent for a child window.
2108//******************************************************************************
2109Win32BaseWindow *Win32BaseWindow::GetTopParent()
2110{
2111 Win32BaseWindow *window = this;
2112
2113 while(window && (window->getStyle() & WS_CHILD))
2114 {
2115 window = window->getParent();
2116 }
2117 return window;
2118}
2119//******************************************************************************
2120//Don't call WinUpdateWindow as that one also updates the child windows
2121//Also need to send WM_PAINT directly to the window procedure, which doesn't
2122//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2123//******************************************************************************
2124BOOL Win32BaseWindow::UpdateWindow()
2125{
2126 RECT rect;
2127
2128 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2129 {//update region not empty
2130 HDC hdc;
2131
2132 hdc = O32_GetDC(OS2Hwnd);
2133 if (isIcon)
2134 {
2135 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2136 SendMessageA(WM_PAINTICON, 0, 0);
2137 } else
2138 {
2139 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2140 SendMessageA(WM_PAINT, 0, 0);
2141 }
2142 O32_ReleaseDC(OS2Hwnd, hdc);
2143 }
2144 return TRUE;
2145}
2146//******************************************************************************
2147//******************************************************************************
2148BOOL Win32BaseWindow::IsIconic()
2149{
2150 return OSLibWinIsIconic(OS2Hwnd);
2151}
2152//******************************************************************************
2153//TODO:
2154//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2155//the current process owns them.
2156//******************************************************************************
2157HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2158 BOOL fUnicode)
2159{
2160 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2161 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2162
2163 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2164 (hwndChildAfter != 0 && !child) ||
2165 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2166 {
2167 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2168 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2169 return 0;
2170 }
2171 if(hwndParent != OSLIB_HWND_DESKTOP)
2172 {//if the current process owns the window, just do a quick search
2173 child = (Win32BaseWindow *)parent->getFirstChild();
2174 if(hwndChildAfter != 0)
2175 {
2176 while(child)
2177 {
2178 if(child->getWindowHandle() == hwndChildAfter)
2179 {
2180 child = (Win32BaseWindow *)child->getNextChild();
2181 break;
2182 }
2183 child = (Win32BaseWindow *)child->getNextChild();
2184 }
2185 }
2186 while(child)
2187 {
2188 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2189 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2190 {
2191 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2192 return child->getWindowHandle();
2193 }
2194 child = (Win32BaseWindow *)child->getNextChild();
2195 }
2196 }
2197 else {
2198 Win32BaseWindow *wnd;
2199 HWND henum, hwnd;
2200
2201 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2202 hwnd = OSLibWinGetNextWindow(henum);
2203
2204 while(hwnd)
2205 {
2206 wnd = GetWindowFromOS2Handle(hwnd);
2207 if(wnd == NULL) {
2208 hwnd = OSLibWinQueryClientWindow(hwnd);
2209 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2210 }
2211
2212 if(wnd) {
2213 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
2214
2215 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
2216 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
2217 break;
2218 }
2219 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2220 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2221 {
2222 OSLibWinEndEnumWindows(henum);
2223 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2224 return wnd->getWindowHandle();
2225 }
2226 }
2227 hwnd = OSLibWinGetNextWindow(henum);
2228 }
2229 OSLibWinEndEnumWindows(henum);
2230 }
2231 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2232 return 0;
2233}
2234//******************************************************************************
2235//******************************************************************************
2236HWND Win32BaseWindow::GetWindow(UINT uCmd)
2237{
2238 HWND hwndRelated = 0;
2239 Win32BaseWindow *window;
2240
2241 switch(uCmd)
2242 {
2243 case GW_HWNDFIRST:
2244 if(getParent()) {
2245 window = (Win32BaseWindow *)getParent()->getFirstChild();
2246 hwndRelated = window->getWindowHandle();
2247 }
2248 break;
2249
2250 case GW_HWNDLAST:
2251 if(getParent())
2252 {
2253 goto end;
2254 }
2255
2256 window = this;
2257 while(window)
2258 {
2259 window = (Win32BaseWindow *)window->getNextChild();
2260 }
2261 hwndRelated = window->getWindowHandle();
2262 break;
2263
2264 case GW_HWNDNEXT:
2265 window = (Win32BaseWindow *)getNextChild();
2266 if(window) {
2267 hwndRelated = window->getWindowHandle();
2268 }
2269 break;
2270
2271 case GW_HWNDPREV:
2272 if(!getParent())
2273 {
2274 goto end;
2275 }
2276 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2277 if(window == this)
2278 {
2279 hwndRelated = 0; /* First in list */
2280 goto end;
2281 }
2282 while(window->getNextChild())
2283 {
2284 if (window->getNextChild() == this)
2285 {
2286 hwndRelated = window->getWindowHandle();
2287 goto end;
2288 }
2289 window = (Win32BaseWindow *)window->getNextChild();
2290 }
2291 break;
2292
2293 case GW_OWNER:
2294 if(getOwner()) {
2295 hwndRelated = getOwner()->getWindowHandle();
2296 }
2297 break;
2298
2299 case GW_CHILD:
2300 if(getFirstChild()) {
2301 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2302 }
2303 break;
2304 }
2305end:
2306 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2307 return hwndRelated;
2308}
2309//******************************************************************************
2310//******************************************************************************
2311HWND Win32BaseWindow::SetActiveWindow()
2312{
2313 return OSLibWinSetActiveWindow(OS2Hwnd);
2314}
2315//******************************************************************************
2316//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2317//******************************************************************************
2318BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2319{
2320 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
2321}
2322//******************************************************************************
2323//******************************************************************************
2324BOOL Win32BaseWindow::CloseWindow()
2325{
2326 return OSLibWinMinimizeWindow(OS2Hwnd);
2327}
2328//******************************************************************************
2329//******************************************************************************
2330HWND Win32BaseWindow::GetActiveWindow()
2331{
2332 HWND hwndActive;
2333 Win32BaseWindow *win32wnd;
2334 ULONG magic;
2335
2336 hwndActive = OSLibWinQueryActiveWindow();
2337
2338 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2339 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2340 if(CheckMagicDword(magic) && win32wnd)
2341 {
2342 return win32wnd->getWindowHandle();
2343 }
2344 return hwndActive;
2345}
2346//******************************************************************************
2347//******************************************************************************
2348BOOL Win32BaseWindow::IsWindowEnabled()
2349{
2350 return OSLibWinIsWindowEnabled(OS2Hwnd);
2351}
2352//******************************************************************************
2353//******************************************************************************
2354BOOL Win32BaseWindow::IsWindowVisible()
2355{
2356 return OSLibWinIsWindowVisible(OS2Hwnd);
2357}
2358//******************************************************************************
2359//******************************************************************************
2360BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2361{
2362 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2363}
2364//******************************************************************************
2365//******************************************************************************
2366BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2367{
2368 if(fUnicode) {
2369 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2370 }
2371 else return (strcmp(windowNameA, wndname) == 0);
2372}
2373//******************************************************************************
2374//******************************************************************************
2375int Win32BaseWindow::GetWindowTextLength()
2376{
2377 return wndNameLength;
2378}
2379//******************************************************************************
2380//******************************************************************************
2381int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2382{
2383 strncpy(lpsz, windowNameA, cch);
2384 return wndNameLength;
2385}
2386//******************************************************************************
2387//******************************************************************************
2388int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2389{
2390 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2391 return wndNameLength;
2392}
2393//******************************************************************************
2394//******************************************************************************
2395BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2396{
2397 if(lpsz == NULL)
2398 return FALSE;
2399
2400 if(windowNameA) free(windowNameA);
2401 if(windowNameW) free(windowNameW);
2402
2403 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2404 strcpy(windowNameA, lpsz);
2405 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2406 lstrcpyAtoW(windowNameW, windowNameA);
2407 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2408
2409 if(OS2HwndFrame)
2410 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2411
2412 return TRUE;
2413}
2414//******************************************************************************
2415//******************************************************************************
2416BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2417{
2418 if(lpsz == NULL)
2419 return FALSE;
2420
2421 if(windowNameA) free(windowNameA);
2422 if(windowNameW) free(windowNameW);
2423
2424 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2425 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2426 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2427 lstrcpyWtoA(windowNameA, windowNameW);
2428 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2429
2430 if(OS2HwndFrame)
2431 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2432
2433 return TRUE;
2434}
2435//******************************************************************************
2436//******************************************************************************
2437LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2438{
2439 LONG oldval;
2440
2441 switch(index) {
2442 case GWL_EXSTYLE:
2443 {
2444 STYLESTRUCT ss;
2445
2446 ss.styleOld = dwExStyle;
2447 ss.styleNew = value;
2448 dprintf(("SetWindowLong GWL_EXSTYLE %x new style %x", getWindowHandle(), value));
2449 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2450 setExStyle(ss.styleNew);
2451 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2452 return ss.styleOld;
2453 }
2454 case GWL_STYLE:
2455 {
2456 STYLESTRUCT ss;
2457
2458 ss.styleOld = dwStyle;
2459 ss.styleNew = value;
2460 dprintf(("SetWindowLong GWL_STYLE %x new style %x", getWindowHandle(), value));
2461 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2462 setStyle(ss.styleNew);
2463 OSLibSetWindowStyle(OS2HwndFrame, dwStyle);
2464 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2465 return ss.styleOld;
2466 }
2467 case GWL_WNDPROC:
2468 oldval = (LONG)getWindowProc();
2469 setWindowProc((WNDPROC)value);
2470 return oldval;
2471 case GWL_HINSTANCE:
2472 oldval = hInstance;
2473 hInstance = value;
2474 return oldval;
2475 case GWL_HWNDPARENT:
2476 return SetParent((HWND)value);
2477 case GWL_ID:
2478 oldval = getWindowId();
2479 setWindowId(value);
2480 return oldval;
2481 case GWL_USERDATA:
2482 oldval = userData;
2483 userData = value;
2484 return oldval;
2485 default:
2486 if(index >= 0 && index/4 < nrUserWindowLong)
2487 {
2488 oldval = userWindowLong[index/4];
2489 userWindowLong[index/4] = value;
2490 return oldval;
2491 }
2492 SetLastError(ERROR_INVALID_PARAMETER);
2493 return 0;
2494 }
2495}
2496//******************************************************************************
2497//******************************************************************************
2498ULONG Win32BaseWindow::GetWindowLongA(int index)
2499{
2500 switch(index) {
2501 case GWL_EXSTYLE:
2502 return dwExStyle;
2503 case GWL_STYLE:
2504 return dwStyle;
2505 case GWL_WNDPROC:
2506 return (ULONG)getWindowProc();
2507 case GWL_HINSTANCE:
2508 return hInstance;
2509 case GWL_HWNDPARENT:
2510 if(getParent()) {
2511 return getParent()->getWindowHandle();
2512 }
2513 else return 0;
2514 case GWL_ID:
2515 return getWindowId();
2516 case GWL_USERDATA:
2517 return userData;
2518 default:
2519 if(index >= 0 && index/4 < nrUserWindowLong)
2520 {
2521 return userWindowLong[index/4];
2522 }
2523 SetLastError(ERROR_INVALID_PARAMETER);
2524 return 0;
2525 }
2526}
2527//******************************************************************************
2528//******************************************************************************
2529WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2530{
2531 WORD oldval;
2532
2533 if(index >= 0 && index/4 < nrUserWindowLong)
2534 {
2535 oldval = ((WORD *)userWindowLong)[index/2];
2536 ((WORD *)userWindowLong)[index/2] = value;
2537 return oldval;
2538 }
2539 SetLastError(ERROR_INVALID_PARAMETER);
2540 return 0;
2541}
2542//******************************************************************************
2543//******************************************************************************
2544WORD Win32BaseWindow::GetWindowWord(int index)
2545{
2546 if(index >= 0 && index/4 < nrUserWindowLong)
2547 {
2548 return ((WORD *)userWindowLong)[index/2];
2549 }
2550 SetLastError(ERROR_INVALID_PARAMETER);
2551 return 0;
2552}
2553//******************************************************************************
2554//******************************************************************************
2555void Win32BaseWindow::setWindowId(DWORD id)
2556{
2557 windowId = id;
2558 OSLibSetWindowID(OS2HwndFrame, id);
2559}
2560//******************************************************************************
2561//******************************************************************************
2562Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2563{
2564 Win32BaseWindow *window;
2565
2566 if(hwnd == NULL && windowDesktop)
2567 return windowDesktop;
2568
2569 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2570 return window;
2571 }
2572 else return NULL;
2573}
2574//******************************************************************************
2575//******************************************************************************
2576Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2577{
2578 Win32BaseWindow *win32wnd;
2579 DWORD magic;
2580
2581 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2582 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2583
2584 if(win32wnd && CheckMagicDword(magic)) {
2585 return win32wnd;
2586 }
2587 return 0;
2588}
2589//******************************************************************************
2590//******************************************************************************
2591Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
2592{
2593 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
2594}
2595//******************************************************************************
2596//******************************************************************************
2597HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2598{
2599 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2600
2601 if(window) {
2602 return window->getOS2WindowHandle();
2603 }
2604 else return hwnd;
2605}
2606//******************************************************************************
2607//******************************************************************************
2608HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
2609{
2610 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2611
2612 if(window) {
2613 return window->getOS2FrameWindowHandle();
2614 }
2615 else return hwnd;
2616}
2617//******************************************************************************
2618//******************************************************************************
2619HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2620{
2621 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2622
2623 if(window) {
2624 return window->getWindowHandle();
2625 }
2626 window = GetWindowFromOS2FrameHandle(hwnd);
2627 if(window) {
2628 return window->getWindowHandle();
2629 }
2630 else return hwnd; //OS/2 window handle
2631}
2632//******************************************************************************
2633//******************************************************************************
2634#ifdef DEBUG
2635void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
2636{
2637 char style[256] = "";
2638 char exstyle[256] = "";
2639
2640 /* Window styles */
2641 if(dwStyle & WS_CHILD)
2642 strcat(style, "WS_CHILD ");
2643 if(dwStyle & WS_POPUP)
2644 strcat(style, "WS_POPUP ");
2645 if(dwStyle & WS_VISIBLE)
2646 strcat(style, "WS_VISIBLE ");
2647 if(dwStyle & WS_DISABLED)
2648 strcat(style, "WS_DISABLED ");
2649 if(dwStyle & WS_CLIPSIBLINGS)
2650 strcat(style, "WS_CLIPSIBLINGS ");
2651 if(dwStyle & WS_CLIPCHILDREN)
2652 strcat(style, "WS_CLIPCHILDREN ");
2653 if(dwStyle & WS_MAXIMIZE)
2654 strcat(style, "WS_MAXIMIZE ");
2655 if(dwStyle & WS_MINIMIZE)
2656 strcat(style, "WS_MINIMIZE ");
2657 if(dwStyle & WS_GROUP)
2658 strcat(style, "WS_GROUP ");
2659 if(dwStyle & WS_TABSTOP)
2660 strcat(style, "WS_TABSTOP ");
2661
2662 if((dwStyle & WS_CAPTION) == WS_CAPTION)
2663 strcat(style, "WS_CAPTION ");
2664 if(dwStyle & WS_DLGFRAME)
2665 strcat(style, "WS_DLGFRAME ");
2666 if(dwStyle & WS_BORDER)
2667 strcat(style, "WS_BORDER ");
2668
2669 if(dwStyle & WS_VSCROLL)
2670 strcat(style, "WS_VSCROLL ");
2671 if(dwStyle & WS_HSCROLL)
2672 strcat(style, "WS_HSCROLL ");
2673 if(dwStyle & WS_SYSMENU)
2674 strcat(style, "WS_SYSMENU ");
2675 if(dwStyle & WS_THICKFRAME)
2676 strcat(style, "WS_THICKFRAME ");
2677 if(dwStyle & WS_MINIMIZEBOX)
2678 strcat(style, "WS_MINIMIZEBOX ");
2679 if(dwStyle & WS_MAXIMIZEBOX)
2680 strcat(style, "WS_MAXIMIZEBOX ");
2681
2682 if(dwExStyle & WS_EX_DLGMODALFRAME)
2683 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
2684 if(dwExStyle & WS_EX_ACCEPTFILES)
2685 strcat(exstyle, "WS_EX_ACCEPTFILES ");
2686 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
2687 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
2688 if(dwExStyle & WS_EX_TOPMOST)
2689 strcat(exstyle, "WS_EX_TOPMOST ");
2690 if(dwExStyle & WS_EX_TRANSPARENT)
2691 strcat(exstyle, "WS_EX_TRANSPARENT ");
2692
2693 if(dwExStyle & WS_EX_MDICHILD)
2694 strcat(exstyle, "WS_EX_MDICHILD ");
2695 if(dwExStyle & WS_EX_TOOLWINDOW)
2696 strcat(exstyle, "WS_EX_TOOLWINDOW ");
2697 if(dwExStyle & WS_EX_WINDOWEDGE)
2698 strcat(exstyle, "WS_EX_WINDOWEDGE ");
2699 if(dwExStyle & WS_EX_CLIENTEDGE)
2700 strcat(exstyle, "WS_EX_CLIENTEDGE ");
2701 if(dwExStyle & WS_EX_CONTEXTHELP)
2702 strcat(exstyle, "WS_EX_CONTEXTHELP ");
2703 if(dwExStyle & WS_EX_RIGHT)
2704 strcat(exstyle, "WS_EX_RIGHT ");
2705 if(dwExStyle & WS_EX_LEFT)
2706 strcat(exstyle, "WS_EX_LEFT ");
2707 if(dwExStyle & WS_EX_RTLREADING)
2708 strcat(exstyle, "WS_EX_RTLREADING ");
2709 if(dwExStyle & WS_EX_LTRREADING)
2710 strcat(exstyle, "WS_EX_LTRREADING ");
2711 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
2712 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
2713 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
2714 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
2715 if(dwExStyle & WS_EX_CONTROLPARENT)
2716 strcat(exstyle, "WS_EX_CONTROLPARENT ");
2717 if(dwExStyle & WS_EX_STATICEDGE)
2718 strcat(exstyle, "WS_EX_STATICEDGE ");
2719 if(dwExStyle & WS_EX_APPWINDOW)
2720 strcat(exstyle, "WS_EX_APPWINDOW ");
2721
2722 dprintf(("Window style: %x %s", dwStyle, style));
2723 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
2724}
2725#endif
2726//******************************************************************************
2727//******************************************************************************
2728
2729GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.