From: rodin Date: Sat, 14 Nov 2009 22:50:17 +0000 (+0000) Subject: Special Portal commit X-Git-Tag: v0.9~304 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=f41fc44565ee60d1551de548c50cb35336322f1b;p=projects%2Fchimara%2Fchimara.git Special Portal commit --- diff --git a/libchimara/input.c b/libchimara/input.c index f48aa84..a0d2ec7 100644 --- a/libchimara/input.c +++ b/libchimara/input.c @@ -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; diff --git a/libchimara/window.c b/libchimara/window.c index 1f28770..8e83b9d 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -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); } diff --git a/libchimara/window.h b/libchimara/window.h index 71bbb74..544d0ce 100644 --- a/libchimara/window.h +++ b/libchimara/window.h @@ -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;