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,9 +2423,10 @@ 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;
if FDragging then if FDragging then
begin begin
HideHint; HideHint;
@ -2435,24 +2436,29 @@ 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;
if ssLeft in Shift then if ssLeft in Shift then
begin begin
Index := MouseToIndex(Y, False); Index := MouseToIndex(Y, False);
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,31 +2476,28 @@ 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; FLongHintTimer.OnTimer := @HintTimer;
FLongHintTimer.OnTimer := @HintTimer; FHintManager.OnMouseDown := @HintMouseDown;
FHintManager.OnMouseDown := @HintMouseDown; FHintManager.WindowName := 'This_is_a_hint_window';
FHintManager.WindowName := 'This_is_a_hint_window'; FHintManager.HideInterval := 4000;
FHintManager.HideInterval := 4000; FHintManager.AutoHide := True;
FHintManager.AutoHide := True;
end;
if not FShowingLongHint then
FLongHintTimer.Enabled := RowCount > 0;
end; end;
FLongHintTimer.Enabled := RowCount > 0;
end; // not FDragging end; // not FDragging
end; end;
procedure TOICustomPropertyGrid.MouseUp(Button:TMouseButton; Shift:TShiftState; procedure TOICustomPropertyGrid.MouseUp(Button:TMouseButton; Shift:TShiftState;
X,Y:integer); X,Y:integer);
begin begin
if FDragging then EndDragSplitter; if FDragging then EndDragSplitter;