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