]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
Move Color::color enum to ColorCode.h
[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/Delegates.h"
18 #include "support/docstring.h"
19
20 #include <boost/noncopyable.hpp>
21
22 #include <vector>
23
24 namespace lyx {
25
26 namespace support { class FileName; }
27
28 class Font;
29 class Buffer;
30 class BufferView;
31 class FuncRequest;
32 class Inset;
33 class Timeout;
34 class ToolbarInfo;
35
36 namespace frontend {
37
38 class Dialogs;
39 class WorkArea;
40
41 /**
42  * LyXView - main LyX window
43  *
44  * This class represents the main LyX window and provides
45  * accessor functions to its content.
46  *
47  * The eventual intention is that LyX will support a number
48  * of containing LyXViews. Currently a lot of code still
49  * relies on there being a single top-level view.
50  *
51  * Additionally we would like to support multiple views
52  * in a single LyXView.
53  */
54 class LyXView : boost::noncopyable,
55         public GuiBufferViewDelegate, public GuiBufferDelegate
56 {
57 public:
58         ///
59         LyXView(int id);
60         ///
61         virtual ~LyXView();
62         ///
63         int id() const { return id_; }
64         ///
65         virtual void close() = 0;
66         ///
67         virtual void setFocus() = 0;
68
69         ///
70         virtual WorkArea * workArea(Buffer & buffer) = 0;
71         ///
72         virtual WorkArea * addWorkArea(Buffer & buffer) = 0;
73         ///
74         virtual void setCurrentWorkArea(WorkArea * work_area) = 0;
75         ///
76         virtual void removeWorkArea(WorkArea * work_area) = 0;
77         /// return the current WorkArea (the one that has the focus).
78         virtual WorkArea const * currentWorkArea() const = 0;
79         /// FIXME: This non-const access is needed because of
80         /// a mis-designed \c ControlSpellchecker.
81         virtual WorkArea * currentWorkArea() = 0;
82
83         /**
84          * This is called after the concrete view has been created.
85          * We have to have the toolbar and the other stuff created
86          * before we can populate it with this call.
87          */
88         virtual void init() = 0;
89
90         enum Maximized {
91                 NotMaximized,
92                 VerticallyMaximized,
93                 HorizontallyMaximized,
94                 CompletelyMaximized
95         };
96
97         ///
98         virtual void setGeometry(
99                 unsigned int width,
100                 unsigned int height,
101                 int posx, int posy,
102                 int maximize,
103                 unsigned int iconSizeXY,
104                 const std::string & geometryArg) = 0;
105
106         /// save the geometry state in the session manager.
107         virtual void saveGeometry() = 0;
108
109         /// show busy cursor
110         virtual void setBusy(bool) = 0;
111
112         //@{ generic accessor functions
113
114         /// \return the current buffer view.
115         BufferView * view();
116
117         /// \return the buffer currently shown in this window
118         Buffer * buffer();
119         Buffer const * buffer() const;
120
121         ///
122         virtual void openLayoutList() = 0;
123         ///
124         virtual bool isToolbarVisible(std::string const & id) = 0;
125         ///
126         virtual void showMiniBuffer(bool visible) = 0;
127         virtual void openMenu(docstring const & name) = 0;
128
129         /// get access to the dialogs
130         Dialogs & getDialogs() { return *dialogs_; }
131         ///
132         Dialogs const & getDialogs() const { return *dialogs_; }
133
134         //@}
135
136         /// load a buffer into the current workarea.
137         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
138                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
139
140         /// set a buffer to the current workarea.
141         void setBuffer(Buffer * b); ///< \c Buffer to set.
142
143         /// updates the possible layouts selectable
144         virtual void updateLayoutChoice() = 0;
145
146         /// update the toolbar
147         virtual void updateToolbars() = 0;
148         /// get toolbar info
149         virtual ToolbarInfo * getToolbarInfo(std::string const & name) = 0;
150         /// toggle toolbar state
151         virtual void toggleToolbarState(std::string const & name, bool allowauto) = 0;
152         /// update the status bar
153         virtual void updateStatusBar() = 0;
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         /// reset autosave timer
165         void resetAutosaveTimer();
166
167         /// dispatch to current BufferView
168         void dispatch(FuncRequest const & cmd);
169
170         /** redraw \c inset in all the BufferViews in which it is currently
171          *  visible. If successful return a pointer to the owning Buffer.
172          */
173         Buffer const * updateInset(Inset const *);
174
175         /// returns true if this view has the focus.
176         virtual bool hasFocus() const = 0;
177
178         /// show the error list to the user
179         void showErrorList(std::string const &);
180
181         
182         //
183         // GuiBufferDelegate
184         //
185         /// This function is called when the buffer structure is changed.
186         void structureChanged() { updateToc(); }
187         /// This function is called when some parsing error shows up.
188         void errors(std::string const & err) { showErrorList(err); }
189         /// This function is called when the buffer readonly status change.
190         void setReadOnly(bool on);
191         /// Update window titles of all users.
192         void updateTitles() { updateWindowTitle(); }
193         /// Reset autosave timers for all users.
194         void resetAutosaveTimers() { resetAutosaveTimer(); }
195
196         /// connect to signals in the given BufferView
197         void connectBufferView(BufferView & bv);
198         /// disconnect from signals in the given BufferView
199         void disconnectBufferView();
200         /// connect to signals in the given buffer
201         void connectBuffer(Buffer & buf);
202         /// disconnect from signals in the given buffer
203         void disconnectBuffer();
204
205 private:
206         /**
207          * setWindowTitle - set title of window
208          * @param t main window title
209          * @param it iconified (short) title
210          */
211         virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
212
213         /// called on timeout
214         void autoSave();
215
216         /// auto-saving of buffers
217         Timeout * const autosave_timeout_;
218         /// dialogs for this view
219         Dialogs * dialogs_;
220
221         /// Bind methods for BufferView messages signal connection
222         //@{
223         void showDialog(std::string const & name);
224         void showDialogWithData(std::string const & name,
225                 std::string const & data);
226         void showInsetDialog(std::string const & name,
227                 std::string const & data, Inset * inset);
228         void updateDialog(std::string const & name,
229                 std::string const & data);
230         //@}
231
232 protected:
233         ///
234         void updateToc();
235         ///
236         void updateEmbeddedFiles();
237
238 private:
239         int id_;
240 };
241
242 } // namespace frontend
243 } // namespace lyx
244
245 #endif // LYXVIEW_H