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>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 * GtkCList for GTK1.2 lib versions, copied from GTK sources.
32 * @todo is this correct?
35 #ifndef __ETH_CLIST_H__
36 #define __ETH_CLIST_H__
39 #include <gtk/gtksignal.h>
40 #include <gtk/gtkalignment.h>
41 #include <gtk/gtklabel.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtkhscrollbar.h>
44 #include <gtk/gtkvscrollbar.h>
45 #include <gtk/gtkenums.h>
49 #endif /* __cplusplus */
53 ETH_CLIST_IN_DRAG = 1 << 0,
54 ETH_CLIST_ROW_HEIGHT_SET = 1 << 1,
55 ETH_CLIST_SHOW_TITLES = 1 << 2,
56 ETH_CLIST_CHILD_HAS_FOCUS = 1 << 3,
57 ETH_CLIST_ADD_MODE = 1 << 4,
58 ETH_CLIST_AUTO_SORT = 1 << 5,
59 ETH_CLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
60 ETH_CLIST_REORDERABLE = 1 << 7,
61 ETH_CLIST_USE_DRAG_ICONS = 1 << 8,
62 ETH_CLIST_DRAW_DRAG_LINE = 1 << 9,
63 ETH_CLIST_DRAW_DRAG_RECT = 1 << 10
79 ETH_CLIST_DRAG_BEFORE,
86 ETH_BUTTON_IGNORED = 0,
87 ETH_BUTTON_SELECTS = 1 << 0,
88 ETH_BUTTON_DRAGS = 1 << 1,
89 ETH_BUTTON_EXPANDS = 1 << 2
92 extern GtkType eth_clist_type;
93 void init_eth_clist_type (void);
95 #define ETH_TYPE_CLIST (eth_clist_type)
96 #define ETH_CLIST(obj) (GTK_CHECK_CAST ((obj), ETH_TYPE_CLIST, EthCList))
97 #define ETH_CLIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), ETH_TYPE_CLIST, EthCListClass))
98 #define ETH_IS_CLIST(obj) (GTK_CHECK_TYPE ((obj), ETH_TYPE_CLIST))
99 #define ETH_IS_CLIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), ETH_TYPE_CLIST))
101 #define ETH_CLIST_FLAGS(clist) (ETH_CLIST (clist)->flags)
102 #define ETH_CLIST_SET_FLAG(clist,flag) (ETH_CLIST_FLAGS (clist) |= (ETH_ ## flag))
103 #define ETH_CLIST_UNSET_FLAG(clist,flag) (ETH_CLIST_FLAGS (clist) &= ~(ETH_ ## flag))
105 #define ETH_CLIST_IN_DRAG(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_IN_DRAG)
106 #define ETH_CLIST_ROW_HEIGHT_SET(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_ROW_HEIGHT_SET)
107 #define ETH_CLIST_SHOW_TITLES(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_SHOW_TITLES)
108 #define ETH_CLIST_CHILD_HAS_FOCUS(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_CHILD_HAS_FOCUS)
109 #define ETH_CLIST_ADD_MODE(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_ADD_MODE)
110 #define ETH_CLIST_AUTO_SORT(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_AUTO_SORT)
111 #define ETH_CLIST_AUTO_RESIZE_BLOCKED(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_AUTO_RESIZE_BLOCKED)
112 #define ETH_CLIST_REORDERABLE(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_REORDERABLE)
113 #define ETH_CLIST_USE_DRAG_ICONS(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_USE_DRAG_ICONS)
114 #define ETH_CLIST_DRAW_DRAG_LINE(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_DRAW_DRAG_LINE)
115 #define ETH_CLIST_DRAW_DRAG_RECT(clist) (ETH_CLIST_FLAGS (clist) & ETH_CLIST_DRAW_DRAG_RECT)
117 #define ETH_CLIST_ROW(_glist_) ((EthCListRow *)((_glist_)->data))
119 /* pointer casting for cells */
120 #define ETH_CELL_TEXT(cell) (((EthCellText *) &(cell)))
121 #define ETH_CELL_PIXMAP(cell) (((EthCellPixmap *) &(cell)))
122 #define ETH_CELL_PIXTEXT(cell) (((EthCellPixText *) &(cell)))
123 #define ETH_CELL_WIDGET(cell) (((EthCellWidget *) &(cell)))
125 typedef struct _EthCList EthCList;
126 typedef struct _EthCListClass EthCListClass;
127 typedef struct _EthCListColumn EthCListColumn;
128 typedef struct _EthCListRow EthCListRow;
130 typedef struct _EthCell EthCell;
131 typedef struct _EthCellText EthCellText;
132 typedef struct _EthCellPixmap EthCellPixmap;
133 typedef struct _EthCellPixText EthCellPixText;
134 typedef struct _EthCellWidget EthCellWidget;
136 typedef gint (*EthCListCompareFunc) (EthCList *clist,
140 typedef struct _EthCListCellInfo EthCListCellInfo;
141 typedef struct _EthCListDestInfo EthCListDestInfo;
143 struct _EthCListCellInfo
149 struct _EthCListDestInfo
151 EthCListCellInfo cell;
152 EthCListDragPos insert_pos;
157 GtkContainer container;
162 GMemChunk *row_mem_chunk;
163 GMemChunk *cell_mem_chunk;
167 /* allocation rectangle after the conatiner_border_width
168 * and the width of the shadow border */
169 GdkRectangle internal_allocation;
173 gint row_center_offset;
180 GdkRectangle column_title_area;
181 GdkWindow *title_window;
183 /* dynamicly allocated array of column structures */
184 EthCListColumn *column;
186 /* the scrolling window and its height and width to
187 * make things a little speedier */
188 GdkWindow *clist_window;
189 gint clist_window_width;
190 gint clist_window_height;
192 /* offsets for scrolling */
196 /* border shadow style */
197 GtkShadowType shadow_type;
199 /* the list's selection mode (gtkenums.h) */
200 GtkSelectionMode selection_mode;
202 /* list of selected rows */
204 GList *selection_end;
206 GList *undo_selection;
207 GList *undo_unselection;
211 guint8 button_actions[5];
216 EthCListCellInfo click_cell;
218 /* scroll adjustments */
219 GtkAdjustment *hadjustment;
220 GtkAdjustment *vadjustment;
222 /* xor GC for the vertical drag line */
225 /* gc for drawing unselected cells */
229 /* cursor used to indicate dragging */
230 GdkCursor *cursor_drag;
232 /* the current x-pixel location of the xor-drag line */
238 /* dragging the selection */
240 GtkStateType anchor_state;
245 GtkSortType sort_type;
246 EthCListCompareFunc compare;
250 struct _EthCListClass
252 GtkContainerClass parent_class;
254 void (*set_scroll_adjustments) (EthCList *clist,
255 GtkAdjustment *hadjustment,
256 GtkAdjustment *vadjustment);
257 void (*refresh) (EthCList *clist);
258 void (*select_row) (EthCList *clist,
262 void (*unselect_row) (EthCList *clist,
266 void (*row_move) (EthCList *clist,
269 void (*click_column) (EthCList *clist,
271 void (*resize_column) (EthCList *clist,
274 void (*toggle_focus_row) (EthCList *clist);
275 void (*select_all) (EthCList *clist);
276 void (*unselect_all) (EthCList *clist);
277 void (*undo_selection) (EthCList *clist);
278 void (*start_selection) (EthCList *clist);
279 void (*end_selection) (EthCList *clist);
280 void (*extend_selection) (EthCList *clist,
281 GtkScrollType scroll_type,
283 gboolean auto_start_selection);
284 void (*scroll_horizontal) (EthCList *clist,
285 GtkScrollType scroll_type,
287 void (*scroll_vertical) (EthCList *clist,
288 GtkScrollType scroll_type,
290 void (*toggle_add_mode) (EthCList *clist);
291 void (*abort_column_resize) (EthCList *clist);
292 void (*resync_selection) (EthCList *clist,
294 GList* (*selection_find) (EthCList *clist,
296 GList *row_list_element);
297 void (*draw_row) (EthCList *clist,
300 EthCListRow *clist_row);
301 void (*draw_drag_highlight) (EthCList *clist,
302 EthCListRow *target_row,
303 gint target_row_number,
304 EthCListDragPos drag_pos);
305 void (*clear) (EthCList *clist);
306 void (*fake_unselect_all) (EthCList *clist,
308 void (*sort_list) (EthCList *clist);
309 gint (*insert_row) (EthCList *clist,
312 void (*remove_row) (EthCList *clist,
314 void (*set_cell_contents) (EthCList *clist,
315 EthCListRow *clist_row,
322 void (*cell_size_request) (EthCList *clist,
323 EthCListRow *clist_row,
325 GtkRequisition *requisition);
329 struct _EthCListColumn
340 GtkJustification justification;
344 guint resizeable : 1;
345 guint auto_resize : 1;
346 guint button_passive : 1;
360 GtkDestroyNotify destroy;
364 guint selectable : 1;
367 /* Cell Structures */
380 struct _EthCellPixmap
393 struct _EthCellPixText
408 struct _EthCellWidget
448 /* constructors useful for gtk-- wrappers */
449 void eth_clist_construct (EthCList *clist,
453 /* create a new EthCList */
454 GtkWidget* eth_clist_new (gint columns);
455 GtkWidget* eth_clist_new_with_titles (gint columns,
458 /* set adjustments of clist */
459 void eth_clist_set_hadjustment (EthCList *clist,
460 GtkAdjustment *adjustment);
461 void eth_clist_set_vadjustment (EthCList *clist,
462 GtkAdjustment *adjustment);
464 /* get adjustments of clist */
465 GtkAdjustment* eth_clist_get_hadjustment (EthCList *clist);
466 GtkAdjustment* eth_clist_get_vadjustment (EthCList *clist);
468 /* set the border style of the clist */
469 void eth_clist_set_shadow_type (EthCList *clist,
472 /* set the clist's selection mode */
473 void eth_clist_set_selection_mode (EthCList *clist,
474 GtkSelectionMode mode);
476 /* enable clists reorder ability */
477 void eth_clist_set_reorderable (EthCList *clist,
478 gboolean reorderable);
479 void eth_clist_set_use_drag_icons (EthCList *clist,
481 void eth_clist_set_button_actions (EthCList *clist,
483 guint8 button_actions);
485 /* freeze all visual updates of the list, and then thaw the list after
486 * you have made a number of changes and the updates wil occure in a
487 * more efficent mannor than if you made them on a unfrozen list
489 void eth_clist_freeze (EthCList *clist);
490 void eth_clist_thaw (EthCList *clist);
492 /* show and hide the column title buttons */
493 void eth_clist_column_titles_show (EthCList *clist);
494 void eth_clist_column_titles_hide (EthCList *clist);
496 /* set the column title to be a active title (responds to button presses,
497 * prelights, and grabs keyboard focus), or passive where it acts as just
500 void eth_clist_column_title_active (EthCList *clist,
502 void eth_clist_column_title_passive (EthCList *clist,
504 void eth_clist_column_titles_active (EthCList *clist);
505 void eth_clist_column_titles_passive (EthCList *clist);
507 /* set the title in the column title button */
508 void eth_clist_set_column_title (EthCList *clist,
512 /* returns the title of column. Returns NULL if title is not set */
513 gchar * eth_clist_get_column_title (EthCList *clist,
516 /* set a widget instead of a title for the column title button */
517 void eth_clist_set_column_widget (EthCList *clist,
521 /* returns the column widget */
522 GtkWidget * eth_clist_get_column_widget (EthCList *clist,
525 /* set the justification on a column */
526 void eth_clist_set_column_justification (EthCList *clist,
528 GtkJustification justification);
530 /* set visibility of a column */
531 void eth_clist_set_column_visibility (EthCList *clist,
535 /* enable/disable column resize operations by mouse */
536 void eth_clist_set_column_resizeable (EthCList *clist,
538 gboolean resizeable);
540 /* resize column automatically to its optimal width */
541 void eth_clist_set_column_auto_resize (EthCList *clist,
543 gboolean auto_resize);
545 gint eth_clist_columns_autosize (EthCList *clist);
547 /* return the optimal column width, i.e. maximum of all cell widths */
548 gint eth_clist_optimal_column_width (EthCList *clist,
551 /* set the pixel width of a column; this is a necessary step in
552 * creating a CList because otherwise the column width is chozen from
553 * the width of the column title, which will never be right
555 void eth_clist_set_column_width (EthCList *clist,
559 /* set column minimum/maximum width. min/max_width < 0 => no restriction */
560 void eth_clist_set_column_min_width (EthCList *clist,
563 void eth_clist_set_column_max_width (EthCList *clist,
567 /* change the height of the rows, the default (height=0) is
568 * the hight of the current font.
570 void eth_clist_set_row_height (EthCList *clist,
573 /* scroll the viewing area of the list to the given column and row;
574 * row_align and col_align are between 0-1 representing the location the
575 * row should appear on the screnn, 0.0 being top or left, 1.0 being
576 * bottom or right; if row or column is -1 then then there is no change
578 void eth_clist_moveto (EthCList *clist,
584 /* returns whether the row is visible */
585 GtkVisibility eth_clist_row_is_visible (EthCList *clist,
588 /* returns the cell type */
589 EthCellType eth_clist_get_cell_type (EthCList *clist,
593 /* sets a given cell's text, replacing its current contents */
594 void eth_clist_set_text (EthCList *clist,
599 /* for the "get" functions, any of the return pointer can be
600 * NULL if you are not interested
602 gint eth_clist_get_text (EthCList *clist,
607 /* sets a given cell's pixmap, replacing its current contents */
608 void eth_clist_set_pixmap (EthCList *clist,
614 gint eth_clist_get_pixmap (EthCList *clist,
620 /* sets a given cell's pixmap and text, replacing its current contents */
621 void eth_clist_set_pixtext (EthCList *clist,
629 gint eth_clist_get_pixtext (EthCList *clist,
637 /* sets the foreground color of a row, the color must already
640 void eth_clist_set_foreground (EthCList *clist,
644 /* sets the background color of a row, the color must already
647 void eth_clist_set_background (EthCList *clist,
651 /* set / get cell styles */
652 void eth_clist_set_cell_style (EthCList *clist,
657 GtkStyle *eth_clist_get_cell_style (EthCList *clist,
661 void eth_clist_set_row_style (EthCList *clist,
665 GtkStyle *eth_clist_get_row_style (EthCList *clist,
668 /* this sets a horizontal and vertical shift for drawing
669 * the contents of a cell; it can be positive or negitive;
670 * this is particulary useful for indenting items in a column
672 void eth_clist_set_shift (EthCList *clist,
678 /* set/get selectable flag of a single row */
679 void eth_clist_set_selectable (EthCList *clist,
681 gboolean selectable);
682 gboolean eth_clist_get_selectable (EthCList *clist,
685 /* prepend/append returns the index of the row you just added,
686 * making it easier to append and modify a row
688 gint eth_clist_prepend (EthCList *clist,
690 gint eth_clist_append (EthCList *clist,
693 /* inserts a row at index row and returns the row where it was
694 * actually inserted (may be different from "row" in auto_sort mode)
696 gint eth_clist_insert (EthCList *clist,
700 /* removes row at index row */
701 void eth_clist_remove (EthCList *clist,
704 /* sets a arbitrary data pointer for a given row */
705 void eth_clist_set_row_data (EthCList *clist,
709 /* sets a data pointer for a given row with destroy notification */
710 void eth_clist_set_row_data_full (EthCList *clist,
713 GtkDestroyNotify destroy);
715 /* returns the data set for a row */
716 gpointer eth_clist_get_row_data (EthCList *clist,
719 /* givin a data pointer, find the first (and hopefully only!)
720 * row that points to that data, or -1 if none do
722 gint eth_clist_find_row_from_data (EthCList *clist,
725 /* force selection of a row */
726 void eth_clist_select_row (EthCList *clist,
730 /* force unselection of a row */
731 void eth_clist_unselect_row (EthCList *clist,
735 /* undo the last select/unselect operation */
736 void eth_clist_undo_selection (EthCList *clist);
738 /* clear the entire list -- this is much faster than removing
739 * each item with eth_clist_remove
741 void eth_clist_clear (EthCList *clist);
743 /* return the row column corresponding to the x and y coordinates,
744 * the returned values are only valid if the x and y coordinates
745 * are respectively to a window == clist->clist_window
747 gint eth_clist_get_selection_info (EthCList *clist,
753 /* in multiple or extended mode, select all rows */
754 void eth_clist_select_all (EthCList *clist);
756 /* in all modes except browse mode, deselect all rows */
757 void eth_clist_unselect_all (EthCList *clist);
759 /* swap the position of two rows */
760 void eth_clist_swap_rows (EthCList *clist,
764 /* move row from source_row position to dest_row position */
765 void eth_clist_row_move (EthCList *clist,
769 /* sets a compare function different to the default */
770 void eth_clist_set_compare_func (EthCList *clist,
771 EthCListCompareFunc cmp_func);
773 /* the column to sort by */
774 void eth_clist_set_sort_column (EthCList *clist,
777 /* how to sort : ascending or descending */
778 void eth_clist_set_sort_type (EthCList *clist,
779 GtkSortType sort_type);
781 /* sort the list with the current compare function */
782 void eth_clist_sort (EthCList *clist);
784 /* Automatically sort upon insertion */
785 void eth_clist_set_auto_sort (EthCList *clist,
791 #endif /* __cplusplus */
793 #endif /* __ETH_CLIST_H__ */