]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
Put LyXView on a diet, step 1: get rid of toolbars direct access from the core. Toolb...
[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         ///
74         virtual WorkArea * workArea(Buffer & buffer) = 0;
75         ///
76         virtual WorkArea * addWorkArea(Buffer & buffer) = 0;
77         ///
78         virtual void setCurrentWorkArea(WorkArea * work_area) = 0;
79         ///
80         virtual void removeWorkArea(WorkArea * work_area) = 0;
81         /// return the current WorkArea (the one that has the focus).
82         virtual WorkArea const * currentWorkArea() const = 0;
83         /// FIXME: This non-const access is needed because of
84         /// a mis-designed \c ControlSpellchecker.
85         virtual WorkArea * currentWorkArea() = 0;
86
87         /**
88          * This is called after the concrete view has been created.
89          * We have to have the toolbar and the other stuff created
90          * before we can populate it with this call.
91          */
92         virtual void init() = 0;
93
94         enum Maximized {
95                 NotMaximized,
96                 VerticallyMaximized,
97                 HorizontallyMaximized,
98                 CompletelyMaximized
99         };
100
101         ///
102         virtual void setGeometry(
103                 unsigned int width,
104                 unsigned int height,
105                 int posx, int posy,
106                 int maximize,
107                 unsigned int iconSizeXY,
108                 const std::string & geometryArg) = 0;
109
110         /// save the geometry state in the session manager.
111         virtual void saveGeometry() = 0;
112
113         /// show busy cursor
114         virtual void busy(bool) = 0;
115
116         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarInfo const & tbinfo, bool newline) = 0;
117
118         //@{ generic accessor functions
119
120         /// \return the current buffer view.
121         BufferView * view();
122
123         /// \return the buffer currently shown in this window
124         Buffer * buffer();
125         Buffer const * buffer() const;
126
127         ///
128         void openLayoutList();
129         ///
130         bool isToolbarVisible(std::string const & id);
131         ///
132         virtual void showMiniBuffer(bool visible) = 0;
133
134         /// return the menubar for this view
135         Menubar & getMenubar() { return *menubar_.get(); }
136         ///
137         Menubar const & getMenubar() const { return *menubar_.get(); }
138
139         /// get access to the dialogs
140         Dialogs & getDialogs() { return *dialogs_.get(); }
141         ///
142         Dialogs const & getDialogs() const { return *dialogs_.get(); }
143
144         //@}
145
146         /// load a buffer into the current workarea.
147         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
148                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
149
150         /// set a buffer to the current workarea.
151         void setBuffer(Buffer * b); ///< \c Buffer to set.
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         /// display a message in the view
168         virtual void message(docstring const &) = 0;
169
170         /// clear any temporary message and replace with current status
171         virtual void clearMessage() = 0;
172
173         /// updates the title of the window
174         void updateWindowTitle();
175
176         /// reset autosave timer
177         void resetAutosaveTimer();
178
179         /// dispatch to current BufferView
180         void dispatch(FuncRequest const & cmd);
181
182         /** redraw \c inset in all the BufferViews in which it is currently
183          *  visible. If successful return a pointer to the owning Buffer.
184          */
185         Buffer const * const updateInset(Inset const *);
186
187         /// returns true if this view has the focus.
188         virtual bool hasFocus() const = 0;
189
190         /// show the error list to the user
191         void showErrorList(std::string const &);
192
193 protected:
194         /// connect to signals in the given BufferView
195         void connectBufferView(BufferView & bv);
196         /// disconnect from signals in the given BufferView
197         void disconnectBufferView();
198         /// connect to signals in the given buffer
199         void connectBuffer(Buffer & buf);
200         /// disconnect from signals in the given buffer
201         void disconnectBuffer();
202
203         /// view's menubar
204         boost::scoped_ptr<Menubar> menubar_;
205         /// view's toolbar
206         boost::scoped_ptr<Toolbars> toolbars_;
207
208 private:
209         /**
210          * setWindowTitle - set title of window
211          * @param t main window title
212          * @param it iconified (short) title
213          */
214         virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
215
216         /// called on timeout
217         void autoSave();
218
219         /// auto-saving of buffers
220         boost::scoped_ptr<Timeout> const autosave_timeout_;
221         /// our function handler
222         boost::scoped_ptr<LyXFunc> lyxfunc_;
223         /// dialogs for this view
224         boost::scoped_ptr<Dialogs> dialogs_;
225
226         /// buffer structure changed signal connection
227         boost::signals::connection bufferStructureChangedConnection_;
228         /// buffer errors signal connection
229         boost::signals::connection errorsConnection_;
230         /// buffer messages signal connection
231         boost::signals::connection messageConnection_;
232         /// buffer busy status signal connection
233         boost::signals::connection busyConnection_;
234         /// buffer title changed signal connection
235         boost::signals::connection titleConnection_;
236         /// buffer reset timers signal connection
237         boost::signals::connection timerConnection_;
238         /// buffer readonly status changed signal connection
239         boost::signals::connection readonlyConnection_;
240
241         /// BufferView messages signal connection
242         //@{
243         boost::signals::connection message_connection_;
244         boost::signals::connection show_dialog_connection_;
245         boost::signals::connection show_dialog_with_data_connection_;
246         boost::signals::connection show_inset_dialog_connection_;
247         boost::signals::connection update_dialog_connection_;
248         boost::signals::connection layout_changed_connection_;
249         //@}
250
251         /// Bind methods for BufferView messages signal connection
252         //@{
253         void showDialog(std::string const & name);
254         void showDialogWithData(std::string const & name,
255                 std::string const & data);
256         void showInsetDialog(std::string const & name,
257                 std::string const & data, Inset * inset);
258         void updateDialog(std::string const & name,
259                 std::string const & data);
260         //@}
261
262         /// notify readonly status
263         void showReadonly(bool);
264
265 protected:
266         ///
267         void updateToc();
268
269         /// view's command buffer controller
270         // this has to be declared _after_ lyxfunc_ as its initialization depends
271         // on it!
272         typedef boost::scoped_ptr<ControlCommandBuffer>
273         CommandBufferPtr;
274
275         CommandBufferPtr const controlcommand_;
276
277 private:
278         int id_;
279 };
280
281 } // namespace frontend
282 } // namespace lyx
283
284 #endif // LYXVIEW_H