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/strfwd.h"
29 /** \enum KernelDocType used to flag the different kinds of buffer
30 * without making the kernel header files available to the
31 * dialog's Controller or View.
41 /** \c Dialog collects the different parts of a Model-Controller-View
42 * split of a generic dialog together.
47 /// \param lv is the access point for the dialog to the LyX kernel.
48 /// \param name is the identifier given to the dialog by its parent
50 Dialog(LyXView & lv) : lyxview_(&lv) {}
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.
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 virtual void showData(std::string const & /*data*/) {}
61 virtual void updateData(std::string const & /*data*/) {}
63 virtual void hide() {}
65 // Override in GuiDialog
66 virtual void slotOK() {}
67 virtual void slotApply() {}
68 virtual void slotRestore() {}
69 virtual void slotClose() {}
71 /** This function is called, for example, if the GUI colours
74 virtual void redraw() {}
77 /** Check whether we may apply our data.
79 * The buttons are disabled if not and (re-)enabled if yes.
81 virtual void checkStatus() {}
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 virtual bool isClosing() const { return false; }
89 /** \c Button controller part
91 virtual void setButtonsValid(bool /*valid*/) {}
95 * of a Model-Controller-View split of a generic dialog.
96 * These few methods are all that a generic dialog needs of a
100 /** A request to modify the data structures stored by the
101 * accompanying Controller in preparation for their dispatch to
104 virtual void applyView() = 0;
106 /// Hide the dialog from sight
107 virtual void hideView() = 0;
109 /// Redraw the dialog (e.g. if the colors have been remapped).
110 virtual void redrawView() = 0;
112 /// Create the dialog if necessary, update it and display it.
113 virtual void showView() = 0;
115 /// Update the display of the dialog whilst it is still visible.
116 virtual void updateView() = 0;
118 /// \return true if the dialog is visible.
119 virtual bool isVisibleView() const = 0;
122 /** Defaults to nothing. Can be used by the Controller, however, to
123 * indicate to the View that something has changed and that the
124 * dialog therefore needs updating.
125 * \param id identifies what should be updated.
127 virtual void partialUpdateView(int /*id*/) = 0;
130 virtual std::string name() const = 0;
133 /** Enable the controller to initialise its data structures.
134 * \param data is a string encoding of the parameters to be displayed.
135 * \return true if the translation was successful.
137 virtual bool initialiseParams(std::string const & data) = 0;
139 /// Enable the controller to clean up its data structures.
140 virtual void clearParams() = 0;
142 /// Enable the Controller to dispatch its data back to the LyX kernel.
143 virtual void dispatchParams() = 0;
145 /** \return true if the dialog should be shown only when
148 virtual bool isBufferDependent() const = 0;
150 /** \return true if the dialog can apply data also
151 * for ReadOnly buffers.
152 * This has to be distinguished from isBufferDependent()
154 virtual bool canApplyToReadOnly() const { return false; }
156 /** The lfun that is sent for applying the data.
158 * This method is used by the default implementation of canApply()
159 * for buffer dependent dialogs that send one lfun when applying the
161 * It should be used in dispatchParams(), too for consistency reasons.
162 * \returns the lfun that is sent for applying the data.
164 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
166 /** Check whether we may apply our data.
168 * The default implementation works for all dialogs that send one
169 * lfun when applying the data. Dialogs that send none or more than
170 * one lfun need to reimplement it.
171 * \returns whether the data can be applied or not.
173 virtual bool canApply() const;
175 /** \return true if the kernel should disconnect the dialog from
176 * a particular inset after the data has been applied to it.
177 * Clearly this makes sense only for dialogs modifying the contents
179 * In practise, only a very few dialogs (e.g. the citation dialog)
182 virtual bool disconnectOnApply() const { return false; }
184 /** \return true if Dialog::View::show() should not display the dialog
185 * after running update. Currently, only ControlSpellchecker
188 virtual bool exitEarly() const { return false; }
191 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
192 * (Ie, it provides an interface to the Model part of the Model-Controller-
194 * In an ideal world, it will shrink as more info is passed to the
195 * Dialog::show() and Dialog::update() methods.
199 /** This method is the primary purpose of the class. It provides
200 * the "gateway" by which the dialog can send a request (of a
201 * change in the data, for more information) to the kernel.
202 * \param fr is the encoding of the request.
204 void dispatch(FuncRequest const & fr) const;
206 /** The dialog has received a request from the user
207 * (who pressed the "Restore" button) to update contents.
208 * It must, therefore, ask the kernel to provide this information.
209 * \param name is used to identify the dialog to the kernel.
211 void updateDialog(std::string const & name) const;
213 /** A request from the Controller that future changes to the data
214 * stored by the dialog are not applied to the inset currently
215 * connected to the dialog. Instead, they will be used to generate
216 * a new inset at the cursor position.
217 * \param name is used to identify the dialog to the kernel.
219 void disconnect(std::string const & name) const;
221 /** \name Kernel Wrappers
222 * Simple wrapper functions to Buffer methods.
225 bool isBufferAvailable() const;
226 bool isBufferReadonly() const;
227 std::string const bufferFilepath() const;
230 /// The type of the current buffer.
231 KernelDocType docType() const;
233 /** \name Kernel Nasties
234 * Unpleasantly public internals of the LyX kernel.
235 * We should aim to reduce/remove these from the interface.
238 LyXView & lyxview() { return *lyxview_; }
239 LyXView const & lyxview() const { return *lyxview_; }
242 Buffer const & buffer() const;
244 BufferView * bufferview();
245 BufferView const * bufferview() const;
249 virtual void apply() {}
255 /// intentionally unimplemented, therefore uncopiable
256 Dialog(Dialog const &);
257 void operator=(Dialog const &);
262 } // namespace frontend