class ItemDescWnd extends UICommonAPI;

var private WindowHandle m_hItemDescWnd;
var private HtmlHandle m_hHtmlViewer;

event OnRegisterEvent()
{
	RegisterEvent(EV_ItemDescWndShow);
	RegisterEvent(EV_ItemDescWndLoadHtmlFromString);
	RegisterEvent(EV_ItemDescWndSetWindowTitle);
}

event OnLoad()
{
	SetClosingOnESC();
	m_hItemDescWnd = GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath);
	m_hHtmlViewer = GetHtmlHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".HtmlViewer");
}

event OnEvent(int Event_ID, String param)
{
	switch(Event_ID)
	{
		case EV_ItemDescWndShow:
			m_hItemDescWnd.ShowWindow();
			m_hItemDescWnd.SetFocus();
			break;
		case EV_ItemDescWndLoadHtmlFromString:
			HandleLoadHtmlFromString(param);
			break;
		case EV_ItemDescWndSetWindowTitle:
			HandleWindowTitle(param);
			break;
	}
}

/**
 * 윈도우 ESC 키로 닫기 처리 
 * "Esc" Key
 ***/
event OnReceivedCloseUI()
{
	PlayConsoleSound(IFST_WINDOW_CLOSE);
	GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath).HideWindow();
}

/**
 * l2text 의 html 파일을 직접 연다.
 **/
function ShowHelp(string strPath)
{
	if (Len(strPath)>0)
	{
		m_hHtmlViewer.LoadHtml(strPath);

		m_hItemDescWnd.ShowWindow();
		m_hItemDescWnd.SetFocus();
	}
}

function _LoadHtmlFromString(string HtmlString)
{
	m_hHtmlViewer.LoadHtmlFromString(HtmlString);	
}

private function HandleWindowTitle(string param)
{
	local string title;
	ParseString(param, "Title", title);
	setWindowTitleByString(Title);
}

private function HandleLoadHtmlFromString(string param)
{
	local string htmlString;
	ParseString(param, "HTMLString", htmlString);

	_LoadHtmlFromString(htmlString);
}
