//================================================================
// Xe UI toolkit
//
// XeLabel
// Private  header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-May-24 16:44:23
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================

#ifndef _XeLabelP_h
#define _XeLabelP_h

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

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


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

#define XeLabelClassCore\
	XePrimitiveClassCore

//================================
// Class record
//================================
typedef struct _XeLabelClassRec
{
	XeLabelClassCore;
} XeLabelClassRec;

extern XeLabelClassRec  _XeLabelWidget_class;


typedef struct
{
	XeString         String;
	XeStringMetrics  Metrics;
	XeCoord2         Size;                    // Position and centered size of the String
	EListA_s(, XeStringBinarySegment, BinarySegments);
} XeLabelString;


#ifndef XeLabel_def
#define XeLabel_def
typedef struct XeLabel_S  XeLabel;
#endif


struct XeLabel_S
{
	XeColor                 ForegroundColor;

	EpImage*                NormalImage;EIndex  NormalImageChangeCount;
	EpImage*                InsensitiveImage;

	int32_t*                ImageSizeXPtr;int32_t*  ImageSizeYPtr;

	XeCoord2                Size;                          // Total size of the Label, including the optional Image and String

	XeLabelString           String;
	XeCoord2                StringPosition;
	XeCoord2                StringOffset;                  // "Ink" offsets (used by italic fonts) and vertical centering offset

	XeCoord2                ImagePosition, ImageSize;      // Position and size of the Image

	XeCoord2                Spacing;                       // Between Image and String

	XeLabelString           AcceleratorString;
	XeCoordinate            AcceleratorStringX;

	int16_t                 ImageBlendMode;                // EpSRC_plus_DSTxONE_MINUS_ALPHA etc. Must be signed because Xe uses -1 to indicate "not set"
	int16_t                 ShadowOffset, ShadowBlur;      // Offset in pixels, blur in 1/16th pixels
	uint8_t                 Type,                          // XeSTRING, XeIMAGE, XeSTRING_IMAGE_HORIZONTAL, etc.
	                        StringAntiAliasing;
	uint8_t                 ImageResizePolicy,
	                        StringGeometryModeX;           // XeStrINK_TIGHT, XeStrADVANCE_ONLY

	XeStringRenderingSettings	 StringRenderingSettings;

	uint32_t                Verbosity : 8;

// Internal data
//
};


#ifdef EX11
typedef struct
{
	GC             StringXGC;
	Pixmap         BackgroundCacheXPixmap;  // Used for caching the background, so we can quickly change the label string, if there's no blending or anti-aliasing
	int            BackgroundCacheXPixmapSizeX, BackgroundCacheXPixmapSizeY;
	EBool          BackgroundCacheXPixmapValid;
} XeLabelPartX11;
#endif


//================================
// Instance definition
//================================
// Instance part
//================================
typedef struct
{
// Resources
//
	char*          Accelerator;

	XeCoord2       LabelPosition;

	uint16_t       ShadowType;
	uint8_t        LabelAlignmentX, LabelAlignmentY;
	char           Mnemonic;

	XeFontList		 FontList;EIndex  FontListChangeCount;

	XeLabel        Label;


// Private variables
//
	EBool          FontListCreated;

#ifdef EX11
	XeLabelPartX11 X;
#endif
} XeLabelPart;


//================================
// Instance record
//================================
typedef struct _XeLabelRec
{
	XeWidgetCore;
	XeBasePart       Base;
	XePrimitivePart  Primitive;
	XeLabelPart      Label;
} XeLabelRec;



//----------------------------------------
// Function prototypes
//----------------------------------------
extern void           _XeLabel_Init(XeLabel* PLabel);
extern void           _XeLabel_FreeContents(XeLabel* PLabel);
extern void           _XeLabel_LayoutStringAndImage(XeLabel* PLabel);
extern XeChangeFlags  _XeLabel_ValueChanged(const char* PName,  XeVisual* PVisual, XeLabel* PLabelNew, XeLabel* PLabelCurrent, XeFontList PFontList);
extern XeChangeFlags  _XeLabel_CheckFontChange(XeLabelPart* POldLabel, XeLabelPart* PLabel);
extern void           _XeLabel_Initialize(XeWidget PW, XeLabelPart* PLabel, EcRGBAiColor** PForegroundColorP,  const EArg* PArgs, const int PNArgs);

extern EChangeFlags   _XeLabel_SetString(XeVisual* PVisual, XeLabel* PLabel, XeString PString, XeFontList PFontList);

extern void           _XeLabel_Update(XeLabel* PLabel);

typedef struct
{
	const char*    API;  // EpAPI_X11, EpAPI_OpenGL etc.
#ifdef XeOpenGL
#endif

#ifdef EX11
	Drawable  XDrawable;
	GC        BackgroundXGC;
	GC        XGC;
#endif
} XeLabelDrawStruct;

extern void	 _XeLabel_Draw(XeLabel* PLabel,  EpImage* PDstImage,  const uint16_t PForegroundBlendMode, const uint16_t PAlphaOp,  const XeVisual* PVisual,  const int PDrawableSizeX, const int PDrawableSizeY,
 const int PX, int PY,  EpImage* PImage,  const EcRGBAiColor* PBackgroundColor, const EcRGBAiColor* PBackgroundColorForShadows, const EcRGBAiColor* PStringColor,
 const EBool PSensitive, const EBool PUseColorsInString,
 XeLabelDrawStruct* PData);


extern void   _XeLabel_Realize(XeWidget PW, XeRealizeCallData* PCallData, const EpImage* (*PRedrawFunc)(XeWidget PW, EpImage* PCacheImage));


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

#endif // _XeLabelP_h
