#ifndef _COBJECTTREE_H_
#define _COBJECTTREE_H_

#include "CObjectBase.h"
#include "../x/Objstr.h"
#include "utils.h"
#include "CObjLayerFont.h"

#define TRE_LEFT               (1<<(LAST_OBJ_FLAG+1))
#define TRE_V_CENTER           (1<<(LAST_OBJ_FLAG+6))
#define TRE_FIXED_ROOT         (1<<(LAST_OBJ_FLAG+8))
#define TRE_HIDDEN_ROOT        (1<<(LAST_OBJ_FLAG+9))
#define TRE_HIGHLIGHT_SELECTED (1<<(LAST_OBJ_FLAG+10))
#define TRE_HIGHLIGHT_CLICKED  (1<<(LAST_OBJ_FLAG+11))

#define NO_ITEM_SELECTED      -1
#define NO_ITEM_CLICKED       -1

// les etats possibles pour les noeuds
#define TRE_SHRINK             0
#define TRE_EXPAND             1

// les types de recherche d'elements
#define TRE_PRE_ORDER          0
#define TRE_LEVEL_ORDER        1


class CObjectTree:public CObjectBase
{
private:
//	int firstItem;            // indice du premier element visible
	int itemSize;             // espacement prevu pour chaque element
	int visibleItemsCount;    // nbre d'elements visibles (suivant itemSize)
	int itemsDisplayed;       // nbre d'elements reellement affiches (= visibleItemsCount sauf pour bout de liste)
	int itemSelected;         // element actuellement sous la souris
	int itemClicked;          // element selectionne conserve, -1 si aucun
	int itemsCount;           // nbre d'elements en tout dans l'arbre
	int reservedSpace;        // decalage du texte en pixels (pour mettre un icône)
	int levelShift;			  // decalage par niveau en pixels

	int TREtransp,TREtextTransp;
	int TREtextColor, TREselectColor, TREselectTansparencyCoeff;
	int TREshadowColor, TREshadowDecal;

	Layer *TRElayerSelect, *TRElayerClicked, *TRElayersBitmaps, *TRElayerGraphics;
	CObjLayerFont *TREfont;

	inline int highlightSelected() {return ObjFlags&TRE_HIGHLIGHT_SELECTED;}
	inline int highlightClicked() {return ObjFlags&TRE_HIGHLIGHT_CLICKED;}

	int setItemsCount(int);

	// retourne l'index de l'element dont on a cliqué sur + / -
	int ClickInShrinkExpand( int, int, int, int );
	Rect2D GetClickableRect( mmachine, int, int );

	void DrawText( char *, int, int, int );
	Layer *DrawBitmap( int, int, int );
	Layer *DrawTreeElements( mmachine, int, int *, int, Layer *, Rect2D );
	Layer *CreateUpperLevelsLayers( mmachine, int, int, Layer *, Layer *, Rect2D );
	Layer *DrawTreeElementsDownwards( mmachine, int, int *, int, int, Layer *, Layer *, Rect2D );

	//retourne l'index de la colonne de la bitmap à afficher
	int GetColumnIndexBitmap(mmachine,int,int);

	// pour les liens entre objets
	int send_notification_value(int, int, int, int);
	int send_notification_size(int, int, int, int);

public:
	CObjectTree(container *,Layer *,Layer *,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,PtrObjFont);
	virtual ~CObjectTree();

	inline int fixedRoot() {return ObjFlags&TRE_FIXED_ROOT;}
	inline int hiddenRoot() {return ObjFlags&TRE_HIDDEN_ROOT;}

	int IsMouseOnObject(int,int,int);
	int CursorMove(int,int,int,int,int);
	int CursorMoveIn(int,int,int,int,int);
	int CursorMoveInWithBtnPushed(int,int,int,int,int);
	int CursorMoveOut(int,int,int,int,int);
	int CursorMoveOutWithBtnPushed(int,int,int,int,int);
	int CursorMoveOutsideWithBtnPushed(int,int,int,int,int);
	int ClickIn(int,int,int,int,int,int);
	int UnClickIn(int,int,int,int,int,int);
	int ClickOut(int,int,int,int,int,int);
	int UnClickOut(int,int,int,int,int,int);
	int DblClickIn(int,int,int,int,int,int);
	int MouseWheel(int,int,int,int,int,int);
	int KeyUp(UINT,int,UINT,int);
	int KeyDown(UINT,int,int,UINT,int);
	int SetFocus(int,int,int);
	int KillFocus(int,int);

	int Timer(int);

	int setFirstItem(int,int,int);
	int addItem(int,int,int);
	int delItem(int,int,int);
	int shrinkItem(int,int,int,int);
	int expandItem(int,int,int,int);
	int getVisibleItemsCount();

	Layer *GetLayer(mmachine m,int p_tab);
	Layer *GetLayerPart(mmachine m,Rect2D *area2redraw,int p_tab);
	
	int DestroyAllLayers();
	int ResizeLayer(int,int,int);

	// pour les liens entre objets
	int handle(CObjMessage* msg);
	int supports( int type );

};

int MYstrcmp( char *str1, char *str2 );

/* fonctions Scol */
int _CRcompTree(mmachine);
int _DScompTree(mmachine);
int _CONVERTcompTreeToObjNode(mmachine);
int _ADDcompTree(mmachine);
int _DELcompTree(mmachine);
int _SDELcompTree(mmachine);
int _RSTcompTree(mmachine);
int _GETcompTreeCount(mmachine);
int _GETcompTreeValue(mmachine);
int _SETcompTreeValue(mmachine);
int _SSETcompTreeValue(mmachine);
int _SETcompTreeFirst(mmachine);
int _SSETcompTreeFirst(mmachine);
int _GETcompTreeState(mmachine);
int _SETcompTreeState(mmachine);
int _GETcompTreeClicked(mmachine);
int _SETcompTreeClicked(mmachine);
int _SSETcompTreeClicked(mmachine);
int _POScompTree(mmachine);
int _CBcompTreeClick(mmachine);
int _CBcompTreeDblClick(mmachine);
int _CBcompTreeStateChanged(mmachine);
int _CBcompTreeResizeResource(mmachine);
int _CBcompTreeResize(mmachine);

#endif