Parent Directory | Revision Log
Enabled api 0.6 support
1 | harbaum | 1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. | ||
3 | * | ||
4 | * This file is part of OSM2Go. | ||
5 | * | ||
6 | * OSM2Go is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation, either version 3 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * OSM2Go is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include "appdata.h" | ||
21 | |||
22 | static void on_info_clicked(GtkButton *button, gpointer data) { | ||
23 | appdata_t *appdata = (appdata_t*)data; | ||
24 | |||
25 | info_dialog(GTK_WIDGET(appdata->window), appdata, NULL); | ||
26 | } | ||
27 | |||
28 | static void on_node_add_clicked(GtkButton *button, gpointer data) { | ||
29 | map_action_set((appdata_t*)data, MAP_ACTION_NODE_ADD); | ||
30 | } | ||
31 | |||
32 | static void on_way_add_clicked(GtkButton *button, gpointer data) { | ||
33 | map_action_set((appdata_t*)data, MAP_ACTION_WAY_ADD); | ||
34 | } | ||
35 | |||
36 | static void on_way_node_add_clicked(GtkButton *button, gpointer data) { | ||
37 | map_action_set((appdata_t*)data, MAP_ACTION_WAY_NODE_ADD); | ||
38 | } | ||
39 | |||
40 | static void on_way_reverse_clicked(GtkButton *button, gpointer data) { | ||
41 | map_edit_way_reverse((appdata_t*)data); | ||
42 | } | ||
43 | |||
44 | static void on_way_cut_clicked(GtkButton *button, gpointer data) { | ||
45 | map_action_set((appdata_t*)data, MAP_ACTION_WAY_CUT); | ||
46 | } | ||
47 | |||
48 | static void on_relation_add_clicked(GtkButton *button, gpointer data) { | ||
49 | appdata_t *appdata = (appdata_t*)data; | ||
50 | |||
51 | harbaum | 154 | g_assert((appdata->map->selected.object.type == NODE) || |
52 | (appdata->map->selected.object.type == WAY)); | ||
53 | harbaum | 1 | |
54 | harbaum | 154 | relation_add_dialog(appdata, &appdata->map->selected.object); |
55 | harbaum | 1 | } |
56 | |||
57 | static void on_trash_clicked(GtkButton *button, gpointer data) { | ||
58 | map_delete_selected((appdata_t*)data); | ||
59 | } | ||
60 | |||
61 | static void on_ok_clicked(GtkButton *button, gpointer data) { | ||
62 | printf("User ok\n"); | ||
63 | map_action_ok((appdata_t*)data); | ||
64 | } | ||
65 | |||
66 | static void on_cancel_clicked(GtkButton *button, gpointer data) { | ||
67 | printf("User cancel\n"); | ||
68 | map_action_cancel((appdata_t*)data); | ||
69 | } | ||
70 | |||
71 | /* enable/disable ok and cancel button */ | ||
72 | void icon_bar_map_cancel_ok(appdata_t *appdata, | ||
73 | gboolean cancel, gboolean ok) { | ||
74 | iconbar_t *iconbar = appdata->iconbar; | ||
75 | gtk_widget_set_sensitive(iconbar->ok, ok); | ||
76 | gtk_widget_set_sensitive(iconbar->cancel, cancel); | ||
77 | } | ||
78 | |||
79 | void icon_bar_map_item_selected(appdata_t *appdata, | ||
80 | map_item_t *map_item, gboolean selected) { | ||
81 | iconbar_t *iconbar = appdata->iconbar; | ||
82 | |||
83 | harbaum | 153 | /* one can't remove relations by clicking this while they are */ |
84 | /* selected. May change in the future */ | ||
85 | harbaum | 154 | if(selected && (!map_item || map_item->object.type != RELATION)) |
86 | harbaum | 153 | gtk_widget_set_sensitive(iconbar->trash, TRUE); |
87 | else | ||
88 | gtk_widget_set_sensitive(iconbar->trash, FALSE); | ||
89 | harbaum | 1 | |
90 | harbaum | 153 | gtk_widget_set_sensitive(iconbar->info, map_item && selected); |
91 | harbaum | 1 | |
92 | harbaum | 153 | gtk_widget_set_sensitive(iconbar->relation_add, map_item && selected); |
93 | |||
94 | harbaum | 154 | if(selected && map_item && map_item->object.type == WAY) { |
95 | harbaum | 1 | gtk_widget_set_sensitive(iconbar->way_node_add, TRUE); |
96 | gtk_widget_set_sensitive(iconbar->way_cut, TRUE); | ||
97 | gtk_widget_set_sensitive(iconbar->way_reverse, TRUE); | ||
98 | } else { | ||
99 | gtk_widget_set_sensitive(iconbar->way_node_add, FALSE); | ||
100 | gtk_widget_set_sensitive(iconbar->way_cut, FALSE); | ||
101 | gtk_widget_set_sensitive(iconbar->way_reverse, FALSE); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /* if a user action is on progress, then disable all buttons that */ | ||
106 | /* cause an action to take place or interfere with the action */ | ||
107 | void icon_bar_map_action_idle(appdata_t *appdata, gboolean idle) { | ||
108 | gint i; | ||
109 | |||
110 | /* icons that are enabled in idle mode */ | ||
111 | GtkWidget *action_idle_widgets[] = { | ||
112 | appdata->iconbar->node_add, | ||
113 | appdata->iconbar->way_add, | ||
114 | NULL | ||
115 | }; | ||
116 | |||
117 | /* icons that are disabled in idle mode */ | ||
118 | GtkWidget *action_disable_widgets[] = { | ||
119 | appdata->iconbar->trash, | ||
120 | appdata->iconbar->info, | ||
121 | appdata->iconbar->relation_add, | ||
122 | NULL | ||
123 | }; | ||
124 | |||
125 | for(i=0;action_idle_widgets[i];i++) | ||
126 | gtk_widget_set_sensitive(action_idle_widgets[i], idle); | ||
127 | |||
128 | for(i=0;action_disable_widgets[i];i++) | ||
129 | gtk_widget_set_sensitive(action_disable_widgets[i], FALSE); | ||
130 | |||
131 | /* special handling for icons that depend on further state */ | ||
132 | if(!idle) { | ||
133 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, FALSE); | ||
134 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, FALSE); | ||
135 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, FALSE); | ||
136 | } else { | ||
137 | harbaum | 154 | if(appdata->map->selected.object.type == WAY) { |
138 | harbaum | 1 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, TRUE); |
139 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, TRUE); | ||
140 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, TRUE); | ||
141 | } else { | ||
142 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, FALSE); | ||
143 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, FALSE); | ||
144 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, FALSE); | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | GtkWidget *icon_add(GtkWidget *vbox, appdata_t *appdata, | ||
150 | char *icon_str, | ||
151 | void(*func)(GtkButton*, gpointer)) { | ||
152 | GtkWidget *but = gtk_button_new(); | ||
153 | GtkWidget *icon = gtk_image_new_from_pixbuf( | ||
154 | icon_load(&appdata->icon, icon_str)); | ||
155 | gtk_button_set_image(GTK_BUTTON(but), icon); | ||
156 | gtk_signal_connect(GTK_OBJECT(but), "clicked", | ||
157 | (GtkSignalFunc)func, appdata); | ||
158 | |||
159 | gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0); | ||
160 | return but; | ||
161 | } | ||
162 | |||
163 | static GtkWidget *tool_add(GtkWidget *toolbar, appdata_t *appdata, | ||
164 | harbaum | 15 | char *icon_str, |
165 | char *tooltip_str, | ||
166 | harbaum | 1 | void(*func)(GtkButton*, gpointer)) { |
167 | GtkWidget *item = | ||
168 | GTK_WIDGET(gtk_tool_button_new( | ||
169 | icon_widget_load(&appdata->icon, icon_str), NULL)); | ||
170 | |||
171 | harbaum | 18 | #ifndef USE_HILDON |
172 | harbaum | 15 | gtk_widget_set_tooltip_text(item, tooltip_str); |
173 | harbaum | 18 | #endif |
174 | harbaum | 15 | |
175 | harbaum | 1 | if(func) |
176 | gtk_signal_connect(GTK_OBJECT(item), "clicked", | ||
177 | (GtkSignalFunc)func, appdata); | ||
178 | |||
179 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); | ||
180 | |||
181 | harbaum | 164 | #ifdef USE_HILDON |
182 | #if MAEMO_VERSION_MAJOR == 5 | ||
183 | harbaum | 165 | gtk_widget_set_size_request(GTK_WIDGET(item), -1, 40); |
184 | harbaum | 164 | #endif |
185 | #endif | ||
186 | |||
187 | harbaum | 1 | return item; |
188 | } | ||
189 | |||
190 | GtkWidget *iconbar_new(appdata_t *appdata) { | ||
191 | appdata->iconbar = g_new0(iconbar_t, 1); | ||
192 | iconbar_t *iconbar = appdata->iconbar; | ||
193 | |||
194 | iconbar->toolbar = gtk_toolbar_new(); | ||
195 | |||
196 | #ifndef PORTRAIT | ||
197 | GtkWidget *box = gtk_vbox_new(FALSE, 0); | ||
198 | gtk_toolbar_set_orientation(GTK_TOOLBAR(iconbar->toolbar), | ||
199 | GTK_ORIENTATION_VERTICAL); | ||
200 | #else | ||
201 | GtkWidget *box = gtk_hbox_new(FALSE, 0); | ||
202 | #endif | ||
203 | |||
204 | gtk_toolbar_set_style(GTK_TOOLBAR(iconbar->toolbar), GTK_TOOLBAR_ICONS); | ||
205 | |||
206 | /* -------------------------------------------------------- */ | ||
207 | harbaum | 15 | iconbar->trash = tool_add(iconbar->toolbar, appdata, |
208 | harbaum | 22 | "trash", _("Delete item"), on_trash_clicked); |
209 | harbaum | 1 | |
210 | /* -------------------------------------------------------- */ | ||
211 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
212 | gtk_separator_tool_item_new(),-1); | ||
213 | harbaum | 22 | iconbar->info = tool_add(iconbar->toolbar, appdata, |
214 | "info", _("Properties"), on_info_clicked); | ||
215 | harbaum | 1 | |
216 | /* -------------------------------------------------------- */ | ||
217 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
218 | gtk_separator_tool_item_new(),-1); | ||
219 | |||
220 | harbaum | 22 | iconbar->node_add = tool_add(iconbar->toolbar, appdata, "node_add", |
221 | _("Add node"), on_node_add_clicked); | ||
222 | harbaum | 1 | |
223 | /* -------------------------------------------------------- */ | ||
224 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
225 | gtk_separator_tool_item_new(),-1); | ||
226 | |||
227 | harbaum | 22 | iconbar->way_add = tool_add(iconbar->toolbar, appdata, "way_add", |
228 | _("Add way"), on_way_add_clicked); | ||
229 | iconbar->way_node_add = tool_add(iconbar->toolbar, appdata, | ||
230 | "way_node_add", _("Add a node to a way"), on_way_node_add_clicked); | ||
231 | iconbar->way_cut = tool_add(iconbar->toolbar, appdata, | ||
232 | "way_cut", _("Split a way"), on_way_cut_clicked); | ||
233 | iconbar->way_reverse = tool_add(iconbar->toolbar, appdata, | ||
234 | "way_reverse", _("Reverse way"), on_way_reverse_clicked); | ||
235 | harbaum | 1 | |
236 | /* -------------------------------------------------------- */ | ||
237 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
238 | gtk_separator_tool_item_new(),-1); | ||
239 | |||
240 | harbaum | 22 | iconbar->relation_add = tool_add(iconbar->toolbar, appdata, |
241 | achadwick | 125 | "relation_add", _("Edit item's relations"), on_relation_add_clicked); |
242 | harbaum | 1 | |
243 | gtk_box_pack_start(GTK_BOX(box), iconbar->toolbar, TRUE, TRUE, 0); | ||
244 | |||
245 | /* -------------------------------------------------------- */ | ||
246 | |||
247 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); | ||
248 | harbaum | 164 | |
249 | #ifdef USE_HILDON | ||
250 | gtk_widget_set_size_request(GTK_WIDGET(hbox), -1, 32); | ||
251 | #endif | ||
252 | |||
253 | harbaum | 1 | iconbar->ok = icon_add(hbox, appdata, "ok", on_ok_clicked); |
254 | harbaum | 165 | // gtk_button_set_relief(GTK_BUTTON(iconbar->ok), GTK_RELIEF_NONE); |
255 | harbaum | 164 | #ifdef USE_HILDON |
256 | #if MAEMO_VERSION_MAJOR == 5 | ||
257 | harbaum | 165 | g_object_set(iconbar->ok, "border-width", 0, NULL ); |
258 | gtk_widget_set_size_request(GTK_WIDGET(iconbar->ok), 32, -1); | ||
259 | harbaum | 164 | #endif |
260 | #endif | ||
261 | |||
262 | harbaum | 1 | iconbar->cancel = icon_add(hbox, appdata, "cancel", on_cancel_clicked); |
263 | harbaum | 165 | // gtk_button_set_relief(GTK_BUTTON(iconbar->cancel), GTK_RELIEF_NONE); |
264 | harbaum | 164 | #ifdef USE_HILDON |
265 | #if MAEMO_VERSION_MAJOR == 5 | ||
266 | harbaum | 165 | g_object_set(iconbar->cancel, "border-width", 0, NULL ); |
267 | gtk_widget_set_size_request(GTK_WIDGET(iconbar->cancel), 32, -1); | ||
268 | harbaum | 164 | #endif |
269 | #endif | ||
270 | |||
271 | harbaum | 1 | gtk_box_pack_end(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
272 | |||
273 | /* --------------------------------------------------------- */ | ||
274 | |||
275 | icon_bar_map_item_selected(appdata, NULL, FALSE); | ||
276 | icon_bar_map_cancel_ok(appdata, FALSE, FALSE); | ||
277 | |||
278 | return box; | ||
279 | } | ||
280 | |||
281 | void iconbar_free(iconbar_t *iconbar) { | ||
282 | if(iconbar) | ||
283 | g_free(iconbar); | ||
284 | } |