Tue May 17 23:03:16 1994 Bob Amstadt (bob@pooh) * [windows/dce.c] Fixed bug with dce initialization that was causing dialog boxes to not be displayed. * [if1632/callback.c] Better fix for bug found by Martin. Sat May 14 19:48:39 1994 Rick Sladkey (jrs@world.std.com) * [ memory/heap.c ] Redirect HEAP_ReAlloc calls with NULL argument to HEAP_Alloc. May 16, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [objects/font.c] Make EnumFonts() calling a callback with dummy fonts ... :-) * [objects/text.c] Add Empty Stub for ExtTextOut(), which temporarely call Textout(). * [if1632/callback.c] Temporarely go around bug in CallWindowProc(), you will see printfs. * [controls/edit.c] Make EDIT controls focused by a mouse click. * [misc/property.c] Bug Fix in function EnumProps(), better use of CallBack16(). * [misc/mmsystem.c] Basic Skelton's for MCI messages dispatching function. Sun May 15 16:15:17 1994 Erik Bos (erik@hacktic.nl) * [windows/utility.c] Added windows_wsprintf() for the emulator, wsprintf() is for libwine. Sat May 14 22:16:40 1994 Rick Sladkey (jrs@world.std.com) * [misc/cursor.c] Fix pointer problems in LoadCursor leading to heap corruption. * [ controls/menu.c ] Fix two NULL dereferencing bugs. Sun May 15 20:07:48 1994 Rick Sladkey (jrs@world.std.com) * [objects/font.c] Fix NULL pointer dereferencing bug in GetCharWidth. * [loader/resource.c] Fix under-allocation of memory in LoadAccelerators. * [windows/class.c] Ignore negative sizes for extra fields in RegisterClass. Sun May 15 06:35:03 1994 David Metcalfe <david@prism.demon.co.uk> * [objects/metafile.c] [include/metafile.h] [include/windows.h] [objects/gdiobj.c] [objects/brush.c] [objects/pen.c] [objects/text.c] [objects/dcvalues.c] [windows/graphics.c] [windows/dc.c] [windows/mapping.c] Beginnings of metafile support. * [misc/file.c] Corrected spelling of _lcreat. * [controls/edit.c] Minor bug fixes.
286 lines
7.6 KiB
C
286 lines
7.6 KiB
C
/*
|
|
* Window classes functions
|
|
*
|
|
* Copyright 1993 Alexandre Julliard
|
|
*/
|
|
|
|
static char Copyright[] = "Copyright Alexandre Julliard, 1993";
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "class.h"
|
|
#include "user.h"
|
|
#include "win.h"
|
|
#include "dce.h"
|
|
|
|
/* #define DEBUG_CLASS /* */
|
|
|
|
|
|
static HCLASS firstClass = 0;
|
|
|
|
|
|
/***********************************************************************
|
|
* CLASS_FindClassByName
|
|
*
|
|
* Return a handle and a pointer to the class.
|
|
* 'ptr' can be NULL if the pointer is not needed.
|
|
*/
|
|
HCLASS CLASS_FindClassByName( char * name, CLASS **ptr )
|
|
{
|
|
ATOM atom;
|
|
HCLASS class;
|
|
CLASS * classPtr;
|
|
|
|
/* First search task-specific classes */
|
|
|
|
if ((atom = FindAtom( name )) != 0)
|
|
{
|
|
for (class = firstClass; (class); class = classPtr->hNext)
|
|
{
|
|
classPtr = (CLASS *) USER_HEAP_ADDR(class);
|
|
if (classPtr->wc.style & CS_GLOBALCLASS) continue;
|
|
if (classPtr->atomName == atom)
|
|
{
|
|
if (ptr) *ptr = classPtr;
|
|
return class;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Then search global classes */
|
|
|
|
if ((atom = GlobalFindAtom( name )) != 0)
|
|
{
|
|
for (class = firstClass; (class); class = classPtr->hNext)
|
|
{
|
|
classPtr = (CLASS *) USER_HEAP_ADDR(class);
|
|
if (!(classPtr->wc.style & CS_GLOBALCLASS)) continue;
|
|
if (classPtr->atomName == atom)
|
|
{
|
|
if (ptr) *ptr = classPtr;
|
|
return class;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* CLASS_FindClassPtr
|
|
*
|
|
* Return a pointer to the CLASS structure corresponding to a HCLASS.
|
|
*/
|
|
CLASS * CLASS_FindClassPtr( HCLASS hclass )
|
|
{
|
|
CLASS * ptr;
|
|
|
|
if (!hclass) return NULL;
|
|
ptr = (CLASS *) USER_HEAP_ADDR( hclass );
|
|
if (ptr->wMagic != CLASS_MAGIC) return NULL;
|
|
return ptr;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* RegisterClass (USER.57)
|
|
*/
|
|
ATOM RegisterClass( LPWNDCLASS class )
|
|
{
|
|
CLASS * newClass, * prevClassPtr;
|
|
HCLASS handle, prevClass;
|
|
|
|
#ifdef DEBUG_CLASS
|
|
printf( "RegisterClass: wndproc=%08x hinst=%d name='%s' background %x\n",
|
|
class->lpfnWndProc, class->hInstance, class->lpszClassName,
|
|
class->hbrBackground );
|
|
#endif
|
|
|
|
/* Check if a class with this name already exists */
|
|
|
|
prevClass = CLASS_FindClassByName( class->lpszClassName, &prevClassPtr );
|
|
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 (!(prevClassPtr->wc.style & CS_GLOBALCLASS)) return 0;
|
|
}
|
|
|
|
/* bug for bug compatible */
|
|
|
|
if (class->cbClsExtra < 0) class->cbClsExtra = 0;
|
|
if (class->cbWndExtra < 0) class->cbWndExtra = 0;
|
|
|
|
/* Create class */
|
|
|
|
handle = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(CLASS)+class->cbClsExtra );
|
|
if (!handle) return 0;
|
|
newClass = (CLASS *) USER_HEAP_ADDR( handle );
|
|
newClass->hNext = firstClass;
|
|
newClass->wMagic = CLASS_MAGIC;
|
|
newClass->cWindows = 0;
|
|
newClass->wc = *class;
|
|
|
|
if (newClass->wc.style & CS_GLOBALCLASS)
|
|
newClass->atomName = GlobalAddAtom( class->lpszClassName );
|
|
else newClass->atomName = AddAtom( class->lpszClassName );
|
|
newClass->wc.lpszClassName = NULL;
|
|
|
|
if (newClass->wc.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 ((int)class->lpszMenuName & 0xffff0000)
|
|
{
|
|
HANDLE hname;
|
|
hname = USER_HEAP_ALLOC( GMEM_MOVEABLE, strlen(class->lpszMenuName)+1);
|
|
if (hname)
|
|
{
|
|
newClass->wc.lpszMenuName = (char *)USER_HEAP_ADDR( hname );
|
|
strcpy( newClass->wc.lpszMenuName, class->lpszMenuName );
|
|
}
|
|
}
|
|
|
|
if (class->cbClsExtra) memset( newClass->wExtra, 0, class->cbClsExtra );
|
|
firstClass = handle;
|
|
return newClass->atomName;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* UnregisterClass (USER.403)
|
|
*/
|
|
BOOL UnregisterClass( LPSTR className, HANDLE instance )
|
|
{
|
|
HANDLE class, prevClass;
|
|
CLASS * classPtr, * prevClassPtr;
|
|
|
|
/* Check if we can remove this class */
|
|
class = CLASS_FindClassByName( className, &classPtr );
|
|
if (!class) return FALSE;
|
|
if ((classPtr->wc.hInstance != instance) || (classPtr->cWindows > 0))
|
|
return FALSE;
|
|
|
|
/* Remove the class from the linked list */
|
|
if (firstClass == class) firstClass = classPtr->hNext;
|
|
else
|
|
{
|
|
for (prevClass = firstClass; prevClass; prevClass=prevClassPtr->hNext)
|
|
{
|
|
prevClassPtr = (CLASS *) USER_HEAP_ADDR(prevClass);
|
|
if (prevClassPtr->hNext == class) break;
|
|
}
|
|
if (!prevClass)
|
|
{
|
|
printf( "ERROR: Class list corrupted\n" );
|
|
return FALSE;
|
|
}
|
|
prevClassPtr->hNext = classPtr->hNext;
|
|
}
|
|
|
|
/* Delete the class */
|
|
if (classPtr->hdce) DCE_FreeDCE( classPtr->hdce );
|
|
if (classPtr->wc.hbrBackground) DeleteObject( classPtr->wc.hbrBackground );
|
|
if (classPtr->wc.style & CS_GLOBALCLASS) GlobalDeleteAtom( classPtr->atomName );
|
|
else DeleteAtom( classPtr->atomName );
|
|
if ((int)classPtr->wc.lpszMenuName & 0xffff0000)
|
|
USER_HEAP_FREE( (int)classPtr->wc.lpszMenuName & 0xffff );
|
|
USER_HEAP_FREE( class );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetClassWord (USER.129)
|
|
*/
|
|
WORD GetClassWord( HWND hwnd, short offset )
|
|
{
|
|
return (WORD)GetClassLong( hwnd, offset );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetClassWord (USER.130)
|
|
*/
|
|
WORD SetClassWord( HWND hwnd, short offset, WORD newval )
|
|
{
|
|
CLASS * classPtr;
|
|
WND * wndPtr;
|
|
WORD *ptr, retval = 0;
|
|
|
|
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
|
|
if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
|
|
ptr = (WORD *)(((char *)classPtr->wExtra) + offset);
|
|
retval = *ptr;
|
|
*ptr = newval;
|
|
return retval;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetClassLong (USER.131)
|
|
*/
|
|
LONG GetClassLong( HWND hwnd, short offset )
|
|
{
|
|
CLASS * classPtr;
|
|
WND * wndPtr;
|
|
|
|
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
|
|
if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
|
|
return *(LONG *)(((char *)classPtr->wExtra) + offset);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetClassLong (USER.132)
|
|
*/
|
|
LONG SetClassLong( HWND hwnd, short offset, LONG newval )
|
|
{
|
|
CLASS * classPtr;
|
|
WND * wndPtr;
|
|
LONG *ptr, retval = 0;
|
|
|
|
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
|
|
if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
|
|
ptr = (LONG *)(((char *)classPtr->wExtra) + offset);
|
|
retval = *ptr;
|
|
*ptr = newval;
|
|
return retval;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetClassName (USER.58)
|
|
*/
|
|
int GetClassName(HWND hwnd, LPSTR lpClassName, short maxCount)
|
|
{
|
|
WND *wndPtr;
|
|
CLASS *classPtr;
|
|
|
|
if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
|
|
if (!(classPtr = CLASS_FindClassPtr(wndPtr->hClass))) return 0;
|
|
|
|
return (GetAtomName(classPtr->atomName, lpClassName, maxCount));
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetClassInfo (USER.404)
|
|
*/
|
|
BOOL GetClassInfo(HANDLE hInstance, LPSTR lpClassName,
|
|
LPWNDCLASS lpWndClass)
|
|
{
|
|
CLASS *classPtr;
|
|
|
|
if (!(CLASS_FindClassByName(lpClassName, &classPtr))) return FALSE;
|
|
if (hInstance && (hInstance != classPtr->wc.hInstance)) return FALSE;
|
|
|
|
memcpy(lpWndClass, &(classPtr->wc), sizeof(WNDCLASS));
|
|
return TRUE;
|
|
}
|