/*	XGDraw.cpp
 *
 *		This is the stack object which provides proper serial access
 *	to drawing stuff
 *
 *	*** Note to X Users:
 *
 *		Views are emulated in the YAAF library by setting the clipping
 *	and the origin of the drawing context to the rectangle the XGView
 *	class resides in. (This is done normally in XGDraw::CreateContext.)
 *	The problem is that there is no way in X to set the origin of
 *	a graphic context (at least that I'm aware of).
 *
 *		That's why the 'fXOrigin' and 'fYOrigin' values; these give
 *	the offset in the graphics context where the view should be
 *	drawn. Normally as all drawing goes through the XGDraw drawing
 *	routines, this isn't a problem. But you should keep this fact in
 *	mind if you extend the XGDraw code with new drawing routines.
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XError.h>
#include <XView.h>
#include <XDraw.h>
#include <XPrinter.h>

#if OPT_WINOS
#include <math.h>
#endif

/************************************************************************/
/*																		*/
/*	Globals																*/
/*																		*/
/************************************************************************/

#if OPT_WINOS == 1
HFONT		GDefaultFont;				// a default font for my stuff.
#endif

#if (OPT_XWIN == 1) || (OPT_WINOS == 1)
Rect		*XGDraw::gUpdate = NULL;	// update rectangle
#endif

XGDraw *XGDraw::gDraw = NULL;

#if OPT_WINOS == 1
extern "C" {
	extern HINSTANCE _GInstance;
}
#endif

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

// @G"Construction/Destruction"

#if 0
#pragma mark Construction/Destruction
#endif

/*	@F"XGDraw::XGDraw" @I
 *
 *		Construct a drawing object from the specified view. This is used
 *	to initiate drawing inside of a view.
 */

XGDraw::XGDraw(XGView *view, bool lc)
{
	/*
	 *	Initialize this drawing state object
	 */
	
	fLast = gDraw;						// and insert me into the linked list
	gDraw = this;
	fView = view;
	fPrinter = NULL;
	fFontPtr = NULL;

	if (fLast) fLast->SaveContext();	// Save old drawing context
	CreateContext(lc);
}

/*	@F"XGDraw::XGDraw" @I
 *
 *		Construct a drawing object for the printer. This is used to
 *	initiate drawing into a printer page.
 */

XGDraw::XGDraw(XGPrinter *print)
{
	fLast = gDraw;
	gDraw = this;
	fView = NULL;
	fPrinter = print;
	fFontPtr = NULL;
	
	if (fLast) fLast->SaveContext();	// save old drawing context
	CreateContext(true);
}

/*	@F"XGDraw::~XGDraw" @I
 *
 *		Destroy this, and restore drawing to the previous draw object
 */

XGDraw::~XGDraw()
{
	DestroyContext();					// Release the current drawing context
	gDraw = fLast;
	if (gDraw) gDraw->RestoreContext();	// Restore last drawing context
}

/************************************************************************/
/*																		*/
/*	Resolution Support													*/
/*																		*/
/************************************************************************/

// @G"Resolution Support"

#if 0
#pragma mark -
#pragma mark Resolution support
#endif

/*	@F"XGDraw::GetResolution" @I
 *
 *		Returns the point resolution of the screen
 */

Point XGDraw::GetResolution()
{
	Point pt;
	
#if OPT_MACOS
	/*
	 *	On the Macintosh this is fixed
	 */
	
	pt.h = 72;
	pt.v = 72;
#endif

#if OPT_XWIN
	/*
	 *	Calculate based on the width/height of the display in pixels and it's
	 *	width/height in millimeters. The results should be close enough.
	 */
	
	pt.h = (DisplayWidth(_GDisplay,0) * 254L) / (10L * DisplayWidthMM(_GDisplay,0));
	pt.v = (DisplayHeight(_GDisplay,0) * 254L) / (10L * DisplayHeightMM(_GDisplay,0));
#endif

#if OPT_WINOS
	pt.h = ::GetDeviceCaps(fDC,LOGPIXELSX);
	pt.v = ::GetDeviceCaps(fDC,LOGPIXELSY);
#endif

	return pt;
}

/************************************************************************/
/*																		*/
/*	Line Drawing Support												*/
/*																		*/
/************************************************************************/

// @G"Line Drawing Support"

#if 0
#pragma mark -
#pragma mark Line Drawing Support
#endif

/*	@F"XGDraw::MoveTo" @I
 *
 *		Move the pen cursor to the specified location.
 */

void XGDraw::MoveTo(short x, short y)
{
#if OPT_MACOS == 1
	::MoveTo(x,y);
#endif

#if OPT_WINOS == 1
	::MoveToEx(fDC,x,y,NULL);
#endif

#if OPT_XWIN == 1
	fXPen = x;
	fYPen = y;
#endif
}

/*	@F"XGDraw::LineTo" @I
 *
 *		Draw line from the pen cursor to the specified location, and
 *	updates the pen location.
 */

void XGDraw::LineTo(short x, short y)
{
#if OPT_MACOS == 1
	::LineTo(x,y);
#endif

#if OPT_WINOS == 1
	HPEN pen;
	HGDIOBJ old;
	
	pen = ::CreatePen(PS_SOLID,fPenWidth,fForeColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)pen);
	::LineTo(fDC,x,y);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)pen);
#endif

#if OPT_XWIN == 1
	::XDrawLine(GetDisplay(),
				GetDrawable(),
				GetGC(),
				fXPen+fXOrigin,
				fYPen+fYOrigin,
				x+fXOrigin,
				y+fYOrigin);
	fXPen = x;
	fYPen = y;
#endif
}

/*	@F"XGDraw::GetPenPos" @I
 *
 *		Get the current pen location
 */

Point XGDraw::GetPenPos(void)
{
	Point pt;
	
#if OPT_XWIN
	pt.h = fXPen;
	pt.v = fYPen;
#endif

#if OPT_WINOS
	POINT p;
	::MoveToEx(GetDC(),0,0,&p);
	::MoveToEx(GetDC(),p.x,p.y,NULL);
	pt.h = p.x;
	pt.v = p.y;
#endif

#if OPT_MACOS
	::GetPen(&pt);
#endif

	return pt;
}

/************************************************************************/
/*																		*/
/*	Ovals/Circles														*/
/*																		*/
/************************************************************************/

// @G"Oval Drawing"

#if 0
#pragma mark -
#pragma mark Oval Drawing
#endif

/*	@F"XGDraw::FrameOval" @I
 *
 *		Frame this oval. Draws an oval outline that fits within the
 *	boundaries of the provided rectangle.
 */

void XGDraw::FrameOval(Rect r)
{
#if OPT_MACOS == 1
	::FrameOval(&r);
#endif

#if OPT_WINOS == 1
	HPEN pen;
	HGDIOBJ old;
	HGDIOBJ oldb;
	
	pen = ::CreatePen(PS_SOLID,fPenWidth,fForeColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)pen);
	oldb = ::SelectObject(GetDC(),GetStockObject(NULL_BRUSH));

	Ellipse(GetDC(),r.left,r.top,r.right-r.left,r.bottom-r.top);

	::SelectObject(GetDC(),oldb);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)pen);
#endif

#if OPT_XWIN == 1
	::XDrawArc(GetDisplay(),
			   GetDrawable(),
			   GetGC(),
			   r.left+fXOrigin,r.top+fYOrigin,
			   r.right-r.left,r.bottom-r.top,
			   0,23040);						// 23040 == 360 * 64
#endif
}

/*	@F"XGDraw::PaintOval" @I
 *
 *		Paint this oval. Draws an filled oval that fits within the
 *	boundaries of the provided rectangle.
 */

void XGDraw::PaintOval(Rect r)
{
#if OPT_MACOS == 1
	::PaintOval(&r);
#endif

#if OPT_WINOS == 1
	HPEN pen;
	HBRUSH brush;
	HGDIOBJ old;
	HGDIOBJ oldb;
	
	pen = ::CreatePen(PS_NULL,1,fBackColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)pen);
	brush = ::CreateSolidBrush(fForeColor);
	oldb = ::SelectObject(GetDC(),brush);

	Ellipse(GetDC(),r.left,r.top,r.right-r.left,r.bottom-r.top);

	::SelectObject(GetDC(),oldb);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)pen);
	::DeleteObject((HGDIOBJ)brush);
#endif

#if OPT_XWIN == 1
	::XFillArc(GetDisplay(),
			   GetDrawable(),
			   GetGC(),
			   r.left+fXOrigin,r.top+fYOrigin,
			   r.right-r.left,r.bottom-r.top,
			   0,23040);						// 23040 == 360 * 64
#endif
}

/*	@F"XGDraw::EraseOval" @I
 *
 *		Erase this oval. Erases a filled oval that fits within the
 *	boundaries of the provided rectangle.
 */

void XGDraw::EraseOval(Rect r)
{
#if OPT_MACOS == 1
	::EraseOval(&r);
#endif

#if OPT_WINOS == 1
	HPEN pen;
	HBRUSH brush;
	HGDIOBJ old;
	HGDIOBJ oldb;
	
	pen = ::CreatePen(PS_NULL,1,fBackColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)pen);
	brush = ::CreateSolidBrush(fBackColor);
	oldb = ::SelectObject(GetDC(),brush);

	Ellipse(GetDC(),r.left,r.top,r.right-r.left,r.bottom-r.top);

	::SelectObject(GetDC(),oldb);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)pen);
	::DeleteObject((HGDIOBJ)brush);
#endif

#if OPT_XWIN == 1
	Color oldfore;
	
	/* Kludge: Paint background */
	oldfore = fForeground;
	SetForeColor(fBackground);
	PaintOval(r);
	SetForeColor(oldfore);
#endif
}

/************************************************************************/
/*																		*/
/*	Arcs																*/
/*																		*/
/************************************************************************/

// @G"Arc Drawing"

#if 0
#pragma mark -
#pragma mark Arc Drawing
#endif

/*	@F"XGDraw::FrameArc" @I
 *
 *		Draw an arc. Angles are specified in degrees similar to the
 *	Macintosh: clockwise from upright in degrees.
 */

void XGDraw::FrameArc(Rect r, short start, short length)
{
#if OPT_MACOS == 1
	::FrameArc(&r,start,length);
#endif

#if OPT_WINOS == 1
	short end;
	short x1,y1,x2,y2;
	
	end = start + length;
	start = 90 - start;
	if (start < 0) start += 360;
	end = 90 - end;
	if (end < 0) end += 360;
	if (length > 0) {
		short tmp;
		tmp = start;
		start = end;
		end = tmp;
	}
	
	/*
	 *	I hate this...
	 */
	
	x1 = ((r.right - r.left) * sin(start * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y1 = ((r.bottom - r.top) * sin(start * 3.1415926 / 180.0) + (r.bottom + r.top))/2;
	x2 = ((r.right - r.left) * sin(end * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y2 = ((r.bottom - r.top) * sin(end * 3.1415926 / 180.0) + (r.bottom + r.top))/2;

	/*
	 *	Draw it
	 */
	
	HPEN pen;
	HGDIOBJ old;
	
	pen = ::CreatePen(PS_SOLID,fPenWidth,fForeColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)pen);
	::Arc(GetDC(),r.left,r.top,r.right,r.bottom,x1,y1,x2,y2);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)pen);
#endif

#if OPT_XWIN == 1
	start = 90 - start;
	if (start < 0) start += 360;
	start *= 64;
	length = -64 * length;

	::XDrawArc(GetDisplay(),
			   GetDrawable(),
			   GetGC(),
			   r.left+fXOrigin,r.top+fYOrigin,
			   r.right-r.left,r.bottom-r.top,
			   start,length);
#endif
}

/*	@F"XGDraw::PaintArc" @I
 *
 *		Fill an arc. Angles are specified in degrees similar to the
 *	Macintosh: clockwise from upright in degrees.
 */

void XGDraw::PaintArc(Rect r, short start, short length)
{
#if OPT_MACOS == 1
	::PaintArc(&r,start,length);
#endif

#if OPT_WINOS == 1
	short end;
	short x1,y1,x2,y2;
	
	end = start + length;
	start = 90 - start;
	if (start < 0) start += 360;
	end = 90 - end;
	if (end < 0) end += 360;
	if (length > 0) {
		short tmp;
		tmp = start;
		start = end;
		end = tmp;
	}
	
	/*
	 *	I hate this...
	 */
	
	x1 = ((r.right - r.left) * sin(start * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y1 = ((r.bottom - r.top) * sin(start * 3.1415926 / 180.0) + (r.bottom + r.top))/2;
	x2 = ((r.right - r.left) * sin(end * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y2 = ((r.bottom - r.top) * sin(end * 3.1415926 / 180.0) + (r.bottom + r.top))/2;

	/*
	 *	Draw it
	 */
	
	HBRUSH brush;
	HGDIOBJ old;
	
	brush = ::CreateSolidBrush(fForeColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)brush);
	::Arc(GetDC(),r.left,r.top,r.right,r.bottom,x1,y1,x2,y2);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)brush);
#endif

#if OPT_XWIN == 1
	start = 90 - start;
	if (start < 0) start += 360;
	start *= 64;
	length = -64 * length;

	::XFillArc(GetDisplay(),
			   GetDrawable(),
			   GetGC(),
			   r.left+fXOrigin,r.top+fYOrigin,
			   r.right-r.left,r.bottom-r.top,
			   start,length);
#endif
}

/*	@F"XGDraw::EraseArc" @I
 *
 *		Erase an arc. Angles are specified in degrees similar to the
 *	Macintosh: clockwise from upright in degrees.
 */

void XGDraw::EraseArc(Rect r, short start, short length)
{
#if OPT_MACOS == 1
	::EraseArc(&r,start,length);
#endif

#if OPT_WINOS == 1
	short end;
	short x1,y1,x2,y2;
	
	end = start + length;
	start = 90 - start;
	if (start < 0) start += 360;
	end = 90 - end;
	if (end < 0) end += 360;
	if (length > 0) {
		short tmp;
		tmp = start;
		start = end;
		end = tmp;
	}
	
	/*
	 *	I hate this...
	 */
	
	x1 = ((r.right - r.left) * sin(start * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y1 = ((r.bottom - r.top) * sin(start * 3.1415926 / 180.0) + (r.bottom + r.top))/2;
	x2 = ((r.right - r.left) * sin(end * 3.1415926 / 180.0) + (r.right + r.left))/2;
	y2 = ((r.bottom - r.top) * sin(end * 3.1415926 / 180.0) + (r.bottom + r.top))/2;

	/*
	 *	Draw it
	 */
	
	HBRUSH brush;
	HGDIOBJ old;
	
	brush = ::CreateSolidBrush(fBackColor);
	old = ::SelectObject(GetDC(),(HGDIOBJ)brush);
	::Arc(GetDC(),r.left,r.top,r.right,r.bottom,x1,y1,x2,y2);
	::SelectObject(GetDC(),old);
	::DeleteObject((HGDIOBJ)brush);
#endif

#if OPT_XWIN == 1
	Color oldfore;
	
	/* Kludge: Paint background */
	oldfore = fForeground;
	SetForeColor(fBackground);
	PaintArc(r,start,length);
	SetForeColor(oldfore);
#endif
}


/************************************************************************/
/*																		*/
/*	Rectangle Support													*/
/*																		*/
/************************************************************************/

// @G"Rectangle Drawing"

#if 0
#pragma mark -
#pragma mark Rectangle Drawing
#endif

/*	@F"XGDraw::FrameRect" @I
 *
 *		This draws a framed rectangle
 */

void XGDraw::FrameRect(Rect r)
{
#if OPT_MACOS == 1
	::FrameRect(&r);
#endif

#if OPT_WINOS == 1
	HBRUSH brush;
	
	brush = ::CreateSolidBrush(fForeColor);
	::FrameRect(fDC,&r,brush);
	::DeleteObject(brush);
#endif

#if OPT_XWIN == 1
	::XDrawRectangle(GetDisplay(),
					 GetDrawable(),
					 GetGC(),
					 r.left + fXOrigin,
					 r.top + fYOrigin,
					 r.right - r.left - 1,
					 r.bottom - r.top - 1);
#endif
}

/*	@F"XGDraw::PaintRect" @I
 *
 *		Paint the specified rectangle
 */

void XGDraw::PaintRect(Rect r)
{
#if OPT_MACOS == 1
	::PaintRect(&r);
#endif

#if OPT_WINOS == 1
	FillRect(r,fForeColor);
#endif

#if OPT_XWIN == 1
	::XFillRectangle(GetDisplay(),
					 GetDrawable(),
					 GetGC(),
					 r.left + fXOrigin,
					 r.top + fYOrigin,
					 r.right - r.left,
					 r.bottom - r.top);
#endif
}

/*	@F"XGDraw::EraseRect" @I
 *
 *		Erase the specified rectangle
 */

void XGDraw::EraseRect(Rect r)
{
#if OPT_MACOS == 1
	::EraseRect(&r);
#endif

#if OPT_WINOS == 1
	::ExtTextOut(fDC,0,0,ETO_OPAQUE,&r,NULL,0,NULL);
#endif

#if OPT_XWIN == 1
	Color oldfore;
	
	/* Kludge: Paint background */
	oldfore = fForeground;
	SetForeColor(fBackground);
	PaintRect(r);
	SetForeColor(oldfore);
#endif
}

/*	@F"XGDraw::InvertRect" @I
 *
 *		Invert the specified rectangle.
 */

void XGDraw::InvertRect(Rect r)
{
#if OPT_MACOS == 1
	::InvertRect(&r);
#endif

#if OPT_WINOS == 1
	::InvertRect(fDC,&r);
#endif

#if OPT_XWIN == 1
	::XSetFunction(GetDisplay(),GetGC(),GXinvert);
	::XFillRectangle(GetDisplay(),
					 GetDrawable(),
					 GetGC(),
					 r.left + fXOrigin,
					 r.top + fYOrigin,
					 r.right - r.left,
					 r.bottom - r.top);
	::XSetFunction(GetDisplay(),GetGC(),GXcopy);
#endif
}

/*	@F"XGDraw::DrawFocusRect" @I
 *
 *		Draws a focus rectangle. Used for indicating who has the
 *	focus. Note that this is an XOR drawing on Windows, but does 
 *  _not_ XOR draw on X or the Mac.
 */

void XGDraw::DrawFocusRect(Rect r)
{
#if OPT_MACOS || OPT_XWIN
	Draw3DRect(r,KXGEGrayFrame);
#endif

#if OPT_WINOS == 1
	::DrawFocusRect(GetDC(),&r);
#endif
}

/*	@F"XGDraw::FillRect" @I
 *
 *		This quickly fills the rectangle with the specified color.
 */

void XGDraw::FillRect(Rect r, Color c)
{
#if OPT_MACOS == 1
	RGBColor oldc;
	
	::GetForeColor(&oldc);
	SetForeColor(c);
	::PaintRect(&r);
	::RGBForeColor(&oldc);
#endif

#if OPT_WINOS == 1
	COLORREF oldc;
	
	oldc = ::GetBkColor(fDC);
	::SetBkColor(fDC,ColorFromPalette(c));
	::ExtTextOut(fDC,0,0,ETO_OPAQUE,&r,NULL,0,NULL);
	::SetBkColor(fDC,oldc);
#endif

#if OPT_XWIN == 1
	Color oldfore;
	
	oldfore = fForeground;
	SetForeColor(c);
	PaintRect(r);
	SetForeColor(oldfore);
#endif
}

/*	@F"XGDraw::FillRect" @I
 *
 *		This quickly fills the rectangle defined by the four parameters
 *	with the specified color.
 */

void XGDraw::FillRect(short left, short top, short right, short bottom, Color c)
{
	Rect r;
	
	r.left = left;
	r.top = top;
	r.right = right;
	r.bottom = bottom;
	
#if OPT_MACOS == 1
	RGBColor oldc;
	
	::GetForeColor(&oldc);
	SetForeColor(c);
	::PaintRect(&r);
	::RGBForeColor(&oldc);
#endif

#if OPT_WINOS == 1
	COLORREF oldc;
	
	oldc = ::GetBkColor(fDC);
	::SetBkColor(fDC,ColorFromPalette(c));
	::ExtTextOut(fDC,0,0,ETO_OPAQUE,&r,NULL,0,NULL);
	::SetBkColor(fDC,oldc);
#endif

#if OPT_XWIN == 1
	FillRect(r,c);
#endif
}

/*	@F"XGDraw::Draw3DRect" @I
 *
 *		Draw the 3D rectangle using standard grays instead of the
 *	foreground and background colors
 */

void XGDraw::Draw3DRect(Rect r, XGERectType type)
{
	Color a,b;
	
	switch (type) {
		case KXGEFrame:
			/* Different from FrameRect() because this guarentees */
			/* the border is one pixel wide black.				  */
			a = ColorFromPalette(KXGColorBlack);
			FillRect(r.left,r.top,r.right,r.top+1,a);
			FillRect(r.left,r.top+1,r.left+1,r.bottom,a);
			FillRect(r.left+1,r.bottom-1,r.right,r.bottom,a);
			FillRect(r.right-1,r.top+1,r.right,r.bottom-1,a);
			break;
			
		case KXGEInset:
			a = ColorFromPalette(KXGColorBtnShadow);
			b = ColorFromPalette(KXGColorBtnHilite);
			FillRect(r.left,r.top,r.right,r.top+1,a);
			FillRect(r.left,r.top+1,r.left+1,r.bottom,a);
			FillRect(r.left+1,r.bottom-1,r.right,r.bottom,b);
			FillRect(r.right-1,r.top+1,r.right,r.bottom-1,b);
			break;

		case KXGEOutset:
			a = ColorFromPalette(KXGColorBtnShadow);
			b = ColorFromPalette(KXGColorBtnHilite);
			FillRect(r.left,r.top,r.right,r.top+1,b);
			FillRect(r.left,r.top+1,r.left+1,r.bottom,b);
			FillRect(r.left+1,r.bottom-1,r.right,r.bottom,a);
			FillRect(r.right-1,r.top+1,r.right,r.bottom-1,a);
			break;
			
		case KXGEButton:
			Draw3DRect(r,KXGEFrame);
			::InsetRect(&r,1,1);
			Draw3DRect(r,KXGEOutset);
			break;
			
		case KXGEInButton:
			Draw3DRect(r,KXGEFrame);
			::InsetRect(&r,1,1);
			Draw3DRect(r,KXGEInset);
			break;
			
		case KXGEGrayFrame:
			a = ColorFromPalette(KXGColorBtnShadow);
			FillRect(r.left,r.top,r.right,r.top+1,a);
			FillRect(r.left,r.top+1,r.left+1,r.bottom,a);
			FillRect(r.left+1,r.bottom-1,r.right,r.bottom,a);
			FillRect(r.right-1,r.top+1,r.right,r.bottom-1,a);
			break;

		case KXGEBackFrame:
			a = ColorFromPalette(KXGColorBtnFace);
			FillRect(r.left,r.top,r.right,r.top+1,a);
			FillRect(r.left,r.top+1,r.left+1,r.bottom,a);
			FillRect(r.left+1,r.bottom-1,r.right,r.bottom,a);
			FillRect(r.right-1,r.top+1,r.right,r.bottom-1,a);
			break;

		case KXGEBackground:
			a = ColorFromPalette(KXGColorBtnFace);
			FillRect(r,a);
			break;
	}
}


/************************************************************************/
/*																		*/
/*	Character Drawing													*/
/*																		*/
/************************************************************************/

// @G"Character Drawing"

#if 0
#pragma mark -
#pragma mark Character Drawing
#endif

/*	@F"XGDraw::SetFont" @I
 *
 *		This sets the current font for my drawing context. When a font
 *	is passed to me, I assume ownership of the font, and will detach
 *	it when done. This means if the code passing a font to me also
 *	wants to hang on to the font, it must explicitly do an attach as well.
 */

void XGDraw::SetFont(XGFont *font)
{
	/*
	 *	Unlock the font that was in me
	 */
	
	if (fFontPtr != NULL) {
		fFontPtr->Detach();
	}
	
	/*
	 *	Set the new font
	 */
	
	fFontPtr = font;
	if (font == NULL) return;

	/*
	 *	Now set the actual font specification
	 */
	
#if OPT_MACOS == 1
	font->SetFont();
#endif

#if OPT_WINOS == 1
	::SelectObject(fDC,font->GetFont(fDC));
#endif

#if OPT_XWIN == 1
	Font fh = font->GetFont();
	if (fh) ::XSetFont(GetDisplay(),GetGC(),fh);
#endif
}

/*	@F"XGDraw::GetFontAscent" @I
 *
 *		Get the ascent of this font.
 */

short XGDraw::GetFontAscent()
{
#if OPT_MACOS == 1
	FontInfo finfo;
	
	::GetFontInfo(&finfo);
	return finfo.ascent;
#endif

#if OPT_WINOS == 1
	TEXTMETRIC tm;
	
	::GetTextMetrics(GetDC(),&tm);
	return tm.tmAscent;
#endif

#if OPT_XWIN == 1
	if (fFontPtr) {
		XFontStruct *fs;
		
		fs = fFontPtr->GetFontStruct();
		if (fs) {
			return fs->ascent;
		}
	}
	return 9;
#endif
}

/*	@F"XGDraw::GetFontDescent" @I
 *
 *		Get the descent of this font.
 */

short XGDraw::GetFontDescent()
{
#if OPT_MACOS == 1
	FontInfo finfo;
	
	::GetFontInfo(&finfo);
	return finfo.descent;
#endif

#if OPT_WINOS == 1
	TEXTMETRIC tm;
	
	::GetTextMetrics(GetDC(),&tm);
	return tm.tmDescent;
#endif

#if OPT_XWIN == 1
	if (fFontPtr) {
		XFontStruct *fs;
		
		fs = fFontPtr->GetFontStruct();
		if (fs) {
			return fs->descent;
		}
	}
	return 3;
#endif
}

/*	@F"XGDraw::GetFontHeight" @I
 *
 *		Get the total height of this font.
 */

short XGDraw::GetFontHeight()
{
#if OPT_MACOS == 1
	FontInfo finfo;
	
	::GetFontInfo(&finfo);
	return finfo.ascent + finfo.descent + finfo.leading;
#endif

#if OPT_WINOS == 1
	TEXTMETRIC tm;
	
	::GetTextMetrics(GetDC(),&tm);
	return tm.tmHeight; // + tm.tmExternalLeading + tm.tmInternalLeading;
#endif

#if OPT_XWIN == 1
	if (fFontPtr) {
		XFontStruct *fs;
		
		fs = fFontPtr->GetFontStruct();
		if (fs) {
			return fs->ascent + fs->descent + 1;
		}
	}
	return 13;
#endif
}

/*	@F"XGDraw::StringWidth" @I
 *
 *		Get the width of this string..
 */

short XGDraw::StringWidth(const char *string, short len)
{
	if (len == -1) {
		for (len = 0; string[len]; len++) ;
	}

#if OPT_MACOS == 1
	return ::TextWidth((Ptr)string,0,len);
#endif

#if OPT_WINOS == 1
	SIZE size;
	
	::GetTextExtentPoint32(GetDC(),string,len,&size);
	return size.cx;
#endif

#if OPT_XWIN == 1
	if (fFontPtr) {
		XFontStruct *fs;
		
		fs = fFontPtr->GetFontStruct();
		if (fs) {
			return XTextWidth(fs,string,len);
		}
	}
	return 10;						// arbitrary width on failure
#endif
}

/*	@F"XGDraw::DrawString" @I
 *
 *		Draws a string. Either a zero-terminated string or by length
 */

void XGDraw::DrawString(const char *string, short len)
{
	if (len == -1) {
		for (len = 0; string[len]; len++) ;
	}

#if OPT_MACOS == 1
	::DrawText((Ptr)string,0,len);
#endif

#if OPT_WINOS == 1
	::TextOut(fDC,0,0,(LPCTSTR)string,len);
#endif

#if OPT_XWIN == 1
	::XDrawString(GetDisplay(),
				  GetDrawable(),
				  GetGC(),
				  fXPen + fXOrigin,
				  fYPen + fYOrigin,
				  string,
				  len);
	if (fFontPtr) {
		XFontStruct *fs;
		
		fs = fFontPtr->GetFontStruct();
		if (fs) {
			fXPen += XTextWidth(fs,string,len);
		}
	}
#endif
}

/*	@F"XGDraw::StringWidthA" @I
 *
 *		Handle string width with amperstand escape
 */

short XGDraw::StringWidthA(const char *string, short len)
{
	char buffer[256];
	int a;
	char *b;
	
	if (len == -1) {
		for (len = 0; string[len]; len++) ;
	}

	b = buffer;
	a = 0;
	while (a < len) {
		if (string[a] == '&') {
			if (string[a+1] != 0) a++;
		}
		*b++ = string[a++];
	}
	buffer[a] = 0;
	return StringWidth(buffer);
}

/*	@F"XGDraw::DrawStringA" @I
 *
 *		Draw with underscore. On the Macintosh this does not
 *	draw an underscore; this is not part of the Macintosh UI Guidelines.
 *	On Windows and X, this *is* a part of the guideline (as well as
 *	menu equivalents on windows and dialog boxes), so they are drawn.
 */

void XGDraw::DrawStringA(const char *string, short len)
{
	short x;
	short start;
#if OPT_WINOS || OPT_XWIN
	Point pt;
	short w;
#endif
	
	if (len == -1) {
		for (len = 0; string[len]; len++) ;
	}

	start = 0;
	for (x = 0; x < len; x++) {
		if ((string[x] == '&') && (string[x+1] != 0)) {
			/*
			 *	Draw the string up until &
			 */
			 
			if (x > start) {
				DrawString(string+start,x-start);
			}
			x++;
			start = x;
			
			/*
			 *	Now draw the amperstand escape
			 */
			
#if OPT_WINOS || OPT_XWIN
			if (string[x] != '&') {
				/*
				 *	Underscore using the line drawing code.
				 */
				
				w = StringWidth(string+x,1);
				pt = GetPenPos();
				
#if OPT_XWIN
				MoveTo(pt.h+w,pt.v+1);			// underscore
				LineTo(pt.h,pt.v+1);
#endif

#if OPT_WINOS
				/* There are subtle differences between these two platforms */
				/* on how lines are drawn. Usually this doesn't matter. Here */
				/* it does. */
				MoveTo(pt.h+w-2,pt.v+1);			// underscore
				LineTo(pt.h-1,pt.v+1);
#endif
				MoveTo(pt.h,pt.v);
			}
#endif
			
			/*
			 *	And continue parsing the string
			 */
			
		}
	}
	
	/*
	 *	Draw the rest of the string
	 */
	
	if (start < x) {
		DrawString(string+start,x-start);
	}
}



/************************************************************************/
/*																		*/
/*	Image Support														*/
/*																		*/
/************************************************************************/

// @G"Image Support"

#if 0
#pragma mark -
#pragma mark Image Support
#endif

/*	@F"XGDraw::DrawIcon" @I
 *
 *		Draw an icon. This loads and draws the specified resource
 */

void XGDraw::DrawIcon(short resID, short x, short y)
{
#if OPT_MACOS == 1
	Rect r;
	CIconHandle cicn;
	
	cicn = ::GetCIcon(resID);
	if (!cicn) return;
	r = (**cicn).iconPMap.bounds;
	::OffsetRect(&r,x-r.left,y-r.top);
	::PlotCIcon(&r,cicn);
	::DisposeCIcon(cicn);
#endif

#if OPT_WINOS == 1
	HICON icon;
	
	icon = (HICON)::LoadImage(_GInstance,
							  MAKEINTRESOURCE(resID),
							  IMAGE_ICON,
							  0,
							  0,
							  0);
	if (icon) {
		::DrawIconEx(GetDC(),x,y,icon,0,0,0,NULL,DI_IMAGE | DI_MASK);
	}
#endif

#if OPT_XWIN
	::DrawXIcon(GetDisplay(),GetDrawable(),GetGC(),resID,x+fXOrigin,y+fYOrigin);
#endif
}

/*	@F"XGDraw::DrawPicture" @I
 *
 *		Draw the picture. This is the same as above, except that
 *	this usually deals with pictures, stored as a separate
 *	data record
 */

void XGDraw::DrawPicture(short resID, short x, short y)
{
#if OPT_MACOS == 1
	PicHandle p;
	Rect r;
	
	p = ::GetPicture(resID);
	if (!p) return;
	r = (**p).picFrame;
	::OffsetRect(&r,x-r.left,y-r.top);
	::DrawPicture(p,&r);
	::ReleaseResource((Handle)p);
#endif

#if OPT_WINOS == 1
	::DrawResBitmap(GetDC(),resID,x,y);
#endif

#if OPT_XWIN == 1
	::DrawXBitmap(GetDisplay(),GetDrawable(),GetGC(),resID,x+fXOrigin,y+fYOrigin);
#endif
}

/************************************************************************/
/*																		*/
/*	Color Support														*/
/*																		*/
/************************************************************************/

// @G"Color Support"

#if 0
#pragma mark -
#pragma mark Color Support
#endif

#if OPT_MACOS == 1

/*	ToWord
 *
 *		Take byte to word
 */

static unsigned short ToWord(unsigned char c)
{
	return (((unsigned short)c) << 8) | c;
}

#endif

/*	@F"XGDraw::SetForeColor" @I
 *
 *		Set the foreground color. If this is a palette color, the color
 *	is converted to the proper RGB value first.
 */

void XGDraw::SetForeColor(Color c)
{
	c = ColorFromPalette(c);
	
#if OPT_MACOS == 1
	RGBColor color;
	
	color.red = ToWord(GetRValue(c));
	color.green = ToWord(GetGValue(c));
	color.blue = ToWord(GetBValue(c));
	
	::RGBForeColor(&color);
#endif

#if OPT_WINOS == 1
	fForeColor = c;
	::SetTextColor(fDC,c);
#endif

#if OPT_XWIN == 1
	fForeground = c;
	XSetForeground(GetDisplay(),GetGC(),AllocColor(c));
#endif
}

/*	@F"XGDraw::SetBackColor" @I
 *
 *		Set background color. If this is a palette color, the color
 *	is converted to the proper RGB value first.
 */

void XGDraw::SetBackColor(Color c)
{
	c = ColorFromPalette(c);
	
#if OPT_MACOS == 1
	RGBColor color;
	
	color.red = ToWord(GetRValue(c));
	color.green = ToWord(GetGValue(c));
	color.blue = ToWord(GetBValue(c));
	
	::RGBBackColor(&color);
#endif

#if OPT_WINOS == 1
	fBackColor = c;
	::SetBkColor(fDC,c);
#endif

#if OPT_XWIN == 1
	fBackground = c;
	XSetBackground(GetDisplay(),GetGC(),AllocColor(c));
#endif
}

// @G"Pen Attributes"

/*	@F"XGDraw::SetPenWidth" @I
 *
 *		Set the width of the pen to use for drawing
 */

void XGDraw::SetPenWidth(short width)
{
	fPenWidth = width;
	
#if OPT_MACOS == 1
	::PenSize(width,width);
#endif

#if OPT_XWIN == 1
#endif
}


/************************************************************************/
/*																		*/
/*	Clipping															*/
/*																		*/
/************************************************************************/

// @G"Clipping"

#if 0
#pragma mark -
#pragma mark Clipping
#endif

/*	@F"XGDraw::ClipRect" @I
 *
 *		Clip inside this rectangle. Allow the entire area if NULL. Does
 *	not work if the 'lc' flag is clear--like I care.
 *
 *		This also clips all the views that are children of my view.
 */

void XGDraw::ClipRect(Rect *s)
{
	Rect r;
	
	/*
	 *	Find the local coordinate clipping region by intersecting
	 *	with 's
	 */
	
	if (!fView) return;
	r = fView->fGlobalRect;
	::OffsetRect(&r,-fView->fGlobalPos.h,-fView->fGlobalPos.v);
	if (s) ::SectRect(s,&r,&r);

#if OPT_MACOS == 1
	::ClipRect(&r);
#endif

#if OPT_WINOS == 1
	HRGN rgn;

	::OffsetRect(&r,fView->fGlobalPos.h,fView->fGlobalPos.v);
	if (gUpdate) ::SectRect(gUpdate,&r,&r);
	rgn = ::CreateRectRgnIndirect(&r);
	::SelectClipRgn(fDC,rgn);
	::DeleteObject(rgn);
#endif

#if OPT_XWIN == 1
	XRectangle xr;
	
	::OffsetRect(&r,fView->fGlobalPos.h,fView->fGlobalPos.v);
	if (gUpdate) ::SectRect(gUpdate,&r,&r);

	xr.x = r.left;
	xr.y = r.top;
	xr.width = r.right - r.left;
	xr.height = r.bottom - r.top;

	::XSetClipRectangles(_GDisplay,fGC,0,0,&xr,1,Unsorted);
#endif	
}

/************************************************************************/
/*																		*/
/*	Drawing Context	(Common)											*/
/*																		*/
/************************************************************************/

// @G"Universal Internal Support"

#if 0
#pragma mark -
#pragma mark Universal Internal Support
#endif

/*	@F"XGDraw::ColorFromPalette" @I
 *
 *		If the palette color field is set, this gets the actual color
 */

Color XGDraw::ColorFromPalette(Color c)
{
#if OPT_MACOS
	RGBColor color;
#endif			

	/* If it's not a special color, just return the color */
	if (GetColorFlag(c) != 0x10) return c;
	
	/* Return the right color */
#if OPT_MACOS || OPT_XWIN
	switch ((short)c) {
		default:
		case 0:	// black
		case 2:	// hilite
			return RGB(0,0,0);					// black
		case 1:	// white
		case 3:	// hilite
			return RGB(0xFF,0xFF,0xFF);			// white
		case 4:	// face
			return RGB(0xDD,0xDD,0xDD);			// lgray
		case 5:	// shadow
			return RGB(0x80,0x80,0x80);			// dgray
#if OPT_XWIN
		case 6:	// hilite
			return RGB(0x80,0xFF,0x80);			// hilite (green)
		case 7:	// hilite text
			return RGB(0,0,0);					// hilite text (black)
#endif

#if OPT_MACOS
		case 6:	// hilite
			LMGetHiliteRGB(&color);
			return RGB((unsigned char)(color.red >> 8),
					   (unsigned char)(color.green >> 8), 
					   (unsigned char)(color.blue >> 8));
		case 7:	// hilite text
			LMGetHiliteRGB(&color);
			if ((color.red < 0x3000) && 
					(color.green < 0x3000) && 
					(color.blue < 0x3000)) {
				// dark color: return white
				return RGB(0xFF,0xFF,0xFF);
			} else {
				// light color: return black
				return RGB(0,0,0);
			}
#endif
		case 8:
			return RGB(0,0,0x80);				// menu hilite (dark blue)
		case 9:
			return RGB(0xDD,0xDD,0xDD);			// dark gray
	}
	return 0;
#endif // OPT_MACOS || OPT_XWIN

#if OPT_WINOS
	switch ((short)c) {
		default:
		case 0:										// black
			return RGB(0,0,0);
		case 1:
			return RGB(0xFF,0xFF,0xFF);
		case 2:
			return GetSysColor(COLOR_BTNTEXT);
		case 3:
			return GetSysColor(COLOR_BTNHILIGHT);	// white
		case 4:
			return GetSysColor(COLOR_BTNFACE);		// lgray
		case 5:
			return GetSysColor(COLOR_BTNSHADOW);	// dgray
		case 6:
		case 8:
			return GetSysColor(COLOR_HIGHLIGHT);	// hilite
		case 7:
		case 9:
			return GetSysColor(COLOR_HIGHLIGHTTEXT);
	}
	return 0;
#endif
}

/************************************************************************/
/*																		*/
/*	Drawing Context	(Macintosh)											*/
/*																		*/
/************************************************************************/

#if 0
#pragma mark -
#pragma mark Internal Support (Macintosh)
#endif

#if OPT_MACOS == 1

/*	XGDraw::SaveContext
 *
 *		Save the drawing context
 */

void XGDraw::SaveContext()
{
	// Save drawing port
	::GetPort(&fPort);
	
	// Save origin
	fOffset.h = fPort->portRect.left;
	fOffset.v = fPort->portRect.top;
	
	// Save clipping rectangle
	fClip = ::NewRgn();
	::GetClip(fClip);
	
	// Save pen state and color information
	::GetPenState(&fPenState);
	fFont = fPort->txFont;
	fFace = fPort->txFace;
	fSize = fPort->txSize;
	fMode = fPort->txMode;
	fSpExtra = fPort->spExtra;	
	::GetForeColor(&fForeColor);
	::GetBackColor(&fBackColor);
}

/*	XGDraw::RestoreContext
 *
 *		Restore the drawing context
 */

void XGDraw::RestoreContext()
{
	// Restore drawing port
	::SetPort(fPort);
	
	// Restore origin
	::SetOrigin(fOffset.h,fOffset.v);
	
	// Restore clipping
	::SetClip(fClip);
	::DisposeRgn(fClip);
	
	// Restore pen state and color information
	::SetPenState(&fPenState);
	::TextFont(fFont);
	::TextFace(fFace);
	::TextSize(fSize);
	::TextMode(fMode);
	::SpaceExtra(fSpExtra);
	::RGBForeColor(&fForeColor);
	::RGBBackColor(&fBackColor);
}

/*	XGDraw::CreateContext
 *
 *		Create drawing context into the geometry specified. The 'local
 *	coordinate' flag indicates that we should clip and offset the viewport
 *	so that (0,0) is the upper left of the view. This is the default.
 *
 *		The only time when we don't want to do this is when we are
 *	dealing with standard Maintosh controls.
 */

void XGDraw::CreateContext(bool lc)
{
	GrafPtr port;
	RGBColor color;
	PenState state;
	Rect r;
	
	if (fView) {
		// Set the drawing port
		port = fView->fRootWindow;
		::SetPort(port);

		if (lc) {
			// Set the coordinate system so it's view local
			::SetOrigin(-fView->fGlobalPos.h,-fView->fGlobalPos.v);
			ClipRect();
		} else {
			// Set the coordinate system so it's global to the window.
			// useful for Macintosh controls
			::SetOrigin(0,0);
			r = fView->fGlobalRect;
			::ClipRect(&r);
		}
	} else if (fPrinter) {
		port = (GrafPtr)(fPrinter->fPort);
		::SetPort(port);
	}
	
	// Now, set the font, text, color and other information
	color.red = 0;
	color.green = 0;
	color.blue = 0;
	::RGBForeColor(&color);
	if (lc) {
		/* Set this only for local views */
		color.red = 0xFFFF;
		color.green = 0xFFFF;
		color.blue = 0xFFFF;
	} else {
		color.red = 0xDDDD;
		color.green = 0xDDDD;
		color.blue = 0xDDDD;
	}
	::RGBBackColor(&color);
	
	::SpaceExtra(0x10000);
	
	::TextFont(1);
	::TextSize(9);
	::TextFace(0);
	::TextMode(srcOr);
	
	state.pnLoc.h = 0;
	state.pnLoc.v = 0;
	state.pnSize.h = 1;
	state.pnSize.v = 1;
	state.pnMode = srcCopy;
	state.pnPat = qd.black;
	::SetPenState(&state);
	
	fPenWidth = 1;
}

/*	XGDraw::DestroyContext
 *
 *		Destroy this context.
 */

void XGDraw::DestroyContext()
{
	if (fFontPtr) fFontPtr->Detach();
}

#endif

/************************************************************************/
/*																		*/
/*	Drawing Context	(Windows)											*/
/*																		*/
/************************************************************************/

#if 0
#pragma mark -
#pragma mark Internal Support (Windows)
#endif

#if OPT_WINOS == 1

/*	XGDraw::SaveContext
 *
 *		Save the drawing context
 */

void XGDraw::SaveContext()
{
	fDCSave = ::SaveDC(fDC);
}

/*	XGDraw::RestoreContext
 *
 *		Restore the drawing context
 */

void XGDraw::RestoreContext()
{
	::RestoreDC(fDC,fDCSave);
}

/*	XGDraw::CreateContext
 *
 *		Create drawing context into the geometry specified.
 */

void XGDraw::CreateContext(bool)
{
	if (fView) {
		fDC = ::GetDC(fView->fRootWindow);

		/*
		 *	Set the local coordinates and clipping coordinates
		 */
		
		ClipRect();
		::SetViewportOrgEx(fDC,fView->fGlobalPos.h,fView->fGlobalPos.v,NULL);
	} else if (fPrinter) {
		fDC = fPrinter->fPrintDC;
	}
	
	
	/*
	 *	Set some parameters for me
	 */
	
	::SetTextColor(fDC,ColorFromPalette(KXGColorBlack));
	::SetBkColor(fDC,ColorFromPalette(KXGColorWhite));
	
	fForeColor = ColorFromPalette(KXGColorBlack);
	fBackColor = ColorFromPalette(KXGColorWhite);
	
	::SetTextAlign(fDC,TA_BASELINE | TA_LEFT | TA_UPDATECP);
	::SetBkMode(fDC,TRANSPARENT);					// sorta like mac
	
	/*
	 *	Set the font
	 */
	
	if (GDefaultFont == NULL) {
		GDefaultFont = ::CreateFont(-MulDiv(8,GetDeviceCaps(fDC,LOGPIXELSY),72),
									0,
									0,
									0,
									FW_NORMAL,
									false,
									false,
									false,
									ANSI_CHARSET,
									OUT_DEFAULT_PRECIS,
									CLIP_DEFAULT_PRECIS,
									PROOF_QUALITY,
									DEFAULT_PITCH | FF_SWISS,
									"Arial");
	}
	fDefFont = ::SelectObject(fDC,GDefaultFont);

	fPenWidth = 1;
}

/*	XGDraw::DestroyContext
 *
 *		Destroy this context. This doesn't do a thing
 */

void XGDraw::DestroyContext()
{
	::SelectObject(fDC,fDefFont);
	if (fFontPtr) fFontPtr->Detach();
	if (fView) {
		::ReleaseDC(fView->fRootWindow,fDC);
	} else if (fPrinter) {
		// On Windows, do nothing.
	}
}

#endif

/************************************************************************/
/*																		*/
/*	Drawing Context	(X Windows)											*/
/*																		*/
/************************************************************************/

#if 0
#pragma mark -
#pragma mark Internal Support (X)
#endif

#if OPT_XWIN == 1

/*	XGDraw::GetDrawable
 *
 *		Get the drawable of my view
 */

Drawable XGDraw::GetDrawable() const
{
	return fView->fRootWindow;
}

/*	XGDraw::SaveContext
 *
 *		Save the drawing context. This is ignored, as this is implicitly
 *	done by the act of creating a Graphics Context in X.
 */

void XGDraw::SaveContext()
{
}

/*	XGDraw::RestoreContext
 *
 *		Restore the drawing context
 */

void XGDraw::RestoreContext()
{
}

/*	XGDraw::CreateContext
 *
 *		Create drawing context into the geometry specified. The 'local
 *	coordinate' parameter is ignored.
 */

void XGDraw::CreateContext(bool)
{
	fGC = ::XCreateGC(_GDisplay,fView->fRootWindow,0,NULL);
	
	/* Set clipping */
	ClipRect();
	
	/* Set other parameters */
	fXOrigin = fView->fGlobalPos.h;
	fYOrigin = fView->fGlobalPos.v;
	
	/* Set the GC parameters */
	SetForeColor(ColorFromPalette(KXGColorBlack));
	SetBackColor(ColorFromPalette(KXGColorWhite));
	
	/* Set the font */
	SetFont(XGFont::LoadFont(1));

	fPenWidth = 1;
}

/*	XGDraw::DestroyContext
 *
 *		Destroy this context. This doesn't do a thing
 */

void XGDraw::DestroyContext()
{
	if (fFontPtr) fFontPtr->Detach();
	::XFreeGC(_GDisplay,fGC);
}

#endif // OPT_XWIN
