]> git.lyx.org Git - features.git/blob - src/frontends/LyXView.h
This commit replaces BufferView->LyXView->Gui->[selection,clipboard] with theApp...
[features.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();
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         /// Temporary method used by the kernel to redraw the work area.
166         virtual void redrawWorkArea();
167
168         /// Temporary method to access the current workArea.
169         /// This is needed for the qt3 and gtk frontend.
170         lyx::frontend::WorkArea * workArea();
171
172         /// show the error list to the user
173         void showErrorList(std::string const &);
174
175         /// connect to signals in the given BufferView
176         void connectBufferView(BufferView & bv);
177         /// disconnect from signals in the given BufferView
178         void disconnectBufferView();
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         /**
192          * setWindowTitle - set title of window
193          * @param t main window title
194          * @param it iconified (short) title
195          */
196         virtual void setWindowTitle(lyx::docstring const & t, lyx::docstring const & it) = 0;
197
198         /// called on timeout
199         void autoSave();
200
201         /// view's toolbar
202         boost::scoped_ptr<Toolbars> toolbars_;
203         /// auto-saving of buffers
204         boost::scoped_ptr<Timeout> const autosave_timeout_;
205         /// our function handler
206         boost::scoped_ptr<LyXFunc> lyxfunc_;
207         /// dialogs for this view
208         boost::scoped_ptr<Dialogs> dialogs_;
209
210         /// buffer errors signal connection
211         boost::signals::connection errorsConnection_;
212         /// buffer messages signal connection
213         boost::signals::connection messageConnection_;
214         /// buffer busy status signal connection
215         boost::signals::connection busyConnection_;
216         /// buffer title changed signal connection
217         boost::signals::connection titleConnection_;
218         /// buffer reset timers signal connection
219         boost::signals::connection timerConnection_;
220         /// buffer readonly status changed signal connection
221         boost::signals::connection readonlyConnection_;
222         /// buffer closing signal connection
223         boost::signals::connection closingConnection_;
224         /// connect to signals in the given buffer
225         void connectBuffer(Buffer & buf);
226         /// disconnect from signals in the given buffer
227         void disconnectBuffer();
228
229         /// BufferView messages signal connection
230         //@{
231         boost::signals::connection message_connection_;
232         boost::signals::connection show_dialog_connection_;
233         boost::signals::connection show_dialog_with_data_connection_;
234         boost::signals::connection show_inset_dialog_connection_;
235         boost::signals::connection update_dialog_connection_;
236         //@}
237
238         /// Bind methods for BufferView messages signal connection
239         //@{
240         void showDialog(std::string const & name);
241         void showDialogWithData(std::string const & name,
242                 std::string const & data);
243         void showInsetDialog(std::string const & name,
244                 std::string const & data, InsetBase * inset);
245         void updateDialog(std::string const & name,
246                 std::string const & data);
247         //@}
248
249         /// notify readonly status
250         void showReadonly(bool);
251
252 protected:
253         /// view's command buffer controller
254         // this has to be declared _after_ lyxfunc_ as its initialization depends
255         // on it!
256         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
257         CommandBufferPtr;
258
259         CommandBufferPtr const controlcommand_;
260 };
261
262 #endif // LYXVIEW_H