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