4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
18 #include "support/docstring.h"
20 #include <boost/utility.hpp>
21 #include <boost/scoped_ptr.hpp>
29 class ButtonController;
31 /** \c Dialog collects the different parts of a Model-Controller-View
32 * split of a generic dialog together.
34 class Dialog /*: boost::noncopyable*/ {
36 /// \param lv is the access point for the dialog to the LyX kernel.
37 /// \param name is the identifier given to the dialog by its parent
39 Dialog(LyXView & lv, std::string const & name);
42 /** The Dialog's name is the means by which a dialog identifies
43 * itself to the kernel.
45 std::string const & name() const { return name_; }
48 * These methods are publicly accessible because they are invoked
49 * by the View when the user presses... guess what ;-)
58 /** \name Container Access
59 * These methods are publicly accessible because they are invoked
60 * by the parent container acting on commands from the LyX kernel.
63 /// \param data is a string encoding of the data to be displayed.
64 /// It is passed to the Controller to be translated into a useable form.
65 void show(std::string const & data);
66 void update(std::string const & data);
69 bool isVisible() const;
71 /** This function is called, for example, if the GUI colours
77 /** Check wether we may apply our data.
79 * The buttons are disabled if not and (re-)enabled if yes.
83 /** When applying, it's useful to know whether the dialog is about
84 * to close or not (no point refreshing the display for example).
86 bool isClosing() const { return is_closing_; }
88 /** The LyX kernel is made available through this wrapper class.
89 * In an ideal world, it will shrink as more info is passed to the
90 * show() and update() methods.
92 Kernel & kernel() { return kernel_; }
94 /** Different dialogs will have different Controllers and Views.
95 * deriving from these base classes.
102 /** \name Dialog Specialization
103 * Methods to set the Controller and View and so specialise
104 * to a particular dialog.
107 /// \param ptr is stored and destroyed by \c Dialog.
108 void setController(Controller * ptr);
109 /// \param ptr is stored and destroyed by \c Dialog.
110 void setView(View * ptr);
113 /** \name Dialog Components
114 * Methods to access the various components making up a dialog.
117 Controller & controller() const;
118 ButtonController & bc() const;
128 boost::scoped_ptr<ButtonController> bc_ptr_;
129 boost::scoped_ptr<Controller> controller_ptr_;
130 boost::scoped_ptr<View> view_ptr_;
134 /** \c Dialog::Controller is an abstract base class for the Controller
135 * of a Model-Controller-View split of a generic dialog.
137 class Dialog::Controller : boost::noncopyable {
139 /// \param parent Dialog owning this Controller.
140 Controller(Dialog & parent);
141 virtual ~Controller() {}
143 /** \name Generic Controller
144 * These few methods are all that a generic dialog needs of a
148 /** Enable the controller to initialise its data structures.
149 * \param data is a string encoding of the parameters to be displayed.
150 * \return true if the translation was successful.
152 virtual bool initialiseParams(std::string const & data) = 0;
154 /// Enable the controller to clean up its data structures.
155 virtual void clearParams() = 0;
157 /// Enable the Controller to dispatch its data back to the LyX kernel.
158 virtual void dispatchParams() = 0;
160 /** \return true if the dialog should be shown only when
163 virtual bool isBufferDependent() const = 0;
165 /** The lfun that is sent for applying the data.
167 * This method is used by the default implementation of canApply()
168 * for buffer dependant dialogs that send one lfun when applying the
170 * It should be used in dispatchParams(), too for consistency reasons.
171 * \returns the lfun that is sent for applying the data.
173 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
175 /** Check whether we may apply our data.
177 * The default implementation works for all dialogs that send one
178 * lfun when applying the data. Dialogs that send none or more than
179 * one lfun need to reimplement it.
180 * \returns whether the data can be applied or not.
182 virtual bool canApply() const;
184 /** \return true if the kernel should disconnect the dialog from
185 * a particular inset after the data has been applied to it.
186 * Clearly this makes sense only for dialogs modifying the contents
188 * In practise, only a very few dialogs (e.g. the citation dialog)
191 virtual bool disconnectOnApply() const { return false; }
193 /** \return true if Dialog::View::show() should not display the dialog
194 * after running update. Currently, only ControlSpellchecker
197 virtual bool exitEarly() const { return false; }
200 /// Main Window access.
201 /// This is unfortunately needed for the qt4 frontend and the \c
202 /// QDialogView framework. This permits to give a parent to the
203 /// constructed \c QDialog via a cast to \c GuiView.
204 LyXView * view() { return &parent_.kernel().lyxview(); }
207 /** \name Controller Access
208 * Enable the derived classes to access the other parts of the whole.
211 Dialog & dialog() { return parent_; }
212 Dialog const & dialog() const { return parent_; }
214 Kernel & kernel() { return parent_.kernel(); }
215 Kernel const & kernel() const { return parent_.kernel(); }
223 /** \c Dialog::View is an abstract base class to the View
224 * of a Model-Controller-View split of a generic dialog.
226 class Dialog::View : boost::noncopyable {
228 /** \param parent Dialog owning this Controller.
229 * \param title is the dialog title displayed by the WM.
231 View(Dialog & parent, lyx::docstring title);
234 /** \name Generic View
235 * These few methods are all that a generic dialog needs of a
239 /** A request to modify the data structures stored by the
240 * accompanying Controller in preparation for their dispatch to
243 virtual void apply() = 0;
245 /// Hide the dialog from sight
246 virtual void hide() = 0;
248 /// Redraw the dialog (e.g. if the colors have been remapped).
249 virtual void redraw() {}
251 /// Create the dialog if necessary, update it and display it.
252 virtual void show() = 0;
254 /// Update the display of the dialog whilst it is still visible.
255 virtual void update() = 0;
257 /// \return true if the dialog is visible.
258 virtual bool isVisible() const = 0;
261 /** Defaults to nothing. Can be used by the Controller, however, to
262 * indicate to the View that something has changed and that the
263 * dialog therefore needs updating.
264 * \param id identifies what should be updated.
266 virtual void partialUpdate(int id);
268 /// sets the title of the dialog (window caption)
269 void setTitle(lyx::docstring const &);
270 /// gets the title of the dialog (window caption)
271 lyx::docstring const & getTitle() const;
273 /** \name View Access
274 * Enable the derived classes to access the other parts of the whole.
277 Dialog & dialog() { return p_; }
278 Dialog const & dialog() const { return p_; }
281 Kernel & kernel() { return p_.kernel(); }
282 Kernel const & kernel() const { return p_.kernel(); }
284 Controller & getController() { return p_.controller(); }
285 Controller const & getController() const { return p_.controller(); }
287 ButtonController & bc() { return p_.bc(); }
288 ButtonController const & bc() const { return p_.bc(); }
293 lyx::docstring title_;
296 } // namespace frontend