Parent Directory | Revision Log
initial line mod support and some small fixes
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 | relation_item_t relitem; |
51 | |
52 | switch(appdata->map->selected.type) { |
53 | case MAP_TYPE_NODE: |
54 | relitem.type = NODE; |
55 | relitem.node = appdata->map->selected.node; |
56 | break; |
57 | |
58 | case MAP_TYPE_WAY: |
59 | relitem.type = WAY; |
60 | relitem.way = appdata->map->selected.way; |
61 | break; |
62 | |
63 | default: |
64 | break; |
65 | } |
66 | |
67 | relation_add_dialog(appdata, &relitem); |
68 | } |
69 | |
70 | static void on_trash_clicked(GtkButton *button, gpointer data) { |
71 | map_delete_selected((appdata_t*)data); |
72 | } |
73 | |
74 | static void on_ok_clicked(GtkButton *button, gpointer data) { |
75 | printf("User ok\n"); |
76 | map_action_ok((appdata_t*)data); |
77 | } |
78 | |
79 | static void on_cancel_clicked(GtkButton *button, gpointer data) { |
80 | printf("User cancel\n"); |
81 | map_action_cancel((appdata_t*)data); |
82 | } |
83 | |
84 | /* enable/disable ok and cancel button */ |
85 | void icon_bar_map_cancel_ok(appdata_t *appdata, |
86 | gboolean cancel, gboolean ok) { |
87 | iconbar_t *iconbar = appdata->iconbar; |
88 | gtk_widget_set_sensitive(iconbar->ok, ok); |
89 | gtk_widget_set_sensitive(iconbar->cancel, cancel); |
90 | } |
91 | |
92 | void icon_bar_map_item_selected(appdata_t *appdata, |
93 | map_item_t *map_item, gboolean selected) { |
94 | iconbar_t *iconbar = appdata->iconbar; |
95 | |
96 | gtk_widget_set_sensitive(iconbar->info, selected); |
97 | gtk_widget_set_sensitive(iconbar->trash, selected); |
98 | |
99 | gtk_widget_set_sensitive(iconbar->relation_add, selected); |
100 | |
101 | if(selected && map_item && map_item->type == MAP_TYPE_WAY) { |
102 | gtk_widget_set_sensitive(iconbar->way_node_add, TRUE); |
103 | gtk_widget_set_sensitive(iconbar->way_cut, TRUE); |
104 | gtk_widget_set_sensitive(iconbar->way_reverse, TRUE); |
105 | } else { |
106 | gtk_widget_set_sensitive(iconbar->way_node_add, FALSE); |
107 | gtk_widget_set_sensitive(iconbar->way_cut, FALSE); |
108 | gtk_widget_set_sensitive(iconbar->way_reverse, FALSE); |
109 | } |
110 | } |
111 | |
112 | /* if a user action is on progress, then disable all buttons that */ |
113 | /* cause an action to take place or interfere with the action */ |
114 | void icon_bar_map_action_idle(appdata_t *appdata, gboolean idle) { |
115 | gint i; |
116 | |
117 | /* icons that are enabled in idle mode */ |
118 | GtkWidget *action_idle_widgets[] = { |
119 | appdata->iconbar->node_add, |
120 | appdata->iconbar->way_add, |
121 | NULL |
122 | }; |
123 | |
124 | /* icons that are disabled in idle mode */ |
125 | GtkWidget *action_disable_widgets[] = { |
126 | appdata->iconbar->trash, |
127 | appdata->iconbar->info, |
128 | appdata->iconbar->relation_add, |
129 | NULL |
130 | }; |
131 | |
132 | for(i=0;action_idle_widgets[i];i++) |
133 | gtk_widget_set_sensitive(action_idle_widgets[i], idle); |
134 | |
135 | for(i=0;action_disable_widgets[i];i++) |
136 | gtk_widget_set_sensitive(action_disable_widgets[i], FALSE); |
137 | |
138 | /* special handling for icons that depend on further state */ |
139 | if(!idle) { |
140 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, FALSE); |
141 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, FALSE); |
142 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, FALSE); |
143 | } else { |
144 | if(appdata->map->selected.type == MAP_TYPE_WAY) { |
145 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, TRUE); |
146 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, TRUE); |
147 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, TRUE); |
148 | } else { |
149 | gtk_widget_set_sensitive(appdata->iconbar->way_node_add, FALSE); |
150 | gtk_widget_set_sensitive(appdata->iconbar->way_cut, FALSE); |
151 | gtk_widget_set_sensitive(appdata->iconbar->way_reverse, FALSE); |
152 | } |
153 | } |
154 | } |
155 | |
156 | GtkWidget *icon_add(GtkWidget *vbox, appdata_t *appdata, |
157 | char *icon_str, |
158 | void(*func)(GtkButton*, gpointer)) { |
159 | GtkWidget *but = gtk_button_new(); |
160 | GtkWidget *icon = gtk_image_new_from_pixbuf( |
161 | icon_load(&appdata->icon, icon_str)); |
162 | gtk_button_set_image(GTK_BUTTON(but), icon); |
163 | gtk_signal_connect(GTK_OBJECT(but), "clicked", |
164 | (GtkSignalFunc)func, appdata); |
165 | |
166 | gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0); |
167 | return but; |
168 | } |
169 | |
170 | static GtkWidget *tool_add(GtkWidget *toolbar, appdata_t *appdata, |
171 | char *icon_str, |
172 | char *tooltip_str, |
173 | void(*func)(GtkButton*, gpointer)) { |
174 | GtkWidget *item = |
175 | GTK_WIDGET(gtk_tool_button_new( |
176 | icon_widget_load(&appdata->icon, icon_str), NULL)); |
177 | |
178 | gtk_widget_set_tooltip_text(item, tooltip_str); |
179 | |
180 | if(func) |
181 | gtk_signal_connect(GTK_OBJECT(item), "clicked", |
182 | (GtkSignalFunc)func, appdata); |
183 | |
184 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); |
185 | |
186 | return item; |
187 | } |
188 | |
189 | GtkWidget *iconbar_new(appdata_t *appdata) { |
190 | appdata->iconbar = g_new0(iconbar_t, 1); |
191 | iconbar_t *iconbar = appdata->iconbar; |
192 | |
193 | iconbar->toolbar = gtk_toolbar_new(); |
194 | |
195 | #ifndef PORTRAIT |
196 | GtkWidget *box = gtk_vbox_new(FALSE, 0); |
197 | gtk_toolbar_set_orientation(GTK_TOOLBAR(iconbar->toolbar), |
198 | GTK_ORIENTATION_VERTICAL); |
199 | #else |
200 | GtkWidget *box = gtk_hbox_new(FALSE, 0); |
201 | #endif |
202 | |
203 | gtk_toolbar_set_style(GTK_TOOLBAR(iconbar->toolbar), GTK_TOOLBAR_ICONS); |
204 | |
205 | /* -------------------------------------------------------- */ |
206 | iconbar->trash = tool_add(iconbar->toolbar, appdata, |
207 | "trash", "Delete item", on_trash_clicked); |
208 | |
209 | /* -------------------------------------------------------- */ |
210 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), |
211 | gtk_separator_tool_item_new(),-1); |
212 | iconbar->info = tool_add(iconbar->toolbar, appdata, "info", _("Properties"), on_info_clicked); |
213 | |
214 | /* -------------------------------------------------------- */ |
215 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), |
216 | gtk_separator_tool_item_new(),-1); |
217 | |
218 | iconbar->node_add = tool_add(iconbar->toolbar, appdata, "node_add", _("Add node"), |
219 | on_node_add_clicked); |
220 | |
221 | /* -------------------------------------------------------- */ |
222 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), |
223 | gtk_separator_tool_item_new(),-1); |
224 | |
225 | iconbar->way_add = tool_add(iconbar->toolbar, appdata, "way_add", _("Add way"), |
226 | on_way_add_clicked); |
227 | iconbar->way_node_add = tool_add(iconbar->toolbar, appdata, "way_node_add", _("Add a node to a way"), |
228 | on_way_node_add_clicked); |
229 | iconbar->way_cut = tool_add(iconbar->toolbar, appdata, "way_cut", _("Split way at a given node"), |
230 | on_way_cut_clicked); |
231 | iconbar->way_reverse = tool_add(iconbar->toolbar, appdata, "way_reverse", _("Reverse way"), |
232 | on_way_reverse_clicked); |
233 | |
234 | /* -------------------------------------------------------- */ |
235 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), |
236 | gtk_separator_tool_item_new(),-1); |
237 | |
238 | iconbar->relation_add = tool_add(iconbar->toolbar, appdata, "relation_add", _("Add relation"), |
239 | on_relation_add_clicked); |
240 | |
241 | gtk_box_pack_start(GTK_BOX(box), iconbar->toolbar, TRUE, TRUE, 0); |
242 | |
243 | /* -------------------------------------------------------- */ |
244 | |
245 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
246 | iconbar->ok = icon_add(hbox, appdata, "ok", on_ok_clicked); |
247 | iconbar->cancel = icon_add(hbox, appdata, "cancel", on_cancel_clicked); |
248 | gtk_box_pack_end(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
249 | |
250 | /* --------------------------------------------------------- */ |
251 | |
252 | icon_bar_map_item_selected(appdata, NULL, FALSE); |
253 | icon_bar_map_cancel_ok(appdata, FALSE, FALSE); |
254 | |
255 | return box; |
256 | } |
257 | |
258 | void iconbar_free(iconbar_t *iconbar) { |
259 | if(iconbar) |
260 | g_free(iconbar); |
261 | } |