2 "$Id: info.c 11116 2008-12-30 06:57:53Z mwedel $";
35 #include <glade/glade.h>
53 #define FONT_STRANGE 2
79 #define NUM_TEXT_VIEWS 2
96 static void message_callback(
int flag,
int type,
int subtype,
char *message);
135 g_object_set(tag,
"foreground-set",
FALSE, NULL);
136 g_object_set(tag,
"background-set",
FALSE, NULL);
137 g_object_set(tag,
"font-desc", NULL, NULL);
140 &style->fg[GTK_STATE_NORMAL],
141 &base_style->fg[GTK_STATE_NORMAL],
144 g_object_set(tag,
"foreground-gdk", &style->fg[GTK_STATE_NORMAL], NULL);
147 &style->bg[GTK_STATE_NORMAL],
148 &base_style->bg[GTK_STATE_NORMAL],
151 g_object_set(tag,
"background-gdk", &style->bg[GTK_STATE_NORMAL], NULL);
153 if (style->font_desc != base_style->font_desc)
154 g_object_set(tag,
"font-desc", style->font_desc, NULL);
169 GtkStyle *tmp_style, *base_style[2];
204 gtk_text_buffer_create_tag(
info_pane[j].textbuffer,
205 "bold",
"weight", PANGO_WEIGHT_BOLD, NULL);
208 gtk_text_buffer_create_tag(
info_pane[j].textbuffer,
209 "italic",
"style", PANGO_STYLE_ITALIC, NULL);
212 gtk_text_buffer_create_tag(
info_pane[j].textbuffer,
213 "underline",
"underline", PANGO_UNDERLINE_SINGLE, NULL);
224 gtk_text_buffer_create_tag(
info_pane[j].textbuffer,
231 gtk_rc_get_style_by_paths(
232 gtk_settings_get_default(),
233 NULL,
"info_default", G_TYPE_NONE);
235 if (!base_style[0]) {
237 "Unable to find base style info_default"
238 " - will not process most info tag styles!");
257 snprintf(style_name,
sizeof(style_name),
"msg_%s",
msg_type_names[i].style_name);
262 gtk_rc_get_style_by_paths(
263 gtk_settings_get_default(), NULL, style_name, G_TYPE_NONE);
272 if (!
info_pane[j].msg_type_tags[type][subtype]) {
274 gtk_text_buffer_create_tag(
278 info_pane[j].msg_type_tags[type][subtype],
279 tmp_style, base_style[j]);
286 if (
info_pane[j].msg_type_tags[type][subtype]) {
287 gtk_text_tag_table_remove(
288 gtk_text_buffer_get_tag_table(
290 info_pane[j].msg_type_tags[type][subtype]);
304 gtk_rc_get_style_by_paths(
305 gtk_settings_get_default(), NULL, style_name, G_TYPE_NONE);
311 gtk_text_buffer_create_tag(
316 tmp_style, base_style[j]);
319 gtk_text_tag_table_remove(
320 gtk_text_buffer_get_tag_table(
332 gtk_rc_get_style_by_paths(
333 gtk_settings_get_default(),
340 gtk_text_buffer_create_tag(
344 info_pane[j].font_tags[i], tmp_style, base_style[j]);
347 gtk_text_tag_table_remove(
348 gtk_text_buffer_get_tag_table(
371 if (
info_pane[j].msg_type_tags[type][subtype]) {
372 gtk_text_tag_table_remove(
373 gtk_text_buffer_get_tag_table(
375 info_pane[j].msg_type_tags[type][subtype]);
383 gtk_text_tag_table_remove(
384 gtk_text_buffer_get_tag_table(
395 gtk_text_tag_table_remove(
396 gtk_text_buffer_get_tag_table(
420 xml_tree = glade_get_widget_tree(GTK_WIDGET(window_root));
422 snprintf(widget_name,
MAX_BUF,
"textview_info%d", i+1);
425 snprintf(widget_name,
MAX_BUF,
"scrolledwindow_textview%d", i+1);
428 glade_xml_get_widget(xml_tree, widget_name);
430 gtk_text_view_set_wrap_mode(
431 GTK_TEXT_VIEW(
info_pane[i].textview), GTK_WRAP_WORD);
434 gtk_text_view_get_buffer(GTK_TEXT_VIEW(
info_pane[i].textview));
437 gtk_scrolled_window_get_vadjustment(
438 GTK_SCROLLED_WINDOW(
info_pane[i].scrolled_window));
440 gtk_text_buffer_get_end_iter(
info_pane[i].textbuffer, &end);
443 gtk_text_buffer_create_mark(
446 gtk_widget_realize(
info_pane[i].textview);
482 int type,
int subtype,
483 int bold,
int italic,
484 int font,
char *color,
int underline)
488 int scroll_to_end=0, color_num;
489 GtkTextTag *color_tag=NULL, *type_tag=NULL;
502 for (color_num = 0; color_num <
NUM_COLORS; color_num++)
505 if (color_num < NUM_COLORS)
521 || type < 0 || subtype < 0 ) {
523 "type (%d) >= MSG_TYPE_LAST (%d) or "
524 "subtype (%d) >= max_subtype (%d)\n",
527 if (
info_pane[pane].msg_type_tags[type][subtype])
529 else if (
info_pane[pane].msg_type_tags[type][0])
533 gtk_text_view_get_visible_rect(
534 GTK_TEXT_VIEW(
info_pane[pane].textview), &rect);
536 if ((
info_pane[pane].adjustment->value + rect.height)
540 gtk_text_buffer_get_end_iter(
info_pane[pane].textbuffer, &end);
542 gtk_text_buffer_insert_with_tags(
543 info_pane[pane].textbuffer, &end, message, strlen(message),
549 color_tag, type_tag, NULL);
552 gtk_text_view_scroll_mark_onscreen(
574 char *marker, *current, *original;
575 int bold=0, italic=0,
font=0, underline=0;
583 current = strdup(message);
589 "Passed invalid color from server: %d, max allowed is %d\n",
590 orig_color, NUM_COLORS);
601 while ((marker = strchr(current,
'[')) != NULL) {
604 if (strlen(current) > 0)
606 current, type, subtype, bold, italic,
font, color, underline);
608 current = marker + 1;
610 if ((marker = strchr(current,
']')) == NULL) {
616 if (!strcmp(current,
"b")) bold =
TRUE;
617 else if (!strcmp(current,
"/b")) bold =
FALSE;
618 else if (!strcmp(current,
"i")) italic =
TRUE;
619 else if (!strcmp(current,
"/i")) italic =
FALSE;
620 else if (!strcmp(current,
"ul")) underline =
TRUE;
621 else if (!strcmp(current,
"/ul")) underline =
FALSE;
627 else if (!strcmp(current,
"/color")) color = NULL;
628 else if (!strncmp(current,
"color=", 6)) color = current + 6;
631 "unrecognized tag: [%s]\n", current);
633 current = marker + 1;
637 pane, current, type, subtype, bold, italic,
font, color, underline);
640 pane,
"\n", type, subtype, bold, italic,
font, color, underline);
682 gtk_text_view_get_visible_rect(
683 GTK_TEXT_VIEW(
info_pane[0].textview), &rect);
685 if ((
info_pane[0].adjustment->value + rect.height)
689 gtk_text_buffer_get_end_iter(
info_pane[0].textbuffer, &end);
691 gtk_text_buffer_insert_with_tags(
692 info_pane[0].textbuffer, &end, str, strlen(str),
695 gtk_text_buffer_insert(
info_pane[0].textbuffer, &end,
"\n" , 1);
698 gtk_text_view_scroll_mark_onscreen(
707 gtk_text_view_get_visible_rect(
708 GTK_TEXT_VIEW(
info_pane[1].textview), &rect);
710 if ((
info_pane[1].adjustment->value + rect.height)
716 gtk_text_buffer_get_end_iter(
info_pane[1].textbuffer, &end);
718 gtk_text_buffer_insert_with_tags(
719 info_pane[1].textbuffer, &end, str, strlen(str),
722 gtk_text_buffer_insert(
info_pane[1].textbuffer, &end,
"\n" , 1);
725 gtk_text_view_scroll_mark_onscreen(
754 gtk_text_buffer_set_text(
info_pane[i].textbuffer,
"", 0);
static XFontStruct * font
const Msg_Type_Names msg_type_names[]
static void add_to_textbuf(int pane, char *message, int type, int subtype, int bold, int italic, int font, char *color, int underline)
void setTextManager(int type, ExtTextManager callback)
struct Info_Pane info_pane[NUM_TEXT_VIEWS]
static char * font_style_names[NUM_FONTS]
void draw_color_info(int colr, const char *buf)
const char *const usercolorname[NUM_COLORS]
void set_text_tag_from_style(GtkTextTag *tag, GtkStyle *style, GtkStyle *base_style)
void LOG(LogLevel level, const char *origin, const char *format,...)
GtkTextTag ** msg_type_tags[MSG_TYPE_LAST]
const char *const colorname[NUM_COLORS]
void info_get_styles(void)
GtkTextTag * color_tags[NUM_COLORS]
void draw_info(const char *str, int color)
GtkTextBuffer * textbuffer
GtkWidget * scrolled_window
const char *const rcsid_gtk2_info_c
GtkTextTag * font_tags[NUM_FONTS]
void set_scroll(const char *s)
GtkTextTag * underline_tag
void set_autorepeat(const char *s)
GtkAdjustment * adjustment
void info_init(GtkWidget *window_root)
static void message_callback(int flag, int type, int subtype, char *message)