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 using Liason::printBuffer;
41 using Liason::getPrinterParams;
43 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
44 : dialog_(0), lv_(lv), d_(d), u_(0), h_(0)
46 // let the dialog be shown
47 // This is a permanent connection so we won't bother
48 // storing a copy because we won't be disconnecting.
49 d->showPrint.connect(SigC::slot(this,&FormPrint::show));
53 FormPrint::~FormPrint()
59 void FormPrint::show()
62 Gtk::Button * b_cancel;
65 GtkWidget * pd = create_DiaPrint();
67 dialog_ = Gtk::wrap(pd);
68 print_all_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_all") ) );
69 print_odd_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_odd") ) );
70 print_even_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_even") ) );
72 print_pages_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "print_pages") ) );
74 print_from_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_from") ) );
75 print_to_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_to") ) );
77 order_normal_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_normal") ) );
78 order_reverse_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_reverse") ) );
80 copies_unsorted_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "copies_unsorted") ) );
81 copies_count_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "copies_count") ) );
83 printto_printer_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_printer") ) );
84 printto_file_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_file") ) );
86 printto_printcommand_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "printto_printcommand") ) );
87 printto_fileentry_ = Gtk::wrap( GNOME_FILE_ENTRY( lookup_widget(pd, "printto_fileentry") ) );
89 b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_print") ) );
90 b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
92 // setting up connections
93 b_ok->clicked.connect(SigC::slot(this, &FormPrint::apply));
94 b_ok->clicked.connect(dialog_->destroy.slot());
95 b_cancel->clicked.connect(dialog_->destroy.slot());
96 dialog_->destroy.connect(SigC::slot(this, &FormPrint::free));
98 u_ = d_->updateBufferDependent.connect(SigC::slot(this,
99 &FormPrint::updateSlot));
100 h_ = d_->hideBufferDependent.connect(dialog_->destroy.slot());
102 if (!dialog_->is_visible()) dialog_->show_all();
104 updateSlot(); // make sure its up-to-date
108 Gdk_Window dialog_win(dialog_->get_window());
113 void FormPrint::hide()
115 if (dialog_!=0) dialog_->destroy();
118 void FormPrint::free()
129 void FormPrint::apply()
131 if (!lv_->view()->available()) return;
133 PrinterParams::WhichPages wp(PrinterParams::ALL);
134 if (print_odd_->get_active()) wp = PrinterParams::ODD;
135 else if (print_even_->get_active()) wp = PrinterParams::EVEN;
139 if (print_pages_->get_active())
141 from = print_from_->get_text();
142 to = print_to_->get_value_as_int();
145 PrinterParams::Target t(PrinterParams::PRINTER);
146 if (printto_file_->get_active()) t = PrinterParams::FILE;
148 // we really should use the return value here I think.
149 if (!printBuffer(lv_->buffer(),
151 printto_printcommand_->get_entry()->get_text(),
152 printto_fileentry_->get_full_path(false),
154 order_reverse_->get_active(),
155 copies_unsorted_->get_active(),
156 copies_count_->get_value_as_int())))
158 WriteAlert(_("Error:"),
159 _("Unable to print"),
160 _("Check that your parameters are correct"));
165 // we can safely ignore the parameter because we can always update
166 void FormPrint::updateSlot(bool)
169 lv_->view()->available())
171 PrinterParams pp(getPrinterParams(lv_->buffer()));
173 printto_printcommand_->get_entry()->set_text( pp.printer_name.c_str() );
174 ((Gtk::Entry *)printto_fileentry_->gtk_entry())->set_text(pp.file_name.c_str());
176 if (pp.target == PrinterParams::PRINTER) printto_printer_->set_active(true);
177 else printto_file_->set_active(true);
179 if (pp.reverse_order) order_reverse_->set_active(true);
180 else order_normal_->set_active(true);
182 switch (pp.which_pages)
184 case PrinterParams::ODD:
185 print_odd_->set_active(true);
188 case PrinterParams::EVEN:
189 print_even_->set_active(true);
192 case PrinterParams::ALL:
194 print_all_->set_active(true);
198 // hmmm... maybe a bit weird but maybe not
199 // we might just be remembering the last
200 // time this was printed.
201 if (!pp.from_page.empty())
203 print_to_->set_value(pp.to_page);
204 print_from_->set_value(strToInt(pp.from_page));