#ifndef ELF_H
#define ELF_H

#include <apps.h> 	// Первым! Приложение!
#include <loader.h>
#include <u.h>
#include <mem.h>
#include <func.h>
#include <charset_conv.h>
#include "../../libuix/include/api.h"

#define      CODE_NULL 		0
#define      CODE_ANSI 		1	// однабайтовая кодировка
#define      CODE_UCS2_BE   2	// UTF-16Big Endian



/* Эта структура идентифицирует приложение. Передаётся в любой обработчик событий */
typedef struct
{ 
    APPLICATION_T           apt; /* Должно обязательно присутствовать, причём первым */
} APP_HELLOWORLD_T;

typedef struct
{
	char str[256];
} LINE;


/* Состояния приложения */
typedef enum
{
    HW_STATE_ANY, /* ANY-state всегда первым */
    HW_STATE_MAIN,
	HW_STATE_EDIT,
    HW_STATE_MAX /* Для удобства */
} HW_STATES_T;


ldrElf * _start( WCHAR * uri, WCHAR * params );

static UINT32 startApp( EVENT_STACK_T *ev_st,  REG_ID_T reg_id,  UINT32 param2 );
static UINT32 destroyApp( EVENT_STACK_T *ev_st,  APPLICATION_T *app );
static UINT32 MainStateEnter( EVENT_STACK_T *ev_st,  APPLICATION_T *app,  ENTER_STATE_TYPE_T type );
static UINT32 EditStateEnter( EVENT_STACK_T *ev_st,  APPLICATION_T *app,  ENTER_STATE_TYPE_T type );
static UINT32 StateExit( EVENT_STACK_T *ev_st,  APPLICATION_T *app,  EXIT_STATE_TYPE_T type );


static UINT32 HandleNavigate( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 idx );
static UINT32 HandleSelect( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 param );

static UINT32 HandleAddLine( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 param );
static UINT32 HandleDeleteLine( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 param );
static UINT32 HandleAbout( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 param );
static UINT32 HandleExit( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 param );

static UINT32 EditDone( EVENT_STACK_T * ev_st, APPLICATION_T * app, UINT32 l );

static void * MainEntryReq( APPLICATION_T * app, UINT32 idx );

static UINT32 Save( EVENT_STACK_T *ev_st,  APPLICATION_T *app );
static UINT32 ReadMenu(WCHAR *ini_uri);

static UINT32 util_asc2ul( const WCHAR * s, UINT32 count );
static UINT32 param2uri(WCHAR *param, WCHAR *uri);

#endif
