]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
This commit replaces BufferView->LyXView->getLyXFunc() with theApp->lyxFunc() and...
[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 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         /* 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         /// sets the layout in the toolbar layout selection
128         void setLayout(std::string const & layout);
129         /// updates the possible layouts selectable
130         void updateLayoutChoice();
131
132         /// update the toolbar
133         void updateToolbars();
134         /// update the menubar
135         void updateMenubar();
136         /// update the status bar
137         virtual void updateStatusBar() = 0;
138
139         /// focus the command buffer (minibuffer)
140         boost::signal<void()> focus_command_buffer;
141
142         /// display a message in the view
143         virtual void message(lyx::docstring const &) = 0;
144
145         /// clear any temporary message and replace with current status
146         virtual void clearMessage() = 0;
147
148         /// updates the title of the window
149         void updateWindowTitle();
150
151         /// reset autosave timer
152         void resetAutosaveTimer();
153
154         /// dispatch to current BufferView
155         void dispatch(FuncRequest const & cmd);
156
157         /** redraw \c inset in all the BufferViews in which it is currently
158          *  visible. If successful return a pointer to the owning Buffer.
159          */
160         Buffer const * const updateInset(InsetBase const *) const;
161
162         /// returns true if this view has the focus.
163         virtual bool hasFocus() const = 0;
164
165         ///
166         virtual lyx::frontend::Gui & gui();
167
168         /// Temporary method used by the kernel to redraw the work area.
169         virtual void redrawWorkArea();
170
171         /// Temporary method to access the current workArea.
172         /// This is needed for the qt3 and gtk frontend.
173         lyx::frontend::WorkArea * workArea();
174
175         /// show the error list to the user
176         void showErrorList(std::string const &);
177
178         /// connect to signals in the given BufferView
179         void connectBufferView(BufferView & bv);
180         /// disconnect from signals in the given BufferView
181         void disconnectBufferView();
182
183 protected:
184         /// current work area (screen view of a BufferView).
185         /**
186         \todo FIXME: there is only one workArea per LyXView for now.
187         */
188         lyx::frontend::WorkArea * work_area_;
189
190         /// view's menubar
191         boost::scoped_ptr<Menubar> menubar_;
192
193 private:
194         lyx::frontend::Gui & owner_;
195         /**
196          * setWindowTitle - set title of window
197          * @param t main window title
198          * @param it iconified (short) title
199          */
200         virtual void setWindowTitle(lyx::docstring const & t, lyx::docstring const & it) = 0;
201
202         /// called on timeout
203         void autoSave();
204
205         /// view's toolbar
206         boost::scoped_ptr<Toolbars> toolbars_;
207         /// auto-saving of buffers
208         boost::scoped_ptr<Timeout> const autosave_timeout_;
209         /// our function handler
210         boost::scoped_ptr<LyXFunc> lyxfunc_;
211         /// dialogs for this view
212         boost::scoped_ptr<Dialogs> dialogs_;
213
214         /// buffer errors signal connection
215         boost::signals::connection errorsConnection_;
216         /// buffer messages signal connection
217         boost::signals::connection messageConnection_;
218         /// buffer busy status signal connection
219         boost::signals::connection busyConnection_;
220         /// buffer title changed signal connection
221         boost::signals::connection titleConnection_;
222         /// buffer reset timers signal connection
223         boost::signals::connection timerConnection_;
224         /// buffer readonly status changed signal connection
225         boost::signals::connection readonlyConnection_;
226         /// buffer closing signal connection
227         boost::signals::connection closingConnection_;
228         /// connect to signals in the given buffer
229         void connectBuffer(Buffer & buf);
230         /// disconnect from signals in the given buffer
231         void disconnectBuffer();
232
233         /// BufferView messages signal connection
234         //@{
235         boost::signals::connection message_connection_;
236         boost::signals::connection show_dialog_connection_;
237         boost::signals::connection show_dialog_with_data_connection_;
238         boost::signals::connection show_inset_dialog_connection_;
239         boost::signals::connection update_dialog_connection_;
240         //@}
241
242         /// Bind methods for BufferView messages signal connection
243         //@{
244         void showDialog(std::string const & name);
245         void showDialogWithData(std::string const & name,
246                 std::string const & data);
247         void showInsetDialog(std::string const & name,
248                 std::string const & data, InsetBase * inset);
249         void updateDialog(std::string const & name,
250                 std::string const & data);
251         //@}
252
253         /// notify readonly status
254         void showReadonly(bool);
255
256 protected:
257         /// view's command buffer controller
258         // this has to be declared _after_ lyxfunc_ as its initialization depends
259         // on it!
260         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
261         CommandBufferPtr;
262
263         CommandBufferPtr const controlcommand_;
264 };
265
266 #endif // LYXVIEW_H