]>
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); | |
777e2d4d | 89 | typedef gboolean (*VikToolKeyFunc) (VikLayer *, GdkEventKey *, gpointer); |
50a14534 EB |
90 | |
91 | typedef struct _VikToolInterface VikToolInterface; | |
92 | struct _VikToolInterface { | |
93 | gchar *name; | |
941aa6e9 AF |
94 | VikToolConstructorFunc create; |
95 | VikToolDestructorFunc destroy; | |
96 | VikToolActivationFunc activate; | |
97 | VikToolActivationFunc deactivate; | |
98 | VikToolMouseFunc click; | |
99 | VikToolMouseFunc move; | |
100 | VikToolMouseFunc release; | |
777e2d4d | 101 | VikToolKeyFunc key_press; /* return FALSE if we don't use the key press -- should return AFLSE most of the time if we want any shortcuts / UI keybindings to work! use sparingly. */ |
bce3a7b0 | 102 | const GdkPixdata *cursor; |
50a14534 EB |
103 | }; |
104 | ||
105 | /* Parameters (for I/O and Properties) */ | |
106 | ||
107 | typedef union { | |
108 | gdouble d; | |
109 | guint32 u; | |
110 | gint32 i; | |
111 | gboolean b; | |
112 | const gchar *s; | |
113 | GdkColor c; | |
ad0a8c2d | 114 | GList *sl; |
50a14534 EB |
115 | } VikLayerParamData; |
116 | ||
117 | typedef struct { | |
118 | const gchar *name; | |
119 | guint8 type; | |
120 | gint16 group; | |
121 | const gchar *title; | |
122 | guint8 widget_type; | |
cdcaf41c QT |
123 | gpointer widget_data; |
124 | gpointer extra_widget_data; | |
50a14534 EB |
125 | } VikLayerParam; |
126 | ||
127 | enum { | |
128 | VIK_LAYER_NOT_IN_PROPERTIES=-2, | |
129 | VIK_LAYER_GROUP_NONE=-1 | |
130 | }; | |
131 | ||
132 | enum { | |
133 | VIK_LAYER_WIDGET_CHECKBUTTON=0, | |
134 | VIK_LAYER_WIDGET_RADIOGROUP, | |
8c721f83 | 135 | VIK_LAYER_WIDGET_RADIOGROUP_STATIC, |
50a14534 EB |
136 | VIK_LAYER_WIDGET_SPINBUTTON, |
137 | VIK_LAYER_WIDGET_ENTRY, | |
138 | VIK_LAYER_WIDGET_FILEENTRY, | |
139 | VIK_LAYER_WIDGET_HSCALE, | |
140 | VIK_LAYER_WIDGET_COLOR, | |
141 | VIK_LAYER_WIDGET_COMBOBOX, | |
ad0a8c2d | 142 | VIK_LAYER_WIDGET_FILELIST, |
50a14534 EB |
143 | }; |
144 | ||
145 | typedef struct { | |
146 | gdouble min; | |
147 | gdouble max; | |
148 | gdouble step; | |
149 | guint8 digits; | |
150 | } VikLayerParamScale; | |
151 | ||
152 | /* id is index */ | |
153 | enum { | |
154 | VIK_LAYER_PARAM_DOUBLE=1, | |
155 | VIK_LAYER_PARAM_UINT, | |
156 | VIK_LAYER_PARAM_INT, | |
157 | VIK_LAYER_PARAM_STRING, | |
158 | VIK_LAYER_PARAM_BOOLEAN, | |
159 | VIK_LAYER_PARAM_COLOR, | |
ad0a8c2d EB |
160 | |
161 | /* NOTE: string layer works auniquely: data.sl should NOT be free'd when | |
162 | * the internals call get_param -- i.e. it should be managed w/in the layer. | |
163 | * The value passed by the internals into set_param should also be managed | |
164 | * by the layer -- i.e. free'd by the layer. | |
165 | */ | |
166 | ||
167 | VIK_LAYER_PARAM_STRING_LIST, | |
50a14534 EB |
168 | }; |
169 | ||
170 | /* layer interface functions */ | |
171 | ||
172 | /* Create a new layer of a certain type. Should be filled with defaults */ | |
173 | typedef VikLayer * (*VikLayerFuncCreate) (VikViewport *); | |
174 | ||
175 | /* normally only needed for layers with sublayers. This is called when they | |
176 | * are added to the treeview so they can add sublayers to the treeview. */ | |
177 | typedef void (*VikLayerFuncRealize) (VikLayer *,VikTreeview *,GtkTreeIter *); | |
178 | ||
179 | /* rarely used, this is called after a read operation or properties box is run. | |
180 | * usually used to create GC's that depend on params, | |
181 | * but GC's can also be created from create() or set_param() */ | |
07059501 | 182 | typedef void (*VikLayerFuncPostRead) (VikLayer *,VikViewport *vp,gboolean from_file); |
50a14534 EB |
183 | |
184 | typedef void (*VikLayerFuncFree) (VikLayer *); | |
185 | ||
186 | /* do _not_ use this unless absolutely neccesary. Use the dynamic properties (see coordlayer for example) | |
187 | * returns TRUE if OK was pressed */ | |
07059501 | 188 | typedef gboolean (*VikLayerFuncProperties) (VikLayer *,VikViewport *); |
50a14534 EB |
189 | |
190 | typedef void (*VikLayerFuncDraw) (VikLayer *,VikViewport *); | |
191 | typedef void (*VikLayerFuncChangeCoordMode) (VikLayer *,VikCoordMode); | |
192 | ||
20c7a3a0 QT |
193 | typedef void (*VikLayerFuncSetMenuItemsSelection) (VikLayer *,guint16); |
194 | typedef guint16 (*VikLayerFuncGetMenuItemsSelection) (VikLayer *); | |
50a14534 EB |
195 | typedef void (*VikLayerFuncAddMenuItems) (VikLayer *,GtkMenu *,gpointer); /* gpointer is a VikLayersPanel */ |
196 | typedef gboolean (*VikLayerFuncSublayerAddMenuItems) (VikLayer *,GtkMenu *,gpointer, /* first gpointer is a VikLayersPanel */ | |
197 | gint,gpointer,GtkTreeIter *); | |
198 | typedef const gchar * (*VikLayerFuncSublayerRenameRequest) (VikLayer *,const gchar *,gpointer, | |
199 | gint,VikViewport *,GtkTreeIter *); /* first gpointer is a VikLayersPanel */ | |
200 | typedef gboolean (*VikLayerFuncSublayerToggleVisible) (VikLayer *,gint,gpointer); | |
201 | ||
911400b5 AF |
202 | typedef void (*VikLayerFuncMarshall) (VikLayer *, guint8 **, gint *); |
203 | typedef VikLayer * (*VikLayerFuncUnmarshall) (guint8 *, gint, VikViewport *); | |
50a14534 EB |
204 | |
205 | /* returns TRUE if needs to redraw due to changed param */ | |
206 | typedef gboolean (*VikLayerFuncSetParam) (VikLayer *, guint16, VikLayerParamData, VikViewport *); | |
207 | ||
208 | typedef VikLayerParamData | |
209 | (*VikLayerFuncGetParam) (VikLayer *, guint16); | |
210 | ||
211 | typedef void (*VikLayerFuncReadFileData) (VikLayer *, FILE *); | |
212 | typedef void (*VikLayerFuncWriteFileData) (VikLayer *, FILE *); | |
213 | ||
33534cd8 AF |
214 | /* item manipulation */ |
215 | typedef void (*VikLayerFuncDeleteItem) (VikLayer *, gint, gpointer); | |
216 | /* layer, subtype, pointer to sub-item */ | |
ddc47a46 | 217 | typedef void (*VikLayerFuncCopyItem) (VikLayer *, gint, gpointer, guint8 **, guint *); |
33534cd8 | 218 | /* layer, subtype, pointer to sub-item, return pointer, return len */ |
ddc47a46 | 219 | typedef gboolean (*VikLayerFuncPasteItem) (VikLayer *, gint, guint8 *, guint); |
50a14534 EB |
220 | typedef void (*VikLayerFuncFreeCopiedItem) (gint, gpointer); |
221 | ||
70a23263 AF |
222 | /* treeview drag and drop method. called on the destination layer. it is given a source and destination layer, |
223 | * and the source and destination iters in the treeview. | |
224 | */ | |
225 | typedef void (*VikLayerFuncDragDropRequest) (VikLayer *, VikLayer *, GtkTreeIter *, GtkTreePath *); | |
226 | ||
5a4a28bf QT |
227 | typedef enum { |
228 | VIK_MENU_ITEM_PROPERTY=1, | |
229 | VIK_MENU_ITEM_CUT=2, | |
230 | VIK_MENU_ITEM_COPY=4, | |
231 | VIK_MENU_ITEM_PASTE=8, | |
232 | VIK_MENU_ITEM_DELETE=16, | |
233 | VIK_MENU_ITEM_ALL=0xff | |
234 | } VikStdLayerMenuItem; | |
50a14534 EB |
235 | |
236 | typedef struct _VikLayerInterface VikLayerInterface; | |
237 | ||
238 | /* See vik_layer_* for function parameter names */ | |
239 | struct _VikLayerInterface { | |
240 | const gchar * name; | |
241 | const GdkPixdata * icon; | |
242 | ||
243 | VikToolInterface * tools; | |
244 | guint16 tools_count; | |
245 | ||
246 | /* for I/O reading to and from .vik files -- params like coordline width, color, etc. */ | |
247 | VikLayerParam * params; | |
248 | guint16 params_count; | |
249 | gchar ** params_groups; | |
250 | guint8 params_groups_count; | |
251 | ||
5a4a28bf QT |
252 | /* menu items to be created */ |
253 | VikStdLayerMenuItem menu_items_selection; | |
254 | ||
50a14534 EB |
255 | VikLayerFuncCreate create; |
256 | VikLayerFuncRealize realize; | |
257 | VikLayerFuncPostRead post_read; | |
258 | VikLayerFuncFree free; | |
259 | ||
260 | VikLayerFuncProperties properties; | |
261 | VikLayerFuncDraw draw; | |
262 | VikLayerFuncChangeCoordMode change_coord_mode; | |
263 | ||
20c7a3a0 QT |
264 | VikLayerFuncSetMenuItemsSelection set_menu_selection; |
265 | VikLayerFuncGetMenuItemsSelection get_menu_selection; | |
266 | ||
50a14534 EB |
267 | VikLayerFuncAddMenuItems add_menu_items; |
268 | VikLayerFuncSublayerAddMenuItems sublayer_add_menu_items; | |
269 | VikLayerFuncSublayerRenameRequest sublayer_rename_request; | |
270 | VikLayerFuncSublayerToggleVisible sublayer_toggle_visible; | |
271 | ||
911400b5 AF |
272 | VikLayerFuncMarshall marshall; |
273 | VikLayerFuncUnmarshall unmarshall; | |
50a14534 EB |
274 | |
275 | /* for I/O */ | |
276 | VikLayerFuncSetParam set_param; | |
277 | VikLayerFuncGetParam get_param; | |
278 | ||
279 | /* for I/O -- extra non-param data like TrwLayer data */ | |
280 | VikLayerFuncReadFileData read_file_data; | |
281 | VikLayerFuncWriteFileData write_file_data; | |
282 | ||
33534cd8 | 283 | VikLayerFuncDeleteItem delete_item; |
50a14534 EB |
284 | VikLayerFuncCopyItem copy_item; |
285 | VikLayerFuncPasteItem paste_item; | |
286 | VikLayerFuncFreeCopiedItem free_copied_item; | |
70a23263 AF |
287 | |
288 | VikLayerFuncDragDropRequest drag_drop_request; | |
50a14534 EB |
289 | }; |
290 | ||
291 | VikLayerInterface *vik_layer_get_interface ( gint type ); | |
292 | ||
293 | ||
294 | void vik_layer_init ( VikLayer *vl, gint type ); | |
295 | void vik_layer_draw ( VikLayer *l, gpointer data ); | |
296 | void vik_layer_change_coord_mode ( VikLayer *l, VikCoordMode mode ); | |
297 | void vik_layer_rename ( VikLayer *l, const gchar *new_name ); | |
298 | void vik_layer_rename_no_copy ( VikLayer *l, gchar *new_name ); | |
92558066 | 299 | const gchar *vik_layer_get_name ( VikLayer *l ); |
50a14534 EB |
300 | |
301 | gboolean vik_layer_set_param (VikLayer *layer, guint16 id, VikLayerParamData data, gpointer vp); | |
302 | ||
303 | void vik_layer_emit_update ( VikLayer *vl ); | |
304 | ||
305 | /* GUI */ | |
20c7a3a0 QT |
306 | void vik_layer_set_menu_items_selection(VikLayer *l, guint16 selection); |
307 | guint16 vik_layer_get_menu_items_selection(VikLayer *l); | |
50a14534 EB |
308 | void vik_layer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp ); |
309 | VikLayer *vik_layer_create ( gint type, gpointer vp, GtkWindow *w, gboolean interactive ); | |
310 | gboolean vik_layer_properties ( VikLayer *layer, gpointer vp ); | |
311 | ||
312 | void vik_layer_realize ( VikLayer *l, VikTreeview *vt, GtkTreeIter * layer_iter ); | |
07059501 | 313 | void vik_layer_post_read ( VikLayer *layer, VikViewport *vp, gboolean from_file ); |
50a14534 EB |
314 | |
315 | gboolean vik_layer_sublayer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter ); | |
316 | ||
317 | VikLayer *vik_layer_copy ( VikLayer *vl, gpointer vp ); | |
911400b5 AF |
318 | void vik_layer_marshall ( VikLayer *vl, guint8 **data, gint *len ); |
319 | VikLayer *vik_layer_unmarshall ( guint8 *data, gint len, VikViewport *vvp ); | |
320 | void vik_layer_marshall_params ( VikLayer *vl, guint8 **data, gint *len ); | |
321 | void vik_layer_unmarshall_params ( VikLayer *vl, guint8 *data, gint len, VikViewport *vvp ); | |
50a14534 EB |
322 | |
323 | const gchar *vik_layer_sublayer_rename_request ( VikLayer *l, const gchar *newname, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter ); | |
324 | ||
325 | gboolean vik_layer_sublayer_toggle_visible ( VikLayer *l, gint subtype, gpointer sublayer ); | |
326 | ||
327 | /* TODO: put in layerspanel */ | |
328 | GdkPixbuf *vik_layer_load_icon ( gint type ); | |
329 | ||
0df66d57 EB |
330 | VikLayer *vik_layer_get_and_reset_trigger(); |
331 | void vik_layer_emit_update_secondary ( VikLayer *vl ); /* to be called by aggregate layer only. doesn't set the trigger */ | |
332 | void vik_layer_emit_update_although_invisible ( VikLayer *vl ); | |
333 | ||
bce3a7b0 EB |
334 | GdkCursor *vik_layer_get_tool_cursor ( gint layer_id, gint tool_id ); |
335 | void vik_layer_cursors_init(); | |
336 | void vik_layer_cursors_uninit(); | |
337 | ||
338 | ||
339 | ||
340 | ||
50a14534 | 341 | #endif |