]>
Commit | Line | Data |
---|---|---|
50a14534 EB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2005, 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 | */ | |
a25c4c50 GB |
21 | #ifndef _VIKING_LAYER_H |
22 | #define _VIKING_LAYER_H | |
23 | ||
e4afc73a | 24 | #include <stdio.h> |
a25c4c50 GB |
25 | #include <glib.h> |
26 | #include <gtk/gtk.h> | |
27 | #include <gdk-pixbuf/gdk-pixdata.h> | |
50a14534 | 28 | |
cdcaf41c | 29 | #include "vikwindow.h" |
a25c4c50 GB |
30 | #include "viktreeview.h" |
31 | #include "vikviewport.h" | |
50a14534 EB |
32 | |
33 | #define VIK_LAYER_TYPE (vik_layer_get_type ()) | |
34 | #define VIK_LAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_LAYER_TYPE, VikLayer)) | |
35 | #define VIK_LAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIK_LAYER_TYPE, VikLayerClass)) | |
36 | #define IS_VIK_LAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIK_LAYER_TYPE)) | |
37 | #define IS_VIK_LAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIK_LAYER_TYPE)) | |
38 | ||
369e959a | 39 | typedef struct _VikLayer VikLayer; |
50a14534 EB |
40 | typedef struct _VikLayerClass VikLayerClass; |
41 | ||
42 | struct _VikLayerClass | |
43 | { | |
44 | GObjectClass object_class; | |
45 | void (* update) (VikLayer *vl); | |
46 | }; | |
47 | ||
48 | GType vik_layer_get_type (); | |
49 | ||
50 | struct _VikLayer { | |
51 | GObject obj; | |
52 | gchar *name; | |
53 | gboolean visible; | |
54 | ||
55 | gboolean realized; | |
94933cb8 | 56 | VikTreeview *vt; /* simply a reference */ |
50a14534 EB |
57 | GtkTreeIter iter; |
58 | ||
59 | /* for explicit "polymorphism" (function type switching) */ | |
60 | guint16 type; | |
61 | }; | |
62 | ||
63 | ||
64 | ||
65 | enum { | |
941aa6e9 AF |
66 | VIK_LAYER_AGGREGATE = 0, |
67 | VIK_LAYER_TRW, | |
68 | VIK_LAYER_COORD, | |
69 | VIK_LAYER_GEOREF, | |
b364d6bc | 70 | VIK_LAYER_GPS, |
941aa6e9 | 71 | VIK_LAYER_MAPS, |
ad0a8c2d | 72 | VIK_LAYER_DEM, |
941aa6e9 | 73 | VIK_LAYER_NUM_TYPES |
50a14534 EB |
74 | }; |
75 | ||
941aa6e9 AF |
76 | typedef enum { |
77 | VIK_LAYER_TOOL_IGNORED=0, | |
78 | VIK_LAYER_TOOL_ACK, | |
79 | VIK_LAYER_TOOL_ACK_REDRAW_ABOVE, | |
80 | VIK_LAYER_TOOL_ACK_REDRAW_ALL, | |
81 | VIK_LAYER_TOOL_ACK_REDRAW_IF_VISIBLE | |
82 | } VikLayerToolFuncStatus; | |
50a14534 | 83 | |
941aa6e9 AF |
84 | /* gpointer is tool-specific state created in the constructor */ |
85 | typedef gpointer (*VikToolConstructorFunc) (VikWindow *, VikViewport *); | |
86 | typedef void (*VikToolDestructorFunc) (gpointer); | |
87 | typedef VikLayerToolFuncStatus (*VikToolMouseFunc) (VikLayer *, GdkEventButton *, gpointer); | |
88 | typedef void (*VikToolActivationFunc) (VikLayer *, gpointer); | |
50a14534 EB |
89 | |
90 | typedef struct _VikToolInterface VikToolInterface; | |
91 | struct _VikToolInterface { | |
92 | gchar *name; | |
941aa6e9 AF |
93 | VikToolConstructorFunc create; |
94 | VikToolDestructorFunc destroy; | |
95 | VikToolActivationFunc activate; | |
96 | VikToolActivationFunc deactivate; | |
97 | VikToolMouseFunc click; | |
98 | VikToolMouseFunc move; | |
99 | VikToolMouseFunc release; | |
50a14534 EB |
100 | }; |
101 | ||
102 | /* Parameters (for I/O and Properties) */ | |
103 | ||
104 | typedef union { | |
105 | gdouble d; | |
106 | guint32 u; | |
107 | gint32 i; | |
108 | gboolean b; | |
109 | const gchar *s; | |
110 | GdkColor c; | |
ad0a8c2d | 111 | GList *sl; |
50a14534 EB |
112 | } VikLayerParamData; |
113 | ||
114 | typedef struct { | |
115 | const gchar *name; | |
116 | guint8 type; | |
117 | gint16 group; | |
118 | const gchar *title; | |
119 | guint8 widget_type; | |
cdcaf41c QT |
120 | gpointer widget_data; |
121 | gpointer extra_widget_data; | |
50a14534 EB |
122 | } VikLayerParam; |
123 | ||
124 | enum { | |
125 | VIK_LAYER_NOT_IN_PROPERTIES=-2, | |
126 | VIK_LAYER_GROUP_NONE=-1 | |
127 | }; | |
128 | ||
129 | enum { | |
130 | VIK_LAYER_WIDGET_CHECKBUTTON=0, | |
131 | VIK_LAYER_WIDGET_RADIOGROUP, | |
8c721f83 | 132 | VIK_LAYER_WIDGET_RADIOGROUP_STATIC, |
50a14534 EB |
133 | VIK_LAYER_WIDGET_SPINBUTTON, |
134 | VIK_LAYER_WIDGET_ENTRY, | |
135 | VIK_LAYER_WIDGET_FILEENTRY, | |
136 | VIK_LAYER_WIDGET_HSCALE, | |
137 | VIK_LAYER_WIDGET_COLOR, | |
138 | VIK_LAYER_WIDGET_COMBOBOX, | |
ad0a8c2d | 139 | VIK_LAYER_WIDGET_FILELIST, |
50a14534 EB |
140 | }; |
141 | ||
142 | typedef struct { | |
143 | gdouble min; | |
144 | gdouble max; | |
145 | gdouble step; | |
146 | guint8 digits; | |
147 | } VikLayerParamScale; | |
148 | ||
149 | /* id is index */ | |
150 | enum { | |
151 | VIK_LAYER_PARAM_DOUBLE=1, | |
152 | VIK_LAYER_PARAM_UINT, | |
153 | VIK_LAYER_PARAM_INT, | |
154 | VIK_LAYER_PARAM_STRING, | |
155 | VIK_LAYER_PARAM_BOOLEAN, | |
156 | VIK_LAYER_PARAM_COLOR, | |
ad0a8c2d EB |
157 | |
158 | /* NOTE: string layer works auniquely: data.sl should NOT be free'd when | |
159 | * the internals call get_param -- i.e. it should be managed w/in the layer. | |
160 | * The value passed by the internals into set_param should also be managed | |
161 | * by the layer -- i.e. free'd by the layer. | |
162 | */ | |
163 | ||
164 | VIK_LAYER_PARAM_STRING_LIST, | |
50a14534 EB |
165 | }; |
166 | ||
167 | /* layer interface functions */ | |
168 | ||
169 | /* Create a new layer of a certain type. Should be filled with defaults */ | |
170 | typedef VikLayer * (*VikLayerFuncCreate) (VikViewport *); | |
171 | ||
172 | /* normally only needed for layers with sublayers. This is called when they | |
173 | * are added to the treeview so they can add sublayers to the treeview. */ | |
174 | typedef void (*VikLayerFuncRealize) (VikLayer *,VikTreeview *,GtkTreeIter *); | |
175 | ||
176 | /* rarely used, this is called after a read operation or properties box is run. | |
177 | * usually used to create GC's that depend on params, | |
178 | * but GC's can also be created from create() or set_param() */ | |
07059501 | 179 | typedef void (*VikLayerFuncPostRead) (VikLayer *,VikViewport *vp,gboolean from_file); |
50a14534 EB |
180 | |
181 | typedef void (*VikLayerFuncFree) (VikLayer *); | |
182 | ||
183 | /* do _not_ use this unless absolutely neccesary. Use the dynamic properties (see coordlayer for example) | |
184 | * returns TRUE if OK was pressed */ | |
07059501 | 185 | typedef gboolean (*VikLayerFuncProperties) (VikLayer *,VikViewport *); |
50a14534 EB |
186 | |
187 | typedef void (*VikLayerFuncDraw) (VikLayer *,VikViewport *); | |
188 | typedef void (*VikLayerFuncChangeCoordMode) (VikLayer *,VikCoordMode); | |
189 | ||
20c7a3a0 QT |
190 | typedef void (*VikLayerFuncSetMenuItemsSelection) (VikLayer *,guint16); |
191 | typedef guint16 (*VikLayerFuncGetMenuItemsSelection) (VikLayer *); | |
50a14534 EB |
192 | typedef void (*VikLayerFuncAddMenuItems) (VikLayer *,GtkMenu *,gpointer); /* gpointer is a VikLayersPanel */ |
193 | typedef gboolean (*VikLayerFuncSublayerAddMenuItems) (VikLayer *,GtkMenu *,gpointer, /* first gpointer is a VikLayersPanel */ | |
194 | gint,gpointer,GtkTreeIter *); | |
195 | typedef const gchar * (*VikLayerFuncSublayerRenameRequest) (VikLayer *,const gchar *,gpointer, | |
196 | gint,VikViewport *,GtkTreeIter *); /* first gpointer is a VikLayersPanel */ | |
197 | typedef gboolean (*VikLayerFuncSublayerToggleVisible) (VikLayer *,gint,gpointer); | |
198 | ||
911400b5 AF |
199 | typedef void (*VikLayerFuncMarshall) (VikLayer *, guint8 **, gint *); |
200 | typedef VikLayer * (*VikLayerFuncUnmarshall) (guint8 *, gint, VikViewport *); | |
50a14534 EB |
201 | |
202 | /* returns TRUE if needs to redraw due to changed param */ | |
203 | typedef gboolean (*VikLayerFuncSetParam) (VikLayer *, guint16, VikLayerParamData, VikViewport *); | |
204 | ||
205 | typedef VikLayerParamData | |
206 | (*VikLayerFuncGetParam) (VikLayer *, guint16); | |
207 | ||
208 | typedef void (*VikLayerFuncReadFileData) (VikLayer *, FILE *); | |
209 | typedef void (*VikLayerFuncWriteFileData) (VikLayer *, FILE *); | |
210 | ||
33534cd8 AF |
211 | /* item manipulation */ |
212 | typedef void (*VikLayerFuncDeleteItem) (VikLayer *, gint, gpointer); | |
213 | /* layer, subtype, pointer to sub-item */ | |
ddc47a46 | 214 | typedef void (*VikLayerFuncCopyItem) (VikLayer *, gint, gpointer, guint8 **, guint *); |
33534cd8 | 215 | /* layer, subtype, pointer to sub-item, return pointer, return len */ |
ddc47a46 | 216 | typedef gboolean (*VikLayerFuncPasteItem) (VikLayer *, gint, guint8 *, guint); |
50a14534 EB |
217 | typedef void (*VikLayerFuncFreeCopiedItem) (gint, gpointer); |
218 | ||
70a23263 AF |
219 | /* treeview drag and drop method. called on the destination layer. it is given a source and destination layer, |
220 | * and the source and destination iters in the treeview. | |
221 | */ | |
222 | typedef void (*VikLayerFuncDragDropRequest) (VikLayer *, VikLayer *, GtkTreeIter *, GtkTreePath *); | |
223 | ||
5a4a28bf QT |
224 | typedef enum { |
225 | VIK_MENU_ITEM_PROPERTY=1, | |
226 | VIK_MENU_ITEM_CUT=2, | |
227 | VIK_MENU_ITEM_COPY=4, | |
228 | VIK_MENU_ITEM_PASTE=8, | |
229 | VIK_MENU_ITEM_DELETE=16, | |
230 | VIK_MENU_ITEM_ALL=0xff | |
231 | } VikStdLayerMenuItem; | |
50a14534 EB |
232 | |
233 | typedef struct _VikLayerInterface VikLayerInterface; | |
234 | ||
235 | /* See vik_layer_* for function parameter names */ | |
236 | struct _VikLayerInterface { | |
237 | const gchar * name; | |
238 | const GdkPixdata * icon; | |
239 | ||
240 | VikToolInterface * tools; | |
241 | guint16 tools_count; | |
242 | ||
243 | /* for I/O reading to and from .vik files -- params like coordline width, color, etc. */ | |
244 | VikLayerParam * params; | |
245 | guint16 params_count; | |
246 | gchar ** params_groups; | |
247 | guint8 params_groups_count; | |
248 | ||
5a4a28bf QT |
249 | /* menu items to be created */ |
250 | VikStdLayerMenuItem menu_items_selection; | |
251 | ||
50a14534 EB |
252 | VikLayerFuncCreate create; |
253 | VikLayerFuncRealize realize; | |
254 | VikLayerFuncPostRead post_read; | |
255 | VikLayerFuncFree free; | |
256 | ||
257 | VikLayerFuncProperties properties; | |
258 | VikLayerFuncDraw draw; | |
259 | VikLayerFuncChangeCoordMode change_coord_mode; | |
260 | ||
20c7a3a0 QT |
261 | VikLayerFuncSetMenuItemsSelection set_menu_selection; |
262 | VikLayerFuncGetMenuItemsSelection get_menu_selection; | |
263 | ||
50a14534 EB |
264 | VikLayerFuncAddMenuItems add_menu_items; |
265 | VikLayerFuncSublayerAddMenuItems sublayer_add_menu_items; | |
266 | VikLayerFuncSublayerRenameRequest sublayer_rename_request; | |
267 | VikLayerFuncSublayerToggleVisible sublayer_toggle_visible; | |
268 | ||
911400b5 AF |
269 | VikLayerFuncMarshall marshall; |
270 | VikLayerFuncUnmarshall unmarshall; | |
50a14534 EB |
271 | |
272 | /* for I/O */ | |
273 | VikLayerFuncSetParam set_param; | |
274 | VikLayerFuncGetParam get_param; | |
275 | ||
276 | /* for I/O -- extra non-param data like TrwLayer data */ | |
277 | VikLayerFuncReadFileData read_file_data; | |
278 | VikLayerFuncWriteFileData write_file_data; | |
279 | ||
33534cd8 | 280 | VikLayerFuncDeleteItem delete_item; |
50a14534 EB |
281 | VikLayerFuncCopyItem copy_item; |
282 | VikLayerFuncPasteItem paste_item; | |
283 | VikLayerFuncFreeCopiedItem free_copied_item; | |
70a23263 AF |
284 | |
285 | VikLayerFuncDragDropRequest drag_drop_request; | |
50a14534 EB |
286 | }; |
287 | ||
288 | VikLayerInterface *vik_layer_get_interface ( gint type ); | |
289 | ||
290 | ||
291 | void vik_layer_init ( VikLayer *vl, gint type ); | |
292 | void vik_layer_draw ( VikLayer *l, gpointer data ); | |
293 | void vik_layer_change_coord_mode ( VikLayer *l, VikCoordMode mode ); | |
294 | void vik_layer_rename ( VikLayer *l, const gchar *new_name ); | |
295 | void vik_layer_rename_no_copy ( VikLayer *l, gchar *new_name ); | |
92558066 | 296 | const gchar *vik_layer_get_name ( VikLayer *l ); |
50a14534 EB |
297 | |
298 | gboolean vik_layer_set_param (VikLayer *layer, guint16 id, VikLayerParamData data, gpointer vp); | |
299 | ||
300 | void vik_layer_emit_update ( VikLayer *vl ); | |
301 | ||
302 | /* GUI */ | |
20c7a3a0 QT |
303 | void vik_layer_set_menu_items_selection(VikLayer *l, guint16 selection); |
304 | guint16 vik_layer_get_menu_items_selection(VikLayer *l); | |
50a14534 EB |
305 | void vik_layer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp ); |
306 | VikLayer *vik_layer_create ( gint type, gpointer vp, GtkWindow *w, gboolean interactive ); | |
307 | gboolean vik_layer_properties ( VikLayer *layer, gpointer vp ); | |
308 | ||
309 | void vik_layer_realize ( VikLayer *l, VikTreeview *vt, GtkTreeIter * layer_iter ); | |
07059501 | 310 | void vik_layer_post_read ( VikLayer *layer, VikViewport *vp, gboolean from_file ); |
50a14534 EB |
311 | |
312 | gboolean vik_layer_sublayer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter ); | |
313 | ||
314 | VikLayer *vik_layer_copy ( VikLayer *vl, gpointer vp ); | |
911400b5 AF |
315 | void vik_layer_marshall ( VikLayer *vl, guint8 **data, gint *len ); |
316 | VikLayer *vik_layer_unmarshall ( guint8 *data, gint len, VikViewport *vvp ); | |
317 | void vik_layer_marshall_params ( VikLayer *vl, guint8 **data, gint *len ); | |
318 | void vik_layer_unmarshall_params ( VikLayer *vl, guint8 *data, gint len, VikViewport *vvp ); | |
50a14534 EB |
319 | |
320 | const gchar *vik_layer_sublayer_rename_request ( VikLayer *l, const gchar *newname, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter ); | |
321 | ||
322 | gboolean vik_layer_sublayer_toggle_visible ( VikLayer *l, gint subtype, gpointer sublayer ); | |
323 | ||
324 | /* TODO: put in layerspanel */ | |
325 | GdkPixbuf *vik_layer_load_icon ( gint type ); | |
326 | ||
0df66d57 EB |
327 | VikLayer *vik_layer_get_and_reset_trigger(); |
328 | void vik_layer_emit_update_secondary ( VikLayer *vl ); /* to be called by aggregate layer only. doesn't set the trigger */ | |
329 | void vik_layer_emit_update_although_invisible ( VikLayer *vl ); | |
330 | ||
50a14534 | 331 | #endif |