]> git.lyx.org Git - features.git/blob - src/frontends/LyXView.h
b353571f03c4c16d7385373bedab188068fd60ac
[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/Toolbars.h"
17
18 #include <boost/scoped_ptr.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/signal.hpp>
21 #include <boost/signals/trackable.hpp>
22 #include <boost/utility.hpp>
23
24 class Buffer;
25 class InsetBase;
26 class Menubar;
27
28 class BufferView;
29 class Dialogs;
30 class LyXFunc;
31 class LyXFont;
32 class Timeout;
33 class FuncRequest;
34
35 namespace lyx {
36 namespace frontend {
37 class Gui;
38 class WorkArea;
39 class ControlCommandBuffer;
40 } // namespace frontend
41
42 } // namespace lyx
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(lyx::frontend::Gui & owner);
61
62         virtual ~LyXView();
63
64         void setWorkArea(lyx::frontend::WorkArea * work_area);
65
66         /**
67          * This is called after the concrete view has been created.
68          * We have to have the toolbar and the other stuff created
69          * before we can populate it with this call.
70          */
71         void init();
72
73         /// show busy cursor
74         virtual void busy(bool) const = 0;
75
76         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
77
78         //@{ generic accessor functions
79
80         /** return the current buffer view
81             Returned as a shared_ptr so that anything wanting to cache the
82             buffer view can do so safely using a boost::weak_ptr.
83          */
84         BufferView * view() const;
85
86         /// return the buffer currently shown in this window
87         Buffer * buffer() const;
88
89         /// return the LyX function handler for this view
90         LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
91         ///
92         LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
93
94         /// return the toolbar for this view
95         Toolbars & getToolbars() { return *toolbars_.get(); }
96         ///
97         Toolbars const & getToolbars() const { return *toolbars_.get(); }
98
99         /// return the menubar for this view
100         Menubar & getMenubar() { return *menubar_.get(); }
101         ///
102         Menubar const & getMenubar() const { return *menubar_.get(); }
103
104         /// get access to the dialogs
105         Dialogs & getDialogs() { return *dialogs_.get(); }
106         ///
107         Dialogs const & getDialogs() const { return *dialogs_.get(); }
108
109         //@}
110
111         /// load a buffer into the current workarea
112         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
113
114         /// set a buffer to the current workarea
115         void setBuffer(Buffer * b);
116
117         /// sets the layout in the toolbar layout selection
118         void setLayout(std::string const & layout);
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(lyx::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         ///
156         virtual lyx::frontend::Gui & gui();
157
158         /// Temporary method used by the kernel to redraw the work area.
159         virtual void redrawWorkArea();
160
161         /// Temporary method to access the current workArea.
162         /// This is needed for the qt3 and gtk frontend.
163         lyx::frontend::WorkArea * workArea();
164
165         /// show the error list to the user
166         void showErrorList(std::string const &);
167
168 protected:
169         /// current work area (screen view of a BufferView).
170         /**
171         \todo FIXME: there is only one workArea per LyXView for now.
172         */
173         lyx::frontend::WorkArea * work_area_;
174
175         /// view's menubar
176         boost::scoped_ptr<Menubar> menubar_;
177
178 private:
179         lyx::frontend::Gui & owner_;
180         /**
181          * setWindowTitle - set title of window
182          * @param t main window title
183          * @param it iconified (short) title
184          */
185         virtual void setWindowTitle(lyx::docstring const & t, lyx::docstring const & it) = 0;
186
187         /// called on timeout
188         void autoSave();
189
190         /// view's toolbar
191         boost::scoped_ptr<Toolbars> toolbars_;
192         /// auto-saving of buffers
193         boost::scoped_ptr<Timeout> const autosave_timeout_;
194         /// our function handler
195         boost::scoped_ptr<LyXFunc> lyxfunc_;
196         /// dialogs for this view
197         boost::scoped_ptr<Dialogs> dialogs_;
198
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         /// notify readonly status
218         void showReadonly(bool);
219
220 protected:
221         /// view's command buffer controller
222         // this has to be declared _after_ lyxfunc_ as its initialization depends
223         // on it!
224         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
225         CommandBufferPtr;
226
227         CommandBufferPtr const controlcommand_;
228 };
229
230 #endif // LYXVIEW_H