]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.h
e9200e4104beba592e52cde3ed8bc62bdca25d3a
[lyx.git] / src / frontends / controllers / Dialog.h
1 // -*- C++ -*-
2 /**
3  * \file Dialog.h
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  * The dialogs use a Model-Controller-View split, instantiated here
12  * by class Dialog.
13  */
14
15 #ifndef DIALOG_H
16 #define DIALOG_H
17
18
19 #include "Kernel.h"
20 #include "LString.h"
21 #include <boost/utility.hpp>
22 #include <boost/scoped_ptr.hpp>
23
24
25 class LyXView;
26 class ButtonController;
27
28
29 class Dialog : boost::noncopyable {
30 public:
31         /** the Dialog's "name" is the means with which a dialog identifies
32          *  itself to the kernel.
33          */
34         Dialog(LyXView &, string const & name);
35         ///
36         ~Dialog();
37
38         ///
39         string const & name() const { return name_; }
40
41         /** These methods are publicly accessible because they are invoked
42             by the View.
43         */
44         //@{
45         ///
46         void ApplyButton();
47         ///
48         void OKButton();
49         ///
50         void CancelButton();
51         ///
52         void RestoreButton();
53         //@}
54
55         /** These methods are publicly accessible because they are invoked
56          *  by the Dialogs class.
57          */
58         //@{
59         /** Some dialogs, eg the Tabular or Preferences dialog, can extract
60             the information they require from the kernel. These dialogs will
61             probably be passed an empty string by the calling Dialogs class.
62             The inset dialogs, however, require information specific to
63             an individual inset. This information will be encoded in "data"
64             and must be translated into a set of parameters that can be
65             updated from the dialog.
66          */
67         void show(string const & data = string());
68         ///
69         void update(string const & data = string());
70         ///
71         void hide();
72         ///
73         bool isVisible() const;
74         /// (Eg, the GUI colours have been changed.)
75         void redraw();
76         //@}
77
78         /** When Applying it's useful to know whether the dialog is about
79          *  to close or not (no point refreshing the display for example).
80          */
81         bool isClosing() const { return is_closing_; }
82
83         /// The LyX kernel is made available through this.
84         Kernel & kernel() { return kernel_; }
85
86         /** Different dialogs will have different
87             Controllers, Views and ButtonControllers.
88         */
89         //@{
90         ///
91         class Controller;
92         ///
93         class View;
94
95         ///
96         void setController(Controller *);
97         ///
98         void setView(View *);
99
100         ///
101         Controller & controller() const;
102         ///
103         ButtonController & bc() const;
104         ///
105         View & view() const;
106         //@}
107
108 private:
109         ///
110         void apply();
111
112         ///
113         bool is_closing_;
114         ///
115         Kernel kernel_;
116         ///
117         string name_;
118         ///
119         boost::scoped_ptr<ButtonController> bc_ptr_;
120         ///
121         boost::scoped_ptr<Controller> controller_ptr_;
122         ///
123         boost::scoped_ptr<View> view_ptr_;
124 };
125
126
127 class Dialog::Controller : boost::noncopyable {
128 public:
129         ///
130         Controller(Dialog & parent) : parent_(parent) {}
131         ///
132         virtual ~Controller() {}
133         ///
134         virtual void initialiseParams(string const & data) = 0;
135         ///
136         virtual void clearParams() = 0;
137         ///
138         virtual void dispatchParams() = 0;
139         ///
140         virtual bool isBufferDependent() const = 0;
141         ///
142         virtual bool disconnectOnApply() const { return false; }
143         ///
144         Dialog & dialog() { return parent_; }
145         ///
146         Dialog const & dialog() const { return parent_; }
147         ///
148         Kernel & kernel() { return parent_.kernel(); }
149         ///
150         Kernel const & kernel() const { return parent_.kernel(); }
151
152 private:
153         ///
154         Dialog & parent_;
155 };
156
157
158 class Dialog::View : boost::noncopyable {
159 public:
160         ///
161         View(Dialog & parent) : p_(parent) {}
162         ///
163         virtual ~View() {}
164
165         /// Apply changes to LyX data from dialog.
166         virtual void apply() = 0;
167         /// Hide the dialog.
168         virtual void hide() = 0;
169         /// Redraw the dialog (e.g. if the colors have been remapped).
170         virtual void redraw() {}
171         /// Create the dialog if necessary, update it and display it.
172         virtual void show() = 0;
173         /// Update dialog before/whilst showing it.
174         virtual void update() = 0;
175         ///
176         virtual bool isVisible() const = 0;
177
178         /** Defaults to nothing. Can be used by the controller, however, to
179          *  indicate to the view that something has changed and that the
180          *  dialog therefore needs updating.
181          */
182         virtual void partialUpdate(int) {}
183
184         ///
185         Dialog & dialog() { return p_; }
186         ///
187         Dialog const & dialog() const { return p_; }
188
189         ///
190         Kernel & kernel() { return p_.kernel(); }
191         ///
192         Kernel const & kernel() const { return p_.kernel(); }
193
194         ///
195         Controller & getController() { return p_.controller(); }
196         ///
197         Controller const & getController() const { return p_.controller(); }
198
199         ///
200         ButtonController & bc() { return p_.bc(); }
201         ///
202         ButtonController const & bc() const { return p_.bc(); }
203
204 protected:
205         ///
206         Dialog & p_;
207 };
208
209
210 #endif // DIALOG_H