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__
40 GTK_CMCLIST_IN_DRAG = 1 << 0,
41 GTK_CMCLIST_ROW_HEIGHT_SET = 1 << 1,
42 GTK_CMCLIST_SHOW_TITLES = 1 << 2,
44 GTK_CMCLIST_ADD_MODE = 1 << 4,
45 GTK_CMCLIST_AUTO_SORT = 1 << 5,
46 GTK_CMCLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
47 GTK_CMCLIST_REORDERABLE = 1 << 7,
48 GTK_CMCLIST_USE_DRAG_ICONS = 1 << 8,
49 GTK_CMCLIST_DRAW_DRAG_LINE = 1 << 9,
50 GTK_CMCLIST_DRAW_DRAG_RECT = 1 << 10
65 GTK_CMCLIST_DRAG_NONE,
66 GTK_CMCLIST_DRAG_BEFORE,
67 GTK_CMCLIST_DRAG_INTO,
68 GTK_CMCLIST_DRAG_AFTER
73 GTK_CMBUTTON_IGNORED = 0,
74 GTK_CMBUTTON_SELECTS = 1 << 0,
75 GTK_CMBUTTON_DRAGS = 1 << 1,
76 GTK_CMBUTTON_EXPANDS = 1 << 2
79 #define GTK_TYPE_CMCLIST (gtk_cmclist_get_type ())
80 #define GTK_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CMCLIST, GtkCMCList))
81 #define GTK_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CMCLIST, GtkCMCListClass))
82 #define GTK_IS_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CMCLIST))
83 #define GTK_IS_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CMCLIST))
84 #define GTK_CMCLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CMCLIST, GtkCMCListClass))
87 #define GTK_CMCLIST_FLAGS(clist) (GTK_CMCLIST (clist)->flags)
88 #define GTK_CMCLIST_SET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) |= (GTK_ ## flag))
89 #define GTK_CMCLIST_UNSET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) &= ~(GTK_ ## flag))
91 #define GTK_CMCLIST_IN_DRAG(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_IN_DRAG)
92 #define GTK_CMCLIST_ROW_HEIGHT_SET(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ROW_HEIGHT_SET)
93 #define GTK_CMCLIST_SHOW_TITLES(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_SHOW_TITLES)
94 #define GTK_CMCLIST_ADD_MODE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ADD_MODE)
95 #define GTK_CMCLIST_AUTO_SORT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_SORT)
96 #define GTK_CMCLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_RESIZE_BLOCKED)
97 #define GTK_CMCLIST_REORDERABLE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_REORDERABLE)
98 #define GTK_CMCLIST_USE_DRAG_ICONS(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_USE_DRAG_ICONS)
99 #define GTK_CMCLIST_DRAW_DRAG_LINE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_LINE)
100 #define GTK_CMCLIST_DRAW_DRAG_RECT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_RECT)
102 #define GTK_CMCLIST_ROW(_glist_) ((GtkCMCListRow *)((_glist_)->data))
104 /* pointer casting for cells */
105 #define GTK_CMCELL_TEXT(cell) (((GtkCMCellText *) &(cell)))
106 #define GTK_CMCELL_PIXBUF(cell) (((GtkCMCellPixbuf *) &(cell)))
107 #define GTK_CMCELL_PIXTEXT(cell) (((GtkCMCellPixText *) &(cell)))
108 #define GTK_CMCELL_WIDGET(cell) (((GtkCMCellWidget *) &(cell)))
110 typedef struct _GtkCMCList GtkCMCList;
111 typedef struct _GtkCMCListClass GtkCMCListClass;
112 typedef struct _GtkCMCListColumn GtkCMCListColumn;
113 typedef struct _GtkCMCListRow GtkCMCListRow;
115 typedef struct _GtkCMCell GtkCMCell;
116 typedef struct _GtkCMCellText GtkCMCellText;
117 typedef struct _GtkCMCellPixbuf GtkCMCellPixbuf;
118 typedef struct _GtkCMCellPixText GtkCMCellPixText;
119 typedef struct _GtkCMCellWidget GtkCMCellWidget;
121 typedef gint (*GtkCMCListCompareFunc) (GtkCMCList *clist,
125 typedef struct _GtkCMCListCellInfo GtkCMCListCellInfo;
126 typedef struct _GtkCMCListDestInfo GtkCMCListDestInfo;
128 struct _GtkCMCListCellInfo
134 struct _GtkCMCListDestInfo
136 GtkCMCListCellInfo cell;
137 GtkCMCListDragPos insert_pos;
142 GtkContainer container;
146 #if !GLIB_CHECK_VERSION(2,10,0)
147 GMemChunk *row_mem_chunk;
148 GMemChunk *cell_mem_chunk;
155 /* allocation rectangle after the conatiner_border_width
156 * and the width of the shadow border */
157 GdkRectangle internal_allocation;
167 GdkRectangle column_title_area;
168 GdkWindow *title_window;
170 /* dynamicly allocated array of column structures */
171 GtkCMCListColumn *column;
173 /* the scrolling window and its height and width to
174 * make things a little speedier */
175 GdkWindow *clist_window;
176 gint clist_window_width;
177 gint clist_window_height;
179 /* offsets for scrolling */
183 /* border shadow style */
184 GtkShadowType shadow_type;
186 /* the list's selection mode (gtkenums.h) */
187 GtkSelectionMode selection_mode;
189 /* list of selected rows */
191 GList *selection_end;
193 GList *undo_selection;
194 GList *undo_unselection;
198 guint8 button_actions[5];
203 GtkCMCListCellInfo click_cell;
205 /* scroll adjustments */
206 GtkAdjustment *hadjustment;
207 GtkAdjustment *vadjustment;
211 /* cursor used to indicate dragging */
212 GdkCursor *cursor_drag;
214 /* the current x-pixel location of the xor-drag line */
220 gint focus_header_column;
222 /* dragging the selection */
224 GtkStateType anchor_state;
229 GtkSortType sort_type;
230 GtkCMCListCompareFunc compare;
233 gint drag_highlight_row;
234 GtkCMCListDragPos drag_highlight_pos;
237 struct _GtkCMCListClass
239 GtkContainerClass parent_class;
241 void (*set_scroll_adjustments) (GtkCMCList *clist,
242 GtkAdjustment *hadjustment,
243 GtkAdjustment *vadjustment);
244 void (*refresh) (GtkCMCList *clist);
245 void (*select_row) (GtkCMCList *clist,
249 void (*unselect_row) (GtkCMCList *clist,
253 void (*row_move) (GtkCMCList *clist,
256 void (*click_column) (GtkCMCList *clist,
258 void (*resize_column) (GtkCMCList *clist,
261 void (*toggle_focus_row) (GtkCMCList *clist);
262 void (*select_all) (GtkCMCList *clist);
263 void (*unselect_all) (GtkCMCList *clist);
264 void (*undo_selection) (GtkCMCList *clist);
265 void (*start_selection) (GtkCMCList *clist);
266 void (*end_selection) (GtkCMCList *clist);
267 void (*extend_selection) (GtkCMCList *clist,
268 GtkScrollType scroll_type,
270 gboolean auto_start_selection);
271 void (*scroll_horizontal) (GtkCMCList *clist,
272 GtkScrollType scroll_type,
274 void (*scroll_vertical) (GtkCMCList *clist,
275 GtkScrollType scroll_type,
277 void (*toggle_add_mode) (GtkCMCList *clist);
278 void (*abort_column_resize) (GtkCMCList *clist);
279 void (*resync_selection) (GtkCMCList *clist,
281 GList* (*selection_find) (GtkCMCList *clist,
283 GList *row_list_element);
284 void (*draw_row) (GtkCMCList *clist,
287 GtkCMCListRow *clist_row);
288 void (*clear) (GtkCMCList *clist);
289 void (*fake_unselect_all) (GtkCMCList *clist,
291 void (*sort_list) (GtkCMCList *clist);
292 gint (*insert_row) (GtkCMCList *clist,
295 void (*remove_row) (GtkCMCList *clist,
297 void (*set_cell_contents) (GtkCMCList *clist,
298 GtkCMCListRow *clist_row,
304 void (*cell_size_request) (GtkCMCList *clist,
305 GtkCMCListRow *clist_row,
307 GtkRequisition *requisition);
311 struct _GtkCMCListColumn
322 GtkJustification justification;
326 guint resizeable : 1;
327 guint auto_resize : 1;
328 guint button_passive : 1;
331 struct _GtkCMCListRow
342 GDestroyNotify destroy;
346 guint selectable : 1;
349 /* Cell Structures */
350 struct _GtkCMCellText
362 struct _GtkCMCellPixbuf
374 struct _GtkCMCellPixText
388 struct _GtkCMCellWidget
426 GType gtk_cmclist_get_type (void);
428 /* create a new GtkCMCList */
429 GtkWidget* gtk_cmclist_new (gint columns);
430 GtkWidget* gtk_cmclist_new_with_titles (gint columns,
433 /* set adjustments of clist */
434 void gtk_cmclist_set_hadjustment (GtkCMCList *clist,
435 GtkAdjustment *adjustment);
436 void gtk_cmclist_set_vadjustment (GtkCMCList *clist,
437 GtkAdjustment *adjustment);
439 /* get adjustments of clist */
440 GtkAdjustment* gtk_cmclist_get_hadjustment (GtkCMCList *clist);
441 GtkAdjustment* gtk_cmclist_get_vadjustment (GtkCMCList *clist);
443 /* set the border style of the clist */
444 void gtk_cmclist_set_shadow_type (GtkCMCList *clist,
447 /* set the clist's selection mode */
448 void gtk_cmclist_set_selection_mode (GtkCMCList *clist,
449 GtkSelectionMode mode);
451 /* enable clists reorder ability */
452 void gtk_cmclist_set_reorderable (GtkCMCList *clist,
453 gboolean reorderable);
454 void gtk_cmclist_set_use_drag_icons (GtkCMCList *clist,
456 void gtk_cmclist_set_button_actions (GtkCMCList *clist,
458 guint8 button_actions);
460 /* freeze all visual updates of the list, and then thaw the list after
461 * you have made a number of changes and the updates wil occure in a
462 * more efficent mannor than if you made them on a unfrozen list
464 void gtk_cmclist_freeze (GtkCMCList *clist);
465 void gtk_cmclist_thaw (GtkCMCList *clist);
467 /* show and hide the column title buttons */
468 void gtk_cmclist_column_titles_show (GtkCMCList *clist);
469 void gtk_cmclist_column_titles_hide (GtkCMCList *clist);
471 /* set the column title to be a active title (responds to button presses,
472 * prelights, and grabs keyboard focus), or passive where it acts as just
475 void gtk_cmclist_column_title_active (GtkCMCList *clist,
477 void gtk_cmclist_column_title_passive (GtkCMCList *clist,
479 void gtk_cmclist_column_titles_active (GtkCMCList *clist);
480 void gtk_cmclist_column_titles_passive (GtkCMCList *clist);
482 /* set the title in the column title button */
483 void gtk_cmclist_set_column_title (GtkCMCList *clist,
487 /* returns the title of column. Returns NULL if title is not set */
488 gchar * gtk_cmclist_get_column_title (GtkCMCList *clist,
491 /* set a widget instead of a title for the column title button */
492 void gtk_cmclist_set_column_widget (GtkCMCList *clist,
496 /* returns the column widget */
497 GtkWidget * gtk_cmclist_get_column_widget (GtkCMCList *clist,
500 /* set the justification on a column */
501 void gtk_cmclist_set_column_justification (GtkCMCList *clist,
503 GtkJustification justification);
505 /* set visibility of a column */
506 void gtk_cmclist_set_column_visibility (GtkCMCList *clist,
510 /* enable/disable column resize operations by mouse */
511 void gtk_cmclist_set_column_resizeable (GtkCMCList *clist,
513 gboolean resizeable);
515 /* resize column automatically to its optimal width */
516 void gtk_cmclist_set_column_auto_resize (GtkCMCList *clist,
518 gboolean auto_resize);
520 gint gtk_cmclist_columns_autosize (GtkCMCList *clist);
522 /* return the optimal column width, i.e. maximum of all cell widths */
523 gint gtk_cmclist_optimal_column_width (GtkCMCList *clist,
526 /* set the pixel width of a column; this is a necessary step in
527 * creating a CList because otherwise the column width is chozen from
528 * the width of the column title, which will never be right
530 void gtk_cmclist_set_column_width (GtkCMCList *clist,
534 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
535 void gtk_cmclist_set_column_min_width (GtkCMCList *clist,
538 void gtk_cmclist_set_column_max_width (GtkCMCList *clist,
542 /* change the height of the rows, the default (height=0) is
543 * the hight of the current font.
545 void gtk_cmclist_set_row_height (GtkCMCList *clist,
548 /* scroll the viewing area of the list to the given column and row;
549 * row_align and col_align are between 0-1 representing the location the
550 * row should appear on the screnn, 0.0 being top or left, 1.0 being
551 * bottom or right; if row or column is -1 then then there is no change
553 void gtk_cmclist_moveto (GtkCMCList *clist,
559 /* returns whether the row is visible */
560 GtkVisibility gtk_cmclist_row_is_visible (GtkCMCList *clist,
563 /* returns the cell type */
564 GtkCMCellType gtk_cmclist_get_cell_type (GtkCMCList *clist,
568 /* sets a given cell's text, replacing its current contents */
569 void gtk_cmclist_set_text (GtkCMCList *clist,
574 /* for the "get" functions, any of the return pointer can be
575 * NULL if you are not interested
577 gint gtk_cmclist_get_text (GtkCMCList *clist,
582 /* sets a given cell's pixbuf, replacing its current contents */
583 void gtk_cmclist_set_pixbuf (GtkCMCList *clist,
588 gint gtk_cmclist_get_pixbuf (GtkCMCList *clist,
593 /* sets a given cell's pixbuf and text, replacing its current contents */
594 void gtk_cmclist_set_pixtext (GtkCMCList *clist,
601 gint gtk_cmclist_get_pixtext (GtkCMCList *clist,
608 /* sets the foreground color of a row, the color must already
611 void gtk_cmclist_set_foreground (GtkCMCList *clist,
613 const GdkColor *color);
615 /* sets the background color of a row, the color must already
618 void gtk_cmclist_set_background (GtkCMCList *clist,
620 const GdkColor *color);
622 /* set / get cell styles */
623 void gtk_cmclist_set_cell_style (GtkCMCList *clist,
628 GtkStyle *gtk_cmclist_get_cell_style (GtkCMCList *clist,
632 void gtk_cmclist_set_row_style (GtkCMCList *clist,
636 GtkStyle *gtk_cmclist_get_row_style (GtkCMCList *clist,
639 /* this sets a horizontal and vertical shift for drawing
640 * the contents of a cell; it can be positive or negitive;
641 * this is particulary useful for indenting items in a column
643 void gtk_cmclist_set_shift (GtkCMCList *clist,
649 /* set/get selectable flag of a single row */
650 void gtk_cmclist_set_selectable (GtkCMCList *clist,
652 gboolean selectable);
653 gboolean gtk_cmclist_get_selectable (GtkCMCList *clist,
656 /* prepend/append returns the index of the row you just added,
657 * making it easier to append and modify a row
659 gint gtk_cmclist_prepend (GtkCMCList *clist,
661 gint gtk_cmclist_append (GtkCMCList *clist,
664 /* inserts a row at index row and returns the row where it was
665 * actually inserted (may be different from "row" in auto_sort mode)
667 gint gtk_cmclist_insert (GtkCMCList *clist,
671 /* removes row at index row */
672 void gtk_cmclist_remove (GtkCMCList *clist,
675 /* sets a arbitrary data pointer for a given row */
676 void gtk_cmclist_set_row_data (GtkCMCList *clist,
680 /* sets a data pointer for a given row with destroy notification */
681 void gtk_cmclist_set_row_data_full (GtkCMCList *clist,
684 GDestroyNotify destroy);
686 /* returns the data set for a row */
687 gpointer gtk_cmclist_get_row_data (GtkCMCList *clist,
690 /* givin a data pointer, find the first (and hopefully only!)
691 * row that points to that data, or -1 if none do
693 gint gtk_cmclist_find_row_from_data (GtkCMCList *clist,
696 /* force selection of a row */
697 void gtk_cmclist_select_row (GtkCMCList *clist,
701 /* force unselection of a row */
702 void gtk_cmclist_unselect_row (GtkCMCList *clist,
706 /* undo the last select/unselect operation */
707 void gtk_cmclist_undo_selection (GtkCMCList *clist);
709 /* clear the entire list -- this is much faster than removing
710 * each item with gtk_cmclist_remove
712 void gtk_cmclist_clear (GtkCMCList *clist);
714 /* return the row column corresponding to the x and y coordinates,
715 * the returned values are only valid if the x and y coordinates
716 * are respectively to a window == clist->clist_window
718 gint gtk_cmclist_get_selection_info (GtkCMCList *clist,
724 /* in multiple or extended mode, select all rows */
725 void gtk_cmclist_select_all (GtkCMCList *clist);
727 /* in all modes except browse mode, deselect all rows */
728 void gtk_cmclist_unselect_all (GtkCMCList *clist);
730 /* swap the position of two rows */
731 void gtk_cmclist_swap_rows (GtkCMCList *clist,
735 /* move row from source_row position to dest_row position */
736 void gtk_cmclist_row_move (GtkCMCList *clist,
740 /* sets a compare function different to the default */
741 void gtk_cmclist_set_compare_func (GtkCMCList *clist,
742 GtkCMCListCompareFunc cmp_func);
744 /* the column to sort by */
745 void gtk_cmclist_set_sort_column (GtkCMCList *clist,
748 /* how to sort : ascending or descending */
749 void gtk_cmclist_set_sort_type (GtkCMCList *clist,
750 GtkSortType sort_type);
752 /* sort the list with the current compare function */
753 void gtk_cmclist_sort (GtkCMCList *clist);
755 /* Automatically sort upon insertion */
756 void gtk_cmclist_set_auto_sort (GtkCMCList *clist,
759 /* Private function for clist, ctree */
761 PangoLayout *_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
762 GtkCMCListRow *clist_row,
769 #endif /* __GTK_CMCLIST_H__ */