#include "stdafx.h"
#include "awaywindow.h"

#define STATUS(x) status.SetText(env.GetWideString("AwayWindow::status",x,_T(x)))

AwayWindow::AwayWindow(void)
{
}

AwayWindow::~AwayWindow(void)
{
}

int AwayWindow::Create(HWND parent)
{
	Load("AwayWindow");
	away.Load("AwayWindow::away");
	message.Load("AwayWindow::message");
	update.Load("AwayWindow::update");
	cancel.Load("AwayWindow::cancel");

	status.Load("AwayWindow::status");
	
	StaticWindow::Create(parent);
	
	away.Create(hWnd);
	message.Create(hWnd);
	update.Create(hWnd);
	cancel.Create(hWnd);

	status.Create(hWnd,ES_LEFT|ES_READONLY);
	status.Disable();

	return 1;
}

void AwayWindow::DeepRefresh()
{
	switch(db.GetCachedUserState(theApp.user.UserId,theApp.user)){
		case dbInvalidParam:
		case dbException:
			break;
		case dbSuccess:
			away.SetValue(theApp.user.Away);
			message.SetText(theApp.user.AwayMessage);

			STATUS("DefaultStatus");
			break;
	}
		
}

void AwayWindow::OnButton(HWND h)
{
	if(h==update.hWnd){
		STATUS("Updating");
		DoEvents();
		theApp.SetAwayStatus(away.checked,message.Data());

		STATUS("DefaultStatus");
		Hide();
	} else if(h==cancel.hWnd){
		Hide();
	}
}
