]>
Commit | Line | Data |
---|---|---|
50a14534 EB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net> | |
4efc10ca | 5 | * Copyright (C) 2011, Rob Norris <rw_norris@hotmail.com> |
c4b6a67d | 6 | * Copyright (C) 2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
50a14534 EB |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | */ | |
23 | ||
4efc10ca RN |
24 | /* gtk status bars: just plain dumb. this file shouldn't have to exist. |
25 | NB as of gtk 2.18 there are 'info bars' that could be useful... */ | |
50a14534 EB |
26 | #include <gtk/gtk.h> |
27 | ||
c4b6a67d GB |
28 | #include <glib/gi18n.h> |
29 | ||
30 | #include <math.h> | |
31 | ||
50a14534 | 32 | #include "vikstatus.h" |
9fbae581 | 33 | #include "background.h" |
50a14534 | 34 | |
c4b6a67d GB |
35 | enum |
36 | { | |
5c0bf50b | 37 | CLICKED, |
c4b6a67d GB |
38 | LAST_SIGNAL |
39 | }; | |
40 | ||
50a14534 | 41 | struct _VikStatusbar { |
4efc10ca RN |
42 | GtkHBox hbox; |
43 | GtkWidget *status[VIK_STATUSBAR_NUM_TYPES]; | |
44 | gboolean empty[VIK_STATUSBAR_NUM_TYPES]; | |
50a14534 EB |
45 | }; |
46 | ||
c4b6a67d GB |
47 | G_DEFINE_TYPE (VikStatusbar, vik_statusbar, GTK_TYPE_HBOX) |
48 | ||
49 | static guint vik_statusbar_signals[LAST_SIGNAL] = { 0 }; | |
50 | ||
c4b6a67d | 51 | static gint |
74dd7f07 | 52 | forward_signal (GObject *object, gpointer user_data) |
c4b6a67d | 53 | { |
74dd7f07 | 54 | gint item = GPOINTER_TO_INT (g_object_get_data ( object, "type" )); |
5c0bf50b | 55 | VikStatusbar *vs = VIK_STATUSBAR (user_data); |
c4b6a67d | 56 | |
9fbae581 RN |
57 | // Clicking on the items field will bring up the background jobs window |
58 | if ( item == VIK_STATUSBAR_ITEMS ) | |
59 | a_background_show_window(); | |
a9eda0af RN |
60 | else if ( item == VIK_STATUSBAR_INFO ) |
61 | // Clear current info message | |
62 | vik_statusbar_set_message ( vs, VIK_STATUSBAR_INFO, "" ); | |
9fbae581 RN |
63 | else |
64 | g_signal_emit (G_OBJECT (vs), | |
65 | vik_statusbar_signals[CLICKED], 0, | |
66 | item); | |
c4b6a67d | 67 | |
5c0bf50b | 68 | return TRUE; |
c4b6a67d | 69 | } |
50a14534 | 70 | |
c4b6a67d GB |
71 | static void |
72 | vik_statusbar_class_init (VikStatusbarClass *klass) | |
73 | { | |
5c0bf50b GB |
74 | vik_statusbar_signals[CLICKED] = |
75 | g_signal_new ("clicked", | |
c4b6a67d GB |
76 | G_TYPE_FROM_CLASS (klass), |
77 | G_SIGNAL_RUN_FIRST, | |
5c0bf50b | 78 | G_STRUCT_OFFSET (VikStatusbarClass, clicked), |
c4b6a67d | 79 | NULL, NULL, |
5c0bf50b | 80 | g_cclosure_marshal_VOID__INT, |
c4b6a67d | 81 | G_TYPE_NONE, 1, |
5c0bf50b | 82 | G_TYPE_INT); |
c4b6a67d | 83 | |
5c0bf50b | 84 | klass->clicked = NULL; |
50a14534 EB |
85 | } |
86 | ||
a9eda0af RN |
87 | static gboolean button_release_event (GtkWidget* widget, GdkEvent *event, gpointer *user_data) |
88 | { | |
89 | if ( ((GdkEventButton*)event)->button == 3 ) { | |
90 | gint type = GPOINTER_TO_INT (g_object_get_data ( G_OBJECT(widget), "type" )); | |
91 | VikStatusbar *vs = VIK_STATUSBAR (user_data); | |
92 | // Right Click: so copy the text in the INFO buffer only ATM | |
93 | if ( type == VIK_STATUSBAR_INFO ) { | |
94 | const gchar* msg = gtk_button_get_label (GTK_BUTTON(vs->status[VIK_STATUSBAR_INFO])); | |
95 | if ( msg ) { | |
96 | GtkClipboard *clipboard = gtk_clipboard_get ( GDK_SELECTION_CLIPBOARD ); | |
97 | gtk_clipboard_set_text ( clipboard, msg, -1 ); | |
98 | } | |
99 | } | |
100 | // We've handled the event | |
101 | return TRUE; | |
102 | } | |
103 | // Otherwise carry on with other event handlers - i.e. ensure forward_signal() is called | |
104 | return FALSE; | |
105 | } | |
106 | ||
c4b6a67d GB |
107 | static void |
108 | vik_statusbar_init (VikStatusbar *vs) | |
50a14534 | 109 | { |
50a14534 EB |
110 | gint i; |
111 | ||
4efc10ca RN |
112 | for ( i = 0; i < VIK_STATUSBAR_NUM_TYPES; i++ ) { |
113 | vs->empty[i] = TRUE; | |
c4b6a67d | 114 | |
a9eda0af | 115 | if (i == VIK_STATUSBAR_ITEMS || i == VIK_STATUSBAR_ZOOM || i == VIK_STATUSBAR_INFO ) |
c4b6a67d GB |
116 | vs->status[i] = gtk_button_new(); |
117 | else | |
118 | { | |
119 | vs->status[i] = gtk_statusbar_new(); | |
120 | gtk_statusbar_set_has_resize_grip ( GTK_STATUSBAR(vs->status[i]), FALSE ); | |
121 | } | |
74dd7f07 | 122 | g_object_set_data (G_OBJECT (vs->status[i]), "type", GINT_TO_POINTER(i)); |
4efc10ca RN |
123 | } |
124 | ||
125 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_TOOL], FALSE, FALSE, 1); | |
81eb3c04 | 126 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_TOOL], 125, -1 ); |
50a14534 | 127 | |
9fbae581 RN |
128 | g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_ITEMS]), "clicked", G_CALLBACK (forward_signal), vs); |
129 | gtk_button_set_relief ( GTK_BUTTON(vs->status[VIK_STATUSBAR_ITEMS]), GTK_RELIEF_NONE ); | |
130 | gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_ITEMS]), _("Current number of background tasks. Click to see the background jobs.")); | |
4efc10ca RN |
131 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ITEMS], FALSE, FALSE, 1); |
132 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ITEMS], 100, -1 ); | |
50a14534 | 133 | |
5c0bf50b | 134 | g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_ZOOM]), "clicked", G_CALLBACK (forward_signal), vs); |
c4b6a67d GB |
135 | gtk_button_set_relief ( GTK_BUTTON(vs->status[VIK_STATUSBAR_ZOOM]), GTK_RELIEF_NONE ); |
136 | gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_ZOOM]), _("Current zoom level. Click to select a new one.")); | |
4efc10ca RN |
137 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ZOOM], FALSE, FALSE, 1); |
138 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ZOOM], 100, -1 ); | |
50a14534 | 139 | |
4efc10ca | 140 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_POSITION], FALSE, FALSE, 1); |
81eb3c04 | 141 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_POSITION], 275, -1 ); |
50a14534 | 142 | |
a9eda0af RN |
143 | g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_INFO]), "button-release-event", G_CALLBACK (button_release_event), vs); |
144 | g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_INFO]), "clicked", G_CALLBACK (forward_signal), vs); | |
145 | gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_INFO]), _("Left click to clear the message. Right click to copy the message.")); | |
146 | gtk_button_set_alignment ( GTK_BUTTON(vs->status[VIK_STATUSBAR_INFO]), 0.0, 0.5 ); // Left align the text | |
4efc10ca | 147 | gtk_box_pack_end ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_INFO], TRUE, TRUE, 1); |
50a14534 | 148 | |
4efc10ca RN |
149 | // Set minimum overall size |
150 | // otherwise the individual size_requests above create an implicit overall size, | |
151 | // and so one can't downsize horizontally as much as may be desired when the statusbar is on | |
152 | gtk_widget_set_size_request ( GTK_WIDGET(vs), 50, -1 ); | |
c4b6a67d GB |
153 | } |
154 | ||
155 | /** | |
156 | * vik_statusbar_new: | |
157 | * | |
158 | * Creates a new #VikStatusbar widget. | |
159 | * | |
160 | * Return value: the new #VikStatusbar widget. | |
161 | **/ | |
162 | VikStatusbar * | |
163 | vik_statusbar_new () | |
164 | { | |
165 | VikStatusbar *vs = VIK_STATUSBAR ( g_object_new ( VIK_STATUSBAR_TYPE, NULL ) ); | |
50a14534 EB |
166 | |
167 | return vs; | |
168 | } | |
169 | ||
4fedc732 GB |
170 | /** |
171 | * vik_statusbar_set_message: | |
172 | * @vs: the #VikStatusbar itself | |
173 | * @field: the field to update | |
174 | * @message: the message to use | |
175 | * | |
176 | * Update the message of the given field. | |
177 | **/ | |
c4b6a67d GB |
178 | void |
179 | vik_statusbar_set_message ( VikStatusbar *vs, vik_statusbar_type_t field, const gchar *message ) | |
50a14534 | 180 | { |
4efc10ca | 181 | if ( field >= 0 && field < VIK_STATUSBAR_NUM_TYPES ) |
50a14534 | 182 | { |
a9eda0af | 183 | if ( field == VIK_STATUSBAR_ITEMS || field == VIK_STATUSBAR_ZOOM || field == VIK_STATUSBAR_INFO ) |
c4b6a67d GB |
184 | { |
185 | gtk_button_set_label ( GTK_BUTTON(vs->status[field]), message); | |
186 | } | |
187 | else | |
188 | { | |
4efc10ca | 189 | GtkStatusbar *gsb = GTK_STATUSBAR(vs->status[field]); |
50a14534 EB |
190 | |
191 | if ( !vs->empty[field] ) | |
192 | gtk_statusbar_pop ( gsb, 0 ); | |
193 | else | |
194 | vs->empty[field] = FALSE; | |
195 | ||
196 | gtk_statusbar_push ( gsb, 0, message ); | |
c4b6a67d | 197 | } |
50a14534 EB |
198 | } |
199 | } |