From 2925a5dc60b950752eb86c96ffb380ed40e4fe1b Mon Sep 17 00:00:00 2001 From: Marijn van Vliet Date: Sun, 15 Nov 2009 16:42:48 +0000 Subject: [PATCH] Fixed reversevideo Fixed input style git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@167 ddfedd41-794f-dd11-ae45-00112f111e67 --- libchimara/Makefile.am | 2 +- libchimara/garglk.c | 17 +++++++++++++++++ libchimara/garglk.h | 2 +- libchimara/input.c | 20 ++++++++++++++++++-- libchimara/style.c | 15 ++++++++------- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/libchimara/Makefile.am b/libchimara/Makefile.am index 9676f85..ddc0438 100644 --- a/libchimara/Makefile.am +++ b/libchimara/Makefile.am @@ -43,7 +43,7 @@ libchimara_la_CFLAGS = @CHIMARA_CFLAGS@ $(AM_CFLAGS) libchimara_la_LIBADD = @CHIMARA_LIBS@ libchimara_la_LDFLAGS = -version-info $(LT_VERSION_INFO) \ -no-undefined \ - -export-symbols-regex "^(glk|chimara|glkunix|giblorb|gidispatch|garglk)_" + -export-symbols-regex "^(glk|chimara|glkunix|giblorb|gidispatch)_" libchimara_includedir = $(includedir)/chimara/libchimara libchimara_include_HEADERS = \ chimara-glk.h \ diff --git a/libchimara/garglk.c b/libchimara/garglk.c index 4708174..1a76bd7 100644 --- a/libchimara/garglk.c +++ b/libchimara/garglk.c @@ -1,6 +1,23 @@ #include +#include "chimara-glk-private.h" + +extern GPrivate *glk_data_key; + +void +apply_reverse_color(GtkTextTag *tag, gpointer data) +{ + g_object_set_data( G_OBJECT(tag), "reverse_color", data ); +} void garglk_set_reversevideo(glui32 reverse) { + printf("set_reversevideo(%d)\n", reverse); + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + g_return_if_fail(glk_data->current_stream != NULL); + g_return_if_fail(glk_data->current_stream->window != NULL); + + GtkTextTagTable *tags = gtk_text_buffer_get_tag_table( GTK_TEXT_BUFFER(glk_data->current_stream->window->widget) ); + gtk_text_tag_table_foreach( tags, apply_reverse_color, GINT_TO_POINTER(reverse) ); } + diff --git a/libchimara/garglk.h b/libchimara/garglk.h index e5234b7..a4dfba6 100644 --- a/libchimara/garglk.h +++ b/libchimara/garglk.h @@ -3,4 +3,4 @@ extern void garglk_set_reversevideo(glui32 reverse); -#endif /* __GARGLK_H__ */ \ No newline at end of file +#endif /* __GARGLK_H__ */ diff --git a/libchimara/input.c b/libchimara/input.c index 605616d..6a05000 100644 --- a/libchimara/input.c +++ b/libchimara/input.c @@ -190,11 +190,18 @@ text_buffer_request_line_event_common(winid_t win, glui32 maxlen, gboolean inser gtk_text_buffer_apply_tag_by_name(buffer, "uneditable", &start_iter, &end_iter); /* Insert pre-entered text if needed */ - if(insert) + if(insert) { gtk_text_buffer_insert(buffer, &end_iter, inserttext, -1); + gtk_text_buffer_get_end_iter(buffer, &end_iter); /* update after text insertion */ + } /* Scroll to input point */ gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), input_position); + + /* Apply the correct style to the input prompt */ + GtkTextIter input_iter; + gtk_text_buffer_get_iter_at_mark(buffer, &input_iter, input_position); + gtk_text_buffer_apply_tag_by_name(buffer, "input", &input_iter, &end_iter); gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), TRUE); g_signal_handler_unblock(buffer, win->insert_text_handler); @@ -635,6 +642,8 @@ pasted into the window. */ void after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar *text, gint len, winid_t win) { + GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) ); + /* Set the history position to NULL and erase the text we were already editing */ if(win->history_pos != NULL) { @@ -645,7 +654,6 @@ after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar if( strchr(text, '\n') != NULL ) { /* Remove signal handlers */ - GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) ); g_signal_handler_block(window_buffer, win->insert_text_handler); /* Make the window uneditable again and retrieve the text that was input */ @@ -655,6 +663,14 @@ after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); event_throw(glk, evtype_LineInput, win, chars_written, 0); } + + /* Apply the 'input' style to the text that was entered */ + GtkTextIter end_iter; + gtk_text_buffer_get_end_iter(window_buffer, &end_iter); + GtkTextIter input_iter; + GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position"); + gtk_text_buffer_get_iter_at_mark(window_buffer, &input_iter, input_position); + gtk_text_buffer_apply_tag_by_name(window_buffer, "input", &input_iter, &end_iter); } /* Internal function: Callback for signal activate on the line input GtkEntry diff --git a/libchimara/style.c b/libchimara/style.c index cf20f0c..5b388f1 100644 --- a/libchimara/style.c +++ b/libchimara/style.c @@ -153,9 +153,12 @@ gtk_text_tag_copy(GtkTextTag *tag) _COPY_FLAG (language_set); #undef _COPY_FLAG + /* Copy the reverse_color attribute, that was added manually */ + g_object_set_data( G_OBJECT(copy), "reverse_color", g_object_get_data(G_OBJECT(tag), "reverse_color") ); + return copy; } - + /* Internal function that reads the default styles from a CSS file */ void style_init() @@ -474,11 +477,8 @@ apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val) ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); GObject *tag_object = G_OBJECT(tag); - gint reverse_color = 0; - /* FIXME where should we keep track of this? - g_object_get(tag, "reverse_color", &reverse_color, NULL); - */ + gint reverse_color = GPOINTER_TO_INT( g_object_get_data(tag_object, "reverse-color") ); int i = 0; gchar color[20]; @@ -569,6 +569,8 @@ apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val) g_object_set(tag_object, "background-gdk", foreground_color, NULL); else g_object_set(tag_object, "background", "#000000", NULL); + + g_object_set_data( tag_object, "reverse-color", GINT_TO_POINTER(val != 0) ); } break; @@ -648,8 +650,7 @@ query_tag(GtkTextTag *tag, glui32 hint) break; case stylehint_ReverseColor: - /* FIXME: implement this */ - return 0; + return GPOINTER_TO_INT( g_object_get_data(G_OBJECT(tag), "reverse_color") ); break; default: -- 2.30.2