]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
* LyXView.h:
[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/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 Intl;
27 class Menubar;
28
29 class BufferView;
30 class Dialogs;
31 class LyXFunc;
32 class LyXFont;
33 class Timeout;
34 class FuncRequest;
35
36 namespace lyx {
37 namespace frontend {
38 class Gui;
39 class WorkArea;
40 class ControlCommandBuffer;
41 } // namespace frontend
42
43 } // namespace lyx
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(lyx::frontend::Gui & owner);
62
63         virtual ~LyXView();
64
65         void setWorkArea(lyx::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         void init();
73
74         /// show busy cursor
75         virtual void busy(bool) const = 0;
76
77         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
78
79         //@{ generic accessor functions
80
81         /** return the current buffer view
82             Returned as a shared_ptr so that anything wanting to cache the
83             buffer view can do so safely using a boost::weak_ptr.
84          */
85         BufferView * view() const;
86
87         /// return the buffer currently shown in this window
88         Buffer * buffer() const;
89
90         /// return the LyX function handler for this view
91         LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
92         ///
93         LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
94
95         /// return the toolbar for this view
96         Toolbars & getToolbars() { return *toolbars_.get(); }
97         ///
98         Toolbars const & getToolbars() const { return *toolbars_.get(); }
99
100         /// return the menubar for this view
101         Menubar & getMenubar() { return *menubar_.get(); }
102         ///
103         Menubar const & getMenubar() const { return *menubar_.get(); }
104
105         /// get access to the dialogs
106         Dialogs & getDialogs() { return *dialogs_.get(); }
107         ///
108         Dialogs const & getDialogs() const { return *dialogs_.get(); }
109
110         /// get this view's keyboard map handler
111         Intl & getIntl() { return *intl_.get(); }
112         ///
113         Intl const & getIntl() const { return *intl_.get(); }
114
115         //@}
116
117         /// load a buffer into the current workarea
118         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
119
120         /// set a buffer to the current workarea
121         void setBuffer(Buffer * b);
122
123         /// sets the layout in the toolbar layout selection
124         void setLayout(std::string const & layout);
125         /// updates the possible layouts selectable
126         void updateLayoutChoice();
127
128         /// update the toolbar
129         void updateToolbars();
130         /// update the menubar
131         void updateMenubar();
132         /// update the status bar
133         virtual void updateStatusBar() = 0;
134
135         /// focus the command buffer (minibuffer)
136         boost::signal<void()> focus_command_buffer;
137
138         /// display a message in the view
139         virtual void message(std::string const &) = 0;
140
141         /// clear any temporary message and replace with current status
142         virtual void clearMessage() = 0;
143
144         /// updates the title of the window
145         void updateWindowTitle();
146
147         /// reset autosave timer
148         void resetAutosaveTimer();
149
150         /// dispatch to current BufferView
151         void dispatch(FuncRequest const & cmd);
152
153         /** redraw \c inset in all the BufferViews in which it is currently
154          *  visible. If successful return a pointer to the owning Buffer.
155          */
156         Buffer const * const updateInset(InsetBase const *) const;
157
158         /// returns true if this view has the focus.
159         virtual bool hasFocus() const = 0;
160
161         ///
162         virtual lyx::frontend::Gui & gui();
163
164         /// Temporary method used by the kernel to redraw the work area.
165         virtual void redrawWorkArea();
166
167         /// Temporary method to access the current workArea.
168         /// This is needed for the qt3 and gtk frontend.
169         lyx::frontend::WorkArea * workArea();
170
171         /// show the error list to the user
172         void showErrorList(std::string const &);
173
174 protected:
175         /// current work area (screen view of a BufferView).
176         /**
177         \todo FIXME: there is only one workArea per LyXView for now.
178         */
179         lyx::frontend::WorkArea * work_area_;
180
181         /// view's menubar
182         boost::scoped_ptr<Menubar> menubar_;
183
184 private:
185         lyx::frontend::Gui & owner_;
186         /**
187          * setWindowTitle - set title of window
188          * @param t main window title
189          * @param it iconified (short) title
190          */
191         virtual void setWindowTitle(std::string const & t, std::string const & it) = 0;
192
193         /// called on timeout
194         void autoSave();
195
196         /// view's toolbar
197         boost::scoped_ptr<Toolbars> toolbars_;
198         /// keyboard mapping object
199         boost::scoped_ptr<Intl> const intl_;
200         /// auto-saving of buffers
201         boost::scoped_ptr<Timeout> const autosave_timeout_;
202         /// our function handler
203         boost::scoped_ptr<LyXFunc> lyxfunc_;
204         /// dialogs for this view
205         boost::scoped_ptr<Dialogs> dialogs_;
206
207         /// buffer errors signal connection
208         boost::signals::connection errorsConnection_;
209         /// buffer messages signal connection
210         boost::signals::connection messageConnection_;
211         /// buffer busy status signal connection
212         boost::signals::connection busyConnection_;
213         /// buffer title changed signal connection
214         boost::signals::connection titleConnection_;
215         /// buffer reset timers signal connection
216         boost::signals::connection timerConnection_;
217         /// buffer readonly status changed signal connection
218         boost::signals::connection readonlyConnection_;
219         /// buffer closing signal connection
220         boost::signals::connection closingConnection_;
221         /// connect to signals in the given buffer
222         void connectBuffer(Buffer & buf);
223         /// disconnect from signals in the given buffer
224         void disconnectBuffer();
225         /// notify readonly status
226         void showReadonly(bool);
227
228 protected:
229         /// view's command buffer controller
230         // this has to be declared _after_ lyxfunc_ as its initialization depends
231         // on it!
232         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
233         CommandBufferPtr;
234
235         CommandBufferPtr const controlcommand_;
236 };
237
238 #endif // LYXVIEW_H