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