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