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__
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>
46 GTK_CMCLIST_IN_DRAG = 1 << 0,
47 GTK_CMCLIST_ROW_HEIGHT_SET = 1 << 1,
48 GTK_CMCLIST_SHOW_TITLES = 1 << 2,
50 GTK_CMCLIST_ADD_MODE = 1 << 4,
51 GTK_CMCLIST_AUTO_SORT = 1 << 5,
52 GTK_CMCLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
53 GTK_CMCLIST_REORDERABLE = 1 << 7,
54 GTK_CMCLIST_USE_DRAG_ICONS = 1 << 8,
55 GTK_CMCLIST_DRAW_DRAG_LINE = 1 << 9,
56 GTK_CMCLIST_DRAW_DRAG_RECT = 1 << 10
71 GTK_CMCLIST_DRAG_NONE,
72 GTK_CMCLIST_DRAG_BEFORE,
73 GTK_CMCLIST_DRAG_INTO,
74 GTK_CMCLIST_DRAG_AFTER
79 GTK_CMBUTTON_IGNORED = 0,
80 GTK_CMBUTTON_SELECTS = 1 << 0,
81 GTK_CMBUTTON_DRAGS = 1 << 1,
82 GTK_CMBUTTON_EXPANDS = 1 << 2
85 #define GTK_TYPE_CMCLIST (gtk_cmclist_get_type ())
86 #define GTK_CMCLIST(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CMCLIST, GtkCMCList))
87 #define GTK_CMCLIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CMCLIST, GtkCMCListClass))
88 #define GTK_IS_CMCLIST(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_CMCLIST))
89 #define GTK_IS_CMCLIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CMCLIST))
90 #define GTK_CMCLIST_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_CMCLIST, GtkCMCListClass))
93 #define GTK_CMCLIST_FLAGS(clist) (GTK_CMCLIST (clist)->flags)
94 #define GTK_CMCLIST_SET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) |= (GTK_ ## flag))
95 #define GTK_CMCLIST_UNSET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) &= ~(GTK_ ## flag))
97 #define GTK_CMCLIST_IN_DRAG(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_IN_DRAG)
98 #define GTK_CMCLIST_ROW_HEIGHT_SET(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ROW_HEIGHT_SET)
99 #define GTK_CMCLIST_SHOW_TITLES(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_SHOW_TITLES)
100 #define GTK_CMCLIST_ADD_MODE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ADD_MODE)
101 #define GTK_CMCLIST_AUTO_SORT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_SORT)
102 #define GTK_CMCLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_RESIZE_BLOCKED)
103 #define GTK_CMCLIST_REORDERABLE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_REORDERABLE)
104 #define GTK_CMCLIST_USE_DRAG_ICONS(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_USE_DRAG_ICONS)
105 #define GTK_CMCLIST_DRAW_DRAG_LINE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_LINE)
106 #define GTK_CMCLIST_DRAW_DRAG_RECT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_RECT)
108 #define GTK_CMCLIST_ROW(_glist_) ((GtkCMCListRow *)((_glist_)->data))
110 /* pointer casting for cells */
111 #define GTK_CMCELL_TEXT(cell) (((GtkCMCellText *) &(cell)))
112 #define GTK_CMCELL_PIXMAP(cell) (((GtkCMCellPixmap *) &(cell)))
113 #define GTK_CMCELL_PIXTEXT(cell) (((GtkCMCellPixText *) &(cell)))
114 #define GTK_CMCELL_WIDGET(cell) (((GtkCMCellWidget *) &(cell)))
116 typedef struct _GtkCMCList GtkCMCList;
117 typedef struct _GtkCMCListClass GtkCMCListClass;
118 typedef struct _GtkCMCListColumn GtkCMCListColumn;
119 typedef struct _GtkCMCListRow GtkCMCListRow;
121 typedef struct _GtkCMCell GtkCMCell;
122 typedef struct _GtkCMCellText GtkCMCellText;
123 typedef struct _GtkCMCellPixmap GtkCMCellPixmap;
124 typedef struct _GtkCMCellPixText GtkCMCellPixText;
125 typedef struct _GtkCMCellWidget GtkCMCellWidget;
127 typedef gint (*GtkCMCListCompareFunc) (GtkCMCList *clist,
131 typedef struct _GtkCMCListCellInfo GtkCMCListCellInfo;
132 typedef struct _GtkCMCListDestInfo GtkCMCListDestInfo;
134 struct _GtkCMCListCellInfo
140 struct _GtkCMCListDestInfo
142 GtkCMCListCellInfo cell;
143 GtkCMCListDragPos insert_pos;
148 GtkContainer container;
152 #if !GLIB_CHECK_VERSION(2,10,0)
153 GMemChunk *row_mem_chunk;
154 GMemChunk *cell_mem_chunk;
161 /* allocation rectangle after the conatiner_border_width
162 * and the width of the shadow border */
163 GdkRectangle internal_allocation;
173 GdkRectangle column_title_area;
174 GdkWindow *title_window;
176 /* dynamicly allocated array of column structures */
177 GtkCMCListColumn *column;
179 /* the scrolling window and its height and width to
180 * make things a little speedier */
181 GdkWindow *clist_window;
182 gint clist_window_width;
183 gint clist_window_height;
185 /* offsets for scrolling */
189 /* border shadow style */
190 GtkShadowType shadow_type;
192 /* the list's selection mode (gtkenums.h) */
193 GtkSelectionMode selection_mode;
195 /* list of selected rows */
197 GList *selection_end;
199 GList *undo_selection;
200 GList *undo_unselection;
204 guint8 button_actions[5];
209 GtkCMCListCellInfo click_cell;
211 /* scroll adjustments */
212 GtkAdjustment *hadjustment;
213 GtkAdjustment *vadjustment;
215 /* xor GC for the vertical drag line */
218 /* gc for drawing unselected cells */
222 /* cursor used to indicate dragging */
223 GdkCursor *cursor_drag;
225 /* the current x-pixel location of the xor-drag line */
231 gint focus_header_column;
233 /* dragging the selection */
235 GtkStateType anchor_state;
240 GtkSortType sort_type;
241 GtkCMCListCompareFunc compare;
244 gint drag_highlight_row;
245 GtkCMCListDragPos drag_highlight_pos;
248 struct _GtkCMCListClass
250 GtkContainerClass parent_class;
252 void (*set_scroll_adjustments) (GtkCMCList *clist,
253 GtkAdjustment *hadjustment,
254 GtkAdjustment *vadjustment);
255 void (*refresh) (GtkCMCList *clist);
256 void (*select_row) (GtkCMCList *clist,
260 void (*unselect_row) (GtkCMCList *clist,
264 void (*row_move) (GtkCMCList *clist,
267 void (*click_column) (GtkCMCList *clist,
269 void (*resize_column) (GtkCMCList *clist,
272 void (*toggle_focus_row) (GtkCMCList *clist);
273 void (*select_all) (GtkCMCList *clist);
274 void (*unselect_all) (GtkCMCList *clist);
275 void (*undo_selection) (GtkCMCList *clist);
276 void (*start_selection) (GtkCMCList *clist);
277 void (*end_selection) (GtkCMCList *clist);
278 void (*extend_selection) (GtkCMCList *clist,
279 GtkScrollType scroll_type,
281 gboolean auto_start_selection);
282 void (*scroll_horizontal) (GtkCMCList *clist,
283 GtkScrollType scroll_type,
285 void (*scroll_vertical) (GtkCMCList *clist,
286 GtkScrollType scroll_type,
288 void (*toggle_add_mode) (GtkCMCList *clist);
289 void (*abort_column_resize) (GtkCMCList *clist);
290 void (*resync_selection) (GtkCMCList *clist,
292 GList* (*selection_find) (GtkCMCList *clist,
294 GList *row_list_element);
295 void (*draw_row) (GtkCMCList *clist,
298 GtkCMCListRow *clist_row);
299 void (*draw_drag_highlight) (GtkCMCList *clist,
300 GtkCMCListRow *target_row,
301 gint target_row_number,
302 GtkCMCListDragPos drag_pos);
303 void (*clear) (GtkCMCList *clist);
304 void (*fake_unselect_all) (GtkCMCList *clist,
306 void (*sort_list) (GtkCMCList *clist);
307 gint (*insert_row) (GtkCMCList *clist,
310 void (*remove_row) (GtkCMCList *clist,
312 void (*set_cell_contents) (GtkCMCList *clist,
313 GtkCMCListRow *clist_row,
320 void (*cell_size_request) (GtkCMCList *clist,
321 GtkCMCListRow *clist_row,
323 GtkRequisition *requisition);
327 struct _GtkCMCListColumn
338 GtkJustification justification;
342 guint resizeable : 1;
343 guint auto_resize : 1;
344 guint button_passive : 1;
347 struct _GtkCMCListRow
358 GDestroyNotify destroy;
362 guint selectable : 1;
365 /* Cell Structures */
366 struct _GtkCMCellText
378 struct _GtkCMCellPixmap
391 struct _GtkCMCellPixText
406 struct _GtkCMCellWidget
446 GType gtk_cmclist_get_type (void);
448 /* create a new GtkCMCList */
449 GtkWidget* gtk_cmclist_new (gint columns);
450 GtkWidget* gtk_cmclist_new_with_titles (gint columns,
453 /* set adjustments of clist */
454 void gtk_cmclist_set_hadjustment (GtkCMCList *clist,
455 GtkAdjustment *adjustment);
456 void gtk_cmclist_set_vadjustment (GtkCMCList *clist,
457 GtkAdjustment *adjustment);
459 /* get adjustments of clist */
460 GtkAdjustment* gtk_cmclist_get_hadjustment (GtkCMCList *clist);
461 GtkAdjustment* gtk_cmclist_get_vadjustment (GtkCMCList *clist);
463 /* set the border style of the clist */
464 void gtk_cmclist_set_shadow_type (GtkCMCList *clist,
467 /* set the clist's selection mode */
468 void gtk_cmclist_set_selection_mode (GtkCMCList *clist,
469 GtkSelectionMode mode);
471 /* enable clists reorder ability */
472 void gtk_cmclist_set_reorderable (GtkCMCList *clist,
473 gboolean reorderable);
474 void gtk_cmclist_set_use_drag_icons (GtkCMCList *clist,
476 void gtk_cmclist_set_button_actions (GtkCMCList *clist,
478 guint8 button_actions);
480 /* freeze all visual updates of the list, and then thaw the list after
481 * you have made a number of changes and the updates wil occure in a
482 * more efficent mannor than if you made them on a unfrozen list
484 void gtk_cmclist_freeze (GtkCMCList *clist);
485 void gtk_cmclist_thaw (GtkCMCList *clist);
487 /* show and hide the column title buttons */
488 void gtk_cmclist_column_titles_show (GtkCMCList *clist);
489 void gtk_cmclist_column_titles_hide (GtkCMCList *clist);
491 /* set the column title to be a active title (responds to button presses,
492 * prelights, and grabs keyboard focus), or passive where it acts as just
495 void gtk_cmclist_column_title_active (GtkCMCList *clist,
497 void gtk_cmclist_column_title_passive (GtkCMCList *clist,
499 void gtk_cmclist_column_titles_active (GtkCMCList *clist);
500 void gtk_cmclist_column_titles_passive (GtkCMCList *clist);
502 /* set the title in the column title button */
503 void gtk_cmclist_set_column_title (GtkCMCList *clist,
507 /* returns the title of column. Returns NULL if title is not set */
508 gchar * gtk_cmclist_get_column_title (GtkCMCList *clist,
511 /* set a widget instead of a title for the column title button */
512 void gtk_cmclist_set_column_widget (GtkCMCList *clist,
516 /* returns the column widget */
517 GtkWidget * gtk_cmclist_get_column_widget (GtkCMCList *clist,
520 /* set the justification on a column */
521 void gtk_cmclist_set_column_justification (GtkCMCList *clist,
523 GtkJustification justification);
525 /* set visibility of a column */
526 void gtk_cmclist_set_column_visibility (GtkCMCList *clist,
530 /* enable/disable column resize operations by mouse */
531 void gtk_cmclist_set_column_resizeable (GtkCMCList *clist,
533 gboolean resizeable);
535 /* resize column automatically to its optimal width */
536 void gtk_cmclist_set_column_auto_resize (GtkCMCList *clist,
538 gboolean auto_resize);
540 gint gtk_cmclist_columns_autosize (GtkCMCList *clist);
542 /* return the optimal column width, i.e. maximum of all cell widths */
543 gint gtk_cmclist_optimal_column_width (GtkCMCList *clist,
546 /* set the pixel width of a column; this is a necessary step in
547 * creating a CList because otherwise the column width is chozen from
548 * the width of the column title, which will never be right
550 void gtk_cmclist_set_column_width (GtkCMCList *clist,
554 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
555 void gtk_cmclist_set_column_min_width (GtkCMCList *clist,
558 void gtk_cmclist_set_column_max_width (GtkCMCList *clist,
562 /* change the height of the rows, the default (height=0) is
563 * the hight of the current font.
565 void gtk_cmclist_set_row_height (GtkCMCList *clist,
568 /* scroll the viewing area of the list to the given column and row;
569 * row_align and col_align are between 0-1 representing the location the
570 * row should appear on the screnn, 0.0 being top or left, 1.0 being
571 * bottom or right; if row or column is -1 then then there is no change
573 void gtk_cmclist_moveto (GtkCMCList *clist,
579 /* returns whether the row is visible */
580 GtkVisibility gtk_cmclist_row_is_visible (GtkCMCList *clist,
583 /* returns the cell type */
584 GtkCMCellType gtk_cmclist_get_cell_type (GtkCMCList *clist,
588 /* sets a given cell's text, replacing its current contents */
589 void gtk_cmclist_set_text (GtkCMCList *clist,
594 /* for the "get" functions, any of the return pointer can be
595 * NULL if you are not interested
597 gint gtk_cmclist_get_text (GtkCMCList *clist,
602 /* sets a given cell's pixmap, replacing its current contents */
603 void gtk_cmclist_set_pixmap (GtkCMCList *clist,
609 gint gtk_cmclist_get_pixmap (GtkCMCList *clist,
615 /* sets a given cell's pixmap and text, replacing its current contents */
616 void gtk_cmclist_set_pixtext (GtkCMCList *clist,
624 gint gtk_cmclist_get_pixtext (GtkCMCList *clist,
632 /* sets the foreground color of a row, the color must already
635 void gtk_cmclist_set_foreground (GtkCMCList *clist,
637 const GdkColor *color);
639 /* sets the background color of a row, the color must already
642 void gtk_cmclist_set_background (GtkCMCList *clist,
644 const GdkColor *color);
646 /* set / get cell styles */
647 void gtk_cmclist_set_cell_style (GtkCMCList *clist,
652 GtkStyle *gtk_cmclist_get_cell_style (GtkCMCList *clist,
656 void gtk_cmclist_set_row_style (GtkCMCList *clist,
660 GtkStyle *gtk_cmclist_get_row_style (GtkCMCList *clist,
663 /* this sets a horizontal and vertical shift for drawing
664 * the contents of a cell; it can be positive or negitive;
665 * this is particulary useful for indenting items in a column
667 void gtk_cmclist_set_shift (GtkCMCList *clist,
673 /* set/get selectable flag of a single row */
674 void gtk_cmclist_set_selectable (GtkCMCList *clist,
676 gboolean selectable);
677 gboolean gtk_cmclist_get_selectable (GtkCMCList *clist,
680 /* prepend/append returns the index of the row you just added,
681 * making it easier to append and modify a row
683 gint gtk_cmclist_prepend (GtkCMCList *clist,
685 gint gtk_cmclist_append (GtkCMCList *clist,
688 /* inserts a row at index row and returns the row where it was
689 * actually inserted (may be different from "row" in auto_sort mode)
691 gint gtk_cmclist_insert (GtkCMCList *clist,
695 /* removes row at index row */
696 void gtk_cmclist_remove (GtkCMCList *clist,
699 /* sets a arbitrary data pointer for a given row */
700 void gtk_cmclist_set_row_data (GtkCMCList *clist,
704 /* sets a data pointer for a given row with destroy notification */
705 void gtk_cmclist_set_row_data_full (GtkCMCList *clist,
708 GDestroyNotify destroy);
710 /* returns the data set for a row */
711 gpointer gtk_cmclist_get_row_data (GtkCMCList *clist,
714 /* givin a data pointer, find the first (and hopefully only!)
715 * row that points to that data, or -1 if none do
717 gint gtk_cmclist_find_row_from_data (GtkCMCList *clist,
720 /* force selection of a row */
721 void gtk_cmclist_select_row (GtkCMCList *clist,
725 /* force unselection of a row */
726 void gtk_cmclist_unselect_row (GtkCMCList *clist,
730 /* undo the last select/unselect operation */
731 void gtk_cmclist_undo_selection (GtkCMCList *clist);
733 /* clear the entire list -- this is much faster than removing
734 * each item with gtk_cmclist_remove
736 void gtk_cmclist_clear (GtkCMCList *clist);
738 /* return the row column corresponding to the x and y coordinates,
739 * the returned values are only valid if the x and y coordinates
740 * are respectively to a window == clist->clist_window
742 gint gtk_cmclist_get_selection_info (GtkCMCList *clist,
748 /* in multiple or extended mode, select all rows */
749 void gtk_cmclist_select_all (GtkCMCList *clist);
751 /* in all modes except browse mode, deselect all rows */
752 void gtk_cmclist_unselect_all (GtkCMCList *clist);
754 /* swap the position of two rows */
755 void gtk_cmclist_swap_rows (GtkCMCList *clist,
759 /* move row from source_row position to dest_row position */
760 void gtk_cmclist_row_move (GtkCMCList *clist,
764 /* sets a compare function different to the default */
765 void gtk_cmclist_set_compare_func (GtkCMCList *clist,
766 GtkCMCListCompareFunc cmp_func);
768 /* the column to sort by */
769 void gtk_cmclist_set_sort_column (GtkCMCList *clist,
772 /* how to sort : ascending or descending */
773 void gtk_cmclist_set_sort_type (GtkCMCList *clist,
774 GtkSortType sort_type);
776 /* sort the list with the current compare function */
777 void gtk_cmclist_sort (GtkCMCList *clist);
779 /* Automatically sort upon insertion */
780 void gtk_cmclist_set_auto_sort (GtkCMCList *clist,
783 /* Private function for clist, ctree */
785 PangoLayout *_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
786 GtkCMCListRow *clist_row,
793 #endif /* __GTK_CMCLIST_H__ */