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