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