2009-01-02 [colin] 3.7.0cvs8
[claws.git] / src / gtk / gtkcmctree.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  * GtkCMCTree 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 Lesser 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  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser 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 /*
25  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
26  * file for a list of people on the GTK+ Team.  See the ChangeLog
27  * files for a list of changes.  These files are distributed with
28  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
29  */
30
31 #ifndef __GTK_CMCTREE_H__
32 #define __GTK_CMCTREE_H__
33
34 #include "gtkcmclist.h"
35
36 G_BEGIN_DECLS
37
38 #define GTK_TYPE_CMCTREE            (gtk_cmctree_get_type ())
39 #define GTK_CMCTREE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CMCTREE, GtkCMCTree))
40 #define GTK_CMCTREE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CMCTREE, GtkCMCTreeClass))
41 #define GTK_IS_CMCTREE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CMCTREE))
42 #define GTK_IS_CMCTREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CMCTREE))
43 #define GTK_CMCTREE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CMCTREE, GtkCMCTreeClass))
44
45 #define GTK_CMCTREE_ROW(_node_) ((GtkCMCTreeRow *)(((GList *)(_node_))->data))
46 #define GTK_CMCTREE_NODE(_node_) ((GtkCMCTreeNode *)((_node_)))
47 #define GTK_CMCTREE_NODE_NEXT(_nnode_) ((GtkCMCTreeNode *)(((GList *)(_nnode_))->next))
48 #define GTK_CMCTREE_NODE_PREV(_pnode_) ((GtkCMCTreeNode *)(((GList *)(_pnode_))->prev))
49 #define GTK_CMCTREE_FUNC(_func_) ((GtkCMCTreeFunc)(_func_))
50
51 #define GTK_TYPE_CMCTREE_NODE (gtk_cmctree_node_get_type ())
52
53 GType gtk_cmctree_pos_get_type (void) G_GNUC_CONST;
54 #define GTK_TYPE_CMCTREE_POS (gtk_cmctree_pos_get_type())
55 GType gtk_cmctree_line_style_get_type (void) G_GNUC_CONST;
56 #define GTK_TYPE_CMCTREE_LINE_STYLE (gtk_cmctree_line_style_get_type())
57 GType gtk_cmctree_expander_style_get_type (void) G_GNUC_CONST;
58 #define GTK_TYPE_CMCTREE_EXPANDER_STYLE (gtk_cmctree_expander_style_get_type())
59 GType gtk_cmctree_expansion_type_get_type (void) G_GNUC_CONST;
60 #define GTK_TYPE_CMCTREE_EXPANSION_TYPE (gtk_cmctree_expansion_type_get_type())
61
62 typedef enum
63 {
64   GTK_CMCTREE_POS_BEFORE,
65   GTK_CMCTREE_POS_AS_CHILD,
66   GTK_CMCTREE_POS_AFTER
67 } GtkCMCTreePos;
68
69 typedef enum
70 {
71   GTK_CMCTREE_LINES_NONE,
72   GTK_CMCTREE_LINES_SOLID,
73   GTK_CMCTREE_LINES_DOTTED,
74   GTK_CMCTREE_LINES_TABBED
75 } GtkCMCTreeLineStyle;
76
77 typedef enum
78 {
79   GTK_CMCTREE_EXPANDER_NONE,
80   GTK_CMCTREE_EXPANDER_SQUARE,
81   GTK_CMCTREE_EXPANDER_TRIANGLE,
82   GTK_CMCTREE_EXPANDER_CIRCULAR
83 } GtkCMCTreeExpanderStyle;
84
85 typedef enum
86 {
87   GTK_CMCTREE_EXPANSION_EXPAND,
88   GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE,
89   GTK_CMCTREE_EXPANSION_COLLAPSE,
90   GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE,
91   GTK_CMCTREE_EXPANSION_TOGGLE,
92   GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE
93 } GtkCMCTreeExpansionType;
94
95 typedef struct _GtkCMCTree      GtkCMCTree;
96 typedef struct _GtkCMCTreeClass GtkCMCTreeClass;
97 typedef struct _GtkCMCTreeRow   GtkCMCTreeRow;
98 typedef struct _GtkCMCTreeNode  GtkCMCTreeNode;
99
100 typedef void (*GtkCMCTreeFunc) (GtkCMCTree     *ctree,
101                               GtkCMCTreeNode *node,
102                               gpointer      data);
103
104 typedef gboolean (*GtkCMCTreeGNodeFunc) (GtkCMCTree     *ctree,
105                                        guint         depth,
106                                        GNode        *gnode,
107                                        GtkCMCTreeNode *cnode,
108                                        gpointer      data);
109
110 typedef gboolean (*GtkCMCTreeCompareDragFunc) (GtkCMCTree     *ctree,
111                                              GtkCMCTreeNode *source_node,
112                                              GtkCMCTreeNode *new_parent,
113                                              GtkCMCTreeNode *new_sibling);
114
115 struct _GtkCMCTree
116 {
117   GtkCMCList clist;
118   
119   GdkGC *lines_gc;
120   
121   gint tree_indent;
122   gint tree_spacing;
123   gint tree_column;
124
125   guint line_style     : 2;
126   guint expander_style : 2;
127   guint show_stub      : 1;
128
129   GtkCMCTreeCompareDragFunc drag_compare;
130 };
131
132 struct _GtkCMCTreeClass
133 {
134   GtkCMCListClass parent_class;
135   
136   void (*tree_select_row)   (GtkCMCTree     *ctree,
137                              GtkCMCTreeNode *row,
138                              gint          column);
139   void (*tree_unselect_row) (GtkCMCTree     *ctree,
140                              GtkCMCTreeNode *row,
141                              gint          column);
142   void (*tree_expand)       (GtkCMCTree     *ctree,
143                              GtkCMCTreeNode *node);
144   void (*tree_collapse)     (GtkCMCTree     *ctree,
145                              GtkCMCTreeNode *node);
146   void (*tree_move)         (GtkCMCTree     *ctree,
147                              GtkCMCTreeNode *node,
148                              GtkCMCTreeNode *new_parent,
149                              GtkCMCTreeNode *new_sibling);
150   void (*change_focus_row_expansion) (GtkCMCTree *ctree,
151                                       GtkCMCTreeExpansionType action);
152 };
153
154 struct _GtkCMCTreeRow
155 {
156   GtkCMCListRow row;
157   
158   GtkCMCTreeNode *parent;
159   GtkCMCTreeNode *sibling;
160   GtkCMCTreeNode *children;
161   
162   GdkPixbuf *pixbuf_closed;
163   GdkPixbuf *pixbuf_opened;
164   
165   guint16 level;
166   
167   guint is_leaf  : 1;
168   guint expanded : 1;
169 };
170
171 struct _GtkCMCTreeNode {
172   GList list;
173 };
174
175
176 /***********************************************************
177  *           Creation, insertion, deletion                 *
178  ***********************************************************/
179
180 GType gtk_cmctree_get_type                       (void);
181 GtkWidget * gtk_cmctree_new_with_titles            (gint          columns, 
182                                                   gint          tree_column,
183                                                   gchar        *titles[]);
184 GtkWidget * gtk_cmctree_new                        (gint          columns, 
185                                                   gint          tree_column);
186 GtkCMCTreeNode * gtk_cmctree_insert_node             (GtkCMCTree     *ctree,
187                                                   GtkCMCTreeNode *parent, 
188                                                   GtkCMCTreeNode *sibling,
189                                                   gchar        *text[],
190                                                   guint8        spacing,
191                                                   GdkPixbuf    *pixbuf_closed,
192                                                   GdkPixbuf    *pixbuf_opened,
193                                                   gboolean      is_leaf,
194                                                   gboolean      expanded);
195 void gtk_cmctree_remove_node                       (GtkCMCTree     *ctree, 
196                                                   GtkCMCTreeNode *node);
197 GtkCMCTreeNode * gtk_cmctree_insert_gnode            (GtkCMCTree          *ctree,
198                                                   GtkCMCTreeNode      *parent,
199                                                   GtkCMCTreeNode      *sibling,
200                                                   GNode             *gnode,
201                                                   GtkCMCTreeGNodeFunc  func,
202                                                   gpointer           data);
203 GNode * gtk_cmctree_export_to_gnode                (GtkCMCTree          *ctree,
204                                                   GNode             *parent,
205                                                   GNode             *sibling,
206                                                   GtkCMCTreeNode      *node,
207                                                   GtkCMCTreeGNodeFunc  func,
208                                                   gpointer           data);
209
210 /***********************************************************
211  *  Generic recursive functions, querying / finding tree   *
212  *  information                                            *
213  ***********************************************************/
214
215 void gtk_cmctree_post_recursive                    (GtkCMCTree     *ctree, 
216                                                   GtkCMCTreeNode *node,
217                                                   GtkCMCTreeFunc  func,
218                                                   gpointer      data);
219 void gtk_cmctree_post_recursive_to_depth           (GtkCMCTree     *ctree, 
220                                                   GtkCMCTreeNode *node,
221                                                   gint          depth,
222                                                   GtkCMCTreeFunc  func,
223                                                   gpointer      data);
224 void gtk_cmctree_pre_recursive                     (GtkCMCTree     *ctree, 
225                                                   GtkCMCTreeNode *node,
226                                                   GtkCMCTreeFunc  func,
227                                                   gpointer      data);
228 void gtk_cmctree_pre_recursive_to_depth            (GtkCMCTree     *ctree, 
229                                                   GtkCMCTreeNode *node,
230                                                   gint          depth,
231                                                   GtkCMCTreeFunc  func,
232                                                   gpointer      data);
233 gboolean gtk_cmctree_is_viewable                   (GtkCMCTree     *ctree, 
234                                                   GtkCMCTreeNode *node);
235 GtkCMCTreeNode * gtk_cmctree_last                    (GtkCMCTree     *ctree,
236                                                   GtkCMCTreeNode *node);
237 GtkCMCTreeNode * gtk_cmctree_find_node_ptr           (GtkCMCTree     *ctree,
238                                                   GtkCMCTreeRow  *ctree_row);
239 GtkCMCTreeNode * gtk_cmctree_node_nth                (GtkCMCTree     *ctree,
240                                                   guint         row);
241 gboolean gtk_cmctree_find                          (GtkCMCTree     *ctree,
242                                                   GtkCMCTreeNode *node,
243                                                   GtkCMCTreeNode *child);
244 gboolean gtk_cmctree_is_ancestor                   (GtkCMCTree     *ctree,
245                                                   GtkCMCTreeNode *node,
246                                                   GtkCMCTreeNode *child);
247 GtkCMCTreeNode * gtk_cmctree_find_by_row_data        (GtkCMCTree     *ctree,
248                                                   GtkCMCTreeNode *node,
249                                                   gpointer      data);
250 /* returns a GList of all GtkCMCTreeNodes with row->data == data. */
251 GList * gtk_cmctree_find_all_by_row_data           (GtkCMCTree     *ctree,
252                                                   GtkCMCTreeNode *node,
253                                                   gpointer      data);
254 GtkCMCTreeNode * gtk_cmctree_find_by_row_data_custom (GtkCMCTree     *ctree,
255                                                   GtkCMCTreeNode *node,
256                                                   gpointer      data,
257                                                   GCompareFunc  func);
258 /* returns a GList of all GtkCMCTreeNodes with row->data == data. */
259 GList * gtk_cmctree_find_all_by_row_data_custom    (GtkCMCTree     *ctree,
260                                                   GtkCMCTreeNode *node,
261                                                   gpointer      data,
262                                                   GCompareFunc  func);
263 gboolean gtk_cmctree_is_hot_spot                   (GtkCMCTree     *ctree,
264                                                   gint          x,
265                                                   gint          y);
266
267 /***********************************************************
268  *   Tree signals : move, expand, collapse, (un)select     *
269  ***********************************************************/
270
271 void gtk_cmctree_move                              (GtkCMCTree     *ctree,
272                                                   GtkCMCTreeNode *node,
273                                                   GtkCMCTreeNode *new_parent, 
274                                                   GtkCMCTreeNode *new_sibling);
275 void gtk_cmctree_expand                            (GtkCMCTree     *ctree,
276                                                   GtkCMCTreeNode *node);
277 void gtk_cmctree_expand_recursive                  (GtkCMCTree     *ctree,
278                                                   GtkCMCTreeNode *node);
279 void gtk_cmctree_expand_to_depth                   (GtkCMCTree     *ctree,
280                                                   GtkCMCTreeNode *node,
281                                                   gint          depth);
282 void gtk_cmctree_collapse                          (GtkCMCTree     *ctree,
283                                                   GtkCMCTreeNode *node);
284 void gtk_cmctree_collapse_recursive                (GtkCMCTree     *ctree,
285                                                   GtkCMCTreeNode *node);
286 void gtk_cmctree_collapse_to_depth                 (GtkCMCTree     *ctree,
287                                                   GtkCMCTreeNode *node,
288                                                   gint          depth);
289 void gtk_cmctree_toggle_expansion                  (GtkCMCTree     *ctree,
290                                                   GtkCMCTreeNode *node);
291 void gtk_cmctree_toggle_expansion_recursive        (GtkCMCTree     *ctree,
292                                                   GtkCMCTreeNode *node);
293 void gtk_cmctree_select                            (GtkCMCTree     *ctree, 
294                                                   GtkCMCTreeNode *node);
295 void gtk_cmctree_select_recursive                  (GtkCMCTree     *ctree, 
296                                                   GtkCMCTreeNode *node);
297 void gtk_cmctree_unselect                          (GtkCMCTree     *ctree, 
298                                                   GtkCMCTreeNode *node);
299 void gtk_cmctree_unselect_recursive                (GtkCMCTree     *ctree, 
300                                                   GtkCMCTreeNode *node);
301 void gtk_cmctree_real_select_recursive             (GtkCMCTree     *ctree, 
302                                                   GtkCMCTreeNode *node, 
303                                                   gint          state);
304
305 /***********************************************************
306  *           Analogons of GtkCMCList functions               *
307  ***********************************************************/
308
309 void gtk_cmctree_node_set_text                     (GtkCMCTree     *ctree,
310                                                   GtkCMCTreeNode *node,
311                                                   gint          column,
312                                                   const gchar  *text);
313 void gtk_cmctree_node_set_pixbuf                   (GtkCMCTree     *ctree,
314                                                   GtkCMCTreeNode *node,
315                                                   gint          column,
316                                                   GdkPixbuf    *pixbuf);
317 void gtk_cmctree_node_set_pixtext                  (GtkCMCTree     *ctree,
318                                                   GtkCMCTreeNode *node,
319                                                   gint          column,
320                                                   const gchar  *text,
321                                                   guint8        spacing,
322                                                   GdkPixbuf    *pixbuf);
323 void gtk_cmctree_set_node_info                     (GtkCMCTree     *ctree,
324                                                   GtkCMCTreeNode *node,
325                                                   const gchar  *text,
326                                                   guint8        spacing,
327                                                   GdkPixbuf    *pixbuf_closed,
328                                                   GdkPixbuf    *pixbuf_opened,
329                                                   gboolean      is_leaf,
330                                                   gboolean      expanded);
331 void gtk_cmctree_node_set_shift                    (GtkCMCTree     *ctree,
332                                                   GtkCMCTreeNode *node,
333                                                   gint          column,
334                                                   gint          vertical,
335                                                   gint          horizontal);
336 void gtk_cmctree_node_set_selectable               (GtkCMCTree     *ctree,
337                                                   GtkCMCTreeNode *node,
338                                                   gboolean      selectable);
339 gboolean gtk_cmctree_node_get_selectable           (GtkCMCTree     *ctree,
340                                                   GtkCMCTreeNode *node);
341 GtkCMCellType gtk_cmctree_node_get_cell_type         (GtkCMCTree     *ctree,
342                                                   GtkCMCTreeNode *node,
343                                                   gint          column);
344 gboolean gtk_cmctree_node_get_text                 (GtkCMCTree     *ctree,
345                                                   GtkCMCTreeNode *node,
346                                                   gint          column,
347                                                   gchar       **text);
348 gboolean gtk_cmctree_node_get_pixbuf               (GtkCMCTree     *ctree,
349                                                   GtkCMCTreeNode *node,
350                                                   gint          column,
351                                                   GdkPixbuf   **pixbuf);
352 gboolean gtk_cmctree_node_get_pixtext              (GtkCMCTree     *ctree,
353                                                   GtkCMCTreeNode *node,
354                                                   gint          column,
355                                                   gchar       **text,
356                                                   guint8       *spacing,
357                                                   GdkPixbuf   **pixbuf);
358 gboolean gtk_cmctree_get_node_info                 (GtkCMCTree     *ctree,
359                                                   GtkCMCTreeNode *node,
360                                                   gchar       **text,
361                                                   guint8       *spacing,
362                                                   GdkPixbuf   **pixbuf_closed,
363                                                   GdkPixbuf   **pixbuf_opened,
364                                                   gboolean     *is_leaf,
365                                                   gboolean     *expanded);
366 void gtk_cmctree_node_set_row_style                (GtkCMCTree     *ctree,
367                                                   GtkCMCTreeNode *node,
368                                                   GtkStyle     *style);
369 GtkStyle * gtk_cmctree_node_get_row_style          (GtkCMCTree     *ctree,
370                                                   GtkCMCTreeNode *node);
371 void gtk_cmctree_node_set_cell_style               (GtkCMCTree     *ctree,
372                                                   GtkCMCTreeNode *node,
373                                                   gint          column,
374                                                   GtkStyle     *style);
375 GtkStyle * gtk_cmctree_node_get_cell_style         (GtkCMCTree     *ctree,
376                                                   GtkCMCTreeNode *node,
377                                                   gint          column);
378 void gtk_cmctree_node_set_foreground               (GtkCMCTree       *ctree,
379                                                   GtkCMCTreeNode   *node,
380                                                   const GdkColor *color);
381 void gtk_cmctree_node_set_background               (GtkCMCTree       *ctree,
382                                                   GtkCMCTreeNode   *node,
383                                                   const GdkColor *color);
384 void gtk_cmctree_node_set_row_data                 (GtkCMCTree     *ctree,
385                                                   GtkCMCTreeNode *node,
386                                                   gpointer      data);
387 void gtk_cmctree_node_set_row_data_full            (GtkCMCTree     *ctree,
388                                                   GtkCMCTreeNode *node,
389                                                   gpointer      data,
390                                                   GDestroyNotify destroy);
391 gpointer gtk_cmctree_node_get_row_data             (GtkCMCTree     *ctree,
392                                                   GtkCMCTreeNode *node);
393 void gtk_cmctree_node_moveto                       (GtkCMCTree     *ctree,
394                                                   GtkCMCTreeNode *node,
395                                                   gint          column,
396                                                   gfloat        row_align,
397                                                   gfloat        col_align);
398 GtkVisibility gtk_cmctree_node_is_visible          (GtkCMCTree     *ctree,
399                                                   GtkCMCTreeNode *node);
400
401 /***********************************************************
402  *             GtkCMCTree specific functions                 *
403  ***********************************************************/
404
405 void gtk_cmctree_set_indent            (GtkCMCTree                *ctree, 
406                                       gint                     indent);
407 void gtk_cmctree_set_spacing           (GtkCMCTree                *ctree, 
408                                       gint                     spacing);
409 void gtk_cmctree_set_show_stub         (GtkCMCTree                *ctree, 
410                                       gboolean                 show_stub);
411 void gtk_cmctree_set_line_style        (GtkCMCTree                *ctree, 
412                                       GtkCMCTreeLineStyle        line_style);
413 void gtk_cmctree_set_expander_style    (GtkCMCTree                *ctree, 
414                                       GtkCMCTreeExpanderStyle    expander_style);
415 void gtk_cmctree_set_drag_compare_func (GtkCMCTree            *ctree,
416                                       GtkCMCTreeCompareDragFunc  cmp_func);
417
418 /***********************************************************
419  *             Tree sorting functions                      *
420  ***********************************************************/
421
422 void gtk_cmctree_sort_node                         (GtkCMCTree     *ctree, 
423                                                   GtkCMCTreeNode *node);
424 void gtk_cmctree_sort_recursive                    (GtkCMCTree     *ctree, 
425                                                   GtkCMCTreeNode *node);
426
427
428 #define gtk_cmctree_set_reorderable(t,r)                    gtk_cmclist_set_reorderable((GtkCMCList*) (t),(r))
429
430 /* GType for the GtkCMCTreeNode.  This is a boxed type, although it uses
431  * no-op's for the copy and free routines.  It is defined in order to
432  * provide type information for the signal arguments
433  */
434 GType   gtk_cmctree_node_get_type                  (void) G_GNUC_CONST;
435
436 G_END_DECLS
437
438 #endif                          /* __GTK_CMCTREE_H__ */