3 * FormPrint Interface Class Implementation
5 * ======================================================
7 * LyX, The Document Processor
9 * Copyright 2000 The LyX Team.
11 * ======================================================
18 #pragma implementation
21 #include "FormPrint.h"
25 #include "PrinterParams.h"
28 #include "BufferView.h"
29 #include "lyx_gui_misc.h"
33 #include "diaprint_interface.h"
37 #include <gtk--/base.h>
38 #include <gtk--/button.h>
40 #ifdef SIGC_CXX_NAMESPACES
45 #ifdef CXX_WORKING_NAMESPACES
46 using Liason::printBuffer;
47 using Liason::getPrinterParams;
50 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
51 : dialog_(NULL), lv_(lv), d_(d), u_(0), h_(0)
53 // let the dialog be shown
54 // This is a permanent connection so we won't bother
55 // storing a copy because we won't be disconnecting.
56 d->showPrint.connect(slot(this,&FormPrint::show));
60 FormPrint::~FormPrint()
66 void FormPrint::show()
69 Gtk::Button * b_cancel;
72 GtkWidget * pd = create_DiaPrint();
74 dialog_ = Gtk::wrap(pd);
75 print_all_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_all") ) );
76 print_odd_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_odd") ) );
77 print_even_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_even") ) );
79 print_pages_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "print_pages") ) );
81 print_from_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_from") ) );
82 print_to_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_to") ) );
84 order_normal_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_normal") ) );
85 order_reverse_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_reverse") ) );
87 copies_unsorted_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "copies_unsorted") ) );
88 copies_count_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "copies_count") ) );
90 printto_printer_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_printer") ) );
91 printto_file_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_file") ) );
93 printto_printcommand_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "printto_printcommand") ) );
94 printto_fileentry_ = Gtk::wrap( GNOME_FILE_ENTRY( lookup_widget(pd, "printto_fileentry") ) );
96 b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_print") ) );
97 b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
99 // setting up connections
100 b_ok->clicked.connect(slot(this, &FormPrint::apply));
101 b_ok->clicked.connect(dialog_->destroy.slot());
102 b_cancel->clicked.connect(dialog_->destroy.slot());
103 dialog_->destroy.connect(slot(this, &FormPrint::free));
105 u_ = d_->updateBufferDependent.connect(slot(this,
106 &FormPrint::update));
107 h_ = d_->hideBufferDependent.connect(dialog_->destroy.slot());
109 if (!dialog_->is_visible()) dialog_->show_all();
111 update(); // make sure its up-to-date
115 Gdk_Window dialog_win(dialog_->get_window());
120 void FormPrint::hide()
122 if (dialog_!=NULL) dialog_->destroy();
125 void FormPrint::free()
136 void FormPrint::apply()
138 if (!lv_->view()->available()) return;
140 PrinterParams::WhichPages wp(PrinterParams::ALL);
141 if (print_odd_->get_active()) wp = PrinterParams::ODD;
142 else if (print_even_->get_active()) wp = PrinterParams::EVEN;
146 if (print_pages_->get_active())
148 from = print_from_->get_text();
149 to = print_to_->get_value_as_int();
152 PrinterParams::Target t(PrinterParams::PRINTER);
153 if (printto_file_->get_active()) t = PrinterParams::FILE;
155 // we really should use the return value here I think.
156 if (!printBuffer(lv_->buffer(),
158 printto_printcommand_->get_entry()->get_text(),
159 printto_fileentry_->get_full_path(false),
161 order_reverse_->get_active(),
162 copies_unsorted_->get_active(),
163 copies_count_->get_value_as_int())))
165 WriteAlert(_("Error:"),
166 _("Unable to print"),
167 _("Check that your parameters are correct"));
172 void FormPrint::update()
174 if (dialog_ != NULL &&
175 lv_->view()->available())
177 PrinterParams pp(getPrinterParams(lv_->buffer()));
179 printto_printcommand_->get_entry()->set_text( pp.printer_name.c_str() );
180 ((Gtk::Entry *)printto_fileentry_->gtk_entry())->set_text(pp.file_name.c_str());
182 if (pp.target == PrinterParams::PRINTER) printto_printer_->set_active(true);
183 else printto_file_->set_active(true);
185 if (pp.reverse_order) order_reverse_->set_active(true);
186 else order_normal_->set_active(true);
188 switch (pp.which_pages)
190 case PrinterParams::ODD:
191 print_odd_->set_active(true);
194 case PrinterParams::EVEN:
195 print_even_->set_active(true);
198 case PrinterParams::ALL:
200 print_all_->set_active(true);
204 // hmmm... maybe a bit weird but maybe not
205 // we might just be remembering the last
206 // time this was printed.
207 if (!pp.from_page.empty())
209 print_to_->set_value(pp.to_page);
210 print_from_->set_value(strToInt(pp.from_page));