]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeprivate.h
Fix selection. I think it's all dandy now. We check the current event for
[~andy/gtk] / gtk / gtktreeprivate.h
1 /* gtktreeprivate.h
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GTK_TREE_PRIVATE_H__
21 #define __GTK_TREE_PRIVATE_H__
22
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27
28 #include <gtk/gtktreeview.h>
29 #include <gtk/gtktreeselection.h>
30 #include <gtk/gtkrbtree.h>
31
32
33   
34 #define TREE_VIEW_DRAG_WIDTH 6
35
36 typedef enum
37 {
38   GTK_TREE_VIEW_IS_LIST = 1 << 0,
39   GTK_TREE_VIEW_SHOW_EXPANDERS = 1 << 1,
40   GTK_TREE_VIEW_IN_COLUMN_RESIZE = 1 << 2,
41   GTK_TREE_VIEW_ARROW_PRELIT = 1 << 3,
42   GTK_TREE_VIEW_HEADERS_VISIBLE = 1 << 4,
43   GTK_TREE_VIEW_DRAW_KEYFOCUS = 1 << 5,
44   GTK_TREE_VIEW_MODEL_SETUP = 1 << 6,
45   GTK_TREE_VIEW_IN_COLUMN_DRAG = 1 << 7,
46 } GtkTreeViewFlags;
47
48 enum
49 {
50   DRAG_COLUMN_WINDOW_STATE_UNSET = 0,
51   DRAG_COLUMN_WINDOW_STATE_ORIGINAL = 1,
52   DRAG_COLUMN_WINDOW_STATE_ARROW = 2,
53   DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT = 3,
54   DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT = 4,
55   
56 };
57 #define GTK_TREE_VIEW_SET_FLAG(tree_view, flag)   G_STMT_START{ (tree_view->priv->flags|=flag); }G_STMT_END
58 #define GTK_TREE_VIEW_UNSET_FLAG(tree_view, flag) G_STMT_START{ (tree_view->priv->flags&=~(flag)); }G_STMT_END
59 #define GTK_TREE_VIEW_FLAG_SET(tree_view, flag)   ((tree_view->priv->flags&flag)==flag)
60 #define TREE_VIEW_HEADER_HEIGHT(tree_view)        (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE)?tree_view->priv->header_height:0)
61 #define TREE_VIEW_COLUMN_WIDTH(column)             (CLAMP (column->width, (column->min_width!=-1)?column->min_width:column->width, (column->max_width!=-1)?column->max_width:column->width))
62 #define TREE_VIEW_DRAW_EXPANDERS(tree_view)       (!GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_IS_LIST)&&GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_SHOW_EXPANDERS))
63
64  /* This lovely little value is used to determine how far away from the title bar
65   * you can move the mouse and still have a column drag work.
66   */
67 #define TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER(tree_view) (10*TREE_VIEW_HEADER_HEIGHT(tree_view))
68
69 typedef void (*GtkTreeViewSearchDialogPositionFunc) (GtkTreeView *tree_view,
70                                                      GtkWidget   *search_dialog);
71
72 typedef struct _GtkTreeViewColumnReorder GtkTreeViewColumnReorder;
73 struct _GtkTreeViewColumnReorder
74 {
75   gint left_align;
76   gint right_align;
77   GtkTreeViewColumn *left_column;
78   GtkTreeViewColumn *right_column;
79 };
80
81 struct _GtkTreeViewPrivate
82 {
83   GtkTreeModel *model;
84
85   guint flags;
86   /* tree information */
87   GtkRBTree *tree;
88
89   gint tab_offset;
90   GtkRBNode *button_pressed_node;
91   GtkRBTree *button_pressed_tree;
92
93   GList *children;
94   gint width;
95   gint height;
96
97   GtkAdjustment *hadjustment;
98   GtkAdjustment *vadjustment;
99
100   GdkWindow *bin_window;
101   GdkWindow *header_window;
102   GdkWindow *drag_window;
103   GdkWindow *drag_highlight_window;
104   GtkTreeViewColumn *drag_column;
105   gint drag_column_x;
106
107   GtkTreeViewColumn *expander_column;
108
109   /* Focus code */
110   GtkTreeViewColumn *focus_column;
111   GtkTreeViewColumn *scroll_column;
112
113   /* Selection stuff */
114   GtkTreeRowReference *anchor;
115   GtkTreeRowReference *cursor;
116
117   /* Column Resizing */
118   GdkCursor *cursor_drag;
119   GdkGC *xor_gc;
120   gint drag_pos;
121   gint x_drag;
122
123   /* Prelight information */
124   GtkRBNode *prelight_node;
125   GtkRBTree *prelight_tree;
126
127   /* The node that's currently being collapsed or expanded */
128   GtkRBNode *expanded_collapsed_node;
129   GtkRBTree *expanded_collapsed_tree;
130   guint expand_collapse_timeout;
131
132   /* Selection information */
133   GtkTreeSelection *selection;
134
135   /* Header information */
136   gint n_columns;
137   GList *columns;
138   gint header_height;
139
140   GtkTreeViewColumnDropFunc column_drop_func;
141   gpointer column_drop_func_data;
142   GtkDestroyNotify column_drop_func_data_destroy;
143   GList *column_drag_info;
144   GtkTreeViewColumnReorder *cur_reorder;
145
146   /* ATK Hack */
147   GtkTreeDestroyCountFunc destroy_count_func;
148   gpointer destroy_count_data;
149   GtkDestroyNotify destroy_count_destroy;
150
151   /* Scroll timeout (e.g. during dnd) */
152   guint scroll_timeout;
153
154   /* Row drag-and-drop */
155   GtkTreeRowReference *drag_dest_row;
156   GtkTreeViewDropPosition drag_dest_pos;
157   guint open_dest_timeout;
158
159   gint pressed_button;
160   gint press_start_x;
161   gint press_start_y;
162
163   /* Scroll-to functionality when unrealized */
164   GtkTreePath *scroll_to_path;
165   GtkTreeViewColumn *scroll_to_column;
166   gfloat scroll_to_row_align;
167   gfloat scroll_to_col_align;
168
169   guint reorderable : 1;
170   guint header_has_focus : 1;
171   guint drag_column_window_state : 3;
172   /* hint to display rows in alternating colors */
173   guint has_rules : 1;
174
175   /* interactive search */
176   guint enable_search : 1;
177   gint search_column;
178   GtkTreeViewSearchDialogPositionFunc search_dialog_position_func;
179   GtkTreeViewSearchEqualFunc search_equal_func;
180   gpointer search_user_data;
181   GtkDestroyNotify search_destroy;
182 };
183
184 #ifdef __GNUC__
185
186 #define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
187      if (!(expr))                                                       \
188        {                                                                \
189          g_log (G_LOG_DOMAIN,                                           \
190                 G_LOG_LEVEL_CRITICAL,                                   \
191                 "file %s: line %d (%s): assertion `%s' failed.\n"       \
192                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
193                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
194                 "without letting the view know.  Any display from now on is likely to\n"  \
195                 "be incorrect.\n",                                                        \
196                 __FILE__,                                               \
197                 __LINE__,                                               \
198                 __PRETTY_FUNCTION__,                                    \
199                 #expr);                                                 \
200          return ret;                                                    \
201        };                               }G_STMT_END
202
203 #define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{             \
204      if (!(expr))                                                       \
205        {                                                                \
206          g_log (G_LOG_DOMAIN,                                           \
207                 G_LOG_LEVEL_CRITICAL,                                   \
208                 "file %s: line %d (%s): assertion `%s' failed.\n"       \
209                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
210                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
211                 "without letting the view know.  Any display from now on is likely to\n"  \
212                 "be incorrect.\n",                                                        \
213                 __FILE__,                                               \
214                 __LINE__,                                               \
215                 __PRETTY_FUNCTION__,                                    \
216                 #expr);                                                 \
217          return;                                                        \
218        };                               }G_STMT_END
219
220 #else
221
222 #define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
223      if (!(expr))                                                       \
224        {                                                                \
225          g_log (G_LOG_DOMAIN,                                           \
226                 G_LOG_LEVEL_CRITICAL,                                   \
227                 "file %s: line %d: assertion `%s' failed.\n"       \
228                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
229                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
230                 "without letting the view know.  Any display from now on is likely to\n"  \
231                 "be incorrect.\n",                                                        \
232                 __FILE__,                                               \
233                 __LINE__,                                               \
234                 #expr);                                                 \
235          return ret;                                                    \
236        };                               }G_STMT_END
237
238 #define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{          \
239      if (!(expr))                                                       \
240        {                                                                \
241          g_log (G_LOG_DOMAIN,                                           \
242                 G_LOG_LEVEL_CRITICAL,                                   \
243                 "file %s: line %d: assertion '%s' failed.\n"            \
244                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
245                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
246                 "without letting the view know.  Any display from now on is likely to\n"  \
247                 "be incorrect.\n",                                                        \
248                 __FILE__,                                               \
249                 __LINE__,                                               \
250                 #expr);                                                 \
251          return;                                                        \
252        };                               }G_STMT_END
253 #endif
254
255
256 /* functions that shouldn't be exported */
257 void         _gtk_tree_selection_internal_select_node (GtkTreeSelection  *selection,
258                                                        GtkRBNode         *node,
259                                                        GtkRBTree         *tree,
260                                                        GtkTreePath       *path,
261                                                        GdkModifierType    state);
262 gboolean     _gtk_tree_view_find_node                 (GtkTreeView       *tree_view,
263                                                        GtkTreePath       *path,
264                                                        GtkRBTree        **tree,
265                                                        GtkRBNode        **node);
266 GtkTreePath *_gtk_tree_view_find_path                 (GtkTreeView       *tree_view,
267                                                        GtkRBTree         *tree,
268                                                        GtkRBNode         *node);
269 void         _gtk_tree_view_update_size               (GtkTreeView       *tree_view);
270
271
272 void _gtk_tree_view_column_realize_button   (GtkTreeViewColumn *column);
273 void _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column);
274 void _gtk_tree_view_column_set_tree_view    (GtkTreeViewColumn *column,
275                                              GtkTreeView       *tree_view);
276 void _gtk_tree_view_column_unset_tree_view  (GtkTreeViewColumn *column);
277 void _gtk_tree_view_column_set_width        (GtkTreeViewColumn *column,
278                                              gint               width);
279 void _gtk_tree_view_column_start_drag       (GtkTreeView       *tree_view,
280                                              GtkTreeViewColumn *column);
281
282 GtkTreeSelection* _gtk_tree_selection_new                (void);
283 GtkTreeSelection* _gtk_tree_selection_new_with_tree_view (GtkTreeView      *tree_view);
284 void              _gtk_tree_selection_set_tree_view      (GtkTreeSelection *selection,
285                                                           GtkTreeView      *tree_view);
286
287
288
289
290 #ifdef __cplusplus
291 }
292 #endif /* __cplusplus */
293
294
295 #endif /* __GTK_TREE_PRIVATE_H__ */
296