(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
Unit AHMTHeaderList;

interface
{$I AHM.INC}
uses
  Windows,SysUtils, Menus, Messages, Classes, Graphics, Controls, Forms,
  stdctrls, extctrls,AHMEnhancedClass,ahmTbackground,AHMControls;

type
  TAHMHeaderList=class(TCustomPanel)
  private
    FDelimiter:Char;
    FHeader:TAHMHeader;
    FHScroll:Boolean;
    FItemHeight:Integer;
    FListBox:TListBox;
    FListBoxStyle:TListBoxStyle;
    FSelColor:TColor;
    FOnHeaderSized:TSectionEvent;
    FOnDrawItem:TDrawItemEvent;
    FAHMAboutStr : TAHMAboutEnhancedStr;
    procedure AlignClients;
    function GetBool(Index:Integer):Boolean;
    function GetCanvas:TCanvas;
    function GetColor(Index:Integer):TColor;
    function GetCursor(Index:Integer):TCursor;
    function GetFont(Index:Integer):TFont;
    function GetHint:String;
    function GetInteger(Index:Integer):Integer;
    function GetSectionEvent:TSectionEvent;
    function GetStrings(Index:Integer):TStrings;
    function GetDragMode:TDragMode;
    function GetDragDropEvent:TDragDropEvent;
    function GetDragOverEvent:TDragOverEvent;
    function GetEndDragEvent:TEndDragEvent;
    function GetKeyEvent(index:Integer):TKeyEvent;
    function GetKeyPressEvent:TKeyPressEvent;
    function GetMeasureItemEvent:TMeasureItemEvent;
    function GetMouseEvent(index:Integer):TMouseEvent;
    function GetMouseMoveEvent:TMouseMoveEvent;
    function GetNotifyEvent(index:Integer):TNotifyEvent;
    function GetSelected(index:integer):Boolean;
    function GetStartDragEvent:TStartDragEvent;
    procedure SetStartDragEvent(aValue:TStartDragEvent);
    procedure SetBool(Index:Integer;aValue:Boolean);
    procedure SetColor(Index:Integer; aValue:TColor);
    procedure SetCursor(Index:Integer; aValue:TCursor);
    procedure SetDelimiter(aValue:Char);
    procedure SetDragMod(aValue:TDragMode);
    procedure SetFont(Index:Integer; aValue:TFont);
    procedure SetHint(aValue:String);
    procedure SetInteger(Index:Integer; aValue:Integer);
    procedure SetSectionEvent(aValue:TSectionEvent);
    procedure SetStrings(Index:Integer;aValue:TStrings);
    procedure SetDragDropEvent(aValue:TDragDropEvent);
    procedure SetDragOverEvent(aValue:TDragOverEvent);
    procedure SetEndDragEvent(aValue:TEndDragEvent);
    procedure SetKeyPressEvent(aValue:TKeyPressEvent);
    procedure SetKeyEvent(index:Integer; aValue:TKeyEvent);
    procedure SetListBoxStyle(aValue:TListBoxStyle);
    procedure SetMeasureItemEvent(aValue:TMeasureItemEvent);
    procedure SetMouseEvent(index:Integer; aValue:TMouseEvent);
    procedure SetMouseMoveEvent(aValue:TMouseMoveEvent);
    procedure SetNotifyEvent(index:Integer; aValue:TNotifyEvent);
    procedure SetSelected(index:integer;flag:boolean);
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure HeaderSized(Sender:TObject;aSection,aWidth:Integer);
    procedure DrawItem(Control:TWinControl;Index:Integer;Rect:TRect;State:TOwnerDrawState);
    procedure SetHBS(value : TBorderStyle);
    Function GetHBS : TBorderStyle;
    procedure Set3D(value : TAHMFont3D);
    Function Get3D : TAHMFont3D;
    procedure SetBack(value : TAHMBackground);
    Function GetBack : TAHMBackground;
    procedure ReadI(Reader:TReader);
    procedure WriteI(Writer:TWriter);
  protected
    procedure DefineProperties(Filer:TFiler);override;
    procedure Paint; override;
  public
    constructor Create(AOwner:TComponent); override;
    procedure Loaded; override;
    destructor Destroy; override;
    function AddLine(const X:array of String):Integer;
    procedure Clear;
    procedure PrepareDrawItem(Rect:TRect;State:TOwnerDrawState);
    procedure SetFocus;override;
    function ItemAtPos(Pos:TPoint;Existing:Boolean):Integer;
    function ItemPart(Index:Integer; Col:Integer):String;
    property Canvas:TCanvas read GetCanvas;
    property ItemIndex:Integer index 1 read GetInteger write SetInteger;
    property ListBx:TListBox read FListBox;
    property SectionCount : Integer index 5 read GetInteger;
    property SelCount : Integer index 3 read GetInteger;
    property Selected[Index:integer]:Boolean read GetSelected write SetSelected;
    property Showing;
    property TopIndex:Integer index 2 read GetInteger write SetInteger;
    property Header:TAHMHeader read FHeader;
  published
    property About : TAHMAboutEnhancedStr read FAHMAboutStr write FAHMAboutStr stored False;
    {$IFDEF AHMONLY4}
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF}
    property Align;
    property AllowResize:Boolean index 5 read GetBool write SetBool default True;
    property BevelInner;
    property BevelOuter;
    property HeaderBackground:TAHMBackground read Getback write Setback;
    property HeaderFont3D : TAHMFont3D read Get3D write Set3D;
    property HeaderBorderStyle:TBorderstyle read GetHBS write SetHBS default bsNone;
    property Color:TColor index 0 read GetColor write SetColor default clWhite;
    property Cursor:TCursor index 0 read GetCursor write SetCursor default crDefault;
    property Delimiter:Char read FDelimiter write SetDelimiter default ';';
    property DragCursor:TCursor index 1 read GetCursor write SetCursor default crDrag;
    property DragMode:TDragMode read GetDragMode write SetDragMod default dmManual;
    property Enabled:Boolean index 0 read GetBool write SetBool default True;
    property ExtendedSelect:Boolean index 1 read GetBool write SetBool default True;
    property Font:TFont index 1 read GetFont write SetFont;
    property HeaderFont:TFont index 0 read GetFont write SetFont;
    property HeaderHeight:Integer index 0 read GetInteger write SetInteger default 25;
    property HeaderVisible:Boolean index 2 read GetBool write SetBool default True;
    property Hint:String read GetHint write SetHint;
    property ItemHeight:Integer index 4 read GetInteger write SetInteger stored false;
    property Items:TStrings index 1 read GetStrings write SetStrings;
    property MultiSelect:Boolean index 3 read GetBool write SetBool default false;
    property ParentShowHint:Boolean index 7 read GetBool write SetBool default True;
    property PopupMenu;
    property HeaderSections:TStrings index 0 read GetStrings write SetStrings;
    property SelectedColor:TColor index 1 read GetColor write SetColor default clHighLight;
    property ShowHint:Boolean index 6 read GetBool write SetBool default false;
    property Sorted:Boolean index 4 read GetBool write SetBool default false;
    property ListBoxStyle:TListBoxStyle read FListBoxStyle write SetListBoxStyle default lbStandard;
    property TabOrder;
    property TabStop:Boolean index 8 read GetBool write SetBool default True;
    property Visible;
    property OnClick:TNotifyEvent index 0 read GetNotifyEvent write SetNotifyEvent;
    property OnDblClick:TNotifyEvent index 1 read GetNotifyEvent write SetNotifyEvent;
    property OnDrawItem:TDrawItemEvent read FOnDrawItem write FOnDrawItem;
    property OnEnter:TNotifyEvent index 2 read GetNotifyEvent write SetNotifyEvent;
    property OnExit:TNotifyEvent index 3 read GetNotifyEvent write SetNotifyEvent;
    property OnDragDrop:TDragDropEvent read GetDragDropEvent write SetDragDropEvent;
    property OnDragOver:TDragOverEvent read GetDragOverEvent write SetDragOverEvent;
    property OnEndDrag:TEndDragEvent read GetEndDragEvent write SetEndDragEvent;
    property OnStartDrag:TStartDragEvent read GetStartDragEvent write SetStartDragEvent;
    property OnMeasureItem:TMeasureItemEvent read GetMeasureItemEvent write SetMeasureItemEvent;
    property OnMouseDown:TMouseEvent index 0 read GetMouseEvent write SetMouseEvent;
    property OnMouseMove:TMouseMoveEvent read GetMouseMoveEvent write SetMouseMoveEvent;
    property OnMouseUp:TMouseEvent index 2 read GetMouseEvent write SetMouseEvent;
    property OnKeyDown:TKeyEvent index 0 read GetKeyEvent write SetKeyEvent;
    property OnKeyUp:TKeyEvent index 1 read GetKeyEvent write SetKeyEvent;
    property OnKeyPress:TKeyPressEvent read GetKeyPressEvent write SetKeyPressEvent;
    property OnHeaderSized:TSectionEvent read FOnHeaderSized write FOnHeaderSized;
    property OnHeaderSizing:TSectionEvent read GetSectionEvent write SetSectionEvent;
    property OnResize;
  end;

implementation

function CodeString(const X:array of String; delimiter:Char):String;
var
  i:integer;
begin
  result:=X[0];
  if sizeof(x)>1 then
    for i:=1 to High(X) do result:=result+delimiter+X[i];
end;

procedure ParseToStrList(const w:string;const delimiter:char; list:TStrings);
var
  i,last:byte;
begin
  if (list=nil) or (w='') then exit;
  list.clear;
  last:=1;
  for i:=0 to length(w) do
    if (w[i]=delimiter) then
      begin
        list.add(copy(w,last,i-last));
        last:=i+1;
      end
    else
      if (i=length(w)) then
        list.add(copy(w,last,i-last+1));
end;

function GetCodedString(const aValue:String; delimiter:Char; index:Integer):String;
var
  i, last, counter:Integer;
  tmp:String;

begin
  result:='';
  i:=Pos(delimiter, aValue);
  if index=0 then
    begin
      if (i=0) then result:=aValue else result:=copy(aValue, 1,i-1);
      exit;
    end;
  if i=0 then exit;

  Counter:=0;
  tmp:=aValue;
  while i<>0 do
    begin
      tmp[i]:=chr(0);
      last:=i+1;
      i:=Pos(delimiter, tmp);
      inc(Counter);
      if Counter=Index then
        begin
          if i=0 then i:=Length(aValue)+1;
          result:=Copy(aValue, last, i-last);
          exit;
        end;
    end;
end;

procedure TAHMHeaderList.AlignClients;
begin
  FListBox.Top:=3+FHeader.Height;
  if (not FHeader.Visible) then
  begin
    FListBox.Width:=Self.Width-6;
    FListBox.Left:=3;
    FListBox.Height:=Self.Height-FListBox.Top-3;
  end
  else
  begin
    FListBox.Width:=Self.Width-8;
    FListBox.Left:=4;
    FListBox.Height:=Self.Height-FListBox.Top-4;
  end;
  if not FListBox.Visible then FListBox.Visible:=true;
  if not FHeader.Visible then exit;
  FHeader.top:=3;
  FHeader.left:=3;
  FHeader.Width:=FListBox.Width+2;
end;

function TAHMHeaderList.AddLine(const X:array of String):Integer;
begin
  result:=Items.Add(CodeString(X, FDelimiter));
end;


function TAHMHeaderList.ItemPart(Index:Integer; Col:Integer):String;
begin
  result:=GetCodedString(Items[index], FDelimiter, Col);
end;

function TAHMHeaderList.GetBool(index:Integer):Boolean;
begin
  case index of
    0: result:=FListBox.Enabled;
    1: result:=FListbox.ExtendedSelect;
    2: result:=FHeader.Visible;
    3: result:=FListbox.MultiSelect;
    4: result:=FlistBox.Sorted;
    5: result:=FHeader.AllowResize;
    6: result:=FListBox.ShowHint;
    7: result:=FListBox.ParentShowHint;
    8: result:=FListBox.TabStop;
  else
    result:=false
  end;
end;

function TAHMHeaderList.GetCanvas:TCanvas;
begin
  result:=FListBox.Canvas;
end;

function TAHMHeaderList.GetColor(Index:Integer):TColor;
begin
  case Index of
    0: Result:=FListBox.Color;
    1: Result:=FSelColor;
  else
    result:=clWhite
  end;
end;

function TAHMHeaderList.GetCursor(Index:Integer):TCursor;
begin
  case index of
    0: result:=FListBox.Cursor;
    1: result:=FListBox.DragCursor;
  else
    result:=crDefault;
  end;
end;

function TAHMHeaderList.GetDragMode:TDragMode;
begin
 result:=FListBox.DragMode;
end;

function TAHMHeaderList.GetFont(index:Integer):TFont;
begin
  case index of
    0:result:=FHeader.Font;
    1:result:=FListBox.Font;
  else
    result:=nil
  end;
end;

function TAHMHeaderList.GetHint:String;
begin
  result:=FListBox.Hint;
end;

function TAHMHeaderList.GetInteger(index:Integer):Integer;
begin
  case index of
    0:result:=FHeader.Height;
    1:result:=FListBox.Itemindex;
    2:result:=FListBox.TopIndex;
    3:result:=FListBox.SelCount;
    4:{if FListBoxStyle<>lbStandard then
        result:=FItemHeight
      else}
        result:=FListBox.ItemHeight;
    5:result:=FHeader.Sections.Count;
  else
    result:=0;
  end;
end;

function TAHMHeaderList.GetSectionEvent:TSectionEvent;
begin
  result:=FHeader.OnSizing;
end;

function TAHMHeaderList.GetStrings(index:Integer):TStrings;
begin
  case index of
    0:result:=FHeader.Sections;
    1:result:=FListBox.Items;
  else
    result:=nil
  end;
end;

function TAHMHeaderList.GetDragDropEvent:TDragDropEvent;
begin
  result:=FListBox.OnDragDrop;
end;

function TAHMHeaderList.GetDragOverEvent:TDragOverEvent;
begin
  result:=FListBox.OnDragOver;
end;

function TAHMHeaderList.GetEndDragEvent:TEndDragEvent;
begin
  result:=FListBox.OnEndDrag;
end;

function TAHMHeaderList.GetStartDragEvent:TStartDragEvent;
begin
  result:=FListBox.OnStartDrag;
end;

procedure TAHMHeaderList.SetStartDragEvent(aValue:TStartDragEvent);
begin
  FListBox.OnStartDrag:=aValue;
end;

function TAHMHeaderList.GetKeyPressEvent:TKeyPressEvent;
begin
  result:=FListBox.OnKeyPress;
end;

function TAHMHeaderList.GetMeasureItemEvent:TMeasureItemEvent;
begin
  result:=FListBox.OnMeasureItem;
end;

function TAHMHeaderList.GetMouseMoveEvent:TMouseMoveEvent;
begin
  result:=FListBox.OnMouseMove;
end;

function TAHMHeaderList.GetKeyEvent(index:Integer):TKeyEvent;
begin
  case index of
    0:result:=FListBox.OnKeyDown;
    1:result:=FListBox.OnKeyUp;
  else
    result:=nil
  end;
end;

function TAHMHeaderList.GetMouseEvent(index:Integer):TMouseEvent;
begin
  case index of
    0:result:=FListBox.OnMouseDown;
    1:result:=FListBox.OnMouseUp;
  else
    result:=nil
  end;
end;

function TAHMHeaderList.GetNotifyEvent(index:Integer):TNotifyEvent;
begin
  case index of
    0:result:=FListBox.OnClick;
    1:result:=FListBox.OnDblClick;
    2:result:=FListBox.OnEnter;
    3:result:=FListBox.OnExit;
  else
    result:=nil
  end;
end;

function TAHMHeaderList.GetSelected(index:integer):Boolean;
begin
  result:=FListBox.Selected[index];
end;

procedure TAHMHeaderList.SetBool(index:Integer;aValue:Boolean);
begin
  case index of
    0: if FListBox.Enabled<>aValue then
         begin
           FListBox.Enabled:=aValue;
           FHeader.Enabled:=aValue;
         end;
    1: if FListBox.ExtendedSelect<>aValue then FListBox.ExtendedSelect:=aValue;
    2: if aValue<>FHeader.Visible then
         begin
           FHeader.Visible:=aValue;
           Invalidate;
         end;
    3: if FListBox.MultiSelect<>aValue then FListBox.MultiSelect:=aValue;
    4: if FListBox.Sorted<>aValue then FListBox.Sorted:=aValue;
    5: if aValue<>FHeader.AllowResize then FHeader.AllowResize:=aValue;
    6: if aValue<>FListBox.ShowHint then
         begin
           FListBox.ShowHint:=aValue;
           FHeader.ShowHint:=aValue;
         end;
    7: if aValue<>FListBox.ParentShowHint then
         begin
           FListBox.ParentShowHint:=aValue;
           FHeader.ParentShowHint:=aValue;
         end;
    8: if FListBox.TabStop<>aValue then FListBox.TabsTop:=aValue;
    9: if FHScroll<>aValue then
         begin
           FHScroll:=aValue;
           SendMessage(FListBox.Handle, LB_SetHorizontalExtent, Byte(FHScroll)*FListBox.Width, Longint(0));
         end;
  end;
end;

procedure TAHMHeaderList.SetColor(Index:Integer; aValue:TColor);
begin
  case index of
    0:FListBox.Color:=aValue;
    1: if FSelColor<>aValue then
         begin
           FSelColor:=aValue;
           invalidate;
         end;
  end;
end;

procedure TAHMHeaderList.SetCursor(Index:Integer; aValue:TCursor);
begin
  case index of
    0: FListBox.Cursor := aValue;
    1: FListBox.DragCursor := aValue;
  end;
end;

procedure TAHMHeaderList.SetDelimiter(aValue:Char);
begin
  if aValue<>FDelimiter then
    begin
      FDelimiter:=aValue;
      FListBox.Refresh;
    end;
end;

procedure TAHMHeaderList.SetDragMod(aValue:TDragMode);
begin
  FListBox.DragMode:=aValue;
end;

procedure TAHMHeaderList.SetFont(index:Integer;aValue:TFont);
begin
  case index of
    0:FHeader.Font.Assign(aValue);
    1:FListBox.Font.Assign(aValue);
  end;
end;

procedure TAHMHeaderList.SetHBS(value : TBorderStyle);
begin
  fheader.BorderStyle:=value;
end;

Function TAHMHeaderList.GetHBS : TBorderStyle;
begin
  result:=fheader.BorderStyle;
end;

function TAHMHeaderList.Get3D : TAHMFont3D;
begin
  result:=FHeader.Font3D;
end;

procedure TAHMHeaderList.Set3D(value : TAHMFont3D);
begin
  fheader.Font3D.assign(value);
end;

procedure TAHMHeaderList.SetBack(value : TAHMBackground);
begin
  fheader.Background:=(value);
end;

Function TAHMHeaderList.GetBack : TAHMBackground;
begin
  result:=(fheader.Background);
end;


procedure TAHMHeaderList.SetHint(aValue:String);
begin
  if aValue<>FListBox.Hint then
    begin
      FListBox.Hint:=aValue;
      FHeader.Hint:=aValue;
    end;
end;

procedure TAHMHeaderList.SetInteger(index:Integer;aValue:Integer);
begin
  case index of
    0:if FHeader.Height<>aValue then
        begin
          FHeader.Height:=aValue;
          Invalidate;
        end;
    1:FListBox.ItemIndex:=aValue;
    2:FListBox.TopIndex:=aValue;
    4:if FListBoxStyle<>lbStandard then
        begin
          FItemHeight:=aValue;
          FListBox.ItemHeight:=aValue;
        end;

  end;
end;

procedure TAHMHeaderList.SetSectionEvent(aValue:TSectionEvent);
begin
  FHeader.OnSizing:=aValue;
end;

procedure TAHMHeaderList.SetStrings(index:Integer;aValue:TStrings);
begin
  case index of
  0:begin
      FHeader.Sections.Assign(aValue);
      FListBox.Refresh;
    end;
  1:FListbox.Items.Assign(aValue);
end;

end;

procedure TAHMHeaderList.SetKeyEvent(index:Integer; aValue:TKeyEvent);
begin
  case index of
    0:FListBox.OnKeyDown:=aValue;
    1:FListBox.OnKeyUp:=aValue;
  end;
end;

procedure TAHMHeaderList.SetDragDropEvent(aValue:TDragDropEvent);
begin
  FListBox.OnDragDrop:=aValue;
end;

procedure TAHMHeaderList.SetDragOverEvent(aValue:TDragOverEvent);
begin
  FListBox.OnDragOver:=aValue;
end;

procedure TAHMHeaderList.SetEndDragEvent(aValue:TEndDragEvent);
begin
  FListBox.OnEndDrag:=aValue;
end;

procedure TAHMHeaderList.SetKeyPressEvent(aValue:TKeyPressEvent);
begin
  FListBox.OnKeyPress:=aValue;
end;

procedure TAHMHeaderList.SetListBoxStyle(aValue:TListBoxStyle);
begin
  if aValue<>FListboxStyle then
  begin
    if aValue=lbStandard then
    begin
      FListBox.Style:=lbStandard;
      Itemheight:=FListbox.Itemheight;
      FListBox.Style:=lbOwnerDrawFixed
    end
    else FListBox.Style:=aValue;
    FListBoxStyle:=aValue;
  end;
end;

procedure TAHMHeaderList.SetMeasureItemEvent(aValue:TMeasureItemEvent);
begin
  FListBox.OnMeasureItem:=aValue;
end;

procedure TAHMHeaderList.SetMouseMoveEvent(aValue:TMouseMoveEvent);
begin
  FListBox.OnMouseMove:=aValue;
end;

procedure TAHMHeaderList.SetMouseEvent(index:Integer; aValue:TMouseEvent);
begin
  case index of
    0:FListBox.OnMouseDown:=aValue;
    1:FListBox.OnMouseUp:=aValue;
  end;
end;

procedure TAHMHeaderList.SetNotifyEvent(index:Integer; aValue:TNotifyEvent);
begin
  case index of
    0:FListBox.OnClick:=aValue;
    1:FListBox.OnDblClick:=aValue;
    2:FListBox.OnEnter:=aValue;
    3:FListBox.OnExit:=aValue;
  end;
end;

procedure TAHMHeaderList.SetSelected(index:integer;flag:boolean);
begin
  FListBox.Selected[index]:=flag;
end;

procedure TAHMHeaderList.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  inherited;
end;

procedure TAHMHeaderList.HeaderSized(Sender:TObject;aSection,aWidth:Integer);
begin
  FListBox.Refresh;
  if Assigned(FonHeaderSized) then FOnHeaderSized(Sender, aSection, aWidth);
end;

procedure TAHMHeaderList.DrawItem(Control:TWinControl;Index:Integer;Rect:TRect;State:TOwnerDrawState);
var tmpList:TStringList;
    tmpItem:String;
    tmpRect:TRect;
    i:Integer;

begin

  If (FListBoxStyle<>lbStandard) and Assigned(FOnDrawItem) then
    begin
      FOnDrawItem(Control, Index, Rect, State);
      exit;
    end;

  with FListBox.Canvas do
    begin
      PrepareDrawItem(Rect, State);
      tmpItem:=FListBox.Items[Index];
      if Length(Trim(tmpitem))<>0 then
        begin
           tmpList:=TStringList.Create;
           try
             tmpRect:=Rect;
             if FHeader.Sections.Count=0 then
               begin
                 TextRect(tmpRect, tmprect.Left+2, tmpRect.Top, tmpitem);
               end
             else
               begin
                 ParseToStrList(tmpItem, FDelimiter, tmpList);
                 for i:=0 to tmpList.Count-1 do
                   begin
                     tmpRect.Right:=tmpRect.Left+FHeader.SectionWidth[i];
                     TextRect(tmpRect, tmprect.Left+2, tmpRect.Top+1, tmpList[i]);
                     tmpRect.Left:=tmpRect.Right;
                     if FHeader.Sections.Count-1=i then exit;
                   end;
               end;
           finally
             tmpList.free;
           end;
        end;

    end;

end;

procedure TAHMHeaderList.PrepareDrawItem(Rect:TRect;State:TOwnerDrawState);
begin
  with FListBox.Canvas do
    begin
      if odSelected in State then
         begin
           Brush.Color := FSelColor;
           Font.Color:=clHighlightText;
         end
       else
         begin
           Brush.Color := Color;
           if oddisabled in State then
             Font.Color:=clInactiveCaption
           else
            Font.Color:=Self.Font.Color;
         end;
       Brush.Style := bsSolid;
       FillRect(Rect);
       if odFocused in State then DrawFocusRect(Rect);
       Brush.Style := bsClear;
    end;

end;

procedure TAHMHeaderList.ReadI(Reader:TReader);
begin
  FListBox.ItemHeight:=Reader.ReadInteger;
end;

procedure TAHMHeaderList.WriteI(Writer:TWriter);
begin
  Writer.WriteInteger(FListBox.ItemHeight);
end;

procedure TAHMHeaderList.DefineProperties(Filer:TFiler);
begin
  Filer.DefineProperty('ItemHeight', ReadI, WriteI, FListBoxStyle<>lbStandard);
end;

procedure TAHMHeaderList.Paint;
begin
  inherited Paint;
  AlignClients;
end;

constructor TAHMHeaderList.Create(AOwner :TComponent);
begin
  inherited Create(AOwner);
  Ctl3D:=False;
  FDelimiter:=';';
  FHScroll:=False;
  FSelColor:=clHighLight;
  FHeader:=TAHMHeader.Create(Self);
  with FHeader do
  begin
    Parent:=Self;
    OnSized:=HeaderSized;
    TabStop:=False;
  end;
  FListBox:=TListBox.Create(Self);
  with FListBox do
    begin
      ParentCtl3D:=False;
      Ctl3D:=False;
      Borderstyle:=bsNone;
      Parent:=Self;
      Color:=clWhite;
      OnDrawItem:=DrawItem;
      Style:=lbOwnerDrawFixed;
    end;
  ControlStyle:=ControlStyle-[csAcceptsControls, csSetCaption];
  AlignClients;
end;

procedure TAHMHeaderList.Loaded;
begin
  inherited Loaded;
end;

destructor TAHMHeaderList.Destroy;
begin
  FHeader.Free;
  FListBox.Free;
  inherited destroy;
end;

function TAHMHeaderList.ItemAtPos(Pos:TPoint;Existing:Boolean):Integer;
begin
  result:=FListBox.ItemAtPos(Pos,Existing);
end;

procedure TAHMHeaderList.Clear;
begin
  FListBox.Clear;
end;

procedure TAHMHeaderList.SetFocus;
begin
  FListBox.SetFocus;
end;

end.
