Mageia Bugzilla – Attachment 8821 Details for
Bug 20036
Gtk3 textview application breaks if it contains invisible text and uses pixel_below_lines > 1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Test demo application that illustrates the problem
demo.c (text/x-csrc), 2.28 KB, created by
Juergen Harms
on 2016-12-28 12:29:17 CET
(
hide
)
Description:
Test demo application that illustrates the problem
Filename:
MIME Type:
Creator:
Juergen Harms
Created:
2016-12-28 12:29:17 CET
Size:
2.28 KB
patch
obsolete
>#include <gtk/gtk.h> >#include <string.h> > >#define MAX_SEEN 30 > >/* Gtk3 textview error demo > ------------------------ > > The application aborts when the pointer enters a line of the textview-panel > that contains invisible text (marked by a trailing '#' character): > >(demo:30090): Gtk-WARNING **: gtktextbtree.c:4041: byte index off the end of the line >(demo:30090): Gtk-ERROR **: Byte index 44 is off the end of the line > > Compile/bind/run with: > gcc `pkg-config --cflags gtk+-3.0` -o demo demo.c `pkg-config --libs gtk+-3.0` ; demo >*/ > >static void activate ( > GtkApplication *app, > gpointer user_data ) >{ > GtkWidget *window; > GtkTextView *text_panel; > GtkTextBuffer *x_bf; > GtkTextIter x_iter; > GtkTextTag *hide_tag; > > int ii; > char *x_data[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ", > "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", > "ABCDEFGHIJKLM", > NULL }; > > window = gtk_application_window_new (app); > gtk_window_set_title ( GTK_WINDOW (window), "Window" ); > gtk_window_set_default_size ( GTK_WINDOW (window), 400, 100 ); > > text_panel = (GtkTextView *)gtk_text_view_new (); > gtk_container_add ( GTK_CONTAINER (window), (GtkWidget *)text_panel ); > gtk_text_view_set_pixels_below_lines ( text_panel, 2 ); /*###########*/ > > x_bf = gtk_text_view_get_buffer ( text_panel ); > gtk_text_buffer_get_start_iter ( x_bf, &x_iter ); > hide_tag = gtk_text_buffer_create_tag ( x_bf, NULL, "invisible", 1, NULL ); > > ii = 0; > while (1) { > char *x_pnt; > int x_length; > > x_pnt = x_data[ii++]; > if ( x_pnt == NULL ) { break; } > x_length = strlen (x_pnt); > if ( x_length < MAX_SEEN ) { > gtk_text_buffer_insert ( x_bf, &x_iter, x_pnt, -1 ); > } else { > gtk_text_buffer_insert ( x_bf, &x_iter, x_pnt, MAX_SEEN ); > gtk_text_buffer_insert_with_tags ( x_bf, &x_iter, > &x_pnt[MAX_SEEN], -1, hide_tag, NULL ); > gtk_text_buffer_insert ( x_bf, &x_iter, " # ", -1 ); > } > gtk_text_buffer_insert ( x_bf, &x_iter, "\n", -1 ); > } > gtk_widget_show_all ( window ); >} > >int main ( > int argc, > char **argv ) >{ > GtkApplication *app; > int status; > > app = gtk_application_new ( "org.gtk.example", G_APPLICATION_FLAGS_NONE ); > g_signal_connect ( app, "activate", G_CALLBACK (activate), NULL ); > status = g_application_run ( G_APPLICATION (app), argc, argv ); > g_object_unref (app); > > return status; >}
#include <gtk/gtk.h> #include <string.h> #define MAX_SEEN 30 /* Gtk3 textview error demo ------------------------ The application aborts when the pointer enters a line of the textview-panel that contains invisible text (marked by a trailing '#' character): (demo:30090): Gtk-WARNING **: gtktextbtree.c:4041: byte index off the end of the line (demo:30090): Gtk-ERROR **: Byte index 44 is off the end of the line Compile/bind/run with: gcc `pkg-config --cflags gtk+-3.0` -o demo demo.c `pkg-config --libs gtk+-3.0` ; demo */ static void activate ( GtkApplication *app, gpointer user_data ) { GtkWidget *window; GtkTextView *text_panel; GtkTextBuffer *x_bf; GtkTextIter x_iter; GtkTextTag *hide_tag; int ii; char *x_data[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", "ABCDEFGHIJKLM", NULL }; window = gtk_application_window_new (app); gtk_window_set_title ( GTK_WINDOW (window), "Window" ); gtk_window_set_default_size ( GTK_WINDOW (window), 400, 100 ); text_panel = (GtkTextView *)gtk_text_view_new (); gtk_container_add ( GTK_CONTAINER (window), (GtkWidget *)text_panel ); gtk_text_view_set_pixels_below_lines ( text_panel, 2 ); /*###########*/ x_bf = gtk_text_view_get_buffer ( text_panel ); gtk_text_buffer_get_start_iter ( x_bf, &x_iter ); hide_tag = gtk_text_buffer_create_tag ( x_bf, NULL, "invisible", 1, NULL ); ii = 0; while (1) { char *x_pnt; int x_length; x_pnt = x_data[ii++]; if ( x_pnt == NULL ) { break; } x_length = strlen (x_pnt); if ( x_length < MAX_SEEN ) { gtk_text_buffer_insert ( x_bf, &x_iter, x_pnt, -1 ); } else { gtk_text_buffer_insert ( x_bf, &x_iter, x_pnt, MAX_SEEN ); gtk_text_buffer_insert_with_tags ( x_bf, &x_iter, &x_pnt[MAX_SEEN], -1, hide_tag, NULL ); gtk_text_buffer_insert ( x_bf, &x_iter, " # ", -1 ); } gtk_text_buffer_insert ( x_bf, &x_iter, "\n", -1 ); } gtk_widget_show_all ( window ); } int main ( int argc, char **argv ) { GtkApplication *app; int status; app = gtk_application_new ( "org.gtk.example", G_APPLICATION_FLAGS_NONE ); g_signal_connect ( app, "activate", G_CALLBACK (activate), NULL ); status = g_application_run ( G_APPLICATION (app), argc, argv ); g_object_unref (app); return status; }
View Attachment As Raw
Actions:
View
Attachments on
bug 20036
: 8821