View Issue Details

IDProjectCategoryView StatusLast Update
0021877LazarusLCLpublic2018-09-15 23:59
ReporterHexNihiloAssigned ToJuha Manninen 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version0.9.31 (SVN)Product Build 
Target VersionFixed in Version 
Summary0021877: TStaticText : bad Width with Autosize := True;
DescriptionHello

Simply code :

procedure TForm1.FormCreate(Sender: TObject);
{uses StdCtrls}
var
 i : Integer;
begin
 sTmp := 'Test';
 for i := 0 to 99 do sTmp := sTmp + LineEnding +
                            'Line '+ IntToStr(i) + 'gfhg jhgf jhghg';

 aStaticText := TStaticText.Create(nil);
 with aStaticText do begin
  Parent := Form1;
  AutoSize := False;
  Visible := False;
 end;

 bStaticText := TStaticText.Create(nil);
 with bStaticText do begin
  Parent := Form1;
  AutoSize := False;
  Visible := False;
  Width := 5000; {or other > Real width. Why ???}
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 aW, bW : Integer;
begin
 with aStaticText do begin
  BeginUpdateBounds;
  Caption := sTmp;
  Visible := True;
  AutoSize := True;
  aW := Width;
  Visible := False;
  EndUpdateBounds;
 end;
 with bStaticText do begin
  BeginUpdateBounds;
  Caption := sTmp;
  Visible := True;
  AutoSize := True;
  bW := Width;
  Visible := False;
  EndUpdateBounds;
 end;
 Showmessage(IntToStr(aW) +'-' +IntToStr(bW));
end;

Result : 69-149 (149 is correct). It seem's that 69 is a default value.
You need to declare Autosize := False and a "big" width... and Autosize := True.

I suppose that it is a bug.
Regards
Additional InformationUbuntu 10.04 LTS - lazarus_0.9.31.35363-0_amd64 - fpc_2.6.1-120214_amd64
TagsNo tags attached.
Fixed in Revisionr59018
LazTarget-
WidgetsetGTK 2
Attached Files
  • BugTstaticText.zip (2,576 bytes)
  • BugTStaticTextWin.zip (2,242 bytes)
  • Capture-Form1.png (28,988 bytes)
    Capture-Form1.png (28,988 bytes)
  • BugTStaticTextNux.zip (2,517 bytes)
  • issue-21877.diff (1,058 bytes)
    Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(revision 59010)
    +++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(working copy)
    @@ -2938,8 +2938,6 @@
     var
       FrameWidget: PGtkFrame;
       LblWidget: PGtkLabel;
    -  DC: HDC;
    -  ALabel: PChar;
     begin
       if not WSCheckHandleAllocated(AWincontrol, 'SetText')
       then Exit;
    @@ -2948,15 +2946,9 @@
       LblWidget := GetLabelWidget(FrameWidget);
     
       if TStaticText(AWinControl).ShowAccelChar and (AText <> '') then
    +    Gtk2WidgetSet.SetLabelCaption(LblWidget, AText)
    +  else
       begin
    -    DC := Widgetset.GetDC(HWND({%H-}PtrUInt(LblWidget)));
    -    ALabel := TGtk2WidgetSet(WidgetSet).ForceLineBreaks(
    -                          DC, PChar(AText), TStaticText(AWinControl).Width, false);
    -    Widgetset.DeleteDC(DC);
    -    Gtk2WidgetSet.SetLabelCaption(LblWidget, ALabel);
    -    StrDispose(ALabel);
    -  end else
    -  begin
         gtk_label_set_text(LblWidget, PChar(AText));
         gtk_label_set_pattern(LblWidget, nil);
       end;
    
    issue-21877.diff (1,058 bytes)

Relationships

related to 0021697 closedZeljan Rikalo TStaticText behaves differently in GTK2 and Qt4 

Activities

2012-04-28 19:49

 

BugTstaticText.zip (2,576 bytes)

2012-04-28 21:03

 

BugTStaticTextWin.zip (2,242 bytes)

HexNihilo

2012-04-28 21:05

reporter   ~0059073

Problem also with Windows.
Please, look at the attachment.

Win7 - lazarus1.1-37043 fpc-2.6.1-20120427-win32

Vojtech Cihak

2012-04-28 21:17

reporter   ~0059074

Maybe it is related to 21697.

Mattias Gaertner

2012-04-28 21:20

manager   ~0059075

Last edited: 2012-04-28 21:23

Are you sure you want to use Begin/EndUpdateBounds?
Maybe you mean Disable/EnableAutoSizing?
The code is unusual. Can you explain in words what you want to achieve?

Zeljan Rikalo

2012-04-29 09:50

developer   ~0059088

Under gtk2 we use GtkLabel for TStaticText, and it have pretty unexpected behaviour in case of sizing.

2012-04-29 11:07

 

Capture-Form1.png (28,988 bytes)
Capture-Form1.png (28,988 bytes)

2012-04-29 11:09

 

BugTStaticTextNux.zip (2,517 bytes)

HexNihilo

2012-04-29 11:14

reporter   ~0059091

Last edited: 2012-04-29 15:25

Hello

@Mattias : Not usual as the met problem. Sorry for this bizarre code (It was the last not happy attempt to by-pass the problem). I join a simple project illustrating the problem with gtk2.

You put 2 TStaticTexts on your Form +

procedure TForm1.FormCreate(Sender: TObject);
var
  i : Integer;
  sTmp : String;
begin

 sTmp := '';
 for i := 0 to 9 do
  sTmp := sTmp +LineEnding +'Line ' +IntToStr(i) +' gfhg jhgf jhghg';

 StaticText1.AutoSize := True;
 StaticText2.Autosize := True;

 StaticText1.Caption := 'StaticText1'+sTmp;

 StaticText2.Width := 700; {!!!! Necessary to AutoSize }
 StaticText2.Caption := 'StaticText2'+sTmp;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 showmessage(IntToStr(StaticText1.Width) +'x' +IntToStr(StaticText1.Height) +'-'
            +IntToStr(StaticText2.Width) +'x' +IntToStr(StaticText2.Height));
end;

Result --> 63x 548-145x191

Look at attachments (Capture-Form1.png & BugTStaticTextNux.zip).

@Zeljan : No, I look for a component of which the line spacing is the same that of TMemo. TLabel has no same under gtk2. But TStaticText, yes. [http://forum.lazarus.freepascal.org/index.php/topic,16709.0.html]

Regards.

accorp

2018-09-15 23:30

reporter  

issue-21877.diff (1,058 bytes)
Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(revision 59010)
+++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(working copy)
@@ -2938,8 +2938,6 @@
 var
   FrameWidget: PGtkFrame;
   LblWidget: PGtkLabel;
-  DC: HDC;
-  ALabel: PChar;
 begin
   if not WSCheckHandleAllocated(AWincontrol, 'SetText')
   then Exit;
@@ -2948,15 +2946,9 @@
   LblWidget := GetLabelWidget(FrameWidget);
 
   if TStaticText(AWinControl).ShowAccelChar and (AText <> '') then
+    Gtk2WidgetSet.SetLabelCaption(LblWidget, AText)
+  else
   begin
-    DC := Widgetset.GetDC(HWND({%H-}PtrUInt(LblWidget)));
-    ALabel := TGtk2WidgetSet(WidgetSet).ForceLineBreaks(
-                          DC, PChar(AText), TStaticText(AWinControl).Width, false);
-    Widgetset.DeleteDC(DC);
-    Gtk2WidgetSet.SetLabelCaption(LblWidget, ALabel);
-    StrDispose(ALabel);
-  end else
-  begin
     gtk_label_set_text(LblWidget, PChar(AText));
     gtk_label_set_pattern(LblWidget, nil);
   end;
issue-21877.diff (1,058 bytes)

accorp

2018-09-15 23:31

reporter   ~0110775

A patch uploaded.

Juha Manninen

2018-09-15 23:59

developer   ~0110777

Applied, thanks. It also simplified the code.
You have a patch frenzy going on. Good! :)

Issue History

Date Modified Username Field Change
2012-04-28 19:49 HexNihilo New Issue
2012-04-28 19:49 HexNihilo File Added: BugTstaticText.zip
2012-04-28 19:49 HexNihilo Widgetset => GTK 2
2012-04-28 21:03 HexNihilo File Added: BugTStaticTextWin.zip
2012-04-28 21:05 HexNihilo Note Added: 0059073
2012-04-28 21:17 Vojtech Cihak Note Added: 0059074
2012-04-28 21:20 Mattias Gaertner Note Added: 0059075
2012-04-28 21:23 Mattias Gaertner Note Edited: 0059075
2012-04-29 09:49 Zeljan Rikalo Relationship added related to 0021697
2012-04-29 09:50 Zeljan Rikalo Note Added: 0059088
2012-04-29 11:07 HexNihilo File Added: Capture-Form1.png
2012-04-29 11:09 HexNihilo File Added: BugTStaticTextNux.zip
2012-04-29 11:14 HexNihilo Note Added: 0059091
2012-04-29 11:15 HexNihilo Note Edited: 0059091
2012-04-29 11:16 HexNihilo Note Edited: 0059091
2012-04-29 11:16 HexNihilo Note Edited: 0059091
2012-04-29 11:17 HexNihilo Note Edited: 0059091
2012-04-29 11:21 HexNihilo Note Edited: 0059091
2012-04-29 11:23 HexNihilo Note Edited: 0059091
2012-04-29 11:32 HexNihilo Note Edited: 0059091
2012-04-29 11:40 HexNihilo Note Edited: 0059091
2012-04-29 11:46 HexNihilo Note Edited: 0059091
2012-04-29 11:49 HexNihilo Note Edited: 0059091
2012-04-29 15:25 HexNihilo Note Edited: 0059091
2018-09-15 23:30 accorp File Added: issue-21877.diff
2018-09-15 23:31 accorp Note Added: 0110775
2018-09-15 23:55 Juha Manninen Assigned To => Juha Manninen
2018-09-15 23:55 Juha Manninen Status new => assigned
2018-09-15 23:59 Juha Manninen Fixed in Revision => r59018
2018-09-15 23:59 Juha Manninen LazTarget => -
2018-09-15 23:59 Juha Manninen Note Added: 0110777
2018-09-15 23:59 Juha Manninen Status assigned => resolved
2018-09-15 23:59 Juha Manninen Resolution open => fixed