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))
91 #define GTK_CLIST_FLAGS(clist) (GTK_CLIST (clist)->flags)
92 #define GTK_CLIST_SET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) |= (GTK_ ## flag))
93 #define GTK_CLIST_UNSET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) &= ~(GTK_ ## flag))
95 #define GTK_CLIST_IN_DRAG(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_IN_DRAG)
96 #define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET)
97 #define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES)
98 #define GTK_CLIST_CHILD_HAS_FOCUS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CHILD_HAS_FOCUS)
99 #define GTK_CLIST_ADD_MODE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ADD_MODE)
100 #define GTK_CLIST_AUTO_SORT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_SORT)
101 #define GTK_CLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_RESIZE_BLOCKED)
102 #define GTK_CLIST_REORDERABLE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_REORDERABLE)
103 #define GTK_CLIST_USE_DRAG_ICONS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_USE_DRAG_ICONS)
104 #define GTK_CLIST_DRAW_DRAG_LINE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_LINE)
105 #define GTK_CLIST_DRAW_DRAG_RECT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_RECT)
107 #define GTK_CLIST_ROW(_glist_) ((GtkCListRow *)((_glist_)->data))
109 /* pointer casting for cells */
110 #define GTK_CELL_TEXT(cell) (((GtkCellText *) &(cell)))
111 #define GTK_CELL_PIXMAP(cell) (((GtkCellPixmap *) &(cell)))
112 #define GTK_CELL_PIXTEXT(cell) (((GtkCellPixText *) &(cell)))
113 #define GTK_CELL_WIDGET(cell) (((GtkCellWidget *) &(cell)))
115 typedef struct _GtkCList GtkCList;
116 typedef struct _GtkCListClass GtkCListClass;
117 typedef struct _GtkCListColumn GtkCListColumn;
118 typedef struct _GtkCListRow GtkCListRow;
120 typedef struct _GtkCell GtkCell;
121 typedef struct _GtkCellText GtkCellText;
122 typedef struct _GtkCellPixmap GtkCellPixmap;
123 typedef struct _GtkCellPixText GtkCellPixText;
124 typedef struct _GtkCellWidget GtkCellWidget;
126 typedef gint (*GtkCListCompareFunc) (GtkCList *clist,
130 typedef struct _GtkCListCellInfo GtkCListCellInfo;
131 typedef struct _GtkCListDestInfo GtkCListDestInfo;
133 struct _GtkCListCellInfo
139 struct _GtkCListDestInfo
141 GtkCListCellInfo cell;
142 GtkCListDragPos insert_pos;
147 GtkContainer container;
152 GMemChunk *row_mem_chunk;
153 GMemChunk *cell_mem_chunk;
157 /* allocation rectangle after the conatiner_border_width
158 * and the width of the shadow border */
159 GdkRectangle internal_allocation;
163 gint row_center_offset;
170 GdkRectangle column_title_area;
171 GdkWindow *title_window;
173 /* dynamicly allocated array of column structures */
174 GtkCListColumn *column;
176 /* the scrolling window and its height and width to
177 * make things a little speedier */
178 GdkWindow *clist_window;
179 gint clist_window_width;
180 gint clist_window_height;
182 /* offsets for scrolling */
186 /* border shadow style */
187 GtkShadowType shadow_type;
189 /* the list's selection mode (gtkenums.h) */
190 GtkSelectionMode selection_mode;
192 /* list of selected rows */
194 GList *selection_end;
196 GList *undo_selection;
197 GList *undo_unselection;
201 guint8 button_actions[5];
206 GtkCListCellInfo click_cell;
208 /* scroll adjustments */
209 GtkAdjustment *hadjustment;
210 GtkAdjustment *vadjustment;
212 /* xor GC for the vertical drag line */
215 /* gc for drawing unselected cells */
219 /* cursor used to indicate dragging */
220 GdkCursor *cursor_drag;
222 /* the current x-pixel location of the xor-drag line */
228 /* dragging the selection */
230 GtkStateType anchor_state;
235 GtkSortType sort_type;
236 GtkCListCompareFunc compare;
240 struct _GtkCListClass
242 GtkContainerClass parent_class;
244 void (*set_scroll_adjustments) (GtkCList *clist,
245 GtkAdjustment *hadjustment,
246 GtkAdjustment *vadjustment);
247 void (*refresh) (GtkCList *clist);
248 void (*select_row) (GtkCList *clist,
252 void (*unselect_row) (GtkCList *clist,
256 void (*row_move) (GtkCList *clist,
259 void (*click_column) (GtkCList *clist,
261 void (*resize_column) (GtkCList *clist,
264 void (*toggle_focus_row) (GtkCList *clist);
265 void (*select_all) (GtkCList *clist);
266 void (*unselect_all) (GtkCList *clist);
267 void (*undo_selection) (GtkCList *clist);
268 void (*start_selection) (GtkCList *clist);
269 void (*end_selection) (GtkCList *clist);
270 void (*extend_selection) (GtkCList *clist,
271 GtkScrollType scroll_type,
273 gboolean auto_start_selection);
274 void (*scroll_horizontal) (GtkCList *clist,
275 GtkScrollType scroll_type,
277 void (*scroll_vertical) (GtkCList *clist,
278 GtkScrollType scroll_type,
280 void (*toggle_add_mode) (GtkCList *clist);
281 void (*abort_column_resize) (GtkCList *clist);
282 void (*resync_selection) (GtkCList *clist,
284 GList* (*selection_find) (GtkCList *clist,
286 GList *row_list_element);
287 void (*draw_row) (GtkCList *clist,
290 GtkCListRow *clist_row);
291 void (*draw_drag_highlight) (GtkCList *clist,
292 GtkCListRow *target_row,
293 gint target_row_number,
294 GtkCListDragPos drag_pos);
295 void (*clear) (GtkCList *clist);
296 void (*fake_unselect_all) (GtkCList *clist,
298 void (*sort_list) (GtkCList *clist);
299 gint (*insert_row) (GtkCList *clist,
302 void (*remove_row) (GtkCList *clist,
304 void (*set_cell_contents) (GtkCList *clist,
305 GtkCListRow *clist_row,
312 void (*cell_size_request) (GtkCList *clist,
313 GtkCListRow *clist_row,
315 GtkRequisition *requisition);
319 struct _GtkCListColumn
330 GtkJustification justification;
334 guint resizeable : 1;
335 guint auto_resize : 1;
336 guint button_passive : 1;
350 GtkDestroyNotify destroy;
354 guint selectable : 1;
357 /* Cell Structures */
370 struct _GtkCellPixmap
383 struct _GtkCellPixText
398 struct _GtkCellWidget
438 GtkType gtk_clist_get_type (void);
440 /* constructors useful for gtk-- wrappers */
441 void gtk_clist_construct (GtkCList *clist,
445 /* create a new GtkCList */
446 GtkWidget* gtk_clist_new (gint columns);
447 GtkWidget* gtk_clist_new_with_titles (gint columns,
450 /* set adjustments of clist */
451 void gtk_clist_set_hadjustment (GtkCList *clist,
452 GtkAdjustment *adjustment);
453 void gtk_clist_set_vadjustment (GtkCList *clist,
454 GtkAdjustment *adjustment);
456 /* get adjustments of clist */
457 GtkAdjustment* gtk_clist_get_hadjustment (GtkCList *clist);
458 GtkAdjustment* gtk_clist_get_vadjustment (GtkCList *clist);
460 /* set the border style of the clist */
461 void gtk_clist_set_shadow_type (GtkCList *clist,
464 /* set the clist's selection mode */
465 void gtk_clist_set_selection_mode (GtkCList *clist,
466 GtkSelectionMode mode);
468 /* enable clists reorder ability */
469 void gtk_clist_set_reorderable (GtkCList *clist,
470 gboolean reorderable);
471 void gtk_clist_set_use_drag_icons (GtkCList *clist,
473 void gtk_clist_set_button_actions (GtkCList *clist,
475 guint8 button_actions);
477 /* freeze all visual updates of the list, and then thaw the list after
478 * you have made a number of changes and the updates wil occure in a
479 * more efficent mannor than if you made them on a unfrozen list
481 void gtk_clist_freeze (GtkCList *clist);
482 void gtk_clist_thaw (GtkCList *clist);
484 /* show and hide the column title buttons */
485 void gtk_clist_column_titles_show (GtkCList *clist);
486 void gtk_clist_column_titles_hide (GtkCList *clist);
488 /* set the column title to be a active title (responds to button presses,
489 * prelights, and grabs keyboard focus), or passive where it acts as just
492 void gtk_clist_column_title_active (GtkCList *clist,
494 void gtk_clist_column_title_passive (GtkCList *clist,
496 void gtk_clist_column_titles_active (GtkCList *clist);
497 void gtk_clist_column_titles_passive (GtkCList *clist);
499 /* set the title in the column title button */
500 void gtk_clist_set_column_title (GtkCList *clist,
504 /* returns the title of column. Returns NULL if title is not set */
505 gchar * gtk_clist_get_column_title (GtkCList *clist,
508 /* set a widget instead of a title for the column title button */
509 void gtk_clist_set_column_widget (GtkCList *clist,
513 /* returns the column widget */
514 GtkWidget * gtk_clist_get_column_widget (GtkCList *clist,
517 /* set the justification on a column */
518 void gtk_clist_set_column_justification (GtkCList *clist,
520 GtkJustification justification);
522 /* set visibility of a column */
523 void gtk_clist_set_column_visibility (GtkCList *clist,
527 /* enable/disable column resize operations by mouse */
528 void gtk_clist_set_column_resizeable (GtkCList *clist,
530 gboolean resizeable);
532 /* resize column automatically to its optimal width */
533 void gtk_clist_set_column_auto_resize (GtkCList *clist,
535 gboolean auto_resize);
537 gint gtk_clist_columns_autosize (GtkCList *clist);
539 /* return the optimal column width, i.e. maximum of all cell widths */
540 gint gtk_clist_optimal_column_width (GtkCList *clist,
543 /* set the pixel width of a column; this is a necessary step in
544 * creating a CList because otherwise the column width is chozen from
545 * the width of the column title, which will never be right
547 void gtk_clist_set_column_width (GtkCList *clist,
551 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
552 void gtk_clist_set_column_min_width (GtkCList *clist,
555 void gtk_clist_set_column_max_width (GtkCList *clist,
559 /* change the height of the rows, the default (height=0) is
560 * the hight of the current font.
562 void gtk_clist_set_row_height (GtkCList *clist,
565 /* scroll the viewing area of the list to the given column and row;
566 * row_align and col_align are between 0-1 representing the location the
567 * row should appear on the screnn, 0.0 being top or left, 1.0 being
568 * bottom or right; if row or column is -1 then then there is no change
570 void gtk_clist_moveto (GtkCList *clist,
576 /* returns whether the row is visible */
577 GtkVisibility gtk_clist_row_is_visible (GtkCList *clist,
580 /* returns the cell type */
581 GtkCellType gtk_clist_get_cell_type (GtkCList *clist,
585 /* sets a given cell's text, replacing its current contents */
586 void gtk_clist_set_text (GtkCList *clist,
591 /* for the "get" functions, any of the return pointer can be
592 * NULL if you are not interested
594 gint gtk_clist_get_text (GtkCList *clist,
599 /* sets a given cell's pixmap, replacing its current contents */
600 void gtk_clist_set_pixmap (GtkCList *clist,
606 gint gtk_clist_get_pixmap (GtkCList *clist,
612 /* sets a given cell's pixmap and text, replacing its current contents */
613 void gtk_clist_set_pixtext (GtkCList *clist,
621 gint gtk_clist_get_pixtext (GtkCList *clist,
629 /* sets the foreground color of a row, the color must already
632 void gtk_clist_set_foreground (GtkCList *clist,
636 /* sets the background color of a row, the color must already
639 void gtk_clist_set_background (GtkCList *clist,
643 /* set / get cell styles */
644 void gtk_clist_set_cell_style (GtkCList *clist,
649 GtkStyle *gtk_clist_get_cell_style (GtkCList *clist,
653 void gtk_clist_set_row_style (GtkCList *clist,
657 GtkStyle *gtk_clist_get_row_style (GtkCList *clist,
660 /* this sets a horizontal and vertical shift for drawing
661 * the contents of a cell; it can be positive or negitive;
662 * this is particulary useful for indenting items in a column
664 void gtk_clist_set_shift (GtkCList *clist,
670 /* set/get selectable flag of a single row */
671 void gtk_clist_set_selectable (GtkCList *clist,
673 gboolean selectable);
674 gboolean gtk_clist_get_selectable (GtkCList *clist,
677 /* prepend/append returns the index of the row you just added,
678 * making it easier to append and modify a row
680 gint gtk_clist_prepend (GtkCList *clist,
682 gint gtk_clist_append (GtkCList *clist,
685 /* inserts a row at index row and returns the row where it was
686 * actually inserted (may be different from "row" in auto_sort mode)
688 gint gtk_clist_insert (GtkCList *clist,
692 /* removes row at index row */
693 void gtk_clist_remove (GtkCList *clist,
696 /* sets a arbitrary data pointer for a given row */
697 void gtk_clist_set_row_data (GtkCList *clist,
701 /* sets a data pointer for a given row with destroy notification */
702 void gtk_clist_set_row_data_full (GtkCList *clist,
705 GtkDestroyNotify destroy);
707 /* returns the data set for a row */
708 gpointer gtk_clist_get_row_data (GtkCList *clist,
711 /* givin a data pointer, find the first (and hopefully only!)
712 * row that points to that data, or -1 if none do
714 gint gtk_clist_find_row_from_data (GtkCList *clist,
717 /* force selection of a row */
718 void gtk_clist_select_row (GtkCList *clist,
722 /* force unselection of a row */
723 void gtk_clist_unselect_row (GtkCList *clist,
727 /* undo the last select/unselect operation */
728 void gtk_clist_undo_selection (GtkCList *clist);
730 /* clear the entire list -- this is much faster than removing
731 * each item with gtk_clist_remove
733 void gtk_clist_clear (GtkCList *clist);
735 /* return the row column corresponding to the x and y coordinates,
736 * the returned values are only valid if the x and y coordinates
737 * are respectively to a window == clist->clist_window
739 gint gtk_clist_get_selection_info (GtkCList *clist,
745 /* in multiple or extended mode, select all rows */
746 void gtk_clist_select_all (GtkCList *clist);
748 /* in all modes except browse mode, deselect all rows */
749 void gtk_clist_unselect_all (GtkCList *clist);
751 /* swap the position of two rows */
752 void gtk_clist_swap_rows (GtkCList *clist,
756 /* move row from source_row position to dest_row position */
757 void gtk_clist_row_move (GtkCList *clist,
761 /* sets a compare function different to the default */
762 void gtk_clist_set_compare_func (GtkCList *clist,
763 GtkCListCompareFunc cmp_func);
765 /* the column to sort by */
766 void gtk_clist_set_sort_column (GtkCList *clist,
769 /* how to sort : ascending or descending */
770 void gtk_clist_set_sort_type (GtkCList *clist,
771 GtkSortType sort_type);
773 /* sort the list with the current compare function */
774 void gtk_clist_sort (GtkCList *clist);
776 /* Automatically sort upon insertion */
777 void gtk_clist_set_auto_sort (GtkCList *clist,
783 #endif /* __cplusplus */
785 #endif /* __GTK_CLIST_H__ */