summaryrefslogtreecommitdiff
blob: 54fa572bc6b324d93e3286615aeb1f20b55f416e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
From ef3c0cdfa18a6f612e5ba84e42bcd288374669fb Mon Sep 17 00:00:00 2001
From: Hugo Pereira Da Costa <hugo.pereira.da.costa@gmail.com>
Date: Thu, 6 Apr 2017 17:32:51 +0200
Subject: Patch from Matt Whitlock to fix crash in ecclipse about invalid
 columns. BUG: 338012

---
 src/oxygengtkcellinfo.cpp | 78 +++++++++++++++++++----------------------------
 src/oxygengtkcellinfo.h   | 22 ++++++++-----
 2 files changed, 46 insertions(+), 54 deletions(-)

diff --git a/src/oxygengtkcellinfo.cpp b/src/oxygengtkcellinfo.cpp
index 52e0d34..8118143 100644
--- a/src/oxygengtkcellinfo.cpp
+++ b/src/oxygengtkcellinfo.cpp
@@ -31,38 +31,41 @@ namespace Oxygen
     //____________________________________________________________________________
     Gtk::CellInfo::CellInfo( GtkTreeView* treeView, int x, int y, int w, int h ):
         _path(0L),
-        _column(0L)
+        _column(-1)
     {
+        GtkTreeViewColumn *column( 0L );
 
         /*
         four attempts are made to get the path from any corner of the rectangle passed in arguments.
         This is necessary to handle half-hidden cells
         */
-        gtk_tree_view_get_path_at_pos( treeView, (gint)x+1, (gint)y+1, &_path, &_column, 0L, 0L );
-
-        if( !_path ) gtk_tree_view_get_path_at_pos( treeView, (gint)x+1, (gint)y+h-1, &_path, &_column, 0L, 0L );
-        else return;
-
-        if( !_path ) gtk_tree_view_get_path_at_pos( treeView, (gint)x+w-1, (gint)y+1, &_path, &_column, 0L, 0L );
-        else return;
-
-        if( !_path ) gtk_tree_view_get_path_at_pos( treeView, (gint)x+w-1, (gint)y+h-1, &_path, &_column, 0L, 0L );
-        else return;
+        gtk_tree_view_get_path_at_pos( treeView, (gint)x+1, (gint)y+1, &_path, &column, 0L, 0L );
+        if( !_path ) {
+            gtk_tree_view_get_path_at_pos( treeView, (gint)x+1, (gint)y+h-1, &_path, &column, 0L, 0L );
+            if( !_path ) {
+                gtk_tree_view_get_path_at_pos( treeView, (gint)x+w-1, (gint)y+1, &_path, &column, 0L, 0L );
+                if( !_path ) {
+                    gtk_tree_view_get_path_at_pos( treeView, (gint)x+w-1, (gint)y+h-1, &_path, &column, 0L, 0L );
+                    if( !_path ) return;
+                }
+            }
+        }
 
+        _column = indexOfColumn( treeView, column );
     }
 
     //____________________________________________________________________________
     bool Gtk::CellInfo::isLastVisibleColumn( GtkTreeView* treeView ) const
     {
-        bool isLast( false );
+        bool isLast( true );
         GList* columns( gtk_tree_view_get_columns( treeView ) );
-        for( GList *child = g_list_last( columns ); child; child = g_list_previous( child ) )
+        for( GList *child = g_list_nth( columns, _column ); ( child = g_list_next( child ) ); )
         {
             if( !GTK_IS_TREE_VIEW_COLUMN( child->data ) ) continue;
             GtkTreeViewColumn* column( GTK_TREE_VIEW_COLUMN( child->data ) );
             if( gtk_tree_view_column_get_visible( column ) )
             {
-                isLast = (_column == column );
+                isLast = false;
                 break;
             }
 
@@ -75,15 +78,15 @@ namespace Oxygen
     //____________________________________________________________________________
     bool Gtk::CellInfo::isFirstVisibleColumn( GtkTreeView* treeView ) const
     {
-        bool isFirst( false );
+        bool isFirst( true );
         GList* columns( gtk_tree_view_get_columns( treeView ) );
-        for( GList *child = g_list_first( columns ); child; child = g_list_next( child ) )
+        for( GList *child = g_list_nth( columns, _column ); ( child = g_list_previous( child ) ); )
         {
             if( !GTK_IS_TREE_VIEW_COLUMN( child->data ) ) continue;
             GtkTreeViewColumn* column( GTK_TREE_VIEW_COLUMN( child->data ) );
             if( gtk_tree_view_column_get_visible( column ) )
             {
-                isFirst= (_column == column );
+                isFirst = false;
                 break;
             }
 
@@ -98,34 +101,7 @@ namespace Oxygen
     {
         // check expander column
         GtkTreeViewColumn* expanderColumn( gtk_tree_view_get_expander_column( treeView ) );
-        if( !expanderColumn || _column == expanderColumn ) return false;
-
-        bool found( false );
-        bool isLeft( false );
-
-        // get all columns
-        GList* columns( gtk_tree_view_get_columns( treeView ) );
-        for( GList *child = g_list_first( columns ); child; child = g_list_next( child ) )
-        {
-            if( !GTK_IS_TREE_VIEW_COLUMN( child->data ) ) continue;
-            GtkTreeViewColumn* column( GTK_TREE_VIEW_COLUMN( child->data ) );
-            if( column == expanderColumn )
-            {
-                if( found )
-                {
-
-                    isLeft = true;
-                    break;
-
-                } else break;
-
-            } else if( found ) break;
-            else if( column == _column ) found = true;
-
-        }
-
-        if( columns ) g_list_free( columns );
-        return isLeft;
+        return expanderColumn && _column < indexOfColumn( treeView, expanderColumn );
 
     }
 
@@ -203,13 +179,23 @@ namespace Oxygen
     {
         GdkRectangle out( Gtk::gdk_rectangle() );
         if( treeView && isValid() )
-        { gtk_tree_view_get_background_area( treeView, _path, _column, &out ); }
+        { gtk_tree_view_get_background_area( treeView, _path, gtk_tree_view_get_column( treeView, _column ), &out ); }
 
         return out;
 
     }
 
     //____________________________________________________________________________
+    gint Gtk::CellInfo::indexOfColumn( GtkTreeView* treeView, GtkTreeViewColumn* column )
+    {
+        GList* columns( gtk_tree_view_get_columns( treeView ) );
+        if( !columns ) return -1;
+        gint index( g_list_index( columns, column ) );
+        g_list_free( columns );
+        return index;
+    }
+
+    //____________________________________________________________________________
     Gtk::CellInfoFlags::CellInfoFlags( GtkTreeView* treeView, const CellInfo& cellInfo ):
         _depth( cellInfo.depth() ),
         _expanderSize(0),
diff --git a/src/oxygengtkcellinfo.h b/src/oxygengtkcellinfo.h
index 919d020..58dd441 100644
--- a/src/oxygengtkcellinfo.h
+++ b/src/oxygengtkcellinfo.h
@@ -47,7 +47,7 @@ namespace Oxygen
             //! empty constructor
             explicit CellInfo( void ):
                 _path( 0L ),
-                _column( 0L )
+                _column( -1 )
             {}
 
             //! copy constructor
@@ -60,8 +60,12 @@ namespace Oxygen
             /*! unfortunately the path retrieval does not always work because x and y must be positive */
             explicit CellInfo( GtkTreeView* treeView, int x, int y ):
                 _path(0L),
-                _column(0L)
-            { gtk_tree_view_get_path_at_pos( treeView, x, y, &_path, &_column, 0L, 0L ); }
+                _column(-1)
+            {
+                GtkTreeViewColumn *column( 0L );
+                gtk_tree_view_get_path_at_pos( treeView, x, y, &_path, &column, 0L, 0L );
+                _column = indexOfColumn( treeView, column );
+            }
 
             //! construct from tree view and rectangle
             explicit CellInfo( GtkTreeView* treeView, int x, int y, int w, int h );
@@ -92,7 +96,7 @@ namespace Oxygen
             {
                 if( _path ) gtk_tree_path_free( _path );
                 _path = 0L;
-                _column = 0L;
+                _column = -1;
             }
 
             //!@name accessors
@@ -100,7 +104,7 @@ namespace Oxygen
 
             //! true if valid
             bool isValid( void ) const
-            { return _path && _column; }
+            { return _path && _column >= 0; }
 
             //! returns true if column is the last one
             bool isLastVisibleColumn( GtkTreeView* ) const;
@@ -110,7 +114,7 @@ namespace Oxygen
 
             //! returns true if column is the one that contains expander
             bool isExpanderColumn( GtkTreeView* treeView ) const
-            { return _column == gtk_tree_view_get_expander_column( treeView ); }
+            { return _column >= 0 && _column == indexOfColumn( treeView, gtk_tree_view_get_expander_column( treeView ) ); }
 
             //! returs true if column is let of expander column
             bool isLeftOfExpanderColumn( GtkTreeView* ) const;
@@ -152,8 +156,8 @@ namespace Oxygen
             //! path
             GtkTreePath* _path;
 
-            //! column
-            GtkTreeViewColumn* _column;
+            //! column index
+            gint _column;
 
             //! streamer
             friend std::ostream& operator << (std::ostream& out, const CellInfo& info )
@@ -168,6 +172,8 @@ namespace Oxygen
                 return out;
             }
 
+            static gint indexOfColumn( GtkTreeView*, GtkTreeViewColumn* );
+
         };
 
         //! cell info flags
-- 
cgit v0.11.2