]> Pileus Git - ~andy/gtk/blob - gtk/gtkclist.h
moved widget creation to gtk_clist_construct for the gtk-- folks.
[~andy/gtk] / gtk / gtkclist.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  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 #ifndef __GTK_CLIST_H__
20 #define __GTK_CLIST_H__
21
22 #include <gdk/gdk.h>
23 #include <gtk/gtksignal.h>
24 #include <gtk/gtkalignment.h>
25 #include <gtk/gtklabel.h>
26 #include <gtk/gtkbutton.h>
27 #include <gtk/gtkhscrollbar.h>
28 #include <gtk/gtkvscrollbar.h>
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif                          /* __cplusplus */
34
35 /* clist flags */
36 enum                    
37 {
38   CLIST_FROZEN          = 1 << 0,                                     
39   CLIST_IN_DRAG         = 1 << 1,                                        
40   CLIST_ROW_HEIGHT_SET  = 1 << 2,
41   CLIST_SHOW_TITLES     = 1 << 3
42 }; 
43
44 /* cell types */
45 typedef enum
46 {
47   GTK_CELL_EMPTY,
48   GTK_CELL_TEXT,
49   GTK_CELL_PIXMAP,
50   GTK_CELL_PIXTEXT,
51   GTK_CELL_WIDGET
52 } GtkCellType;
53
54 #define GTK_CLIST(obj)          GTK_CHECK_CAST (obj, gtk_clist_get_type (), GtkCList)
55 #define GTK_CLIST_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_clist_get_type (), GtkCListClass)
56 #define GTK_IS_CLIST(obj)       GTK_CHECK_TYPE (obj, gtk_clist_get_type ())
57
58 #define GTK_CLIST_FLAGS(clist)             (GTK_CLIST (clist)->flags)
59 #define GTK_CLIST_SET_FLAGS(clist,flag)    (GTK_CLIST_FLAGS (clist) |= (flag))
60 #define GTK_CLIST_UNSET_FLAGS(clist,flag)  (GTK_CLIST_FLAGS (clist) &= ~(flag))
61
62 #define GTK_CLIST_FROZEN(clist)            (GTK_CLIST_FLAGS (clist) & CLIST_FROZEN)
63 #define GTK_CLIST_IN_DRAG(clist)           (GTK_CLIST_FLAGS (clist) & CLIST_IN_DRAG)
64 #define GTK_CLIST_ROW_HEIGHT_SET(clist)    (GTK_CLIST_FLAGS (clist) & CLIST_ROW_HEIGHT_SET)
65 #define GTK_CLIST_SHOW_TITLES(clist)       (GTK_CLIST_FLAGS (clist) & CLIST_SHOW_TITLES)
66
67 /* pointer casting for cells */
68 #define GTK_CELL_TEXT(cell)     (((GtkCellText *) &(cell)))
69 #define GTK_CELL_PIXMAP(cell)   (((GtkCellPixmap *) &(cell)))
70 #define GTK_CELL_PIXTEXT(cell)  (((GtkCellPixText *) &(cell)))
71 #define GTK_CELL_WIDGET(cell)   (((GtkCellWidget *) &(cell)))
72
73 typedef struct _GtkCList GtkCList;
74 typedef struct _GtkCListClass GtkCListClass;
75 typedef struct _GtkCListColumn GtkCListColumn;
76 typedef struct _GtkCListRow GtkCListRow;
77
78 typedef struct _GtkCell GtkCell;
79 typedef struct _GtkCellText GtkCellText;
80 typedef struct _GtkCellPixmap GtkCellPixmap;
81 typedef struct _GtkCellPixText GtkCellPixText;
82 typedef struct _GtkCellWidget GtkCellWidget;
83
84 struct _GtkCList
85 {
86   GtkContainer container;
87   
88   guint8 flags;
89
90   /* mem chunks */
91   GMemChunk *row_mem_chunk;
92   GMemChunk *cell_mem_chunk;
93
94   /* allocation rectangle after the conatiner_border_width
95    * and the width of the shadow border */
96   GdkRectangle internal_allocation;
97
98   /* rows */
99   gint rows;
100   gint row_center_offset;
101   gint row_height;
102   GList *row_list;
103   GList *row_list_end;
104   
105   /* columns */
106   gint columns;
107   GdkRectangle column_title_area;
108   GdkWindow *title_window;
109   
110   /* dynamicly allocated array of column structures */
111   GtkCListColumn *column;
112   
113   /*the scrolling window and it's height and width to
114    * make things a little speedier */
115   GdkWindow *clist_window;
116   gint clist_window_width;
117   gint clist_window_height;
118   
119   /* offsets for scrolling */
120   gint hoffset;
121   gint voffset;
122   
123   /* border shadow style */
124   GtkShadowType shadow_type;
125   
126   /* the list's selection mode (gtkenums.h) */
127   GtkSelectionMode selection_mode;
128
129   /* list of selected rows */
130   GList *selection;
131
132   /* scrollbars */
133   GtkWidget *vscrollbar;
134   GtkWidget *hscrollbar;
135   guint8 vscrollbar_policy;
136   guint8 hscrollbar_policy;
137
138   /* xor GC for the vertical drag line */
139   GdkGC *xor_gc;
140
141   /* gc for drawing unselected cells */
142   GdkGC *fg_gc;
143   GdkGC *bg_gc;
144
145   /* cursor used to indicate dragging */
146   GdkCursor *cursor_drag;
147
148   /* the current x-pixel location of the xor-drag line */
149   gint x_drag;
150 };
151
152 struct _GtkCListClass
153 {
154   GtkContainerClass parent_class;
155   
156   void (*select_row) (GtkCList * clist,
157                       gint row,
158                       gint column,
159                       GdkEventButton * event);
160   void (*unselect_row) (GtkCList * clist,
161                         gint row,
162                         gint column,
163                         GdkEventButton * event);
164   void (*click_column) (GtkCList * clist,
165                         gint column);
166
167   gint scrollbar_spacing;
168 };
169
170 struct _GtkCListColumn
171 {
172   gchar *title;
173   GdkRectangle area;
174   
175   GtkWidget *button;
176   GdkWindow *window;
177
178   gint width;
179   GtkJustification justification;
180
181   gint width_set : 1;
182 };
183
184 struct _GtkCListRow
185 {
186   GtkCell *cell;
187   GtkStateType state;
188
189   GdkColor foreground;
190   GdkColor background;
191
192   gpointer data;
193
194   gint fg_set : 1;
195   gint bg_set : 1;
196 };
197
198 /* Cell Structures */
199 struct _GtkCellText
200 {
201   GtkCellType type;
202   
203   gint vertical;
204   gint horizontal;
205   
206   gchar *text;
207 };
208
209 struct _GtkCellPixmap
210 {
211   GtkCellType type;
212   
213   gint vertical;
214   gint horizontal;
215   
216   GdkPixmap *pixmap;
217   GdkBitmap *mask;
218 };
219
220 struct _GtkCellPixText
221 {
222   GtkCellType type;
223   
224   gint vertical;
225   gint horizontal;
226   
227   gchar *text;
228   guint8 spacing;
229   GdkPixmap *pixmap;
230   GdkBitmap *mask;
231 };
232
233 struct _GtkCellWidget
234 {
235   GtkCellType type;
236   
237   gint vertical;
238   gint horizontal;
239   
240   GtkWidget *widget;
241 };
242
243 struct _GtkCell
244 {
245   GtkCellType type;
246
247   gint vertical;
248   gint horizontal;
249
250   union {
251     gchar *text;
252
253     struct {
254       GdkPixmap *pixmap;
255       GdkBitmap *mask;
256     } pm;
257
258     struct {
259       gchar *text;
260       guint8 spacing;
261       GdkPixmap *pixmap;
262       GdkBitmap *mask;
263     } pt;
264
265     GtkWidget *widget;
266   } u;
267 };
268
269 guint gtk_clist_get_type (void);
270
271 /* constructers useful for gtk-- wrappers */
272 void gtk_clist_construct (GtkCList * clist,
273                           gint columns,
274                           gchar * titles[]);
275
276 /* create a new GtkCList */
277 GtkWidget *gtk_clist_new (gint columns);
278 GtkWidget *gtk_clist_new_with_titles (gint columns,
279                                       gchar * titles[]);
280
281 /* set the border style of the clist */
282 void gtk_clist_set_border (GtkCList * clist,
283                            GtkShadowType border);
284
285 /* set the clist's selection mode */
286 void gtk_clist_set_selection_mode (GtkCList * clist,
287                                    GtkSelectionMode mode);
288
289 /* set policy on the scrollbar, to either show them all the time
290  * or show them only when they are needed, ie., when there is more than one page
291  * of information */
292 void gtk_clist_set_policy (GtkCList * clist,
293                            GtkPolicyType vscrollbar_policy,
294                            GtkPolicyType hscrollbar_policy);
295
296 /* freeze all visual updates of the list, and then thaw the list after you have made
297  * a number of changes and the updates wil occure in a more efficent mannor than if
298  * you made them on a unfrozen list */
299 void gtk_clist_freeze (GtkCList * clist);
300 void gtk_clist_thaw (GtkCList * clist);
301
302 /* show and hide the column title buttons */
303 void gtk_clist_column_titles_show (GtkCList * clist);
304 void gtk_clist_column_titles_hide (GtkCList * clist);
305
306 /* set the column title to be a active title (responds to button presses, 
307  * prelights, and grabs keyboard focus), or passive where it acts as just
308  * a title */
309 void gtk_clist_column_title_active (GtkCList * clist,
310                                      gint column);
311 void gtk_clist_column_title_passive (GtkCList * clist,
312                                      gint column);
313 void gtk_clist_column_titles_active (GtkCList * clist);
314 void gtk_clist_column_titles_passive (GtkCList * clist);
315
316 /* set the title in the column title button */
317 void gtk_clist_set_column_title (GtkCList * clist,
318                                  gint column,
319                                  gchar * title);
320
321 /* set a widget instead of a title for the column title button */
322 void gtk_clist_set_column_widget (GtkCList * clist,
323                                   gint column,
324                                   GtkWidget * widget);
325
326 /* set the justification on a column */
327 void gtk_clist_set_column_justification (GtkCList * clist,
328                                          gint column,
329                                          GtkJustification justification);
330
331 /* set the pixel width of a column; this is a necessary step in
332  * creating a CList because otherwise the column width is chozen from
333  * the width of the column title, which will never be right */
334 void gtk_clist_set_column_width (GtkCList * clist,
335                                  gint column,
336                                  gint width);
337
338 /* change the height of the rows, the default is the hight of the current
339  * font */
340 void gtk_clist_set_row_height (GtkCList * clist,
341                                gint height);
342
343 /* scroll the viewing area of the list to the given column
344  * and row; row_align and col_align are between 0-1 representing the
345  * location the row should appear on the screnn, 0.0 being top or left,
346  * 1.0 being bottom or right; if row or column is -1 then then there
347  * is no change */
348 void gtk_clist_moveto (GtkCList * clist,
349                        gint row,
350                        gint column,
351                        gfloat row_align,
352                        gfloat col_align);
353
354 /* returns true if the row is visible */
355 gint gtk_clist_row_isvisable (GtkCList * clist,
356                               gint row);
357
358 /* returns the cell type */
359 GtkCellType gtk_clist_get_cell_type (GtkCList * clist,
360                                      gint row,
361                                      gint column);
362
363 /* sets a given cell's text, replacing it's current contents */
364 void gtk_clist_set_text (GtkCList * clist,
365                          gint row,
366                          gint column,
367                          gchar * text);
368
369 /* for the "get" functions, any of the return pointer can be
370  * NULL if you are not interested */
371 gint gtk_clist_get_text (GtkCList * clist,
372                          gint row,
373                          gint column,
374                          gchar ** text);
375
376 /* sets a given cell's pixmap, replacing it's current contents */
377 void gtk_clist_set_pixmap (GtkCList * clist,
378                            gint row,
379                            gint column,
380                            GdkPixmap * pixmap,
381                            GdkBitmap * mask);
382
383 gint gtk_clist_get_pixmap (GtkCList * clist,
384                            gint row,
385                            gint column,
386                            GdkPixmap ** pixmap,
387                            GdkBitmap ** mask);
388
389 /* sets a given cell's pixmap and text, replacing it's current contents */
390 void gtk_clist_set_pixtext (GtkCList * clist,
391                             gint row,
392                             gint column,
393                             gchar * text,
394                             guint8 spacing,
395                             GdkPixmap * pixmap,
396                             GdkBitmap * mask);
397
398 gint gtk_clist_get_pixtext (GtkCList * clist,
399                             gint row,
400                             gint column,
401                             gchar ** text,
402                             guint8 * spacing,
403                             GdkPixmap ** pixmap,
404                             GdkBitmap ** mask);
405
406 /* sets the foreground color of a row, the colar must already
407  * be allocated */
408 void gtk_clist_set_foreground (GtkCList * clist,
409                                gint row,
410                                GdkColor * color);
411
412 /* sets the background color of a row, the colar must already
413  * be allocated */
414 void gtk_clist_set_background (GtkCList * clist,
415                                gint row,
416                                GdkColor * color);
417
418 /* this sets a horizontal and vertical shift for drawing
419  * the contents of a cell; it can be positive or negitive; this is
420  * partuculary useful for indenting items in a column */
421 void gtk_clist_set_shift (GtkCList * clist,
422                           gint row,
423                           gint column,
424                           gint vertical,
425                           gint horizontal);
426
427 /* append returns the index of the row you just added, making
428  * it easier to append and modify a row */
429 gint gtk_clist_append (GtkCList * clist,
430                        gchar * text[]);
431
432 /* inserts a row at index row */
433 void gtk_clist_insert (GtkCList * clist,
434                        gint row,
435                        gchar * text[]);
436
437 /* removes row at index row */
438 void gtk_clist_remove (GtkCList * clist,
439                        gint row);
440
441 /* sets a arbitrary data pointer for a given row */
442 void gtk_clist_set_row_data (GtkCList * clist,
443                              gint row,
444                              gpointer data);
445
446 /* returns the data set for a row */
447 gpointer gtk_clist_get_row_data (GtkCList * clist,
448                                  gint row);
449
450 /* givin a data pointer, find the first (and hopefully only!)
451  * row that points to that data, or -1 if none do */
452 gint gtk_clist_find_row_from_data (GtkCList * clist,
453                                    gpointer data);
454
455 /* force selection of a row */
456 void gtk_clist_select_row (GtkCList * clist,
457                            gint row,
458                            gint column);
459
460 /* force unselection of a row */
461 void gtk_clist_unselect_row (GtkCList * clist,
462                              gint row,
463                              gint column);
464
465 /* clear the entire list -- this is much faster than removing each item 
466  * with gtk_clist_remove */
467 void gtk_clist_clear (GtkCList * clist);
468
469 #ifdef __cplusplus
470 }
471 #endif                          /* __cplusplus */
472
473
474 #endif                          /* __GTK_CLIST_H__ */