Updated Turkish translation
[navit-package] / navit / gui.c
1 /**
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 struct gui {
31         struct gui_methods meth;
32         struct gui_priv *priv;
33         struct attr **attrs;
34 };
35
36 struct gui *
37 gui_new(struct attr *parent, struct attr **attrs)
38 {
39         struct gui *this_;
40         struct attr *type_attr;
41         struct gui_priv *(*guitype_new)(struct navit *nav, struct gui_methods *meth, struct attr **attrs);
42         struct attr cbl;
43         if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
44                 return NULL;
45         }
46
47         guitype_new=plugin_get_gui_type(type_attr->u.str);
48         if (! guitype_new)
49                 return NULL;
50
51         this_=g_new0(struct gui, 1);
52         this_->attrs=attr_list_dup(attrs);
53         cbl.type=attr_callback_list;
54         cbl.u.callback_list=callback_list_new();
55         this_->attrs=attr_generic_add_attr(this_->attrs, &cbl);
56         this_->priv=guitype_new(parent->u.navit, &this_->meth, this_->attrs);
57         return this_;
58 }
59
60 int
61 gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
62 {
63         return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
64 }
65
66 struct menu *
67 gui_menubar_new(struct gui *gui)
68 {
69         struct menu *this_;
70         if (! gui->meth.menubar_new)
71                 return NULL;
72         this_=g_new0(struct menu, 1);
73         this_->priv=gui->meth.menubar_new(gui->priv, &this_->meth);
74         if (! this_->priv) {
75                 g_free(this_);
76                 return NULL;
77         }
78         return this_;
79 }
80
81 struct menu *
82 gui_popup_new(struct gui *gui)
83 {
84         struct menu *this_;
85         if (! gui->meth.popup_new)
86                 return NULL;
87         this_=g_new0(struct menu, 1);
88         this_->priv=gui->meth.popup_new(gui->priv, &this_->meth);
89         if (! this_->priv) {
90                 g_free(this_);
91                 return NULL;
92         }
93         return this_;
94 }
95
96 struct datawindow *
97 gui_datawindow_new(struct gui *gui, char *name, struct callback *click, struct callback *close)
98 {
99         struct datawindow *this_;
100         if (! gui->meth.datawindow_new)
101                 return NULL;
102         this_=g_new0(struct datawindow, 1);
103         this_->priv=gui->meth.datawindow_new(gui->priv, name, click, close, &this_->meth);
104         if (! this_->priv) {
105                 g_free(this_);
106                 return NULL;
107         }
108         return this_;
109 }
110
111 int
112 gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description)
113 {
114         int ret;
115         dbg(2,"enter\n");
116         if (! gui->meth.add_bookmark)
117                 return 0;
118         ret=gui->meth.add_bookmark(gui->priv, c, description);
119         
120         dbg(2,"ret=%d\n", ret);
121         return ret;
122 }
123
124 int
125 gui_set_graphics(struct gui *this_, struct graphics *gra)
126 {
127         if (! this_->meth.set_graphics)
128                 return 1;
129         return this_->meth.set_graphics(this_->priv, gra);
130 }
131
132 void
133 gui_disable_suspend(struct gui *this_)
134 {
135         if (this_->meth.disable_suspend)
136                 this_->meth.disable_suspend(this_->priv);
137 }
138
139 int
140 gui_has_main_loop(struct gui *this_)
141 {
142         if (! this_->meth.run_main_loop)
143                 return 0;
144         return 1;
145 }
146
147 int
148 gui_run_main_loop(struct gui *this_)
149 {
150         if (! gui_has_main_loop(this_))
151                 return 1;
152         return this_->meth.run_main_loop(this_->priv);
153 }
154