File: msgbar.c

package info (click to toggle)
gnotepad%2B 1.0.2-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 756 kB
  • ctags: 832
  • sloc: ansic: 9,141; sh: 329; makefile: 156
file content (154 lines) | stat: -rw-r--r-- 3,449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* vi:set ts=8 sts=0 sw=8:
 * $Id: msgbar.c,v 1.8 1998/10/09 15:29:37 kahn Exp kahn $
 *
 * Copyright (C) 1998 Andy C. Kahn <kahn@zk3.dec.com>
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, write to the Free Software
 *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <stdarg.h>
#include <string.h>
#include "win.h"
#include "msgbar.h"
#include "prefs.h"


/*** global function definitions ***/
/*
 * PUBLIC: msgbar_clear
 *
 * clears the text by using a space (" ").  apparently, Gtk has no provision
 * for clearing a label widget.
 */
void
msgbar_clear(gpointer data)
{
	win_t *w = (win_t *)data;

	msgbar_printf(w, " ");
	gtk_timeout_remove(w->timeout_id);
} /* msgbar_clear */


/*
 * PUBLIC: msgbar_init
 *
 * initialize the message bar.  called from win_new().
 */
void
msgbar_init(win_t *w, GtkWidget *parent)
{
	w->msgbar = gtk_label_new("Hello world");
	gtk_box_pack_start(GTK_BOX(parent), w->msgbar, FALSE, FALSE, 0);
	gtk_misc_set_alignment(GTK_MISC(w->msgbar), 0.0, 0.5);

	/* set according to preferences */
	if (IS_SHOW_MSGBAR())
		gtk_widget_show(w->msgbar);
} /* msgbar_init */


/*
 * PUBLIC: msgbar_printf
 *
 * sets the message/status bar.  remembers the last message set so that a
 * duplicate one won't be set on top of the current one.
 */
void
msgbar_printf(win_t *w, const char *fmt, ...)
{
#ifdef GTK_HAVE_FEATURES_1_1_0
	va_list args;
#else
	va_list ap1, ap2;
#endif
	char *msg;

#ifdef GTK_HAVE_FEATURES_1_1_0
	va_start(args, fmt);
	msg = g_strdup_vprintf(fmt, args);
	va_end(args);
#else
	va_start(ap1, fmt);
	va_start(ap2, fmt);
	msg = g_vsprintf(fmt, &ap1, &ap2);
	va_end(ap1);
	va_end(ap2);
#endif
	if (w->lastmsg == NULL || strcmp(w->lastmsg, msg)) {
		gtk_label_set(GTK_LABEL(w->msgbar), msg);
		if (w->lastmsg)
			g_free(w->lastmsg);
		w->lastmsg = g_strdup(msg);
		gtk_timeout_remove(w->timeout_id);
		msgbar_timeout_add(w);
	}
#ifdef GTK_HAVE_FEATURES_1_1_0
	g_free(msg);
#endif
} /* msgbar_printf */


/*
 * PUBLIC: msgbar_redraw
 *
 * redraws the msgbar for a specified window
 */
void
msgbar_redraw(win_t *w)
{
	if (IS_SHOW_MSGBAR()) {
		gtk_widget_show(w->msgbar);
		gtk_widget_show(w->docinfo);
	} else {
		gtk_widget_hide(w->msgbar);
		gtk_widget_hide(w->docinfo);
	}
} /* msgbar_redraw */


/*
 * PUBLIC: msgbar toggle
 *
 * toggles the msgbar on/off
 */
void
msgbar_toggle(GtkWidget *wgt, gpointer cbdata)
{
	win_t *w = (win_t *)cbdata;

	g_assert(w != NULL);
	if (IS_SHOW_MSGBAR()) {
		gtk_widget_hide_all(w->hbox_bot);
		CLEAR_SHOW_MSGBAR();
	} else {
		gtk_widget_show_all(w->hbox_bot);
		SET_SHOW_MSGBAR();
	}
} /* msgbar_toggle */


/*
 * PUBLIC: msgbar_timeout_add
 *
 * after ~3 seconds, clears the message bar.
 */
void
msgbar_timeout_add(win_t *w)
{
	w->timeout_id = gtk_timeout_add(3000, (GtkFunction)msgbar_clear, w);
} /* msgbar_timeout_add */


/* the end */