//----------------------------------------------------
/**
	\file		ctk/inc/wtree.h
	\ingroup	visualization
	\ingroup	all
	
	\brief		Automat okna zobrazujiciho stromove menu
				pro 3-radkovy displej OPC04
				<<< ALL >>>

	\author		ConTeK s.r.o., Petr Cernin
	\version	01.00
	\date		00.00.0000
*/
//----------------------------------------------------

#ifndef _WTREE_H_
#define _WTREE_H_

#include <ctktypes.h>
#include <datadef.h>
#include <wnd.h>

// Typ uzlu stromu
#define TN_TEXT			0x00		//!< obycejny text WTreeNode.w.Text
#define TN_PARAM		0x10		//!< parametr WTreeNode.w.Code
#define TN_PARAM_REMAP	0x20		//!< remapovany parametr WTreeNode.w.Code
#define TN_PARAM_TEXT	0x30		//!< text parametru WTreeNode.w.Code


#define TN_LEVEL		0x0F		//!< maska
#define TN_TYPE			0xF0		//!< maska


//----------------------------------------------------
//! popis jedenoho uzelu stromu
typedef struct _WTREE_NODE
{
	uint8_t	 Level;					//!< Uroven uzlu a typ

	union
	{
		uint8_t  Command;			//!< Prikaz
		uint8_t	 Flags;				//!< Priznaky
	} b;
	
	union
	{
		stringindex_t	Text;		//!< Text uzlu
		paramcode_t		Code;		//!< Kod parametru
	} w;

} WTREE_NODE;

//
// forward deklarace
//

typedef struct _WTREE_CTX WTREE_CTX;

//
//
//

typedef void (* wTreeSelectProc_t) (const WTREE_CTX * const _ctx, const WTREE_NODE * const _node);


//----------------------------------------------------
/**
	callback volany po zmene obsahu stromu 
*/
//----------------------------------------------------

typedef void (* wTreeChangeProc_t) (const WTREE_CTX * const _ctx);


//----------------------------------------------------
/**
	\brief	callback volany v ramci  treeEnumParams()
	
	\param	code  .. kod parametru
	\param  param .. uzivatelsky parametr predany treeEnumParams();
*/
//----------------------------------------------------

typedef void (* wTreeEnumProc_t)(const paramcode_t _code, const uint16_t _param);


//----------------------------------------------------
/**
	\brief	callback volany pro remapovani kodu parametru
	
	\param	code .. kod parametru
	\param	vraci kod remapovaneho parametru
*/
//----------------------------------------------------

typedef paramcode_t (* wTreeRemapProc_t) (const paramcode_t _code);


//----------------------------------------------------
//! popisujici stav automatu pro zobrazeni stromu

struct _WTREE_CTX
{	
	const WTREE_NODE *	Tree;			//!< Ukazatel na prvni uzel stromu (flash)
	uint16_t			TopItem;		//!< Prvni zobrazena polozka
	uint16_t			SelItem;		//!< Vybrana polozka
	uint8_t				Level;			//!< Aktualni uroven ve stromu
	
	uint8_t				UnitWidth;		//!< Sirka pole pro jednotku parametru
	
	wTreeSelectProc_t	OnSelect;		//!< Callback volany pri vyvolani prikazu
	wTreeChangeProc_t	OnChange;		//!< Callback volany pri zmene obsahu
	wTreeRemapProc_t	OnRemap;		//!< Callback volany pro remapovani kodu parametru
};


//----------------------------------------------------
/**
	\brief	Inicializae struktury kontextu automatu pro
			rizeni okna se stromem
	
	\param	ctx			ukazatel na strukturu kontext
	\param	tree		ukazatel na struturu dat stromu
	\param	paramDef	ukazatel na definici parametru
	\param	paramData 	ukazatel na datovou strukturu parametru
	\param	onSelect	callback volany pri vyberu polozky
	\param	onChange	callback volany pri zmene obsahu okna
*/
//----------------------------------------------------

void wTreeInitialize(WTREE_CTX * const _ctx, const WTREE_NODE * const _tree, 
	wTreeSelectProc_t _onSelect, wTreeChangeProc_t _onChange,
	wTreeRemapProc_t _onRemap);


//----------------------------------------------------
// void wTreeEvent( WTREE_CTX *ctx, uint8_t event, uint8_t info )
//---
//
//---
//

void wTreeEvent(WTREE_CTX * const _ctx, const wndevent_t _event, const wndinfo_t _info);


//----------------------------------------------------
/**
	\brief	Funkce pro enumerovani aktualne viditelnych polozek stromu

	\param	ctx			kontext automatu	
	\param	callback	volana rutina (callback)
	\param	param		parametr callbacku
*/
//----------------------------------------------------

void wTreeEnumParams(const WTREE_CTX * const _ctx, wTreeEnumProc_t _callback, const wndparam_t _param);


//----------------------------------------------------
/**
	\brief	Funkce pro vykresleni stromove struktury na displej

	\param	ctx		kontext automatu	
*/
//----------------------------------------------------

void wTreePaint(const WTREE_CTX * const _ctx);

#endif // _TREEWND_H_
