1 /* make and manage windows ... subclass off this for dialog boxes
2  */
3 
4 /*
5 
6     Copyright (C) 1991-2003 The National Gallery
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 
22  */
23 
24 /*
25 
26     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27 
28 */
29 
30 #ifndef IWINDOW_H
31 #define IWINDOW_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 
37 #define TYPE_IWINDOW (iwindow_get_type())
38 #define IWINDOW( obj ) (GTK_CHECK_CAST( (obj), TYPE_IWINDOW, iWindow ))
39 #define IWINDOW_CLASS( klass ) \
40 	(GTK_CHECK_CLASS_CAST( (klass), TYPE_IWINDOW, iWindowClass ))
41 #define IS_IWINDOW( obj ) (GTK_CHECK_TYPE( (obj), TYPE_IWINDOW ))
42 #define IS_IWINDOW_CLASS( klass ) \
43 	(GTK_CHECK_CLASS_TYPE( (klass), TYPE_IWINDOW ))
44 #define IWINDOW_GET_CLASS( obj ) \
45 	(GTK_CHECK_GET_CLASS( (obj), TYPE_IWINDOW, iWindowClass ))
46 
47 typedef struct _iWindow iWindow;
48 
49 /* Our cursor shapes.
50  */
51 typedef enum _iWindowShape {
52 	/* Tool shapes.
53 	 */
54 	IWINDOW_SHAPE_DROPPER = 0,
55 	IWINDOW_SHAPE_PEN,
56 	IWINDOW_SHAPE_SMUDGE,
57 	IWINDOW_SHAPE_SMEAR,
58 	IWINDOW_SHAPE_TEXT,
59 	IWINDOW_SHAPE_RECT,
60 	IWINDOW_SHAPE_FLOOD,
61 	IWINDOW_SHAPE_MOVE,
62 	IWINDOW_SHAPE_EDIT,
63 	IWINDOW_SHAPE_MAGIN,
64 	IWINDOW_SHAPE_MAGOUT,
65 
66 	/* Resize shapes.
67 	 */
68 	IWINDOW_SHAPE_TOP,
69 	IWINDOW_SHAPE_BOTTOM,
70 	IWINDOW_SHAPE_LEFT,
71 	IWINDOW_SHAPE_RIGHT,
72 	IWINDOW_SHAPE_TOPRIGHT,
73 	IWINDOW_SHAPE_TOPLEFT,
74 	IWINDOW_SHAPE_BOTTOMRIGHT,
75 	IWINDOW_SHAPE_BOTTOMLEFT,
76 
77 	/* Watch positions.
78 	 */
79 	IWINDOW_SHAPE_HGLASS1,
80 	IWINDOW_SHAPE_HGLASS2,
81 	IWINDOW_SHAPE_HGLASS3,
82 	IWINDOW_SHAPE_HGLASS4,
83 	IWINDOW_SHAPE_HGLASS5,
84 	IWINDOW_SHAPE_HGLASS6,
85 	IWINDOW_SHAPE_HGLASS7,
86 	IWINDOW_SHAPE_HGLASS8,
87 
88 	/* No shape set (shape we inherit).
89 	 */
90 	IWINDOW_SHAPE_NONE,
91 
92 	IWINDOW_SHAPE_LAST
93 } iWindowShape;
94 
95 /* Keep a set of these, one for each of the clients who might want to set the
96  * shape for a window.
97  */
98 typedef struct {
99 	iWindow *iwnd;
100 	int priority;			/* Higher priority == more on top */
101 	const char *name;		/* For debugging */
102 
103 	/* Shape currently requested by this user.
104 	 */
105 	iWindowShape shape;
106 } iWindowCursorContext;
107 
108 /* The result from a window/dialog/whatever ... not just a bool.
109  */
110 typedef enum iwindow_result {
111 	IWINDOW_ERROR = 0,		/* Tried but failed */
112 	IWINDOW_YES,			/* User tried the action */
113 	IWINDOW_NO			/* User cancelled */
114 } iWindowResult;
115 
116 /* Our callbacks don't return iWindowResult, instead
117  * they are given a notify function (plus an environment parameter) which
118  * they use to inform their caller of their iWindowResult.
119  */
120 typedef void (*iWindowNotifyFn)( void *, iWindowResult );
121 
122 /* What our callbacks look like.
123  */
124 typedef void (*iWindowFn)( iWindow *, void *, iWindowNotifyFn, void * );
125 
126 /* Build function for window contents.
127  */
128 typedef void (*iWindowBuildFn)( iWindow *,
129 	GtkWidget *, void *, void *, void * );
130 
131 /* A suspension ... an iWindowFn plus a set of args we are saving for later.
132  */
133 typedef struct {
134 	iWindowFn fn;
135 	iWindow *iwnd;
136 	void *client;
137 	iWindowNotifyFn nfn;
138 	void *sys;
139 } iWindowSusp;
140 
141 #define IWINDOW_SUSP( X ) ((iWindowSusp *) (X))
142 
143 struct _iWindow {
144 	GtkWindow parent_object;
145 
146 	/* Parent window. Used for (eg.) image displays windows which we need
147 	 * to float over the main workspace.
148 	 */
149 	GtkWidget *parent;		/* Our parent widget */
150 	iWindow *parent_window;		/* Our parent window */
151 	guint parent_unmap_sid; 	/* Watch parent death here */
152 
153 	GtkWidget *work;
154 	GtkAccelGroup *accel_group;
155 	Infobar *infobar;
156 
157 	char *title;
158 
159 	/* Action stuff. We init this and add a few common actions to help out
160 	 * subclasses.
161 	 */
162 	GtkActionGroup *action_group;
163 	GtkUIManager *ui_manager;
164 
165 	/* Per instance build function.
166 	 */
167 	iWindowBuildFn build;
168 	void *build_a, *build_b, *build_c;
169 
170 	/* Called before cancellable popdown ... _TRUE from this will
171 	 * destroy window, _FALSE won't, _ERROR won't and pops an error box.
172 	 */
173 	iWindowFn popdown;
174 	void *popdown_a;
175 
176 	/* Notify handling.
177 	 */
178 	gboolean destroy;		/* True if being destroyed */
179 	int pending;			/* Number of notifies waiting on */
180 
181 	/* Cursor handling.
182 	 */
183 	iWindowShape shape;		/* Global shape ... for hglass */
184 	GSList *contexts;		/* Set of other requested shapes */
185 	GdkWindow *work_window;		/* The window we actually set */
186 
187 	/* Size memorization.
188 	 */
189 	const char *width_pref;		/* Prefs we save width/height in */
190 	const char *height_pref;
191 };
192 
193 typedef struct _iWindowClass {
194 	GtkWindowClass parent_class;
195 
196 	/* Per class build/popdown functions.
197 	 */
198 	void (*build)( GtkWidget * );
199 	void (*popdown)( GtkWidget * );
200 
201 	/* Whether windows of this class should be marked as transient for
202 	 * their parents (eg. dialogs usually are).
203 	 */
204 	gboolean transient;
205 } iWindowClass;
206 
207 int iwindow_number( void );
208 iWindow *iwindow_pick_one( void );
209 typedef void (*iWindowMapFn)( iWindow *, void * );
210 void *iwindow_map_all( iWindowMapFn fn, void *a );
211 
212 iWindowCursorContext *iwindow_cursor_context_new( iWindow *,
213 	int, const char * );
214 void iwindow_cursor_context_set_cursor( iWindowCursorContext *, iWindowShape );
215 void iwindow_cursor_context_destroy( iWindowCursorContext *cntxt );
216 
217 iWindowSusp *iwindow_susp_new( iWindowFn,
218 	iWindow *, void *, iWindowNotifyFn, void * );
219 void iwindow_susp_trigger( iWindowSusp * );
220 void iwindow_susp_return( void *, iWindowResult );
221 void iwindow_susp_comp( void *, iWindowResult );
222 
223 void iwindow_notify_send( iWindow *iwnd,
224 	iWindowFn fn, void *client, iWindowNotifyFn back, void *sys );
225 void iwindow_notify_return( iWindow *iwnd );
226 
227 void iwindow_true_cb( iWindow *, void *, iWindowNotifyFn nfn, void *sys );
228 void iwindow_false_cb( iWindow *, void *, iWindowNotifyFn nfn, void *sys );
229 void iwindow_notify_null( void *client, iWindowResult result );
230 
231 GtkType iwindow_get_type( void );
232 
233 GtkWidget *iwindow_new( GtkWindowType );
234 void iwindow_set_title( iWindow *, const char *, ... )
235 	__attribute__((format(printf, 2, 3)));
236 void iwindow_set_build( iWindow *, iWindowBuildFn, void *, void *, void * );
237 void iwindow_set_popdown( iWindow *, iWindowFn, void * );
238 void iwindow_set_size_prefs( iWindow *, const char *, const char * );
239 void iwindow_set_work_window( iWindow *iwnd, GdkWindow *work_window );
240 void iwindow_set_parent( iWindow *, GtkWidget *par );
241 
242 void iwindow_build( iWindow * );
243 void *iwindow_kill( iWindow * );
244 void iwindow_kill_action_cb( GtkAction *action, iWindow *iwnd );
245 
246 GtkWidget *iwindow_get_root( GtkWidget *widget );
247 GtkWidget *iwindow_get_root_noparent( GtkWidget *widget );
248 void iwindow_alert( GtkWidget *parent, GtkMessageType type );
249 
250 #ifdef __cplusplus
251 }
252 #endif /* __cplusplus */
253 
254 #endif /* IWINDOW_H */
255