4e4b0b60a7ea1daa0e948b5c10dc38a33e37f940
[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   GdkPixmap *pixmap_closed;
163   GdkBitmap *mask_closed;
164   GdkPixmap *pixmap_opened;
165   GdkBitmap *mask_opened;
166   
167   guint16 level;
168   
169   guint is_leaf  : 1;
170   guint expanded : 1;
171 };
172
173 struct _GtkCMCTreeNode {
174   GList list;
175 };
176
177
178 /***********************************************************
179  *           Creation, insertion, deletion                 *
180  ***********************************************************/
181
182 GType gtk_cmctree_get_type                       (void);
183 GtkWidget * gtk_cmctree_new_with_titles            (gint          columns, 
184                                                   gint          tree_column,
185                                                   gchar        *titles[]);
186 GtkWidget * gtk_cmctree_new                        (gint          columns, 
187                                                   gint          tree_column);
188 GtkCMCTreeNode * gtk_cmctree_insert_node             (GtkCMCTree     *ctree,
189                                                   GtkCMCTreeNode *parent, 
190                                                   GtkCMCTreeNode *sibling,
191                                                   gchar        *text[],
192                                                   guint8        spacing,
193                                                   GdkPixmap    *pixmap_closed,
194                                                   GdkBitmap    *mask_closed,
195                                                   GdkPixmap    *pixmap_opened,
196                                                   GdkBitmap    *mask_opened,
197                                                   gboolean      is_leaf,
198                                                   gboolean      expanded);
199 void gtk_cmctree_remove_node                       (GtkCMCTree     *ctree, 
200                                                   GtkCMCTreeNode *node);
201 GtkCMCTreeNode * gtk_cmctree_insert_gnode            (GtkCMCTree          *ctree,
202                                                   GtkCMCTreeNode      *parent,
203                                                   GtkCMCTreeNode      *sibling,
204                                                   GNode             *gnode,
205                                                   GtkCMCTreeGNodeFunc  func,
206                                                   gpointer           data);
207 GNode * gtk_cmctree_export_to_gnode                (GtkCMCTree          *ctree,
208                                                   GNode             *parent,
209                                                   GNode             *sibling,
210                                                   GtkCMCTreeNode      *node,
211                                                   GtkCMCTreeGNodeFunc  func,
212                                                   gpointer           data);
213
214 /***********************************************************
215  *  Generic recursive functions, querying / finding tree   *
216  *  information                                            *
217  ***********************************************************/
218
219 void gtk_cmctree_post_recursive                    (GtkCMCTree     *ctree, 
220                                                   GtkCMCTreeNode *node,
221                                                   GtkCMCTreeFunc  func,
222                                                   gpointer      data);
223 void gtk_cmctree_post_recursive_to_depth           (GtkCMCTree     *ctree, 
224                                                   GtkCMCTreeNode *node,
225                                                   gint          depth,
226                                                   GtkCMCTreeFunc  func,
227                                                   gpointer      data);
228 void gtk_cmctree_pre_recursive                     (GtkCMCTree     *ctree, 
229                                                   GtkCMCTreeNode *node,
230                                                   GtkCMCTreeFunc  func,
231                                                   gpointer      data);
232 void gtk_cmctree_pre_recursive_to_depth            (GtkCMCTree     *ctree, 
233                                                   GtkCMCTreeNode *node,
234                                                   gint          depth,
235                                                   GtkCMCTreeFunc  func,
236                                                   gpointer      data);
237 gboolean gtk_cmctree_is_viewable                   (GtkCMCTree     *ctree, 
238                                                   GtkCMCTreeNode *node);
239 GtkCMCTreeNode * gtk_cmctree_last                    (GtkCMCTree     *ctree,
240                                                   GtkCMCTreeNode *node);
241 GtkCMCTreeNode * gtk_cmctree_find_node_ptr           (GtkCMCTree     *ctree,
242                                                   GtkCMCTreeRow  *ctree_row);
243 GtkCMCTreeNode * gtk_cmctree_node_nth                (GtkCMCTree     *ctree,
244                                                   guint         row);
245 gboolean gtk_cmctree_find                          (GtkCMCTree     *ctree,
246                                                   GtkCMCTreeNode *node,
247                                                   GtkCMCTreeNode *child);
248 gboolean gtk_cmctree_is_ancestor                   (GtkCMCTree     *ctree,
249                                                   GtkCMCTreeNode *node,
250                                                   GtkCMCTreeNode *child);
251 GtkCMCTreeNode * gtk_cmctree_find_by_row_data        (GtkCMCTree     *ctree,
252                                                   GtkCMCTreeNode *node,
253                                                   gpointer      data);
254 /* returns a GList of all GtkCMCTreeNodes with row->data == data. */
255 GList * gtk_cmctree_find_all_by_row_data           (GtkCMCTree     *ctree,
256                                                   GtkCMCTreeNode *node,
257                                                   gpointer      data);
258 GtkCMCTreeNode * gtk_cmctree_find_by_row_data_custom (GtkCMCTree     *ctree,
259                                                   GtkCMCTreeNode *node,
260                                                   gpointer      data,
261                                                   GCompareFunc  func);
262 /* returns a GList of all GtkCMCTreeNodes with row->data == data. */
263 GList * gtk_cmctree_find_all_by_row_data_custom    (GtkCMCTree     *ctree,
264                                                   GtkCMCTreeNode *node,
265                                                   gpointer      data,
266                                                   GCompareFunc  func);
267 gboolean gtk_cmctree_is_hot_spot                   (GtkCMCTree     *ctree,
268                                                   gint          x,
269                                                   gint          y);
270
271 /***********************************************************
272  *   Tree signals : move, expand, collapse, (un)select     *
273  ***********************************************************/
274
275 void gtk_cmctree_move                              (GtkCMCTree     *ctree,
276                                                   GtkCMCTreeNode *node,
277                                                   GtkCMCTreeNode *new_parent, 
278                                                   GtkCMCTreeNode *new_sibling);
279 void gtk_cmctree_expand                            (GtkCMCTree     *ctree,
280                                                   GtkCMCTreeNode *node);
281 void gtk_cmctree_expand_recursive                  (GtkCMCTree     *ctree,
282                                                   GtkCMCTreeNode *node);
283 void gtk_cmctree_expand_to_depth                   (GtkCMCTree     *ctree,
284                                                   GtkCMCTreeNode *node,
285                                                   gint          depth);
286 void gtk_cmctree_collapse                          (GtkCMCTree     *ctree,
287                                                   GtkCMCTreeNode *node);
288 void gtk_cmctree_collapse_recursive                (GtkCMCTree     *ctree,
289                                                   GtkCMCTreeNode *node);
290 void gtk_cmctree_collapse_to_depth                 (GtkCMCTree     *ctree,
291                                                   GtkCMCTreeNode *node,
292                                                   gint          depth);
293 void gtk_cmctree_toggle_expansion                  (GtkCMCTree     *ctree,
294                                                   GtkCMCTreeNode *node);
295 void gtk_cmctree_toggle_expansion_recursive        (GtkCMCTree     *ctree,
296                                                   GtkCMCTreeNode *node);
297 void gtk_cmctree_select                            (GtkCMCTree     *ctree, 
298                                                   GtkCMCTreeNode *node);
299 void gtk_cmctree_select_recursive                  (GtkCMCTree     *ctree, 
300                                                   GtkCMCTreeNode *node);
301 void gtk_cmctree_unselect                          (GtkCMCTree     *ctree, 
302                                                   GtkCMCTreeNode *node);
303 void gtk_cmctree_unselect_recursive                (GtkCMCTree     *ctree, 
304                                                   GtkCMCTreeNode *node);
305 void gtk_cmctree_real_select_recursive             (GtkCMCTree     *ctree, 
306                                                   GtkCMCTreeNode *node, 
307                                                   gint          state);
308
309 /***********************************************************
310  *           Analogons of GtkCMCList functions               *
311  ***********************************************************/
312
313 void gtk_cmctree_node_set_text                     (GtkCMCTree     *ctree,
314                                                   GtkCMCTreeNode *node,
315                                                   gint          column,
316                                                   const gchar  *text);
317 void gtk_cmctree_node_set_pixmap                   (GtkCMCTree     *ctree,
318                                                   GtkCMCTreeNode *node,
319                                                   gint          column,
320                                                   GdkPixmap    *pixmap,
321                                                   GdkBitmap    *mask);
322 void gtk_cmctree_node_set_pixtext                  (GtkCMCTree     *ctree,
323                                                   GtkCMCTreeNode *node,
324                                                   gint          column,
325                                                   const gchar  *text,
326                                                   guint8        spacing,
327                                                   GdkPixmap    *pixmap,
328                                                   GdkBitmap    *mask);
329 void gtk_cmctree_set_node_info                     (GtkCMCTree     *ctree,
330                                                   GtkCMCTreeNode *node,
331                                                   const gchar  *text,
332                                                   guint8        spacing,
333                                                   GdkPixmap    *pixmap_closed,
334                                                   GdkBitmap    *mask_closed,
335                                                   GdkPixmap    *pixmap_opened,
336                                                   GdkBitmap    *mask_opened,
337                                                   gboolean      is_leaf,
338                                                   gboolean      expanded);
339 void gtk_cmctree_node_set_shift                    (GtkCMCTree     *ctree,
340                                                   GtkCMCTreeNode *node,
341                                                   gint          column,
342                                                   gint          vertical,
343                                                   gint          horizontal);
344 void gtk_cmctree_node_set_selectable               (GtkCMCTree     *ctree,
345                                                   GtkCMCTreeNode *node,
346                                                   gboolean      selectable);
347 gboolean gtk_cmctree_node_get_selectable           (GtkCMCTree     *ctree,
348                                                   GtkCMCTreeNode *node);
349 GtkCMCellType gtk_cmctree_node_get_cell_type         (GtkCMCTree     *ctree,
350                                                   GtkCMCTreeNode *node,
351                                                   gint          column);
352 gboolean gtk_cmctree_node_get_text                 (GtkCMCTree     *ctree,
353                                                   GtkCMCTreeNode *node,
354                                                   gint          column,
355                                                   gchar       **text);
356 gboolean gtk_cmctree_node_get_pixmap               (GtkCMCTree     *ctree,
357                                                   GtkCMCTreeNode *node,
358                                                   gint          column,
359                                                   GdkPixmap   **pixmap,
360                                                   GdkBitmap   **mask);
361 gboolean gtk_cmctree_node_get_pixtext              (GtkCMCTree     *ctree,
362                                                   GtkCMCTreeNode *node,
363                                                   gint          column,
364                                                   gchar       **text,
365                                                   guint8       *spacing,
366                                                   GdkPixmap   **pixmap,
367                                                   GdkBitmap   **mask);
368 gboolean gtk_cmctree_get_node_info                 (GtkCMCTree     *ctree,
369                                                   GtkCMCTreeNode *node,
370                                                   gchar       **text,
371                                                   guint8       *spacing,
372                                                   GdkPixmap   **pixmap_closed,
373                                                   GdkBitmap   **mask_closed,
374                                                   GdkPixmap   **pixmap_opened,
375                                                   GdkBitmap   **mask_opened,
376                                                   gboolean     *is_leaf,
377                                                   gboolean     *expanded);
378 void gtk_cmctree_node_set_row_style                (GtkCMCTree     *ctree,
379                                                   GtkCMCTreeNode *node,
380                                                   GtkStyle     *style);
381 GtkStyle * gtk_cmctree_node_get_row_style          (GtkCMCTree     *ctree,
382                                                   GtkCMCTreeNode *node);
383 void gtk_cmctree_node_set_cell_style               (GtkCMCTree     *ctree,
384                                                   GtkCMCTreeNode *node,
385                                                   gint          column,
386                                                   GtkStyle     *style);
387 GtkStyle * gtk_cmctree_node_get_cell_style         (GtkCMCTree     *ctree,
388                                                   GtkCMCTreeNode *node,
389                                                   gint          column);
390 void gtk_cmctree_node_set_foreground               (GtkCMCTree       *ctree,
391                                                   GtkCMCTreeNode   *node,
392                                                   const GdkColor *color);
393 void gtk_cmctree_node_set_background               (GtkCMCTree       *ctree,
394                                                   GtkCMCTreeNode   *node,
395                                                   const GdkColor *color);
396 void gtk_cmctree_node_set_row_data                 (GtkCMCTree     *ctree,
397                                                   GtkCMCTreeNode *node,
398                                                   gpointer      data);
399 void gtk_cmctree_node_set_row_data_full            (GtkCMCTree     *ctree,
400                                                   GtkCMCTreeNode *node,
401                                                   gpointer      data,
402                                                   GDestroyNotify destroy);
403 gpointer gtk_cmctree_node_get_row_data             (GtkCMCTree     *ctree,
404                                                   GtkCMCTreeNode *node);
405 void gtk_cmctree_node_moveto                       (GtkCMCTree     *ctree,
406                                                   GtkCMCTreeNode *node,
407                                                   gint          column,
408                                                   gfloat        row_align,
409                                                   gfloat        col_align);
410 GtkVisibility gtk_cmctree_node_is_visible          (GtkCMCTree     *ctree,
411                                                   GtkCMCTreeNode *node);
412
413 /***********************************************************
414  *             GtkCMCTree specific functions                 *
415  ***********************************************************/
416
417 void gtk_cmctree_set_indent            (GtkCMCTree                *ctree, 
418                                       gint                     indent);
419 void gtk_cmctree_set_spacing           (GtkCMCTree                *ctree, 
420                                       gint                     spacing);
421 void gtk_cmctree_set_show_stub         (GtkCMCTree                *ctree, 
422                                       gboolean                 show_stub);
423 void gtk_cmctree_set_line_style        (GtkCMCTree                *ctree, 
424                                       GtkCMCTreeLineStyle        line_style);
425 void gtk_cmctree_set_expander_style    (GtkCMCTree                *ctree, 
426                                       GtkCMCTreeExpanderStyle    expander_style);
427 void gtk_cmctree_set_drag_compare_func (GtkCMCTree            *ctree,
428                                       GtkCMCTreeCompareDragFunc  cmp_func);
429
430 /***********************************************************
431  *             Tree sorting functions                      *
432  ***********************************************************/
433
434 void gtk_cmctree_sort_node                         (GtkCMCTree     *ctree, 
435                                                   GtkCMCTreeNode *node);
436 void gtk_cmctree_sort_recursive                    (GtkCMCTree     *ctree, 
437                                                   GtkCMCTreeNode *node);
438
439
440 #define gtk_cmctree_set_reorderable(t,r)                    gtk_cmclist_set_reorderable((GtkCMCList*) (t),(r))
441
442 /* GType for the GtkCMCTreeNode.  This is a boxed type, although it uses
443  * no-op's for the copy and free routines.  It is defined in order to
444  * provide type information for the signal arguments
445  */
446 GType   gtk_cmctree_node_get_type                  (void) G_GNUC_CONST;
447
448 G_END_DECLS
449
450 #endif                          /* __GTK_CMCTREE_H__ */