Release 970928

Sat Sep 27 12:36:56 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [if1632/relay.c]
	Made Catch and Throw also save %si and %di (untested).

	* [memory/selector.c]
	Added check for %fs and %gs in SELECTOR_FreeBlock.

	* [rc/winerc.c]
	Generated files no longer depend on Wine includes.
	Made .h generation optional.

	* [tools/build.c] [loader/task.c]
	Added CALL32_Init function.
	Added possibility to pass arguments when using CALLTO16_regs_.
	32-bit stack pointer is now saved on the 16-bit stack, instead of
	using IF1632_Saved32_esp.
	Removed CallTo32 callbacks.

	* [tools/makedep.c] [*/Makefile.in]
	Added support for directly generating dependencies for .y, .l and
	.rc files. Modified the makefiles to use this feature.

	* [windows/winproc.c] [if1632/thunk.c]
	Use CALLTO16_regs to call window procedures.

Thu Sep 25 12:18:57 1997  Kristian Nielsen <kristian.nielsen@risoe.dk>

	* [if1632/kernel.spec]
	Changed entry for SwitchStackBack to remove arguments from stack
	upon return (arguments left over from previous SwitchStackTo()).
	Borland C++ 4.0 now compiles "Hello World" (but crashes after
	outputting the .exe).

Wed Sep 24 13:54:44 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/directory.c]
	SearchPath might get NULL buffer (empty LRU list in wordpad).

	* [memory/selector.c]
	Added SUnMapLS*.

	* [loader/pe_image.c]
	Be able to run executeables from non mmap()ble filesystems.
	PE_LoadLibrary adds librarys loaded by another process to
	its own modref list too.

	* [windows/keyboard.c][include/accel.h][loader/resource.c]
	Fixed accelerator leakage, use SDK defines/names.

	* [graphics/env.c][misc/main.c]
	Set/GetEnvironemnt have nothing to do with environment vars,
	but with Printer Environment.

	* [graphics/escape.c]
	Escape32: map args back to segmented pointers.

	* [windows/win.c]
	WS_POPUP|WS_CHILD windows don't need a parent window (SDK).

Tue Sep 16 14:40:16 1997  Robert Wilhelm  <robert@physiol.med.tu-muenchen.de>

	* [if1632/crtdll.spec] [misc/crtdll.c]
	Added signal().
diff --git a/windows/dialog.c b/windows/dialog.c
index 31cd880..b56f684 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -502,10 +502,16 @@
     {
           /* The font height must be negative as it is a point size */
           /* (see CreateFont() documentation in the Windows SDK).   */
-	hFont = CreateFont16( -template.pointSize, 0, 0, 0, FW_DONTCARE,
+	if (win32Template)
+	    hFont = CreateFont16( -template.pointSize, 0, 0, 0, FW_DONTCARE,
 			    FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
 			    PROOF_QUALITY, FF_DONTCARE,
-                            template.faceName );  /* FIXME: win32 */
+                            template.faceName );
+	else
+	    hFont = CreateFont32W( -template.pointSize, 0, 0, 0, FW_DONTCARE,
+			    FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
+			    PROOF_QUALITY, FF_DONTCARE,
+                            template.faceName );
 	if (hFont)
 	{
 	    TEXTMETRIC16 tm;
@@ -562,17 +568,18 @@
         }
     }
 
-    if (procType != WIN_PROC_16)
+    if (procType == WIN_PROC_16)
+        hwnd = CreateWindowEx16(template.exStyle, template.className,
+                                template.caption, template.style & ~WS_VISIBLE,
+                                rect.left, rect.top, rect.right, rect.bottom,
+                                owner, hMenu, hInst, NULL );
+    else
         hwnd = CreateWindowEx32W(template.exStyle, (LPCWSTR)template.className,
                                  (LPCWSTR)template.caption,
                                  template.style & ~WS_VISIBLE,
                                  rect.left, rect.top, rect.right, rect.bottom,
                                  owner, hMenu, hInst, NULL );
-    else
-        hwnd = CreateWindowEx32A(template.exStyle, template.className,
-                                template.caption, template.style & ~WS_VISIBLE,
-                                rect.left, rect.top, rect.right, rect.bottom,
-                                owner, hMenu, hInst, NULL );
+	
     if (!hwnd)
     {
 	if (hFont) DeleteObject32( hFont );
diff --git a/windows/event.c b/windows/event.c
index c843ec9..cb6dcb8 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -775,6 +775,7 @@
 	/* Fill WINDOWPOS struct */
 	winpos.flags = SWP_NOACTIVATE | SWP_NOZORDER;
 	winpos.hwnd = hwnd;
+        /* FIXME: position should be relative to root window */
 	winpos.x = event->x;
 	winpos.y = event->y;
 	winpos.cx = event->width;
diff --git a/windows/hook.c b/windows/hook.c
index 55e5785..594dd1a 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -17,7 +17,6 @@
 #include "windows.h"
 #include "hook.h"
 #include "queue.h"
-#include "stackframe.h"
 #include "user.h"
 #include "heap.h"
 #include "struct32.h"
@@ -696,7 +695,7 @@
 	}
 	else
 	  lpcbtcwW->lpcs->lpszClass = (LPCWSTR)lpcbtcwA->lpcs->lpszClass;
-	*plParam = lpcbtcwW;
+	*plParam = (LPARAM)lpcbtcwW;
     }
     return;
 }
@@ -750,7 +749,7 @@
                                                    lpcbtcwW->lpcs->lpszClass );
 	else
 	  lpcbtcwA->lpcs->lpszClass = (LPSTR)lpcbtcwW->lpcs->lpszClass;
-	*plParam = lpcbtcwA;
+	*plParam = (LPARAM)lpcbtcwA;
     }
     return;
 }
@@ -963,7 +962,6 @@
     HANDLE16 prevHook;
     HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
     LRESULT ret;
-    WORD old_ds;
 
     WPARAM32 wParamOrig = wParam;
     LPARAM lParamOrig = lParam;
@@ -986,11 +984,7 @@
     dprintf_hook( stddeb, "Calling hook %04x: %d %08x %08lx\n",
                   hook, code, wParam, lParam );
 
-    /* Set DS = SS to call hook procedure */
-    old_ds = CURRENT_DS;
-    CURRENT_DS = SELECTOROF(IF1632_Saved16_ss_sp);
     ret = data->proc(code, wParam, lParam);
-    CURRENT_DS = old_ds;
 
     dprintf_hook( stddeb, "Ret hook %04x = %08lx\n", hook, ret );
 
diff --git a/windows/keyboard.c b/windows/keyboard.c
index 9421737..229ef59 100644
--- a/windows/keyboard.c
+++ b/windows/keyboard.c
@@ -600,63 +600,33 @@
     return GetAsyncKeyState32(nKey);
 }
 
-
-
 /**********************************************************************
- *			TranslateAccelerator 	[USER.178]
+ *			TranslateAccelerator 	[USER.178][USER32.551..]
  *
  * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP  -messages
  */
-INT32 WINAPI TranslateAccelerator32(HWND32 hWnd, HACCEL32 hAccel, LPMSG32 msg)
+static BOOL32 KBD_translate_accelerator(HWND32 hWnd,LPMSG32 msg,
+                                        BYTE fVirt,WORD key,WORD cmd)
 {
-    MSG16	msg16;
+    BOOL32	sendmsg = FALSE;
 
-    STRUCT32_MSG32to16(msg,&msg16);
-    return TranslateAccelerator16(hWnd,hAccel,&msg16);
-}
-	
-INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
-{
-    ACCELHEADER	*lpAccelTbl;
-    int 	i;
-    BOOL32 sendmsg;
-    
-    if (hAccel == 0 || msg == NULL) return 0;
-    if (msg->message != WM_KEYDOWN &&
-    	msg->message != WM_KEYUP &&
-	msg->message != WM_SYSKEYDOWN &&
-	msg->message != WM_SYSKEYUP &&
-    	msg->message != WM_CHAR) return 0;
-
-    dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
-msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
-
-    lpAccelTbl = (LPACCELHEADER)GlobalLock16(hAccel);
-    for (sendmsg= i = 0; i < lpAccelTbl->wCount; i++) 
+    if(msg->wParam == key) 
     {
-     if(msg->wParam == lpAccelTbl->tbl[i].wEvent) 
-     {
-      if (msg->message == WM_CHAR) 
-      {
-        if ( !(lpAccelTbl->tbl[i].type & ALT_ACCEL) && 
-             !(lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) )
+    	if (msg->message == WM_CHAR) {
+        if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
         {
    	  dprintf_accel(stddeb,"found accel for WM_CHAR: ('%c')",msg->wParam&0xff);
    	  sendmsg=TRUE;
    	}  
-      }
-      else
-      {
-       if(lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) 
-       {
+      } else {
+       if(fVirt & FVIRTKEY) {
 	INT32 mask = 0;
         dprintf_accel(stddeb,"found accel for virt_key %04x (scan %04x)",
   	                       msg->wParam,0xff & HIWORD(msg->lParam));                
-	if(GetKeyState32(VK_SHIFT) & 0x8000) mask |= SHIFT_ACCEL;
-	if(GetKeyState32(VK_CONTROL) & 0x8000) mask |= CONTROL_ACCEL;
-	if(GetKeyState32(VK_MENU) & 0x8000) mask |= ALT_ACCEL;
-	if(mask == (lpAccelTbl->tbl[i].type &
-			    (SHIFT_ACCEL | CONTROL_ACCEL | ALT_ACCEL)))
+	if(GetKeyState32(VK_SHIFT) & 0x8000) mask |= FSHIFT;
+	if(GetKeyState32(VK_CONTROL) & 0x8000) mask |= FCONTROL;
+	if(GetKeyState32(VK_MENU) & 0x8000) mask |= FALT;
+	if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
           sendmsg=TRUE;			    
         else
           dprintf_accel(stddeb,", but incorrect SHIFT/CTRL/ALT-state\n");
@@ -665,7 +635,7 @@
        {
          if (!(msg->lParam & 0x01000000))  /* no special_key */
          {
-           if ((lpAccelTbl->tbl[i].type & ALT_ACCEL) && (msg->lParam & 0x20000000))
+           if ((fVirt & FALT) && (msg->lParam & 0x20000000))
            {                                                   /* ^^ ALT pressed */
 	    dprintf_accel(stddeb,"found accel for Alt-%c", msg->wParam&0xff);
 	    sendmsg=TRUE;	    
@@ -682,10 +652,10 @@
         if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
           mesg=1;
         else 
-         if (GetCapture16())
+         if (GetCapture32())
            mesg=2;
          else
-          if (!IsWindowEnabled16(hWnd))
+          if (!IsWindowEnabled32(hWnd))
             mesg=3;
           else
           {
@@ -693,9 +663,9 @@
 
             hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU32)wndPtr->wIDmenu;
 	    iSysStat = (wndPtr->hSysMenu) ? GetMenuState32(GetSubMenu16(wndPtr->hSysMenu, 0),
-					    lpAccelTbl->tbl[i].wIDval, MF_BYCOMMAND) : -1 ;
+					    cmd, MF_BYCOMMAND) : -1 ;
 	    iStat = (hMenu) ? GetMenuState32(hMenu,
-					    lpAccelTbl->tbl[i].wIDval, MF_BYCOMMAND) : -1 ;
+					    cmd, MF_BYCOMMAND) : -1 ;
 
             if (iSysStat!=-1)
             {
@@ -726,8 +696,8 @@
           {
               dprintf_accel(stddeb,", sending %s, wParam=%0x\n",
                   mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
-                  lpAccelTbl->tbl[i].wIDval);
-	      SendMessage16(hWnd, mesg, lpAccelTbl->tbl[i].wIDval,0x00010000L);
+                  cmd);
+	      SendMessage32A(hWnd, mesg, cmd, 0x00010000L);
 	  }
 	  else
 	  {
@@ -742,12 +712,56 @@
 	    */
 	    dprintf_accel(stddeb,", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
 	  }          
-          GlobalUnlock16(hAccel);
-          return 1;         
+          return TRUE;         
       }
-     }
     }
-    GlobalUnlock16(hAccel);
+    return FALSE;
+}
+
+INT32 WINAPI TranslateAccelerator32(HWND32 hWnd, HACCEL32 hAccel, LPMSG32 msg)
+{
+    LPACCEL32	lpAccelTbl = (LPACCEL32)LockResource32(hAccel);
+    int 	i;
+    
+    if (hAccel == 0 || msg == NULL) return 0;
+    if (msg->message != WM_KEYDOWN &&
+    	msg->message != WM_KEYUP &&
+	msg->message != WM_SYSKEYDOWN &&
+	msg->message != WM_SYSKEYUP &&
+    	msg->message != WM_CHAR) return 0;
+
+    dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
+msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
+
+    for (i = 0; lpAccelTbl[i].key ; i++)
+    	if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
+                                      lpAccelTbl[i].key,lpAccelTbl[i].cmd))
+		return 1;
+    return 0;
+}
+	
+INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
+{
+    LPACCEL16	lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
+    int 	i;
+    MSG32	msg32;
+    
+    if (hAccel == 0 || msg == NULL) return 0;
+    if (msg->message != WM_KEYDOWN &&
+    	msg->message != WM_KEYUP &&
+	msg->message != WM_SYSKEYDOWN &&
+	msg->message != WM_SYSKEYUP &&
+    	msg->message != WM_CHAR) return 0;
+
+    dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
+msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
+    STRUCT32_MSG16to32(msg,&msg32);
+
+
+    for (i=0;lpAccelTbl[i].key;i++) 
+    	if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
+                                      lpAccelTbl[i].key,lpAccelTbl[i].cmd))
+		return 1;
     return 0;
 }
 
diff --git a/windows/syscolor.c b/windows/syscolor.c
index e722daa..fc1fb9d 100644
--- a/windows/syscolor.c
+++ b/windows/syscolor.c
@@ -210,7 +210,6 @@
 /*************************************************************************
  *             SetSysColors16   (USER.181)
  */
-/* FIXME -- check return type and insert comment if correct.  */
 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
 			    const COLORREF *lpColorValues )
 {
diff --git a/windows/user.c b/windows/user.c
index 90e7567..dda1a28 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -23,8 +23,6 @@
 
 WORD USER_HeapSel = 0;
 
-extern HGLOBAL16 LoadDIBCursorHandler( HGLOBAL16, HINSTANCE16, HRSRC16 );
-extern HGLOBAL16 LoadDIBIconHandler( HGLOBAL16, HINSTANCE16, HRSRC16 );
 extern BOOL32 MENU_PatchResidentPopup( HQUEUE16, WND* );
 extern void QUEUE_FlushMessages(HQUEUE16);
 
diff --git a/windows/win.c b/windows/win.c
index 22d8eaf..32c9f2f 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -468,7 +468,7 @@
     if (HIWORD(cs->lpszClass)) dprintf_win( stddeb, "'%s' ", cs->lpszClass );
     else dprintf_win( stddeb, "#%04x ", LOWORD(cs->lpszClass) );
 
-    dprintf_win( stddeb, "%08lx %08lx %d,%d %dx%d %04x %04x %04x %p\n",
+    dprintf_win( stddeb, "%08lx %08lx %d,%d %dx%d %04x %04x %08x %p\n",
 		 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
 		 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams);
 
@@ -482,11 +482,9 @@
             fprintf( stderr, "CreateWindowEx: bad parent %04x\n", cs->hwndParent );
 	    return 0;
 	}
-    }
-    else if (cs->style & WS_CHILD)
-    {
+    } else if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
         fprintf( stderr, "CreateWindowEx: no parent for child window\n" );
-        return 0;  /* WS_CHILD needs a parent */
+        return 0;  /* WS_CHILD needs a parent, but WS_POPUP doesn't */
     }
 
     /* Find the window class */
@@ -526,7 +524,7 @@
     wndPtr->next  = NULL;
     wndPtr->child = NULL;
 
-    if (cs->style & WS_CHILD)
+    if ((cs->style & WS_CHILD) && cs->hwndParent)
     {
         wndPtr->parent = WIN_FindWndPtr( cs->hwndParent );
         wndPtr->owner  = NULL;
diff --git a/windows/winproc.c b/windows/winproc.c
index 267029e..ddb5be1 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -9,7 +9,6 @@
 #include "windows.h"
 #include "heap.h"
 #include "selectors.h"
-#include "stackframe.h"
 #include "struct32.h"
 #include "win.h"
 #include "winproc.h"
@@ -1779,17 +1778,13 @@
 {
     UINT16 msg16;
     MSGPARAM16 mp16;
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
-    WORD ds = CURRENT_DS;
 
     mp16.lParam = lParam;
     if (WINPROC_MapMsg32ATo16( msg, wParam, 
 			      &msg16, &mp16.wParam, &mp16.lParam ) == -1)
         return 0;
-    if (wndPtr) CURRENT_DS = wndPtr->hInstance;
     mp16.lResult = WINPROC_CallWndProc16Ptr( func, hwnd, msg16,
                                              mp16.wParam, mp16.lParam );
-    CURRENT_DS = ds;
     WINPROC_UnmapMsg32ATo16( msg, wParam, lParam, &mp16 );
     return mp16.lResult;
 }
@@ -1806,16 +1801,12 @@
 {
     UINT16 msg16;
     MSGPARAM16 mp16;
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
-    WORD ds = CURRENT_DS;
 
     mp16.lParam = lParam;
     if (WINPROC_MapMsg32WTo16( msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
         return 0;
-    if (wndPtr) CURRENT_DS = wndPtr->hInstance;
     mp16.lResult = WINPROC_CallWndProc16Ptr( func, hwnd, msg16,
                                              mp16.wParam, mp16.lParam );
-    CURRENT_DS = ds;
     WINPROC_UnmapMsg32WTo16( msg, wParam, lParam, &mp16 );
     return mp16.lResult;
 }
@@ -1827,41 +1818,22 @@
 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
                                  WPARAM16 wParam, LPARAM lParam )
 {
-    LRESULT result;
-    WND *wndPtr;
-    WORD ds;
     WINDOWPROC *proc = WINPROC_GetPtr( func );
 
     if (!proc)
-    {
-        ds = CURRENT_DS;
-        wndPtr = WIN_FindWndPtr( hwnd );
-        if (wndPtr) CURRENT_DS = wndPtr->hInstance;
-        result = WINPROC_CallWndProc16Ptr( func, hwnd, msg, wParam, lParam );
-        CURRENT_DS = ds;
-        return result;
-    }
+        return WINPROC_CallWndProc16Ptr( func, hwnd, msg, wParam, lParam );
+
 #if testing
-    wndPtr = WIN_FindWndPtr( hwnd );
-    if (wndPtr) CURRENT_DS = wndPtr->hInstance;
-    result = WINPROC_CallWndProc16Ptr( WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16),
-                                       hwnd, msg, wParam, lParam );
-    CURRENT_DS = ds;
-    return result;
+    func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
+    return WINPROC_CallWndProc16Ptr( func, hwnd, msg, wParam, lParam );
 #endif
     
     switch(proc->type)
     {
     case WIN_PROC_16:
         if (!proc->thunk.t_from32.proc) return 0;
-        ds = CURRENT_DS;
-        wndPtr = WIN_FindWndPtr( hwnd );
-        if (wndPtr) CURRENT_DS = wndPtr->hInstance;
-        result = WINPROC_CallWndProc16Ptr( proc->thunk.t_from32.proc,
-                                           hwnd, msg, wParam, lParam );
-        CURRENT_DS = ds;
-        return result;
-
+        return WINPROC_CallWndProc16Ptr( proc->thunk.t_from32.proc,
+                                         hwnd, msg, wParam, lParam );
     case WIN_PROC_32A:
         if (!proc->thunk.t_from16.proc) return 0;
         return WINPROC_CallProc16To32A( hwnd, msg, wParam, lParam,