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