pcb 4.1.1
An interactive printed circuit board layout editor.

gui-log-window.c

Go to the documentation of this file.
00001 /*
00002  *                            COPYRIGHT
00003  *
00004  *  PCB, interactive printed circuit board design
00005  *  Copyright (C) 1994,1995,1996 Thomas Nau
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along
00018  *  with this program; if not, write to the Free Software Foundation, Inc.,
00019  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  *
00021  *  Contact addresses for paper mail and Email:
00022  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
00023  *  Thomas.Nau@rz.uni-ulm.de
00024  *
00025  */
00026 
00027 /* This file written by Bill Wilson for the PCB Gtk port
00028 */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033 
00034 #include "gui.h"
00035 #include "pcb-printf.h"
00036 
00037 #ifdef HAVE_LIBDMALLOC
00038 #include <dmalloc.h>
00039 #endif
00040 
00041 static GtkWidget *log_window, *log_text;
00042 static gboolean log_show_on_append = FALSE;
00043 
00044 /* Remember user window resizes. */
00045 static gint
00046 log_window_configure_event_cb (GtkWidget * widget,
00047                                GdkEventConfigure * ev, gpointer data)
00048 {
00049   GtkAllocation allocation;
00050 
00051   gtk_widget_get_allocation (widget, &allocation);
00052   ghidgui->log_window_width = allocation.width;
00053   ghidgui->log_window_height = allocation.height;
00054   ghidgui->config_modified = TRUE;
00055 
00056   return FALSE;
00057 }
00058 
00059 static void
00060 log_close_cb (gpointer data)
00061 {
00062   gtk_widget_destroy (log_window);
00063   log_window = NULL;
00064 }
00065 
00066 static void
00067 log_destroy_cb (GtkWidget * widget, gpointer data)
00068 {
00069   log_window = NULL;
00070 }
00071 
00072 void
00073 ghid_log_window_create ()
00074 {
00075   GtkWidget *vbox, *hbox, *button;
00076 
00077   if (log_window)
00078     return;
00079 
00080   log_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00081   g_signal_connect (G_OBJECT (log_window), "destroy",
00082                     G_CALLBACK (log_destroy_cb), NULL);
00083   g_signal_connect (G_OBJECT (log_window), "configure_event",
00084                     G_CALLBACK (log_window_configure_event_cb), NULL);
00085   gtk_window_set_title (GTK_WINDOW (log_window), _("PCB Log"));
00086   gtk_window_set_wmclass (GTK_WINDOW (log_window), "PCB_Log", "PCB");
00087   gtk_window_resize (GTK_WINDOW (log_window),
00088                      ghidgui->log_window_width,
00089                      ghidgui->log_window_height);
00090 
00091   vbox = gtk_vbox_new (FALSE, 0);
00092   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
00093   gtk_container_add (GTK_CONTAINER (log_window), vbox);
00094 
00095   log_text = ghid_scrolled_text_view (vbox, NULL,
00096                                       GTK_POLICY_AUTOMATIC,
00097                                       GTK_POLICY_AUTOMATIC);
00098 
00099   hbox = gtk_hbutton_box_new ();
00100   gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
00101   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00102   button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
00103   g_signal_connect (G_OBJECT (button), "clicked",
00104                     G_CALLBACK (log_close_cb), NULL);
00105   gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
00106 
00107   gtk_widget_realize (log_window);
00108   if (Settings.AutoPlace)
00109     gtk_window_move (GTK_WINDOW (log_window), 10, 10);
00110 }
00111 
00112 void
00113 ghid_log_window_show (gboolean raise)
00114 {
00115   ghid_log_window_create ();
00116   gtk_widget_show_all (log_window);
00117   if (raise)
00118     gtk_window_present (GTK_WINDOW(log_window));
00119 }
00120 
00121 static void
00122 ghid_log_append_string (gchar * s)
00123 {
00124   if (log_show_on_append)
00125     ghid_log_window_show(FALSE);
00126   else
00127     ghid_log_window_create ();
00128   ghid_text_view_append (log_text, s);
00129 }
00130 
00131 void
00132 ghid_log (const char *fmt, ...)
00133 {
00134   va_list ap;
00135   va_start (ap, fmt);
00136   ghid_logv (fmt, ap);
00137   va_end (ap);
00138 }
00139 
00140 void
00141 ghid_logv (const char *fmt, va_list args)
00142 {
00143   gchar *msg = pcb_vprintf (fmt, args);
00144   ghid_log_append_string (msg);
00145   g_free (msg);
00146 }
00147 
00148 static const char logshowonappend_syntax[] =
00149   "LogShowOnAppend(true|false)";
00150 
00151 static const char logshowonappend_help[] =
00152   "If true, the log window will be shown whenever something is appended \
00153 to it.  If false, the log will still be updated, but the window won't \
00154 be shown.";
00155 
00156 static gint
00157 GhidLogShowOnAppend (int argc, char **argv, Coord x, Coord y)
00158 {
00159   char *a = argc == 1 ? argv[0] : (char *)"";
00160 
00161   if (strncasecmp(a, "t", 1) == 0)
00162     {
00163       log_show_on_append = TRUE;
00164     }
00165   else if (strncasecmp(a, "f", 1) == 0)
00166     {
00167       log_show_on_append = FALSE;
00168     }
00169   return 0;
00170 }
00171 
00172 HID_Action ghid_log_action_list[] = {
00173   {"LogShowOnAppend", 0, GhidLogShowOnAppend,
00174    logshowonappend_help, logshowonappend_syntax}
00175   ,
00176 };
00177 
00178 REGISTER_ACTIONS (ghid_log_action_list)