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

Contents of /navit/navit/gui.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (10 years, 9 months ago) by zoff99
File MIME type: text/plain
File size: 4294 byte(s)
lots of new stuff, tranlsations, bug fixes ...
1 zoff99 2 /**
2     * Navit, a modular navigation system.
3     * Copyright (C) 2005-2008 Navit Team
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     #include <glib.h>
21     #include <string.h>
22     #include "debug.h"
23     #include "callback.h"
24     #include "gui.h"
25     #include "menu.h"
26     #include "data_window.h"
27     #include "item.h"
28     #include "plugin.h"
29    
30 zoff99 27 struct gui
31     {
32 zoff99 2 struct gui_methods meth;
33     struct gui_priv *priv;
34     struct attr **attrs;
35     struct attr parent;
36     };
37    
38     struct gui *
39     gui_new(struct attr *parent, struct attr **attrs)
40     {
41     struct gui *this_;
42     struct attr *type_attr;
43 zoff99 27 struct gui_priv *(*guitype_new)(struct navit *nav,
44     struct gui_methods *meth, struct attr **attrs, struct gui *gui);
45 zoff99 2 struct attr cbl;
46 zoff99 27 if (!(type_attr = attr_search(attrs, NULL, attr_type)))
47     {
48 zoff99 2 return NULL;
49     }
50    
51 zoff99 27 guitype_new = plugin_get_gui_type(type_attr->u.str);
52     if (!guitype_new)
53     return NULL;
54 zoff99 2
55     this_=g_new0(struct gui, 1);
56 zoff99 27 this_->attrs = attr_list_dup(attrs);
57     cbl.type = attr_callback_list;
58     cbl.u.callback_list = callback_list_new();
59     this_->attrs = attr_generic_add_attr(this_->attrs, &cbl);
60     this_->priv = guitype_new(parent->u.navit, &this_->meth, this_->attrs,
61     this_);
62     this_->parent = *parent;
63 zoff99 2 return this_;
64     }
65    
66 zoff99 27 int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr,
67     struct attr_iter *iter)
68 zoff99 2 {
69     int ret;
70 zoff99 27 if (this_->meth.get_attr)
71     {
72     ret = this_->meth.get_attr(this_->priv, type, attr);
73 zoff99 2 if (ret)
74     return ret;
75     }
76 zoff99 27 if (type == this_->parent.type)
77     {
78     *attr = this_->parent;
79 zoff99 2 return 1;
80     }
81     return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
82     }
83    
84 zoff99 27 int gui_set_attr(struct gui *this_, struct attr *attr)
85 zoff99 2 {
86 zoff99 27 int ret = 1;
87 zoff99 2 if (this_->meth.set_attr)
88 zoff99 27 ret = this_->meth.set_attr(this_->priv, attr);
89 zoff99 2 if (ret == 1)
90 zoff99 27 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
91 zoff99 2 return ret != 0;
92     }
93    
94 zoff99 27 int gui_add_attr(struct gui *this_, struct attr *attr)
95 zoff99 2 {
96 zoff99 27 int ret = 0;
97     if (this_->meth.add_attr)
98     ret = this_->meth.add_attr(this_->priv, attr);
99 zoff99 2 return ret;
100     }
101    
102     struct menu *
103     gui_menubar_new(struct gui *gui)
104     {
105     struct menu *this_;
106 zoff99 27 if (!gui->meth.menubar_new)
107     return NULL; this_=g_new0(struct menu, 1);
108     this_->priv = gui->meth.menubar_new(gui->priv, &this_->meth);
109     if (!this_->priv)
110     {
111 zoff99 2 g_free(this_);
112     return NULL;
113     }
114     return this_;
115     }
116    
117     struct menu *
118     gui_popup_new(struct gui *gui)
119     {
120     struct menu *this_;
121 zoff99 27 if (!gui->meth.popup_new)
122     return NULL; this_=g_new0(struct menu, 1);
123     this_->priv = gui->meth.popup_new(gui->priv, &this_->meth);
124     if (!this_->priv)
125     {
126 zoff99 2 g_free(this_);
127     return NULL;
128     }
129     return this_;
130     }
131    
132     struct datawindow *
133 zoff99 27 gui_datawindow_new(struct gui *gui, char *name, struct callback *click,
134     struct callback *close)
135 zoff99 2 {
136     struct datawindow *this_;
137 zoff99 27 if (!gui->meth.datawindow_new)
138     return NULL; this_=g_new0(struct datawindow, 1);
139     this_->priv = gui->meth.datawindow_new(gui->priv, name, click, close,
140     &this_->meth);
141     if (!this_->priv)
142     {
143 zoff99 2 g_free(this_);
144     return NULL;
145     }
146     return this_;
147     }
148    
149 zoff99 27 int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description)
150 zoff99 2 {
151     int ret;
152 zoff99 27 dbg(2, "enter\n");
153     if (!gui->meth.add_bookmark)
154 zoff99 2 return 0;
155 zoff99 27 ret = gui->meth.add_bookmark(gui->priv, c, description);
156    
157     dbg(2, "ret=%d\n", ret);
158 zoff99 2 return ret;
159     }
160    
161 zoff99 27 int gui_set_graphics(struct gui *this_, struct graphics *gra)
162 zoff99 2 {
163 zoff99 27 if (!this_->meth.set_graphics)
164 zoff99 2 return 1;
165     return this_->meth.set_graphics(this_->priv, gra);
166     }
167    
168 zoff99 27 void gui_disable_suspend(struct gui *this_)
169 zoff99 2 {
170     if (this_->meth.disable_suspend)
171     this_->meth.disable_suspend(this_->priv);
172     }
173    
174 zoff99 27 int gui_has_main_loop(struct gui *this_)
175 zoff99 2 {
176 zoff99 27 if (!this_->meth.run_main_loop)
177 zoff99 2 return 0;
178     return 1;
179     }
180    
181 zoff99 27 int gui_run_main_loop(struct gui *this_)
182 zoff99 2 {
183 zoff99 27 if (!gui_has_main_loop(this_))
184 zoff99 2 return 1;
185     return this_->meth.run_main_loop(this_->priv);
186     }
187    

   
Visit the ZANavi Wiki