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