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