//===============================================================================
// Xe UI toolkit
//
// XeScale
//  Private header file
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-May-28 22:12:50
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//===============================================================================
#ifndef _XeScaleP_h
#define _XeScaleP_h

#include <Xe/ManagerP.h>
#include <Xe/LabelP.h>
#include <Xe/Scale.h>

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

//================================
// Class definition
//================================
// Class part
//================================
typedef struct _XeScaleClassPart
{
	EPointer  Extension;
} XeScaleClassPart;


//================================
// Class record
//================================
typedef struct _XeScaleClassRec
{
	XeCompositeClassCore;
	XeConstraintClassPart  Constraint;
	XeManagerClassPart     Manager;
	XeScaleClassPart       Scale;
} XeScaleClassRec;

extern XeScaleClassRec  _XeScaleWidget_class;


//================================
// Instance definition
//================================
// Instance part
//================================
typedef struct
{
// Resources
	int                TextFieldDigits;

	XeColor            LabelColor, TroughColor, SliderColor, SliderActiveColor;
	XeColor            TextBackgroundColor, TextForegroundColor, CursorColor, TextSelectionColor;
	XeColor            ActiveColor;
	XeColor            ThermoColor, ThermoStartColor, ThermoEndColor;

	EFixed             HMinimum, HMaximum, HIncrement, HValue, HResetValue, HAlignTo, HAlignOffset, ScaleHMinimum, ScaleHMaximum, ScaleHValue;

	XeValueAndRanges*  ValueAndRangesDefault;

	XeValue            Value, Minimum, Maximum, ScaleMinimum, ScaleMaximum,
	                   Increment, ResetValue,
	                   ValueFromTextField,  // Value converted back from the string in the TextField, used to see if the user really changed it.
	                   AlignTo, AlignOffset;

	XeCallbackList     DrawBackgroundCallback, ValueChangedBeforeRedrawCallback, ValueChangedCallback, ActivateCallback, TextFieldChgCallback;

	XeFontList         TextFieldFontList;

	int                ActivateOnTextChangeDelay;  // Activate (read number from textfield) after this many milliseconds of last textfield change

	uint16_t           ShadowType;
	uint16_t           RulerMode;
	uint8_t            ValueType, ScaleType, Decimals, Orientation, LabelPlacement, TextFieldPlacement, ButtonPlacement;

	EBool              ValueUndefined;
	EBool              ActivateOnLeave, CorrectOnLeave, ActivateOnTextChange;
	EBool              ScaleGroove, CreateLabel, CreateScale, CreateTextField, CreateUpButton, CreateDownButton, CreateResetButton;
	EBool              Editable,
	                   ThermoFlow;  // Applied when the thermometer pixmap is not solid, determines whether the
	                                // thermometer 'bar' is like a flowing fluid or a sliding bar

	int32_t            ScaleCornerRadius;
	EInt32_2           LabelScaleSpacing, ScaleTextFieldSpacing;
	XeCoordinate       TextFieldShadowThickness, PreferredScaleLengthInPixels, ScaleShadowThickness, ScaleWidthInPixels,
	                   SliderLengthInPixels;

	int                ScalePitWOffset;  // Offset of the scale 'pit' from the edge of the scale area (perpendicular to the scale orientation)
	int                SliderWOffset;    // Offset of the slider from the edge of the scale area (perpendicular to the scale orientation)

	EpImage*           ScaleImage;       // Cached background of the Scale Widget without the slider / thermo bar
	EpImage*           ScaleTmpImage;    // Temporary Image for the above, for compositing
	EpImage*           SliderImage;


	EBool              TextFieldSizeXAdjustable;

	XeCoordinate       ThermoGapWidth, ThermoShadowThickness;

	int                SliderBorderWidth;

	void*              ValueArray;  // For non-linear sliders, here are the values for the range
	                                // of min-max (int* or double*, depending on the ValueType)
	int                ValueCount;  // Count of values in the Values array
	int                ValueIndex;  // Index to the current value in the ValueArray

	int                  RangeCount;
	XeThermometerRange*  RangeList;



// Read-only resources
	XeWidget             TextFieldW, UpButtonW, DownButtonW, ResetButtonW;

	XeTile               ThermometerTile;


// Private variables
	XeIntervalId         TextChangeActivateTimer;
	int                  ScaleLen;
	int                  PointerLocation;  // Indicates wheter the pointer is outside, on the scale area or on the slider
	XeCoord2             ScalePosition, TextFieldPosition, ResetButtonPosition;
	int32_t              UpDownButtonX, UpButtonY, DownButtonY;
	XeCoordinate         SliderDragOffset, SliderX, SliderY,
	                     SliderWidthInPixels, SliderPositionInPixels;

	EpImage*             ThermometerImage;

	XeCoordinate         ScaleAreaWidth, SliderPreferedLength;
	XeCoord2             SetButtonSize;
	XeCoordinate         ThermoLength;

	EBool                DragMode, LabelStringCreatedFromName;
	int                  BarLengthInPixels;  // For faster redraw of the Bar

	EBool                SliderImageGiven;
} XeScalePart;


//================================
// Instance record
//================================
typedef struct _XeScaleRec
{
	XeCompositeWidgetCore;

	XeBasePart      Base;
	XeManagerPart   Manager;
	XeLabelPart     Label;
	XeScalePart     Scale;
} XeScaleRec;


extern void      _XeScale_CreateScaleImage(XeScaleWidget PEW, const EBool PForceRedraw);
extern void      _XeScale_CreateSliderImage(XeScaleWidget PEW, const EBool PCreate);
extern void      _XeScale_CreateThermometerImage(XeScaleWidget PEW);

extern void      _XeScale_ValueToString(XeScaleWidget PEW, char* PTargetStr);

extern void      _XeScale_GetPreferredSize(XeScaleWidget PEW, XeWidgetGeometry* PGeo);
extern void      _XeScale_Layout(XeScaleWidget PEW,  const int PSizeX, const int PSizeY,  const int PAction);

extern void      _XeScale_Action(XeWidget PW, XeEvent* PEvent, String* PP, Cardinal* PNP);

extern void      _XeCB_ScaleButtons(XeWidget PW, EPointer PClientData, EPointer PCallData);
extern void      _XeCB_ScaleTextField(XeWidget PW, EPointer PClientData, EPointer PCallData);

extern EpImage*  _XeScale_Redraw(XeScaleWidget PEW, EpImage* PImage, int PFlags);
extern void      _XeScale_LocatePointer(XeScaleWidget PEW,  const int PX, const int PY);

extern void      _XeScale_UpdateTextField(XeScaleWidget PEW);


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

#endif  // _XeScaleP_h
