2 * Claws Mail -- 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 static void set_hand_cursor(GdkWindow
*window
)
63 cm_return_if_fail(window
!= NULL
);
66 hand_cursor
= gdk_cursor_new_for_display(
67 gdk_window_get_display(window
), GDK_HAND2
);
71 NoticeView
*noticeview_create(MainWindow
*mainwin
)
73 NoticeView
*noticeview
;
83 debug_print("Creating notice view...\n");
84 noticeview
= g_new0(NoticeView
, 1);
86 noticeview
->window
= mainwin
->window
;
88 vgrid
= gtk_grid_new();
89 gtk_widget_set_name(GTK_WIDGET(vgrid
), "noticeview");
90 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid
),
91 GTK_ORIENTATION_VERTICAL
);
92 gtk_grid_set_row_spacing(GTK_GRID(vgrid
), 4);
93 gtk_widget_show(vgrid
);
94 hsep
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
95 g_object_set(hsep
, "margin", 1, NULL
);
96 gtk_container_add(GTK_CONTAINER(vgrid
), hsep
);
98 hgrid
= gtk_grid_new();
99 gtk_orientable_set_orientation(GTK_ORIENTABLE(hgrid
),
100 GTK_ORIENTATION_HORIZONTAL
);
101 gtk_widget_show(hgrid
);
102 g_object_set(hgrid
, "margin", 1, NULL
);
103 gtk_container_add(GTK_CONTAINER(vgrid
), hgrid
);
105 evtbox
= gtk_event_box_new();
106 gtk_event_box_set_visible_window(GTK_EVENT_BOX(evtbox
), FALSE
);
107 gtk_widget_show(evtbox
);
109 icon
= stock_pixmap_widget(STOCK_PIXMAP_NOTICE_WARN
);
111 gtk_widget_show(icon
);
112 g_signal_connect(G_OBJECT(evtbox
), "button-press-event",
113 G_CALLBACK(noticeview_icon_pressed
),
114 (gpointer
) noticeview
);
115 g_signal_connect(G_OBJECT(evtbox
), "motion-notify-event",
116 G_CALLBACK(noticeview_visi_notify
), noticeview
);
117 g_signal_connect(G_OBJECT(evtbox
), "leave-notify-event",
118 G_CALLBACK(noticeview_leave_notify
), noticeview
);
119 g_signal_connect(G_OBJECT(evtbox
), "enter-notify-event",
120 G_CALLBACK(noticeview_enter_notify
), noticeview
);
122 gtk_container_add(GTK_CONTAINER(evtbox
), icon
);
123 gtk_container_add(GTK_CONTAINER(hgrid
), evtbox
);
125 text
= gtk_label_new("");
126 gtk_widget_show(text
);
127 gtk_container_add(GTK_CONTAINER(hgrid
), text
);
129 widget
= gtk_button_new_with_label("");
130 g_signal_connect(G_OBJECT(widget
), "clicked",
131 G_CALLBACK(noticeview_button_pressed
),
132 (gpointer
) noticeview
);
133 g_object_set(widget
, "margin", 4, NULL
);
134 gtk_container_add(GTK_CONTAINER(hgrid
), widget
);
136 widget2
= gtk_button_new_with_label("");
137 g_signal_connect(G_OBJECT(widget2
), "clicked",
138 G_CALLBACK(noticeview_2ndbutton_pressed
),
139 (gpointer
) noticeview
);
140 gtk_container_add(GTK_CONTAINER(hgrid
), widget2
);
142 noticeview
->vgrid
= vgrid
;
143 noticeview
->hsep
= hsep
;
144 noticeview
->hgrid
= hgrid
;
145 noticeview
->icon
= icon
;
146 noticeview
->text
= text
;
147 noticeview
->button
= widget
;
148 noticeview
->button2
= widget2
;
149 noticeview
->evtbox
= evtbox
;
150 noticeview
->visible
= TRUE
;
154 void noticeview_destroy(NoticeView
*noticeview
)
159 gboolean
noticeview_is_visible(NoticeView
*noticeview
)
161 return noticeview
->visible
;
164 void noticeview_show(NoticeView
*noticeview
)
166 if (!noticeview
->visible
) {
167 gtk_widget_show(GTK_WIDGET_PTR(noticeview
));
168 noticeview
->visible
= TRUE
;
172 void noticeview_hide(NoticeView
*noticeview
)
174 if (noticeview
&& noticeview
->visible
) {
175 gtk_widget_hide(GTK_WIDGET_PTR(noticeview
));
176 noticeview
->visible
= FALSE
;
180 void noticeview_set_text(NoticeView
*noticeview
, const char *text
)
182 cm_return_if_fail(noticeview
);
183 gtk_label_set_text(GTK_LABEL(noticeview
->text
), text
);
186 void noticeview_set_button_text(NoticeView
*noticeview
, const char *text
)
188 cm_return_if_fail(noticeview
);
192 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview
->button
)))), text
);
193 gtk_widget_show(noticeview
->button
);
195 gtk_widget_hide(noticeview
->button
);
197 /* Callers defining only one button don't have to mind
198 * resetting the second one. Callers defining two have
199 * to define the second button after the first one.
201 gtk_widget_hide(noticeview
->button2
);
204 void noticeview_set_button_press_callback(NoticeView
*noticeview
,
205 void (*callback
)(void),
208 noticeview
->press
= (void (*) (NoticeView
*, gpointer
)) callback
;
209 noticeview
->user_data
= user_data
;
212 static void noticeview_button_pressed(GtkButton
*button
, NoticeView
*noticeview
)
214 if (noticeview
->press
) {
215 noticeview
->press(noticeview
, noticeview
->user_data
);
219 static gboolean
noticeview_icon_pressed(GtkWidget
*widget
, GdkEventButton
*evt
,
220 NoticeView
*noticeview
)
222 if (evt
&& evt
->button
== 1 && noticeview
->icon_clickable
) {
223 noticeview_button_pressed(NULL
, noticeview
);
228 static gboolean
noticeview_visi_notify(GtkWidget
*widget
,
229 GdkEventVisibility
*event
,
230 NoticeView
*noticeview
)
232 GdkWindow
*window
= gtk_widget_get_window(noticeview
->evtbox
);
234 if (noticeview
->icon_clickable
) {
235 set_hand_cursor(window
);
236 gdk_window_set_cursor(window
, hand_cursor
);
241 static gboolean
noticeview_leave_notify(GtkWidget
*widget
,
242 GdkEventCrossing
*event
,
243 NoticeView
*noticeview
)
245 gdk_window_set_cursor(gtk_widget_get_window(noticeview
->evtbox
), NULL
);
249 static gboolean
noticeview_enter_notify(GtkWidget
*widget
,
250 GdkEventCrossing
*event
,
251 NoticeView
*noticeview
)
253 GdkWindow
*window
= gtk_widget_get_window(noticeview
->evtbox
);
255 if (noticeview
->icon_clickable
) {
256 set_hand_cursor(window
);
257 gdk_window_set_cursor(window
, hand_cursor
);
262 void noticeview_set_2ndbutton_text(NoticeView
*noticeview
, const char *text
)
264 cm_return_if_fail(noticeview
);
268 (GTK_LABEL(gtk_bin_get_child(GTK_BIN((noticeview
->button2
)))), text
);
269 gtk_widget_show(noticeview
->button2
);
271 gtk_widget_hide(noticeview
->button2
);
274 void noticeview_set_2ndbutton_press_callback(NoticeView
*noticeview
,
275 void (*callback
)(void),
278 noticeview
->press2
= (void (*) (NoticeView
*, gpointer
)) callback
;
279 noticeview
->user_data2
= user_data
;
282 static void noticeview_2ndbutton_pressed(GtkButton
*button
, NoticeView
*noticeview
)
284 if (noticeview
->press2
) {
285 noticeview
->press2(noticeview
, noticeview
->user_data2
);
289 void noticeview_set_icon(NoticeView
*noticeview
, StockPixmap icon
)
293 if (stock_pixbuf_gdk(icon
, &pixbuf
) < 0)
296 gtk_image_set_from_pixbuf(GTK_IMAGE(noticeview
->icon
), pixbuf
);
299 void noticeview_set_icon_clickable(NoticeView
*noticeview
, gboolean setting
)
301 noticeview
->icon_clickable
= setting
;
304 void noticeview_set_tooltip (NoticeView
*noticeview
, const gchar
*text
)
306 CLAWS_SET_TIP(noticeview
->evtbox
,