Parent Directory | Revision Log
Color system cleaned up, desktop fullscreen
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 | 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 | harbaum | 15 | char *icon_str, |
172 | char *tooltip_str, | ||
173 | harbaum | 1 | 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 | harbaum | 18 | #ifndef USE_HILDON |
179 | harbaum | 15 | gtk_widget_set_tooltip_text(item, tooltip_str); |
180 | harbaum | 18 | #endif |
181 | harbaum | 15 | |
182 | harbaum | 1 | if(func) |
183 | gtk_signal_connect(GTK_OBJECT(item), "clicked", | ||
184 | (GtkSignalFunc)func, appdata); | ||
185 | |||
186 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); | ||
187 | |||
188 | return item; | ||
189 | } | ||
190 | |||
191 | GtkWidget *iconbar_new(appdata_t *appdata) { | ||
192 | appdata->iconbar = g_new0(iconbar_t, 1); | ||
193 | iconbar_t *iconbar = appdata->iconbar; | ||
194 | |||
195 | iconbar->toolbar = gtk_toolbar_new(); | ||
196 | |||
197 | #ifndef PORTRAIT | ||
198 | GtkWidget *box = gtk_vbox_new(FALSE, 0); | ||
199 | gtk_toolbar_set_orientation(GTK_TOOLBAR(iconbar->toolbar), | ||
200 | GTK_ORIENTATION_VERTICAL); | ||
201 | #else | ||
202 | GtkWidget *box = gtk_hbox_new(FALSE, 0); | ||
203 | #endif | ||
204 | |||
205 | gtk_toolbar_set_style(GTK_TOOLBAR(iconbar->toolbar), GTK_TOOLBAR_ICONS); | ||
206 | |||
207 | /* -------------------------------------------------------- */ | ||
208 | harbaum | 15 | iconbar->trash = tool_add(iconbar->toolbar, appdata, |
209 | harbaum | 22 | "trash", _("Delete item"), on_trash_clicked); |
210 | harbaum | 1 | |
211 | /* -------------------------------------------------------- */ | ||
212 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
213 | gtk_separator_tool_item_new(),-1); | ||
214 | harbaum | 22 | iconbar->info = tool_add(iconbar->toolbar, appdata, |
215 | "info", _("Properties"), on_info_clicked); | ||
216 | harbaum | 1 | |
217 | /* -------------------------------------------------------- */ | ||
218 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
219 | gtk_separator_tool_item_new(),-1); | ||
220 | |||
221 | harbaum | 22 | iconbar->node_add = tool_add(iconbar->toolbar, appdata, "node_add", |
222 | _("Add node"), on_node_add_clicked); | ||
223 | harbaum | 1 | |
224 | /* -------------------------------------------------------- */ | ||
225 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
226 | gtk_separator_tool_item_new(),-1); | ||
227 | |||
228 | harbaum | 22 | iconbar->way_add = tool_add(iconbar->toolbar, appdata, "way_add", |
229 | _("Add way"), on_way_add_clicked); | ||
230 | iconbar->way_node_add = tool_add(iconbar->toolbar, appdata, | ||
231 | "way_node_add", _("Add a node to a way"), on_way_node_add_clicked); | ||
232 | iconbar->way_cut = tool_add(iconbar->toolbar, appdata, | ||
233 | "way_cut", _("Split a way"), on_way_cut_clicked); | ||
234 | iconbar->way_reverse = tool_add(iconbar->toolbar, appdata, | ||
235 | "way_reverse", _("Reverse way"), on_way_reverse_clicked); | ||
236 | harbaum | 1 | |
237 | /* -------------------------------------------------------- */ | ||
238 | gtk_toolbar_insert(GTK_TOOLBAR(iconbar->toolbar), | ||
239 | gtk_separator_tool_item_new(),-1); | ||
240 | |||
241 | harbaum | 22 | iconbar->relation_add = tool_add(iconbar->toolbar, appdata, |
242 | "relation_add", _("Edit items relations"), on_relation_add_clicked); | ||
243 | harbaum | 1 | |
244 | gtk_box_pack_start(GTK_BOX(box), iconbar->toolbar, TRUE, TRUE, 0); | ||
245 | |||
246 | /* -------------------------------------------------------- */ | ||
247 | |||
248 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); | ||
249 | iconbar->ok = icon_add(hbox, appdata, "ok", on_ok_clicked); | ||
250 | iconbar->cancel = icon_add(hbox, appdata, "cancel", on_cancel_clicked); | ||
251 | gtk_box_pack_end(GTK_BOX(box), hbox, FALSE, FALSE, 0); | ||
252 | |||
253 | /* --------------------------------------------------------- */ | ||
254 | |||
255 | icon_bar_map_item_selected(appdata, NULL, FALSE); | ||
256 | icon_bar_map_cancel_ok(appdata, FALSE, FALSE); | ||
257 | |||
258 | return box; | ||
259 | } | ||
260 | |||
261 | void iconbar_free(iconbar_t *iconbar) { | ||
262 | if(iconbar) | ||
263 | g_free(iconbar); | ||
264 | } |