1 /*
2  * ROX-Filer, filer for the ROX desktop project
3  * By Thomas Leonard, <tal197@users.sourceforge.net>.
4  */
5 
6 #ifndef __VIEW_IFACE_H__
7 #define __VIEW_IFACE_H__
8 
9 #define AUTOSCROLL_STEP 20
10 
11 #include <glib-object.h>
12 #include <gdk/gdk.h>
13 
14 typedef enum {
15 	/* iter->next moves to selected items only */
16 	VIEW_ITER_SELECTED	= 1 << 0,
17 
18 	/* iteration starts from cursor (first call to next() returns
19 	 * iter AFTER cursor). If there is no cursor, flag is ignored
20 	 * (will iterate over everything).
21 	 */
22 	VIEW_ITER_FROM_CURSOR	= 1 << 1,
23 
24 	/* next() moves backwards */
25 	VIEW_ITER_BACKWARDS	= 1 << 2,
26 
27 	/* next() always returns NULL and has no effect */
28 	VIEW_ITER_ONE_ONLY	= 1 << 3,
29 
30 	/* Like FROM_CURSOR, but using the base position. The base is set
31 	 * from the cursor position when the path minibuffer is opened.
32 	 */
33 	VIEW_ITER_FROM_BASE	= 1 << 4,
34 } IterFlags;
35 
36 typedef struct _ViewIfaceClass	ViewIfaceClass;
37 
38 /* A viewport containing a Collection which also handles redraw.
39  * This is the Collection-based implementation of the View interface.
40  */
41 typedef struct _ViewCollection ViewCollection;
42 
43 struct _ViewIter {
44 	/* Returns the value last returned by next() */
45 	DirItem	   *(*peek)(ViewIter *iter);
46 
47 	DirItem	   *(*next)(ViewIter *iter);
48 
49 	/* private fields */
50 	ViewIface   *view;
51 	int	   i, n_remaining;
52 	int	   flags;
53 };
54 
55 struct _ViewIfaceClass {
56 	GTypeInterface base_iface;
57 
58 	void (*sort)(ViewIface *obj);
59 	void (*style_changed)(ViewIface *obj, int flags);
60 	void (*add_items)(ViewIface *obj, GPtrArray *items);
61 	void (*update_items)(ViewIface *obj, GPtrArray *items);
62 	void (*delete_if)(ViewIface *obj,
63 			gboolean (*test)(gpointer item, gpointer data),
64 			gpointer data);
65 	void (*clear)(ViewIface *obj);
66 	void (*select_all)(ViewIface *obj);
67 	void (*clear_selection)(ViewIface *obj);
68 	int (*count_items)(ViewIface *obj);
69 	int (*count_selected)(ViewIface *obj);
70 	void (*show_cursor)(ViewIface *obj);
71 
72 	void (*get_iter)(ViewIface *obj, ViewIter *iter, IterFlags flags);
73 	void (*get_iter_at_point)(ViewIface *obj, ViewIter *iter,
74 				  GdkWindow *src, int x, int y);
75 	void (*cursor_to_iter)(ViewIface *obj, ViewIter *iter);
76 
77 	void (*set_selected)(ViewIface *obj, ViewIter *iter, gboolean selected);
78 	gboolean (*get_selected)(ViewIface *obj, ViewIter *iter);
79 	void (*set_frozen)(ViewIface *obj, gboolean frozen);
80 	void (*select_only)(ViewIface *obj, ViewIter *iter);
81 	void (*wink_item)(ViewIface *obj, ViewIter *iter);
82 	void (*autosize)(ViewIface *obj);
83 	gboolean (*cursor_visible)(ViewIface *obj);
84 	void (*set_base)(ViewIface *obj, ViewIter *iter);
85 	void (*start_lasso_box)(ViewIface *obj, GdkEventButton *event);
86 	void (*extend_tip)(ViewIface *obj, ViewIter *iter, GString *tip);
87 	gboolean (*auto_scroll_callback)(ViewIface *obj);
88 };
89 
90 #define VIEW_TYPE_IFACE           (view_iface_get_type())
91 
92 #define VIEW(obj)		  (G_TYPE_CHECK_INSTANCE_CAST((obj), \
93 				   VIEW_TYPE_IFACE, ViewIface))
94 
95 #define VIEW_IS_IFACE(obj)	  (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
96 				   VIEW_TYPE_IFACE))
97 
98 #define VIEW_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), \
99 				   VIEW_TYPE_IFACE, ViewIfaceClass))
100 
101 /* Flags for view_style_changed() */
102 enum {
103 	VIEW_UPDATE_VIEWDATA	= 1 << 0,
104 	VIEW_UPDATE_NAME	= 1 << 1,
105 	VIEW_UPDATE_HEADERS	= 1 << 2,
106 };
107 
108 GType view_iface_get_type(void);
109 void view_sort(ViewIface *obj);
110 void view_style_changed(ViewIface *obj, int flags);
111 gboolean view_autoselect(ViewIface *obj, const gchar *leaf);
112 void view_add_items(ViewIface *obj, GPtrArray *items);
113 void view_update_items(ViewIface *obj, GPtrArray *items);
114 void view_delete_if(ViewIface *obj,
115 		    gboolean (*test)(gpointer item, gpointer data),
116 		    gpointer data);
117 void view_clear(ViewIface *obj);
118 void view_select_all(ViewIface *obj);
119 void view_clear_selection(ViewIface *obj);
120 int view_count_items(ViewIface *obj);
121 int view_count_selected(ViewIface *obj);
122 void view_show_cursor(ViewIface *obj);
123 
124 void view_get_iter(ViewIface *obj, ViewIter *iter, IterFlags flags);
125 void view_get_iter_at_point(ViewIface *obj, ViewIter *iter,
126 			    GdkWindow *src, int x, int y);
127 void view_get_cursor(ViewIface *obj, ViewIter *iter);
128 void view_cursor_to_iter(ViewIface *obj, ViewIter *iter);
129 
130 void view_set_selected(ViewIface *obj, ViewIter *iter, gboolean selected);
131 gboolean view_get_selected(ViewIface *obj, ViewIter *iter);
132 void view_select_only(ViewIface *obj, ViewIter *iter);
133 void view_freeze(ViewIface *obj);
134 void view_thaw(ViewIface *obj);
135 void view_select_if(ViewIface *obj,
136 		    gboolean (*test)(ViewIter *iter, gpointer data),
137 		    gpointer data);
138 
139 void view_wink_item(ViewIface *obj, ViewIter *iter);
140 void view_autosize(ViewIface *obj);
141 gboolean view_cursor_visible(ViewIface *obj);
142 void view_set_base(ViewIface *obj, ViewIter *iter);
143 void view_start_lasso_box(ViewIface *obj, GdkEventButton *event);
144 void view_extend_tip(ViewIface *obj, ViewIter *iter, GString *tip);
145 gboolean view_auto_scroll_callback(ViewIface *obj);
146 
147 #endif /* __VIEW_IFACE_H__ */
148