2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2012 Hiroyuki Yamamoto & The Claws Mail 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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
35 # include <compface.h>
38 #include "prefs_common.h"
41 #include "stock_pixmap.h"
43 #include "noticeview.h"
45 static void noticeview_button_pressed (GtkButton *button, NoticeView *noticeview);
46 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview);
47 static gboolean noticeview_icon_pressed (GtkWidget *widget, GdkEventButton *evt,
48 NoticeView *noticeview);
49 static gboolean noticeview_visi_notify(GtkWidget *widget,
50 GdkEventVisibility *event,
51 NoticeView *noticeview);
52 static gboolean noticeview_leave_notify(GtkWidget *widget,
53 GdkEventCrossing *event,
54 NoticeView *textview);
55 static gboolean noticeview_enter_notify(GtkWidget *widget,
56 GdkEventCrossing *event,
57 NoticeView *textview);
59 static GdkCursor *hand_cursor = NULL;
61 NoticeView *noticeview_create(MainWindow *mainwin)
63 NoticeView *noticeview;
73 debug_print("Creating notice view...\n");
74 noticeview = g_new0(NoticeView, 1);
77 hand_cursor = gdk_cursor_new(GDK_HAND2);
79 noticeview->window = mainwin->window;
81 vbox = gtk_vbox_new(FALSE, 4);
82 gtk_widget_show(vbox);
83 hsep = gtk_hseparator_new();
84 gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 1);
86 hbox = gtk_hbox_new(FALSE, 4);
87 gtk_widget_show(hbox);
88 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
90 evtbox = gtk_event_box_new();
91 gtk_event_box_set_visible_window(GTK_EVENT_BOX(evtbox), FALSE);
92 gtk_widget_show(evtbox);
94 icon = stock_pixmap_widget(noticeview->window, STOCK_PIXMAP_NOTICE_WARN);
96 gtk_widget_show(icon);
97 g_signal_connect(G_OBJECT(evtbox), "button-press-event",
98 G_CALLBACK(noticeview_icon_pressed),
99 (gpointer) noticeview);
100 g_signal_connect(G_OBJECT(evtbox), "motion-notify-event",
101 G_CALLBACK(noticeview_visi_notify), noticeview);
102 g_signal_connect(G_OBJECT(evtbox), "leave-notify-event",
103 G_CALLBACK(noticeview_leave_notify), noticeview);
104 g_signal_connect(G_OBJECT(evtbox), "enter-notify-event",
105 G_CALLBACK(noticeview_enter_notify), noticeview);
107 gtk_container_add(GTK_CONTAINER(evtbox), icon);
108 gtk_box_pack_start(GTK_BOX(hbox), evtbox, FALSE, TRUE, 0);
110 text = gtk_label_new("");
111 gtk_widget_show(text);
112 gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
114 widget = gtk_button_new_with_label("");
115 g_signal_connect(G_OBJECT(widget), "clicked",
116 G_CALLBACK(noticeview_button_pressed),
117 (gpointer) noticeview);
118 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
120 widget2 = gtk_button_new_with_label("");
121 g_signal_connect(G_OBJECT(widget2), "clicked",
122 G_CALLBACK(noticeview_2ndbutton_pressed),
123 (gpointer) noticeview);
124 gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);
126 noticeview->vbox = vbox;
127 noticeview->hsep = hsep;
128 noticeview->hbox = hbox;
129 noticeview->icon = icon;
130 noticeview->text = text;
131 noticeview->button = widget;
132 noticeview->button2= widget2;
133 noticeview->evtbox = evtbox;
134 noticeview->visible= TRUE;
135 #if !(GTK_CHECK_VERSION(2,12,0))
136 noticeview->tooltips = tips;
141 void noticeview_destroy(NoticeView *noticeview)
146 gboolean noticeview_is_visible(NoticeView *noticeview)
148 return noticeview->visible;
151 void noticeview_show(NoticeView *noticeview)
153 if (!noticeview->visible) {
154 gtk_widget_show(GTK_WIDGET_PTR(noticeview));
155 noticeview->visible = TRUE;
159 void noticeview_hide(NoticeView *noticeview)
161 if (noticeview && noticeview->visible) {
162 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
163 noticeview->visible = FALSE;
167 void noticeview_set_text(NoticeView *noticeview, const char *text)
169 cm_return_if_fail(noticeview);
170 gtk_label_set_text(GTK_LABEL(noticeview->text), text);
173 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
175 cm_return_if_fail(noticeview);
179 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button)))), text);
180 gtk_widget_show(noticeview->button);
182 gtk_widget_hide(noticeview->button);
184 /* Callers defining only one button don't have to mind
185 * resetting the second one. Callers defining two have
186 * to define the second button after the first one.
188 gtk_widget_hide(noticeview->button2);
191 void noticeview_set_button_press_callback(NoticeView *noticeview,
192 void (*callback)(void),
195 noticeview->press = (void (*) (NoticeView *, gpointer)) callback;
196 noticeview->user_data = user_data;
199 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
201 if (noticeview->press) {
202 noticeview->press(noticeview, noticeview->user_data);
206 static gboolean noticeview_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
207 NoticeView *noticeview)
209 if (evt && evt->button == 1 && noticeview->icon_clickable) {
210 noticeview_button_pressed(NULL, noticeview);
215 static gboolean noticeview_visi_notify(GtkWidget *widget,
216 GdkEventVisibility *event,
217 NoticeView *noticeview)
219 if (noticeview->icon_clickable)
220 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), hand_cursor);
224 static gboolean noticeview_leave_notify(GtkWidget *widget,
225 GdkEventCrossing *event,
226 NoticeView *noticeview)
228 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), NULL);
232 static gboolean noticeview_enter_notify(GtkWidget *widget,
233 GdkEventCrossing *event,
234 NoticeView *noticeview)
236 if (noticeview->icon_clickable)
237 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), hand_cursor);
241 void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
243 cm_return_if_fail(noticeview);
247 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button2)))), text);
248 gtk_widget_show(noticeview->button2);
250 gtk_widget_hide(noticeview->button2);
253 void noticeview_set_2ndbutton_press_callback(NoticeView *noticeview,
254 void (*callback)(void),
257 noticeview->press2 = (void (*) (NoticeView *, gpointer)) callback;
258 noticeview->user_data2 = user_data;
261 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
263 if (noticeview->press2) {
264 noticeview->press2(noticeview, noticeview->user_data2);
268 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
272 if (stock_pixbuf_gdk(noticeview->window, icon, &pixbuf) < 0)
275 gtk_image_set_from_pixbuf(GTK_IMAGE(noticeview->icon), pixbuf);
278 void noticeview_set_icon_clickable(NoticeView *noticeview, gboolean setting)
280 noticeview->icon_clickable = setting;
283 void noticeview_set_tooltip (NoticeView *noticeview, const gchar *text)
285 #if !(GTK_CHECK_VERSION(2,12,0))
286 GtkTooltips *tips = noticeview->tooltips;
288 CLAWS_SET_TIP(noticeview->evtbox,