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/>.
27 #include <glib/gi18n.h>
34 # include <compface.h>
37 #include "prefs_common.h"
40 #include "stock_pixmap.h"
42 #include "noticeview.h"
44 static void noticeview_button_pressed (GtkButton *button, NoticeView *noticeview);
45 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview);
46 static gboolean noticeview_icon_pressed (GtkWidget *widget, GdkEventButton *evt,
47 NoticeView *noticeview);
48 static gboolean noticeview_visi_notify(GtkWidget *widget,
49 GdkEventVisibility *event,
50 NoticeView *noticeview);
51 static gboolean noticeview_leave_notify(GtkWidget *widget,
52 GdkEventCrossing *event,
53 NoticeView *textview);
54 static gboolean noticeview_enter_notify(GtkWidget *widget,
55 GdkEventCrossing *event,
56 NoticeView *textview);
58 static GdkCursor *hand_cursor = NULL;
60 NoticeView *noticeview_create(MainWindow *mainwin)
62 NoticeView *noticeview;
72 debug_print("Creating notice view...\n");
73 noticeview = g_new0(NoticeView, 1);
76 hand_cursor = gdk_cursor_new(GDK_HAND2);
78 noticeview->window = mainwin->window;
80 vbox = gtk_vbox_new(FALSE, 4);
81 gtk_widget_show(vbox);
82 hsep = gtk_hseparator_new();
83 gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 1);
85 hbox = gtk_hbox_new(FALSE, 4);
86 gtk_widget_show(hbox);
87 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
89 evtbox = gtk_event_box_new();
90 gtk_event_box_set_visible_window(GTK_EVENT_BOX(evtbox), FALSE);
91 gtk_widget_show(evtbox);
93 icon = stock_pixmap_widget(noticeview->window, STOCK_PIXMAP_NOTICE_WARN);
95 gtk_widget_show(icon);
96 g_signal_connect(G_OBJECT(evtbox), "button-press-event",
97 G_CALLBACK(noticeview_icon_pressed),
98 (gpointer) noticeview);
99 g_signal_connect(G_OBJECT(evtbox), "motion-notify-event",
100 G_CALLBACK(noticeview_visi_notify), noticeview);
101 g_signal_connect(G_OBJECT(evtbox), "leave-notify-event",
102 G_CALLBACK(noticeview_leave_notify), noticeview);
103 g_signal_connect(G_OBJECT(evtbox), "enter-notify-event",
104 G_CALLBACK(noticeview_enter_notify), noticeview);
106 gtk_container_add(GTK_CONTAINER(evtbox), icon);
107 gtk_box_pack_start(GTK_BOX(hbox), evtbox, FALSE, TRUE, 0);
109 text = gtk_label_new("");
110 gtk_widget_show(text);
111 gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
113 widget = gtk_button_new_with_label("");
114 g_signal_connect(G_OBJECT(widget), "clicked",
115 G_CALLBACK(noticeview_button_pressed),
116 (gpointer) noticeview);
117 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
119 widget2 = gtk_button_new_with_label("");
120 g_signal_connect(G_OBJECT(widget2), "clicked",
121 G_CALLBACK(noticeview_2ndbutton_pressed),
122 (gpointer) noticeview);
123 gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);
125 noticeview->vbox = vbox;
126 noticeview->hsep = hsep;
127 noticeview->hbox = hbox;
128 noticeview->icon = icon;
129 noticeview->text = text;
130 noticeview->button = widget;
131 noticeview->button2= widget2;
132 noticeview->evtbox = evtbox;
133 noticeview->visible= TRUE;
134 #if !(GTK_CHECK_VERSION(2,12,0))
135 noticeview->tooltips = tips;
140 void noticeview_destroy(NoticeView *noticeview)
145 gboolean noticeview_is_visible(NoticeView *noticeview)
147 return noticeview->visible;
150 void noticeview_show(NoticeView *noticeview)
152 if (!noticeview->visible) {
153 gtk_widget_show(GTK_WIDGET_PTR(noticeview));
154 noticeview->visible = TRUE;
158 void noticeview_hide(NoticeView *noticeview)
160 if (noticeview && noticeview->visible) {
161 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
162 noticeview->visible = FALSE;
166 void noticeview_set_text(NoticeView *noticeview, const char *text)
168 cm_return_if_fail(noticeview);
169 gtk_label_set_text(GTK_LABEL(noticeview->text), text);
172 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
174 cm_return_if_fail(noticeview);
178 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button)))), text);
179 gtk_widget_show(noticeview->button);
181 gtk_widget_hide(noticeview->button);
183 /* Callers defining only one button don't have to mind
184 * resetting the second one. Callers defining two have
185 * to define the second button after the first one.
187 gtk_widget_hide(noticeview->button2);
190 void noticeview_set_button_press_callback(NoticeView *noticeview,
191 void (*callback)(void),
194 noticeview->press = (void (*) (NoticeView *, gpointer)) callback;
195 noticeview->user_data = user_data;
198 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
200 if (noticeview->press) {
201 noticeview->press(noticeview, noticeview->user_data);
205 static gboolean noticeview_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
206 NoticeView *noticeview)
208 if (evt && evt->button == 1 && noticeview->icon_clickable) {
209 noticeview_button_pressed(NULL, noticeview);
214 static gboolean noticeview_visi_notify(GtkWidget *widget,
215 GdkEventVisibility *event,
216 NoticeView *noticeview)
218 if (noticeview->icon_clickable)
219 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), hand_cursor);
223 static gboolean noticeview_leave_notify(GtkWidget *widget,
224 GdkEventCrossing *event,
225 NoticeView *noticeview)
227 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), NULL);
231 static gboolean noticeview_enter_notify(GtkWidget *widget,
232 GdkEventCrossing *event,
233 NoticeView *noticeview)
235 if (noticeview->icon_clickable)
236 gdk_window_set_cursor(gtk_widget_get_window(noticeview->evtbox), hand_cursor);
240 void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
242 cm_return_if_fail(noticeview);
246 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button2)))), text);
247 gtk_widget_show(noticeview->button2);
249 gtk_widget_hide(noticeview->button2);
252 void noticeview_set_2ndbutton_press_callback(NoticeView *noticeview,
253 void (*callback)(void),
256 noticeview->press2 = (void (*) (NoticeView *, gpointer)) callback;
257 noticeview->user_data2 = user_data;
260 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
262 if (noticeview->press2) {
263 noticeview->press2(noticeview, noticeview->user_data2);
267 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
271 if (stock_pixbuf_gdk(noticeview->window, icon, &pixbuf) < 0)
274 gtk_image_set_from_pixbuf(GTK_IMAGE(noticeview->icon), pixbuf);
277 void noticeview_set_icon_clickable(NoticeView *noticeview, gboolean setting)
279 noticeview->icon_clickable = setting;
282 void noticeview_set_tooltip (NoticeView *noticeview, const gchar *text)
284 #if !(GTK_CHECK_VERSION(2,12,0))
285 GtkTooltips *tips = noticeview->tooltips;
287 CLAWS_SET_TIP(noticeview->evtbox,