View Issue Details

IDProjectCategoryView StatusLast Update
0015472LazarusWidgetsetpublic2010-03-25 20:00
ReporterJuha Manninen Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.29 (SVN) 
Target Version1.0.0Fixed in Version0.9.29 (SVN) 
Summary0015472: GTK2 source editor tab selection behaves wrong
DescriptionThis may happen with all LCL tabbed pages with GTK2 bindings but I tested only with Lazarus source editor.

1. Open so many files that all tabs are not visible at the same time.
2. Select the first editor tab.
3. Browse to the end of tab list using the right side arrow. The first tab should not be visible any more.
4. Select the last editor tab.
5. Now, try to select the first (left side) VISIBLE tab. It does not get selected. Instead focus jumps to the ultimate first tab which was not visible during selection.

QT bindings version works correctly.
Additional InformationLinux Opensuse 11.2, KDE4.3.4.
TagsNo tags attached.
Fixed in Revision24209
LazTarget0.9.30
WidgetsetGTK 2
Attached Files

Activities

Wimpie Nortje

2010-03-05 15:03

reporter   ~0034953

When you follow steps 1-3 and drag the final tab to the second visible position it sometimes gets moved to the absolute 2nd position instead of the visible 2nd position.

Maybe this should be a different bug, but I think it is related.

I use GTK2 on Kubuntu 9.10, i386

Flávio Etrusco

2010-03-11 15:34

developer   ~0035259

Last edited: 2010-03-11 16:27

My guess of what is going one: try pressing the mouse button without releasing, see the tab is selected, then release the button and it seems to scroll to the first item do another click at the same point...

2010-03-23 05:16

 

notebookbug.zip (133,378 bytes)

Flávio Etrusco

2010-03-23 05:22

developer   ~0035960

Last edited: 2010-03-23 13:28

Attached a little app to help debug the problem.
It happens when the Tab2 is the first tab visible, but doesn't seem to happen when last tab is visible.
From the "DebugLn" it's shown that the TabIndexAtClientPos is wrong at the time of MouseDown. Also, Y value in MouseDown/Up is negative! But get translated correctly in TabIndexAtClientPos.
Unfortunately gtk2 doesn't have a built-in implementation of TabIndexAtClientPos or similar, but newer versions (2.17.x at least) have drag'n'drop reorder built-in; maybe we could pass this feature to the widgetset, even though on other WSs they would have to be implemented in LCL glue.

Flávio Etrusco

2010-03-23 17:28

developer   ~0035985

I found a simple hack to fix the issue: search the wanted tab (do the loop) backwards in TabIndexAtClientPos.

2010-03-23 17:29

 

gtk-sourceeditor-tab-click-hack.patch (948 bytes)   
# HG changeset patch
# User etrusco <flavio.etrusco@gmail.com>
# Date 1269350243 10800
# Branch trunk
# Node ID 2adb09fe44efc9348b88e675459365bfaa1ed5b1
# Parent  75442cb0f7b0d028f85dc7a72f325a5880bff42c
[mq]: gtk_sourceditor_tab_click_fix

diff --git a/lcl/interfaces/gtk/gtkwsextctrls.pp b/lcl/interfaces/gtk/gtkwsextctrls.pp
--- a/lcl/interfaces/gtk/gtkwsextctrls.pp
+++ b/lcl/interfaces/gtk/gtkwsextctrls.pp
@@ -575,9 +575,10 @@ begin
   {$ELSE}
   NotebookPos:=AClientPos;
   {$ENDIF}
-  // go through all tabs
+  // go through all tabs. Do it backwards to avoid a bug with calculation of
+  //hidden/scrolled out tabs in the beginning of the notebook.
   Count:=g_list_length(NoteBookWidget^.Children);
-  for i:=0 to Count-1 do begin
+  for i:=Count-1 downto 0 do begin
     PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget,i);
     if PageWidget<>nil then begin
       TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);

Zeljan Rikalo

2010-03-23 18:16

developer   ~0035989

Patch is here, so 0.9.30

Juha Manninen

2010-03-23 20:45

developer   ~0035999

The patch doesn't solve the problem but moves it elsewhere. Now the ultimate last tab gets selected when you try to select the rightmost visible tab.
So the problem is kind of reversed which is understandable because the FOR loop was reversed :-)
Anyway, I guess you are near a solution now.

Zeljan Rikalo

2010-03-23 21:14

developer   ~0036001

Patch isn't good - it just shifts problem to another side

Zeljan Rikalo

2010-03-23 22:11

developer   ~0036002

Problem is because gtk's signal switch-page sends visible pagenum but not real pagenum.

Flávio Etrusco

2010-03-24 01:37

developer   ~0036008

Last edited: 2010-03-24 02:00

Of course I tried that before sending the patch, but I couldn't get it to trigger (in the last page).
The example seems to behave a little different than the IDE, don't know why.
Anyway, the problem as I see (and said) is in the LCL-implemented TabIndexAtClientPos, but indeed I didn't check the pages returned by gtk_notebook_get_page_nth is returning the expected page, so maybe it's some other interaction.

Not to mention that the drag only works in the label area, not the border around it - the tab drawing -, and it returns "-1". Couldn't find a property that determined the border size... Maybe it's 'tab-curvature' + 'tab-overlap'?

Flávio Etrusco

2010-03-24 08:05

developer   ~0036013

Last edited: 2010-03-24 08:07

Found another trick: check the active page first.

diff --git a/lcl/interfaces/gtk/gtkwsextctrls.pp b/lcl/interfaces/gtk/gtkwsextctrls.pp
--- a/lcl/interfaces/gtk/gtkwsextctrls.pp
+++ b/lcl/interfaces/gtk/gtkwsextctrls.pp
@@ -575,6 +575,24 @@ begin
   {$ELSE}
   NotebookPos:=AClientPos;
   {$ENDIF}
+
+  i := gtk_notebook_get_current_page(NoteBookWidget);
+  PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget, i);
+  if PageWidget<>nil then begin
+    TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
+    if TabWidget<>nil then begin
+      // test if position is in tabwidget
+      if (TabWidget^.Allocation.X<=NoteBookPos.X)
+      and (TabWidget^.Allocation.Y<=NoteBookPos.Y)
+      and (TabWidget^.Allocation.X+TabWidget^.Allocation.Width>NoteBookPos.X)
+      and (TabWidget^.Allocation.Y+TabWidget^.Allocation.Height>NoteBookPos.Y)
+      then begin
+        Result:=i;
+        exit;
+      end;
+    end;
+  end;
+
   // go through all tabs
   Count:=g_list_length(NoteBookWidget^.Children);
   for i:=0 to Count-1 do begin


Zeljan Rikalo

2010-03-24 08:30

developer   ~0036015

What if there's no active pageWidget ? I don't think that bug is at that place.
Look at switch-page signal attached to notebook.
Add some debugging code there, click on tab (when you have many tabs) now you see that it triggers ok for the first time, but then comes another signal from gtk2 which switches one more page left for no reason.

Zeljan Rikalo

2010-03-25 11:38

developer   ~0036066

Test and close if ok.

Juha Manninen

2010-03-25 14:53

developer   ~0036079

The problem is fixed. Good!
It still behaves differently between GTK2 and QT versions, but they are both good behaviors. A feature, not a bug. In GTK2 version the left and right arrows for tab list change the focus, too, to next tabbed page. In QT version it only scrolls the tab list, focus stays where it is.

Zeljan Rikalo

2010-03-25 16:16

developer   ~0036082

maybe it's fixable but no time to fix it now .. please close issue.

Juha Manninen

2010-03-25 20:00

developer   ~0036087

Closing...

Issue History

Date Modified Username Field Change
2010-01-06 16:05 Juha Manninen New Issue
2010-01-06 16:05 Juha Manninen Widgetset => GTK 2
2010-03-05 15:03 Wimpie Nortje Note Added: 0034953
2010-03-11 15:34 Flávio Etrusco Note Added: 0035259
2010-03-11 16:27 Flávio Etrusco Note Edited: 0035259
2010-03-12 16:05 Vincent Snijders LazTarget => 1.0
2010-03-12 16:05 Vincent Snijders Status new => acknowledged
2010-03-12 16:05 Vincent Snijders Target Version => 1.0.0
2010-03-23 05:16 Flávio Etrusco File Added: notebookbug.zip
2010-03-23 05:22 Flávio Etrusco Note Added: 0035960
2010-03-23 13:28 Flávio Etrusco Note Edited: 0035960
2010-03-23 17:28 Flávio Etrusco Note Added: 0035985
2010-03-23 17:29 Flávio Etrusco File Added: gtk-sourceeditor-tab-click-hack.patch
2010-03-23 18:16 Zeljan Rikalo LazTarget 1.0 => 0.9.30
2010-03-23 18:16 Zeljan Rikalo Note Added: 0035989
2010-03-23 20:45 Juha Manninen Note Added: 0035999
2010-03-23 21:14 Zeljan Rikalo Note Added: 0036001
2010-03-23 22:11 Zeljan Rikalo Note Added: 0036002
2010-03-24 01:37 Flávio Etrusco Note Added: 0036008
2010-03-24 02:00 Flávio Etrusco Note Edited: 0036008
2010-03-24 08:05 Flávio Etrusco Note Added: 0036013
2010-03-24 08:07 Flávio Etrusco Note Edited: 0036013
2010-03-24 08:30 Zeljan Rikalo Note Added: 0036015
2010-03-25 11:38 Zeljan Rikalo Fixed in Revision => 24209
2010-03-25 11:38 Zeljan Rikalo Status acknowledged => resolved
2010-03-25 11:38 Zeljan Rikalo Fixed in Version => 0.9.29 (SVN)
2010-03-25 11:38 Zeljan Rikalo Resolution open => fixed
2010-03-25 11:38 Zeljan Rikalo Assigned To => Zeljan Rikalo
2010-03-25 11:38 Zeljan Rikalo Note Added: 0036066
2010-03-25 14:53 Juha Manninen Note Added: 0036079
2010-03-25 16:16 Zeljan Rikalo Note Added: 0036082
2010-03-25 20:00 Juha Manninen Status resolved => closed
2010-03-25 20:00 Juha Manninen Note Added: 0036087