]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
Put LyXView on a diet, step 2: get rid of menubar direct access from the core. Menuba...
[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 WorkArea;
45
46 /**
47  * LyXView - main LyX window
48  *
49  * This class represents the main LyX window and provides
50  * accessor functions to its content.
51  *
52  * The eventual intention is that LyX will support a number
53  * of containing LyXViews. Currently a lot of code still
54  * relies on there being a single top-level view.
55  *
56  * Additionally we would like to support multiple views
57  * in a single LyXView.
58  */
59 class LyXView : public boost::signals::trackable, boost::noncopyable {
60 public:
61
62         LyXView(int id);
63
64         virtual ~LyXView();
65
66         int const id() const { return id_; }
67
68         virtual void close() = 0;
69
70         virtual void setFocus() = 0;
71
72         ///
73         virtual WorkArea * workArea(Buffer & buffer) = 0;
74         ///
75         virtual WorkArea * addWorkArea(Buffer & buffer) = 0;
76         ///
77         virtual void setCurrentWorkArea(WorkArea * work_area) = 0;
78         ///
79         virtual void removeWorkArea(WorkArea * work_area) = 0;
80         /// return the current WorkArea (the one that has the focus).
81         virtual WorkArea const * currentWorkArea() const = 0;
82         /// FIXME: This non-const access is needed because of
83         /// a mis-designed \c ControlSpellchecker.
84         virtual WorkArea * currentWorkArea() = 0;
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         BufferView * view();
121
122         /// \return the buffer currently shown in this window
123         Buffer * buffer();
124         Buffer const * buffer() const;
125
126         ///
127         void openLayoutList();
128         ///
129         bool isToolbarVisible(std::string const & id);
130         ///
131         virtual void showMiniBuffer(bool visible) = 0;
132         virtual void openMenu(docstring const & name) = 0;
133
134         /// get access to the dialogs
135         Dialogs & getDialogs() { return *dialogs_.get(); }
136         ///
137         Dialogs const & getDialogs() const { return *dialogs_.get(); }
138
139         //@}
140
141         /// load a buffer into the current workarea.
142         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
143                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
144
145         /// set a buffer to the current workarea.
146         void setBuffer(Buffer * b); ///< \c Buffer to set.
147
148         /// updates the possible layouts selectable
149         void updateLayoutChoice();
150
151         /// update the toolbar
152         void updateToolbars();
153         /// get toolbar info
154         ToolbarInfo * getToolbarInfo(std::string const & name);
155         /// toggle toolbar state
156         void toggleToolbarState(std::string const & name, bool allowauto);
157         /// update the status bar
158         virtual void updateStatusBar() = 0;
159
160         /// display a message in the view
161         virtual void message(docstring const &) = 0;
162
163         /// clear any temporary message and replace with current status
164         virtual void clearMessage() = 0;
165
166         /// updates the title of the window
167         void updateWindowTitle();
168
169         /// reset autosave timer
170         void resetAutosaveTimer();
171
172         /// dispatch to current BufferView
173         void dispatch(FuncRequest const & cmd);
174
175         /** redraw \c inset in all the BufferViews in which it is currently
176          *  visible. If successful return a pointer to the owning Buffer.
177          */
178         Buffer const * const updateInset(Inset const *);
179
180         /// returns true if this view has the focus.
181         virtual bool hasFocus() const = 0;
182
183         /// show the error list to the user
184         void showErrorList(std::string const &);
185
186 protected:
187         /// connect to signals in the given BufferView
188         void connectBufferView(BufferView & bv);
189         /// disconnect from signals in the given BufferView
190         void disconnectBufferView();
191         /// connect to signals in the given buffer
192         void connectBuffer(Buffer & buf);
193         /// disconnect from signals in the given buffer
194         void disconnectBuffer();
195
196         /// view's toolbar
197         boost::scoped_ptr<Toolbars> toolbars_;
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         /// auto-saving of buffers
211         boost::scoped_ptr<Timeout> const autosave_timeout_;
212         /// our function handler
213         boost::scoped_ptr<LyXFunc> lyxfunc_;
214         /// dialogs for this view
215         boost::scoped_ptr<Dialogs> dialogs_;
216
217         /// buffer structure changed signal connection
218         boost::signals::connection bufferStructureChangedConnection_;
219         /// buffer errors signal connection
220         boost::signals::connection errorsConnection_;
221         /// buffer messages signal connection
222         boost::signals::connection messageConnection_;
223         /// buffer busy status signal connection
224         boost::signals::connection busyConnection_;
225         /// buffer title changed signal connection
226         boost::signals::connection titleConnection_;
227         /// buffer reset timers signal connection
228         boost::signals::connection timerConnection_;
229         /// buffer readonly status changed signal connection
230         boost::signals::connection readonlyConnection_;
231
232         /// BufferView messages signal connection
233         //@{
234         boost::signals::connection message_connection_;
235         boost::signals::connection show_dialog_connection_;
236         boost::signals::connection show_dialog_with_data_connection_;
237         boost::signals::connection show_inset_dialog_connection_;
238         boost::signals::connection update_dialog_connection_;
239         boost::signals::connection layout_changed_connection_;
240         //@}
241
242         /// Bind methods for BufferView messages signal connection
243         //@{
244         void showDialog(std::string const & name);
245         void showDialogWithData(std::string const & name,
246                 std::string const & data);
247         void showInsetDialog(std::string const & name,
248                 std::string const & data, Inset * inset);
249         void updateDialog(std::string const & name,
250                 std::string const & data);
251         //@}
252
253         /// notify readonly status
254         void showReadonly(bool);
255
256 protected:
257         ///
258         void updateToc();
259
260         /// view's command buffer controller
261         // this has to be declared _after_ lyxfunc_ as its initialization depends
262         // on it!
263         typedef boost::scoped_ptr<ControlCommandBuffer>
264         CommandBufferPtr;
265
266         CommandBufferPtr const controlcommand_;
267
268 private:
269         int id_;
270 };
271
272 } // namespace frontend
273 } // namespace lyx
274
275 #endif // LYXVIEW_H