]>
Commit | Line | Data |
---|---|---|
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 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | */ | |
22 | ||
23 | /* gtk status bars: just plain dumb. this file shouldn't have to exist. | |
24 | NB as of gtk 2.18 there are 'info bars' that could be useful... */ | |
25 | #include <gtk/gtk.h> | |
26 | ||
27 | #include "vikstatus.h" | |
28 | ||
29 | struct _VikStatusbar { | |
30 | GtkHBox hbox; | |
31 | GtkWidget *status[VIK_STATUSBAR_NUM_TYPES]; | |
32 | gboolean empty[VIK_STATUSBAR_NUM_TYPES]; | |
33 | }; | |
34 | ||
35 | GType vik_statusbar_get_type (void) | |
36 | { | |
37 | static GType vs_type = 0; | |
38 | ||
39 | if (!vs_type) | |
40 | { | |
41 | static const GTypeInfo vs_info = | |
42 | { | |
43 | sizeof (VikStatusbarClass), | |
44 | NULL, /* base_init */ | |
45 | NULL, /* base_finalize */ | |
46 | NULL, /* class init */ | |
47 | NULL, /* class_finalize */ | |
48 | NULL, /* class_data */ | |
49 | sizeof (VikStatusbar), | |
50 | 0, | |
51 | NULL /* instance init */ | |
52 | }; | |
53 | vs_type = g_type_register_static ( GTK_TYPE_HBOX, "VikStatusbar", &vs_info, 0 ); | |
54 | } | |
55 | ||
56 | return vs_type; | |
57 | } | |
58 | ||
59 | /** | |
60 | * vik_statusbar_new: | |
61 | * | |
62 | * Creates a new #VikStatusbar widget. | |
63 | * | |
64 | * Return value: the new #VikStatusbar widget. | |
65 | **/ | |
66 | VikStatusbar *vik_statusbar_new () | |
67 | { | |
68 | VikStatusbar *vs = VIK_STATUSBAR ( g_object_new ( VIK_STATUSBAR_TYPE, NULL ) ); | |
69 | gint i; | |
70 | ||
71 | for ( i = 0; i < VIK_STATUSBAR_NUM_TYPES; i++ ) { | |
72 | vs->empty[i] = TRUE; | |
73 | vs->status[i] = gtk_statusbar_new(); | |
74 | gtk_statusbar_set_has_resize_grip ( GTK_STATUSBAR(vs->status[i]), FALSE ); | |
75 | } | |
76 | ||
77 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_TOOL], FALSE, FALSE, 1); | |
78 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_TOOL], 150, -1 ); | |
79 | ||
80 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ITEMS], FALSE, FALSE, 1); | |
81 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ITEMS], 100, -1 ); | |
82 | ||
83 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_ZOOM], FALSE, FALSE, 1); | |
84 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_ZOOM], 100, -1 ); | |
85 | ||
86 | gtk_box_pack_start ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_POSITION], FALSE, FALSE, 1); | |
87 | gtk_widget_set_size_request ( vs->status[VIK_STATUSBAR_POSITION], 250, -1 ); | |
88 | ||
89 | gtk_box_pack_end ( GTK_BOX(vs), vs->status[VIK_STATUSBAR_INFO], TRUE, TRUE, 1); | |
90 | ||
91 | // Set minimum overall size | |
92 | // otherwise the individual size_requests above create an implicit overall size, | |
93 | // and so one can't downsize horizontally as much as may be desired when the statusbar is on | |
94 | gtk_widget_set_size_request ( GTK_WIDGET(vs), 50, -1 ); | |
95 | ||
96 | return vs; | |
97 | } | |
98 | ||
99 | /** | |
100 | * vik_statusbar_set_message: | |
101 | * @vs: the #VikStatusbar itself | |
102 | * @field: the field to update | |
103 | * @message: the message to use | |
104 | * | |
105 | * Update the message of the given field. | |
106 | **/ | |
107 | void vik_statusbar_set_message ( VikStatusbar *vs, vik_statusbar_type_t field, const gchar *message ) | |
108 | { | |
109 | if ( field >= 0 && field < VIK_STATUSBAR_NUM_TYPES ) | |
110 | { | |
111 | GtkStatusbar *gsb = GTK_STATUSBAR(vs->status[field]); | |
112 | ||
113 | if ( !vs->empty[field] ) | |
114 | gtk_statusbar_pop ( gsb, 0 ); | |
115 | else | |
116 | vs->empty[field] = FALSE; | |
117 | ||
118 | gtk_statusbar_push ( gsb, 0, message ); | |
119 | } | |
120 | } |