]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
Keep LAssert.h in ControlInset.h; revert previous change.
[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 {
41         d_.showPrint.connect(SigC::slot(this, &ControlPrint::show));
42 }
43
44
45 void ControlPrint::apply()
46 {
47         if (!lv_.view()->available())
48                 return;
49    
50         view().apply();
51
52         if (!printBuffer(lv_.buffer(), params())) {
53                 WriteAlert(_("Error:"),
54                            _("Unable to print"),
55                            _("Check that your parameters are correct"));
56         }
57 }
58
59
60 PrinterParams & ControlPrint::params() const
61 {
62         lyx::Assert(params_);
63         return *params_;
64 }
65
66
67 void ControlPrint::setParams()
68 {
69         if (params_) delete params_;
70         params_ = new PrinterParams(getPrinterParams(lv_.buffer()));
71
72         bc().valid(); // so that the user can press Ok
73 }
74
75
76 void ControlPrint::clearParams()
77 {
78         if (params_) {
79                 delete params_;
80                 params_ = 0;
81         }
82 }
83
84
85 string const ControlPrint::Browse(string const & in_name)
86 {
87         string const title = N_("Print to file");
88         string const pattern = "*.ps";
89
90         // Show the file browser dialog
91         return browseFile(&lv_, in_name, title, pattern,
92                            make_pair(string(), string()),
93                            make_pair(string(), string()));
94 }