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

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

Window destruction fixes

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