g_signal_handler_unblock( win->widget, win->char_input_keypress_handler );
gdk_threads_enter();
-
- /*
- if(win->type == wintype_TextBuffer)
- {
- GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
- GtkTextIter iter;
- gtk_text_buffer_get_end_iter(buffer, &iter);
- gtk_text_buffer_place_cursor(buffer, &iter);
- gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), gtk_text_buffer_get_insert(buffer));
- // Why doesn't this always work??
- } */
-
gtk_widget_grab_focus( GTK_WIDGET(win->widget) );
gdk_threads_leave();
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);
/* Helper function: move the pager to the last visible position in the buffer,
and return the distance between the pager and the end of the buffer in buffer
coordinates */
-static gint
-move_pager_and_get_scroll_distance(GtkTextView *textview)
+static void
+move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gint *scroll_distance)
{
+ while( gtk_events_pending() ) {
+ gtk_main_iteration();
+ }
+
GdkRectangle pagerpos, endpos, visiblerect;
GtkTextIter oldpager, newpager, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
gtk_text_buffer_get_iter_at_mark(buffer, &newpager, pager);
gtk_text_view_get_iter_location(textview, &newpager, &pagerpos);
gtk_text_view_get_iter_location(textview, &end, &endpos);
+
+ g_printerr("View height = %d\n", visiblerect.height);
+ g_printerr("End - Pager = %d\n", endpos.y - pagerpos.y);
- //g_printerr("View height = %d\n", visiblerect.height);
- //g_printerr("End - Pager = %d\n", endpos.y - pagerpos.y);
-
- return endpos.y - pagerpos.y;
+ *view_height = visiblerect.height;
+ *scroll_distance = endpos.y - pagerpos.y;
}
/* Helper function: turn on paging for this textview */
g_signal_handler_block(win->widget, win->pager_keypress_handler);
}
-/* Update the pager position after new text is inserted in the buffer */
+/* Update the pager position after new text is inserted in the buffer and the
+text view has calculated where it is */
void
-pager_after_insert_text(GtkTextBuffer *buffer, GtkTextIter *location, gchar *text, gint len, winid_t win)
+pager_after_size_allocate(GtkTextView *view, GtkAllocation *allocation, winid_t win)
{
while(gtk_events_pending())
gtk_main_iteration();
/* Move the pager to the last visible character in the buffer */
- gint scroll_distance = move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget) );
+ gint view_height, scroll_distance;
+ move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance );
- if(scroll_distance > 0 && !win->currently_paging)
- start_paging(win);
+ if(!win->currently_paging) {
+ if(scroll_distance > view_height) {
+ start_paging(win);
+ /* Seriously... */
+ gdk_window_invalidate_rect(gtk_widget_get_window(win->widget), NULL, TRUE);
+ }
+ else if(scroll_distance > 0) {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
+ gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), gtk_text_buffer_get_mark(buffer, "end_position"));
+ while( gtk_events_pending() ) {
+ gtk_main_iteration();
+ }
+ }
+ }
}
void
gtk_main_iteration();
/* Move the pager, etc. */
- gint scroll_distance = move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget) );
+ gint scroll_distance, view_height;
+ move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance );
if(scroll_distance > 0 && !win->currently_paging)
start_paging(win);
gboolean
pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win)
{
- /*** ALTERNATIVE, POSSIBLY INFERIOR, METHOD OF SCROLLING ***
- GtkTextMark *pagermark = gtk_text_buffer_get_mark(buffer, "pager_position");
- gtk_text_view_scroll_to_mark(textview, pagermark, 0.0, TRUE, 0.0, 0.0);
- */
-
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(win->frame) );
gdouble step_increment, page_size, upper, lower, value;
g_object_get(adj,
/* Draw the 'more' tag */
GdkGC *context = gdk_gc_new(GDK_DRAWABLE(event->window));
- /*
- gdk_draw_layout_with_colors(event->window, context,
- winx + winwidth - promptwidth,
- winy + winheight - promptheight,
- prompt, &white, &red);
- */
gdk_draw_layout(event->window, context,
winx + winwidth - promptwidth,
winy + winheight - promptheight,
/* Connect signal handlers */
/* Pager */
- win->pager_expose_handler = g_signal_connect( textview, "expose-event", G_CALLBACK(pager_on_expose), win );
+ /* "size-allocate"? Really? WTF, GTK? */
+ g_signal_connect_after( textview, "size-allocate", G_CALLBACK(pager_after_size_allocate), win );
+ win->pager_expose_handler = g_signal_connect_after( textview, "expose-event", G_CALLBACK(pager_on_expose), win );
g_signal_handler_block(textview, win->pager_expose_handler);
win->pager_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(pager_on_key_press_event), win );
g_signal_handler_block(textview, win->pager_keypress_handler);
- g_signal_connect_after( textbuffer, "insert-text", G_CALLBACK(pager_after_insert_text), win );
+ //g_signal_connect_after( textbuffer, "insert-text", G_CALLBACK(pager_after_insert_text), win );
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow));
g_signal_connect_after(adj, "value-changed", G_CALLBACK(pager_after_adjustment_changed), win);
(for line input) */
gtk_text_buffer_create_tag(textbuffer, "uneditable", "editable", FALSE, "editable-set", TRUE, NULL);
- /* Mark the position where the user will input text */
+ /* Mark the position where the user will input text and the end mark */
GtkTextIter end;
gtk_text_buffer_get_end_iter(textbuffer, &end);
gtk_text_buffer_create_mark(textbuffer, "input_position", &end, TRUE);
+ gtk_text_buffer_create_mark(textbuffer, "end_position", &end, FALSE);
/* Create the pager position mark; it stands for the last character in the buffer
that has been on-screen */