IdeIntf: objectinspector: fix Hint flickering

git-svn-id: trunk@53366 -
This commit is contained in:
ondrej 2016-11-15 08:17:52 +00:00
parent 7ad916287c
commit c49f1ff869

View File

@ -312,9 +312,10 @@ type
FPropNameFilter : String; FPropNameFilter : String;
// hint stuff // hint stuff
FHintTimer: TTimer; FLongHintTimer: TTimer;
FHintManager: THintWindowManager; FHintManager: THintWindowManager;
FHintIndex: integer; FHintIndex: integer;
FHintType: TPropEditHint;
FShowingLongHint: boolean; // last hint was activated by the hinttimer FShowingLongHint: boolean; // last hint was activated by the hinttimer
ValueEdit: TEdit; ValueEdit: TEdit;
@ -326,10 +327,10 @@ type
{$ENDIF} {$ENDIF}
ValueButton: TSpeedButton; ValueButton: TSpeedButton;
procedure HintMouseLeave(Sender: TObject);
procedure HintTimer(Sender: TObject); procedure HintTimer(Sender: TObject);
procedure ResetHintTimer; procedure ResetLongHintTimer;
procedure HideHint; procedure HideHint;
procedure OnUserInput(Sender: TObject; {%H-}Msg: Cardinal);
procedure HintMouseDown(Sender: TObject; Button: TMouseButton; procedure HintMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
@ -435,6 +436,7 @@ type
procedure MouseDown(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override; procedure MouseDown(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override;
procedure MouseMove(Shift:TShiftState; X,Y:integer); override; procedure MouseMove(Shift:TShiftState; X,Y:integer); override;
procedure MouseUp(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override; procedure MouseUp(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override;
procedure MouseLeave; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure HandleStandardKeys(var Key: Word; Shift: TShiftState); virtual; procedure HandleStandardKeys(var Key: Word; Shift: TShiftState); virtual;
@ -1115,7 +1117,6 @@ begin
FDefaultItemHeight:=DefItemHeight; FDefaultItemHeight:=DefItemHeight;
BuildPropertyList; BuildPropertyList;
Application.AddOnUserInputHandler(@OnUserInput,true);
end; end;
constructor TOICustomPropertyGrid.Create(TheOwner: TComponent); constructor TOICustomPropertyGrid.Create(TheOwner: TComponent);
@ -1128,7 +1129,6 @@ var
a: integer; a: integer;
begin begin
SetIdleEvent(false); SetIdleEvent(false);
Application.RemoveOnUserInputHandler(@OnUserInput);
FItemIndex := -1; FItemIndex := -1;
for a := 0 to FRows.Count - 1 do for a := 0 to FRows.Count - 1 do
Rows[a].Free; Rows[a].Free;
@ -1140,7 +1140,7 @@ begin
FreeAndNil(FNameFont); FreeAndNil(FNameFont);
FreeAndNil(FHighlightFont); FreeAndNil(FHighlightFont);
FreeAndNil(FExpandedProperties); FreeAndNil(FExpandedProperties);
FreeAndNil(FHintTimer); FreeAndNil(FLongHintTimer);
FreeAndNil(FHintManager); FreeAndNil(FHintManager);
FreeAndNil(FNewComboBoxItems); FreeAndNil(FNewComboBoxItems);
FreeAndNil(FActiveRowBmp); FreeAndNil(FActiveRowBmp);
@ -1152,14 +1152,14 @@ begin
if not ShowHint then exit(false); if not ShowHint then exit(false);
Result := true; Result := true;
if FHintTimer = nil then if FLongHintTimer = nil then
begin begin
FHintIndex := -1; FHintIndex := -1;
FShowingLongHint := False; FShowingLongHint := False;
FHintTimer := TTimer.Create(nil); FLongHintTimer := TTimer.Create(nil);
FHintTimer.Interval := 500; FLongHintTimer.Interval := 500;
FHintTimer.Enabled := False; FLongHintTimer.Enabled := False;
FHintTimer.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';
@ -2180,7 +2180,8 @@ begin
Result:=true; Result:=true;
end; end;
function TOICustomPropertyGrid.MouseToIndex(y:integer;MustExist:boolean):integer; function TOICustomPropertyGrid.MouseToIndex(Y: integer; MustExist: boolean
): integer;
var l,r,m:integer; var l,r,m:integer;
begin begin
l:=0; l:=0;
@ -2344,6 +2345,16 @@ begin
end; end;
end; end;
procedure TOICustomPropertyGrid.MouseLeave;
begin
if Assigned(FHintManager) and Assigned(FHintManager.CurHintWindow)
and FHintManager.CurHintWindow.Visible
and not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos)) then
FHintManager.HideHint;
inherited MouseLeave;
end;
procedure TOICustomPropertyGrid.MouseMove(Shift:TShiftState; X,Y:integer); procedure TOICustomPropertyGrid.MouseMove(Shift:TShiftState; X,Y:integer);
var var
TheHint: String; TheHint: String;
@ -2351,16 +2362,20 @@ var
procedure DoShow(pt: TPoint); inline; procedure DoShow(pt: TPoint); inline;
begin begin
FHintManager.ShowHint(ClientToScreen(pt), TheHint); FHintManager.ShowHint(ClientToScreen(pt), TheHint);
if FHintManager.CurHintWindow<>nil then
FHintManager.CurHintWindow.OnMouseLeave := @HintMouseLeave;
end; end;
var var
SplitDistance:integer; SplitDistance:integer;
Index, Brd: Integer; Index, Brd: Integer;
fPropRow: TOIPropertyGridRow; fPropRow: TOIPropertyGridRow;
HintType: TPropEditHint;
begin begin
inherited MouseMove(Shift,X,Y); inherited MouseMove(Shift,X,Y);
SplitDistance:=X-SplitterX; SplitDistance:=X-SplitterX;
if FDragging then begin if FDragging then begin
HideHint;
if ssLeft in Shift then begin if ssLeft in Shift then begin
SplitterX:=SplitterX+SplitDistance; SplitterX:=SplitterX+SplitDistance;
end else begin end else begin
@ -2384,19 +2399,27 @@ begin
// to check if the property text fits in its box, if not show a hint // to check if the property text fits in its box, if not show a hint
if not (ShowHint and InitHints) then Exit; if not (ShowHint and InitHints) then Exit;
Index := MouseToIndex(y,false); Index := MouseToIndex(y,false);
HintType := GetHintTypeAt(Index, x);
if (Index<>FHintIndex) or (HintType<>FHintType) then
HideHint;
ResetLongHintTimer;
if (Index = -1) or FShowingLongHint if (Index = -1) or FShowingLongHint
or ( FHintManager.HintIsVisible and (Index = FHintIndex) ) then Exit; or ( FHintManager.HintIsVisible and (Index = FHintIndex) and (HintType=FHintType) ) then
Exit;
FHintIndex:=Index; FHintIndex:=Index;
FHintType := HintType;
fPropRow := GetRow(Index); fPropRow := GetRow(Index);
if X < SplitterX then if HintType = pehName then
begin begin
// Mouse is over property name... // Mouse is over property name...
TheHint := fPropRow.Name; TheHint := fPropRow.Name;
Brd := BorderWidth + GetTreeIconX(Index) + Indent; Brd := BorderWidth + GetTreeIconX(Index) + Indent;
if (Canvas.TextWidth(TheHint) + Brd) >= SplitterX then if (Canvas.TextWidth(TheHint) + Brd) >= SplitterX then
DoShow(Point(Brd, fPropRow.Top-TopY-1)); DoShow(Point(Brd, fPropRow.Top-TopY-1));
end end else
else begin if HintType in [pehValue,pehEditButton] then
begin
// Mouse is over property value... // Mouse is over property value...
TheHint := fPropRow.LastPaintedValue; TheHint := fPropRow.LastPaintedValue;
if length(TheHint) > 100 then if length(TheHint) > 100 then
@ -2598,11 +2621,6 @@ begin
FOnSelectionChange(Self); FOnSelectionChange(Self);
end; end;
procedure TOICustomPropertyGrid.OnUserInput(Sender: TObject; Msg: Cardinal);
begin
ResetHintTimer;
end;
procedure TOICustomPropertyGrid.HintMouseDown(Sender: TObject; procedure TOICustomPropertyGrid.HintMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var var
@ -2614,6 +2632,12 @@ begin
end; end;
end; end;
procedure TOICustomPropertyGrid.HintMouseLeave(Sender: TObject);
begin
if FindLCLControl(Mouse.CursorPos)<>Self then
FHintManager.HideHint;
end;
procedure TOICustomPropertyGrid.EndDragSplitter; procedure TOICustomPropertyGrid.EndDragSplitter;
begin begin
if FDragging then begin if FDragging then begin
@ -3432,8 +3456,8 @@ var
AHint: String; AHint: String;
OkToShow: Boolean; OkToShow: Boolean;
begin begin
if FHintTimer <> nil then if FLongHintTimer <> nil then
FHintTimer.Enabled := False; FLongHintTimer.Enabled := False;
if (not InitHints) then exit; if (not InitHints) then exit;
Position := Mouse.CursorPos; Position := Mouse.CursorPos;
@ -3462,17 +3486,17 @@ begin
// Show hint if all is well. // Show hint if all is well.
if OkToShow and FHintManager.ShowHint(Position, AHint) then begin if OkToShow and FHintManager.ShowHint(Position, AHint) then begin
FHintIndex := Index; FHintIndex := Index;
FHintType := HintType;
FShowingLongHint := True; FShowingLongHint := True;
end; end;
end; end;
procedure TOICustomPropertyGrid.ResetHintTimer; procedure TOICustomPropertyGrid.ResetLongHintTimer;
begin begin
HideHint; if FLongHintTimer = Nil then Exit;
if FHintTimer = Nil then Exit; FLongHintTimer.Enabled := False;
FHintTimer.Enabled := False;
if RowCount > 0 then if RowCount > 0 then
FHintTimer.Enabled := not FDragging; FLongHintTimer.Enabled := not FDragging;
end; end;
procedure TOICustomPropertyGrid.HideHint; procedure TOICustomPropertyGrid.HideHint;
@ -3519,8 +3543,8 @@ var
begin begin
if not CanEditRowValue(false) then exit; if not CanEditRowValue(false) then exit;
if FHintTimer <> nil then if FLongHintTimer <> nil then
FHintTimer.Enabled := False; FLongHintTimer.Enabled := False;
if (FCurrentEdit = ValueComboBox) then if (FCurrentEdit = ValueComboBox) then
begin begin