#include "stdafx.h"
#include "eventpopuplist.h"

EventPopupList::EventPopupList()
{

}

EventPopupList::~EventPopupList()
{

}

int EventPopupList::Create(HWND parent)
{
	Load("eventpopup");
	titlebar.Load("eventpopup::titlebar");
	subtitle.Load("eventpopup::subtitle");
	title = L"";
	titlebar.title = L"";
	subtitle.title = L"";

	list.Load("eventpopup::list");
	list.scrollbar.Load("eventpopup::scrollbar");

	PublicEvent.Load("eventpopup::items::public");
	PrivateEvent.Load("eventpopup::items::private");

	spacing = env.GetInt("eventpopup::items","spacing",0);

	Hide();
	PopupList::Create(parent);

	// finally request notifications for changes
	AddCustomNotification(bcEvent);

	return 1;
}

void EventPopupList::DeepRefresh(EventRecord& record)
{
	list.DeleteAllItems();

	// add the description item
	ListItem * item = list.CreateItem(record.Description,record.EventId);
	item->userdata = NULL;
	item->usertype = 0;
	// set the appearance style
	if(record.Private){
		item->Set(PrivateEvent);
	} else {
		item->Set(PublicEvent);
	}
	// calculate height required to show all the text at this width
	item->size.Height = MeasureTextHeight(item->fontname.data(),item->fontsize,
		record.Description,size.Width-item->textlocation.X-list.scrollbar.size.Width-1)+spacing;
	list.AddItem(item);
}

void EventPopupList::OnCustomNotify(int id, Notification& n)
{

}
