Contents of /trunk/src/statusbar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 195 - (show annotations)
Wed Jul 8 08:51:02 2009 UTC (14 years, 11 months ago) by harbaum
File MIME type: text/plain
File size: 5327 byte(s)
Speaking names in status bar
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 #if !defined(USE_HILDON) || (MAEMO_VERSION_MAJOR < 5)
23 void statusbar_highlight(appdata_t *appdata, gboolean highlight) {
24 if(highlight) {
25 GdkColor color;
26 gdk_color_parse("red", &color);
27 gtk_widget_modify_bg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
28 gtk_widget_modify_base(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
29 gtk_widget_modify_fg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
30 } else
31 gtk_widget_modify_bg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, NULL);
32 }
33
34
35 // Set the persistent message, replacing anything currently there.
36 void statusbar_set(appdata_t *appdata, const char *msg, gboolean highlight) {
37 statusbar_highlight(appdata, highlight);
38
39 printf("statusbar_set: %s\n", msg);
40
41 if (appdata->statusbar->mid) {
42 gtk_statusbar_remove(GTK_STATUSBAR(appdata->statusbar->widget),
43 appdata->statusbar->cid, appdata->statusbar->mid);
44 appdata->statusbar->mid = 0;
45 }
46
47 if (msg) {
48 guint mid = gtk_statusbar_push(GTK_STATUSBAR(appdata->statusbar->widget),
49 appdata->statusbar->cid, msg);
50 appdata->statusbar->mid = mid;
51 }
52 }
53
54
55 // Clear any brief message currently set, dropping back to the persistent one.
56
57 static gboolean statusbar_brief_clear(gpointer data) {
58 appdata_t *appdata = (appdata_t *)data;
59 if (appdata->statusbar->brief_mid) {
60 gtk_statusbar_remove(GTK_STATUSBAR(appdata->statusbar->widget),
61 appdata->statusbar->cid,
62 appdata->statusbar->brief_mid);
63 appdata->statusbar->brief_mid = 0;
64 }
65 return FALSE;
66 }
67
68 // Flash up a brief, temporary message. Once it disappears, drop back to any
69 // persistent message set with statusbar_set().
70 //
71 // If msg is NULL, clear the message and don't establish a handler.
72 //
73 // If timeout is negative, don't establish a handler. You'll have to clear it
74 // yourself later. If it's zero, use the default.
75
76 void statusbar_brief(appdata_t *appdata, const char *msg, gint timeout) {
77 printf("statusbar_brief: %s\n", msg);
78 if (appdata->statusbar->brief_handler_id) {
79 gtk_timeout_remove(appdata->statusbar->brief_handler_id);
80 appdata->statusbar->brief_handler_id = 0;
81 }
82 statusbar_brief_clear(appdata);
83 guint mid = 0;
84 if (msg) {
85 mid = gtk_statusbar_push(GTK_STATUSBAR(appdata->statusbar->widget),
86 appdata->statusbar->cid, msg);
87 if (mid) {
88 appdata->statusbar->brief_mid = mid;
89 }
90 }
91 if (mid && (timeout >= 0)) {
92 if (timeout == 0) {
93 timeout = STATUSBAR_DEFAULT_BRIEF_TIME;
94 }
95 appdata->statusbar->brief_handler_id
96 = gtk_timeout_add(timeout, statusbar_brief_clear, appdata);
97 }
98 }
99
100 GtkWidget *statusbar_new(appdata_t *appdata) {
101 appdata->statusbar = (statusbar_t*)g_new0(statusbar_t, 1);
102
103 appdata->statusbar->eventbox = gtk_event_box_new();
104 appdata->statusbar->widget = gtk_statusbar_new();
105
106 #ifdef USE_HILDON
107 /* why the heck does hildon show this by default? It's useless!! */
108 g_object_set(appdata->statusbar->widget,
109 "has-resize-grip", FALSE,
110 NULL );
111 #endif
112 gtk_container_add(GTK_CONTAINER(appdata->statusbar->eventbox),
113 appdata->statusbar->widget);
114
115 appdata->statusbar->cid = gtk_statusbar_get_context_id(
116 GTK_STATUSBAR(appdata->statusbar->widget), "Msg");
117
118 return appdata->statusbar->eventbox;
119 }
120
121 #else
122 void statusbar_highlight(appdata_t *appdata, gboolean highlight) {
123 if(highlight) {
124 GdkColor color;
125 gdk_color_parse("red", &color);
126 gtk_widget_modify_bg(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
127 gtk_widget_modify_base(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
128 gtk_widget_modify_fg(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
129 } else
130 gtk_widget_modify_bg(appdata->statusbar->widget, GTK_STATE_NORMAL, NULL);
131 }
132
133
134 // Set the persistent message, replacing anything currently there.
135 void statusbar_set(appdata_t *appdata, const char *msg, gboolean highlight) {
136 statusbar_highlight(appdata, highlight);
137
138 printf("statusbar_set: %s\n", msg);
139
140 if(!msg)
141 gtk_label_set_text(GTK_LABEL(appdata->statusbar->widget), msg);
142 else
143 gtk_label_set_text(GTK_LABEL(appdata->statusbar->widget), msg);
144 }
145
146 GtkWidget *statusbar_new(appdata_t *appdata) {
147 appdata->statusbar = (statusbar_t*)g_new0(statusbar_t, 1);
148
149 appdata->statusbar->widget = gtk_label_new("");
150 return appdata->statusbar->widget;
151 }
152
153 #endif
154
155 void statusbar_free(statusbar_t *statusbar) {
156 if(statusbar)
157 g_free(statusbar);
158 }
159
160
161 // vim:et:ts=8:sw=2:sts=2:ai