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

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

Bugfixes for enum* apis & findwindowex

File size: 93.4 KB
Line 
1/* $Id: win32wbase.cpp,v 1.51 1999-10-17 16:59:58 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 fIsDestroyed = TRUE;
729 //According to the SDK, WM_PARENTNOTIFY messages are sent to the parent (this window)
730 //before any window destruction has begun
731 child = (Win32BaseWindow *)getFirstChild();
732 while(child) {
733 child->NotifyParent(WM_DESTROY, 0, 0);
734
735 child = (Win32BaseWindow *)child->getNextChild();
736 }
737 SendInternalMessageA(WM_DESTROY, 0, 0);
738
739 if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndHorzScroll);
740 if (hwndVertScroll && OSLibWinQueryWindow(hwndVertScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndVertScroll);
741
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 dwStyle &= ~(WS_MINIMIZE|WS_MAXIMIZE);
849 if(fMinimize) {
850 fwSizeType = SIZE_MINIMIZED;
851 dwStyle |= WS_MINIMIZE;
852 }
853 else
854 if(fMaximize) {
855 fwSizeType = SIZE_MAXIMIZED;
856 dwStyle |= WS_MAXIMIZE;
857 }
858 else fwSizeType = SIZE_RESTORED;
859
860 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
861}
862//******************************************************************************
863//******************************************************************************
864ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
865{
866 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
867
868 //According to SDK docs, if app returns FALSE & window is being deactivated,
869 //default processing is cancelled
870 //TODO: According to Wine we should proceed anyway if window is sysmodal
871 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
872 {
873 return 0;
874 }
875 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
876
877 curprocid = GetCurrentProcessId();
878 if(hwnd) {
879 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
880 }
881
882 if(curprocid != procidhwnd && fActivate) {
883 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
884 }
885 return rc;
886}
887//******************************************************************************
888//******************************************************************************
889ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
890{
891 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
892}
893//******************************************************************************
894//TODO: Is this correct and complete?
895//Add print screen, break & numlock
896//******************************************************************************
897void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
898{
899 switch(virtualkey) {
900 case VK_DOWN:
901 case VK_UP:
902 case VK_PRIOR:
903 case VK_NEXT:
904 case VK_END:
905 case VK_DIVIDE:
906 case VK_DELETE:
907 case VK_EXECUTE: //Numeric enter key?
908 case VK_HOME:
909 case VK_INSERT:
910 case VK_RCONTROL:
911 case VK_RMENU: //is this the right alt???
912 *lParam = *lParam | (1<<24);
913 }
914}
915//******************************************************************************
916//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
917//******************************************************************************
918ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
919{
920 ULONG lParam = 0;
921
922 lParam = repeatcnt;
923 lParam |= (scancode << 16);
924 setExtendedKey(vkey, &lParam);
925
926 if(keyflags & KEY_ALTDOWN)
927 lParam |= (1<<29);
928 if(keyflags & KEY_PREVDOWN)
929 lParam |= (1<<30);
930 if(keyflags & KEY_UP)
931 lParam |= (1<<31);
932 if(keyflags & KEY_DEADKEY) {
933 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
934 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
935 }
936 else {
937 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
938 return SendInternalMessageA(WM_CHAR, cmd, lParam);
939 }
940}
941//******************************************************************************
942//******************************************************************************
943ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
944{
945 ULONG lParam=0;
946
947 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
948 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
949 // bit 24, 1=extended key
950 // bit 25-28, reserved
951 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
952 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
953 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
954
955 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
956
957 setExtendedKey(virtualKey, &lParam);
958 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
959}
960//******************************************************************************
961//******************************************************************************
962ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
963{
964 ULONG lParam=0;
965
966 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
967 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
968 // bit 24, 1=extended key
969 // bit 25-28, reserved
970 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
971 if (keyWasPressed)
972 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
973 // bit 31, transition state, always 0 for WM_KEYDOWN
974
975 setExtendedKey(virtualKey, &lParam);
976
977 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
978
979 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
980}
981//******************************************************************************
982//******************************************************************************
983ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
984{
985 ULONG lParam=0;
986
987 lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
988 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
989 // bit 24, 1=extended key
990 // bit 25-28, reserved
991 lParam |= 0 << 29; // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
992 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
993 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
994
995 setExtendedKey(virtualKey, &lParam);
996 dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
997
998 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
999}
1000//******************************************************************************
1001//******************************************************************************
1002ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1003{
1004 ULONG lParam=0;
1005
1006 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1007 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1008 // bit 24, 1=extended key
1009 // bit 25-28, reserved
1010 // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
1011 if (keyWasPressed)
1012 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1013 // bit 31, transition state, always 0 for WM_KEYDOWN
1014
1015 setExtendedKey(virtualKey, &lParam);
1016 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1017
1018 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
1019}
1020//******************************************************************************
1021//******************************************************************************
1022ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1023{
1024 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1025}
1026//******************************************************************************
1027//******************************************************************************
1028ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1029{
1030 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1031}
1032//******************************************************************************
1033//******************************************************************************
1034//******************************************************************************
1035ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
1036{
1037 ULONG win32msg;
1038 ULONG win32ncmsg;
1039
1040 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1041 switch(msg) {
1042 case BUTTON_LEFTDOWN:
1043 win32msg = WM_LBUTTONDOWN;
1044 win32ncmsg = WM_NCLBUTTONDOWN;
1045 break;
1046 case BUTTON_LEFTUP:
1047 win32msg = WM_LBUTTONUP;
1048 win32ncmsg = WM_NCLBUTTONUP;
1049 break;
1050 case BUTTON_LEFTDBLCLICK:
1051 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1052 {
1053 win32msg = WM_LBUTTONDBLCLK;
1054 win32ncmsg = WM_NCLBUTTONDBLCLK;
1055 } else
1056 {
1057 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1058 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1059 }
1060 break;
1061 case BUTTON_RIGHTUP:
1062 win32msg = WM_RBUTTONUP;
1063 win32ncmsg = WM_NCRBUTTONUP;
1064 break;
1065 case BUTTON_RIGHTDOWN:
1066 win32msg = WM_RBUTTONDOWN;
1067 win32ncmsg = WM_NCRBUTTONDOWN;
1068 break;
1069 case BUTTON_RIGHTDBLCLICK:
1070 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1071 {
1072 win32msg = WM_RBUTTONDBLCLK;
1073 win32ncmsg = WM_NCRBUTTONDBLCLK;
1074 } else
1075 {
1076 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1077 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1078 }
1079 break;
1080 case BUTTON_MIDDLEUP:
1081 win32msg = WM_MBUTTONUP;
1082 win32ncmsg = WM_NCMBUTTONUP;
1083 break;
1084 case BUTTON_MIDDLEDOWN:
1085 win32msg = WM_MBUTTONDOWN;
1086 win32ncmsg = WM_NCMBUTTONDOWN;
1087 break;
1088 case BUTTON_MIDDLEDBLCLICK:
1089 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1090 {
1091 win32msg = WM_MBUTTONDBLCLK;
1092 win32ncmsg = WM_NCMBUTTONDBLCLK;
1093 } else
1094 {
1095 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1096 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1097 }
1098 break;
1099 default:
1100 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1101 return 1;
1102 }
1103
1104 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1105
1106 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1107 if(lastHitTestVal != HTCLIENT) {
1108 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1109 }
1110 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1111}
1112//******************************************************************************
1113//******************************************************************************
1114ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1115{
1116 ULONG winstate = 0;
1117 ULONG setcursormsg = WM_MOUSEMOVE;
1118
1119 if(keystate & WMMOVE_LBUTTON)
1120 winstate |= MK_LBUTTON;
1121 if(keystate & WMMOVE_RBUTTON)
1122 winstate |= MK_RBUTTON;
1123 if(keystate & WMMOVE_MBUTTON)
1124 winstate |= MK_MBUTTON;
1125 if(keystate & WMMOVE_SHIFT)
1126 winstate |= MK_SHIFT;
1127 if(keystate & WMMOVE_CTRL)
1128 winstate |= MK_CONTROL;
1129
1130 if(lastHitTestVal != HTCLIENT) {
1131 setcursormsg = WM_NCMOUSEMOVE;
1132 }
1133 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1134 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1135
1136 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1137 if(lastHitTestVal != HTCLIENT) {
1138 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1139 }
1140 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1141}
1142//******************************************************************************
1143//******************************************************************************
1144ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1145{
1146 if (select && isIcon)
1147 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1148 else
1149 return SendInternalMessageA(WM_PAINT, 0, 0);
1150}
1151//******************************************************************************
1152//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1153// (or are we simply erasing too much here)
1154//******************************************************************************
1155ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1156{
1157 ULONG rc;
1158 HDC hdcErase = hdc;
1159
1160 if (hdcErase == 0)
1161 hdcErase = O32_GetDC(OS2Hwnd);
1162
1163 if(isIcon)
1164 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1165 else
1166 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1167 if (hdc == 0)
1168 O32_ReleaseDC(OS2Hwnd, hdcErase);
1169 return (rc);
1170}
1171//******************************************************************************
1172//******************************************************************************
1173ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1174{
1175 if(isUnicode) {
1176 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1177 }
1178 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1179}
1180//******************************************************************************
1181//TODO: in- or excluding terminating 0?
1182//******************************************************************************
1183ULONG Win32BaseWindow::MsgGetTextLength()
1184{
1185 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1186}
1187//******************************************************************************
1188//******************************************************************************
1189char *Win32BaseWindow::MsgGetText()
1190{
1191 if(isUnicode) {
1192 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1193 }
1194 else {
1195 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1196 }
1197 return windowNameA;
1198}
1199//******************************************************************************
1200//******************************************************************************
1201BOOL Win32BaseWindow::isMDIClient()
1202{
1203 return FALSE;
1204}
1205//******************************************************************************
1206//******************************************************************************
1207BOOL Win32BaseWindow::isMDIChild()
1208{
1209 return FALSE;
1210}
1211//******************************************************************************
1212//TODO: Not complete
1213//******************************************************************************
1214BOOL Win32BaseWindow::isFrameWindow()
1215{
1216// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1217 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1218 return TRUE;
1219
1220 return FALSE;
1221}
1222//******************************************************************************
1223//TODO: Not complete (flags)
1224//******************************************************************************
1225SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1226{
1227 switch(nBar) {
1228 case SB_HORZ:
1229 if(horzScrollInfo) {
1230 //CB:horzScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndHorzScroll);
1231 return horzScrollInfo;
1232 }
1233 break;
1234 case SB_VERT:
1235 if(vertScrollInfo) {
1236 //CB:vertScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndVertScroll);
1237 return vertScrollInfo;
1238 }
1239 break;
1240 }
1241 return NULL;
1242}
1243/***********************************************************************/
1244/***********************************************************************/
1245VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1246{
1247 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1248}
1249/***********************************************************************
1250 * NC_HandleSysCommand
1251 *
1252 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1253 *
1254 * TODO: Not done (see #if 0)
1255 */
1256LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1257{
1258 UINT uCommand = wParam & 0xFFF0;
1259
1260 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1261 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1262
1263 switch (uCommand)
1264 {
1265#if 0
1266 case SC_SIZE:
1267 case SC_MOVE:
1268 NC_DoSizeMove( hwnd, wParam );
1269 break;
1270#endif
1271
1272 case SC_MINIMIZE:
1273 ShowWindow(SW_MINIMIZE);
1274 break;
1275
1276 case SC_MAXIMIZE:
1277 ShowWindow(SW_MAXIMIZE);
1278 break;
1279
1280 case SC_RESTORE:
1281 ShowWindow(SW_RESTORE);
1282 break;
1283
1284 case SC_CLOSE:
1285 return SendMessageA(WM_CLOSE, 0, 0);
1286
1287#if 0
1288 case SC_VSCROLL:
1289 case SC_HSCROLL:
1290 NC_TrackScrollBar( hwnd, wParam, pt32 );
1291 break;
1292
1293 case SC_MOUSEMENU:
1294 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1295 break;
1296
1297 case SC_KEYMENU:
1298 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1299 break;
1300
1301 case SC_TASKLIST:
1302 WinExec( "taskman.exe", SW_SHOWNORMAL );
1303 break;
1304
1305 case SC_SCREENSAVE:
1306 if (wParam == SC_ABOUTWINE)
1307 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1308 else
1309 if (wParam == SC_PUTMARK)
1310 dprintf(("Mark requested by user\n"));
1311 break;
1312
1313 case SC_HOTKEY:
1314 case SC_ARRANGE:
1315 case SC_NEXTWINDOW:
1316 case SC_PREVWINDOW:
1317 break;
1318#endif
1319 }
1320 return 0;
1321}
1322//******************************************************************************
1323//******************************************************************************
1324LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1325{
1326 //SvL: Set background color to default button color (not window (white))
1327 if(ctlType == CTLCOLOR_BTN)
1328 {
1329 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1330 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1331 return GetSysColorBrush(COLOR_BTNFACE);
1332 }
1333 //SvL: Set background color to default dialog color if window is dialog
1334 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1335 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1336 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1337 return GetSysColorBrush(COLOR_BTNFACE);
1338 }
1339
1340 if( ctlType == CTLCOLOR_SCROLLBAR)
1341 {
1342 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1343 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1344 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1345 SetBkColor( hdc, bk);
1346
1347//TODO?
1348#if 0
1349 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1350 * we better use 0x55aa bitmap brush to make scrollbar's background
1351 * look different from the window background.
1352 */
1353 if (bk == GetSysColor(COLOR_WINDOW)) {
1354 return CACHE_GetPattern55AABrush();
1355 }
1356#endif
1357 UnrealizeObject( hb );
1358 return (LRESULT)hb;
1359 }
1360
1361 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1362
1363 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1364 {
1365 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1366 }
1367 else
1368 {
1369 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1370 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1371 }
1372 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1373}
1374//******************************************************************************
1375//******************************************************************************
1376LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1377{
1378 switch(Msg)
1379 {
1380 case WM_CLOSE:
1381 DestroyWindow();
1382 return 0;
1383
1384 case WM_GETTEXTLENGTH:
1385 return wndNameLength;
1386
1387 case WM_GETTEXT: //TODO: SS_ICON controls
1388 strncpy((LPSTR)lParam, windowNameA, wParam);
1389 return min(wndNameLength, wParam);
1390
1391 case WM_SETTEXT:
1392 if(!fInternalMsg) {
1393 return SetWindowTextA((LPSTR)lParam);
1394 }
1395 else return 0;
1396
1397 case WM_SETREDRAW:
1398 if(wParam)
1399 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1400 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1401
1402 return 0; //TODO
1403
1404 case WM_NCCREATE:
1405 return(TRUE);
1406
1407 case WM_NCCALCSIZE:
1408 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1409
1410 case WM_CTLCOLORMSGBOX:
1411 case WM_CTLCOLOREDIT:
1412 case WM_CTLCOLORLISTBOX:
1413 case WM_CTLCOLORBTN:
1414 case WM_CTLCOLORDLG:
1415 case WM_CTLCOLORSTATIC:
1416 case WM_CTLCOLORSCROLLBAR:
1417 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1418
1419 case WM_CTLCOLOR:
1420 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1421
1422 case WM_VKEYTOITEM:
1423 case WM_CHARTOITEM:
1424 return -1;
1425
1426 case WM_PARENTNOTIFY:
1427 return 0;
1428
1429 case WM_MOUSEACTIVATE:
1430 {
1431 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1432 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1433 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1434 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1435 {
1436 if(getParent()) {
1437 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1438 if(rc) return rc;
1439 }
1440 }
1441 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1442 }
1443 case WM_SETCURSOR:
1444 {
1445 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1446 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1447 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1448 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1449 {
1450 if(getParent()) {
1451 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1452 if(rc) return rc;
1453 }
1454 }
1455 return 1;
1456 }
1457 case WM_MOUSEMOVE:
1458 return 1; //Let OS/2 change the mouse cursor back to the default
1459
1460 case WM_WINDOWPOSCHANGED:
1461 {
1462
1463/* undocumented SWP flags - from SDK 3.1 */
1464#define SWP_NOCLIENTSIZE 0x0800
1465#define SWP_NOCLIENTMOVE 0x1000
1466
1467 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1468 WPARAM wp = SIZE_RESTORED;
1469
1470 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1471 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1472
1473 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1474 {
1475 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1476 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1477
1478 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1479 rectClient.bottom - rectClient.top));
1480 }
1481 return 0;
1482 }
1483 case WM_ERASEBKGND:
1484 case WM_ICONERASEBKGND:
1485 {
1486 RECT rect;
1487 int rc;
1488
1489 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1490
1491 rc = GetClipBox( (HDC)wParam, &rect );
1492 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1493 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1494
1495 return 1;
1496 }
1497 case WM_GETDLGCODE:
1498 return 0;
1499
1500 case WM_NCLBUTTONDOWN:
1501 case WM_NCLBUTTONUP:
1502 case WM_NCLBUTTONDBLCLK:
1503 case WM_NCRBUTTONUP:
1504 case WM_NCRBUTTONDOWN:
1505 case WM_NCRBUTTONDBLCLK:
1506 case WM_NCMBUTTONDOWN:
1507 case WM_NCMBUTTONUP:
1508 case WM_NCMBUTTONDBLCLK:
1509 return 0; //TODO: Send WM_SYSCOMMAND if required
1510
1511 case WM_NCHITTEST: //TODO: Calculate position of
1512 return HTCLIENT;
1513
1514 case WM_SYSCOMMAND:
1515 {
1516 POINT point;
1517
1518 point.x = LOWORD(lParam);
1519 point.y = HIWORD(lParam);
1520 return HandleSysCommand(wParam, &point);
1521 }
1522
1523 case WM_SYSKEYDOWN:
1524 if(HIWORD(lParam) & KEYDATA_ALT)
1525 {
1526 if(wParam == VK_F4) /* try to close the window */
1527 {
1528 Win32BaseWindow *window = GetTopParent();
1529 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE) )
1530 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1531 }
1532 }
1533 return 0;
1534
1535 case WM_QUERYOPEN:
1536 case WM_QUERYENDSESSION:
1537 return 1;
1538
1539 case WM_NOTIFYFORMAT:
1540 if (IsUnicode()) return NFR_UNICODE;
1541 else return NFR_ANSI;
1542
1543 case WM_SETICON:
1544 case WM_GETICON:
1545 {
1546 LRESULT result = 0;
1547 if (!windowClass) return result;
1548 int index = GCL_HICON;
1549
1550 if (wParam == ICON_SMALL)
1551 index = GCL_HICONSM;
1552
1553 result = windowClass->getClassLongA(index);
1554
1555 if (Msg == WM_SETICON)
1556 windowClass->setClassLongA(index, lParam);
1557
1558 return result;
1559 }
1560
1561 default:
1562 return 1;
1563 }
1564}
1565//******************************************************************************
1566//******************************************************************************
1567LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1568{
1569 switch(Msg)
1570 {
1571 case WM_GETTEXTLENGTH:
1572 return wndNameLength;
1573
1574 case WM_GETTEXT: //TODO: SS_ICON controls
1575 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1576 return min(wndNameLength, wParam);
1577
1578 case WM_SETTEXT:
1579 if(!fInternalMsg) {
1580 return SetWindowTextW((LPWSTR)lParam);
1581 }
1582 else return 0;
1583
1584 default:
1585 return DefWindowProcA(Msg, wParam, lParam);
1586 }
1587}
1588//******************************************************************************
1589//******************************************************************************
1590LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1591{
1592 LRESULT rc;
1593 BOOL fInternalMsgBackup = fInternalMsg;
1594
1595 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1596 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1597 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1598 }
1599
1600 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1601 return(0);
1602 }
1603 fInternalMsg = FALSE;
1604 switch(Msg)
1605 {
1606 case WM_CREATE:
1607 {
1608 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1609 dprintf(("WM_CREATE returned -1\n"));
1610 rc = -1; //don't create window
1611 break;
1612 }
1613 NotifyParent(Msg, wParam, lParam);
1614
1615 rc = 0;
1616 break;
1617 }
1618 case WM_SETTEXT:
1619 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1620 break;
1621
1622 case WM_LBUTTONDOWN:
1623 case WM_MBUTTONDOWN:
1624 case WM_RBUTTONDOWN:
1625 NotifyParent(Msg, wParam, lParam);
1626 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1627 break;
1628
1629 case WM_DESTROY:
1630 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1631 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1632 break;
1633
1634 default:
1635 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1636 break;
1637 }
1638 fInternalMsg = fInternalMsgBackup;
1639 return rc;
1640}
1641//******************************************************************************
1642//******************************************************************************
1643LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1644{
1645 LRESULT rc;
1646 BOOL fInternalMsgBackup = fInternalMsg;
1647
1648 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1649 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1650 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1651 }
1652
1653 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1654 return(0);
1655 }
1656 fInternalMsg = FALSE;
1657 switch(Msg)
1658 {
1659 case WM_CREATE:
1660 {
1661 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1662 dprintf(("WM_CREATE returned -1\n"));
1663 rc = -1; //don't create window
1664 break;
1665 }
1666 NotifyParent(Msg, wParam, lParam);
1667
1668 rc = 0;
1669 break;
1670 }
1671 case WM_SETTEXT:
1672 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1673 break;
1674
1675 case WM_LBUTTONDOWN:
1676 case WM_MBUTTONDOWN:
1677 case WM_RBUTTONDOWN:
1678 NotifyParent(Msg, wParam, lParam);
1679 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1680 break;
1681
1682 case WM_DESTROY:
1683 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1684 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1685 break;
1686
1687 default:
1688 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1689 break;
1690 }
1691 fInternalMsg = fInternalMsgBackup;
1692 return rc;
1693}
1694//******************************************************************************
1695//Called as a result of an OS/2 message
1696//******************************************************************************
1697LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1698{
1699 LRESULT rc;
1700 BOOL fInternalMsgBackup = fInternalMsg;
1701
1702 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1703 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1704
1705 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1706 return(0);
1707 }
1708 fInternalMsg = TRUE;
1709 switch(Msg)
1710 {
1711 case WM_CREATE:
1712 {
1713 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1714 dprintf(("WM_CREATE returned -1\n"));
1715 rc = -1; //don't create window
1716 break;
1717 }
1718 NotifyParent(Msg, wParam, lParam);
1719 rc = 0;
1720 break;
1721 }
1722 case WM_LBUTTONDOWN:
1723 case WM_MBUTTONDOWN:
1724 case WM_RBUTTONDOWN:
1725 NotifyParent(Msg, wParam, lParam);
1726 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1727 break;
1728
1729 case WM_DESTROY:
1730 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1731 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1732 break;
1733 default:
1734 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1735 break;
1736 }
1737 fInternalMsg = fInternalMsgBackup;
1738 return rc;
1739}
1740//******************************************************************************
1741//Called as a result of an OS/2 message
1742//todo, unicode msgs (WM_SETTEXT etc)
1743//******************************************************************************
1744LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1745{
1746 LRESULT rc;
1747 BOOL fInternalMsgBackup = fInternalMsg;
1748
1749 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1750 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1751
1752 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1753 return(0);
1754 }
1755 fInternalMsg = TRUE;
1756 switch(Msg)
1757 {
1758 case WM_CREATE:
1759 {
1760 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1761 dprintf(("WM_CREATE returned -1\n"));
1762 rc = -1; //don't create window
1763 break;
1764 }
1765 NotifyParent(Msg, wParam, lParam);
1766 rc = 0;
1767 break;
1768 }
1769 case WM_LBUTTONDOWN:
1770 case WM_MBUTTONDOWN:
1771 case WM_RBUTTONDOWN:
1772 NotifyParent(Msg, wParam, lParam);
1773 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1774 break;
1775
1776 case WM_DESTROY:
1777 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1778 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1779 break;
1780 default:
1781 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1782 break;
1783 }
1784 fInternalMsg = fInternalMsgBackup;
1785 return rc;
1786}
1787//******************************************************************************
1788//******************************************************************************
1789BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1790{
1791 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1792}
1793//******************************************************************************
1794//******************************************************************************
1795BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1796{
1797 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1798}
1799//******************************************************************************
1800//TODO: do we need to inform the parent of the parent (etc) of the child window?
1801//******************************************************************************
1802void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1803{
1804 Win32BaseWindow *window = this;
1805 Win32BaseWindow *parentwindow;
1806
1807 while(window)
1808 {
1809 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1810 {
1811 /* Notify the parent window only */
1812 parentwindow = window->getParent();
1813 if(parentwindow) {
1814 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1815 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1816 }
1817 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1818 }
1819 }
1820 else break;
1821
1822 window = parentwindow;
1823 }
1824}
1825//******************************************************************************
1826//******************************************************************************
1827Win32BaseWindow *Win32BaseWindow::getTopParent()
1828{
1829 Win32BaseWindow *tmpWnd = this;
1830
1831 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1832 {
1833 tmpWnd = tmpWnd->getParent();
1834 }
1835 return tmpWnd;
1836}
1837//******************************************************************************
1838//******************************************************************************
1839BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1840{
1841
1842 dprintf(("SetMenu %x", hMenu));
1843 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1844 if(OS2HwndMenu == 0) {
1845 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1846 return FALSE;
1847 }
1848 return TRUE;
1849}
1850//******************************************************************************
1851//******************************************************************************
1852BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1853{
1854 Win32Resource *winres = (Win32Resource *)hAccel;
1855 HANDLE accelhandle;
1856
1857 if(HIWORD(hAccel) == 0) {
1858 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1859 SetLastError(ERROR_INVALID_PARAMETER);
1860 return FALSE;
1861 }
1862 acceltableResource = winres;
1863 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1864 winres->setOS2Handle(accelhandle);
1865 return(accelhandle != 0);
1866}
1867//******************************************************************************
1868//******************************************************************************
1869BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1870{
1871 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1872 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1873 SendMessageA(WM_SETICON, hIcon, 0);
1874 return TRUE;
1875 }
1876 return FALSE;
1877}
1878//******************************************************************************
1879//******************************************************************************
1880BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1881{
1882 ULONG showstate = 0;
1883
1884 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
1885#if 1
1886 if (flags & WIN_NEED_SIZE)
1887 {
1888 /* should happen only in CreateWindowEx() */
1889 int wParam = SIZE_RESTORED;
1890
1891 flags &= ~WIN_NEED_SIZE;
1892 if (dwStyle & WS_MAXIMIZE)
1893 wParam = SIZE_MAXIMIZED;
1894 else
1895 if (dwStyle & WS_MINIMIZE)
1896 wParam = SIZE_MINIMIZED;
1897
1898 SendMessageA(WM_SIZE, wParam,
1899 MAKELONG(rectClient.right-rectClient.left,
1900 rectClient.bottom-rectClient.top));
1901 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1902 }
1903#else
1904 if(fFirstShow) {
1905 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
1906 SendMessageA(WM_SIZE, SIZE_RESTORED,
1907 MAKELONG(rectClient.right-rectClient.left,
1908 rectClient.bottom-rectClient.top));
1909 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1910
1911 }
1912 fFirstShow = FALSE;
1913 }
1914#endif
1915 switch(nCmdShow)
1916 {
1917 case SW_SHOW:
1918 case SW_SHOWDEFAULT: //todo
1919 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1920 break;
1921 case SW_HIDE:
1922 showstate = SWPOS_HIDE;
1923 break;
1924 case SW_RESTORE:
1925 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1926 break;
1927 case SW_MINIMIZE:
1928 showstate = SWPOS_MINIMIZE;
1929 break;
1930 case SW_SHOWMAXIMIZED:
1931 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1932 break;
1933 case SW_SHOWMINIMIZED:
1934 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1935 break;
1936 case SW_SHOWMINNOACTIVE:
1937 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1938 break;
1939 case SW_SHOWNA:
1940 showstate = SWPOS_SHOW;
1941 break;
1942 case SW_SHOWNOACTIVATE:
1943 showstate = SWPOS_SHOW;
1944 break;
1945 case SW_SHOWNORMAL:
1946 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1947 break;
1948 }
1949
1950#if 0
1951 if(showstate & SWPOS_SHOW && (getStyle() & WS_VISIBLE) == 0) {
1952 SetWindowLongA(GWL_STYLE, getStyle() | WS_VISIBLE);
1953 }
1954#endif
1955 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
1956 return rc;
1957}
1958//******************************************************************************
1959//******************************************************************************
1960BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1961{
1962 BOOL rc = FALSE;
1963 Win32BaseWindow *window;
1964 HWND hParent = 0;
1965
1966 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1967
1968 if (fuFlags &
1969 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1970 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1971 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1972 SWP_NOOWNERZORDER))
1973 {
1974 return FALSE;
1975 }
1976
1977 WINDOWPOS wpos;
1978 SWP swp, swpOld;
1979
1980 wpos.flags = fuFlags;
1981 wpos.cy = cy;
1982 wpos.cx = cx;
1983 wpos.x = x;
1984 wpos.y = y;
1985 wpos.hwndInsertAfter = hwndInsertAfter;
1986 wpos.hwnd = getWindowHandle();
1987
1988 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
1989 {
1990 if (isChild())
1991 {
1992 hParent = getParent()->getOS2WindowHandle();
1993 }
1994 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1995 }
1996
1997 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1998 if (swp.fl == 0)
1999 return TRUE;
2000
2001// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2002 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2003 {
2004 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2005 if(wndBehind) {
2006 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2007 }
2008 else {
2009 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2010 swp.hwndInsertBehind = 0;
2011 }
2012 }
2013#if 0
2014 if (isFrameWindow())
2015 {
2016 if (!isChild())
2017 {
2018 POINT maxSize, maxPos, minTrack, maxTrack;
2019
2020 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2021
2022 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2023 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2024 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2025 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2026 }
2027 swp.hwnd = OS2HwndFrame;
2028 }
2029 else
2030#endif
2031 swp.hwnd = OS2HwndFrame;
2032
2033 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2034
2035 rc = OSLibWinSetMultWindowPos(&swp, 1);
2036
2037 if (rc == FALSE)
2038 {
2039 dprintf(("OSLibWinSetMultWindowPos failed!"));
2040 }
2041 else
2042 {
2043 if (fuFlags & SWP_FRAMECHANGED_W)
2044 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2045 }
2046
2047 return (rc);
2048}
2049//******************************************************************************
2050//TODO: WPF_RESTOREMAXIMIZED
2051//******************************************************************************
2052BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2053{
2054 if(isFrameWindow())
2055 {
2056 // Set the minimized position
2057 if (winpos->flags & WPF_SETMINPOSITION)
2058 {
2059 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2060 }
2061
2062 //TODO: Max position
2063
2064 // Set the new restore position.
2065 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2066 }
2067
2068 return ShowWindow(winpos->showCmd);
2069}
2070//******************************************************************************
2071//Also destroys all the child windows (destroy parent, destroy children)
2072//******************************************************************************
2073BOOL Win32BaseWindow::DestroyWindow()
2074{
2075 return OSLibWinDestroyWindow(OS2HwndFrame);
2076}
2077//******************************************************************************
2078//******************************************************************************
2079HWND Win32BaseWindow::GetParent()
2080{
2081 if(getParent()) {
2082 return getParent()->getWindowHandle();
2083 }
2084 else return 0;
2085}
2086//******************************************************************************
2087//******************************************************************************
2088HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2089{
2090 HWND oldhwnd;
2091 Win32BaseWindow *newparent;
2092
2093 if(getParent()) {
2094 oldhwnd = getParent()->getWindowHandle();
2095 getParent()->RemoveChild(this);
2096 }
2097 else oldhwnd = 0;
2098
2099 if(hwndNewParent == 0) {//desktop window = parent
2100 setParent(NULL);
2101 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2102 return oldhwnd;
2103 }
2104 newparent = GetWindowFromHandle(hwndNewParent);
2105 if(newparent)
2106 {
2107 setParent(newparent);
2108 getParent()->AddChild(this);
2109 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2110 return oldhwnd;
2111 }
2112 SetLastError(ERROR_INVALID_PARAMETER);
2113 return 0;
2114}
2115//******************************************************************************
2116//******************************************************************************
2117BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2118{
2119 if(getParent()) {
2120 return getParent()->getWindowHandle() == hwndParent;
2121 }
2122 else return 0;
2123}
2124//******************************************************************************
2125//******************************************************************************
2126HWND Win32BaseWindow::GetTopWindow()
2127{
2128 return GetWindow(GW_CHILD);
2129}
2130//******************************************************************************
2131// Get the top-level parent for a child window.
2132//******************************************************************************
2133Win32BaseWindow *Win32BaseWindow::GetTopParent()
2134{
2135 Win32BaseWindow *window = this;
2136
2137 while(window && (window->getStyle() & WS_CHILD))
2138 {
2139 window = window->getParent();
2140 }
2141 return window;
2142}
2143//******************************************************************************
2144//Don't call WinUpdateWindow as that one also updates the child windows
2145//Also need to send WM_PAINT directly to the window procedure, which doesn't
2146//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2147//******************************************************************************
2148BOOL Win32BaseWindow::UpdateWindow()
2149{
2150 RECT rect;
2151
2152 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2153 {//update region not empty
2154 HDC hdc;
2155
2156 hdc = O32_GetDC(OS2Hwnd);
2157 if (isIcon)
2158 {
2159 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2160 SendMessageA(WM_PAINTICON, 0, 0);
2161 } else
2162 {
2163 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2164 SendMessageA(WM_PAINT, 0, 0);
2165 }
2166 O32_ReleaseDC(OS2Hwnd, hdc);
2167 }
2168 return TRUE;
2169}
2170//******************************************************************************
2171//******************************************************************************
2172BOOL Win32BaseWindow::IsIconic()
2173{
2174 return OSLibWinIsIconic(OS2Hwnd);
2175}
2176//******************************************************************************
2177//TODO:
2178//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2179//the current process owns them.
2180//******************************************************************************
2181HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2182 BOOL fUnicode)
2183{
2184 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2185 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2186
2187 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2188 (hwndChildAfter != 0 && !child) ||
2189 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2190 {
2191 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2192 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2193 return 0;
2194 }
2195 if(hwndParent != OSLIB_HWND_DESKTOP)
2196 {//if the current process owns the window, just do a quick search
2197 child = (Win32BaseWindow *)parent->getFirstChild();
2198 if(hwndChildAfter != 0)
2199 {
2200 while(child)
2201 {
2202 if(child->getWindowHandle() == hwndChildAfter)
2203 {
2204 child = (Win32BaseWindow *)child->getNextChild();
2205 break;
2206 }
2207 child = (Win32BaseWindow *)child->getNextChild();
2208 }
2209 }
2210 while(child)
2211 {
2212 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2213 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2214 {
2215 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2216 return child->getWindowHandle();
2217 }
2218 child = (Win32BaseWindow *)child->getNextChild();
2219 }
2220 }
2221 else {
2222 Win32BaseWindow *wnd;
2223 HWND henum, hwnd;
2224
2225 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2226 hwnd = OSLibWinGetNextWindow(henum);
2227
2228 while(hwnd)
2229 {
2230 wnd = GetWindowFromOS2Handle(hwnd);
2231 if(wnd == NULL) {
2232 hwnd = OSLibWinQueryClientWindow(hwnd);
2233 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2234 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2235 }
2236
2237 if(wnd) {
2238 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
2239
2240 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
2241 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
2242 break;
2243 }
2244 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2245 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2246 {
2247 OSLibWinEndEnumWindows(henum);
2248 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2249 return wnd->getWindowHandle();
2250 }
2251 }
2252 hwnd = OSLibWinGetNextWindow(henum);
2253 }
2254 OSLibWinEndEnumWindows(henum);
2255 }
2256 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2257 return 0;
2258}
2259//******************************************************************************
2260//******************************************************************************
2261HWND Win32BaseWindow::GetWindow(UINT uCmd)
2262{
2263 HWND hwndRelated = 0;
2264 Win32BaseWindow *window;
2265
2266 switch(uCmd)
2267 {
2268 case GW_HWNDFIRST:
2269 if(getParent()) {
2270 window = (Win32BaseWindow *)getParent()->getFirstChild();
2271 hwndRelated = window->getWindowHandle();
2272 }
2273 break;
2274
2275 case GW_HWNDLAST:
2276 if(getParent())
2277 {
2278 goto end;
2279 }
2280
2281 window = this;
2282 while(window)
2283 {
2284 window = (Win32BaseWindow *)window->getNextChild();
2285 }
2286 hwndRelated = window->getWindowHandle();
2287 break;
2288
2289 case GW_HWNDNEXT:
2290 window = (Win32BaseWindow *)getNextChild();
2291 if(window) {
2292 hwndRelated = window->getWindowHandle();
2293 }
2294 break;
2295
2296 case GW_HWNDPREV:
2297 if(!getParent())
2298 {
2299 goto end;
2300 }
2301 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2302 if(window == this)
2303 {
2304 hwndRelated = 0; /* First in list */
2305 goto end;
2306 }
2307 while(window->getNextChild())
2308 {
2309 if (window->getNextChild() == this)
2310 {
2311 hwndRelated = window->getWindowHandle();
2312 goto end;
2313 }
2314 window = (Win32BaseWindow *)window->getNextChild();
2315 }
2316 break;
2317
2318 case GW_OWNER:
2319 if(getOwner()) {
2320 hwndRelated = getOwner()->getWindowHandle();
2321 }
2322 break;
2323
2324 case GW_CHILD:
2325 if(getFirstChild()) {
2326 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2327 }
2328 break;
2329 }
2330end:
2331 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2332 return hwndRelated;
2333}
2334//******************************************************************************
2335//******************************************************************************
2336HWND Win32BaseWindow::SetActiveWindow()
2337{
2338 return OSLibWinSetActiveWindow(OS2Hwnd);
2339}
2340//******************************************************************************
2341//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2342//******************************************************************************
2343BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2344{
2345 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
2346}
2347//******************************************************************************
2348//******************************************************************************
2349BOOL Win32BaseWindow::CloseWindow()
2350{
2351 return OSLibWinMinimizeWindow(OS2Hwnd);
2352}
2353//******************************************************************************
2354//******************************************************************************
2355HWND Win32BaseWindow::GetActiveWindow()
2356{
2357 HWND hwndActive;
2358 Win32BaseWindow *win32wnd;
2359 ULONG magic;
2360
2361 hwndActive = OSLibWinQueryActiveWindow();
2362
2363 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2364 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2365 if(CheckMagicDword(magic) && win32wnd)
2366 {
2367 return win32wnd->getWindowHandle();
2368 }
2369 return hwndActive;
2370}
2371//******************************************************************************
2372//******************************************************************************
2373BOOL Win32BaseWindow::IsWindowEnabled()
2374{
2375 return OSLibWinIsWindowEnabled(OS2Hwnd);
2376}
2377//******************************************************************************
2378//******************************************************************************
2379BOOL Win32BaseWindow::IsWindowVisible()
2380{
2381 return OSLibWinIsWindowVisible(OS2Hwnd);
2382}
2383//******************************************************************************
2384//******************************************************************************
2385BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2386{
2387 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2388}
2389//******************************************************************************
2390//******************************************************************************
2391BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2392{
2393 if(fUnicode) {
2394 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2395 }
2396 else return (strcmp(windowNameA, wndname) == 0);
2397}
2398//******************************************************************************
2399//******************************************************************************
2400int Win32BaseWindow::GetWindowTextLength()
2401{
2402 return wndNameLength;
2403}
2404//******************************************************************************
2405//******************************************************************************
2406int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2407{
2408 strncpy(lpsz, windowNameA, cch);
2409 return wndNameLength;
2410}
2411//******************************************************************************
2412//******************************************************************************
2413int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2414{
2415 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2416 return wndNameLength;
2417}
2418//******************************************************************************
2419//******************************************************************************
2420BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2421{
2422 if(lpsz == NULL)
2423 return FALSE;
2424
2425 if(windowNameA) free(windowNameA);
2426 if(windowNameW) free(windowNameW);
2427
2428 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2429 strcpy(windowNameA, lpsz);
2430 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2431 lstrcpyAtoW(windowNameW, windowNameA);
2432 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2433
2434 if(OS2HwndFrame)
2435 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2436
2437 return TRUE;
2438}
2439//******************************************************************************
2440//******************************************************************************
2441BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2442{
2443 if(lpsz == NULL)
2444 return FALSE;
2445
2446 if(windowNameA) free(windowNameA);
2447 if(windowNameW) free(windowNameW);
2448
2449 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2450 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2451 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2452 lstrcpyWtoA(windowNameA, windowNameW);
2453 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2454
2455 if(OS2HwndFrame)
2456 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2457
2458 return TRUE;
2459}
2460//******************************************************************************
2461//******************************************************************************
2462LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2463{
2464 LONG oldval;
2465
2466 switch(index) {
2467 case GWL_EXSTYLE:
2468 {
2469 STYLESTRUCT ss;
2470
2471 ss.styleOld = dwExStyle;
2472 ss.styleNew = value;
2473 dprintf(("SetWindowLong GWL_EXSTYLE %x new style %x", getWindowHandle(), value));
2474 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2475 setExStyle(ss.styleNew);
2476 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2477 return ss.styleOld;
2478 }
2479 case GWL_STYLE:
2480 {
2481 STYLESTRUCT ss;
2482
2483 ss.styleOld = dwStyle;
2484 ss.styleNew = value;
2485 dprintf(("SetWindowLong GWL_STYLE %x new style %x", getWindowHandle(), value));
2486 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2487 setStyle(ss.styleNew);
2488 if(!IsWindowDestroyed())
2489 OSLibSetWindowStyle(OS2HwndFrame, dwStyle);
2490 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2491 return ss.styleOld;
2492 }
2493 case GWL_WNDPROC:
2494 oldval = (LONG)getWindowProc();
2495 setWindowProc((WNDPROC)value);
2496 return oldval;
2497 case GWL_HINSTANCE:
2498 oldval = hInstance;
2499 hInstance = value;
2500 return oldval;
2501 case GWL_HWNDPARENT:
2502 return SetParent((HWND)value);
2503 case GWL_ID:
2504 oldval = getWindowId();
2505 setWindowId(value);
2506 return oldval;
2507 case GWL_USERDATA:
2508 oldval = userData;
2509 userData = value;
2510 return oldval;
2511 default:
2512 if(index >= 0 && index/4 < nrUserWindowLong)
2513 {
2514 oldval = userWindowLong[index/4];
2515 userWindowLong[index/4] = value;
2516 return oldval;
2517 }
2518 SetLastError(ERROR_INVALID_PARAMETER);
2519 return 0;
2520 }
2521}
2522//******************************************************************************
2523//******************************************************************************
2524ULONG Win32BaseWindow::GetWindowLongA(int index)
2525{
2526 switch(index) {
2527 case GWL_EXSTYLE:
2528 return dwExStyle;
2529 case GWL_STYLE:
2530 return dwStyle;
2531 case GWL_WNDPROC:
2532 return (ULONG)getWindowProc();
2533 case GWL_HINSTANCE:
2534 return hInstance;
2535 case GWL_HWNDPARENT:
2536 if(getParent()) {
2537 return getParent()->getWindowHandle();
2538 }
2539 else return 0;
2540 case GWL_ID:
2541 return getWindowId();
2542 case GWL_USERDATA:
2543 return userData;
2544 default:
2545 if(index >= 0 && index/4 < nrUserWindowLong)
2546 {
2547 return userWindowLong[index/4];
2548 }
2549 SetLastError(ERROR_INVALID_PARAMETER);
2550 return 0;
2551 }
2552}
2553//******************************************************************************
2554//******************************************************************************
2555WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2556{
2557 WORD oldval;
2558
2559 if(index >= 0 && index/4 < nrUserWindowLong)
2560 {
2561 oldval = ((WORD *)userWindowLong)[index/2];
2562 ((WORD *)userWindowLong)[index/2] = value;
2563 return oldval;
2564 }
2565 SetLastError(ERROR_INVALID_PARAMETER);
2566 return 0;
2567}
2568//******************************************************************************
2569//******************************************************************************
2570WORD Win32BaseWindow::GetWindowWord(int index)
2571{
2572 if(index >= 0 && index/4 < nrUserWindowLong)
2573 {
2574 return ((WORD *)userWindowLong)[index/2];
2575 }
2576 SetLastError(ERROR_INVALID_PARAMETER);
2577 return 0;
2578}
2579//******************************************************************************
2580//******************************************************************************
2581void Win32BaseWindow::setWindowId(DWORD id)
2582{
2583 windowId = id;
2584 OSLibSetWindowID(OS2HwndFrame, id);
2585}
2586//******************************************************************************
2587//******************************************************************************
2588Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2589{
2590 Win32BaseWindow *window;
2591
2592 if(hwnd == NULL && windowDesktop)
2593 return windowDesktop;
2594
2595 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2596 return window;
2597 }
2598 else return NULL;
2599}
2600//******************************************************************************
2601//******************************************************************************
2602Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2603{
2604 Win32BaseWindow *win32wnd;
2605 DWORD magic;
2606
2607 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2608 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2609
2610 if(win32wnd && CheckMagicDword(magic)) {
2611 return win32wnd;
2612 }
2613 return 0;
2614}
2615//******************************************************************************
2616//******************************************************************************
2617Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
2618{
2619 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
2620}
2621//******************************************************************************
2622//******************************************************************************
2623HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2624{
2625 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2626
2627 if(window) {
2628 return window->getOS2WindowHandle();
2629 }
2630 else return hwnd;
2631}
2632//******************************************************************************
2633//******************************************************************************
2634HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
2635{
2636 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2637
2638 if(window) {
2639 return window->getOS2FrameWindowHandle();
2640 }
2641 else return hwnd;
2642}
2643//******************************************************************************
2644//******************************************************************************
2645HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2646{
2647 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2648
2649 if(window) {
2650 return window->getWindowHandle();
2651 }
2652 window = GetWindowFromOS2FrameHandle(hwnd);
2653 if(window) {
2654 return window->getWindowHandle();
2655 }
2656 else return hwnd; //OS/2 window handle
2657}
2658//******************************************************************************
2659//******************************************************************************
2660#ifdef DEBUG
2661void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
2662{
2663 char style[256] = "";
2664 char exstyle[256] = "";
2665
2666 /* Window styles */
2667 if(dwStyle & WS_CHILD)
2668 strcat(style, "WS_CHILD ");
2669 if(dwStyle & WS_POPUP)
2670 strcat(style, "WS_POPUP ");
2671 if(dwStyle & WS_VISIBLE)
2672 strcat(style, "WS_VISIBLE ");
2673 if(dwStyle & WS_DISABLED)
2674 strcat(style, "WS_DISABLED ");
2675 if(dwStyle & WS_CLIPSIBLINGS)
2676 strcat(style, "WS_CLIPSIBLINGS ");
2677 if(dwStyle & WS_CLIPCHILDREN)
2678 strcat(style, "WS_CLIPCHILDREN ");
2679 if(dwStyle & WS_MAXIMIZE)
2680 strcat(style, "WS_MAXIMIZE ");
2681 if(dwStyle & WS_MINIMIZE)
2682 strcat(style, "WS_MINIMIZE ");
2683 if(dwStyle & WS_GROUP)
2684 strcat(style, "WS_GROUP ");
2685 if(dwStyle & WS_TABSTOP)
2686 strcat(style, "WS_TABSTOP ");
2687
2688 if((dwStyle & WS_CAPTION) == WS_CAPTION)
2689 strcat(style, "WS_CAPTION ");
2690 if(dwStyle & WS_DLGFRAME)
2691 strcat(style, "WS_DLGFRAME ");
2692 if(dwStyle & WS_BORDER)
2693 strcat(style, "WS_BORDER ");
2694
2695 if(dwStyle & WS_VSCROLL)
2696 strcat(style, "WS_VSCROLL ");
2697 if(dwStyle & WS_HSCROLL)
2698 strcat(style, "WS_HSCROLL ");
2699 if(dwStyle & WS_SYSMENU)
2700 strcat(style, "WS_SYSMENU ");
2701 if(dwStyle & WS_THICKFRAME)
2702 strcat(style, "WS_THICKFRAME ");
2703 if(dwStyle & WS_MINIMIZEBOX)
2704 strcat(style, "WS_MINIMIZEBOX ");
2705 if(dwStyle & WS_MAXIMIZEBOX)
2706 strcat(style, "WS_MAXIMIZEBOX ");
2707
2708 if(dwExStyle & WS_EX_DLGMODALFRAME)
2709 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
2710 if(dwExStyle & WS_EX_ACCEPTFILES)
2711 strcat(exstyle, "WS_EX_ACCEPTFILES ");
2712 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
2713 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
2714 if(dwExStyle & WS_EX_TOPMOST)
2715 strcat(exstyle, "WS_EX_TOPMOST ");
2716 if(dwExStyle & WS_EX_TRANSPARENT)
2717 strcat(exstyle, "WS_EX_TRANSPARENT ");
2718
2719 if(dwExStyle & WS_EX_MDICHILD)
2720 strcat(exstyle, "WS_EX_MDICHILD ");
2721 if(dwExStyle & WS_EX_TOOLWINDOW)
2722 strcat(exstyle, "WS_EX_TOOLWINDOW ");
2723 if(dwExStyle & WS_EX_WINDOWEDGE)
2724 strcat(exstyle, "WS_EX_WINDOWEDGE ");
2725 if(dwExStyle & WS_EX_CLIENTEDGE)
2726 strcat(exstyle, "WS_EX_CLIENTEDGE ");
2727 if(dwExStyle & WS_EX_CONTEXTHELP)
2728 strcat(exstyle, "WS_EX_CONTEXTHELP ");
2729 if(dwExStyle & WS_EX_RIGHT)
2730 strcat(exstyle, "WS_EX_RIGHT ");
2731 if(dwExStyle & WS_EX_LEFT)
2732 strcat(exstyle, "WS_EX_LEFT ");
2733 if(dwExStyle & WS_EX_RTLREADING)
2734 strcat(exstyle, "WS_EX_RTLREADING ");
2735 if(dwExStyle & WS_EX_LTRREADING)
2736 strcat(exstyle, "WS_EX_LTRREADING ");
2737 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
2738 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
2739 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
2740 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
2741 if(dwExStyle & WS_EX_CONTROLPARENT)
2742 strcat(exstyle, "WS_EX_CONTROLPARENT ");
2743 if(dwExStyle & WS_EX_STATICEDGE)
2744 strcat(exstyle, "WS_EX_STATICEDGE ");
2745 if(dwExStyle & WS_EX_APPWINDOW)
2746 strcat(exstyle, "WS_EX_APPWINDOW ");
2747
2748 dprintf(("Window style: %x %s", dwStyle, style));
2749 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
2750}
2751#endif
2752//******************************************************************************
2753//******************************************************************************
2754
2755GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.