]> git.street.me.uk Git - andy/viking.git/blob - src/uibuilder.h
Rework layer set parameters so it should be more easily extendable.
[andy/viking.git] / src / uibuilder.h
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  */
21 #ifndef _VIKING_UIBUILDER_H
22 #define _VIKING_UIBUILDER_H
23
24 #include <gtk/gtk.h>
25 #include "vik_compat.h"
26 #include "config.h"
27
28 G_BEGIN_DECLS
29
30 /* Parameters (for I/O and Properties) */
31
32 typedef union {
33   gdouble d;
34   guint32 u;
35   gint32 i;
36   gboolean b;
37   const gchar *s;
38   GdkColor c;
39   GList *sl;
40   gpointer ptr; // For internal usage - don't save this value in a file!
41 } VikLayerParamData;
42
43 typedef struct {
44   guint16             id;
45   VikLayerParamData   data;
46   gpointer            vp; // AKA VikViewport*
47   gboolean            is_file_operation; // denotes if for file I/O, as opposed to display/cut/copy etc... operations
48 } VikLayerSetParam;
49
50 typedef enum {
51   VIK_LAYER_WIDGET_CHECKBUTTON=0,
52   VIK_LAYER_WIDGET_RADIOGROUP,
53   VIK_LAYER_WIDGET_RADIOGROUP_STATIC,
54   VIK_LAYER_WIDGET_SPINBUTTON,
55   VIK_LAYER_WIDGET_ENTRY,
56   VIK_LAYER_WIDGET_PASSWORD,
57   VIK_LAYER_WIDGET_FILEENTRY,
58   VIK_LAYER_WIDGET_FOLDERENTRY,
59   VIK_LAYER_WIDGET_HSCALE,
60   VIK_LAYER_WIDGET_COLOR,
61   VIK_LAYER_WIDGET_COMBOBOX,
62   VIK_LAYER_WIDGET_FILELIST,
63   VIK_LAYER_WIDGET_BUTTON,
64 } VikLayerWidgetType;
65
66 /* id is index */
67 typedef enum {
68 VIK_LAYER_PARAM_DOUBLE=1,
69 VIK_LAYER_PARAM_UINT,
70 VIK_LAYER_PARAM_INT,
71
72 /* in my_layer_set_param, if you want to use the string, you should dup it
73  * in my_layer_get_param, the string returned will NOT be free'd, you are responsible for managing it (I think) */
74 VIK_LAYER_PARAM_STRING,
75 VIK_LAYER_PARAM_BOOLEAN,
76 VIK_LAYER_PARAM_COLOR,
77
78 /* NOTE: string list works uniquely: data.sl should NOT be free'd when
79  * the internals call get_param -- i.e. it should be managed w/in the layer.
80  * The value passed by the internals into set_param should also be managed
81  * by the layer -- i.e. free'd by the layer.
82  */
83
84 VIK_LAYER_PARAM_STRING_LIST,
85 VIK_LAYER_PARAM_PTR, // Not really a 'parameter' but useful to route to extended configuration (e.g. toolbar order)
86 } VikLayerParamType;
87
88 typedef enum {
89   VIK_LAYER_AGGREGATE = 0,
90   VIK_LAYER_TRW,
91   VIK_LAYER_COORD,
92   VIK_LAYER_GEOREF,
93   VIK_LAYER_GPS,
94   VIK_LAYER_MAPS,
95   VIK_LAYER_DEM,
96 #ifdef HAVE_LIBMAPNIK
97   VIK_LAYER_MAPNIK,
98 #endif
99   VIK_LAYER_NUM_TYPES // Also use this value to indicate no layer association
100 } VikLayerTypeEnum;
101
102 // Default value has to be returned via a function
103 //  because certain types value are can not be statically allocated
104 //  (i.e. a string value that is dependent on other functions)
105 // Also easier for colours to be set via a function call rather than a static assignment
106 typedef VikLayerParamData (*VikLayerDefaultFunc) ( void );
107
108 // Convert between the value held internally and the value used for display
109 //  e.g. keep the internal value in seconds yet use days in the display
110 typedef VikLayerParamData (*VikLayerConvertFunc) ( VikLayerParamData );
111
112 typedef struct {
113   VikLayerTypeEnum layer;
114   const gchar *name;
115   VikLayerParamType type;
116   gint16 group;
117   const gchar *title;
118   VikLayerWidgetType widget_type;
119   gpointer widget_data;
120   gpointer extra_widget_data;
121   const gchar *tooltip;
122   VikLayerDefaultFunc default_value;
123   VikLayerConvertFunc convert_to_display;
124   VikLayerConvertFunc convert_to_internal;
125 } VikLayerParam;
126
127 enum {
128 VIK_LAYER_NOT_IN_PROPERTIES=-2,
129 VIK_LAYER_GROUP_NONE=-1
130 };
131
132 typedef struct {
133   gdouble min;
134   gdouble max;
135   gdouble step;
136   guint8 digits;
137 } VikLayerParamScale;
138
139
140   /* Annoyingly 'C' cannot initialize unions properly */
141   /* It's dependent on the standard used or the compiler support... */
142 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__
143 #define VIK_LPD_BOOLEAN(X)     (VikLayerParamData) { .b = (X) }
144 #define VIK_LPD_INT(X)         (VikLayerParamData) { .u = (X) }
145 #define VIK_LPD_UINT(X)        (VikLayerParamData) { .i = (X) }
146 #define VIK_LPD_COLOR(X,Y,Z,A) (VikLayerParamData) { .c = (GdkColor){ (X), (Y), (Z), (A) } }
147 #define VIK_LPD_DOUBLE(X)      (VikLayerParamData) { .d = (X) }
148 #else
149 #define VIK_LPD_BOOLEAN(X)     (VikLayerParamData) { (X) }
150 #define VIK_LPD_INT(X)         (VikLayerParamData) { (X) }
151 #define VIK_LPD_UINT(X)        (VikLayerParamData) { (X) }
152 #define VIK_LPD_COLOR(X,Y,Z,A) (VikLayerParamData) { (X), (Y), (Z), (A) }
153 #define VIK_LPD_DOUBLE(X)      (VikLayerParamData) { (X) }
154 #endif
155
156 VikLayerParamData vik_lpd_true_default ( void );
157 VikLayerParamData vik_lpd_false_default ( void );
158
159 typedef enum {
160   UI_CHG_LAYER = 0,
161   UI_CHG_PARAM,
162   UI_CHG_PARAM_ID,
163   UI_CHG_WIDGETS,
164   UI_CHG_LABELS,
165   UI_CHG_LAST
166 } ui_change_index;
167
168 typedef gpointer ui_change_values[UI_CHG_LAST];
169
170 GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data );
171 VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerParam *param );
172 gint a_uibuilder_properties_factory ( const gchar *dialog_name,
173                                       GtkWindow *parent,
174                                       VikLayerParam *params,
175                                       guint16 params_count,
176                                       gchar **groups,
177                                       guint8 groups_count,
178                                       gboolean (*setparam) (gpointer,gpointer), // AKA VikLayerFuncSetParam in viklayer.h
179                                       gboolean (*setparam4) (gpointer,guint16,VikLayerParamData,gpointer), // Fixed 4 Parameter version
180                                       gpointer pass_along1, // Possibly VikLayer* or own type for 4 param call used as first parameter
181                                       gpointer pass_along2, // Possibly VikViewport* or own type for 4 param call used as last parameter
182                                       VikLayerParamData (*getparam) (gpointer,guint16,gboolean),  // AKA VikLayerFuncGetParam in viklayer.h
183                                       gpointer pass_along_getparam,
184                                       void (*changeparam) (GtkWidget*, ui_change_values) ); // AKA VikLayerFuncChangeParam in viklayer.h
185
186 VikLayerParamData *a_uibuilder_run_dialog ( const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params,
187                         guint16 params_count, gchar **groups, guint8 groups_count,
188                         VikLayerParamData *params_defaults );
189
190 /* frees data from last (if ness) */
191 void a_uibuilder_free_paramdatas ( VikLayerParamData *paramdatas, VikLayerParam *params, guint16 params_count );
192
193 typedef enum {
194   VL_SO_NONE = 0,
195   VL_SO_ALPHABETICAL_ASCENDING,
196   VL_SO_ALPHABETICAL_DESCENDING,
197   VL_SO_DATE_ASCENDING,
198   VL_SO_DATE_DESCENDING,
199   VL_SO_LAST
200 } vik_layer_sort_order_t;
201
202 G_END_DECLS
203
204 #endif