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

Contents of /navit/navit/gui.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations) (download)
Wed Mar 4 14:00:54 2015 UTC (9 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 5369 byte(s)
new market version, lots of fixes
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
65 if (!(type_attr = attr_search(attrs, NULL, attr_type)))
66 {
67 return NULL;
68 }
69
70 #ifdef PLUGSSS
71 guitype_new = plugin_get_gui_type(type_attr->u.str);
72
73 if (!guitype_new)
74 {
75 return NULL;
76 }
77 #endif
78
79 this_=g_new0(struct gui, 1);
80 this_->attrs = attr_list_dup(attrs);
81
82 cbl.type = attr_callback_list;
83 cbl.u.callback_list = callback_list_new("gui_new:cbl.u.callback_list");
84
85 this_->attrs = attr_generic_add_attr(this_->attrs, &cbl);
86
87 #ifdef PLUGSSS
88 this_->priv = guitype_new(parent->u.navit, &this_->meth, this_->attrs, this_);
89 #else
90 this_->priv = gui_internal_new(parent->u.navit, &this_->meth, this_->attrs, this_);
91 #endif
92
93 this_->parent = *parent;
94
95 return this_;
96 }
97
98 int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
99 {
100 int ret;
101 if (this_->meth.get_attr)
102 {
103 ret = this_->meth.get_attr(this_->priv, type, attr);
104 if (ret)
105 return ret;
106 }
107 if (type == this_->parent.type)
108 {
109 *attr = this_->parent;
110 return 1;
111 }
112 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
113 }
114
115 int gui_set_attr(struct gui *this_, struct attr *attr)
116 {
117 int ret = 1;
118 if (this_->meth.set_attr)
119 ret = this_->meth.set_attr(this_->priv, attr);
120 if (ret == 1)
121 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
122 return ret != 0;
123 }
124
125 int gui_add_attr(struct gui *this_, struct attr *attr)
126 {
127 int ret = 0;
128 if (this_->meth.add_attr)
129 ret = this_->meth.add_attr(this_->priv, attr);
130 return ret;
131 }
132
133 struct menu *
134 gui_menubar_new(struct gui *gui)
135 {
136 struct menu *this_;
137 if (!gui->meth.menubar_new)
138 return NULL;this_=g_new0(struct menu, 1);
139 this_->priv = gui->meth.menubar_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 menu *
149 gui_popup_new(struct gui *gui)
150 {
151 struct menu *this_;
152 if (!gui->meth.popup_new)
153 return NULL;this_=g_new0(struct menu, 1);
154 this_->priv = gui->meth.popup_new(gui->priv, &this_->meth);
155 if (!this_->priv)
156 {
157 g_free(this_);
158 return NULL;
159 }
160 return this_;
161 }
162
163 struct datawindow *
164 gui_datawindow_new(struct gui *gui, char *name, struct callback *click, struct callback *close)
165 {
166 struct datawindow *this_;
167
168 if (!gui->meth.datawindow_new)
169 return NULL;this_=g_new0(struct datawindow, 1);
170
171 this_->priv = gui->meth.datawindow_new(gui->priv, name, click, close, &this_->meth);
172
173 if (!this_->priv)
174 {
175 g_free(this_);
176 return NULL;
177 }
178
179 return this_;
180 }
181
182 int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description)
183 {
184 int ret;
185 dbg(2, "enter\n");
186 if (!gui->meth.add_bookmark)
187 return 0;
188 ret = gui->meth.add_bookmark(gui->priv, c, description);
189
190 dbg(2, "ret=%d\n", ret);
191 return ret;
192 }
193
194 int gui_set_graphics(struct gui *this_, struct graphics *gra)
195 {
196 if (!this_->meth.set_graphics)
197 return 1;
198 return this_->meth.set_graphics(this_->priv, gra);
199 }
200
201 void gui_disable_suspend(struct gui *this_)
202 {
203 if (this_->meth.disable_suspend)
204 this_->meth.disable_suspend(this_->priv);
205 }
206
207 int gui_has_main_loop(struct gui *this_)
208 {
209 if (!this_->meth.run_main_loop)
210 {
211 dbg(0, "gui_has_main_loop:FALSE\n");
212 return 0;
213 }
214 dbg(0, "gui_has_main_loop:TRUE\n");
215 return 1;
216 }
217
218 int gui_run_main_loop(struct gui *this_)
219 {
220 if (!gui_has_main_loop(this_))
221 {
222 return 1;
223 }
224 dbg(0,"gui_run_main_loop:calling -> run_main_loop(this_)\n");
225 return this_->meth.run_main_loop(this_->priv);
226 }
227

   
Visit the ZANavi Wiki