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