View Issue Details

IDProjectCategoryView StatusLast Update
0016376LazarusIDEpublic2011-07-22 09:08
ReporterGraeme GeldenhuysAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86OSUbuntu LinuxOS Version8.04.2
Product Version0.9.29 (SVN)Product Buildr25080 
Target Version1.0.0Fixed in Version 
Summary0016376: Initial selected tree node has wrong text color
DescriptionThis happens in all treeviews:
  - Project Inspector
  - Environment Options
  etc..

The text should be white on a blue selection background. if I select another node and then the first node, then the color is correct. But if the dialog is displayed for the first time and the first treenode has selection, then the text color is wrong. See attached image.

I'm only using Lazarus with GTK2, so I don't know if other widgetsets are affected.
TagsNo tags attached.
Fixed in Revision31778
LazTarget1.0
WidgetsetGTK, GTK 2
Attached Files
  • treeview_LCL-GTK1.png (6,728 bytes)
    treeview_LCL-GTK1.png (6,728 bytes)
  • gtk2treetext.png (52,171 bytes)
    gtk2treetext.png (52,171 bytes)
  • OI_1.png (48,683 bytes)
    OI_1.png (48,683 bytes)
  • OI_2.png (45,014 bytes)
    OI_2.png (45,014 bytes)
  • treeview.diff (1,355 bytes)
    Index: include/treeview.inc
    ===================================================================
    --- include/treeview.inc	(revision 30856)
    +++ include/treeview.inc	(working copy)
    @@ -4612,7 +4612,7 @@
           Details := ThemeServices.GetElementDetails(ttItemNormal);
     
         if (tvoThemedDraw in Options) then
    -      ThemeServices.DrawText(Canvas, Details, AText, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0)
    +      ThemeServices.DrawText(Canvas.Handle, Details, AText, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0)
         else
           DrawText(Canvas.Handle, PChar(AText), -1, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
       end;
    Index: interfaces/gtk2/gtk2themes.pas
    ===================================================================
    --- interfaces/gtk2/gtk2themes.pas	(revision 30856)
    +++ interfaces/gtk2/gtk2themes.pas	(working copy)
    @@ -559,7 +559,7 @@
                   case Details.State of
                     TREIS_SELECTED,
                     TREIS_HOTSELECTED: Result.State := GTK_STATE_SELECTED;
    -                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_ACTIVE;
    +                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_SELECTED; //Was: GTK_STATE_ACTIVE;
                     TREIS_HOT: Result.State := GTK_STATE_PRELIGHT;
                     TREIS_DISABLED: Result.State := GTK_STATE_INSENSITIVE;
                   else
    
    treeview.diff (1,355 bytes)
  • gtk2.treeview.diff (1,756 bytes)
    Index: lcl/interfaces/gtk2/gtk2themes.pas
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2themes.pas	(revision 30856)
    +++ lcl/interfaces/gtk2/gtk2themes.pas	(working copy)
    @@ -88,6 +88,7 @@
            const R: TRect; ClipRect: PRect); override;
     
         procedure DrawIcon(DC: HDC; Details: TThemedElementDetails; const R: TRect; himl: HIMAGELIST; Index: Integer); override;
    +    procedure DrawText(ACanvas: TPersistent; Details: TThemedElementDetails; const S: String; R: TRect; Flags, Flags2: Cardinal); virtual; overload;
         procedure DrawText(DC: HDC; Details: TThemedElementDetails; const S: String; R: TRect; Flags, Flags2: Cardinal); override;
     
         function ContentRect(DC: HDC; Details: TThemedElementDetails; BoundingRect: TRect): TRect; override;
    @@ -559,7 +560,7 @@
                   case Details.State of
                     TREIS_SELECTED,
                     TREIS_HOTSELECTED: Result.State := GTK_STATE_SELECTED;
    -                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_ACTIVE;
    +                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_SELECTED; //Was: GTK_STATE_ACTIVE;
                     TREIS_HOT: Result.State := GTK_STATE_PRELIGHT;
                     TREIS_DISABLED: Result.State := GTK_STATE_INSENSITIVE;
                   else
    @@ -934,6 +935,16 @@
     
     end;
     
    +procedure TGtk2ThemeServices.DrawText(ACanvas: TPersistent;
    +  Details: TThemedElementDetails; const S: String; R: TRect; Flags,
    +  Flags2: Cardinal);
    +begin
    +  if ThemesEnabled then
    +    DrawText(TCanvas(ACanvas).Handle, Details, S, R, Flags, Flags2)
    +  else
    +    inherited;
    +end;
    +
     procedure TGtk2ThemeServices.DrawText(DC: HDC; Details: TThemedElementDetails;
       const S: String; R: TRect; Flags, Flags2: Cardinal);
     var
    
    gtk2.treeview.diff (1,756 bytes)

Relationships

related to 0017286 closedZeljan Rikalo color scheme of message window 

Activities

2010-04-30 16:31

 

Graeme Geldenhuys

2010-04-30 16:46

reporter   ~0037127

More testing reveals that it actually happens whenever the treeview looses focus.

Zeljan Rikalo

2010-04-30 17:24

developer   ~0037128

I suppose that DrawText() isn't implemented in gtk2 themes.

Graeme Geldenhuys

2010-05-03 08:40

reporter   ~0037180

I wouldn't know, but I do know it worked before. Even tooltip hints text color is drawn correctly, so I don't think it's a Drawtext() and 'gtk2 theme' issue.

Zeljan Rikalo

2010-05-26 10:58

developer   ~0038011

mean gtk2lcl theme implementation.Indeed, this behaviour is different than gtk2 pure app.

Vincent Snijders

2010-10-29 14:36

manager   ~0042329

Last edited: 2010-10-29 15:48

Messages view uses treeview too, so I added related issue.

Graeme Geldenhuys

2010-10-29 15:19

reporter   ~0042337

This bug is visible in LCL-GTK1, LCL-GTK2. The issue can also been seen in the Project Inspector treeview. See attached image showing LCL-GTK1 with the problem. I'm using Lazarus svn (dated 2010-10-27).

Other non-LCL (but still GTK1 or GTK2) applications don't look like this, so it is NOT a theme bug, but a problem in LCL.

2010-10-29 15:20

 

treeview_LCL-GTK1.png (6,728 bytes)
treeview_LCL-GTK1.png (6,728 bytes)

Graeme Geldenhuys

2010-10-29 15:22

reporter   ~0042338

Messages view also has this bug. See another screenshot attached.

2010-10-29 15:23

 

Bart Broersma

2010-12-02 15:32

developer   ~0043892

My 2 cents...

DrawText is implemented in TGTK2ThemeServices, but in DoPaintNode ThemeServices.DrawText does not call TGTK2ThemeServices.DrawText but Themes.DrawText instead.

If we call
  ThemeServices.DrawText(Canvas.Handle, Details, AText, NodeRect, DT_CENTER or DT_VCENTER, 0)

instead of

  ThemeServices.DrawText(Canvas, Details, AText, NodeRect, DT_CENTER or DT_VCENTER, 0)

Then we actually call GTK2ThemeServices.DrawText().

This draws the node with clWindowText (I guess, it is black on my screen).


AFAICS in my GTK2 a TreeView wich does not have focus, still has the selected item in the same backgroundcolor as if it had focus.
This can be achieved in GetGtkStyleParams() by changing the following line (appr. line 562 in lcl/interfaces/gtk2/gtk2themes.pas)

  TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_ACTIVE;

into

  TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_SELECTED;


If we only want no highlighted background but only the text-color to indicate which node is seleced (e.g. clHighLight) this can easily be achieved in Themes.DrawText() (appr. line 2394 in lcl/themes.pas):

    case Details.State of
      TREIS_SELECTED,
      TREIS_HOTSELECTED: Canvas.Font.Color := clHighlightText;
      TREIS_SELECTEDNOTFOCUS: Canvas.Font.Color := WhatEverColorWeFindUseFull; <--
    else
      Canvas.Font.Color := clWindowText;
    end;

Just one other observation.
Setting TreeView.Enabled to false does not have any visible effect (wether or not the TreeView is "themed" or not). I'ld expect the control to be "grayed" out.
Also the enumerate ttItemDisabled does not seem to be used anywhere in the sources?

Zeljan Rikalo

2011-04-04 09:05

developer   ~0047171

Cannot reproduce anymore.Probably fixed in the meantime. Tested with gtk and gtk2 Lazarus 0.9.31 r30166M FPC 2.4.3 i386-linux-gtk 2.

2011-04-22 20:26

 

gtk2treetext.png (52,171 bytes)
gtk2treetext.png (52,171 bytes)

Vladimir Zhirov

2011-04-22 20:29

reporter   ~0047695

I still can reproduce it with Lazarus 0.9.31 r30406 (GTK2), the screenshot is attached (gtk2treetext.png). This problem affects message window too, text color should be white on my theme instead of black.

Bart Broersma

2011-06-20 01:33

developer   ~0049214

Last edited: 2011-06-20 13:38

Well, the problem still is there.
I attached 2 screenshots (Laz r30856/fpc 2.4.2/GTK2)

OI_1.png: just selected Form1 in OI
OI_2.png: just clicked on Properties tab in OI

As you can see, you can no longer see what you have selected in OI, so you do not know which component's properties you are editing.

IMHO a treeview that does not have focus, should still indicate which item is selected.

2011-06-20 01:33

 

OI_1.png (48,683 bytes)
OI_1.png (48,683 bytes)

2011-06-20 01:34

 

OI_2.png (45,014 bytes)
OI_2.png (45,014 bytes)

2011-06-20 15:47

 

treeview.diff (1,355 bytes)
Index: include/treeview.inc
===================================================================
--- include/treeview.inc	(revision 30856)
+++ include/treeview.inc	(working copy)
@@ -4612,7 +4612,7 @@
       Details := ThemeServices.GetElementDetails(ttItemNormal);
 
     if (tvoThemedDraw in Options) then
-      ThemeServices.DrawText(Canvas, Details, AText, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0)
+      ThemeServices.DrawText(Canvas.Handle, Details, AText, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0)
     else
       DrawText(Canvas.Handle, PChar(AText), -1, NodeRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
   end;
Index: interfaces/gtk2/gtk2themes.pas
===================================================================
--- interfaces/gtk2/gtk2themes.pas	(revision 30856)
+++ interfaces/gtk2/gtk2themes.pas	(working copy)
@@ -559,7 +559,7 @@
               case Details.State of
                 TREIS_SELECTED,
                 TREIS_HOTSELECTED: Result.State := GTK_STATE_SELECTED;
-                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_ACTIVE;
+                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_SELECTED; //Was: GTK_STATE_ACTIVE;
                 TREIS_HOT: Result.State := GTK_STATE_PRELIGHT;
                 TREIS_DISABLED: Result.State := GTK_STATE_INSENSITIVE;
               else
treeview.diff (1,355 bytes)

Bart Broersma

2011-06-20 15:55

developer   ~0049234

Currently the drawtext for a treeview-item on gtk is the one from themes.pas, not the on from interfaces/gtk2/gtk2themes.pas.

Attached diff fixes the issue from OI_2.png.
If a list is not focused, you still can see which item is selected.
This is how gtk listviews on my system (Suse 10.0, GTK 2.8.3-4) behave.

The Gtk2 themes manager seems to paint the Treeview with the same colors used to paint Menu items. On my system these colors are a little bit darker blue than the colors used to highlight text.
If I run the gtk-demo app (provided with my distro), it seems that a gtk2 listview uses the same highlight colors for it's items as it uses for hightlighting (=selecting) text in a TEdit (hope I made myself clear).

Bart Broersma

2011-06-20 16:40

developer   ~0049236

Last edited: 2011-06-20 17:13

The previous patch will not work for Windows.
Calling DrawText with a Handle instead of with a Canvas, results in no text being drawn at all.

The new diff (gtk2.treeview.diff) has a slightly different approach.

In Gtk2Themes.pas it implements a procedure

TGtk2ThemeServices.DrawText(ACanvas: TPersistent; Details: TThemedElementDetails; const S: String; R: TRect; Flags, Flags2: Cardinal)

whichs in turn calls the DrawText with the Canvas.Handle.

This seems to work, and leaves the win32 implementation unchanged.

2011-06-20 17:06

 

gtk2.treeview.diff (1,756 bytes)
Index: lcl/interfaces/gtk2/gtk2themes.pas
===================================================================
--- lcl/interfaces/gtk2/gtk2themes.pas	(revision 30856)
+++ lcl/interfaces/gtk2/gtk2themes.pas	(working copy)
@@ -88,6 +88,7 @@
        const R: TRect; ClipRect: PRect); override;
 
     procedure DrawIcon(DC: HDC; Details: TThemedElementDetails; const R: TRect; himl: HIMAGELIST; Index: Integer); override;
+    procedure DrawText(ACanvas: TPersistent; Details: TThemedElementDetails; const S: String; R: TRect; Flags, Flags2: Cardinal); virtual; overload;
     procedure DrawText(DC: HDC; Details: TThemedElementDetails; const S: String; R: TRect; Flags, Flags2: Cardinal); override;
 
     function ContentRect(DC: HDC; Details: TThemedElementDetails; BoundingRect: TRect): TRect; override;
@@ -559,7 +560,7 @@
               case Details.State of
                 TREIS_SELECTED,
                 TREIS_HOTSELECTED: Result.State := GTK_STATE_SELECTED;
-                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_ACTIVE;
+                TREIS_SELECTEDNOTFOCUS: Result.State := GTK_STATE_SELECTED; //Was: GTK_STATE_ACTIVE;
                 TREIS_HOT: Result.State := GTK_STATE_PRELIGHT;
                 TREIS_DISABLED: Result.State := GTK_STATE_INSENSITIVE;
               else
@@ -934,6 +935,16 @@
 
 end;
 
+procedure TGtk2ThemeServices.DrawText(ACanvas: TPersistent;
+  Details: TThemedElementDetails; const S: String; R: TRect; Flags,
+  Flags2: Cardinal);
+begin
+  if ThemesEnabled then
+    DrawText(TCanvas(ACanvas).Handle, Details, S, R, Flags, Flags2)
+  else
+    inherited;
+end;
+
 procedure TGtk2ThemeServices.DrawText(DC: HDC; Details: TThemedElementDetails;
   const S: String; R: TRect; Flags, Flags2: Cardinal);
 var
gtk2.treeview.diff (1,756 bytes)

Bart Broersma

2011-07-13 12:58

developer   ~0049938

Reminder sent to: Zeljan Rikalo

Zeljan, can you take a look at my (latest) patch and see if it is valid?

Zeljan Rikalo

2011-07-13 15:05

developer   ~0049941

@Bart, patch looks good, but no free time to test it atm...maybe tonight or tomorrow ...

Bart Broersma

2011-07-13 19:55

developer   ~0049948

Thanks for looking into it.

Zeljan Rikalo

2011-07-22 09:08

developer   ~0050094

Please test and close if ok.

Issue History

Date Modified Username Field Change
2010-04-30 16:31 Graeme Geldenhuys New Issue
2010-04-30 16:31 Graeme Geldenhuys File Added: Screenshot-IDE_Options.png
2010-04-30 16:31 Graeme Geldenhuys Widgetset => GTK 2
2010-04-30 16:46 Graeme Geldenhuys Note Added: 0037127
2010-04-30 17:24 Zeljan Rikalo Note Added: 0037128
2010-05-03 08:40 Graeme Geldenhuys Note Added: 0037180
2010-05-26 10:58 Zeljan Rikalo Note Added: 0038011
2010-10-29 14:34 Vincent Snijders LazTarget => 1.0
2010-10-29 14:34 Vincent Snijders Status new => acknowledged
2010-10-29 14:34 Vincent Snijders Target Version => 1.0.0
2010-10-29 14:36 Vincent Snijders Relationship added related to 0017286
2010-10-29 14:36 Vincent Snijders Note Added: 0042329
2010-10-29 15:19 Graeme Geldenhuys Note Added: 0042337
2010-10-29 15:20 Graeme Geldenhuys File Added: treeview_LCL-GTK1.png
2010-10-29 15:22 Graeme Geldenhuys Note Added: 0042338
2010-10-29 15:23 Graeme Geldenhuys File Added: Messages_Window_LCL-GTK1.png
2010-10-29 15:47 Vincent Snijders Widgetset GTK 2 => GTK, GTK 2
2010-10-29 15:48 Vincent Snijders Note Edited: 0042329
2010-12-02 15:32 Bart Broersma Note Added: 0043892
2010-12-03 08:53 Paul Ishenin Status acknowledged => assigned
2010-12-03 08:53 Paul Ishenin Assigned To => Paul Ishenin
2011-04-04 09:05 Zeljan Rikalo Status assigned => resolved
2011-04-04 09:05 Zeljan Rikalo Resolution open => fixed
2011-04-04 09:05 Zeljan Rikalo Note Added: 0047171
2011-04-22 20:26 Vladimir Zhirov File Added: gtk2treetext.png
2011-04-22 20:29 Vladimir Zhirov Note Added: 0047695
2011-06-20 01:33 Bart Broersma Status resolved => assigned
2011-06-20 01:33 Bart Broersma Resolution fixed => reopened
2011-06-20 01:33 Bart Broersma Note Added: 0049214
2011-06-20 01:33 Bart Broersma File Added: OI_1.png
2011-06-20 01:34 Bart Broersma File Added: OI_2.png
2011-06-20 13:38 Bart Broersma Note Edited: 0049214
2011-06-20 15:47 Bart Broersma File Added: treeview.diff
2011-06-20 15:55 Bart Broersma Note Added: 0049234
2011-06-20 16:40 Bart Broersma Note Added: 0049236
2011-06-20 17:06 Bart Broersma File Added: gtk2.treeview.diff
2011-06-20 17:13 Bart Broersma Note Edited: 0049236
2011-07-13 12:58 Bart Broersma Note Added: 0049938
2011-07-13 15:05 Zeljan Rikalo Note Added: 0049941
2011-07-13 19:55 Bart Broersma Note Added: 0049948
2011-07-22 09:08 Zeljan Rikalo Fixed in Revision => 31778
2011-07-22 09:08 Zeljan Rikalo Status assigned => resolved
2011-07-22 09:08 Zeljan Rikalo Resolution reopened => fixed
2011-07-22 09:08 Zeljan Rikalo Note Added: 0050094