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