Sweden-Number/windows/winproc.c

406 lines
14 KiB
C
Raw Normal View History

Release 960516 Thu May 16 13:35:31 1996 Alexandre Julliard <julliard@lrc.epfl.ch> * [*/*.c] Renamed RECT, POINT and SIZE structures to RECT16, POINT16 and SIZE16. Implemented Win32 version of most functions that take these types as parameters. * [configure] Patched autoconf to attempt to correctly detect -lnsl and -lsocket. Please check this out. * [controls/button.c] Added support for Win32 BM_* messages. * [controls/menu.c] Avoid sending extra WM_MENUSELECT messages. This avoids crashes with Excel. * [memory.heap.c] [include/heap.h] Added support for SEGPTRs in Win32 heaps. Added a few macros to make using SEGPTRs easier. They are a bit slower than MAKE_SEGPTR, but they work with Win32. * [memory/atom.c] Implemented Win32 atom functions. * [memory/local.c] Fixed LocalReAlloc() changes to avoid copying the whole block twice. * [win32/memory.c] Use /dev/zero instead of MAP_ANON for VirtualAlloc(). * [windows/class.c] Properly implemented the Win32 class functions. * [windows/winproc.c] (New file) New file handling the message translation between Win16 and Win32. Mon May 13 18:00:00 1996 Alex Korobka <alex@phm30.pharm.sunysb.edu> * [windows/mdi.c] [windows/menu.c] Improved WM_MDICREATE and WM_MDICASCADE handling. * [windows/event.c] [objects/bitblt.c] Handle GraphicsExpose event for BitBlt from screen to screen. * [windows/event.c] [windows/win.c] [windows/nonclient.c] Bunch of fixes for problems with -managed. * [windows/win.c] [windows/winpos.c] Changed conditions for WM_SIZE, WM_MOVE, and WM_GETMINMAXINFO in CreateWindow. * [windows/win.c] [windows/queue.c] [misc/user.c] Do not send WM_PARENTNOTIFY when in AppExit and call WH_SHELL on window creation/destruction. * [objects/palette.c] Crude RealizePalette(). At least something is visible in LviewPro. Sun May 12 02:05:00 1996 Thomas Sandford <t.d.g.sandford@prds-grn.demon.co.uk> * [if1632/gdi32.spec] Added Rectangle (use win16 version). * [if1632/kernel32.spec] Added GetWindowsDirectoryA (use win16 GetWindowsDirectory). * [if1632/user32.spec] Added GetSubMenu, MoveWindow, SetScrollPos, SetScrollRange (use win16 versions). Added SetWindowsHookExA (empty stub for now). * [include/handle32.h] Changed #include <malloc.h> to #include <stdlib.h> to prevent hate message from FreeBSD compiler. * [win32/newfns.c] Added new function SetWindowsHookEx32A (empty stub for now). * [win32/user32.c] Removed redundant debugging printf statement. Sun May 12 01:24:57 1996 Huw D. M. Davies <h.davies1@physics.oxford.ac.uk> * [memory/local.c] Avoid creating adjacent free blocks. Free the block in LocalReAlloc() before allocating a new one. Fixed LocalReAlloc() for discarded blocks. Fri May 10 23:05:12 1996 Jukka Iivonen <iivonen@cc.helsinki.fi> * [resources/sysres_Fi.rc] ChooseFont and ChooseColor dialogs updated. Fri May 10 17:19:33 1996 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [files/drive.c,if1632/kernel.spec] GetCurrentDirectory(),SetCurrentDirectory() implemented. * [if1632/advapi32.spec] [if1632/kernel.spec] [if1632/shell.spec] [include/windows.h] [include/winreg.h] [loader/main.c] [misc/main.c] [misc/shell.c] [misc/registry.c] Registry fixes: - loads win95 registry databases, - save only updated keys on default, - now adhers to the new function naming standard, - minor cleanups. Tue May 7 22:36:13 1996 Albrecht Kleine <kleine@ak.sax.de> * [combo.c] Added WM_COMMAND-handling for interaction between EDIT and COMBOLBOX and synchronized mine with Greg Kreider's works. * [commdlg.c] Bugfix in ChooseFont: font size handling.
1996-05-16 20:21:06 +02:00
/*
* Window procedure callbacks
*
* Copyright 1995 Martin von Loewis
* Copyright 1996 Alexandre Julliard
*/
#include <stdio.h>
#include "windows.h"
#include "alias.h"
#include "callback.h"
#include "heap.h"
#include "ldt.h"
#include "stackframe.h"
#include "struct32.h"
#include "win.h"
/**********************************************************************
* WINPROC_CallProc16To32
*
* Call a 32-bit window procedure, translating the 16-bit args.
*/
static LRESULT WINPROC_CallProc16To32( WNDPROC32 func, HWND16 hwnd, UINT16 msg,
WPARAM16 wParam, LPARAM lParam )
{
LRESULT result;
switch(msg)
{
case WM_ACTIVATE:
case WM_CHARTOITEM:
case WM_COMMAND:
case WM_HSCROLL:
case WM_VKEYTOITEM:
case WM_VSCROLL:
return CallWndProc32( func, hwnd, msg,
MAKEWPARAM( wParam, HIWORD(lParam) ),
(LPARAM)(HWND32)LOWORD(lParam) );
case WM_CTLCOLOR:
return CallWndProc32( func, hwnd, WM_CTLCOLORMSGBOX + HIWORD(lParam),
(WPARAM32)(HDC32)wParam,
(LPARAM)(HWND32)LOWORD(lParam) );
case WM_GETMINMAXINFO:
{
MINMAXINFO32 mmi;
STRUCT32_MINMAXINFO16to32( (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam),
&mmi );
result = CallWndProc32( func, hwnd, msg, wParam, (LPARAM)&mmi);
STRUCT32_MINMAXINFO32to16( &mmi,
(MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
}
return result;
case WM_GETTEXT:
/* FIXME: Unicode */
return CallWndProc32( func, hwnd, msg, wParam,
(LPARAM)PTR_SEG_TO_LIN(lParam) );
case WM_MDISETMENU:
return CallWndProc32( func, hwnd, msg,
(WPARAM32)(HMENU32)LOWORD(lParam),
(LPARAM)(HMENU32)HIWORD(lParam) );
case WM_MENUCHAR:
case WM_MENUSELECT:
return CallWndProc32( func, hwnd, msg,
MAKEWPARAM( wParam, LOWORD(lParam) ),
(LPARAM)(HMENU32)HIWORD(lParam) );
case WM_NCCALCSIZE:
{
NCCALCSIZE_PARAMS16 *pnc16;
NCCALCSIZE_PARAMS32 nc;
WINDOWPOS32 wp;
pnc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
CONV_RECT16TO32( &pnc16->rgrc[0], &nc.rgrc[0] );
if (wParam)
{
CONV_RECT16TO32( &pnc16->rgrc[1], &nc.rgrc[1] );
CONV_RECT16TO32( &pnc16->rgrc[2], &nc.rgrc[2] );
STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(pnc16->lppos),
&wp );
nc.lppos = &wp;
}
result = CallWndProc32( func, hwnd, msg, wParam, (LPARAM)&nc );
pnc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
CONV_RECT32TO16( &nc.rgrc[0], &pnc16->rgrc[0] );
if (wParam)
{
CONV_RECT32TO16( &nc.rgrc[1], &pnc16->rgrc[1] );
CONV_RECT32TO16( &nc.rgrc[2], &pnc16->rgrc[2] );
STRUCT32_WINDOWPOS32to16( nc.lppos,
(WINDOWPOS16 *)PTR_SEG_TO_LIN(pnc16->lppos));
}
}
return result;
case WM_NCCREATE:
case WM_CREATE:
{
CREATESTRUCT16 *pcs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
CREATESTRUCT32A cs;
STRUCT32_CREATESTRUCT16to32A( pcs16, &cs );
/* FIXME: Unicode */
cs.lpszName = (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszName);
cs.lpszClass = (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszClass);
result = CallWndProc32( func, hwnd, msg, wParam, (LPARAM)&cs );
pcs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
STRUCT32_CREATESTRUCT32Ato16( &cs, pcs16 );
if (cs.lpszName != (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszName))
fprintf( stderr, "CallWindowProc16: WM_NCCREATE(%04x) changed lpszName (%p->%p), please report.\n",
msg, (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszName), cs.lpszName);
if (cs.lpszClass != (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszClass))
fprintf( stderr, "CallWindowProc16: WM_NCCREATE(%04x) changed lpszClass (%p->%p), please report.\n",
msg, (LPCSTR)PTR_SEG_TO_LIN(pcs16->lpszClass), cs.lpszClass);
}
return result;
case WM_PARENTNOTIFY:
if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
return CallWndProc32( func, hwnd, msg,
MAKEWPARAM( wParam, HIWORD(lParam) ),
(LPARAM)(HWND32)LOWORD(lParam) );
else return CallWndProc32( func, hwnd, msg,
MAKEWPARAM( wParam, 0 /* FIXME? */ ),
lParam );
case WM_SETTEXT:
/* FIXME: Unicode */
return CallWndProc32( func, hwnd, msg, wParam,
(LPARAM)PTR_SEG_TO_LIN(lParam) );
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
{
WINDOWPOS32 wp;
STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam),
&wp );
result = CallWndProc32( func, hwnd, msg, wParam, (LPARAM)&wp );
STRUCT32_WINDOWPOS32to16( &wp,
(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam) );
}
return result;
case WM_ASKCBFORMATNAME:
case WM_COMPAREITEM:
case WM_DELETEITEM:
case WM_DEVMODECHANGE:
case WM_DRAWITEM:
case WM_MDIACTIVATE:
case WM_MDICREATE:
case WM_MEASUREITEM:
case WM_PAINTCLIPBOARD:
case WM_SIZECLIPBOARD:
case WM_WININICHANGE:
fprintf( stderr, "CallWindowProc16To32: message %04x needs translation\n", msg );
default: /* No translation needed */
return CallWndProc32( func, hwnd, msg, (WPARAM32)wParam, lParam );
}
}
/**********************************************************************
* WINPROC_CallProc32To16
*
* Call a 16-bit window procedure, translating the 32-bit args.
*/
static LRESULT WINPROC_CallProc32To16( WNDPROC16 func, WORD ds, HWND32 hwnd,
UINT32 msg, WPARAM32 wParam,
LPARAM lParam )
{
LRESULT result;
switch(msg)
{
case WM_ACTIVATE:
case WM_CHARTOITEM:
case WM_COMMAND:
case WM_HSCROLL:
case WM_VKEYTOITEM:
case WM_VSCROLL:
return CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
return CallWndProc16( func, ds, hwnd, WM_CTLCOLOR, (WPARAM16)wParam,
MAKELPARAM( (HWND16)lParam,
(WORD)msg - WM_CTLCOLORMSGBOX ) );
case WM_GETMINMAXINFO:
{
MINMAXINFO16 *mmi = SEGPTR_NEW(MINMAXINFO16);
if (!mmi) return 0;
STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, mmi );
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(mmi) );
STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO32 *)lParam );
SEGPTR_FREE(mmi);
}
return result;
case WM_GETTEXT:
{
LPSTR str;
wParam = MIN( wParam, 0xff80 ); /* Size must be < 64K */
if (!(str = SEGPTR_ALLOC( wParam ))) return 0;
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(str) );
if (result > 0) memcpy( (LPSTR)lParam, str, result );
SEGPTR_FREE(str);
}
return result;
case WM_MDISETMENU:
return CallWndProc16( func, ds, hwnd, msg, TRUE /* FIXME? */,
MAKELPARAM( (HMENU16)LOWORD(lParam),
(HMENU16)HIWORD(lParam) ) );
case WM_MENUCHAR:
case WM_MENUSELECT:
return CallWndProc16( func, ds, hwnd, msg, (WPARAM16)LOWORD(wParam),
MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ) );
case WM_NCCALCSIZE:
{
NCCALCSIZE_PARAMS32 *nc32 = (NCCALCSIZE_PARAMS32 *)lParam;
NCCALCSIZE_PARAMS16 *nc;
WINDOWPOS16 *wp = NULL;
if (!(nc = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
if (wParam)
{
CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
{
SEGPTR_FREE(nc);
return 0;
}
STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
nc->lppos = SEGPTR_GET(wp);
}
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(nc) );
CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
if (wParam)
{
CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
nc32->lppos );
SEGPTR_FREE(wp);
}
SEGPTR_FREE(nc);
}
return result;
case WM_NCCREATE:
case WM_CREATE:
{
CREATESTRUCT16 *cs;
CREATESTRUCT32A *cs32 = (CREATESTRUCT32A *)lParam;
LPSTR name, cls;
if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return 0;
STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
name = SEGPTR_STRDUP( cs32->lpszName );
cls = SEGPTR_STRDUP( cs32->lpszClass );
cs->lpszName = SEGPTR_GET(name);
cs->lpszClass = SEGPTR_GET(cls);
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(cs) );
STRUCT32_CREATESTRUCT16to32A( cs, cs32 );
if (PTR_SEG_TO_LIN(cs->lpszName) != name)
cs32->lpszName = (LPCSTR)PTR_SEG_TO_LIN( cs->lpszName );
if (PTR_SEG_TO_LIN(cs->lpszClass) != cls)
cs32->lpszClass = (LPCSTR)PTR_SEG_TO_LIN( cs->lpszClass );
SEGPTR_FREE(name);
SEGPTR_FREE(cls);
SEGPTR_FREE(cs);
}
return result;
case WM_PARENTNOTIFY:
if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
return CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
MAKELPARAM( (HWND16)lParam, LOWORD(wParam)));
case WM_SETTEXT:
{
LPSTR str = SEGPTR_STRDUP( (LPSTR)lParam );
if (!str) return 0;
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(str) );
SEGPTR_FREE(str);
}
return result;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
{
WINDOWPOS16 *wp;
if (!(wp = SEGPTR_NEW(WINDOWPOS16))) return 0;
STRUCT32_WINDOWPOS32to16( (WINDOWPOS32 *)lParam, wp );
result = CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam,
(LPARAM)SEGPTR_GET(wp) );
STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS32 *)lParam );
SEGPTR_FREE(wp);
}
return result;
case WM_ASKCBFORMATNAME:
case WM_COMPAREITEM:
case WM_DELETEITEM:
case WM_DEVMODECHANGE:
case WM_DRAWITEM:
case WM_MDIACTIVATE:
case WM_MDICREATE:
case WM_MEASUREITEM:
case WM_PAINTCLIPBOARD:
case WM_SIZECLIPBOARD:
case WM_WININICHANGE:
fprintf( stderr, "CallWindowProc32To16: message %04x needs translation\n", msg );
default: /* No translation needed */
return CallWndProc16( func, ds, hwnd, msg, (WPARAM16)wParam, lParam );
}
}
/**********************************************************************
* CallWindowProc16 (USER.122)
*/
LRESULT CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
WPARAM16 wParam, LPARAM lParam )
{
FUNCTIONALIAS *a;
/* check if we have something better than 16 bit relays */
if (!ALIAS_UseAliases || !(a=ALIAS_LookupAlias((DWORD)func)) ||
(!a->wine && !a->win32))
{
WND *wndPtr = WIN_FindWndPtr( hwnd );
return CallWndProc16( (FARPROC)func,
wndPtr ? wndPtr->hInstance : CURRENT_DS,
hwnd, msg, wParam, lParam );
}
if(a->wine)
return ((LONG(*)(WORD,WORD,WORD,LONG))(a->wine))
(hwnd,msg,wParam,lParam);
return WINPROC_CallProc16To32( (WNDPROC32)a->win32, hwnd, msg,
wParam, lParam );
}
/**********************************************************************
* CallWindowProc32A (USER32.17)
*/
LRESULT CallWindowProc32A( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
WPARAM32 wParam, LPARAM lParam )
{
FUNCTIONALIAS *a = NULL;
WND *wndPtr;
WORD ds;
/* check if we have something better than 16 bit relays */
if (ALIAS_UseAliases && (a=ALIAS_LookupAlias((DWORD)func)) &&
(a->wine || a->win32))
{
/* FIXME: Unicode */
if (a->wine)
return ((WNDPROC32)a->wine)(hwnd,msg,wParam,lParam);
else return CallWndProc32( func, hwnd, msg, wParam, lParam );
}
wndPtr = WIN_FindWndPtr( hwnd );
ds = wndPtr ? wndPtr->hInstance : CURRENT_DS;
if (!a)
{
fprintf( stderr, "CallWindowProc32A: no alias for %p\n", func );
return 0;
}
return WINPROC_CallProc32To16( (WNDPROC16)a->win16, ds, hwnd, msg,
wParam, lParam );
}
/**********************************************************************
* CallWindowProc32W (USER32.18)
*/
LRESULT CallWindowProc32W( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
WPARAM32 wParam, LPARAM lParam )
{
/* FIXME: Unicode translation */
return CallWindowProc32A( func, hwnd, msg, wParam, lParam );
}