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