]> git.street.me.uk Git - andy/viking.git/blob - src/vikstatus.c
Import Launchpad translation updates
[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
34 enum
35 {
36   CLICKED,
37   LAST_SIGNAL
38 };
39
40 struct _VikStatusbar {
41   GtkHBox hbox;
42   GtkWidget *status[VIK_STATUSBAR_NUM_TYPES];
43   gboolean empty[VIK_STATUSBAR_NUM_TYPES];
44 };
45
46 G_DEFINE_TYPE (VikStatusbar, vik_statusbar, GTK_TYPE_HBOX)
47
48 static guint vik_statusbar_signals[LAST_SIGNAL] = { 0 };
49
50 static gint
51 forward_signal (GtkObject *object, gpointer user_data)
52 {
53     gint item = GPOINTER_TO_INT (gtk_object_get_data ( object, "type" ));
54     VikStatusbar *vs = VIK_STATUSBAR (user_data);
55
56     g_signal_emit (G_OBJECT (vs),
57                    vik_statusbar_signals[CLICKED], 0,
58                    item);
59
60     return TRUE;
61 }
62
63 static void
64 vik_statusbar_class_init (VikStatusbarClass *klass)
65 {
66   vik_statusbar_signals[CLICKED] =
67     g_signal_new ("clicked",
68                   G_TYPE_FROM_CLASS (klass),
69                   G_SIGNAL_RUN_FIRST,
70                   G_STRUCT_OFFSET (VikStatusbarClass, clicked),
71                   NULL, NULL,
72                   g_cclosure_marshal_VOID__INT,
73                   G_TYPE_NONE, 1,
74                   G_TYPE_INT);
75
76   klass->clicked = NULL;
77 }
78
79 static void
80 vik_statusbar_init (VikStatusbar *vs)
81 {
82   gint i;
83
84   for ( i = 0; i < VIK_STATUSBAR_NUM_TYPES; i++ ) {
85     vs->empty[i] = TRUE;
86     
87     if (i == VIK_STATUSBAR_ZOOM)
88       vs->status[i] = gtk_button_new();
89     else
90     {
91       vs->status[i] = gtk_statusbar_new();
92       gtk_statusbar_set_has_resize_grip ( GTK_STATUSBAR(vs->status[i]), FALSE );
93     }
94     gtk_object_set_data (GTK_OBJECT (vs->status[i]), "type", GINT_TO_POINTER(i));
95   }
96
97   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_TOOL], FALSE, FALSE, 1);
98   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_TOOL], 150, -1 );
99
100   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ITEMS], FALSE, FALSE, 1);
101   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ITEMS], 100, -1 );
102
103   g_signal_connect ( G_OBJECT(vs->status[VIK_STATUSBAR_ZOOM]), "clicked", G_CALLBACK (forward_signal), vs);
104   gtk_button_set_relief ( GTK_BUTTON(vs->status[VIK_STATUSBAR_ZOOM]), GTK_RELIEF_NONE );
105   gtk_widget_set_tooltip_text (GTK_WIDGET (vs->status[VIK_STATUSBAR_ZOOM]), _("Current zoom level. Click to select a new one."));
106   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ZOOM], FALSE, FALSE, 1);
107   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ZOOM], 100, -1 );
108
109   gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_POSITION], FALSE, FALSE, 1);
110   gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_POSITION], 250, -1 );
111
112   gtk_box_pack_end ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_INFO], TRUE, TRUE, 1);
113
114   // Set minimum overall size
115   //  otherwise the individual size_requests above create an implicit overall size,
116   //  and so one can't downsize horizontally as much as may be desired when the statusbar is on
117   gtk_widget_set_size_request ( GTK_WIDGET(vs), 50, -1 );
118 }
119
120 /**
121  * vik_statusbar_new:
122  *
123  * Creates a new #VikStatusbar widget.
124  *
125  * Return value: the new #VikStatusbar widget.
126  **/
127 VikStatusbar *
128 vik_statusbar_new ()
129 {
130   VikStatusbar *vs = VIK_STATUSBAR ( g_object_new ( VIK_STATUSBAR_TYPE, NULL ) );
131
132   return vs;
133 }
134
135 /**
136  * vik_statusbar_set_message:
137  * @vs: the #VikStatusbar itself
138  * @field: the field to update
139  * @message: the message to use
140  *
141  * Update the message of the given field.
142  **/
143 void
144 vik_statusbar_set_message ( VikStatusbar *vs, vik_statusbar_type_t field, const gchar *message )
145 {
146   if ( field >= 0 && field < VIK_STATUSBAR_NUM_TYPES )
147   {
148     if ( field == VIK_STATUSBAR_ZOOM )
149     {
150       gtk_button_set_label ( GTK_BUTTON(vs->status[field]), message);
151     }
152     else
153     {
154     GtkStatusbar *gsb = GTK_STATUSBAR(vs->status[field]);
155
156     if ( !vs->empty[field] )
157       gtk_statusbar_pop ( gsb, 0 );
158     else
159       vs->empty[field] = FALSE;
160
161     gtk_statusbar_push ( gsb, 0, message );
162     }
163   }
164 }