]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
Once again the user can use the Font button on the toolbar to get the current
[lyx.git] / src / frontends / controllers / ControlPrint.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 2001 The LyX Team.
7  *
8  *======================================================
9  *
10  * \file ControlPrint.C
11  * \author Angus Leeming, a.leeming@.ac.uk
12  */
13
14 #include <config.h>
15 #include <utility>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "ControlPrint.h"
24 #include "buffer.h"
25 #include "Dialogs.h"
26 #include "LyXView.h"
27 #include "lyxrc.h"
28 #include "PrinterParams.h"
29 #include "Liason.h"
30 #include "helper_funcs.h" // browseFile
31 #include "lyx_gui_misc.h" // WriteAlert
32 #include "gettext.h"
33
34 using Liason::printBuffer;
35 using Liason::getPrinterParams;
36 using std::make_pair;
37
38 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
39     : ControlDialog<ControlConnectBD>(lv, d),
40       params_(0)
41 {
42         d_.showPrint.connect(SigC::slot(this, &ControlPrint::show));
43 }
44
45
46 void ControlPrint::apply()
47 {
48         if (!lv_.view()->available())
49                 return;
50    
51         view().apply();
52
53         if (!printBuffer(lv_.buffer(), params())) {
54                 WriteAlert(_("Error:"),
55                            _("Unable to print"),
56                            _("Check that your parameters are correct"));
57         }
58 }
59
60
61 PrinterParams & ControlPrint::params() const
62 {
63         lyx::Assert(params_);
64         return *params_;
65 }
66
67
68 void ControlPrint::setParams()
69 {
70         if (params_) delete params_;
71         params_ = new PrinterParams(getPrinterParams(lv_.buffer()));
72
73         bc().valid(); // so that the user can press Ok
74 }
75
76
77 void ControlPrint::clearParams()
78 {
79         if (params_) {
80                 delete params_;
81                 params_ = 0;
82         }
83 }
84
85
86 string const ControlPrint::Browse(string const & in_name)
87 {
88         string const title = N_("Print to file");
89         string const pattern = "*.ps";
90
91         // Show the file browser dialog
92         return browseFile(&lv_, in_name, title, pattern,
93                            make_pair(string(), string()),
94                            make_pair(string(), string()));
95 }