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