]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormPrint.C
Dekel's lyxrc.example; Angus's FormDocument; John's build-listerrors; POTFILES.in...
[lyx.git] / src / frontends / gnome / FormPrint.C
1 // -*- C++ -*-
2 /* FormPrint.C
3  * FormPrint Interface Class Implementation
4  * This file is part of
5  * ====================================================== 
6  *
7  *           LyX, The Document Processor
8  *
9  *           Copyright 2000 The LyX Team.
10  *
11  * ======================================================
12  */
13
14
15 #include <config.h>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FormPrint.h"
22 #include "LyXView.h"
23 #include "Dialogs.h"
24 #include "lyxrc.h"
25 #include "PrinterParams.h"
26 #include "Liason.h"
27 #include "debug.h"
28 #include "BufferView.h"
29 #include "lyx_gui_misc.h"
30 #include "gettext.h"
31
32 extern "C" {
33 #include "diaprint_interface.h"
34 #include "support.h"
35 }
36
37 #include <gtk--/base.h>
38 #include <gtk--/button.h>
39
40 #ifdef SIGC_CXX_NAMESPACES
41 using SigC::slot;
42 using SigC::bind;
43 #endif
44
45 #ifdef CXX_WORKING_NAMESPACES
46 using Liason::printBuffer;
47 using Liason::getPrinterParams;
48 #endif
49
50 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
51   : dialog_(NULL), lv_(lv), d_(d), u_(0), h_(0)
52 {
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));
57 }
58
59
60 FormPrint::~FormPrint()
61 {
62   hide();
63 }
64
65
66 void FormPrint::show()
67 {
68   Gtk::Button * b_ok;
69   Gtk::Button * b_cancel;
70   if (!dialog_)
71     {
72       GtkWidget * pd = create_DiaPrint();
73
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") ) );
78
79       print_pages_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "print_pages") ) );
80
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") ) );
83
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") ) );
86
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") ) );
89
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") ) );
92
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") ) );
95
96       b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_print") ) );
97       b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
98
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));
104
105       u_ = d_->updateBufferDependent.connect(slot(this,
106                                                   &FormPrint::update));
107       h_ = d_->hideBufferDependent.connect(dialog_->destroy.slot());
108
109       if (!dialog_->is_visible()) dialog_->show_all();
110
111       update();  // make sure its up-to-date
112     }
113   else
114     {
115       Gdk_Window dialog_win(dialog_->get_window());
116       dialog_win.raise();
117     }
118 }
119
120 void FormPrint::hide()
121 {
122   if (dialog_!=NULL) dialog_->destroy();
123 }
124
125 void FormPrint::free()
126 {
127   if (dialog_!=NULL)
128     {
129       dialog_ = NULL;
130       u_.disconnect();
131       h_.disconnect();
132     }
133 }
134
135
136 void FormPrint::apply()
137 {
138   if (!lv_->view()->available()) return;
139
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;
143
144   string from;
145   int to(0);
146   if (print_pages_->get_active())
147     {
148       from = print_from_->get_text();
149       to = print_to_->get_value_as_int();
150     }
151   
152   PrinterParams::Target t(PrinterParams::PRINTER);
153   if (printto_file_->get_active()) t = PrinterParams::FILE;
154   
155   // we really should use the return value here I think.
156   if (!printBuffer(lv_->buffer(),
157                    PrinterParams(t,
158                                  printto_printcommand_->get_entry()->get_text(),
159                                  printto_fileentry_->get_full_path(false),
160                                  wp, from, to,
161                                  order_reverse_->get_active(),
162                                  copies_unsorted_->get_active(),
163                                  copies_count_->get_value_as_int())))
164     {
165       WriteAlert(_("Error:"),
166                  _("Unable to print"),
167                  _("Check that your parameters are correct"));
168     }
169 }
170
171
172 void FormPrint::update()
173 {
174   if (dialog_ != NULL &&
175       lv_->view()->available())
176     {
177       PrinterParams pp(getPrinterParams(lv_->buffer()));
178
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());
181
182       if (pp.target == PrinterParams::PRINTER) printto_printer_->set_active(true);
183       else printto_file_->set_active(true);
184
185       if (pp.reverse_order) order_reverse_->set_active(true);
186       else order_normal_->set_active(true);
187
188       switch (pp.which_pages)
189         {
190         case PrinterParams::ODD:
191           print_odd_->set_active(true);
192           break;
193           
194         case PrinterParams::EVEN:
195           print_even_->set_active(true);
196           break;
197           
198         case PrinterParams::ALL:
199         default:
200           print_all_->set_active(true);
201           break;
202         }
203       
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())
208         {
209           print_to_->set_value(pp.to_page);
210           print_from_->set_value(strToInt(pp.from_page));
211         }
212     }
213 }