IdeIntf: Simplify hint handling in TOICustomPropertyGrid.MouseMove a little. Add comments.

git-svn-id: trunk@64029 -
This commit is contained in:
juha 2020-10-16 19:44:46 +00:00
parent 70240d5335
commit c83c7f8279

View File

@ -2400,7 +2400,7 @@ var
HintType: TPropEditHint; HintType: TPropEditHint;
fPropRow: TOIPropertyGridRow; fPropRow: TOIPropertyGridRow;
procedure DoShow(pt: TPoint); inline; procedure ShowShortHint(pt: TPoint); inline;
//var HintFont: TFont; //var HintFont: TFont;
begin begin
if WidgetSet.GetLCLCapability(lcTransparentWindow)=LCL_CAPABILITY_NO then if WidgetSet.GetLCLCapability(lcTransparentWindow)=LCL_CAPABILITY_NO then
@ -2423,6 +2423,7 @@ var
var var
SplitDistance, Index, TextLeft: Integer; SplitDistance, Index, TextLeft: Integer;
HintWillChange: Boolean;
begin begin
inherited MouseMove(Shift,X,Y); inherited MouseMove(Shift,X,Y);
SplitDistance := X-SplitterX; SplitDistance := X-SplitterX;
@ -2435,7 +2436,7 @@ begin
EndDragSplitter; EndDragSplitter;
end end
else begin else begin
if (abs(SplitDistance)<=2) then if abs(SplitDistance) <= 2 then
Cursor := crHSplit Cursor := crHSplit
else else
Cursor := crDefault; Cursor := crDefault;
@ -2445,14 +2446,19 @@ begin
SetItemIndexAndFocus(Index); SetItemIndexAndFocus(Index);
SetCaptureControl(Self); SetCaptureControl(Self);
end; end;
// hide the hint of an earlier row // The following code handler 2 kinds of hints :
// 1. Property's name / value when it does not fit in the cell.
// 2. Long description of a property / value, only when ShowHint option is set.
Index := MouseToIndex(y,false); Index := MouseToIndex(y,false);
HintType := GetHintTypeAt(Index, x); HintType := GetHintTypeAt(Index, x);
if (Index<>FHintIndex) or (HintType<>FHintType) then HintWillChange := (Index<>FHintIndex) or (HintType<>FHintType);
HideHint; if HintWillChange then
if (Index > -1) and not FShowingLongHint HideHint; // hide the hint of an earlier row
and not (FHintManager.HintIsVisible and (Index=FHintIndex) and (HintType=FHintType)) then // Don't show any more hints if the long hint is there.
begin // check if the property text fits in its box, if not show a hint if FShowingLongHint or (Index = -1) then Exit;
// Show the property text as a hint if it does not fit in its box.
if HintWillChange or not FHintManager.HintIsVisible then
begin
FHintIndex := Index; FHintIndex := Index;
FHintType := HintType; FHintType := HintType;
fPropRow := GetRow(Index); fPropRow := GetRow(Index);
@ -2461,7 +2467,7 @@ begin
TheHint := fPropRow.Name; TheHint := fPropRow.Name;
TextLeft := BorderWidth + GetTreeIconX(Index) + Indent + 5; TextLeft := BorderWidth + GetTreeIconX(Index) + Indent + 5;
if (Canvas.TextWidth(TheHint) + TextLeft) >= SplitterX-2 then if (Canvas.TextWidth(TheHint) + TextLeft) >= SplitterX-2 then
DoShow(Point(TextLeft - 3, fPropRow.Top-TopY-1)); ShowShortHint(Point(TextLeft-3, fPropRow.Top-TopY-1));
end else end else
if HintType in [pehValue,pehEditButton] then if HintType in [pehValue,pehEditButton] then
begin // Mouse is over property value... begin // Mouse is over property value...
@ -2470,15 +2476,14 @@ begin
TheHint := copy(TheHint, 1, 100) + '...'; TheHint := copy(TheHint, 1, 100) + '...';
TextLeft := SplitterX+2; TextLeft := SplitterX+2;
if Canvas.TextWidth(TheHint) > (ClientWidth - BorderWidth - TextLeft) then if Canvas.TextWidth(TheHint) > (ClientWidth - BorderWidth - TextLeft) then
DoShow(Point(TextLeft - 3, fPropRow.Top-TopY-1)); ShowShortHint(Point(TextLeft-3, fPropRow.Top-TopY-1));
end; end;
end; end;
if ShowHint then // Initialize timer for a long hint describing the property and value.
begin // Initialize timer for a long hint describing the property and value. if not ShowHint then Exit;
if FLongHintTimer = nil then if FLongHintTimer = nil then
begin begin
FHintIndex := -1; FHintIndex := -1;
Assert(not FShowingLongHint, 'TOICustomPropertyGrid.MouseMove: ShowingLongHint!');
FLongHintTimer := TTimer.Create(nil); FLongHintTimer := TTimer.Create(nil);
FLongHintTimer.Interval := 500; FLongHintTimer.Interval := 500;
FLongHintTimer.Enabled := False; FLongHintTimer.Enabled := False;
@ -2488,9 +2493,7 @@ begin
FHintManager.HideInterval := 4000; FHintManager.HideInterval := 4000;
FHintManager.AutoHide := True; FHintManager.AutoHide := True;
end; end;
if not FShowingLongHint then
FLongHintTimer.Enabled := RowCount > 0; FLongHintTimer.Enabled := RowCount > 0;
end;
end; // not FDragging end; // not FDragging
end; end;