1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00
wine/windows/cursor.c
Alexandre Julliard ff8331ea68 Release 950918
Sun Sep 17 16:47:49 1995  Alexandre Julliard  <julliard@sunsite.unc.edu>

	* [configure.in] [*/Makefile.in] [Make.rules.in]
	Cleaned up makefiles, added configuration option for Winelib,
	grouped common make rules in Make.rules.in.

	* [Configure]
	Renamed to 'Configure.old'; please use 'configure' instead.

	* [controls/menu.c]
	Fixed DestroyMenu() to avoid deleting the same menu twice.
	More fixes to WM_MENUSELECT, and added WM_INITMENU.

	* [if1632/relay.c]
	Fixed wrong register values displayed by RELAY_DebugCall32().

	* [memory/local.c]
	Fixed LocalLock() and LocalUnlock() to increment/decrement the
	lock count for moveable blocks.

	* [misc/commdlg.c] [misc/shell.c] [rc/winerc.c]
	Modified the generated C file so that the resource information
	(size, etc.) is also exported.
	Modified common dialogs to use the new informations.

	* [misc/main.c] [ANNOUNCE]
	Update the list of contributors. Please let me know if I forgot
	someone.

	* [rc/sysres.rc] [rc/sysres_En.rc]
	Moved English resources to sysres_En.rc.
	Changed ids from numeric to symbolic for dialogs.

	* [windows/dialog.c]
	Modified template parsing to be able to pass segmented pointers to
	CreateWindow().

	* [windows/win.c]
	CreateWindow() now takes segmented pointers for class and window
	names.
	Maxmimize or minimize the window upon creation if the WS_MAXIMIZE
	or WS_MINIMIZE bits are set.

Thu Sep 14 17:19:57 1995  Paul Wilhelm  <paul@paul.accessone.com>

	* [controls/scroll.c]
	Fixed scroll-bar bugs for non-client windows.

Thu Sep 14 14:04:14 MET DST 1995 Jochen Hoenicke <Jochen.Hoenicke@arbi.Informatik.Uni-Oldenburg.de>

	* [include/cursor.h] [windows/cursor.c]
	Cursor is not mirrored any more and the hotspot is set right.

Wed Sep 13 14:22:31 1995  Marcus Meissner  <msmeissn@faui01.informatik.uni-erlangen.de>

	* [ole.h]
	Misc small fixes.

Mon Sep  4 00:01:23 1995  Jon Tombs <jon@gte.esi.us.es>

	* [rc/sysres_Es.rc]
	First attempt at Spanish [Es] language support.

Sun Sep  3 13:22:33 1995     Martin von Loewis <loewis@informatik.hu-berlin.de>

	* [include/alias.h][windows/alias.c][include/relay32.h]
	New files

	* [controls/widgets.c]
	WIDGETS_Init: register alias window procedures

	* [if1632/callback.c]
	CallWndProc: Call alias functions if necessary

	* [if1632/gdi32.spec]
	GetStockObject, TextOutA: new relays

	* [misc/user32.c][if1632/user32.spec][misc/Makefile.in][misc/Imakefile]
	user32.c: new file
	BeginPaint,CreateWindowExA,DefWindowProcA,DispatchMessage,EndPaint,
	GetMessageA,RegisterClassA,ShowWindow,UpdateWindow: new relays

	* [if1632/winprocs32.spec][loader/pe_image.c][loader/module.c]
	PE_Win32CallToStart: new function
	MODULE_CreateInstance: removed static attribute
	LoadModule: Try loading PE image on error 21
	PE_LoadModule: new function
	PE_LoadImage: initialize pe_data with 0
	
	* [include/dlls.h][include/peexe.h]
	moved pe_data and w_files to peexe.h
	
	* [misc/shell.c]
	ShellAbout: Register AboutWndProc aliases

	* [miscemu/int21.c]
	handle 0x440A and 0xDC

	* [miscemu/int2f.c]
	handle 0x84

	* [objects/dib.c]
	CreateDIBitmap: complain if BITMAPINFOHEADER is of wrong size

	* [tools/build.c]
	include windows.h and relay32.h into generated Win32 relays,
	don't declare the implementation as int (*)();
	limit in WIN32_builtin was off by one

	* [windows/caret.c]
	CARET_Initialize: new function, call on strategic places

	* [windows/messagebox.c]
	MessageBox: register message box proc aliases

	* [if1632/advapi32.spec][if1632/comdlg32.spec]
	New files

	* [if1632/Makefile.in][if1632/Imakefile][if1632/relay32.c]
	added new spec files
	RELAY32_GetBuiltinDLL: perform lookup case insensitive
	RELAY32_GetEntryPoint: start name search at 0

	* [if1632/user.spec][if1632/kernel.spec][if1632/gdi.spec]
	Added stubs for new Win95 API

Sat Sep 2 1995  Martin Roy

	* [misc/commdlg.c]
	In WM_INITDIALOG, current filter must reflect lpofn->nFilterIndex.
  	When process IDOK button in FILEDLG_WMCommand(),
 	lpofn->nFilterIndex should be updated to current selection.

Thu Aug 31 15:00:00 1995 Ram'on Garc'ia <ramon@ie3.clubs.etsit.upm.es>

	* [loader/module.c] [loader/ne_image.c]
	Added support of self-loading modules.
1995-09-18 11:19:54 +00:00

427 lines
12 KiB
C

/*
* WINE
static char Copyright[] = "Copyright Martin Ayotte, 1993";
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "windows.h"
#include "win.h"
#include "gdi.h"
#include "neexe.h"
#include "wine.h"
#include "callback.h"
#include "cursor.h"
#include "resource.h"
#include "stddebug.h"
#include "debug.h"
#include "arch.h"
#include "bitmap.h"
static int ShowCursCount = 0;
static HCURSOR hActiveCursor;
static HCURSOR hEmptyCursor = 0;
RECT ClipCursorRect;
static struct {
SEGPTR name; HCURSOR cursor; unsigned int shape;
} system_cursor[] =
{
{ IDC_ARROW, 0, XC_top_left_arrow},
{ IDC_IBEAM, 0, XC_xterm },
{ IDC_WAIT, 0, XC_watch },
{ IDC_CROSS, 0, XC_crosshair },
{ IDC_UPARROW, 0, XC_based_arrow_up },
{ IDC_SIZE, 0, XC_bottom_right_corner },
{ IDC_ICON, 0, XC_icon },
{ IDC_SIZENWSE, 0, XC_fleur },
{ IDC_SIZENESW, 0, XC_fleur },
{ IDC_SIZEWE, 0, XC_sb_h_double_arrow },
{ IDC_SIZENS, 0, XC_sb_v_double_arrow }
};
#define NB_SYS_CURSORS (sizeof(system_cursor)/sizeof(system_cursor[0]))
/**********************************************************************
* LoadCursor [USER.173]
*/
HCURSOR LoadCursor(HANDLE instance, SEGPTR cursor_name)
{
HCURSOR hCursor;
HRSRC hRsrc;
HANDLE rsc_mem;
char *lpbits;
LONG *lpl,size;
CURSORALLOC *lpcur;
CURSORDIR *lpcurdir;
CURSORDESCRIP curdesc;
POINT hotspot;
int i;
dprintf_resource(stddeb,"LoadCursor: instance = %04x, name = %08lx\n",
instance, cursor_name);
if (!instance)
{
for (i = 0; i < NB_SYS_CURSORS; i++)
if (system_cursor[i].name == cursor_name)
{
if (!system_cursor[i].cursor)
{
hCursor = GlobalAlloc (GMEM_MOVEABLE, sizeof (Cursor));
dprintf_cursor(stddeb,"LoadCursor Alloc hCursor=%X\n", hCursor);
system_cursor[i].cursor = hCursor;
lpcur = (CURSORALLOC *) GlobalLock(hCursor);
lpcur->xcursor = XCreateFontCursor(display, system_cursor[i].shape);
GlobalUnlock(hCursor);
}
return system_cursor[i].cursor;
}
return 0;
}
if (!(hRsrc = FindResource( instance, cursor_name, RT_GROUP_CURSOR )))
return 0;
rsc_mem = LoadResource(instance, hRsrc );
if (rsc_mem == (HANDLE)NULL) {
fprintf(stderr,"LoadCursor / Cursor %08lx not Found !\n", cursor_name);
return 0;
}
lpcurdir = (CURSORDIR *)LockResource(rsc_mem);
if (lpcurdir == NULL) {
FreeResource( rsc_mem );
return 0;
}
curdesc = *(CURSORDESCRIP *)(lpcurdir + 1); /* CONV_CURDESC ? */
#if 0
dprintf_cursor(stddeb,"LoadCursor / curReserved=%X\n", lpcurdir->cdReserved);
dprintf_cursor(stddeb,"LoadCursor / curResourceType=%X\n", lpcurdir->cdType);
dprintf_cursor(stddeb,"LoadCursor / curResourceCount=%X\n", lpcurdir->cdCount);
dprintf_cursor(stddeb,"LoadCursor / cursor Width=%d\n",
(int)curdesc.Width);
dprintf_cursor(stddeb,"LoadCursor / cursor Height=%d\n",
(int)curdesc.Height);
dprintf_cursor(stddeb,"LoadCursor / cursor curDIBSize=%lX\n",
(DWORD)curdesc.curDIBSize);
dprintf_cursor(stddeb,"LoadCursor / cursor curDIBOffset=%lX\n",
(DWORD)curdesc.curDIBOffset);
#endif
FreeResource( rsc_mem );
if (!(hRsrc = FindResource( instance,
MAKEINTRESOURCE(curdesc.curDIBOffset),
RT_CURSOR )))
return 0;
rsc_mem = LoadResource(instance, hRsrc );
if (rsc_mem == (HANDLE)NULL) {
fprintf(stderr,
"LoadCursor / Cursor %08lx Bitmap not Found !\n", cursor_name);
return 0;
}
lpl = (LONG *) LockResource(rsc_mem);
if (lpl == NULL) {
FreeResource( rsc_mem );
return 0;
}
hotspot = *(POINT *) lpl++; /* CONV_POINT ? */
size = CONV_LONG (*lpl);
#if 0
if (!(hdc = GetDC(0))) {
FreeResource( rsc_mem );
return 0;
}
if (size == sizeof(BITMAPCOREHEADER)){
CONV_BITMAPCOREHEADER (lpl);
((BITMAPINFOHEADER *)lpl)->biHeight /= 2;
lpcur->hBitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lpl );
} else if (size == sizeof(BITMAPINFOHEADER)){
CONV_BITMAPINFO (lpl);
((BITMAPINFOHEADER *)lpl)->biHeight /= 2;
lpcur->hBitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lpl );
} else {
fprintf(stderr,"No bitmap for cursor?\n");
lpcur->hBitmap = 0;
}
ReleaseDC(0,hdc);
#endif
if (size == sizeof(BITMAPCOREHEADER))
lpbits = (char *)lpl + sizeof(BITMAPCOREHEADER) + 2*sizeof(RGBTRIPLE);
else if (size == sizeof(BITMAPINFOHEADER))
lpbits = (char *)lpl + sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD);
else {
fprintf(stderr,"Invalid bitmap in cursor resource\n");
FreeResource(rsc_mem);
return 0;
}
/* The height of the cursor is the height of the XOR-Bitmap
* plus the height of the AND-Bitmap, so divide it by two.
*/
size = curdesc.Height/2 * ((curdesc.Width+31)/32 * 4);
#if 0
dprintf_cursor(stddeb,"Bitmap:\n");
for(i=0;i<2*size;i++) {
dprintf_cursor(stddeb,"%02x ",(unsigned char) lpc[i]);
if ((i & 7) == 7) dprintf_cursor(stddeb,"\n");
}
#endif
hCursor = CreateCursor(instance, hotspot.x, hotspot.y,
curdesc.Width, curdesc.Height / 2,
lpbits+size, lpbits);
FreeResource( rsc_mem );
return hCursor;
}
/***********************************************************************
* CreateCursorIconIndirect (USER.408)
*
* Returns handle to either an icon or a cursor. Used by CreateCursor
* and CreateIcon in Windoze, but will use same in this version.
*/
HANDLE CreateCursorIconIndirect(HANDLE hInstance, LPCURSORICONINFO lpInfo,
LPSTR lpANDBits, /* bitmap data */
LPSTR lpXORBits /* masking data */)
{
return CreateIcon(hInstance,
lpInfo->nWidth, lpInfo->nHeight,
lpInfo->byPlanes, lpInfo->byBitsPix,
lpANDBits, lpXORBits);
}
/**********************************************************************
* CreateCursor [USER.406]
*/
HCURSOR CreateCursor(HANDLE instance, short nXhotspot, short nYhotspot,
short nWidth, short nHeight, LPSTR lpANDbitPlane, LPSTR lpXORbitPlane)
{
HCURSOR hCursor;
CURSORALLOC *lpcur;
int bpl = (nWidth + 31)/32 * 4;
char *tmpbits = malloc(bpl * nHeight);
char *src, *dst;
int i;
XImage *image;
Pixmap pixshape, pixmask;
extern void _XInitImageFuncPtrs( XImage* );
XColor bkcolor,fgcolor;
Colormap cmap = XDefaultColormap(display,XDefaultScreen(display));
dprintf_resource(stddeb, "CreateCursor: inst=%04x nXhotspot=%d nYhotspot=%d nWidth=%d nHeight=%d\n",
instance, nXhotspot, nYhotspot, nWidth, nHeight);
dprintf_resource(stddeb,"CreateCursor: inst=%04x lpANDbitPlane=%p lpXORbitPlane=%p\n",
instance, lpANDbitPlane, lpXORbitPlane);
image = XCreateImage( display, DefaultVisualOfScreen(screen),
1, ZPixmap, 0, tmpbits,
nWidth, nHeight, 32, bpl );
if (!image) {
free (tmpbits);
return 0;
}
image->byte_order = MSBFirst;
image->bitmap_bit_order = MSBFirst;
image->bitmap_unit = 16;
_XInitImageFuncPtrs(image);
hCursor = GlobalAlloc(GMEM_MOVEABLE, sizeof(Cursor));
if (hCursor == (HCURSOR)NULL) {
XDestroyImage(image);
return 0;
}
dprintf_cursor(stddeb,"CreateCursor Alloc hCursor=%X\n", hCursor);
lpcur = (CURSORALLOC *)GlobalLock(hCursor);
for(src=lpANDbitPlane, dst=tmpbits+(nHeight-1)*bpl;
dst>=tmpbits; src+=bpl, dst-=bpl)
for(i=0; i<bpl; i++)
dst[i] = ~src[i];
pixmask = XCreatePixmap(display, DefaultRootWindow(display),
nWidth, nHeight, 1);
CallTo32_LargeStack(XPutImage, 10,
display, pixmask, BITMAP_monoGC, image,
0, 0, 0, 0, nWidth, nHeight );
for(src=lpXORbitPlane, dst=tmpbits+(nHeight-1)*bpl;
dst>=tmpbits; src+=bpl, dst-=bpl)
for(i=0; i<bpl; i++)
dst[i] = ~src[i];
pixshape = XCreatePixmap(display, DefaultRootWindow(display),
nWidth, nHeight, 1);
CallTo32_LargeStack(XPutImage, 10,
display, pixshape, BITMAP_monoGC, image,
0, 0, 0, 0, nWidth, nHeight );
XParseColor(display,cmap,"#000000",&fgcolor);
XParseColor(display,cmap,"#ffffff",&bkcolor);
lpcur->xcursor = XCreatePixmapCursor(display, pixshape, pixmask,
&fgcolor, &bkcolor, nXhotspot, nYhotspot);
XFreePixmap(display, pixshape);
XFreePixmap(display, pixmask);
GlobalUnlock(hCursor);
XDestroyImage(image);
return hCursor;
}
/**********************************************************************
* DestroyCursor [USER.458]
*/
BOOL DestroyCursor(HCURSOR hCursor)
{
int i;
CURSORALLOC *lpcur;
if (hCursor == 0) return FALSE;
for (i = 0; i < NB_SYS_CURSORS; i++) {
if (system_cursor[i].cursor == hCursor) return TRUE;
}
lpcur = (CURSORALLOC *)GlobalLock(hCursor);
XFreeCursor (display, lpcur->xcursor);
GlobalUnlock(hCursor);
GlobalFree(hCursor);
return TRUE;
}
/**********************************************************************
* CURSOR_SetCursor
*
* Internal helper function for SetCursor() and ShowCursor().
*/
static void CURSOR_SetCursor( HCURSOR hCursor )
{
CURSORALLOC *lpcur;
if (!(lpcur = (CURSORALLOC *)GlobalLock(hCursor))) return;
if (rootWindow != DefaultRootWindow(display))
{
XDefineCursor( display, rootWindow, lpcur->xcursor );
}
else
{
HWND hwnd = GetWindow( GetDesktopWindow(), GW_CHILD );
while(hwnd)
{
Window win = WIN_GetXWindow( hwnd );
if (win) XDefineCursor( display, win, lpcur->xcursor );
hwnd = GetWindow( hwnd, GW_HWNDNEXT );
}
}
GlobalUnlock( hCursor );
}
/**********************************************************************
* SetCursor [USER.69]
*/
HCURSOR SetCursor(HCURSOR hCursor)
{
HCURSOR hOldCursor;
dprintf_cursor(stddeb,"SetCursor / hCursor=%04X !\n", hCursor);
hOldCursor = hActiveCursor;
hActiveCursor = hCursor;
if ((hCursor != hOldCursor) || (ShowCursCount < 0))
{
CURSOR_SetCursor( hCursor );
}
ShowCursCount = 0;
return hOldCursor;
}
/**********************************************************************
* GetCursor [USER.247]
*/
HCURSOR GetCursor(void)
{
return hActiveCursor;
}
/**********************************************************************
* SetCursorPos [USER.70]
*/
void SetCursorPos(short x, short y)
{
dprintf_cursor(stddeb,"SetCursorPos // x=%d y=%d\n", x, y);
XWarpPointer( display, None, rootWindow, 0, 0, 0, 0, x, y );
}
/**********************************************************************
* GetCursorPos [USER.17]
*/
void GetCursorPos(LPPOINT lpRetPoint)
{
Window root, child;
int rootX, rootY;
int childX, childY;
unsigned int mousebut;
if (!lpRetPoint) return;
if (!XQueryPointer( display, rootWindow, &root, &child,
&rootX, &rootY, &childX, &childY, &mousebut ))
lpRetPoint->x = lpRetPoint->y = 0;
else
{
lpRetPoint->x = rootX + desktopX;
lpRetPoint->y = rootY + desktopY;
}
dprintf_cursor(stddeb,
"GetCursorPos // x=%d y=%d\n", lpRetPoint->x, lpRetPoint->y);
}
/**********************************************************************
* ShowCursor [USER.71]
*/
int ShowCursor(BOOL bShow)
{
dprintf_cursor(stddeb, "ShowCursor(%d), count=%d\n", bShow, ShowCursCount);
if (bShow)
{
if (++ShowCursCount == 0) /* Time to show it */
CURSOR_SetCursor( hActiveCursor );
}
else /* Hide it */
{
if (--ShowCursCount == -1) /* Time to hide it */
{
if (!hEmptyCursor)
hEmptyCursor = CreateCursor( 0, 1, 1, 1, 1,
"\xFF\xFF\xFF\xFF", "\xFF\xFF\xFF\xFF" );
CURSOR_SetCursor( hEmptyCursor );
}
}
return 0;
}
/**********************************************************************
* ClipCursor [USER.16]
*/
void ClipCursor(LPRECT lpNewClipRect)
{
if (!lpNewClipRect) SetRectEmpty( &ClipCursorRect );
else CopyRect( &ClipCursorRect, lpNewClipRect );
}
/**********************************************************************
* GetClipCursor [USER.309]
*/
void GetClipCursor(LPRECT lpRetClipRect)
{
if (lpRetClipRect != NULL)
CopyRect(lpRetClipRect, &ClipCursorRect);
}