Broad front of work in progress:
[xiph/unicode.git] / sushivision / internal.h
blob1144c5bb68aa3e0ba8057f41c87c79ca541b13e2
1 /*
3 * sushivision copyright (C) 2006-2007 Monty <monty@xiph.org>
5 * sushivision is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * sushivision 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with sushivision; see the file COPYING. If not, write to the
17 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 typedef struct _sv_undo _sv_undo_t;
24 #include <time.h>
25 #include <signal.h>
26 #include <pthread.h>
27 #include <gtk/gtk.h>
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include "sushivision.h"
32 /* locking *****************************************************/
34 // strict mutex acquisation ordering:
35 // gdk -> panel -> objective -> dimension -> scale
36 // functions below check/enforce
38 extern void _sv_gdk_lock_i(const char *func, int line);
39 extern void _sv_gdk_unlock_i(const char *func, int line);
40 extern void _sv_panel_lock_i(const char *func, int line);
41 extern void _sv_panel_unlock_i(const char *func, int line);
42 extern void _sv_objective_lock_i(const char *func, int line);
43 extern void _sv_objective_unlock_i(const char *func, int line);
44 extern void _sv_dimension_lock_i(const char *func, int line);
45 extern void _sv_dimension_unlock_i(const char *func, int line);
46 extern void _sv_scale_lock_i(const char *func, int line);
47 extern void _sv_scale_unlock_i(const char *func, int line);
49 #define gdk_lock() _sv_gdk_lock_i(__FUNCTION__,__LINE__);
50 #define gdk_unlock() _sv_gdk_lock_i(__FUNCTION__,__LINE__);
52 #define panel_lock() _sv_panel_lock_i(__FUNCTION__,__LINE__);
53 #define panel_unlock() _sv_panel_lock_i(__FUNCTION__,__LINE__);
55 #define obj_lock() _sv_objective_lock_i(__FUNCTION__,__LINE__);
56 #define obj_unlock() _sv_objective_lock_i(__FUNCTION__,__LINE__);
58 #define dim_lock() _sv_dimension_lock_i(__FUNCTION__,__LINE__);
59 #define dim_unlock() _sv_dimension_lock_i(__FUNCTION__,__LINE__);
61 #define scale_lock() _sv_scale_lock_i(__FUNCTION__,__LINE__);
62 #define scale_unlock() _sv_scale_lock_i(__FUNCTION__,__LINE__);
64 typedef struct {
65 char *s;
66 double v;
67 } _sv_tokenval;
69 typedef struct {
70 char *name;
71 char *label;
73 int n;
74 _sv_tokenval **values;
75 } _sv_token;
77 typedef struct {
78 int n;
79 _sv_token **list;
80 } _sv_tokenlist;
82 /* tokenization and API argument parsing *****************************/
84 // name string
85 // labelname name[:string]
86 // displayvalue number[:string]
87 // flag string
88 // parameter {flag|string=number}
89 // parameterlist paramentry[, paramentry[...]]
90 // valuelist displayvalue[, displayvalue[...]]
91 // declparam label(parameterlist)
92 // nameparam name(parameterlist)
93 // namelist nameparam[, nameparam[...]]
95 extern char *_sv_tokenize_string(char *in);
96 extern _sv_tokenval *_sv_tokenize_number(char *in);
97 extern _sv_token *_sv_tokenize_name(char *in);
98 extern _sv_token *_sv_tokenize_labelname(char *in);
99 extern _sv_tokenval *_sv_tokenize_displayvalue(char *in);
100 extern _sv_tokenval *_sv_tokenize_flag(char *in);
101 extern _sv_tokenval *_sv_tokenize_parameter(char *in);
102 extern _sv_token *_sv_tokenize_parameterlist(char *in);
103 extern _sv_token *_sv_tokenize_valuelist(char *in);
104 extern _sv_token *_sv_tokenize_nameparam(char *in);
105 extern _sv_token *_sv_tokenize_declparam(char *in);
106 extern _sv_tokenlist *_sv_tokenize_namelist(char *in);
107 extern _sv_tokenlist *_sv_tokenize_noparamlist(char *in);
108 extern void _sv_tokenval_free(_sv_tokenval *t);
109 extern void _sv_token_free(_sv_token *t);
110 extern void _sv_tokenlist_free(_sv_tokenlist *l);
111 extern char *_sv_tokenize_escape(char *a);
114 /* used to glue numeric settings to semantic labels for menus/save files **/
115 typedef struct _sv_propmap _sv_propmap_t;
116 struct _sv_propmap {
117 char *left;
118 int value;
120 char *right;
121 _sv_propmap_t **submenu;
122 void (*callback)(sv_panel_t *, GtkWidget *);
125 #include "mapping.h"
126 #include "slice.h"
127 #include "spinner.h"
128 #include "slider.h"
129 #include "scale.h"
130 #include "plot.h"
131 #include "dimension.h"
132 #include "objective.h"
133 #include "panel-1d.h"
134 #include "panel-xy.h"
135 #include "panel-2d.h"
136 #include "xml.h"
137 #include "gtksucks.h"
139 union _sv_panel_subtype {
140 _sv_panelxy_t *xy;
141 _sv_panel1d_t *p1;
142 _sv_panel2d_t *p2;
145 // undo history; the panel types vary slightly, but only slightly, so
146 // for now we use a master undo type which leaves one or two fields
147 // unused for a given panel.
148 typedef struct {
149 int *mappings;
150 double *scale_vals[3];
152 int x_d;
153 int y_d;
155 double box[4];
156 int box_active;
158 int grid_mode;
159 int cross_mode;
160 int legend_mode;
161 int bg_mode;
162 int text_mode;
163 int menu_cursamp;
164 int oversample_n;
165 int oversample_d;
167 } _sv_panel_undo_t;
169 typedef union {
170 _sv_bythread_cache_1d_t p1;
171 _sv_bythread_cache_xy_t xy;
172 _sv_bythread_cache_2d_t p2;
173 } _sv_bythread_cache_t;
175 struct _sv_panel_internal {
176 GtkWidget *toplevel;
177 GtkWidget *topbox;
178 GtkWidget *plotbox;
179 GtkWidget *graph;
180 _sv_spinner_t *spinner;
181 GtkWidget *popmenu;
183 sv_dim_t *x_d;
184 sv_dim_t *y_d;
186 enum sv_background bg_type;
187 _sv_dim_widget_t **dim_scales;
188 int oldbox_active;
190 int realized;
192 int map_active;
193 int map_progress_count;
194 int map_complete_count;
195 int map_serialno;
197 int legend_active;
198 int legend_progress_count;
199 int legend_complete_count;
200 int legend_serialno;
202 int plot_active;
203 int plot_progress_count;
204 int plot_complete_count;
205 int plot_serialno;
207 time_t last_map_throttle;
209 int menu_cursamp;
210 int oversample_n;
211 int oversample_d;
212 int def_oversample_n;
213 int def_oversample_d;
215 int (*callback_precompute)(sv_panel_t *,void*);
216 void *callback_precompute_data;
218 // function bundles
219 void (*realize)(sv_panel_t *p);
220 int (*map_action)(sv_panel_t *p, _sv_bythread_cache_t *c);
221 int (*legend_action)(sv_panel_t *p);
222 int (*compute_action)(sv_panel_t *p, _sv_bythread_cache_t *c);
223 void (*request_compute)(sv_panel_t *p);
224 void (*crosshair_action)(sv_panel_t *p);
225 void (*print_action)(sv_panel_t *p, cairo_t *c, int w, int h);
226 int (*save_action)(sv_panel_t *p, xmlNodePtr pn);
227 int (*load_action)(sv_panel_t *p, _sv_panel_undo_t *u, xmlNodePtr pn, int warn);
229 void (*undo_log)(_sv_panel_undo_t *u, sv_panel_t *p);
230 void (*undo_restore)(_sv_panel_undo_t *u, sv_panel_t *p);
233 struct _sv_undo {
234 _sv_panel_undo_t *panels;
235 double *dim_vals[3];
238 extern void _sv_clean_exit(void);
239 extern void _sv_wake_workers(void);
240 extern int _sv_main_save(void);
241 extern int _sv_main_load(void);
242 extern void _sv_first_load_warning(int *);
245 extern sv_panel_t *_sv_panel_new(int number,
246 char *name,
247 char *objectivelist,
248 char *dimensionlist,
249 unsigned flags);
250 extern void _sv_panel_realize(sv_panel_t *p);
251 extern void _sv_panel_dirty_map(sv_panel_t *p);
252 extern void _sv_panel_dirty_map_throttled(sv_panel_t *p);
253 extern void _sv_panel_dirty_legend(sv_panel_t *p);
254 extern void _sv_panel_dirty_plot(sv_panel_t *p);
255 extern void _sv_panel_recompute(sv_panel_t *p);
256 extern void _sv_panel_clean_map(sv_panel_t *p);
257 extern void _sv_panel_clean_legend(sv_panel_t *p);
258 extern void _sv_panel_clean_plot(sv_panel_t *p);
259 extern void _sv_panel_undo_log(sv_panel_t *p, _sv_panel_undo_t *u);
260 extern void _sv_panel_undo_restore(sv_panel_t *p, _sv_panel_undo_t *u);
261 extern void _sv_panel_update_menus(sv_panel_t *p);
262 extern int _sv_panel_save(sv_panel_t *p, xmlNodePtr n);
263 extern int _sv_panel_load(sv_panel_t *p, _sv_panel_undo_t *u, xmlNodePtr n, int warn);
266 extern void _sv_map_set_throttle_time(sv_panel_t *p);
268 extern void _sv_undo_log();
269 extern void _sv_undo_push();
270 extern void _sv_undo_pop();
271 extern void _sv_undo_suspend();
272 extern void _sv_undo_resume();
273 extern void _sv_undo_restore();
274 extern void _sv_undo_up();
275 extern void _sv_undo_down();
277 extern sv_scale_t *_sv_scale_new_v(char *legend, char *first, char *second, va_list ap);
279 extern sig_atomic_t _sv_exiting;
280 extern char *_sv_filebase;
281 extern char *_sv_filename;
282 extern char *_sv_dirname;
283 extern char *_sv_cwdname;
285 extern int _sv_dimensions;
286 extern sv_dim_t **_sv_dimension_list;
287 extern int _sv_objectives;
288 extern sv_obj_t **_sv_objective_list;
289 extern int _sv_panels;
290 extern sv_panel_t **_sv_panel_list;
291 extern int _sv_undo_level;
292 extern int _sv_undo_suspended;
293 extern _sv_undo_t **_sv_undo_stack;
295 extern pthread_key_t _sv_dim_key;
296 extern pthread_key_t _sv_obj_key;
298 extern sv_obj_t *_sv_obj(char *name);
299 extern sv_dim_t *_sv_dim(char *name);