]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
This commit continues the drastic diet operated on BufferView. It removes all boost...
[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 "errorlist.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 Toolbars;
26 class InsetBase;
27 class Intl;
28 class Menubar;
29
30 class BufferView;
31 class Dialogs;
32 class LyXFunc;
33 class LyXFont;
34 class Timeout;
35 class FuncRequest;
36
37 namespace lyx {
38 namespace frontend {
39 class Gui;
40 class WorkArea;
41 class ControlCommandBuffer;
42 } // namespace frontend
43
44 } // namespace lyx
45
46 /**
47  * LyXView - main LyX window
48  *
49  * This class represents the main LyX window and provides
50  * accessor functions to its content.
51  *
52  * The eventual intention is that LyX will support a number
53  * of containing LyXViews. Currently a lot of code still
54  * relies on there being a single top-level view.
55  *
56  * Additionally we would like to support multiple views
57  * in a single LyXView.
58  */
59 class LyXView : public boost::signals::trackable, boost::noncopyable {
60 public:
61
62         LyXView(lyx::frontend::Gui & owner);
63
64         virtual ~LyXView();
65
66         void setWorkArea(lyx::frontend::WorkArea * work_area);
67
68         /**
69          * This is called after the concrete view has been created.
70          * We have to have the toolbar and the other stuff created
71          * before we can populate it with this call.
72          */
73         void init();
74
75         /// show busy cursor
76         virtual void busy(bool) const = 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         /// get this view's keyboard map handler
110         Intl & getIntl() { return *intl_.get(); }
111         ///
112         Intl const & getIntl() const { return *intl_.get(); }
113
114         //@}
115
116         /// load a buffer into the current workarea
117         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
118
119         /// set a buffer to the current workarea
120         void setBuffer(Buffer * b);
121
122         /// sets the layout in the toolbar layout selection
123         void setLayout(std::string const & layout);
124         /// updates the possible layouts selectable
125         void updateLayoutChoice();
126
127         /// update the toolbar
128         void updateToolbars();
129         /// update the menubar
130         void updateMenubar();
131         /// update the status bar
132         virtual void updateStatusBar() = 0;
133
134         /// focus the command buffer (minibuffer)
135         boost::signal<void()> focus_command_buffer;
136
137         /// display a message in the view
138         virtual void message(std::string const &) = 0;
139
140         /// clear any temporary message and replace with current status
141         virtual void clearMessage() = 0;
142
143         /// updates the title of the window
144         void updateWindowTitle();
145
146         /// reset autosave timer
147         void resetAutosaveTimer();
148
149         /// dispatch to current BufferView
150         void dispatch(FuncRequest const & cmd);
151
152         /** redraw \c inset in all the BufferViews in which it is currently
153          *  visible. If successful return a pointer to the owning Buffer.
154          */
155         Buffer const * const updateInset(InsetBase const *) const;
156
157         /// returns true if this view has the focus.
158         virtual bool hasFocus() const = 0;
159
160         ///
161         virtual lyx::frontend::Gui & gui();
162
163         /// Temporary method used by the kernel to redraw the work area.
164         virtual void redrawWorkArea();
165
166         /// Temporary method to access the current workArea.
167         /// This is needed for the qt3 and gtk frontend.
168         lyx::frontend::WorkArea * workArea();
169
170         /// get the stored error list
171         ErrorList const & getErrorList() const;
172         /// show the error list to the user
173         void showErrorList(std::string const &);
174         /// add an error to the list
175         /** FIXME: public method until the signal connection in
176         * BufferView::menuInsertLyXFile() is removed.
177         */
178         void addError(ErrorItem const &);
179
180 protected:
181         /// current work area (screen view of a BufferView).
182         /**
183         \todo FIXME: there is only one workArea per LyXView for now.
184         */
185         lyx::frontend::WorkArea * work_area_;
186
187         /// view's menubar
188         boost::scoped_ptr<Menubar> menubar_;
189
190 private:
191         lyx::frontend::Gui & owner_;
192         /**
193          * setWindowTitle - set title of window
194          * @param t main window title
195          * @param it iconified (short) title
196          */
197         virtual void setWindowTitle(std::string const & t, std::string const & it) = 0;
198
199         /// called on timeout
200         void autoSave();
201
202         /// view's toolbar
203         boost::scoped_ptr<Toolbars> toolbars_;
204         /// keyboard mapping object
205         boost::scoped_ptr<Intl> const intl_;
206         /// auto-saving of buffers
207         boost::scoped_ptr<Timeout> const autosave_timeout_;
208         /// our function handler
209         boost::scoped_ptr<LyXFunc> lyxfunc_;
210         /// dialogs for this view
211         boost::scoped_ptr<Dialogs> dialogs_;
212
213         /// An error list (replaces the error insets)
214         ErrorList errorlist_;
215
216         /// buffer errors signal connection
217         boost::signals::connection errorConnection_;
218         /// buffer messages signal connection
219         boost::signals::connection messageConnection_;
220         /// buffer busy status signal connection
221         boost::signals::connection busyConnection_;
222         /// buffer title changed signal connection
223         boost::signals::connection titleConnection_;
224         /// buffer reset timers signal connection
225         boost::signals::connection timerConnection_;
226         /// buffer readonly status changed signal connection
227         boost::signals::connection readonlyConnection_;
228         /// buffer closing signal connection
229         boost::signals::connection closingConnection_;
230         /// connect to signals in the given buffer
231         void connectBuffer(Buffer & buf);
232         /// disconnect from signals in the given buffer
233         void disconnectBuffer();
234         /// notify readonly status
235         void showReadonly(bool);
236
237 protected:
238         /// view's command buffer controller
239         // this has to be declared _after_ lyxfunc_ as its initialization depends
240         // on it!
241         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
242         CommandBufferPtr;
243
244         CommandBufferPtr const controlcommand_;
245 };
246
247 #endif // LYXVIEW_H