]> git.lyx.org Git - features.git/blob - src/frontends/LyXView.h
Immediate rendering of buffer change for one or multiple LyXView.
[features.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 namespace lyx {
27
28 class Buffer;
29 class InsetBase;
30 class Menubar;
31
32 class BufferView;
33 class Dialogs;
34 class LyXFunc;
35 class LyXFont;
36 class Timeout;
37 class FuncRequest;
38
39 namespace frontend {
40 class WorkArea;
41 class ControlCommandBuffer;
42 } // namespace frontend
43
44
45 /**
46  * LyXView - main LyX window
47  *
48  * This class represents the main LyX window and provides
49  * accessor functions to its content.
50  *
51  * The eventual intention is that LyX will support a number
52  * of containing LyXViews. Currently a lot of code still
53  * relies on there being a single top-level view.
54  *
55  * Additionally we would like to support multiple views
56  * in a single LyXView.
57  */
58 class LyXView : public boost::signals::trackable, boost::noncopyable {
59 public:
60
61         LyXView();
62
63         virtual ~LyXView();
64
65         void setWorkArea(frontend::WorkArea * work_area);
66
67         /**
68          * This is called after the concrete view has been created.
69          * We have to have the toolbar and the other stuff created
70          * before we can populate it with this call.
71          */
72         virtual void init() = 0;
73
74         virtual void setGeometry(
75                 unsigned int width,
76                 unsigned int height,
77                 int posx, int posy,
78                 bool maximize) = 0;
79
80         /// show busy cursor
81         virtual void busy(bool) const = 0;
82
83         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
84
85         //@{ generic accessor functions
86
87         /** return the current buffer view
88             Returned as a shared_ptr so that anything wanting to cache the
89             buffer view can do so safely using a boost::weak_ptr.
90          */
91         BufferView * view() const;
92
93         /// return the buffer currently shown in this window
94         Buffer * buffer() const;
95
96         /// return the toolbar for this view
97         Toolbars & getToolbars() { return *toolbars_.get(); }
98         ///
99         Toolbars const & getToolbars() const { return *toolbars_.get(); }
100
101         /// return the menubar for this view
102         Menubar & getMenubar() { return *menubar_.get(); }
103         ///
104         Menubar const & getMenubar() const { return *menubar_.get(); }
105
106         /// get access to the dialogs
107         Dialogs & getDialogs() { return *dialogs_.get(); }
108         ///
109         Dialogs const & getDialogs() const { return *dialogs_.get(); }
110
111         //@}
112
113         /// load a buffer into the current workarea
114         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
115
116         /// set a buffer to the current workarea
117         void setBuffer(Buffer * b);
118
119         /// updates the possible layouts selectable
120         void updateLayoutChoice();
121
122         /// update the toolbar
123         void updateToolbars();
124         /// update the menubar
125         void updateMenubar();
126         /// update the status bar
127         virtual void updateStatusBar() = 0;
128
129         /// focus the command buffer (minibuffer)
130         boost::signal<void()> focus_command_buffer;
131
132         /// display a message in the view
133         virtual void message(docstring const &) = 0;
134
135         /// clear any temporary message and replace with current status
136         virtual void clearMessage() = 0;
137
138         /// updates the title of the window
139         void updateWindowTitle();
140
141         /// reset autosave timer
142         void resetAutosaveTimer();
143
144         /// dispatch to current BufferView
145         void dispatch(FuncRequest const & cmd);
146
147         /** redraw \c inset in all the BufferViews in which it is currently
148          *  visible. If successful return a pointer to the owning Buffer.
149          */
150         Buffer const * const updateInset(InsetBase const *) const;
151
152         /// returns true if this view has the focus.
153         virtual bool hasFocus() const = 0;
154
155         /// Temporary method to access the current workArea.
156         /// This is needed for the gtk frontend.
157         frontend::WorkArea * workArea();
158
159         /// show the error list to the user
160         void showErrorList(std::string const &);
161
162         /// connect to signals in the given BufferView
163         void connectBufferView(BufferView & bv);
164         /// disconnect from signals in the given BufferView
165         void disconnectBufferView();
166
167 protected:
168         /// current work area (screen view of a BufferView).
169         /**
170         \todo FIXME: there is only one workArea per LyXView for now.
171         */
172         frontend::WorkArea * work_area_;
173
174         /// view's menubar
175         boost::scoped_ptr<Menubar> menubar_;
176
177 private:
178         /**
179          * setWindowTitle - set title of window
180          * @param t main window title
181          * @param it iconified (short) title
182          */
183         virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
184
185         /// called on timeout
186         void autoSave();
187
188         /// view's toolbar
189         boost::scoped_ptr<Toolbars> toolbars_;
190         /// auto-saving of buffers
191         boost::scoped_ptr<Timeout> const autosave_timeout_;
192         /// our function handler
193         boost::scoped_ptr<LyXFunc> lyxfunc_;
194         /// dialogs for this view
195         boost::scoped_ptr<Dialogs> dialogs_;
196
197         /// buffer changed signal connection
198         boost::signals::connection bufferChangedConnection_;
199         /// buffer errors signal connection
200         boost::signals::connection errorsConnection_;
201         /// buffer messages signal connection
202         boost::signals::connection messageConnection_;
203         /// buffer busy status signal connection
204         boost::signals::connection busyConnection_;
205         /// buffer title changed signal connection
206         boost::signals::connection titleConnection_;
207         /// buffer reset timers signal connection
208         boost::signals::connection timerConnection_;
209         /// buffer readonly status changed signal connection
210         boost::signals::connection readonlyConnection_;
211         /// buffer closing signal connection
212         boost::signals::connection closingConnection_;
213         /// connect to signals in the given buffer
214         void connectBuffer(Buffer & buf);
215         /// disconnect from signals in the given buffer
216         void disconnectBuffer();
217
218         /// BufferView messages signal connection
219         //@{
220         boost::signals::connection message_connection_;
221         boost::signals::connection show_dialog_connection_;
222         boost::signals::connection show_dialog_with_data_connection_;
223         boost::signals::connection show_inset_dialog_connection_;
224         boost::signals::connection update_dialog_connection_;
225         boost::signals::connection layout_changed_connection_;
226         //@}
227
228         /// Bind methods for BufferView messages signal connection
229         //@{
230         void showDialog(std::string const & name);
231         void showDialogWithData(std::string const & name,
232                 std::string const & data);
233         void showInsetDialog(std::string const & name,
234                 std::string const & data, InsetBase * inset);
235         void updateDialog(std::string const & name,
236                 std::string const & data);
237         //@}
238
239         /// notify readonly status
240         void showReadonly(bool);
241
242 protected:
243         /// view's command buffer controller
244         // this has to be declared _after_ lyxfunc_ as its initialization depends
245         // on it!
246         typedef boost::scoped_ptr<frontend::ControlCommandBuffer>
247         CommandBufferPtr;
248
249         CommandBufferPtr const controlcommand_;
250 };
251
252 } // namespace lyx
253
254 #endif // LYXVIEW_H