Special Portal commit
authorrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Sat, 14 Nov 2009 22:50:17 +0000 (22:50 +0000)
committerrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Sat, 14 Nov 2009 22:50:17 +0000 (22:50 +0000)
libchimara/input.c
libchimara/window.c
libchimara/window.h

index f48aa848fbc3ccda941dcac94e14d1e2474ae6be..a0d2ec759eedd6a90bf3dfd90c0be1eb1cf1c9bb 100644 (file)
@@ -385,31 +385,8 @@ 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. */
 gboolean
-on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
+on_char_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
 {
-       /* If this is a text grid window, and line input is active, then redirect the key press to the line input GtkEntry */
-       if( win->type == wintype_TextGrid && (win->input_request_type == INPUT_REQUEST_LINE || win->input_request_type == INPUT_REQUEST_LINE_UNICODE) )
-       {
-               if(event->keyval == GDK_Up || event->keyval == GDK_KP_Up
-                   || event->keyval == GDK_Down || event->keyval == GDK_KP_Down
-                   || event->keyval == GDK_Left || event->keyval == GDK_KP_Left
-                   || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
-                   || event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab
-                   || event->keyval == GDK_Page_Up || event->keyval == GDK_KP_Page_Up
-                   || event->keyval == GDK_Page_Down || event->keyval == GDK_KP_Page_Down
-                   || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
-                   || event->keyval == GDK_End || event->keyval == GDK_KP_End)
-                       return FALSE; /* Don't redirect these keys */
-               gtk_widget_grab_focus(win->input_entry);
-               gtk_editable_set_position(GTK_EDITABLE(win->input_entry), -1);
-               gboolean retval = TRUE;
-               g_signal_emit_by_name(win->input_entry, "key-press-event", event, &retval);
-               return retval; /* Block this key event if the entry handled it */
-       }
-       if(win->input_request_type != INPUT_REQUEST_CHARACTER && 
-               win->input_request_type != INPUT_REQUEST_CHARACTER_UNICODE)
-               return FALSE;
-
        glui32 keycode = keyval_to_glk_keycode(event->keyval, win->input_request_type == INPUT_REQUEST_CHARACTER_UNICODE);
 
        ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(widget, CHIMARA_TYPE_GLK));
@@ -424,6 +401,44 @@ on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
        return TRUE;
 }
 
+gboolean
+on_line_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
+{
+       switch(win->type)
+       {
+               case wintype_TextBuffer:
+                       if(event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
+                       {
+                               
+                       }
+                       else if(event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
+                       {
+                       
+                       }
+                       break;
+
+               /* If this is a text grid window, then redirect the key press to the line input GtkEntry */
+               case wintype_TextGrid:
+               {
+                       if(event->keyval == GDK_Up || event->keyval == GDK_KP_Up
+                               || event->keyval == GDK_Down || event->keyval == GDK_KP_Down
+                               || event->keyval == GDK_Left || event->keyval == GDK_KP_Left
+                               || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
+                               || event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab
+                               || event->keyval == GDK_Page_Up || event->keyval == GDK_KP_Page_Up
+                               || event->keyval == GDK_Page_Down || event->keyval == GDK_KP_Page_Down
+                               || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
+                               || event->keyval == GDK_End || event->keyval == GDK_KP_End)
+                               return FALSE; /* Don't redirect these keys */
+                       gtk_widget_grab_focus(win->input_entry);
+                       gtk_editable_set_position(GTK_EDITABLE(win->input_entry), -1);
+                       gboolean retval = TRUE;
+                       g_signal_emit_by_name(win->input_entry, "key-press-event", event, &retval);
+                       return retval; /* Block this key event if the entry handled it */
+               }
+       }
+}
+
 /* Internal function: finish handling a line input request, for both text grid and text buffer windows. */
 static int
 write_to_window_buffer(winid_t win, const gchar *inserted_text)
@@ -503,6 +518,11 @@ finish_text_buffer_line_input(winid_t win, gboolean emit_signal)
                g_assert(glk);
                g_signal_emit_by_name(glk, "line-input", win->rock, inserted_text);
        }
+       
+       /* Add the text to the window input history */
+       win->history = g_list_prepend(win->history, g_strdup(inserted_text));
+       win->history_pos = win->history;
+       
        g_free(inserted_text);
 
        return chars_written;
index 1f287700a8ce8a51dfc11355ed28dd6bf2a3481c..8e83b9d194f92c080bcef3020bcd721785297f34 100644 (file)
@@ -30,6 +30,7 @@ window_new_common(glui32 rock)
        win->input_request_type = INPUT_REQUEST_NONE;
        win->line_input_buffer = NULL;
        win->line_input_buffer_unicode = NULL;
+       win->history = NULL;
 
        /* Initialise the buffer */
        win->buffer = g_string_sized_new(1024);
@@ -52,6 +53,9 @@ window_close_common(winid_t win, gboolean destroy_node)
                g_node_destroy(win->window_node);
        win->magic = MAGIC_FREE;
 
+       g_list_foreach(win->history, g_free, NULL);
+       g_list_free(win->history);
+
        g_string_free(win->buffer, TRUE);
        g_free(win);
 }
index 71bbb7436168cbbe368ae5827920e05f58d7c422..544d0cec62129350e8af65aefbd5d770ff9bdd2b 100644 (file)
@@ -59,12 +59,15 @@ struct glk_window_struct
        glui32 line_input_buffer_max_len;
        gidispatch_rock_t buffer_rock;
        gboolean mouse_input_requested;
+       GList *history;
+       GList *history_pos;
        /* Line input field (text grids only) */
        glui32 input_length;
        GtkTextChildAnchor *input_anchor;
        GtkWidget *input_entry;
        /* Signal handlers */
-       gulong keypress_handler;
+       gulong char_input_keypress_handler;
+       gulong line_input_keypress_handler;
        gulong insert_text_handler;
        gulong mouse_click_handler;
        gulong mouse_move_handler;