2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002 Hiroyuki Yamamoto & The Sylpheed Claws Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n.h>
28 #include <gtk/gtkwidget.h>
29 #include <gtk/gtkhbox.h>
30 #include <gtk/gtkvbox.h>
31 #include <gtk/gtklabel.h>
32 #include <gtk/gtkpixmap.h>
38 # include <compface.h>
41 #include "prefs_common.h"
44 #include "stock_pixmap.h"
46 #include "noticeview.h"
48 static void noticeview_button_pressed (GtkButton *button, NoticeView *noticeview);
49 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview);
50 static gboolean noticeview_icon_pressed (GtkWidget *widget, GdkEventButton *evt,
51 NoticeView *noticeview);
53 NoticeView *noticeview_create(MainWindow *mainwin)
55 NoticeView *noticeview;
65 debug_print("Creating notice view...\n");
66 noticeview = g_new0(NoticeView, 1);
68 noticeview->window = mainwin->window;
70 vbox = gtk_vbox_new(FALSE, 4);
71 gtk_widget_show(vbox);
72 hsep = gtk_hseparator_new();
73 gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 1);
75 hbox = gtk_hbox_new(FALSE, 4);
76 gtk_widget_show(hbox);
77 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
79 evtbox = gtk_event_box_new();
80 gtk_event_box_set_visible_window(GTK_EVENT_BOX(evtbox), FALSE);
81 gtk_widget_show(evtbox);
83 icon = stock_pixmap_widget(noticeview->window, STOCK_PIXMAP_NOTICE_WARN);
85 gtk_widget_show(icon);
86 g_signal_connect(G_OBJECT(evtbox), "button-press-event",
87 G_CALLBACK(noticeview_icon_pressed),
88 (gpointer) noticeview);
90 gtk_container_add(GTK_CONTAINER(evtbox), icon);
91 gtk_box_pack_start(GTK_BOX(hbox), evtbox, FALSE, TRUE, 0);
93 text = gtk_label_new("");
94 gtk_widget_show(text);
95 gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
97 widget = gtk_button_new_with_label("");
98 gtk_widget_set_size_request(widget, 120, -1);
99 g_signal_connect(G_OBJECT(widget), "clicked",
100 G_CALLBACK(noticeview_button_pressed),
101 (gpointer) noticeview);
102 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
104 widget2 = gtk_button_new_with_label("");
105 gtk_widget_set_size_request(widget2, 120, -1);
106 g_signal_connect(G_OBJECT(widget2), "clicked",
107 G_CALLBACK(noticeview_2ndbutton_pressed),
108 (gpointer) noticeview);
109 gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);
111 noticeview->vbox = vbox;
112 noticeview->hsep = hsep;
113 noticeview->hbox = hbox;
114 noticeview->icon = icon;
115 noticeview->text = text;
116 noticeview->button = widget;
117 noticeview->button2 = widget2;
119 noticeview->visible = TRUE;
124 void noticeview_destroy(NoticeView *noticeview)
129 gboolean noticeview_is_visible(NoticeView *noticeview)
131 return noticeview->visible;
134 void noticeview_show(NoticeView *noticeview)
136 if (!noticeview->visible) {
137 gtk_widget_show(GTK_WIDGET_PTR(noticeview));
138 noticeview->visible = TRUE;
142 void noticeview_hide(NoticeView *noticeview)
144 if (noticeview->visible) {
145 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
146 noticeview->visible = FALSE;
150 void noticeview_set_text(NoticeView *noticeview, const char *text)
152 g_return_if_fail(noticeview);
153 gtk_label_set_text(GTK_LABEL(noticeview->text), text);
156 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
158 g_return_if_fail(noticeview);
162 (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
163 gtk_widget_show(noticeview->button);
165 gtk_widget_hide(noticeview->button);
167 /* Callers defining only one button don't have to mind
168 * resetting the second one. Callers defining two have
169 * to define the second button after the first one.
171 gtk_widget_hide(noticeview->button2);
174 void noticeview_set_button_press_callback(NoticeView *noticeview,
175 GtkSignalFunc callback,
178 noticeview->press = (void (*) (NoticeView *, gpointer)) callback;
179 noticeview->user_data = user_data;
182 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
184 if (noticeview->press) {
185 noticeview->press(noticeview, noticeview->user_data);
189 static gboolean noticeview_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
190 NoticeView *noticeview)
192 if (evt && evt->button == 1 && noticeview->icon_clickable) {
193 noticeview_button_pressed(NULL, noticeview);
198 void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
200 g_return_if_fail(noticeview);
204 (GTK_LABEL(GTK_BIN(noticeview->button2)->child), text);
205 gtk_widget_show(noticeview->button2);
207 gtk_widget_hide(noticeview->button2);
210 void noticeview_set_2ndbutton_press_callback(NoticeView *noticeview,
211 GtkSignalFunc callback,
214 noticeview->press2 = (void (*) (NoticeView *, gpointer)) callback;
215 noticeview->user_data2 = user_data;
218 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
220 if (noticeview->press2) {
221 noticeview->press2(noticeview, noticeview->user_data2);
225 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
230 if (stock_pixmap_gdk(noticeview->window, icon, &pixmap, &bitmap) < 0)
233 gtk_image_set_from_pixmap(GTK_IMAGE(noticeview->icon), pixmap, bitmap);
236 void noticeview_set_icon_clickable(NoticeView *noticeview, gboolean setting)
238 noticeview->icon_clickable = setting;