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>
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.
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.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #ifndef __GTK_CLIST_H__
29 #define __GTK_CLIST_H__
32 #include <gtk/gtksignal.h>
33 #include <gtk/gtkalignment.h>
34 #include <gtk/gtklabel.h>
35 #include <gtk/gtkbutton.h>
36 #include <gtk/gtkhscrollbar.h>
37 #include <gtk/gtkvscrollbar.h>
38 #include <gtk/gtkenums.h>
42 #endif /* __cplusplus */
46 GTK_CLIST_IN_DRAG = 1 << 0,
47 GTK_CLIST_ROW_HEIGHT_SET = 1 << 1,
48 GTK_CLIST_SHOW_TITLES = 1 << 2,
49 GTK_CLIST_CHILD_HAS_FOCUS = 1 << 3,
50 GTK_CLIST_ADD_MODE = 1 << 4,
51 GTK_CLIST_AUTO_SORT = 1 << 5,
52 GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
53 GTK_CLIST_REORDERABLE = 1 << 7,
54 GTK_CLIST_USE_DRAG_ICONS = 1 << 8,
55 GTK_CLIST_DRAW_DRAG_LINE = 1 << 9,
56 GTK_CLIST_DRAW_DRAG_RECT = 1 << 10
72 GTK_CLIST_DRAG_BEFORE,
79 GTK_BUTTON_IGNORED = 0,
80 GTK_BUTTON_SELECTS = 1 << 0,
81 GTK_BUTTON_DRAGS = 1 << 1,
82 GTK_BUTTON_EXPANDS = 1 << 2
85 #define GTK_TYPE_CLIST (gtk_clist_get_type ())
86 #define GTK_CLIST(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CLIST, GtkCList))
87 #define GTK_CLIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLIST, GtkCListClass))
88 #define GTK_IS_CLIST(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_CLIST))
89 #define GTK_IS_CLIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CLIST))
90 #define GTK_CLIST_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_CLIST, GtkCListClass))
93 #define GTK_CLIST_FLAGS(clist) (GTK_CLIST (clist)->flags)
94 #define GTK_CLIST_SET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) |= (GTK_ ## flag))
95 #define GTK_CLIST_UNSET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) &= ~(GTK_ ## flag))
97 #define GTK_CLIST_IN_DRAG(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_IN_DRAG)
98 #define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET)
99 #define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES)
100 #define GTK_CLIST_CHILD_HAS_FOCUS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CHILD_HAS_FOCUS)
101 #define GTK_CLIST_ADD_MODE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ADD_MODE)
102 #define GTK_CLIST_AUTO_SORT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_SORT)
103 #define GTK_CLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_RESIZE_BLOCKED)
104 #define GTK_CLIST_REORDERABLE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_REORDERABLE)
105 #define GTK_CLIST_USE_DRAG_ICONS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_USE_DRAG_ICONS)
106 #define GTK_CLIST_DRAW_DRAG_LINE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_LINE)
107 #define GTK_CLIST_DRAW_DRAG_RECT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_RECT)
109 #define GTK_CLIST_ROW(_glist_) ((GtkCListRow *)((_glist_)->data))
111 /* pointer casting for cells */
112 #define GTK_CELL_TEXT(cell) (((GtkCellText *) &(cell)))
113 #define GTK_CELL_PIXMAP(cell) (((GtkCellPixmap *) &(cell)))
114 #define GTK_CELL_PIXTEXT(cell) (((GtkCellPixText *) &(cell)))
115 #define GTK_CELL_WIDGET(cell) (((GtkCellWidget *) &(cell)))
117 typedef struct _GtkCList GtkCList;
118 typedef struct _GtkCListClass GtkCListClass;
119 typedef struct _GtkCListColumn GtkCListColumn;
120 typedef struct _GtkCListRow GtkCListRow;
122 typedef struct _GtkCell GtkCell;
123 typedef struct _GtkCellText GtkCellText;
124 typedef struct _GtkCellPixmap GtkCellPixmap;
125 typedef struct _GtkCellPixText GtkCellPixText;
126 typedef struct _GtkCellWidget GtkCellWidget;
128 typedef gint (*GtkCListCompareFunc) (GtkCList *clist,
132 typedef struct _GtkCListCellInfo GtkCListCellInfo;
133 typedef struct _GtkCListDestInfo GtkCListDestInfo;
135 struct _GtkCListCellInfo
141 struct _GtkCListDestInfo
143 GtkCListCellInfo cell;
144 GtkCListDragPos insert_pos;
149 GtkContainer container;
154 GMemChunk *row_mem_chunk;
155 GMemChunk *cell_mem_chunk;
159 /* allocation rectangle after the conatiner_border_width
160 * and the width of the shadow border */
161 GdkRectangle internal_allocation;
165 gint row_center_offset;
172 GdkRectangle column_title_area;
173 GdkWindow *title_window;
175 /* dynamicly allocated array of column structures */
176 GtkCListColumn *column;
178 /* the scrolling window and its height and width to
179 * make things a little speedier */
180 GdkWindow *clist_window;
181 gint clist_window_width;
182 gint clist_window_height;
184 /* offsets for scrolling */
188 /* border shadow style */
189 GtkShadowType shadow_type;
191 /* the list's selection mode (gtkenums.h) */
192 GtkSelectionMode selection_mode;
194 /* list of selected rows */
196 GList *selection_end;
198 GList *undo_selection;
199 GList *undo_unselection;
203 guint8 button_actions[5];
208 GtkCListCellInfo click_cell;
210 /* scroll adjustments */
211 GtkAdjustment *hadjustment;
212 GtkAdjustment *vadjustment;
214 /* xor GC for the vertical drag line */
217 /* gc for drawing unselected cells */
221 /* cursor used to indicate dragging */
222 GdkCursor *cursor_drag;
224 /* the current x-pixel location of the xor-drag line */
230 /* dragging the selection */
232 GtkStateType anchor_state;
237 GtkSortType sort_type;
238 GtkCListCompareFunc compare;
242 struct _GtkCListClass
244 GtkContainerClass parent_class;
246 void (*set_scroll_adjustments) (GtkCList *clist,
247 GtkAdjustment *hadjustment,
248 GtkAdjustment *vadjustment);
249 void (*refresh) (GtkCList *clist);
250 void (*select_row) (GtkCList *clist,
254 void (*unselect_row) (GtkCList *clist,
258 void (*row_move) (GtkCList *clist,
261 void (*click_column) (GtkCList *clist,
263 void (*resize_column) (GtkCList *clist,
266 void (*toggle_focus_row) (GtkCList *clist);
267 void (*select_all) (GtkCList *clist);
268 void (*unselect_all) (GtkCList *clist);
269 void (*undo_selection) (GtkCList *clist);
270 void (*start_selection) (GtkCList *clist);
271 void (*end_selection) (GtkCList *clist);
272 void (*extend_selection) (GtkCList *clist,
273 GtkScrollType scroll_type,
275 gboolean auto_start_selection);
276 void (*scroll_horizontal) (GtkCList *clist,
277 GtkScrollType scroll_type,
279 void (*scroll_vertical) (GtkCList *clist,
280 GtkScrollType scroll_type,
282 void (*toggle_add_mode) (GtkCList *clist);
283 void (*abort_column_resize) (GtkCList *clist);
284 void (*resync_selection) (GtkCList *clist,
286 GList* (*selection_find) (GtkCList *clist,
288 GList *row_list_element);
289 void (*draw_row) (GtkCList *clist,
292 GtkCListRow *clist_row);
293 void (*draw_drag_highlight) (GtkCList *clist,
294 GtkCListRow *target_row,
295 gint target_row_number,
296 GtkCListDragPos drag_pos);
297 void (*clear) (GtkCList *clist);
298 void (*fake_unselect_all) (GtkCList *clist,
300 void (*sort_list) (GtkCList *clist);
301 gint (*insert_row) (GtkCList *clist,
304 void (*remove_row) (GtkCList *clist,
306 void (*set_cell_contents) (GtkCList *clist,
307 GtkCListRow *clist_row,
314 void (*cell_size_request) (GtkCList *clist,
315 GtkCListRow *clist_row,
317 GtkRequisition *requisition);
321 struct _GtkCListColumn
332 GtkJustification justification;
336 guint resizeable : 1;
337 guint auto_resize : 1;
338 guint button_passive : 1;
352 GtkDestroyNotify destroy;
356 guint selectable : 1;
359 /* Cell Structures */
372 struct _GtkCellPixmap
385 struct _GtkCellPixText
400 struct _GtkCellWidget
440 GtkType gtk_clist_get_type (void);
442 /* constructors useful for gtk-- wrappers */
443 void gtk_clist_construct (GtkCList *clist,
447 /* create a new GtkCList */
448 GtkWidget* gtk_clist_new (gint columns);
449 GtkWidget* gtk_clist_new_with_titles (gint columns,
452 /* set adjustments of clist */
453 void gtk_clist_set_hadjustment (GtkCList *clist,
454 GtkAdjustment *adjustment);
455 void gtk_clist_set_vadjustment (GtkCList *clist,
456 GtkAdjustment *adjustment);
458 /* get adjustments of clist */
459 GtkAdjustment* gtk_clist_get_hadjustment (GtkCList *clist);
460 GtkAdjustment* gtk_clist_get_vadjustment (GtkCList *clist);
462 /* set the border style of the clist */
463 void gtk_clist_set_shadow_type (GtkCList *clist,
466 /* set the clist's selection mode */
467 void gtk_clist_set_selection_mode (GtkCList *clist,
468 GtkSelectionMode mode);
470 /* enable clists reorder ability */
471 void gtk_clist_set_reorderable (GtkCList *clist,
472 gboolean reorderable);
473 void gtk_clist_set_use_drag_icons (GtkCList *clist,
475 void gtk_clist_set_button_actions (GtkCList *clist,
477 guint8 button_actions);
479 /* freeze all visual updates of the list, and then thaw the list after
480 * you have made a number of changes and the updates wil occure in a
481 * more efficent mannor than if you made them on a unfrozen list
483 void gtk_clist_freeze (GtkCList *clist);
484 void gtk_clist_thaw (GtkCList *clist);
486 /* show and hide the column title buttons */
487 void gtk_clist_column_titles_show (GtkCList *clist);
488 void gtk_clist_column_titles_hide (GtkCList *clist);
490 /* set the column title to be a active title (responds to button presses,
491 * prelights, and grabs keyboard focus), or passive where it acts as just
494 void gtk_clist_column_title_active (GtkCList *clist,
496 void gtk_clist_column_title_passive (GtkCList *clist,
498 void gtk_clist_column_titles_active (GtkCList *clist);
499 void gtk_clist_column_titles_passive (GtkCList *clist);
501 /* set the title in the column title button */
502 void gtk_clist_set_column_title (GtkCList *clist,
506 /* returns the title of column. Returns NULL if title is not set */
507 gchar * gtk_clist_get_column_title (GtkCList *clist,
510 /* set a widget instead of a title for the column title button */
511 void gtk_clist_set_column_widget (GtkCList *clist,
515 /* returns the column widget */
516 GtkWidget * gtk_clist_get_column_widget (GtkCList *clist,
519 /* set the justification on a column */
520 void gtk_clist_set_column_justification (GtkCList *clist,
522 GtkJustification justification);
524 /* set visibility of a column */
525 void gtk_clist_set_column_visibility (GtkCList *clist,
529 /* enable/disable column resize operations by mouse */
530 void gtk_clist_set_column_resizeable (GtkCList *clist,
532 gboolean resizeable);
534 /* resize column automatically to its optimal width */
535 void gtk_clist_set_column_auto_resize (GtkCList *clist,
537 gboolean auto_resize);
539 gint gtk_clist_columns_autosize (GtkCList *clist);
541 /* return the optimal column width, i.e. maximum of all cell widths */
542 gint gtk_clist_optimal_column_width (GtkCList *clist,
545 /* set the pixel width of a column; this is a necessary step in
546 * creating a CList because otherwise the column width is chozen from
547 * the width of the column title, which will never be right
549 void gtk_clist_set_column_width (GtkCList *clist,
553 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
554 void gtk_clist_set_column_min_width (GtkCList *clist,
557 void gtk_clist_set_column_max_width (GtkCList *clist,
561 /* change the height of the rows, the default (height=0) is
562 * the hight of the current font.
564 void gtk_clist_set_row_height (GtkCList *clist,
567 /* scroll the viewing area of the list to the given column and row;
568 * row_align and col_align are between 0-1 representing the location the
569 * row should appear on the screnn, 0.0 being top or left, 1.0 being
570 * bottom or right; if row or column is -1 then then there is no change
572 void gtk_clist_moveto (GtkCList *clist,
578 /* returns whether the row is visible */
579 GtkVisibility gtk_clist_row_is_visible (GtkCList *clist,
582 /* returns the cell type */
583 GtkCellType gtk_clist_get_cell_type (GtkCList *clist,
587 /* sets a given cell's text, replacing its current contents */
588 void gtk_clist_set_text (GtkCList *clist,
593 /* for the "get" functions, any of the return pointer can be
594 * NULL if you are not interested
596 gint gtk_clist_get_text (GtkCList *clist,
601 /* sets a given cell's pixmap, replacing its current contents */
602 void gtk_clist_set_pixmap (GtkCList *clist,
608 gint gtk_clist_get_pixmap (GtkCList *clist,
614 /* sets a given cell's pixmap and text, replacing its current contents */
615 void gtk_clist_set_pixtext (GtkCList *clist,
623 gint gtk_clist_get_pixtext (GtkCList *clist,
631 /* sets the foreground color of a row, the color must already
634 void gtk_clist_set_foreground (GtkCList *clist,
638 /* sets the background color of a row, the color must already
641 void gtk_clist_set_background (GtkCList *clist,
645 /* set / get cell styles */
646 void gtk_clist_set_cell_style (GtkCList *clist,
651 GtkStyle *gtk_clist_get_cell_style (GtkCList *clist,
655 void gtk_clist_set_row_style (GtkCList *clist,
659 GtkStyle *gtk_clist_get_row_style (GtkCList *clist,
662 /* this sets a horizontal and vertical shift for drawing
663 * the contents of a cell; it can be positive or negitive;
664 * this is particulary useful for indenting items in a column
666 void gtk_clist_set_shift (GtkCList *clist,
672 /* set/get selectable flag of a single row */
673 void gtk_clist_set_selectable (GtkCList *clist,
675 gboolean selectable);
676 gboolean gtk_clist_get_selectable (GtkCList *clist,
679 /* prepend/append returns the index of the row you just added,
680 * making it easier to append and modify a row
682 gint gtk_clist_prepend (GtkCList *clist,
684 gint gtk_clist_append (GtkCList *clist,
687 /* inserts a row at index row and returns the row where it was
688 * actually inserted (may be different from "row" in auto_sort mode)
690 gint gtk_clist_insert (GtkCList *clist,
694 /* removes row at index row */
695 void gtk_clist_remove (GtkCList *clist,
698 /* sets a arbitrary data pointer for a given row */
699 void gtk_clist_set_row_data (GtkCList *clist,
703 /* sets a data pointer for a given row with destroy notification */
704 void gtk_clist_set_row_data_full (GtkCList *clist,
707 GtkDestroyNotify destroy);
709 /* returns the data set for a row */
710 gpointer gtk_clist_get_row_data (GtkCList *clist,
713 /* givin a data pointer, find the first (and hopefully only!)
714 * row that points to that data, or -1 if none do
716 gint gtk_clist_find_row_from_data (GtkCList *clist,
719 /* force selection of a row */
720 void gtk_clist_select_row (GtkCList *clist,
724 /* force unselection of a row */
725 void gtk_clist_unselect_row (GtkCList *clist,
729 /* undo the last select/unselect operation */
730 void gtk_clist_undo_selection (GtkCList *clist);
732 /* clear the entire list -- this is much faster than removing
733 * each item with gtk_clist_remove
735 void gtk_clist_clear (GtkCList *clist);
737 /* return the row column corresponding to the x and y coordinates,
738 * the returned values are only valid if the x and y coordinates
739 * are respectively to a window == clist->clist_window
741 gint gtk_clist_get_selection_info (GtkCList *clist,
747 /* in multiple or extended mode, select all rows */
748 void gtk_clist_select_all (GtkCList *clist);
750 /* in all modes except browse mode, deselect all rows */
751 void gtk_clist_unselect_all (GtkCList *clist);
753 /* swap the position of two rows */
754 void gtk_clist_swap_rows (GtkCList *clist,
758 /* move row from source_row position to dest_row position */
759 void gtk_clist_row_move (GtkCList *clist,
763 /* sets a compare function different to the default */
764 void gtk_clist_set_compare_func (GtkCList *clist,
765 GtkCListCompareFunc cmp_func);
767 /* the column to sort by */
768 void gtk_clist_set_sort_column (GtkCList *clist,
771 /* how to sort : ascending or descending */
772 void gtk_clist_set_sort_type (GtkCList *clist,
773 GtkSortType sort_type);
775 /* sort the list with the current compare function */
776 void gtk_clist_sort (GtkCList *clist);
778 /* Automatically sort upon insertion */
779 void gtk_clist_set_auto_sort (GtkCList *clist,
785 #endif /* __cplusplus */
787 #endif /* __GTK_CLIST_H__ */