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 Lesser 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser 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-2000. 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_CMCLIST_H__
29 #define __GTK_CMCLIST_H__
38 #if GTK_CHECK_VERSION(3, 0, 0)
39 /* Generic visibility flags */
43 GTK_VISIBILITY_PARTIAL,
50 GTK_CMCLIST_IN_DRAG = 1 << 0,
51 GTK_CMCLIST_ROW_HEIGHT_SET = 1 << 1,
52 GTK_CMCLIST_SHOW_TITLES = 1 << 2,
54 GTK_CMCLIST_ADD_MODE = 1 << 4,
55 GTK_CMCLIST_AUTO_SORT = 1 << 5,
56 GTK_CMCLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
57 GTK_CMCLIST_REORDERABLE = 1 << 7,
58 GTK_CMCLIST_USE_DRAG_ICONS = 1 << 8,
59 GTK_CMCLIST_DRAW_DRAG_LINE = 1 << 9,
60 GTK_CMCLIST_DRAW_DRAG_RECT = 1 << 10
75 GTK_CMCLIST_DRAG_NONE,
76 GTK_CMCLIST_DRAG_BEFORE,
77 GTK_CMCLIST_DRAG_INTO,
78 GTK_CMCLIST_DRAG_AFTER
83 GTK_CMBUTTON_IGNORED = 0,
84 GTK_CMBUTTON_SELECTS = 1 << 0,
85 GTK_CMBUTTON_DRAGS = 1 << 1,
86 GTK_CMBUTTON_EXPANDS = 1 << 2
89 #define GTK_TYPE_CMCLIST (gtk_cmclist_get_type ())
90 #define GTK_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CMCLIST, GtkCMCList))
91 #define GTK_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CMCLIST, GtkCMCListClass))
92 #define GTK_IS_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CMCLIST))
93 #define GTK_IS_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CMCLIST))
94 #define GTK_CMCLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CMCLIST, GtkCMCListClass))
97 #define GTK_CMCLIST_FLAGS(clist) (GTK_CMCLIST (clist)->flags)
98 #define GTK_CMCLIST_SET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) |= (GTK_ ## flag))
99 #define GTK_CMCLIST_UNSET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) &= ~(GTK_ ## flag))
101 #define GTK_CMCLIST_IN_DRAG(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_IN_DRAG)
102 #define GTK_CMCLIST_ROW_HEIGHT_SET(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ROW_HEIGHT_SET)
103 #define GTK_CMCLIST_SHOW_TITLES(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_SHOW_TITLES)
104 #define GTK_CMCLIST_ADD_MODE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ADD_MODE)
105 #define GTK_CMCLIST_AUTO_SORT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_SORT)
106 #define GTK_CMCLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_RESIZE_BLOCKED)
107 #define GTK_CMCLIST_REORDERABLE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_REORDERABLE)
108 #define GTK_CMCLIST_USE_DRAG_ICONS(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_USE_DRAG_ICONS)
109 #define GTK_CMCLIST_DRAW_DRAG_LINE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_LINE)
110 #define GTK_CMCLIST_DRAW_DRAG_RECT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_RECT)
112 #define GTK_CMCLIST_ROW(_glist_) ((GtkCMCListRow *)((_glist_)->data))
114 /* pointer casting for cells */
115 #define GTK_CMCELL_TEXT(cell) (((GtkCMCellText *) &(cell)))
116 #define GTK_CMCELL_PIXBUF(cell) (((GtkCMCellPixbuf *) &(cell)))
117 #define GTK_CMCELL_PIXTEXT(cell) (((GtkCMCellPixText *) &(cell)))
118 #define GTK_CMCELL_WIDGET(cell) (((GtkCMCellWidget *) &(cell)))
120 typedef struct _GtkCMCList GtkCMCList;
121 typedef struct _GtkCMCListClass GtkCMCListClass;
122 typedef struct _GtkCMCListColumn GtkCMCListColumn;
123 typedef struct _GtkCMCListRow GtkCMCListRow;
125 typedef struct _GtkCMCell GtkCMCell;
126 typedef struct _GtkCMCellText GtkCMCellText;
127 typedef struct _GtkCMCellPixbuf GtkCMCellPixbuf;
128 typedef struct _GtkCMCellPixText GtkCMCellPixText;
129 typedef struct _GtkCMCellWidget GtkCMCellWidget;
131 typedef gint (*GtkCMCListCompareFunc) (GtkCMCList *clist,
135 typedef struct _GtkCMCListCellInfo GtkCMCListCellInfo;
136 typedef struct _GtkCMCListDestInfo GtkCMCListDestInfo;
138 struct _GtkCMCListCellInfo
144 struct _GtkCMCListDestInfo
146 GtkCMCListCellInfo cell;
147 GtkCMCListDragPos insert_pos;
152 GtkContainer container;
156 #if !GLIB_CHECK_VERSION(2,10,0)
157 GMemChunk *row_mem_chunk;
158 GMemChunk *cell_mem_chunk;
165 /* allocation rectangle after the conatiner_border_width
166 * and the width of the shadow border */
167 GdkRectangle internal_allocation;
177 GdkRectangle column_title_area;
178 GdkWindow *title_window;
180 /* dynamicly allocated array of column structures */
181 GtkCMCListColumn *column;
183 /* the scrolling window and its height and width to
184 * make things a little speedier */
185 GdkWindow *clist_window;
186 gint clist_window_width;
187 gint clist_window_height;
189 /* offsets for scrolling */
193 /* border shadow style */
194 GtkShadowType shadow_type;
196 /* the list's selection mode (gtkenums.h) */
197 GtkSelectionMode selection_mode;
199 /* list of selected rows */
201 GList *selection_end;
203 GList *undo_selection;
204 GList *undo_unselection;
208 guint8 button_actions[5];
213 GtkCMCListCellInfo click_cell;
215 /* scroll adjustments */
216 GtkAdjustment *hadjustment;
217 GtkAdjustment *vadjustment;
221 /* cursor used to indicate dragging */
222 GdkCursor *cursor_drag;
224 /* the current x-pixel location of the xor-drag line */
230 gint focus_header_column;
232 /* dragging the selection */
234 GtkStateType anchor_state;
239 GtkSortType sort_type;
240 GtkCMCListCompareFunc compare;
243 gint drag_highlight_row;
244 GtkCMCListDragPos drag_highlight_pos;
247 struct _GtkCMCListClass
249 GtkContainerClass parent_class;
251 #if !GTK_CHECK_VERSION(3, 0, 0)
252 void (*set_scroll_adjustments) (GtkCMCList *clist,
253 GtkAdjustment *hadjustment,
254 GtkAdjustment *vadjustment);
256 void (*refresh) (GtkCMCList *clist);
257 void (*select_row) (GtkCMCList *clist,
261 void (*unselect_row) (GtkCMCList *clist,
265 void (*row_move) (GtkCMCList *clist,
268 void (*click_column) (GtkCMCList *clist,
270 void (*resize_column) (GtkCMCList *clist,
273 void (*toggle_focus_row) (GtkCMCList *clist);
274 void (*select_all) (GtkCMCList *clist);
275 void (*unselect_all) (GtkCMCList *clist);
276 void (*undo_selection) (GtkCMCList *clist);
277 void (*start_selection) (GtkCMCList *clist);
278 void (*end_selection) (GtkCMCList *clist);
279 void (*extend_selection) (GtkCMCList *clist,
280 GtkScrollType scroll_type,
282 gboolean auto_start_selection);
283 void (*scroll_horizontal) (GtkCMCList *clist,
284 GtkScrollType scroll_type,
286 void (*scroll_vertical) (GtkCMCList *clist,
287 GtkScrollType scroll_type,
289 void (*toggle_add_mode) (GtkCMCList *clist);
290 void (*abort_column_resize) (GtkCMCList *clist);
291 void (*resync_selection) (GtkCMCList *clist,
293 GList* (*selection_find) (GtkCMCList *clist,
295 GList *row_list_element);
296 void (*draw_row) (GtkCMCList *clist,
299 GtkCMCListRow *clist_row);
300 void (*clear) (GtkCMCList *clist);
301 void (*fake_unselect_all) (GtkCMCList *clist,
303 void (*sort_list) (GtkCMCList *clist);
304 gint (*insert_row) (GtkCMCList *clist,
307 void (*remove_row) (GtkCMCList *clist,
309 void (*set_cell_contents) (GtkCMCList *clist,
310 GtkCMCListRow *clist_row,
316 void (*cell_size_request) (GtkCMCList *clist,
317 GtkCMCListRow *clist_row,
319 GtkRequisition *requisition);
323 struct _GtkCMCListColumn
334 GtkJustification justification;
338 guint resizeable : 1;
339 guint auto_resize : 1;
340 guint button_passive : 1;
343 struct _GtkCMCListRow
354 GDestroyNotify destroy;
358 guint selectable : 1;
361 /* Cell Structures */
362 struct _GtkCMCellText
374 struct _GtkCMCellPixbuf
386 struct _GtkCMCellPixText
400 struct _GtkCMCellWidget
438 GType gtk_cmclist_get_type (void);
440 /* create a new GtkCMCList */
441 GtkWidget* gtk_cmclist_new (gint columns);
442 GtkWidget* gtk_cmclist_new_with_titles (gint columns,
445 /* set adjustments of clist */
446 void gtk_cmclist_set_hadjustment (GtkCMCList *clist,
447 GtkAdjustment *adjustment);
448 void gtk_cmclist_set_vadjustment (GtkCMCList *clist,
449 GtkAdjustment *adjustment);
451 /* get adjustments of clist */
452 GtkAdjustment* gtk_cmclist_get_hadjustment (GtkCMCList *clist);
453 GtkAdjustment* gtk_cmclist_get_vadjustment (GtkCMCList *clist);
455 /* set the border style of the clist */
456 void gtk_cmclist_set_shadow_type (GtkCMCList *clist,
459 /* set the clist's selection mode */
460 void gtk_cmclist_set_selection_mode (GtkCMCList *clist,
461 GtkSelectionMode mode);
463 /* enable clists reorder ability */
464 void gtk_cmclist_set_reorderable (GtkCMCList *clist,
465 gboolean reorderable);
466 void gtk_cmclist_set_use_drag_icons (GtkCMCList *clist,
468 void gtk_cmclist_set_button_actions (GtkCMCList *clist,
470 guint8 button_actions);
472 /* freeze all visual updates of the list, and then thaw the list after
473 * you have made a number of changes and the updates wil occure in a
474 * more efficent mannor than if you made them on a unfrozen list
476 void gtk_cmclist_freeze (GtkCMCList *clist);
477 void gtk_cmclist_thaw (GtkCMCList *clist);
479 /* show and hide the column title buttons */
480 void gtk_cmclist_column_titles_show (GtkCMCList *clist);
481 void gtk_cmclist_column_titles_hide (GtkCMCList *clist);
483 /* set the column title to be a active title (responds to button presses,
484 * prelights, and grabs keyboard focus), or passive where it acts as just
487 void gtk_cmclist_column_title_active (GtkCMCList *clist,
489 void gtk_cmclist_column_title_passive (GtkCMCList *clist,
491 void gtk_cmclist_column_titles_active (GtkCMCList *clist);
492 void gtk_cmclist_column_titles_passive (GtkCMCList *clist);
494 /* set the title in the column title button */
495 void gtk_cmclist_set_column_title (GtkCMCList *clist,
499 /* returns the title of column. Returns NULL if title is not set */
500 gchar * gtk_cmclist_get_column_title (GtkCMCList *clist,
503 /* set a widget instead of a title for the column title button */
504 void gtk_cmclist_set_column_widget (GtkCMCList *clist,
508 /* returns the column widget */
509 GtkWidget * gtk_cmclist_get_column_widget (GtkCMCList *clist,
512 /* set the justification on a column */
513 void gtk_cmclist_set_column_justification (GtkCMCList *clist,
515 GtkJustification justification);
517 /* set visibility of a column */
518 void gtk_cmclist_set_column_visibility (GtkCMCList *clist,
522 /* enable/disable column resize operations by mouse */
523 void gtk_cmclist_set_column_resizeable (GtkCMCList *clist,
525 gboolean resizeable);
527 /* resize column automatically to its optimal width */
528 void gtk_cmclist_set_column_auto_resize (GtkCMCList *clist,
530 gboolean auto_resize);
532 gint gtk_cmclist_columns_autosize (GtkCMCList *clist);
534 /* return the optimal column width, i.e. maximum of all cell widths */
535 gint gtk_cmclist_optimal_column_width (GtkCMCList *clist,
538 /* set the pixel width of a column; this is a necessary step in
539 * creating a CList because otherwise the column width is chozen from
540 * the width of the column title, which will never be right
542 void gtk_cmclist_set_column_width (GtkCMCList *clist,
546 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
547 void gtk_cmclist_set_column_min_width (GtkCMCList *clist,
550 void gtk_cmclist_set_column_max_width (GtkCMCList *clist,
554 /* change the height of the rows, the default (height=0) is
555 * the hight of the current font.
557 void gtk_cmclist_set_row_height (GtkCMCList *clist,
560 /* scroll the viewing area of the list to the given column and row;
561 * row_align and col_align are between 0-1 representing the location the
562 * row should appear on the screnn, 0.0 being top or left, 1.0 being
563 * bottom or right; if row or column is -1 then then there is no change
565 void gtk_cmclist_moveto (GtkCMCList *clist,
571 /* returns whether the row is visible */
572 GtkVisibility gtk_cmclist_row_is_visible (GtkCMCList *clist,
575 /* returns the cell type */
576 GtkCMCellType gtk_cmclist_get_cell_type (GtkCMCList *clist,
580 /* sets a given cell's text, replacing its current contents */
581 void gtk_cmclist_set_text (GtkCMCList *clist,
586 /* for the "get" functions, any of the return pointer can be
587 * NULL if you are not interested
589 gint gtk_cmclist_get_text (GtkCMCList *clist,
594 /* sets a given cell's pixbuf, replacing its current contents */
595 void gtk_cmclist_set_pixbuf (GtkCMCList *clist,
600 gint gtk_cmclist_get_pixbuf (GtkCMCList *clist,
605 /* sets a given cell's pixbuf and text, replacing its current contents */
606 void gtk_cmclist_set_pixtext (GtkCMCList *clist,
613 gint gtk_cmclist_get_pixtext (GtkCMCList *clist,
620 /* sets the foreground color of a row, the color must already
623 void gtk_cmclist_set_foreground (GtkCMCList *clist,
625 const GdkColor *color);
627 /* sets the background color of a row, the color must already
630 void gtk_cmclist_set_background (GtkCMCList *clist,
632 const GdkColor *color);
634 /* set / get cell styles */
635 void gtk_cmclist_set_cell_style (GtkCMCList *clist,
640 GtkStyle *gtk_cmclist_get_cell_style (GtkCMCList *clist,
644 void gtk_cmclist_set_row_style (GtkCMCList *clist,
648 GtkStyle *gtk_cmclist_get_row_style (GtkCMCList *clist,
651 /* this sets a horizontal and vertical shift for drawing
652 * the contents of a cell; it can be positive or negitive;
653 * this is particulary useful for indenting items in a column
655 void gtk_cmclist_set_shift (GtkCMCList *clist,
661 /* set/get selectable flag of a single row */
662 void gtk_cmclist_set_selectable (GtkCMCList *clist,
664 gboolean selectable);
665 gboolean gtk_cmclist_get_selectable (GtkCMCList *clist,
668 /* prepend/append returns the index of the row you just added,
669 * making it easier to append and modify a row
671 gint gtk_cmclist_prepend (GtkCMCList *clist,
673 gint gtk_cmclist_append (GtkCMCList *clist,
676 /* inserts a row at index row and returns the row where it was
677 * actually inserted (may be different from "row" in auto_sort mode)
679 gint gtk_cmclist_insert (GtkCMCList *clist,
683 /* removes row at index row */
684 void gtk_cmclist_remove (GtkCMCList *clist,
687 /* sets a arbitrary data pointer for a given row */
688 void gtk_cmclist_set_row_data (GtkCMCList *clist,
692 /* sets a data pointer for a given row with destroy notification */
693 void gtk_cmclist_set_row_data_full (GtkCMCList *clist,
696 GDestroyNotify destroy);
698 /* returns the data set for a row */
699 gpointer gtk_cmclist_get_row_data (GtkCMCList *clist,
702 /* givin a data pointer, find the first (and hopefully only!)
703 * row that points to that data, or -1 if none do
705 gint gtk_cmclist_find_row_from_data (GtkCMCList *clist,
708 /* force selection of a row */
709 void gtk_cmclist_select_row (GtkCMCList *clist,
713 /* force unselection of a row */
714 void gtk_cmclist_unselect_row (GtkCMCList *clist,
718 /* undo the last select/unselect operation */
719 void gtk_cmclist_undo_selection (GtkCMCList *clist);
721 /* clear the entire list -- this is much faster than removing
722 * each item with gtk_cmclist_remove
724 void gtk_cmclist_clear (GtkCMCList *clist);
726 /* return the row column corresponding to the x and y coordinates,
727 * the returned values are only valid if the x and y coordinates
728 * are respectively to a window == clist->clist_window
730 gint gtk_cmclist_get_selection_info (GtkCMCList *clist,
736 /* in multiple or extended mode, select all rows */
737 void gtk_cmclist_select_all (GtkCMCList *clist);
739 /* in all modes except browse mode, deselect all rows */
740 void gtk_cmclist_unselect_all (GtkCMCList *clist);
742 /* swap the position of two rows */
743 void gtk_cmclist_swap_rows (GtkCMCList *clist,
747 /* move row from source_row position to dest_row position */
748 void gtk_cmclist_row_move (GtkCMCList *clist,
752 /* sets a compare function different to the default */
753 void gtk_cmclist_set_compare_func (GtkCMCList *clist,
754 GtkCMCListCompareFunc cmp_func);
756 /* the column to sort by */
757 void gtk_cmclist_set_sort_column (GtkCMCList *clist,
760 /* how to sort : ascending or descending */
761 void gtk_cmclist_set_sort_type (GtkCMCList *clist,
762 GtkSortType sort_type);
764 /* sort the list with the current compare function */
765 void gtk_cmclist_sort (GtkCMCList *clist);
767 /* Automatically sort upon insertion */
768 void gtk_cmclist_set_auto_sort (GtkCMCList *clist,
771 /* Private function for clist, ctree */
773 PangoLayout *_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
774 GtkCMCListRow *clist_row,
781 #endif /* __GTK_CMCLIST_H__ */