View Issue Details

IDProjectCategoryView StatusLast Update
0035453LazarusLCLpublic2019-05-09 06:26
ReporterJoeny AngAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSArch LinuxOS Version
Product Version2.0.2Product Build 
Target VersionFixed in Version2.1 (SVN) 
Summary0035453: [Patch] Grids Hints are inconsistent
DescriptionThe attached patch tries to fix the following issues:

For TCustomGrid and its descendants:

ShowHint = False
  1. goCellHints, OnGetCellHint(): Application.Hint should be empty.
  2. goTruncCellHints: Application.Hint should be empty.

ShowHint = True
  1. chpAllNoDefault/chpTruncOnly: default hint should not be displayed.
  2. chpAll, goCellHints: stacked hints are inconsistent, depending on the Hint
     returned by OnGetCellHint().
     - if a "|" is present, default long hint is omitted.
     - if without "|", the default short hint is appended to the long hint.
  3. chpAll, goTruncCellHints: default short hint should not be appended to
     the long hint.
  4. chpAllNoDefault, goCellHints, goTruncCellHints: the truncated cell text
     hints should not be appended to the long hint.
  5. chpAll: when mouse is moved from a cell with hint to an area without a
     cell, the hint should revert to the default hint.
  6. Truncated cell text hints should only be passed to OnGetCellHint() when
     CellHintPriority = chpTruncOnly, to prevent duplicate calls to
     OnGetCellHint().

Tested on GTK2 and Win32.
TagsNo tags attached.
Fixed in Revision61184
LazTarget2.0.4
WidgetsetGTK 2, Win32/Win64
Attached Files
  • grids-hints-fix.patch (4,546 bytes)
    --- lcl/dbgrids.pas
    +++ lcl/dbgrids.pas
    @@ -1665,7 +1665,8 @@
           Result := F.DisplayText
         else
           Result := '(blob)';
    -  if Assigned(OnGetCellHint) then begin
    +  // pass to OnGetCellHint() only if chpTruncOnly
    +  if Assigned(OnGetCellHint) and (CellHintPriority = chpTruncOnly) then begin
         C := ColumnFromGridColumn(ACol) as TColumn;
         FOnGetCellHint(self, C, Result);
       end;
    --- lcl/grids.pas
    +++ lcl/grids.pas
    @@ -3931,16 +3931,12 @@
       end;
     
     begin
    -  if ([goCellHints, goTruncCellHints]*Options = []) then
    +  if not ShowHint then
         exit;
     
       cell := MouseToCell(APoint);
       if (cell.x = -1) or (cell.y = -1) then
    -  begin
    -    Hint := FSavedHint;
    -    Application.Hint := GetLongHint(FSavedHint);
         exit;
    -  end;
     
       txt1 := '';          // Hint returned by OnGetCellHint
       txt2 := '';          // Hint returned by GetTruncCellHintText
    @@ -3948,7 +3944,7 @@
       txt := '';           // Hint to be displayed as popup
       PrepareCellHints(cell.x, cell.y); // in DBGrid, set the active record to cell.y
       try
    -    if (goCellHints in Options) then
    +    if (goCellHints in Options) and (FCellHintPriority <> chpTruncOnly) then
           txt1 := GetCellHintText(cell.x, cell.y);
         if (goTruncCellHints in Options) then begin
           txt2 := GetTruncCellHintText(cell.x, cell.y);
    @@ -3965,31 +3961,24 @@
       case FCellHintPriority of
         chpAll:
           begin
    -        AddToHint(txt, txt1);
    +        AddToHint(txt, GetShortHint(FSavedHint));
    +        AddToHint(txt, GetShortHint(txt1));
             AddToHint(txt, txt2);
    -        if (txt <> '') then begin
    -          if FSavedHint = '' then
    -            AppHint := txt
    -          else begin
    -            txt := GetShortHint(FSavedHint) + LineEnding + txt;
    -            AppHint := GetLongHint(FSavedHint) + LineEnding + txt;
    -          end;
    -        end else
    -        begin
    -          txt := GetShortHint(FSavedHint);
    -          AppHint := GetLongHint(FSavedHint);
    -        end;
    +        AddToHint(AppHint, GetLongHint(FSavedHint));
    +        AddToHint(AppHint, GetLongHint(txt1));
           end;
         chpAllNoDefault:
           begin
    -        AddToHint(txt, txt1);
    +        AddToHint(txt, GetShortHint(txt1));
             AddToHint(txt, txt2);
    -        AppHint := txt;
    +        AddToHint(AppHint, GetLongHint(txt1));
           end;
         chpTruncOnly:
           begin
             AddToHint(txt, txt2);
             AppHint := txt;
    +        if Pos('|', AppHint) = 0 then
    +          AppHint := AppHint + '|';
           end;
       end;
     
    @@ -3999,7 +3988,7 @@
       if (AppHint = '') then AppHint := FSavedhint;
         *)
     
    -  if (txt <> '') and not EditorMode and not (csDesigning in ComponentState) then begin
    +  if not EditorMode and not (csDesigning in ComponentState) then begin
         Hint := txt;
         //set Application.Hint as well (issue #0026957)
         Application.Hint := GetLongHint(AppHint);
    @@ -6728,13 +6717,19 @@
               AllowOutboundEvents := obe;
             end;
     
    -        //if we are not over a cell, and we use cellhint, we need to empty Application.Hint
    -        if (p.X < 0) and ([goCellHints, goTruncCellHints]*Options <> []) and
    -          (FCellHintPriority <> chpAll)
    -        then begin
    -          Application.Hint := '';
    -          Hint := '';
    -        end;
    +        // if we are not over a cell
    +        if p.X < 0 then
    +          begin
    +            // empty hints
    +            Application.Hint := '';
    +            Hint := '';
    +            // if FCellHintPriority = chpAll, restore default hint
    +            if ShowHint and (FCellHintPriority = chpAll) then
    +              begin
    +                Hint := FSavedHint;
    +                Application.Hint := GetLongHint(FSavedHint);
    +              end;
    +          end;
     
             with FGCache do
               if (MouseCell.X <> p.X) or (MouseCell.Y <> p.Y) then begin
    @@ -8041,12 +8036,14 @@
     begin
       inherited;
       FSavedHint := Hint;
    +  // Note: disable hint when entering grid's border, we'll manage our own hints
    +  Application.Hint := '';
    +  Application.CancelHint;
     end;
     
     procedure TCustomGrid.CMMouseLeave(var Message: TLMessage);
     begin
    -  if [goCellHints, goTruncCellHints] * Options <> [] then
    -    Hint := FSavedHint;
    +  Hint := FSavedHint;
       ResetHotCell;
       inherited CMMouseLeave(Message);
     end;
    @@ -8524,6 +8521,8 @@
     function TCustomGrid.GetTruncCellHintText(ACol, ARow: Integer): string;
     begin
       Result := GetCells(ACol, ARow);
    +  if Assigned(FOnGetCellHint) and (FCellHintPriority = chpTruncOnly) then
    +    FOnGetCellHint(self, ACol, ARow, result);
     end;
     
     function TCustomGrid.GetCells(ACol, ARow: Integer): string;
    
    
    grids-hints-fix.patch (4,546 bytes)
  • grids-hints-fix-v1.zip (131,001 bytes)

Activities

Joeny Ang

2019-04-27 07:51

reporter  

grids-hints-fix.patch (4,546 bytes)
--- lcl/dbgrids.pas
+++ lcl/dbgrids.pas
@@ -1665,7 +1665,8 @@
       Result := F.DisplayText
     else
       Result := '(blob)';
-  if Assigned(OnGetCellHint) then begin
+  // pass to OnGetCellHint() only if chpTruncOnly
+  if Assigned(OnGetCellHint) and (CellHintPriority = chpTruncOnly) then begin
     C := ColumnFromGridColumn(ACol) as TColumn;
     FOnGetCellHint(self, C, Result);
   end;
--- lcl/grids.pas
+++ lcl/grids.pas
@@ -3931,16 +3931,12 @@
   end;
 
 begin
-  if ([goCellHints, goTruncCellHints]*Options = []) then
+  if not ShowHint then
     exit;
 
   cell := MouseToCell(APoint);
   if (cell.x = -1) or (cell.y = -1) then
-  begin
-    Hint := FSavedHint;
-    Application.Hint := GetLongHint(FSavedHint);
     exit;
-  end;
 
   txt1 := '';          // Hint returned by OnGetCellHint
   txt2 := '';          // Hint returned by GetTruncCellHintText
@@ -3948,7 +3944,7 @@
   txt := '';           // Hint to be displayed as popup
   PrepareCellHints(cell.x, cell.y); // in DBGrid, set the active record to cell.y
   try
-    if (goCellHints in Options) then
+    if (goCellHints in Options) and (FCellHintPriority <> chpTruncOnly) then
       txt1 := GetCellHintText(cell.x, cell.y);
     if (goTruncCellHints in Options) then begin
       txt2 := GetTruncCellHintText(cell.x, cell.y);
@@ -3965,31 +3961,24 @@
   case FCellHintPriority of
     chpAll:
       begin
-        AddToHint(txt, txt1);
+        AddToHint(txt, GetShortHint(FSavedHint));
+        AddToHint(txt, GetShortHint(txt1));
         AddToHint(txt, txt2);
-        if (txt <> '') then begin
-          if FSavedHint = '' then
-            AppHint := txt
-          else begin
-            txt := GetShortHint(FSavedHint) + LineEnding + txt;
-            AppHint := GetLongHint(FSavedHint) + LineEnding + txt;
-          end;
-        end else
-        begin
-          txt := GetShortHint(FSavedHint);
-          AppHint := GetLongHint(FSavedHint);
-        end;
+        AddToHint(AppHint, GetLongHint(FSavedHint));
+        AddToHint(AppHint, GetLongHint(txt1));
       end;
     chpAllNoDefault:
       begin
-        AddToHint(txt, txt1);
+        AddToHint(txt, GetShortHint(txt1));
         AddToHint(txt, txt2);
-        AppHint := txt;
+        AddToHint(AppHint, GetLongHint(txt1));
       end;
     chpTruncOnly:
       begin
         AddToHint(txt, txt2);
         AppHint := txt;
+        if Pos('|', AppHint) = 0 then
+          AppHint := AppHint + '|';
       end;
   end;
 
@@ -3999,7 +3988,7 @@
   if (AppHint = '') then AppHint := FSavedhint;
     *)
 
-  if (txt <> '') and not EditorMode and not (csDesigning in ComponentState) then begin
+  if not EditorMode and not (csDesigning in ComponentState) then begin
     Hint := txt;
     //set Application.Hint as well (issue #0026957)
     Application.Hint := GetLongHint(AppHint);
@@ -6728,13 +6717,19 @@
           AllowOutboundEvents := obe;
         end;
 
-        //if we are not over a cell, and we use cellhint, we need to empty Application.Hint
-        if (p.X < 0) and ([goCellHints, goTruncCellHints]*Options <> []) and
-          (FCellHintPriority <> chpAll)
-        then begin
-          Application.Hint := '';
-          Hint := '';
-        end;
+        // if we are not over a cell
+        if p.X < 0 then
+          begin
+            // empty hints
+            Application.Hint := '';
+            Hint := '';
+            // if FCellHintPriority = chpAll, restore default hint
+            if ShowHint and (FCellHintPriority = chpAll) then
+              begin
+                Hint := FSavedHint;
+                Application.Hint := GetLongHint(FSavedHint);
+              end;
+          end;
 
         with FGCache do
           if (MouseCell.X <> p.X) or (MouseCell.Y <> p.Y) then begin
@@ -8041,12 +8036,14 @@
 begin
   inherited;
   FSavedHint := Hint;
+  // Note: disable hint when entering grid's border, we'll manage our own hints
+  Application.Hint := '';
+  Application.CancelHint;
 end;
 
 procedure TCustomGrid.CMMouseLeave(var Message: TLMessage);
 begin
-  if [goCellHints, goTruncCellHints] * Options <> [] then
-    Hint := FSavedHint;
+  Hint := FSavedHint;
   ResetHotCell;
   inherited CMMouseLeave(Message);
 end;
@@ -8524,6 +8521,8 @@
 function TCustomGrid.GetTruncCellHintText(ACol, ARow: Integer): string;
 begin
   Result := GetCells(ACol, ARow);
+  if Assigned(FOnGetCellHint) and (FCellHintPriority = chpTruncOnly) then
+    FOnGetCellHint(self, ACol, ARow, result);
 end;
 
 function TCustomGrid.GetCells(ACol, ARow: Integer): string;

grids-hints-fix.patch (4,546 bytes)

Jesus Reyes

2019-05-03 03:09

developer   ~0115968

Can you please attach a sample that shows the problem and that your patch fixes? thanks.

Joeny Ang

2019-05-06 05:26

reporter   ~0116036

Hi, attached a sample project. Thanks.

grids-hints-fix-v1.zip (131,001 bytes)

Jesus Reyes

2019-05-09 06:26

developer   ~0116096

Applied, thanks.

Issue History

Date Modified Username Field Change
2019-04-27 07:51 Joeny Ang New Issue
2019-04-27 07:51 Joeny Ang File Added: grids-hints-fix.patch
2019-05-03 03:07 Jesus Reyes Assigned To => Jesus Reyes
2019-05-03 03:07 Jesus Reyes Status new => assigned
2019-05-03 03:09 Jesus Reyes Note Added: 0115968
2019-05-03 03:09 Jesus Reyes Status assigned => feedback
2019-05-03 03:09 Jesus Reyes LazTarget => -
2019-05-06 05:26 Joeny Ang File Added: grids-hints-fix-v1.zip
2019-05-06 05:26 Joeny Ang Note Added: 0116036
2019-05-06 05:26 Joeny Ang Status feedback => assigned
2019-05-09 06:26 Jesus Reyes Status assigned => resolved
2019-05-09 06:26 Jesus Reyes Resolution open => fixed
2019-05-09 06:26 Jesus Reyes Fixed in Version => 2.1 (SVN)
2019-05-09 06:26 Jesus Reyes Fixed in Revision => 61184
2019-05-09 06:26 Jesus Reyes LazTarget - => 2.0.4
2019-05-09 06:26 Jesus Reyes Widgetset GTK 2, Win32/Win64 => GTK 2, Win32/Win64
2019-05-09 06:26 Jesus Reyes Note Added: 0116096