//========================================================================
// Xe UI toolkit
//
// XeList
//  Public header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Jun-12 18:20:23
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//========================================================================
#ifndef _XeListWidget_h
#define _XeListWidget_h

#include <Xe/Xe.h>
#include <Xe/Label.h>

#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif


enum
{
	XeSINGLE_SELECT = 1,
	XeMULTIPLE_SELECT,
	XeMULTIPLE_SELECT_AT_LEAST_ONE  // Multi-select with at least one item selected
};


enum
{
	XeMultiSelectOFF = 1,
	XeMultiSelectON,
	XeMultiSelectTOGGLE
};


typedef struct
{
	XeCallbackStructCore;
	XeString 	ItemStr;
	int       ItemLength;
	int       ItemPosition;
	EBool     DoubleClick;
} XeListCallbackStruct;


#define XeListItemSTRING     0x0001
#define XeListItemUSER_DATA  0x0002

typedef struct
{
	XeString  String;
	EpImage*  NormalImage;
	EpImage*  SelectedImage;
	EPointer  UserData;
	uint32_t  Selected : 1;
} XeListItem;

#ifndef xeListItem_def
#define xeListItem_def  1
typedef struct  xeListItem_S       xeListItem;
typedef struct  xeListItem_S*      xeListItemPtr;
EListA_t(xeListItemPtr);
typedef struct XeListItemColumn_S  XeListItemColumn;
#endif


//========================================
// Initialize an XeListItem
//========================================
static inline void XeListItem_Init(XeListItem* PItem)
{
	PItem->String = NULL;
	PItem->NormalImage = NULL;
	PItem->SelectedImage = NULL;
	PItem->Selected = FALSE;
	PItem->UserData = NULL;
}


extern XeWidgetClass*            XeListWidget_class;
typedef struct _XeListClassRec*  XeListWidgetClass;
typedef struct _XeListRec*       XeListWidget;


extern void    XeList_AddItemUnselected(XeWidget PW, XeString PItem, const int PLocation);
extern void    XeList_DeleteAllItems(XeWidget PW);
extern void    XeList_DeselectAllItems(XeWidget PW);
extern void    XeList_SelectItemByIndex(XeWidget PW, const int PIndex);
extern EIndex  XeList_ItemsSetSelections(XeWidget PW,  const EBool* PSelected, const EIndex PN);

extern void    XeList_ItemUpdate(XeWidget PW, XeListItem* PItem, const int PIndex);
extern EIndex  XeList_GetSelectedItems(XeWidget PW, XeListItem** PItems, const uint16_t PComponents);
extern EBool   XeList_ItemSelected(XeWidget PW, const EIndex PIndex);

extern void         XeListItems_Free(XeDisplay* PDisplay, xeListItemPtrListA* PItems);

enum
{
	XeListKEEP_SELECTIONS = 0x0001,
	XeListRESET_SCROLL =    0x0002,
	XeListLAYOUT =          0x0004
};

extern void         XeList_SetItems(XeWidget PW,  xeListItem** PItems, const EIndex PNItems, const EBool PItemsPersistent,  const uint16_t PFlags);
extern xeListItem*  XeListItem_New(const int PNumOfColumns);

extern void    XeList_UpdateAndRedraw(XeWidget PW);

extern XeListItemColumn*  XeListItem_Column(xeListItem* PListItem, const EIndex PColumnIndex);

extern EIndex             XeListItem_ColumnSet(xeListItem* PListItem, const EIndex PColumnIndex, XeStringBinarySegmentListA* PString,
                           EpImage* PNormalImage, EpImage* PSelectedImage,  const XeCoordinate PSpacingX);

extern EBool     XeList_GetSelectedPos(XeWidget PW,  int** PPosListRet, int* PPosCountRet);
extern EBool     XeList_ItemExists(XeWidget PW, XeString PItem);
extern XeWidget  XeScrolledList_New(XeWidget PParentW, const char* PName,  const EArg* PArgs, const int PNumOfArgs);

extern XeCoordinate  XeList_ColumnPreferredSizeX(XeWidget PW, const int PColumn, const EBool PAddSpacing);


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
} // Close scope of 'extern "C"' declaration
#endif

#endif // _XeListWidget_h
