Fixed text grid line input bugs
authorPhilip Chimento <philip.chimento@gmail.com>
Tue, 17 Nov 2009 00:03:43 +0000 (00:03 +0000)
committerPhilip Chimento <philip.chimento@gmail.com>
Tue, 17 Nov 2009 00:03:43 +0000 (00:03 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@168 ddfedd41-794f-dd11-ae45-00112f111e67

libchimara/input.c
libchimara/window.c
tests/gridtest.c
tests/plugin-loader.c

index 6a050005e9a555094bd09351e00e2269ef64ced8..82269835dd0d82d45c95051d615c9336663fc146 100644 (file)
@@ -22,7 +22,7 @@ request_char_event_common(winid_t win, gboolean unicode)
        ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
 
        win->input_request_type = unicode? INPUT_REQUEST_CHARACTER_UNICODE : INPUT_REQUEST_CHARACTER;
-       g_signal_handler_unblock( G_OBJECT(win->widget), win->char_input_keypress_handler );
+       g_signal_handler_unblock( win->widget, win->char_input_keypress_handler );
 
        gdk_threads_enter();
        
@@ -158,8 +158,6 @@ text_grid_request_line_event_common(winid_t win, glui32 maxlen, gboolean insert,
     
     gtk_widget_show(win->input_entry);
     gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(win->widget), win->input_entry, win->input_anchor);
-       
-       g_signal_handler_unblock( G_OBJECT(win->widget), win->char_input_keypress_handler );
 
        gtk_widget_grab_focus(win->input_entry);
        
@@ -266,6 +264,7 @@ glk_request_line_event(winid_t win, char *buf, glui32 maxlen, glui32 initlen)
                break;
     }
        g_free(inserttext);
+       g_signal_handler_unblock(win->widget, win->line_input_keypress_handler);
        
        /* Emit the "waiting" signal to let listeners know we are ready for input */
        g_signal_emit_by_name(glk_data->self, "waiting");
@@ -325,7 +324,8 @@ glk_request_line_event_uni(winid_t win, glui32 *buf, glui32 maxlen, glui32 initl
            case wintype_TextGrid:
                text_grid_request_line_event_common(win, maxlen, (initlen > 0), utf8);
                break;
-    }          
+    }
+    g_signal_handler_unblock(win->widget, win->line_input_keypress_handler);
        g_free(utf8);
        
        /* Emit the "waiting" signal to let listeners know we are ready for input */
@@ -364,12 +364,11 @@ glk_cancel_line_event(winid_t win, event_t *event)
        if(win->input_request_type != INPUT_REQUEST_LINE && win->input_request_type != INPUT_REQUEST_LINE_UNICODE)
                return;
 
-       g_signal_handler_block( G_OBJECT(win->widget), win->char_input_keypress_handler );
+       g_signal_handler_block( win->widget, win->line_input_keypress_handler );
 
        int chars_written = 0;
 
        if(win->type == wintype_TextGrid) {
-               g_signal_handler_block( G_OBJECT(win->widget), win->char_input_keypress_handler );
                chars_written = finish_text_grid_line_input(win, FALSE);
        } else if(win->type == wintype_TextBuffer) {
                GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
@@ -392,7 +391,7 @@ glk_cancel_line_event(winid_t win, event_t *event)
        }
 }
 
-/* Internal function: General callback for signal key-press-event on a text buffer or text grid window. Used in character input on both text buffers and grids, and also in line input on grids, to redirect keystrokes to the line input field. Blocked when not in use. */
+/* Internal function: General callback for signal key-press-event on a text buffer or text grid window. Used in character input on both text buffers and grids. Blocked when not in use. */
 gboolean
 on_char_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
 {
@@ -655,6 +654,7 @@ after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar
        {
                /* Remove signal handlers */
                g_signal_handler_block(window_buffer, win->insert_text_handler);
+               g_signal_handler_block(win->widget, win->line_input_keypress_handler);
                
                /* Make the window uneditable again and retrieve the text that was input */
         gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), FALSE);
@@ -678,7 +678,7 @@ in a text grid window. */
 void
 on_input_entry_activate(GtkEntry *input_entry, winid_t win)
 {
-       g_signal_handler_block(win->widget, win->char_input_keypress_handler);
+       g_signal_handler_block(win->widget, win->line_input_keypress_handler);
 
        int chars_written = finish_text_grid_line_input(win, TRUE);
        ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK));
@@ -703,8 +703,8 @@ on_input_entry_key_press_event(GtkEntry *input_entry, GdkEventKey *event, winid_
        
                if(win->history_pos == NULL) 
                {
-                       gchar *current_input = gtk_entry_get_text(input_entry);
-                       win->history = g_list_prepend(win->history, current_input);
+                       const gchar *current_input = gtk_entry_get_text(input_entry);
+                       win->history = g_list_prepend(win->history, g_strdup(current_input));
                        win->history_pos = win->history;
                }
 
index d78853d5ceda77510ba99f0cb4d016679f1489ce..87264c1156a418bdee1692bd46df49ebecdb4017 100644 (file)
@@ -488,10 +488,12 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        /* width and height are set later */
                        
                        /* Connect signal handlers */
-                       win->char_input_keypress_handler = g_signal_connect( G_OBJECT(textview), "key-press-event", G_CALLBACK(on_char_input_key_press_event), win );
+                       win->char_input_keypress_handler = g_signal_connect(textview, "key-press-event", G_CALLBACK(on_char_input_key_press_event), win);
                        g_signal_handler_block(textview, win->char_input_keypress_handler);
+                       win->line_input_keypress_handler = g_signal_connect(textview, "key-press-event", G_CALLBACK(on_line_input_key_press_event), win);
+                       g_signal_handler_block(textview, win->line_input_keypress_handler);
 
-                       gtk_widget_add_events( GTK_WIDGET(textview), GDK_BUTTON_RELEASE_MASK );
+                       gtk_widget_add_events( textview, GDK_BUTTON_RELEASE_MASK );
                        win->mouse_click_handler = g_signal_connect_after( G_OBJECT(textview), "button-release-event", G_CALLBACK(on_window_button_release_event), win );
                        g_signal_handler_block( textview, win->mouse_click_handler );
 
@@ -530,15 +532,16 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        g_object_unref(zero);
 
                        /* Connect signal handlers */
-                       win->char_input_keypress_handler = g_signal_connect( G_OBJECT(textview), "key-press-event", G_CALLBACK(on_char_input_key_press_event), win );
-                       g_signal_handler_block( G_OBJECT(textview), win->char_input_keypress_handler );
-                       win->line_input_keypress_handler = g_signal_connect( G_OBJECT(textview), "key-press-event", G_CALLBACK(on_line_input_key_press_event), win );
+                       win->char_input_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(on_char_input_key_press_event), win );
+                       g_signal_handler_block(textview, win->char_input_keypress_handler);
+                       win->line_input_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(on_line_input_key_press_event), win );
+                       g_signal_handler_block(textview, win->line_input_keypress_handler);
                        
                        gtk_widget_add_events( GTK_WIDGET(textview), GDK_BUTTON_RELEASE_MASK );
-                       win->mouse_click_handler = g_signal_connect_after( G_OBJECT(textview), "button-release-event", G_CALLBACK(on_window_button_release_event), win );
+                       win->mouse_click_handler = g_signal_connect_after( textview, "button-release-event", G_CALLBACK(on_window_button_release_event), win );
                        g_signal_handler_block( textview, win->mouse_click_handler );
 
-                       win->insert_text_handler = g_signal_connect_after( G_OBJECT(textbuffer), "insert-text", G_CALLBACK(after_window_insert_text), win );
+                       win->insert_text_handler = g_signal_connect_after( textbuffer, "insert-text", G_CALLBACK(after_window_insert_text), win );
                        g_signal_handler_block( textbuffer, win->insert_text_handler );
 
                        /* Create an editable tag to indicate uneditable parts of the window
index c33a4766add973fe3da386c46f96cdadf95e48be..59804940d8528dffc31e9bbe0dab583c4d638dfd 100644 (file)
@@ -12,82 +12,37 @@ void glk_main(void)
         return;
     
     glk_set_window(mainwin);
-    glk_put_string("Philip en Marijn zijn vet goed.\n");
-    glk_put_string("A veeeeeeeeeeeeeeeeeeeeeeeeeeeery looooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing.\n");
-    
-    int count;
-    for(count = 0; count < 30; count++)
-        glk_put_string("I want to write past the end of this text buffer! ");
-    
-    glui32 width, height;
+    glui32 width, height, x, y;
     glk_window_get_size(mainwin, &width, &height);
-    fprintf(stderr, "\nWidth: %d\nHeight: %d\nPress a key in the window, not in the terminal.\n", width, height);
-    glk_request_char_event(mainwin);
-    while(1) {
-        glk_select(&ev);
-        if(ev.type == evtype_CharInput)
-            break;
-    }
-    
-    glk_window_move_cursor(mainwin, 15, 15);
-    glk_put_string(". . ");
-    glk_window_move_cursor(mainwin, 15, 16);
-    glk_put_string(" . .");
-    glk_window_move_cursor(mainwin, 15, 17);
-    glk_put_string(". . ");
-    glk_window_move_cursor(mainwin, 15, 18);
-    glk_put_string(" . .");
-    fprintf(stderr, "Cursor location test.\nPress another key.\n");
-    glk_request_char_event(mainwin);
-    while(1) {
-        glk_select(&ev);
-        if(ev.type == evtype_CharInput)
-            break;
+    if(height < 4 || width < 22)
+    {
+       glk_put_string("Window not big enough");
+       glk_exit();
     }
+    x = width / 2 - 10;
+    y = height / 2;
     
     char *buffer = calloc(256, sizeof(char));
     assert(buffer);
     
-    fprintf(stderr, "Line input field until end of line\n");
-    glk_window_move_cursor(mainwin, 10, 18);
-    glk_request_line_event(mainwin, buffer, 256, 0);
-    while(1) {
-        glk_select(&ev);
-        if(ev.type == evtype_LineInput)
-            break;
-    }
-    
-    fprintf(stderr, "Another line input field until end of line\n");
-    glk_window_move_cursor(mainwin, 10, 20);
-    glk_request_line_event(mainwin, buffer, 256, 0);
-    while(1) {
-        glk_select(&ev);
-        if(ev.type == evtype_LineInput)
-            break;
-    }
-    
-    fprintf(stderr, "Now edit your previous line input\n");
-    glk_window_move_cursor(mainwin, 10, 22);
-    glk_request_line_event(mainwin, buffer, 256, strlen(buffer));
-    while(1) {
+    glk_window_move_cursor(mainwin, x, y - 1);
+    glk_put_string("Enter text, or 'quit'");
+    glk_window_move_cursor(mainwin, x, y);
+    glk_request_line_event(mainwin, buffer, 21, 0);
+    while(strncmp(buffer, "quit", 4)) 
+    {
         glk_select(&ev);
         if(ev.type == evtype_LineInput)
-            break;
+        {
+               glk_window_move_cursor(mainwin, x, y + 1);
+               glk_put_string("                     ");
+               glk_window_move_cursor(mainwin, x, y + 1);
+               glk_put_buffer(buffer, ev.val1);
+               glk_window_move_cursor(mainwin, x, y);
+               glk_request_line_event(mainwin, buffer, 21, 0);
+        }
     }
-    
-       char *text = calloc(ev.val1 + 1, sizeof(char));
-       assert(text);
-       strncpy(text, buffer, ev.val1);
-       text[ev.val1] = '\0';
-    fprintf(stderr, "Your string was: '%s'.\nPress another key to clear the window and exit.\n", text);
-       free(text);
-    glk_request_char_event(mainwin);
-    while(1) {
-        glk_select(&ev);
-        if(ev.type == evtype_CharInput)
-            break;
-    }
-    
+    glk_cancel_line_event(mainwin, NULL);
     glk_window_clear(mainwin);
     free(buffer);
 }
index 03ab746cb3a3ce7377a44390306fca5ba7827bc7..767be6cd4ff7fb4d2d44902b3ecc19748b44ee2d 100644 (file)
@@ -64,6 +64,7 @@ create_window(void)
                "border-width", 6, 
                "spacing", 6,
                NULL);
+       g_signal_connect(glk, "stopped", G_CALLBACK(gtk_main_quit), NULL);
        chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12");
        chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12");
        gtk_container_add(GTK_CONTAINER(window), glk);