]> git.lyx.org Git - lyx.git/blob - src/frontends/Dialog.h
Move Color::color enum to ColorCode.h
[lyx.git] / src / frontends / 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 #include "lfuns.h"
16
17 #include "support/docstring.h"
18 #include <string>
19
20 namespace lyx {
21
22 class Buffer;
23 class BufferView;
24 class FuncRequest;
25
26 namespace frontend {
27
28 class LyXView;
29
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.
33  */
34 enum KernelDocType
35 {
36         LATEX,
37         LITERATE,
38         DOCBOOK
39 };
40
41
42 /** \c Dialog collects the different parts of a Model-Controller-View
43  *  split of a generic dialog together.
44  */
45 class Dialog 
46 {
47 public:
48         /// \param lv is the access point for the dialog to the LyX kernel.
49         /// \param name is the identifier given to the dialog by its parent
50         /// container.
51         Dialog(LyXView & lv) : lyxview_(&lv) {}
52         virtual ~Dialog();
53
54         /** \name Container Access
55          *  These methods are publicly accessible because they are invoked
56          *  by the parent container acting on commands from the LyX kernel.
57          */
58         //@{
59         /// \param data is a string encoding of the data to be displayed.
60         /// It is passed to the Controller to be translated into a useable form.
61         virtual void showData(std::string const & /*data*/) {}
62         virtual void updateData(std::string const & /*data*/) {}
63
64         virtual void hide() {}
65
66         // Override in GuiDialog
67         virtual void slotOK() {}
68         virtual void slotApply() {}
69         virtual void slotRestore() {}
70         virtual void slotClose() {}
71
72         /** This function is called, for example, if the GUI colours
73          *  have been changed.
74          */
75         virtual void redraw() {}
76         //@}
77
78         /** Check whether we may apply our data.
79          *
80          *  The buttons are disabled if not and (re-)enabled if yes.
81          */
82         virtual void checkStatus() {}
83
84         /** When applying, it's useful to know whether the dialog is about
85          *  to close or not (no point refreshing the display for example).
86          */
87         virtual bool isClosing() const { return false; }
88
89
90         /** \c Button controller part
91          */
92         virtual void setButtonsValid(bool /*valid*/) {}
93
94
95         /** \c View part
96          *  of a Model-Controller-View split of a generic dialog.
97          *  These few methods are all that a generic dialog needs of a
98          *  view.
99          */
100         //@{
101         /** A request to modify the data structures stored by the
102          *  accompanying Controller in preparation for their dispatch to
103          *  the LyX kernel.
104          */
105         virtual void applyView() = 0;
106
107         /// Hide the dialog from sight
108         virtual void hideView() = 0;
109
110         /// Redraw the dialog (e.g. if the colors have been remapped).
111         virtual void redrawView() = 0;
112
113         /// Create the dialog if necessary, update it and display it.
114         virtual void showView() = 0;
115
116         /// Update the display of the dialog whilst it is still visible.
117         virtual void updateView() = 0;
118
119         /// \return true if the dialog is visible.
120         virtual bool isVisibleView() const = 0;
121         //@}
122
123         /** Defaults to nothing. Can be used by the Controller, however, to
124          *  indicate to the View that something has changed and that the
125          *  dialog therefore needs updating.
126          *  \param id identifies what should be updated.
127          */
128         virtual void partialUpdateView(int /*id*/) = 0;
129
130         ///
131         virtual std::string name() const = 0;
132
133         //@{
134         /** Enable the controller to initialise its data structures.
135          *  \param data is a string encoding of the parameters to be displayed.
136          *  \return true if the translation was successful.
137          */
138         virtual bool initialiseParams(std::string const & data) = 0;
139
140         /// Enable the controller to clean up its data structures.
141         virtual void clearParams() = 0;
142
143         /// Enable the Controller to dispatch its data back to the LyX kernel.
144         virtual void dispatchParams() = 0;
145
146         /** \return true if the dialog should be shown only when
147          *  a buffer is open.
148          */
149         virtual bool isBufferDependent() const = 0;
150
151         /** \return true if the dialog can apply data also
152          *  for ReadOnly buffers.
153          *  This has to be distinguished from isBufferDependent()
154          */
155         virtual bool canApplyToReadOnly() const { return false; }
156
157         /** The lfun that is sent for applying the data.
158          *
159          * This method is used by the default implementation of canApply()
160          * for buffer dependent dialogs that send one lfun when applying the
161          * data.
162          * It should be used in dispatchParams(), too for consistency reasons.
163          *  \returns the lfun that is sent for applying the data.
164          */
165         virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
166
167         /** Check whether we may apply our data.
168          *
169          * The default implementation works for all dialogs that send one
170          * lfun when applying the data. Dialogs that send none or more than
171          * one lfun need to reimplement it.
172          *  \returns whether the data can be applied or not.
173          */
174         virtual bool canApply() const;
175
176         /** \return true if the kernel should disconnect the dialog from
177          *  a particular inset after the data has been applied to it.
178          *  Clearly this makes sense only for dialogs modifying the contents
179          *  of an inset :-)
180          *  In practise, only a very few dialogs (e.g. the citation dialog)
181          *  return true.
182          */
183         virtual bool disconnectOnApply() const { return false; }
184
185         /** \return true if Dialog::View::show() should not display the dialog
186          *   after running update. Currently, only ControlSpellchecker
187          *   makes use of that.
188         */
189         virtual bool exitEarly() const { return false; }
190         //@}
191
192         /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
193          * (Ie, it provides an interface to the Model part of the Model-Controller-
194          *  View split.
195          *  In an ideal world, it will shrink as more info is passed to the
196          *  Dialog::show() and Dialog::update() methods.
197          */
198
199
200         /** This method is the primary purpose of the class. It provides
201          *  the "gateway" by which the dialog can send a request (of a
202          *  change in the data, for more information) to the kernel.
203          *  \param fr is the encoding of the request.
204          */
205         void dispatch(FuncRequest const & fr) const;
206
207         /** The dialog has received a request from the user
208          *  (who pressed the "Restore" button) to update contents.
209          *  It must, therefore, ask the kernel to provide this information.
210          *  \param name is used to identify the dialog to the kernel.
211          */
212         void updateDialog(std::string const & name) const;
213
214         /** A request from the Controller that future changes to the data
215          *  stored by the dialog are not applied to the inset currently
216          *  connected to the dialog. Instead, they will be used to generate
217          *  a new inset at the cursor position.
218          *  \param name is used to identify the dialog to the kernel.
219          */
220         void disconnect(std::string const & name) const;
221
222         /** \name Kernel Wrappers
223          *  Simple wrapper functions to Buffer methods.
224          */
225         //@{
226         bool isBufferAvailable() const;
227         bool isBufferReadonly() const;
228         std::string const bufferFilepath() const;
229         //@}
230
231         /// The type of the current buffer.
232         KernelDocType docType() const;
233
234         /** \name Kernel Nasties
235          *  Unpleasantly public internals of the LyX kernel.
236          *  We should aim to reduce/remove these from the interface.
237          */
238         //@{
239         LyXView & lyxview() { return *lyxview_; }
240         LyXView const & lyxview() const { return *lyxview_; }
241
242         Buffer & buffer();
243         Buffer const & buffer() const;
244
245         BufferView * bufferview();
246         BufferView const * bufferview() const;
247         //@}
248
249 protected:
250         virtual void apply() {}
251
252 private:
253         LyXView * lyxview_;
254
255 private:
256         /// intentionally unimplemented, therefore uncopiable
257         Dialog(Dialog const &);
258         void operator=(Dialog const &);
259
260 };
261
262
263 } // namespace frontend
264 } // namespace lyx
265
266 #endif // DIALOG_H