1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
32 #ifdef HAVE_LIBDMALLOC
46 /* Private functions */
48 static void print_dialog_action_radio_toggled (GtkWidget
* w
,
49 PrintDialog
* dialog
);
51 static void print_dialog_init (PrintDialog
* dialog
);
52 static void print_dialog_init_paper_combobox (PrintDialog
* d
);
53 static void print_dialog_init_type_combobox (PrintDialog
* d
);
54 static void print_dialog_init_orient_combobox (PrintDialog
* d
);
55 static void print_dialog_set_property (GObject
* object
, guint property_id
,
58 static void print_dialog_set_property_comboboxes (PrintDialog
*dialog
,
60 const GValue
* value
);
61 static void print_dialog_get_property (GObject
* object
, guint property_id
,
62 GValue
* value
, GParamSpec
* pspec
);
63 static void print_dialog_get_property_comboboxes (PrintDialog
* dialog
,
66 static void print_dialog_class_init (PrintDialogClass
* class);
71 * \brief Callback function to show file chooser dialog
73 * \par Shows file chooser dialog for user to select PostScript file
75 * \par Private callback function, should not be called by any code
79 print_dialog_action_choosefile (GtkWidget
* w
, PrintDialog
* dialog
)
81 GtkWidget
*filechooser
;
82 const gchar
*filename
;
83 const gchar
*newfilename
;
84 filechooser
= gtk_file_chooser_dialog_new (_("Select PostScript Filename..."),
86 GTK_FILE_CHOOSER_ACTION_SAVE
,
90 GTK_RESPONSE_ACCEPT
, NULL
);
92 /* Set the alternative button order (ok, cancel, help) for other systems */
93 gtk_dialog_set_alternative_button_order(GTK_DIALOG(filechooser
),
98 filename
= gtk_entry_get_text (GTK_ENTRY (dialog
->fnfield
));
99 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser
), filename
);
101 gtk_dialog_set_default_response(GTK_DIALOG(filechooser
),
102 GTK_RESPONSE_ACCEPT
);
104 if (gtk_dialog_run (GTK_DIALOG (filechooser
)) == GTK_RESPONSE_ACCEPT
)
107 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser
));
108 gtk_entry_set_text (GTK_ENTRY (dialog
->fnfield
), newfilename
);
111 gtk_widget_destroy (filechooser
);
116 * \brief Create, initialize and populate a combobox for selecting
117 * what paper size to print to.
118 * \par Private function, should not be
119 * called by any code outside x_print.c
122 print_dialog_init_paper_combobox (PrintDialog
* d
)
124 GtkComboBox
*combobox
;
128 combobox
= GTK_COMBO_BOX (gtk_combo_box_new_text ());
129 gtk_combo_box_set_active (combobox
, -1);
131 /* Populate combo box with available paper sizes */
133 string
= (gchar
*) s_papersizes_get (i
);
134 while (string
!= NULL
)
136 gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox
), i
, string
);
139 string
= (gchar
*) s_papersizes_get (i
);
142 d
->papercbox
= combobox
;
146 * \brief Create, initialize and populate a combobox for selecting
147 * the type of printout to produce.
148 * \par Private function, should not be called by any code
152 print_dialog_init_type_combobox (PrintDialog
* d
)
156 GtkCellRenderer
*renderer
;
160 model
= gtk_list_store_new (2, G_TYPE_STRING
, G_TYPE_INT
);
162 gtk_list_store_append (model
, &iter
);
163 gtk_list_store_set (model
, &iter
,
164 0, _("Extents with margins"),
168 gtk_list_store_append (model
, &iter
);
169 gtk_list_store_set (model
, &iter
,
170 0, _("Extents no margins"),
171 1, EXTENTS_NOMARGINS
,
174 gtk_list_store_append (model
, &iter
);
175 gtk_list_store_set (model
, &iter
,
176 0, _("Current Window"),
180 combobox
= gtk_combo_box_new_with_model (GTK_TREE_MODEL (model
));
182 renderer
= gtk_cell_renderer_text_new ();
183 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
),
185 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox
),
186 renderer
, "text", 0);
188 d
->typecbox
= GTK_COMBO_BOX (combobox
);
192 * \brief Create, initialize and populate a combobox for selecting
194 * \par Private function, should not be called by any code
198 print_dialog_init_orient_combobox (PrintDialog
* d
)
202 GtkCellRenderer
*renderer
;
206 model
= gtk_list_store_new (2, G_TYPE_STRING
, G_TYPE_INT
);
208 gtk_list_store_append (model
, &iter
);
209 gtk_list_store_set (model
, &iter
,
214 gtk_list_store_append (model
, &iter
);
215 gtk_list_store_set (model
, &iter
,
220 combobox
= gtk_combo_box_new_with_model (GTK_TREE_MODEL (model
));
222 renderer
= gtk_cell_renderer_text_new ();
223 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
),
225 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox
),
226 renderer
, "text", 0);
228 d
->orientcbox
= GTK_COMBO_BOX (combobox
);
232 * \brief Handle the user clicking on radio buttons to select print
235 * \par Private callback function, should not be called by any code
239 print_dialog_action_radio_toggled (GtkWidget
* w
, PrintDialog
* dialog
)
241 if (w
== GTK_WIDGET (dialog
->cmdradio
))
243 gtk_widget_set_sensitive (GTK_WIDGET (dialog
->cmdfield
),
244 gtk_toggle_button_get_active
245 (GTK_TOGGLE_BUTTON (w
)));
247 else if (w
== GTK_WIDGET (dialog
->fileradio
))
249 gtk_widget_set_sensitive (GTK_WIDGET (dialog
->fnfield
),
250 gtk_toggle_button_get_active
251 (GTK_TOGGLE_BUTTON (w
)));
252 gtk_widget_set_sensitive (GTK_WIDGET (dialog
->saveasbutton
),
253 gtk_toggle_button_get_active
254 (GTK_TOGGLE_BUTTON (w
)));
259 /*! \todo Finish function documentation
261 * \par Function Description
265 print_dialog_init (PrintDialog
* dialog
)
269 GtkWidget
*settingstable
, *desttable
;
271 GtkWidget
*print_button
;
273 /* Initialize properties */
274 g_object_set (G_OBJECT (dialog
),
276 "title", _("Print..."),
277 "modal", TRUE
, "destroy-with-parent", TRUE
, NULL
);
279 /* Setup hbox for two main panes */
280 box
= gtk_vbox_new (FALSE
, 2);
281 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
), box
);
284 frame
= gtk_frame_new (_("Settings"));
285 gtk_container_set_border_width (GTK_CONTAINER (frame
), 3);
286 gtk_container_add (GTK_CONTAINER (box
), frame
);
288 /* Upper table with drop-down menus & labels
289 * Left-hand column contains labels, right-hand contains comboboxes*/
290 settingstable
= gtk_table_new (2, 3, FALSE
);
291 gtk_table_set_col_spacings (GTK_TABLE (settingstable
), 5);
292 gtk_table_set_row_spacings (GTK_TABLE (settingstable
), 5);
293 gtk_container_set_border_width (GTK_CONTAINER (settingstable
), 5);
294 gtk_container_add (GTK_CONTAINER (frame
), settingstable
);
296 label
= gtk_label_new (_("Output paper size:"));
297 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0);
298 gtk_table_attach (GTK_TABLE (settingstable
),
300 0, 1, 0, 1, GTK_EXPAND
| GTK_FILL
, GTK_EXPAND
, 0, 0);
302 print_dialog_init_paper_combobox (dialog
);
303 gtk_table_attach (GTK_TABLE (settingstable
),
304 GTK_WIDGET (dialog
->papercbox
),
305 1, 2, 0, 1, GTK_FILL
, 0, 0, 0);
307 label
= gtk_label_new (_("Type:"));
308 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0);
309 gtk_table_attach (GTK_TABLE (settingstable
),
311 0, 1, 1, 2, GTK_EXPAND
| GTK_FILL
, GTK_EXPAND
, 0, 0);
313 print_dialog_init_type_combobox (dialog
);
314 gtk_table_attach (GTK_TABLE (settingstable
),
315 GTK_WIDGET (dialog
->typecbox
),
316 1, 2, 1, 2, GTK_FILL
, 0, 0, 0);
318 label
= gtk_label_new (_("Orientation:"));
319 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0);
320 gtk_table_attach (GTK_TABLE (settingstable
),
322 0, 1, 2, 3, GTK_EXPAND
| GTK_FILL
, GTK_EXPAND
, 0, 0);
324 print_dialog_init_orient_combobox (dialog
);
325 gtk_table_attach (GTK_TABLE (settingstable
),
326 GTK_WIDGET (dialog
->orientcbox
),
327 1, 2, 2, 3, GTK_FILL
, 0, 0, 0);
330 frame
= gtk_frame_new (_("Destination"));
331 gtk_container_set_border_width (GTK_CONTAINER (frame
), 3);
332 gtk_container_add (GTK_CONTAINER (box
), frame
);
334 /* Table with destination selectors */
335 desttable
= gtk_table_new (3, 2, FALSE
);
336 gtk_table_set_col_spacings (GTK_TABLE (desttable
), 5);
337 gtk_table_set_row_spacings (GTK_TABLE (desttable
), 5);
338 gtk_container_set_border_width (GTK_CONTAINER (desttable
), 5);
339 gtk_container_add (GTK_CONTAINER (frame
), desttable
);
341 /* Widgets for printing to file */
343 GTK_RADIO_BUTTON (gtk_radio_button_new_with_label (NULL
, _("File:")));
344 gtk_table_attach (GTK_TABLE (desttable
),
345 GTK_WIDGET (dialog
->fileradio
),
346 0, 1, 0, 1, GTK_FILL
, GTK_EXPAND
, 0, 0);
347 g_signal_connect (dialog
->fileradio
,
349 GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled
),
352 dialog
->fnfield
= GTK_ENTRY (gtk_entry_new ());
353 gtk_table_attach (GTK_TABLE (desttable
),
354 GTK_WIDGET (dialog
->fnfield
),
355 1, 2, 0, 1, GTK_EXPAND
| GTK_FILL
, 0, 0, 0);
357 dialog
->saveasbutton
= GTK_BUTTON(gtk_button_new());
358 gtk_container_add(GTK_CONTAINER(dialog
->saveasbutton
),
359 gtk_image_new_from_stock(GTK_STOCK_OPEN
,
360 GTK_ICON_SIZE_SMALL_TOOLBAR
));
361 gtk_button_set_relief(GTK_BUTTON(dialog
->saveasbutton
), GTK_RELIEF_NONE
);
363 gtk_table_attach (GTK_TABLE (desttable
),
364 GTK_WIDGET (dialog
->saveasbutton
), 2, 3, 0, 1,
366 g_signal_connect (dialog
->saveasbutton
,
368 GTK_SIGNAL_FUNC (print_dialog_action_choosefile
), dialog
);
370 /* Widgets for printing to command */
372 GTK_RADIO_BUTTON (gtk_radio_button_new_with_label_from_widget
373 (dialog
->fileradio
, _("Command:")));
374 gtk_table_attach (GTK_TABLE (desttable
),
375 GTK_WIDGET (dialog
->cmdradio
),
376 0, 1, 1, 2, GTK_FILL
, GTK_EXPAND
, 0, 0);
377 g_signal_connect (dialog
->cmdradio
,
379 GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled
),
382 dialog
->cmdfield
= GTK_ENTRY (gtk_entry_new ());
383 gtk_table_attach (GTK_TABLE (desttable
), GTK_WIDGET (dialog
->cmdfield
),
384 1, 3, 1, 2, GTK_EXPAND
| GTK_FILL
, 0, 0, 0);
386 /* Add "Cancel" and "Print" buttons */
387 gtk_dialog_add_button (GTK_DIALOG (dialog
),
388 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
);
389 print_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
390 GTK_STOCK_PRINT
, GTK_RESPONSE_ACCEPT
);
391 gtk_widget_grab_focus(print_button
);
393 /* Set the alternative button order (ok, cancel, help) for other systems */
394 gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog
),
399 /* Set initial radiobutton selection */
400 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->cmdradio
), TRUE
);
403 /*! \todo Finish function documentation
405 * \par Function Description
409 print_dialog_set_property (GObject
* object
,
411 const GValue
* value
, GParamSpec
* pspec
)
413 PrintDialog
*dialog
= PRINT_DIALOG (object
);
414 gboolean file_active
= FALSE
;
419 gtk_entry_set_text (dialog
->fnfield
,
420 (char *) g_value_get_string (value
));
424 gtk_entry_set_text (dialog
->cmdfield
,
425 (char *) g_value_get_string (value
));
429 gtk_combo_box_set_active (dialog
->papercbox
,
430 g_value_get_int (value
));
433 case PROP_ORIENTATION
:
434 print_dialog_set_property_comboboxes (dialog
,
440 print_dialog_set_property_comboboxes (dialog
,
446 file_active
= g_value_get_boolean (value
);
447 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->fileradio
),
449 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->cmdradio
),
454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
458 /*! \todo Finish function documentation
460 * \par Function Description
464 print_dialog_set_property_comboboxes (PrintDialog
* dialog
,
466 const GValue
* value
)
471 model
= gtk_combo_box_get_model (cbox
);
472 gtk_tree_model_get_iter_first (model
, &iter
);
475 GValue temp_value
= {0, }; /* Make sure it's blank*/
476 gtk_tree_model_get_value (model
, &iter
, 1, &temp_value
);
478 if (g_value_get_int (&temp_value
) == g_value_get_int (value
))
480 gtk_combo_box_set_active_iter (cbox
, &iter
);
484 } while (gtk_tree_model_iter_next (model
, &iter
));
486 gtk_combo_box_set_active (cbox
, 0);
489 /*! \todo Finish function documentation
491 * \par Function Description
495 print_dialog_get_property (GObject
* object
,
497 GValue
* value
, GParamSpec
* pspec
)
499 PrintDialog
*dialog
= PRINT_DIALOG (object
);
500 gboolean file_active
= FALSE
;
505 g_value_set_string (value
,
506 gtk_entry_get_text (GTK_ENTRY (dialog
->fnfield
)));
510 g_value_set_string (value
,
511 gtk_entry_get_text (GTK_ENTRY (dialog
->cmdfield
)));
515 g_value_set_int (value
, gtk_combo_box_get_active (dialog
->papercbox
));
518 case PROP_ORIENTATION
:
519 print_dialog_get_property_comboboxes (dialog
,
525 print_dialog_get_property_comboboxes (dialog
,
532 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog
->fileradio
));
533 g_value_set_boolean (value
, file_active
);
537 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
541 /*! \todo Finish function documentation
543 * \par Function Description
547 print_dialog_get_property_comboboxes (PrintDialog
* dialog
,
551 GValue temp_value
= {0, };
555 model
= gtk_combo_box_get_model (cbox
);
557 gtk_combo_box_get_active_iter (cbox
, &iter
);
558 gtk_tree_model_get_value (model
, &iter
, 1, &temp_value
);
559 g_value_copy (&temp_value
, value
);
560 g_value_unset (&temp_value
);
563 /*! \todo Finish function documentation
565 * \par Function Description
566 * \bug Hardcoded 'magic' numbers in this function
570 print_dialog_class_init (PrintDialogClass
* class)
572 GObjectClass
*gobject_class
= G_OBJECT_CLASS (class);
574 gobject_class
->set_property
= print_dialog_set_property
;
575 gobject_class
->get_property
= print_dialog_get_property
;
577 g_object_class_install_property (gobject_class
, PROP_FILENAME
,
578 g_param_spec_string ("filename",
582 g_object_class_install_property (gobject_class
, PROP_COMMAND
,
583 g_param_spec_string ("command",
587 g_object_class_install_property (gobject_class
, PROP_PAPERSIZE
,
588 g_param_spec_int ("papersize",
589 "", "", 0, G_MAXINT
, 0,
592 g_object_class_install_property (gobject_class
, PROP_ORIENTATION
,
593 g_param_spec_int ("orientation",
594 "", "", 0, G_MAXINT
, 0,
597 g_object_class_install_property (gobject_class
, PROP_TYPE
,
598 g_param_spec_int ("type",
599 "", "", 0, G_MAXINT
, 0,
602 g_object_class_install_property (gobject_class
, PROP_USEFILE
,
603 g_param_spec_boolean ("usefile",
608 /*! \todo Finish function documentation
610 * \par Function Description
614 print_dialog_get_type ()
616 static GType print_dialog_type
= 0;
618 if (!print_dialog_type
)
620 static const GTypeInfo print_dialog_info
= {
621 sizeof (PrintDialogClass
),
622 NULL
, /* base_init */
623 NULL
, /* base_finalize */
624 (GClassInitFunc
) print_dialog_class_init
,
625 NULL
, /* class_finalize */
626 NULL
, /* class_data */
627 sizeof (PrintDialog
),
629 (GInstanceInitFunc
) print_dialog_init
,
631 print_dialog_type
= g_type_register_static (GSCHEM_TYPE_DIALOG
,
633 &print_dialog_info
, 0);
636 return print_dialog_type
;
639 /*! \todo Finish function documentation
641 * \par Function Description
645 x_print_setup (GSCHEM_TOPLEVEL
*w_current
, char *filename
)
647 TOPLEVEL
*toplevel
= w_current
->toplevel
;
648 gchar
* command
= w_current
->print_command
;
649 gint orient
= toplevel
->print_orientation
;
650 gint type
= toplevel
->print_output_type
;
651 gint paperidx
, x
, y
, result
;
652 gchar
*string
, *destination
;
653 gboolean usefile
= FALSE
;
655 GtkWidget
*popup_message
;
657 /* Work out current paper size by iterating through available paper
658 * sizes. Set the default paper size as the active selection */
660 /* FIXME: ought to have a TOPLEVEL property containing
661 * default paper size name, this is somewhat hackish. No
662 * better way of doing it with current implementation of
663 * varying paper size though. */
667 string
= (gchar
*) s_papersizes_get (paperidx
);
668 s_papersizes_get_size (string
, &x
, &y
);
670 if ((x
== toplevel
->paper_width
)
671 && (y
== toplevel
->paper_height
))
683 /* Create a print dialog, find out whether the user clicks Print or
684 Cancel, and then print or return accordingly */
685 dialog
= GTK_DIALOG (g_object_new (TYPE_PRINT_DIALOG
,
687 "filename", filename
,
688 "papersize", paperidx
,
689 "orientation", orient
,
693 "settings-name", "print",
694 "gschem-toplevel", w_current
,
696 gtk_widget_show_all (GTK_WIDGET (dialog
));
698 gtk_dialog_set_default_response(GTK_DIALOG(dialog
),
699 GTK_RESPONSE_ACCEPT
);
700 gtk_window_set_transient_for(GTK_WINDOW(dialog
),
701 GTK_WINDOW(w_current
->main_window
));
703 result
= gtk_dialog_run (dialog
);
705 if (result
== GTK_RESPONSE_ACCEPT
)
707 /* Extract values from dialog and set the paper size */
708 g_object_get (dialog
,
710 "filename", &filename
,
711 "papersize", &paperidx
,
712 "orientation", &toplevel
->print_orientation
,
713 "type", &toplevel
->print_output_type
,
717 s_papersizes_get_size (s_papersizes_get (paperidx
),
718 &toplevel
->paper_width
,
719 &toplevel
->paper_height
);
721 /* de select everything first */
722 o_select_unselect_all( w_current
);
724 if (usefile
&& filename
[0])
727 destination
= filename
;
728 result
= f_print_file (toplevel
, filename
);
731 /* Print to command and save command for later use. */
733 destination
= command
;
734 result
= f_print_command (toplevel
, command
);
736 g_free (w_current
->print_command
);
737 w_current
->print_command
= g_strdup (command
);
741 s_log_message (_("No print destination specified\n"));
745 /* Check whether it worked */
748 s_log_message (_("Cannot print current schematic to [%s]\n"),
751 /* Pop up a message warning the user */
753 gtk_message_dialog_new (GTK_WINDOW(dialog
),
754 GTK_DIALOG_DESTROY_WITH_PARENT
,
757 _("Error printing to file '%s'\n"
758 "Check the log window for more information"),
760 gtk_dialog_run (GTK_DIALOG (popup_message
));
764 s_log_message (_("Printed current schematic to [%s]\n"),
769 /* We don't need the dialog any more */
770 gtk_widget_destroy (GTK_WIDGET (dialog
));