]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
reduce #includes
[lyx.git] / src / frontends / LyXView.h
1 // -*- C++ -*-
2 /**
3  * \file LyXView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYXVIEW_H
14 #define LYXVIEW_H
15
16 #include "frontends/Application.h"
17 #include "support/docstring.h"
18
19 #include <boost/signal.hpp>
20 #include <boost/signals/trackable.hpp>
21 #include <boost/utility.hpp>
22
23 #include <vector>
24
25 namespace lyx {
26
27 namespace support { class FileName; }
28
29 class Font;
30 class Buffer;
31 class BufferView;
32 class FuncRequest;
33 class Inset;
34 class Timeout;
35 class ToolbarInfo;
36
37 namespace frontend {
38
39 class Dialogs;
40 class WorkArea;
41 class Toolbar;
42 class Toolbars;
43
44 /**
45  * LyXView - main LyX window
46  *
47  * This class represents the main LyX window and provides
48  * accessor functions to its content.
49  *
50  * The eventual intention is that LyX will support a number
51  * of containing LyXViews. Currently a lot of code still
52  * relies on there being a single top-level view.
53  *
54  * Additionally we would like to support multiple views
55  * in a single LyXView.
56  */
57 class LyXView : public boost::signals::trackable, boost::noncopyable {
58 public:
59         ///
60         LyXView(int id);
61         ///
62         virtual ~LyXView();
63         ///
64         int id() const { return id_; }
65         ///
66         virtual void close() = 0;
67         ///
68         virtual void setFocus() = 0;
69
70         ///
71         virtual WorkArea * workArea(Buffer & buffer) = 0;
72         ///
73         virtual WorkArea * addWorkArea(Buffer & buffer) = 0;
74         ///
75         virtual void setCurrentWorkArea(WorkArea * work_area) = 0;
76         ///
77         virtual void removeWorkArea(WorkArea * work_area) = 0;
78         /// return the current WorkArea (the one that has the focus).
79         virtual WorkArea const * currentWorkArea() const = 0;
80         /// FIXME: This non-const access is needed because of
81         /// a mis-designed \c ControlSpellchecker.
82         virtual WorkArea * currentWorkArea() = 0;
83
84         /**
85          * This is called after the concrete view has been created.
86          * We have to have the toolbar and the other stuff created
87          * before we can populate it with this call.
88          */
89         virtual void init() = 0;
90
91         enum Maximized {
92                 NotMaximized,
93                 VerticallyMaximized,
94                 HorizontallyMaximized,
95                 CompletelyMaximized
96         };
97
98         ///
99         virtual void setGeometry(
100                 unsigned int width,
101                 unsigned int height,
102                 int posx, int posy,
103                 int maximize,
104                 unsigned int iconSizeXY,
105                 const std::string & geometryArg) = 0;
106
107         /// save the geometry state in the session manager.
108         virtual void saveGeometry() = 0;
109
110         /// show busy cursor
111         virtual void busy(bool) = 0;
112
113         virtual Toolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline) = 0;
114
115         //@{ generic accessor functions
116
117         /// \return the current buffer view.
118         BufferView * view();
119
120         /// \return the buffer currently shown in this window
121         Buffer * buffer();
122         Buffer const * buffer() const;
123
124         ///
125         void openLayoutList();
126         ///
127         bool isToolbarVisible(std::string const & id);
128         ///
129         virtual void showMiniBuffer(bool visible) = 0;
130         virtual void openMenu(docstring const & name) = 0;
131
132         /// get access to the dialogs
133         Dialogs & getDialogs() { return *dialogs_; }
134         ///
135         Dialogs const & getDialogs() const { return *dialogs_; }
136
137         //@}
138
139         /// load a buffer into the current workarea.
140         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
141                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
142
143         /// set a buffer to the current workarea.
144         void setBuffer(Buffer * b); ///< \c Buffer to set.
145
146         /// updates the possible layouts selectable
147         void updateLayoutChoice();
148
149         /// update the toolbar
150         void updateToolbars();
151         /// get toolbar info
152         ToolbarInfo * getToolbarInfo(std::string const & name);
153         /// toggle toolbar state
154         void toggleToolbarState(std::string const & name, bool allowauto);
155         /// update the status bar
156         virtual void updateStatusBar() = 0;
157
158         /// display a message in the view
159         virtual void message(docstring const &) = 0;
160
161         /// clear any temporary message and replace with current status
162         virtual void clearMessage() = 0;
163
164         /// updates the title of the window
165         void updateWindowTitle();
166
167         /// reset autosave timer
168         void resetAutosaveTimer();
169
170         /// dispatch to current BufferView
171         void dispatch(FuncRequest const & cmd);
172
173         /** redraw \c inset in all the BufferViews in which it is currently
174          *  visible. If successful return a pointer to the owning Buffer.
175          */
176         Buffer const * updateInset(Inset const *);
177
178         /// returns true if this view has the focus.
179         virtual bool hasFocus() const = 0;
180
181         /// show the error list to the user
182         void showErrorList(std::string const &);
183
184 protected:
185         /// connect to signals in the given BufferView
186         void connectBufferView(BufferView & bv);
187         /// disconnect from signals in the given BufferView
188         void disconnectBufferView();
189         /// connect to signals in the given buffer
190         void connectBuffer(Buffer & buf);
191         /// disconnect from signals in the given buffer
192         void disconnectBuffer();
193
194         /// view's toolbar
195         Toolbars * toolbars_;
196
197 private:
198         /**
199          * setWindowTitle - set title of window
200          * @param t main window title
201          * @param it iconified (short) title
202          */
203         virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
204
205         /// called on timeout
206         void autoSave();
207
208         /// auto-saving of buffers
209         Timeout * const autosave_timeout_;
210         /// dialogs for this view
211         Dialogs * dialogs_;
212
213         /// buffer structure changed signal connection
214         boost::signals::connection bufferStructureChangedConnection_;
215         /// embedded file change signal connection
216         boost::signals::connection bufferEmbeddingChangedConnection_;
217         /// buffer errors signal connection
218         boost::signals::connection errorsConnection_;
219         /// buffer messages signal connection
220         boost::signals::connection messageConnection_;
221         /// buffer busy status signal connection
222         boost::signals::connection busyConnection_;
223         /// buffer title changed signal connection
224         boost::signals::connection titleConnection_;
225         /// buffer reset timers signal connection
226         boost::signals::connection timerConnection_;
227         /// buffer readonly status changed signal connection
228         boost::signals::connection readonlyConnection_;
229
230         /// BufferView messages signal connection
231         //@{
232         boost::signals::connection message_connection_;
233         boost::signals::connection show_dialog_connection_;
234         boost::signals::connection show_dialog_with_data_connection_;
235         boost::signals::connection show_inset_dialog_connection_;
236         boost::signals::connection update_dialog_connection_;
237         boost::signals::connection layout_changed_connection_;
238         //@}
239
240         /// Bind methods for BufferView messages signal connection
241         //@{
242         void showDialog(std::string const & name);
243         void showDialogWithData(std::string const & name,
244                 std::string const & data);
245         void showInsetDialog(std::string const & name,
246                 std::string const & data, Inset * inset);
247         void updateDialog(std::string const & name,
248                 std::string const & data);
249         //@}
250
251         /// notify readonly status
252         void showReadonly(bool);
253
254 protected:
255         ///
256         void updateToc();
257         ///
258         void updateEmbeddedFiles();
259
260 private:
261         int id_;
262 };
263
264 } // namespace frontend
265 } // namespace lyx
266
267 #endif // LYXVIEW_H