/[zanavi_public1]/navit/navit/gui.c
ZANavi

Contents of /navit/navit/gui.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 5037 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #include <glib.h>
40 #include <string.h>
41 #include "debug.h"
42 #include "callback.h"
43 #include "gui.h"
44 #include "menu.h"
45 #include "data_window.h"
46 #include "item.h"
47 #include "plugin.h"
48
49 struct gui
50 {
51 struct gui_methods meth;
52 struct gui_priv *priv;
53 struct attr **attrs;
54 struct attr parent;
55 };
56
57 struct gui *
58 gui_new(struct attr *parent, struct attr **attrs)
59 {
60 struct gui *this_;
61 struct attr *type_attr;
62 struct gui_priv *(*guitype_new)(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui);
63 struct attr cbl;
64 if (!(type_attr = attr_search(attrs, NULL, attr_type)))
65 {
66 return NULL;
67 }
68
69 guitype_new = plugin_get_gui_type(type_attr->u.str);
70 if (!guitype_new)
71 return NULL;
72
73 this_=g_new0(struct gui, 1);
74 this_->attrs = attr_list_dup(attrs);
75 cbl.type = attr_callback_list;
76 cbl.u.callback_list = callback_list_new();
77 this_->attrs = attr_generic_add_attr(this_->attrs, &cbl);
78 this_->priv = guitype_new(parent->u.navit, &this_->meth, this_->attrs, this_);
79 this_->parent = *parent;
80 return this_;
81 }
82
83 int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
84 {
85 int ret;
86 if (this_->meth.get_attr)
87 {
88 ret = this_->meth.get_attr(this_->priv, type, attr);
89 if (ret)
90 return ret;
91 }
92 if (type == this_->parent.type)
93 {
94 *attr = this_->parent;
95 return 1;
96 }
97 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
98 }
99
100 int gui_set_attr(struct gui *this_, struct attr *attr)
101 {
102 int ret = 1;
103 if (this_->meth.set_attr)
104 ret = this_->meth.set_attr(this_->priv, attr);
105 if (ret == 1)
106 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
107 return ret != 0;
108 }
109
110 int gui_add_attr(struct gui *this_, struct attr *attr)
111 {
112 int ret = 0;
113 if (this_->meth.add_attr)
114 ret = this_->meth.add_attr(this_->priv, attr);
115 return ret;
116 }
117
118 struct menu *
119 gui_menubar_new(struct gui *gui)
120 {
121 struct menu *this_;
122 if (!gui->meth.menubar_new)
123 return NULL;this_=g_new0(struct menu, 1);
124 this_->priv = gui->meth.menubar_new(gui->priv, &this_->meth);
125 if (!this_->priv)
126 {
127 g_free(this_);
128 return NULL;
129 }
130 return this_;
131 }
132
133 struct menu *
134 gui_popup_new(struct gui *gui)
135 {
136 struct menu *this_;
137 if (!gui->meth.popup_new)
138 return NULL;this_=g_new0(struct menu, 1);
139 this_->priv = gui->meth.popup_new(gui->priv, &this_->meth);
140 if (!this_->priv)
141 {
142 g_free(this_);
143 return NULL;
144 }
145 return this_;
146 }
147
148 struct datawindow *
149 gui_datawindow_new(struct gui *gui, char *name, struct callback *click, struct callback *close)
150 {
151 struct datawindow *this_;
152 if (!gui->meth.datawindow_new)
153 return NULL;this_=g_new0(struct datawindow, 1);
154 this_->priv = gui->meth.datawindow_new(gui->priv, name, click, close, &this_->meth);
155 if (!this_->priv)
156 {
157 g_free(this_);
158 return NULL;
159 }
160 return this_;
161 }
162
163 int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description)
164 {
165 int ret;
166 dbg(2, "enter\n");
167 if (!gui->meth.add_bookmark)
168 return 0;
169 ret = gui->meth.add_bookmark(gui->priv, c, description);
170
171 dbg(2, "ret=%d\n", ret);
172 return ret;
173 }
174
175 int gui_set_graphics(struct gui *this_, struct graphics *gra)
176 {
177 if (!this_->meth.set_graphics)
178 return 1;
179 return this_->meth.set_graphics(this_->priv, gra);
180 }
181
182 void gui_disable_suspend(struct gui *this_)
183 {
184 if (this_->meth.disable_suspend)
185 this_->meth.disable_suspend(this_->priv);
186 }
187
188 int gui_has_main_loop(struct gui *this_)
189 {
190 if (!this_->meth.run_main_loop)
191 return 0;
192 return 1;
193 }
194
195 int gui_run_main_loop(struct gui *this_)
196 {
197 if (!gui_has_main_loop(this_))
198 return 1;
199 return this_->meth.run_main_loop(this_->priv);
200 }
201

   
Visit the ZANavi Wiki