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

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

groupbox redraw + setpos fixes

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