Hi

Attached is a patch for the TCustomGrid.GridLineWidth property. Please
review before applying this patch.

This is not a full implementation but rather a quick cosmetic
implementation.  The difference is that this patch changes the grid
line width for painting only, but not the actual offset or regions of
the cells due to the change in Grid Line Width.  Fixed columns don't
draw the grid lines thicker than 1 (not sure if this is correct
behaviour).

At least with this patch you are now able to hide the grid lines
(GridLineWidth = 0) when required. This is the main feature I was
missing to get my custom component to work.

In the Delphi implementation, the cell size will stay the same even
though the grid line width increases.  Delphi does cause a very
strange effect (I think it's a bug) when the GridLineWidth is set to a
negative values.  I don't think Lazarus needs to copy that behaviour
so the lowest value the GridLineWidth will go is 0 in the LCL.



--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 10957)
+++ lcl/grids.pas	(working copy)
@@ -2694,6 +2694,7 @@
     {$endif}
     with R, Canvas do begin
       Pen.Color := fBorderColor;
+      Pen.Width := 1;
       MoveTo(0,0);
       LineTo(0,Bottom);
       LineTo(Right, Bottom);
@@ -2936,44 +2937,64 @@
 begin
   // Draw Cell Grid or Maybe in the future Borders..
   with Canvas, aRect do begin
-    if (gdFixed in aState) then begin
+    if (gdFixed in aState) then
+    begin
       Dv := goFixedVertLine in Options;
       Dh := goFixedHorzLine in Options;
       Pen.Style := psSolid;
-      if not FFlat then begin
-        if FTitleStyle=tsNative then begin
+      if FGridLineWidth > 0 then
+        Pen.Width := 1
+      else
+        Pen.Width := 0;
+      if not FFlat then
+      begin
+        if FTitleStyle=tsNative then
+        begin
           aR := aRect;
           DrawFrameControl(Handle, ar, DFC_BUTTON, DFCS_BUTTONPUSH);
           exit;
-        end else begin
-          Pen.Color := cl3DHilight;
-          MoveTo(Right - 1, Top);
-          LineTo(Left, Top);
-          LineTo(Left, Bottom);
-          if FTitleStyle=tsStandard then begin
-            // more contrast
-            Pen.Color := cl3DShadow;
-            MoveTo(Left+1, Bottom-2);
-            LineTo(Right-2, Bottom-2);
-            LineTo(Right-2, Top);
+        end
+        else
+        begin
+          if FGridLineWidth > 0 then
+          begin
+            Pen.Color := cl3DHilight;
+            MoveTo(Right - 1, Top);
+            LineTo(Left, Top);
+            LineTo(Left, Bottom);
+            if FTitleStyle=tsStandard then
+            begin
+              // more contrast
+              Pen.Color := cl3DShadow;
+              MoveTo(Left+1, Bottom-2);
+              LineTo(Right-2, Bottom-2);
+              LineTo(Right-2, Top);
+            end;
           end;
         end;
       end;
       Pen.Color := cl3DDKShadow;
-    end else begin
+    end
+    else
+    begin
       Dv := goVertLine in Options;
       Dh := goHorzLine in Options;
       Pen.Style := fGridLineStyle;
       Pen.Color := fGridLineColor;
+      Pen.Width := fGridLineWidth;
     end;
-    if Dh then begin
-      MoveTo(Left, Bottom - 1);
-      LineTo(Right, Bottom - 1);
+    
+    if fGridLineWidth > 0 then
+    begin
+      if Dh then begin
+        MoveTo(Left, Bottom - 1);
+        LineTo(Right, Bottom - 1);
+      end;
+      if Dv then begin
+         MoveTo(Right - 1, Top);
+         LineTo(Right - 1, Bottom);
+      end;
     end;
-    if Dv then begin
-       MoveTo(Right - 1, Top);
-       LineTo(Right - 1, Bottom);
-    end;
   end;
 end;
 
@@ -3284,9 +3305,9 @@
 
 procedure TCustomGrid.SetGridLineWidth(const AValue: Integer);
 begin
-  // Todo
-  if FGridLineWidth=AValue then exit;
-  FGridLineWidth:=AValue;
+  if FGridLineWidth = AValue then
+    exit;
+  FGridLineWidth := AValue;
   Invalidate;
 end;
 
@@ -6120,10 +6141,11 @@
      goSmoothScroll ];
   FScrollbars:=ssAutoBoth;
   fGridState:=gsNormal;
-  fDefColWidth:=DEFCOLWIDTH;
-  fDefRowHeight:=DEFROWHEIGHT;
-  fGridLineColor:=clSilver;
+  FDefColWidth:=DEFCOLWIDTH;
+  FDefRowHeight:=DEFROWHEIGHT;
+  FGridLineColor:=clSilver;
   FGridLineStyle:=psSolid;
+  FGridLineWidth := 1;
   fFocusColor:=clRed;
   FFixedColor:=clBtnFace;
   FSelectedColor:= clHighlight;

Reply via email to