//	Zinc Application Framework - W_GDIDSP.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(W_GDIDSP_HPP)
#define W_GDIDSP_HPP
#include <z_dsp.hpp>

class ZAF_EXPORT ZafGdiDisplay : public ZafDisplay
{
public:
	// Logical mapping tables.
	OSLineStyle lineTable[ZAF_MAXLINES];
	OSFillPattern patternTable[ZAF_MAXPATTERNS];
	OSColor colorTable[ZAF_MAXCOLORS];
	OSMono monoTable[ZAF_MAXCOLORS];
	OSFont fontTable[ZAF_MAXFONTS];
	OSMode modeTable[ZAF_MAXMODES];

	// Palette device support.
	bool paletteDevice;
	HPALETTE logicalPalette;

	// --- General ---
	ZafGdiDisplay(void);
	virtual ~ZafGdiDisplay(void);

	// Gdi Cache.
	HBRUSH GetGdiCacheBrush(ZafPaletteStruct palette);
	HPEN GetGdiCachePen(ZafPaletteStruct palette, int width);
	int ReleaseGdiCacheObject(HGDIOBJ hGdiObject);

	// --- Drawing Primitives ---
	// bitmap
	virtual ZafError Bitmap(ZafCoordinate column, ZafCoordinate line, ZafBitmapStruct &bitmap);
	virtual ZafError ConvertToOSBitmap(ZafBitmapStruct &bitmap);
	virtual ZafError ConvertToZafBitmap(ZafBitmapStruct &bitmap);
	virtual ZafError DestroyOSBitmap(ZafBitmapStruct &bitmap);
	virtual ZafError DestroyZafBitmap(ZafBitmapStruct &bitmap);
	// icon
	virtual ZafError Icon(ZafCoordinate column, ZafCoordinate line, ZafIconStruct &icon);
	virtual ZafError ConvertToOSIcon(ZafIconStruct &icon);
	virtual ZafError ConvertToZafIcon(ZafIconStruct &icon);
	virtual ZafError DestroyOSIcon(ZafIconStruct &icon);
	virtual ZafError DestroyZafIcon(ZafIconStruct &icon);
	// mouse
	virtual ZafError Mouse(ZafCoordinate column, ZafCoordinate line, ZafMouseStruct &mouse);
	virtual ZafError ConvertToOSMouse(ZafMouseStruct &mouse);
	virtual ZafError ConvertToZafMouse(ZafMouseStruct &mouse);
	virtual ZafError DestroyOSMouse(ZafMouseStruct &mouse);
	virtual ZafError DestroyZafMouse(ZafMouseStruct &mouse);
	// text
	virtual ZafError Text(ZafCoordinate left, ZafCoordinate top, const ZafIChar *text, int length = -1,
		int hotKeyIndex = -1, bool fill = false);
	virtual ZafError Text(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom,
		const ZafIChar *text, int length = -1,
		ZafHzJustify hzJustify = ZAF_HZ_LEFT,
		ZafVtJustify vtJustify = ZAF_VT_CENTER,
		int hotKeyIndex = -1, bool fill = false);
	virtual ZafRegionStruct TextSize(const ZafIChar *text, int length = -1);
	// graphics
	virtual ZafError Ellipse(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom,
		float startAngle, float endAngle, int width = ZAF_HAIR_LINE, bool fill = false);
	virtual ZafError Line(ZafCoordinate column1, ZafCoordinate line1, ZafCoordinate column2, ZafCoordinate line2,
		int width = ZAF_HAIR_LINE);
	virtual ZafError Pixel(ZafCoordinate column, ZafCoordinate line,
		ZafLogicalColor color = ZAF_CLR_DEFAULT, ZafLogicalColor mono = ZAF_MONO_DEFAULT);
	virtual ZafError Polygon(int numPoints, const ZafCoordinate *polygonPoints,
		int width = ZAF_HAIR_LINE, bool fill = false, bool close = false);
	virtual ZafError Rectangle(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom,
		int width = ZAF_HAIR_LINE, bool fill = false);
	virtual ZafError RegionCopy(const ZafRegionStruct &oldRegion,
		int newColumn, int newLine);
	virtual ZafError RectangleXORDiff(const ZafRegionStruct *oldRegion,
		const ZafRegionStruct *newRegion);

	// --- Drawing support ---
	// get
	virtual ZafRegionStruct ClipRegion(void) const;
	// set
	virtual ZafLogicalColor SetBackground(ZafLogicalColor color);
	virtual ZafRegionStruct SetClipRegion(const ZafRegionStruct &region);
	virtual ZafLogicalFont SetFont(ZafLogicalFont font);
	virtual ZafLogicalColor SetForeground(ZafLogicalColor color);
	virtual ZafLogicalLineStyle SetLineStyle(ZafLogicalLineStyle line);
	virtual ZafLogicalMode SetMode(ZafLogicalMode mode);
	virtual ZafPaletteStruct SetPalette(ZafPaletteStruct palette);
	virtual ZafLogicalFillPattern SetFillPattern(ZafLogicalFillPattern pattern);

	// --- Table support ---
	virtual ZafLogicalColor AddColor(ZafLogicalColor index, ZafUInt8 red, ZafUInt8 green, ZafUInt8 blue);
	virtual ZafLogicalFont AddFont(ZafLogicalFont index, char *fontFamily, int pointSize,
		ZafFontWeight weight = ZAF_FNT_WEIGHT_NORMAL,
		ZafFontSlant slant = ZAF_FNT_SLANT_NORMAL,
		ZafFontPitch ptich = ZAF_FNT_PITCH_DEFAULT);
	virtual ZafError DestroyColor(ZafLogicalColor color);
	virtual ZafError DestroyFont(ZafLogicalFont font);
	virtual ZafError ColorInfo(ZafLogicalColor index, ZafUInt8 &red, ZafUInt8 &green, ZafUInt8 &blue);
	virtual ZafError FontInfo(ZafLogicalFont index, char *fontFamily, int bufferSize,
		int *pointSize, ZafFontWeight *weight = ZAF_NULLP(ZafFontWeight),
		ZafFontSlant *slant = ZAF_NULLP(ZafFontSlant),
		ZafFontPitch *pitch = ZAF_NULLP(ZafFontPitch),
		ZafCoordinate *averageCharWidth = ZAF_NULLP(ZafCoordinate),
		ZafCoordinate *height = ZAF_NULLP(ZafCoordinate),
		ZafCoordinate *leading = ZAF_NULLP(ZafCoordinate));

	// --- ScreenOS specific support members ---
	virtual ZafError BeginDraw(OSDisplayContext displayContext,
		OSDrawContext drawContext, const ZafRegionStruct &draw,
		const ZafRegionStruct &clip);
	virtual ZafError EndDraw(void);
	virtual OSDisplayContext DisplayContext(void) const;
	virtual OSDrawContext DrawContext(void) const;
	virtual OSDisplayContext RestoreDisplayContext(void);
	virtual OSDrawContext RestoreDrawContext(void);
	virtual OSDisplayContext SetDisplayContext(OSDisplayContext context);
	virtual OSDrawContext SetDrawContext(OSDrawContext context);

protected:
	HBRUSH hBrush;
	OSDisplayContext hDC;
	HPEN hPen;
	OSDrawContext hWnd;
	int virtualCount;

	void CreateLogicalPalette(void);
};

#endif // W_GDIDSP_HPP

