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