[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gEDA-dev: [PATCH] libgeda, gschem: New print dialog
Hi folks,
I present my new print dialog: essentially, a rewrite of gschem's x_print_c
using GTK 2.4 widgets.
It contains support for printing to a command instead of to a file, but this
is currently disabled. A following patch will enable the functionality and
provide a Guile function for setting the default print command.
I know it's (far too) major to get into the imminent snapshot, but I thought
someone might like to have a look. This is a diff against CVS head, so it
includes my f_print_stream patch which the new dialog box needs.
Any comments/suggestions welcome.
Peter
--
Quake II build tools maintainer http://tinyurl.com/fkldd
v2sw6YShw7$ln5pr6ck3ma8u6/8Lw3+2m0l7Ci6e4+8t4Eb8Aen5+6g6Pa2Xs5MSr5p4
hackerkey.com
diff --git a/geda/gaf/gschem/include/prototype.h b/geda/gaf/gschem/include/prototype.h
index 0eccba8..8225b43 100644
--- a/geda/gaf/gschem/include/prototype.h
+++ b/geda/gaf/gschem/include/prototype.h
@@ -944,15 +944,6 @@ void x_preview_create_drawing(GtkWidget
void x_preview_setup_rest(TOPLEVEL *preview);
TOPLEVEL *x_preview_setup(GtkWidget *xfwindow, GtkWidget *drawbox);
/* x_print.c */
-gint print_landscape(GtkWidget *w, TOPLEVEL *w_current);
-gint print_portrait(GtkWidget *w, TOPLEVEL *w_current);
-gint x_print_set_window(GtkWidget *w, TOPLEVEL *w_current);
-gint x_print_set_extents(GtkWidget *w, TOPLEVEL *w_current);
-gint x_print_set_nomargins(GtkWidget *w, TOPLEVEL *w_current);
-gint x_print_change_size(GtkWidget *gtklist, TOPLEVEL *w_current);
-gint x_print_print(GtkWidget *w, TOPLEVEL *w_current);
-gint x_print_cancel(GtkWidget *w, TOPLEVEL *w_current);
-int x_print_keypress(GtkWidget *widget, GdkEventKey *event, TOPLEVEL *w_current);
void x_print_setup(TOPLEVEL *w_current, char *filename);
/* x_script.c */
void script_selection_ok(GtkWidget *w, TOPLEVEL *w_current);
diff --git a/geda/gaf/gschem/src/x_dialog.c b/geda/gaf/gschem/src/x_dialog.c
index b4914ec..b0cf16d 100644
--- a/geda/gaf/gschem/src/x_dialog.c
+++ b/geda/gaf/gschem/src/x_dialog.c
@@ -3401,9 +3401,6 @@ #if 0 /* don't raise these windows ever
}
#endif
- if(w_current->pwindow) {
- gdk_window_raise(w_current->pwindow->window);
- }
if(w_current->iwindow) {
gdk_window_raise(w_current->iwindow->window);
}
diff --git a/geda/gaf/gschem/src/x_print.c b/geda/gaf/gschem/src/x_print.c
index 248a0dd..62cb07c 100644
--- a/geda/gaf/gschem/src/x_print.c
+++ b/geda/gaf/gschem/src/x_print.c
@@ -35,511 +35,531 @@ #ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
-static const gchar *list_item_data_key = "list_item_data";
-
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
- */
-gint print_landscape(GtkWidget *w, TOPLEVEL *w_current)
+/* Private structures */
+struct st_print_info
{
- w_current->print_orientation = LANDSCAPE;
- return(0);
-}
-
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
+ TOPLEVEL *w_current;
+ GtkWidget *dialog;
+ GtkWidget *fnfield;
+ GtkWidget *cmdfield;
+ GtkWidget *fileradio;
+ GtkWidget *cmdradio;
+};
+
+/* Private constants */
+enum type_indices
+{ EXTENTS_IDX = 0, EXTENTS_NOMARGINS_IDX = 1, WINDOW_IDX = 2 };
+enum orient_indices
+{ PORTRAIT_IDX = 1, LANDSCAPE_IDX = 0 };
+
+/* Private functions */
+void x_print_end (GtkWidget * w, struct st_print_info *info);
+void x_print_print (GtkWidget * w, struct st_print_info *info);
+void x_print_choosefile (GtkWidget * w, struct st_print_info *info);
+int x_print_keypress (GtkWidget * widget, GdkEventKey * event,
+ struct st_print_info *info);
+void x_paper_combobox_changed (GtkWidget * w, TOPLEVEL * w_current);
+void x_type_combobox_changed (GtkWidget * w, TOPLEVEL * w_current);
+void x_orient_combobox_changed (GtkWidget * w, TOPLEVEL * w_current);
+GtkWidget *create_paper_combobox (TOPLEVEL * w_current);
+GtkWidget *create_type_combobox (TOPLEVEL * w_current);
+GtkWidget *create_orient_combobox (TOPLEVEL * w_current);
+
+
+/*!
+ * \brief Dismiss print dialog box
+ * \par Close print dialog box and free malloc-ated memory.
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
*/
-gint print_portrait(GtkWidget *w, TOPLEVEL *w_current)
+void
+x_print_end (GtkWidget * w, struct st_print_info *info)
{
- w_current->print_orientation = PORTRAIT;
- return(0);
-}
+ gtk_widget_hide_all (info->dialog);
+ gtk_widget_destroy (info->dialog);
+ g_free (info);
+};
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
+/*!
+ * \brief Callback function for doing actual print
*
- */
-gint x_print_set_window(GtkWidget *w, TOPLEVEL *w_current)
-{
- f_print_set_type(w_current, WINDOW);
- return(0);
-}
-
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
+ * \par Opens target file, or opens pipe to target command, and
+ * prints PostScript into the stream before dismissing the dialog
+ * box.
*
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
*/
-gint x_print_set_extents(GtkWidget *w, TOPLEVEL *w_current )
+void
+x_print_print (GtkWidget * w, struct st_print_info *info)
{
- f_print_set_type(w_current, EXTENTS);
- return(0);
-}
+ int status;
+ FILE *targetfp = NULL;
+ const char *string;
+
+ /* Extract values from widgets */
+ TOPLEVEL *w_current = info->w_current;
+ const char *filename = gtk_entry_get_text (GTK_ENTRY (info->fnfield));
+ const char *command = gtk_entry_get_text (GTK_ENTRY (info->cmdfield));
+ const gboolean usefile =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->fileradio));
+
+ if (usefile && filename[0])
+ /* Open file for writing */
+ {
+ string = filename;
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
- */
-gint x_print_set_nomargins(GtkWidget *w, TOPLEVEL *w_current )
-{
- f_print_set_type(w_current, EXTENTS_NOMARGINS);
- return(0);
+ targetfp = fopen (filename, "wb");
+ }
+ else if (command[0])
+ /* Open pipe for writing */
+ {
+ string = command;
+
+ targetfp = popen (command, "w");
+ }
+ else
+ {
+ s_log_message (_("No print destination specified\n"));
+ return;
+ }
+
+ /* check we have a valid file pointer */
+ if (targetfp == NULL)
+ {
+ s_log_message (_("Could not open [%s] for printing\n"), string);
+ return;
+ }
+
+
+ if (targetfp != NULL)
+ {
+
+ /* de select everything first */
+ o_select_run_hooks (info->w_current, NULL, 2);
+ o_selection_remove_most (info->w_current,
+ info->w_current->page_current->
+ selection2_head);
+
+ status = f_print_stream (w_current, targetfp);
+
+ if (status)
+ {
+ s_log_message (_("Cannot print current schematic to [%s]\n"),
+ string);
+ }
+ else
+ {
+ s_log_message (_("Printed current schematic to [%s]\n"), string);
+ }
+
+ usefile ? fclose (targetfp) : pclose (targetfp);
+ }
+
+ /* Dispose of the print dialog */
+ x_print_end (w, info);
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
+/*!
+ * \brief Callback function to show file chooser dialog
*
- * \note
- * this is from gtktest.c and only used in this file,
- * there are other create_menus...
+ * \par Shows file chooser dialog for user to select PostScript file
+ * to print to.
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
*/
-static GtkWidget *create_menu_orient (TOPLEVEL *w_current)
+void
+x_print_choosefile (GtkWidget * w, struct st_print_info *info)
{
- GtkWidget *menu;
- GtkWidget *menuitem;
- GSList *group;
- char *buf;
-
- menu = gtk_menu_new ();
- group = NULL;
-
- buf = g_strdup_printf(_("Landscape"));
- menuitem = gtk_radio_menu_item_new_with_label (group, buf);
- g_free(buf);
- group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
- (GtkSignalFunc) print_landscape,
- w_current);
-
- gtk_widget_show (menuitem);
-
- buf = g_strdup_printf(_("Portrait"));
- menuitem = gtk_radio_menu_item_new_with_label (group, buf);
- g_free(buf);
- group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
- (GtkSignalFunc) print_portrait,
- w_current);
- gtk_widget_show (menuitem);
-
- if (w_current->print_orientation == PORTRAIT) {
- gtk_menu_set_active(GTK_MENU (menu),1);
- print_portrait (NULL, w_current);
- } else {
- print_landscape (NULL, w_current);
- }
-
- return menu;
+ GtkWidget *filechooser;
+ const gchar *filename;
+ const gchar *newfilename;
+ filechooser = gtk_file_chooser_dialog_new (_("Save PostScript As..."),
+ GTK_WINDOW (info->dialog),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE_AS,
+ GTK_RESPONSE_ACCEPT, NULL);
+
+ filename = gtk_entry_get_text (GTK_ENTRY (info->fnfield));
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), filename);
+
+
+ if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
+ {
+ newfilename =
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
+ gtk_entry_set_text (GTK_ENTRY (info->fnfield), newfilename);
+ }
+
+ gtk_widget_destroy (filechooser);
+
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
+
+/*!
+ * \brief Handle keypress events caught by the print dialog.
+ * \par Currently only dismisses the dialog on Esc being pressed.
*
- * \note
- * this is from gtktest.c and only used in this file,
- * there are other create_menus...
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
*/
-static GtkWidget *create_menu_type (TOPLEVEL *w_current)
+int
+x_print_keypress (GtkWidget * widget, GdkEventKey * event,
+ struct st_print_info *info)
{
- GtkWidget *menu;
- GtkWidget *menuitem;
- GSList *group;
- char *buf;
-
- menu = gtk_menu_new ();
- group = NULL;
-
- buf = g_strdup_printf(_("Extents with margins"));
- menuitem = gtk_radio_menu_item_new_with_label (group, buf);
- g_free(buf);
- group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
- (GtkSignalFunc) x_print_set_extents,
- w_current);
- gtk_widget_show (menuitem);
-
- buf = g_strdup_printf(_("Extents no margins"));
- menuitem = gtk_radio_menu_item_new_with_label(group, buf);
- g_free(buf);
- group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem));
- gtk_menu_append(GTK_MENU(menu), menuitem);
- gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
- (GtkSignalFunc) x_print_set_nomargins, w_current);
- gtk_widget_show(menuitem);
-
- buf = g_strdup_printf(_("Current Window"));
- menuitem = gtk_radio_menu_item_new_with_label (group, buf);
- g_free(buf);
- group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
- (GtkSignalFunc) x_print_set_window,
- w_current);
- gtk_widget_show (menuitem);
+ if ((widget == info->dialog) &&
+ (strcmp (gdk_keyval_name (event->keyval), "Escape") == 0))
+ {
+ x_print_end (widget, info);
+ return TRUE;
- switch (w_current->print_output_type)
- {
- case(EXTENTS):
- gtk_menu_set_active(GTK_MENU (menu),0);
- f_print_set_type(w_current, EXTENTS);
- break;
+ }
- case(EXTENTS_NOMARGINS):
- gtk_menu_set_active(GTK_MENU (menu),1);
- f_print_set_type(w_current, EXTENTS_NOMARGINS);
- break;
+ return FALSE;
+}
- case(WINDOW):
- gtk_menu_set_active(GTK_MENU (menu),2);
- f_print_set_type(w_current, WINDOW);
- break;
- }
+/*!
+ * \brief Set the document paper size in response to the combobox
+ * selection changing.
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
+ */
+void
+x_paper_combobox_changed (GtkWidget * w, TOPLEVEL * w_current)
+{
+ char *s;
+ s = gtk_combo_box_get_active_text (GTK_COMBO_BOX (w));
+ if (s == NULL)
+ return;
- return menu;
+ s_papersizes_get_size (s,
+ &w_current->paper_width, &w_current->paper_height);
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
+/*!
+ * \brief Create, initialize and populate a combobox for selecting
+ * what paper size to print to.
+ * \par Private function, should not be
+ * called by any code outside x_print.c
*/
-gint x_print_change_size (GtkWidget *gtklist, TOPLEVEL *w_current)
+GtkWidget *
+create_paper_combobox (TOPLEVEL * w_current)
{
- GList *dlist;
- GtkObject *listitem;
- gchar *item_data_string;
+ GtkWidget *combobox;
+ gchar *string;
+ int i, x, y;
+
+ combobox = gtk_combo_box_new_text ();
+ g_signal_connect (combobox,
+ "changed",
+ GTK_SIGNAL_FUNC (x_paper_combobox_changed), w_current);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), -1);
+
+ /* Populate combobox by iterating through available paper sizes.
+ * Set the default paper size as the active selection */
+ i = 0;
+ string = (gchar *) s_papersizes_get (i);
+ while (string != NULL)
+ {
- dlist = GTK_LIST(w_current->plib_list)->selection;
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), i, string);
- if (!dlist) {
- /* g_print("Selection cleared\n");*/
- return(0);
- }
+ /* FIXME: ought a TOPLEVEL property containing default paper size
+ * name, this is somewhat hackish. No better way of doing it with
+ * cureent implementation of varying paper size though. */
+ s_papersizes_get_size (string, &x, &y);
- listitem = GTK_OBJECT(dlist->data);
- item_data_string=gtk_object_get_data(listitem, list_item_data_key);
+ if ((x == w_current->paper_width) && (y == w_current->paper_height))
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), i);
+ }
-#if DEBUG
- printf("paper_size string: %s\n", item_data_string);
- len = strlen(item_data_string);
- /* strcpy(current_attr_name, item_data_string);*/
-#endif
+ i++;
+ string = (char *) s_papersizes_get (i);
+ }
- s_papersizes_get_size(item_data_string,
- &w_current->paper_width,
- &w_current->paper_height);
+ return combobox;
+}
-#if 0
- gtk_entry_set_text(GTK_ENTRY(w_current->asentry_name),
- item_data_string);
- gtk_entry_select_region(GTK_ENTRY(w_current->asentry_name), 0, len);
-#endif
- return(0);
+/*!
+ * \brief Set the the type of printout to produce in response to the
+ * combobox selection changing.
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c */
+void
+x_type_combobox_changed (GtkWidget * w, TOPLEVEL * w_current)
+{
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (w)))
+ {
+ case EXTENTS_IDX:
+ w_current->print_output_type = EXTENTS;
+ break;
+ case EXTENTS_NOMARGINS_IDX:
+ w_current->print_output_type = EXTENTS_NOMARGINS;
+ break;
+ case WINDOW_IDX:
+ w_current->print_output_type = WINDOW;
+ break;
+ }
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
- */
-gint x_print_print(GtkWidget *w, TOPLEVEL *w_current)
+/*!
+ * \brief Create, initialize and populate a combobox for selecting
+ * the type of printout to produce.
+ * \par Private function, should not be called by any code
+ * outside x_print.c */
+GtkWidget *
+create_type_combobox (TOPLEVEL * w_current)
{
- int status;
- const char *filename =
- gtk_entry_get_text(GTK_ENTRY(w_current->pfilename_entry));
+ GtkWidget *combobox;
+ gchar *label;
+
+ combobox = gtk_combo_box_new_text ();
+ g_signal_connect (combobox,
+ "changed",
+ GTK_SIGNAL_FUNC (x_type_combobox_changed), w_current);
- if (filename[0] != '\0') {
+ label = g_strdup_printf (_("Extents with margins"));
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), EXTENTS_IDX, label);
- /* de select everything first */
- o_select_run_hooks(w_current, NULL, 2);
- o_selection_remove_most(w_current,
- w_current->page_current->
- selection2_head);
+ label = g_strdup_printf (_("Extents no margins"));
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), EXTENTS_NOMARGINS_IDX,
+ label);
- status = f_print(w_current, filename);
+ label = g_strdup_printf (_("Current Window"));
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), WINDOW_IDX, label);
- if (status) {
- s_log_message(_("Cannot print current schematic to [%s]\n"), filename);
- } else {
- s_log_message(_("Printed current schematic to [%s]\n"), filename);
+
+ /* Set initial value */
+ switch (w_current->print_output_type)
+ {
+ case (EXTENTS_NOMARGINS):
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox),
+ EXTENTS_NOMARGINS_IDX);
+ break;
+ case (WINDOW):
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), WINDOW_IDX);
+ break;
+ case (EXTENTS):
+ default:
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), EXTENTS_IDX);
+ break;
}
- }
- gtk_widget_destroy(w_current->pwindow);
- w_current->pwindow = NULL;
- return(0);
-}
+ return combobox;
-gint x_print_cancel(GtkWidget *w, TOPLEVEL *w_current)
-{
-#if 0
- gtk_grab_remove(w_current->pwindow);
-#endif
- gtk_widget_destroy(w_current->pwindow);
- w_current->pwindow = NULL;
- return(0);
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
+/*!
+ * \brief Set the the page orientation in response to the combobox
+ * selection changing.
+ * \par Private callback function, should not be called by any code
+ * outside x_print.c
*/
-int x_print_keypress(GtkWidget * widget, GdkEventKey * event,
- TOPLEVEL * w_current)
+void
+x_orient_combobox_changed (GtkWidget * w, TOPLEVEL * w_current)
{
- if (strcmp(gdk_keyval_name(event->keyval), "Escape") == 0) {
- x_print_cancel(NULL, w_current);
- return TRUE;
- }
-
- return FALSE;
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (w)))
+ {
+ case PORTRAIT_IDX:
+ w_current->print_orientation = PORTRAIT;
+ break;
+ case LANDSCAPE_IDX:
+ default:
+ w_current->print_orientation = LANDSCAPE;
+ break;
+ }
}
-/*! \todo Finish function documentation!!!
- * \brief
- * \par Function Description
- *
- */
-void x_print_setup (TOPLEVEL *w_current, char *filename)
+/*!
+ * \brief Create, initialize and populate a combobox for selecting
+ * paper orientation.
+ * \par Private function, should not be called by any code
+ * outside x_print.c */
+GtkWidget *
+create_orient_combobox (TOPLEVEL * w_current)
{
- GtkWidget *label;
- GtkWidget *separator;
- GtkWidget *box;
- GtkWidget *box2;
- GtkWidget *buttonprint;
- GtkWidget *buttoncancel;
- GtkWidget *scrolled_win;
- GtkWidget *list_item;
- GtkWidget *optionmenu;
- GtkWidget *orient_menu;
- GtkWidget *type_menu;
- GtkWidget *vbox, *action_area;
- char *string = NULL;
- int i;
-
- /* freeze the window_current pointer so that it doesn't change */
-
- if (!w_current->pwindow) {
-
- w_current->pwindow = x_create_dialog_box(&vbox, &action_area);
- gtk_container_border_width(GTK_CONTAINER(w_current->pwindow), 5);
-
- gtk_window_position(GTK_WINDOW (w_current->pwindow),
- GTK_WIN_POS_MOUSE);
-
- gtk_signal_connect(GTK_OBJECT (w_current->pwindow),
- "destroy",
- GTK_SIGNAL_FUNC(destroy_window),
- &w_current->pwindow);
-
-#if 0 /* this was causing the dialog box to not die */
- gtk_signal_connect(GTK_OBJECT (w_current->pwindow),
- "delete_event",
- GTK_SIGNAL_FUNC(destroy_window),
- &w_current->pwindow);
-#endif
+ GtkWidget *combobox;
+ gchar *label;
- gtk_window_set_title(GTK_WINDOW(w_current->pwindow),
- _("Print..."));
+ combobox = gtk_combo_box_new_text ();
+ g_signal_connect (combobox,
+ "changed",
+ GTK_SIGNAL_FUNC (x_orient_combobox_changed), w_current);
-#ifdef HAS_GTK12
- buttonprint = gtk_button_new_with_label (_("Print"));
-#else
- buttonprint = gtk_button_new_from_stock (GTK_STOCK_PRINT);
-#endif
- GTK_WIDGET_SET_FLAGS (buttonprint, GTK_CAN_DEFAULT);
- gtk_box_pack_start(GTK_BOX(action_area),
- buttonprint, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(buttonprint), "clicked",
- GTK_SIGNAL_FUNC(x_print_print), w_current);
- gtk_widget_show (buttonprint);
- gtk_widget_grab_default (buttonprint);
-
-#ifdef HAS_GTK12
- buttoncancel = gtk_button_new_with_label (_("Cancel"));
-#else
- buttoncancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
-#endif
- GTK_WIDGET_SET_FLAGS (buttoncancel, GTK_CAN_DEFAULT);
- gtk_box_pack_start(GTK_BOX(action_area),
- buttoncancel, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(buttoncancel),
- "clicked", GTK_SIGNAL_FUNC(x_print_cancel),
- w_current);
- gtk_widget_show (buttoncancel);
-
- label = gtk_label_new (_("Output paper size"));
- gtk_misc_set_padding (GTK_MISC (label), 5, 5);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
-
- gtk_widget_show (label);
-
- scrolled_win = gtk_scrolled_window_new (NULL, NULL);
-
- gtk_scrolled_window_set_policy(
- GTK_SCROLLED_WINDOW(scrolled_win),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start(GTK_BOX(vbox), scrolled_win, TRUE, TRUE, 10);
- gtk_widget_set_usize(GTK_WIDGET(scrolled_win), 150, 100);
- gtk_widget_show (scrolled_win);
- box2 = gtk_vbox_new (FALSE, 0);
- gtk_scrolled_window_add_with_viewport(
- GTK_SCROLLED_WINDOW (scrolled_win), box2);
- gtk_widget_show(box2);
-
- separator = gtk_hseparator_new ();
- gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 0);
- gtk_widget_show (separator);
-
- w_current->plib_list = gtk_list_new ();
-
- gtk_container_add(GTK_CONTAINER (box2), w_current->plib_list);
- gtk_widget_show (w_current->plib_list);
-
- i = 0;
- string = (char *) s_papersizes_get(i);
- while (string != NULL) {
- GtkWidget *label = gtk_label_new(string);
-
- gtk_misc_set_alignment(GTK_MISC (label), 0, 0);
-
- list_item = gtk_list_item_new();
- gtk_container_add(GTK_CONTAINER(list_item), label);
- gtk_widget_show(label);
- gtk_container_add(GTK_CONTAINER(w_current->plib_list),
- list_item);
- gtk_widget_show (list_item);
- gtk_label_get(GTK_LABEL(label), &string);
- gtk_object_set_data(GTK_OBJECT(list_item),
- list_item_data_key,
- string);
- i++;
- string = (char *) s_papersizes_get(i);
- }
+ label = g_strdup_printf (_("Landscape"));
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), LANDSCAPE_IDX, label);
+
+ label = g_strdup_printf (_("Portrait"));
+ gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), PORTRAIT_IDX, label);
- gtk_signal_connect(GTK_OBJECT(w_current->plib_list),
- "selection_changed",
- GTK_SIGNAL_FUNC(x_print_change_size),
- w_current);
-
- box = gtk_hbox_new(FALSE, 0);
- gtk_container_border_width(GTK_CONTAINER(box), 0);
- gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, TRUE, 5);
- gtk_box_set_spacing(GTK_BOX(box), 10);
- gtk_widget_show(box);
-
- label = gtk_label_new (_("Filename"));
- gtk_misc_set_alignment( GTK_MISC (label), 0, 0);
- gtk_misc_set_padding (GTK_MISC (label), 0, 0);
- gtk_box_pack_start (GTK_BOX (box),
- label, FALSE, FALSE, 0);
-
- gtk_widget_show (label);
-
- w_current->pfilename_entry =
- gtk_entry_new_with_max_length(200);
- gtk_editable_select_region(
- GTK_EDITABLE(w_current->pfilename_entry), 0, -1);
- gtk_box_pack_start(GTK_BOX (box),
- w_current->pfilename_entry, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(w_current->pfilename_entry),
- "activate",
- GTK_SIGNAL_FUNC(x_print_print),
- w_current);
- gtk_widget_show (w_current->pfilename_entry);
-
- separator = gtk_hseparator_new ();
- gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 0);
- gtk_widget_show (separator);
-
- label = gtk_label_new (_("Type"));
- gtk_misc_set_padding (GTK_MISC (label), 5, 5);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
- gtk_widget_show (label);
- optionmenu = gtk_option_menu_new ();
- type_menu = create_menu_type (w_current);
- gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu),
- type_menu);
- gtk_option_menu_set_history(GTK_OPTION_MENU (optionmenu), 4);
- gtk_box_pack_start(GTK_BOX(vbox), optionmenu, FALSE, TRUE, 0);
- gtk_widget_show(optionmenu);
-
- label = gtk_label_new (_("Orientation"));
- gtk_misc_set_padding (GTK_MISC (label), 5, 5);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
-
- gtk_widget_show (label);
- optionmenu = gtk_option_menu_new ();
- orient_menu = create_menu_orient (w_current);
- gtk_option_menu_set_menu(GTK_OPTION_MENU (optionmenu),
- orient_menu);
- gtk_option_menu_set_history(GTK_OPTION_MENU (optionmenu), 4);
- gtk_box_pack_start(GTK_BOX(vbox), optionmenu, FALSE, TRUE, 0);
- gtk_widget_show (optionmenu);
-
- /* set some defaults */
- switch (w_current->print_output_type)
+ /* Set initial value */
+ switch (w_current->print_orientation)
{
- case(EXTENTS):
- gtk_menu_set_active(GTK_MENU (type_menu),0);
- f_print_set_type(w_current, EXTENTS);
- break;
-
- case(EXTENTS_NOMARGINS):
- gtk_menu_set_active(GTK_MENU (type_menu),1);
- f_print_set_type(w_current, EXTENTS_NOMARGINS);
- break;
-
- case(WINDOW):
- gtk_menu_set_active(GTK_MENU (type_menu),2);
- f_print_set_type(w_current, WINDOW);
- break;
- }
-
- if (w_current->print_orientation == PORTRAIT) {
- gtk_menu_set_active(GTK_MENU (orient_menu),1);
- print_portrait (NULL, w_current);
- } else {
- gtk_menu_set_active(GTK_MENU (orient_menu),0);
- print_landscape (NULL, w_current);
+ case PORTRAIT:
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), PORTRAIT_IDX);
+ break;
+ case LANDSCAPE:
+ default:
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), LANDSCAPE_IDX);
+ break;
}
- gtk_signal_connect(GTK_OBJECT(w_current->pwindow), "key_press_event",
- (GtkSignalFunc) x_print_keypress, w_current);
- }
-
-
-
- if (!GTK_WIDGET_VISIBLE (w_current->pwindow)) {
- gtk_entry_set_text(GTK_ENTRY(w_current->pfilename_entry),
- filename);
-#if 0
- gtk_entry_select_region(GTK_ENTRY(w_current->pfilename_entry),
- 0, strlen(filename));
-#endif
+ return combobox;
+}
- gtk_widget_show (w_current->pwindow);
- gdk_window_raise(w_current->pwindow->window);
-#if 0
- gtk_grab_add (w_current->pwindow);
-#endif
- } else {
- /* window should already be mapped, otherwise this
- * will core */
- gdk_window_raise(w_current->pwindow->window);
- }
+/*!
+ * \brief Create and display print dialog
+ */
+void
+x_print_setup (TOPLEVEL * w_current, char *filename)
+{
+ GtkWidget *buttonprint;
+ GtkWidget *buttoncancel;
+ GtkWidget *box;
+ GtkWidget *frame;
+ GtkWidget *settingstable, *desttable;
+ GtkWidget *buttonsaveas;
+ GtkWidget *label;
+ struct st_print_info *printinfo = g_malloc (sizeof (struct st_print_info));
+
+ printinfo->w_current = w_current;
+
+ /* Create modal dialog */
+ printinfo->dialog = gtk_dialog_new ();
+ gtk_window_set_title (GTK_WINDOW (printinfo->dialog), _("Print..."));
+ gtk_window_set_transient_for (GTK_WINDOW (printinfo->dialog),
+ GTK_WINDOW (w_current->main_window));
+ gtk_window_set_modal (GTK_WINDOW (printinfo->dialog), TRUE);
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (printinfo->dialog), TRUE);
+ /* g_signal_connect (printinfo->dialog,
+ "destroy",
+ GTK_SIGNAL_FUNC (x_print_end),
+ printinfo); */
+ g_signal_connect (printinfo->dialog,
+ "key_press_event",
+ GTK_SIGNAL_FUNC (x_print_keypress), printinfo);
+
+ /* Setup hbox for two main panes */
+ box = gtk_vbox_new (FALSE, 2);
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (printinfo->dialog)->vbox),
+ box);
+
+ /* Upper frame */
+ frame = gtk_frame_new (_("Settings"));
+ gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
+ gtk_container_add (GTK_CONTAINER (box), frame);
+
+ /* Upper table with drop-down menus & labels
+ * Left-hand column contains labels, right-hand contains comboboxes*/
+ settingstable = gtk_table_new (2, 3, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (settingstable), 5);
+ gtk_table_set_row_spacings (GTK_TABLE (settingstable), 5);
+ gtk_container_set_border_width (GTK_CONTAINER (settingstable), 5);
+ gtk_container_add (GTK_CONTAINER (frame), settingstable);
+
+ label = gtk_label_new (_("Output paper size"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
+ gtk_table_attach (GTK_TABLE (settingstable),
+ label,
+ 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
+
+
+ gtk_table_attach (GTK_TABLE (settingstable),
+ GTK_WIDGET (create_paper_combobox (w_current)),
+ 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
+
+ label = gtk_label_new (_("Type"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
+ gtk_table_attach (GTK_TABLE (settingstable),
+ label,
+ 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
+
+ gtk_table_attach (GTK_TABLE (settingstable),
+ GTK_WIDGET (create_type_combobox (w_current)),
+ 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
+
+ label = gtk_label_new (_("Orientation"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
+ gtk_table_attach (GTK_TABLE (settingstable),
+ label,
+ 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
+
+ gtk_table_attach (GTK_TABLE (settingstable),
+ GTK_WIDGET (create_orient_combobox (w_current)),
+ 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
+
+ /* Lower frame */
+ frame = gtk_frame_new (_("Destination"));
+ gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
+ gtk_container_add (GTK_CONTAINER (box), frame);
+
+ /* Table with destination selectors */
+ desttable = gtk_table_new (3, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (desttable), 5);
+ gtk_table_set_row_spacings (GTK_TABLE (desttable), 5);
+ gtk_container_set_border_width (GTK_CONTAINER (desttable), 5);
+ gtk_container_add (GTK_CONTAINER (frame), desttable);
+
+ /* Widgets for printing to file */
+ printinfo->fileradio = gtk_radio_button_new_with_label (NULL, _("File"));
+ gtk_table_attach (GTK_TABLE (desttable),
+ printinfo->fileradio,
+ 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
+
+ printinfo->fnfield = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (printinfo->fnfield), filename);
+ gtk_table_attach (GTK_TABLE (desttable),
+ printinfo->fnfield,
+ 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
+
+ buttonsaveas = gtk_button_new_from_stock (GTK_STOCK_SAVE_AS);
+ gtk_table_attach (GTK_TABLE (desttable),
+ buttonsaveas, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
+ g_signal_connect (buttonsaveas,
+ "clicked",
+ GTK_SIGNAL_FUNC (x_print_choosefile), printinfo);
+
+ /* Widgets for printing to command */
+ printinfo->cmdradio =
+ gtk_radio_button_new_with_label_from_widget
+ (GTK_RADIO_BUTTON (printinfo->fileradio), _("Command"));
+ gtk_table_attach (GTK_TABLE (desttable),
+ printinfo->cmdradio,
+ 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
+
+ printinfo->cmdfield = gtk_entry_new ();
+ gtk_table_attach (GTK_TABLE (desttable),
+ printinfo->cmdfield,
+ 1, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0);
+
+ /* Add "Cancel" button */
+ buttoncancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+ g_signal_connect (buttoncancel,
+ "clicked", GTK_SIGNAL_FUNC (x_print_end), printinfo);
+ gtk_container_add (GTK_CONTAINER
+ (GTK_DIALOG (printinfo->dialog)->action_area),
+ buttoncancel);
+
+ /* Add "Print" button */
+ buttonprint = gtk_button_new_from_stock (GTK_STOCK_PRINT);
+ gtk_container_add (GTK_CONTAINER
+ (GTK_DIALOG (printinfo->dialog)->action_area),
+ buttonprint);
+
+ /* Ugly hack to pass multiple items to event handler */
+ g_signal_connect (buttonprint,
+ "clicked", GTK_SIGNAL_FUNC (x_print_print), printinfo);
+
+ /* FIXME For now, disable printing to command until the backend supports it. */
+ gtk_widget_set_sensitive (GTK_WIDGET (printinfo->cmdradio), FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (printinfo->cmdfield), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (printinfo->fileradio),
+ TRUE);
+
+ /* Show dialog and save a pointer to it */
+ gtk_widget_show_all (printinfo->dialog);
}
diff --git a/geda/gaf/gschem/src/x_window.c b/geda/gaf/gschem/src/x_window.c
index 558beb3..6eecd35 100644
--- a/geda/gaf/gschem/src/x_window.c
+++ b/geda/gaf/gschem/src/x_window.c
@@ -109,7 +109,6 @@ void x_window_setup (TOPLEVEL *toplevel)
toplevel->trwindow = NULL;
toplevel->tswindow = NULL;
toplevel->pswindow = NULL;
- toplevel->pwindow = NULL;
toplevel->iwindow = NULL;
toplevel->abwindow = NULL;
toplevel->hkwindow = NULL;
@@ -965,9 +964,6 @@ #endif
if (w_current->iwindow)
gtk_widget_destroy(w_current->iwindow);
- if (w_current->pwindow)
- gtk_widget_destroy(w_current->pwindow);
-
if (w_current->hkwindow)
gtk_widget_destroy(w_current->hkwindow);
diff --git a/geda/gaf/libgeda/include/prototype.h b/geda/gaf/libgeda/include/prototype.h
index d34e31b..fb331ee 100644
--- a/geda/gaf/libgeda/include/prototype.h
+++ b/geda/gaf/libgeda/include/prototype.h
@@ -26,6 +26,7 @@ int f_print_header(TOPLEVEL *w_current,
void f_print_footer(FILE *fp);
void f_print_objects(TOPLEVEL *w_current, FILE *fp, OBJECT *head, int start_x, int start_y, float scale, int unicode_count, gunichar *unicode_table);
int f_print(TOPLEVEL *w_current, const char *filename);
+int f_print_stream(TOPLEVEL *w_current, FILE *fp);
void f_print_set_type(TOPLEVEL *w_current, int type);
int f_print_initialize_glyph_table(void);
diff --git a/geda/gaf/libgeda/include/struct.h b/geda/gaf/libgeda/include/struct.h
index 32bc299..39cd0b9 100644
--- a/geda/gaf/libgeda/include/struct.h
+++ b/geda/gaf/libgeda/include/struct.h
@@ -618,9 +618,10 @@ #endif
/* each of the different */
/* members of this array are */
- GtkWidget *pwindow; /* printing dialog box */
- GtkWidget *plib_list; /* paper size box */
- GtkWidget *pfilename_entry;
+ GtkWidget *printdialog; /* printing dialog box */
+ gchar *printcommand; /* command to print to */
+ gchar *printfilename; /* filename to print to */
+ gboolean printtofile; /* print to file if TRUE */
GtkWidget *iwindow; /* image write dialog box */
GtkWidget *ifilename_entry;
diff --git a/geda/gaf/libgeda/src/f_print.c b/geda/gaf/libgeda/src/f_print.c
index 42f67a2..af818d9 100644
--- a/geda/gaf/libgeda/src/f_print.c
+++ b/geda/gaf/libgeda/src/f_print.c
@@ -352,7 +352,9 @@ void f_print_objects(TOPLEVEL *w_current
return;
}
-/*! \brief Print the current TOPLEVEL object to a postscript document.
+/*! \brief Print the current TOPLEVEL object to a file as a postscript
+ * document.
+ *
* \par Function Description
*
* \param [in] w_current The TOPLEVEL object to print.
@@ -362,6 +364,33 @@ void f_print_objects(TOPLEVEL *w_current
int f_print(TOPLEVEL *w_current, const char *filename)
{
FILE *fp;
+ int result;
+
+ /* dots are breaking my filename selection hack hack !!!! */
+ fp = fopen(filename, "w");
+
+ /* check to see if it worked */
+ if (fp == NULL) {
+ s_log_message("Could not open [%s] for printing\n", filename);
+ return(-1);
+ }
+
+ result = f_print_stream(w_current, fp);
+ fclose (fp);
+ return result;
+}
+
+/*! \brief Print the current TOPLEVEL object to a stream as a
+ * postscript document.
+ * \par Function Description
+ *
+ * \param [in] w_current The TOPLEVEL object to print.
+ * \param [in] fp An open FILE pointer
+ * \return 0 on success, -1 on failure.
+ */
+
+int f_print_stream(TOPLEVEL *w_current, FILE *fp)
+{
int origin_x, origin_y, bottom, right;
int margin_x, margin_y;
int dx,dy;
@@ -379,16 +408,6 @@ int f_print(TOPLEVEL *w_current, const c
w_current->page_current->object_head,
0, unicode_table);
-
- /* dots are breaking my filename selection hack hack !!!! */
- fp = fopen(filename, "w");
-
- /* check to see if it worked */
- if (fp == NULL) {
- s_log_message("Could not open [%s] for printing\n", filename);
- return(-1);
- }
-
/* printf("%d %d\n", w_current->paper_width, w_current->paper_height);*/
world_get_complex_bounds(w_current,
@@ -539,7 +558,6 @@ #endif
f_print_footer(fp);
- fclose(fp);
return(0);
}
diff --git a/geda/gaf/libgeda/src/s_toplevel.c b/geda/gaf/libgeda/src/s_toplevel.c
index d660cd1..1aec2ca 100644
--- a/geda/gaf/libgeda/src/s_toplevel.c
+++ b/geda/gaf/libgeda/src/s_toplevel.c
@@ -213,10 +213,6 @@ TOPLEVEL *s_toplevel_new (void)
/* toplevel->fileselect */
- toplevel->pwindow = NULL;
- toplevel->plib_list = NULL;
- toplevel->pfilename_entry = NULL;
-
toplevel->iwindow = NULL;
toplevel->ifilename_entry = NULL;
PGP signature
_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev