r1576: Improved iterator interface.
[rox-filer.git] / ROX-Filer / src / view_iface.c
blob6a2187835219aef97f336e39e86b94936fc5793d
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* view_iface.c - operations supported by all views */
24 #include "config.h"
26 #include "global.h"
28 #include "view_iface.h"
30 /* A word about interfaces:
32 * gobject's documentation's explanation of interfaces leaves something[1] to
33 * be desired, so I'd better explain here...
35 * [1] Like, eg, an explanation.
37 * A ViewIfaceClass is a struct which contains a number of function
38 * pointers. Each class that implements the View interface creates its
39 * own ViewIfaceClass with pointers to its implementation. This is stored
40 * with the class.
42 * When you want to call a method (eg, sort()) on a View, you call
43 * view_sort(object) here, which gets the class of object and then looks
44 * for that class's implementation of the View interface, and then calls
45 * the actual function through that.
48 /****************************************************************
49 * EXTERNAL INTERFACE *
50 ****************************************************************/
52 GType view_iface_get_type(void)
54 static GType iface_type = 0;
56 if (!iface_type)
58 static const GTypeInfo iface_info =
60 sizeof (ViewIfaceClass),
61 NULL, /* base_init */
62 NULL, /* base_finalize */
65 iface_type = g_type_register_static(G_TYPE_INTERFACE,
66 "ViewIface", &iface_info, 0);
68 /* Actually, all Views should be GTK_TYPE_WIDGETs, to be more
69 * accurate, but including gtk.h takes so long, and noone's
70 * going to get this wrong ;-)
72 g_type_interface_add_prerequisite(iface_type, G_TYPE_OBJECT);
75 return iface_type;
78 /* The sort function has changed -- resort */
79 void view_sort(ViewIface *obj)
81 g_return_if_fail(VIEW_IS_IFACE(obj));
82 VIEW_IFACE_GET_CLASS(obj)->sort(obj);
85 /* The style has changed -- shrink the grid and redraw.
86 * Also update ViewData (and name layout too) if appropriate
87 * flags are set.
89 void view_style_changed(ViewIface *obj, int flags)
91 g_return_if_fail(VIEW_IS_IFACE(obj));
92 VIEW_IFACE_GET_CLASS(obj)->style_changed(obj, flags);
95 /* Wink or move the cursor to this item, if present. Return TRUE on
96 * success (iff leaf was present).
98 gboolean view_autoselect(ViewIface *obj, const gchar *leaf)
100 g_return_val_if_fail(VIEW_IS_IFACE(obj), FALSE);
101 g_return_val_if_fail(leaf != NULL, FALSE);
103 return VIEW_IFACE_GET_CLASS(obj)->autoselect(obj, leaf);
106 /* Scanning has turned up some new items... */
107 void view_add_items(ViewIface *obj, GPtrArray *items)
109 VIEW_IFACE_GET_CLASS(obj)->add_items(obj, items);
112 /* These items are already known, but have changed... */
113 void view_update_items(ViewIface *obj, GPtrArray *items)
115 VIEW_IFACE_GET_CLASS(obj)->update_items(obj, items);
118 /* Call test(item) for each item in the view and delete all those for
119 * which it returns TRUE.
121 void view_delete_if(ViewIface *obj,
122 gboolean (*test)(gpointer item, gpointer data),
123 gpointer data)
125 g_return_if_fail(VIEW_IS_IFACE(obj));
127 VIEW_IFACE_GET_CLASS(obj)->delete_if(obj, test, data);
130 /* Remove all items from the view (used when changing directory) */
131 void view_clear(ViewIface *obj)
133 g_return_if_fail(VIEW_IS_IFACE(obj));
135 VIEW_IFACE_GET_CLASS(obj)->clear(obj);
138 /* Unselect all items */
139 void view_clear_selection(ViewIface *obj)
141 g_return_if_fail(VIEW_IS_IFACE(obj));
143 VIEW_IFACE_GET_CLASS(obj)->clear_selection(obj);
146 /* Return the total number of items */
147 int view_count_items(ViewIface *obj)
149 g_return_val_if_fail(VIEW_IS_IFACE(obj), 0);
151 return VIEW_IFACE_GET_CLASS(obj)->count_items(obj);
154 /* Return the number of selected items */
155 int view_count_selected(ViewIface *obj)
157 g_return_val_if_fail(VIEW_IS_IFACE(obj), 0);
159 return VIEW_IFACE_GET_CLASS(obj)->count_selected(obj);
162 void view_show_cursor(ViewIface *obj)
164 g_return_if_fail(VIEW_IS_IFACE(obj));
166 VIEW_IFACE_GET_CLASS(obj)->show_cursor(obj);
169 /* Create an iterator which will return each element selected by 'type'
170 * from successive calls to iter.next(&iter). NULL indicates the end
171 * of the sequence.
173 * The iterator does not need to be freed. It becomes invalid if the
174 * view is changed in any way.
176 void view_get_iter(ViewIface *obj, ViewIter *iter, int flags)
178 g_return_if_fail(VIEW_IS_IFACE(obj));
180 iter->flags = flags;
182 VIEW_IFACE_GET_CLASS(obj)->get_iter(obj, iter);
185 /* Position cursor on the last item returned by iter.next() */
186 void view_cursor_to_iter(ViewIface *obj, ViewIter *iter)
188 g_return_if_fail(VIEW_IS_IFACE(obj));
190 VIEW_IFACE_GET_CLASS(obj)->cursor_to_iter(obj, iter);