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();
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);
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");
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 */
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) );
}
}
-/* 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)
{
{
/* 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);
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));
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;
}
/* 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 );
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
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);
}
"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);