Release 960805

Sun Aug  4 18:18:48 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [controls/scroll.c]
	Attempted to implement undocumented scroll-bar messages.

	* [tools/build.c] [include/callback.h] [windows/winproc.c]
	CallTo16_* functions now get DS from the previous 16-bit stackframe.

	* [if1632/thunk.c] [include/callback.h]
	Added thunks to implement callbacks for the emulator. Now all the
	Enum* functions always take a real function pointer even in the
	emulator.
	
	* [loader/builtin.c]
	Removed binary search in BUILTIN_GetEntryPoint32(), as it didn't
 	work with NULL entry points. Using linear search now.

	* [loader/module.c]
	Implemented IsSharedSelector().

	* [loader/task.c]
	Changed SwitchStackTo/Back to use the instance data to store the
	previous stack instead of the TDB. Also copy the local variables
	onto the new stack.
	Added GetExeVersion() and SetTackSignalProc().
	Implemented SetSigHandler().

Sat Aug  3 22:19:00 1996  Thomas Sandford <t.d.g.sandford@prds-grn.demon.co.uk>

	* [controls/menu.c]
	"Fixed" problem in deleting menus where win32 could get into an
	endless loop when it crashed. I think I've fixed the symptoms, not
	the original problem so it might be worth further investigation.

	* [debugger/registers.c]
	Added missing #ifdefs on FS_REG and GS_REG, needed for FreeBSD to
	compile wine properly.

	* [files/dos_fs.c]
	Made DOSFS_Hash and DOSFS_Match non-static so they can be called
	from win32/findfile.c (q.v.).

	* [if1632/gdi32.spec]
	Added SetMapMode (call existing function)

	* [if1632/kernel32.spec]
	Added FindFirstFileA and SetFileAttributesA.

	* [if1632/user32.spec]
	Added BringWindowToTop, CreatePopupMenu, GetKeyState, GetParent,
	IsDlgButtonChecked (call existing functions) and IsDialogMessageA,
	UnhookWindowsHookEx.

	* [win32/file.c]
	Added stub function SetFileAttributes32A. It's a stub because I
	can't really work out what this function should do with most
	attributes in a Unix environment. Anyone care to expand it?

	* [win32/findfile.c]
	New file. Initial stab at FindFirstFile. This doesn't work as
	specified yet, though a lot of the groundwork is there. I haven't
	time to work on this for the next month, so if anyone wants to pick
	it up and run with it please do.

	* [win32/memory.c]
	Removed malloc.h from includes (covered by stdlib.h include, and
	gets rid of a warning in FreeBSD).

	* [win32/newfns.c]
	UnhookWindowsHookEx32A stub added.

	* [win32/user32.c]
	Added implementation of IsDialogMessage32A.

	* [windows/dialog.c]
	IsDlgButtonChecked now calls SendDlgItemMessage32A instead of
	SendDlgItemMessage16.

Sat Aug  3 18:00:00 1996 Alex Korobka <alex@phm30.pharm.sunysb.edu>

	* [windows/graphics.c]
	Removed rectangle checking (conflicted with nonstandard
	mapping modes). 

	* [windows/dialog.c]
	Added check for child-style dialogs to DS_ABSALIGN
	coordinate conversion.

	* [objects/color.c]
	Cleaned up misc. bits

Thu Aug  1 10:51:45 1996  Andrew Lewycky <plewycky@oise.utoronto.ca>

	* [windows/focus.c] [windows/event.c] [windows/win.c]
	  [windows/defdlg.c]
	Fixes to focusing and activation.

	* [windows/defdlg.c]
	Properly(?) handle DM_GETDEFID.

	* [controls/combo.c]
	Handle CB_FINDSTRINGEXACT, CB_SETEDITSEL, CB_GETEDITSEL.
	CBCheckSize: Adjust edit position.

Tue Jul 30 09:46:36 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/file.c] [include/file.h] [loader/module.c] [loader/ne_image.c]
	Pass HFILEs instead of unix-fds to self-loader code.

Mon Jul 29 21:48:25 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [include/metafile.h] [objects/metafile.c] [objects/text.c]
	Implemented handling of some new metafile records (META_...)
	in PlayMetaFileRecord(), rewrite of 'case META_EXTTEXTOUT'.
	Added functions like MF_StretchBlt() for usage in metafiles.
	Minor bugfix in CopyMetafile().

	* [objects/bitmap.c][objects/dib.c]
	Added check for metafile-DC in Bitmap and DIB functions:
	CreateCompatibleBitmap() etc.
diff --git a/loader/task.c b/loader/task.c
index bf32790..b1bea0d 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -25,6 +25,7 @@
 #include "peexe.h"
 #include "pe_image.h"
 #include "queue.h"
+#include "stackframe.h"
 #include "toolhelp.h"
 #include "stddebug.h"
 #include "debug.h"
@@ -61,9 +62,9 @@
 static FARPROC16 TASK_RescheduleProc;
 
 #ifdef WINELIB
-#define TASK_SCHEDULE()  TASK_Reschedule();
+#define TASK_SCHEDULE()  TASK_Reschedule()
 #else
-#define TASK_SCHEDULE()  CallTo16_word_(TASK_RescheduleProc,0)
+#define TASK_SCHEDULE()  CallTo16_word_(TASK_RescheduleProc)
 #endif
 
 static HANDLE TASK_CreateDOSEnvironment(void);
@@ -1066,20 +1067,33 @@
 {
     TDB *pTask;
     STACK16FRAME *oldFrame, *newFrame;
+    INSTANCEDATA *pData;
+    UINT16 copySize;
 
     if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return;
+    if (!(pData = (INSTANCEDATA *)GlobalLock16( seg ))) return;
     dprintf_task( stddeb, "SwitchStackTo: old=%04x:%04x new=%04x:%04x\n",
                   IF1632_Saved16_ss, IF1632_Saved16_sp, seg, ptr );
+
     /* Save the old stack */
-    oldFrame = CURRENT_STACK16;
-    pTask->switchStackSS = IF1632_Saved16_ss;
-    pTask->switchStackSP = IF1632_Saved16_sp;
+
+    oldFrame           = CURRENT_STACK16;
+    pData->old_sp      = IF1632_Saved16_sp;
+    pData->old_ss      = IF1632_Saved16_ss;
+    pData->stacktop    = top;
+    pData->stackmin    = ptr;
+    pData->stackbottom = ptr;
+
     /* Switch to the new stack */
-    IF1632_Saved16_ss = seg;
-    IF1632_Saved16_sp = ptr - sizeof(STACK16FRAME);
+
+    IF1632_Saved16_ss = pTask->ss = seg;
+    IF1632_Saved16_sp = pTask->sp = ptr - sizeof(STACK16FRAME);
     newFrame = CURRENT_STACK16;
-    /* Build the stack frame on the new stack */
-    *newFrame = *oldFrame;
+
+    /* Copy the stack frame and the local variables to the new stack */
+
+    copySize = oldFrame->bp - pData->old_sp;
+    memcpy( newFrame, oldFrame, MAX( copySize, sizeof(STACK16FRAME) ));
 }
 
 
@@ -1094,22 +1108,28 @@
 {
     TDB *pTask;
     STACK16FRAME *oldFrame, *newFrame;
+    INSTANCEDATA *pData;
 
     if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return;
-    if (!pTask->switchStackSS)
+    if (!(pData = (INSTANCEDATA *)GlobalLock16( IF1632_Saved16_ss ))) return;
+    if (!pData->old_ss)
     {
         fprintf( stderr, "SwitchStackBack: no previous SwitchStackTo\n" );
         return;
     }
     dprintf_task( stddeb, "SwitchStackBack: restoring stack %04x:%04x\n",
-                  pTask->switchStackSS, pTask->switchStackSP );
+                  pData->old_ss, pData->old_sp );
 
     oldFrame = CURRENT_STACK16;
+
     /* Switch back to the old stack */
-    IF1632_Saved16_ss = pTask->switchStackSS;
-    IF1632_Saved16_sp = pTask->switchStackSP;
-    pTask->switchStackSS = 0;
+
+    IF1632_Saved16_ss = pTask->ss = pData->old_ss;
+    IF1632_Saved16_sp = pTask->sp = pData->old_sp;
+    pData->old_ss = pData->old_sp = 0;
+
     /* Build a stack frame for the return */
+
     newFrame = CURRENT_STACK16;
     newFrame->saved_ss = oldFrame->saved_ss;
     newFrame->saved_sp = oldFrame->saved_sp;
@@ -1185,6 +1205,18 @@
 
 
 /***********************************************************************
+ *           GetExeVersion   (KERNEL.105)
+ */
+WORD GetExeVersion(void)
+{
+    TDB *pTask;
+
+    if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return 0;
+    return pTask->version;
+}
+
+
+/***********************************************************************
  *           SetErrorMode   (KERNEL.107)
  */
 UINT SetErrorMode( UINT mode )
@@ -1222,6 +1254,9 @@
 
 /***********************************************************************
  *           GetTaskDS   (KERNEL.155)
+ *
+ * Note: this function apparently returns a DWORD with LOWORD == HIWORD.
+ * I don't think we need to bother with this.
  */
 HINSTANCE16 GetTaskDS(void)
 {
@@ -1246,6 +1281,47 @@
 
 
 /***********************************************************************
+ *           SetTaskSignalProc   (KERNEL.38)
+ */
+FARPROC16 SetTaskSignalProc( HTASK16 hTask, FARPROC16 proc )
+{
+    TDB *pTask;
+    FARPROC16 oldProc;
+
+    if (!hTask) hTask = hCurrentTask;
+    if (!(pTask = (TDB *)GlobalLock16( hTask ))) return NULL;
+    oldProc = pTask->userhandler;
+    pTask->userhandler = proc;
+    return oldProc;
+}
+
+
+/***********************************************************************
+ *           SetSigHandler   (KERNEL.140)
+ */
+WORD SetSigHandler( FARPROC16 newhandler, FARPROC16* oldhandler,
+                    UINT16 *oldmode, UINT16 newmode, UINT16 flag )
+{
+    fprintf(stdnimp,"SetSigHandler(%p,%p,%p,%d,%d), unimplemented.\n",
+            newhandler,oldhandler,oldmode,newmode,flag );
+
+    if (flag != 1) return 0;
+    if (!newmode) newhandler = NULL;  /* Default handler */
+    if (newmode != 4)
+    {
+        TDB *pTask;
+
+        if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return 0;
+        if (oldmode) *oldmode = pTask->signal_flags;
+        pTask->signal_flags = newmode;
+        if (oldhandler) *oldhandler = pTask->sighandler;
+        pTask->sighandler = newhandler;
+    }
+    return 0;
+}
+
+
+/***********************************************************************
  *           GetExePtr   (KERNEL.133)
  */
 HMODULE16 GetExePtr( HANDLE16 handle )
@@ -1349,15 +1425,3 @@
     if (GlobalSize16(hTask) < sizeof(TDB)) return 0;
     return pTask->compat_flags;
 }
-
-
-/***********************************************************************
- *           SetSigHandler   (KERNEL.140)
- */
-WORD SetSigHandler( SEGPTR newhandler,SEGPTR* oldhandler,
-                    LPUINT16 *oldmode,UINT16 newmode,UINT16 flag )
-{
-    fprintf(stdnimp,"SetSigHandler(%lx,%p,%p,%d,%d), unimplemented.\n",
-            newhandler,oldhandler,oldmode,newmode,flag );
-    return 0;
-}