]> git.street.me.uk Git - andy/viking.git/blame - src/uibuilder.c
Read OSM Metatile capability and basic test with single example metatile.
[andy/viking.git] / src / uibuilder.c
CommitLineData
f33aa4e0
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
d9d1084e
GB
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
f33aa4e0 25#include <gtk/gtk.h>
d9d1084e 26#include <glib/gi18n.h>
f33aa4e0
EB
27#include "uibuilder.h"
28#include "vikradiogroup.h"
29#include "vikfileentry.h"
30#include "vikfilelist.h"
31
a7023a1b
RN
32VikLayerParamData vik_lpd_true_default ( void ) { return VIK_LPD_BOOLEAN ( TRUE ); }
33VikLayerParamData vik_lpd_false_default ( void ) { return VIK_LPD_BOOLEAN ( FALSE ); }
34
f33aa4e0
EB
35GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data )
36{
a87f8fa1
RN
37 // Perform pre conversion if necessary
38 VikLayerParamData vlpd = data;
39 if ( param->convert_to_display )
40 vlpd = param->convert_to_display ( data );
41
f33aa4e0
EB
42 GtkWidget *rv = NULL;
43 switch ( param->widget_type )
44 {
45 case VIK_LAYER_WIDGET_COLOR:
46 if ( param->type == VIK_LAYER_PARAM_COLOR )
a87f8fa1 47 rv = gtk_color_button_new_with_color ( &(vlpd.c) );
f33aa4e0
EB
48 break;
49 case VIK_LAYER_WIDGET_CHECKBUTTON:
50 if ( param->type == VIK_LAYER_PARAM_BOOLEAN )
51 {
52 //rv = gtk_check_button_new_with_label ( //param->title );
53 rv = gtk_check_button_new ();
a87f8fa1 54 if ( vlpd.b )
f33aa4e0
EB
55 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(rv), TRUE );
56 }
57 break;
58 case VIK_LAYER_WIDGET_COMBOBOX:
f33aa4e0
EB
59 if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
60 {
77a62382 61 /* Build a simple combobox */
f33aa4e0 62 gchar **pstr = param->widget_data;
1bc1c05b 63 rv = vik_combo_box_text_new ();
f33aa4e0 64 while ( *pstr )
1bc1c05b 65 vik_combo_box_text_append ( rv, *(pstr++) );
f33aa4e0
EB
66 if ( param->extra_widget_data ) /* map of alternate uint values for options */
67 {
77a62382 68 /* Set the effective default value */
f33aa4e0
EB
69 int i;
70 for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
a87f8fa1 71 if ( ((guint *)param->extra_widget_data)[i] == vlpd.u )
f33aa4e0 72 {
77a62382 73 /* Match default value */
f33aa4e0
EB
74 gtk_combo_box_set_active ( GTK_COMBO_BOX(rv), i );
75 break;
76 }
77 }
a8876892 78 else
a87f8fa1 79 gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), vlpd.u );
f33aa4e0 80 }
77a62382 81 else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && !param->extra_widget_data )
ce37ab9b 82 {
77a62382 83 /* Build a combobox with editable text */
ce37ab9b 84 gchar **pstr = param->widget_data;
1bc1c05b
RN
85#if GTK_CHECK_VERSION (2, 24, 0)
86 rv = gtk_combo_box_text_new_with_entry ();
87#else
88 rv = gtk_combo_box_entry_new_text ();
89#endif
a87f8fa1
RN
90 if ( vlpd.s )
91 vik_combo_box_text_append ( rv, vlpd.s );
ce37ab9b 92 while ( *pstr )
1bc1c05b 93 vik_combo_box_text_append ( rv, *(pstr++) );
a87f8fa1 94 if ( vlpd.s )
ce37ab9b
GB
95 gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
96 }
77a62382
GB
97 else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && param->extra_widget_data)
98 {
99 /* Build a combobox with fixed selections without editable text */
100 gchar **pstr = param->widget_data;
101 rv = GTK_WIDGET ( vik_combo_box_text_new () );
102 while ( *pstr )
103 vik_combo_box_text_append ( rv, *(pstr++) );
a87f8fa1 104 if ( vlpd.s )
77a62382
GB
105 {
106 /* Set the effective default value */
107 /* In case of value does not exist, set the first value */
108 gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
109 int i;
110 for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
a87f8fa1 111 if ( strcmp(((const char **)param->extra_widget_data)[i], vlpd.s) == 0 )
77a62382
GB
112 {
113 /* Match default value */
114 gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), i );
115 break;
116 }
117 }
118 else
119 gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
120 }
f33aa4e0 121 break;
f33aa4e0
EB
122 case VIK_LAYER_WIDGET_RADIOGROUP:
123 /* widget_data and extra_widget_data are GList */
124 if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
125 {
126 rv = vik_radio_group_new ( param->widget_data );
127 if ( param->extra_widget_data ) /* map of alternate uint values for options */
128 {
129 int i;
a8876892 130 int nb_elem = g_list_length(param->widget_data);
f33aa4e0 131 for ( i = 0; i < nb_elem; i++ )
a87f8fa1 132 if ( GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, i) ) == vlpd.u )
f33aa4e0
EB
133 {
134 vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i );
135 break;
136 }
137 }
a87f8fa1
RN
138 else if ( vlpd.u ) /* zero is already default */
139 vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), vlpd.u );
f33aa4e0
EB
140 }
141 break;
142 case VIK_LAYER_WIDGET_RADIOGROUP_STATIC:
143 if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
144 {
145 rv = vik_radio_group_new_static ( (const gchar **) param->widget_data );
146 if ( param->extra_widget_data ) /* map of alternate uint values for options */
147 {
148 int i;
149 for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
a87f8fa1 150 if ( ((guint *)param->extra_widget_data)[i] == vlpd.u )
f33aa4e0
EB
151 {
152 vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i );
153 break;
154 }
155 }
a87f8fa1
RN
156 else if ( vlpd.u ) /* zero is already default */
157 vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), vlpd.u );
f33aa4e0
EB
158 }
159 break;
160 case VIK_LAYER_WIDGET_SPINBUTTON:
161 if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT
162 || param->type == VIK_LAYER_PARAM_INT) && param->widget_data )
163 {
a87f8fa1 164 gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? vlpd.d : (param->type == VIK_LAYER_PARAM_UINT ? vlpd.u : vlpd.i);
f33aa4e0 165 VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data;
ac33062d 166 rv = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( init_val, scale->min, scale->max, scale->step, scale->step, 0 )), scale->step, scale->digits );
f33aa4e0
EB
167 }
168 break;
169 case VIK_LAYER_WIDGET_ENTRY:
170 if ( param->type == VIK_LAYER_PARAM_STRING )
171 {
172 rv = gtk_entry_new ();
a87f8fa1
RN
173 if ( vlpd.s )
174 gtk_entry_set_text ( GTK_ENTRY(rv), vlpd.s );
f33aa4e0
EB
175 }
176 break;
d9d1084e
GB
177 case VIK_LAYER_WIDGET_PASSWORD:
178 if ( param->type == VIK_LAYER_PARAM_STRING )
179 {
180 rv = gtk_entry_new ();
181 gtk_entry_set_visibility ( GTK_ENTRY(rv), FALSE );
a87f8fa1
RN
182 if ( vlpd.s )
183 gtk_entry_set_text ( GTK_ENTRY(rv), vlpd.s );
e6994d8d
RN
184 gtk_widget_set_tooltip_text ( GTK_WIDGET(rv),
185 _("Take care that this password will be stored clearly in a plain file.") );
d9d1084e
GB
186 }
187 break;
f33aa4e0
EB
188 case VIK_LAYER_WIDGET_FILEENTRY:
189 if ( param->type == VIK_LAYER_PARAM_STRING )
190 {
857baaa3 191 rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, GPOINTER_TO_INT(param->widget_data));
a87f8fa1
RN
192 if ( vlpd.s )
193 vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
f33aa4e0
EB
194 }
195 break;
79672b85
JJ
196 case VIK_LAYER_WIDGET_FOLDERENTRY:
197 if ( param->type == VIK_LAYER_PARAM_STRING )
198 {
857baaa3 199 rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, VF_FILTER_NONE);
a87f8fa1
RN
200 if ( vlpd.s )
201 vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
79672b85
JJ
202 }
203 break;
204
f33aa4e0
EB
205 case VIK_LAYER_WIDGET_FILELIST:
206 if ( param->type == VIK_LAYER_PARAM_STRING_LIST )
207 {
8a2df21a 208 rv = vik_file_list_new ( _(param->title), NULL );
a87f8fa1 209 vik_file_list_set_files ( VIK_FILE_LIST(rv), vlpd.sl );
f33aa4e0
EB
210 }
211 break;
212 case VIK_LAYER_WIDGET_HSCALE:
213 if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT
214 || param->type == VIK_LAYER_PARAM_INT) && param->widget_data )
215 {
a87f8fa1 216 gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? vlpd.d : (param->type == VIK_LAYER_PARAM_UINT ? vlpd.u : vlpd.i);
f33aa4e0
EB
217 VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data;
218 rv = gtk_hscale_new_with_range ( scale->min, scale->max, scale->step );
219 gtk_scale_set_digits ( GTK_SCALE(rv), scale->digits );
220 gtk_range_set_value ( GTK_RANGE(rv), init_val );
221 }
fc23d18f
RN
222
223 case VIK_LAYER_WIDGET_BUTTON:
224 if ( param->type == VIK_LAYER_PARAM_PTR && param->widget_data ) {
225 rv = gtk_button_new_with_label ( param->widget_data );
226 g_signal_connect ( G_OBJECT(rv), "clicked", G_CALLBACK (vlpd.ptr), param->extra_widget_data );
227 }
228 break;
229
9351abc4 230 default: break;
f33aa4e0 231 }
e6994d8d
RN
232 if ( rv && !gtk_widget_get_tooltip_text ( rv ) ) {
233 if ( param->tooltip )
234 gtk_widget_set_tooltip_text ( rv, _(param->tooltip) );
235 }
f33aa4e0
EB
236 return rv;
237}
238
239VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerParam *param )
240{
241 VikLayerParamData rv;
242 switch ( param->widget_type )
243 {
244 case VIK_LAYER_WIDGET_COLOR:
245 gtk_color_button_get_color ( GTK_COLOR_BUTTON(widget), &(rv.c) );
246 break;
247 case VIK_LAYER_WIDGET_CHECKBUTTON:
248 rv.b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
249 break;
250 case VIK_LAYER_WIDGET_COMBOBOX:
ce37ab9b
GB
251 if ( param->type == VIK_LAYER_PARAM_UINT )
252 {
253 rv.i = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) );
254 if ( rv.i == -1 ) rv.i = 0;
255 rv.u = rv.i;
256 if ( param->extra_widget_data )
257 rv.u = ((guint *)param->extra_widget_data)[rv.u];
258 }
259 if ( param->type == VIK_LAYER_PARAM_STRING)
260 {
77a62382
GB
261 if ( param->extra_widget_data )
262 {
263 /* Combobox displays labels and we want values from extra */
264 int pos = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) );
265 rv.s = ((const char **)param->extra_widget_data)[pos];
266 }
267 else
268 {
269 /* Return raw value */
1bc1c05b 270#if GTK_CHECK_VERSION (2, 24, 0)
77a62382 271 rv.s = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget))));
1bc1c05b 272#else
77a62382 273 rv.s = gtk_combo_box_get_active_text ( GTK_COMBO_BOX(widget) );
1bc1c05b 274#endif
77a62382 275 }
ce37ab9b
GB
276 g_debug("%s: %s", __FUNCTION__, rv.s);
277 }
f33aa4e0 278 break;
f33aa4e0
EB
279 case VIK_LAYER_WIDGET_RADIOGROUP:
280 case VIK_LAYER_WIDGET_RADIOGROUP_STATIC:
281 rv.u = vik_radio_group_get_selected(VIK_RADIO_GROUP(widget));
282 if ( param->extra_widget_data )
dc2c040e 283 rv.u = GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, rv.u) );
f33aa4e0
EB
284 break;
285 case VIK_LAYER_WIDGET_SPINBUTTON:
286 if ( param->type == VIK_LAYER_PARAM_UINT )
287 rv.u = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) );
288 else if ( param->type == VIK_LAYER_PARAM_INT )
289 rv.i = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) );
290 else
291 rv.d = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(widget) );
292 break;
293 case VIK_LAYER_WIDGET_ENTRY:
d9d1084e 294 case VIK_LAYER_WIDGET_PASSWORD:
f33aa4e0
EB
295 rv.s = gtk_entry_get_text ( GTK_ENTRY(widget) );
296 break;
297 case VIK_LAYER_WIDGET_FILEENTRY:
79672b85 298 case VIK_LAYER_WIDGET_FOLDERENTRY:
f33aa4e0
EB
299 rv.s = vik_file_entry_get_filename ( VIK_FILE_ENTRY(widget) );
300 break;
301 case VIK_LAYER_WIDGET_FILELIST:
302 rv.sl = vik_file_list_get_files ( VIK_FILE_LIST(widget) );
303 break;
304 case VIK_LAYER_WIDGET_HSCALE:
305 if ( param->type == VIK_LAYER_PARAM_UINT )
306 rv.u = (guint32) gtk_range_get_value ( GTK_RANGE(widget) );
307 else if ( param->type == VIK_LAYER_PARAM_INT )
308 rv.i = (gint32) gtk_range_get_value ( GTK_RANGE(widget) );
309 else
310 rv.d = gtk_range_get_value ( GTK_RANGE(widget) );
311 break;
9351abc4 312 default: break;
f33aa4e0 313 }
a87f8fa1
RN
314
315 // Perform conversion if necessary
316 if ( param->convert_to_internal )
317 rv = param->convert_to_internal ( rv );
318
f33aa4e0
EB
319 return rv;
320}
321
db43cfa4
RN
322//static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
323gint a_uibuilder_properties_factory ( const gchar *dialog_name,
324 GtkWindow *parent,
325 VikLayerParam *params,
326 guint16 params_count,
327 gchar **groups,
328 guint8 groups_count,
329 gboolean (*setparam) (gpointer,guint16,VikLayerParamData,gpointer,gboolean),
330 gpointer pass_along1,
331 gpointer pass_along2,
332 VikLayerParamData (*getparam) (gpointer,guint16,gboolean),
333 gpointer pass_along_getparam,
334 void (*changeparam) (GtkWidget*, ui_change_values) )
335 /* pass_along1 and pass_along2 are for set_param first and last params */
f33aa4e0
EB
336{
337 guint16 i, j, widget_count = 0;
338 gboolean must_redraw = FALSE;
339
340 if ( ! params )
341 return 1; /* no params == no options, so all is good */
342
343 for ( i = 0; i < params_count; i++ )
344 if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
345 widget_count++;
346
347 if ( widget_count == 0)
348 return 0; /* TODO -- should be one? */
349 else
350 {
351 /* create widgets and titles; place in table */
13fde155 352 GtkWidget *dialog = gtk_dialog_new_with_buttons ( dialog_name,
9be0449f
RN
353 parent,
354 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
355 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
356 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL );
f9d4faa9
RN
357 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
358 GtkWidget *response_w = NULL;
359#if GTK_CHECK_VERSION (2, 20, 0)
360 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
361#endif
f33aa4e0
EB
362 gint resp;
363
f33aa4e0
EB
364 GtkWidget *table = NULL;
365 GtkWidget **tables = NULL; /* for more than one group */
366
367 GtkWidget *notebook = NULL;
db43cfa4 368 GtkWidget **labels = g_malloc ( sizeof(GtkWidget *) * widget_count );
f33aa4e0 369 GtkWidget **widgets = g_malloc ( sizeof(GtkWidget *) * widget_count );
db43cfa4 370 ui_change_values *change_values = g_malloc ( sizeof(ui_change_values) * widget_count );
f33aa4e0
EB
371
372 if ( groups && groups_count > 1 )
373 {
374 guint8 current_group;
375 guint16 tab_widget_count;
376 notebook = gtk_notebook_new ();
0ae518e4
RN
377 // Switch to vertical notebook mode when many groups
378 if ( groups_count > 4 )
379 gtk_notebook_set_tab_pos ( GTK_NOTEBOOK(notebook), GTK_POS_LEFT );
9b082b39 380 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, FALSE, FALSE, 0);
f33aa4e0
EB
381 tables = g_malloc ( sizeof(GtkWidget *) * groups_count );
382 for ( current_group = 0; current_group < groups_count; current_group++ )
383 {
384 tab_widget_count = 0;
385 for ( j = 0; j < params_count; j ++ )
386 if ( params[j].group == current_group )
387 tab_widget_count++;
388
389 if ( tab_widget_count )
390 {
391 tables[current_group] = gtk_table_new ( tab_widget_count, 1, FALSE );
392 gtk_notebook_append_page ( GTK_NOTEBOOK(notebook), tables[current_group], gtk_label_new(groups[current_group]) );
393 }
394 }
395 }
396 else
397 {
398 table = gtk_table_new( widget_count, 1, FALSE );
9b082b39 399 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, FALSE, FALSE, 0);
f33aa4e0
EB
400 }
401
402 for ( i = 0, j = 0; i < params_count; i++ )
403 {
404 if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
405 {
406 if ( tables )
407 table = tables[MAX(0, params[i].group)]; /* round up NOT_IN_GROUP, that's not reasonable here */
408
158b3642 409 widgets[j] = a_uibuilder_new_widget ( &(params[i]), getparam ( pass_along_getparam, i, FALSE ) );
f33aa4e0 410
a7023a1b 411 if ( widgets[j] ) {
db43cfa4
RN
412 labels[j] = gtk_label_new(_(params[i].title));
413 gtk_table_attach ( GTK_TABLE(table), labels[j], 0, 1, j, j+1, 0, 0, 0, 0 );
a7023a1b 414 gtk_table_attach ( GTK_TABLE(table), widgets[j], 1, 2, j, j+1, GTK_EXPAND | GTK_FILL, 0, 2, 2 );
db43cfa4
RN
415
416 if ( changeparam )
417 {
418 change_values[j][UI_CHG_LAYER] = pass_along1;
419 change_values[j][UI_CHG_PARAM] = &params[i];
420 change_values[j][UI_CHG_PARAM_ID] = GINT_TO_POINTER((gint)i);
421 change_values[j][UI_CHG_WIDGETS] = widgets;
422 change_values[j][UI_CHG_LABELS] = labels;
423
424 switch ( params[i].widget_type )
425 {
426 // Change conditions for other widget types can be added when needed
427 case VIK_LAYER_WIDGET_COMBOBOX:
428 g_signal_connect ( G_OBJECT(widgets[j]), "changed", G_CALLBACK(changeparam), change_values[j] );
429 break;
430 case VIK_LAYER_WIDGET_CHECKBUTTON:
431 g_signal_connect ( G_OBJECT(widgets[j]), "toggled", G_CALLBACK(changeparam), change_values[j] );
432 break;
433 default: break;
434 }
435 }
a7023a1b 436 }
f33aa4e0
EB
437 j++;
438 }
439 }
440
db43cfa4
RN
441 // Repeat run through to force changeparam callbacks now that the widgets have been created
442 // This primarily so the widget sensitivities get set up
443 if ( changeparam ) {
444 for ( i = 0, j = 0; i < params_count; i++ ) {
445 if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES ) {
446 if ( widgets[j] ) {
447 changeparam ( widgets[j], change_values[j] );
448 }
449 j++;
450 }
451 }
452 }
453
f9d4faa9
RN
454 if ( response_w )
455 gtk_widget_grab_focus ( response_w );
456
f33aa4e0
EB
457 gtk_widget_show_all ( dialog );
458
459 resp = gtk_dialog_run (GTK_DIALOG (dialog));
460 if ( resp == GTK_RESPONSE_ACCEPT )
461 {
462 for ( i = 0, j = 0; i < params_count; i++ )
463 {
464 if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
465 {
158b3642
RN
466 if ( setparam ( pass_along1,
467 i,
468 a_uibuilder_widget_get_value ( widgets[j], &(params[i]) ),
469 pass_along2,
470 FALSE ) )
f33aa4e0
EB
471 must_redraw = TRUE;
472 j++;
473 }
474 }
475
476 gtk_widget_destroy ( dialog ); /* hide before redrawing. */
477 g_free ( widgets );
db43cfa4
RN
478 g_free ( labels );
479 g_free ( change_values );
74ace2b1
RN
480 if ( tables )
481 g_free ( tables );
f33aa4e0
EB
482
483 return must_redraw ? 2 : 3; /* user clicked OK */
484 }
485
486 if ( tables )
487 g_free ( tables );
488 gtk_widget_destroy ( dialog );
489 g_free ( widgets );
490 return 0;
491 }
492}
493
494
495static void uibuilder_run_setparam ( VikLayerParamData *paramdatas, guint16 i, VikLayerParamData data, VikLayerParam *params )
496{
497 /* could have to copy it if it's a string! */
498 switch ( params[i].type ) {
499 case VIK_LAYER_PARAM_STRING:
500 paramdatas[i].s = g_strdup ( data.s );
501 break;
502 default:
503 paramdatas[i] = data; /* string list will have to be freed by layer. anything else not freed */
504 }
505}
506
507static VikLayerParamData uibuilder_run_getparam ( VikLayerParamData *params_defaults, guint16 i )
508{
509 return params_defaults[i];
510}
511
512
13fde155 513VikLayerParamData *a_uibuilder_run_dialog ( const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params,
f33aa4e0
EB
514 guint16 params_count, gchar **groups, guint8 groups_count,
515 VikLayerParamData *params_defaults )
516{
517 VikLayerParamData *paramdatas = g_new(VikLayerParamData, params_count);
13fde155
RN
518 if ( a_uibuilder_properties_factory ( dialog_name,
519 parent,
dc2c040e
RN
520 params,
521 params_count,
522 groups,
523 groups_count,
524 (gpointer) uibuilder_run_setparam,
525 paramdatas,
526 params,
527 (gpointer) uibuilder_run_getparam,
db43cfa4
RN
528 params_defaults,
529 NULL ) > 0 ) {
f33aa4e0
EB
530
531 return paramdatas;
532 }
533 g_free ( paramdatas );
534 return NULL;
535}
536
537/* frees data from last (if ness) */
538void a_uibuilder_free_paramdatas ( VikLayerParamData *paramdatas, VikLayerParam *params, guint16 params_count )
539{
540 int i;
541 /* may have to free strings, etc. */
542 for ( i = 0; i < params_count; i++ ) {
543 switch ( params[i].type ) {
544 case VIK_LAYER_PARAM_STRING:
545 g_free ( (gchar *) paramdatas[i].s );
546 break;
547 case VIK_LAYER_PARAM_STRING_LIST: {
548 /* should make a util function out of this */
549 GList *iter = paramdatas[i].sl;
550 while ( iter ) {
551 g_free ( iter->data );
552 iter = iter->next;
553 }
554 g_list_free ( paramdatas[i].sl );
555 break;
b5926b35
RN
556 default:
557 break;
f33aa4e0
EB
558 }
559 }
560 }
561 g_free ( paramdatas );
562}