4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
16 #include "frontends/Application.h"
17 #include "frontends/Toolbars.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>
43 class ControlCommandBuffer;
44 } // namespace frontend
48 * LyXView - main LyX window
50 * This class represents the main LyX window and provides
51 * accessor functions to its content.
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.
57 * Additionally we would like to support multiple views
58 * in a single LyXView.
60 class LyXView : public boost::signals::trackable, boost::noncopyable {
67 int const id() const { return id_; }
69 virtual void close() = 0;
71 std::vector<int> const & workAreaIds() const { return work_area_ids_; }
73 void setWorkArea(frontend::WorkArea * work_area);
75 /// This signal is emitted with the LyXView id when it is closed.
76 boost::signal<void(int)> closed;
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.
83 virtual void init() = 0;
86 virtual void setGeometry(
92 /// save the geometry state in the session manager.
93 virtual void saveGeometry() = 0;
96 virtual void busy(bool) = 0;
98 virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
100 //@{ generic accessor functions
102 /** return the current buffer view
103 Returned as a shared_ptr so that anything wanting to cache the
104 buffer view can do so safely using a boost::weak_ptr.
106 BufferView * view() const;
108 /// return the buffer currently shown in this window
109 Buffer * buffer() const;
111 /// return the toolbar for this view
112 Toolbars & getToolbars() { return *toolbars_.get(); }
114 Toolbars const & getToolbars() const { return *toolbars_.get(); }
116 /// return the menubar for this view
117 Menubar & getMenubar() { return *menubar_.get(); }
119 Menubar const & getMenubar() const { return *menubar_.get(); }
121 /// get access to the dialogs
122 Dialogs & getDialogs() { return *dialogs_.get(); }
124 Dialogs const & getDialogs() const { return *dialogs_.get(); }
128 /// load a buffer into the current workarea
129 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
131 /// set a buffer to the current workarea
132 void setBuffer(Buffer * b);
134 /// updates the possible layouts selectable
135 void updateLayoutChoice();
137 /// update the toolbar
138 void updateToolbars();
139 /// update the menubar
140 void updateMenubar();
141 /// update the status bar
142 virtual void updateStatusBar() = 0;
144 /// focus the command buffer (minibuffer)
145 boost::signal<void()> focus_command_buffer;
147 /// display a message in the view
148 virtual void message(docstring const &) = 0;
150 /// clear any temporary message and replace with current status
151 virtual void clearMessage() = 0;
153 /// updates the title of the window
154 void updateWindowTitle();
156 /// reset autosave timer
157 void resetAutosaveTimer();
159 /// dispatch to current BufferView
160 void dispatch(FuncRequest const & cmd);
162 /** redraw \c inset in all the BufferViews in which it is currently
163 * visible. If successful return a pointer to the owning Buffer.
165 Buffer const * const updateInset(InsetBase const *) const;
167 /// returns true if this view has the focus.
168 virtual bool hasFocus() const = 0;
170 /// show the error list to the user
171 void showErrorList(std::string const &);
173 /// connect to signals in the given BufferView
174 void connectBufferView(BufferView & bv);
175 /// disconnect from signals in the given BufferView
176 void disconnectBufferView();
179 /// current work area (screen view of a BufferView).
181 \todo FIXME: there is only one workArea per LyXView for now.
183 frontend::WorkArea * work_area_;
186 boost::scoped_ptr<Menubar> menubar_;
190 * setWindowTitle - set title of window
191 * @param t main window title
192 * @param it iconified (short) title
194 virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
196 /// called on timeout
200 boost::scoped_ptr<Toolbars> toolbars_;
201 /// auto-saving of buffers
202 boost::scoped_ptr<Timeout> const autosave_timeout_;
203 /// our function handler
204 boost::scoped_ptr<LyXFunc> lyxfunc_;
205 /// dialogs for this view
206 boost::scoped_ptr<Dialogs> dialogs_;
208 /// buffer changed signal connection
209 boost::signals::connection bufferChangedConnection_;
210 /// buffer errors signal connection
211 boost::signals::connection errorsConnection_;
212 /// buffer messages signal connection
213 boost::signals::connection messageConnection_;
214 /// buffer busy status signal connection
215 boost::signals::connection busyConnection_;
216 /// buffer title changed signal connection
217 boost::signals::connection titleConnection_;
218 /// buffer reset timers signal connection
219 boost::signals::connection timerConnection_;
220 /// buffer readonly status changed signal connection
221 boost::signals::connection readonlyConnection_;
222 /// buffer closing signal connection
223 boost::signals::connection closingConnection_;
224 /// connect to signals in the given buffer
225 void connectBuffer(Buffer & buf);
226 /// disconnect from signals in the given buffer
227 void disconnectBuffer();
229 /// BufferView messages signal connection
231 boost::signals::connection message_connection_;
232 boost::signals::connection show_dialog_connection_;
233 boost::signals::connection show_dialog_with_data_connection_;
234 boost::signals::connection show_inset_dialog_connection_;
235 boost::signals::connection update_dialog_connection_;
236 boost::signals::connection layout_changed_connection_;
239 /// Bind methods for BufferView messages signal connection
241 void showDialog(std::string const & name);
242 void showDialogWithData(std::string const & name,
243 std::string const & data);
244 void showInsetDialog(std::string const & name,
245 std::string const & data, InsetBase * inset);
246 void updateDialog(std::string const & name,
247 std::string const & data);
250 /// notify readonly status
251 void showReadonly(bool);
254 /// view's command buffer controller
255 // this has to be declared _after_ lyxfunc_ as its initialization depends
257 typedef boost::scoped_ptr<frontend::ControlCommandBuffer>
260 CommandBufferPtr const controlcommand_;
264 std::vector<int> work_area_ids_;