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