View Issue Details

IDProjectCategoryView StatusLast Update
0016183LazarusLCLpublic2021-01-23 07:34
ReporterLuiz Americo Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0016183: Form is painted with two colors when scrolled
DescriptionTo get the visual glitch, in an empty form set the vertical scrollbar page to 300 and range to 500 and in runtime do some scroll.
TagsNo tags attached.
Fixed in Revisionr64167
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0011010 closedAles Katona TScrollBox color change applies to only viewable area. 
related to 0033905 new TTabSheet does not follow theme color 

Activities

2010-04-02 05:05

 

scrollcolor.png (5,762 bytes)   
scrollcolor.png (5,762 bytes)   

Luiz Americo

2010-04-02 05:08

developer   ~0036392

Using Clearlooks theme under Ubuntu 9.04

Zeljan Rikalo

2010-04-02 08:36

developer   ~0036397

What's gtk2 version ?

Luiz Americo

2010-04-02 12:07

developer   ~0036403

GTK2 2.16

Zeljan Rikalo

2010-05-20 16:22

developer   ~0037815

Do you get glitches by scrolling with mouse only or with pg up/down ?
So, my question is
1.When you start your form and move scrollbar down with mouse (NOT WHEEL), see any glitches ?
2.When you start your form and move scrollbar down with mouse wheel, see any glitches (I did after some time)?
3.When you move scrollbar by pressing pg down/up (reach end and then again) I see glitches.

Problem is that ScrollBy() is not called (don't know if it should) when doing move with mousewheel (and mouse is NOT over scrollbar) and with pg up/down.
Then Widget^.ClientWidget is not repainted correctly.

Zeljan Rikalo

2010-05-20 18:41

developer   ~0037817

tracked GDK_EXPOSE and I can see there that something is wrong.If scrollbar goes "out of range" then glitches occurs.
How it can go "out of range" ?
1.As first let's see what's "ok range" : when you start form move scrollbar with left mouse button down (while it cannot be moved anymore).Now back it to start pos.

2.Now press PgDown twice (first comes to max, second is "out of range") or scroll down by mouse wheel (but mouse cursor is not over scrollbar, but over form viewport (Widget^.ClientWidget) - both produces scrollbar "out of range", that produces (I suppose so) clientWidget^.window out of range and then we get strange GDK_EXPOSE events eg. two events in packet, one is ok another not - glitches occurs. My gtk2-2.12 does not produce glitches like yours but it paints black that area ...

So problem could be "out of range" problem of scrollbar which exposes parts which shouldn't be exposed.

Luiz Americo

2010-06-13 16:29

developer   ~0038545

1.When you start your form and move scrollbar down with mouse (NOT WHEEL), see any glitches ?

Yes

2.When you start your form and move scrollbar down with mouse wheel, see any glitches (I did after some time)?

Yes

3.When you move scrollbar by pressing pg down/up (reach end and then again) I see glitches.

Yes


Now, it's more evident with Human theme

Zeljan Rikalo

2010-06-22 19:48

developer   ~0038742

@Luiz can you retest with r26258 ? I've changed ScrollBy behaviour.

Luiz Americo

2010-06-22 23:01

developer   ~0038748

It's still there.
If i would bet where the problem is i would do at the client widget approach, unfortunately i don't have time now.

Ere Maijala

2010-07-12 20:02

reporter   ~0039289

Maybe related to these lines (2322-2323) in gtk2widgetset.inc:
    if (BGColor = clDefault) or (BGColor = clBtnFace) then
      NewColor := nil

If you set the color to anything else than those two, it seems to work fine. E.g. this can be used as a workaround during startup:
ScrollBox.Color := ColorToRGB(ScrollBox.Color);

Zeljan Rikalo

2019-10-21 15:08

developer   ~0118755

Please attach patch so ppl can test

Juha Manninen

2019-10-21 18:27

developer   ~0118756

Last edited: 2019-10-21 18:29

View 2 revisions

Zeljko, this is a 9.5 years old report.
I cannot reproduce it now. Maybe it happend only with an old GTK2 version or maybe it got fixed in LCL-GTK2 somehow.
The code found by Ere Maijala is still there.
 "if (BGColor = clDefault) or (BGColor = clBtnFace) then"
Testing for 2 predefined colors looks like a hack but for me it seems to work.
Please test if you can reproduce.

The common denominator with the related 0033905 is color clBtnFace.

Joeny Ang

2020-11-28 10:27

reporter   ~0127228

Hi, this issue can still be reproduced. See test project and proposed patch :)
scrolling-control-2-colors.patch (4,240 bytes)   
--- lcl/widgetset/wsforms.pp.64142
+++ lcl/widgetset/wsforms.pp
@@ -50,6 +50,7 @@
   TWSScrollingWinControl = class(TWSWinControl)
   published
     // procedure ScrollBy is moved to TWSWinControl.
+    class function GetDefaultColor(const AControl: TControl; const ADefaultColorType: TDefaultColorType): TColor; override;
   end;
 
   { TWSScrollBox }
@@ -140,6 +141,19 @@
 
 implementation
 
+{ TWSScrollingWinControl }
+
+class function TWSScrollingWinControl.GetDefaultColor(const AControl: TControl;
+  const ADefaultColorType: TDefaultColorType): TColor;
+const
+  DefColors: array[TDefaultColorType] of TColor = (
+ { dctBrush } clForm,
+ { dctFont  } clBtnText
+  );
+begin
+  Result := DefColors[ADefaultColorType];
+end;
+
 { TWSCustomForm }
 
 class procedure TWSCustomForm.CloseModal(const ACustomForm: TCustomForm);
--- lcl/interfaces/gtk2/gtk2proc.inc.64142
+++ lcl/interfaces/gtk2/gtk2proc.inc
@@ -7575,7 +7575,7 @@
   var FormWidget: Pointer; AWidgetInfo: PWidgetInfo = nil): Pointer;
 var
   ScrolledWidget, ClientAreaWidget: PGtkWidget;
-  WindowStyle: PGtkStyle;
+//  WindowStyle: PGtkStyle;
   Adjustment: PGtkAdjustment;
 begin
   // Create the VBox. We need that to place controls outside
@@ -7592,8 +7592,10 @@
   gtk_widget_show(ScrolledWidget);
 
   ClientAreaWidget := gtk_layout_new(nil, nil);
-  WindowStyle := GetStyle(lgsWindow);
-  gtk_widget_set_style(ClientAreaWidget, WindowStyle);
+  // issue #16183: not sure why the GtkLayout is given a GtkWindow style here,
+  // this prevents setting color to the GtkLayout
+//  WindowStyle := GetStyle(lgsWindow);
+//  gtk_widget_set_style(ClientAreaWidget, WindowStyle);
   //debugln('CreateFormContents Style=',GetStyleDebugReport(WindowStyle));
   gtk_container_add(PGtkContainer(ScrolledWidget), ClientAreaWidget);
 
--- lcl/interfaces/gtk2/gtk2widgetset.inc.64142
+++ lcl/interfaces/gtk2/gtk2widgetset.inc
@@ -2307,7 +2307,10 @@
 
   if ChangeBGColor then
   begin
-    if (BGColor = clDefault) or (BGColor = clBtnFace) then
+    // setting bg color to nil will cancel previous calls to gtk_widget_modify_bg()
+    // cannot use nil on a GtkLayout (issue #16183)
+    if not GTK_IS_LAYOUT(AWidget) and
+      ((BGColor = clDefault) or (BGColor = clBtnFace)) then
       NewColor := nil
     else
     begin
--- lcl/interfaces/gtk2/gtk2wsforms.pp.64142
+++ lcl/interfaces/gtk2/gtk2wsforms.pp
@@ -863,8 +863,27 @@
 end;
 
 class procedure TGtk2WSCustomForm.SetColor(const AWinControl: TWinControl);
+var
+  AScrolled: PGtkWidget;
+  FColor: TColor;
 begin
   TGtk2WSWinControl.SetColor(AWinControl);
+
+  // Forms: GtkWindow->GtkVBox->gtkScrolledWindow->GtkLayout
+  // we need to set the color of the GtkLayout so that the whole viewport
+  // will be filled (issue #16183)
+  AScrolled := g_object_get_data({%H-}PGObject(AWinControl.Handle), odnScrollArea);
+  if GTK_IS_SCROLLED_WINDOW(AScrolled) and
+    GTK_IS_LAYOUT({%H-}PGtkBin(AScrolled)^.child) then
+  begin
+    FColor := AWinControl.Color;
+    if FColor = clDefault then
+      FColor := GetDefaultColor(AWinControl, dctBrush);
+    Gtk2WidgetSet.SetWidgetColor({%H-}PGtkBin(AScrolled)^.child,
+                                 clNone, FColor,
+                                 [GTK_STATE_NORMAL, GTK_STATE_ACTIVE,
+                                  GTK_STATE_PRELIGHT, GTK_STATE_SELECTED]);
+  end;
 end;
 
 class procedure TGtk2WSCustomForm.SetRealPopupParent(
@@ -970,12 +989,20 @@
 end;
 
 class procedure TGtk2WSScrollingWinControl.SetColor(const AWinControl: TWinControl);
+var
+  FColor: TColor;
 begin
   if not WSCheckHandleAllocated(AWinControl, 'SetColor')
   then Exit;
 
+  // ScrollingWinControl: GtkScrolledWindow->GtkLayout
+  // we need to set the color of the GtkLayout so that the whole viewport
+  // will be filled (issue #16183)
+  FColor := AWinControl.Color;
+  if FColor = clDefault then
+    FColor := GetDefaultColor(AWinControl, dctBrush);
   Gtk2WidgetSet.SetWidgetColor({%H-}PGtkBin(AWinControl.Handle)^.child,
-                               clNone, AWinControl.Color,
+                               clNone, FColor,
                                [GTK_STATE_NORMAL, GTK_STATE_ACTIVE,
                                 GTK_STATE_PRELIGHT, GTK_STATE_SELECTED]);
 end;

jamie philbrook

2020-11-28 14:32

reporter   ~0127237

This looks like nothing more than a brush issue.

You have Erase background messages and things like that...

Also it looks like you are attempting to make changes in global spec but have specific widget spec in it if I read this correctly.. "TWS" I don't see GKT in it..?

I think we should leave sleeping dogs alone.
 
 I have no issues getting rid of effects like that in user code when using what is already available .

Juha Manninen

2020-11-30 21:55

developer   ~0127283

Last edited: 2020-11-30 21:57

View 2 revisions

Applied, thanks.
I changed variable name FColor -> AColor.
I was able to reproduce the problem with your example project and saw the patch fixed it.

@Jamie, the changes are mostly for LCL-GTK2 code. Only one method was added to the common WS code.

Issue History

Date Modified Username Field Change
2010-04-02 05:05 Luiz Americo New Issue
2010-04-02 05:05 Luiz Americo File Added: scrollcolor.png
2010-04-02 05:05 Luiz Americo LazTarget => -
2010-04-02 05:05 Luiz Americo Widgetset => GTK 2
2010-04-02 05:07 Luiz Americo Relationship added related to 0011010
2010-04-02 05:08 Luiz Americo Note Added: 0036392
2010-04-02 08:36 Zeljan Rikalo Note Added: 0036397
2010-04-02 08:36 Zeljan Rikalo Status new => feedback
2010-04-02 12:07 Luiz Americo Note Added: 0036403
2010-05-20 16:22 Zeljan Rikalo Note Added: 0037815
2010-05-20 18:41 Zeljan Rikalo Note Added: 0037817
2010-06-13 16:29 Luiz Americo Note Added: 0038545
2010-06-22 19:48 Zeljan Rikalo Note Added: 0038742
2010-06-22 23:01 Luiz Americo Note Added: 0038748
2010-07-12 20:02 Ere Maijala Note Added: 0039289
2010-11-02 12:00 Vincent Snijders Status feedback => acknowledged
2019-10-20 17:27 Juha Manninen Relationship added related to 0033905
2019-10-21 15:08 Zeljan Rikalo Note Added: 0118755
2019-10-21 18:27 Juha Manninen Note Added: 0118756
2019-10-21 18:29 Juha Manninen Note Edited: 0118756 View Revisions
2020-11-28 10:27 Joeny Ang Note Added: 0127228
2020-11-28 10:27 Joeny Ang File Added: scrolling-control-2-colors.patch
2020-11-28 10:27 Joeny Ang File Added: scrolling-control-2-color-test-01.zip
2020-11-28 14:32 jamie philbrook Note Added: 0127237
2020-11-30 21:44 Juha Manninen Assigned To => Juha Manninen
2020-11-30 21:44 Juha Manninen Status acknowledged => assigned
2020-11-30 21:55 Juha Manninen Status assigned => resolved
2020-11-30 21:55 Juha Manninen Resolution open => fixed
2020-11-30 21:55 Juha Manninen Fixed in Revision => r64167
2020-11-30 21:55 Juha Manninen Widgetset GTK 2 => GTK 2
2020-11-30 21:55 Juha Manninen Note Added: 0127283
2020-11-30 21:57 Juha Manninen Note Edited: 0127283 View Revisions