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 /// toggle toolbar state
140 void toggleToolbarState(std::string const & name);
141 /// update the menubar
142 void updateMenubar();
143 /// update the status bar
144 virtual void updateStatusBar() = 0;
146 /// focus the command buffer (minibuffer)
147 boost::signal<void()> focus_command_buffer;
149 /// display a message in the view
150 virtual void message(docstring const &) = 0;
152 /// clear any temporary message and replace with current status
153 virtual void clearMessage() = 0;
155 /// updates the title of the window
156 void updateWindowTitle();
158 /// updates the tab view
159 virtual void updateTab() = 0;
161 /// reset autosave timer
162 void resetAutosaveTimer();
164 /// dispatch to current BufferView
165 void dispatch(FuncRequest const & cmd);
167 /** redraw \c inset in all the BufferViews in which it is currently
168 * visible. If successful return a pointer to the owning Buffer.
170 Buffer const * const updateInset(InsetBase const *) const;
172 /// returns true if this view has the focus.
173 virtual bool hasFocus() const = 0;
175 /// show the error list to the user
176 void showErrorList(std::string const &);
178 /// connect to signals in the given BufferView
179 void connectBufferView(BufferView & bv);
180 /// disconnect from signals in the given BufferView
181 void disconnectBufferView();
184 /// current work area (screen view of a BufferView).
186 \todo FIXME: there is only one workArea per LyXView for now.
188 frontend::WorkArea * work_area_;
191 boost::scoped_ptr<Menubar> menubar_;
195 * setWindowTitle - set title of window
196 * @param t main window title
197 * @param it iconified (short) title
199 virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
201 /// called on timeout
205 boost::scoped_ptr<Toolbars> toolbars_;
206 /// auto-saving of buffers
207 boost::scoped_ptr<Timeout> const autosave_timeout_;
208 /// our function handler
209 boost::scoped_ptr<LyXFunc> lyxfunc_;
210 /// dialogs for this view
211 boost::scoped_ptr<Dialogs> dialogs_;
213 /// buffer changed signal connection
214 boost::signals::connection bufferChangedConnection_;
215 /// buffer errors signal connection
216 boost::signals::connection errorsConnection_;
217 /// buffer messages signal connection
218 boost::signals::connection messageConnection_;
219 /// buffer busy status signal connection
220 boost::signals::connection busyConnection_;
221 /// buffer title changed signal connection
222 boost::signals::connection titleConnection_;
223 /// buffer reset timers signal connection
224 boost::signals::connection timerConnection_;
225 /// buffer readonly status changed signal connection
226 boost::signals::connection readonlyConnection_;
227 /// buffer closing signal connection
228 boost::signals::connection closingConnection_;
229 /// connect to signals in the given buffer
230 void connectBuffer(Buffer & buf);
231 /// disconnect from signals in the given buffer
232 void disconnectBuffer();
234 /// BufferView messages signal connection
236 boost::signals::connection message_connection_;
237 boost::signals::connection show_dialog_connection_;
238 boost::signals::connection show_dialog_with_data_connection_;
239 boost::signals::connection show_inset_dialog_connection_;
240 boost::signals::connection update_dialog_connection_;
241 boost::signals::connection layout_changed_connection_;
244 /// Bind methods for BufferView messages signal connection
246 void showDialog(std::string const & name);
247 void showDialogWithData(std::string const & name,
248 std::string const & data);
249 void showInsetDialog(std::string const & name,
250 std::string const & data, InsetBase * inset);
251 void updateDialog(std::string const & name,
252 std::string const & data);
255 /// notify readonly status
256 void showReadonly(bool);
259 /// view's command buffer controller
260 // this has to be declared _after_ lyxfunc_ as its initialization depends
262 typedef boost::scoped_ptr<frontend::ControlCommandBuffer>
265 CommandBufferPtr const controlcommand_;
269 std::vector<int> work_area_ids_;