//===============================================================================
// Xe UI toolkit
//
// XeTextField
//  Private header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-May-28 22:25:36
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//===============================================================================
#ifndef _XeTextFieldP_h
#define _XeTextFieldP_h

#include <EUndo.h>

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

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

#define XeSELECT	0x01
#define XeSCROLL	0x02
#define XeREDRAW	0x04

#define XeChgTEXT  0x0001

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

#define XeTextFieldClassCore\
	XePrimitiveClassCore

typedef struct _XeTextFieldClassRec
{
	XeTextFieldClassCore;
} XeTextFieldClassRec;

extern XeTextFieldClassRec  _XeTextField_class;


typedef struct
{
	EOperatorCore;

	XeWidget  TextFieldW;
	char*     OldString;
	wchar_t*  OldWString;
	char*     NewString;
	wchar_t*  NewWString;

	XeTextPosition  Location, OldNCharacters, NewNCharacters;
	XeTextPosition  OldCursorPosition, NewCursorPosition;
} XeOperatorEditText;


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

	int                        PreferredNumOfRows, PreferredNumOfColumns;
	int                        NumOfRows, NumOfColumns;

	int                        NumOfTextColors;
	XeCoord2                   StringAreaSize, TextMarginSize;

	XeCoord2                   StringPosition;

	XeFontList                 FontList;

	uint16_t                   ShadowType;
	uint8_t                    StringAlignmentX, StringAlignmentY;

	char                       CursorType;              // XeIBEAM, XeSOLID

	XeCoordinate               StringCenterOffsetY;
	XeCoord2                   StringSize;
	XeCoord2                   StringOffset;            // Scroll-offset in pixels. These are synchronized with TopCharacter!

	XeTextPosition             TopCharacter,			       // Character position where displaying begins
	                           CursorPosition;
	XeTextPosition             CursorCol, CursorRow;
	XeCoord2                   CursorPos;               // Cursor position in pixels

	int                        CursorBlinkRate;
	int                        UndoStepsMax;
	XeCallbackList             CursorMovedCallback, ValueChangedCallback, ModifyVerifyCallback, MotionVerifyCallback,
	                           ActivateCallback;

	EBool                      Editable, ActivateOnLeave, InsertMode,
	                           UseWString,              // Use wide-character strings (wchar_t vs. char)
	                           EditCompoundString,      // Edit the compound string / edit normal string and convert to compound for rendering
	                           CursorPositionVisible,
	                           ShadowColorsFromParentBackground;


	XeStringRenderingSettings	 StringRenderingSettings;

// Private variables
//
	EUndoStack                 UndoStack;

	uint32_t                   FontListCreated : 1,     // Default FontList was created in initialize()
	                           MotionSelectEnabled : 1;

	int                        CursorState;             // 0: off 255: on
	float                      ScrollSpeedX, ScrollSpeedY;
	XeCoord2                   CursorWPos;              // Window-relative Cursor position in pixels
	XeCoord2                   CursorSize;
	XeIntervalId               CursorTimerID, ScrollTimerID;
	EpImage*                   AACacheImage;            // For supersampling (anti-aliasing)
	XeTextPosition             StringLength,
	                           SelectionStart, SelectionEnd,
	                           SelectionAnchor;
	char*                      String;                  // This could be UTF-8
	wchar_t*                   WString;                 // X11 wide-character string (unicode)
	XeString                   CompoundString;
	EListA_s(, XeStringBinarySegment, StringBinarySegments);
	XeIntervalId               DoubleClickTimer;

	uint8_t*                   Clipboard;
	uint8_t                    ClipboardFormat;         // XeSTRING8 or XeWSTRING

	char                       ObfuscationCharacter;    // If not 0, display this character for each character. E.g. '*' for password entry.
	EpImage*                   UnderCursorImage;        // For blinking the cursor

// X11
#ifdef EX11
	Pixmap                     X_UnderCursorPixmap;     // For blinking the cursor
	XImage*                    X_UnderCursorXImage;
	GC                         X_TextDrawGC, X_CursorDrawGC;
	Pixmap                     X_AACachePixmap;         // For supersampling (anti-aliasing). This Pixmap is the same size as AACacheImage. This is how we know when we need to resize it.
#endif
} XeTextFieldPart;


//================================
// Instance record
//================================
typedef struct _XeTextFieldRec
{
	XeWidgetCore;
	XeBasePart       Base;
	XePrimitivePart  Primitive;
	XeTextFieldPart  TextField;
} XeTextFieldRec;

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

#endif // _XeTextFieldP_h
