mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 20:04:00 +02:00
LCL: TreeView tooltips support. Issue #28879, patch from Alexey Torgashin.
git-svn-id: trunk@50186 -
This commit is contained in:
parent
e3a1721df5
commit
030f238cbd
lcl
@ -3248,6 +3248,7 @@ type
|
||||
FTreeLinePenStyle: TPenStyle;
|
||||
FExpandSignColor : TColor;
|
||||
FTreeNodes: TTreeNodes;
|
||||
FHintWnd: THintWindow;
|
||||
procedure CanvasChanged(Sender: TObject);
|
||||
function GetAutoExpand: boolean;
|
||||
function GetBottomItem: TTreeNode;
|
||||
@ -3312,6 +3313,7 @@ type
|
||||
procedure UpdateMaxRight;
|
||||
procedure UpdateTopItem;
|
||||
procedure UpdateScrollbars;
|
||||
procedure UpdateTooltip(X, Y: integer);
|
||||
procedure InternalSelectionChanged;
|
||||
protected
|
||||
FChangeTimer: TTimer;
|
||||
|
@ -4217,6 +4217,55 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomTreeView.UpdateTooltip(X, Y: integer);
|
||||
const
|
||||
cMaxHintWidth = 800; //some guess value
|
||||
var
|
||||
Node: TTreeNode;
|
||||
P: TPoint;
|
||||
R: TRect;
|
||||
OffsetLeft: integer;
|
||||
SText: string;
|
||||
begin
|
||||
if FHintWnd=nil then
|
||||
FHintWnd:=THintWindow.Create(Self);
|
||||
|
||||
Node:=GetNodeAt(X, Y);
|
||||
if Node=nil then
|
||||
begin
|
||||
FHintWnd.Hide;
|
||||
exit;
|
||||
end;
|
||||
|
||||
SText:=Node.Text;
|
||||
OffsetLeft:=(Node.Level+1)*16 + 2;
|
||||
//seems each level gives indent of 16pix
|
||||
//this needs dec for ShowRoot=false, but i cannot guess, by 16pix?
|
||||
|
||||
if Assigned(FImages) then
|
||||
if (not Node.Selected and (Node.ImageIndex>=0)) or
|
||||
(Node.Selected and (Node.SelectedIndex>=0)) then
|
||||
Inc(OffsetLeft, FImages.Width);
|
||||
|
||||
Canvas.Font.Assign(Self.Font);
|
||||
if Canvas.TextWidth(SText)+OffsetLeft < ClientWidth then
|
||||
begin
|
||||
FHintWnd.Hide;
|
||||
exit;
|
||||
end;
|
||||
|
||||
R:=FHintWnd.CalcHintRect(cMaxHintWidth, SText, nil);
|
||||
|
||||
//show hint at edge of control, to not overlap node, to allow click node,
|
||||
//also hint fontsize <> control fontsize
|
||||
P:=Point(ClientWidth, Node.Top);
|
||||
P:=ClientToScreen(P);
|
||||
OffsetRect(R, P.X, P.Y);
|
||||
|
||||
FHintWnd.ActivateHint(R, SText);
|
||||
FHintWnd.Invalidate; //for Windows
|
||||
end;
|
||||
|
||||
function TCustomTreeView.GetSelection: TTreeNode;
|
||||
begin
|
||||
if RightClickSelect and Assigned(FRClickNode) then
|
||||
@ -5338,6 +5387,8 @@ begin
|
||||
inherited MouseMove(Shift, x, y);
|
||||
if (tvoAutoInsertMark in FOptions) then
|
||||
UpdateInsertMark(X,Y);
|
||||
if (tvoToolTips in FOptions) then
|
||||
UpdateTooltip(X, Y);
|
||||
end;
|
||||
|
||||
procedure TCustomTreeView.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
||||
|
Loading…
Reference in New Issue
Block a user