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

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

lots of changes

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