Contents of /trunk/src/statusbar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209 - (show annotations)
Fri Jul 10 19:45:31 2009 UTC (14 years, 10 months ago) by harbaum
File MIME type: text/plain
File size: 5352 byte(s)
Version increase
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 #ifndef USE_HILDON
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 #endif
100
101 GtkWidget *statusbar_new(appdata_t *appdata) {
102 appdata->statusbar = (statusbar_t*)g_new0(statusbar_t, 1);
103
104 appdata->statusbar->eventbox = gtk_event_box_new();
105 appdata->statusbar->widget = gtk_statusbar_new();
106
107 #ifdef USE_HILDON
108 /* why the heck does hildon show this by default? It's useless!! */
109 g_object_set(appdata->statusbar->widget,
110 "has-resize-grip", FALSE,
111 NULL );
112 #endif
113 gtk_container_add(GTK_CONTAINER(appdata->statusbar->eventbox),
114 appdata->statusbar->widget);
115
116 appdata->statusbar->cid = gtk_statusbar_get_context_id(
117 GTK_STATUSBAR(appdata->statusbar->widget), "Msg");
118
119 return appdata->statusbar->eventbox;
120 }
121
122 #else
123 void statusbar_highlight(appdata_t *appdata, gboolean highlight) {
124 if(highlight) {
125 GdkColor color;
126 gdk_color_parse("red", &color);
127 gtk_widget_modify_bg(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
128 gtk_widget_modify_base(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
129 gtk_widget_modify_fg(appdata->statusbar->widget, GTK_STATE_NORMAL, &color);
130 } else
131 gtk_widget_modify_bg(appdata->statusbar->widget, GTK_STATE_NORMAL, NULL);
132 }
133
134
135 // Set the persistent message, replacing anything currently there.
136 void statusbar_set(appdata_t *appdata, const char *msg, gboolean highlight) {
137 statusbar_highlight(appdata, highlight);
138
139 printf("statusbar_set: %s\n", msg);
140
141 if(!msg)
142 gtk_label_set_text(GTK_LABEL(appdata->statusbar->widget), msg);
143 else
144 gtk_label_set_text(GTK_LABEL(appdata->statusbar->widget), msg);
145 }
146
147 GtkWidget *statusbar_new(appdata_t *appdata) {
148 appdata->statusbar = (statusbar_t*)g_new0(statusbar_t, 1);
149
150 appdata->statusbar->widget = gtk_label_new("");
151 return appdata->statusbar->widget;
152 }
153
154 #endif
155
156 void statusbar_free(statusbar_t *statusbar) {
157 if(statusbar)
158 g_free(statusbar);
159 }
160
161
162 // vim:et:ts=8:sw=2:sts=2:ai