2 * FormPrint Interface Class Implementation
4 * ======================================================
6 * LyX, The Document Processor
8 * Copyright 2000 The LyX Team.
10 * ======================================================
17 #pragma implementation
20 #include "FormPrint.h"
24 #include "PrinterParams.h"
27 #include "BufferView.h"
28 #include "lyx_gui_misc.h"
32 #include "diaprint_interface.h"
36 #include <gtk--/base.h>
37 #include <gtk--/button.h>
39 using Liason::printBuffer;
40 using Liason::getPrinterParams;
42 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
43 : dialog_(0), lv_(lv), d_(d), u_(0), h_(0)
45 // let the dialog be shown
46 // This is a permanent connection so we won't bother
47 // storing a copy because we won't be disconnecting.
48 d->showPrint.connect(SigC::slot(this,&FormPrint::show));
52 FormPrint::~FormPrint()
58 void FormPrint::show()
61 Gtk::Button * b_cancel;
64 GtkWidget * pd = create_DiaPrint();
66 dialog_ = Gtk::wrap(pd);
67 print_all_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_all") ) );
68 print_odd_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_odd") ) );
69 print_even_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "print_even") ) );
71 print_pages_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "print_pages") ) );
73 print_from_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_from") ) );
74 print_to_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "print_to") ) );
76 order_normal_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_normal") ) );
77 order_reverse_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "order_reverse") ) );
79 copies_unsorted_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "copies_unsorted") ) );
80 copies_count_ = Gtk::wrap( GTK_SPIN_BUTTON( lookup_widget(pd, "copies_count") ) );
82 printto_printer_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_printer") ) );
83 printto_file_ = Gtk::wrap( GTK_RADIO_BUTTON( lookup_widget(pd, "printto_file") ) );
85 printto_printcommand_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "printto_printcommand") ) );
86 printto_fileentry_ = Gtk::wrap( GNOME_FILE_ENTRY( lookup_widget(pd, "printto_fileentry") ) );
88 b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_print") ) );
89 b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
91 // setting up connections
92 b_ok->clicked.connect(SigC::slot(this, &FormPrint::apply));
93 b_ok->clicked.connect(dialog_->destroy.slot());
94 b_cancel->clicked.connect(dialog_->destroy.slot());
95 dialog_->destroy.connect(SigC::slot(this, &FormPrint::free));
97 u_ = d_->updateBufferDependent.connect(SigC::slot(this,
98 &FormPrint::updateSlot));
99 h_ = d_->hideBufferDependent.connect(dialog_->destroy.slot());
101 if (!dialog_->is_visible()) dialog_->show_all();
103 updateSlot(); // make sure its up-to-date
107 Gdk_Window dialog_win(dialog_->get_window());
112 void FormPrint::hide()
114 if (dialog_!=0) dialog_->destroy();
117 void FormPrint::free()
128 void FormPrint::apply()
130 if (!lv_->view()->available()) return;
132 PrinterParams::WhichPages wp(PrinterParams::ALL);
133 if (print_odd_->get_active()) wp = PrinterParams::ODD;
134 else if (print_even_->get_active()) wp = PrinterParams::EVEN;
138 if (print_pages_->get_active())
140 from = print_from_->get_text();
141 to = print_to_->get_value_as_int();
144 PrinterParams::Target t(PrinterParams::PRINTER);
145 if (printto_file_->get_active()) t = PrinterParams::FILE;
147 // we really should use the return value here I think.
148 if (!printBuffer(lv_->buffer(),
150 printto_printcommand_->get_entry()->get_text(),
151 printto_fileentry_->get_full_path(false),
153 order_reverse_->get_active(),
154 copies_unsorted_->get_active(),
155 copies_count_->get_value_as_int())))
157 WriteAlert(_("Error:"),
158 _("Unable to print"),
159 _("Check that your parameters are correct"));
164 // we can safely ignore the parameter because we can always update
165 void FormPrint::updateSlot(bool)
168 lv_->view()->available())
170 PrinterParams pp(getPrinterParams(lv_->buffer()));
172 printto_printcommand_->get_entry()->set_text( pp.printer_name.c_str() );
173 ((Gtk::Entry *)printto_fileentry_->gtk_entry())->set_text(pp.file_name.c_str());
175 if (pp.target == PrinterParams::PRINTER) printto_printer_->set_active(true);
176 else printto_file_->set_active(true);
178 if (pp.reverse_order) order_reverse_->set_active(true);
179 else order_normal_->set_active(true);
181 switch (pp.which_pages)
183 case PrinterParams::ODD:
184 print_odd_->set_active(true);
187 case PrinterParams::EVEN:
188 print_even_->set_active(true);
191 case PrinterParams::ALL:
193 print_all_->set_active(true);
197 // hmmm... maybe a bit weird but maybe not
198 // we might just be remembering the last
199 // time this was printed.
200 if (!pp.from_page.empty())
202 print_to_->set_value(pp.to_page);
203 print_from_->set_value(strToInt(pp.from_page));