]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.C
Pragmatic pimpl-ing of BufferParams.
[lyx.git] / src / frontends / controllers / Dialog.C
1 /**
2  * \file Dialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Dialog.h"
14
15 #include "ButtonController.h"
16 #include "BCView.h"
17 #include "support/LAssert.h"
18
19 using namespace lyx::support;
20
21 Dialog::Dialog(LyXView & lv, string const & name)
22         : is_closing_(false), kernel_(lv), name_(name),
23           bc_ptr_(new ButtonController)
24 {}
25
26
27 Dialog::~Dialog()
28 {}
29
30
31 void Dialog::ApplyButton()
32 {
33         apply();
34         bc().apply();
35 }
36
37
38 void Dialog::OKButton()
39 {
40         is_closing_ = true;
41         apply();
42         is_closing_ = false;
43         hide();
44         bc().ok();
45 }
46
47
48 void Dialog::CancelButton()
49 {
50         hide();
51         bc().cancel();
52 }
53
54
55 void Dialog::RestoreButton()
56 {
57         // Tell the kernel that a request to refresh the dialog's contents
58         // has been received. It's up to the kernel to supply the necessary
59         // info by calling Dialog::update().
60         kernel().updateDialog(name_);
61         bc().restore();
62 }
63
64
65 void Dialog::show(string const & data)
66 {
67         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
68                 return;
69
70         if (!controller().initialiseParams(data)) {
71                 lyxerr << "Dialog \"" << name_
72                        << "\" failed to translate the data "
73                         "string passed to show()" << std::endl;
74                 return;
75         }
76
77         bc().readOnly(kernel().isBufferReadonly());
78         view().show();
79
80         // The widgets may not be valid, so refresh the button controller
81         bc().refresh();
82 }
83
84
85 void Dialog::update(string const & data)
86 {
87         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
88                 return;
89
90         if (!controller().initialiseParams(data)) {
91                 lyxerr << "Dialog \"" << name_
92                        << "\" failed to translate the data "
93                         "string passed to update()" << std::endl;
94                 return;
95         }
96
97         bc().readOnly(kernel().isBufferReadonly());
98         view().update();
99
100         // The widgets may not be valid, so refresh the button controller
101         bc().refresh();
102 }
103
104
105 void Dialog::hide()
106 {
107         if (!view().isVisible())
108                 return;
109
110         controller().clearParams();
111         view().hide();
112 }
113
114
115 void Dialog::apply()
116 {
117         if (kernel().isBufferReadonly())
118                 return;
119
120         view().apply();
121         controller().dispatchParams();
122
123         if (controller().disconnectOnApply() && !is_closing_) {
124                 kernel().disconnect(name());
125                 controller().initialiseParams(string());
126                 view().update();
127         }
128 }
129
130
131 bool Dialog::isVisible() const
132 {
133         return view().isVisible();
134 }
135
136
137 void Dialog::redraw()
138 {
139         view().redraw();
140 }
141
142
143 ButtonController & Dialog::bc() const
144 {
145         Assert(bc_ptr_.get());
146         return *bc_ptr_.get();
147 }
148
149
150 void Dialog::setController(Controller * i)
151 {
152         Assert(i && !controller_ptr_.get());
153         controller_ptr_.reset(i);
154 }
155
156
157 void Dialog::setView(View * v)
158 {
159         Assert(v && !view_ptr_.get());
160         view_ptr_.reset(v);
161 }
162
163
164 Dialog::Controller::Controller(Dialog & parent)
165         : parent_(parent)
166 {}
167
168
169 Dialog::Controller & Dialog::controller() const
170 {
171         Assert(controller_ptr_.get());
172         return *controller_ptr_.get();
173 }
174
175
176 Dialog::View::View(Dialog & parent, string title) :
177         p_(parent), title_(title)
178 {}
179
180
181 Dialog::View & Dialog::view() const
182 {
183         Assert(view_ptr_.get());
184         return *view_ptr_.get();
185 }
186
187
188 void Dialog::View::setTitle(string const & newtitle)
189 {
190         title_ = newtitle;
191 }
192
193
194 string const & Dialog::View::getTitle() const
195 {
196         return title_;
197 }
198
199
200 void Dialog::View::partialUpdate(int)
201 {}