#ifndef _COBJECTLIST_H_
#define _COBJECTLIST_H_

#include "CObjectBase.h"
#include "../x/Objstr.h"
#include "utils.h"
#include "CObjLayerFont.h"

#define LST_LEFT               (1<<(LAST_OBJ_FLAG+1))
#define LST_RIGHT              (1<<(LAST_OBJ_FLAG+2))
#define LST_TOP                (1<<(LAST_OBJ_FLAG+3))
#define LST_BOTTOM             (1<<(LAST_OBJ_FLAG+4))
#define LST_H_CENTER           (1<<(LAST_OBJ_FLAG+5))
#define LST_V_CENTER           (1<<(LAST_OBJ_FLAG+6))
#define LST_IMG_RIGHT          (1<<(LAST_OBJ_FLAG+7))
#define LST_IMG_TOP            (1<<(LAST_OBJ_FLAG+8))
#define LST_IMG_BOTTOM         (1<<(LAST_OBJ_FLAG+9))
#define LST_HIGHLIGHT_SELECTED (1<<(LAST_OBJ_FLAG+10))
#define LST_HIGHLIGHT_CLICKED  (1<<(LAST_OBJ_FLAG+11))

#define LST_HORIZONTAL         0
#define LST_VERTICAL           1

#define NO_ITEM_SELECTED      -1
#define NO_ITEM_CLICKED       -1

class CObjectList:public CObjectBase
{
private:
	int direction;            // vertical ou horizontal
	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 la liste
	int reservedSpace;        // en pixels
	int popup;				  // la liste est popup (d'un combo) et devra etre refermee apres selection

	int LSTtransp;
	int LSTtextColor, LSTtextTransp,LSTselectColor, LSTselectTansparencyCoeff;
	int LSTshadowColor, LSTshadowDecal;

	Layer *LSTlayerSelect, *LSTlayerClicked, *LSTlayersBitmaps;
	CObjLayerFont *LSTfont;

	inline int highlightSelected() {return ObjFlags&LST_HIGHLIGHT_SELECTED;}
	inline int highlightClicked() {return ObjFlags&LST_HIGHLIGHT_CLICKED;}

	void DrawText( char *, int );
	Layer *DrawBitmap( int, int );
	Layer *DrawListElements( mmachine, int );

	// pour les liens entre objets
	int send_notification_value(int, int, int, int);
	int send_notification_max(int, int, int, int);
	int send_notification_select(int, int, int, int);
	int send_notification_string_select(int, char*, int);
	int send_notification_close_list();

public:
	CObjectList(container *,Layer *,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,PtrObjFont);
	virtual ~CObjectList();

	int setFirstItem( int newIndex, int notifylinks, int redrawobject );
	int getFirstItem();
	int setSelectedItem( int newIndex, int notifylinks, int redrawobject );
	int setClickedItem( int newIndex, int notifylinks, int redrawobject );
	int getSelectedItem();
	int getClickedItem();
	int addItem( int position );        // uniquement pour le decompte d'elements et les liens !
	int removeItem( int position );     // uniquement pour le decompte d'elements et les liens !
	int removeAllItems();				// uniquement pour le decompte d'elements et les liens !
	int getItemsCount();

	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);

	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 );

};

/* fonctions Scol */
int _CRcompList(mmachine);
int _DScompList(mmachine);
int _CONVERTcompListToObjNode(mmachine);
int _CBcompListClick(mmachine);
int _CBcompListSClick(mmachine);
int _CBcompListDblClick(mmachine);
int _SETcompListFirst(mmachine m);
int _SSETcompListFirst(mmachine m);
int _ADDcompList( mmachine m );
int _DELcompList( mmachine m );
int _SETcompListValue( mmachine m );
int _SDELcompList( mmachine m );
int _SSETcompListValue( mmachine m );
int _POScompList( mmachine m );
int _GETcompListCount( mmachine m );
int _RSTcompList( mmachine m );
int _GETcompListValue( mmachine m );
int _GETcompListClicked( mmachine m );
int _SETcompListClicked( mmachine m );
int _SSETcompListClicked( mmachine m );
int _CBcompListChange(mmachine m);
int _CBcompListResizeResource(mmachine m);
int _CBcompListResize(mmachine m);

#endif