]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormPrint.C
remove CXX_WORKING_NAMESPACES
[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 using Liason::printBuffer;
41 using Liason::getPrinterParams;
42
43 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
44   : dialog_(0), lv_(lv), d_(d), u_(0), h_(0)
45 {
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));
50 }
51
52
53 FormPrint::~FormPrint()
54 {
55   hide();
56 }
57
58
59 void FormPrint::show()
60 {
61   Gtk::Button * b_ok;
62   Gtk::Button * b_cancel;
63   if (!dialog_)
64     {
65       GtkWidget * pd = create_DiaPrint();
66
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") ) );
71
72       print_pages_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "print_pages") ) );
73
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") ) );
76
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") ) );
79
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") ) );
82
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") ) );
85
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") ) );
88
89       b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_print") ) );
90       b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
91
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));
97
98       u_ = d_->updateBufferDependent.connect(SigC::slot(this,
99                                                   &FormPrint::updateSlot));
100       h_ = d_->hideBufferDependent.connect(dialog_->destroy.slot());
101
102       if (!dialog_->is_visible()) dialog_->show_all();
103
104       updateSlot();  // make sure its up-to-date
105     }
106   else
107     {
108       Gdk_Window dialog_win(dialog_->get_window());
109       dialog_win.raise();
110     }
111 }
112
113 void FormPrint::hide()
114 {
115   if (dialog_!=0) dialog_->destroy();
116 }
117
118 void FormPrint::free()
119 {
120   if (dialog_!=0)
121     {
122       dialog_ = 0;
123       u_.disconnect();
124       h_.disconnect();
125     }
126 }
127
128
129 void FormPrint::apply()
130 {
131   if (!lv_->view()->available()) return;
132
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;
136
137   string from;
138   int to(0);
139   if (print_pages_->get_active())
140     {
141       from = print_from_->get_text();
142       to = print_to_->get_value_as_int();
143     }
144   
145   PrinterParams::Target t(PrinterParams::PRINTER);
146   if (printto_file_->get_active()) t = PrinterParams::FILE;
147   
148   // we really should use the return value here I think.
149   if (!printBuffer(lv_->buffer(),
150                    PrinterParams(t,
151                                  printto_printcommand_->get_entry()->get_text(),
152                                  printto_fileentry_->get_full_path(false),
153                                  wp, from, to,
154                                  order_reverse_->get_active(),
155                                  copies_unsorted_->get_active(),
156                                  copies_count_->get_value_as_int())))
157     {
158       WriteAlert(_("Error:"),
159                  _("Unable to print"),
160                  _("Check that your parameters are correct"));
161     }
162 }
163
164
165 // we can safely ignore the parameter because we can always update
166 void FormPrint::updateSlot(bool)
167 {
168   if (dialog_ != 0 &&
169       lv_->view()->available())
170     {
171       PrinterParams pp(getPrinterParams(lv_->buffer()));
172
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());
175
176       if (pp.target == PrinterParams::PRINTER) printto_printer_->set_active(true);
177       else printto_file_->set_active(true);
178
179       if (pp.reverse_order) order_reverse_->set_active(true);
180       else order_normal_->set_active(true);
181
182       switch (pp.which_pages)
183         {
184         case PrinterParams::ODD:
185           print_odd_->set_active(true);
186           break;
187           
188         case PrinterParams::EVEN:
189           print_even_->set_active(true);
190           break;
191           
192         case PrinterParams::ALL:
193         default:
194           print_all_->set_active(true);
195           break;
196         }
197       
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())
202         {
203           print_to_->set_value(pp.to_page);
204           print_from_->set_value(strToInt(pp.from_page));
205         }
206     }
207 }