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

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

Window creation rewrite + bugfixes. NOT WORKING CORRECTLY YET..

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