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

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

WS_VISIBLE & scrollbar fixes

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