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