Merge with modular_map
[navit-package] / src / gui.c
1 #include <glib.h>
2 #include "gui.h"
3 #include "statusbar.h"
4 #include "menu.h"
5 #include "plugin.h"
6
7 struct gui *
8 gui_new(struct navit *nav, const char *type, int w, int h)
9 {
10         struct gui *this_;
11         struct gui_priv *(*guitype_new)(struct navit *nav, struct gui_methods *meth, int w, int h);
12
13         guitype_new=plugin_get_gui_type(type);
14         if (! guitype_new)
15                 return NULL;
16
17         this_=g_new0(struct gui, 1);
18         this_->priv=guitype_new(nav, &this_->meth, w, h);
19         return this_;
20 }
21
22 struct statusbar *
23 gui_statusbar_new(struct gui *gui)
24 {
25         struct statusbar *this_;
26         if (! gui->meth.statusbar_new)
27                 return NULL;
28         this_=g_new0(struct statusbar, 1);
29         this_->priv=gui->meth.statusbar_new(gui->priv, &this_->meth);
30         if (! this_->priv) {
31                 g_free(this_);
32                 return NULL;
33         }
34         return this_;
35 }
36
37 struct menu *
38 gui_menubar_new(struct gui *gui)
39 {
40         struct menu *this_;
41         if (! gui->meth.menubar_new)
42                 return NULL;
43         this_=g_new0(struct menu, 1);
44         this_->priv=gui->meth.menubar_new(gui->priv, &this_->meth);
45         if (! this_->priv) {
46                 g_free(this_);
47                 return NULL;
48         }
49         return this_;
50 }
51
52
53 struct menu *
54 gui_toolbar_new(struct gui *gui)
55 {
56         struct menu *this_;
57         if (! gui->meth.toolbar_new)
58                 return NULL;
59         this_=g_new0(struct menu, 1);
60         this_->priv=gui->meth.toolbar_new(gui->priv, &this_->meth);
61         if (! this_->priv) {
62                 g_free(this_);
63                 return NULL;
64         }
65         return this_;
66 }
67
68 struct menu *
69 gui_popup_new(struct gui *gui)
70 {
71         struct menu *this_;
72         if (! gui->meth.popup_new)
73                 return NULL;
74         this_=g_new0(struct menu, 1);
75         this_->priv=gui->meth.popup_new(gui->priv, &this_->meth);
76         if (! this_->priv) {
77                 g_free(this_);
78                 return NULL;
79         }
80         return this_;
81 }
82
83 int
84 gui_set_graphics(struct gui *this_, struct graphics *gra)
85 {
86         if (! this_->meth.set_graphics)
87                 return 1;
88         return this_->meth.set_graphics(this_->priv, gra);
89 }
90
91 int
92 gui_has_main_loop(struct gui *this_)
93 {
94         if (! this_->meth.run_main_loop)
95                 return 0;
96         return 1;
97 }
98
99 int
100 gui_run_main_loop(struct gui *this_)
101 {
102         if (! gui_has_main_loop(this_))
103                 return 1;
104         return this_->meth.run_main_loop(this_->priv);
105 }
106