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_wmclass(GTK_WINDOW(window), "log_window", "Sylpheed");
56 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
57 gtk_widget_set_usize(window, 520, 400);
58 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
59 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), NULL);
60 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
61 GTK_SIGNAL_FUNC(key_pressed), logwin);
62 gtk_widget_realize(window);
64 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
65 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
66 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
67 gtk_container_add(GTK_CONTAINER(window), scrolledwin);
68 gtk_widget_show(scrolledwin);
70 text = gtk_text_new(gtk_scrolled_window_get_hadjustment
71 (GTK_SCROLLED_WINDOW(scrolledwin)),
72 gtk_scrolled_window_get_vadjustment
73 (GTK_SCROLLED_WINDOW(scrolledwin)));
74 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
75 gtk_widget_show(text);
77 logwin->window = window;
78 logwin->scrolledwin = scrolledwin;
86 void log_window_init(LogWindow *logwin)
88 GdkColormap *colormap;
90 {{0, 0, 0xafff, 0}, {0, 0xefff, 0, 0}, {0, 0xefff, 0, 0}};
94 gtkut_widget_disable_theme_engine(logwin->text);
96 logwin->msg_color = color[0];
97 logwin->warn_color = color[1];
98 logwin->error_color = color[2];
100 colormap = gdk_window_get_colormap(logwin->window->window);
101 gdk_colormap_alloc_colors(colormap, color, 3, FALSE, TRUE, success);
103 for (i = 0; i < 3; i++) {
104 if (success[i] == FALSE) {
107 g_warning("LogWindow: color allocation failed\n");
108 style = gtk_widget_get_style(logwin->window);
109 logwin->msg_color = logwin->warn_color =
110 logwin->error_color = style->black;
116 void log_window_show(LogWindow *logwin)
118 gtk_widget_hide(logwin->window);
119 gtk_widget_show(logwin->window);
122 void log_window_append(const gchar *str, LogType type)
125 GdkColor *color = NULL;
128 g_return_if_fail(logwindow != NULL);
130 text = GTK_TEXT(logwindow->text);
134 color = &logwindow->warn_color;
138 color = &logwindow->error_color;
142 color = &logwindow->msg_color;
147 if (head) gtk_text_insert(text, NULL, color, NULL, head, -1);
148 gtk_text_insert(text, NULL, color, NULL, str, -1);
151 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
154 if (event && event->keyval == GDK_Escape)
155 gtk_widget_hide(logwin->window);