unit u_hint_attribs;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Graphics, Controls;
// Call as many times as you like to customize your application hints
procedure SetAppHintAttributes(aBackgroundColor,
aFontColor: TColor;
aFontHeight: integer=0;
aFontName: string='default';
aFontStyles: TFontStyles=[];
aAlign: TAlignment=taLeftJustify);
implementation
uses Forms, dialogs;
type
{ TAppCustomHint }
TAppCustomHint = class(THintWindow)
private class var
_FBackGroundColor,
_FFontColor: TColor;
_FFontHeight: integer;
_FFontName: string;
_FFontStyles: TFontStyles;
_FAlign: TAlignment;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure Paint; override;
class procedure InitParam(aBackgroundColor,
aFontColor: TColor;
aFontHeight: integer;
aFontName: string;
aFontStyles: TFontStyles;
aAlign: TAlignment);
procedure ProcessOnShowHintEvent(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
constructor TAppCustomHint.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Application.AddOnShowHintHandler(@ProcessOnShowHintEvent);
end;
procedure TAppCustomHint.ProcessOnShowHintEvent(var HintStr: string;
var CanShow: Boolean; var HintInfo: THintInfo);
begin
Font.Height := _FFontHeight;
Font.Name := _FFontName;
Font.Style := _FFontStyles;
Font.Color := _FFontColor;
end;
destructor TAppCustomHint.Destroy;
begin
Application.RemoveOnShowHintHandler(@ProcessOnShowHintEvent);
inherited Destroy;
end;
procedure TAppCustomHint.AfterConstruction;
var
HintStr: string = ''; // Init the variables to prevent variable not
CanShow: Boolean = True; // initilized warning
HintInfo: THintInfo;
begin
inherited AfterConstruction;
HintInfo:=Default(THintInfo);
ProcessOnShowHintEvent(HintStr, CanShow, HintInfo);
end;
procedure TAppCustomHint.Paint;
var r: TRect;
ts: TTextStyle;
begin
r := ClientRect;
with ts do begin
Alignment := _FAlign;
Layout := tlCenter;
SingleLine := False;
Clipping := False;
Wordbreak := True;
Opaque := False;
SystemFont := False;
RightToLeft := BidiMode<>bdLeftToRight;
end;
with Canvas do begin
Brush.Style := bsSolid;
Brush.Color := _FBackGroundColor;
FillRect(r);
Canvas.Font.Color := _FFontColor;
Canvas.Font.Height := _FFontHeight;
Canvas.Font.Name := _FFontName;
Canvas.Font.Style := _FFontStyles;
TextRect(r, 0, 0, Caption, ts);
end;
end;
class procedure TAppCustomHint.InitParam(aBackgroundColor, aFontColor: TColor;
aFontHeight: integer; aFontName: string; aFontStyles: TFontStyles; aAlign: TAlignment);
begin
if aFontName = '' then aFontName := 'default';
_FBackGroundColor := aBackgroundColor;
_FFontColor := aFontColor;
_FFontHeight := aFontHeight;
_FFontName := aFontName;
_FFontStyles := aFontStyles;
_FAlign := aAlign;
end;
procedure SetAppHintAttributes(aBackgroundColor, aFontColor: TColor;
aFontHeight: integer; aFontName: string; aFontStyles: TFontStyles; aAlign: TAlignment);
begin
TAppCustomHint.InitParam(aBackgroundColor, aFontColor, aFontHeight, aFontName,
aFontStyles, aAlign);
HintWindowClass := TAppCustomHint;
end;
end.