]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.h
Hold on to your hats.
[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 ButtonControllerBase;
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         ///
37         string const & name() const { return name_; }
38
39         /** These methods are publicly accessible because they are invoked
40             by the View.
41         */
42         //@{
43         ///
44         void ApplyButton();
45         ///
46         void OKButton();
47         ///
48         void CancelButton();
49         ///
50         void RestoreButton();
51         //@}
52
53         /** These methods are publicly accessible because they are invoked
54          *  by the Dialogs class.
55          */
56         //@{
57         /** Some dialogs, eg the Tabular or Preferences dialog, can extract
58             the information they require from the kernel. These dialogs will
59             probably be passed an empty string by the calling Dialogs class.
60             The inset dialogs, however, require information specific to
61             an individual inset. This information will be encoded in "data"
62             and must be translated into a set of parameters that can be
63             updated from the dialog.
64          */
65         void show(string const & data = string());
66         ///
67         void update(string const & data = string());
68         ///
69         void hide();
70         ///
71         bool isVisible() const;
72         /// (Eg, the GUI colours have been changed.)
73         void redraw();
74         //@}
75
76         /** When Applying it's useful to know whether the dialog is about
77          *  to close or not (no point refreshing the display for example).
78          */
79         bool isClosing() const { return is_closing_; }
80
81         /// The LyX kernel is made available through this.
82         Kernel & kernel() { return kernel_; }
83
84         /** Different dialogs will have different
85             Controllers, Views and ButtonControllers.
86         */
87         //@{
88         ///
89         class Controller;
90         ///
91         class View;
92
93         ///
94         void setController(Controller *);
95         ///
96         void setView(View *);
97         ///
98         void setButtonController(ButtonControllerBase *);
99
100         ///
101         Controller & controller() const;
102         ///
103         ButtonControllerBase & bc() const;
104 private:
105         ///
106         View & view() const;
107         //@}
108
109         ///
110         void apply();
111
112         ///
113         bool is_closing_;
114         ///
115         Kernel kernel_;
116         ///
117         string name_;
118         ///
119         boost::scoped_ptr<ButtonControllerBase> 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         Kernel & kernel() { return parent_.kernel(); }
145         ///
146         Kernel const & kernel() const { return parent_.kernel(); }
147
148 private:
149         ///
150         Dialog & parent_;
151 };
152
153
154 class Dialog::View : boost::noncopyable {
155 public:
156         ///
157         View(Dialog & parent) : p_(parent) {}
158         ///
159         virtual ~View() {}
160
161         /// Apply changes to LyX data from dialog.
162         virtual void apply() = 0;
163         /// Hide the dialog.
164         virtual void hide() = 0;
165         /// Redraw the dialog (e.g. if the colors have been remapped).
166         virtual void redraw() {}
167         /// Create the dialog if necessary, update it and display it.
168         virtual void show() = 0;
169         /// Update dialog before/whilst showing it.
170         virtual void update() = 0;
171         ///
172         virtual bool isVisible() const = 0;
173
174         /** Defaults to nothing. Can be used by the controller, however, to
175          *  indicate to the view that something has changed and that the
176          *  dialog therefore needs updating.
177          */
178         virtual void partialUpdate(int) {}
179
180         ///
181         Dialog & dialog() { return p_; }
182         ///
183         Dialog const & dialog() const { return p_; }
184
185         ///
186         Kernel & kernel() { return p_.kernel(); }
187         ///
188         Kernel const & kernel() const { return p_.kernel(); }
189
190         ///
191         Controller & getController() { return p_.controller(); }
192         ///
193         Controller const & getController() const { return p_.controller(); }
194
195 protected:
196         ///
197         Dialog & p_;
198 };
199
200
201 #endif // DIALOG_H