home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d456 / DCSLIB25.ZIP / DCEditButton.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-26  |  77KB  |  2,612 lines

  1. {
  2.  BUSINESS CONSULTING
  3.  s a i n t - p e t e r s b u r g
  4.  
  5.          Components Library for Borland Delphi 4.x, 5.x
  6.          Copyright (c) 1998-2000 Alex'EM
  7.  
  8. }
  9. unit DCEditButton;
  10. {$I DCConst.inc}
  11.  
  12. interface
  13.  
  14. uses
  15.   Windows, SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  16.   Dialogs, StdCtrls, DCEditTools, Forms, ComCtrls, DCConst;
  17.  
  18. type
  19.   PButtonInfo = ^TButtonInfo;
  20.   TButtonInfo = packed record
  21.     Allignment : WORD;
  22.     Tag        : integer;
  23.     Style      : WORD;
  24.     EvtStyle   : WORD;
  25.     Top        : smallint;
  26.     Left       : smallint;
  27.     Height     : smallint;
  28.     Width      : smallint;
  29.     ImageIndex : integer;
  30.     Enabled    : boolean;
  31.     Grouped    : boolean;
  32.     AncStyle   : WORD;
  33.     DisStyle   : WORD;
  34.     AbsolutePos: boolean;
  35.     ResetOnExit: boolean;
  36.   end;
  37.  
  38.   TEBHintEvent  = procedure (Sender: TObject; Mode:integer) of object;
  39.   TEBCheckArea  = procedure (Sender: TObject; X, Y: integer; var Selected: boolean) of object;
  40.   TEBGetRegion  = procedure (Sender: TObject; var Rgn: HRGN) of object;
  41.   TEBSetState  =  procedure (Sender: TObject; var State: TButtonState) of object;
  42.  
  43.   TDCEditButtons = class;
  44.   TEditButtonClass = class of TDCEditButton;
  45.  
  46.   TDCEditButton = class(TPersistent)
  47.   private
  48.     FName: string;
  49.     FLeft: integer;
  50.     FTop: integer;
  51.     FWidth: integer;
  52.     FHeight: integer;
  53.     FStyle: TButtonStyle;
  54.     FOwner: TWinControl;
  55.     FEditButtons: TDCEditButtons;
  56.     FButtonState: TButtonState;
  57.     FGlyph: TBitmap;
  58.     FEnabled: boolean;
  59.     FCanvas: TCanvas;
  60.     FBrushColor: TColor;
  61.     FDown: boolean;
  62.     FDownButton: boolean;
  63.     FDownClick: boolean;
  64.     FEventStyle: TEventStyle;
  65.     FText: string;
  66.     FAllignment: TAllignment;
  67.     FFont: TFont;
  68.     FHint: string;
  69.     FMouseInControl: boolean;
  70.     FOnClick: TNotifyEvent;
  71.     FDisableStyle: TDisableStyle;
  72.     FVisible: boolean;
  73.     FVisibleWidth: integer;
  74.     FOnDrawHint: TEBHintEvent;
  75.     FOnCheckArea: TEBCheckArea;
  76.     FGrouped: boolean;
  77.     FAnchorStyle: TAnchorStyle;
  78.     FAbsolutePos: boolean;
  79.     FImages: TImageList;
  80.     FImageIndex: integer;
  81.     FIndex: integer;
  82.     FResetOnExitControl: boolean;
  83.     FTextSize: TPoint;
  84.     FOnSetButtonState: TEBSetState;
  85.     FTag: integer;
  86.     FDrawText: boolean;
  87.     FHighlight: boolean;
  88.     FFlatPattern: boolean;
  89.     FComment: string;
  90.     FFocusSensitive: boolean;
  91.     FDoubleBuffered: boolean;
  92.     FTransparent: boolean;
  93.     FSelectColor: TColor;
  94.     FSimpleStyle: boolean;
  95.     function GetGlyph: TBitmap;
  96.     procedure SetGlyph(Value: TBitmap);
  97.     procedure DrawHint(Mode: integer);
  98.     procedure DrawTransformBitmap(ACanvas: TCanvas; ImageRect: TRect; Style: TTransformStyle);
  99.     procedure SetText(Value:string);
  100.     procedure SetAllignment(Value:TAllignment);
  101.     procedure SetButtonState(Value:TButtonState);
  102.     procedure SetMouseInControl(Value:boolean);
  103.     procedure SetCanvas(Value:TCanvas);
  104.     procedure SetEnabled(const Value: boolean);
  105.     procedure SetVisible(const Value: boolean);
  106.     function GetWidth: integer;
  107.     procedure SetImages(const Value: TImageList);
  108.     procedure SetImageIndex(const Value: integer);
  109.     procedure SetFont(const Value: TFont);
  110.     function IsEqual(Button: TDCEditButton): Boolean;
  111.     procedure SetWidth(const Value: integer);
  112.     procedure SetHighlight(const Value: boolean);
  113.     procedure SetDownClick(const Value: boolean);
  114.     procedure SetStyle(const Value: TButtonStyle);
  115.     procedure SetTransparent(const Value: boolean);
  116.     procedure SetSelectColor(const Value: TColor);
  117.   protected
  118.     function AsignedImages: boolean;
  119.     function GetEditButtons: TDCEditButtons;
  120.     procedure DrawBkgnd(ACanvas: TCanvas; Rect: TRect); virtual;
  121.     procedure DrawBitmap(ACanvas: TCanvas; ImageRect: TRect); virtual;
  122.     procedure DrawEditText(ACanvas: TCanvas; var TextRect: TRect); virtual;
  123.     procedure DrawLiteDisableBitmap(ACanvas: TCanvas; ImageRect: TRect);
  124.     procedure DrawNormDisableBitmap(ACanvas: TCanvas; ImageRect: TRect);
  125.     procedure DrawTranDisableBitmap(ACanvas: TCanvas; ImageRect: TRect);
  126.     function OneClickButton: boolean; virtual;
  127.     function GetTextSize: TPoint; virtual;
  128.     procedure BeginDrawText(ACanvas: TCanvas; ATextRect: TRect); virtual;
  129.     procedure BeginDrawBkgn(ACanvas: TCanvas; ARect: TRect;
  130.       var ImageRect: TRect; var TextRect: TRect); virtual;
  131.     property FocusSensitive: boolean read FFocusSensitive write FFocusSensitive;
  132.   public
  133.     procedure Paint(Clip: HRGN = NULLREGION); virtual;
  134.     procedure DoPaint(ACanvas: TCanvas; ARect: TRect); virtual;
  135.     procedure DrawBorder(ACanvas: TCanvas; ARect: TRect); virtual;
  136.     constructor Create(AOwner: TComponent); virtual;
  137.     destructor Destroy; override;
  138.     procedure SetBounds(ARect: TRect);
  139.     function UpdateButtonState(X, Y: integer; ADown, AMove: boolean): boolean;
  140.     function  MouseInRect(X, Y: integer): boolean;
  141.     procedure ResetProperties;
  142.     function GetImageRect: TRect;
  143.     function GetTextRect(IRect: TRect): TRect;
  144.     function GetImageOffset: TPoint; virtual;
  145.     function GetTextOffset: TPoint; virtual;
  146.     procedure Invalidate;
  147.     procedure Click;
  148.     function GetGlyphHeight: integer;
  149.     function GetGlyphWidth: integer;
  150.     function GetBounds: TRect;
  151.     procedure ReadData(Stream: TStream; Info: PButtonInfo);
  152.     procedure WriteData(Stream: TStream; Info: PButtonInfo);
  153.     property AbsolutePos: boolean read FAbsolutePos write FAbsolutePos;
  154.     property Images: TImageList read FImages write SetImages;
  155.     property Index: integer read FIndex;
  156.     property ResetOnExitControl: boolean read FResetOnExitControl
  157.       write FResetOnExitControl;
  158.     property OnCheckArea: TEBCheckArea read FOnCheckArea write FOnCheckArea;
  159.     property Name: string read FName write FName;
  160.     property Glyph: TBitmap read GetGlyph write SetGlyph;
  161.     property ButtonState: TButtonState read FButtonState write SetButtonState;
  162.     property Style: TButtonStyle read FStyle write SetStyle;
  163.     property Enabled: boolean read FEnabled write SetEnabled;
  164.     property BrushColor: TColor read FBrushColor write FBrushColor;
  165.     property EventStyle: TEventStyle read FEventStyle write FEventStyle;
  166.     property Width: integer read GetWidth write SetWidth;
  167.     property Height: integer read FHeight write FHeight;
  168.     property Left: integer read FLeft write FLeft;
  169.     property Top: integer read FTop write FTop;
  170.     property Tag: integer read Ftag write FTag;
  171.     property Text: string read FText write SetText;
  172.     property Caption: string read FText write SetText;
  173.     property Allignment: TAllignment read FAllignment write SetAllignment;
  174.     property Font: TFont read FFont write SetFont;
  175.     property Hint: string read FHint write FHint;
  176.     property MouseInControl: boolean read FMouseInControl write SetMouseInControl;
  177.     property Canvas: TCanvas read FCanvas write SetCanvas;
  178.     property OnClick: TNotifyEvent read FOnClick write FOnClick;
  179.     property DisableStyle: TDisableStyle read FDisableStyle write FDisableStyle;
  180.     property Visible: boolean read FVisible write SetVisible;
  181.     property OnDrawHint: TEBHintEvent read FOnDrawHint write FOnDrawHint;
  182.     property Owner: TWinControl read FOwner;
  183.     property Grouped: boolean read FGrouped write FGrouped;
  184.     property AnchorStyle: TAnchorStyle read FAnchorStyle write FAnchorStyle;
  185.     property ImageIndex: integer read FImageIndex write SetImageIndex;
  186.     property OnSetButtonState: TEBSetState read FOnSetButtonState write FOnSetButtonState;
  187.     property DownClick: boolean read FDownClick write SetDownClick;
  188.     property DownButton: boolean read FDownButton write FDownButton;
  189.     property DrawText: boolean read FDrawText write FDrawText;
  190.     property Highlight: boolean read FHighlight write SetHighlight;
  191.     property TextSize: TPoint read FTextSize;
  192.     property FlatPattern: boolean read FFlatPattern write FFlatPattern;
  193.     property Comment: string read FComment write FComment;
  194.     property DoubleBuffered: boolean read FDoubleBuffered write FDoubleBuffered;
  195.     property OwnerButtons: TDCEditButtons read FEditButtons;
  196.     property Transparent: boolean read FTransparent write SetTransparent;
  197.     property SelectColor: TColor read FSelectColor write SetSelectColor;
  198.     property SimpleStyle: boolean read FSimpleStyle write FSimpleStyle;
  199.   end;
  200.  
  201.   TDCHintButton = class(TDCEditButton)
  202.   protected
  203.     function GetTextSize: TPoint; override;
  204.   public
  205.     constructor Create(AOwner: TComponent); override;
  206.     procedure DrawBorder(ACanvas: TCanvas; ARect: TRect); override;
  207.   end;
  208.  
  209.   TDCEditButtons = class(TPersistent)
  210.   private
  211.     FOwner: TWinControl;
  212.     FButtons: TList;
  213.     FMaxImageWidth: integer;
  214.     FMouseDown: boolean;
  215.     FMouseInControl: boolean;
  216.     FProcClear: boolean;
  217.     FNewWndProc: Pointer;
  218.     FDefWndProc: Pointer;
  219.     FAnchorStyle: TAnchorStyle;
  220.     FAbsolutePos: boolean;
  221.     FActiveButton: TDCEditButton;
  222.     FImages: TImageList;
  223.     FOnGetRegion: TEBGetRegion;
  224.     FColor: TColor;
  225.     FPaintOnSizing: boolean;
  226.     FUpdateCount: integer;
  227.     FOnlyClientRepaint: boolean;
  228.     FBkgImage: TBitmap;
  229.     procedure EditWndProc(var Message: TMessage);
  230.     procedure SetButton(Index: integer; const Value: TDCEditButton);
  231.     function GetButton(Index: integer): TDCEditButton;
  232.     function GetCount: integer;
  233.     procedure OffsetButtons(Pos: TPoint);
  234.     function GetEnabled: boolean;
  235.     procedure SetEnabled(const Value: boolean);
  236.     procedure SetImages(const Value: TImageList);
  237.     procedure UpdateIndex;
  238.     procedure SetColor(const Value: TColor);
  239.     function GetSelectedButton: TDCEditButton;
  240.     procedure SetActiveButton(const Value: TDCEditButton);
  241.     procedure DoChangeFocus;
  242.     function GetButtonsActive: boolean;
  243.     function UpdateButtonsOnClick(X, Y: integer; AMove: boolean): boolean;
  244.   private
  245.     procedure ReadData(Stream: TStream);
  246.     procedure WriteData(Stream: TStream);
  247.   protected
  248.     procedure DefineProperties(Filer: TFiler); override;
  249.     procedure SaveBackground;
  250.   public
  251.     constructor Create(AOwner: TWinControl);
  252.     destructor Destroy; override;
  253.     function GetRegion: HRGN;
  254.     function AddButton: TDCEditButton;
  255.     function AddButtonEx(EditButtonClass: TEditButtonClass): TDCEditButton;
  256.     procedure DeleteButton(Index: integer);
  257.     procedure MoveButton(CurIndex, NewIndex: integer);
  258.     function FindButton(AName: string): TDCEditButton;
  259.     function UpdateButtons(XPos, YPos: integer; ADown, AMove: boolean): boolean;
  260.     function MouseInButtonArea(XPos, YPos: integer; var Button: TDCEditButton): boolean;
  261.     function GetButtonsRect: TRect;
  262.     procedure ResetProperties;
  263.     procedure UpdateDeviceRegion(DC: HDC);
  264.     procedure UpdateMouseInControl(Value: boolean);
  265.     procedure SetWndProc;
  266.     procedure ClrWndProc;
  267.     procedure RepaintButtons(AClip: HRGN = NULLREGION);
  268.     procedure Clear;
  269.     procedure Invalidate;
  270.     procedure BeginUpdate;
  271.     procedure EndUpdate;
  272.     procedure UpdateMaxImageWidth;
  273.     procedure PaintBackground(ARect: TRect; AButton: TDCEditButton; ACanvas: TCanvas);
  274.     function IsButtonAccel(VK: Word; var Button: TDCEditButton): Boolean;
  275.     property Buttons[Index: integer]: TDCEditButton read GetButton write SetButton;
  276.     property Items[Index: integer]: TDCEditButton read GetButton write SetButton;
  277.     property Count: integer read GetCount;
  278.     property Owner: TWinControl read FOwner;
  279.     property ActiveButton: TDCEditButton read FActiveButton write SetActiveButton;
  280.     property MaxImageWidth: integer read FMaxImageWidth;
  281.     property MouseDown: boolean read FMouseDown write FMouseDown;
  282.     property AbsolutePos: boolean read FAbsolutePos write FAbsolutePos;
  283.     property Images: TImageList read FImages write SetImages;
  284.     property AnchorStyle: TAnchorStyle read FAnchorStyle write FAnchorStyle;
  285.     property Enabled: boolean read GetEnabled write SetEnabled;
  286.     property OnGetRegion: TEBGetRegion read FOnGetRegion write FOnGetRegion;
  287.     property Color: TColor read FColor write SetColor;
  288.     property PaintOnSizing: boolean read FPaintOnSizing write FPaintOnSizing;
  289.     property SelectedButton: TDCEditButton read GetSelectedButton;
  290.     property IsButtonsActive: boolean read GetButtonsActive;
  291.     property OnlyClientRepaint: boolean read FOnlyClientRepaint write FOnlyClientRepaint;
  292.   end;
  293.  
  294. const
  295.   ButtonOffset  = 3;   // ╨α±±≥ε φΦσ ∞αµΣ≤ φα≈αδε∞ Ωφε∩ΩΦ Φ φα≈αδε∞ ≡Φ±≤φΩα
  296.   TextBtnOffset = 3;   // ╨α±±≥ε φΦσ ∞σµΣ≤ ≡Φ±≤φΩε∞ Φ φα≈αδε∞ φαΣ∩Φ±Φ
  297.  
  298. procedure HookMouseHooks(AButtons: TDCEditButtons);
  299. procedure UnHookMouseHooks;
  300.  
  301. implementation
  302. uses
  303.   DCResource;
  304.  
  305. type
  306.   TEditControl = class(TWinControl)
  307.     {}
  308.   end;
  309.  
  310. var
  311.   UserBitmap, GlyphBitmap: TBitmap;
  312.   MouseHook: HHOOK;
  313.   Buttons: TDCEditButtons;
  314.  
  315. function GetMouseHook(nCode: Integer; wParam: Longint; var Msg: TMsg): Longint; stdcall;
  316. begin
  317.   Result := CallNextHookEx(MouseHook, nCode, wParam, Longint(@Msg));
  318.   if (nCode >= 0) and (Application <> nil) and (Buttons <> nil)then
  319.   with Msg do
  320.   begin
  321.     if (Message = WM_LBUTTONUP) then
  322.     begin
  323.       Buttons.UpdateButtons( -1, -1, False, False);
  324.       UnHookMouseHooks;
  325.     end;
  326.   end;
  327. end;
  328.  
  329. procedure HookMouseHooks(AButtons: TDCEditButtons);
  330. begin
  331.   if MouseHook = 0 then
  332.   begin
  333.     MouseHook := SetWindowsHookEx(WH_GETMESSAGE, @GetMouseHook, 0, GetCurrentThreadID);
  334.     Buttons := AButtons;
  335.   end;
  336. end;
  337.  
  338. procedure UnHookMouseHooks;
  339. begin
  340.   if MouseHook <> 0 then UnhookWindowsHookEx(MouseHook);
  341.   MouseHook := 0;
  342. end;
  343.  
  344. constructor TDCEditButton.Create(AOwner: TComponent);
  345. begin
  346.   inherited Create;
  347.   FName  := 'Button';
  348.  
  349.   FGlyph := TBitmap.Create;
  350.   FGlyph.Transparent := True;
  351.  
  352.   FEnabled := True;
  353.   FOwner := AOwner as TWinControl;
  354.  
  355.   FCanvas := TControlCanvas.Create;
  356.   TControlCanvas(FCanvas).Control := AOwner as TWinControl;
  357.   FFont := FCanvas.Font;
  358.  
  359.   FButtonState   := btRest;
  360.   FGlyph.LoadFromResourceName(HInstance, 'DC_BTNPOPUP');
  361.   FDown := False;
  362.   FDownButton := False;
  363.   FDownClick := False;
  364.   FEventStyle := esNormal;
  365.   FAllignment := abCenter;
  366.   FMouseInControl:= False;
  367.   FDisableStyle := deLite;
  368.   FVisible := True;
  369.   FGrouped := False;
  370.   FImageIndex := -1;
  371.   FDrawText := True;
  372.  
  373.   FResetOnExitControl := True;
  374.   FEditButtons := nil;
  375.   FHighlight := True;
  376.   FFlatPattern := False;
  377.   FFocusSensitive := False;
  378.   FDoubleBuffered := True;
  379.   FTransparent := False;
  380.   FSelectColor := clXPSelected;
  381.   FSimpleStyle := False;
  382. end;
  383.  
  384. destructor TDCEditButton.Destroy;
  385. begin
  386.   FGlyph.Free;
  387.   FCanvas.Free;
  388.   inherited;
  389. end;
  390.  
  391. procedure TDCEditButton.SetBounds(ARect: TRect);
  392. begin
  393.   Left  := ARect.Left;
  394.   Top   := ARect.Top;
  395.   Width := ARect.Right{ - ARect.Left};
  396.   Height:= ARect.Bottom{ - ARect.Top};
  397. end;
  398.  
  399. function TDCEditButton.MouseInRect(X, Y: integer): boolean;
  400. begin
  401.   if Visible and Enabled then
  402.     Result := PtInRect(Rect(FLeft,FTop,FLeft+FWidth,FTop+FHeight), Point(X,Y))
  403.   else
  404.     Result := False;
  405.   if Assigned(FOnCheckArea) then  FOnCheckArea(Self, X, Y, Result)
  406. end;
  407.  
  408. function TDCEditButton.UpdateButtonState( X, Y: integer; ADown, AMove: boolean): boolean;
  409.  var
  410.   OButtonState: TButtonState;
  411.   ClickButton: boolean;
  412. begin
  413.   OButtonState := FButtonState;
  414.   ClickButton  := False;
  415.  
  416.   if Caption = MenuLineCaption then
  417.   begin
  418.     ButtonState := btRest;
  419.     Result := False;
  420.     Exit;
  421.   end;
  422.  
  423.   if not Enabled then
  424.   begin
  425.     if MouseInRect(X, Y) then
  426.       ButtonState := btRestMouseInRect
  427.     else
  428.       ButtonState := btRest;
  429.   end
  430.   else begin
  431.     case FEventStyle of
  432.       esNormal  :
  433.         begin
  434.           if MouseInRect(X, Y)
  435.           then
  436.             if not AMove then
  437.             begin
  438.               if ADown then
  439.               begin
  440.                  ButtonState := btDownMouseInRect;
  441.                  FDown := True;
  442.               end
  443.               else begin
  444.                 ButtonState := btRestMouseInRect;
  445.                 if FDown or OneClickButton then
  446.                   if ButtonState <> OButtonState then ClickButton := True;
  447.               end
  448.             end
  449.             else begin
  450.               if ADown and FDown then
  451.                  ButtonState := btDownMouseInRect
  452.               else begin
  453.                 ButtonState := btRestMouseInRect;
  454.                 FDown := False;
  455.               end;
  456.             end
  457.           else begin
  458.             ButtonState := btRest;
  459.           end;
  460.           if not ADown and not AMove then FDown:= False;
  461.         end;
  462.       esDropDown:
  463.         begin
  464.           if FDownClick then
  465.           begin
  466.             if MouseInRect(X, Y) then
  467.               if not AMove then
  468.               begin
  469.                 if ADown then
  470.                 begin
  471.                    ButtonState := btDownMouseInRect;
  472.                    FDown := True;
  473.                 end
  474.                 else begin
  475.                   if FDown or OneClickButton then
  476.                   begin
  477.                     FDownButton := not FDownButton;
  478.                     if FDownButton then
  479.                     begin
  480.                       ButtonState := btDownMouseInRect;
  481.                       if ButtonState = btDownMouseInRect then 
  482.                         Click
  483.                       else
  484.                         FDownButton := not FDownButton;
  485.                     end
  486.                     else begin
  487.                       ButtonState := btRestMouseInRect;
  488.                       if ButtonState = btRestMouseInRect then 
  489.                         Click
  490.                       else
  491.                         FDownButton := not FDownButton;
  492.                     end;
  493.                   end;
  494.                 end
  495.               end
  496.               else begin
  497.                 if (ADown and FDown) or FDownButton then
  498.                   ButtonState := btDownMouseInRect
  499.                 else begin
  500.                   if not ADown then
  501.                     ButtonState := btRestMouseInRect
  502.                   else
  503.                     ButtonState := btRest;
  504.                   FDown := False;
  505.                 end;
  506.               end
  507.             else begin
  508.               if FDownButton then
  509.                 ButtonState := btDownMouseInRect
  510.               else begin
  511.                 if FDown then 
  512.                 begin
  513.                   if FDownButton then
  514.                     ButtonState := btDownMouseInRect
  515.                   else
  516.                     if not AMove then
  517.                       ButtonState := btRest
  518.                     else
  519.                       ButtonState := btRestMouseInRect;
  520.                 end
  521.                 else
  522.                   ButtonState := btRest;
  523.               end;
  524.             end;
  525.             if not ADown and not AMove then FDown:= False;
  526.           end
  527.           else begin
  528.             if MouseInRect(X,Y) then 
  529.             begin
  530.               if ADown then
  531.               begin
  532.                 if not AMove then
  533.                 begin
  534.                   case FButtonState of
  535.                       btDownMouseInRect :
  536.                         begin
  537.                           ButtonState := btRestMouseInRect;
  538.                           if Buttonstate = btRestMouseInRect then ClickButton := True;
  539.                         end;
  540.                       btRestMouseInRect,
  541.                       btRest :
  542.                         begin
  543.                           ButtonState := btDownMouseInRect;
  544.                           if Buttonstate = btDownMouseInRect then ClickButton := True;
  545.                         end;
  546.                   end;
  547.                 end
  548.               end
  549.               else if FButtonState <> btDownMouseInRect then
  550.               begin
  551.                 ButtonState := btRestMouseInRect;
  552.               end
  553.             end
  554.             else
  555.               if FButtonState <> btDownMouseInRect then
  556.               begin
  557.                 ButtonState := btRest;
  558.               end
  559.           end;
  560.         end;
  561.     end;
  562.   end;
  563.   if OButtonState <> FButtonState then
  564.   begin
  565.     if not( (OButtonState in [btRestMouseInRect, btRest]) and
  566.             (FButtonState in [btRestMouseInRect, btRest]) and
  567.             ((FStyle = stNormal) or FMouseInControl)
  568.           )
  569.     then begin
  570.       invalidate;
  571.       Result := True;
  572.     end
  573.     else
  574.       Result := False;
  575.  
  576.   end else
  577.     Result := False;
  578.  
  579.   if ClickButton then Click;
  580.  
  581. end;
  582.  
  583. procedure TDCEditButton.SetGlyph( Value: TBitmap );
  584. begin
  585.   FGlyph.Assign(Value);
  586.   invalidate;
  587. end;
  588.  
  589. function TDCEditButton.GetGlyph: TBitmap;
  590. begin
  591.   Result := FGlyph;
  592. end;
  593.  
  594. procedure TDCEditButton.Paint(Clip: HRGN = NULLREGION);
  595.  var
  596.   Clip1: HRGN;
  597.   LogFont: TLogFont;
  598.   pFont0: HFONT;
  599. begin
  600.   if (not Visible) or not FOwner.HandleAllocated or (FWidth<0) or (FHeight<0) then Exit;
  601.  
  602.   FCanvas.Handle := GetWindowDC(Owner.Handle);
  603.  
  604.   if Assigned(FEditButtons) then
  605.     Clip1 := FEditButtons.GetRegion
  606.   else
  607.     Clip1 := NULLREGION;
  608.  
  609.   if Clip1 <> NULLREGION then
  610.   begin;
  611.     if Clip <> NULLREGION then
  612.       CombineRgn(Clip, Clip1, Clip, RGN_AND)
  613.     else
  614.       Clip := Clip1;
  615.   end;
  616.  
  617.   if (Clip <> NULLREGION) then SelectClipRgn(FCanvas.Handle, Clip);
  618.  
  619.  
  620.   if not RectVisible(FCanvas.Handle, GetBounds) then
  621.   begin
  622.     ReleaseDC(FOwner.Handle, FCanvas.Handle);
  623.     if Clip1 <> NULLREGION then DeleteObject(Clip1);
  624.     Exit;
  625.   end;
  626.  
  627.   try
  628.     if DoubleBuffered then
  629.     begin
  630.       UserBitmap.Width  := FWidth;
  631.       UserBitmap.Height := FHeight;
  632.       DoPaint(UserBitmap.Canvas, Rect(0, 0, FWidth, FHeight));
  633.       FCanvas.Draw(FLeft, FTop, UserBitmap);
  634.     end
  635.     else begin
  636.       GetObject(FFont.Handle, SizeOf(TLogFont), @LogFont);
  637.       pFont0 := CreateFontIndirect(LogFont);
  638.       SelectObject(Canvas.Handle, pFont0);
  639.       DoPaint(FCanvas, GetBounds);
  640.       DeleteObject(pFont0);
  641.     end;
  642.   finally
  643.     ReleaseDC(FOwner.Handle, FCanvas.Handle);
  644.     FCanvas.Handle := 0;
  645.     if Clip1 <> NULLREGION then DeleteObject(Clip1)
  646.   end;
  647. end;
  648.  
  649. procedure TDCEditButton.DrawEditText(ACanvas: TCanvas; var TextRect: TRect);
  650.  var
  651.   AText: string;
  652.   ATextRect: TRect;
  653.   Offs: TPoint;
  654.   DrawFlag: WORD;
  655. begin
  656.   if Caption <> MenuLineCaption then inherited;
  657.   Offs := GetTextOffset;
  658.   ATextRect := TextRect;
  659.   OffsetRect(ATextRect, Offs.X, Offs.Y);
  660.  
  661.   if ATextRect.Right - ATextRect.Left> Width then ATextRect.Right := ATextRect.Left + Width;
  662.  
  663.   DrawFlag :=DT_END_ELLIPSIS;
  664.  
  665.   if (FAllignment = abCenter)      or
  666.      (FAllignment = abImageTop)   or
  667.      (FAllignment = abImageBottom)
  668.   then
  669.     DrawFlag := DrawFlag or DT_CENTER;
  670.  
  671.   with ACanvas do
  672.   begin
  673.     Font.Assign(FFont);
  674.     BeginDrawText(ACanvas, ATextRect);
  675.     AText := FText;
  676.     SetBkMode(Handle, Windows.TRANSPARENT);
  677.     if not Enabled and (FDisableStyle <> deNone) then begin
  678.       if FDisableStyle = deNormal then
  679.       begin
  680.         OffsetRect(ATextRect, 1, 1);
  681.         Font.Color := clWindow;
  682.  
  683.         if AText <> '' then
  684.           if FHighlight then
  685.             DrawHighLightText(ACanvas, PChar(AText), ATextRect, 1,
  686.               DrawFlag, FImages)
  687.           else
  688.             Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText),
  689.               ATextRect, DrawFlag);
  690.         OffsetRect(ATextRect, -1, -1);
  691.       end;
  692.       Font.Color := clBtnShadow;
  693.       if AText <> '' then
  694.         if FHighlight then
  695.           DrawHighLightText(ACanvas, PChar(AText), ATextRect, 1,
  696.             DrawFlag, FImages)
  697.         else
  698.           Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText),
  699.             ATextRect, DrawFlag);
  700.     end
  701.     else
  702.       if AText <> '' then
  703.       begin
  704.         if FHighlight then
  705.           DrawHighLightText(ACanvas, PChar(AText), ATextRect, 1,
  706.             DrawFlag, FImages)
  707.         else
  708.           Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText),
  709.             ATextRect, DrawFlag);
  710.       end;
  711.   end;
  712. end;
  713.  
  714. procedure TDCEditButton.DrawBitmap(ACanvas: TCanvas; ImageRect: TRect);
  715.  var
  716.   Offs: TPoint;
  717.   R, R1, AImageRect: TRect;
  718.   ABitmap: TBitmap;
  719.  
  720.   procedure CopyImage(Canvas: TCanvas; Rect: TRect);
  721.   begin
  722.     if AsignedImages then
  723.       Images.Draw(Canvas, Rect.Left, Rect.Top, ImageIndex, True)
  724.     else
  725.       Canvas.StretchDraw(Rect, Glyph);
  726.   end;
  727. begin
  728.   AImageRect := ImageRect;
  729.   Offs := GetImageOffset;
  730.   OffsetRect(AImageRect, Offs.X, Offs.Y);
  731.   if (Enabled or (FDisableStyle = deNone)) and
  732.      not ((FStyle = stIcon) and (FButtonState = btDownMouseInRect)) then
  733.   begin
  734.     if (FStyle = stSingle) or (FStyle = stXPStyle) then
  735.     begin
  736.       ABitmap := TBitmap.Create;
  737.       try
  738.         R1 := AImageRect;
  739.         OffsetRect(R1, -R1.Left, -R1.Top);
  740.  
  741.         Inc(AImageRect.Right);
  742.         R := AImageRect;
  743.  
  744.         ABitmap.Width := AImageRect.Right - AImageRect.Left;
  745.         ABitmap.Height := AImageRect.Bottom - AImageRect.Top;
  746.         OffsetRect(R, -R.Left, -R.Top);
  747.  
  748.         ABitmap.Canvas.Brush.Color := clFuchsia;
  749.         ABitmap.Canvas.FillRect(R);
  750.         CopyImage(ABitmap.Canvas, R1);
  751.  
  752.         if FStyle = stXPStyle then
  753.           if FButtonState = btRestMouseInRect then
  754.             TransformBitmap(ABitmap, ABitmap, tsXPStyle)
  755.           else
  756.         else
  757.           if (FButtonState = btDownMouseInRect) and FSimpleStyle then
  758.             TransformBitmap(ABitmap, ABitmap, tsInvert);
  759.  
  760.         DrawTransparentBitmap(ACanvas.Handle, ABitmap, AImageRect, False);
  761.       finally
  762.         ABitmap.Free;
  763.       end;
  764.     end
  765.     else
  766.       CopyImage(ACanvas, AImageRect);
  767.   end
  768.   else begin
  769.      case FDisableStyle of
  770.        deLite  : DrawLiteDisableBitmap(ACanvas, ImageRect);
  771.        deNormal: DrawNormDisableBitmap(ACanvas, ImageRect);
  772.        deTrans : DrawTranDisableBitmap(ACanvas, ImageRect);
  773.      end
  774.   end;
  775.  
  776.   case FStyle of
  777.     stOutbar:
  778.       if (EventStyle <> esDropDown) and (GetGlyphWidth > 0) and (GetGlyphHeight > 0) then
  779.       with ACanvas do
  780.       begin
  781.         InflateRect(ImageRect, 2, 2);
  782.         if (csDesigning in (FOwner as TComponent).ComponentState) then
  783.         begin
  784.           if ColorToRGB(FBrushColor) <> clSilver then
  785.           begin
  786.             DrawEdge(Handle, ImageRect, BDR_RAISEDINNER, BF_TOPLEFT);
  787.             DrawEdge(Handle, ImageRect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  788.           end
  789.           else
  790.             DrawEdge(Handle, ImageRect, BDR_RAISEDINNER, BF_RECT);
  791.         end
  792.         else
  793.           if Enabled then
  794.           begin
  795.             case FButtonState of
  796.               btRest:
  797.                 ;
  798.               btDownMouseInRect:
  799.                 if ColorToRGB(FBrushColor) <> clSilver then
  800.                 begin
  801.                   DrawEdge(Handle, ImageRect, BDR_SUNKENINNER, BF_TOPLEFT);
  802.                   DrawEdge(Handle, ImageRect, BDR_SUNKENOUTER, BF_BOTTOMRIGHT);
  803.                 end
  804.                 else
  805.                   DrawEdge(Handle, ImageRect, BDR_SUNKENOUTER, BF_RECT);
  806.               btRestMouseInRect:
  807.                 if ColorToRGB(FBrushColor) <> clSilver then
  808.                 begin
  809.                   DrawEdge(Handle, ImageRect, BDR_RAISEDINNER, BF_TOPLEFT);
  810.                   DrawEdge(Handle, ImageRect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  811.                 end
  812.                 else
  813.                   DrawEdge(Handle, ImageRect, BDR_RAISEDINNER, BF_RECT);
  814.             end
  815.           end
  816.       end;
  817.     stIcon:
  818.       if (GetGlyphWidth > 0) and (GetGlyphHeight > 0) and Enabled then
  819.       begin
  820.         case FButtonState of
  821.           btRest:
  822.             {DrawTransformBitmap(ImageRect, tsTransparent)};
  823.           btDownMouseInRect:
  824.             DrawTransformBitmap(ACanvas, ImageRect, tsShadow);
  825.           btRestMouseInRect:
  826.             ;
  827.         end
  828.       end;
  829.   end;
  830. end;
  831.  
  832. procedure TDCEditButton.DrawLiteDisableBitmap(ACanvas: TCanvas; ImageRect: TRect);
  833.  var
  834.   ARect: TRect;
  835. begin
  836.   try
  837.     ARect := Rect(0,0,GetGlyphWidth, GetGlyphHeight);
  838.     if (GetGlyphHeight > 0) and (GetGlyphWidth > 0) then
  839.     begin
  840.       if AsignedImages then
  841.       begin
  842.         with GlyphBitmap.Canvas do
  843.         begin
  844.           Brush.Color := clWhite;
  845.           FillRect(ARect);
  846.         end;
  847.         FImages.GetBitmap(FImageIndex, GlyphBitmap);
  848.         TransformBitmap(GlyphBitmap, GlyphBitmap, tsDisable);
  849.       end
  850.       else begin
  851.         GlyphBitmap.Assign(FGlyph);
  852.         TransformBitmap(Glyph, GlyphBitmap, tsDisable);
  853.       end;
  854.  
  855.       ACanvas.StretchDraw(ImageRect, GlyphBitmap);
  856.     end;
  857.   finally
  858.     {};
  859.   end;
  860. end;
  861.  
  862. procedure TDCEditButton.DrawTransformBitmap(ACanvas: TCanvas; ImageRect: TRect;
  863.   Style: TTransformStyle);
  864.  var
  865.   ARect: TRect;
  866. begin
  867.   try
  868.     ARect := Rect(0, 0, GetGlyphWidth, GetGlyphHeight);
  869.     if (GetGlyphHeight > 0) and (GetGlyphWidth > 0) then
  870.     begin
  871.       if AsignedImages then
  872.       begin
  873.         with GlyphBitmap.Canvas do
  874.         begin
  875.           Brush.Color := clFuchsia;
  876.           FillRect(ARect);
  877.         end;
  878.         FImages.GetBitmap(FImageIndex, GlyphBitmap);
  879.         TransformBitmap(GlyphBitmap, GlyphBitmap, Style);
  880.       end
  881.       else begin
  882.         GlyphBitmap.Assign(FGlyph);
  883.         TransformBitmap(Glyph, GlyphBitmap, Style);
  884.       end;
  885.  
  886.       ACanvas.StretchDraw(ImageRect, GlyphBitmap);
  887.     end;
  888.   finally
  889.     {};
  890.   end;
  891.  
  892. end;
  893.  
  894.  
  895. procedure TDCEditButton.DrawNormDisableBitmap(ACanvas: TCanvas; ImageRect: TRect);
  896.  const
  897.   ROP_DSPDxax = $00E20746;
  898. begin
  899.   try
  900.     with GlyphBitmap do
  901.     begin
  902.       if AsignedImages then
  903.       begin
  904.         Canvas.Brush.Color := clWhite;
  905.         Canvas.FillRect(Rect(0,0,GetGlyphWidth, GetGlyphHeight));
  906.         FImages.GetBitmap(FImageIndex, GlyphBitmap);
  907.       end
  908.       else
  909.         Assign(Glyph);
  910.       HandleType := bmDDB;
  911.       Canvas.Brush.Color := clBlack;
  912.       Width := GetGlyphWidth;
  913.       if Monochrome then
  914.       begin
  915.         Canvas.Font.Color := clWhite;
  916.         Monochrome := False;
  917.         Canvas.Brush.Color := clWhite;
  918.       end;
  919.       Monochrome := True;
  920.     end;
  921.     with ACanvas do
  922.     begin
  923.       Brush.Color := clBtnShadow;
  924.       SetTextColor(Handle, clBlack);
  925.       SetBkColor(Handle, clWhite);
  926.       BitBlt(Handle, ImageRect.Left,ImageRect.Top, GetGlyphWidth, GetGlyphHeight,
  927.              GlyphBitmap.Canvas.Handle, 0, 0, ROP_DSPDxax);
  928.  
  929.     end;
  930.   finally
  931.     {}
  932.   end;
  933. end;
  934.  
  935. procedure TDCEditButton.DrawBorder(ACanvas: TCanvas; ARect: TRect);
  936.  var
  937.   AButtonState: TButtonState;
  938.   BBrush: HBRUSH;
  939.   ARGB: integer;
  940. begin
  941.   AButtonState := FButtonState;
  942.   if not Enabled then AButtonState := btRest;
  943.  
  944.   case AButtonState of
  945.     btRest:
  946.       begin
  947.         if (csDesigning in (FOwner as TComponent).ComponentState) then
  948.         begin
  949.           case FStyle of
  950.             stNormal    :
  951.               begin
  952.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_RECT);
  953.                 InflateRect(ARect, -1, -1);
  954.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  955.               end;
  956.             stFlat :
  957.               DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  958.             stControlFlat :
  959.               if Enabled then
  960.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT)
  961.               else
  962.                 FrameRect(ACanvas.Handle, ARect, GetSysColorBrush(COLOR_WINDOW));
  963.             stShadowFlat:
  964.               begin
  965.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
  966.                 ARGB := ColorToRGB(BrushColor);
  967.                 case ARGB of
  968.                   $808080: {clGray}
  969.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  970.                   $C0C0C0: {clSilver}
  971.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  972.                   else
  973.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  974.                 end;
  975.               end;
  976.             stNone:;
  977.             stIcon:;
  978.             stSingle:;
  979.           end;
  980.         end
  981.         else
  982.           case FStyle of
  983.             stNormal :
  984.               begin
  985.                 if Enabled then
  986.                 begin
  987.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_RECT);
  988.                   InflateRect(ARect, -1, -1);
  989.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  990.                 end
  991.                 else begin
  992.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_TOPLEFT);
  993.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  994.                   InflateRect(ARect, -1, -1);
  995.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
  996.                   DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENINNER, BF_BOTTOMRIGHT);
  997.                 end;
  998.               end;
  999.             stFlat   :
  1000.               if FMouseInControl then
  1001.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  1002.             stControlFlat :
  1003.               if FMouseInControl then
  1004.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT)
  1005.               else begin
  1006.                 if Assigned(FOwner) and (FOwner is TWinControl) then
  1007.                 begin
  1008.                   BBrush := CreateSolidBrush(ColorToRGB(TEditControl(FOwner).Color));
  1009. //                  FrameRect(ACanvas.Handle, ARect, BBrush);
  1010.                   DeleteObject(BBrush);
  1011.                 end
  1012.                 else
  1013.                   FrameRect(ACanvas.Handle, ARect, GetSysColorBrush(COLOR_WINDOW));
  1014.               end;
  1015.             stShadowFlat:
  1016.               if FMouseInControl then
  1017.               begin
  1018.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
  1019.                 ARGB := ColorToRGB(BrushColor);
  1020.                 case ARGB of
  1021.                   $808080: {clGray}
  1022.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  1023.                   $C0C0C0: {clSilver}
  1024.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  1025.                   else
  1026.                     DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  1027.                 end;
  1028.               end;
  1029.             stNone:;
  1030.             stIcon:;
  1031.             stSingle:;
  1032.             stXPStyle:
  1033.               if not FMouseInControl then
  1034.               begin
  1035.                 if Assigned(FOwner) and (FOwner is TWinControl) then
  1036.                 begin
  1037.                   BBrush := CreateSolidBrush(ColorToRGB(TEditControl(FOwner).Color));
  1038.                   FrameRect(ACanvas.Handle, ARect, BBrush);
  1039.                   DeleteObject(BBrush);
  1040.                 end
  1041.                 else
  1042.                   FrameRect(ACanvas.Handle, ARect, GetSysColorBrush(COLOR_WINDOW));
  1043.               end;
  1044.           end;
  1045.       end;
  1046.     btDownMouseInRect:
  1047.       begin
  1048.         case FStyle of
  1049.           stNormal:
  1050.             begin
  1051.               FrameRect(ACanvas.Handle, ARect, GetSysColorBrush(COLOR_BTNSHADOW));
  1052.             end;
  1053.           stFlat,
  1054.           stControlFlat   :
  1055.             DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_RECT);
  1056.           stShadowFlat:
  1057.             begin
  1058.               DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_BOTTOMRIGHT);
  1059.               ARGB := ColorToRGB(BrushColor);
  1060.               case ARGB of
  1061.                 $808080: {clGray}
  1062.                   DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENINNER, BF_TOPLEFT);
  1063.                 $C0C0C0: {clSilver}
  1064.                   DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_TOPLEFT);
  1065.                 else
  1066.                   DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_TOPLEFT);
  1067.               end;
  1068.             end;
  1069.           stOutBar:
  1070.             if (GetGlyphHeight=0) or (GetGlyphWidth=0) or
  1071.                (EventStyle=esDropDown)
  1072.             then
  1073.               if ColorToRGB(FBrushColor) <> clSilver then
  1074.               begin
  1075.                 DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENINNER, BF_TOPLEFT);
  1076.                 DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_BOTTOMRIGHT);
  1077.               end
  1078.               else
  1079.                 DrawEdge(ACanvas.Handle, ARect, BDR_SUNKENOUTER, BF_RECT);
  1080.           stNone:;
  1081.           stIcon:;
  1082.         end;
  1083.       end;
  1084.     btRestMouseInRect:
  1085.       begin
  1086.         case FStyle of
  1087.           stNormal        :
  1088.             begin
  1089.               DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_RECT);
  1090.               InflateRect(ARect, -1, -1);
  1091.               DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  1092.             end;
  1093.           stFlat,
  1094.           stControlFlat   :
  1095.             DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  1096.           stShadowFlat:
  1097.             begin
  1098.               DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
  1099.               ARGB := ColorToRGB(BrushColor);
  1100.               case ARGB of
  1101.                 $808080: {clGray}
  1102.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  1103.                 $C0C0C0: {clSilver}
  1104.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  1105.                 else
  1106.                   DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
  1107.               end;
  1108.             end;
  1109.           stOutBar:
  1110.             if (GetGlyphHeight=0) or (GetGlyphWidth=0) or
  1111.                (EventStyle=esDropDown)
  1112.             then
  1113.               if ColorToRGB(FBrushColor) <> clSilver then
  1114.               begin
  1115.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
  1116.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
  1117.               end
  1118.               else
  1119.                 DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_RECT);
  1120.           stNone:;
  1121.           stIcon:;
  1122.        end;
  1123.       end;
  1124.   end;
  1125. end;
  1126.  
  1127. procedure TDCEditButton.ResetProperties;
  1128. var
  1129.   P: TPoint;
  1130. begin
  1131.   GetCursorPos(P);
  1132.   P := (FOwner as TControl).ScreenToClient(P);
  1133.   if ResetOnExitControl or (FEventStyle <> esDropDown) then
  1134.   begin
  1135.     if MouseInRect( P.X, P.Y ) then
  1136.       FButtonState := btRestMouseInRect
  1137.     else
  1138.       FButtonState := btRest;
  1139.  
  1140.     FDown       := False;
  1141.     FDownButton := False;
  1142.     invalidate;
  1143.   end;
  1144. end;
  1145.  
  1146. procedure TDCEditButton.SetText(Value:string);
  1147. begin
  1148.   FText     := Value;
  1149.   FTextSize := GetTextSize;
  1150. end;
  1151.  
  1152. procedure TDCEditButton.SetAllignment(Value:TAllignment);
  1153. begin
  1154.   if Value <>  FAllignment then
  1155.   begin
  1156.     FAllignment := Value;
  1157.   end;
  1158. end;
  1159.  
  1160. procedure TDCEditButton.SetButtonState(Value:TButtonState);
  1161. begin
  1162.   if Assigned(FOnSetButtonState) then FOnSetButtonState(Self, Value);
  1163.   if Value <> FButtonState then
  1164.   begin
  1165.     FButtonState := Value;
  1166.     if FDownClick and (FButtonState <> btDownMouseInRect) then FDownButton := False;
  1167.   end;
  1168. end;
  1169.  
  1170. procedure TDCEditButton.SetMouseInControl(Value:boolean);
  1171. begin
  1172.   if Value <>  FMouseInControl then
  1173.   begin
  1174.     if not Value then FButtonState := btRest;
  1175.     FMouseInControl := Value;
  1176.   end;
  1177. end;
  1178.  
  1179. procedure TDCEditButton.SetCanvas(Value:TCanvas);
  1180. begin
  1181.   FCanvas := Value;
  1182. end;
  1183.  
  1184. procedure TDCEditButton.SetEnabled(const Value: boolean);
  1185. begin
  1186.   if Value <> FEnabled then
  1187.   begin
  1188.     FEnabled := Value;
  1189.     invalidate;
  1190.   end;
  1191. end;
  1192.  
  1193. { TDCEditButtons }
  1194.  
  1195. function TDCEditButtons.AddButton: TDCEditButton;
  1196. begin
  1197.   Result := AddButtonEx(TDCEditButton);
  1198. end;
  1199.  
  1200. procedure TDCEditButtons.Clear;
  1201.  var
  1202.   i: integer;
  1203. begin
  1204.   for i := 0 to FButtons.Count-1 do
  1205.     TDCEditButton(FButtons.Items[i]).Free;
  1206.   FButtons.Clear;
  1207. end;
  1208.  
  1209. procedure TDCEditButtons.ClrWndProc;
  1210. begin
  1211.   if not FProcClear and Assigned(FDefWndProc) then
  1212.   begin
  1213.     FProcClear := True;
  1214.     if (FOwner <> nil) then
  1215.       SetWindowLong(FOwner.Handle, GWL_WNDPROC, LongInt(FDefWndProc));
  1216.   end;
  1217. end;
  1218.  
  1219. constructor TDCEditButtons.Create(AOwner: TWinControl);
  1220. begin
  1221.   inherited Create;
  1222.   FBkgImage := TBitmap.Create;
  1223.   FOwner    := AOwner;
  1224.   FButtons  := TList.Create;
  1225.  
  1226.   FMouseInControl := False;
  1227.   FPaintOnSizing  := True;
  1228.   FOnlyClientRepaint := False;
  1229.   FMouseDown   := False;
  1230.   FAbsolutePos := True;
  1231.   FActiveButton:= nil;
  1232.  
  1233.   FProcClear  := True;
  1234.   {$IFDEF DELPHI_V6}
  1235.     FNewWndProc := Classes.MakeObjectInstance(EditWndProc);
  1236.   {$ELSE}
  1237.     FNewWndProc := MakeObjectInstance(EditWndProc);
  1238.   {$ENDIF}
  1239.   FUpdateCount:= 0;
  1240. end;
  1241.  
  1242. procedure TDCEditButtons.DefineProperties(Filer: TFiler);
  1243.   function WriteButtons: Boolean;
  1244.   var
  1245.     I: Integer;
  1246.     Items: TDCEditButtons;
  1247.   begin
  1248.     Items := TDCEditButtons(Filer.Ancestor);
  1249.     if Items = nil then
  1250.       Result := Count > 0
  1251.     else if Items.Count <> Count then
  1252.       Result := True
  1253.     else
  1254.     begin
  1255.       Result := False;
  1256.       for I := 0 to Count - 1 do
  1257.       begin
  1258.         Result := not Buttons[I].IsEqual(Items.Buttons[I]);
  1259.         if Result then Break;
  1260.       end
  1261.     end;
  1262.   end;
  1263.  
  1264. begin
  1265.   inherited DefineProperties(Filer);
  1266.   Filer.DefineBinaryProperty('Data', ReadData, WriteData, WriteButtons);
  1267. end;
  1268.  
  1269. procedure TDCEditButtons.DeleteButton(Index: integer);
  1270. begin
  1271.   TDCEditButton(FButtons.Items[Index]).Free;
  1272.   FButtons.Delete(Index);
  1273.   UpdateIndex;
  1274. end;
  1275.  
  1276. destructor TDCEditButtons.Destroy;
  1277. begin
  1278.   ClrWndProc;
  1279.   {$IFDEF DELPHI_V6}
  1280.     Classes.FreeObjectInstance(FNewWndProc);
  1281.   {$ELSE}
  1282.     FreeObjectInstance(FNewWndProc);
  1283.   {$ENDIF}
  1284.   Clear;
  1285.   FButtons.Free;
  1286.   FBkgImage.Free;
  1287.   inherited;
  1288. end;
  1289.  
  1290. procedure TDCEditButtons.EditWndProc(var Message: TMessage);
  1291.  var
  1292.   lInherited: boolean;
  1293.   Pos: TPoint;
  1294.   WndPos: TWindowPos;
  1295.   Offset: TPoint;
  1296.   Button: TDCEditButton;
  1297. begin
  1298.   lInherited := True;
  1299.   try
  1300.     with Message do
  1301.     begin
  1302.       case Msg of
  1303.         WM_NCHITTEST:
  1304.           begin
  1305.            if not(csDesigning in FOwner.ComponentState) then
  1306.            begin
  1307.              GetCursorPos(Pos);
  1308.              if MouseInButtonArea(Pos.X, Pos.Y, Button) then
  1309.              begin
  1310.                lInherited := False;
  1311.                Message.Result := HTCLIENT;
  1312.              end;
  1313.            end;
  1314.           end;
  1315.         WM_DESTROY:
  1316.          ClrWndProc;
  1317.         WM_WINDOWPOSCHANGED:
  1318.          begin
  1319.            WndPos := PWindowPos(Message.LParam)^;
  1320.            if WndPos.Flags = SWP_SHOWWINDOW then RepaintButtons;
  1321.          end;
  1322.         WM_WINDOWPOSCHANGING:
  1323.          begin
  1324.            WndPos := PWindowPos(Message.LParam)^;
  1325.            if (WndPos.CX <> 0) or (WndPos.CY <> 0)
  1326.            then begin
  1327.              Offset := Point(WndPos.CX-FOwner.Width, WndPos.CY-FOwner.Height);
  1328.              if (Offset.X <> 0) or (Offset.Y <> 0) then
  1329.                 OffsetButtons(Offset);
  1330.            end;
  1331.          end;
  1332.         WM_NCPAINT:
  1333.          begin
  1334.            lInherited :=  False;
  1335.            Result := CallWindowProc(FDefWndProc, FOwner.Handle, Msg, WParam, LParam);
  1336.            if PaintOnSizing then RepaintButtons(HRGN(WParam));
  1337.          end;
  1338.         WM_PAINT:
  1339.          begin
  1340.            lInherited :=  False;
  1341.            Result := CallWindowProc(FDefWndProc, Owner.Handle, Msg, WParam, LParam);
  1342.            SaveBackground;
  1343.            RepaintButtons;
  1344.          end;
  1345.         WM_ERASEBKGND:
  1346.          begin
  1347.            if PaintOnSizing then UpdateDeviceRegion(WParam);
  1348.          end;
  1349.         WM_MOUSEMOVE, WM_NCMOUSEMOVE:
  1350.          begin
  1351.            GetCursorPos(Pos);
  1352.            UpdateButtonsOnClick(Pos.X, Pos.Y, True);
  1353.          end;
  1354.         WM_LBUTTONDOWN, WM_LBUTTONDBLCLK,
  1355.         WM_NCLBUTTONDOWN, WM_NCLBUTTONDBLCLK:
  1356.          begin
  1357.            if not(csDesigning in FOwner.ComponentState) then
  1358.            begin
  1359.              GetCursorPos(Pos);
  1360.              if MouseInButtonArea(Pos.X, Pos.Y, Button) then
  1361.              begin
  1362.                FMouseDown := True;
  1363.                lInherited := False;
  1364.                Result := CallWindowProc(FDefWndProc, FOwner.Handle, Msg, WParam, LParam);
  1365.              end;
  1366.              UpdateButtonsOnClick(Pos.X, Pos.Y, False);
  1367.            end;
  1368.          end;
  1369.         WM_LBUTTONUP, WM_NCLBUTTONUP:
  1370.          begin
  1371.            FMouseDown := False;
  1372.            GetCursorPos(Pos);
  1373.            if MouseInButtonArea(Pos.X, Pos.Y, Button) then
  1374.            begin
  1375.              Result := CallWindowProc(FDefWndProc, FOwner.Handle, Msg, WParam, LParam);
  1376.              lInherited := False;
  1377.            end;
  1378.            UpdateButtonsOnClick(Pos.X, Pos.Y, False);
  1379.          end;
  1380.         WM_SETFOCUS, WM_KILLFOCUS:
  1381.         begin
  1382.           DoChangeFocus;
  1383.         end;
  1384.       end;
  1385.       if lInherited then
  1386.         Result := CallWindowProc(FDefWndProc, FOwner.Handle, Msg, WParam, LParam);
  1387.     end;
  1388.   except
  1389.     {}
  1390.   end;
  1391. end;
  1392.  
  1393. function TDCEditButtons.FindButton(AName: string): TDCEditButton;
  1394.  var
  1395.   i: integer;
  1396. begin
  1397.   Result := nil;
  1398.   for i := 0 to FButtons.Count-1 do
  1399.   begin
  1400.     if AnsiCompareText(AName, TDCEditButton(FButtons.Items[i]).Name) = 0 then
  1401.     begin
  1402.       Result := TDCEditButton(FButtons.Items[i]);
  1403.       Break;
  1404.     end;
  1405.   end;
  1406. end;
  1407.  
  1408. function TDCEditButtons.GetButton(Index: integer): TDCEditButton;
  1409. begin
  1410.   Result := TDCEditButton(FButtons.Items[Index]);
  1411. end;
  1412.  
  1413. function TDCEditButtons.GetButtonsRect: TRect;
  1414.  var
  1415.   i: integer;
  1416.   Button: TDCEditButton;
  1417.   R: TRect;
  1418. begin
  1419.   SetRectEmpty(Result);
  1420.   for i := 0 to Count-1 do
  1421.   begin
  1422.     Button := Buttons[i];
  1423.     with Button do
  1424.       if Visible then begin
  1425.         R := Rect(Left, Top, Left+Width, Top+Height);
  1426.         UnionRect(Result,Result,R);
  1427.       end;
  1428.   end;
  1429. end;
  1430.  
  1431. function TDCEditButtons.GetCount: integer;
  1432. begin
  1433.   Result := FButtons.Count;
  1434. end;
  1435.  
  1436. function TDCEditButtons.GetEnabled: boolean;
  1437.  var
  1438.   i: integer;
  1439. begin
  1440.   Result := False;
  1441.   for i := 0 to Count-1 do
  1442.   begin
  1443.     if Result then Break;
  1444.     Result := Buttons[i].Enabled;
  1445.   end;
  1446. end;
  1447.  
  1448. procedure TDCEditButtons.Invalidate;
  1449. begin
  1450.   RepaintButtons;
  1451. end;
  1452.  
  1453. function TDCEditButtons.MouseInButtonArea(XPos, YPos: integer; var Button: TDCEditButton): boolean;
  1454.  var
  1455.   i, X, Y: integer;
  1456.   P: TPoint;
  1457. begin
  1458.   Result := False;
  1459.   for i := 0 to Count-1 do
  1460.   begin
  1461.     if Buttons[i].AbsolutePos then
  1462.     begin
  1463.       P := Point(FOwner.Left,FOwner.Top);
  1464.       X := XPos - P.X;
  1465.       Y := YPos - P.Y;
  1466.     end
  1467.     else begin
  1468.       P := FOwner.ScreenToClient(Point(XPos, YPos));
  1469.       X := P.X;
  1470.       Y := P.Y;
  1471.     end;
  1472.     Result := Buttons[i].MouseInRect(X, Y);
  1473.     if Result then begin
  1474.       Button := Buttons[i];
  1475.       Break;
  1476.     end;
  1477.   end;
  1478. end;
  1479.  
  1480. procedure TDCEditButtons.MoveButton(CurIndex, NewIndex: integer);
  1481. begin
  1482.   FButtons.Move(CurIndex, NewIndex);
  1483.   UpdateIndex;
  1484. end;
  1485.  
  1486. procedure TDCEditButtons.OffsetButtons(Pos: TPoint);
  1487.  var
  1488.   i: integer;
  1489.   Button: TDCEditButton;
  1490. begin
  1491.   for i := 0 to Count-1 do
  1492.   begin
  1493.      Button := Buttons[i];
  1494.      with Button do
  1495.        case AnchorStyle of
  1496.          asNone:;
  1497.          asTR  :
  1498.            SetBounds(Rect(Left+Pos.X, Top, Width, Height));
  1499.          asBL  :
  1500.            SetBounds(Rect(Left, Top+Pos.Y, Width, Height));
  1501.          asBR  :
  1502.            SetBounds(Rect(Left+Pos.X, Top+Pos.Y, Width, Height));
  1503.          asTBL :
  1504.            SetBounds(Rect(Left, Top, Width, Height+Pos.Y));
  1505.          asTBR :
  1506.            SetBounds(Rect(Left+Pos.X, Top, Width, Height+Pos.Y));
  1507.          asTBLR:
  1508.            SetBounds(Rect(Left, Top, Width+Pos.X, Height+Pos.Y));
  1509.          asTLR :
  1510.            SetBounds(Rect(Left, Top, Width+Pos.X, Height));
  1511.          asBLR :
  1512.            SetBounds(Rect(Left, Top+Pos.Y, Width+Pos.X, Height));
  1513.          asTCn:
  1514.            SetBounds(Rect(Left+Pos.X div 2, Top, Width, Height));
  1515.          asCnR:
  1516.            SetBounds(Rect(Left+Pos.X, Top + Pos.Y div 2, Width, Height));
  1517.        end;
  1518.      if FPaintOnSizing then Button.invalidate;
  1519.   end;
  1520. end;
  1521.  
  1522. procedure TDCEditButtons.ReadData(Stream: TStream);
  1523. var
  1524.   I, Count: Integer;
  1525.   ButtonInfo: TButtonInfo;
  1526.   Button: TDCEditButton;
  1527. begin
  1528.   Stream.ReadBuffer(Count, SizeOf(Count));
  1529.   for I := 0 to Count - 1 do
  1530.   begin
  1531.     Button := AddButton;
  1532.     Button.ReadData(Stream, @ButtonInfo);
  1533.   end;
  1534. end;
  1535.  
  1536. procedure TDCEditButtons.WriteData(Stream: TStream);
  1537. var
  1538.   i: Integer;
  1539.   ButtonInfo: TButtonInfo;
  1540. begin
  1541.   i := Count;
  1542.   Stream.WriteBuffer(i, SizeOf(Integer));
  1543.   for i :=0 to Count-1 do
  1544.     Buttons[i].WriteData(Stream, @ButtonInfo);
  1545. end;
  1546.  
  1547. procedure TDCEditButtons.RepaintButtons(AClip: HRGN = NULLREGION);
  1548.  var
  1549.   i: integer;
  1550.   Button: TDCEditButton;
  1551.   DC: HDC;
  1552. begin
  1553.   if FOwner.HandleAllocated then
  1554.   begin
  1555.     if FUpdateCount = 0 then
  1556.     begin
  1557.       DC := GetDCEx(0, AClip, DCX_WINDOW or DCX_CACHE or DCX_CLIPSIBLINGS);
  1558.       try
  1559.         for i := 0 to Count-1 do
  1560.         begin
  1561.           Button := Buttons[i];
  1562.           Button.Paint(AClip);
  1563.         end;
  1564.       finally
  1565.         ReleaseDC(0, DC);
  1566.       end;
  1567.     end;
  1568.   end;
  1569.   //if ActiveButton <> nil then ActiveButton.DrawHint(0);
  1570. end;
  1571.  
  1572. procedure TDCEditButtons.ResetProperties;
  1573.  var
  1574.   i: integer;
  1575. begin
  1576.   for i := 0 to Count-1 do Buttons[i].ResetProperties;
  1577.   ActiveButton := nil;
  1578. end;
  1579.  
  1580. procedure TDCEditButtons.SetButton(Index: integer;
  1581.   const Value: TDCEditButton);
  1582. begin
  1583.   FButtons.Items[Index] := Value;
  1584. end;
  1585.  
  1586. procedure TDCEditButtons.SetEnabled(const Value: boolean);
  1587.  var
  1588.   i: integer;
  1589. begin
  1590.   for i := 0 to Count-1 do Buttons[i].Enabled := Value;
  1591. end;
  1592.  
  1593. procedure TDCEditButtons.SetImages(const Value: TImageList);
  1594.  var
  1595.   i: integer;
  1596. begin
  1597.   FImages := Value;
  1598.   for i := 0 to Count-1 do
  1599.     Buttons[i].Images := Value;
  1600.   RepaintButtons;
  1601. end;
  1602.  
  1603. procedure TDCEditButtons.SetWndProc;
  1604. begin
  1605.   if not Assigned(FDefWndProc) then
  1606.      FDefWndProc := Pointer(GetWindowLong(FOwner.Handle, GWL_WNDPROC));
  1607.   SetWindowLong(FOwner.Handle, GWL_WNDPROC, LongInt(FNewWndProc));
  1608.   FProcClear := False;
  1609. end;
  1610.  
  1611. function TDCEditButtons.UpdateButtons(XPos, YPos: integer; ADown, AMove: boolean): boolean;
  1612.  var
  1613.   X, Y, i: integer;
  1614.   AActiveButton: TDCEditButton;
  1615.   P: TPoint;
  1616. begin
  1617.   Result := False;
  1618.   if (csDesigning in FOwner.ComponentState) or (Count =0 ) then  Exit;
  1619.   AActiveButton := FActiveButton;
  1620.   FActiveButton := nil;
  1621.   for i := 0 to Count-1 do
  1622.   begin
  1623.     if Buttons[i].AbsolutePos then
  1624.     begin
  1625.       P := Point(FOwner.Left, FOwner.Top);
  1626.       X := XPos - P.X;
  1627.       Y := YPos - P.Y;
  1628.     end
  1629.     else begin
  1630.       P := FOwner.ScreenToClient(Point(XPos, YPos));
  1631.       X := P.X;
  1632.       Y := P.Y;
  1633.     end;
  1634.     if Buttons[i].MouseInRect(X, Y) then FActiveButton := Buttons[i];
  1635.     Result := Buttons[i].UpdateButtonState(X, Y, ADown, AMove);
  1636.   end;
  1637.  
  1638.   if (FActiveButton <> nil) and
  1639.      ((AActiveButton <> nil) and (FActiveButton.Index <> AActiveButton.Index) or
  1640.       (AActiveButton = nil)) then
  1641.     FActiveButton.DrawHint(0);
  1642.  
  1643.   if (FActiveButton = nil) and (AActiveButton <> nil) then
  1644.     AActiveButton.DrawHint(1);
  1645. end;
  1646.  
  1647. function TDCEditButtons.UpdateButtonsOnClick(X, Y: integer; AMove: boolean): boolean;
  1648.  var
  1649.   ButtonUpdate: boolean;
  1650.   Button: TDCEditButton;
  1651. begin
  1652.   Result := False;
  1653.   if FOwner = nil then Exit;
  1654.   if Count > 0 then
  1655.   begin
  1656.     ButtonUpdate := UpdateButtons(X, Y, FMouseDown, AMove);
  1657.     if ButtonUpdate and MouseInButtonArea(X, Y, Button) then Result := True
  1658.   end;
  1659. end;
  1660.  
  1661. procedure TDCEditButtons.UpdateDeviceRegion(DC: HDC);
  1662.  var
  1663.   i: integer;
  1664.   Button: TDCEditButton;
  1665.   HP: TPoint;
  1666.   HC: TRect;
  1667. begin
  1668.   HP := Point(0,0);
  1669.   with FOwner do
  1670.   begin
  1671.     HP := ClientToScreen(Point(0,0));
  1672.     GetWindowRect(Handle, HC);
  1673.     HP.X := HP.X - HC.Left;
  1674.     HP.Y := HP.Y - HC.Top;
  1675.   end;
  1676.  
  1677.   for i := 0 to Count-1 do
  1678.   begin
  1679.     Button := Buttons[i];
  1680.     with Button do
  1681.       if Visible and not Transparent then ExcludeClipRect(DC, Left-HP.X, Top-HP.Y, Left+Width-HP.X,
  1682.         Top+Height-HP.Y);
  1683.   end;
  1684.  
  1685. end;
  1686.  
  1687. procedure TDCEditButtons.UpdateIndex;
  1688.  var
  1689.   i: integer;
  1690. begin
  1691.   for i:=0 to FButtons.Count-1 do
  1692.     TDCEditButton(FButtons[i]).FIndex := i;
  1693. end;
  1694.  
  1695. procedure TDCEditButtons.UpdateMouseInControl(Value: boolean);
  1696.  var
  1697.   i: integer;
  1698. begin
  1699.   if (FMouseInControl <> Value) then
  1700.   begin
  1701.     FMouseInControl := Value;
  1702.     for i := 0 to FButtons.Count-1 do Buttons[i].MouseInControl := Value;
  1703.   end;
  1704. end;
  1705.  
  1706. procedure TDCEditButton.SetVisible(const Value: boolean);
  1707.  var
  1708.   R: TRect;
  1709. begin
  1710.   if FVisible <> Value then
  1711.   begin
  1712.     FVisible := Value;
  1713.     if Value then
  1714.     begin
  1715.       FWidth := FVisibleWidth;
  1716.       R := GetBounds;
  1717.     end
  1718.     else begin
  1719.       R := GetBounds;
  1720.       FVisibleWidth := FWidth;
  1721.       FWidth := 0;
  1722.     end;
  1723.     if FOwner.HandleAllocated then
  1724.       InvalidateRect(FOwner.Handle, @R, not FVisible);
  1725.   end;
  1726. end;
  1727.  
  1728. function TDCEditButton.GetWidth: integer;
  1729. begin
  1730.   if Visible then
  1731.     Result := FWidth
  1732.   else
  1733.     Result := FVisibleWidth;
  1734. end;
  1735.  
  1736. procedure TDCEditButton.DrawHint(Mode: integer);
  1737. begin
  1738.   if Assigned(FOnDrawHint) then FOnDrawHint(Self, Mode);
  1739. end;
  1740.  
  1741. procedure TDCEditButton.SetImages(const Value: TImageList);
  1742. begin
  1743.   FImages   := Value;
  1744.   FTextSize := GetTextSize;
  1745.   invalidate;
  1746. end;
  1747.  
  1748. procedure TDCEditButton.SetImageIndex(const Value: integer);
  1749. begin
  1750.   FImageIndex := Value;
  1751.   invalidate;
  1752. end;
  1753.  
  1754. function TDCEditButton.GetGlyphHeight: integer;
  1755. begin
  1756.   if (AsignedImages) and (FImageIndex <> -1) then
  1757.     Result := FImages.Height
  1758.   else begin
  1759.     Result := FGlyph.Height;
  1760.   end
  1761. end;
  1762.  
  1763. function TDCEditButton.GetGlyphWidth: integer;
  1764. begin
  1765.   if (AsignedImages) and (FImageIndex <> -1) then
  1766.     Result := FImages.Width
  1767.   else
  1768.     Result := FGlyph.Width;
  1769. end;
  1770.  
  1771. function TDCEditButton.AsignedImages: boolean;
  1772. begin
  1773.   Result := Assigned(Images) and FGlyph.Empty;
  1774. end;
  1775.  
  1776. function TDCEditButton.GetImageRect: TRect;
  1777.  var
  1778.   Pos, ATextSize: TPoint;
  1779.   DrawRectX: integer;
  1780.   TextOffs: integer;
  1781. begin
  1782.   if (GetGlyphWidth = 0) or (GetGlyphHeight = 0) then
  1783.   begin
  1784.     Result := Rect(ButtonOffset, ButtonOffset, ButtonOffset, ButtonOffset);
  1785.     Exit;
  1786.   end;
  1787.  
  1788.   if not DrawText or (Caption = '') then
  1789.     ATextSize := Point(0, 0)
  1790.   else
  1791.     ATextSize := FTextSize;
  1792.  
  1793.   if (ATextSize.X = 0) or (GetGlyphWidth = 0) then
  1794.     TextOffs := 0
  1795.   else
  1796.     TextOffs := TextBtnOffset;
  1797.  
  1798.   case FAllignment of
  1799.      abLeft :
  1800.        begin
  1801.          Pos.X := ButtonOffset;
  1802.          Pos.Y := (FHeight-GetGlyphHeight) div 2;
  1803.        end;
  1804.      abRight:
  1805.        begin
  1806.          Pos.X := FWidth-GetGlyphWidth - ButtonOffset;
  1807.          Pos.Y := (FHeight-GetGlyphHeight) div 2;
  1808.        end;
  1809.      abCenter:
  1810.        begin
  1811.          DrawRectX := GetGlyphWidth+ATextSize.X+(2*ButtonOffset+TextOffs);
  1812.          if DrawRectX >= FWidth
  1813.             then Pos.X := ButtonOffset
  1814.             else Pos.X := ButtonOffset+ (FWidth-GetGlyphWidth-ATextSize.X-
  1815.                                    (2*ButtonOffset+TextOffs)) div 2;
  1816.          Pos.Y := (FHeight-GetGlyphHeight) div 2;
  1817.        end;
  1818.      abImageTop:
  1819.        begin
  1820.          Pos.X := ButtonOffset+(FWidth-GetGlyphWidth-2*ButtonOffset) div 2;
  1821.          Pos.Y :=ButtonOffset +
  1822.             (FHeight-GetGlyphHeight-ATextSize.Y-
  1823.             (2*ButtonOffset+TextOffs)) div 2;
  1824.        end;
  1825.      abImageBottom:
  1826.        begin
  1827.          Pos.X := ButtonOffset+(FWidth-GetGlyphWidth-2*ButtonOffset) div 2;
  1828.          Pos.Y :=ButtonOffset + ATextSize.Y + TextOffs+
  1829.             (FHeight-GetGlyphHeight-ATextSize.Y-
  1830.             (2*ButtonOffset+TextOffs)) div 2;
  1831.        end;
  1832.   end;
  1833.   Result := Rect(0, 0, GetGlyphWidth, GetGlyphHeight);
  1834.   OffsetRect(Result, Pos.X, Pos.Y);
  1835. end;
  1836.  
  1837. function TDCEditButton.GetTextRect(IRect: TRect): TRect;
  1838.  var
  1839.   TextOffs: integer;
  1840. begin
  1841.   if (FTextSize.X = 0) or (GetGlyphWidth=0) then
  1842.     TextOffs := 0
  1843.   else
  1844.     TextOffs := TextBtnOffset;
  1845.  
  1846.   case FAllignment of
  1847.     abLeft, abRight, abCenter:
  1848.       begin
  1849.         case FAllignment of
  1850.           abLeft : Result := Rect(IRect.Right+TextOffs, 0, IRect.Right+TextOffs+FTextSize.X, Height);
  1851.           abRight: Result := Rect(ButtonOffset, 0, IRect.Left-TextOffs, Height);
  1852.           abCenter: Result := Rect(IRect.Right+TextOffs, 0, FWidth-ButtonOffset, Height);
  1853.         end;
  1854.         if (Result.Bottom-Result.Top) > FTextSize.Y then
  1855.         begin
  1856.           Result.Top    := (Result.Bottom+Result.Top-FTextSize.Y)shr 1;
  1857.           Result.Bottom := Result.Top + FTextSize.Y;
  1858.         end;
  1859.       end;
  1860.     abImageTop:
  1861.       begin
  1862.         Result := Rect(ButtonOffset, IRect.Bottom+TextOffs, FWidth-ButtonOffset, FHeight);
  1863.         if (Result.Right-Result.Left) > FTextSize.X then
  1864.         begin
  1865.           Result.Left    := (Result.Right+Result.Left-FTextSize.X)shr 1;
  1866.           Result.Right   := Result.Left + FTextSize.X;
  1867.         end;
  1868.       end;
  1869.     abImageBottom:
  1870.       begin
  1871.         Result := Rect(ButtonOffset, 0, FWidth-ButtonOffset, IRect.Left-TextOffs);
  1872.         if (Result.Right-Result.Left) > FTextSize.X then
  1873.         begin
  1874.           Result.Left    := (Result.Right+Result.Left-FTextSize.X)shr 1;
  1875.           Result.Right   := Result.Left + FTextSize.X;
  1876.         end;
  1877.       end;
  1878.   end;
  1879.   OffsetRect(Result, 1, 1);
  1880.   Inflaterect(Result, 1, 1);
  1881. end;
  1882.  
  1883. function TDCEditButton.GetTextSize: TPoint;
  1884.  var
  1885.   ARect: TRect;
  1886. begin
  1887.   UserBitmap.Canvas.Font := FFont;
  1888.   if FHighlight then
  1889.     Result := DrawHighLightText(UserBitmap.Canvas, PChar(FText), Rect(0,0, MaxInt, MaxInt), 0,
  1890.       DT_END_ELLIPSIS, FImages)
  1891.   else begin
  1892.     ARect := Rect(0,0, MaxInt, MaxInt);
  1893.     Windows.DrawText(UserBitmap.Canvas.Handle, PChar(FText), Length(FText),
  1894.       ARect, DT_CALCRECT);
  1895.     Result :=  Point(ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
  1896.   end;
  1897. end;
  1898.  
  1899. procedure TDCEditButton.SetFont(const Value: TFont);
  1900. begin
  1901.   FFont.Assign(Value);
  1902.   FTextSize := GetTextSize;
  1903. end;
  1904.  
  1905. function TDCEditButton.GetImageOffset: TPoint;
  1906. begin
  1907.   if (FButtonState = btDownMouseInRect) and
  1908.      not((FStyle = stShadowFlat) or (FStyle = stNone) or (FStyle = stIcon) or
  1909.       (FStyle = stSingle) or (FStyle = stXPStyle))
  1910.   then
  1911.     Result := Point(1, 1)
  1912.   else
  1913.     Result := Point(0, 0);
  1914. end;
  1915.  
  1916. function TDCEditButton.GetTextOffset: TPoint;
  1917. begin
  1918.   if (FButtonState = btDownMouseInRect) and
  1919.      not((FStyle = stShadowFlat) or (FStyle = stNone) or
  1920.          (FStyle = stOutBar) and (FEventStyle <> esDropDown) or
  1921.          (FStyle = stIcon) or (FStyle = stSingle) or (FStyle = stXPStyle))
  1922.   then
  1923.     Result := Point(1, 1)
  1924.   else
  1925.     Result := Point(0, 0);
  1926. end;
  1927.  
  1928. procedure TDCEditButton.Invalidate;
  1929. begin
  1930.   Paint;
  1931. end;
  1932.  
  1933. function TDCEditButton.IsEqual(Button: TDCEditButton): Boolean;
  1934. begin
  1935.   Result := (Text = Button.Text) and (ImageIndex = Button.ImageIndex);
  1936. end;
  1937.  
  1938. procedure TDCEditButton.ReadData(Stream: TStream; Info: PButtonInfo);
  1939.  var
  1940.   Size, ALen: LongWord;
  1941.   AText: PChar;
  1942.   ACLen, AHLen: LongWord;
  1943. begin
  1944.  
  1945.   Stream.ReadBuffer(Size, SizeOf(Size));
  1946.   Stream.ReadBuffer(ALen, SizeOf(Integer));
  1947.   Stream.ReadBuffer(Info^, Size);
  1948.  
  1949.   ACLen := ALen and $0000FFFF;
  1950.   AHLen := (ALen shr 16) and $0000FFFF;
  1951.  
  1952.   Tag          := Info^.Tag;
  1953.   ImageIndex   := Info^.ImageIndex;
  1954.   Enabled      := Info^.Enabled;
  1955.   Top          := Info^.Top;
  1956.   Left         := Info^.Left;
  1957.   Width        := Info^.Width;
  1958.   Height       := Info^.Height;
  1959.   Allignment   := TAllignment(Info^.Allignment);
  1960.   if Info^.Style <= integer(stNone) then
  1961.     Style      := TButtonStyle(Info^.Style)
  1962.   else
  1963.     Style      := stFlat;
  1964.   EventStyle   := TEventStyle(Info^.EvtStyle);
  1965.   Grouped      := Info^.Grouped;
  1966.   AnchorStyle  := TAnchorStyle(Info^.AncStyle);
  1967.   DisableStyle := TDisableStyle(Info^.DisStyle);
  1968.   AbsolutePos  := Info^.AbsolutePos;
  1969.   ResetOnExitControl  := Info^.ResetOnExit;
  1970.  
  1971.   GetMem(AText, ACLen);
  1972.   try
  1973.     Stream.ReadBuffer(AText^, ACLen);
  1974.     Text := AText;
  1975.   finally
  1976.     FreeMem(AText);
  1977.   end;
  1978.  
  1979.   if AHLen > 0 then
  1980.   begin
  1981.     GetMem(AText, AHLen);
  1982.     try
  1983.       Stream.ReadBuffer(AText^, AHLen);
  1984.       Hint := AText;
  1985.     finally
  1986.       FreeMem(AText);
  1987.     end;
  1988.   end
  1989.   else
  1990.     Hint := ''
  1991. end;
  1992.  
  1993. procedure TDCEditButton.WriteData(Stream: TStream; Info: PButtonInfo);
  1994.  var
  1995.    Size, ALen: LongWord;
  1996.    AText: PChar;
  1997.    ACLen, AHLen: LongWord;
  1998. begin
  1999.   Size := SizeOf(TButtonInfo);
  2000.  
  2001.   ACLen := (Length(Text) + 1) and $0000FFFF;
  2002.  
  2003.   if Hint <> '' then
  2004.     AHLen := (Length(Hint) + 1) and $0000FFFF
  2005.   else
  2006.     AHLen :=  0;
  2007.   ALen  := AHLen shl 16 + ACLen;
  2008.  
  2009.   Info^.Tag        := Tag;
  2010.   Info^.ImageIndex := ImageIndex;
  2011.   Info^.Enabled    := Enabled;
  2012.   Info^.Top        := Top;
  2013.   Info^.Left       := Left;
  2014.   Info^.Width      := Width;
  2015.   Info^.Height     := Height;
  2016.   Info^.Allignment := integer(Allignment);
  2017.   Info^.Style      := integer(Style);
  2018.   Info^.EvtStyle   := integer(EventStyle);
  2019.   Info^.Grouped    := Grouped;
  2020.   Info^.AncStyle   := integer(AnchorStyle);
  2021.   Info^.DisStyle   := integer(DisableStyle);
  2022.   Info^.AbsolutePos:= AbsolutePos;
  2023.   Info^.ResetOnExit:= ResetOnExitControl;
  2024.  
  2025.   Stream.WriteBuffer(Size , SizeOf(Size));
  2026.   Stream.WriteBuffer(ALen , SizeOf(Integer));
  2027.   Stream.WriteBuffer(Info^, Size);
  2028.  
  2029.   GetMem(AText, ACLen);
  2030.   try
  2031.     StrPCopy(AText, Text);
  2032.     Stream.WriteBuffer(AText^ , ACLen);
  2033.   finally
  2034.     FreeMem(AText);
  2035.   end;
  2036.  
  2037.   if AHLen > 0 then
  2038.   begin
  2039.     GetMem(AText, AHLen);
  2040.     try
  2041.       StrPCopy(AText, Hint);
  2042.       Stream.WriteBuffer(AText^ , AHLen);
  2043.     finally
  2044.       FreeMem(AText);
  2045.     end;
  2046.   end;
  2047. end;
  2048.  
  2049. function TDCEditButtons.GetRegion: HRGN;
  2050. begin
  2051.   if Assigned(FOnGetRegion) then
  2052.     FOnGetRegion(Self, Result)
  2053.   else
  2054.     Result := NULLREGION;
  2055. end;
  2056.  
  2057. function TDCEditButton.GetBounds: TRect;
  2058. begin
  2059.   Result := Rect(0, 0, Width, Height);
  2060.   OffsetRect(Result, Left, Top);
  2061. end;
  2062.  
  2063. procedure TDCEditButton.Click;
  2064. begin
  2065.   if Assigned(FEditButtons) then FEditButtons.ActiveButton := TDCEditButton(Self);
  2066.   if Assigned(FOnClick) then FOnClick(Self);
  2067. end;
  2068.  
  2069. procedure TDCEditButton.SetWidth(const Value: integer);
  2070. begin
  2071.   if Visible then
  2072.     FWidth := Value
  2073.   else
  2074.     FVisibleWidth := Value;  
  2075. end;
  2076.  
  2077. procedure TDCEditButtons.SetColor(const Value: TColor);
  2078.  var
  2079.   i: integer;
  2080.   Button: TDCEditButton;
  2081. begin
  2082.   for i := 0 to FButtons.Count-1 do
  2083.   begin
  2084.     Button := TDCEditButton(Items[i]);
  2085.     if Button.BrushColor = FColor then Button.BrushColor := Value; 
  2086.   end;
  2087.   FColor := Value;
  2088. end;
  2089.  
  2090. function TDCEditButtons.IsButtonAccel(VK: Word;
  2091.   var Button: TDCEditButton): Boolean;
  2092.  var
  2093.   i: integer;
  2094.   eButton: TDCEditButton;
  2095. begin
  2096.   Result := False;
  2097.   Button := nil;
  2098.   for i := 0 to FButtons.Count - 1 do
  2099.   begin
  2100.     eButton := TDCEditButton(FButtons[i]);
  2101.     if eButton.Enabled and eButton.Visible and
  2102.        IsAccel(Ord(AnsiUpperCase(Chr(VK))[1]), AnsiUpperCase(eButton.Caption)) then
  2103.     begin
  2104.       Button := TDCEditButton(FButtons[i]);
  2105.       Result := True;
  2106.       Break;
  2107.     end;
  2108.   end;
  2109. end;
  2110.  
  2111. function TDCEditButtons.GetSelectedButton: TDCEditButton;
  2112.  var
  2113.   Button: TDCEditButton;
  2114.   i: integer;
  2115. begin
  2116.   Result := ActiveButton;
  2117.   if (Result <> nil) and (Result.ButtonState <> btDownMouseInRect) then
  2118.   begin
  2119.     Result := nil;
  2120.     for i := 0 to Count - 1 do
  2121.     begin
  2122.       Button := Buttons[i];
  2123.       if Button.ButtonState = btDownMouseInRect then
  2124.       begin
  2125.         Result := Button;
  2126.         Break;
  2127.       end;
  2128.     end;
  2129.   end;
  2130. end;
  2131.  
  2132. procedure TDCEditButton.SetHighlight(const Value: boolean);
  2133. begin
  2134.   if Value <> FHighlight then
  2135.   begin
  2136.     FHighlight := Value;
  2137.     FTextSize  := GetTextSize;
  2138.     Invalidate;
  2139.   end;
  2140. end;
  2141.  
  2142. procedure TDCEditButton.SetDownClick(const Value: boolean);
  2143. begin
  2144.   if not FDownClick and (ButtonState <> btDownMouseInRect) then FDownButton:= False;
  2145.   if Value and (FEventStyle = esDropDown) and
  2146.      (ButtonState = btDownMouseInRect) then FDownButton:= True;
  2147.   FDownClick  := Value;
  2148. end;
  2149.  
  2150. procedure TDCEditButtons.SetActiveButton(const Value: TDCEditButton);
  2151. begin
  2152.   FActiveButton := Value;
  2153. end;
  2154.  
  2155. procedure TDCEditButtons.BeginUpdate;
  2156. begin
  2157.   Inc(FUpdateCount);
  2158. end;
  2159.  
  2160. procedure TDCEditButtons.EndUpdate;
  2161. begin
  2162.   Dec(FUpdateCount);
  2163.   if FUpdateCount = 0 then RepaintButtons;
  2164. end;
  2165.  
  2166. function TDCEditButtons.AddButtonEx(
  2167.   EditButtonClass: TEditButtonClass): TDCEditButton;
  2168.  var
  2169.   Button: TDCEditButton;
  2170.   AIndex: integer;
  2171. begin
  2172.   Button := EditButtonClass.Create(FOwner);
  2173.   AIndex := FButtons.Add(Button);
  2174.   Button.Name  := Format('%s%d', [Button.Name,AIndex]);
  2175.   Button.Glyph := nil;
  2176.   Button.Grouped  := True;
  2177.   Button.AnchorStyle := AnchorStyle;
  2178.   Button.AbsolutePos := AbsolutePos;
  2179.   Button.Images      := FImages;
  2180.   Button.FIndex      := AIndex;
  2181.   Button.FEditButtons:= Self;
  2182.   Button.BrushColor  := FColor;
  2183.  
  2184.   Result := Button;
  2185. end;
  2186.  
  2187. function TDCEditButton.GetEditButtons: TDCEditButtons;
  2188. begin
  2189.   Result := FEditButtons;
  2190. end;
  2191.  
  2192. function TDCEditButton.OneClickButton: boolean;
  2193. begin
  2194.   Result := False;
  2195. end;
  2196.  
  2197. procedure TDCEditButton.BeginDrawText(ACanvas: TCanvas; ATextRect: TRect);
  2198.  var
  2199.   ParentForm: TCustomForm;
  2200. begin
  2201.   with ACanvas do
  2202.   begin
  2203.     case FStyle of
  2204.       stIcon:
  2205.         case FButtonState of
  2206.           btRest:;
  2207.           btDownMouseInRect:
  2208.             begin
  2209.               ParentForm := GetParentForm(FEditButtons.Owner);
  2210.               if (ParentForm <> nil) and (ParentForm.ActiveControl = FEditButtons.Owner) then
  2211.               begin
  2212.                 Brush.Color := clHighlight;
  2213.                 Font.Color  := clHighlightText;
  2214.               end
  2215.               else begin
  2216.                 Brush.Color := clBtnFace;
  2217.               end;
  2218.               FillRect(ATextRect);
  2219.               Dec(ATextRect.Bottom, 2);
  2220.               Windows.DrawFocusRect(ACanvas.Handle, ATextRect);
  2221.             end;
  2222.           btRestMouseInRect:
  2223.         end;
  2224.     end;
  2225.   end;
  2226. end;
  2227.  
  2228. procedure TDCEditButtons.DoChangeFocus;
  2229.  var
  2230.   i: integer;
  2231. begin
  2232.   for i := 0 to Count-1 do
  2233.   begin
  2234.     if Buttons[i].FocusSensitive then Buttons[i].invalidate;
  2235.   end;
  2236. end;
  2237.  
  2238. function TDCEditButtons.GetButtonsActive: boolean;
  2239.  var
  2240.   Button: TDCEditButton;
  2241.   i: integer;
  2242. begin
  2243.   Result := False;
  2244.   for i := 0 to Count - 1 do
  2245.   begin
  2246.     Button := Buttons[i];
  2247.     if Button.ButtonState <> btRest then
  2248.     begin
  2249.       Result := True;
  2250.       Break;
  2251.     end;
  2252.   end;
  2253. end;
  2254.  
  2255. procedure TDCEditButtons.SaveBackground;
  2256.  var
  2257.   DC: HDC;
  2258.   R: TRect;
  2259. begin
  2260.   DC := GetWindowDC(Owner.Handle);
  2261.   GetWindowRect(Owner.Handle, R); OffsetRect(R,  -R.Left, -R.Top);
  2262.   try
  2263.     with FBkgImage do
  2264.     begin
  2265.       Width  := R.Right;
  2266.       Height := R.Bottom;
  2267.       BitBlt(Canvas.Handle, 0, 0, Width, Height, DC, 0, 0, SRCCOPY);
  2268.     end;
  2269.   finally
  2270.     ReleaseDC(Owner.Handle, DC)
  2271.   end;
  2272. end;
  2273.  
  2274. procedure TDCEditButtons.PaintBackground(ARect: TRect; AButton: TDCEditButton;
  2275.  ACanvas: TCanvas);
  2276. begin
  2277.   BitBlt(ACanvas.Handle, ARect.Left, ARect.Top, ARect.Right - ARect.Left,
  2278.    ARect.Bottom - ARect.Top, FBkgImage.Canvas.Handle, AButton.Left, AButton.Top, SRCCOPY);
  2279. end;
  2280.  
  2281. procedure TDCEditButtons.UpdateMaxImageWidth;
  2282.  var
  2283.   i, MaxWidth: integer;
  2284.   Button: TDCEditButton;
  2285. begin
  2286.   MaxWidth := 0;
  2287.   for i := 0 to Count-1 do
  2288.   begin
  2289.     Button := Buttons[i];
  2290.     with Button do
  2291.     begin
  2292.       if (Caption <> MenuLineCaption) and not Button.Glyph.Empty then
  2293.         MaxWidth := _intMax(Button.Glyph.Width, MaxWidth);
  2294.     end;
  2295.     FMaxImageWidth := MaxWidth;
  2296.   end;
  2297. end;
  2298.  
  2299. { TDCHintButton }
  2300.  
  2301. constructor TDCHintButton.Create(AOwner: TComponent);
  2302. begin
  2303.   inherited;
  2304.   Style := stNone;
  2305. end;
  2306.  
  2307. procedure TDCHintButton.DrawBorder(ACanvas: TCanvas; ARect: TRect);
  2308.  const
  2309.   HintEllipseRadius = 3;
  2310.  
  2311.  var
  2312.   AButtonState: TButtonState;
  2313.  
  2314.   procedure DrawNormalHintButton(ACanvas: TCanvas; ARect: TRect);
  2315.    var
  2316.     Rgn: HRgn;
  2317.     nEllipse: integer;
  2318.    begin
  2319.     nEllipse := HintEllipseRadius;
  2320.     InflateRect(ARect, -1,-1);
  2321.     with ARect do
  2322.       Rgn := CreateRoundRectRgn(Left, Top, Right, Bottom, nEllipse, nEllipse);
  2323.  
  2324.     ACanvas.Pen.Style := psSolid;
  2325.     ACanvas.Brush.Color := clHintBackground;
  2326.     PaintRgn(ACanvas.Handle, Rgn);
  2327.  
  2328.     ACanvas.Brush.Color := clHintNormal;
  2329.     FrameRgn(ACanvas.Handle, Rgn, ACanvas.Brush.Handle, 1, 1);
  2330.     DeleteObject(Rgn)
  2331.   end;
  2332.  
  2333.   procedure DrawUpHintButton(ACanvas: TCanvas; ARect: TRect);
  2334.    var
  2335.     Rgn: HRgn;
  2336.     nEllipse: integer;
  2337.     i: integer;
  2338.     AColor: TColor;
  2339.   begin
  2340.     nEllipse := HintEllipseRadius+1;
  2341.     with ARect do
  2342.       Rgn := CreateRoundRectRgn(Left, Top, Right, Bottom, nEllipse, nEllipse);
  2343.  
  2344.     ACanvas.Pen.Style := psSolid;
  2345.     ACanvas.Brush.Color := clHintBackground;
  2346.     PaintRgn(ACanvas.Handle, Rgn);
  2347.  
  2348.     ACanvas.Brush.Color := clHintLight;
  2349.     FrameRgn(ACanvas.Handle, Rgn, ACanvas.Brush.Handle, 1, 1);
  2350.     DeleteObject(Rgn);
  2351.  
  2352.     ACanvas.Pen.Color   := clHintDark;
  2353.     with ARect do
  2354.     begin
  2355.       ACanvas.PolyLine([Point(Right-3, Top+3), Point(Right-3, Bottom-5),
  2356.                         Point(Right-4, Bottom-4), Point(Right-5, Bottom-3),
  2357.                         Point(Left+2, Bottom-3)]);
  2358.       ACanvas.Pixels[Right-3, Top+2]    := clHintNormal;
  2359.       ACanvas.Pixels[Left+2 , Bottom-4] := clHintNormal;
  2360.     end;
  2361.  
  2362.     ACanvas.Pen.Color   := clHintBackground;
  2363.     InflateRect(ARect, -5, -5);
  2364.     for i := 1 to 4 do
  2365.     begin
  2366.       InflateRect(ARect, 1, 1);
  2367.       AColor := ACanvas.Pen.Color;
  2368.       ACanvas.Pen.Color   := RGB(GetRValue(AColor)-5, GetGValue(AColor)-5, GetBValue(AColor)-5);
  2369.       with ARect do
  2370.       begin
  2371.         ACanvas.PolyLine([Point(Right-3, Top+3), Point(Right-3, Bottom-5),
  2372.                           Point(Right-4, Bottom-4), Point(Right-5, Bottom-3),
  2373.                           Point(Left+2, Bottom-3)]);
  2374.         ACanvas.Pixels[Right-3, Top+2]    := AColor;
  2375.         ACanvas.Pixels[Left+2 , Bottom-4] := AColor;
  2376.       end;
  2377.     end;
  2378.   end;
  2379.  
  2380.   procedure DrawDownHintButton(ACanvas: TCanvas; ARect: TRect);
  2381.   var
  2382.    Rgn: HRgn;
  2383.    nEllipse: integer;
  2384.     i: integer;
  2385.     AColor: TColor;
  2386.   begin
  2387.     nEllipse := HintEllipseRadius + 1;
  2388.     with ARect do
  2389.       Rgn := CreateRoundRectRgn(Left, Top, Right, Bottom, nEllipse, nEllipse);
  2390.  
  2391.     ACanvas.Pen.Style := psSolid;
  2392.     ACanvas.Brush.Color := clHintBackground;
  2393.     PaintRgn(ACanvas.Handle, Rgn);
  2394.  
  2395.     ACanvas.Brush.Color := clHintLight;
  2396.     FrameRgn(ACanvas.Handle, Rgn, ACanvas.Brush.Handle, 1, 1);
  2397.     DeleteObject(Rgn);
  2398.  
  2399.     ACanvas.Pen.Color   := clHintDark;
  2400.     with ARect do
  2401.     begin
  2402.       ACanvas.PolyLine([Point(Left+1, Bottom-5),
  2403.                         Point(Left+1, Top+3), Point(Left+2, Top+2),
  2404.                         Point(Left+3, Top+1), Point(Right-4,Top+1)]);
  2405.       ACanvas.Pixels[Right-4, Top+2]    := clHintNormal;
  2406.       ACanvas.Pixels[Left+1 , Bottom-4] := clHintNormal;
  2407.     end;
  2408.  
  2409.     ACanvas.Pen.Color   := clHintBackground;
  2410.     InflateRect(ARect, -5, -5);
  2411.     for i := 1 to 4 do
  2412.     begin
  2413.       InflateRect(ARect, 1, 1);
  2414.       AColor := ACanvas.Pen.Color;
  2415.       ACanvas.Pen.Color   := RGB(GetRValue(AColor)-5, GetGValue(AColor)-5, GetBValue(AColor)-5);
  2416.       with ARect do
  2417.       begin
  2418.         ACanvas.PolyLine([Point(Left+1, Bottom-5),
  2419.                           Point(Left+1, Top+3), Point(Left+2, Top+2),
  2420.                           Point(Left+3, Top+1), Point(Right-4,Top+1)]);
  2421.         ACanvas.Pixels[Right-4, Top+2]    := AColor;
  2422.         ACanvas.Pixels[Left+1 , Bottom-4] := AColor;
  2423.       end;
  2424.     end;
  2425.   end;
  2426.  
  2427. begin
  2428.   AButtonState := FButtonState;
  2429.   if not Enabled then AButtonState := btRest;
  2430.  
  2431.   with UserBitmap do
  2432.     case AButtonState of
  2433.       btRest:
  2434.         begin
  2435.           if (csDesigning in (FOwner as TComponent).ComponentState) then
  2436.           begin
  2437.             DrawNormalHintButton(Canvas, ARect);
  2438.           end
  2439.           else
  2440.             DrawNormalHintButton(Canvas, ARect);
  2441.         end;
  2442.       btDownMouseInRect:
  2443.         begin
  2444.           DrawDownHintButton(Canvas, ARect);
  2445.         end;
  2446.       btRestMouseInRect:
  2447.         begin
  2448.           DrawUpHintButton(Canvas, ARect);
  2449.         end;
  2450.     end;
  2451. end;
  2452.  
  2453. procedure TDCEditButton.SetStyle(const Value: TButtonStyle);
  2454. begin
  2455.   FStyle := Value;
  2456.   FFocusSensitive := FStyle = stIcon;
  2457. end;
  2458.  
  2459. procedure TDCEditButton.DoPaint(ACanvas: TCanvas; ARect: TRect);
  2460.  var
  2461.   ImageRect, TextRect: TRect;
  2462. begin
  2463.   BeginDrawBkgn(ACanvas, ARect, ImageRect, TextRect);
  2464.   DrawBkgnd(ACanvas, ARect);
  2465.   DrawBorder(ACanvas, ARect);
  2466.   DrawBitmap(ACanvas, ImageRect);
  2467.   if (FText <> '') and FDrawText then DrawEditText(ACanvas, TextRect);
  2468. end;
  2469.  
  2470. function TDCHintButton.GetTextSize: TPoint;
  2471. begin
  2472.   Result := inherited GetTextSize;
  2473.   Inc(Result.Y, 2);
  2474. end;
  2475.  
  2476. procedure TDCEditButton.SetTransparent(const Value: boolean);
  2477. begin
  2478.   if FTransparent <> Value then
  2479.   begin
  2480.     FTransparent := Value;
  2481.     if Assigned(OwnerButtons) then OwnerButtons.Invalidate;
  2482.   end;
  2483. end;
  2484.  
  2485. procedure TDCEditButton.DrawTranDisableBitmap(ACanvas: TCanvas;
  2486.   ImageRect: TRect);
  2487.  var
  2488.   ARect: TRect;
  2489. begin
  2490.   try
  2491.     ARect := Rect(0, 0, GetGlyphWidth, GetGlyphHeight);
  2492.     if (GetGlyphHeight > 0) and (GetGlyphWidth > 0) then
  2493.     begin
  2494.       if AsignedImages then
  2495.       begin
  2496.         with GlyphBitmap.Canvas do
  2497.         begin
  2498.           Brush.Color := clWhite;
  2499.           FillRect(ARect);
  2500.         end;
  2501.         FImages.GetBitmap(FImageIndex, GlyphBitmap);
  2502.         TransformBitmapTransparent(GlyphBitmap, nil, GlyphBitmap, 40);
  2503.       end
  2504.       else begin
  2505.         GlyphBitmap.Assign(FGlyph);
  2506.         TransformBitmapTransparent(Glyph, nil, GlyphBitmap, 40);
  2507.       end;
  2508.       ACanvas.StretchDraw(ImageRect, GlyphBitmap);
  2509.     end;
  2510.   finally
  2511.     {};
  2512.   end;
  2513. end;
  2514.  
  2515. procedure TDCEditButton.DrawBkgnd(ACanvas: TCanvas; Rect: TRect);
  2516. begin
  2517.   if Transparent and Assigned(OwnerButtons) then
  2518.     OwnerButtons.PaintBackground(Rect, Self, ACanvas)
  2519.   else
  2520.     FillRect(ACanvas.Handle, Rect, ACanvas.Brush.Handle);
  2521. end;
  2522.  
  2523. procedure TDCEditButton.BeginDrawBkgn(ACanvas: TCanvas; ARect: TRect;
  2524.   var ImageRect: TRect; var TextRect: TRect);
  2525. begin
  2526.   ImageRect := GetImageRect;
  2527.   TextRect  := GetTextRect(ImageRect);
  2528.   OffsetRect(ImageRect, ARect.Left, ARect.Top);
  2529.   OffsetRect(TextRect, ARect.Left, ARect.Top);
  2530.  
  2531.   if not Enabled then
  2532.      case FDisableStyle of
  2533.        deLite  :
  2534.          if FStyle = stNone then
  2535.            ACanvas.Brush.Color := FBrushColor
  2536.          else
  2537.            ACanvas.Brush.Bitmap := AllocPatternBitmap(clLite, clBtnFace);
  2538.        deNormal:
  2539.          ACanvas.Brush.Color  := FBrushColor;
  2540.        deNone  :
  2541.          ACanvas.Brush.Color  := FBrushColor;
  2542.        deTrans :
  2543.          ACanvas.Brush.Color  := FBrushColor;
  2544.      end
  2545.   else
  2546.     case FStyle of
  2547.       stOutBar:
  2548.         begin
  2549.           if FEventStyle = esDropDown then
  2550.           begin
  2551.             case FButtonState of
  2552.               btRest, btRestMouseInRect:
  2553.                 ACanvas.Brush.Color := FBrushColor;
  2554.               btDownMouseInRect:
  2555.                  if ColorToRGB(FBrushColor) = ColorToRGB(clBtnFace) then
  2556.                    ACanvas.Brush.Bitmap := AllocPatternBitmap(clWhite, clBtnFace)
  2557.                  else
  2558.                    ACanvas.Brush.Color := FBrushColor;
  2559.             end;
  2560.           end
  2561.           else
  2562.             ACanvas.Brush.Color := FBrushColor;
  2563.         end;
  2564.       stShadowFlat:
  2565.         case FButtonState of
  2566.           btRest:
  2567.             if (csDesigning in (FOwner as TComponent).ComponentState) and
  2568.                (ColorToRGB(FBrushColor) = clWhite) then
  2569.               ACanvas.Brush.Bitmap := AllocPatternBitmap(clWhite, clBtnFace)
  2570.             else
  2571.               ACanvas.Brush.Color := FBrushColor;
  2572.           btDownMouseInRect, btRestMouseInRect:
  2573.             if (ColorToRGB(FBrushColor) = clWhite)  or
  2574.                ((ColorToRGB(FBrushColor) = clSilver) or (FBrushColor = clBtnFace)) and FFlatPattern then
  2575.               ACanvas.Brush.Bitmap := AllocPatternBitmap(clWhite, clBtnFace)
  2576.             else
  2577.               ACanvas.Brush.Color := FBrushColor;
  2578.         end;
  2579.       stSingle, stXPStyle:
  2580.         case FButtonState of
  2581.           btRest:
  2582.             ACanvas.Brush.Color := FBrushColor;
  2583.           btRestMouseInRect:
  2584.             ACanvas.Brush.Color := FSelectColor;
  2585.           btDownMouseInRect:
  2586.             ACanvas.Brush.Color := clXPDropDown;
  2587.         end;
  2588.       else
  2589.         ACanvas.Brush.Color := FBrushColor;
  2590.  
  2591.     end;
  2592. end;
  2593.  
  2594. procedure TDCEditButton.SetSelectColor(const Value: TColor);
  2595. begin
  2596.   FSelectColor := Value;
  2597. end;
  2598.  
  2599. initialization
  2600.  UserBitmap      := TBitmap.Create;
  2601.  GlyphBitmap      := TBitmap.Create;
  2602.  
  2603.  GlyphBitmap.Transparent := True;
  2604.  ShortDateFormat := Format('dd%0:smm%0:syyyy',[DateSeparator]);
  2605.  
  2606. finalization
  2607.  UserBitmap.Free;
  2608.  GlyphBitmap.Free;
  2609.  
  2610. end.
  2611.  
  2612.