Recent

Author Topic: Possible TStringGrid issue  (Read 8360 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Possible TStringGrid issue
« on: March 31, 2011, 12:27:42 am »
Maybe this is TStringGrid incompatibility cross platforms (working with OnDrawCell event).

Try attached project. You should see text in cell.

Does not work at Linux + Qt 4.7.1, Laz. 0.9.31 + fpc 2.5.1
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Possible TStringGrid issue
« Reply #1 on: March 31, 2011, 02:19:44 am »
After further analysis I maybe found patch.

Adding one line to grids.pas (line 8842) brings back previous functionality.
Code: [Select]
procedure TCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
  aState:TGridDrawState);
var
  OldDefaultDrawing: boolean;
begin
  if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin
    PrepareCanvas(aCol, aRow, aState);
    if DefaultDrawing then
      DefaultDrawCell(aCol, aRow, aRect, aState);
    OnDrawCell(Self,aCol,aRow,aRect,aState);
    DrawTextInCell(aCol,aRow,aRect,aState); //added
  end else begin ....  


(See another thread and screenshot from fredvs: http://www.lazarus.freepascal.org/index.php/topic,12589.msg65163/topicseen.html#new)

Now text in StringGrid is visible again when OnDrawCell event is assigned.

Seems work on both Qt and GTK2.

I'll post bugreport but tommorow, it's too late now.
« Last Edit: March 31, 2011, 02:24:52 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Possible TStringGrid issue
« Reply #2 on: March 31, 2011, 01:12:52 pm »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Fred vS

  • Hero Member
  • *****
  • Posts: 3952
    • StrumPract is the musicians best friend
Re: Possible TStringGrid issue
« Reply #3 on: March 31, 2011, 02:30:15 pm »
Hello Mr Blaazen.

Quote
DrawTextInCell(aCol,aRow,aRect,aState); //added

Nice ! I will try it....

Thanks
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3952
    • StrumPract is the musicians best friend
Re: Possible TStringGrid issue
« Reply #4 on: November 09, 2012, 05:59:58 pm »
Hello amigos.
Since last post of Mr Blaazen, this bug is still in Lazarus, even in version 1 RC 2  :-[

Then it should be a good idea to add this in your /lcl/grids.pas code :

Quote
DrawTextInCell(aCol,aRow,aRect,aState) //added

Just like Mr Blaazen show us in earlier topics...

I have added also a variable, custgrid, so i can choose to redraw text or not...

first add this after procedure Register;

Code: [Select]
var

custgrid : shortint ;

and add this in procedure TCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
  aState:TGridDrawState);

Code: [Select]
procedure TCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
  aState:TGridDrawState);
var
  OldDefaultDrawing: boolean;
begin
  if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin
    PrepareCanvas(aCol, aRow, aState);
    if DefaultDrawing then
      DefaultDrawCell(aCol, aRow, aRect, aState);
    OnDrawCell(Self,aCol,aRow,aRect,aState);
if custgrid = 1 then DrawTextInCell(aCol,aRow,aRect,aState) //added
    end else begin
    OldDefaultDrawing:=FDefaultDrawing;
    FDefaultDrawing:=True;
    try
      PrepareCanvas(aCol, aRow, aState);
    finally
      FDefaultDrawing:=OldDefaultDrawing;
    end;
    DefaultDrawCell(aCol,aRow,aRect,aState);
  end;
  DrawCellGrid(aCol,aRow,aRect,aState);
end;

Then re-compile Lazarus.

And i hope that one day it gonna be fix so we do not need to change the source and recompile Lazarus...

« Last Edit: November 09, 2012, 06:07:15 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

jujibo

  • Full Member
  • ***
  • Posts: 118
Re: Possible TStringGrid issue
« Reply #5 on: November 09, 2012, 06:26:53 pm »
You can take a look at bugreport:

http://bugs.freepascal.org/view.php?id=19043

Status says closed. Read added notes.

Fred vS

  • Hero Member
  • *****
  • Posts: 3952
    • StrumPract is the musicians best friend
Re: Possible TStringGrid issue
« Reply #6 on: November 09, 2012, 08:05:53 pm »
Quote
Status says closed. Read added notes.

The status is closed, maybe, but the bug remains.
I have read that added notes long time ago, but without the patch, i cannot draw my cell and write text on in, even on brand new Lazarus versions...
« Last Edit: November 09, 2012, 08:08:15 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Possible TStringGrid issue
« Reply #7 on: November 14, 2012, 11:06:29 pm »
Previously, it worked as described, but later it was changed to the current behavior, the reason is for example when you draw a icon left aligned in the cell, if you do not draw also the text next to the icon, the automatic draw text would overwrite the icon. 

In this case is the whole cell background that is being painted and the text alignment set in OnPrepareCanvas may be right, but we don't have a way to tell the grid.

If somebody can envision a property, option, etc. So the grid can be instructed to always draw the text even on custom OnDrawCell, please submit a bug report with a feature resquest, if it includes an implementation patch, much better :)

 

TinyPortal © 2005-2018