]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
Create a grfx::Loader class and so move large chunks of code out of
[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
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlPrint.h"
21 #include "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "buffer.h"
24 #include "frontends/LyXView.h"
25 #include "PrinterParams.h"
26 #include "Liason.h"
27 #include "helper_funcs.h"
28 #include "frontends/Alert.h"
29 #include "gettext.h"
30 #include "BufferView.h"
31 #include "support/LAssert.h"
32
33 using Liason::printBuffer;
34 using Liason::getPrinterParams;
35
36
37 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
38         : ControlDialogBD(lv, d),
39           params_(0)
40 {}
41
42
43 void ControlPrint::apply()
44 {
45         if (!lv_.view()->available())
46                 return;
47
48         view().apply();
49
50         if (!printBuffer(lv_.buffer(), params())) {
51                 Alert::alert(_("Error:"),
52                            _("Unable to print"),
53                            _("Check that your parameters are correct"));
54         }
55 }
56
57
58 PrinterParams & ControlPrint::params() const
59 {
60         lyx::Assert(params_);
61         return *params_;
62 }
63
64
65 void ControlPrint::setParams()
66 {
67         if (params_) delete params_;
68         params_ = new PrinterParams(getPrinterParams(lv_.buffer()));
69
70         bc().valid(); // so that the user can press Ok
71 }
72
73
74 void ControlPrint::clearParams()
75 {
76         if (params_) {
77                 delete params_;
78                 params_ = 0;
79         }
80 }
81
82
83 string const ControlPrint::Browse(string const & in_name)
84 {
85         string const title = _("Print to file");
86         string const pattern = "*.ps";
87
88         // Show the file browser dialog
89         return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
90                              title, pattern);
91 }