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