Re: is there a signal for typing at bottom of window?
- From: <cecashon aol com>
- To: dougm bravoecho net, jkraehemann gmail com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: is there a signal for typing at bottom of window?
- Date: Thu, 27 Sep 2018 21:46:48 +0000 (UTC)
You might be able to fiddle around with the newlines at the end of the buffer to get something to work with
the textview.
Eric
//gcc -Wall text_space1.c -o text_space1 `pkg-config --cflags --libs gtk+-3.0`
#include <gtk/gtk.h>
static void value_changed(GtkAdjustment *v_adjust, GtkWidget **widgets)
{
static gint s_line=0;
GtkTextIter iter, end_iter;
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(widgets[0]));
GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
gtk_text_buffer_get_end_iter(buffer, &end_iter);
gint line=gtk_text_iter_get_line(&iter);
//Check if cursor line is below a certain line in the buffer.
gint below=gtk_text_buffer_get_line_count(buffer)-6;
if(s_line!=line&&line>below)
{
g_print("Scroll Line\n");
gint count=0;
gint i=0;
//Check for newlines.
gtk_text_iter_backward_char(&end_iter);
for(i=0;i<4;i++)
{
if('\n'==gtk_text_iter_get_char(&end_iter)) count++;
if(!gtk_text_iter_backward_char(&end_iter))
{
g_print("Break\n");
break;
}
}
//Add newlines if needed.
if(count>0)
{
GtkTextMark *mark2=gtk_text_buffer_create_mark(buffer, "back", &iter, TRUE);
gint newlines=4-count;
gtk_text_buffer_get_end_iter(buffer, &end_iter);
gchar string[newlines];
for(i=0;i<newlines;i++) string[i]='\n';
gtk_text_buffer_insert(buffer, &end_iter, string, newlines);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark2);
gtk_text_buffer_place_cursor(buffer, &iter);
gtk_range_set_value(GTK_RANGE(widgets[1]), gtk_adjustment_get_upper(v_adjust));
gtk_text_buffer_delete_mark(buffer, mark2);
}
s_line=line;
}
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Text Space");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
GtkTextIter iter;
gtk_text_buffer_get_end_iter(buffer, &iter);
GtkTextMark *mark=gtk_text_buffer_create_mark(buffer, "back", &iter, TRUE);
//Append 4 newlines to the buffer.
gtk_text_buffer_insert(buffer, &iter, "\n\n\n\n", -1);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
gtk_text_buffer_place_cursor(buffer, &iter);
gtk_text_buffer_delete_mark(buffer, mark);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
GtkAdjustment *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
gtk_container_add(GTK_CONTAINER(scroll), textview);
GtkWidget *range=gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scroll));
GtkWidget *widgets[2]={textview, range};
g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed), widgets);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]