{ ------------------------------------------------------------- }
{ Purpose : Next Collection 6                                   }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2018. All Rights Reserved.         }
{ ------------------------------------------------------------- }
{$I '..\NxSuite6.inc'}
unit NxCollection6;

interface

uses
  { Standard }
  Classes, Types, Windows, Graphics, Controls, Messages, ImgList, ComCtrls, ExtCtrls,
  {$IFDEF UI_TYPES}UITypes,{$ENDIF}
  { Next Standard 6 }
  NxConsts6, NxTypes6, NxIntf6, NxClasses6, NxControls6, NxHTML6, NxStyles6;

const
  szFlipPanelHeaderHeight = 16;
  scDashboardPanelWidth = 80;

type
  { TNxCollectionControl6 }

  TNxCollectionControl6 = class(TNxStyledControl6, INxVersionControl)
  private
    FAlpha: Byte;
    function GetControlName: string;
    function GetVersion: string;
    procedure SetAlpha(const Value: Byte);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Paint; override;
    { Windows Messages }
    procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
    procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Assign(Source: TPersistent); override;
    { Properties }
    property DoubleBuffered;
  published
    property Alpha: Byte read FAlpha write SetAlpha default 255;
    property ControlName: string read GetControlName;
    property Version: string read GetVersion;
  end;

  { TNxGlyph6 }

  TNxGlyph6 = class(TGraphicControl)
  private
    FTransparent: Boolean;
    FGlyph: TBitmap;
    procedure SetTransparent(const Value: Boolean);
    procedure SetGlyph(const Value: TBitmap);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
  published
    { Properties }
    property Glyph: TBitmap read FGlyph write SetGlyph;
    property Transparent: Boolean read FTransparent write SetTransparent default True;
  end;

  { TNxButton6 }

  TNxButtonLayout = (blGlyphBottom, blGlyphLeft, blGlyphRight, blGlyphTop);

  TNxButton6 = class(TNxCollectionControl6)
  private
    FActive: Boolean;
    FArrowSpacing: Integer;
    FCancel: Boolean;
    FDefault: Boolean;
    FDown: Boolean;
    FEnableDblClick: Boolean;
    FGlyph: TPicture;
    FGlyphSpacing: Integer;
    FImageIndex: TImageIndex;
    FImages: TImageList;
    FLayout: TNxButtonLayout;
    FModalResult: TModalResult;
    FShowArrow: Boolean;
    FState: TNxButtonState;
    FStyle: TNxAppearanceStyle;
    FTransparent: Boolean;
    { Property Accessories }
    function GetIconSize: TSize;
    procedure SetDefault(const Value: Boolean);
    procedure SetDown(const Value: Boolean);
    procedure SetEnableDblClick(const Value: Boolean);
    procedure SetGlyph(const Value: TPicture);
    procedure SetGlyphSpacing(const Value: Integer);
    procedure SetImageIndex(const Value: TImageIndex);
    procedure SetImages(const Value: TImageList);
    procedure SetLayout(const Value: TNxButtonLayout);
    procedure SetShowArrow(const Value: Boolean);
    procedure SetState(const Value: TNxButtonState);
    procedure SetStyle(const Value: TNxAppearanceStyle);
    procedure SetTransparent(const Value: Boolean);
    procedure SetArrowSpacing(const Value: Integer);
  protected
    procedure CreateWnd; override;
    { Methods }
    function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
    procedure DoGlyphChange(Sender: TObject);
    procedure DrawDropDownIndicator(Canvas: TCanvas; Dest: TRect; Size: TSize); virtual;
    function GetArrowSize: TSize; virtual;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    procedure PaintContent(Canvas: TCanvas);
    procedure PaintIcon(Canvas: TCanvas; Location: TPoint);
    { Delphi Messages }
    procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
    procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;
    procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;
    procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
	  procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
    { Windows Messages }
    procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
    procedure WMThemeChanged(var Message: TMessage); message WM_THEMECHANGED;
    { Properties }
    property State: TNxButtonState read FState write SetState;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
    procedure Click; override;
    function HasIcon: Boolean;
    { Properties }
    property ArrowSize: TSize read GetArrowSize;
    property IconSize: TSize read GetIconSize;
  published
    property ArrowSpacing: Integer read FArrowSpacing write SetArrowSpacing default pdDouble;
    property AutoSize;
    property Cancel: Boolean read FCancel write FCancel default False;
    property Caption;
    property Default: Boolean read FDefault write SetDefault default False;
    property Down: Boolean read FDown write SetDown default False;
    property EnableDblClick: Boolean read FEnableDblClick write SetEnableDblClick default True;
    property Glyph: TPicture read FGlyph write SetGlyph;
    property GlyphSpacing: Integer read FGlyphSpacing write SetGlyphSpacing default pdDouble;
    property Height default 23;
    property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
    property Images: TImageList read FImages write SetImages;
    property Layout: TNxButtonLayout read FLayout write SetLayout default blGlyphLeft;
    property ModalResult: TModalResult read FModalResult write FModalResult default 0;
    property ShowArrow: Boolean read FShowArrow write SetShowArrow default False;
    property Style: TNxAppearanceStyle read FStyle write SetStyle default stNative;
    property TabStop default True;
    property Transparent: Boolean read FTransparent write SetTransparent default False;
  end;

  { TNxTile6 }

  TNxTileLocation = class(TNxLocation)
  private
    FAnchors: TAnchors;
    procedure SetAnchors(const Value: TAnchors);
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Anchors: TAnchors read FAnchors write SetAnchors default [akLeft, akTop];
  end;

  TNxTile6 = class(TNxCollectionControl6)
  private
    FCaptionFont: TFont;
    FCaptionLocation: TNxTileLocation;
    FPicture: TPicture;
    FPictureLocation: TNxTileLocation;
    FPictureFillMode: TNxFillMode;
    { Property Accessors }
    procedure SetCaptionLocation(const Value: TNxTileLocation);
    procedure SetCaptionFont(const Value: TFont);
    procedure SetPicture(const Value: TPicture);
    procedure SetPictureLocation(const Value: TNxTileLocation);
    procedure SetPictureFillMode(const Value: TNxFillMode);
  protected
    { Event Handlers }
    procedure DoPictureChange(Sender: TObject);
    procedure Paint; override;
    { Windows Messages }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
  published
    property Caption;
    property CaptionFont: TFont read FCaptionFont write SetCaptionFont;
    property CaptionLocation: TNxTileLocation read FCaptionLocation write SetCaptionLocation;
    property Color stored True;
    property Picture: TPicture read FPicture write SetPicture;
    property PictureFillMode: TNxFillMode read FPictureFillMode write
      SetPictureFillMode default fmCenter;
    property PictureLocation: TNxTileLocation read FPictureLocation write SetPictureLocation;
    property Text;
  end;

  { TNxPanel6 }

  TNxBorders = set of (bdBottom, bdLeft, bdRight, bdTop);
  TNxPanelStyle = (pnSolid, pnGradient, pnInverseGradient);

  TNxPanel6 = class(TNxCollectionControl6)
  private
    FBorders: TNxBorders;
    FCaption: WideString;
    FEffects: TNxPaintEffects;
    FPen: TPen;
    procedure SetBorders(const Value: TNxBorders);
    procedure SetCaption(const Value: WideString);
    procedure SetEffects(const Value: TNxPaintEffects);
    procedure SetPen(const Value: TPen);
  protected
    procedure AdjustClientRect(var Rect: TRect); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure DoCaptionChange; virtual;
    procedure DoChange(Sender: TObject);
    function GetPanelRect: TRect; virtual;
    procedure Paint; override;
    { Windows Messages }
    procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
  published
    { Properties }
    property Borders: TNxBorders read FBorders write SetBorders default [bdBottom, bdLeft, bdRight, bdTop];
    property Caption: WideString read FCaption write SetCaption;
    property Effects: TNxPaintEffects read FEffects write SetEffects default [];
    property Pen: TPen read FPen write SetPen;
  end;

  { TNxFlipPanel6 }

  TNxHeaderLayout = (hlLeftToRight, hlRightToLeft);

  TNxFlipChangeArea = (faButton, faHeader, faNone);

  TNxGlyphPosition = (gpBeforeText, gpAfterText);

  TNxFlipPanel6 = class(TNxPanel6)
  private
    FCollapsedCaption: WideString;
    FExpanded: Boolean;
    FFlipChangeArea: TNxFlipChangeArea;
    FFullHeight: Integer;
    FGlyph: TPicture;
    FGlyphButtonState: TNxButtonState;
    FGlyphCollapse: TBitmap;
    FGlyphExpand: TBitmap;
    FGlyphPosition: TNxGlyphPosition;
    FHeaderBorderColor: TColor;
    FHeaderColor: TColor;
    FHeaderFont: TFont;
    FHeaderHeight: Integer;
    FHeaderIndent: Integer;
    FHeaderLayout: TNxHeaderLayout;
    FHeaderState: TNxButtonState;
    FHeaderStyle: TNxAppearanceStyle;
    FHeaderStyleOptions: TNxStyleOptions;
    FHotTrack: Boolean;
    FOnGlyphClick: TNotifyEvent;
    FPanelPadding: TPadding;
    FParentHeaderFont: Boolean;
    FShowHeader: Boolean;
    FShowToggleButton: Boolean;
    FToggleButtonStyle: TNxToggleButtonStyle;
    function GetCaptionText: WideString;
    function GetGlyphRect: TRect;
    function GetToggleButtonStyle: TNxToggleButtonStyle;
    function GetToggleSize: TSize;
    procedure SetCollapsedCaption(const Value: WideString);
    procedure SetExpanded(const Value: Boolean);
    procedure SetGlyph(const Value: TPicture);
    procedure SetGlyphCollapse(const Value: TBitmap);
    procedure SetGlyphExpand(const Value: TBitmap);
    procedure SetGlyphPosition(const Value: TNxGlyphPosition);
    procedure SetHeaderBorderColor(const Value: TColor);
    procedure SetHeaderColor(const Value: TColor);
    procedure SetHeaderFont(const Value: TFont);
    procedure SetHeaderHeight(const Value: Integer);
    procedure SetHeaderIndent(const Value: Integer);
    procedure SetHeaderLayout(const Value: TNxHeaderLayout);
    procedure SetHeaderState(const Value: TNxButtonState);
    procedure SetHeaderStyle(const Value: TNxAppearanceStyle);
    procedure SetHeaderStyleOptions(const Value: TNxStyleOptions);
    procedure SetHotTrack(const Value: Boolean);
    procedure SetPanelPadding(const Value: TPadding);
    procedure SetParentHeaderFont(const Value: Boolean);
    procedure SetShowHeader(const Value: Boolean);
    procedure SetShowToggleButton(const Value: Boolean);
    procedure SetToggleStyle(const Value: TNxToggleButtonStyle);
  protected
    { Event Handlers }
    procedure DoChange; dynamic;
    procedure DoCaptionChange; override;
    procedure DoGlyphClick(Sender: TObject); dynamic;
    procedure DoHeaderChange(Sender: TObject);
    procedure DoHeaderFontChange(Sender: TObject);
    procedure DoInnerPaddingChange(Sender: TObject);
    procedure DoPaddingChange(Sender: TObject); override;
    function GetHeaderRect: TRect; virtual;
    function GetPanelRect: TRect; override;
    function GetToggleRect: TRect; virtual;
    { Stream Methods }
    procedure DefineProperties(Filer: TFiler); override;
    procedure ReadFullHeight(Reader: TReader);
    procedure WriteFullHeight(Writer: TWriter);
    { Overrided Methods }
    procedure AdjustClientRect(var Rect: TRect); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    { Methods }
    procedure InvalidateHeader;
    procedure PaintHeader(HeaderRect: TRect); virtual;
    procedure PaintToggle(X: Integer);
    { Delphi Messages }
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
    procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    { WinApi Messages }
    procedure WMSize(var Message: TWMSize); message WM_SIZE;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
    procedure Flip;
    function HasGlyph: Boolean;
    { Properties }
    property CaptionText: WideString read GetCaptionText;
    property GlyphRect: TRect read GetGlyphRect;
    property ToggleRect: TRect read GetToggleRect;
    property ToggleSize: TSize read GetToggleSize;
    property HeaderState: TNxButtonState read FHeaderState write SetHeaderState;
  published
    { Properties }
    property CollapsedCaption: WideString read FCollapsedCaption write SetCollapsedCaption;
    property Expanded: Boolean read FExpanded write SetExpanded default True;
    property FlipChangeArea: TNxFlipChangeArea read FFlipChangeArea write FFlipChangeArea default faButton;
    property Glyph: TPicture read FGlyph write SetGlyph;
    property GlyphCollapse: TBitmap read FGlyphCollapse write SetGlyphCollapse;
    property GlyphExpand: TBitmap read FGlyphExpand write SetGlyphExpand;
    property GlyphPosition: TNxGlyphPosition read FGlyphPosition write SetGlyphPosition default gpBeforeText;
    property HeaderBorderColor: TColor read FHeaderBorderColor write SetHeaderBorderColor default clBtnShadow;
    property HeaderColor: TColor read FHeaderColor write SetHeaderColor default clBtnFace;
    property HeaderFont: TFont read FHeaderFont write SetHeaderFont;
    property HeaderHeight: Integer read FHeaderHeight write SetHeaderHeight default szFlipPanelHeaderHeight;
    property HeaderLayout: TNxHeaderLayout read FHeaderLayout write SetHeaderLayout default hlLeftToRight;
    property HeaderStyle: TNxAppearanceStyle read FHeaderStyle write SetHeaderStyle
      default stNative;
    property HeaderStyleOptions: TNxStyleOptions read FHeaderStyleOptions
      write SetHeaderStyleOptions default [soNativeStyles, soVCLStyles];
    property HeaderIndent: Integer read FHeaderIndent write SetHeaderIndent default pdDouble;
    property HotTrack: Boolean read FHotTrack write SetHotTrack default False;
    property PanelPadding: TPadding read FPanelPadding write SetPanelPadding;
    property ParentHeaderFont: Boolean read FParentHeaderFont write SetParentHeaderFont default True;
    property ShowHeader: Boolean read FShowHeader write SetShowHeader default True;
    property ShowToggleButton: Boolean read FShowToggleButton write SetShowToggleButton default True;
    property ToggleButtonStyle: TNxToggleButtonStyle read GetToggleButtonStyle write SetToggleStyle default tsTriangle;
    property OnGlyphClick: TNotifyEvent read FOnGlyphClick write FOnGlyphClick;
  end;

  { TNxPathControl6 }

  TNxPathControl6 = class(TNxCollectionControl6)

  end;

  { TNxHeaderPanel6 }
  { ToDo: call it MessagePanel6 ? }

  TNxHeaderPanel6 = class(TGraphicControl)
  private
    { Property Fields }
    FAlignment: TAlignment;
    FBorderColor: TColor;
    FCaption: WideString;
    FDivider: Boolean;
    FGlyph: TPicture;
    FHorzSpacing: Integer;
    FPadding: TPadding;
    FSchemeColors: Boolean;
    FState: TNxButtonState;
    FStaticPanel: Boolean;
    FText: WideString;
    FTransparentColor: TColor;
    FVerticalAlignment: TVerticalAlignment;
    FVertSpacing: Integer;
    FWrapKind: TNxWrapKind;
    { Property Accessors }
    procedure SetAlignment(const Value: TAlignment);
    procedure SetBorderColor(const Value: TColor);
    procedure SetCaption(const Value: WideString);
    procedure SetDivider(const Value: Boolean);
    procedure SetGlyph(const Value: TPicture);
    procedure SetHorzSpacing(const Value: Integer);
    procedure SetPadding(const Value: TPadding);
    procedure SetSchemeColors(const Value: Boolean);
    procedure SetText(const Value: WideString);
    procedure SetVerticalAlignment(const Value: TVerticalAlignment);
    procedure SetVertSpacing(const Value: Integer);
    procedure SetWrapKind(const Value: TNxWrapKind);
  protected
    procedure SetTransparentColor(const Value: TColor);
    { Event Handlers }
    procedure DoGlyphChange(Sender: TObject);
    procedure DoPaddingChange(Sender: TObject);
    { TGraphicControl }
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    { Delphi Messages }
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
	  procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    { Windows Messages }
    procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_ERASEBKGND;
    { Propertie }
    property State: TNxButtonState read FState write FState;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Action;
  	property Align;
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property Anchors;
    property BorderColor: TColor read FBorderColor write SetBorderColor default clBlack;
    property Caption: WideString read FCaption write SetCaption;
    property Color;
    property Constraints;
    property Divider: Boolean read FDivider write SetDivider default False;
    property Enabled;
    property Font;
    property Glyph: TPicture read FGlyph write SetGlyph;
    property HorzSpacing: Integer read FHorzSpacing write SetHorzSpacing default pdStandard;
    {$IFDEF PADDING}
    property Margins;
    {$ENDIF}
    property Padding: TPadding read FPadding write SetPadding;
    property ParentColor;
    property ParentFont;
    property PopupMenu;
    property SchemeColors: Boolean read FSchemeColors write SetSchemeColors default True;
    property StaticPanel: Boolean read FStaticPanel write FStaticPanel default True;
    property Text: WideString read FText write SetText;
    property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clNone;
    property VerticalAlignment: TVerticalAlignment read FVerticalAlignment write SetVerticalAlignment default taAlignTop;
    property VertSpacing: Integer read FVertSpacing write SetVertSpacing default pdStandard;
    property Visible;
    property WrapKind: TNxWrapKind read FWrapKind write SetWrapKind default wkNone;

    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

  { TNxLinkLabel6 }

  TNxLinkArea = (laClientRect, laIconAndText);

  TNxLinkLabel6 = class(TNxCollectionControl6)
  private
    FActiveStyle: TNxPaintStyle6;
    FAlignment: TAlignment;
    FCaption: WideString;
    FGlyph: TPicture;
    FHotStyle: TNxPaintStyle6;
    FImageIndex: TImageIndex;
    FImages: TCustomImageList;
    FLinkArea: TNxLinkArea;
    FState: TNxButtonState;
    FPressedStyle: TNxPaintStyle6;
    FTextSpacing: Integer;
    FTransparent: Boolean;
    FTransparentColor: TColor;
    FVerticalAlignment: TVerticalAlignment;
    { Property Accessors }
    function GetContentRect: TRect;
    function GetContentSize: TSize;
    procedure SetActiveStyle(const Value: TNxPaintStyle6);
    procedure SetAlignment(const Value: TAlignment);
    procedure SetCaption(const Value: WideString);
    procedure SetGlyph(const Value: TPicture);
    procedure SetHotStyle(const Value: TNxPaintStyle6);
    procedure SetImageIndex(const Value: TImageIndex);
    procedure SetImages(const Value: TCustomImageList);
    procedure SetPressedStyle(const Value: TNxPaintStyle6);
    procedure SetState(const Value: TNxButtonState);
    procedure SetTextSpacing(const Value: Integer);
    procedure SetTransparent(const Value: Boolean);
    procedure SetTransparentColor(const Value: TColor);
    procedure SetVerticalAlignment(const Value: TVerticalAlignment);
  protected
    procedure Changed;
    procedure DoGlyphChange(Sender: TObject);
    procedure DoPaddingChange(Sender: TObject); override;
    { TControl }
    function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    procedure SetName(const Value: TComponentName); override;
    { Delphi Messages }
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    { Windows Messages }
    procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_ERASEBKGND;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;	public
    { Properties }
    property State: TNxButtonState read FState write SetState;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure Assign(Source: TPersistent); override;
    function HasIcon: Boolean;
    { Properties }
    property ContentRect: TRect read GetContentRect;
    property ContentSize: TSize read GetContentSize;
  published
    property ActiveStyle: TNxPaintStyle6 read FActiveStyle write SetActiveStyle;
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property AutoSize default True;
    property Caption: WideString read FCaption write SetCaption;
    property Glyph: TPicture read FGlyph write SetGlyph;
    property HotStyle: TNxPaintStyle6 read FHotStyle write SetHotStyle;
    property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
    property Images: TCustomImageList read FImages write SetImages;
    property LinkArea: TNxLinkArea read FLinkArea write FLinkArea default laIconAndText;
    property PressedStyle: TNxPaintStyle6 read FPressedStyle write SetPressedStyle;
    property TextSpacing: Integer read FTextSpacing write SetTextSpacing default pdDouble;
    property Transparent: Boolean read FTransparent write SetTransparent default False;
    property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clNone;
    property VerticalAlignment: TVerticalAlignment read FVerticalAlignment write SetVerticalAlignment default taVerticalCenter;
  end;

  { TNxSplitter6 }

  TNxSplitter6 = class(TSplitter)
  private
    FGlyph: TBitmap;
    FGlyphTransparent: Boolean;
    procedure SetGlyph(const Value: TBitmap);
    procedure SetGlyphTransparent(const Value: Boolean);
  protected
  	procedure Paint; override;
    procedure DoGlyphChange(Sender: TObject);
    procedure MakeTransparent;
    { Windows Messages }
    procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_ERASEBKGND;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Glyph: TBitmap read FGlyph write SetGlyph;
    property GlyphTransparent: Boolean read FGlyphTransparent write SetGlyphTransparent default False;
    property Width default 8;
    property OnDblClick;
  end;

  { TNxHTMLLabel6 }

  TNxHTMLLabel6 = class(TGraphicControl)
  private
    FCaption: WideString;
    FOnLinkClick: TNxLinkHitEvent;
    FStylesSheet: TNxStylesSheet6;
    FTransparentSet: Boolean;
    FView: TNxHTMLView;
    { Property Accessors }
    function GetTransparent: Boolean;
    procedure SetCaption(const Value: WideString);
    procedure SetStylesSheet(const Value: TNxStylesSheet6);
    procedure SetTransparent(const Value: Boolean);
  protected
    procedure AdjustBounds; dynamic;
    function GetDefaultStyle: TNxCSSStyle;
    { Event Handlers }
    procedure DoLinkClick(Href: WideString); dynamic;
    { Overrided Methods }
    function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  	procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Properties }
    property Action;
    property Align;
    property Anchors;
    property AutoSize default False;
    property Caption: WideString read FCaption write SetCaption;
    property Color;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property StylesSheet: TNxStylesSheet6 read FStylesSheet write SetStylesSheet;
    property Transparent: Boolean read GetTransparent write SetTransparent stored FTransparentSet;
    property Visible;
    { Events }
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnLinkClick: TNxLinkHitEvent read FOnLinkClick write FOnLinkClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

  { TNxHint6 }

  TNxHint6 = class(TComponent)
  private
    FPadding: TPadding;
    FStylesSheet: TNxStylesSheet6;
    procedure SetStylesSheet(const Value: TNxStylesSheet6);
    procedure SetPadding(const Value: TPadding);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Padding: TPadding read FPadding write SetPadding;
    property StylesSheet: TNxStylesSheet6 read FStylesSheet write SetStylesSheet;
  end;

  { TNxHintWindow6 }

  TNxHintWindow6 = class(THintWindow)
  private
    FView: TNxHTMLView;
    function GetStylesSheet: TNxStylesSheet6;
  protected
    procedure AddPadding(var Rect: TRect);
    procedure CreateParams(var Params: TCreateParams); override;
    function GetDefaultStyle: TNxCSSStyle;
    function GetContentRect: TRect;
    function GetHintComponent: TNxHint6;
    procedure NCPaint(DC: HDC); override;
    procedure Paint; override;
    { Properties }
    property StylesSheet: TNxStylesSheet6 read GetStylesSheet;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Methods }
    procedure ActivateHint(Rect: TRect; const AHint: string); override;
  end;

  { TNxImage6 }

  TNxImage6 = class(TNxCollectionControl6)
  private
    FBorderPen: TPen;
    FEffects: TNxPaintEffects;
    FEmptyCaption: WideString;
    FFillMode: TNxFillMode;
    FPicture: TPicture;
    procedure SetBorderPen(const Value: TPen);
    procedure SetEffects(const Value: TNxPaintEffects);
    procedure SetEmptyCaption(const Value: WideString);
    procedure SetFillMode(const Value: TNxFillMode);
    procedure SetPicture(const Value: TPicture);
  protected
    procedure DoPaddingChange(Sender: TObject); override;
    procedure DoPictureChange(Sender: TObject);
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BorderPen: TPen read FBorderPen write SetBorderPen;
    property Effects: TNxPaintEffects read FEffects write SetEffects default [];
    property EmptyCaption: WideString read FEmptyCaption write SetEmptyCaption;
    property FillMode: TNxFillMode read FFillMode write SetFillMode default fmAspectFit;
    property Picture: TPicture read FPicture write SetPicture;
  end;

  { TNxTrackBar6 }

  TNxTrackProgress = (tpHidden, tpLeftToPosition, tpRightToPosition);

  TNxTrackBar6 = class(TNxStyledControl6)
  private
    FImages: TImageList;
    FImagesDistance: Integer;
    FMax: Double;
    FMin: Double;
    FOnChange: TNotifyEvent;
    FOnCustomDrawTrack: TNxCustomDrawEvent;
    FPosition: Double;
    FPrecision: Integer;
    FProgressColor: TColor;
    FProgressLocation: TNxTrackProgress;
    FSignsColor: TColor;
    FState: TNxButtonState;
    FStep: Double;
    FStyle: TNxAppearanceStyle;
    FThumbBorderColor: TColor;
    FThumbColor: TColor;
    FThumbSize: TNxSize;
    FTickMarks: Boolean;
    FTrackColor: TColor;
    FTrackHeight: Integer;
    function GetContentRect: TRect;
    function GetMinusRect: TRect;
    function GetPlusRect: TRect;
    function GetProgressRect: TRect;
    function GetThumbRect: TRect;
    function GetThumbSize: TSize;
    function GetTrackRect: TRect;
    function GetTrackTouchRect: TRect;
    procedure SetImages(const Value: TImageList);
    procedure SetImagesDistance(const Value: Integer);
    procedure SetMax(const Value: Double);
    procedure SetMin(const Value: Double);
    procedure SetPosition(const Value: Double);
    procedure SetPrecision(const Value: Integer);
    procedure SetProgressColor(const Value: TColor);
    procedure SetProgressLocation(const Value: TNxTrackProgress);
    procedure SetSignsColor(const Value: TColor);
    procedure SetState(const Value: TNxButtonState);
    procedure SetStep(const Value: Double);
    procedure SetStyle(const Value: TNxAppearanceStyle);
    procedure SetThumbColor(const Value: TColor);
    procedure SetThumbSize(const Value: TNxSize);
    procedure SetTickMarks(const Value: Boolean);
    procedure SetTrackColor(const Value: TColor);
    procedure SetTrackHeight(const Value: Integer);
    procedure SetThumbBorderColor(const Value: TColor);
  protected
    procedure DoChange; dynamic;
    procedure DoCustomDrawTrack(DrawingCanvas: TCanvas; DrawingRect: TRect);
    procedure DoThumbSizeChange(Sender: TObject);
    procedure Paint; override;
    procedure PaintImages;
    procedure PaintMinus(Dest: TRect);
    procedure PaintPlus(Dest: TRect);
    procedure PaintProgress(const ARect: TRect);
    procedure PaintTickMarks;
    { Keyboard }
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    { Mouse }
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); overload; override;
    { Properties }
    property State: TNxButtonState read FState write SetState;
    { Winapi }
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function GetPositionAtPos(const X, Y: Integer): Double;
    property ContentRect: TRect read GetContentRect;
    property MinusRect: TRect read GetMinusRect;
    property PlusRect: TRect read GetPlusRect;
    property ProgressRect: TRect read GetProgressRect;
    property ThumbRect: TRect read GetThumbRect;
    property TrackRect: TRect read GetTrackRect;
    property TrackTouchRect: TRect read GetTrackTouchRect;
  published
    property Images: TImageList read FImages write SetImages;
    property ImagesDistance: Integer read FImagesDistance write SetImagesDistance default pdDouble;
    property Max: Double read FMax write SetMax;
    property Min: Double read FMin write SetMin;
    property Position: Double read FPosition write SetPosition;
    property Precision: Integer read FPrecision write SetPrecision default 0;
    property ProgressColor: TColor read FProgressColor write SetProgressColor default clGray;
    property ProgressLocation: TNxTrackProgress read FProgressLocation write SetProgressLocation default tpLeftToPosition;
    property SignsColor: TColor read FSignsColor write SetSignsColor default clGray;
    property Step: Double read FStep write SetStep;
    property Style: TNxAppearanceStyle read FStyle write SetStyle default stNative;
    property ThumbBorderColor: TColor read FThumbBorderColor write SetThumbBorderColor default clBlack;
    property ThumbColor: TColor read FThumbColor write SetThumbColor default clHighlight;
    property ThumbSize: TNxSize read FThumbSize write SetThumbSize;
    property TickMarks: Boolean read FTickMarks write SetTickMarks default True;
    property TrackColor: TColor read FTrackColor write SetTrackColor default clSilver;
    property TrackHeight: Integer read FTrackHeight write SetTrackHeight default 6;
    { Events }
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    property OnCustomDrawTrack: TNxCustomDrawEvent read FOnCustomDrawTrack write FOnCustomDrawTrack;
  end;

  { TNxButtonSlider6 }

  TNxIndicatorStyle = (isHidden, isSingle, isMultiple);

  TNxButtonSlider6 = class(TNxStyledControl6)
  private
    { Proeprty Fields }
    FHotIndex: Integer;
    FImages: TImageList;
    FIndicatorColor: TColor;
    FIndicatorHeight: Integer;
    FIndicatorSpacing: Integer;
    FIndicatorStyle: TNxIndicatorStyle;
    FIndicatorWidth: Integer;
    FInnactiveIndicatorColor: TColor;
    FOnSelect: TNxIndexChangeEvent;
    FPushedIndex: Integer;
    FSelectedIndex: Integer;
    FStyle: TNxAppearanceStyle;
    FTransparent: Boolean;
    FUserDefinedStyle: TNxButtonUserDefinedStyle6;
    { Property Getters and Setters }
    function GetButtonCount: Integer;
    function GetButtonsRect: TRect;
    function GetButtonWidth: Integer;
    function GetSelectedButtonRect: TRect;
    procedure SetHotIndex(const Value: Integer);
    procedure SetImages(const Value: TImageList);
    procedure SetIndicatorColor(const Value: TColor);
    procedure SetIndicatorHeight(const Value: Integer);
    procedure SetIndicatorSpacing(const Value: Integer);
    procedure SetIndicatorStyle(const Value: TNxIndicatorStyle);
    procedure SetIndicatorWidth(const Value: Integer);
    procedure SetInnactiveIndicatorColor(const Value: TColor);
    procedure SetPushedIndex(const Value: Integer);
    procedure SetSelectedIndex(const Value: Integer);
    procedure SetStyle(const Value: TNxAppearanceStyle);
    procedure SetTransparent(const Value: Boolean);
    procedure SetUserDefinedStyle(const Value: TNxButtonUserDefinedStyle6);
  protected
    procedure DrawIndicator(const AIndicatorRect: TRect; const Index: Integer);
    procedure DoSelect(NewIndex, OldIndex: Integer);
    procedure DoUserDefinedStyleChange(Sender: TObject);
    { Overrided }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    { Mouse }
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    procedure PaintButtonContent(const AButtonRect: TRect; const Index: Integer;
      const AState: TNxButtonState); virtual;
    procedure PaintButtonFace(const AButtonRect: TRect; const Index: Integer;
      const AState: TNxButtonState); virtual;
    procedure PaintButtons(const AButtonsRect: TRect); virtual;
    procedure PaintUserDefinedStyleButton(const AButtonRect: TRect; const Index: Integer;
      const AState: TNxButtonState); virtual;
    { Messages }
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function GetButtonIndexAtPos(const X, Y: Integer): Integer;
    function GetButtonRect(const Index: Integer): TRect;
    procedure RefreshButton(const Index: Integer);
    procedure RefreshIndicators(const Index: Integer);
    property ButtonCount: Integer read GetButtonCount;
    property ButtonsRect: TRect read GetButtonsRect;
    property ButtonWidth: Integer read GetButtonWidth;
    property HotIndex: Integer read FHotIndex write SetHotIndex;
    property PushedIndex: Integer read FPushedIndex write SetPushedIndex;
    property SelectedButtonRect: TRect read GetSelectedButtonRect;
  published
    property Images: TImageList read FImages write SetImages;
    property IndicatorColor: TColor read FIndicatorColor write SetIndicatorColor default clGreen;
    property IndicatorHeight: Integer read FIndicatorHeight write SetIndicatorHeight default 2;
    property IndicatorSpacing: Integer read FIndicatorSpacing write SetIndicatorSpacing default pdDouble;
    property IndicatorStyle: TNxIndicatorStyle read FIndicatorStyle write SetIndicatorStyle default isMultiple;
    property IndicatorWidth: Integer read FIndicatorWidth write SetIndicatorWidth default 6;
    property InnactiveIndicatorColor: TColor read FInnactiveIndicatorColor write SetInnactiveIndicatorColor default clSilver;
    property SelectedIndex: Integer read FSelectedIndex write SetSelectedIndex default 0;
    property Style: TNxAppearanceStyle read FStyle write SetStyle default stNative;
    property Transparent: Boolean read FTransparent write SetTransparent default False;
    property UserDefinedStyle: TNxButtonUserDefinedStyle6 read FUserDefinedStyle write SetUserDefinedStyle;
    { Events }
    property OnSelect: TNxIndexChangeEvent read FOnSelect write FOnSelect;
  end;

  { TNxMultistateButton6 }

implementation

uses
  { Standard }
  SysUtils, Math, Forms,
  { Next Standard 6}
  NxGraphics6, NxTheme6;

{ TNxCollectionControl6 }

procedure TNxCollectionControl6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxCollectionControl6 then
  begin
    Alpha := TNxCollectionControl6(Source).Alpha;
  end;
end;

constructor TNxCollectionControl6.Create(AOwner: TComponent);
begin
  inherited;
  FAlpha := 255;
end;

procedure TNxCollectionControl6.CreateParams(var Params: TCreateParams);
begin
  inherited;
  with Params do
  begin
    if Alpha < 255 then ExStyle := ExStyle or WS_EX_TRANSPARENT;
  end;
end;

function TNxCollectionControl6.GetControlName: string;
begin
  Result := ClassName;
end;

function TNxCollectionControl6.GetVersion: string;
begin
  Result := vrNextCollection;
end;

procedure TNxCollectionControl6.Paint;
begin
  inherited;
  if Alpha < 255 then
  begin
    EraseBackground(Self, Canvas);
  end;
end;

procedure TNxCollectionControl6.SetAlpha(const Value: Byte);
var
  Update: Boolean;
begin
  if Value <> FAlpha then
  begin
    { Not solid anymore }
    Update := FAlpha = 255;

    FAlpha := Value;

    { Call CreateParams }
    if Update then RecreateWnd;

    Invalidate;
  end;
end;

procedure TNxCollectionControl6.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
  Message.Result := 1;
end;

procedure TNxCollectionControl6.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
  inherited;
  if Alpha < 255 then Invalidate;
end;

procedure TNxCollectionControl6.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  inherited;
  if Alpha < 255 then Invalidate;
end;

{ TNxGlyph6 }

procedure TNxGlyph6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxGlyph6 then
  begin
    Transparent := TNxGlyph6(Source).Transparent;
  end;
end;

constructor TNxGlyph6.Create(AOwner: TComponent);
begin
  inherited;
  FTransparent := True;
end;

destructor TNxGlyph6.Destroy;
begin
  FreeAndNil(FGlyph);
  inherited;
end;

procedure TNxGlyph6.SetGlyph(const Value: TBitmap);
begin
  FGlyph.Assign(Value);
end;

procedure TNxGlyph6.SetTransparent(const Value: Boolean);
begin
  if FTransparent <> Value then
  begin
    FTransparent := Value;

    if FTransparent
      then ControlStyle := ControlStyle - [csOpaque]
      else ControlStyle := ControlStyle + [csOpaque];

    Invalidate;
  end;
end;

{ TNxButton6 }

procedure TNxButton6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxButton6 then
  begin
    Cancel := TNxButton6(Source).Cancel;
    Default := TNxButton6(Source).Default;
    Down := TNxButton6(Source).Down;
    Glyph.Assign(TNxButton6(Source).Glyph);
    GlyphSpacing := TNxButton6(Source).GlyphSpacing;
    ImageIndex := TNxButton6(Source).ImageIndex;
    Layout := TNxButton6(Source).Layout;
    ModalResult := TNxButton6(Source).ModalResult;
    ShowArrow := TNxButton6(Source).ShowArrow;
    Style := TNxButton6(Source).Style;
    Transparent := TNxButton6(Source).Transparent;
  end;
end;

function TNxButton6.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
  Result := inherited CanAutoSize(NewWidth, NewHeight);

  Canvas.Font.Assign(Font);

  with GetTextSize(Canvas, Caption, False) do
  begin
    NewHeight := cy;
    NewWidth := cx;
  end;

  if HasIcon then
  begin
    NewHeight := Max(IconSize.cy, NewHeight);
    Inc(NewWidth, IconSize.cx + GlyphSpacing);
  end;

  if ShowArrow then
  begin
    Inc(NewWidth, ArrowSpacing);
    Inc(NewWidth, ArrowSize.cx);
  end;

  Inc(NewHeight, Padding.Top + Padding.Bottom);
  Inc(NewWidth, Padding.Left + Padding.Right);
end;

procedure TNxButton6.Click;
begin
  if Assigned(GetParentForm(Self))
    then GetParentForm(Self).ModalResult := ModalResult;

  inherited;
end;

procedure TNxButton6.CMDialogChar(var Message: TCMDialogChar);
begin
  with Message do
  begin
    if IsAccel(CharCode, Caption) then
    begin
      Click;
      Result := 1;
    end else inherited;
  end;
end;

procedure TNxButton6.CMDialogKey(var Message: TCMDialogKey);
begin
  inherited;
  with Message do
  begin
    if Enabled
      and (((CharCode = VK_RETURN) and FActive) or ((CharCode = VK_ESCAPE) and FCancel))
      and (KeyDataToShiftState(Message.KeyData) = []) then
    begin
      Click;
    end else inherited;
  end;
end;

procedure TNxButton6.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

procedure TNxButton6.CMEnter(var Message: TCMEnter);
begin
  inherited;
  Invalidate;
end;

procedure TNxButton6.CMExit(var Message: TCMExit);
begin
  inherited;
  Invalidate;
end;

procedure TNxButton6.CMFocusChanged(var Message: TCMFocusChanged);
begin
  with Message do
    if Sender is TNxButton6 then
      FActive := Sender = Self
    else
      FActive := FDefault;

  if FActive then Include(FState, bsSelected) else Exclude(FState, bsSelected);
  inherited;
end;

procedure TNxButton6.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  State := State + [bsHover];
end;

procedure TNxButton6.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  State := State - [bsHover];
end;

procedure TNxButton6.CMTextChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

constructor TNxButton6.Create(AOwner: TComponent);
begin
  inherited;
  FArrowSpacing := pdDouble;
  FCancel := False;
  FDefault := False;
  FDown := False;
  FGlyph := TPicture.Create;
  FGlyphSpacing := pdDouble;
  FImageIndex := -1;
  FImages := nil;
  FLayout := blGlyphLeft;
  FModalResult := 0;
  FShowArrow := False;
  FState := [];
  FStyle := stNative;
  FTransparent := False;

  Width := 75;
  Height := 25;
end;

procedure TNxButton6.CreateWnd;
begin
  inherited;
  FActive := FDefault;
end;

destructor TNxButton6.Destroy;
begin
  FreeAndNil(FGlyph);
  inherited;
end;

procedure TNxButton6.DoGlyphChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxButton6.DrawDropDownIndicator(Canvas: TCanvas; Dest: TRect; Size: TSize);
var
  ArrowRect: TRect;
begin
  ArrowRect := CenteredRect(Dest, Bounds(0, 0, Size.cx, Size.cy));
  with Canvas, ArrowRect do
  begin
    Brush.Color := clBlack;
    Pen.Color := Brush.Color;
    Polygon([
      Point(Left, Top),
      Point(Right, Top),
      Point(Left + (Right - Left) div 2, Bottom)
    ]);
  end;
end;

function TNxButton6.GetArrowSize: TSize;
begin
  case Style of
    stModern: Result := Size(6, 3);
    else Result := Size(8, 4);
  end;
  Result := DotToPixel(Result);
end;

function TNxButton6.GetIconSize: TSize;
begin
  with Result do
    if Assigned(Glyph)
      and Assigned(Glyph.Graphic)
      and not Glyph.Graphic.Empty then
    begin
      cx := Glyph.Width;
      cy := Glyph.Height;
    end else if Assigned(Images) then
    begin
      cx := Images.Width;
      cy := Images.Height;
    end;
end;

function TNxButton6.HasIcon: Boolean;
begin
  Result := (Assigned(FGlyph) and Assigned(FGlyph.Graphic) and not FGlyph.Graphic.Empty)
    or (Assigned(FImages) and InRange(FImageIndex, 0, Pred(FImages.Count)));
end;

procedure TNxButton6.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  State := State + [bsPressed];

  if not Focused
    then SetFocus;
end;

procedure TNxButton6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  { Note: CMMouseLeave don't trigger if
          cursor is captured by MouseDown }
  if PtInRect(ClientRect, Point(X, Y)) then
    State := State + [bsHover]
  else
    State := State - [bsHover];

end;

procedure TNxButton6.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  State := State - [bsPressed];
end;

procedure TNxButton6.Paint;
var
  Buffer: TBitmap;
begin
  inherited;

  Buffer := TBitmap.Create;

  try
    Buffer.Width := Width;
    Buffer.Height := Height;

    if Focused then Include(FState, bsSelected);

    case Style of
      stNative: TNxButtonStyle6.Paint(Buffer.Canvas, Handle, ClientRect,
                  FState, StyleOptions);
      stModern: DrawModernButton(Buffer.Canvas, ClientRect, FState);

      stUserDefined:
        with Buffer.Canvas do
        begin
          Pen.Color := BorderColor;
          Brush.Color := Color;
          Rectangle(ClientRect);
        end;
    end;

    PaintContent(Buffer.Canvas);

    Canvas.Draw(0, 0, Buffer);
  finally
    FreeAndNil(Buffer);
  end;

end;

procedure TNxButton6.PaintContent(Canvas: TCanvas);
var
  CaptionAlignment: TAlignment;
  CaptionSize: TSize;
  CaptionRect, ArrowRect: TRect;
  Spacing, ArrowLeft: Integer;
  CaptionLocation, IconLocation: TPoint;
begin
  with Canvas do
  begin
    Font.Assign(Self.Font);
    if not Enabled then Font.Color := clGrayText;

    case Style of
      stModern: ;
      stNative: Font.Color := TNxButtonStyle6.GetTextColor(Self, Font.Color, FState);
    end;

    CaptionSize := GetTextSize(Canvas, Caption, False);

    if HasIcon then
    begin

      Spacing := 0;
      if Caption <> '' then Spacing := GlyphSpacing;

      IconLocation := CenterInRect(ClientRect, IconSize.cx, IconSize.cy);

      with IconLocation do
        case Layout of
          blGlyphBottom:
          begin
            Inc(Y, CaptionSize.cy div 2);
            PaintIcon(Canvas, IconLocation);
            Dec(Y, CaptionSize.cy);
          end;

          blGlyphLeft:
          begin
            Dec(X, CaptionSize.cx div 2);
            PaintIcon(Canvas, IconLocation);
            Inc(X, IconSize.cx + Spacing);
          end;

          blGlyphTop:
          begin
            Dec(Y, CaptionSize.cy div 2);
            PaintIcon(Canvas, IconLocation);
            Inc(Y, IconSize.cy);
          end;

          else
          begin
            Inc(X, CaptionSize.cx div 2);

            PaintIcon(Canvas, IconLocation);

            Dec(X, Spacing + CaptionSize.cx);
          end;
        end;

        case Layout of
          blGlyphLeft, blGlyphRight:
          begin
            CaptionAlignment := taLeftJustify;
            CaptionRect := Bounds(IconLocation.X, 0, CaptionSize.cx, ClientHeight);

            case Layout of
              blGlyphRight: ArrowLeft := CaptionRect.Right + Spacing + IconSize.cx;
              else ArrowLeft := CaptionRect.Right;
            end;
          end else
          begin
            CaptionAlignment := Classes.taCenter;
            CaptionLocation := Point(RectWidth(ClientRect) div 2 - CaptionSize.cx div 2, IconLocation.Y);

            CaptionRect := Bounds(CaptionLocation.X, CaptionLocation.Y,
              CaptionSize.cx, CaptionSize.cy);

            ArrowLeft := CaptionRect.Right;
          end;

        end;

      { Draw Text }
      DrawTextRect(Canvas, CaptionRect, CaptionAlignment, taVerticalCenter, Caption, wkEllipsis, True)
    end else
    begin
      CaptionRect := CenteredRect(ClientRect, Bounds(0, 0, CaptionSize.cx, ClientHeight));
      ArrowLeft := CaptionRect.Right;

      DrawTextRect(Canvas, CaptionRect, Classes.taCenter, taVerticalCenter, Caption, wkEllipsis, True)
    end;

    if ShowArrow then
    begin
      ArrowRect := Bounds(ArrowLeft, 0, GetArrowSize.cx, ClientHeight);
      Inc(ArrowRect.Left, DotToPixel(ArrowSpacing));
      DrawDropDownIndicator(Canvas, ArrowRect, GetArrowSize);
    end;
  end;
end;

procedure TNxButton6.PaintIcon(Canvas: TCanvas; Location: TPoint);
begin
  if Assigned(FGlyph)
    and Assigned(FGlyph.Graphic)
    and not FGlyph.Graphic.Empty then
  begin
    Canvas.Draw(Location.X, Location.Y, FGlyph.Graphic);
  end
  else if Assigned(FImages) and InRange(FImageIndex, 0, Pred(FImages.Count)) then
  begin
    FImages.Draw(Canvas, Location.X, Location.Y, FImageIndex);
  end;
end;

procedure TNxButton6.SetArrowSpacing(const Value: Integer);
begin
  if FArrowSpacing <> Value then
  begin
    FArrowSpacing := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetDefault(const Value: Boolean);
begin
  if FDefault <> Value then
  begin
    FDefault := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetDown(const Value: Boolean);
begin
  if Value <> FDown then
  begin
    FDown := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetEnableDblClick(const Value: Boolean);
begin
  FEnableDblClick := Value;
end;

procedure TNxButton6.SetGlyph(const Value: TPicture);
begin
  FGlyph.Assign(Value);
  if Assigned(FGlyph)
    then FGlyph.OnChange := DoGlyphChange;

  Invalidate;
end;

procedure TNxButton6.SetGlyphSpacing(const Value: Integer);
begin
  if Value <> FGlyphSpacing then
  begin
    FGlyphSpacing := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetImageIndex(const Value: TImageIndex);
begin
  if Value <> FImageIndex then
  begin
    FImageIndex := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetImages(const Value: TImageList);
begin
  if Value <> FImages then
  begin
    FImages := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetLayout(const Value: TNxButtonLayout);
begin
  if Value <> FLayout then
  begin
    FLayout := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetShowArrow(const Value: Boolean);
begin
  if Value <> FShowArrow then
  begin
    FShowArrow := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetState(const Value: TNxButtonState);
begin
  if Value <> FState then
  begin
    FState := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetStyle(const Value: TNxAppearanceStyle);
begin
  if Value <> FStyle then
  begin
    FStyle := Value;
    Invalidate;
  end;
end;

procedure TNxButton6.SetTransparent(const Value: Boolean);
begin
  FTransparent := Value;
end;

procedure TNxButton6.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
  if SupportStyle([soVCLStyles]) then
    Message.Result := 1
  else
    inherited;
end;

procedure TNxButton6.WMThemeChanged(var Message: TMessage);
begin

end;

{ TNxTileLocation }

constructor TNxTileLocation.Create(AOwner: TComponent);
begin
  inherited;
  FAnchors := [akLeft, akTop];
end;

procedure TNxTileLocation.SetAnchors(const Value: TAnchors);
begin
  if Value <> FAnchors then
  begin
    FAnchors := Value;
    DoChange;
  end;
end;

{ TNxTile6 }

procedure TNxTile6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxTile6 then
  begin

  end;
end;

constructor TNxTile6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle + [csOpaque];
  DoubleBuffered := True;
  FCaptionFont := TFont.Create;
  FCaptionFont.OnChange := DoPictureChange;
  FCaptionLocation := TNxTileLocation.Create(Self);
  FCaptionLocation.OnChange := DoPictureChange;
  FPicture := TPicture.Create;
  FPicture.OnChange := DoPictureChange;
  FPictureLocation := TNxTileLocation.Create(Self);
  FPictureLocation.OnChange := DoPictureChange;
end;

destructor TNxTile6.Destroy;
begin
  { Destroy Obj. }
  FCaptionFont.Free;
  FCaptionLocation.Free;
  FPicture.Free;
  FPictureLocation.Free;
  inherited;
end;

procedure TNxTile6.DoPictureChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxTile6.Paint;
var
  CaptionRect: TRect;
  CaptionSize: TSize;
  PictureRect: TRect;
begin
  inherited;

  { AlphaBlend }
  ColorOverlay(Canvas, ClientRect, Color, Alpha);

  { Picture }
  if Assigned(Picture.Graphic) then
  begin
    PictureRect := AnchorRect(PaddingRect, Size(Picture.Graphic.Width,
      Picture.Graphic.Height),
      PictureLocation.Anchors,
      Point(PictureLocation.X, PictureLocation.Y));

    PaintGraphic(Canvas, Picture.Graphic, PictureRect, PictureFillMode);
  end;

  { Caption }
  Canvas.Font.Assign(FCaptionFont);

  CaptionSize := GetTextSize(Canvas, Caption, True);

  CaptionRect := AnchorRect(PaddingRect, CaptionSize,
    CaptionLocation.Anchors,
    Point(CaptionLocation.X, CaptionLocation.Y));

  DrawTextRect(Canvas, CaptionRect, Classes.taCenter, taVerticalCenter, Caption, wkNone);
end;

procedure TNxTile6.SetCaptionFont(const Value: TFont);
begin
  FCaptionFont.Assign(Value);
  FCaptionFont.OnChange := DoPictureChange;
end;

procedure TNxTile6.SetCaptionLocation(const Value: TNxTileLocation);
begin
  FCaptionLocation.Assign(Value);
  FCaptionLocation.OnChange := DoPictureChange;
end;

procedure TNxTile6.SetPicture(const Value: TPicture);
begin
  FPicture.Assign(Value);
  FPicture.OnChange := DoPictureChange;
end;

procedure TNxTile6.SetPictureFillMode(const Value: TNxFillMode);
begin
  if Value <> FPictureFillMode then
  begin
    FPictureFillMode := Value;
    Invalidate;
  end;
end;

procedure TNxTile6.SetPictureLocation(const Value: TNxTileLocation);
begin
  FPictureLocation.Assign(Value);
  Invalidate;
end;

{ TNxPanel6 }

procedure TNxPanel6.AdjustClientRect(var Rect: TRect);
begin
  inherited;
{$IFNDEF PADDING}
  Inc(Rect.Top, Padding.Top);
  Inc(Rect.Left, Padding.Left);
  Dec(Rect.Bottom, Padding.Bottom);
  Dec(Rect.Right, Padding.Right);
{$ENDIF}
end;

procedure TNxPanel6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxPanel6 then
  begin
    Borders := TNxPanel6(Source).Borders;
    Pen.Assign(TNxPanel6(Source).Pen);
  end;
end;

constructor TNxPanel6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
    csDoubleClicks, csReplicatable, csSetCaption];

  FBorders := [bdBottom, bdLeft, bdRight, bdTop];
  FEffects := [];
  FPen := TPen.Create;
end;

procedure TNxPanel6.CreateParams(var Params: TCreateParams);
begin
  inherited;
  with Params do
  begin
    with WindowClass do Style := Style and not CS_HREDRAW and not CS_VREDRAW;
  end;
end;

destructor TNxPanel6.Destroy;
begin
  FreeAndNil(FPen);
  inherited;
end;

procedure TNxPanel6.DoCaptionChange;
begin

end;

procedure TNxPanel6.DoChange(Sender: TObject);
begin
  Invalidate;
end;

function TNxPanel6.GetPanelRect: TRect;
begin
  Result := ClientRect;
end;

procedure TNxPanel6.Paint;
var
  FillColor: TColor;
begin
  inherited;
  { Panel (content) paint }
  if RectInRect(ClientRect, GetPanelRect) then
  begin
    { Default, no style }
    FillColor := Color;

    { Only Delphi Style can have own color }
    if CanStyle(soVCLStyles) then
    begin
      FillColor := TNxPanelStyle6.GetFillColor(Self, FillColor);
    end;

    { Fill with Color }
    ColorOverlay(Canvas, GetPanelRect, FillColor, Alpha);

    { Apply Filters & Effects }
    PaintEffects(Canvas, GetPanelRect, Effects);
  end;
end;

procedure TNxPanel6.SetBorders(const Value: TNxBorders);
begin
  if Value <> FBorders then
  begin
    FBorders := Value;
    Invalidate;
  end;
end;

procedure TNxPanel6.SetCaption(const Value: WideString);
begin
  if Value <> FCaption then
  begin
    FCaption := Value;

    { Virtual }
    DoCaptionChange;
  end;
end;

procedure TNxPanel6.SetEffects(const Value: TNxPaintEffects);
begin
  if Value <> FEffects then
  begin
    FEffects := Value;
    Invalidate;
  end;
end;

procedure TNxPanel6.SetPen(const Value: TPen);
begin
  FPen.Assign(Value);

  if Assigned(FPen)
    then FPen.OnChange := DoChange;

  Invalidate;
end;

procedure TNxPanel6.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
  Message.Result := 1;
end;

procedure TNxPanel6.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
  inherited;

end;

{ TNxFlipPanel6 }

procedure TNxFlipPanel6.AdjustClientRect(var Rect: TRect);
begin
  inherited;
  Inc(Rect.Top, FHeaderHeight + FPanelPadding.Top);
  Inc(Rect.Left, FPanelPadding.Left);
  Dec(Rect.Bottom, FPanelPadding.Bottom);
  Dec(Rect.Right, FPanelPadding.Right);
end;

procedure TNxFlipPanel6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxFlipPanel6 then
  begin
    CollapsedCaption := TNxFlipPanel6(Source).CollapsedCaption;
    Expanded := TNxFlipPanel6(Source).Expanded;
    FlipChangeArea := TNxFlipPanel6(Source).FlipChangeArea;
    Glyph.Assign(TNxFlipPanel6(Source).Glyph);
    GlyphCollapse.Assign(TNxFlipPanel6(Source).Glyph);
    GlyphExpand.Assign(TNxFlipPanel6(Source).Glyph);
    GlyphPosition := TNxFlipPanel6(Source).GlyphPosition;
    HeaderBorderColor := TNxFlipPanel6(Source).HeaderBorderColor;
    HeaderColor := TNxFlipPanel6(Source).HeaderColor;
    HeaderFont.Assign(TNxFlipPanel6(Source).HeaderFont);
    HeaderHeight := TNxFlipPanel6(Source).HeaderHeight;
    HeaderIndent := TNxFlipPanel6(Source).HeaderIndent;
    HeaderStyle := TNxFlipPanel6(Source).HeaderStyle;
    HotTrack := TNxFlipPanel6(Source).HotTrack;
    ParentHeaderFont := TNxFlipPanel6(Source).ParentHeaderFont;
    ShowHeader := TNxFlipPanel6(Source).ShowHeader;
    ShowToggleButton := TNxFlipPanel6(Source).ShowToggleButton;
    ToggleButtonStyle := TNxFlipPanel6(Source).ToggleButtonStyle;
  end;
end;

procedure TNxFlipPanel6.CMDialogChar(var Message: TCMDialogChar);
begin
  inherited;
  with Message do
  begin
    if IsAccel(CharCode, CaptionText) then
    begin
      Flip;
      Result := 1;
    end else inherited;
  end;
end;

procedure TNxFlipPanel6.CMFontChanged(var Message: TMessage);
begin
  inherited;
  if ParentHeaderFont then
  begin
    HeaderFont.OnChange := nil;
    HeaderFont := Font;
  end;
end;

procedure TNxFlipPanel6.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  HeaderState := HeaderState - [bsHover];
end;

procedure TNxFlipPanel6.CMTextChanged(var Message: TMessage);
begin
  inherited;
end;

constructor TNxFlipPanel6.Create(AOwner: TComponent);
begin
  inherited;
  FCollapsedCaption := '';
  FExpanded := True;
  FFlipChangeArea := faButton;
  FGlyph := TPicture.Create;
  FGlyph.OnChange := DoHeaderChange;
  FGlyphButtonState := [];
  FGlyphCollapse := TBitmap.Create;
  FGlyphCollapse.OnChange := DoHeaderChange;
  FGlyphExpand := TBitmap.Create;
  FGlyphExpand.OnChange := DoHeaderChange;
  FGlyphPosition := gpBeforeText;
  FHeaderBorderColor := clBtnShadow;
  FHeaderColor := clBtnFace;
  FHeaderFont := TFont.Create;
  FHeaderFont.OnChange := DoHeaderFontChange;
  FHeaderHeight := szFlipPanelHeaderHeight;
  FHeaderIndent := pdDouble;
  FHeaderLayout := hlLeftToRight;
  FHeaderState := [];
  FHeaderStyle := stNative;
  FHeaderStyleOptions := [soNativeStyles, soVCLStyles];
  FHotTrack := False;
  FPanelPadding := TPadding.Create(nil);
  FPanelPadding.OnChange := DoInnerPaddingChange;
  FParentHeaderFont := True;
  FShowToggleButton := True;
  FShowHeader := True;
  FToggleButtonStyle := tsTriangle;
  Height := 128;
  Width := 128;
end;

procedure TNxFlipPanel6.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    with WindowClass do Style := Style or CS_HREDRAW or CS_VREDRAW;
  end;
end;

procedure TNxFlipPanel6.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineProperty('FullHeight', ReadFullHeight, WriteFullHeight, True);
end;

destructor TNxFlipPanel6.Destroy;
begin
  FreeAndNil(FGlyph);
  FreeAndNil(FGlyphCollapse);
  FreeAndNil(FGlyphExpand);
  FreeAndNil(FHeaderFont);
  FreeAndNil(FPanelPadding);
  inherited;
end;

procedure TNxFlipPanel6.DoCaptionChange;
begin
  InvalidateHeader;
end;

procedure TNxFlipPanel6.DoChange;
begin

end;

procedure TNxFlipPanel6.DoGlyphClick(Sender: TObject);
begin
  if Assigned(FOnGlyphClick) then FOnGlyphClick(Self);
end;

procedure TNxFlipPanel6.DoHeaderChange(Sender: TObject);
begin
  InvalidateHeader;
end;

procedure TNxFlipPanel6.DoHeaderFontChange(Sender: TObject);
begin
  if not (csLoading in ComponentState) then
  begin
    FParentHeaderFont := False;
  end;

  InvalidateHeader;
end;

procedure TNxFlipPanel6.DoInnerPaddingChange(Sender: TObject);
begin
  Invalidate;
  Realign;
end;

procedure TNxFlipPanel6.DoPaddingChange(Sender: TObject);
begin
  inherited;
  Invalidate;
end;

procedure TNxFlipPanel6.Flip;
begin
  Expanded := not Expanded;
end;

function TNxFlipPanel6.GetToggleButtonStyle: TNxToggleButtonStyle;
begin
  Result := FToggleButtonStyle;
end;

function TNxFlipPanel6.GetToggleRect: TRect;
var
  Y: Integer;
begin
  Y := Ceil(HeaderHeight / 2) - Ceil(ToggleSize.cy / 2);

  case FHeaderLayout of
    hlLeftToRight: Result := Bounds(FHeaderIndent, Y, ToggleSize.cx, ToggleSize.cy);
    hlRightToLeft: Result := Bounds(ClientWidth - FHeaderIndent - ToggleSize.cx, Y, ToggleSize.cx, ToggleSize.cy);
  end;
end;

function TNxFlipPanel6.GetToggleSize: TSize;
var
  D: Integer;
begin
  case FToggleButtonStyle of
    tsStyleNative: Result := Size(9, 9);
    tsTriangle:
    begin
      D := Round(HeaderHeight / 2.66);
      Result := Size(D, D);
    end;
    tsSquare: Result := Size(9, 9);
    tsGlyph:
    begin
      if Expanded and Assigned(GlyphCollapse)
        then Result := Size(GlyphCollapse.Width, GlyphCollapse.Height)
      else if Assigned(GlyphExpand)
        then Result := Size(GlyphExpand.Width, GlyphExpand.Height);
    end;
  end;
end;

function TNxFlipPanel6.HasGlyph: Boolean;
begin
  Result := Assigned(Glyph) and Assigned(Glyph.Graphic) and not Glyph.Graphic.Empty;
end;

function TNxFlipPanel6.GetCaptionText: WideString;
begin
  Result := Caption;
  if not Expanded and (FCollapsedCaption <> '') then Result := FCollapsedCaption;
end;

function TNxFlipPanel6.GetGlyphRect: TRect;
var
  Location, GlyphLocation: TPoint;
begin
  case HeaderLayout of
    hlLeftToRight: Location := Point(HeaderIndent, 0);
    hlRightToLeft: Location := Point(ClientWidth - HeaderIndent, 0);
  end;

  { Toggle button }
  if ShowToggleButton then
  begin
    if HeaderLayout = hlRightToLeft then Dec(Location.X, ToggleSize.cx);

    { Spacing }
    case FHeaderLayout of
      hlLeftToRight: Inc(Location.X, pdDouble + ToggleSize.cx);
      hlRightToLeft: Dec(Location.X, pdDouble);
    end;
  end;

  if HasGlyph then
  begin
    GlyphLocation := Location;

    case GlyphPosition of
      gpAfterText:
      begin
        case FHeaderLayout of
          hlLeftToRight: GlyphLocation.X := GetHeaderRect.Right - FGlyph.Width - pdDouble;
          hlRightToLeft: GlyphLocation.X := pdDouble;
        end;
      end;

      gpBeforeText:
      begin
        if HeaderLayout = hlRightToLeft
          then Dec(GlyphLocation.X, FGlyph.Width);

        case HeaderLayout of
          hlLeftToRight: Inc(Location.X, FGlyph.Width + pdDouble);
          hlRightToLeft: Dec(Location.X, FGlyph.Width + pdDouble);
        end;
      end;
    end;

    GlyphLocation.Y := HeaderHeight div 2 - FGlyph.Height div 2;

    Result := Bounds(GlyphLocation.X, GlyphLocation.Y, FGlyph.Width, FGlyph.Height);
  end;
end;

function TNxFlipPanel6.GetHeaderRect: TRect;
begin
  Result := Bounds(0, 0, ClientWidth, HeaderHeight);
end;

function TNxFlipPanel6.GetPanelRect: TRect;
begin
  Result := inherited GetPanelRect;
  Inc(Result.Top, HeaderHeight);
end;

procedure TNxFlipPanel6.InvalidateHeader;
begin
  InvalidateRect(GetHeaderRect);
end;

procedure TNxFlipPanel6.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  if PtInRect(GetHeaderRect, Point(X, Y)) then
  begin
    HeaderState := HeaderState + [bsPressed];
    if PtInRect(GlyphRect, Point(X, Y)) then Include(FGlyphButtonState, bsPressed);
  end;
end;

procedure TNxFlipPanel6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  if HotTrack and PtInRect(GetHeaderRect, Point(X, Y))
  then
    HeaderState := HeaderState + [bsHover]
  else
    HeaderState := HeaderState - [bsHover];
end;

procedure TNxFlipPanel6.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  CanFlip: Boolean;
begin
  inherited;

  CanFlip := False;

  case FlipChangeArea of
    faButton: CanFlip := ShowToggleButton and PtInRect(GetToggleRect, Point(X, Y));
    faHeader: CanFlip := PtInRect(GetHeaderRect, Point(X, Y));
    faNone: ;
  end;

  { Set Expanded }
  if CanFlip then Flip;

  if bsPressed in FGlyphButtonState then
  begin
    Exclude(FGlyphButtonState, bsPressed);
    if PtInRect(GlyphRect, Point(X, Y))
      then DoGlyphClick(Self);
  end;

  HeaderState := HeaderState - [bsPressed];
end;

procedure TNxFlipPanel6.Paint;
var
  PanelRect: TRect;
  PaddingColor: TColor;
begin
  inherited Paint;
  if csDesigning in ComponentState then
  begin
    PanelRect := ClientRect;
    Inc(PanelRect.Top, FHeaderHeight);

    PaddingColor := IfThen(IsColorLight(Color), DarkerColor(Color, 5), LighterColor(Color, 25));

    FillPadding(Canvas, PaddingColor, PanelRect, PanelPadding);

  end;
  PaintHeader(GetHeaderRect);
end;

procedure TNxFlipPanel6.PaintToggle(X: Integer);
var
  Y, C: Integer;
  Bitmap: TBitmap;
begin
  Y := FHeaderHeight div 2;

  with Canvas do
    case FToggleButtonStyle of
      tsStyleNative:
        begin
          TNxTreeStyledView6.PaintToggle(Canvas, Self.Handle, ToggleRect,
            Expanded, HeaderState, HeaderStyleOptions);
        end;

      tsTriangle:
        if Expanded then
        begin
          Y := Y - ToggleSize.cy div 2;

          if bsHover in FHeaderState then
          begin
            Brush.Color := ColorOf(seMenu);
          end else
          begin
            Brush.Color := $00444444;
          end;
          Pen.Color := Brush.Color;

          C := ToggleSize.cy - 1;

          Polygon([
            Point(X, Y + C),
            Point(X + C, Y + C),
            Point(X + C, Y),
            Point(X, Y + C)
          ]);
        end else
        begin
          Y := Y - Pred(ToggleSize.cy);

          if bsHover in FHeaderState then
          begin
            Brush.Color := ColorOf(seBtnFramePressed);
            Pen.Color := Brush.Color;
          end else
          begin
            Brush.Color := clWhite;
            Pen.Color := $00888683;
          end;

          Polygon([
            Point(X, Y),
            Point(X + ToggleSize.cx - 2, Y + ToggleSize.cx - 2),
            Point(X, Y + (ToggleSize.cx - 2) * 2),
            Point(X, Y)
          ]);
        end;
      tsSquare:
      begin
        Pen.Color := clGray;
        Brush.Color := HeaderColor;
        Rectangle(ToggleRect);

        C := Floor(ToggleSize.cx / 2);
        Polyline([
          Point(ToggleRect.Left + 2, ToggleRect.Top + C),
          Point(ToggleRect.Right - 2, ToggleRect.Top + C)
        ]);
        if not Expanded then
          Polyline([
            Point(ToggleRect.Left + C, ToggleRect.Top + 2),
            Point(ToggleRect.Left + C, ToggleRect.Bottom - 2)
          ]);
      end;
      tsGlyph:
      begin
        Bitmap := nil;

        Y := Floor(HeaderHeight / 2) - Floor(ToggleSize.cy / 2);
        if Expanded and Assigned(GlyphCollapse)
          then Bitmap := GlyphCollapse
        else if Assigned(GlyphExpand)
          then Bitmap := GlyphExpand;

        if Assigned(Bitmap) then
        begin
          Bitmap.TransparentColor := Bitmap.Canvas.Pixels[0, Bitmap.Height - 1];
          Bitmap.Transparent := True;
          Draw(X, Y, Bitmap);
        end;
      end;
    end;
end;

procedure TNxFlipPanel6.PaintHeader(HeaderRect: TRect);
var
  Location, GlyphLocation: TPoint;
  CaptionRect: TRect;
  CaptionAlignment: TAlignment;
begin
  with Canvas do
  begin

    { Background }
    if (not HotTrack)
      or (FHeaderState <> []) then
    begin

      case FHeaderStyle of
        stNative:
          if SupportStyle(HeaderStyleOptions) then
          begin
            TNxHeaderStyle6.Paint(Canvas, Self.Handle, HeaderRect,
              HeaderState, HeaderStyleOptions);
          end else
          begin
            Brush.Color := HeaderColor;
            FillRect(HeaderRect);
          end;

        stUserDefined:
        begin
          Brush.Color := HeaderColor;
          Pen.Color := HeaderBorderColor;
          Rectangle(HeaderRect);
        end;

        stModern:
        begin
          Brush.Color := HeaderColor;

          if bsHover in FHeaderState
            then Brush.Color := ColorOf(seBtnFace);

          if bsPressed in FHeaderState
            then Brush.Color := ColorOf(seBtnFacePressed);

          if Expanded then
          begin
            Pen.Color := ColorOf(seBtnFacePressed);
            Rectangle(HeaderRect);
          end
          else FillRect(HeaderRect);
        end;

      end;

    end else
    begin
      Brush.Color := Color;
      FillRect(HeaderRect);
    end;

    case FHeaderLayout of
      hlLeftToRight: Location := Point(FHeaderIndent, 0);
      hlRightToLeft: Location := Point(ClientWidth - FHeaderIndent, 0);
    end;

    { Button }
    if ShowToggleButton then
    begin

      if FHeaderLayout = hlRightToLeft then Dec(Location.X, ToggleSize.cx);

      PaintToggle(Location.X);

      case FHeaderLayout of
        hlLeftToRight: Inc(Location.X, pdDouble + ToggleSize.cx);
        hlRightToLeft: Dec(Location.X, pdDouble);
      end;

    end;

    { Icon }

    if Assigned(FGlyph)
      and Assigned(FGlyph.Graphic)
      and not FGlyph.Graphic.Empty then
    begin

      GlyphLocation := Location;

      case GlyphPosition of
        gpAfterText:
        begin
          case FHeaderLayout of
            hlLeftToRight: GlyphLocation.X := HeaderRect.Right - FGlyph.Width - pdDouble;
            hlRightToLeft: GlyphLocation.X := pdDouble;
          end;
        end;

        gpBeforeText:
        begin
          if FHeaderLayout = hlRightToLeft
            then Dec(GlyphLocation.X, FGlyph.Width);

          case FHeaderLayout of
            hlLeftToRight: Inc(Location.X, FGlyph.Width + pdDouble);
            hlRightToLeft: Dec(Location.X, FGlyph.Width + pdDouble);
          end;
        end;

      end;

      GlyphLocation.Y := HeaderHeight div 2 - FGlyph.Height div 2;

      Canvas.Draw(GlyphLocation.X, GlyphLocation.Y, FGlyph.Graphic);

    end;

    { Title }
    Font.Assign(HeaderFont);

    case FHeaderLayout of
      hlLeftToRight:
      begin
        CaptionRect := Rect(Location.X, 0, ClientWidth, FHeaderHeight);
        CaptionAlignment := taLeftJustify;
      end;
      else
      begin
        CaptionRect := Rect(0, 0, Location.X, FHeaderHeight);
        CaptionAlignment := taRightJustify;
      end;
    end;

    DrawTextRect(Canvas, CaptionRect, CaptionAlignment, taVerticalCenter, CaptionText, wkEllipsis);

  end;

end;

procedure TNxFlipPanel6.ReadFullHeight(Reader: TReader);
begin
  FFullHeight := Reader.ReadInteger;
  if not FExpanded then
  begin
    Height := FHeaderHeight;
  end else Height := FFullHeight;
end;

procedure TNxFlipPanel6.SetCollapsedCaption(const Value: WideString);
begin
  if Value <> FCollapsedCaption then
  begin
    FCollapsedCaption := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetExpanded(const Value: Boolean);
begin
  if Value <> FExpanded then
  begin
    FExpanded := Value;

    InvalidateHeader;

    if FExpanded then
    begin
      ClientHeight := FFullHeight;
    end else
    begin
      FFullHeight := ClientHeight;
      ClientHeight := HeaderHeight;
    end;

  end;

end;

procedure TNxFlipPanel6.SetGlyph(const Value: TPicture);
begin
  FGlyph.Assign(Value);

  if Assigned(FGlyph)
    then FGlyph.OnChange := DoHeaderChange;
end;

procedure TNxFlipPanel6.SetGlyphCollapse(const Value: TBitmap);
begin
  if FGlyphCollapse <> Value then
  begin
    FGlyphCollapse.Assign(Value);

    if Assigned(FGlyphCollapse)
      then FGlyphCollapse.OnChange := DoHeaderChange;
  end;
end;

procedure TNxFlipPanel6.SetGlyphExpand(const Value: TBitmap);
begin
  if FGlyphExpand <> Value then
  begin
    FGlyphExpand.Assign(Value);

    if Assigned(FGlyphExpand)
      then FGlyphExpand.OnChange := DoHeaderChange;
  end;
end;

procedure TNxFlipPanel6.SetGlyphPosition(const Value: TNxGlyphPosition);
begin
  if Value <> FGlyphPosition then
  begin
    FGlyphPosition := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderBorderColor(const Value: TColor);
begin
  if Value <> FHeaderBorderColor then
  begin
    FHeaderBorderColor := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderColor(const Value: TColor);
begin
  if Value <> FHeaderColor then
  begin
    FHeaderColor := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderFont(const Value: TFont);
begin
  FHeaderFont.Assign(Value);
  FHeaderFont.OnChange := DoHeaderFontChange;
end;

procedure TNxFlipPanel6.SetHeaderHeight(const Value: Integer);
begin
  if Value <> FHeaderHeight then
  begin
    FHeaderHeight := Value;
    Invalidate;
    Realign;
  end;
end;

procedure TNxFlipPanel6.SetHeaderIndent(const Value: Integer);
begin
  if Value <> FHeaderIndent then
  begin
    FHeaderIndent := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderState(const Value: TNxButtonState);
begin
  if Value <> FHeaderState then
  begin
    FHeaderState := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderStyle(const Value: TNxAppearanceStyle);
begin
  if Value <> FHeaderStyle then
  begin
    FHeaderStyle := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderStyleOptions(const Value: TNxStyleOptions);
begin
  if Value <> FHeaderStyleOptions then
  begin
    FHeaderStyleOptions := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHeaderLayout(const Value: TNxHeaderLayout);
begin
  if Value <> FHeaderLayout then
  begin
    FHeaderLayout := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetHotTrack(const Value: Boolean);
begin
  if Value <> FHotTrack then
  begin
    FHotTrack := Value;
    Invalidate;
  end;
end;

procedure TNxFlipPanel6.SetPanelPadding(const Value: TPadding);
begin
  FPanelPadding := Value;
  FPanelPadding.OnChange := DoInnerPaddingChange;
end;

procedure TNxFlipPanel6.SetParentHeaderFont(const Value: Boolean);
begin
  if FParentHeaderFont <> Value then
  begin
    FParentHeaderFont := Value;

    if FParentHeaderFont
      then FHeaderFont.Assign(Font);

    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.SetShowToggleButton(const Value: Boolean);
begin
  if Value <> FShowToggleButton then
  begin
    FShowToggleButton := Value;
    Invalidate;
  end;
end;

procedure TNxFlipPanel6.SetShowHeader(const Value: Boolean);
begin
  if Value <> FShowHeader then
  begin
    FShowHeader := Value;
    Invalidate;
  end;
end;

procedure TNxFlipPanel6.SetToggleStyle(const Value: TNxToggleButtonStyle);
begin
  if Value <> FToggleButtonStyle then
  begin
    FToggleButtonStyle := Value;
    InvalidateHeader;
  end;
end;

procedure TNxFlipPanel6.WMSize(var Message: TWMSize);
var
  OldHeaderHeight: Integer;
begin
  inherited;
  if not Expanded then
  begin
    OldHeaderHeight := HeaderHeight;
    HeaderHeight := ClientHeight;
    Inc(FFullHeight, HeaderHeight - OldHeaderHeight);
  end else
  begin
    FFullHeight := ClientHeight;
  end;
end;

procedure TNxFlipPanel6.WriteFullHeight(Writer: TWriter);
begin
  Writer.WriteInteger(FFullHeight);
end;

{ TNxHeaderPanel6 }

procedure TNxHeaderPanel6.CMFontChanged(var Message: TMessage);
begin
  inherited;

end;

procedure TNxHeaderPanel6.CMMouseEnter(var Message: TMessage);
begin
  inherited;

end;

procedure TNxHeaderPanel6.CMMouseLeave(var Message: TMessage);
begin
  inherited;

end;

constructor TNxHeaderPanel6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle - [csOpaque];

  { Init. fields }
  FAlignment := taLeftJustify;
  FDivider := False;
  FGlyph := TPicture.Create;
  FGlyph.OnChange := DoGlyphChange;
  FHorzSpacing := pdStandard;
  FPadding := TPadding.Create(nil);
  FPadding.OnChange := DoPaddingChange;
  FSchemeColors := True;
  FStaticPanel := True;
  FTransparentColor := clNone;
  FVertSpacing := pdStandard;
  FWrapKind := wkWordWrap;
end;

destructor TNxHeaderPanel6.Destroy;
begin
  FreeAndNil(FGlyph);
  FreeAndNil(FPadding);
  inherited;
end;

procedure TNxHeaderPanel6.DoGlyphChange(Sender: TObject);
begin
  SetTransparentColor(FTransparentColor);
  Invalidate;
end;

procedure TNxHeaderPanel6.DoPaddingChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxHeaderPanel6.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;

end;

procedure TNxHeaderPanel6.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;

end;

procedure TNxHeaderPanel6.Paint;
var
  PaintPos: TPoint;
  TextSize: TSize;
  Buffer: TBitmap;
begin
  inherited;

  Buffer := TBitmap.Create;

  try
    Buffer.Width := ClientWidth;
    Buffer.Height := ClientHeight;

    with Buffer.Canvas do
    begin
      if SchemeColors
        then Brush.Color := ColorOf(seBtnFaceChecked)
        else Brush.Color := Color;
      FillRect(ClientRect);
    end;

    PaintPos := Point(Padding.Left, Padding.Top);

    if Assigned(Glyph)
      and Assigned(Glyph.Graphic)
      and not Glyph.Graphic.Empty then
    begin

      if Glyph.Graphic is TBitmap then
      begin
        DrawBitmap(Buffer.Canvas, PaintPos.X, PaintPos.Y, Glyph.Graphic as TBitmap);
      end else
        Canvas.Draw(PaintPos.X, PaintPos.Y, Glyph.Graphic);

      Inc(PaintPos.X, Glyph.Width);

      Inc(PaintPos.X, HorzSpacing);
    end;

    if Caption <> EmptyStr then
    begin
      TextSize := GetTextSize(Buffer.Canvas, Caption, True);

      Buffer.Canvas.Font.Assign(Font);
      Buffer.Canvas.Font.Style := [fsBold];

      DrawTextRect(Buffer.Canvas, Rect(PaintPos.X, PaintPos.Y, ClientWidth, PaintPos.Y + TextSize.cy), taLeftJustify, taAlignTop, Caption, wkEllipsis);

      Inc(PaintPos.Y, TextSize.cy);

      Inc(PaintPos.Y, VertSpacing);
    end;

    if Text <> EmptyStr then
    begin
      Buffer.Canvas.Font.Assign(Font);

      DrawTextRect(Buffer.Canvas, Rect(PaintPos.X, PaintPos.Y, ClientWidth - Padding.Right, ClientHeight - Padding.Bottom), taLeftJustify, taAlignTop, Text, WrapKind);
    end;

  finally
    Canvas.Draw(0, 0, Buffer);
    FreeAndNil(Buffer);
  end;

end;

procedure TNxHeaderPanel6.SetAlignment(const Value: TAlignment);
begin
  if Value <> FAlignment then
  begin
    FAlignment := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetBorderColor(const Value: TColor);
begin
  if Value <> FBorderColor then
  begin
    FBorderColor := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetCaption(const Value: WideString);
begin
  if Value <> FCaption then
  begin
    FCaption := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetDivider(const Value: Boolean);
begin
  if Value <> FDivider then
  begin
    FDivider := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetGlyph(const Value: TPicture);
begin
  if Value <> FGlyph then
  begin
    FGlyph.Assign(Value);
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetHorzSpacing(const Value: Integer);
begin
  if Value <> FHorzSpacing then
  begin
    FHorzSpacing := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetPadding(const Value: TPadding);
begin
  FPadding.Assign(Value);
  Invalidate;
end;

procedure TNxHeaderPanel6.SetSchemeColors(const Value: Boolean);
begin
  if Value <> FSchemeColors then
  begin
    FSchemeColors := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetText(const Value: WideString);
begin
  if Value <> FText then
  begin
    FText := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetTransparentColor(const Value: TColor);
begin
  FTransparentColor := Value;

  if Glyph.Graphic is TBitmap then
    with Glyph.Graphic as TBitmap do
    begin
      TransparentColor := FTransparentColor;
      Transparent := FTransparentColor <> clNone;
    end;
end;

procedure TNxHeaderPanel6.SetVerticalAlignment(const Value: TVerticalAlignment);
begin
  if Value <> FVerticalAlignment then
  begin
    FVerticalAlignment := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetVertSpacing(const Value: Integer);
begin
  if Value <> FVertSpacing then
  begin
    FVertSpacing := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.SetWrapKind(const Value: TNxWrapKind);
begin
  if Value <> FWrapKind then
  begin
    FWrapKind := Value;
    Invalidate;
  end;
end;

procedure TNxHeaderPanel6.WMEraseBkGnd(var Message: TWMEraseBkGnd);
begin
  Message.Result := 1;
end;

{ TNxLinkLabel6 }

procedure TNxLinkLabel6.Assign(Source: TPersistent);
begin
  inherited;
  if Source is TNxLinkLabel6 then
  begin
    ActiveStyle.Assign(TNxLinkLabel6(Source).ActiveStyle);
    Alignment := TNxLinkLabel6(Source).Alignment;
    Glyph := TNxLinkLabel6(Source).Glyph;
    HotStyle.Assign(TNxLinkLabel6(Source).HotStyle);
    ImageIndex := TNxLinkLabel6(Source).ImageIndex;
    Images := TNxLinkLabel6(Source).Images;
    LinkArea := TNxLinkLabel6(Source).LinkArea;
    PressedStyle.Assign(TNxLinkLabel6(Source).PressedStyle);
    TextSpacing := TNxLinkLabel6(Source).TextSpacing;
    VerticalAlignment := TNxLinkLabel6(Source).VerticalAlignment;
  end;
end;

function TNxLinkLabel6.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
  Result := True;
  if Align in [alNone, alLeft, alRight] then
    NewWidth := ContentSize.cx + Padding.Left + Padding.Right;
  if Align in [alNone, alTop, alBottom] then
    NewHeight := ContentSize.cy + Padding.Top + Padding.Bottom;
end;

procedure TNxLinkLabel6.Changed;
begin
  if AutoSize then AdjustSize;
  Invalidate;
end;

procedure TNxLinkLabel6.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  State := State - [bsHover];
end;

constructor TNxLinkLabel6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := [csCaptureMouse, csClickEvents, csSetCaption,
    csDoubleClicks, csReplicatable];

  AutoSize := True;
  DoubleBuffered := True;

  FActiveStyle := TNxPaintStyle6.Create;
  FActiveStyle.TextDecoration := tdUnderline;
  FActiveStyle.OnChange := DoGlyphChange;
  FAlignment := taLeftJustify;
  FGlyph := TPicture.Create;
  FGlyph.OnChange := DoGlyphChange;
  FHotStyle := TNxPaintStyle6.Create;
  FHotStyle.TextDecoration := tdUnderline;
  FHotStyle.OnChange := DoGlyphChange;
  FImageIndex := -1;
  FImages := nil;
  FLinkArea := laIconAndText;
  FState := [];
  FPressedStyle := TNxPaintStyle6.Create;
  FPressedStyle.TextDecoration := tdUnderline;
  FPressedStyle.OnChange := DoGlyphChange;
  FTextSpacing := pdDouble;
  FTransparent := False;
  FTransparentColor := clNone;
  FVerticalAlignment := taVerticalCenter;
end;

destructor TNxLinkLabel6.Destroy;
begin
  FreeAndNil(FActiveStyle);
  FreeAndNil(FGlyph);
  FreeAndNil(FHotStyle);
  FreeAndNil(FPressedStyle);
  inherited;
end;

procedure TNxLinkLabel6.DoGlyphChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxLinkLabel6.DoPaddingChange(Sender: TObject);
begin
  inherited;
  Invalidate;
end;

function TNxLinkLabel6.GetContentRect: TRect;
var
  Location: TPoint;
begin
  Location := PosInRect(ContentSize.cx, ContentSize.cy, PaddingRect, Alignment, VerticalAlignment);
  Result := Bounds(Location.X, Location.Y, ContentSize.cx, ContentSize.cy);
end;

function TNxLinkLabel6.GetContentSize: TSize;
var
  S: WideString;
  CaptionSize: TSize;
begin
  Result := Size(0, 0);

  with Canvas do
  begin
    S := Caption;
    Font.Assign(Self.Font);

    if bsHover in FState then
    begin
      FHotStyle.Decorate(Font);

      S := TNxPaintStyle6.TransformText(S, FHotStyle.TextTransform)
    end;

    if Assigned(Glyph) and Assigned(Glyph.Graphic) and not Glyph.Graphic.Empty then
    begin
      Result.cy := Glyph.Height;
      Result.cx := Glyph.Width;
    end else if Assigned(Images) and InRange(ImageIndex, 0, Pred(Images.Count)) then
    begin
      Result.cy := Images.Height;
      Result.cx := Images.Width;
    end;

    if S <> EmptyStr then
    begin
      CaptionSize := GetTextSize(Canvas, S, True);

      if Result.cx > 0 then Inc(Result.cx, FTextSpacing);
      Inc(Result.cx, CaptionSize.cx);

      if CaptionSize.cy > Result.cy then
        Result.cy := CaptionSize.cy;
    end;
  end;
end;

function TNxLinkLabel6.HasIcon: Boolean;
begin
  Result := (Assigned(Glyph.Graphic) and not Glyph.Graphic.Empty)
    or (Assigned(Images) and InRange(ImageIndex, 0, Pred(Images.Count)));
end;

procedure TNxLinkLabel6.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  case LinkArea of
    laIconAndText:
      if PtInRect(ContentRect, Point(X, Y))
        then State := State + [bsPressed];
    laClientRect:
      State := State + [bsPressed];
  end;
end;

procedure TNxLinkLabel6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  case LinkArea of
    laIconAndText:
      if PtInRect(ContentRect, Point(X, Y))
        then State := State + [bsHover]
        else State := State - [bsHover];
    laClientRect:
      State := State + [bsHover];
  end;
end;

procedure TNxLinkLabel6.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  State := State - [bsPressed];
end;

procedure TNxLinkLabel6.Paint;
var
  Location: TPoint;
  Y: Integer;
  CaptionRect: TRect;
  S: WideString;
  Style: TNxPaintStyle6;
begin
  inherited;

  Location := PosInRect(ContentSize.cx, ContentSize.cy, PaddingRect, Alignment, VerticalAlignment);

  Style := nil;
  if bsHover in FState then Style := FHotStyle;
  if bsPressed in FState then Style := FPressedStyle;

  with Canvas do
  begin

    if Transparent then EraseBackground(Self, Canvas) else
    begin


      if Assigned(Style) and Style.HasBackground
        then Style.FillRect(Canvas, ClientRect)
      else
      begin
        Brush.Color := Color;
        FillRect(ClientRect);
      end;

    end;

    { Icon painting }

    if Assigned(Glyph.Graphic)
      and not Glyph.Graphic.Empty then
    begin
      Y := Location.Y + ContentSize.cy div 2 - Glyph.Height div 2;

      Canvas.Draw(Location.X, Y, Glyph.Graphic);

      Inc(Location.X, Glyph.Width);
    end
    else if Assigned(Images) and InRange(ImageIndex, 0, Pred(Images.Count)) then
    begin
//      Y := Location.Y + ContentSize.cy div 2 - Images.Height div 2;

      Images.Draw(Canvas, Location.X, Location.Y, ImageIndex);

      Inc(Location.X, Images.Width);
    end;

    if HasIcon and (Caption <> EmptyStr)
      then Inc(Location.X, FTextSpacing);

    { Text painting }

    if Caption <> EmptyStr then
    begin
      CaptionRect := Rect(Location.X, Location.Y, PaddingRect.Right, Location.Y + ContentSize.cy);

      Font.Assign(Self.Font);

      S := Caption;

      if Assigned(Style) then
      begin
        Style.Decorate(Font);

        if Style.Color <> clNone then
          Font.Color := Style.Color;

        S := TNxPaintStyle6.TransformText(S, Style.TextTransform)
      end;

      DrawTextRect(Canvas, CaptionRect, taLeftJustify, VerticalAlignment, S, wkEllipsis);
    end;

  end;

end;

procedure TNxLinkLabel6.SetActiveStyle(const Value: TNxPaintStyle6);
begin
  FActiveStyle.Assign(Value);
end;

procedure TNxLinkLabel6.SetAlignment(const Value: TAlignment);
begin
  if Value <> FAlignment then
  begin
    FAlignment := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.SetCaption(const Value: WideString);
begin
  if Value <> FCaption then
  begin
    FCaption := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.SetGlyph(const Value: TPicture);
begin
  FGlyph.Assign(Value);
  FGlyph.OnChange := DoGlyphChange;
end;

procedure TNxLinkLabel6.SetHotStyle(const Value: TNxPaintStyle6);
begin
  FHotStyle.Assign(Value);
end;

procedure TNxLinkLabel6.SetImageIndex(const Value: TImageIndex);
begin
  if Value <> FImageIndex then
  begin
    FImageIndex := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.SetImages(const Value: TCustomImageList);
begin
  if Value <> FImages then
  begin
    FImages := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.SetName(const Value: TComponentName);
begin
  inherited;
  if not (csLoading in ComponentState) then
    if Caption = EmptyStr then Caption := Name;
end;

procedure TNxLinkLabel6.SetPressedStyle(const Value: TNxPaintStyle6);
begin
  FPressedStyle.Assign(Value);
end;

procedure TNxLinkLabel6.SetState(const Value: TNxButtonState);
begin
  if Value <> FState then
  begin
    FState := Value;

    if bsHover in FState then Cursor := crHandPoint
      else Cursor := crDefault;

    Changed;
  end;
end;

procedure TNxLinkLabel6.SetTextSpacing(const Value: Integer);
begin
  if Value <> FTextSpacing then
  begin
    FTextSpacing := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.SetTransparent(const Value: Boolean);
begin
  if Value <> FTransparent then
  begin
    FTransparent := Value;
    Invalidate;
  end;
end;

procedure TNxLinkLabel6.SetTransparentColor(const Value: TColor);
begin
  FTransparentColor := Value;

  if Glyph.Graphic is TBitmap then
    with Glyph.Graphic as TBitmap do
    begin
      TransparentColor := FTransparentColor;
      Transparent := FTransparentColor <> clNone;
    end;
end;

procedure TNxLinkLabel6.SetVerticalAlignment(const Value: TVerticalAlignment);
begin
  if Value <> FVerticalAlignment then
  begin
    FVerticalAlignment := Value;
    Changed;
  end;
end;

procedure TNxLinkLabel6.WMEraseBkGnd(var Message: TWMEraseBkGnd);
begin
  Message.Result := 1;
end;

procedure TNxLinkLabel6.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
  inherited;
  if Transparent then Invalidate;
end;

{ TNxSplitter6 }

constructor TNxSplitter6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle - [csOpaque];
  FGlyph := TBitmap.Create;
  FGlyphTransparent := False;
  Width := 8;
end;

destructor TNxSplitter6.Destroy;
begin
  FreeAndNil(FGlyph);
  inherited;
end;

procedure TNxSplitter6.DoGlyphChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxSplitter6.MakeTransparent;
begin
  if Assigned(Glyph) and not Glyph.Empty then
    if GlyphTransparent then
    begin
      Glyph.TransparentColor := Glyph.Canvas.Pixels[0, Glyph.Height - 1];
      Glyph.Transparent := True;
    end else Glyph.Transparent := False;
end;

procedure TNxSplitter6.Paint;
var
  GlyphLocation: TPoint;
begin
  with Canvas do
  begin
    Brush.Color := ColorOf(seBtnFace);
    FillRect(ClientRect);

    { Glyph }
    if Assigned(Glyph)
      and not Glyph.Empty then
    begin
      GlyphLocation := CenterInRect(ClientRect, Glyph.Width, Glyph.Height);
      Draw(GlyphLocation.X, GlyphLocation.Y, Glyph);
    end;
  end;
end;

procedure TNxSplitter6.SetGlyph(const Value: TBitmap);
begin
  if Value <> FGlyph then
  begin
    FGlyph.Assign(Value);

    { Set TransparentColor }
    MakeTransparent;

    if Assigned(FGlyph) then FGlyph.OnChange := DoGlyphChange;

    Invalidate;
  end;
end;

procedure TNxSplitter6.SetGlyphTransparent(const Value: Boolean);
begin
  if Value <> FGlyphTransparent then
  begin
    FGlyphTransparent := Value;
    MakeTransparent;
  end;
end;

procedure TNxSplitter6.WMEraseBkGnd(var Message: TWMEraseBkGnd);
begin
  Message.Result := 1;
end;

{ TNxHTMLLabel6 }

procedure TNxHTMLLabel6.AdjustBounds;
begin
  FView.HTML := Caption;
  FView.Operation := [hoCalc];
  FView.StyleSheet := StylesSheet;
  FView.PaintTo(Canvas, ClientRect);
  Width := FView.BestSize.cx;
  Height := FView.BestSize.cy;
end;

function TNxHTMLLabel6.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
  FView.HTML := Caption;
  FView.Operation := [hoCalc];
  FView.StyleSheet := StylesSheet;
  FView.PaintTo(Canvas, ClientRect);
  NewWidth := FView.BestSize.cx;
  NewHeight := FView.BestSize.cy;
  Result := True;
end;

constructor TNxHTMLLabel6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle + [csOpaque];

  { Init. fields }
  FCaption := EmptyStr;
  FStylesSheet := nil;
  FView := TNxHTMLView.Create;

  ParentColor := False;
end;

destructor TNxHTMLLabel6.Destroy;
begin
  FView.Free;
  inherited;
end;

procedure TNxHTMLLabel6.DoLinkClick(Href: WideString);
begin
  if Assigned(FOnLinkClick) then FOnLinkClick(Self, Href);
end;

function TNxHTMLLabel6.GetDefaultStyle: TNxCSSStyle;
begin
  Result.Color := clWindowText;
  Result.FontFamily := Font.Name;
  Result.FontSize := IntToStr(Font.Size);
  Result.TextAlign := taLeft;
end;

function TNxHTMLLabel6.GetTransparent: Boolean;
begin
  Result := not (csOpaque in ControlStyle);
end;

procedure TNxHTMLLabel6.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;

end;

procedure TNxHTMLLabel6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  Canvas.Font.Assign(Self.Font);

  FView.HTML := Caption;
  FView.DefaultStyle := GetDefaultStyle;
  FView.Operation := [hoHitTest];
  FView.StyleSheet := StylesSheet;
  FView.HitLocation := Point(X, Y);
  FView.PaintTo(Canvas, ClientRect);

  if FView.HitHref <> EmptyStr then
    Cursor := crHandPoint
  else
    Cursor := crDefault;
end;

procedure TNxHTMLLabel6.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  Canvas.Font.Assign(Self.Font);

  FView.HTML := Caption;
  FView.DefaultStyle := GetDefaultStyle;
  FView.Operation := [hoHitTest];
  FView.StyleSheet := StylesSheet;
  FView.HitLocation := Point(X, Y);
  FView.PaintTo(Canvas, ClientRect);

  if FView.HitHref <> EmptyStr then
  begin
    DoLinkClick(FView.HitHref);
  end;
end;

procedure TNxHTMLLabel6.Paint;
begin
  inherited;

  with Canvas do
  begin
    Font.Assign(Self.Font);

    { Background }
    Brush.Color := Color;
    if not Transparent
      then FillRect(ClientRect);
  end;

  FView.HTML := Caption;
  FView.DefaultStyle := GetDefaultStyle;
  FView.Operation := [hoPaint];
  FView.StyleSheet := StylesSheet;
  FView.PaintTo(Canvas, ClientRect);
end;

procedure TNxHTMLLabel6.SetCaption(const Value: WideString);
begin
  if Value <> FCaption then
  begin
    FCaption := Value;

    { Set best-size }
    if not (csReading in ComponentState)
      and AutoSize then AdjustBounds;

    Invalidate;
  end;
end;

procedure TNxHTMLLabel6.SetStylesSheet(const Value: TNxStylesSheet6);
begin
  FStylesSheet := Value;
end;

procedure TNxHTMLLabel6.SetTransparent(const Value: Boolean);
begin
  if Value <> Transparent then
  begin
    if Value then
      ControlStyle := ControlStyle - [csOpaque]
    else
      ControlStyle := ControlStyle + [csOpaque];

    Invalidate;
  end;

  FTransparentSet := True;
end;

{ TNxHint6 }

constructor TNxHint6.Create(AOwner: TComponent);
begin
  inherited;
  FStylesSheet := nil;
  FPadding := TPadding.Create(nil);
  FPadding.SetBounds(pdDouble, pdDouble, pdDouble, pdDouble);
  HintWindowClass := TNxHintWindow6;
end;

destructor TNxHint6.Destroy;
begin
  FPadding.Free;
  inherited;
end;

procedure TNxHint6.SetPadding(const Value: TPadding);
begin
  FPadding := Value;
end;

procedure TNxHint6.SetStylesSheet(const Value: TNxStylesSheet6);
begin
  FStylesSheet := Value;
end;

{ TNxHintWindow6 }

procedure TNxHintWindow6.ActivateHint(Rect: TRect; const AHint: string);
begin
  with Rect do
  begin
    FView.HTML := AHint;
    FView.DefaultStyle := GetDefaultStyle;
    FView.Operation := [hoCalc];

    if GetHintComponent <> nil then
    begin
      FView.StyleSheet := GetHintComponent.StylesSheet;
    end;

    FView.PaintTo(Canvas, Bounds(0, 0, 2000, 2000));

    Rect.Right := Rect.Left + FView.BestSize.cx + 2;
    Rect.Bottom := Rect.Top + FView.BestSize.cy + 2;

    if GetHintComponent <> nil then
    begin
      with GetHintComponent do
      begin
        Dec(Rect.Left, Padding.Left);
        Dec(Rect.Top, Padding.Top);
        Inc(Rect.Right, Padding.Right);
        Inc(Rect.Bottom, Padding.Bottom);
      end;
    end;
  end;

  inherited;
end;

procedure TNxHintWindow6.AddPadding(var Rect: TRect);
begin
  if GetHintComponent <> nil then
  begin
    PaddingRect(Rect, GetHintComponent.Padding);
  end;
end;

constructor TNxHintWindow6.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle + [csOpaque];
  FView := TNxHTMLView.Create;
end;

procedure TNxHintWindow6.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    if CheckWin32Version(5, 1) then
      WindowClass.Style := WindowClass.Style and not CS_DROPSHADOW;
  end;
end;

destructor TNxHintWindow6.Destroy;
begin
  FreeAndNil(FView);
  inherited;
end;

function TNxHintWindow6.GetContentRect: TRect;
begin
  Result := ClientRect;
  AddPadding(Result);
end;

function TNxHintWindow6.GetDefaultStyle: TNxCSSStyle;
begin
  Result.Color := Font.Color;
  Result.FontFamily := 'Segoe UI';
  Result.FontSize := '8';
  Result.TextAlign := taLeft;
end;

function TNxHintWindow6.GetHintComponent: TNxHint6;
var
  i: Integer;
begin
  { Default, not found }
  Result := nil;

  for i := 0 to Pred(Application.MainForm.ComponentCount) do
    if Application.MainForm.Components[i] is TNxHint6 then
    begin
      Result := TNxHint6(Application.MainForm.Components[i]);

      Exit;
    end;
end;

function TNxHintWindow6.GetStylesSheet: TNxStylesSheet6;
begin
  if GetHintComponent <> nil then
  begin
    Result := GetHintComponent.StylesSheet;
  end else Result := nil;
end;

procedure TNxHintWindow6.NCPaint(DC: HDC);
var
  Pen: HPEN;
  R: TRect;
  BorderColor: TColor;
begin
  GetWindowRect(Handle, R);
  OffsetRect(R, -R.Left, -R.Top);
  BorderColor := ColorOf(seDivider);
  Pen := CreatePen(PS_SOLID, 1, ColorToRGB(BorderColor));
  try
    SelectObject(DC, Pen);

    Rectangle(DC, R.Left, R.Top, R.Right, R.Bottom);
  finally
    DeleteObject(Pen);
  end;
end;

procedure TNxHintWindow6.Paint;
begin
  with Canvas do
  begin
    Font.Assign(Self.Font);

    { Background }
    Brush.Color := clWhite;
    FillRect(ClientRect);
  end;

  FView.HTML := Caption;
  FView.DefaultStyle := GetDefaultStyle;
  FView.Operation := [hoPaint];
  FView.StyleSheet := StylesSheet;

  FView.PaintTo(Canvas, GetContentRect);
end;

{ TNxImage6 }

constructor TNxImage6.Create(AOwner: TComponent);
begin
  inherited;
  FBorderPen := TPen.Create;
  FEmptyCaption := 'Empty';
  FFillMode := fmAspectFit;
  FPicture := TPicture.Create;
  FPicture.OnChange := DoPictureChange;
end;

destructor TNxImage6.Destroy;
begin
  FreeAndNil(FBorderPen);
  FreeAndNil(FPicture);
  inherited;
end;

procedure TNxImage6.DoPaddingChange(Sender: TObject);
begin
  inherited;
  Invalidate;
end;

procedure TNxImage6.DoPictureChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxImage6.Paint;
var
  ContentRect, FocusRect, EffectsRect: TRect;
begin
  inherited;
  ContentRect := PaddingRect;

  with Canvas do
  begin
    Brush.Color := Self.Color;
    FillRect(ClientRect);
  end;

  if Assigned(Picture) and Assigned(Picture.Graphic) then
  begin
    { Paint TGraphic & get TRect }
    EffectsRect := PaintGraphic(Canvas, Picture.Graphic, ContentRect, FillMode);

    if not IsRectEmpty(EffectsRect) then
    begin
      PaintEffects(Canvas, EffectsRect, Effects);

      if Focused then
      begin
        FocusRect := ContentRect;
        with Canvas do
        begin
          Pen.Assign(BorderPen);
          Pen.Color := clHighlight;
          Brush.Style := bsClear;
          Rectangle(FocusRect);
          InflateRect(FocusRect, -1, -1);
          Rectangle(FocusRect);
          Brush.Style := bsSolid;
        end;
      end;
    end;
  end else
    with Canvas do
    begin
      { Image not Assigned }
      Pen.Color := clGrayText;
      Pen.Style := psDot;
      RoundRect(ContentRect.Left, ContentRect.Top, ContentRect.Right, ContentRect.Bottom, 10, 10);
      Pen.Style := psSolid;
      Font.Color := Pen.Color;
      DrawTextRect(Canvas, ContentRect, Classes.taCenter, taVerticalCenter, EmptyCaption, wkEllipsis);
    end;
end;

procedure TNxImage6.SetBorderPen(const Value: TPen);
begin
  FBorderPen.Assign(Value);
end;

procedure TNxImage6.SetEffects(const Value: TNxPaintEffects);
begin
  if Value <> FEffects then
  begin
    FEffects := Value;
    Invalidate;
  end;
end;

procedure TNxImage6.SetEmptyCaption(const Value: WideString);
begin
  if Value <> FEmptyCaption then
  begin
    FEmptyCaption := Value;
    Invalidate;
  end;
end;

procedure TNxImage6.SetFillMode(const Value: TNxFillMode);
begin
  if Value <> FFillMode then
  begin
    FFillMode := Value;
    Invalidate;
  end;
end;

procedure TNxImage6.SetPicture(const Value: TPicture);
begin
  FPicture.Assign(Value);
end;

{ TNxTrackBar6 }

constructor TNxTrackBar6.Create(AOwner: TComponent);
begin
  inherited;
  FImages := nil;
  FImagesDistance := pdDouble;
  FMax := 5;
  FMin := 1;
  FPosition := 1;
  FPrecision := 0;
  FProgressColor := clGray;
  FProgressLocation := tpLeftToPosition;
  FSignsColor := clGray;
  FStep := 1;
  FStyle := stNative;
  FThumbBorderColor := clBlack;
  FThumbColor := clWhite;
  FThumbSize := TNxSize.Create(8, 8);
  FThumbSize.OnChange := DoThumbSizeChange;
  FTickMarks := True;
  FTrackColor := clSilver;
  FTrackHeight := 6;
end;

destructor TNxTrackBar6.Destroy;
begin
  FThumbSize.Free;
  inherited;
end;

procedure TNxTrackBar6.DoChange;
begin
  if Assigned(FOnChange) then FOnChange(Self);
end;

procedure TNxTrackBar6.DoCustomDrawTrack(DrawingCanvas: TCanvas; DrawingRect: TRect);
begin
  if Assigned(FOnCustomDrawTrack) then FOnCustomDrawTrack(Self, Canvas, DrawingRect);
end;

procedure TNxTrackBar6.DoThumbSizeChange(Sender: TObject);
begin
  Invalidate;
end;

function TNxTrackBar6.GetContentRect: TRect;
begin
  Result := ClientRect;
  if Assigned(Images) then Dec(Result.Bottom, Images.Height);
end;

function TNxTrackBar6.GetMinusRect: TRect;
begin
  with ContentRect do
  begin
    Result := Bounds(Left, 0, DotToPixel(6), DotToPixel(2));
    OffsetRect(Result, Top, RectHeight(ContentRect) div 2 - RectHeight(Result) div 2);
  end;
end;

function TNxTrackBar6.GetPlusRect: TRect;
begin
  with ContentRect do
  begin
    Result := Bounds(Right - DotToPixel(8), 0, DotToPixel(8), DotToPixel(8));
    OffsetRect(Result, Top, RectHeight(ContentRect) div 2 - RectHeight(Result) div 2);
  end;
end;

function TNxTrackBar6.GetPositionAtPos(const X, Y: Integer): Double;
var
  Spot: Integer;
begin
  Spot := X - TrackRect.Left;
  Result := RoundTo(Spot / RectWidth(TrackRect) * (Max - Min) + Min, FPrecision);
  if Result > Max then Result := Max;
  if Result < Min then Result := Min;
end;

function TNxTrackBar6.GetProgressRect: TRect;
begin
  Result := TrackRect;
  InflateRect(Result, -2, -2);
  case ProgressLocation of
    tpLeftToPosition: Result.Right := ThumbRect.Left + RectWidth(ThumbRect) div 2;
    tpRightToPosition: Result.Left := ThumbRect.Left + RectWidth(ThumbRect) div 2;
  end;
end;

function TNxTrackBar6.GetThumbRect: TRect;
var
  Distance: Integer;
  TrackSize, SliderSize: TSize;
begin
  TrackSize := Size(RectWidth(TrackRect), RectHeight(TrackRect));

  Distance := Round(TrackSize.cx * (Position - Min) / (Max - Min));

  SliderSize := GetThumbSize;

  with Result do
  begin
    Left := TrackRect.Left + Distance - SliderSize.cx div 2;
    Top := TrackSize.cy div 2 - SliderSize.cy div 2 + TrackRect.Top;
    Right := Left + SliderSize.cx;
    Bottom := Top + SliderSize.cy;
  end;
end;

function TNxTrackBar6.GetThumbSize: TSize;
begin
  case Style of
    stNative: Result := Size(8, 13);
    stModern: Result := Size(4, 11);
    else Result := FThumbSize.AsSize;
  end;
  Result := DotToPixel(Result);
end;

function TNxTrackBar6.GetTrackRect: TRect;
begin
  Result.Left := MinusRect.Right + DotToPixel(4);
  Result.Right := PlusRect.Left - DotToPixel(4);
  Result.Top := 0;
  Result.Bottom := Result.Top + TrackHeight;
  OffsetRect(Result, 0, RectHeight(ContentRect) div 2 - RectHeight(Result) div 2);
end;

function TNxTrackBar6.GetTrackTouchRect: TRect;
begin
  Result := TrackRect;
  Result.Top := ThumbRect.Top;
  Result.Bottom := ThumbRect.Bottom;
end;

procedure TNxTrackBar6.KeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if Key = VK_RIGHT then Position := Position + Step;
  if Key = VK_LEFT then Position := Position - Step;
  if Key = VK_HOME then Position := Min;
  if Key = VK_END then Position := Max;
end;

procedure TNxTrackBar6.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  if Button = mbLeft then
  begin
    if PtInRect(MinusRect, Point(X, Y)) then
    begin
      Position := Position - Step;
    end
    else if PtInRect(PlusRect, Point(X, Y)) then
    begin
      Position := Position + Step;
    end
    else if PtInRect(TrackTouchRect, Point(X, Y))
      or PtInRect(ThumbRect, Point(X, Y)) then
    begin
      Position := GetPositionAtPos(X, Y);

      { Activate Hint too }
      State := State + [bsPressed];
    end;
    if CanFocus and CanFocusParent then SetFocus;
  end;
end;

procedure TNxTrackBar6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  if bsPressed in State then Position := GetPositionAtPos(X, Y);

  if PtInRect(ThumbRect, Point(X, Y))
    then State := State + [bsHover]
    else State := State - [bsHover];
end;

procedure TNxTrackBar6.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  State := State - [bsPressed];
end;

procedure TNxTrackBar6.Paint;
begin
  inherited;
  EraseBkGnd(ClientRect, Color);

  PaintMinus(MinusRect);
  PaintPlus(PlusRect);

  if TickMarks then PaintTickMarks;
  if Assigned(Images) then PaintImages;

  with Canvas do
  begin
    case Style of
      stNative:
      begin
        TNxTrackBarStyle6.PaintTrack(Canvas, Parent.Handle, TrackRect, StyleOptions);
        PaintProgress(ProgressRect);
        TNxTrackBarStyle6.PaintThumb(Canvas, Parent.Handle, ThumbRect, State, StyleOptions);
      end;
      stModern:
      begin
        FillRect(TrackRect);
        if (bsHover in State) or (bsPressed in State)
          then Brush.Color := ColorOf(seTrackBar);
        PaintProgress(ProgressRect);
        FillRect(ThumbRect);
      end;
      stUserDefined:
      begin
        Brush.Color := TrackColor;
        if not Assigned(OnCustomDrawTrack) then
        begin
          FillRect(TrackRect);
        end else
        begin
          DoCustomDrawTrack(Canvas, TrackRect);
        end;
        PaintProgress(ProgressRect);
        Brush.Color := ThumbColor;
        Pen.Color := ThumbBorderColor;
        Canvas.Rectangle(ThumbRect);
      end;
    end;
  end;
end;

procedure TNxTrackBar6.PaintImages;
var
  X, Y, Index, Spacing: Integer;
  i: Double;
begin
  i := FMin;
  Index := 0;
  Spacing := Round(RectWidth(TrackRect) / (FMax - FMin));
  X := TrackRect.Left - Images.Width div 2;
  Y := TrackRect.Bottom + ImagesDistance;
  while i <= FMax do
  begin
    if InRange(Index, 0, Images.Count) then
    begin
      Images.Draw(Canvas, X, Y, Index);
    end;
    i := i + Step;
    X := X + Spacing;
    Inc(Index);
  end;
end;

procedure TNxTrackBar6.PaintMinus(Dest: TRect);
begin
  with Canvas, Brush do
  begin
    case FStyle of
      stNative: Color := clGray;
      stModern: Color := clWhite;
      stUserDefined: Color := FSignsColor;
    end;
    FillRect(Dest);
  end;
end;

procedure TNxTrackBar6.PaintPlus(Dest: TRect);
var
  Delta: Integer;
  Center: TPoint;
begin
  Delta := DotToPixel(1);
  Center := CenterPoint(Dest);
  with Canvas, Center do
  begin
    case Style of
      stNative: Pen.Color := clGray;
      stModern: Pen.Color := clWhite;
      stUserDefined: Pen.Color := FSignsColor;
    end;
    Brush.Color := Pen.Color;
    Polygon([
      Point(Dest.Left, Y - Delta),
      Point(X - Delta, Y - Delta),
      Point(X - Delta, Dest.Top),
      Point(X + Delta - 1, Dest.Top),
      Point(X + Delta - 1, Y - Delta),
      Point(Dest.Right - 1, Y - Delta),
      Point(Dest.Right - 1, Y + Delta - 1),
      Point(X + Delta - 1, Y + Delta - 1),
      Point(X + Delta - 1, Dest.Bottom - 1),
      Point(X - Delta, Dest.Bottom - 1),
      Point(X - Delta, Y + Delta - 1),
      Point(Dest.Left, Y + Delta - 1)
    ]);
  end;
end;

procedure TNxTrackBar6.PaintProgress(const ARect: TRect);
begin
  case Style of
    stModern: Canvas.Brush.Color := ColorOf(seHighlight);
    else Canvas.Brush.Color := ProgressColor;
  end;
  Canvas.FillRect(ARect);
end;

procedure TNxTrackBar6.PaintTickMarks;
var
  X, Y, Distance: Integer;
  i: Double;
begin
  Y := TrackRect.Bottom;
  i := FMin;
  while i <= FMax do
  begin
    Distance := Round(RectWidth(TrackRect) * (i - Min) / (Max - Min));
    X := TrackRect.Left + Distance;

    Canvas.Pen.Color := TrackColor;
    Canvas.Polyline([
      Point(X, Y + 2),
      Point(X, Y + 4)
    ]);
    i := i + Step;
  end;
end;

procedure TNxTrackBar6.SetImages(const Value: TImageList);
begin
  if Value <> FImages then
  begin
    if Assigned(FImages) then FImages.RemoveFreeNotification(Self);
    FImages := Value;
    if Assigned(FImages) then FImages.FreeNotification(Self);
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetImagesDistance(const Value: Integer);
begin
  if Value <> FImagesDistance then
  begin
    FImagesDistance := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetMax(const Value: Double);
begin
  if Value <> FMax then
  begin
    FMax := Value;
    if FMax <= FMin then FMax := FMin + Step;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetMin(const Value: Double);
begin
  if Value <> FMin then
  begin
    FMin := Value;
    if FMin >= FMax then FMin := FMax - Step;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetPosition(const Value: Double);
var
  NewPosition: Double;
begin
  if Value <> FPosition then
  begin
    NewPosition := Value;
    if NewPosition > FMax then NewPosition := FMax;
    if NewPosition < FMin then NewPosition := FMin;
    if NewPosition <> FPosition then
    begin
      InvalidateRect(ThumbRect);
      if ProgressLocation <> tpHidden then InvalidateRect(ProgressRect);
      FPosition := NewPosition;
      DoChange;
      InvalidateRect(ThumbRect);
      if ProgressLocation <> tpHidden then InvalidateRect(ProgressRect);
    end;
  end;
end;

procedure TNxTrackBar6.SetPrecision(const Value: Integer);
begin
  if Value <> FPrecision then
  begin
    FPrecision := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetProgressColor(const Value: TColor);
begin
  if Value <> FProgressColor then
  begin
    FProgressColor := Value;
    InvalidateRect(ProgressRect);
  end;
end;

procedure TNxTrackBar6.SetProgressLocation(const Value: TNxTrackProgress);
begin
  if Value <> FProgressLocation then
  begin
    FProgressLocation := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetSignsColor(const Value: TColor);
begin
  if Value <> FSignsColor then
  begin
    FSignsColor := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetState(const Value: TNxButtonState);
begin
  if Value <> FState then
  begin
    FState := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetStep(const Value: Double);
begin
  FStep := Value;
end;

procedure TNxTrackBar6.SetStyle(const Value: TNxAppearanceStyle);
begin
  if Value <> FStyle then
  begin
    FStyle := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetThumbBorderColor(const Value: TColor);
begin
  if Value <> FThumbBorderColor then
  begin
    FThumbBorderColor := Value;
    InvalidateRect(ThumbRect);
  end;
end;

procedure TNxTrackBar6.SetThumbColor(const Value: TColor);
begin
  if Value <> FThumbColor then
  begin
    FThumbColor := Value;
    InvalidateRect(ThumbRect);
  end;
end;

procedure TNxTrackBar6.SetThumbSize(const Value: TNxSize);
begin
  FThumbSize.Assign(Value);
  Invalidate;
end;

procedure TNxTrackBar6.SetTickMarks(const Value: Boolean);
begin
  if Value <> FTickMarks then
  begin
    FTickMarks := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetTrackColor(const Value: TColor);
begin
  if Value <> FTrackColor then
  begin
    FTrackColor := Value;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.SetTrackHeight(const Value: Integer);
begin
  if Value <> FTrackHeight then
  begin
    FTrackHeight := Value;
    if FTrackHeight < 1 then FTrackHeight := 1;
    Invalidate;
  end;
end;

procedure TNxTrackBar6.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  inherited;
  Message.Result := Message.Result or DLGC_WANTCHARS or DLGC_WANTARROWS;
end;

{ TNxButtonSlider6 }

procedure TNxButtonSlider6.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  HotIndex := -1;
end;

constructor TNxButtonSlider6.Create(AOwner: TComponent);
begin
  inherited;
  FHotIndex := -1;
  FImages := nil;
  FIndicatorColor := clGreen;
  FIndicatorHeight := 2;
  FIndicatorSpacing := pdDouble;
  FIndicatorStyle := isMultiple;
  FIndicatorWidth := 6;
  FInnactiveIndicatorColor := clSilver;
  FPushedIndex := -1;
  FSelectedIndex := 0;
  FStyle := stNative;
  FUserDefinedStyle := TNxButtonUserDefinedStyle6.Create;
  FUserDefinedStyle.OnChange := DoUserDefinedStyleChange;
end;

destructor TNxButtonSlider6.Destroy;
begin
  FreeAndNil(FUserDefinedStyle);
  inherited;
end;

procedure TNxButtonSlider6.DoSelect(NewIndex, OldIndex: Integer);
begin
  if Assigned(FOnSelect) then FOnSelect(Self, NewIndex, OldIndex);
end;

procedure TNxButtonSlider6.DoUserDefinedStyleChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TNxButtonSlider6.DrawIndicator(const AIndicatorRect: TRect; const Index: Integer);
const
  DotsSpacing = 1;
var
  i, X, NegativeSpace, CenterX, LineWidth: Integer;
  DotRect: TRect;
begin
  if IndicatorStyle = isMultiple then
  begin
    if Index > 0 then NegativeSpace := Pred(Index) * DotsSpacing else NegativeSpace := 0;

    LineWidth := IndicatorWidth * Succ(Index) + NegativeSpace;

    CenterX := AIndicatorRect.Left + (RectWidth(AIndicatorRect) div 2);

    X := CenterX - LineWidth div 2;

    for i := 0 to Index do
    begin
      DotRect := Bounds(X, AIndicatorRect.Top, IndicatorWidth, RectHeight(AIndicatorRect));

      Canvas.FillRect(DotRect);

      Inc(X, IndicatorWidth + DotsSpacing);
    end;

  end else Canvas.FillRect(AIndicatorRect);
end;

function TNxButtonSlider6.GetButtonCount: Integer;
begin
  if FImages <> nil then Result := FImages.Count else Result := 0;
end;

function TNxButtonSlider6.GetButtonIndexAtPos(const X, Y: Integer): Integer;
begin
  Result := (X - ButtonsRect.Left) div ButtonWidth;
end;

function TNxButtonSlider6.GetButtonRect(const Index: Integer): TRect;
begin
  Result := Bounds(ButtonsRect.Left, ButtonsRect.Top, ButtonWidth, RectHeight(ButtonsRect));
  OffsetRect(Result, Index * ButtonWidth, 0);
end;

function TNxButtonSlider6.GetButtonsRect: TRect;
begin
  Result := PaddingRect;
end;

function TNxButtonSlider6.GetButtonWidth: Integer;
begin
  Result := RectWidth(PaddingRect) div FImages.Count;
end;

function TNxButtonSlider6.GetSelectedButtonRect: TRect;
begin
  Result := Bounds(ButtonsRect.Left + ButtonWidth * SelectedIndex, ButtonsRect.Top,
    ButtonWidth, RectHeight(ButtonsRect));
end;

procedure TNxButtonSlider6.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  SelectedIndex := GetButtonIndexAtPos(X, Y);
  PushedIndex := SelectedIndex;
end;

procedure TNxButtonSlider6.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  HotIndex := GetButtonIndexAtPos(X, Y);
  if ssLeft in Shift then
  begin
    if InRange(HotIndex, 0, Pred(ButtonCount)) then
    begin
      PushedIndex := HotIndex;
      SelectedIndex := HotIndex;
    end;
  end;
end;

procedure TNxButtonSlider6.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  PushedIndex := -1;
end;

procedure TNxButtonSlider6.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if (AComponent = FImages) and (Operation = opRemove) then
  begin
    FImages.RemoveFreeNotification(Self);
    FImages := nil;
  end;
end;

procedure TNxButtonSlider6.Paint;
begin
  inherited;
  if not Transparent then
  begin
    FillPadding(Canvas, Color, ClientRect, Padding);
  end;
  if ButtonCount > 0 then PaintButtons(ButtonsRect) else EraseBkGnd(ClientRect, Color);
end;

procedure TNxButtonSlider6.PaintButtonContent(const AButtonRect: TRect; const Index: Integer;
  const AState: TNxButtonState);
var
  ImageRect, IndicatorRect: TRect;
  IndicatorLeft, IndicatorTop: Integer;
begin
  if InRange(Index, 0, Pred(FImages.Count)) then
  begin
    ImageRect := CenteredRect(AButtonRect, Rect(0, 0, FImages.Width, FImages.Height));
    FImages.Draw(Canvas, ImageRect.Left, ImageRect.Top, Index);

    if IndicatorStyle <> isHidden then
    begin

      if Index <= SelectedIndex then
      begin
        Canvas.Brush.Color := FIndicatorColor;
      end else
      begin
        Canvas.Brush.Color := FInnactiveIndicatorColor;
      end;

      IndicatorLeft := AButtonRect.Left + (RectWidth(AButtonRect) div 2 - IndicatorWidth div 2);
      IndicatorTop := ImageRect.Bottom + IndicatorSpacing;

      case IndicatorStyle of
        isSingle: IndicatorRect := Bounds(IndicatorLeft, IndicatorTop, IndicatorWidth, IndicatorHeight);
        isMultiple: IndicatorRect := Rect(AButtonRect.Left, IndicatorTop, AButtonRect.Right,
          IndicatorTop + IndicatorHeight);
      end;

      DrawIndicator(IndicatorRect, Index);
    end;
  end;
end;

procedure TNxButtonSlider6.PaintButtonFace(const AButtonRect: TRect;
  const Index: Integer; const AState: TNxButtonState);
begin
  Canvas.Brush.Color := Color;
  case FStyle of
    stModern:
    begin
      if AState = [] then EraseBkGnd(AButtonRect);
      DrawModernToolButton(Canvas, AButtonRect, AState);
    end;
    stNative: TNxToolbarStyle6.Paint(Canvas, Handle, AButtonRect, AState, StyleOptions, True);
    stUserDefined: PaintUserDefinedStyleButton(AButtonRect, Index, AState);
  end;
end;

procedure TNxButtonSlider6.PaintButtons(const AButtonsRect: TRect);
var
  i, X: Integer;
  ButtonRect: TRect;
  ButtonState: TNxButtonState;
begin
  inherited;
  X := AButtonsRect.Left;
  ButtonState := [];
  for i := 0 to Pred(FImages.Count) do
  begin
    ButtonRect := Bounds(X, AButtonsRect.Top, ButtonWidth, RectHeight(AButtonsRect));
    ButtonState := [];
    if i = FHotIndex then Include(ButtonState, bsHover);
    if i = FPushedIndex then Include(ButtonState, bsPressed);
    if i = FSelectedIndex then Include(ButtonState, bsChecked);
    PaintButtonFace(ButtonRect, i, ButtonState);
    PaintButtonContent(ButtonRect, i, ButtonState);
    Inc(X, RectWidth(ButtonRect));
  end;
  if X < AButtonsRect.Right then
  begin
    Canvas.Brush.Color := Color;
    Canvas.FillRect(Rect(X, AButtonsRect.Top, AButtonsRect.Right, AButtonsRect.Bottom));
  end;
end;

procedure TNxButtonSlider6.PaintUserDefinedStyleButton(const AButtonRect: TRect; const Index: Integer;
  const AState: TNxButtonState);
begin
  if Assigned(UserDefinedStyle) then
  begin
    Canvas.Brush.Color := Color;
    UserDefinedStyle.DrawToCanvas(Canvas, AButtonRect, AState);
  end;
end;

procedure TNxButtonSlider6.RefreshButton(const Index: Integer);
begin
  if InRange(Index, 0, Pred(ButtonCount)) then
  begin
    InvalidateRect(GetButtonRect(Index));
  end;
end;

procedure TNxButtonSlider6.RefreshIndicators(const Index: Integer);
var
  i: Integer;
begin
  for i := 0 to Pred(Index) do RefreshButton(i);
end;

procedure TNxButtonSlider6.SetHotIndex(const Value: Integer);
begin
  if FHotIndex <> Value then
  begin
    RefreshButton(FHotIndex);
    FHotIndex := Value;
    RefreshButton(FHotIndex);
  end;
end;

procedure TNxButtonSlider6.SetImages(const Value: TImageList);
begin
  if FImages <> Value then
  begin
    FImages := Value;
    if Assigned(FImages) then FImages.FreeNotification(Self);
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetIndicatorColor(const Value: TColor);
begin
  if FIndicatorColor <> Value then
  begin
    FIndicatorColor := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetIndicatorHeight(const Value: Integer);
begin
  if Value <> FIndicatorHeight then
  begin
    FIndicatorHeight := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetIndicatorSpacing(const Value: Integer);
begin
  if Value <> FIndicatorSpacing then
  begin
    FIndicatorSpacing := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetIndicatorStyle(const Value: TNxIndicatorStyle);
begin
  if Value <> FIndicatorStyle then
  begin
    FIndicatorStyle := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetIndicatorWidth(const Value: Integer);
begin
  if Value <> FIndicatorWidth then
  begin
    FIndicatorWidth := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetInnactiveIndicatorColor(const Value: TColor);
begin
  if Value <> FInnactiveIndicatorColor then
  begin
    FInnactiveIndicatorColor := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetPushedIndex(const Value: Integer);
begin
  if Value <> FPushedIndex then
  begin
    RefreshButton(FPushedIndex);
    FPushedIndex := Value;
    RefreshButton(FPushedIndex);
  end;
end;

procedure TNxButtonSlider6.SetSelectedIndex(const Value: Integer);
var
  OldIndex: Integer;
begin
  if Value <> FSelectedIndex then
  begin
    OldIndex := FSelectedIndex;
    RefreshButton(FSelectedIndex);
    if IndicatorStyle <> isHidden then RefreshIndicators(FSelectedIndex);
    FSelectedIndex := Value;
    RefreshButton(FSelectedIndex);
    if IndicatorStyle <> isHidden then RefreshIndicators(FSelectedIndex);
    DoSelect(FSelectedIndex, OldIndex);
  end;
end;

procedure TNxButtonSlider6.SetStyle(const Value: TNxAppearanceStyle);
begin
  if Value <> FStyle then
  begin
    FStyle := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetTransparent(const Value: Boolean);
begin
  if Value <> FTransparent then
  begin
    FTransparent := Value;
    Invalidate;
  end;
end;

procedure TNxButtonSlider6.SetUserDefinedStyle(const Value: TNxButtonUserDefinedStyle6);
begin
  if Value <> FUserDefinedStyle then
  begin
    FUserDefinedStyle := Value;
    if Assigned(FUserDefinedStyle) then
    begin
      FUserDefinedStyle.OnChange := DoUserDefinedStyleChange;
    end;
  end;
end;

end.
