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