Fixed reversevideo
authorMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Sun, 15 Nov 2009 16:42:48 +0000 (16:42 +0000)
committerMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Sun, 15 Nov 2009 16:42:48 +0000 (16:42 +0000)
Fixed input style

git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@167 ddfedd41-794f-dd11-ae45-00112f111e67

libchimara/Makefile.am
libchimara/garglk.c
libchimara/garglk.h
libchimara/input.c
libchimara/style.c

index 9676f852b34e701fa512059e01c15fcb184ff68a..ddc0438b40790610df7d1fc18010b0c3163c595e 100644 (file)
@@ -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 \
index 4708174112eb3821b01294e3fa7bc75e1bd66822..1a76bd7e4e36ca9b7076966484b07f375c943b3e 100644 (file)
@@ -1,6 +1,23 @@
 #include <libchimara/glk.h>
+#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) );
 }
+
index e5234b7b875c03a802def3f31f2959e7330aba55..a4dfba6a3a503ee191c9173577e6923a8867c324 100644 (file)
@@ -3,4 +3,4 @@
 
 extern void garglk_set_reversevideo(glui32 reverse);
 
-#endif /* __GARGLK_H__ */
\ No newline at end of file
+#endif /* __GARGLK_H__ */
index 605616d0e38c9eb94473ab292c592a984bc1af8c..6a050005e9a555094bd09351e00e2269ef64ced8 100644 (file)
@@ -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
index cf20f0ca1ccbe58f77805b96db02016e55a61207..5b388f1032e78fb66796627e9b780f502966696b 100644 (file)
@@ -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: