]> Pileus Git - ~andy/gtk/blob - gtk/gtkctree.h
e430a19dd5f2cce2ef49960124db1cc461a4a33b
[~andy/gtk] / gtk / gtkctree.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald
3  * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>
4  *
5  * GtkCTree widget for GTK+
6  * Copyright (C) 1998 Lars Hamann and Stefan Jeske
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef __GTK_CTREE_H__
25 #define __GTK_CTREE_H__
26
27 #include <gtk/gtkclist.h>
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif                          /* __cplusplus */
33
34 #define GTK_TYPE_CTREE            (gtk_ctree_get_type ())
35 #define GTK_CTREE(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_CTREE, GtkCTree))
36 #define GTK_CTREE_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CTREE, GtkCTreeClass))
37 #define GTK_IS_CTREE(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_CTREE))
38 #define GTK_IS_CTREE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CTREE))
39
40 #define GTK_CTREE_ROW(_glist_) ((GtkCTreeRow *)((_glist_)->data))
41 #define GTK_CTREE_TREE(_ctree_, _glist_) \
42   ((GtkCellTree *) &(((GtkCTreeRow *)((_glist_)->data))->cell[(_ctree_)->tree_col]))
43
44 #define GTK_CTREE_FUNC(_func_) ((GtkCTreeFunc)(_func_))
45
46 typedef enum
47 {
48   GTK_CTREE_POS_BEFORE,
49   GTK_CTREE_POS_AS_CHILD,
50   GTK_CTREE_POS_AFTER
51 } GtkCTreePos;
52
53 typedef enum
54 {
55   GTK_CTREE_LINES_SOLID,
56   GTK_CTREE_LINES_DOTTED,
57   GTK_CTREE_LINES_TABBED,
58   GTK_CTREE_LINES_NONE
59 } GtkCTreeLineStyle;
60
61 typedef enum
62 {
63   GTK_CTREE_EXPANSION_EXPAND,
64   GTK_CTREE_EXPANSION_EXPAND_RECURSIVE,
65   GTK_CTREE_EXPANSION_COLLAPSE,
66   GTK_CTREE_EXPANSION_COLLAPSE_RECURSIVE,
67   GTK_CTREE_EXPANSION_TOGGLE,
68   GTK_CTREE_EXPANSION_TOGGLE_RECURSIVE
69 } GtkCTreeExpansionType;
70
71 typedef struct _GtkCTree      GtkCTree;
72 typedef struct _GtkCTreeClass GtkCTreeClass;
73 typedef struct _GtkCTreeRow   GtkCTreeRow;
74
75 typedef void (*GtkCTreeFunc) (GtkCTree *ctree,
76                               GList    *node,
77                               gpointer  data);
78
79 typedef gint (*GtkCTreeCompareFunc) (GtkCTree    *ctree,
80                                      const GList *node1,
81                                      const GList *node2);
82
83 struct _GtkCTree
84 {
85   GtkCList clist;
86
87   GdkGC *xor_gc;
88   GdkGC *lines_gc;
89   GdkWindow *drag_icon;
90   gint icon_width;
91   gint icon_height;
92
93   gint tree_indent;
94   gint tree_column;
95   gint drag_row;
96   GList *drag_source;
97   GList *drag_target;
98   gint insert_pos;
99   GtkCTreeCompareFunc node_compare;
100
101   guint auto_sort   : 1;
102   guint reorderable : 1;
103   guint use_icons   : 1;
104   guint in_drag     : 1;
105   guint drag_rect   : 1;
106   guint line_style  : 2;
107 };
108
109 struct _GtkCTreeClass
110 {
111   GtkCListClass parent_class;
112
113   void (*tree_select_row)   (GtkCTree *ctree,
114                              GList    *row,
115                              gint      column);
116   void (*tree_unselect_row) (GtkCTree *ctree,
117                              GList    *row,
118                              gint      column);
119   void (*tree_expand)       (GtkCTree *ctree,
120                              GList    *node);
121   void (*tree_collapse)     (GtkCTree *ctree,
122                              GList    *node);
123   void (*tree_move)         (GtkCTree *ctree,
124                              GList    *node,
125                              GList    *new_parent,
126                              GList    *new_sibling);
127   void (*change_focus_row_expansion) (GtkCTree *ctree,
128                                       GtkCTreeExpansionType action);
129 };
130
131 struct _GtkCTreeRow
132 {
133   GtkCListRow row;
134
135   GList *parent;
136   GList *sibling;
137   GList *children;
138
139   GdkPixmap *pixmap_closed;
140   GdkBitmap *mask_closed;
141   GdkPixmap *pixmap_opened;
142   GdkBitmap *mask_opened;
143
144   guint16 level;
145
146   guint is_leaf  : 1;
147   guint expanded : 1;
148 };
149
150
151 /***********************************************************
152  *           Creation, insertion, deletion                 *
153  ***********************************************************/
154
155 GtkType     gtk_ctree_get_type              (void);
156 void        gtk_ctree_construct             (GtkCTree     *ctree,
157                                              gint          columns, 
158                                              gint          tree_column,
159                                              gchar        *titles[]);
160 GtkWidget * gtk_ctree_new_with_titles       (gint          columns, 
161                                              gint          tree_column,
162                                              gchar        *titles[]);
163 GtkWidget * gtk_ctree_new                   (gint          columns, 
164                                              gint          tree_column);
165 GList *     gtk_ctree_insert                (GtkCTree     *ctree,
166                                              GList        *parent, 
167                                              GList        *sibling,
168                                              gchar        *text[],
169                                              guint8        spacing,
170                                              GdkPixmap    *pixmap_closed,
171                                              GdkBitmap    *mask_closed,
172                                              GdkPixmap    *pixmap_opened,
173                                              GdkBitmap    *mask_opened,
174                                              gboolean      is_leaf,
175                                              gboolean      expanded);
176 void       gtk_ctree_remove                 (GtkCTree     *ctree, 
177                                              GList        *node);
178
179 /***********************************************************
180  *  Generic recursive functions, querying / finding tree   *
181  *  information                                            *
182  ***********************************************************/
183
184 void       gtk_ctree_post_recursive          (GtkCTree     *ctree, 
185                                               GList        *node,
186                                               GtkCTreeFunc  func,
187                                               gpointer      data);
188 void       gtk_ctree_post_recursive_to_depth (GtkCTree     *ctree, 
189                                               GList        *node,
190                                               gint          depth,
191                                               GtkCTreeFunc  func,
192                                               gpointer      data);
193 void       gtk_ctree_pre_recursive           (GtkCTree     *ctree, 
194                                               GList        *node,
195                                               GtkCTreeFunc  func,
196                                               gpointer      data);
197 void       gtk_ctree_pre_recursive_to_depth  (GtkCTree     *ctree, 
198                                               GList        *node,
199                                               gint          depth,
200                                               GtkCTreeFunc  func,
201                                               gpointer      data);
202 gboolean   gtk_ctree_is_visible              (GtkCTree     *ctree, 
203                                               GList        *node);
204 GList *    gtk_ctree_last                    (GtkCTree     *ctree,
205                                               GList        *node);
206 GList *    gtk_ctree_find_glist_ptr          (GtkCTree     *ctree,
207                                               GtkCTreeRow  *ctree_row);
208 gint       gtk_ctree_find                    (GtkCTree     *ctree,
209                                               GList        *node,
210                                               GList        *child);
211 gboolean   gtk_ctree_is_ancestor             (GtkCTree     *ctree,
212                                               GList        *node,
213                                               GList        *child);
214 GList *    gtk_ctree_find_by_row_data        (GtkCTree     *ctree,
215                                               GList        *node,
216                                               gpointer      data);
217 gboolean   gtk_ctree_is_hot_spot             (GtkCTree     *ctree,
218                                               gint          x,
219                                               gint          y);
220
221 /***********************************************************
222  *   Tree signals : move, expand, collapse, (un)select     *
223  ***********************************************************/
224
225 void       gtk_ctree_move                   (GtkCTree     *ctree,
226                                              GList        *node,
227                                              GList        *new_parent, 
228                                              GList        *new_sibling);
229 void       gtk_ctree_expand                 (GtkCTree     *ctree,
230                                              GList        *node);
231 void       gtk_ctree_expand_recursive       (GtkCTree     *ctree,
232                                              GList        *node);
233 void       gtk_ctree_expand_to_depth        (GtkCTree     *ctree,
234                                              GList        *node,
235                                              gint          depth);
236 void       gtk_ctree_collapse               (GtkCTree     *ctree,
237                                              GList        *node);
238 void       gtk_ctree_collapse_recursive     (GtkCTree     *ctree,
239                                              GList        *node);
240 void       gtk_ctree_collapse_to_depth      (GtkCTree     *ctree,
241                                              GList        *node,
242                                              gint          depth);
243 void       gtk_ctree_toggle_expansion       (GtkCTree     *ctree,
244                                              GList        *node);
245 void       gtk_ctree_toggle_expansion_recursive (GtkCTree *ctree,
246                                                  GList    *node);
247 void       gtk_ctree_select                 (GtkCTree     *ctree, 
248                                              GList        *node);
249 void       gtk_ctree_select_recursive       (GtkCTree     *ctree, 
250                                              GList        *node);
251 void       gtk_ctree_unselect               (GtkCTree     *ctree, 
252                                              GList        *node);
253 void       gtk_ctree_unselect_recursive     (GtkCTree     *ctree, 
254                                              GList        *node);
255 void       gtk_ctree_real_select_recursive  (GtkCTree     *ctree, 
256                                              GList        *node, 
257                                              gint          state);
258
259 /***********************************************************
260  *           Analogons of GtkCList functions               *
261  ***********************************************************/
262
263 void       gtk_ctree_set_text               (GtkCTree     *ctree,
264                                              GList        *node,
265                                              gint          column,
266                                              gchar        *text);
267 void       gtk_ctree_set_pixmap             (GtkCTree     *ctree,
268                                              GList        *node,
269                                              gint          column,
270                                              GdkPixmap    *pixmap,
271                                              GdkBitmap    *mask);
272 void       gtk_ctree_set_pixtext            (GtkCTree     *ctree,
273                                              GList        *node,
274                                              gint          column,
275                                              gchar        *text,
276                                              guint8        spacing,
277                                              GdkPixmap    *pixmap,
278                                              GdkBitmap    *mask);
279 void       gtk_ctree_set_node_info          (GtkCTree     *ctree,
280                                              GList        *node,
281                                              gchar        *text,
282                                              guint8        spacing,
283                                              GdkPixmap    *pixmap_closed,
284                                              GdkBitmap    *mask_closed,
285                                              GdkPixmap    *pixmap_opened,
286                                              GdkBitmap    *mask_opened,
287                                              gboolean      is_leaf,
288                                              gboolean      expanded);
289 void       gtk_ctree_set_shift              (GtkCTree     *ctree,
290                                              GList        *node,
291                                              gint          column,
292                                              gint          vertical,
293                                              gint          horizontal);
294 GtkCellType gtk_ctree_get_cell_type         (GtkCTree     *ctree,
295                                              GList        *node,
296                                              gint          column);
297 gint       gtk_ctree_get_text               (GtkCTree     *ctree,
298                                              GList        *node,
299                                              gint          column,
300                                              gchar       **text);
301 gint       gtk_ctree_get_pixmap             (GtkCTree     *ctree,
302                                              GList        *node,
303                                              gint          column,
304                                              GdkPixmap   **pixmap,
305                                              GdkBitmap   **mask);
306 gint       gtk_ctree_get_pixtext            (GtkCTree     *ctree,
307                                              GList        *node,
308                                              gint          column,
309                                              gchar       **text,
310                                              guint8       *spacing,
311                                              GdkPixmap   **pixmap,
312                                              GdkBitmap   **mask);
313 gint       gtk_ctree_get_node_info          (GtkCTree     *ctree,
314                                              GList        *node,
315                                              gchar       **text,
316                                              guint8       *spacing,
317                                              GdkPixmap   **pixmap_closed,
318                                              GdkBitmap   **mask_closed,
319                                              GdkPixmap   **pixmap_opened,
320                                              GdkBitmap   **mask_opened,
321                                              gboolean     *is_leaf,
322                                              gboolean     *expanded);
323 void       gtk_ctree_set_foreground         (GtkCTree     *ctree,
324                                              GList        *node,
325                                              GdkColor     *color);
326 void       gtk_ctree_set_background         (GtkCTree     *ctree,
327                                              GList        *node,
328                                              GdkColor     *color);
329 void       gtk_ctree_set_row_data           (GtkCTree     *ctree,
330                                              GList        *node,
331                                              gpointer      data);
332 void       gtk_ctree_set_row_data_full      (GtkCTree     *ctree,
333                                              GList        *node,
334                                              gpointer      data,
335                                              GtkDestroyNotify destroy);
336 gpointer   gtk_ctree_get_row_data           (GtkCTree     *ctree,
337                                              GList        *node);
338 void       gtk_ctree_moveto                 (GtkCTree     *ctree,
339                                              GList        *node,
340                                              gint          column,
341                                              gfloat        row_align,
342                                              gfloat        col_align);
343
344 /***********************************************************
345  *             GtkCTree specific functions                 *
346  ***********************************************************/
347
348 void       gtk_ctree_set_indent             (GtkCTree     *ctree, 
349                                              gint          indent);
350 void       gtk_ctree_set_reorderable        (GtkCTree     *ctree,
351                                              gboolean      reorderable);
352 void       gtk_ctree_set_use_drag_icons     (GtkCTree     *ctree,
353                                              gboolean      use_icons);
354 void       gtk_ctree_set_line_style         (GtkCTree     *ctree, 
355                                              GtkCTreeLineStyle line_style);
356
357 /***********************************************************
358  *             Tree sorting functions                      *
359  ***********************************************************/
360
361 void       gtk_ctree_set_auto_sort          (GtkCTree     *ctree,
362                                              gboolean      auto_sort);
363 void       gtk_ctree_set_compare_func       (GtkCTree     *ctree,
364                                              GtkCTreeCompareFunc cmp_func);
365 void       gtk_ctree_sort                   (GtkCTree     *ctree, 
366                                              GList        *node);
367 void       gtk_ctree_sort_recursive         (GtkCTree     *ctree, 
368                                              GList        *node);
369
370 #ifdef __cplusplus
371 }
372 #endif                          /* __cplusplus */
373
374 #endif                          /* __GTK_CTREE_H__ */