3.7.2 unleashed
[claws.git] / src / noticeview.c
blob8aa726c33e26ef43b0bc65306504ba2b80776ed4
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002 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/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
24 #include "defs.h"
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <time.h>
33 #if HAVE_LIBCOMPFACE
34 # include <compface.h>
35 #endif
37 #include "prefs_common.h"
38 #include "gtkutils.h"
39 #include "utils.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;
63 GtkWidget *vbox;
64 GtkWidget *hsep;
65 GtkWidget *hbox;
66 GtkWidget *icon;
67 GtkWidget *text;
68 GtkWidget *widget;
69 GtkWidget *widget2;
70 GtkWidget *evtbox;
71 CLAWS_TIP_DECL();
73 debug_print("Creating notice view...\n");
74 noticeview = g_new0(NoticeView, 1);
76 if (!hand_cursor)
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), "visibility-notify-event",
101 G_CALLBACK(noticeview_visi_notify), noticeview);
102 g_signal_connect(G_OBJECT(evtbox), "motion-notify-event",
103 G_CALLBACK(noticeview_visi_notify), noticeview);
104 g_signal_connect(G_OBJECT(evtbox), "leave-notify-event",
105 G_CALLBACK(noticeview_leave_notify), noticeview);
106 g_signal_connect(G_OBJECT(evtbox), "enter-notify-event",
107 G_CALLBACK(noticeview_enter_notify), noticeview);
109 gtk_container_add(GTK_CONTAINER(evtbox), icon);
110 gtk_box_pack_start(GTK_BOX(hbox), evtbox, FALSE, TRUE, 0);
112 text = gtk_label_new("");
113 gtk_widget_show(text);
114 gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
116 widget = gtk_button_new_with_label("");
117 g_signal_connect(G_OBJECT(widget), "clicked",
118 G_CALLBACK(noticeview_button_pressed),
119 (gpointer) noticeview);
120 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
122 widget2 = gtk_button_new_with_label("");
123 g_signal_connect(G_OBJECT(widget2), "clicked",
124 G_CALLBACK(noticeview_2ndbutton_pressed),
125 (gpointer) noticeview);
126 gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);
128 noticeview->vbox = vbox;
129 noticeview->hsep = hsep;
130 noticeview->hbox = hbox;
131 noticeview->icon = icon;
132 noticeview->text = text;
133 noticeview->button = widget;
134 noticeview->button2= widget2;
135 noticeview->evtbox = evtbox;
136 noticeview->visible= TRUE;
137 #if !(GTK_CHECK_VERSION(2,12,0))
138 noticeview->tooltips = tips;
139 #endif
140 return noticeview;
143 void noticeview_destroy(NoticeView *noticeview)
145 g_free(noticeview);
148 gboolean noticeview_is_visible(NoticeView *noticeview)
150 return noticeview->visible;
153 void noticeview_show(NoticeView *noticeview)
155 if (!noticeview->visible) {
156 gtk_widget_show(GTK_WIDGET_PTR(noticeview));
157 noticeview->visible = TRUE;
161 void noticeview_hide(NoticeView *noticeview)
163 if (noticeview && noticeview->visible) {
164 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
165 noticeview->visible = FALSE;
169 void noticeview_set_text(NoticeView *noticeview, const char *text)
171 cm_return_if_fail(noticeview);
172 gtk_label_set_text(GTK_LABEL(noticeview->text), text);
175 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
177 cm_return_if_fail(noticeview);
179 if (text != NULL) {
180 gtk_label_set_text
181 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button)))), text);
182 gtk_widget_show(noticeview->button);
183 } else
184 gtk_widget_hide(noticeview->button);
186 /* Callers defining only one button don't have to mind
187 * resetting the second one. Callers defining two have
188 * to define the second button after the first one.
190 gtk_widget_hide(noticeview->button2);
193 void noticeview_set_button_press_callback(NoticeView *noticeview,
194 void (*callback)(void),
195 gpointer *user_data)
197 noticeview->press = (void (*) (NoticeView *, gpointer)) callback;
198 noticeview->user_data = user_data;
201 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
203 if (noticeview->press) {
204 noticeview->press(noticeview, noticeview->user_data);
208 static gboolean noticeview_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
209 NoticeView *noticeview)
211 if (evt && evt->button == 1 && noticeview->icon_clickable) {
212 noticeview_button_pressed(NULL, noticeview);
214 return FALSE;
217 static gboolean noticeview_visi_notify(GtkWidget *widget,
218 GdkEventVisibility *event,
219 NoticeView *noticeview)
221 if (noticeview->icon_clickable)
222 gdk_window_set_cursor(noticeview->evtbox->window, hand_cursor);
223 return FALSE;
226 static gboolean noticeview_leave_notify(GtkWidget *widget,
227 GdkEventCrossing *event,
228 NoticeView *noticeview)
230 gdk_window_set_cursor(noticeview->evtbox->window, NULL);
231 return FALSE;
234 static gboolean noticeview_enter_notify(GtkWidget *widget,
235 GdkEventCrossing *event,
236 NoticeView *noticeview)
238 if (noticeview->icon_clickable)
239 gdk_window_set_cursor(noticeview->evtbox->window, hand_cursor);
240 return FALSE;
243 void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
245 cm_return_if_fail(noticeview);
247 if (text != NULL) {
248 gtk_label_set_text
249 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview->button2)))), text);
250 gtk_widget_show(noticeview->button2);
251 } else
252 gtk_widget_hide(noticeview->button2);
255 void noticeview_set_2ndbutton_press_callback(NoticeView *noticeview,
256 void (*callback)(void),
257 gpointer *user_data)
259 noticeview->press2 = (void (*) (NoticeView *, gpointer)) callback;
260 noticeview->user_data2 = user_data;
263 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
265 if (noticeview->press2) {
266 noticeview->press2(noticeview, noticeview->user_data2);
270 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
272 GdkPixbuf *pixbuf;
274 if (stock_pixbuf_gdk(noticeview->window, icon, &pixbuf) < 0)
275 return;
277 gtk_image_set_from_pixbuf(GTK_IMAGE(noticeview->icon), pixbuf);
280 void noticeview_set_icon_clickable(NoticeView *noticeview, gboolean setting)
282 noticeview->icon_clickable = setting;
285 void noticeview_set_tooltip (NoticeView *noticeview, const gchar *text)
287 #if !(GTK_CHECK_VERSION(2,12,0))
288 GtkTooltips *tips = noticeview->tooltips;
289 #endif
290 CLAWS_SET_TIP(noticeview->evtbox,
291 text);