Contents of /trunk/src/statusbar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations)
Wed Dec 24 14:17:20 2008 UTC (15 years, 5 months ago) by achadwick
File MIME type: text/plain
File size: 4200 byte(s)
The "look at me still talking when there's mapping to do" update.

UI: Make display more responsive during long busy periods. Use Hildon banners
    if available, or temporary statusbar messages for non-Hildon. Some message
    wording changes.

Bugfix: Prevent some segfaults when tapping screen during a redraw by putting
    a grabby banner in the way.

Etc: Update credits.
1 harbaum 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     void statusbar_highlight(appdata_t *appdata, gboolean highlight) {
23     if(highlight) {
24     GdkColor color;
25     gdk_color_parse("red", &color);
26     gtk_widget_modify_bg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
27     gtk_widget_modify_base(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
28     gtk_widget_modify_fg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, &color);
29     } else
30     gtk_widget_modify_bg(appdata->statusbar->eventbox, GTK_STATE_NORMAL, NULL);
31     }
32    
33 achadwick 28
34     // Set the persistent message, replacing anything currently there.
35    
36 harbaum 1 void statusbar_set(appdata_t *appdata, const char *msg, gboolean highlight) {
37     statusbar_highlight(appdata, highlight);
38    
39 achadwick 28 printf("statusbar_set: %s\n", msg);
40 harbaum 1
41 achadwick 28 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 harbaum 1
47 achadwick 28 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 harbaum 1 mid = gtk_statusbar_push(GTK_STATUSBAR(appdata->statusbar->widget),
86 achadwick 28 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 harbaum 1 }
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     void statusbar_free(statusbar_t *statusbar) {
122     if(statusbar)
123     g_free(statusbar);
124     }
125 achadwick 28
126     // vim:et:ts=8:sw=2:sts=2:ai