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;
171 GdkRectangle column_title_area;
172 GdkWindow *title_window;
174 /* dynamicly allocated array of column structures */
175 GtkCListColumn *column;
177 /* the scrolling window and its height and width to
178 * make things a little speedier */
179 GdkWindow *clist_window;
180 gint clist_window_width;
181 gint clist_window_height;
183 /* offsets for scrolling */
187 /* border shadow style */
188 GtkShadowType shadow_type;
190 /* the list's selection mode (gtkenums.h) */
191 GtkSelectionMode selection_mode;
193 /* list of selected rows */
195 GList *selection_end;
197 GList *undo_selection;
198 GList *undo_unselection;
202 guint8 button_actions[5];
207 GtkCListCellInfo click_cell;
209 /* scroll adjustments */
210 GtkAdjustment *hadjustment;
211 GtkAdjustment *vadjustment;
213 /* xor GC for the vertical drag line */
216 /* gc for drawing unselected cells */
220 /* cursor used to indicate dragging */
221 GdkCursor *cursor_drag;
223 /* the current x-pixel location of the xor-drag line */
229 /* dragging the selection */
231 GtkStateType anchor_state;
236 GtkSortType sort_type;
237 GtkCListCompareFunc compare;
241 struct _GtkCListClass
243 GtkContainerClass parent_class;
245 void (*set_scroll_adjustments) (GtkCList *clist,
246 GtkAdjustment *hadjustment,
247 GtkAdjustment *vadjustment);
248 void (*refresh) (GtkCList *clist);
249 void (*select_row) (GtkCList *clist,
253 void (*unselect_row) (GtkCList *clist,
257 void (*row_move) (GtkCList *clist,
260 void (*click_column) (GtkCList *clist,
262 void (*resize_column) (GtkCList *clist,
265 void (*toggle_focus_row) (GtkCList *clist);
266 void (*select_all) (GtkCList *clist);
267 void (*unselect_all) (GtkCList *clist);
268 void (*undo_selection) (GtkCList *clist);
269 void (*start_selection) (GtkCList *clist);
270 void (*end_selection) (GtkCList *clist);
271 void (*extend_selection) (GtkCList *clist,
272 GtkScrollType scroll_type,
274 gboolean auto_start_selection);
275 void (*scroll_horizontal) (GtkCList *clist,
276 GtkScrollType scroll_type,
278 void (*scroll_vertical) (GtkCList *clist,
279 GtkScrollType scroll_type,
281 void (*toggle_add_mode) (GtkCList *clist);
282 void (*abort_column_resize) (GtkCList *clist);
283 void (*resync_selection) (GtkCList *clist,
285 GList* (*selection_find) (GtkCList *clist,
287 GList *row_list_element);
288 void (*draw_row) (GtkCList *clist,
291 GtkCListRow *clist_row);
292 void (*draw_drag_highlight) (GtkCList *clist,
293 GtkCListRow *target_row,
294 gint target_row_number,
295 GtkCListDragPos drag_pos);
296 void (*clear) (GtkCList *clist);
297 void (*fake_unselect_all) (GtkCList *clist,
299 void (*sort_list) (GtkCList *clist);
300 gint (*insert_row) (GtkCList *clist,
303 void (*remove_row) (GtkCList *clist,
305 void (*set_cell_contents) (GtkCList *clist,
306 GtkCListRow *clist_row,
313 void (*cell_size_request) (GtkCList *clist,
314 GtkCListRow *clist_row,
316 GtkRequisition *requisition);
320 struct _GtkCListColumn
331 GtkJustification justification;
335 guint resizeable : 1;
336 guint auto_resize : 1;
337 guint button_passive : 1;
351 GtkDestroyNotify destroy;
355 guint selectable : 1;
358 /* Cell Structures */
371 struct _GtkCellPixmap
384 struct _GtkCellPixText
399 struct _GtkCellWidget
439 GtkType gtk_clist_get_type (void);
441 /* constructors useful for gtk-- wrappers */
442 void gtk_clist_construct (GtkCList *clist,
446 /* create a new GtkCList */
447 GtkWidget* gtk_clist_new (gint columns);
448 GtkWidget* gtk_clist_new_with_titles (gint columns,
451 /* set adjustments of clist */
452 void gtk_clist_set_hadjustment (GtkCList *clist,
453 GtkAdjustment *adjustment);
454 void gtk_clist_set_vadjustment (GtkCList *clist,
455 GtkAdjustment *adjustment);
457 /* get adjustments of clist */
458 GtkAdjustment* gtk_clist_get_hadjustment (GtkCList *clist);
459 GtkAdjustment* gtk_clist_get_vadjustment (GtkCList *clist);
461 /* set the border style of the clist */
462 void gtk_clist_set_shadow_type (GtkCList *clist,
465 /* set the clist's selection mode */
466 void gtk_clist_set_selection_mode (GtkCList *clist,
467 GtkSelectionMode mode);
469 /* enable clists reorder ability */
470 void gtk_clist_set_reorderable (GtkCList *clist,
471 gboolean reorderable);
472 void gtk_clist_set_use_drag_icons (GtkCList *clist,
474 void gtk_clist_set_button_actions (GtkCList *clist,
476 guint8 button_actions);
478 /* freeze all visual updates of the list, and then thaw the list after
479 * you have made a number of changes and the updates wil occure in a
480 * more efficent mannor than if you made them on a unfrozen list
482 void gtk_clist_freeze (GtkCList *clist);
483 void gtk_clist_thaw (GtkCList *clist);
485 /* show and hide the column title buttons */
486 void gtk_clist_column_titles_show (GtkCList *clist);
487 void gtk_clist_column_titles_hide (GtkCList *clist);
489 /* set the column title to be a active title (responds to button presses,
490 * prelights, and grabs keyboard focus), or passive where it acts as just
493 void gtk_clist_column_title_active (GtkCList *clist,
495 void gtk_clist_column_title_passive (GtkCList *clist,
497 void gtk_clist_column_titles_active (GtkCList *clist);
498 void gtk_clist_column_titles_passive (GtkCList *clist);
500 /* set the title in the column title button */
501 void gtk_clist_set_column_title (GtkCList *clist,
505 /* returns the title of column. Returns NULL if title is not set */
506 gchar * gtk_clist_get_column_title (GtkCList *clist,
509 /* set a widget instead of a title for the column title button */
510 void gtk_clist_set_column_widget (GtkCList *clist,
514 /* returns the column widget */
515 GtkWidget * gtk_clist_get_column_widget (GtkCList *clist,
518 /* set the justification on a column */
519 void gtk_clist_set_column_justification (GtkCList *clist,
521 GtkJustification justification);
523 /* set visibility of a column */
524 void gtk_clist_set_column_visibility (GtkCList *clist,
528 /* enable/disable column resize operations by mouse */
529 void gtk_clist_set_column_resizeable (GtkCList *clist,
531 gboolean resizeable);
533 /* resize column automatically to its optimal width */
534 void gtk_clist_set_column_auto_resize (GtkCList *clist,
536 gboolean auto_resize);
538 gint gtk_clist_columns_autosize (GtkCList *clist);
540 /* return the optimal column width, i.e. maximum of all cell widths */
541 gint gtk_clist_optimal_column_width (GtkCList *clist,
544 /* set the pixel width of a column; this is a necessary step in
545 * creating a CList because otherwise the column width is chozen from
546 * the width of the column title, which will never be right
548 void gtk_clist_set_column_width (GtkCList *clist,
552 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
553 void gtk_clist_set_column_min_width (GtkCList *clist,
556 void gtk_clist_set_column_max_width (GtkCList *clist,
560 /* change the height of the rows, the default (height=0) is
561 * the hight of the current font.
563 void gtk_clist_set_row_height (GtkCList *clist,
566 /* scroll the viewing area of the list to the given column and row;
567 * row_align and col_align are between 0-1 representing the location the
568 * row should appear on the screnn, 0.0 being top or left, 1.0 being
569 * bottom or right; if row or column is -1 then then there is no change
571 void gtk_clist_moveto (GtkCList *clist,
577 /* returns whether the row is visible */
578 GtkVisibility gtk_clist_row_is_visible (GtkCList *clist,
581 /* returns the cell type */
582 GtkCellType gtk_clist_get_cell_type (GtkCList *clist,
586 /* sets a given cell's text, replacing its current contents */
587 void gtk_clist_set_text (GtkCList *clist,
592 /* for the "get" functions, any of the return pointer can be
593 * NULL if you are not interested
595 gint gtk_clist_get_text (GtkCList *clist,
600 /* sets a given cell's pixmap, replacing its current contents */
601 void gtk_clist_set_pixmap (GtkCList *clist,
607 gint gtk_clist_get_pixmap (GtkCList *clist,
613 /* sets a given cell's pixmap and text, replacing its current contents */
614 void gtk_clist_set_pixtext (GtkCList *clist,
622 gint gtk_clist_get_pixtext (GtkCList *clist,
630 /* sets the foreground color of a row, the color must already
633 void gtk_clist_set_foreground (GtkCList *clist,
637 /* sets the background color of a row, the color must already
640 void gtk_clist_set_background (GtkCList *clist,
644 /* set / get cell styles */
645 void gtk_clist_set_cell_style (GtkCList *clist,
650 GtkStyle *gtk_clist_get_cell_style (GtkCList *clist,
654 void gtk_clist_set_row_style (GtkCList *clist,
658 GtkStyle *gtk_clist_get_row_style (GtkCList *clist,
661 /* this sets a horizontal and vertical shift for drawing
662 * the contents of a cell; it can be positive or negitive;
663 * this is particulary useful for indenting items in a column
665 void gtk_clist_set_shift (GtkCList *clist,
671 /* set/get selectable flag of a single row */
672 void gtk_clist_set_selectable (GtkCList *clist,
674 gboolean selectable);
675 gboolean gtk_clist_get_selectable (GtkCList *clist,
678 /* prepend/append returns the index of the row you just added,
679 * making it easier to append and modify a row
681 gint gtk_clist_prepend (GtkCList *clist,
683 gint gtk_clist_append (GtkCList *clist,
686 /* inserts a row at index row and returns the row where it was
687 * actually inserted (may be different from "row" in auto_sort mode)
689 gint gtk_clist_insert (GtkCList *clist,
693 /* removes row at index row */
694 void gtk_clist_remove (GtkCList *clist,
697 /* sets a arbitrary data pointer for a given row */
698 void gtk_clist_set_row_data (GtkCList *clist,
702 /* sets a data pointer for a given row with destroy notification */
703 void gtk_clist_set_row_data_full (GtkCList *clist,
706 GtkDestroyNotify destroy);
708 /* returns the data set for a row */
709 gpointer gtk_clist_get_row_data (GtkCList *clist,
712 /* givin a data pointer, find the first (and hopefully only!)
713 * row that points to that data, or -1 if none do
715 gint gtk_clist_find_row_from_data (GtkCList *clist,
718 /* force selection of a row */
719 void gtk_clist_select_row (GtkCList *clist,
723 /* force unselection of a row */
724 void gtk_clist_unselect_row (GtkCList *clist,
728 /* undo the last select/unselect operation */
729 void gtk_clist_undo_selection (GtkCList *clist);
731 /* clear the entire list -- this is much faster than removing
732 * each item with gtk_clist_remove
734 void gtk_clist_clear (GtkCList *clist);
736 /* return the row column corresponding to the x and y coordinates,
737 * the returned values are only valid if the x and y coordinates
738 * are respectively to a window == clist->clist_window
740 gint gtk_clist_get_selection_info (GtkCList *clist,
746 /* in multiple or extended mode, select all rows */
747 void gtk_clist_select_all (GtkCList *clist);
749 /* in all modes except browse mode, deselect all rows */
750 void gtk_clist_unselect_all (GtkCList *clist);
752 /* swap the position of two rows */
753 void gtk_clist_swap_rows (GtkCList *clist,
757 /* move row from source_row position to dest_row position */
758 void gtk_clist_row_move (GtkCList *clist,
762 /* sets a compare function different to the default */
763 void gtk_clist_set_compare_func (GtkCList *clist,
764 GtkCListCompareFunc cmp_func);
766 /* the column to sort by */
767 void gtk_clist_set_sort_column (GtkCList *clist,
770 /* how to sort : ascending or descending */
771 void gtk_clist_set_sort_type (GtkCList *clist,
772 GtkSortType sort_type);
774 /* sort the list with the current compare function */
775 void gtk_clist_sort (GtkCList *clist);
777 /* Automatically sort upon insertion */
778 void gtk_clist_set_auto_sort (GtkCList *clist,
781 /* Private function for clist, ctree */
783 PangoLayout *_gtk_clist_create_cell_layout (GtkCList *clist,
784 GtkCListRow *clist_row,
789 #endif /* __cplusplus */
791 #endif /* __GTK_CLIST_H__ */