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