Release 950606

Tue Jun  6 12:11:41 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [controls/menu.c]
	Fixed bug with drawing multi-column menus with vertical separator.

	* [debugger/debug.l]
	Fixed NULL-pointer reference after readline().

	* [if1632/winprocs.spec] [miscemu/int21.c] [miscemu/interrupts.c]
	Added interrupt vector emulation. Allows to retrieve an interrupt
	vector and jump to it without crashing.

	* [loader/ldt.c]
	Moved ldt.c to memory directory.

	* [loader/task.c]
	Implemented LockCurrentTask() and GetInstanceData().

	* [objects/bitblt.c]
	Fixed a bug that caused StretchBlt() to use wrong colors when
	stretching a monochrome bitmap to a color display.

	* [objects/bitmap.c]
	Fixed a segmented pointer bug in CreateBitmapIndirect().

	* [tools/build.c]
	Added possibility to have arguments for register functions; used
	by interrupt vectors to remove the flags from the stack.
	Generate a new function CallTo32_LargeStack(), that allows calling
	a 32-bit function using the original 32-bit stack, for functions
	that need more that 64k of stack.

Tue May 30 10:29:56 1995  Martin von Loewis  <martin@informatik.hu-berlin.de>

	* [if1632/shell.spec] [misc/shell.c]
	DoEnvironmentSubst: fixed prototype

	* [if1632/gdi.spec] [objects/palette.c]
	SetSystemPaletteUse: new function

	* [if1632/kernel.spec] [loader/resource.c]
	DirectResAlloc: new function

	* [if1632/user.spec] [windows/keyboard.c]
	SetKeyboardState: new function

Mon May 29 12:58:28 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
	* [tools/build.c]
        Prevent interrupts from destroying the args for a 32 bit function
        by loading the correct value into %esp directly after %ss.

	* [loader/ne_image.c] [loader/module.c]
	The new instance must be created earlier in LoadModule(), so that
	fixups referencing it will be handled correctly.
        Initialize the local heap for a DGROUP in NE_LoadSegment().
	
	* [objects/dib.c]
	Like RLE8 bitmaps, RLE4 bitmaps don't always end with a proper code.
	This used to crash Wine. Fixed.

        * [objects/text.c]
	Fix possible null pointer dereference in debugging output.
	
	* [misc/commdlg.c]
	Handle user input in the edit control better. Some bugs fixed.
	
	* [memory/local.c]
	Started implementing moveable blocks. This is unfinished (!), but
	at least it does not seem to break things.

Wed May 24 13:26:36 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
	* [loader/module.c]
	LoadModule(): DLLs occasionally have a data segment, and they work
	much better if it is loaded :-)
	LoadLibrary(): pass HMODULE instead of HINSTANCE to NE_InitializeDLLs.
	FindModule(): also strip off the last backslash of the pathnames
	(Winhelp tried to load C:\WINDOWS\SYSTEM\COMMDLG.DLL).
	GetModuleHandle(): just call MODULE_FindModule, it does the same job,
	only better.
	
	* [loader/ne_image.c]
	LocalInit() the heap of a DLL in NE_InitDLL. (This is probably
	not really correct, it seems that all programs and DLLs try to do
	this themselves. But they pass weird parameters.)
	NE_InitializeDLLs should also call NE_InitDLL for the passed hModule.
	
	* [loader/task.c] [misc/user.c]
	Finish global initializations in InitTask instead of InitApp, or
	all the DLLs will be initialized in InitTask without any available
	window classes!
diff --git a/objects/bitblt.c b/objects/bitblt.c
index 6822f53..f5037b0 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -9,6 +9,7 @@
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 #include "bitmap.h"
+#include "callback.h"
 #include "color.h"
 #include "dc.h"
 #include "metafile.h"
@@ -581,7 +582,7 @@
     register short i;
 
     pdata += swap ? start+width-1 : start;
-    if (image->depth == depthDst)
+    if (image->depth == depthDst)  /* color -> color */
     {
         if (COLOR_PixelToPalette && (depthDst != 1))
             if (swap) for (i = 0; i < width; i++)
@@ -596,16 +597,25 @@
     }
     else
     {
-        if (image->depth == 1)
+        if (image->depth == 1)  /* monochrome -> color */
+        {
+            if (COLOR_PixelToPalette)
+            {
+                fg = COLOR_PixelToPalette[fg];
+                bg = COLOR_PixelToPalette[bg];
+            }
             if (swap) for (i = 0; i < width; i++)
                 *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
             else for (i = 0; i < width; i++)
                 *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
-        else
+        }
+        else  /* color -> monochrome */
+        {
             if (swap) for (i = 0; i < width; i++)
                 *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
             else for (i = 0; i < width; i++)
                 *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
+        }
     }
 }
 
@@ -1203,8 +1213,9 @@
     dprintf_bitblt(stddeb, "PatBlt: %d %d,%d %dx%d %06lx\n",
 	    hdc, left, top, width, height, rop );
 
-    return BITBLT_InternalStretchBlt( dc, left, top, width, height,
-                                      NULL, 0, 0, 0, 0, rop );
+    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
+                                 dc, left, top, width, height,
+                                 NULL, 0, 0, 0, 0, rop );
 }
 
 
@@ -1231,8 +1242,9 @@
                 hdcDst, xDst, yDst, width, height, dcDst->w.bitsPerPixel, rop);
     dprintf_bitblt(stddeb,"        src org=%d,%d  dst org=%d,%d\n",
                 dcSrc->w.DCOrgX, dcSrc->w.DCOrgY, dcDst->w.DCOrgX, dcDst->w.DCOrgY );
-    return BITBLT_InternalStretchBlt( dcDst, xDst, yDst, width, height,
-                                      dcSrc, xSrc, ySrc, width, height, rop );
+    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
+                                dcDst, xDst, yDst, width, height,
+                                dcSrc, xSrc, ySrc, width, height, rop );
 }
 
 
@@ -1261,7 +1273,7 @@
                    dcSrc ? dcSrc->w.bitsPerPixel : 0, hdcDst, xDst, yDst,
                    widthDst, heightDst, dcDst->w.bitsPerPixel, rop );
 
-    return BITBLT_InternalStretchBlt( dcDst, xDst, yDst, widthDst, heightDst,
-                                      dcSrc, xSrc, ySrc, widthSrc, heightSrc,
-                                      rop );
+    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
+                                dcDst, xDst, yDst, widthDst, heightDst,
+                                dcSrc, xSrc, ySrc, widthSrc, heightSrc, rop );
 }
diff --git a/objects/bitmap.c b/objects/bitmap.c
index e394ccb..e0f15c4 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -2,15 +2,14 @@
  * GDI bitmap objects
  *
  * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "gdi.h"
 #include "arch.h"
+#include "callback.h"
 #include "dc.h"
 #include "bitmap.h"
 #include "prototypes.h"
@@ -81,10 +80,43 @@
 HBITMAP CreateBitmap( short width, short height, 
 		      BYTE planes, BYTE bpp, LPSTR bits )
 {
-    BITMAP bitmap = { 0, width, height, 0, planes, bpp, bits };
-    dprintf_gdi(stddeb, "CreateBitmap: %dx%d, %d colors\n", 
-	     width, height, 1 << (planes*bpp) );
-    return CreateBitmapIndirect( &bitmap );
+    BITMAPOBJ * bmpObjPtr;
+    HBITMAP hbitmap;
+
+    dprintf_gdi( stddeb, "CreateBitmap: %dx%d, %d colors\n", 
+                 width, height, 1 << (planes*bpp) );
+
+      /* Check parameters */
+    if (!height || !width || planes != 1) return 0;
+    if ((bpp != 1) && (bpp != screenDepth)) return 0;
+    if (height < 0) height = -height;
+    if (width < 0) width = -width;
+
+      /* Create the BITMAPOBJ */
+    hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
+    if (!hbitmap) return 0;
+    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
+
+    bmpObjPtr->size.cx = 0;
+    bmpObjPtr->size.cy = 0;
+    bmpObjPtr->bitmap.bmType = 0;
+    bmpObjPtr->bitmap.bmWidth = width;
+    bmpObjPtr->bitmap.bmHeight = height;
+    bmpObjPtr->bitmap.bmPlanes = planes;
+    bmpObjPtr->bitmap.bmBitsPixel = bpp;
+    bmpObjPtr->bitmap.bmWidthBytes = (width * bpp + 15) / 16 * 2;
+    bmpObjPtr->bitmap.bmBits = NULL;
+
+      /* Create the pixmap */
+    bmpObjPtr->pixmap = XCreatePixmap(display, rootWindow, width, height, bpp);
+    if (!bmpObjPtr->pixmap)
+    {
+	GDI_HEAP_FREE( hbitmap );
+	hbitmap = 0;
+    }
+    else if (bits)  /* Set bitmap bits */
+	SetBitmapBits( hbitmap, height * bmpObjPtr->bitmap.bmWidthBytes, bits);
+    return hbitmap;
 }
 
 
@@ -106,43 +138,8 @@
  */
 HBITMAP CreateBitmapIndirect( BITMAP * bmp )
 {
-    BITMAPOBJ * bmpObjPtr;
-    HBITMAP hbitmap;
-
-      /* Check parameters */
-    if (!bmp->bmHeight || !bmp->bmWidth) return 0;
-    if (bmp->bmPlanes != 1) return 0;
-    if ((bmp->bmBitsPixel != 1) && (bmp->bmBitsPixel != screenDepth)) return 0;
-
-    if (bmp->bmHeight < 0)
-	bmp->bmHeight = -bmp->bmHeight;
-    
-    if (bmp->bmWidth < 0)
-	bmp->bmWidth = -bmp->bmWidth;
-    
-
-      /* Create the BITMAPOBJ */
-    hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
-    if (!hbitmap) return 0;
-    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
-
-    bmpObjPtr->size.cx = 0;
-    bmpObjPtr->size.cy = 0;
-    bmpObjPtr->bitmap  = *bmp;
-    bmpObjPtr->bitmap.bmBits = NULL;
-    bmpObjPtr->bitmap.bmWidthBytes = (bmp->bmWidth*bmp->bmBitsPixel+15)/16 * 2;
-
-      /* Create the pixmap */
-    bmpObjPtr->pixmap = XCreatePixmap( display, rootWindow, bmp->bmWidth,
-				       bmp->bmHeight, bmp->bmBitsPixel );
-    if (!bmpObjPtr->pixmap)
-    {
-	GDI_HEAP_FREE( hbitmap );
-	hbitmap = 0;
-    }
-    else if (bmp->bmBits)  /* Set bitmap bits */
-	SetBitmapBits( hbitmap, bmpObjPtr->bitmap.bmHeight*bmpObjPtr->bitmap.bmWidthBytes, bmp->bmBits );
-    return hbitmap;
+    return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
+                         bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
 }
 
 
@@ -167,8 +164,9 @@
     if (!height) return 0;
     
     if (!(image = BITMAP_BmpToImage( &bmp->bitmap, buffer ))) return 0;
-    XGetSubImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth, height,
-		  AllPlanes, ZPixmap, image, 0, 0 );
+    CallTo32_LargeStack( (int(*)())XGetSubImage, 11,
+                         display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
+                         height, AllPlanes, ZPixmap, image, 0, 0 );
     image->data = NULL;
     XDestroyImage( image );
     return height * bmp->bitmap.bmWidthBytes;
@@ -197,8 +195,9 @@
     if (!height) return 0;
     	
     if (!(image = BITMAP_BmpToImage( &bmp->bitmap, buffer ))) return 0;
-    XPutImage( display, bmp->pixmap, BITMAP_GC(bmp), image, 0, 0,
-	       0, 0, bmp->bitmap.bmWidth, height );
+    CallTo32_LargeStack( XPutImage, 10,
+                         display, bmp->pixmap, BITMAP_GC(bmp), image, 0, 0,
+                         0, 0, bmp->bitmap.bmWidth, height );
     image->data = NULL;
     XDestroyImage( image );
     return height * bmp->bitmap.bmWidthBytes;
diff --git a/objects/dib.c b/objects/dib.c
index b8d7313..f55c44f 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -10,6 +10,7 @@
 #include <X11/Xutil.h>
 #include "dc.h"
 #include "bitmap.h"
+#include "callback.h"
 #include "palette.h"
 #include "icon.h"
 #include "stackframe.h"
@@ -172,9 +173,10 @@
 {
 	int x = 0, c, length;
 	BYTE *begin = bits;
-	
-	lines--;
-	while (1) {
+
+        lines--;
+	while ((INT)lines >= 0)
+        {
 		length = *bits++;
 		if (length) {	/* encoded */
 			c = *bits++;
@@ -562,9 +564,11 @@
     if (startscan+lines > info->bmiHeader.biHeight)
 	lines = info->bmiHeader.biHeight - startscan;
 
-    return DIB_SetImageBits( dc, lines, bmp->bitmap.bmBitsPixel,
-			     bits, info, coloruse, bmp->pixmap, BITMAP_GC(bmp),
-			     0, 0, 0, startscan, bmp->bitmap.bmWidth, lines );
+    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 14,
+                                dc, lines, bmp->bitmap.bmBitsPixel,
+                                bits, info, coloruse, bmp->pixmap,
+                                BITMAP_GC(bmp), 0, 0, 0, startscan,
+                                bmp->bitmap.bmWidth, lines );
 }
 
 
@@ -592,13 +596,13 @@
 
     DC_SetupGCForText( dc );  /* To have the correct colors */
     XSetFunction( display, dc->u.x.gc, DC_XROPfunction[dc->w.ROPmode-1] );
-    return DIB_SetImageBits( dc, lines, dc->w.bitsPerPixel,
-			     bits, info, coloruse,
-			     dc->u.x.drawable, dc->u.x.gc,
-			     xSrc, ySrc - startscan,
-			     dc->w.DCOrgX + XLPTODP( dc, xDest ),
-			     dc->w.DCOrgY + YLPTODP( dc, yDest ),
-			     cx, cy );
+    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 14,
+                                dc, lines, dc->w.bitsPerPixel, bits, info,
+                                coloruse, dc->u.x.drawable, dc->u.x.gc,
+                                xSrc, ySrc - startscan,
+                                dc->w.DCOrgX + XLPTODP( dc, xDest ),
+                                dc->w.DCOrgY + YLPTODP( dc, yDest ),
+                                cx, cy );
 }
 
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index c34a379..2cfcd75 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -2,9 +2,7 @@
  * GDI functions
  *
  * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/objects/palette.c b/objects/palette.c
index 80b64c4..dd925ce 100644
--- a/objects/palette.c
+++ b/objects/palette.c
@@ -21,6 +21,8 @@
 /* #define DEBUG_PALETTE */
 #include "debug.h"
 
+static WORD SystemPaletteUse = SYSPAL_STATIC;	/* currently not considered */
+
 /***********************************************************************
  *           CreatePalette    (GDI.360)
  */
@@ -80,13 +82,26 @@
 
 
 /***********************************************************************
+ *           SetSystemPaletteUse    (GDI.373)
+ *	Should this be per DC rather than system wide?
+ *  Currently, it does not matter as the use is only set and returned,
+ *  but not taken into account
+ */
+WORD SetSystemPaletteUse( HDC hdc, WORD use)
+{
+	 WORD old=SystemPaletteUse;
+	 printf("SetSystemPaletteUse(%04X,%04X) // empty stub !!!\n", hdc, use);
+	 SystemPaletteUse=use;
+	 return old;
+}
+
+/***********************************************************************
  *           GetSystemPaletteUse    (GDI.374)
  */
 WORD GetSystemPaletteUse( HDC hdc )
 {
 	printf("GetSystemPaletteUse(%04X) // empty stub !!!\n", hdc);
-	/* Assuming there is remaining system colors ... */
-	return SYSPAL_STATIC;
+	return SystemPaletteUse;
 }
 
 
diff --git a/objects/text.c b/objects/text.c
index 9e3347c..52673fe 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -302,9 +302,12 @@
     if (!DC_SetupGCForText( dc )) return TRUE;
     font = dc->u.x.font.fstruct;
 
-    dprintf_text(stddeb,"ExtTextOut: %d,%d '%*.*s', %d  flags=%d rect=%d,%d,%d,%d\n",
-            x, y, count, count, str, count, flags,
-            lprect->left, lprect->top, lprect->right, lprect->bottom );
+    dprintf_text(stddeb,"ExtTextOut: %d,%d '%*.*s', %d  flags=%d\n",
+            x, y, count, count, str, count, flags);
+    if (lprect != NULL) {
+      dprintf_text(stddeb, "rect %d %d %d %d\n",
+		   lprect->left, lprect->top, lprect->right, lprect->bottom );
+    }
 
       /* Setup coordinates */