//========================================================================
// Xe UI toolkit
//
// XeList
// Private  header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Jun-06 16:44:15
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//========================================================================
#ifndef _XeListP_h
#define _XeListP_h

#include <Xe/LabelP.h>
#include <Xe/List.h>

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


//================================
// Class definition
//================================

#define XeListClassCore\
	XePrimitiveClassCore

//================================
// Class record
//================================
typedef struct _XeListClassRec
{
	XeListClassCore;
} XeListClassRec;

extern XeListClassRec  _XeListWidget_class;

#ifdef EX11
typedef struct
{
	Pixmap    XPixmap;
	int16_t   SizeX, SizeY,  DrawnSizeX, DrawnSizeY;
	uint32_t  Uptodate : 1;
} xeListPixmap;

typedef struct
{
	xeListPixmap  NormalPixmap;
	xeListPixmap  SelectedPixmap;
} xeListItemX11;

#define xeListItemX11Core\
	xeListItemX11  X

#else  // EX11
#define xeListItemX11Core
#endif  // EX11

#define xeListItemCore\
	EPointer       UserData;\
	uint32_t       Selected : 1,\
	               NumOfColumns : 6,        /* The number of columns is stored in the item as well for safety */\
/* Derived from Label.Sizes. Stored here to represent the total width of the column and the max height of the row if there are multiple columns. */\
	               SizeX : 12, SizeY : 12;\
	xeListItemX11Core


#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

struct xeListItem_S
{
	xeListItemCore;
};

struct XeListItemColumn_S
{
	XeLabel   Label;
	EpImage*  SelectedImage;
	uint8_t   AlignmentX;
};

typedef struct
{
	XeCoordinate  SizeX;
} XeListColumn;


//================================================================================
// Same as XeListItem_Column(), but static inline for Xe internal functions
//================================================================================
static inline XeListItemColumn* _XeListItem_Column(const xeListItem* PItem, const EIndex PColumnIndex)
{
	return((XeListItemColumn*)((uint8_t*)PItem + sizeof(xeListItem) + sizeof(XeListItemColumn) * PColumnIndex));
}

//================================
// Instance definition
//================================
// Instance part
//================================
typedef struct
{
// Resources
//
	XeColor         ForegroundColor, ItemHighlightColor;

	XeCoord2        Spacing,  ItemMarginSize;
	XeFontList      FontList;EIndex  FontListChangeCount;

	int             VisibleItemCount,
	                TopItemPosition;

	int             NColumns;               // For example "Name, Size, Type" in a FileSelectionBox
	XeListColumn*   Columns;
	XeCoordinate    ColumnSpacing;

	uint16_t        ShadowType;

	EBool           AlignStringBeginnings;  // If some entries have Images, or Images + Strings, align the beginning of all strings.
	                                        // You want to do this, in a file list, where some entries have icons, others don't, but
	                                        // you don't want to do this, if a string is used *instead* of an image (e.g. in a font list, you
	                                        // could not render the name of a font, with the font itself, so you fall back to a string, with the default font)
	EBool           ItemsAlternatingBackgroundColor;

	uint8_t         SelectionPolicy, StringAntiAliasing;


	XeCallbackList  ActivateCallback, BrowseSelectionCallback, DefaultActionCallback,
	                ExtendedSelectionCallback, MultipleSelectionCallback, SingleSelectionCallback,
	                ItemsRebuildCallback, ItemsUpdateCallback;

// Internal variables
//
	uint32_t        NColumns_Set : 1,       // NColumns was set by the application (e.g. a FileSelectionBox has Name, Size, Time columns), so don't change it when Items changes
	                RecomputeSize : 1,      // In bytes. Items have a variable size depending on the number of columns
	                ItemsPersistent : 1;
	int             MaxItemSizeY;
	xeListItem*     ActiveItem;             // Last activated Item

	EListA_s(, xeListItemPtr, Items);

	XeIntervalId    DoubleClickTimer;
	uint16_t        MultiSelectMode;int  MultiSelectAnchorItemIndex;
	uint32_t        MotionSelectEnabled : 1, ReceivedResize : 1;

#ifdef EX11
	GC              X_ListBackgroundGC;
#endif
} XeListPart;


//================================
// Instance record
//================================
typedef struct _XeListRec
{
	XeWidgetCore;
	XeBasePart       Base;
	XePrimitivePart  Primitive;
	XeListPart       List;
} XeListRec;


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

#endif // _XeListP_h
