1993-09-04 12:09:32 +02:00
|
|
|
/*
|
|
|
|
* USER DCE functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char Copyright[] = "Copyright Alexandre Julliard, 1993";
|
|
|
|
|
|
|
|
#include "dce.h"
|
1993-09-29 13:21:49 +01:00
|
|
|
#include "class.h"
|
1993-09-04 12:09:32 +02:00
|
|
|
#include "win.h"
|
|
|
|
#include "gdi.h"
|
1993-09-29 13:21:49 +01:00
|
|
|
#include "user.h"
|
1993-09-04 12:09:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
#define NB_DCE 5 /* Number of DCEs created at startup */
|
|
|
|
|
|
|
|
extern Display * XT_display;
|
|
|
|
extern Screen * XT_screen;
|
|
|
|
|
|
|
|
static HANDLE firstDCE = 0;
|
|
|
|
static HDC defaultDCstate = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DCE_Init
|
|
|
|
*/
|
|
|
|
void DCE_Init()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
HANDLE handle;
|
|
|
|
DCE * dce;
|
|
|
|
|
|
|
|
for (i = 0; i < NB_DCE; i++)
|
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
handle = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(DCE) );
|
1993-09-04 12:09:32 +02:00
|
|
|
if (!handle) return;
|
1993-09-29 13:21:49 +01:00
|
|
|
dce = (DCE *) USER_HEAP_ADDR( handle );
|
1993-09-04 12:09:32 +02:00
|
|
|
dce->hdc = CreateDC( "DISPLAY", NULL, NULL, NULL );
|
|
|
|
if (!dce->hdc)
|
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
USER_HEAP_FREE( handle );
|
1993-09-04 12:09:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dce->hwndCurrent = 0;
|
|
|
|
dce->flags = 0;
|
|
|
|
dce->inUse = FALSE;
|
|
|
|
dce->xOrigin = 0;
|
|
|
|
dce->yOrigin = 0;
|
|
|
|
dce->hNext = firstDCE;
|
|
|
|
firstDCE = handle;
|
|
|
|
if (!defaultDCstate) defaultDCstate = GetDCState( dce->hdc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDC (USER.66)
|
|
|
|
*/
|
|
|
|
HDC GetDC( HWND hwnd )
|
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
HANDLE hdce;
|
|
|
|
HDC hdc = 0;
|
1993-09-04 12:09:32 +02:00
|
|
|
DCE * dce;
|
|
|
|
DC * dc;
|
|
|
|
WND * wndPtr = NULL;
|
1993-09-29 13:21:49 +01:00
|
|
|
CLASS * classPtr;
|
1993-09-04 12:09:32 +02:00
|
|
|
|
|
|
|
if (hwnd)
|
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
|
|
|
|
if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
|
|
|
|
if (wndPtr->hdc) hdc = wndPtr->hdc;
|
|
|
|
else if (classPtr->hdc) hdc = classPtr->hdc;
|
1993-09-04 12:09:32 +02:00
|
|
|
}
|
|
|
|
|
1993-09-29 13:21:49 +01:00
|
|
|
if (!hdc)
|
1993-09-04 12:09:32 +02:00
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
for (hdce = firstDCE; (hdce); hdce = dce->hNext)
|
|
|
|
{
|
|
|
|
dce = (DCE *) USER_HEAP_ADDR( hdce );
|
|
|
|
if (!dce) return 0;
|
|
|
|
if (!dce->inUse) break;
|
|
|
|
}
|
|
|
|
if (!hdce) return 0;
|
|
|
|
dce->hwndCurrent = hwnd;
|
|
|
|
dce->inUse = TRUE;
|
|
|
|
hdc = dce->hdc;
|
1993-09-04 12:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize DC */
|
|
|
|
|
1993-09-29 13:21:49 +01:00
|
|
|
if (!(dc = (DC *) GDI_GetObjPtr( dce->hdc, DC_MAGIC ))) return 0;
|
|
|
|
|
1993-09-04 12:09:32 +02:00
|
|
|
if (wndPtr)
|
|
|
|
{
|
|
|
|
dc->u.x.drawable = XtWindow( wndPtr->winWidget );
|
|
|
|
dc->u.x.widget = wndPtr->winWidget;
|
1993-09-29 13:21:49 +01:00
|
|
|
if (wndPtr->dwStyle & WS_CLIPCHILDREN)
|
|
|
|
XSetSubwindowMode( XT_display, dc->u.x.gc, ClipByChildren );
|
|
|
|
else XSetSubwindowMode( XT_display, dc->u.x.gc, IncludeInferiors);
|
1993-09-04 12:09:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc->u.x.drawable = DefaultRootWindow( XT_display );
|
|
|
|
dc->u.x.widget = 0;
|
1993-09-29 13:21:49 +01:00
|
|
|
XSetSubwindowMode( XT_display, dc->u.x.gc, IncludeInferiors );
|
1993-09-04 12:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_WIN
|
|
|
|
printf( "GetDC(%d): returning %d\n", hwnd, hdc );
|
|
|
|
#endif
|
|
|
|
return hdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReleaseDC (USER.68)
|
|
|
|
*/
|
|
|
|
int ReleaseDC( HWND hwnd, HDC hdc )
|
|
|
|
{
|
|
|
|
HANDLE hdce, next;
|
|
|
|
DCE * dce;
|
|
|
|
WND * wndPtr = NULL;
|
1993-09-29 13:21:49 +01:00
|
|
|
CLASS * classPtr;
|
1993-09-04 12:09:32 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_WIN
|
|
|
|
printf( "ReleaseDC: %d %d\n", hwnd, hdc );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hwnd)
|
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
|
|
|
|
if (wndPtr->hdc && (wndPtr->hdc == hdc)) return 1;
|
|
|
|
if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
|
|
|
|
if (classPtr->hdc && (classPtr->hdc == hdc)) return 1;
|
1993-09-04 12:09:32 +02:00
|
|
|
}
|
|
|
|
|
1993-09-29 13:21:49 +01:00
|
|
|
for (hdce = firstDCE; (hdce); hdce = dce->hNext)
|
1993-09-04 12:09:32 +02:00
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
if (!(dce = (DCE *) USER_HEAP_ADDR( hdce ))) return 0;
|
1993-09-04 12:09:32 +02:00
|
|
|
if (dce->inUse && (dce->hdc == hdc)) break;
|
|
|
|
}
|
|
|
|
|
1993-09-29 13:21:49 +01:00
|
|
|
if (hdce)
|
1993-09-04 12:09:32 +02:00
|
|
|
{
|
1993-09-29 13:21:49 +01:00
|
|
|
SetDCState( dce->hdc, defaultDCstate );
|
1993-09-04 12:09:32 +02:00
|
|
|
dce->inUse = FALSE;
|
1993-09-29 13:21:49 +01:00
|
|
|
}
|
1993-09-04 12:09:32 +02:00
|
|
|
return (hdce != 0);
|
|
|
|
}
|