X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Foutput-viewer.c;h=0372e14cf9325df0a7a62604229b329784ca073a;hb=17cc22594edc09fa76e03777a9019ec579cd8a1a;hp=d2f46bab59173d6c21459c288c52237703e5c3b0;hpb=5de8102af0956488f48ae9bf4941e5867a0f1260;p=pspp diff --git a/src/ui/gui/output-viewer.c b/src/ui/gui/output-viewer.c index d2f46bab59..0372e14cf9 100644 --- a/src/ui/gui/output-viewer.c +++ b/src/ui/gui/output-viewer.c @@ -28,6 +28,8 @@ #include #include +#include "xalloc.h" + struct output_viewer { struct editor_window parent; @@ -46,6 +48,8 @@ cancel_urgency (GtkWindow *window, gpointer data) static struct output_viewer *the_output_viewer = NULL; +int viewer_length = 16; +int viewer_width = 59; /* Callback for the "delete" action (clicking the x on the top right hand corner of the window) */ @@ -64,6 +68,46 @@ on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data) } +/* Sets width and length according to the new size + of the output window */ +static void +on_textview_resize (GtkWidget *widget, + GtkAllocation *allocation, + gpointer user_data) +{ + PangoContext * context ; + PangoLayout *layout ; + PangoRectangle logical; + GtkStyle *style; + gint right_margin, left_margin; + GtkTextView *text_view = GTK_TEXT_VIEW (widget); + + context = gtk_widget_create_pango_context (widget); + layout = pango_layout_new (context); + + style = gtk_widget_get_style (widget); + + pango_layout_set_font_description (layout, style->font_desc); + + /* Find the width of one character. We can use any character, because + the textview has a monospaced font */ + pango_layout_set_text (layout, "M", 1); + + pango_layout_get_extents (layout, NULL, &logical); + + left_margin = gtk_text_view_get_left_margin (text_view); + right_margin = gtk_text_view_get_right_margin (text_view); + + viewer_length = allocation->height / PANGO_PIXELS (logical.height); + viewer_width = (allocation->width - right_margin - left_margin) + / PANGO_PIXELS (logical.width); + + g_object_unref (G_OBJECT (layout)); + g_object_unref (G_OBJECT (context)); +} + + + /* Create a new output viewer */ @@ -101,6 +145,9 @@ new_output_viewer (void) pango_font_description_free (font_desc); } + g_signal_connect (ov->textview, "size-allocate", + G_CALLBACK (on_textview_resize), NULL); + ov->fp = NULL; g_signal_connect (get_widget_assert (xml,"help_about"), @@ -151,7 +198,7 @@ void reload_viewer (struct output_viewer *ov) { GtkTextIter end_iter; - char line[OUTPUT_LINE_WIDTH]; + static char *line = NULL; GtkTextMark *mark ; gboolean chars_inserted = FALSE; @@ -166,12 +213,14 @@ reload_viewer (struct output_viewer *ov) } } + line = xrealloc (line, sizeof (char) * (viewer_width + 1)); + gtk_text_buffer_get_end_iter (ov->buffer, &end_iter); mark = gtk_text_buffer_create_mark (ov->buffer, NULL, &end_iter, TRUE); /* Read in the next lot of text */ - while (fgets (line, OUTPUT_LINE_WIDTH, ov->fp) != NULL) + while (fgets (line, viewer_width + 1, ov->fp) != NULL) { chars_inserted = TRUE; gtk_text_buffer_insert (ov->buffer, &end_iter, line, -1);