]> Pileus Git - ~andy/gtk/blob - gtk/gtkclist.h
Added column list widget GtkCList. -Jay Painter
[~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
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif                          /* __cplusplus */
35
36 /* clist flags */
37 enum                    
38 {
39   CLIST_FROZEN          = 1 << 0,                                     
40   CLIST_IN_DRAG         = 1 << 1,                                        
41   CLIST_ROW_HEIGHT_SET  = 1 << 2
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
66 /* pointer casting for cells */
67 #define GTK_CELL_TEXT(cell)     (((GtkCellText *) &(cell)))
68 #define GTK_CELL_PIXMAP(cell)   (((GtkCellPixmap *) &(cell)))
69 #define GTK_CELL_PIXTEXT(cell)  (((GtkCellPixText *) &(cell)))
70 #define GTK_CELL_WIDGET(cell)   (((GtkCellWidget *) &(cell)))
71
72 typedef struct _GtkCList GtkCList;
73 typedef struct _GtkCListClass GtkCListClass;
74 typedef struct _GtkCListColumn GtkCListColumn;
75 typedef struct _GtkCListRow GtkCListRow;
76
77 typedef struct _GtkCell GtkCell;
78 typedef struct _GtkCellText GtkCellText;
79 typedef struct _GtkCellPixmap GtkCellPixmap;
80 typedef struct _GtkCellPixText GtkCellPixText;
81 typedef struct _GtkCellWidget GtkCellWidget;
82
83 struct _GtkCList
84 {
85   GtkContainer container;
86   
87   guint8 flags;
88
89   /* allocation rectangle after the conatiner_border_width
90    * and the width of the shadow border */
91   GdkRectangle internal_allocation;
92   
93   /* memory chunks */
94   GMemChunk *row_mem_chunk;
95   GMemChunk *cell_mem_chunk;
96
97   /* rows */
98   gint rows;
99   gint row_center_offset;
100   gint row_height;
101   GList *row_list;
102   GList *row_list_end;
103   
104   /* columns */
105   gint columns;
106   GdkRectangle column_title_area;
107   GdkWindow *title_window;
108   
109   /* dynamicly allocated array of column structures */
110   GtkCListColumn *column;
111   
112   /*the scrolling window and it's height and width to
113    * make things a little speedier */
114   GdkWindow *clist_window;
115   gint clist_window_width;
116   gint clist_window_height;
117   
118   /* offsets for scrolling */
119   gint hoffset;
120   gint voffset;
121   
122   /* border shadow style */
123   GtkShadowType shadow_type;
124   
125   /* the list's selection mode (gtkenums.h) */
126   GtkSelectionMode selection_mode;
127
128   /* scrollbars */
129   GtkWidget *vscrollbar;
130   GtkWidget *hscrollbar;
131   guint8 vscrollbar_policy;
132   guint8 hscrollbar_policy;
133
134   /* xor GC for the verticle drag line */
135   GdkGC *xor_gc;
136
137   /* gc for drawing unselected cells */
138   GdkGC *fg_gc;
139   GdkGC *bg_gc;
140
141   /* cursor used to indicate dragging */
142   GdkCursor *cursor_drag;
143
144   /* the current x-pixel location of the xor-drag line */
145   gint x_drag;
146 };
147
148 struct _GtkCListClass
149 {
150   GtkContainerClass parent_class;
151   
152   void (*select_row) (GtkCList * clist,
153                       gint row,
154                       gint column,
155                       GdkEventButton * event);
156   void (*unselect_row) (GtkCList * clist,
157                         gint row,
158                         gint column,
159                         GdkEventButton * event);
160   void (*click_column) (GtkCList * clist,
161                         gint column);
162 };
163
164 struct _GtkCListColumn
165 {
166   gchar *title;
167   GdkRectangle area;
168   
169   GtkWidget *button;
170   gint width;
171   GtkJustification justification;
172 };
173
174 struct _GtkCListRow
175 {
176   GtkCell *cell;
177   GtkStateType state;
178
179   GdkColor foreground;
180   GdkColor background;
181
182   gpointer data;
183 };
184
185 /* Cell Structures */
186 struct _GtkCellText
187 {
188   GtkCellType type;
189   
190   gint verticle;
191   gint horizontal;
192   
193   gchar *text;
194 };
195
196 struct _GtkCellPixmap
197 {
198   GtkCellType type;
199   
200   gint verticle;
201   gint horizontal;
202   
203   GdkPixmap *pixmap;
204   GdkBitmap *mask;
205 };
206
207 struct _GtkCellPixText
208 {
209   GtkCellType type;
210   
211   gint verticle;
212   gint horizontal;
213   
214   gchar *text;
215   guint8 spacing;
216   GdkPixmap *pixmap;
217   GdkBitmap *mask;
218 };
219
220 struct _GtkCellWidget
221 {
222   GtkCellType type;
223   
224   gint verticle;
225   gint horizontal;
226   
227   GtkWidget *widget;
228 };
229
230 struct _GtkCell
231 {
232   GtkCellType type;
233
234   gint verticle;
235   gint horizontal;
236
237   union {
238     gchar *text;
239
240     struct {
241       GdkPixmap *pixmap;
242       GdkBitmap *mask;
243     } pm;
244
245     struct {
246       gchar *text;
247       guint8 spacing;
248       GdkPixmap *pixmap;
249       GdkBitmap *mask;
250     } pt;
251
252     GtkWidget *widget;
253   } u;
254 };
255
256 guint gtk_clist_get_type (void);
257
258 /* create a new GtkCList */
259 GtkWidget *gtk_clist_new (int columns,
260                           gchar * titles[]);
261
262 /* set the border style of the clist */
263 void gtk_clist_set_border (GtkCList * clist,
264                            GtkShadowType border);
265
266 /* set the clist's selection mode */
267 void gtk_clist_set_selection_mode (GtkCList * clist,
268                                    GtkSelectionMode mode);
269
270 /* set policy on the scrollbar, to either show them all the time
271  * or show them only when they are needed, ie., when there is more than one page
272  * of information */
273 void gtk_clist_set_policy (GtkCList * clist,
274                            GtkPolicyType vscrollbar_policy,
275                            GtkPolicyType hscrollbar_policy);
276
277 /* freeze all visual updates of the list, and then thaw the list after you have made
278  * a number of changes and the updates wil occure in a more efficent mannor than if
279  * you made them on a unfrozen list */
280 void gtk_clist_freeze (GtkCList * clist);
281 void gtk_clist_thaw (GtkCList * clist);
282
283 /* set the title in the column title button */
284 void gtk_clist_set_column_title (GtkCList * clist,
285                                  gint column,
286                                  gchar * title);
287
288 /* set a widget instead of a title for the column title button */
289 void gtk_clist_set_column_widget (GtkCList * clist,
290                                   gint column,
291                                   GtkWidget * widget);
292
293 /* set the justification on a column */
294 void gtk_clist_set_column_justification (GtkCList * clist,
295                                          gint column,
296                                          GtkJustification justification);
297
298 /* set the pixel width of a column; this is a necessary step in
299  * creating a CList because otherwise the column width is chozen from
300  * the width of the column title, which will never be right */
301 void gtk_clist_set_column_width (GtkCList * clist,
302                                  gint column,
303                                  gint width);
304
305 /* change the height of the rows, the default is the hight of the current
306  * font */
307 void gtk_clist_set_row_height (GtkCList * clist,
308                                gint height);
309
310 /* scroll the viewing area of the list to the given column
311  * and row; row_align and col_align are between 0-1 representing the
312  * location the row should appear on the screnn, 0.0 being top or left,
313  * 1.0 being bottom or right */
314 void gtk_clist_moveto (GtkCList * clist,
315                        gint row,
316                        gint column,
317                        gfloat row_align,
318                        gfloat col_align);
319
320 /* sets a given cell's text, replacing it's current contents */
321 void gtk_clist_set_text (GtkCList * clist,
322                          gint row,
323                          gint column,
324                          gchar * text);
325
326 /* sets a given cell's pixmap, replacing it's current contents */
327 void gtk_clist_set_pixmap (GtkCList * clist,
328                            gint row,
329                            gint column,
330                            GdkPixmap * pixmap,
331                            GdkBitmap * mask);
332
333 /* sets a given cell's pixmap and text, replacing it's current contents */
334 void gtk_clist_set_pixtext (GtkCList * clist,
335                             gint row,
336                             gint column,
337                             gchar * text,
338                             guint8 spacing,
339                             GdkPixmap * pixmap,
340                             GdkBitmap * mask);
341
342 /* sets the foreground color of a row, the colar must already
343  * be allocated */
344 void gtk_clist_set_foreground (GtkCList * clist,
345                                gint row,
346                                GdkColor * color);
347
348 /* sets the background color of a row, the colar must already
349  * be allocated */
350 void gtk_clist_set_background (GtkCList * clist,
351                                gint row,
352                                GdkColor * color);
353
354 /* this sets a horizontal and verticle shift for drawing
355  * the contents of a cell; it can be positive or negitive; this is
356  * partuculary useful for indenting items in a column */
357 void gtk_clist_set_shift (GtkCList * clist,
358                           gint row,
359                           gint column,
360                           gint verticle,
361                           gint horizontal);
362
363 /* append returns the index of the row you just added, making
364  * it easier to append and modify a row */
365 gint gtk_clist_append (GtkCList * clist,
366                        gchar * text[]);
367
368 /* inserts a row at index row */
369 void gtk_clist_insert (GtkCList * clist,
370                        gint row,
371                        gchar * text[]);
372
373 /* removes row at index row */
374 void gtk_clist_remove (GtkCList * clist,
375                        gint row);
376
377 /* sets a arbitrary data pointer for a given row */
378 void gtk_clist_set_row_data (GtkCList * clist,
379                              gint row,
380                              gpointer data);
381
382 /* returns the data set for a row */
383 gpointer gtk_clist_get_row_data (GtkCList * clist,
384                                  gint row);
385
386 /* force selection of a row */
387 void gtk_clist_select_row (GtkCList * clist,
388                            gint row,
389                            gint column);
390
391 /* force unselection of a row */
392 void gtk_clist_unselect_row (GtkCList * clist,
393                              gint row,
394                              gint column);
395
396 /* clear the entire list -- this is much faster than removing each item 
397  * with gtk_clist_remove */
398 void gtk_clist_clear (GtkCList * clist);
399
400 #ifdef __cplusplus
401 }
402 #endif                          /* __cplusplus */
403
404
405 #endif                          /* __GTK_CLIST_H__ */