]> git.street.me.uk Git - andy/viking.git/blob - src/viklayer.h
Never willingly abort, remove exit() statements.
[andy/viking.git] / src / viklayer.h
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  */
21 #ifndef _VIKING_LAYER_H
22 #define _VIKING_LAYER_H
23
24 #include <stdio.h>
25 #include <glib.h>
26 #include <gtk/gtk.h>
27 #include <gdk-pixbuf/gdk-pixdata.h>
28
29 #include "uibuilder.h"
30 #include "vikwindow.h"
31 #include "viktreeview.h"
32 #include "vikviewport.h"
33
34 #define VIK_LAYER_TYPE            (vik_layer_get_type ())
35 #define VIK_LAYER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_LAYER_TYPE, VikLayer))
36 #define VIK_LAYER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), VIK_LAYER_TYPE, VikLayerClass))
37 #define IS_VIK_LAYER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIK_LAYER_TYPE))
38 #define IS_VIK_LAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIK_LAYER_TYPE))
39
40 typedef struct _VikLayer VikLayer;
41 typedef struct _VikLayerClass VikLayerClass;
42
43 struct _VikLayerClass
44 {
45   GObjectClass object_class;
46   void (* update) (VikLayer *vl);
47 };
48
49 GType vik_layer_get_type ();
50
51 struct _VikLayer {
52   GObject obj;
53   gchar *name;
54   gboolean visible;
55
56   gboolean realized;
57   VikTreeview *vt; /* simply a reference */
58   GtkTreeIter iter;
59
60   /* for explicit "polymorphism" (function type switching) */
61   guint16 type;
62 };
63
64
65
66 enum {
67   VIK_LAYER_AGGREGATE = 0,
68   VIK_LAYER_TRW,
69   VIK_LAYER_COORD,
70   VIK_LAYER_GEOREF,
71   VIK_LAYER_GPS,
72   VIK_LAYER_MAPS,
73   VIK_LAYER_DEM,
74   VIK_LAYER_NUM_TYPES
75 };
76
77 /* I think most of these are ignored,
78  * returning GRAB_FOCUS grabs the focus for mouse move,
79  * mouse click, release always grabs focus. Focus allows key presses
80  * to be handled.
81  * It used to be that, if ignored, Viking could look for other layers.
82  * this was useful for clicking a way/trackpoint in any layer,
83  * if no layer was selected (find way/trackpoint)
84  */
85 typedef enum { 
86   VIK_LAYER_TOOL_IGNORED=0,
87   VIK_LAYER_TOOL_ACK,
88   VIK_LAYER_TOOL_ACK_REDRAW_ABOVE,
89   VIK_LAYER_TOOL_ACK_REDRAW_ALL,
90   VIK_LAYER_TOOL_ACK_REDRAW_IF_VISIBLE,
91   VIK_LAYER_TOOL_ACK_GRAB_FOCUS, /* only for move */
92 } VikLayerToolFuncStatus;
93
94 /* gpointer is tool-specific state created in the constructor */
95 typedef gpointer (*VikToolConstructorFunc) (VikWindow *, VikViewport *);
96 typedef void (*VikToolDestructorFunc) (gpointer);
97 typedef VikLayerToolFuncStatus (*VikToolMouseFunc) (VikLayer *, GdkEventButton *, gpointer);
98 typedef VikLayerToolFuncStatus (*VikToolMouseMoveFunc) (VikLayer *, GdkEventMotion *, gpointer);
99 typedef void (*VikToolActivationFunc) (VikLayer *, gpointer);
100 typedef gboolean (*VikToolKeyFunc) (VikLayer *, GdkEventKey *, gpointer);
101
102 typedef struct _VikToolInterface VikToolInterface;
103 struct _VikToolInterface {
104   GtkRadioActionEntry radioActionEntry;
105   VikToolConstructorFunc create;
106   VikToolDestructorFunc destroy;
107   VikToolActivationFunc activate;
108   VikToolActivationFunc deactivate;
109   VikToolMouseFunc click;
110   VikToolMouseMoveFunc move;
111   VikToolMouseFunc release;
112   VikToolKeyFunc key_press; /* return FALSE if we don't use the key press -- should return FALSE most of the time if we want any shortcuts / UI keybindings to work! use sparingly. */
113   gboolean pan_handler; // Call click & release funtions even when 'Pan Mode' is on
114   GdkCursorType cursor_type;
115   const GdkPixdata *cursor_data;
116   const GdkCursor *cursor;
117 };
118
119 /* Parameters (for I/O and Properties) */
120 /* --> moved to uibuilder.h */
121
122
123 /* layer interface functions */
124
125 /* Create a new layer of a certain type. Should be filled with defaults */
126 typedef VikLayer *    (*VikLayerFuncCreate)                (VikViewport *);
127
128 /* normally only needed for layers with sublayers. This is called when they
129  * are added to the treeview so they can add sublayers to the treeview. */
130 typedef void          (*VikLayerFuncRealize)               (VikLayer *,VikTreeview *,GtkTreeIter *);
131
132 /* rarely used, this is called after a read operation or properties box is run.
133  * usually used to create GC's that depend on params,
134  * but GC's can also be created from create() or set_param() */
135 typedef void          (*VikLayerFuncPostRead)              (VikLayer *,VikViewport *vp,gboolean from_file);
136
137 typedef void          (*VikLayerFuncFree)                  (VikLayer *);
138
139 /* do _not_ use this unless absolutely neccesary. Use the dynamic properties (see coordlayer for example)
140   * returns TRUE if OK was pressed */
141 typedef gboolean      (*VikLayerFuncProperties)            (VikLayer *,VikViewport *);
142
143 typedef void          (*VikLayerFuncDraw)                  (VikLayer *,VikViewport *);
144 typedef void          (*VikLayerFuncChangeCoordMode)       (VikLayer *,VikCoordMode);
145
146 typedef void          (*VikLayerFuncSetMenuItemsSelection)          (VikLayer *,guint16);
147 typedef guint16          (*VikLayerFuncGetMenuItemsSelection)          (VikLayer *);
148
149 typedef void          (*VikLayerFuncAddMenuItems)          (VikLayer *,GtkMenu *,gpointer); /* gpointer is a VikLayersPanel */
150 typedef gboolean      (*VikLayerFuncSublayerAddMenuItems)  (VikLayer *,GtkMenu *,gpointer, /* first gpointer is a VikLayersPanel */
151                                                             gint,gpointer,GtkTreeIter *,VikViewport *);
152 typedef const gchar * (*VikLayerFuncSublayerRenameRequest) (VikLayer *,const gchar *,gpointer,
153                                                             gint,VikViewport *,GtkTreeIter *); /* first gpointer is a VikLayersPanel */
154 typedef gboolean      (*VikLayerFuncSublayerToggleVisible) (VikLayer *,gint,gpointer);
155 typedef const gchar * (*VikLayerFuncSublayerTooltip)       (VikLayer *,gint,gpointer);
156 typedef const gchar * (*VikLayerFuncLayerTooltip)          (VikLayer *);
157 typedef gboolean      (*VikLayerFuncLayerSelected)         (VikLayer *,gint,gpointer,gint,gpointer); /* 2nd gpointer is a VikLayersPanel */
158
159 typedef void          (*VikLayerFuncMarshall)              (VikLayer *, guint8 **, gint *);
160 typedef VikLayer *    (*VikLayerFuncUnmarshall)            (guint8 *, gint, VikViewport *);
161
162 /* returns TRUE if needs to redraw due to changed param */
163 /* in parameter gboolean denotes if for file I/O, as opposed to display/cut/copy etc... operations */
164 typedef gboolean      (*VikLayerFuncSetParam)              (VikLayer *, guint16, VikLayerParamData, VikViewport *, gboolean);
165
166 /* in parameter gboolean denotes if for file I/O, as opposed to display/cut/copy etc... operations */
167 typedef VikLayerParamData
168                       (*VikLayerFuncGetParam)              (VikLayer *, guint16, gboolean);
169
170 typedef gboolean      (*VikLayerFuncReadFileData)          (VikLayer *, FILE *); // Should report success or failure
171 typedef void          (*VikLayerFuncWriteFileData)         (VikLayer *, FILE *);
172
173 /* item manipulation */
174 typedef void          (*VikLayerFuncDeleteItem)            (VikLayer *, gint, gpointer);
175                                                          /*      layer, subtype, pointer to sub-item */
176 typedef void          (*VikLayerFuncCutItem)               (VikLayer *, gint, gpointer);
177 typedef void          (*VikLayerFuncCopyItem)              (VikLayer *, gint, gpointer, guint8 **, guint *);
178                                                          /*      layer, subtype, pointer to sub-item, return pointer, return len */
179 typedef gboolean      (*VikLayerFuncPasteItem)             (VikLayer *, gint, guint8 *, guint);
180 typedef void          (*VikLayerFuncFreeCopiedItem)        (gint, gpointer);
181
182 /* treeview drag and drop method. called on the destination layer. it is given a source and destination layer, 
183  * and the source and destination iters in the treeview. 
184  */
185 typedef void          (*VikLayerFuncDragDropRequest)       (VikLayer *, VikLayer *, GtkTreeIter *, GtkTreePath *);
186
187 typedef gboolean      (*VikLayerFuncSelectClick)           (VikLayer *, GdkEventButton *, VikViewport *, tool_ed_t*);
188 typedef gboolean      (*VikLayerFuncSelectMove)            (VikLayer *, GdkEventButton *, VikViewport *, tool_ed_t*);
189 typedef gboolean      (*VikLayerFuncSelectRelease)         (VikLayer *, GdkEventButton *, VikViewport *, tool_ed_t*);
190 typedef gboolean      (*VikLayerFuncSelectedViewportMenu)  (VikLayer *, GdkEventButton *, VikViewport *);
191
192 typedef enum {
193   VIK_MENU_ITEM_PROPERTY=1,
194   VIK_MENU_ITEM_CUT=2,
195   VIK_MENU_ITEM_COPY=4,
196   VIK_MENU_ITEM_PASTE=8,
197   VIK_MENU_ITEM_DELETE=16,
198   VIK_MENU_ITEM_ALL=0xff
199 } VikStdLayerMenuItem;
200
201 typedef struct _VikLayerInterface VikLayerInterface;
202
203 /* See vik_layer_* for function parameter names */
204 struct _VikLayerInterface {
205   const gchar *                     name;
206   const gchar *                     accelerator;
207   const GdkPixdata *                icon;
208
209   VikToolInterface *                tools;
210   guint16                           tools_count;
211
212   /* for I/O reading to and from .vik files -- params like coordline width, color, etc. */
213   VikLayerParam *                   params;
214   guint16                           params_count;
215   gchar **                          params_groups;
216   guint8                            params_groups_count;
217
218   /* menu items to be created */
219   VikStdLayerMenuItem               menu_items_selection;
220
221   VikLayerFuncCreate                create;
222   VikLayerFuncRealize               realize;
223   VikLayerFuncPostRead              post_read;
224   VikLayerFuncFree                  free;
225
226   VikLayerFuncProperties            properties;
227   VikLayerFuncDraw                  draw;
228   VikLayerFuncChangeCoordMode       change_coord_mode;
229
230   VikLayerFuncSetMenuItemsSelection set_menu_selection;
231   VikLayerFuncGetMenuItemsSelection get_menu_selection;
232
233   VikLayerFuncAddMenuItems          add_menu_items;
234   VikLayerFuncSublayerAddMenuItems  sublayer_add_menu_items;
235   VikLayerFuncSublayerRenameRequest sublayer_rename_request;
236   VikLayerFuncSublayerToggleVisible sublayer_toggle_visible;
237   VikLayerFuncSublayerTooltip       sublayer_tooltip;
238   VikLayerFuncLayerTooltip          layer_tooltip;
239   VikLayerFuncLayerSelected         layer_selected;
240
241   VikLayerFuncMarshall              marshall;
242   VikLayerFuncUnmarshall            unmarshall;
243
244   /* for I/O */
245   VikLayerFuncSetParam              set_param;
246   VikLayerFuncGetParam              get_param;
247
248   /* for I/O -- extra non-param data like TrwLayer data */
249   VikLayerFuncReadFileData          read_file_data;
250   VikLayerFuncWriteFileData         write_file_data;
251
252   VikLayerFuncDeleteItem            delete_item;
253   VikLayerFuncCutItem               cut_item;
254   VikLayerFuncCopyItem              copy_item;
255   VikLayerFuncPasteItem             paste_item;
256   VikLayerFuncFreeCopiedItem        free_copied_item;
257
258   VikLayerFuncDragDropRequest       drag_drop_request;
259
260   VikLayerFuncSelectClick           select_click;
261   VikLayerFuncSelectMove            select_move;
262   VikLayerFuncSelectRelease         select_release;
263   VikLayerFuncSelectedViewportMenu  show_viewport_menu;
264 };
265
266 VikLayerInterface *vik_layer_get_interface ( gint type );
267
268
269 void vik_layer_init ( VikLayer *vl, gint type );
270 void vik_layer_draw ( VikLayer *l, gpointer data );
271 void vik_layer_change_coord_mode ( VikLayer *l, VikCoordMode mode );
272 void vik_layer_rename ( VikLayer *l, const gchar *new_name );
273 void vik_layer_rename_no_copy ( VikLayer *l, gchar *new_name );
274 const gchar *vik_layer_get_name ( VikLayer *l );
275
276 gboolean vik_layer_set_param (VikLayer *layer, guint16 id, VikLayerParamData data, gpointer vp, gboolean is_file_operation);
277
278 void vik_layer_emit_update ( VikLayer *vl, gboolean from_background );
279
280 /* GUI */
281 void vik_layer_set_menu_items_selection(VikLayer *l, guint16 selection);
282 guint16 vik_layer_get_menu_items_selection(VikLayer *l);
283 void vik_layer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp );
284 VikLayer *vik_layer_create ( gint type, gpointer vp, GtkWindow *w, gboolean interactive );
285 gboolean vik_layer_properties ( VikLayer *layer, gpointer vp );
286
287 void vik_layer_realize ( VikLayer *l, VikTreeview *vt, GtkTreeIter * layer_iter );
288 void vik_layer_post_read ( VikLayer *layer, VikViewport *vp, gboolean from_file );
289
290 gboolean vik_layer_sublayer_add_menu_items ( VikLayer *l, GtkMenu *menu, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter, VikViewport *vvp );
291
292 VikLayer *vik_layer_copy ( VikLayer *vl, gpointer vp );
293 void      vik_layer_marshall ( VikLayer *vl, guint8 **data, gint *len );
294 VikLayer *vik_layer_unmarshall ( guint8 *data, gint len, VikViewport *vvp );
295 void      vik_layer_marshall_params ( VikLayer *vl, guint8 **data, gint *len );
296 void      vik_layer_unmarshall_params ( VikLayer *vl, guint8 *data, gint len, VikViewport *vvp );
297
298 const gchar *vik_layer_sublayer_rename_request ( VikLayer *l, const gchar *newname, gpointer vlp, gint subtype, gpointer sublayer, GtkTreeIter *iter );
299
300 gboolean vik_layer_sublayer_toggle_visible ( VikLayer *l, gint subtype, gpointer sublayer );
301
302 const gchar* vik_layer_sublayer_tooltip ( VikLayer *l, gint subtype, gpointer sublayer );
303
304 const gchar* vik_layer_layer_tooltip ( VikLayer *l );
305
306 gboolean vik_layer_selected ( VikLayer *l, gint subtype, gpointer sublayer, gint type, gpointer vlp );
307
308 /* TODO: put in layerspanel */
309 GdkPixbuf *vik_layer_load_icon ( gint type );
310
311 VikLayer *vik_layer_get_and_reset_trigger();
312 void vik_layer_emit_update_secondary ( VikLayer *vl ); /* to be called by aggregate layer only. doesn't set the trigger */
313 void vik_layer_emit_update_although_invisible ( VikLayer *vl );
314
315 #endif