]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
Switch from SigC signals to boost::signals
[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 "frontends/LyXView.h"
27 #include "PrinterParams.h"
28 #include "Liason.h"
29 #include "helper_funcs.h"
30 #include "frontends/Alert.h"
31 #include "gettext.h"
32 #include "BufferView.h"
33 #include "support/LAssert.h"
34
35 #include <boost/bind.hpp>
36
37 using Liason::printBuffer;
38 using Liason::getPrinterParams;
39 using std::make_pair;
40
41 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
42         : ControlDialogBD(lv, d),
43           params_(0)
44 {
45         d_.showPrint = boost::bind(&ControlPrint::show, this);
46 }
47
48
49 void ControlPrint::apply()
50 {
51         if (!lv_.view()->available())
52                 return;
53
54         view().apply();
55
56         if (!printBuffer(lv_.buffer(), params())) {
57                 Alert::alert(_("Error:"),
58                            _("Unable to print"),
59                            _("Check that your parameters are correct"));
60         }
61 }
62
63
64 PrinterParams & ControlPrint::params() const
65 {
66         lyx::Assert(params_);
67         return *params_;
68 }
69
70
71 void ControlPrint::setParams()
72 {
73         if (params_) delete params_;
74         params_ = new PrinterParams(getPrinterParams(lv_.buffer()));
75
76         bc().valid(); // so that the user can press Ok
77 }
78
79
80 void ControlPrint::clearParams()
81 {
82         if (params_) {
83                 delete params_;
84                 params_ = 0;
85         }
86 }
87
88
89 string const ControlPrint::Browse(string const & in_name)
90 {
91         string const title = _("Print to file");
92         string const pattern = "*.ps";
93
94         // Show the file browser dialog
95         return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
96                              title, pattern);
97 }