]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
This commit introduces Application_pimpl and cleanup the header includes of the affec...
[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 class Buffer;
27 class InsetBase;
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 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();
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         /* FIXME: Abdel 22/09/71
91         there is only one lyxFunc() for now but there is maybe a need
92         for more in the feature. Something like that:
93         
94                 LyXFunc & getLyXFunc() { return theApp->lyxFunc(id_); }
95
96         where id_ would be the this LyXView ID.
97         That's the reason why I didn't remove these methods for now.
98         */
99         /// return the LyX function handler for this view
100         LyXFunc & getLyXFunc() { return theApp->lyxFunc(); }
101         ///
102         LyXFunc const & getLyXFunc() const { return theApp->lyxFunc(); }
103
104         /// return the toolbar for this view
105         Toolbars & getToolbars() { return *toolbars_.get(); }
106         ///
107         Toolbars const & getToolbars() const { return *toolbars_.get(); }
108
109         /// return the menubar for this view
110         Menubar & getMenubar() { return *menubar_.get(); }
111         ///
112         Menubar const & getMenubar() const { return *menubar_.get(); }
113
114         /// get access to the dialogs
115         Dialogs & getDialogs() { return *dialogs_.get(); }
116         ///
117         Dialogs const & getDialogs() const { return *dialogs_.get(); }
118
119         //@}
120
121         /// load a buffer into the current workarea
122         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
123
124         /// set a buffer to the current workarea
125         void setBuffer(Buffer * b);
126
127         /// updates the possible layouts selectable
128         void updateLayoutChoice();
129
130         /// update the toolbar
131         void updateToolbars();
132         /// update the menubar
133         void updateMenubar();
134         /// update the status bar
135         virtual void updateStatusBar() = 0;
136
137         /// focus the command buffer (minibuffer)
138         boost::signal<void()> focus_command_buffer;
139
140         /// display a message in the view
141         virtual void message(lyx::docstring const &) = 0;
142
143         /// clear any temporary message and replace with current status
144         virtual void clearMessage() = 0;
145
146         /// updates the title of the window
147         void updateWindowTitle();
148
149         /// reset autosave timer
150         void resetAutosaveTimer();
151
152         /// dispatch to current BufferView
153         void dispatch(FuncRequest const & cmd);
154
155         /** redraw \c inset in all the BufferViews in which it is currently
156          *  visible. If successful return a pointer to the owning Buffer.
157          */
158         Buffer const * const updateInset(InsetBase const *) const;
159
160         /// returns true if this view has the focus.
161         virtual bool hasFocus() const = 0;
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         /// show the error list to the user
171         void showErrorList(std::string const &);
172
173         /// connect to signals in the given BufferView
174         void connectBufferView(BufferView & bv);
175         /// disconnect from signals in the given BufferView
176         void disconnectBufferView();
177
178 protected:
179         /// current work area (screen view of a BufferView).
180         /**
181         \todo FIXME: there is only one workArea per LyXView for now.
182         */
183         lyx::frontend::WorkArea * work_area_;
184
185         /// view's menubar
186         boost::scoped_ptr<Menubar> menubar_;
187
188 private:
189         /**
190          * setWindowTitle - set title of window
191          * @param t main window title
192          * @param it iconified (short) title
193          */
194         virtual void setWindowTitle(lyx::docstring const & t, lyx::docstring const & it) = 0;
195
196         /// called on timeout
197         void autoSave();
198
199         /// view's toolbar
200         boost::scoped_ptr<Toolbars> toolbars_;
201         /// auto-saving of buffers
202         boost::scoped_ptr<Timeout> const autosave_timeout_;
203         /// our function handler
204         boost::scoped_ptr<LyXFunc> lyxfunc_;
205         /// dialogs for this view
206         boost::scoped_ptr<Dialogs> dialogs_;
207
208         /// buffer errors signal connection
209         boost::signals::connection errorsConnection_;
210         /// buffer messages signal connection
211         boost::signals::connection messageConnection_;
212         /// buffer busy status signal connection
213         boost::signals::connection busyConnection_;
214         /// buffer title changed signal connection
215         boost::signals::connection titleConnection_;
216         /// buffer reset timers signal connection
217         boost::signals::connection timerConnection_;
218         /// buffer readonly status changed signal connection
219         boost::signals::connection readonlyConnection_;
220         /// buffer closing signal connection
221         boost::signals::connection closingConnection_;
222         /// connect to signals in the given buffer
223         void connectBuffer(Buffer & buf);
224         /// disconnect from signals in the given buffer
225         void disconnectBuffer();
226
227         /// BufferView messages signal connection
228         //@{
229         boost::signals::connection message_connection_;
230         boost::signals::connection show_dialog_connection_;
231         boost::signals::connection show_dialog_with_data_connection_;
232         boost::signals::connection show_inset_dialog_connection_;
233         boost::signals::connection update_dialog_connection_;
234         boost::signals::connection layout_changed_connection_;
235         //@}
236
237         /// Bind methods for BufferView messages signal connection
238         //@{
239         void showDialog(std::string const & name);
240         void showDialogWithData(std::string const & name,
241                 std::string const & data);
242         void showInsetDialog(std::string const & name,
243                 std::string const & data, InsetBase * inset);
244         void updateDialog(std::string const & name,
245                 std::string const & data);
246         //@}
247
248         /// notify readonly status
249         void showReadonly(bool);
250
251 protected:
252         /// view's command buffer controller
253         // this has to be declared _after_ lyxfunc_ as its initialization depends
254         // on it!
255         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
256         CommandBufferPtr;
257
258         CommandBufferPtr const controlcommand_;
259 };
260
261 #endif // LYXVIEW_H