]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeprivate.h
Patch Thomas Broyer from <tbroyer@ltgt.net>. Expander arrows are now
[~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 struct _GtkTreeViewColumnReorder GtkTreeViewColumnReorder;
70 struct _GtkTreeViewColumnReorder
71 {
72   gint left_align;
73   gint right_align;
74   GtkTreeViewColumn *left_column;
75   GtkTreeViewColumn *right_column;
76 };
77
78 struct _GtkTreeViewPrivate
79 {
80   GtkTreeModel *model;
81
82   guint flags;
83   /* tree information */
84   GtkRBTree *tree;
85
86   gint tab_offset;
87   GtkRBNode *button_pressed_node;
88   GtkRBTree *button_pressed_tree;
89
90   GList *children;
91   gint width;
92   gint height;
93
94   GtkAdjustment *hadjustment;
95   GtkAdjustment *vadjustment;
96
97   GdkWindow *bin_window;
98   GdkWindow *header_window;
99   GdkWindow *drag_window;
100   GdkWindow *drag_highlight_window;
101   GtkTreeViewColumn *drag_column;
102   gint drag_column_x;
103
104   GtkTreeViewColumn *expander_column;
105
106   /* Focus code */
107   GtkTreeViewColumn *focus_column;
108   GtkTreeViewColumn *scroll_column;
109
110   /* Selection stuff */
111   GtkTreeRowReference *anchor;
112   GtkTreeRowReference *cursor;
113
114   /* Column Resizing */
115   GdkCursor *cursor_drag;
116   GdkGC *xor_gc;
117   gint drag_pos;
118   gint x_drag;
119
120   /* Prelight information */
121   GtkRBNode *prelight_node;
122   GtkRBTree *prelight_tree;
123
124   /* Selection information */
125   GtkTreeSelection *selection;
126
127   /* Header information */
128   gint n_columns;
129   GList *columns;
130   gint header_height;
131
132   GtkTreeViewColumnDropFunc column_drop_func;
133   gpointer column_drop_func_data;
134   GtkDestroyNotify column_drop_func_data_destroy;
135   GList *column_drag_info;
136   GtkTreeViewColumnReorder *cur_reorder;
137
138   /* ATK Hack */
139   GtkTreeDestroyCountFunc destroy_count_func;
140   gpointer destroy_count_data;
141   GtkDestroyNotify destroy_count_destroy;
142
143   /* Scroll timeout (e.g. during dnd) */
144   guint scroll_timeout;
145
146   /* Row drag-and-drop */
147   GtkTreeRowReference *drag_dest_row;
148   GtkTreeViewDropPosition drag_dest_pos;
149   guint open_dest_timeout;
150
151   gint pressed_button;
152   gint press_start_x;
153   gint press_start_y;
154
155   /* Scroll-to functionality when unrealized */
156   GtkTreePath *scroll_to_path;
157   GtkTreeViewColumn *scroll_to_column;
158   gfloat scroll_to_row_align;
159   gfloat scroll_to_col_align;
160
161   guint reorderable : 1;
162   guint header_has_focus : 1;
163   guint drag_column_window_state : 3;
164   /* hint to display rows in alternating colors */
165   guint has_rules : 1;
166
167   guint in_extended_selection : 1;
168   guint in_free_motion : 1;
169 };
170
171 #ifdef __GNUC__
172
173 #define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
174      if (!(expr))                                                       \
175        {                                                                \
176          g_log (G_LOG_DOMAIN,                                           \
177                 G_LOG_LEVEL_CRITICAL,                                   \
178                 "file %s: line %d (%s): assertion `%s' failed.\n"       \
179                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
180                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
181                 "without letting the view know.  Any display from now on is likely to\n"  \
182                 "be incorrect.\n",                                                        \
183                 __FILE__,                                               \
184                 __LINE__,                                               \
185                 __PRETTY_FUNCTION__,                                    \
186                 #expr);                                                 \
187          return ret;                                                    \
188        };                               }G_STMT_END
189
190 #define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{             \
191      if (!(expr))                                                       \
192        {                                                                \
193          g_log (G_LOG_DOMAIN,                                           \
194                 G_LOG_LEVEL_CRITICAL,                                   \
195                 "file %s: line %d (%s): assertion `%s' failed.\n"       \
196                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
197                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
198                 "without letting the view know.  Any display from now on is likely to\n"  \
199                 "be incorrect.\n",                                                        \
200                 __FILE__,                                               \
201                 __LINE__,                                               \
202                 __PRETTY_FUNCTION__,                                    \
203                 #expr);                                                 \
204          return;                                                        \
205        };                               }G_STMT_END
206
207 #else
208
209 #define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
210      if (!(expr))                                                       \
211        {                                                                \
212          g_log (G_LOG_DOMAIN,                                           \
213                 G_LOG_LEVEL_CRITICAL,                                   \
214                 "file %s: line %d: assertion `%s' failed.\n"       \
215                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
216                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
217                 "without letting the view know.  Any display from now on is likely to\n"  \
218                 "be incorrect.\n",                                                        \
219                 __FILE__,                                               \
220                 __LINE__,                                               \
221                 #expr);                                                 \
222          return ret;                                                    \
223        };                               }G_STMT_END
224
225 #define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{          \
226      if (!(expr))                                                       \
227        {                                                                \
228          g_log (G_LOG_DOMAIN,                                           \
229                 G_LOG_LEVEL_CRITICAL,                                   \
230                 "file %s: line %d: assertion '%s' failed.\n"            \
231                 "There is a disparity between the internal view of the GtkTreeView,\n"    \
232                 "and the GtkTreeModel.  This generally means that the model has changed\n"\
233                 "without letting the view know.  Any display from now on is likely to\n"  \
234                 "be incorrect.\n",                                                        \
235                 __FILE__,                                               \
236                 __LINE__,                                               \
237                 #expr);                                                 \
238          return;                                                        \
239        };                               }G_STMT_END
240 #endif
241
242
243 /* functions that shouldn't be exported */
244 void         _gtk_tree_selection_internal_select_node (GtkTreeSelection  *selection,
245                                                        GtkRBNode         *node,
246                                                        GtkRBTree         *tree,
247                                                        GtkTreePath       *path,
248                                                        GdkModifierType    state);
249 gboolean     _gtk_tree_view_find_node                 (GtkTreeView       *tree_view,
250                                                        GtkTreePath       *path,
251                                                        GtkRBTree        **tree,
252                                                        GtkRBNode        **node);
253 GtkTreePath *_gtk_tree_view_find_path                 (GtkTreeView       *tree_view,
254                                                        GtkRBTree         *tree,
255                                                        GtkRBNode         *node);
256 void         _gtk_tree_view_update_size               (GtkTreeView       *tree_view);
257
258
259 void _gtk_tree_view_column_realize_button   (GtkTreeViewColumn *column);
260 void _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column);
261 void _gtk_tree_view_column_set_tree_view    (GtkTreeViewColumn *column,
262                                              GtkTreeView       *tree_view);
263 void _gtk_tree_view_column_unset_tree_view  (GtkTreeViewColumn *column);
264 void _gtk_tree_view_column_set_width        (GtkTreeViewColumn *column,
265                                              gint               width);
266 void _gtk_tree_view_column_start_drag       (GtkTreeView       *tree_view,
267                                              GtkTreeViewColumn *column);
268
269 GtkTreeSelection* _gtk_tree_selection_new                (void);
270 GtkTreeSelection* _gtk_tree_selection_new_with_tree_view (GtkTreeView      *tree_view);
271 void              _gtk_tree_selection_set_tree_view      (GtkTreeSelection *selection,
272                                                           GtkTreeView      *tree_view);
273
274
275
276
277 #ifdef __cplusplus
278 }
279 #endif /* __cplusplus */
280
281
282 #endif /* __GTK_TREE_PRIVATE_H__ */
283