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