home *** CD-ROM | disk | FTP | other *** search
- unit ListBoxEx;
-
- interface
-
- uses Windows, Messages, Classes, Controls, Graphics, StdCtrls, Forms;
-
- type
- TListBoxOptions = class (TPersistent)
- private
- fHintColor: TColor;
- published
- property HintColor: TColor read fHintColor write fHintColor default clInfoBk;
- end;
-
- TListBoxEx = class (TListBox)
- private
- fLastHintIdx: Integer;
- fOptions: TListBoxOptions;
- procedure CMHintShow (var Msg: TCMHintShow); message cm_HintShow;
- protected
- procedure MouseMove (Shift: TShiftState; X, Y: Integer); override;
- public
- constructor Create (AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Advanced: TListBoxOptions read fOptions write fOptions;
- end;
-
- procedure Register;
-
- implementation
-
- constructor TListBoxEx.Create (AOwner: TComponent);
- begin
- Inherited Create (AOwner);
- fOptions := TListBoxOptions.Create;
- fOptions.fHintColor := clInfoBk;
- fLastHintIdx := -1;
- end;
-
- destructor TListBoxEx.Destroy;
- begin
- fOptions.Free;
- Inherited Destroy;
- end;
-
- procedure TListBoxEx.CMHintShow (var Msg: TCMHintShow);
- var
- ShowHint: Boolean;
- begin
- ShowHint := False;
- with Msg.HintInfo^ do if Self = HintControl then begin
- HintStr := '';
- HintColor := fOptions.fHintColor;
- fLastHintIdx := CursorPos.y div ItemHeight;
- if Items.Count > TopIndex + fLastHintIdx then HintStr := Items [TopIndex + fLastHintIdx];
- HintPos := ClientToScreen (Point (0, (ItemHeight * fLastHintIdx) - 2));
- ShowHint := Width < Canvas.TextWidth (HintStr) + 10;
- end;
-
- Msg.Result := Ord (not ShowHint);
- end;
-
- procedure TListBoxEx.MouseMove (Shift: TShiftState; X, Y: Integer);
- begin
- if (fLastHintIdx >= 0) and (Y div ItemHeight <> fLastHintIdx) then begin
- Application.CancelHint;
- fLastHintIdx := -1;
- end;
-
- Inherited MouseMove (Shift, X, Y);
- end;
-
- procedure Register;
- begin
- RegisterComponents ('Uncommon', [TListBoxEx]);
- end;
-
- end.
-
-
-