#pragma once

//===========================================================================//
// File:	 GmlDisplaySystem.h											 //
// Project:  gosGml				                                         //
// Contents:																 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 4/10/00   DP     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 2000 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//
#include "gosGml.hpp"
#include "Text Draw Buffer.h"
#include "Gmlparser.h"
#include "link.h"
#include "GQueue.h"
#include "GmlParsedString.h"
#include "region.h"
#include "Hash.h"
#include "CacheString.h"
#include "Remote.h"
#include "Scrollbar.h"

#define LineBreakSize 4
#define ImageBuffer 4



//GmlDisplaySystem is the control class for the in game Gml system. It has control over all sub classes.
class GmlDisplaySystem
{
	public:
		GmlDisplaySystem(char* fontPath, char* imagePath, rect* DisplayTextArea, int tabwidth=15); //create Gml system window, blank
		~GmlDisplaySystem();
		int TextDrawGml(char* TextData); //display this Gml; does not clear pane.
		void Clear(); //clear the Gml system STUB
		char* TestForHit(int iRelX,int iRelY);
		ExportImageData* ExportImageList();
		ExportHyperlink* ExportHyperlinks();
		void ManageVideo(HGOSVIDEO I);
		void ManageImage(DWORD I);
		void SetParserCallback(ParserCallback* PCB);

#ifndef GosGML_InternalTest
	private:
#endif
		Link* links;
		int TabWidth;
		rect* TextArea;
		GmlParser * GmlP;
		TextDrawBuffer * TDB;
		Hash<DWORD,char*>* ImageHash;
		Hash<DWORD,char*>* FontHash;
		char* CachedText;
		char* FontPath;
		char* ImagePath;
		char* BrokenImage;
		GQueue<GmlParsedString>* DisplayQueue;
		GStack<DWORD>* ImagePtrStack;
		GStack<HGOSFONT3D>* FontPtrStack;
		GQueue<CacheString>* APICache;
		GStack<HGOSVIDEO>* VideoStack;
		GStack<ImageData>* RegisteredImageStack;
		GStack<GMLHyperlink>* LinkStack;
		Scrollbar* SB;

		GmlDisplaySystem();	//call me not
		GmlDisplaySystem(GmlDisplaySystem&);//don't call this
		GmlDisplaySystem& operator= (GmlDisplaySystem const &); //don't call the assignment operator

		char* GrabTag(char* Text);
		void Chomp(char*& Text);
		void ChompN(char*& Text);
		void ChompToTag(char*& Text);
		void DisplayTextFromBuffer();
		void DisplayRegionFromBuffer(rect region, bool FreeLine=false);
		void TextTab();
		int TextTabEndingPos(int XPos);
		void DisplayLineFromQueue(GQueue<GmlParsedString>* LineQueue, int MaxX, int BiggestFontThisLine);
		void DisplayWrapLine(GQueue<GmlParsedString>* LineQueue, GmlParsedString* Line, int MaxX, int BiggestFontThisLine, rect region);
		void DisplayImage(char* FileName, char* Alt, int BiggestFontThisLine, int DisplayPos, rect* region);
		char* GrabHeaders(char* Text);
		bool CheckForCacheHit(char* Text);
		void ClearCache(int level=0);
		int DealWithCacheHit();
		void _gos_TextDraw( const char *Message );
		void _gos_TextSetPosition( int XPosition, int YPosition );
		void DrawImage( gos_VERTEX* Vertices, DWORD Image );
		void _gos_TextStringLength( DWORD* Width, DWORD* Height, const char *Message );
		void _gos_TextSetAttributes( HGOSFONT3D FontHandle, DWORD Foreground, float Size, bool WordWrap, bool Proportional, bool Bold, bool Italic, DWORD WrapType=0, bool DisableEmbeddedCodes=0 );
		bool _gos_LoadFont(char* LoadName);
		DWORD LoadTex(char* Text);
		inline int GmlDisplaySystem::GetImageHeight(DWORD TexHandle);
		inline int GmlDisplaySystem::GetImageWidth(DWORD TexHandle);
		void RegisterImage(char* Name,  char* Alt, DWORD Handle, int x, int y);
};
