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_DISABLE_DEPRECATED
30 #ifndef __GTK_CLIST_H__
31 #define __GTK_CLIST_H__
34 #include <gtk/gtksignal.h>
35 #include <gtk/gtkalignment.h>
36 #include <gtk/gtklabel.h>
37 #include <gtk/gtkbutton.h>
38 #include <gtk/gtkhscrollbar.h>
39 #include <gtk/gtkvscrollbar.h>
40 #include <gtk/gtkenums.h>
44 #endif /* __cplusplus */
48 GTK_CLIST_IN_DRAG = 1 << 0,
49 GTK_CLIST_ROW_HEIGHT_SET = 1 << 1,
50 GTK_CLIST_SHOW_TITLES = 1 << 2,
52 GTK_CLIST_ADD_MODE = 1 << 4,
53 GTK_CLIST_AUTO_SORT = 1 << 5,
54 GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
55 GTK_CLIST_REORDERABLE = 1 << 7,
56 GTK_CLIST_USE_DRAG_ICONS = 1 << 8,
57 GTK_CLIST_DRAW_DRAG_LINE = 1 << 9,
58 GTK_CLIST_DRAW_DRAG_RECT = 1 << 10
74 GTK_CLIST_DRAG_BEFORE,
81 GTK_BUTTON_IGNORED = 0,
82 GTK_BUTTON_SELECTS = 1 << 0,
83 GTK_BUTTON_DRAGS = 1 << 1,
84 GTK_BUTTON_EXPANDS = 1 << 2
87 #define GTK_TYPE_CLIST (gtk_clist_get_type ())
88 #define GTK_CLIST(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CLIST, GtkCList))
89 #define GTK_CLIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLIST, GtkCListClass))
90 #define GTK_IS_CLIST(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_CLIST))
91 #define GTK_IS_CLIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CLIST))
92 #define GTK_CLIST_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_CLIST, GtkCListClass))
95 #define GTK_CLIST_FLAGS(clist) (GTK_CLIST (clist)->flags)
96 #define GTK_CLIST_SET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) |= (GTK_ ## flag))
97 #define GTK_CLIST_UNSET_FLAG(clist,flag) (GTK_CLIST_FLAGS (clist) &= ~(GTK_ ## flag))
99 #define GTK_CLIST_IN_DRAG(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_IN_DRAG)
100 #define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET)
101 #define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES)
102 #define GTK_CLIST_ADD_MODE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ADD_MODE)
103 #define GTK_CLIST_AUTO_SORT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_SORT)
104 #define GTK_CLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_RESIZE_BLOCKED)
105 #define GTK_CLIST_REORDERABLE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_REORDERABLE)
106 #define GTK_CLIST_USE_DRAG_ICONS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_USE_DRAG_ICONS)
107 #define GTK_CLIST_DRAW_DRAG_LINE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_LINE)
108 #define GTK_CLIST_DRAW_DRAG_RECT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_RECT)
110 #define GTK_CLIST_ROW(_glist_) ((GtkCListRow *)((_glist_)->data))
112 /* pointer casting for cells */
113 #define GTK_CELL_TEXT(cell) (((GtkCellText *) &(cell)))
114 #define GTK_CELL_PIXMAP(cell) (((GtkCellPixmap *) &(cell)))
115 #define GTK_CELL_PIXTEXT(cell) (((GtkCellPixText *) &(cell)))
116 #define GTK_CELL_WIDGET(cell) (((GtkCellWidget *) &(cell)))
118 typedef struct _GtkCList GtkCList;
119 typedef struct _GtkCListClass GtkCListClass;
120 typedef struct _GtkCListColumn GtkCListColumn;
121 typedef struct _GtkCListRow GtkCListRow;
123 typedef struct _GtkCell GtkCell;
124 typedef struct _GtkCellText GtkCellText;
125 typedef struct _GtkCellPixmap GtkCellPixmap;
126 typedef struct _GtkCellPixText GtkCellPixText;
127 typedef struct _GtkCellWidget GtkCellWidget;
129 typedef gint (*GtkCListCompareFunc) (GtkCList *clist,
133 typedef struct _GtkCListCellInfo GtkCListCellInfo;
134 typedef struct _GtkCListDestInfo GtkCListDestInfo;
136 struct _GtkCListCellInfo
142 struct _GtkCListDestInfo
144 GtkCListCellInfo cell;
145 GtkCListDragPos insert_pos;
150 GtkContainer container;
155 GMemChunk *row_mem_chunk;
156 GMemChunk *cell_mem_chunk;
160 /* allocation rectangle after the conatiner_border_width
161 * and the width of the shadow border */
162 GdkRectangle internal_allocation;
172 GdkRectangle column_title_area;
173 GdkWindow *title_window;
175 /* dynamicly allocated array of column structures */
176 GtkCListColumn *column;
178 /* the scrolling window and its height and width to
179 * make things a little speedier */
180 GdkWindow *clist_window;
181 gint clist_window_width;
182 gint clist_window_height;
184 /* offsets for scrolling */
188 /* border shadow style */
189 GtkShadowType shadow_type;
191 /* the list's selection mode (gtkenums.h) */
192 GtkSelectionMode selection_mode;
194 /* list of selected rows */
196 GList *selection_end;
198 GList *undo_selection;
199 GList *undo_unselection;
203 guint8 button_actions[5];
208 GtkCListCellInfo click_cell;
210 /* scroll adjustments */
211 GtkAdjustment *hadjustment;
212 GtkAdjustment *vadjustment;
214 /* xor GC for the vertical drag line */
217 /* gc for drawing unselected cells */
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 GtkCListCompareFunc compare;
244 struct _GtkCListClass
246 GtkContainerClass parent_class;
248 void (*set_scroll_adjustments) (GtkCList *clist,
249 GtkAdjustment *hadjustment,
250 GtkAdjustment *vadjustment);
251 void (*refresh) (GtkCList *clist);
252 void (*select_row) (GtkCList *clist,
256 void (*unselect_row) (GtkCList *clist,
260 void (*row_move) (GtkCList *clist,
263 void (*click_column) (GtkCList *clist,
265 void (*resize_column) (GtkCList *clist,
268 void (*toggle_focus_row) (GtkCList *clist);
269 void (*select_all) (GtkCList *clist);
270 void (*unselect_all) (GtkCList *clist);
271 void (*undo_selection) (GtkCList *clist);
272 void (*start_selection) (GtkCList *clist);
273 void (*end_selection) (GtkCList *clist);
274 void (*extend_selection) (GtkCList *clist,
275 GtkScrollType scroll_type,
277 gboolean auto_start_selection);
278 void (*scroll_horizontal) (GtkCList *clist,
279 GtkScrollType scroll_type,
281 void (*scroll_vertical) (GtkCList *clist,
282 GtkScrollType scroll_type,
284 void (*toggle_add_mode) (GtkCList *clist);
285 void (*abort_column_resize) (GtkCList *clist);
286 void (*resync_selection) (GtkCList *clist,
288 GList* (*selection_find) (GtkCList *clist,
290 GList *row_list_element);
291 void (*draw_row) (GtkCList *clist,
294 GtkCListRow *clist_row);
295 void (*draw_drag_highlight) (GtkCList *clist,
296 GtkCListRow *target_row,
297 gint target_row_number,
298 GtkCListDragPos drag_pos);
299 void (*clear) (GtkCList *clist);
300 void (*fake_unselect_all) (GtkCList *clist,
302 void (*sort_list) (GtkCList *clist);
303 gint (*insert_row) (GtkCList *clist,
306 void (*remove_row) (GtkCList *clist,
308 void (*set_cell_contents) (GtkCList *clist,
309 GtkCListRow *clist_row,
316 void (*cell_size_request) (GtkCList *clist,
317 GtkCListRow *clist_row,
319 GtkRequisition *requisition);
323 struct _GtkCListColumn
334 GtkJustification justification;
338 guint resizeable : 1;
339 guint auto_resize : 1;
340 guint button_passive : 1;
354 GtkDestroyNotify destroy;
358 guint selectable : 1;
361 /* Cell Structures */
374 struct _GtkCellPixmap
387 struct _GtkCellPixText
402 struct _GtkCellWidget
442 GtkType gtk_clist_get_type (void) G_GNUC_CONST;
444 /* create a new GtkCList */
445 GtkWidget* gtk_clist_new (gint columns);
446 GtkWidget* gtk_clist_new_with_titles (gint columns,
449 /* set adjustments of clist */
450 void gtk_clist_set_hadjustment (GtkCList *clist,
451 GtkAdjustment *adjustment);
452 void gtk_clist_set_vadjustment (GtkCList *clist,
453 GtkAdjustment *adjustment);
455 /* get adjustments of clist */
456 GtkAdjustment* gtk_clist_get_hadjustment (GtkCList *clist);
457 GtkAdjustment* gtk_clist_get_vadjustment (GtkCList *clist);
459 /* set the border style of the clist */
460 void gtk_clist_set_shadow_type (GtkCList *clist,
463 /* set the clist's selection mode */
464 void gtk_clist_set_selection_mode (GtkCList *clist,
465 GtkSelectionMode mode);
467 /* enable clists reorder ability */
468 void gtk_clist_set_reorderable (GtkCList *clist,
469 gboolean reorderable);
470 void gtk_clist_set_use_drag_icons (GtkCList *clist,
472 void gtk_clist_set_button_actions (GtkCList *clist,
474 guint8 button_actions);
476 /* freeze all visual updates of the list, and then thaw the list after
477 * you have made a number of changes and the updates wil occure in a
478 * more efficent mannor than if you made them on a unfrozen list
480 void gtk_clist_freeze (GtkCList *clist);
481 void gtk_clist_thaw (GtkCList *clist);
483 /* show and hide the column title buttons */
484 void gtk_clist_column_titles_show (GtkCList *clist);
485 void gtk_clist_column_titles_hide (GtkCList *clist);
487 /* set the column title to be a active title (responds to button presses,
488 * prelights, and grabs keyboard focus), or passive where it acts as just
491 void gtk_clist_column_title_active (GtkCList *clist,
493 void gtk_clist_column_title_passive (GtkCList *clist,
495 void gtk_clist_column_titles_active (GtkCList *clist);
496 void gtk_clist_column_titles_passive (GtkCList *clist);
498 /* set the title in the column title button */
499 void gtk_clist_set_column_title (GtkCList *clist,
503 /* returns the title of column. Returns NULL if title is not set */
504 gchar * gtk_clist_get_column_title (GtkCList *clist,
507 /* set a widget instead of a title for the column title button */
508 void gtk_clist_set_column_widget (GtkCList *clist,
512 /* returns the column widget */
513 GtkWidget * gtk_clist_get_column_widget (GtkCList *clist,
516 /* set the justification on a column */
517 void gtk_clist_set_column_justification (GtkCList *clist,
519 GtkJustification justification);
521 /* set visibility of a column */
522 void gtk_clist_set_column_visibility (GtkCList *clist,
526 /* enable/disable column resize operations by mouse */
527 void gtk_clist_set_column_resizeable (GtkCList *clist,
529 gboolean resizeable);
531 /* resize column automatically to its optimal width */
532 void gtk_clist_set_column_auto_resize (GtkCList *clist,
534 gboolean auto_resize);
536 gint gtk_clist_columns_autosize (GtkCList *clist);
538 /* return the optimal column width, i.e. maximum of all cell widths */
539 gint gtk_clist_optimal_column_width (GtkCList *clist,
542 /* set the pixel width of a column; this is a necessary step in
543 * creating a CList because otherwise the column width is chozen from
544 * the width of the column title, which will never be right
546 void gtk_clist_set_column_width (GtkCList *clist,
550 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
551 void gtk_clist_set_column_min_width (GtkCList *clist,
554 void gtk_clist_set_column_max_width (GtkCList *clist,
558 /* change the height of the rows, the default (height=0) is
559 * the hight of the current font.
561 void gtk_clist_set_row_height (GtkCList *clist,
564 /* scroll the viewing area of the list to the given column and row;
565 * row_align and col_align are between 0-1 representing the location the
566 * row should appear on the screnn, 0.0 being top or left, 1.0 being
567 * bottom or right; if row or column is -1 then then there is no change
569 void gtk_clist_moveto (GtkCList *clist,
575 /* returns whether the row is visible */
576 GtkVisibility gtk_clist_row_is_visible (GtkCList *clist,
579 /* returns the cell type */
580 GtkCellType gtk_clist_get_cell_type (GtkCList *clist,
584 /* sets a given cell's text, replacing its current contents */
585 void gtk_clist_set_text (GtkCList *clist,
590 /* for the "get" functions, any of the return pointer can be
591 * NULL if you are not interested
593 gint gtk_clist_get_text (GtkCList *clist,
598 /* sets a given cell's pixmap, replacing its current contents */
599 void gtk_clist_set_pixmap (GtkCList *clist,
605 gint gtk_clist_get_pixmap (GtkCList *clist,
611 /* sets a given cell's pixmap and text, replacing its current contents */
612 void gtk_clist_set_pixtext (GtkCList *clist,
620 gint gtk_clist_get_pixtext (GtkCList *clist,
628 /* sets the foreground color of a row, the color must already
631 void gtk_clist_set_foreground (GtkCList *clist,
635 /* sets the background color of a row, the color must already
638 void gtk_clist_set_background (GtkCList *clist,
642 /* set / get cell styles */
643 void gtk_clist_set_cell_style (GtkCList *clist,
648 GtkStyle *gtk_clist_get_cell_style (GtkCList *clist,
652 void gtk_clist_set_row_style (GtkCList *clist,
656 GtkStyle *gtk_clist_get_row_style (GtkCList *clist,
659 /* this sets a horizontal and vertical shift for drawing
660 * the contents of a cell; it can be positive or negitive;
661 * this is particulary useful for indenting items in a column
663 void gtk_clist_set_shift (GtkCList *clist,
669 /* set/get selectable flag of a single row */
670 void gtk_clist_set_selectable (GtkCList *clist,
672 gboolean selectable);
673 gboolean gtk_clist_get_selectable (GtkCList *clist,
676 /* prepend/append returns the index of the row you just added,
677 * making it easier to append and modify a row
679 gint gtk_clist_prepend (GtkCList *clist,
681 gint gtk_clist_append (GtkCList *clist,
684 /* inserts a row at index row and returns the row where it was
685 * actually inserted (may be different from "row" in auto_sort mode)
687 gint gtk_clist_insert (GtkCList *clist,
691 /* removes row at index row */
692 void gtk_clist_remove (GtkCList *clist,
695 /* sets a arbitrary data pointer for a given row */
696 void gtk_clist_set_row_data (GtkCList *clist,
700 /* sets a data pointer for a given row with destroy notification */
701 void gtk_clist_set_row_data_full (GtkCList *clist,
704 GtkDestroyNotify destroy);
706 /* returns the data set for a row */
707 gpointer gtk_clist_get_row_data (GtkCList *clist,
710 /* givin a data pointer, find the first (and hopefully only!)
711 * row that points to that data, or -1 if none do
713 gint gtk_clist_find_row_from_data (GtkCList *clist,
716 /* force selection of a row */
717 void gtk_clist_select_row (GtkCList *clist,
721 /* force unselection of a row */
722 void gtk_clist_unselect_row (GtkCList *clist,
726 /* undo the last select/unselect operation */
727 void gtk_clist_undo_selection (GtkCList *clist);
729 /* clear the entire list -- this is much faster than removing
730 * each item with gtk_clist_remove
732 void gtk_clist_clear (GtkCList *clist);
734 /* return the row column corresponding to the x and y coordinates,
735 * the returned values are only valid if the x and y coordinates
736 * are respectively to a window == clist->clist_window
738 gint gtk_clist_get_selection_info (GtkCList *clist,
744 /* in multiple or extended mode, select all rows */
745 void gtk_clist_select_all (GtkCList *clist);
747 /* in all modes except browse mode, deselect all rows */
748 void gtk_clist_unselect_all (GtkCList *clist);
750 /* swap the position of two rows */
751 void gtk_clist_swap_rows (GtkCList *clist,
755 /* move row from source_row position to dest_row position */
756 void gtk_clist_row_move (GtkCList *clist,
760 /* sets a compare function different to the default */
761 void gtk_clist_set_compare_func (GtkCList *clist,
762 GtkCListCompareFunc cmp_func);
764 /* the column to sort by */
765 void gtk_clist_set_sort_column (GtkCList *clist,
768 /* how to sort : ascending or descending */
769 void gtk_clist_set_sort_type (GtkCList *clist,
770 GtkSortType sort_type);
772 /* sort the list with the current compare function */
773 void gtk_clist_sort (GtkCList *clist);
775 /* Automatically sort upon insertion */
776 void gtk_clist_set_auto_sort (GtkCList *clist,
779 /* Private function for clist, ctree */
781 PangoLayout *_gtk_clist_create_cell_layout (GtkCList *clist,
782 GtkCListRow *clist_row,
787 #endif /* __cplusplus */
789 #endif /* __GTK_CLIST_H__ */
791 #endif /* GTK_DISABLE_DEPRECATED */