#include "NTEvent.h"
#include <stdio.h>
#include <stdlib.h>

namespace NTCurses {

void NTEvent::InitEvent( void ) {
	event_type = NT_EVENT_NULL;
	event_params = NULL;
}

NTEvent::NTEvent() {
	InitEvent();
}

NTEvent::NTEvent( NTEventType etype ) {
	InitEvent();
	event_type = etype;
}

NTEvent::~NTEvent() {
	if (event_params) {
		free( event_params );
		event_params = NULL;
	}
}


NTKeyEvent::NTKeyEvent( int kcode ) : NTEvent( NT_EVENT_KEYPRESS ) {
	event_data.keycode = kcode;
}

NTMouseEvent::NTMouseEvent( int mx , int my , int mz , unsigned int bstate ) : NTEvent( NT_EVENT_MOUSE ) {
	event_data.mouse_state.x = mx;
	event_data.mouse_state.y = my;
	event_data.mouse_state.z = mz;
	event_data.mouse_state.buttonstate = bstate;
}

NTModalExitEvent::NTModalExitEvent( int exitcode ) : NTEvent( NT_EVENT_MODAL_EXIT ) {
	event_data.modal_exit = exitcode;
}

NTNextNodeControlEvent::NTNextNodeControlEvent( void ) : NTEvent( NT_EVENT_NEXT_NODE_FOCUS ) {}
NTPrevNodeControlEvent::NTPrevNodeControlEvent( void ) : NTEvent( NT_EVENT_PREV_NODE_FOCUS ) {}
NTNextRowControlEvent::NTNextRowControlEvent( void ) : NTEvent( NT_EVENT_NEXT_ROW_FOCUS ) {}
NTPrevRowControlEvent::NTPrevRowControlEvent( void ) : NTEvent( NT_EVENT_PREV_ROW_FOCUS ) {}
NTNextPageRowControlEvent::NTNextPageRowControlEvent( void ) : NTEvent( NT_EVENT_NEXT_PAGE_ROW_FOCUS ) {}
NTPrevPageRowControlEvent::NTPrevPageRowControlEvent( void ) : NTEvent( NT_EVENT_PREV_PAGE_ROW_FOCUS ) {}

NTSetCursorPosXEvent::NTSetCursorPosXEvent( int pos ) : NTEvent( NT_EVENT_SET_CURSOR_POS_X ) {
	event_data.pos_x = pos;
}

NTSetCursorPosYEvent::NTSetCursorPosYEvent( int pos ) : NTEvent( NT_EVENT_SET_CURSOR_POS_Y ) {
	event_data.pos_y = pos;
}

NTSetCursorPosEvent::NTSetCursorPosEvent( int px , int py ) : NTEvent( NT_EVENT_SET_CURSOR_POS ) {
	event_data.pos.pos_x = px;
	event_data.pos.pos_y = py;
}

NTCustomEvent::NTCustomEvent( int code , void *ptr ) : NTEvent( NT_EVENT_CUSTOM ) {
	event_data.custom.eventcode = code;
	event_data.custom.customptr = ptr;
}

}
