//================================================================
// Xe UI toolkit
//
// Core types
// (types that don't need system-specific GUI references, so we can include this on any platform)
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Jul-02 03:25:06
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================
#ifndef _XeTypes_h
#define _XeTypes_h

#include <ETypes.h>
#include <EClass.h>

#include <Image/Image.h>

#define XeNEWCENTRALRESIZE  1

#define XeOpenGL    1
#define XeFREETYPE  1
#define XeTHREADS   1

// Menu Button optional sub-button types
#define XeSB_DELETE   0x0001
#define XeSB_OPTIONS  0x0002

#define XeACTIVE            0x0001
#define XeARMED             0x0002
#define XeSUB_ARMED         0x0004
#define XeIN_MENUPANE       0x0008
#define XeSET               0x0010
#define XeRADIOBUTTON_MODE  0x0020

#ifdef EX11
	#include <X11/Xlib.h>
	#include <X11/Xutil.h>
	#ifndef sgi
		#include <X11/XlibConf.h>  // For XTHREADS
	#endif
#endif


#ifdef EX11
	typedef struct _XDisplay  XDisplay;
	#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
	#define Display  _XDisplay
#endif

#ifdef X_HAVE_UTF8_STRING
//#define XeX_HAVE_UTF8_STRING  1
#endif
#endif


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



#ifdef VMS
	#define externalref globalref
	#define externaldef(psect) globaldef {"psect"} noshare
#else
	#define externalref extern
	#define externaldef(psect)
#endif


typedef unsigned long  Pixel;      // Index into colormap / RGBA8 color

typedef uint32_t       XeModifiers;
typedef uint16_t       XeChangeFlags;


typedef struct _XeDisplay_S  XeDisplay;



// Visual type flags
//
#define XeVisualTRUECOLOR   0x0001
#define XeVisualCOLORINDEX  0x0002
#define XeVisualGL          0x0004


typedef struct
{
	EObjectCore(EObject);

	XeDisplay*  Display;

	uint16_t    TypeFlags;  // XeTRUECOLOR, XeCOLORINDEX etc.

	int         Depth;                            // Bits per pixel
	Pixel       RedMask, GreenMask, BlueMask;     // Bitmasks for the color channels
	int         RedShift, GreenShift, BlueShift;  // How much to shift an R, G or B value to get to it's position in the mask
	Pixel       RedTable[256], GreenTable[256], BlueTable[256];  // Channel lookup-tables

#ifdef EX11
	XVisualInfo*  X_VisualInfo;  // The X11 VisualInfo structure
	Colormap      X_Colormap;    // The (default) X11 colormap associated with this Visual
	GC            X_GC;          // Default X11 graphics context associated with this Visual
#endif // EX11
} XeVisual;



// Change indicator flags, used by SetValues methods and Xe_GeometryUpdateEnable
//
#define XeChgREDRAW               0x01
#define XeChgREDRAW_CLEAR_CACHES  0x02  // Clear / redraw any image caches
#define XeChgSIZE                 0x04
#define XeChgLAYOUT               0x08
#define XeChgCONFIGURECHILDREN    0x10
#define XeChgSETVALUES            0x20


#ifdef EX11
typedef KeyCode       XeKeyCode;

#define XeFlagX            CWX
#define XeFlagY            CWY
#define XeFlagSizeX        CWWidth
#define XeFlagSizeY        CWHeight
#define XeFlagBorderWidth  CWBorderWidth
#define XeFlagSibling      CWSibling
#define XeFlagStackMode    CWStackMode

// Addition to Xlib geometry requests: ask what would happen, don't do it
#define XeFlagQueryOnly	(1 << 7)

#define XeButton1  Button1
#define XeButton2  Button2
#define XeButton3  Button3
#define XeButton4  Button4
#define XeButton5  Button5

#define XeButton1Mask  Button1Mask
#define XeButton2Mask  Button2Mask
#define XeButton3Mask  Button3Mask
#define XeButton4Mask  Button4Mask
#define XeButton5Mask  Button5Mask

#define XeKeyPressMask            KeyPressMask
#define XeKeyReleaseMask          KeyReleaseMask
#define XeButtonPressMask         ButtonPressMask
#define XeButtonReleaseMask       ButtonReleaseMask
#define XeEnterWindowMask         EnterWindowMask
#define XeLeaveWindowMask         LeaveWindowMask
#define XeExposureMask            ExposureMask
#define XePointerMotionMask       PointerMotionMask
#define XeButton1MotionMask       Button1MotionMask
#define XeButton2MotionMask       Button2MotionMask
#define XeButton3MotionMask       Button3MotionMask
#define XeButtonMotionMask        ButtonMotionMask
#define XeFocusChangeMask         FocusChangeMask
#define XeVisibilityChangeMask    VisibilityChangeMask
#define XeStructureNotifyMask     StructureNotifyMask
#define XeSubstructureNotifyMask  SubstructureNotifyMask
#define XePropertyChangeMask      PropertyChangeMask

#define XeKeyPress          KeyPress
#define XeKeyRelease        KeyRelease
#define XeButtonPress       ButtonPress
#define XeButtonRelease     ButtonRelease
#define XeMotionNotify      MotionNotify
#define XeEnterNotify       EnterNotify
#define XeLeaveNotify       LeaveNotify
#define XeFocusIn           FocusIn
#define XeFocusOut          FocusOut
#define XeKeymapNotify      KeymapNotify
#define XeExpose            Expose
#define XeGraphicsExpose    GraphicsExpose
#define XeNoExpose          NoExpose
#define XeVisibilityNotify  VisibilityNotify
#define XeCreateNotify      CreateNotify
#define XeDestroyNotify     DestroyNotify
#define XeUnmapNotify       UnmapNotify
#define XeMapNotify         MapNotify
#define XeMapRequest        MapRequest
#define XeReparentNotify    ReparentNotify
#define XeConfigureNotify   ConfigureNotify
#define XeConfigureRequest  ConfigureRequest
#define XeGravityNotify     GravityNotify
#define XeResizeRequest     ResizeRequest
#define XeCirculateNotify   CirculateNotify
#define XeCirculateRequest  CirculateRequest
#define XePropertyNotify    PropertyNotify
#define XeSelectionClear    SelectionClear
#define XeSelectionRequest  SelectionRequest
#define XeSelectionNotify   SelectionNotify
#define XeColormapNotify    ColormapNotify
#define XeClientMessage     ClientMessage
#define XeMappingNotify     MappingNotify
#define XeGenericEvent      GenericEvent

#define XeKeySym            KeySym

#define XeVisibilityUnobscured         VisibilityUnobscured
#define XeVisibilityPartiallyObscured  VisibilityPartiallyObscured
#define XeVisibilityFullyObscured      VisibilityFullyObscured

#else

typedef uint32_t  XeKeyCode;

#define XeFlagX            0x01
#define XeFlagY            0x02
#define XeFlagSizeX        0x04
#define XeFlagSizeY        0x08
#define XeFlagBorderWidth  0x10
#define XeFlagSibling      0x20
#define XeFlagStackMode    0x40

#define XeButton1  1
#define XeButton2  2
#define XeButton3  3
#define XeButton4  4
#define XeButton5  5


#define XeButton1Mask  0x00000100
#define XeButton2Mask  0x00000200
#define XeButton3Mask  0x00000400
#define XeButton4Mask  0x00000800
#define XeButton5Mask  0x00001000

#define XeKeyPressMask       0x00000001
#define XeKeyReleaseMask     0x00000002
#define XeButtonPressMask    0x00000004
#define XeButtonReleaseMask  0x00000008

#define XeKeyPress           2
#define XeKeyRelease         3
#define XeButtonPress        4
#define XeButtonRelease      5
#define XeMotionNotify       6
#define XeEnterNotify        7
#define XeLeaveNotify        8
#define XeFocusIn            9
#define XeFocusOut          10
#define XeKeymapNotify      11
#define XeExpose            12
#define XeGraphicsExpose    13
#define XeNoExpose          14
#define XeVisibilityNotify  15
#define XeCreateNotify      16
#define XeDestroyNotify     17
#define XeUnmapNotify       18
#define XeMapNotify         19
#define XeMapRequest        20
#define XeReparentNotify    21
#define XeConfigureNotify   22
#define XeConfigureRequest  23
#define XeGravityNotify     24
#define XeResizeRequest     25
#define XeCirculateNotify   26
#define XeCirculateRequest  27
#define XePropertyNotify    28
#define XeSelectionClear    29
#define XeSelectionRequest  30
#define XeSelectionNotify   31
#define XeColormapNotify    32
#define XeClientMessage     33
#define XeMappingNotify     34
#define XeGenericEvent      35

#define XeKeySym            uint32_t

#define XeVisibilityUnobscured         0
#define XeVisibilityPartiallyObscured  1
#define XeVisibilityFullyObscured      2

#endif


typedef uint32_t  XeModifierMask;


// Direction (also used for menu posting via: 'PostMenuTo')
//
enum
{
	XeLEFT = 0,
	XeRIGHT,
	XeUP,
	XeDOWN,
	XeACTIVE_MENU_BUTTON    // Used with OptionMenus
};

#define XeARROW_LEFT   XeLEFT
#define XeARROW_RIGHT  XeRIGHT
#define XeARROW_UP     XeUP
#define XeARROW_DOWN   XeDOWN

// Orientation / layout flags
//
#define	XeHORIZONTAL    0x01
#define XeVERTICAL      0x02
#define XeTABBED_PANEL  0x04

// Placements
//
enum { XeBEFORE_SCALE = 0, XeAFTER_SCALE, XeAROUND_SCALE, XeBEFORE_TEXTFIELD, XeAFTER_TEXTFIELD };

// Redraw policies
//
enum
{
	XeRedrawNONE = 0,           // Disable redraw completely (e.g. for a known-to-be always obscured Widget)
	XeRedrawALL,                // Redraw Widget from scratch every time
	XeRedrawCACHE_BEFORE_DRAW,  // Redraw Widget into cache Pixmap, copy it to screen, then free cache Pixmap (essentially "double-buffering", to eliminate seeing individual draw operations)
	XeRedrawCACHE_ALL,          // Keep cache EpImage and Pixmap around as long as Widget is alive
	XeRedrawCACHE_DIRECT        // Draw directly into platform-dependent buffers (cache Pixmap, OpenGL texture etc.). Don't use an EpImage
};


// Child type defines for Xe...GetChild
//
enum
{
	XeDIALOG_MAIN = 0,
	XeDIALOG_WORK_AREA,
	XeDIALOG_DIR_TEXT,
	XeDIALOG_FILE_TEXT,
	XeDIALOG_FILE_LIST,
	XeDIALOG_FILTER_LIST,
	XeDIALOG_CUSTOM_ITEM,
	XeDIALOG_IMAGE_LABEL,

	XeDIALOG_NONE,           XeDIALOG_APPLY_BUTTON,
	XeDIALOG_CANCEL_BUTTON,  XeDIALOG_DEFAULT_BUTTON,
	XeDIALOG_OK_BUTTON,      XeDIALOG_FILTER_LABEL,
	XeDIALOG_FILTER_TEXT,    XeDIALOG_HELP_BUTTON,
	XeDIALOG_LIST,           XeDIALOG_LIST_LABEL,
	XeDIALOG_MESSAGE_LABEL,  XeDIALOG_SELECTION_LABEL,
	XeDIALOG_SYMBOL_LABEL,   XeDIALOG_TEXT,
	XeDIALOG_SEPARATOR,      XeDIALOG_DIR_LIST,
	XeDIALOG_DIR_LIST_LABEL,
	XeOPTION_LABEL
};



#define XeINVALID_DIMENSION  0

enum
{
	XeATTACH_NONE,
	XeATTACH_FORM,
	XeATTACH_OPPOSITE_FORM,
	XeATTACH_WIDGET,
	XeATTACH_OPPOSITE_WIDGET,
	XeATTACH_POSITION,
	XeATTACH_SELF
};


// Layout method option codes
//
enum
{
	XeINITIALIZE = 0,  // Called from the initialize method
	XeRESIZE,          // Called from the resize method
	XeSET_VALUES,      // Called from the SetValues method
	XeSET_CHILDREN,
	XeSET_CHILDREN_CONSTRAINTS,
	XeCONFIGURE_CHILDREN,
	XeMOVE_CHILDREN,
	XeCONFIGURE_ME,
	XeTEST
};

// Mouse dragging modes NONE, BUTTON1, BUTTON2, BUTTON3
//
enum { XeDRAG_NONE = 0, XeDRAG_BUTTON1, XeDRAG_BUTTON2, XeDRAG_BUTTON3 };


typedef char*           String;
typedef int32_t         XeCoordinate;
typedef unsigned int    Cardinal;

typedef struct
{
	XeCoordinate  X, Y;
}	XeCoord2;

static inline XeCoord2 XeCoord2_s(const XeCoordinate PX, const XeCoordinate PY)
{
	const XeCoord2  LV = { PX, PY };
	return(LV);
}

typedef unsigned int    XeGeometryMask;

#define XeCoordinateBIG  ((XeCoordinate)2147483647)

#ifdef CRAY
typedef long           XeEnum;
typedef long           XeClassFlags;
#else
typedef uint32_t       XeClassFlags;
typedef unsigned char  XeEnum;
#endif


#ifndef EBoolTYPE
typedef char  EBool;
#define EBoolTYPE
#endif  // EBoolTYPE


typedef union
{
	int        i32;
	long long  i64;
	float      f32;
	double     f64;
} XeValue;

// XeFIXME - this must match XrmValue on X11 platforms, for now
typedef struct
{
	unsigned int  Size;
	EPointer     Address;
} XeSizeAddr;


enum
{
	XePLAIN = 1,
	XeGRADIENT,
	XeMETAL,
	XeGLASS
};

enum
{
	XeTYPE_RGB_COLOR = 1,
	XeTYPE_RGBA_COLOR
};


#define XeMATRIX  0x0001

// Unit types
//
enum
{
	XePIXELS = 1,
	Xe100TH_MILLIMETERS,
	Xe1000TH_INCHES,
	Xe100TH_POINTS,
	Xe100TH_FONT_UNITS,
	XeCHARACTERS,
	XeTHOUSANDTHS,     // Proportional
	XeTENTHOUSANDTHS
};


// Shadow types
//
#define XeShadowNONE        0x0000
#define XeShadowOUT_LEFT    0x0001
#define XeShadowOUT_RIGHT   0x0002
#define XeShadowOUT_TOP     0x0004
#define XeShadowOUT_BOTTOM  0x0008
#define XeShadowOUT         (XeShadowOUT_LEFT|XeShadowOUT_RIGHT|XeShadowOUT_TOP|XeShadowOUT_BOTTOM)
#define XeShadowIN_LEFT     0x0010
#define XeShadowIN_RIGHT    0x0020
#define XeShadowIN_TOP      0x0040
#define XeShadowIN_BOTTOM   0x0080
#define XeShadowIN          (XeShadowIN_LEFT|XeShadowIN_RIGHT|XeShadowIN_TOP|XeShadowIN_BOTTOM)
#define XeShadowETCHED_IN   (XeShadowOUT_LEFT|XeShadowOUT_RIGHT|XeShadowOUT_TOP|XeShadowOUT_BOTTOM|XeShadowIN_LEFT|XeShadowIN_RIGHT|XeShadowIN_TOP|XeShadowIN_BOTTOM)

#define XeShadowCAST        0x0100

// Top folder tip
//
#define XeShadowOUT_TOP_TIP  (XeShadowOUT_LEFT|XeShadowOUT_RIGHT|XeShadowOUT_TOP)


#define XeShadowDIRECTION  0x01FF

#define XeShadowRESERVED   0x0200
#define XeShadowSPECIALS   (XeShadowRESERVED)



#define XeSHRINK    0x01
#define XeGROW      0x02

#define XeSHRINK_X  0x01
#define XeGROW_X    0x02
#define XeSHRINK_Y  0x04
#define XeGROW_Y    0x08


// Label type flags
//
enum
{
	XeSTRING = 0, XeIMAGE, XeIMAGE_STRING_OVERLAY, XeSTRING_IMAGE_HORIZONTAL, XeIMAGE_STRING_HORIZONTAL, XeSTRING_IMAGE_VERTICAL, XeIMAGE_STRING_VERTICAL
};


// Scale type flags
//
#define XeCUSTOM_SLIDER  0x00
#define XeSLIDER         0x01
#define XeTHERMOMETER    0x02

// Alignments
//
enum { XeAlignBEGINNING = 0, XeAlignEND, XeAlignCENTER, XeAlignJUSTIFY };

// Arrow behaviors
//
enum { XeARROW_PUSH_IN = 0, XeARROW_ALWAYS_IN };


// Common callback reasons
//
enum
{
	XeCR_NONE = 0,
	XeCR_ACTIVATE,
	XeCR_ACTIVATE_OPTIONS,
	XeCR_ACTIVATE_ALL,
	XeCR_APPLY,
	XeCR_ARM,
	XeCR_CANCEL,
	XeCR_CASCADING,
	XeCR_CLIPBOARD_DATA_DELETE,
	XeCR_CLIPBOARD_DATA_REQUEST,
	XeCR_CLOSE,
	XeCR_DISARM,
	XeCR_DRAG,
	XeCR_DEFAULT_ACTION,
	XeCR_EXECUTE,
	XeCR_EXPOSE,
	XeCR_FOCUS, XeCR_LOSING_FOCUS,
	XeCR_HELP,
	XeCR_INCREMENT, XeCR_DECREMENT,	
	XeCR_INPUT,
	XeCR_ITEMS_REBUILD,
	XeCR_ITEMS_UPDATE,            // Update cached xeListItems if, for example the fonts changed
	XeCR_MAP, XeCR_UNMAP,
	XeCR_MODIFYING_TEXT_VALUE,
	XeCR_MOVING_INSERT_CURSOR,
	XeCR_PAGE_INCREMENT, XeCR_PAGE_DECREMENT,
	XeCR_REDRAW,
	XeCR_RESIZE,
	XeCR_TO_TOP, XeCR_TO_BOTTOM,
	XeCR_OK,
	XeCR_NO_MATCH,
	XeCR_CREATE,
	XeCR_RESET,
	XeCR_TEAR_OFF_ACTIVATE,
	XeCR_TEAR_OFF_DEACTIVATE,
	XeCR_OBSCURED_TRAVERSAL,
	XeCR_PROTOCOLS,
	XeCR_VALUE_CHANGED_BEFORE_REDRAW,
	XeCR_VALUE_CHANGED,
	XeCR_SAVE,

	XeCR_SINGLE_SELECT, XeCR_MULTIPLE_SELECT, XeCR_EXTENDED_SELECT, XeCR_BROWSE_SELECT,
	XeCR_GAIN_PRIMARY, XeCR_LOSE_PRIMARY,

	XeCR_REFRESHDIR,
	XeCR_LISTTOGGLE,
	XeCR_DIRLISTTOGGLE,
	XeCR_HOSTLISTTOGGLE,
	XeCR_ADD, XeCR_ADDRESS, XeCR_DEL, XeCR_SELECT,

	XeCR_DELETE,
	XeCR_FULLSCREEN_ON,
	XeCR_FULLSCREEN_OFF,

	XeCR_CUSTOM0         // Start of Custom callback reasons
};

typedef struct
{
	String     Name;
	String     Class;
	String     Type;           // Representation type (pointer to fly-weight string. Xe does string pointer comparisons, not strcmp!)
	Cardinal   Size;           // Size in bytes of representation
	Cardinal   Offset;         // Offset from base to put resource value
	String     DefaultType;    // Representation type of the given default
	EPointer   DefaultPtr;     // Pointer to the default value
} XeResource;

#ifndef XeWidget_DEF
#define XeWidget_DEF  1
typedef struct _XeWidget_S*      XeWidget;
#endif

typedef struct XeObjectClass_S   XeObjectClass;
typedef struct XeObjectClass_S*  XeObjectClassPtr;
EListA_t(XeObjectClassPtr);

typedef struct _XeWidgetClass    XeWidgetClass;
typedef struct _XeWidgetClass*   XeWidgetClassPtr;
EListA_t(XeWidgetClassPtr);

#define XeDebugMESSAGES        0x0001
#define XeDebugERRORS          0x0002
#define XeDebugWIGET_GEOMETRY  0x0004
#define XeDebugSAVE_IMAGES     0x0008

#define XeAppCore\
	char*     Name;\
	uint32_t  DebugFlags;\
	EIndex    RedrawCount

#ifndef _XeP_h
struct XeApp_S
{
	XeAppCore;
};
#endif

typedef struct XeApp_S*      XeApp;

typedef void (*XeErrorMessageHandler)(XeApp PApp, const int PType, const char* PName, const char* PTypeName, const char* PClassName, const char* PFunction, const char* PFile, const int PLine, const char* PMessage,  const char** PParams, const int PNParams);





// Per-character font metric information.
//
typedef struct
{
//	short           LBearing;    // Origin to left edge of raster
//	short           RBearing;    // Origin to right edge of raster
	short           SizeX;       // Advance to next char's origin
//	short           Ascent;      // Baseline to top edge of raster
//	short           Descent;     // Baseline to bottom edge of raster
//	unsigned short  Attributes;  // Per char flags (not predefined)
} XeCharStruct;


typedef struct
{
	float  Ascent, Descent,
	       CapsHeight,  // Height of the capital 'E' glyph from the baseline. Used for centering text vertically in a more aesthetically pleasing way.
	       SizeX;
} XeBounds;



typedef struct XeFontFamily_S   XeFontFamily;
typedef struct XeFontFamily_S*  XeFontFamilyPtr;
EListA_t(XeFontFamilyPtr);

typedef struct XeFont_S         XeFont;
typedef struct XeFont_S*        XeFontPtr;
EListA_t(XeFontPtr);

typedef uint32_t                XeFontStyleFlags;

typedef struct
{
#ifdef EX11
	char*  X_Name;
#endif

	EBool  Remove;  // Used when re-parsing the Font database
} XeFontCharSet;


// Rasterized Glyph
//
typedef struct
{
	EInt32_2  HBearing, Size;
	EInt32_2  Advance;  // 26.6 bit fixed-point vector

	EInt16_2  BitmapSize;
	uint8_t*  BitmapPixels;
	int16_t   BitmapBytesPerLine;
	uint8_t   BitmapPixelMode;
	int16_t   BitmapTop, BitmapLeft;

	void*     FTGlyph;  // FT_Glyph is a pointer, so we can do this. This allows us to not include FreeType headers, in this low-level header
} XeGlyphRaster, *XeGlyphRasterPtr;
EListA_t(XeGlyphRasterPtr);

typedef struct
{
	XeCoord2  Size;  // Size that only includes Advance, so the "ink" may stick out to the left and/or right. See Bearing values below

// Negative numbers mean the "ink" sticks out on the left and/or right. E.g. Italics fonts might stick out.
// This is not added to Size.X because layout (e.g. centering) should be calculated based on the "visual" size.
	XeCoordinate  HBearingLeft, HBearingRight, BearingTop;

	XeCoordinate  TotalAdvanceX;
	XeCoordinate  MaxAscent, MaxDescent;

	float     LastLineMaxDescent;
	float     FirstLineMaxAccentHeight;           // Derived

	int       DebugLevel;
} XeStringMetrics;


// Font Object at a specific pixel size
//
typedef struct XeFontSize_S  XeFontSize;
struct XeFontSize_S
{
	EObjectCore(EObject);

	char*             FName;            // The name the FontSize is identified by when saving/loading preferences (AA:X-foundry-family-weight... (XLFD) for X Fonts, and AA:-Foundry-Faimly-Style for portable Fonts)

// If not NULL, this FontSize is tied to a specific Display (e.g. X11 Fonts at certain sizes. FreeType Fonts are not tied to a Display)
// XeFont and XeFontSize *both* have this field, because X11 supports scalable fonts (shown as pixel size 0 in -*-*-...)
//
	XeDisplay*        Display;

	XeFont*           Font;             // Pointer back to the Font, to which this XeFontSize belongs.

	XeBounds          MaxBounds;        // Maximum ascent, maximum descent and maximum glyph width

	char*             FileName;

	EListA_s(, XeGlyphRasterPtr, Glyphs);   // Rendered glyphs cache. It may not contain all available glyphs of the FontSize, as it may take too long to load / render all of them on startup.
	int               NAllGlyphs;           // Number of all available glyphs.
	int*              UnicodeToGlyphIndex;  // Table for finding the glyph index from a unicode codepoint. Built on demand.
	int               CodeMax;              // Largest character code that has a glyph in UnicodeToGlyphIndex
	int               CodeMaxRequested;     // Largest requested code when XeFontSize_GlyphsLoadAndRender was called for this FontSize

// Font sample Images for XeFontSelectorPanel
//
	EpImage*          SampleImage;          // 8-bit "pixel coverage" Image (without / before applying a text color)
	EpImage*          NormalImage;
	EpImage*          SelectedImage;

	float             PxSize;             // Size in pixels
	float             AAOrigPxSize;       // if it's an Image-downsampline anti-aliased bitmap font, this is the original bitmap's PxSize, otherwise this field is 0.0

	float             AntiAliasing;       // 0.0: no AA, 1.0: AA with alpha-blending (FreeType, etc.), > 1.0: Image-scaling based AA

	EListA(, XeFontCharSet*, CharSets);
	uint32_t          SysBitmap : 1,      // Has a bitmap on the system (vs. generated in runtime, from a scaleable font)
	                  Remove : 1,         // Used when re-parsing the Font database
	                  Loaded : 1;         // This FontSize was initialized from FreeType or via an .efn image

	EObject*          GPUData;            // Data for rendering text with this font on the GPU (with OpenGL, Vulkan, etc.)


#ifdef EX11
	XFontSet          X_FontSet;
#endif
};


typedef XeFontSize*  XeFontSizePtr;
EListA_t(XeFontSizePtr);


// Font style flags
//
#define XeFontWEIGHT           0x000F
#define XeFontWtEXTRALIGHT     0x0001   // 100 wt
#define XeFontWtLIGHT          0x0002   // 200 wt
#define XeFontWtDEMI           0x0003   // 300 wt
#define XeFontWtREGULAR        0x0004   // 400 wt
#define XeFontWtMEDIUM         0x0005   // 500 wt
#define XeFontWtDEMIBOLD       0x0006   // 600 wt
#define XeFontWtBOLD           0x0007   // 700 wt
#define XeFontWtBLACK          0x0008   // 800 wt
#define XeFontWtEXTRABLACK     0x0009   // 900 wt

#define XeFontSLANT            0x0070
#define XeFontSlantROMAN       0x0010
#define XeFontSlantITALIC      0x0020
#define XeFontSlantOBLIQUE     0x0040

#define XeFontSPACING          0x0700
#define XeFontSpPROPORTIONAL   0x0100
#define XeFontSpMONOSPACE      0x0200  // Uniform spacing. Glyphs may extend outside of character cell (some text renderers can't handle these and leave garbage)
#define XeFontSpCHARACTERCELL  0x0400  // Uniform spacing. Glyphs are guaranteed to fit in character cell

typedef struct
{
	char*             Name;
	XeFontStyleFlags  Flags;  // XeFontWtMEDIUM|XeFontSlantITALIC, etc. 0 means unspecified / any
} XeFontStyle;

enum
{
	XeFontSplineModeOUTLINE = 1,
	XeFontSplineModeWIRE,
	XeFontSplineModeWIRE_DOUBLE,  // Wire font represented as infinitely thin outline (doubled CVs)
};


typedef struct XeGlyph_S   XeGlyph;
typedef struct XeGlyph_S*  XeGlyphPtr;
EListA_t(XeGlyphPtr);


#define XeTag(pValue, a, b, c, d)  pValue = (((uint32_t)(a) << 24 ) | ( (uint32_t)(b) << 16) | ((uint32_t)(c) <<  8) | (uint32_t)(d))

extern const float  XeFont_FTScale;  // This makes Glyphs height ~1.0

typedef enum XeEncoding_
{
	XeTag(XeEncodingNONE, 0, 0, 0, 0),

	XeTag(XeEncodingMS_SYMBOL, 'S', 'Y', 'M', 'B'),
	XeTag(XeEncodingUNICODE,   'U', 'N', 'I', 'C'),

	XeTag(XeEncodingSJIS,    'S', 'J', 'I', 'S'),
	XeTag(XeEncodingPRC,     'G', 'B', ' ', ' '),
	XeTag(XeEncodingBIG5,    'B', 'I', 'G', '5'),
	XeTag(XeEncodingWANSUNG, 'W', 'A', 'N', 'S'),
	XeTag(XeEncodingJOHAB,   'J', 'O', 'H', 'A'),

	XeTag(XeEncodingADOBE_STANDARD, 'A', 'D', 'O', 'B'),
	XeTag(XeEncodingADOBE_EXPERT,   'A', 'D', 'B', 'E'),
	XeTag(XeEncodingADOBE_CUSTOM,   'A', 'D', 'B', 'C'),
	XeTag(XeEncodingADOBE_LATIN_1,  'L', 'A', 'T', '1'),

	XeTag(XeEncodingOLD_LATIN_2, 'L', 'A', 'T', '2'),

	XeTag(XeEncodingAPPLE_ROMAN, 'A', 'R', 'M', 'N' )
} XeEncoding;


// Character map : character code to glyph index
typedef struct
{
	XeEncoding  Encoding;
	uint16_t    PlatformID;  // As per the TrueType spec
	uint16_t    EncodingID;  // As per the TrueType spec
	EListA_s(, EIndexKeyValue, CharToGlyph);
} XeCharMap, *XeCharMapPtr;
EListA_t(XeCharMapPtr);

// Font Object. Specifies a Font style within a FontFamily
//
struct XeFont_S
{
	EObjectCore(EObject);

	XeFontFamily*     Family;          // Pointer back to the FontFamily, to which this Font (style) belongs.

// If not NULL, this *entire* Font is tied to a specific Display (e.g. X11 Fonts or certain FontSizes. FreeType and .efn Fonts are not tied to a Display)
// XeFont and XeFontSize *both* have this field, because X11 supports scalable fonts (shown as pixel size 0 in -*-*-...), so either an entire Font,
// or just some of its FontSizes may be tied to a Display.
// If only certain sizes are tied to a Display, this field is NULL
//
	XeDisplay*        Display;

	char*             FileName;
	int               FontIndexInFile;   // Font style index within a file

	XeFontStyle       Style;
	uint16_t          Spacing;           // XeFontPROPORTIONAL, XeFontMONOSPACE, or XeFontCHARACTERCELL

	XeBounds          MaxBounds;         // Maximum ascent, maximum descent and maximum glyph width

	EListA_s(, XeFontSizePtr, Sizes);    // Cached Font sizes / bitmaps
	EListA_s(, XeFontSizePtr, AASizes);  // Anti-aliased Font sizes

	EListA_s(, XeCharMapPtr, CharMaps);  // Character mappings (e.g. unicode to glyph index)
	XeCharMap*        CharMap;           // The current CharMap
	uint32_t          SysFont : 1,       // System font (e.g. X11) vs. a Font loaded with FreeType or by Xe (e.g. from a .efn file)
	                  Scaleable : 1,
	                  SplineMode : 2,    // XeFontSplineModeOUTLINE, XeFontSplineModeWIRE (non-outline vector font, used by CAD, engraving etc.) etc.
	                  Remove : 1,        // Used when re-parsing the Font database
	                  DrawWithXe;        // E.g. single-line Fonts are drawn by Xe's Spline renderer, even if this font has an FTFace

	EListA_s(, XeGlyphPtr, Glyphs);      // Spline / Face glyphs for scaleable fonts, when FreeType is not used

#ifdef XeFREETYPE
	void*             FTFace;            // FreeType font handle
	EIndex2           FTFontPixelSize;   // This keeps track of what we set with FT_Set_Pixel_Sizes(), so we don't have to call it for every Glyph
#endif

#ifdef EX11
	char*             X_Name;            // If it's a scaleable X11 Font, the X11 name, otherwise NULL
#endif
};


struct XeFontFamily_S
{
	EObjectCore(EObject);

	char*    FoundryName;
	EListA_s(, XeFontPtr, Fonts);
	EBool    Remove;         // Used when re-parsing the Font database
};



#define XeFontSTRMAX  64

typedef struct
{
	int               SizeInPixels, SizeInPoints;
	int               ResolutionX, ResolutionY;
	int               AverageWidth;
	XeFontStyleFlags  StyleFlags, Spacing;
	EBool             Scaleable;
	char              WeightStr[XeFontSTRMAX], SlantStr[XeFontSTRMAX], WidthStr[XeFontSTRMAX], AddStyleStr[XeFontSTRMAX], SpacingStr[XeFontSTRMAX];
	char              Encoding[XeFontSTRMAX], Charset[XeFontSTRMAX];
} XeFontParams;



typedef struct
{
// String to identify the Font within a FontList. These are compared as pointers and not duplicated or freed by Xe, so it's
// the application's responsibility to maintain them (e.g. global const variables, such as const char HeaderTag = "header1").
// This system allows applications to quickly and efficiently change the Fonts in existing compound strings, for example when the user changes the application preferences.
	const char*  FontTag;
	XeFontSize*  FontSize;
} XeFontListEntry;


typedef struct
{
	EListA(, XeFontListEntry*, Fonts);
	EIndex  ChangeCount;  // Indicates that the contents of this FontList have changed
} XeFontListRec;

typedef XeFontListRec*       XeFontList;       // Opaque to outside


#ifdef XeOpenGL
typedef struct
{
	EpGPUFrameBuffer*  FBO;  // GPU (OpenGL, Vulkan) framebuffer object used for drawing
} XeDisplayGLData;

#define XeDisplayCoreGL\
	XeDisplayGLData*  GL
#else
#define XeDisplayCoreGL
#endif



#ifdef EX11
#define XeDisplayCoreX11\
	Display*   X_Display;\
	Atom       XA_WM_LOCALE_NAME;        /* X Atoms for Shell Widget window manager settings  */\
	Atom       XA_WM_CLIENT_LEADER;\
	Atom       XA_WM_WINDOW_ROLE;\
	Atom       XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW;\
	Atom       XA_CLIPBOARD;\
	Atom       XA_NET_ACTIVE_WINDOW;\
	Atom       XA_TARGETS;\
	Atom       XA_WIDGETID;\
	Atom       XA_COMPOUND_TEXT, XA_UTF8_STRING;\
	Atom       XA_WM_State, XA_FullScreen;
#else
#define XeDisplayCoreX11
#endif

#define XeDisplayCore\
	int        ScreenNumber;\
	XeVisual*  DefaultVisual;\
	XeVisual*  TruecolorVisual;\
	int        MaxTrueColorBitDepth;\
	int        MaxColorIndexBitDepth;\
	XeApp      App;\
	EListA(, XeFont*, Fonts);             /* Fonts / FontSizes that are tied to this Display (X11 Fonts are tied to a Display. FreeType Fonts are not) */\
	uint16_t   FontNamesCollected : 1,    /* Fonts were collected with detals via XListFontsWithInfo (slower, but all info. Ready for use in Font selection GUI)  */\
	           FontsCollected : 1,        /* Fonts were collected, but only via XListFonts (faster, but limited use. Speed may be critical, e.g. at app startup, when trying to find a fallback Font)  */\
	           BeingFreed : 1;\
	XeDisplayCoreX11\
	XeDisplayCoreGL


// Struct that stores platform-dependent display information per XeApp
struct _XeDisplay_S
{
	XeDisplayCore;
};



typedef struct _LockRec*  LockPtr;
typedef void (*XeThreadAppFunc)(XeApp PApp);
typedef void (*XeThreadAppYieldLockFunc)(XeApp PApp, EBool* PPushThread, EBool* PPushedThread, int* PLevel);
typedef void (*XeThreadAppRestoreLockFunc)(XeApp PApp, int PLevel, EBool* PPushedThread);

typedef struct _XeFreeRec_S  _XeFreeRec;

typedef struct
{
	XeGeometryMask  RequestMode;
	XeCoord2        Position, Size;
	XeCoordinate    BorderWidth;
	XeWidget        Sibling;
	int             StackMode;  // Above, Below, TopIf, BottomIf, Opposite
} XeWidgetGeometry;


// XeEvent types
//
enum
{
	XeREDRAW = 1
};


#ifdef EX11
#define XeEventCoreX\
	unsigned long  X_Serial;  /* # of last request processed by server */
#else
#define XeEventCoreX
#endif

#define XeEventCore\
	int         Type;  /* XeKeyPress, etc. */\
	XeDisplay*  Display;\
	EBool       FromSendEvent;\
	XeEventCoreX

typedef struct
{
	int  X, Y,  SizeX, SizeY;
} XeRegion;


typedef struct
{
	XeEventCore
} XeEvent;

typedef struct
{
	XeEventCore

	ETime           Time_us;        // Time the event was processed, in microseconds

	XeKeyCode       Code;
	XeModifierMask  State;

	XeModifiers     Modifiers;
	uint32_t        KeySym;
	EInt32_2        Position;
} XeKeyEvent;



typedef struct
{
	XeEventCore

	ETime           Time_us;        // Time the event was processed, in microseconds

	int             Button;
	XeModifierMask  State;
	EInt32_2        Position, RootPosition;
} XeButtonEvent;



#define XeMAX_MOTION_SAMPLES  64

typedef struct
{
	EInt32_2  Position;
	ETime     Time_us;  // Microseconds
} XePosAndTime;

typedef struct
{
	XeEventCore

	int             Button;
	XeModifierMask  State;
	XePosAndTime    Positions[XeMAX_MOTION_SAMPLES];  // Most recent first
	int             NPositions;

#ifdef EX11
	char            X_IsHint;
#endif
} XeMotionEvent;


typedef struct
{
	XeEventCore

	int             Button;
	XeModifierMask  State;
	EInt32_2        Position;
	EBool           Focus;

#ifdef EX11
	int             X_Mode;    // NotifyNormal, NotifyGrab, NotifyUngrab
	int             X_Detail;  // NotifyAncestor, NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
#endif
} XeCrossingEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	int  X_Mode;    // NotifyNormal, NotifyWhileGrabbed, NotifyGrab, NotifyUngrab
	int  X_Detail;  // NotifyAncestor, NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual, NotifyDetailNone
#endif
} XeFocusChangeEvent;


typedef struct
{
	XeEventCore

	XeRegion  Region;
} XeRedrawEvent;


typedef struct
{
	XeEventCore

	EInt32_2  Position, Size;
	EIndex    Count;
} XeExposeEvent;

typedef struct
{
	XeEventCore

	EInt32_2  Position, Size;
	int       BorderWidth;

#ifdef EX11
	Window    X_Window;
	Window    X_SubWindow;
#endif
} XeConfigureEvent;

typedef struct
{
	XeEventCore

	EInt32_2  Position;

#ifdef EX11
	Window    X_Window;
	Window    X_ParentWindow;
#endif
} XeReparentEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Window    X_Window;
#endif
} XeMapEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Window    X_Window;
#endif
} XeUnmapEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	int  X_Request;  // One of MappingModifier, MappingKeyboard, MappingPointer
#endif
} XeMappingEvent;

typedef struct
{
	XeEventCore

	int  State;
} XeVisibilityEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Window    X_Window;
	Atom      X_Atom;
//Time      X_Time;
	int       X_State;		// NewValue, Deleted
#endif
} XePropertyEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Time  X_Time;
	Atom  X_Selection;
#endif
} XeSelectionClearEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Time       X_Time;
	XDisplay*  X_Display;
	Window     X_RequestorWindow;
	Atom       X_Selection;
	Atom       X_Target, X_Property;
#endif
} XeSelectionRequestEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Time        X_Time;
	XDisplay*   X_Display;
	Window      X_RequestorWindow;
	Atom        X_Selection;
	Atom        X_Target, X_Property;

/*
	unsigned long serial;	@* # of last request processed by server @/
	Bool send_event;	@* true if this came from a SendEvent request @/
	Display *display;	@* Display the event was read from @/
	Window requestor;
	Atom selection;
	Atom target;
	Atom property;		@* ATOM or None @/
*/
#endif
} XeSelectionEvent;

typedef struct
{
	XeEventCore

#ifdef EX11
	Atom  X_MessageType;
	int   X_Format;
	union
	{
		char   b[20];
		short  s[10];
		long   l[5];
	} X_Data;
#endif
} XeClientMessageEvent;


typedef union
{
	XeEvent                  Core;
	XeKeyEvent               Key;
	XeButtonEvent            Button;
	XeMotionEvent            Motion;
	XeCrossingEvent          Crossing;   // XeEnterNotify and XeLeaveNotify
	XeFocusChangeEvent       Focus;      // XeFocusIn, XeFocusOut
	XeExposeEvent            ExposeD;
	XeConfigureEvent         Configure;
	XeReparentEvent          Reparent;
	XeMapEvent               Map;        // Maping window
	XeUnmapEvent             Unmap;      // Unmapping window
	XeMappingEvent           Mapping;    // Keyboard mapping change
	XeVisibilityEvent        Visibility;
	XeRedrawEvent            Redraw;
	XeSelectionEvent         Selection;
	XeSelectionClearEvent    SelectionClearD;
	XeSelectionRequestEvent  SelectionRequestD;
	XePropertyEvent          Property;
	XeClientMessageEvent     Client;
} XeEventAll;


typedef unsigned long  XeEventMask;
typedef enum { XeListHead, XeListTail } XeListPosition;


typedef void    (*XeEventHandler)(XeWidget PW, XeEvent* PEvent, EPointer PClientData, EBool* PCdr);

typedef EBool   (*XeAcceptFocusFunc)(XeWidget PW, ETime* PTime);

typedef void    (*XeFunc)(void);
typedef void    (*XeObjectClassFunc)(XeObjectClass* PClass);
typedef void    (*XeWidgetClassFunc)(XeWidgetClass* PClass);
typedef void    (*XeWidgetFunc)(XeWidget PW);

typedef void    (*EArgsFunc)(XeWidget PW,  EArg* PArgs, const int PArgsN);
typedef void    (*XeInitFunc)(XeWidget PRequestW, XeWidget PNewW, const EArg* PArgs, const int PNArgs);
typedef XeChangeFlags  (*XeSetValuesFunc)(XeWidget POldW, XeWidget PRequestW, XeWidget PNewW,  const EArg* PArgs, const int PNrgs);
typedef EBool   (*EArgsFuncB)(XeWidget PW, const EArg* PArgs, const int PNArgs);
typedef void    (*XeAlmostFunc)(XeWidget POldW, XeWidget PNewW, XeWidgetGeometry* PRequestW, XeWidgetGeometry* PReply);
typedef void    (*XeRedrawFunc)(XeWidget PW, XeRedrawEvent* PEvent);
typedef void    (*XeGL_RedrawFunc)(XeWidget PW);

typedef void    (*XeCallbackFunc)(XeWidget PW, EPointer PCallData, EPointer PClientData);
typedef void    (*XeActionFunc)(XeWidget PW, XeEvent* PEvent, String* PP, Cardinal* PN);

typedef struct XeActionRec_S*  XeActionList;
typedef struct XeActionRec_S
{
	char*         String;
	XeActionFunc  Func;
} XeActionRec;


typedef enum
{
	XeGeometryYES,     // Request accepted
	XeGeometryNO,      // Request denied.
	XeGeometryALMOST,  // Request denied, but willing to take a compromise.
	XeGeometryDONE,    // Request accepted and done.
} XeGeometryResult;


typedef enum { XeGrabNone, XeGrabNonexclusive, XeGrabExclusive } XeGrabMode;


#define XeSetArg(arg, n, v)  ((void)((arg).Name = (n), (arg).Value = (EArgVal)(v)))


typedef struct
{
	EpImage*  Image_ArrowRight;
	EpImage*  Image_DialogBox;
	EpImage*  Image_Filter;

	EpImage*  Image_PushButtonLeft;
	EpImage*  Image_PushButtonMiddle;
	EpImage*  Image_PushButtonRight;

	EpImage*  Image_OptionCascadeButtonLeft;
	EpImage*  Image_OptionCascadeButtonMiddle;
	EpImage*  Image_OptionCascadeButtonRight;

	EpImage*  Image_ToggleButtonIndicator;
	EpImage*  Image_ToggleButtonIndicatorActive;
	EpImage*  Image_ToggleButtonIndicatorSet;

	EpImage*  Image_Stop;   EpImage*  Image_Stop_Active;
	EpImage*  Image_Find;   EpImage*  Image_Find_Active;
	EpImage*  Image_Replace;EpImage*  Image_Replace_Active;
	EpImage*  Image_Delete; EpImage*  Image_Delete_Active;

	EpImage*  Image_Plus;  EpImage*  Image_Plus_Active;
	EpImage*  Image_Minus; EpImage*  Image_Minus_Active;
} XeTheme;


// Generalized soft drop-shadow with optional OpenGL etc. texture.
// It can be used with a 3x3 grid that allows the edges to be stretched
//
#define XeDropShadowCore\
	EIndex    BlurRadius,         /* Corners are BlurRadius x BlurRadius pixels */\
	          EdgeLength,         /* Length of edges in pixels (to be stretched at rendering time) */\
	          Margin              /* Added to the image to make sure the blurred shadow doesn't leak out */ 

typedef struct
{
	XeDropShadowCore;
} XeDropShadow;

// PGeometryMode for _XeStringMetrics_ToSizeAndOffset()
enum
{
	XeStrINK_TIGHT = 1,
	XeStrADVANCE_ONLY
};


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

#endif // _XeTypes_h
