2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtktext.h>
31 #include <gtk/gtkstyle.h>
34 #include "logwindow.h"
38 static LogWindow
*logwindow
;
40 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
43 LogWindow
*log_window_create(void)
47 GtkWidget
*scrolledwin
;
50 debug_print(_("Creating log window...\n"));
51 logwin
= g_new0(LogWindow
, 1);
53 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
54 gtk_window_set_title(GTK_WINDOW(window
), _("Protocol log"));
55 gtk_window_set_policy(GTK_WINDOW(window
), TRUE
, TRUE
, FALSE
);
56 gtk_widget_set_usize(window
, 520, 400);
57 gtk_signal_connect(GTK_OBJECT(window
), "delete_event",
58 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete
), NULL
);
59 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
60 GTK_SIGNAL_FUNC(key_pressed
), logwin
);
61 gtk_widget_realize(window
);
63 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
64 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
65 GTK_POLICY_NEVER
, GTK_POLICY_ALWAYS
);
66 gtk_container_add(GTK_CONTAINER(window
), scrolledwin
);
67 gtk_widget_show(scrolledwin
);
69 text
= gtk_text_new(gtk_scrolled_window_get_hadjustment
70 (GTK_SCROLLED_WINDOW(scrolledwin
)),
71 gtk_scrolled_window_get_vadjustment
72 (GTK_SCROLLED_WINDOW(scrolledwin
)));
73 gtk_container_add(GTK_CONTAINER(scrolledwin
), text
);
74 gtk_widget_show(text
);
76 logwin
->window
= window
;
77 logwin
->scrolledwin
= scrolledwin
;
85 void log_window_init(LogWindow
*logwin
)
87 GdkColormap
*colormap
;
89 {{0, 0, 0xafff, 0}, {0, 0xefff, 0, 0}, {0, 0xefff, 0, 0}};
93 gtkut_widget_disable_theme_engine(logwin
->text
);
95 logwin
->msg_color
= color
[0];
96 logwin
->warn_color
= color
[1];
97 logwin
->error_color
= color
[2];
99 colormap
= gdk_window_get_colormap(logwin
->window
->window
);
100 gdk_colormap_alloc_colors(colormap
, color
, 3, FALSE
, TRUE
, success
);
102 for (i
= 0; i
< 3; i
++) {
103 if (success
[i
] == FALSE
) {
106 g_warning("LogWindow: color allocation failed\n");
107 style
= gtk_widget_get_style(logwin
->window
);
108 logwin
->msg_color
= logwin
->warn_color
=
109 logwin
->error_color
= style
->black
;
115 void log_window_show(LogWindow
*logwin
)
117 gtk_widget_hide(logwin
->window
);
118 gtk_widget_show(logwin
->window
);
121 void log_window_append(const gchar
*str
, LogType type
)
124 GdkColor
*color
= NULL
;
127 g_return_if_fail(logwindow
!= NULL
);
129 text
= GTK_TEXT(logwindow
->text
);
131 /*gtk_text_freeze(text);*/
135 color
= &logwindow
->warn_color
;
139 color
= &logwindow
->error_color
;
143 color
= &logwindow
->msg_color
;
148 if (head
) gtk_text_insert(text
, NULL
, color
, NULL
, head
, -1);
149 gtk_text_insert(text
, NULL
, color
, NULL
, str
, -1);
151 /*gtk_text_thaw(text);*/
154 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
157 if (event
&& event
->keyval
== GDK_Escape
)
158 gtk_widget_hide(logwin
->window
);