Release 960506

Mon May  6 12:56:26 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [DEVELOPERS-HINTS]
	Added paragraph on naming conventions for Win16/Win32/Winelib.

	* [controls/menu.c]
	Create a default system menu that is the same for all windows
	instead of making a copy every time.

	* [include/wintypes.h]
	Added WINELIB_NAME and DECL_WINELIB_TYPE macros.
	Added xx16 and xx32 definitions for most types. General clean-up.

	* [memory/global.c] [memory/local.c] [*/*]
	Renamed Global and Local heap functions to xxx16. Added all xxx32
	versions of the same functions.

	* [memory/selector.c]
	Mask out lower bits of selector in FreeSelector().

	* [misc/lstr.c]
	Fixed wvsprintf().

	* [windows/class.c]
	Changed the class structure to make Win32 support easier.

	* [windows/defwnd.c]
	Added handling of WM_INITMENUPOPUP for system menu to gray out
	invalid options.

	* [windows/winpos.c]
	Bug fix: the WINDOSPOS structure pointer in WM_NCCALCSIZE must be
	a SEGPTR.

Sun May  5 03:51:26 1996  Huw D. M. Davies <h.davies1@physics.oxford.ac.uk>

	* [memory/local.c]
	Implementation of moveable and (rudimentary) support for
 	discardable local memory, plus several bug fixes.

Sat May  4 18:33:35 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [include/windows.h] [windows/win.c] [if1632/user.spec] 
	FindWindowEx() implemented (someone reported it was missing
	for FrameMaker 4.1).

	* [if1632/kernel32.spec] [if1632/user32.spec] [win32/memory.c]
	  [win32/resource.c]
	Misc small stubs/small functions which bring win95 binaries
	further down the road. (IsBadCodePtr, LocalReAlloc,GetCursorPos)
	Small fix in WIN32_LoadAcceleratorsA.

Fri May  3 19:43:12 1996  Frans van Dorsselaer <dorssel@rulhm1.LeidenUniv.nl>

	* [controls/edit.c] [controls/EDIT.TODO]
	Changed / fixed some types and typecasts.
	Fixed the scrollbar reset after WM_SETHANDLE / WM_SETTEXT.
	Added heap initialization in WM_CREATE.

Fri May  3 19:30:02 1996  Greg Kreider <kreider@natlab.research.philips.com>

	* [controls/combo.c] [controls/listbox.c]
	Pass WM_[HV]SCROLL to listbox, but not combo.
	Don't try to redraw non-existant scroll bars (changes dwStyle flags).
	Combo box gets border.
	Combo box includes button (otherwise button won't trigger dropdown).
	Proper border around RectButton.
	Check size consistancy of combo, listbox, and button after resizing 
	or before painting.  These routines still aren't completely correct.
	Localize size checks in separate routines.
	Listboxes are white.

Thu May  2 19:21:23 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [controls/combo.c][include/commdlg.h][include/commdlg.c]
	  [resources/sysres_De.rc][resources/sysres_En.rc]
	Introduced ChooseFont dialog, but needed some patches in 
	handling of comboboxes with edit controls.

Tue Apr 30 00:33:27 1996  Ulrich Schmid  <uschmid@mail.hh.provi.de>

	* [programs/winhelp/*]
	Added a help viewer and a simple `.hlp' to `.sgml' converter.

Mon Apr 29 14:17:57 1996  Tristan Tarrant <tst@sthinc.demon.co.uk>

	* [resources/sysres_*.rc] [misc/shell.c]
	Modified size of "About" dialog boxes.

Sat Apr 27 18:10:11 Martin von Loewis <loewis@informatik.hu-berlin.de>

	* [if1632/Makefile.in][loader/builtin.c]
	crtdll.spec, ntdll.spec, wsock32.spec: new files.

	* [loader/pe_image.c]
	Fix error message if import by ordinal failed.
diff --git a/windows/class.c b/windows/class.c
index 1a97140..c05eb39 100644
--- a/windows/class.c
+++ b/windows/class.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "class.h"
+#include "heap.h"
 #include "user.h"
 #include "win.h"
 #include "dce.h"
@@ -31,8 +32,7 @@
     char className[80];
     int i;
 
-    if (((CLASS *)USER_HEAP_LIN_ADDR(ptr->self) != ptr) ||
-        (ptr->wMagic != CLASS_MAGIC))
+    if (ptr->magic != CLASS_MAGIC)
     {
         fprintf( stderr, "%p is not a class\n", ptr );
         return;
@@ -42,17 +42,17 @@
 
     fprintf( stderr, "Class %p:\n", ptr );
     fprintf( stderr,
-             "next=%p  name=%04x '%s'  style=%04x  wndProc=%08lx\n"
+             "next=%p  name=%04x '%s'  style=%08x  wndProc=%08lx\n"
              "inst=%04x  hdce=%04x  icon=%04x  cursor=%04x  bkgnd=%04x\n"
              "clsExtra=%d  winExtra=%d  #windows=%d\n",
-             ptr->next, ptr->atomName, className, ptr->wc.style,
-             (DWORD)ptr->wc.lpfnWndProc, ptr->wc.hInstance, ptr->hdce,
-             ptr->wc.hIcon, ptr->wc.hCursor, ptr->wc.hbrBackground,
-             ptr->wc.cbClsExtra, ptr->wc.cbWndExtra, ptr->cWindows );
-    if (ptr->wc.cbClsExtra)
+             ptr->next, ptr->atomName, className, ptr->style,
+             (DWORD)ptr->lpfnWndProc, ptr->hInstance, ptr->hdce,
+             ptr->hIcon, ptr->hCursor, ptr->hbrBackground,
+             ptr->cbClsExtra, ptr->cbWndExtra, ptr->cWindows );
+    if (ptr->cbClsExtra)
     {
         fprintf( stderr, "extra bytes:" );
-        for (i = 0; i < ptr->wc.cbClsExtra; i++)
+        for (i = 0; i < ptr->cbClsExtra; i++)
             fprintf( stderr, " %02x", *((BYTE *)ptr->wExtra+i) );
         fprintf( stderr, "\n" );
     }
@@ -70,12 +70,12 @@
     CLASS *ptr;
     char className[80];
 
-    fprintf( stderr, " Class   Name                Style WndProc\n" );
+    fprintf( stderr, " Class   Name                 Style   WndProc\n" );
     for (ptr = firstClass; ptr; ptr = ptr->next)
     {
         GlobalGetAtomName( ptr->atomName, className, sizeof(className) );
-        fprintf( stderr, "%08lx %-20.20s %04x %08lx\n", (DWORD)ptr, className,
-                 ptr->wc.style, (DWORD)ptr->wc.lpfnWndProc );
+        fprintf( stderr, "%08lx %-20.20s %08x %08lx\n", (DWORD)ptr, className,
+                 ptr->style, (DWORD)ptr->lpfnWndProc );
     }
     fprintf( stderr, "\n" );
 }
@@ -104,11 +104,11 @@
     /* Delete the class */
 
     if (classPtr->hdce) DCE_FreeDCE( classPtr->hdce );
-    if (classPtr->wc.hbrBackground) DeleteObject( classPtr->wc.hbrBackground );
+    if (classPtr->hbrBackground) DeleteObject( classPtr->hbrBackground );
     GlobalDeleteAtom( classPtr->atomName );
-    if (HIWORD(classPtr->wc.lpszMenuName))
-	USER_HEAP_FREE( (HANDLE)classPtr->wc.lpszMenuName );
-    USER_HEAP_FREE( classPtr->self );
+    if (HIWORD(classPtr->lpszMenuName))
+	USER_HEAP_FREE( (HANDLE)classPtr->lpszMenuName );
+    HeapFree( SystemHeap, 0, classPtr );
 }
 
 
@@ -122,12 +122,43 @@
     for (ptr = firstClass; ptr; ptr = next)
     {
         next = ptr->next;
-	if (ptr->wc.hInstance == hModule) CLASS_FreeClass( ptr );
+	if (ptr->hInstance == hModule) CLASS_FreeClass( ptr );
     }
 }
 
 
 /***********************************************************************
+ *           CLASS_FindClassByAtom
+ *
+ * Return a pointer to the class.
+ */
+CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE16 hinstance )
+{
+    CLASS * class;
+
+      /* First search task-specific classes */
+
+    for (class = firstClass; (class); class = class->next)
+    {
+        if (class->style & CS_GLOBALCLASS) continue;
+        if ((class->atomName == atom) && 
+            ((hinstance==(HINSTANCE16)0xffff) ||
+             (hinstance == class->hInstance))) return class;
+    }
+    
+      /* Then search global classes */
+
+    for (class = firstClass; (class); class = class->next)
+    {
+        if (!(class->style & CS_GLOBALCLASS)) continue;
+        if (class->atomName == atom) return class;
+    }
+
+    return 0;
+}
+
+
+/***********************************************************************
  *           CLASS_FindClassByName
  *
  * Return a pointer to the class.
@@ -135,93 +166,76 @@
 CLASS *CLASS_FindClassByName( SEGPTR name, HINSTANCE hinstance )
 {
     ATOM atom;
-    CLASS * class;
 
     if (!(atom = GlobalFindAtom( name ))) return 0;
-
-      /* First search task-specific classes */
-
-    for (class = firstClass; (class); class = class->next)
-    {
-        if (class->wc.style & CS_GLOBALCLASS) continue;
-        if ((class->atomName == atom) && 
-            ((hinstance==(HINSTANCE)0xffff) ||
-             (hinstance == class->wc.hInstance))) return class;
-    }
-    
-      /* Then search global classes */
-
-    for (class = firstClass; (class); class = class->next)
-    {
-        if (!(class->wc.style & CS_GLOBALCLASS)) continue;
-        if (class->atomName == atom) return class;
-    }
-
-    return 0;
+    return CLASS_FindClassByAtom( atom, hinstance );
 }
 
 
 /***********************************************************************
- *           RegisterClass    (USER.57)
+ *           RegisterClass16    (USER.57)
  */
-ATOM RegisterClass( LPWNDCLASS class )
+ATOM RegisterClass16( const WNDCLASS16 *wc )
 {
     CLASS * newClass, * prevClass;
-    HCLASS handle;
+    HANDLE16 hInstance;
     int classExtra;
 
     dprintf_class( stddeb, "RegisterClass: wndproc=%08lx hinst=%04x name='%s' background %04x\n",
-                 (DWORD)class->lpfnWndProc, class->hInstance,
-                 HIWORD(class->lpszClassName) ?
-                  (char *)PTR_SEG_TO_LIN(class->lpszClassName) : "(int)",
-                 class->hbrBackground );
+                 (DWORD)wc->lpfnWndProc, wc->hInstance,
+                 HIWORD(wc->lpszClassName) ?
+                  (char *)PTR_SEG_TO_LIN(wc->lpszClassName) : "(int)",
+                 wc->hbrBackground );
     dprintf_class(stddeb,"               style=%04x clsExtra=%d winExtra=%d\n",
-                  class->style, class->cbClsExtra, class->cbWndExtra );
+                  wc->style, wc->cbClsExtra, wc->cbWndExtra );
     
       /* Window classes are owned by modules, not instances */
-    class->hInstance = GetExePtr( class->hInstance );
+    hInstance = GetExePtr( wc->hInstance );
     
       /* Check if a class with this name already exists */
-    prevClass = CLASS_FindClassByName( class->lpszClassName, class->hInstance);
+    prevClass = CLASS_FindClassByName( wc->lpszClassName, hInstance );
     if (prevClass)
     {
 	  /* Class can be created only if it is local and */
 	  /* if the class with the same name is global.   */
 
-	if (class->style & CS_GLOBALCLASS) return 0;
-	if (!(prevClass->wc.style & CS_GLOBALCLASS)) return 0;
+	if (wc->style & CS_GLOBALCLASS) return 0;
+	if (!(prevClass->style & CS_GLOBALCLASS)) return 0;
     }
 
       /* Create class */
 
-    classExtra = (class->cbClsExtra < 0) ? 0 : class->cbClsExtra;
-    handle = USER_HEAP_ALLOC( sizeof(CLASS) + classExtra );
-    if (!handle) return 0;
-    newClass = (CLASS *) USER_HEAP_LIN_ADDR( handle );
-    newClass->self          = handle;
+    classExtra = (wc->cbClsExtra < 0) ? 0 : wc->cbClsExtra;
+    newClass = (CLASS *)HeapAlloc( SystemHeap, 0, sizeof(CLASS) + classExtra );
+    if (!newClass) return 0;
     newClass->next          = firstClass;
-    newClass->wMagic        = CLASS_MAGIC;
+    newClass->magic         = CLASS_MAGIC;
     newClass->cWindows      = 0;  
-    newClass->wc            = *class;
-    newClass->wc.cbWndExtra = (class->cbWndExtra < 0) ? 0 : class->cbWndExtra;
-    newClass->wc.cbClsExtra = classExtra;
+    newClass->style         = wc->style;
+    newClass->lpfnWndProc   = wc->lpfnWndProc;
+    newClass->cbWndExtra    = (wc->cbWndExtra < 0) ? 0 : wc->cbWndExtra;
+    newClass->cbClsExtra    = classExtra;
+    newClass->lpszMenuName  = wc->lpszMenuName;
+    newClass->hInstance     = hInstance;
+    newClass->hIcon         = wc->hIcon;
+    newClass->hCursor       = wc->hCursor;
+    newClass->hbrBackground = wc->hbrBackground;
 
-    newClass->atomName = GlobalAddAtom( class->lpszClassName );
-    newClass->wc.lpszClassName = 0;
+    newClass->atomName = GlobalAddAtom( wc->lpszClassName );
 
-    if (newClass->wc.style & CS_CLASSDC)
+    if (newClass->style & CS_CLASSDC)
 	newClass->hdce = DCE_AllocDCE( DCE_CLASS_DC );
     else newClass->hdce = 0;
 
       /* Make a copy of the menu name (only if it is a string) */
 
-    if (HIWORD(class->lpszMenuName))
+    if (HIWORD(wc->lpszMenuName))
     {
-        char *menuname = PTR_SEG_TO_LIN( class->lpszMenuName );
+        char *menuname = PTR_SEG_TO_LIN( wc->lpszMenuName );
 	HANDLE hname = USER_HEAP_ALLOC( strlen(menuname)+1 );
 	if (hname)
 	{
-	    newClass->wc.lpszMenuName = (SEGPTR)USER_HEAP_SEG_ADDR( hname );
+	    newClass->lpszMenuName = (SEGPTR)USER_HEAP_SEG_ADDR( hname );
 	    strcpy( USER_HEAP_LIN_ADDR( hname ), menuname );
 	}
     }
@@ -233,9 +247,57 @@
 
 
 /***********************************************************************
- *           UnregisterClass    (USER.403)
+ *           RegisterClass32A      (USER32.426)
  */
-BOOL UnregisterClass( SEGPTR className, HANDLE hinstance )
+ATOM RegisterClass32A( const WNDCLASS32A* wc )
+{
+    WNDCLASS16 copy;
+    HANDLE classh = 0, menuh = 0;
+    SEGPTR classsegp, menusegp;
+    char *classbuf, *menubuf;
+
+    ATOM retval;
+    copy.style=wc->style;
+    ALIAS_RegisterAlias(0,0,(DWORD)wc->lpfnWndProc);
+    copy.lpfnWndProc=wc->lpfnWndProc;
+    copy.cbClsExtra=wc->cbClsExtra;
+    copy.cbWndExtra=wc->cbWndExtra;
+    copy.hInstance=(HINSTANCE)wc->hInstance;
+    copy.hIcon=(HICON)wc->hIcon;
+    copy.hCursor=(HCURSOR)wc->hCursor;
+    copy.hbrBackground=(HBRUSH)wc->hbrBackground;
+    
+    /* FIXME: There has to be a better way of doing this - but neither
+       malloc nor alloca will work */
+
+    if(wc->lpszMenuName)
+    {
+        menuh = GlobalAlloc16(0, strlen(wc->lpszMenuName)+1);
+        menusegp = WIN16_GlobalLock16(menuh);
+        menubuf = PTR_SEG_TO_LIN(menusegp);
+        strcpy( menubuf, wc->lpszMenuName);
+        copy.lpszMenuName=menusegp;
+    }else
+        copy.lpszMenuName=0;
+    if(wc->lpszClassName)
+    {
+        classh = GlobalAlloc16(0, strlen(wc->lpszClassName)+1);
+        classsegp = WIN16_GlobalLock16(classh);
+        classbuf = PTR_SEG_TO_LIN(classsegp);
+        strcpy( classbuf, wc->lpszClassName);
+        copy.lpszClassName=classsegp;
+    }
+    retval = RegisterClass16(&copy);
+    GlobalFree16(menuh);
+    GlobalFree16(classh);
+    return retval;
+}
+
+
+/***********************************************************************
+ *           UnregisterClass16    (USER.403)
+ */
+BOOL UnregisterClass16( SEGPTR className, HINSTANCE16 hinstance )
 {
     CLASS *classPtr;
 
@@ -244,7 +306,7 @@
       /* Check if we can remove this class */
     if (!(classPtr = CLASS_FindClassByName( className, hinstance )))
         return FALSE;
-    if ((classPtr->wc.hInstance != hinstance) || (classPtr->cWindows > 0))
+    if ((classPtr->hInstance != hinstance) || (classPtr->cWindows > 0))
 	return FALSE;
     CLASS_FreeClass( classPtr );
     return TRUE;
@@ -263,14 +325,15 @@
         return *(WORD *)(((char *)wndPtr->class->wExtra) + offset);
     switch(offset)
     {
-        case GCW_HBRBACKGROUND: return wndPtr->class->wc.hbrBackground;
-        case GCW_HCURSOR:       return wndPtr->class->wc.hCursor;
-        case GCW_HICON:         return wndPtr->class->wc.hIcon;
-        case GCW_HMODULE:       return wndPtr->class->wc.hInstance;
-        case GCW_CBWNDEXTRA:    return wndPtr->class->wc.cbWndExtra;
-        case GCW_CBCLSEXTRA:    return wndPtr->class->wc.cbClsExtra;
-        case GCW_STYLE:         return wndPtr->class->wc.style;
+        case GCW_HBRBACKGROUND: return wndPtr->class->hbrBackground;
+        case GCW_HCURSOR:       return wndPtr->class->hCursor;
+        case GCW_HICON:         return wndPtr->class->hIcon;
+        case GCW_HMODULE:       return wndPtr->class->hInstance;
         case GCW_ATOM:          return wndPtr->class->atomName;
+        case GCW_STYLE:
+        case GCW_CBWNDEXTRA:
+        case GCW_CBCLSEXTRA:
+            return (WORD)GetClassLong( hwnd, offset );
     }
     fprintf(stderr, "Warning: invalid offset %d for GetClassWord()\n", offset);
     return 0;
@@ -289,14 +352,15 @@
     if (offset >= 0) ptr = (WORD *)(((char *)wndPtr->class->wExtra) + offset);
     else switch(offset)
     {
-        case GCW_HBRBACKGROUND: ptr = &wndPtr->class->wc.hbrBackground; break;
-        case GCW_HCURSOR:       ptr = &wndPtr->class->wc.hCursor; break;
-        case GCW_HICON:         ptr = &wndPtr->class->wc.hIcon; break;
-        case GCW_HMODULE:       ptr = &wndPtr->class->wc.hInstance; break;
-        case GCW_CBWNDEXTRA:    ptr = &wndPtr->class->wc.cbWndExtra; break;
-        case GCW_CBCLSEXTRA:    ptr = &wndPtr->class->wc.cbClsExtra; break;
-        case GCW_STYLE:         ptr = &wndPtr->class->wc.style; break;
+        case GCW_HBRBACKGROUND: ptr = &wndPtr->class->hbrBackground; break;
+        case GCW_HCURSOR:       ptr = &wndPtr->class->hCursor; break;
+        case GCW_HICON:         ptr = &wndPtr->class->hIcon; break;
+        case GCW_HMODULE:       ptr = &wndPtr->class->hInstance; break;
         case GCW_ATOM:          ptr = &wndPtr->class->atomName; break;
+        case GCW_STYLE:
+        case GCW_CBWNDEXTRA:
+        case GCW_CBCLSEXTRA:
+            return (WORD)SetClassLong( hwnd, offset, (LONG)newval );
         default:
             fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
                      offset);
@@ -320,8 +384,11 @@
         return *(WORD *)(((char *)wndPtr->class->wExtra) + offset);
     switch(offset)
     {
-        case GCL_MENUNAME: return (LONG)wndPtr->class->wc.lpszMenuName;
-        case GCL_WNDPROC:  return (LONG)wndPtr->class->wc.lpfnWndProc;
+        case GCL_STYLE:      return (LONG)wndPtr->class->style;
+        case GCL_CBWNDEXTRA: return (LONG)wndPtr->class->cbWndExtra;
+        case GCL_CBCLSEXTRA: return (LONG)wndPtr->class->cbClsExtra;
+        case GCL_MENUNAME:   return (LONG)wndPtr->class->lpszMenuName;
+        case GCL_WNDPROC:    return (LONG)wndPtr->class->lpfnWndProc;
     }
     fprintf(stderr, "Warning: invalid offset %d for GetClassLong()\n", offset);
     return 0;
@@ -340,8 +407,11 @@
     if (offset >= 0) ptr = (LONG *)(((char *)wndPtr->class->wExtra) + offset);
     else switch(offset)
     {
-        case GCL_MENUNAME: ptr = (LONG*)&wndPtr->class->wc.lpszMenuName; break;
-        case GCL_WNDPROC:  ptr = (LONG*)&wndPtr->class->wc.lpfnWndProc; break;
+        case GCL_STYLE:      ptr = (LONG*)&wndPtr->class->style; break;
+        case GCL_CBWNDEXTRA: ptr = (LONG*)&wndPtr->class->cbWndExtra; break;
+        case GCL_CBCLSEXTRA: ptr = (LONG*)&wndPtr->class->cbClsExtra; break;
+        case GCL_MENUNAME:   ptr = (LONG*)&wndPtr->class->lpszMenuName; break;
+        case GCL_WNDPROC:    ptr = (LONG*)&wndPtr->class->lpfnWndProc; break;
         default:
             fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
                      offset);
@@ -371,7 +441,7 @@
 /***********************************************************************
  *           GetClassInfo      (USER.404)
  */
-BOOL GetClassInfo( HANDLE hInstance, SEGPTR name, LPWNDCLASS lpWndClass )
+BOOL GetClassInfo( HANDLE hInstance, SEGPTR name, WNDCLASS16 *lpWndClass )
 {
     CLASS *classPtr;
 
@@ -382,9 +452,19 @@
     hInstance = GetExePtr( hInstance );
     
     if (!(classPtr = CLASS_FindClassByName( name, hInstance ))) return FALSE;
-    if (hInstance && (hInstance != classPtr->wc.hInstance)) return FALSE;
+    if (hInstance && (hInstance != classPtr->hInstance)) return FALSE;
 
-    memcpy(lpWndClass, &(classPtr->wc), sizeof(WNDCLASS));
+    lpWndClass->style         = (UINT16)classPtr->style;
+    lpWndClass->lpfnWndProc   = classPtr->lpfnWndProc;
+    lpWndClass->cbClsExtra    = (INT16)classPtr->cbClsExtra;
+    lpWndClass->cbWndExtra    = (INT16)classPtr->cbWndExtra;
+    lpWndClass->hInstance     = classPtr->hInstance;
+    lpWndClass->hIcon         = classPtr->hIcon;
+    lpWndClass->hCursor       = classPtr->hCursor;
+    lpWndClass->hbrBackground = classPtr->hbrBackground;
+    lpWndClass->lpszMenuName  = classPtr->lpszMenuName;
+    lpWndClass->lpszClassName = 0;
+
     return TRUE;
 }
 
@@ -414,7 +494,7 @@
         pClassEntry->wNext = 0;
         return FALSE;
     }
-    pClassEntry->hInst = class->wc.hInstance;
+    pClassEntry->hInst = class->hInstance;
     pClassEntry->wNext++;
     GlobalGetAtomName( class->atomName, pClassEntry->szClassName,
                        sizeof(pClassEntry->szClassName) );