Contents of /trunk/src/statusbar.c

Parent Directory Parent Directory | Revision Log Revision Log


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