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 /* Generic visibility flags */
42 GTK_VISIBILITY_PARTIAL
,
48 GTK_CMCLIST_IN_DRAG
= 1 << 0,
49 GTK_CMCLIST_ROW_HEIGHT_SET
= 1 << 1,
50 GTK_CMCLIST_SHOW_TITLES
= 1 << 2,
52 GTK_CMCLIST_ADD_MODE
= 1 << 4,
53 GTK_CMCLIST_AUTO_SORT
= 1 << 5,
54 GTK_CMCLIST_AUTO_RESIZE_BLOCKED
= 1 << 6,
55 GTK_CMCLIST_REORDERABLE
= 1 << 7,
56 GTK_CMCLIST_USE_DRAG_ICONS
= 1 << 8,
57 GTK_CMCLIST_DRAW_DRAG_LINE
= 1 << 9,
58 GTK_CMCLIST_DRAW_DRAG_RECT
= 1 << 10
73 GTK_CMCLIST_DRAG_NONE
,
74 GTK_CMCLIST_DRAG_BEFORE
,
75 GTK_CMCLIST_DRAG_INTO
,
76 GTK_CMCLIST_DRAG_AFTER
81 GTK_CMBUTTON_IGNORED
= 0,
82 GTK_CMBUTTON_SELECTS
= 1 << 0,
83 GTK_CMBUTTON_DRAGS
= 1 << 1,
84 GTK_CMBUTTON_EXPANDS
= 1 << 2
87 #define GTK_TYPE_CMCLIST (gtk_cmclist_get_type ())
88 #define GTK_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CMCLIST, GtkCMCList))
89 #define GTK_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CMCLIST, GtkCMCListClass))
90 #define GTK_IS_CMCLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CMCLIST))
91 #define GTK_IS_CMCLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CMCLIST))
92 #define GTK_CMCLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CMCLIST, GtkCMCListClass))
95 #define GTK_CMCLIST_FLAGS(clist) (GTK_CMCLIST (clist)->flags)
96 #define GTK_CMCLIST_SET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) |= (GTK_ ## flag))
97 #define GTK_CMCLIST_UNSET_FLAG(clist,flag) (GTK_CMCLIST_FLAGS (clist) &= ~(GTK_ ## flag))
99 #define GTK_CMCLIST_IN_DRAG(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_IN_DRAG)
100 #define GTK_CMCLIST_ROW_HEIGHT_SET(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ROW_HEIGHT_SET)
101 #define GTK_CMCLIST_SHOW_TITLES(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_SHOW_TITLES)
102 #define GTK_CMCLIST_ADD_MODE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_ADD_MODE)
103 #define GTK_CMCLIST_AUTO_SORT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_SORT)
104 #define GTK_CMCLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_AUTO_RESIZE_BLOCKED)
105 #define GTK_CMCLIST_REORDERABLE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_REORDERABLE)
106 #define GTK_CMCLIST_USE_DRAG_ICONS(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_USE_DRAG_ICONS)
107 #define GTK_CMCLIST_DRAW_DRAG_LINE(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_LINE)
108 #define GTK_CMCLIST_DRAW_DRAG_RECT(clist) (GTK_CMCLIST_FLAGS (clist) & GTK_CMCLIST_DRAW_DRAG_RECT)
110 #define GTK_CMCLIST_ROW(_glist_) ((GtkCMCListRow *)((_glist_)->data))
112 /* pointer casting for cells */
113 #define GTK_CMCELL_TEXT(cell) (((GtkCMCellText *) &(cell)))
114 #define GTK_CMCELL_PIXBUF(cell) (((GtkCMCellPixbuf *) &(cell)))
115 #define GTK_CMCELL_PIXTEXT(cell) (((GtkCMCellPixText *) &(cell)))
116 #define GTK_CMCELL_WIDGET(cell) (((GtkCMCellWidget *) &(cell)))
118 typedef struct _GtkCMCList GtkCMCList
;
119 typedef struct _GtkCMCListClass GtkCMCListClass
;
120 typedef struct _GtkCMCListColumn GtkCMCListColumn
;
121 typedef struct _GtkCMCListRow GtkCMCListRow
;
123 typedef struct _GtkCMCell GtkCMCell
;
124 typedef struct _GtkCMCellText GtkCMCellText
;
125 typedef struct _GtkCMCellPixbuf GtkCMCellPixbuf
;
126 typedef struct _GtkCMCellPixText GtkCMCellPixText
;
127 typedef struct _GtkCMCellWidget GtkCMCellWidget
;
129 typedef gint (*GtkCMCListCompareFunc
) (GtkCMCList
*clist
,
133 typedef struct _GtkCMCListCellInfo GtkCMCListCellInfo
;
134 typedef struct _GtkCMCListDestInfo GtkCMCListDestInfo
;
136 struct _GtkCMCListCellInfo
142 struct _GtkCMCListDestInfo
144 GtkCMCListCellInfo cell
;
145 GtkCMCListDragPos insert_pos
;
150 GtkContainer container
;
158 /* allocation rectangle after the conatiner_border_width
159 * and the width of the shadow border */
160 GdkRectangle internal_allocation
;
170 GdkRectangle column_title_area
;
171 GdkWindow
*title_window
;
173 /* dynamicly allocated array of column structures */
174 GtkCMCListColumn
*column
;
176 /* the scrolling window and its height and width to
177 * make things a little speedier */
178 GdkWindow
*clist_window
;
179 gint clist_window_width
;
180 gint clist_window_height
;
182 /* offsets for scrolling */
186 /* border shadow style */
187 GtkShadowType shadow_type
;
189 /* the list's selection mode (gtkenums.h) */
190 GtkSelectionMode selection_mode
;
192 /* list of selected rows */
194 GList
*selection_end
;
196 GList
*undo_selection
;
197 GList
*undo_unselection
;
201 guint8 button_actions
[5];
206 GtkCMCListCellInfo click_cell
;
208 /* scroll adjustments */
209 GtkAdjustment
*hadjustment
;
210 GtkAdjustment
*vadjustment
;
214 /* cursor used to indicate dragging */
215 GdkCursor
*cursor_drag
;
217 /* the current x-pixel location of the xor-drag line */
223 gint focus_header_column
;
225 /* dragging the selection */
227 GtkStateType anchor_state
;
232 GtkSortType sort_type
;
233 GtkCMCListCompareFunc compare
;
236 gint drag_highlight_row
;
237 GtkCMCListDragPos drag_highlight_pos
;
241 struct _GtkCMCListClass
243 GtkContainerClass parent_class
;
245 void (*refresh
) (GtkCMCList
*clist
);
246 void (*select_row
) (GtkCMCList
*clist
,
250 void (*unselect_row
) (GtkCMCList
*clist
,
254 void (*row_move
) (GtkCMCList
*clist
,
257 void (*click_column
) (GtkCMCList
*clist
,
259 void (*resize_column
) (GtkCMCList
*clist
,
262 void (*toggle_focus_row
) (GtkCMCList
*clist
);
263 void (*select_all
) (GtkCMCList
*clist
);
264 void (*unselect_all
) (GtkCMCList
*clist
);
265 void (*undo_selection
) (GtkCMCList
*clist
);
266 void (*start_selection
) (GtkCMCList
*clist
);
267 void (*end_selection
) (GtkCMCList
*clist
);
268 void (*extend_selection
) (GtkCMCList
*clist
,
269 GtkScrollType scroll_type
,
271 gboolean auto_start_selection
);
272 void (*scroll_horizontal
) (GtkCMCList
*clist
,
273 GtkScrollType scroll_type
,
275 void (*scroll_vertical
) (GtkCMCList
*clist
,
276 GtkScrollType scroll_type
,
278 void (*toggle_add_mode
) (GtkCMCList
*clist
);
279 void (*abort_column_resize
) (GtkCMCList
*clist
);
280 void (*resync_selection
) (GtkCMCList
*clist
,
282 GList
* (*selection_find
) (GtkCMCList
*clist
,
284 GList
*row_list_element
);
285 void (*draw_row
) (GtkCMCList
*clist
,
288 GtkCMCListRow
*clist_row
);
289 void (*clear
) (GtkCMCList
*clist
);
290 void (*fake_unselect_all
) (GtkCMCList
*clist
,
292 void (*sort_list
) (GtkCMCList
*clist
);
293 gint (*insert_row
) (GtkCMCList
*clist
,
296 void (*remove_row
) (GtkCMCList
*clist
,
298 void (*set_cell_contents
) (GtkCMCList
*clist
,
299 GtkCMCListRow
*clist_row
,
305 void (*cell_size_request
) (GtkCMCList
*clist
,
306 GtkCMCListRow
*clist_row
,
308 GtkRequisition
*requisition
);
312 struct _GtkCMCListColumn
323 GtkJustification justification
;
327 guint resizeable
: 1;
328 guint auto_resize
: 1;
329 guint button_passive
: 1;
332 struct _GtkCMCListRow
343 GDestroyNotify destroy
;
347 guint selectable
: 1;
350 /* Cell Structures */
351 struct _GtkCMCellText
363 struct _GtkCMCellPixbuf
375 struct _GtkCMCellPixText
389 struct _GtkCMCellWidget
427 GType
gtk_cmclist_get_type (void);
429 /* create a new GtkCMCList */
430 GtkWidget
* gtk_cmclist_new (gint columns
);
431 GtkWidget
* gtk_cmclist_new_with_titles (gint columns
,
434 /* set adjustments of clist */
435 void gtk_cmclist_set_hadjustment (GtkCMCList
*clist
,
436 GtkAdjustment
*adjustment
);
437 void gtk_cmclist_set_vadjustment (GtkCMCList
*clist
,
438 GtkAdjustment
*adjustment
);
440 /* get adjustments of clist */
441 GtkAdjustment
* gtk_cmclist_get_hadjustment (GtkCMCList
*clist
);
442 GtkAdjustment
* gtk_cmclist_get_vadjustment (GtkCMCList
*clist
);
444 /* set the border style of the clist */
445 void gtk_cmclist_set_shadow_type (GtkCMCList
*clist
,
448 /* set the clist's selection mode */
449 void gtk_cmclist_set_selection_mode (GtkCMCList
*clist
,
450 GtkSelectionMode mode
);
452 /* enable clists reorder ability */
453 void gtk_cmclist_set_reorderable (GtkCMCList
*clist
,
454 gboolean reorderable
);
455 void gtk_cmclist_set_use_drag_icons (GtkCMCList
*clist
,
457 void gtk_cmclist_set_button_actions (GtkCMCList
*clist
,
459 guint8 button_actions
);
461 /* freeze all visual updates of the list, and then thaw the list after
462 * you have made a number of changes and the updates wil occure in a
463 * more efficent mannor than if you made them on a unfrozen list
465 void gtk_cmclist_freeze (GtkCMCList
*clist
);
466 void gtk_cmclist_thaw (GtkCMCList
*clist
);
468 /* show and hide the column title buttons */
469 void gtk_cmclist_column_titles_show (GtkCMCList
*clist
);
470 void gtk_cmclist_column_titles_hide (GtkCMCList
*clist
);
472 /* set the column title to be a active title (responds to button presses,
473 * prelights, and grabs keyboard focus), or passive where it acts as just
476 void gtk_cmclist_column_title_active (GtkCMCList
*clist
,
478 void gtk_cmclist_column_title_passive (GtkCMCList
*clist
,
480 void gtk_cmclist_column_titles_active (GtkCMCList
*clist
);
481 void gtk_cmclist_column_titles_passive (GtkCMCList
*clist
);
483 /* set the title in the column title button */
484 void gtk_cmclist_set_column_title (GtkCMCList
*clist
,
488 /* returns the title of column. Returns NULL if title is not set */
489 gchar
* gtk_cmclist_get_column_title (GtkCMCList
*clist
,
492 /* set a widget instead of a title for the column title button */
493 void gtk_cmclist_set_column_widget (GtkCMCList
*clist
,
497 /* returns the column widget */
498 GtkWidget
* gtk_cmclist_get_column_widget (GtkCMCList
*clist
,
501 /* set the justification on a column */
502 void gtk_cmclist_set_column_justification (GtkCMCList
*clist
,
504 GtkJustification justification
);
506 /* set visibility of a column */
507 void gtk_cmclist_set_column_visibility (GtkCMCList
*clist
,
511 /* enable/disable column resize operations by mouse */
512 void gtk_cmclist_set_column_resizeable (GtkCMCList
*clist
,
514 gboolean resizeable
);
516 /* resize column automatically to its optimal width */
517 void gtk_cmclist_set_column_auto_resize (GtkCMCList
*clist
,
519 gboolean auto_resize
);
521 gint
gtk_cmclist_columns_autosize (GtkCMCList
*clist
);
523 /* return the optimal column width, i.e. maximum of all cell widths */
524 gint
gtk_cmclist_optimal_column_width (GtkCMCList
*clist
,
527 /* set the pixel width of a column; this is a necessary step in
528 * creating a CList because otherwise the column width is chozen from
529 * the width of the column title, which will never be right
531 void gtk_cmclist_set_column_width (GtkCMCList
*clist
,
535 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
536 void gtk_cmclist_set_column_min_width (GtkCMCList
*clist
,
539 void gtk_cmclist_set_column_max_width (GtkCMCList
*clist
,
543 /* change the height of the rows, the default (height=0) is
544 * the hight of the current font.
546 void gtk_cmclist_set_row_height (GtkCMCList
*clist
,
549 /* scroll the viewing area of the list to the given column and row;
550 * row_align and col_align are between 0-1 representing the location the
551 * row should appear on the screnn, 0.0 being top or left, 1.0 being
552 * bottom or right; if row or column is -1 then then there is no change
554 void gtk_cmclist_moveto (GtkCMCList
*clist
,
560 /* returns whether the row is visible */
561 GtkVisibility
gtk_cmclist_row_is_visible (GtkCMCList
*clist
,
564 /* returns whether the row is above or below current viewport */
565 gboolean
gtk_cmclist_row_is_above_viewport (GtkCMCList
*clist
,
567 gboolean
gtk_cmclist_row_is_below_viewport (GtkCMCList
*clist
,
570 /* returns the cell type */
571 GtkCMCellType
gtk_cmclist_get_cell_type (GtkCMCList
*clist
,
575 /* sets a given cell's text, replacing its current contents */
576 void gtk_cmclist_set_text (GtkCMCList
*clist
,
581 /* for the "get" functions, any of the return pointer can be
582 * NULL if you are not interested
584 gint
gtk_cmclist_get_text (GtkCMCList
*clist
,
589 /* sets a given cell's pixbuf, replacing its current contents */
590 void gtk_cmclist_set_pixbuf (GtkCMCList
*clist
,
595 gint
gtk_cmclist_get_pixbuf (GtkCMCList
*clist
,
600 /* sets a given cell's pixbuf and text, replacing its current contents */
601 void gtk_cmclist_set_pixtext (GtkCMCList
*clist
,
608 gint
gtk_cmclist_get_pixtext (GtkCMCList
*clist
,
615 /* sets the foreground color of a row, the color must already
618 void gtk_cmclist_set_foreground (GtkCMCList
*clist
,
620 const GdkColor
*color
);
622 /* sets the background color of a row, the color must already
625 void gtk_cmclist_set_background (GtkCMCList
*clist
,
627 const GdkColor
*color
);
629 /* set / get cell styles */
630 void gtk_cmclist_set_cell_style (GtkCMCList
*clist
,
635 GtkStyle
*gtk_cmclist_get_cell_style (GtkCMCList
*clist
,
639 void gtk_cmclist_set_row_style (GtkCMCList
*clist
,
643 GtkStyle
*gtk_cmclist_get_row_style (GtkCMCList
*clist
,
646 /* this sets a horizontal and vertical shift for drawing
647 * the contents of a cell; it can be positive or negitive;
648 * this is particulary useful for indenting items in a column
650 void gtk_cmclist_set_shift (GtkCMCList
*clist
,
656 /* set/get selectable flag of a single row */
657 void gtk_cmclist_set_selectable (GtkCMCList
*clist
,
659 gboolean selectable
);
660 gboolean
gtk_cmclist_get_selectable (GtkCMCList
*clist
,
663 /* prepend/append returns the index of the row you just added,
664 * making it easier to append and modify a row
666 gint
gtk_cmclist_prepend (GtkCMCList
*clist
,
668 gint
gtk_cmclist_append (GtkCMCList
*clist
,
671 /* inserts a row at index row and returns the row where it was
672 * actually inserted (may be different from "row" in auto_sort mode)
674 gint
gtk_cmclist_insert (GtkCMCList
*clist
,
678 /* removes row at index row */
679 void gtk_cmclist_remove (GtkCMCList
*clist
,
682 /* sets a arbitrary data pointer for a given row */
683 void gtk_cmclist_set_row_data (GtkCMCList
*clist
,
687 /* sets a data pointer for a given row with destroy notification */
688 void gtk_cmclist_set_row_data_full (GtkCMCList
*clist
,
691 GDestroyNotify destroy
);
693 /* returns the data set for a row */
694 gpointer
gtk_cmclist_get_row_data (GtkCMCList
*clist
,
697 /* givin a data pointer, find the first (and hopefully only!)
698 * row that points to that data, or -1 if none do
700 gint
gtk_cmclist_find_row_from_data (GtkCMCList
*clist
,
703 /* force selection of a row */
704 void gtk_cmclist_select_row (GtkCMCList
*clist
,
708 /* force unselection of a row */
709 void gtk_cmclist_unselect_row (GtkCMCList
*clist
,
713 /* undo the last select/unselect operation */
714 void gtk_cmclist_undo_selection (GtkCMCList
*clist
);
716 /* clear the entire list -- this is much faster than removing
717 * each item with gtk_cmclist_remove
719 void gtk_cmclist_clear (GtkCMCList
*clist
);
721 /* return the row column corresponding to the x and y coordinates,
722 * the returned values are only valid if the x and y coordinates
723 * are respectively to a window == clist->clist_window
725 gint
gtk_cmclist_get_selection_info (GtkCMCList
*clist
,
731 /* in multiple or extended mode, select all rows */
732 void gtk_cmclist_select_all (GtkCMCList
*clist
);
734 /* in all modes except browse mode, deselect all rows */
735 void gtk_cmclist_unselect_all (GtkCMCList
*clist
);
737 /* swap the position of two rows */
738 void gtk_cmclist_swap_rows (GtkCMCList
*clist
,
742 /* move row from source_row position to dest_row position */
743 void gtk_cmclist_row_move (GtkCMCList
*clist
,
747 /* sets a compare function different to the default */
748 void gtk_cmclist_set_compare_func (GtkCMCList
*clist
,
749 GtkCMCListCompareFunc cmp_func
);
751 /* the column to sort by */
752 void gtk_cmclist_set_sort_column (GtkCMCList
*clist
,
755 /* how to sort : ascending or descending */
756 void gtk_cmclist_set_sort_type (GtkCMCList
*clist
,
757 GtkSortType sort_type
);
759 /* sort the list with the current compare function */
760 void gtk_cmclist_sort (GtkCMCList
*clist
);
762 /* Automatically sort upon insertion */
763 void gtk_cmclist_set_auto_sort (GtkCMCList
*clist
,
766 /* Private function for clist, ctree */
768 PangoLayout
*_gtk_cmclist_create_cell_layout (GtkCMCList
*clist
,
769 GtkCMCListRow
*clist_row
,
776 #endif /* __GTK_CMCLIST_H__ */