}
int
+attr_generic_get_attr(struct attr **attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter)
+{
+ while (*attrs) {
+ if ((*attrs)->type == type) {
+ *attr=**attrs;
+ return 1;
+ }
+ attrs++;
+ }
+ return 0;
+}
+
+int
attr_data_size(struct attr *attr)
{
if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
g_free(attr->u.color);
g_free(attr);
}
+
+struct attr *
+attr_dup(struct attr *attr)
+{
+ int size;
+ struct attr *ret=g_new0(struct attr, 1);
+ ret->type=attr->type;
+ if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) {
+ ret->u.num=attr->u.num;
+ } else {
+ size=attr_data_size(attr);
+ if (size) {
+ ret->u.data=g_malloc(size);
+ memcpy(ret->u.data, attr->u.data, size);
+ }
+ }
+ return ret;
+}
+
+void
+attr_list_free(struct attr **attrs)
+{
+ int count=0;
+ while (attrs[count]) {
+ attr_free(attrs[count++]);
+ }
+ g_free(attrs);
+}
+
+struct attr **
+attr_list_dup(struct attr **attrs)
+{
+ struct attr **ret=attrs;
+ int i,count=0;
+
+ while (attrs[count])
+ count++;
+ ret=g_new0(struct attr *, count+1);
+ for (i = 0 ; i < count ; i++)
+ ret[i]=attr_dup(attrs[i]);
+ return ret;
+}
enum attr_type type;
union {
char *str;
+ void *data;
int num;
struct item *item;
enum item_type item_type;
struct navigation *navigation;
struct coord *coord;
struct pcoord *pcoord;
+ struct gui *gui;
+ struct graphics *graphics;
} u;
};
/* prototypes */
enum attr_type;
struct attr;
+struct attr_iter;
struct map;
enum attr_type attr_from_name(const char *name);
char *attr_to_name(enum attr_type attr);
struct attr *attr_new_from_text(const char *name, const char *value);
char *attr_to_text(struct attr *attr, struct map *map, int pretty);
struct attr *attr_search(struct attr **attrs, struct attr *last, enum attr_type attr);
+int attr_generic_get_attr(struct attr **attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter);
int attr_data_size(struct attr *attr);
void *attr_data_get(struct attr *attr);
void attr_data_set(struct attr *attr, void *data);
void attr_free(struct attr *attr);
+struct attr *attr_dup(struct attr *attr);
+void attr_list_free(struct attr **attrs);
+struct attr **attr_list_dup(struct attr **attrs);
/* end of prototypes */
#endif
#ifdef __cplusplus
ATTR(map)
ATTR(bookmark_map)
ATTR(former_destination_map)
+ATTR(graphics)
+ATTR(gui)
ATTR2(0x0008ffff,type_object_end)
ATTR2(0x00090000,type_coord_begin)
ATTR2(0x0009ffff,type_coord_end)
struct graphics_methods meth;
struct graphics_font *font[16];
struct graphics_gc *gc[3];
+ struct attr **attrs;
int ready;
};
return NULL;
this_=g_new0(struct graphics, 1);
this_->priv=(*new)(&this_->meth, attrs);
+ this_->attrs=attr_list_dup(attrs);
return this_;
}
+int
+graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
+{
+ return attr_generic_get_attr(this_->attrs, type, attr, iter);
+}
+
+
struct graphics *
graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h)
{
};
/* prototypes */
+enum attr_type;
enum draw_mode_num;
struct attr;
+struct attr_iter;
struct color;
struct displayitem;
struct displaylist;
struct point;
struct transformation;
struct graphics *graphics_new(const char *type, struct attr **attrs);
+int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
struct graphics *graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h);
void graphics_init(struct graphics *this_);
void *graphics_get_data(struct graphics *this_, char *type);
#include <glib.h>
#include "config.h"
#include "point.h"
+#include "item.h"
#include "graphics.h"
#include "color.h"
#include "debug.h"
#include "gui.h"
#include "menu.h"
#include "data_window.h"
+#include "item.h"
#include "plugin.h"
+struct gui {
+ struct gui_methods meth;
+ struct gui_priv *priv;
+ struct attr **attrs;
+};
+
struct gui *
gui_new(struct navit *nav, const char *type, struct attr **attrs)
{
this_=g_new0(struct gui, 1);
this_->priv=guitype_new(nav, &this_->meth, attrs);
+ this_->attrs=attr_list_dup(attrs);
return this_;
}
+int
+gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
+{
+ return attr_generic_get_attr(this_->attrs, type, attr, iter);
+}
+
struct menu *
gui_menubar_new(struct gui *gui)
{
};
-struct gui {
- struct gui_methods meth;
- struct gui_priv *priv;
-};
-
/* prototypes */
+enum attr_type;
struct attr;
+struct attr_iter;
struct callback;
-struct coord;
struct datawindow;
struct graphics;
struct gui;
struct menu;
struct navit;
+struct pcoord;
struct gui *gui_new(struct navit *nav, const char *type, struct attr **attrs);
+int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
struct menu *gui_menubar_new(struct gui *gui);
struct menu *gui_popup_new(struct gui *gui);
struct datawindow *gui_datawindow_new(struct gui *gui, char *name, struct callback *click, struct callback *close);
struct log_data header;
struct log_data data;
struct log_data trailer;
+ struct attr **attrs;
};
static void
return TRUE;
}
+int
+log_get_attr(struct log *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
+{
+ return attr_generic_get_attr(this_->attrs, type, attr, iter);
+}
+
+
struct log *
log_new(struct attr **attrs)
{
expand_filenames(ret);
log_open(ret);
gettimeofday(&ret->last_flush, NULL);
+ ret->attrs=attr_list_dup(attrs);
return ret;
}
#ifndef NAVIT_LOG_H
#define NAVIT_LOG_H
/* prototypes */
+enum attr_type;
struct attr;
+struct attr_iter;
struct log;
+int log_get_attr(struct log *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
struct log *log_new(struct attr **attrs);
void log_set_header(struct log *this_, char *data, int len);
void log_set_trailer(struct log *this_, char *data, int len);
GList *mapsets;
GList *layouts;
struct gui *gui;
- char *gui_type;
struct layout *layout_current;
struct graphics *gra;
- char *gra_type;
struct action *action;
struct transformation *trans;
struct compass *compass;
return this_;
}
-void
-navit_set_gui(struct navit *this_, struct gui *gui, char *type)
+static int
+navit_set_gui(struct navit *this_, struct gui *gui)
{
+ if (this_->gui)
+ return 0;
this_->gui=gui;
- this_->gui_type=g_strdup(type);
if (gui_has_main_loop(this_->gui)) {
if (! main_loop_gui) {
main_loop_gui=this_->gui;
} else {
g_warning("gui with main loop already active, ignoring this instance");
- return;
+ return 0;
}
}
+ return 1;
}
-void
-navit_set_graphics(struct navit *this_, struct graphics *gra, char *type)
+static int
+navit_set_graphics(struct navit *this_, struct graphics *gra)
{
+ if (this_->gra)
+ return 0;
this_->gra=gra;
- this_->gra_type=g_strdup(type);
graphics_register_resize_callback(this_->gra, navit_resize, this_);
graphics_register_button_callback(this_->gra, navit_button, this_);
graphics_register_motion_callback(this_->gra, navit_motion, this_);
+ return 1;
}
struct graphics *
struct navit_vehicle *nv;
if (!this_->gui) {
- g_warning("failed to instantiate gui '%s'\n",this_->gui_type);
+ g_warning("no gui\n");
navit_destroy(this_);
return;
}
if (!this_->gra) {
- g_warning("failed to instantiate graphics '%s'\n",this_->gra_type);
+ g_warning("no graphics\n");
navit_destroy(this_);
return;
}
if (gui_set_graphics(this_->gui, this_->gra)) {
- g_warning("failed to connect graphics '%s' to gui '%s'\n", this_->gra_type, this_->gui_type);
+ struct attr attr_type_gui, attr_type_graphics;
+ gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
+ graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
+ g_warning("failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
g_warning(" Please see http://navit.sourceforge.net/wiki/index.php/Failed_to_connect_graphics_to_gui\n");
g_warning(" for explanations and solutions\n");
}
static int
-navit_add_log(struct navit *this_, struct log *log, struct attr **attrs)
+navit_add_log(struct navit *this_, struct log *log)
{
- struct attr *type;
- type = attr_search(attrs, NULL, attr_type);
- if (!type)
- return 1;
- if (!strcmp(type->u.str, "textfile_debug")) {
+ struct attr type_attr;
+ if (!log_get_attr(log, attr_type, &type_attr, NULL))
+ return 0;
+ if (!strcmp(type_attr.u.str, "textfile_debug")) {
if (this_->textfile_debug_log)
- return 1;
+ return 0;
this_->textfile_debug_log=log;
- return 0;
+ return 1;
}
- return 1;
+ return 0;
}
int
{
switch (attr->type) {
case attr_log:
- return navit_add_log(this_, attr->u.log, attrs);
+ return navit_add_log(this_, attr->u.log);
+ case attr_gui:
+ return navit_set_gui(this_, attr->u.gui);
+ case attr_graphics:
+ return navit_set_graphics(this_, attr->u.graphics);
default:
return 0;
}
#endif
extern struct gui *main_loop_gui;
/* prototypes */
-enum item_type;
enum attr_type;
+enum item_type;
struct attr;
struct attr_iter;
-struct attr_iter;
struct callback;
-struct coord;
struct displaylist;
struct graphics;
struct gui;
struct layout;
struct mapset;
-struct menu;
struct navigation;
struct navit;
struct navit_vehicle;
void navit_add_layout(struct navit *this_, struct layout *lay);
void navit_draw(struct navit *this_);
void navit_draw_displaylist(struct navit *this_);
+void navit_resize(void *data, int w, int h);
+int navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback);
+void navit_handle_motion(struct navit *this_, struct point *p);
void navit_zoom_in(struct navit *this_, int factor, struct point *p);
void navit_zoom_out(struct navit *this_, int factor, struct point *p);
struct navit *navit_new(struct attr **attrs);
-void navit_set_gui(struct navit *this_, struct gui *gui, char *type);
-void navit_set_graphics(struct navit *this_, struct graphics *gra, char *type);
struct graphics *navit_get_graphics(struct navit *this_);
void navit_set_destination(struct navit *this_, struct pcoord *c, char *description);
void navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description);
void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
void navit_tracking_add(struct navit *this_, struct tracking *tracking);
void navit_route_add(struct navit *this_, struct route *route);
-struct map *navit_get_route_map(struct navit *this_);
void navit_navigation_add(struct navit *this_, struct navigation *navigation);
void navit_set_speech(struct navit *this_, struct speech *speech);
struct gui *navit_get_gui(struct navit *this_);
struct navigation *navit_get_navigation(struct navit *this_);
struct displaylist *navit_get_displaylist(struct navit *this_);
void navit_destroy(struct navit *this_);
-void navit_toggle_routegraph_display(struct navit *nav);
/* end of prototypes */
#ifdef __cplusplus
}
xmlconfig_graphics(struct xmlstate *state)
{
struct attr **attrs;
+ struct attr graphics_attr;
const char *type=find_attribute(state, "type", 1);
if (! type)
return 0;
dbg(0,"Failed to create graphics '%s'\n", type);
return 0;
}
- navit_set_graphics(state->parent->element_object, state->element_object, type);
- return 1;
+ graphics_attr.type=attr_graphics;
+ graphics_attr.u.graphics=state->element_object;
+ return navit_add_attr(state->parent->element_object, &graphics_attr, NULL);
}
static int
xmlconfig_gui(struct xmlstate *state)
{
struct attr **attrs;
+ struct attr gui_attr;
const char *type=find_attribute(state, "type", 1);
if (! type)
return 0;
dbg(0,"Failed to create gui '%s'\n", type);
return 0;
}
- navit_set_gui(state->parent->element_object, state->element_object, type);
- return 1;
+ gui_attr.type=attr_gui;
+ gui_attr.u.gui=state->element_object;
+ return navit_add_attr(state->parent->element_object, &gui_attr, NULL);
}
static int