]> git.street.me.uk Git - andy/viking.git/blob - src/vikstatus.c
Fix needing to calculate bounds of *both* tracks when a track is split via the marker.
[andy/viking.git] / src / vikstatus.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5  * Copyright (C) 2011, Rob Norris <rw_norris@hotmail.com>
6  * Copyright (C) 2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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
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... */
26 #include <gtk/gtk.h>
27
28 #include <glib/gi18n.h>
29
30 #include <math.h>
31
32 #include "vikstatus.h"
33 #include "background.h"
34
35 enum
36 {
37   CLICKED,
38   LAST_SIGNAL
39 };
40
41 struct _VikStatusbar {
42   GtkHBox hbox;
43   GtkWidget *status[VIK_STATUSBAR_NUM_TYPES];
44   gboolean empty[VIK_STATUSBAR_NUM_TYPES];
45 };
46
47 G_DEFINE_TYPE (VikStatusbar, vik_statusbar, GTK_TYPE_HBOX)
48
49 static guint vik_statusbar_signals[LAST_SIGNAL] = { 0 };
50
51 static gint
52 forward_signal (GObject *object, gpointer user_data)
53 {
54     gint item = GPOINTER_TO_INT (g_object_get_data ( object, "type" ));
55     VikStatusbar *vs = VIK_STATUSBAR (user_data);
56
57     // Clicking on the items field will bring up the background jobs window
58     if ( item == VIK_STATUSBAR_ITEMS )
59       a_background_show_window();
60     else
61       g_signal_emit (G_OBJECT (vs),
62                      vik_statusbar_signals[CLICKED], 0,
63                      item);
64
65     return TRUE;
66 }
67
68 static void
69 vik_statusbar_class_init (VikStatusbarClass *klass)
70 {
71   vik_statusbar_signals[CLICKED] =
72     g_signal_new ("clicked",
73                   G_TYPE_FROM_CLASS (klass),
74                   G_SIGNAL_RUN_FIRST,
75                   G_STRUCT_OFFSET (VikStatusbarClass, clicked),
76                   NULL, NULL,
77                   g_cclosure_marshal_VOID__INT,
78                   G_TYPE_NONE, 1,
79                   G_TYPE_INT);
80
81   klass->clicked = NULL;
82 }
83
84 static void
85 vik_statusbar_init (VikStatusbar *vs)
86 {
87   gint i;
88
89   for ( i = 0; i < VIK_STATUSBAR_NUM_TYPES; i++ ) {
90     vs->empty[i] = TRUE;
91     
92     if (i == VIK_STATUSBAR_ITEMS || i == VIK_STATUSBAR_ZOOM )
93       vs->status[i] = gtk_button_new();
94     else
95     {
96       vs->status[i] = gtk_statusbar_new();
97       gtk_statusbar_set_has_resize_grip ( GTK_STATUSBAR(vs->status[i]), FALSE );
98     }
99     g_object_set_data (G_OBJECT (vs->status[i]), "type", GINT_TO_POINTER(i));
100   }
101
102   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_TOOL], FALSE, FALSE, 1);
103   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_TOOL], 125, -1 );
104
105   g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_ITEMS]), "clicked", G_CALLBACK (forward_signal), vs);
106   gtk_button_set_relief ( GTK_BUTTON(vs->status[VIK_STATUSBAR_ITEMS]), GTK_RELIEF_NONE );
107   gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_ITEMS]), _("Current number of background tasks. Click to see the background jobs."));
108   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ITEMS], FALSE, FALSE, 1);
109   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ITEMS], 100, -1 );
110
111   g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_ZOOM]), "clicked", G_CALLBACK (forward_signal), vs);
112   gtk_button_set_relief ( GTK_BUTTON(vs->status[VIK_STATUSBAR_ZOOM]), GTK_RELIEF_NONE );
113   gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_ZOOM]), _("Current zoom level. Click to select a new one."));
114   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ZOOM], FALSE, FALSE, 1);
115   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ZOOM], 100, -1 );
116
117   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_POSITION], FALSE, FALSE, 1);
118   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_POSITION], 275, -1 );
119
120   gtk_box_pack_end ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_INFO], TRUE, TRUE, 1);
121
122   // Set minimum overall size
123   //  otherwise the individual size_requests above create an implicit overall size,
124   //  and so one can't downsize horizontally as much as may be desired when the statusbar is on
125   gtk_widget_set_size_request ( GTK_WIDGET(vs), 50, -1 );
126 }
127
128 /**
129  * vik_statusbar_new:
130  *
131  * Creates a new #VikStatusbar widget.
132  *
133  * Return value: the new #VikStatusbar widget.
134  **/
135 VikStatusbar *
136 vik_statusbar_new ()
137 {
138   VikStatusbar *vs = VIK_STATUSBAR ( g_object_new ( VIK_STATUSBAR_TYPE, NULL ) );
139
140   return vs;
141 }
142
143 /**
144  * vik_statusbar_set_message:
145  * @vs: the #VikStatusbar itself
146  * @field: the field to update
147  * @message: the message to use
148  *
149  * Update the message of the given field.
150  **/
151 void
152 vik_statusbar_set_message ( VikStatusbar *vs, vik_statusbar_type_t field, const gchar *message )
153 {
154   if ( field >= 0 && field < VIK_STATUSBAR_NUM_TYPES )
155   {
156     if ( field == VIK_STATUSBAR_ITEMS || field == VIK_STATUSBAR_ZOOM  )
157     {
158       gtk_button_set_label ( GTK_BUTTON(vs->status[field]), message);
159     }
160     else
161     {
162     GtkStatusbar *gsb = GTK_STATUSBAR(vs->status[field]);
163
164     if ( !vs->empty[field] )
165       gtk_statusbar_pop ( gsb, 0 );
166     else
167       vs->empty[field] = FALSE;
168
169     gtk_statusbar_push ( gsb, 0, message );
170     }
171   }
172 }