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.
17 #include "support/docstring.h"
30 /** \enum KernelDocType used to flag the different kinds of buffer
31 * without making the kernel header files available to the
32 * dialog's Controller or View.
42 /** Different dialogs will have different Controllers and Views.
43 * deriving from these base classes.
49 /** \c Dialog collects the different parts of a Model-Controller-View
50 * split of a generic dialog together.
55 /// \param lv is the access point for the dialog to the LyX kernel.
56 /// \param name is the identifier given to the dialog by its parent
61 /** \name Container Access
62 * These methods are publicly accessible because they are invoked
63 * by the parent container acting on commands from the LyX kernel.
66 /// \param data is a string encoding of the data to be displayed.
67 /// It is passed to the Controller to be translated into a useable form.
68 virtual void showData(std::string const & /*data*/) {}
69 virtual void updateData(std::string const & /*data*/) {}
71 virtual void hide() {}
73 // Override in GuiDialog
74 virtual void slotOK() {}
75 virtual void slotApply() {}
76 virtual void slotRestore() {}
77 virtual void slotClose() {}
79 /** This function is called, for example, if the GUI colours
82 virtual void redraw() {}
85 /** Check whether we may apply our data.
87 * The buttons are disabled if not and (re-)enabled if yes.
89 virtual void checkStatus() {}
91 /** When applying, it's useful to know whether the dialog is about
92 * to close or not (no point refreshing the display for example).
94 virtual bool isClosing() const { return false; }
96 /** \name Dialog Specialization
97 * Methods to set the Controller and View and so specialise
98 * to a particular dialog.
101 virtual Controller & controller() = 0;
104 /** \c Button controller part
106 virtual void setButtonsValid(bool /*valid*/) {}
110 * of a Model-Controller-View split of a generic dialog.
111 * These few methods are all that a generic dialog needs of a
115 /** A request to modify the data structures stored by the
116 * accompanying Controller in preparation for their dispatch to
119 virtual void applyView() = 0;
121 /// Hide the dialog from sight
122 virtual void hideView() = 0;
124 /// Redraw the dialog (e.g. if the colors have been remapped).
125 virtual void redrawView() = 0;
127 /// Create the dialog if necessary, update it and display it.
128 virtual void showView() = 0;
130 /// Update the display of the dialog whilst it is still visible.
131 virtual void updateView() = 0;
133 /// \return true if the dialog is visible.
134 virtual bool isVisibleView() const = 0;
137 /** Defaults to nothing. Can be used by the Controller, however, to
138 * indicate to the View that something has changed and that the
139 * dialog therefore needs updating.
140 * \param id identifies what should be updated.
142 virtual void partialUpdateView(int /*id*/) = 0;
145 virtual std::string name() const = 0;
148 virtual void apply() {}
151 /// intentionally unimplemented, therefore uncopiable
152 Dialog(Dialog const &);
153 void operator=(Dialog const &);
157 /** \c Controller is an abstract base class for the Controller
158 * of a Model-Controller-View split of a generic dialog.
163 /// \param parent Dialog owning this Controller.
164 Controller(Dialog & parent);
165 // the same. avoids ambiguity with the (non-existent) copy constructor
166 Controller(Dialog * parent);
167 virtual ~Controller();
168 void setLyXView(LyXView & lv) { lyxview_ = &lv; }
170 /** \name Generic Controller
171 * These few methods are all that a generic dialog needs of a
175 /** Enable the controller to initialise its data structures.
176 * \param data is a string encoding of the parameters to be displayed.
177 * \return true if the translation was successful.
179 virtual bool initialiseParams(std::string const & data) = 0;
181 /// Enable the controller to clean up its data structures.
182 virtual void clearParams() = 0;
184 /// Enable the Controller to dispatch its data back to the LyX kernel.
185 virtual void dispatchParams() = 0;
187 /** \return true if the dialog should be shown only when
190 virtual bool isBufferDependent() const = 0;
192 /** \return true if the dialog can apply data also
193 * for ReadOnly buffers.
194 * This has to be distinguished from isBufferDependent()
196 virtual bool canApplyToReadOnly() const { return false; }
198 /** The lfun that is sent for applying the data.
200 * This method is used by the default implementation of canApply()
201 * for buffer dependent dialogs that send one lfun when applying the
203 * It should be used in dispatchParams(), too for consistency reasons.
204 * \returns the lfun that is sent for applying the data.
206 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
208 /** Check whether we may apply our data.
210 * The default implementation works for all dialogs that send one
211 * lfun when applying the data. Dialogs that send none or more than
212 * one lfun need to reimplement it.
213 * \returns whether the data can be applied or not.
215 virtual bool canApply() const;
217 /** \return true if the kernel should disconnect the dialog from
218 * a particular inset after the data has been applied to it.
219 * Clearly this makes sense only for dialogs modifying the contents
221 * In practise, only a very few dialogs (e.g. the citation dialog)
224 virtual bool disconnectOnApply() const { return false; }
226 /** \return true if Dialog::View::show() should not display the dialog
227 * after running update. Currently, only ControlSpellchecker
230 virtual bool exitEarly() const { return false; }
233 /** \name Controller Access
234 * Enable the derived classes to access the other parts of the whole.
237 Dialog & dialog() { return parent_; }
238 Dialog const & dialog() const { return parent_; }
241 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
242 * (Ie, it provides an interface to the Model part of the Model-Controller-
244 * In an ideal world, it will shrink as more info is passed to the
245 * Dialog::show() and Dialog::update() methods.
249 /** This method is the primary purpose of the class. It provides
250 * the "gateway" by which the dialog can send a request (of a
251 * change in the data, for more information) to the kernel.
252 * \param fr is the encoding of the request.
254 void dispatch(FuncRequest const & fr) const;
256 /** The dialog has received a request from the user
257 * (who pressed the "Restore" button) to update contents.
258 * It must, therefore, ask the kernel to provide this information.
259 * \param name is used to identify the dialog to the kernel.
261 void updateDialog(std::string const & name) const;
263 /** A request from the Controller that future changes to the data
264 * stored by the dialog are not applied to the inset currently
265 * connected to the dialog. Instead, they will be used to generate
266 * a new inset at the cursor position.
267 * \param name is used to identify the dialog to the kernel.
269 void disconnect(std::string const & name) const;
271 /** \name Kernel Wrappers
272 * Simple wrapper functions to Buffer methods.
275 bool isBufferAvailable() const;
276 bool isBufferReadonly() const;
277 std::string const bufferFilepath() const;
280 /// The type of the current buffer.
281 KernelDocType docType() const;
283 /** \name Kernel Nasties
284 * Unpleasantly public internals of the LyX kernel.
285 * We should aim to reduce/remove these from the interface.
288 LyXView & lyxview() { return *lyxview_; }
289 LyXView const & lyxview() const { return *lyxview_; }
292 Buffer const & buffer() const;
294 BufferView * bufferview();
295 BufferView const * bufferview() const;
299 /// intentionally unimplemented, therefore uncopiable
300 Controller(Controller const &);
301 void operator=(Controller const &);
309 } // namespace frontend