]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.h
Doxygen fixes.
[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
12 #ifndef DIALOG_H
13 #define DIALOG_H
14
15
16 #include "Kernel.h"
17 #include "LString.h"
18 #include <boost/utility.hpp>
19 #include <boost/scoped_ptr.hpp>
20
21
22 class LyXView;
23 class ButtonController;
24
25
26 /** \c Dialog collects the different parts of a Model-Controller-View
27  *  split of a generic dialog together.
28  */
29 class Dialog : boost::noncopyable {
30 public:
31         /// \param lv is the access point for the dialog to the LyX kernel.
32         /// \param name is the identifier given to the dialog by its parent
33         /// container.
34         Dialog(LyXView & lv, string const & name);
35         ~Dialog();
36
37         /** The Dialog's name is the means by which a dialog identifies
38          *  itself to the kernel.
39          */
40         string const & name() const { return name_; }
41
42         /** \name Buttons
43          *  These methods are publicly accessible because they are invoked
44          *  by the View when the user presses... guess what ;-)
45          */
46         //@{
47         void ApplyButton();
48         void OKButton();
49         void CancelButton();
50         void RestoreButton();
51         //@}
52
53         /** \name Container Access
54          *  These methods are publicly accessible because they are invoked
55          *  by the parent container acting on commands from the LyX kernel.
56          */
57         //@{
58         /// \param data is a string encoding of the data to be displayed.
59         /// It is passed to the Controller to be translated into a useable form.
60         void show(string const & data);
61         void update(string const & data);
62
63         void hide();
64         bool isVisible() const;
65
66         /** This function is called, for example, if the GUI colours
67          *  have been changed.
68          */
69         void redraw();
70         //@}
71
72         /** When applying, it's useful to know whether the dialog is about
73          *  to close or not (no point refreshing the display for example).
74          */
75         bool isClosing() const { return is_closing_; }
76
77         /** The LyX kernel is made available through this wrapper class.
78          *  In an ideal world, it will shrink as more info is passed to the
79          *  show() and update() methods.
80          */
81         Kernel & kernel() { return kernel_; }
82
83         /** Different dialogs will have different Controllers and Views.
84          *  deriving from these base classes.
85          */
86         //@{
87         class Controller;
88         class View;
89         //@}
90
91         /** \name Dialog Specialization
92          *  Methods to set the Controller and View and so specialise
93          *  to a particular dialog.
94          */
95         //@{
96         /// \param ptr is stored and destroyed by \c Dialog.
97         void setController(Controller * ptr);
98         /// \param ptr is stored and destroyed by \c Dialog.
99         void setView(View * ptr);
100         //@}
101
102         /** \name Dialog Components
103          *  Methods to access the various components making up a dialog.
104          */
105         //@{
106         Controller & controller() const;
107         ButtonController & bc() const;
108         View & view() const;
109         //@}
110
111 private:
112         void apply();
113
114         bool is_closing_;
115         Kernel kernel_;
116         string name_;
117         boost::scoped_ptr<ButtonController> bc_ptr_;
118         boost::scoped_ptr<Controller> controller_ptr_;
119         boost::scoped_ptr<View> view_ptr_;
120 };
121
122
123 /** \c Dialog::Controller is an abstract base class for the Controller
124  *  of a Model-Controller-View split of a generic dialog.
125  */
126 class Dialog::Controller : boost::noncopyable {
127 public:
128         /// \param parent Dialog owning this Controller.
129         Controller(Dialog & parent);
130         virtual ~Controller() {}
131
132         /** \name Generic Controller
133          *  These few methods are all that a generic dialog needs of a
134          *  controller.
135          */
136         //@{
137         /** Enable the controller to initialise its data structures.
138          *  \param data is a string encoding of the parameters to be displayed.
139          *  \return true if the translation was successful.
140          */
141         virtual bool initialiseParams(string const & data) = 0;
142
143         /// Enable the controller to clean up its data structures.
144         virtual void clearParams() = 0;
145
146         /// Enable the Controller to dispatch its data back to the LyX kernel.
147         virtual void dispatchParams() = 0;
148
149         /** \return true if the dialog should be shown only when
150          *  a buffer is open.
151          */
152         virtual bool isBufferDependent() const = 0;
153
154         /** \return true if the kernel should disconnect the dialog from
155          *  a particular inset after the data has been applied to it.
156          *  Clearly this makes sense only for dialogs modifying the contents
157          *  of an inset :-)
158          *  In practise, only a very few dialogs (e.g. the citation dialog)
159          *  return true.
160          */
161         virtual bool disconnectOnApply() const { return false; }
162         //@}
163
164 protected:
165         /** \name Controller Access
166          *  Enable the derived classes to access the other parts of the whole.
167          */
168         //@{
169         Dialog & dialog() { return parent_; }
170         Dialog const & dialog() const { return parent_; }
171
172         Kernel & kernel() { return parent_.kernel(); }
173         Kernel const & kernel() const { return parent_.kernel(); }
174         //@}
175
176 private:
177         Dialog & parent_;
178 };
179
180
181 /** \c Dialog::View is an abstract base class to the View
182  *  of a Model-Controller-View split of a generic dialog.
183  */
184 class Dialog::View : boost::noncopyable {
185 public:
186         /** \param parent Dialog owning this Controller.
187          *  \param title  is the dialog title displayed by the WM.
188          */
189         View(Dialog & parent, string title);
190         virtual ~View() {}
191
192         /** \name Generic View
193          *  These few methods are all that a generic dialog needs of a
194          *  view.
195          */
196         //@{
197         /** A request to modify the data structures stored by the
198          *  accompanying Controller in preparation for their dispatch to
199          *  the LyX kernel.
200          */
201         virtual void apply() = 0;
202
203         /// Hide the dialog from sight
204         virtual void hide() = 0;
205
206         /// Redraw the dialog (e.g. if the colors have been remapped).
207         virtual void redraw() {}
208
209         /// Create the dialog if necessary, update it and display it.
210         virtual void show() = 0;
211
212         /// Update the display of the dialog whilst it is still visible.
213         virtual void update() = 0;
214
215         /// \return true if the dialog is visible.
216         virtual bool isVisible() const = 0;
217         //@}
218
219         /** Defaults to nothing. Can be used by the Controller, however, to
220          *  indicate to the View that something has changed and that the
221          *  dialog therefore needs updating.
222          *  \param id identifies what should be updated.
223          */
224         virtual void partialUpdate(int id);
225
226         /// sets the title of the dialog (window caption)
227         void setTitle(string const &);
228         /// gets the title of the dialog (window caption)
229         string const & getTitle() const;
230
231         /** \name View Access
232          *  Enable the derived classes to access the other parts of the whole.
233          */
234         //@{
235         Dialog & dialog() { return p_; }
236         Dialog const & dialog() const { return p_; }
237
238 protected:
239         Kernel & kernel() { return p_.kernel(); }
240         Kernel const & kernel() const { return p_.kernel(); }
241
242         Controller & getController() { return p_.controller(); }
243         Controller const & getController() const { return p_.controller(); }
244
245         ButtonController & bc() { return p_.bc(); }
246         ButtonController const & bc() const { return p_.bc(); }
247         //@}
248
249 private:
250         Dialog & p_;
251         string title_;
252 };
253
254
255 #endif // DIALOG_H