(************************************************************************
*    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 AHMTPrinterCombo;

interface
{$I AHM.INC}
uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Menus,Printers,AHMStdClass,AHMStandardConst;

type
  TAHMPrinterCombo = class(TCustomCombobox)
  private
    FAboutStr : TAHMAboutSControlStr;
    FResBmp : TBitmap;
    Function GetSelectedPrinter : String;
  protected
    procedure DrawItem(Index : Integer; Rect : TRect; State : TOwnerDrawState); override;
    property ItemHeight;
    property Style;
    property Items;
    property MaxLength;
    property Sorted;
    property Text;
    property OnMeasureItem;
  public
    constructor Create(AOwner : TComponent); override;
    procedure CreateWnd; override;
    procedure Loaded; override;
    destructor Destroy; override;
    property SelectedPrinter : string read GetSelectedPrinter;
    procedure Change; override;
  published
    property About : TAHMAboutSControlStr read FAboutStr write FAboutStr;
    {$IFDEF AHMONLY4}
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF}
    property Color;
    property Ctl3D;
    property DragMode;
    property DragCursor;
    property DropDownCount;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnDropDown;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
  end;

{$R AHMTPrinterCombo.res}
implementation

constructor TAHMPrinterCombo.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  if Owner is TWinControl then Parent := (Owner as TWinControl);
  FResBmp:=TBitmap.Create;
  FResBmp.LoadFromResourceName(HInstance,'AHMPrinterResource');
  Style:=csOwnerDrawFixed;
  Itemheight:=22;
end;

procedure TAHMPrinterCombo.Loaded;
begin
  inherited Loaded;
  Itemheight:=22;
end;

procedure TAHMPrinterCombo.CreateWnd;
begin
  inherited CreateWnd;
  Items.clear;
  Items:=Printer.Printers;
  Itemheight:=22;
  if Items.Count=0 then
  begin
    Items.add(ahmrcstdnoprinters);
    ItemIndex:=0;
    Enabled:=false;
  end else ItemIndex:=Printer.PrinterIndex;
end;

destructor TAHMPrinterCombo.Destroy;
begin
  FResBmp.Free;
  inherited Destroy;
end;

function TAHMPrinterCombo.GetSelectedPrinter : String;
begin
  result:='';
end;

procedure TAHMPrinterCombo.DrawItem(Index : Integer; Rect : TRect; State : TOwnerDrawState);
var CurRect:TRect;
begin
  CurRect:=Classes.Rect(6,((Itemheight-FResbmp.Height) div 2)+2,22,((Itemheight - FResbmp.Height) div 2)+FResbmp.Height+2);
  canvas.fillrect(rect);
  with Canvas do
  begin
    BrushCopy(CurRect,FResBmp,Classes.Rect(0,0,FResBmp.Width,FResbmp.Height),FResBmp.Canvas.Pixels[0,FresBmp.Height-1]);
    Currect:=ClientRect;
    OffsetRect(Currect,25,0);
    DrawTextEx(Canvas.Handle,PChar(Items[Index]),-1,CurRect,DT_Left or DT_VCenter or DT_SingleLine,nil);
  end;
end;

procedure TAHMPrinterCombo.Change;
begin
  Printer.PrinterIndex:=ItemIndex;
end;

end.
