gschem

x_print.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #ifdef HAVE_STDLIB_H
00024 #include <stdlib.h>
00025 #endif
00026 #ifdef HAVE_STRING_H
00027 #include <string.h>
00028 #endif
00029 
00030 #include "gschem.h"
00031 
00032 #ifdef HAVE_LIBDMALLOC
00033 #include <dmalloc.h>
00034 #endif
00035 
00036 enum
00037   {
00038   PROP_FILENAME = 1,
00039   PROP_COMMAND,
00040   PROP_PAPERSIZE,
00041   PROP_ORIENTATION,
00042   PROP_TYPE,
00043   PROP_USEFILE
00044   };
00045 
00046 /* Private functions */
00047 
00048 static void print_dialog_action_radio_toggled (GtkWidget * w,
00049                                               PrintDialog * dialog);
00050 
00051 static void print_dialog_init (PrintDialog * dialog);
00052 static void print_dialog_init_paper_combobox (PrintDialog * d);
00053 static void print_dialog_init_type_combobox (PrintDialog * d);
00054 static void print_dialog_init_orient_combobox (PrintDialog * d);
00055 static void print_dialog_set_property (GObject * object, guint property_id,
00056                                       const GValue * value,
00057                                       GParamSpec * pspec);
00058 static void print_dialog_set_property_comboboxes (PrintDialog *dialog,
00059                           GtkComboBox *cbox,
00060                           const GValue * value);
00061 static void print_dialog_get_property (GObject * object, guint property_id,
00062                                       GValue * value, GParamSpec * pspec);
00063 static void print_dialog_get_property_comboboxes (PrintDialog * dialog,
00064                           GtkComboBox * cbox,
00065                           GValue * value);
00066 static void print_dialog_class_init (PrintDialogClass * class);
00067 
00068 
00069 
00078 static void
00079 print_dialog_action_choosefile (GtkWidget * w, PrintDialog * dialog)
00080 {
00081   GtkWidget *filechooser;
00082   const gchar *filename;
00083   const gchar *newfilename;
00084   filechooser = gtk_file_chooser_dialog_new (_("Select PostScript Filename..."),
00085                          GTK_WINDOW (dialog),
00086                          GTK_FILE_CHOOSER_ACTION_SAVE,
00087                          GTK_STOCK_CANCEL,
00088                          GTK_RESPONSE_CANCEL,
00089                          GTK_STOCK_OK,
00090                          GTK_RESPONSE_ACCEPT, NULL);
00091 
00092   /* Set the alternative button order (ok, cancel, help) for other systems */
00093   gtk_dialog_set_alternative_button_order(GTK_DIALOG(filechooser),
00094                       GTK_RESPONSE_ACCEPT,
00095                       GTK_RESPONSE_CANCEL,
00096                       -1);
00097 
00098   filename = gtk_entry_get_text (GTK_ENTRY (dialog->fnfield));
00099   gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), filename);
00100 
00101   gtk_dialog_set_default_response(GTK_DIALOG(filechooser),
00102                   GTK_RESPONSE_ACCEPT);
00103 
00104   if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
00105     {
00106       newfilename =
00107     gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
00108       gtk_entry_set_text (GTK_ENTRY (dialog->fnfield), newfilename);
00109     }
00110 
00111   gtk_widget_destroy (filechooser);
00112 
00113 }
00114 
00121 static void
00122 print_dialog_init_paper_combobox (PrintDialog * d)
00123 {
00124   GtkComboBox *combobox;
00125   gchar *string;
00126   gint i;
00127 
00128   combobox = GTK_COMBO_BOX (gtk_combo_box_new_text ());
00129   gtk_combo_box_set_active (combobox, -1);
00130 
00131   /* Populate combo box with available paper sizes */
00132   i = 0;
00133   string = (gchar *) s_papersizes_get (i);
00134   while (string != NULL)
00135     {
00136       gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), i, string);
00137       
00138       i++;
00139       string = (gchar *) s_papersizes_get (i);
00140     }
00141 
00142   d->papercbox = combobox;
00143 }
00144 
00151 static void
00152 print_dialog_init_type_combobox (PrintDialog * d)
00153 {
00154   GtkListStore *model;
00155   GtkTreeIter iter;
00156   GtkCellRenderer *renderer;
00157 
00158   GtkWidget *combobox;
00159   
00160   model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
00161 
00162   gtk_list_store_append (model, &iter);
00163   gtk_list_store_set (model, &iter, 
00164               0, _("Extents with margins"),
00165               1, EXTENTS,
00166               -1);
00167   
00168   gtk_list_store_append (model, &iter);
00169   gtk_list_store_set (model, &iter,
00170               0, _("Extents no margins"),
00171               1, EXTENTS_NOMARGINS,
00172               -1);
00173   
00174   gtk_list_store_append (model, &iter);
00175   gtk_list_store_set (model, &iter,
00176               0, _("Current Window"),
00177               1, WINDOW,
00178               -1);
00179 
00180   combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
00181   
00182   renderer = gtk_cell_renderer_text_new ();
00183   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
00184                   renderer, TRUE);
00185   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox),
00186                  renderer, "text", 0);
00187 
00188   d->typecbox = GTK_COMBO_BOX (combobox);
00189 }
00190 
00197 static void
00198 print_dialog_init_orient_combobox (PrintDialog * d)
00199 {
00200   GtkListStore *model;
00201   GtkTreeIter iter;
00202   GtkCellRenderer *renderer;
00203 
00204   GtkWidget *combobox;
00205   
00206   model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
00207 
00208   gtk_list_store_append (model, &iter);
00209   gtk_list_store_set (model, &iter, 
00210               0, _("Landscape"),
00211               1, LANDSCAPE,
00212               -1);
00213   
00214   gtk_list_store_append (model, &iter);
00215   gtk_list_store_set (model, &iter,
00216               0, _("Portrait"),
00217               1, PORTRAIT,
00218               -1);
00219 
00220   combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
00221   
00222   renderer = gtk_cell_renderer_text_new ();
00223   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
00224                   renderer, TRUE);
00225   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox),
00226                  renderer, "text", 0);
00227 
00228   d->orientcbox = GTK_COMBO_BOX (combobox);
00229 }
00230 
00238 static void
00239 print_dialog_action_radio_toggled (GtkWidget * w, PrintDialog * dialog)
00240 {
00241   if (w == GTK_WIDGET (dialog->cmdradio))
00242     {
00243       gtk_widget_set_sensitive (GTK_WIDGET (dialog->cmdfield),
00244                                gtk_toggle_button_get_active
00245                                (GTK_TOGGLE_BUTTON (w)));
00246     }
00247   else if (w == GTK_WIDGET (dialog->fileradio))
00248     {
00249       gtk_widget_set_sensitive (GTK_WIDGET (dialog->fnfield),
00250                                gtk_toggle_button_get_active
00251                                (GTK_TOGGLE_BUTTON (w)));
00252       gtk_widget_set_sensitive (GTK_WIDGET (dialog->saveasbutton),
00253                                gtk_toggle_button_get_active
00254                                (GTK_TOGGLE_BUTTON (w)));
00255     }
00256 }
00257 
00258 
00264 static void
00265 print_dialog_init (PrintDialog * dialog)
00266 {
00267   GtkWidget *box;
00268   GtkWidget *frame;
00269   GtkWidget *settingstable, *desttable;
00270   GtkWidget *label;
00271   GtkWidget *print_button;
00272 
00273   /* Initialize properties */
00274   g_object_set (G_OBJECT (dialog),
00275         /* GtkWindow */
00276         "title", _("Print..."),
00277         "modal", TRUE, "destroy-with-parent", TRUE, NULL);
00278 
00279   /* Setup hbox for two main panes */
00280   box = gtk_vbox_new (FALSE, 2);
00281   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);
00282 
00283   /* Upper frame */
00284   frame = gtk_frame_new (_("Settings"));
00285   gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
00286   gtk_container_add (GTK_CONTAINER (box), frame);
00287 
00288   /* Upper table with drop-down menus & labels 
00289    * Left-hand column contains labels, right-hand contains comboboxes*/
00290   settingstable = gtk_table_new (2, 3, FALSE);
00291   gtk_table_set_col_spacings (GTK_TABLE (settingstable), 5);
00292   gtk_table_set_row_spacings (GTK_TABLE (settingstable), 5);
00293   gtk_container_set_border_width (GTK_CONTAINER (settingstable), 5);
00294   gtk_container_add (GTK_CONTAINER (frame), settingstable);
00295 
00296   label = gtk_label_new (_("Output paper size:"));
00297   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
00298   gtk_table_attach (GTK_TABLE (settingstable),
00299             label,
00300             0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
00301 
00302   print_dialog_init_paper_combobox (dialog);
00303   gtk_table_attach (GTK_TABLE (settingstable),
00304             GTK_WIDGET (dialog->papercbox),
00305             1, 2, 0, 1, GTK_FILL, 0, 0, 0);
00306 
00307   label = gtk_label_new (_("Type:"));
00308   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
00309   gtk_table_attach (GTK_TABLE (settingstable),
00310             label,
00311             0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
00312 
00313   print_dialog_init_type_combobox (dialog);
00314   gtk_table_attach (GTK_TABLE (settingstable),
00315             GTK_WIDGET (dialog->typecbox),
00316             1, 2, 1, 2, GTK_FILL, 0, 0, 0);
00317 
00318   label = gtk_label_new (_("Orientation:"));
00319   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
00320   gtk_table_attach (GTK_TABLE (settingstable),
00321             label,
00322             0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
00323 
00324   print_dialog_init_orient_combobox (dialog);
00325   gtk_table_attach (GTK_TABLE (settingstable),
00326             GTK_WIDGET (dialog->orientcbox),
00327             1, 2, 2, 3, GTK_FILL, 0, 0, 0);
00328 
00329   /* Lower frame */
00330   frame = gtk_frame_new (_("Destination"));
00331   gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
00332   gtk_container_add (GTK_CONTAINER (box), frame);
00333 
00334   /* Table with destination selectors */
00335   desttable = gtk_table_new (3, 2, FALSE);
00336   gtk_table_set_col_spacings (GTK_TABLE (desttable), 5);
00337   gtk_table_set_row_spacings (GTK_TABLE (desttable), 5);
00338   gtk_container_set_border_width (GTK_CONTAINER (desttable), 5);
00339   gtk_container_add (GTK_CONTAINER (frame), desttable);
00340 
00341   /* Widgets for printing to file */
00342   dialog->fileradio =
00343     GTK_RADIO_BUTTON (gtk_radio_button_new_with_label (NULL, _("File:")));
00344   gtk_table_attach (GTK_TABLE (desttable),
00345             GTK_WIDGET (dialog->fileradio),
00346             0, 1, 0, 1, GTK_FILL, GTK_EXPAND, 0, 0);
00347   g_signal_connect (dialog->fileradio,
00348             "toggled",
00349             GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled),
00350             dialog);
00351 
00352   dialog->fnfield = GTK_ENTRY (gtk_entry_new ());
00353   gtk_table_attach (GTK_TABLE (desttable),
00354             GTK_WIDGET (dialog->fnfield),
00355             1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
00356 
00357   dialog->saveasbutton = GTK_BUTTON(gtk_button_new());
00358   gtk_container_add(GTK_CONTAINER(dialog->saveasbutton),
00359             gtk_image_new_from_stock(GTK_STOCK_OPEN,
00360                          GTK_ICON_SIZE_SMALL_TOOLBAR));
00361   gtk_button_set_relief(GTK_BUTTON(dialog->saveasbutton), GTK_RELIEF_NONE);
00362 
00363   gtk_table_attach (GTK_TABLE (desttable),
00364             GTK_WIDGET (dialog->saveasbutton), 2, 3, 0, 1,
00365             GTK_FILL, 0, 0, 0);
00366   g_signal_connect (dialog->saveasbutton,
00367             "clicked",
00368             GTK_SIGNAL_FUNC (print_dialog_action_choosefile), dialog);
00369 
00370   /* Widgets for printing to command */
00371   dialog->cmdradio =
00372     GTK_RADIO_BUTTON (gtk_radio_button_new_with_label_from_widget
00373               (dialog->fileradio, _("Command:")));
00374   gtk_table_attach (GTK_TABLE (desttable),
00375             GTK_WIDGET (dialog->cmdradio),
00376             0, 1, 1, 2,  GTK_FILL, GTK_EXPAND, 0, 0);
00377   g_signal_connect (dialog->cmdradio,
00378             "toggled",
00379             GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled),
00380             dialog);
00381 
00382   dialog->cmdfield = GTK_ENTRY (gtk_entry_new ());
00383   gtk_table_attach (GTK_TABLE (desttable), GTK_WIDGET (dialog->cmdfield),
00384             1, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0);
00385 
00386   /* Add "Cancel" and "Print" buttons */
00387    gtk_dialog_add_button (GTK_DIALOG (dialog),
00388                   GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
00389    print_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
00390                   GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT);
00391    gtk_widget_grab_focus(print_button);
00392 
00393   /* Set the alternative button order (ok, cancel, help) for other systems */
00394   gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),
00395                       GTK_RESPONSE_ACCEPT,
00396                       GTK_RESPONSE_REJECT,
00397                       -1);
00398 
00399   /* Set initial radiobutton selection */
00400   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->cmdradio), TRUE);
00401 }
00402 
00408 static void
00409 print_dialog_set_property (GObject * object,
00410                           guint property_id,
00411                           const GValue * value, GParamSpec * pspec)
00412 {
00413   PrintDialog *dialog = PRINT_DIALOG (object);
00414   gboolean file_active = FALSE;
00415 
00416   switch (property_id)
00417     {
00418     case PROP_FILENAME:
00419       gtk_entry_set_text (dialog->fnfield,
00420                          (char *) g_value_get_string (value));
00421       return;
00422 
00423     case PROP_COMMAND:
00424       gtk_entry_set_text (dialog->cmdfield,
00425                          (char *) g_value_get_string (value));
00426       return;
00427 
00428     case PROP_PAPERSIZE:
00429       gtk_combo_box_set_active (dialog->papercbox,
00430                                g_value_get_int (value));
00431       return;
00432 
00433     case PROP_ORIENTATION:
00434       print_dialog_set_property_comboboxes (dialog, 
00435                         dialog->orientcbox,
00436                         value);
00437       return;
00438 
00439     case PROP_TYPE:
00440       print_dialog_set_property_comboboxes (dialog, 
00441                         dialog->typecbox,
00442                         value);
00443       return;
00444 
00445     case PROP_USEFILE:
00446       file_active = g_value_get_boolean (value);
00447       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->fileradio),
00448                                    file_active);
00449       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->cmdradio),
00450                                    !file_active);
00451       return;
00452 
00453     default:
00454       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
00455     }
00456 }
00457 
00463 static void
00464 print_dialog_set_property_comboboxes (PrintDialog * dialog,
00465                       GtkComboBox * cbox,
00466                       const GValue * value)
00467 {
00468   GtkTreeIter iter;
00469   GtkTreeModel *model;
00470 
00471   model = gtk_combo_box_get_model (cbox);
00472   gtk_tree_model_get_iter_first (model, &iter);
00473 
00474   do {
00475     GValue temp_value = {0, }; /* Make sure it's blank*/
00476     gtk_tree_model_get_value (model, &iter, 1, &temp_value);
00477 
00478     if (g_value_get_int (&temp_value) == g_value_get_int (value))
00479       {
00480     gtk_combo_box_set_active_iter (cbox, &iter);
00481     return;
00482       }
00483 
00484   } while (gtk_tree_model_iter_next (model, &iter));
00485 
00486   gtk_combo_box_set_active (cbox, 0);
00487 }
00488 
00494 static void
00495 print_dialog_get_property (GObject * object,
00496                           guint property_id,
00497                           GValue * value, GParamSpec * pspec)
00498 {
00499   PrintDialog *dialog = PRINT_DIALOG (object);
00500   gboolean file_active = FALSE;
00501 
00502   switch (property_id)
00503     {
00504     case PROP_FILENAME:
00505       g_value_set_string (value,
00506               gtk_entry_get_text (GTK_ENTRY (dialog->fnfield)));
00507       return;
00508  
00509     case PROP_COMMAND:
00510       g_value_set_string (value,
00511               gtk_entry_get_text (GTK_ENTRY (dialog->cmdfield)));
00512       return;
00513  
00514     case PROP_PAPERSIZE:
00515       g_value_set_int (value, gtk_combo_box_get_active (dialog->papercbox));
00516       return;
00517  
00518     case PROP_ORIENTATION:
00519       print_dialog_get_property_comboboxes (dialog,
00520                         dialog->orientcbox,
00521                         value);
00522       return;
00523       
00524     case PROP_TYPE:
00525       print_dialog_get_property_comboboxes (dialog,
00526                         dialog->typecbox,
00527                         value);
00528       return;
00529  
00530     case PROP_USEFILE:
00531       file_active = 
00532         gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->fileradio));
00533       g_value_set_boolean (value, file_active);
00534       return;
00535             
00536     default:
00537       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
00538     }
00539 } 
00540 
00546 static void
00547 print_dialog_get_property_comboboxes (PrintDialog * dialog,
00548                       GtkComboBox * cbox,
00549                       GValue * value)
00550 {
00551   GValue temp_value = {0, };
00552   GtkTreeModel *model;
00553   GtkTreeIter iter;
00554 
00555   model = gtk_combo_box_get_model (cbox);
00556 
00557   gtk_combo_box_get_active_iter (cbox, &iter);
00558   gtk_tree_model_get_value (model, &iter, 1, &temp_value);
00559   g_value_copy (&temp_value, value);
00560   g_value_unset (&temp_value);
00561 }
00562 
00569 static void
00570 print_dialog_class_init (PrintDialogClass * class)
00571 {
00572   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
00573 
00574   gobject_class->set_property = print_dialog_set_property;
00575   gobject_class->get_property = print_dialog_get_property;
00576 
00577   g_object_class_install_property (gobject_class, PROP_FILENAME,
00578                    g_param_spec_string ("filename",
00579                             "", "", "",
00580                              G_PARAM_READWRITE));
00581 
00582   g_object_class_install_property (gobject_class, PROP_COMMAND,
00583                    g_param_spec_string ("command",
00584                             "", "", "lpr",
00585                              G_PARAM_READWRITE));
00586 
00587   g_object_class_install_property (gobject_class, PROP_PAPERSIZE,
00588                    g_param_spec_int ("papersize",
00589                              "", "", 0, G_MAXINT, 0,
00590                              G_PARAM_READWRITE));
00591 
00592   g_object_class_install_property (gobject_class, PROP_ORIENTATION,
00593                    g_param_spec_int ("orientation",
00594                              "", "", 0, G_MAXINT, 0,
00595                              G_PARAM_READWRITE));
00596 
00597   g_object_class_install_property (gobject_class, PROP_TYPE,
00598                    g_param_spec_int ("type",
00599                              "", "", 0, G_MAXINT, 0,
00600                              G_PARAM_READWRITE));
00601 
00602   g_object_class_install_property (gobject_class, PROP_USEFILE,
00603                    g_param_spec_boolean ("usefile",
00604                              "", "", FALSE,
00605                              G_PARAM_READWRITE));
00606 }
00607 
00613 GType
00614 print_dialog_get_type ()
00615 {
00616   static GType print_dialog_type = 0;
00617  
00618   if (!print_dialog_type)
00619     {
00620       static const GTypeInfo print_dialog_info = {
00621     sizeof (PrintDialogClass),
00622     NULL,           /* base_init */
00623     NULL,           /* base_finalize */
00624     (GClassInitFunc) print_dialog_class_init,
00625     NULL,           /* class_finalize */
00626     NULL,           /* class_data */
00627     sizeof (PrintDialog),
00628     0,          /* n_preallocs */
00629     (GInstanceInitFunc) print_dialog_init,
00630       };
00631       print_dialog_type = g_type_register_static (GSCHEM_TYPE_DIALOG,
00632                           "PrintDialog",
00633                           &print_dialog_info, 0);
00634     }
00635 
00636   return print_dialog_type;
00637 }
00638 
00644 void
00645 x_print_setup (GSCHEM_TOPLEVEL *w_current, char *filename)
00646 {
00647   TOPLEVEL *toplevel = w_current->toplevel;
00648   gchar * command = w_current->print_command;
00649   gint orient = toplevel->print_orientation;
00650   gint type = toplevel->print_output_type;
00651   gint paperidx, x, y, result;
00652   gchar *string, *destination;
00653   gboolean usefile = FALSE;
00654   GtkDialog *dialog; 
00655   GtkWidget *popup_message;
00656 
00657   /* Work out current paper size by iterating through available paper
00658    * sizes.  Set the default paper size as the active selection */
00659 
00660   /* FIXME: ought to have a TOPLEVEL property containing
00661    * default paper size name, this is somewhat hackish. No
00662    * better way of doing it with current implementation of
00663    * varying paper size though. */
00664   paperidx = 0;
00665   while (TRUE)
00666     {
00667       string = (gchar *) s_papersizes_get (paperidx);
00668       s_papersizes_get_size (string, &x, &y);
00669 
00670       if ((x == toplevel->paper_width)
00671       && (y == toplevel->paper_height))
00672     {
00673       break;
00674     }
00675       if (string == NULL)
00676     {
00677       paperidx = 0;
00678       break;
00679     }
00680       paperidx++;
00681     }
00682  
00683   /* Create a print dialog, find out whether the user clicks Print or
00684      Cancel, and then print or return accordingly */
00685   dialog = GTK_DIALOG (g_object_new (TYPE_PRINT_DIALOG,
00686                                      "command", command,
00687                                      "filename", filename,
00688                                      "papersize", paperidx,
00689                                      "orientation", orient,
00690                                      "type", type,
00691                                      "usefile", usefile,
00692                                      /* GschemDialog */
00693                                      "settings-name", "print",
00694                                      "gschem-toplevel", w_current,
00695                                      NULL));
00696   gtk_widget_show_all (GTK_WIDGET (dialog));
00697 
00698   gtk_dialog_set_default_response(GTK_DIALOG(dialog),
00699                   GTK_RESPONSE_ACCEPT);
00700   gtk_window_set_transient_for(GTK_WINDOW(dialog),
00701                    GTK_WINDOW(w_current->main_window));
00702 
00703   result = gtk_dialog_run (dialog);
00704   
00705   if (result == GTK_RESPONSE_ACCEPT)
00706     {
00707       /* Extract values from dialog and set the paper size */
00708       g_object_get (dialog,
00709             "command", &command,
00710             "filename", &filename,
00711             "papersize", &paperidx,
00712             "orientation", &toplevel->print_orientation,
00713             "type", &toplevel->print_output_type,
00714             "usefile", &usefile,
00715             NULL);
00716 
00717       s_papersizes_get_size (s_papersizes_get (paperidx),
00718                  &toplevel->paper_width,
00719                  &toplevel->paper_height);
00720         
00721       /* de select everything first */
00722       o_select_unselect_all( w_current );
00723 
00724       if (usefile && filename[0])
00725     /* Print to file */
00726     {
00727       destination = filename;
00728       result = f_print_file (toplevel,
00729                                  toplevel->page_current,
00730                                  filename);
00731     }
00732       else if (command[0])
00733     /* Print to command and save command for later use. */
00734     {
00735       destination = command;
00736       result = f_print_command (toplevel,
00737                                     toplevel->page_current,
00738                                     command);
00739       
00740       g_free (w_current->print_command);
00741       w_current->print_command = g_strdup (command);
00742     }
00743       else
00744     {
00745       s_log_message (_("No print destination specified\n"));
00746       return;
00747     }
00748 
00749       /* Check whether it worked */
00750       if (result)
00751     {
00752       s_log_message (_("Cannot print current schematic to [%s]\n"), 
00753              destination);
00754 
00755       /* Pop up a message warning the user */
00756       popup_message = 
00757         gtk_message_dialog_new (GTK_WINDOW(dialog),
00758                     GTK_DIALOG_DESTROY_WITH_PARENT,
00759                     GTK_MESSAGE_ERROR,
00760                     GTK_BUTTONS_CLOSE,
00761                     _("Error printing to file '%s'\n"
00762                       "Check the log window for more information"),
00763                     destination);
00764       gtk_dialog_run (GTK_DIALOG (popup_message));    
00765     }
00766       else
00767     {
00768       s_log_message (_("Printed current schematic to [%s]\n"), 
00769              destination);
00770     }
00771     }
00772    
00773   /* We don't need the dialog any more */
00774   gtk_widget_destroy (GTK_WIDGET (dialog));
00775 
00776 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines