//========================================================================
// Xe UI toolkit
//
// XeList
//  Public header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Feb-26 00:28:44
//
// 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;
} XeListCallbackStruct;


#define XeListItemSTRING      0x0001
#define XeListItemUSER_DATA   0x0002

typedef struct
{
	XeString  String;
	EpImage*  NormalImage;
	EpImage*  SelectedImage;
	EPointer  UserData;
	EBool     Selected;
} XeListItem;


//========================================
// 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 void    XeList_SetItems(XeWidget PW,  XeListItem* PItems, const int PNItems,  const EBool PKeepSelections, const EBool PResetScroll);
extern EIndex  XeList_GetSelectedItems(XeWidget PW, XeListItem** PItems, const uint16_t PComponents);
extern EBool   XeList_ItemSelected(XeWidget PW, const EIndex PIndex);

extern void    XeList_ItemArrayFree(XeListItem* PItems, const int PNumOfItems);

extern void    XeList_UpdateAndRedraw(XeWidget PW);


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


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

#endif // _XeListWidget_h
