]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
Add tab support
[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 #include <vector>
27
28 namespace lyx {
29
30 class Buffer;
31 class InsetBase;
32 class Menubar;
33
34 class BufferView;
35 class Dialogs;
36 class LyXFunc;
37 class LyXFont;
38 class Timeout;
39 class FuncRequest;
40
41 namespace frontend {
42 class WorkArea;
43 class ControlCommandBuffer;
44 } // namespace frontend
45
46
47 /**
48  * LyXView - main LyX window
49  *
50  * This class represents the main LyX window and provides
51  * accessor functions to its content.
52  *
53  * The eventual intention is that LyX will support a number
54  * of containing LyXViews. Currently a lot of code still
55  * relies on there being a single top-level view.
56  *
57  * Additionally we would like to support multiple views
58  * in a single LyXView.
59  */
60 class LyXView : public boost::signals::trackable, boost::noncopyable {
61 public:
62
63         LyXView(int id);
64
65         virtual ~LyXView();
66
67         int const id() const { return id_; }
68
69         virtual void close() = 0;
70
71         std::vector<int> const & workAreaIds() const { return work_area_ids_; }
72
73         void setWorkArea(frontend::WorkArea * work_area);
74
75         /// This signal is emitted with the LyXView id when it is closed.
76         boost::signal<void(int)> closed;
77
78         /**
79          * This is called after the concrete view has been created.
80          * We have to have the toolbar and the other stuff created
81          * before we can populate it with this call.
82          */
83         virtual void init() = 0;
84
85         ///
86         virtual void setGeometry(
87                 unsigned int width,
88                 unsigned int height,
89                 int posx, int posy,
90                 bool maximize) = 0;
91
92         /// save the geometry state in the session manager.
93         virtual void saveGeometry() = 0;
94
95         /// show busy cursor
96         virtual void busy(bool) = 0;
97
98         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
99
100         //@{ generic accessor functions
101
102         /** return the current buffer view
103             Returned as a shared_ptr so that anything wanting to cache the
104             buffer view can do so safely using a boost::weak_ptr.
105          */
106         BufferView * view() const;
107
108         /// return the buffer currently shown in this window
109         Buffer * buffer() const;
110
111         /// return the toolbar for this view
112         Toolbars & getToolbars() { return *toolbars_.get(); }
113         ///
114         Toolbars const & getToolbars() const { return *toolbars_.get(); }
115
116         /// return the menubar for this view
117         Menubar & getMenubar() { return *menubar_.get(); }
118         ///
119         Menubar const & getMenubar() const { return *menubar_.get(); }
120
121         /// get access to the dialogs
122         Dialogs & getDialogs() { return *dialogs_.get(); }
123         ///
124         Dialogs const & getDialogs() const { return *dialogs_.get(); }
125
126         //@}
127
128         /// load a buffer into the current workarea
129         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
130
131         /// set a buffer to the current workarea
132         void setBuffer(Buffer * b);
133
134         /// updates the possible layouts selectable
135         void updateLayoutChoice();
136
137         /// update the toolbar
138         void updateToolbars();
139         /// update the menubar
140         void updateMenubar();
141         /// update the status bar
142         virtual void updateStatusBar() = 0;
143
144         /// focus the command buffer (minibuffer)
145         boost::signal<void()> focus_command_buffer;
146
147         /// display a message in the view
148         virtual void message(docstring const &) = 0;
149
150         /// clear any temporary message and replace with current status
151         virtual void clearMessage() = 0;
152
153         /// updates the title of the window
154         void updateWindowTitle();
155
156         /// updates the tab view
157         virtual void updateTab() = 0;
158
159         /// reset autosave timer
160         void resetAutosaveTimer();
161
162         /// dispatch to current BufferView
163         void dispatch(FuncRequest const & cmd);
164
165         /** redraw \c inset in all the BufferViews in which it is currently
166          *  visible. If successful return a pointer to the owning Buffer.
167          */
168         Buffer const * const updateInset(InsetBase const *) const;
169
170         /// returns true if this view has the focus.
171         virtual bool hasFocus() const = 0;
172
173         /// show the error list to the user
174         void showErrorList(std::string const &);
175
176         /// connect to signals in the given BufferView
177         void connectBufferView(BufferView & bv);
178         /// disconnect from signals in the given BufferView
179         void disconnectBufferView();
180
181 protected:
182         /// current work area (screen view of a BufferView).
183         /**
184         \todo FIXME: there is only one workArea per LyXView for now.
185         */
186         frontend::WorkArea * work_area_;
187
188         /// view's menubar
189         boost::scoped_ptr<Menubar> menubar_;
190
191 private:
192         /**
193          * setWindowTitle - set title of window
194          * @param t main window title
195          * @param it iconified (short) title
196          */
197         virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
198
199         /// called on timeout
200         void autoSave();
201
202         /// view's toolbar
203         boost::scoped_ptr<Toolbars> toolbars_;
204         /// auto-saving of buffers
205         boost::scoped_ptr<Timeout> const autosave_timeout_;
206         /// our function handler
207         boost::scoped_ptr<LyXFunc> lyxfunc_;
208         /// dialogs for this view
209         boost::scoped_ptr<Dialogs> dialogs_;
210
211         /// buffer changed signal connection
212         boost::signals::connection bufferChangedConnection_;
213         /// buffer errors signal connection
214         boost::signals::connection errorsConnection_;
215         /// buffer messages signal connection
216         boost::signals::connection messageConnection_;
217         /// buffer busy status signal connection
218         boost::signals::connection busyConnection_;
219         /// buffer title changed signal connection
220         boost::signals::connection titleConnection_;
221         /// buffer reset timers signal connection
222         boost::signals::connection timerConnection_;
223         /// buffer readonly status changed signal connection
224         boost::signals::connection readonlyConnection_;
225         /// buffer closing signal connection
226         boost::signals::connection closingConnection_;
227         /// connect to signals in the given buffer
228         void connectBuffer(Buffer & buf);
229         /// disconnect from signals in the given buffer
230         void disconnectBuffer();
231
232         /// BufferView messages signal connection
233         //@{
234         boost::signals::connection message_connection_;
235         boost::signals::connection show_dialog_connection_;
236         boost::signals::connection show_dialog_with_data_connection_;
237         boost::signals::connection show_inset_dialog_connection_;
238         boost::signals::connection update_dialog_connection_;
239         boost::signals::connection layout_changed_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<frontend::ControlCommandBuffer>
261         CommandBufferPtr;
262
263         CommandBufferPtr const controlcommand_;
264
265 private:
266         int id_;
267         std::vector<int> work_area_ids_;
268 };
269
270 } // namespace lyx
271
272 #endif // LYXVIEW_H