From: Ben Pfaff Date: Tue, 25 Sep 2007 04:16:19 +0000 (+0000) Subject: John's original code for patch #6210. X-Git-Tag: sav-api~1257 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70c7494a0b0a9e6ce90c271f65095bc474b775ee;p=pspp John's original code for patch #6210. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 0bec245b2f..51568e785c 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,9 @@ +2007-09-19 John Darrington + + * settings.c settings.h: Changed viewport's length and width to be + owned by the user interface which uses the data library. This allows + better abstraction, and makes dynamically adjustable dimensions easier. + 2007-09-18 Ben Pfaff * procedure.c (proc_extract_active_file_data): New function. diff --git a/src/data/settings.c b/src/data/settings.c index b0fc89ae55..095a931854 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -29,8 +29,8 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -static int viewlength = 24; -static int viewwidth = 79; +static int *viewlength = NULL; +static int *viewwidth = NULL; static bool long_view = false; static bool safer_mode = false; @@ -74,13 +74,12 @@ static int *algorithm = &global_algorithm; static int syntax = ENHANCED; -static void init_viewport (void); -static void get_termcap_viewport (void); +static void init_viewport (int *, int *); void -settings_init (void) +settings_init (int *width, int *length) { - init_viewport (); + init_viewport (width, length); i18n_init (); } @@ -94,14 +93,14 @@ settings_done (void) int get_viewlength (void) { - return viewlength; + return *viewlength; } /* Sets the view length. */ void set_viewlength (int viewlength_) { - viewlength = viewlength_; + *viewlength = viewlength_; } /* Set view width to a very long value, and prevent it from ever @@ -110,42 +109,34 @@ void force_long_view (void) { long_view = true; - viewwidth = 9999; } /* Screen width. */ int get_viewwidth(void) { - return viewwidth; + if (long_view) + return 9999; + + return *viewwidth; } /* Sets the screen width. */ void set_viewwidth (int viewwidth_) { - viewwidth = viewwidth_; + *viewwidth = viewwidth_; } static void -init_viewport (void) +init_viewport (int *width, int *length) { + viewwidth = width; + viewlength = length; + if (long_view) return; - viewwidth = viewlength = -1; - - get_termcap_viewport (); - - if (viewwidth < 0 && getenv ("COLUMNS") != NULL) - viewwidth = atoi (getenv ("COLUMNS")); - if (viewlength < 0 && getenv ("LINES") != NULL) - viewlength = atoi (getenv ("LINES")); - - if (viewwidth < 0) - viewwidth = 79; - if (viewlength < 0) - viewlength = 24; } /* Whether PSPP can erase and overwrite files. */ @@ -498,38 +489,3 @@ set_syntax (enum behavior_mode mode) { syntax = mode; } - -/* Code that interfaces to ncurses. This must be at the very end - of this file because curses.h redefines "bool" on some systems - (e.g. OpenBSD), causing declaration mismatches with functions - that have parameters or return values of type "bool". */ -#if HAVE_LIBNCURSES -#include -#include - -static void -get_termcap_viewport (void) -{ - char term_buffer[16384]; - if (getenv ("TERM") == NULL) - return; - else if (tgetent (term_buffer, getenv ("TERM")) <= 0) - { - error (0,0, _("could not access definition for terminal `%s'"), - getenv ("TERM")); - return; - } - - if (tgetnum ("li") > 0) - viewlength = tgetnum ("li"); - - if (tgetnum ("co") > 1) - viewwidth = tgetnum ("co") - 1; -} -#else /* !HAVE_LIBNCURSES */ -static void -get_termcap_viewport (void) -{ - /* Nothing to do. */ -} -#endif /* !HAVE_LIBNCURSES */ diff --git a/src/data/settings.h b/src/data/settings.h index ac4c1e202b..63e3d1fe7e 100644 --- a/src/data/settings.h +++ b/src/data/settings.h @@ -20,7 +20,7 @@ #include #include -void settings_init (void); +void settings_init (int *, int *); void settings_done (void); void force_long_view (void); diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index 31453f01c1..72d615b615 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,14 @@ +2007-09-19 John Darrington + + * message-dialog.c: Changed the ouput message title to be + appropriate for the severity of the message. + + * output-viewer.c output-viewer.h : Added a callback for the resize + signal of the output viewer, and set the viewport length and + width accordingly. + + * psppire.c: Update to new init_settings interface. + 2007-09-27 John Darrington Addressing bug #20821: diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index fca13956b1..969758e2fb 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -103,29 +103,58 @@ popup_message (const struct msg *m) { case MSG_ERROR: message_type = GTK_MESSAGE_ERROR; + switch (m->category) + { + case MSG_SYNTAX: + msg = _("Script Error"); + break; + + case MSG_DATA: + msg = _("Data File Error"); + break; + + case MSG_GENERAL: + default: + msg = _("PSPP Error"); + break; + }; break; case MSG_WARNING: message_type = GTK_MESSAGE_WARNING; + switch (m->category) + { + case MSG_SYNTAX: + msg = _("Script Warning"); break; - case MSG_NOTE: + + case MSG_DATA: + msg = _("Data File Warning"); + break; + + case MSG_GENERAL: default: - message_type = GTK_MESSAGE_INFO; + msg = _("PSPP Warning"); break; }; - + break; + case MSG_NOTE: + default: + message_type = GTK_MESSAGE_INFO; switch (m->category) { case MSG_SYNTAX: - msg = _("Script Error"); + msg = _("Script Information"); break; case MSG_DATA: - msg = _("Data File Error"); + msg = _("Data File Information"); break; case MSG_GENERAL: default: - msg = _("PSPP Error"); + msg = _("PSPP Information"); + break; + }; break; }; diff --git a/src/ui/gui/output-viewer.c b/src/ui/gui/output-viewer.c index d2f46bab59..62dc85f1c2 100644 --- a/src/ui/gui/output-viewer.c +++ b/src/ui/gui/output-viewer.c @@ -46,6 +46,8 @@ cancel_urgency (GtkWindow *window, gpointer data) static struct output_viewer *the_output_viewer = NULL; +int viewer_length = -1; +int viewer_width = -1; /* Callback for the "delete" action (clicking the x on the top right hand corner of the window) */ @@ -64,6 +66,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 +143,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"), diff --git a/src/ui/gui/output-viewer.h b/src/ui/gui/output-viewer.h index 0bc148bb3c..2036b66f32 100644 --- a/src/ui/gui/output-viewer.h +++ b/src/ui/gui/output-viewer.h @@ -23,6 +23,9 @@ #include "window-manager.h" +extern int viewer_length ; +extern int viewer_width ; + struct output_viewer * new_output_viewer (void); void reload_viewer (struct output_viewer *); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index ff155d68fe..b874d393cf 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -85,7 +85,7 @@ initialize (void) fmt_init (); fn_init (); outp_init (); - settings_init (); + settings_init (&viewer_width, &viewer_length); fh_init (); the_source_stream = create_source_stream ( diff --git a/src/ui/terminal/ChangeLog b/src/ui/terminal/ChangeLog index 0e6e014d9b..f7983110fd 100644 --- a/src/ui/terminal/ChangeLog +++ b/src/ui/terminal/ChangeLog @@ -1,3 +1,9 @@ +2007-09-19 John Darrington + + * main.c: Moved get_termcap_viewport from src/data/settings.c + Added a handler for SIGWINCH to call this function. Adjusted + init_settings to suit new interface. + 2007-09-22 Ben Pfaff Bug #21128. Reviewed by John Darrington. diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index 46ded354f7..b25350b94c 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -78,6 +78,11 @@ static struct dataset * the_dataset = NULL; static struct lexer *the_lexer; static struct source_stream *the_source_stream ; +static int view_length = -1; +static int view_width = -1; + +static void get_termcap_viewport (int); + /* Program entry point. */ int @@ -87,6 +92,7 @@ main (int argc, char **argv) signal (SIGSEGV, bug_handler); signal (SIGFPE, bug_handler); signal (SIGINT, interrupt_handler); + signal (SIGWINCH, get_termcap_viewport); set_program_name (argv[0]); @@ -104,7 +110,8 @@ main (int argc, char **argv) ); prompt_init (); readln_initialize (); - settings_init (); + get_termcap_viewport (0); + settings_init (&view_width, &view_length); random_init (); the_dataset = create_dataset (); @@ -224,3 +231,71 @@ terminate (bool success) } exit (success ? EXIT_SUCCESS : EXIT_FAILURE); } + + + +#include "error.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) + +static void +set_fallback_viewport (void) +{ + if (view_width < 0 && getenv ("COLUMNS") != NULL) + view_width = atoi (getenv ("COLUMNS")); + + if (view_length < 0 && getenv ("LINES") != NULL) + view_length = atoi (getenv ("LINES")); + + if (view_width < 0) + view_width = 79; + + if (view_length < 0) + view_length = 24; +} + +/* Code that interfaces to ncurses. This must be at the very end + of this file because curses.h redefines "bool" on some systems + (e.g. OpenBSD), causing declaration mismatches with functions + that have parameters or return values of type "bool". */ +#if HAVE_LIBNCURSES +#include +#include + +static void +get_termcap_viewport (int sig UNUSED) +{ + char term_buffer [16384]; + + if (getenv ("TERM") == NULL) + goto fallback; + + else if (tgetent (term_buffer, getenv ("TERM")) <= 0) + { + error (0,0, _("could not access definition for terminal `%s'"), + getenv ("TERM")); + goto fallback; + } + + if (tgetnum ("li") > 0) + view_length = tgetnum ("li"); + + if (tgetnum ("co") > 1) + view_width = tgetnum ("co") - 1; + + fallback: + set_fallback_viewport (); +} + +#else /* !HAVE_LIBNCURSES */ + +static void +get_termcap_viewport (int sig UNUSED) +{ + set_fallback_viewport (); +} + +#endif /* !HAVE_LIBNCURSES */ + +