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(
91 unsigned int iconSizeXY,
92 const std::string & geometryArg) = 0;
94 /// save the geometry state in the session manager.
95 virtual void saveGeometry() = 0;
98 virtual void busy(bool) = 0;
100 virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
102 //@{ generic accessor functions
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.
108 BufferView * view() const;
110 /// return the buffer currently shown in this window
111 Buffer * buffer() const;
113 /// return the toolbar for this view
114 Toolbars & getToolbars() { return *toolbars_.get(); }
116 Toolbars const & getToolbars() const { return *toolbars_.get(); }
118 /// return the menubar for this view
119 Menubar & getMenubar() { return *menubar_.get(); }
121 Menubar const & getMenubar() const { return *menubar_.get(); }
123 /// get access to the dialogs
124 Dialogs & getDialogs() { return *dialogs_.get(); }
126 Dialogs const & getDialogs() const { return *dialogs_.get(); }
130 /// load a buffer into the current workarea
131 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
133 /// set a buffer to the current workarea
134 void setBuffer(Buffer * b);
136 /// updates the possible layouts selectable
137 void updateLayoutChoice();
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;
150 /// focus the command buffer (minibuffer)
151 boost::signal<void()> focus_command_buffer;
153 /// display a message in the view
154 virtual void message(docstring const &) = 0;
156 /// clear any temporary message and replace with current status
157 virtual void clearMessage() = 0;
159 /// updates the title of the window
160 void updateWindowTitle();
162 /// updates the tab view
163 virtual void updateTab() = 0;
165 /// reset autosave timer
166 void resetAutosaveTimer();
168 /// dispatch to current BufferView
169 void dispatch(FuncRequest const & cmd);
171 /** redraw \c inset in all the BufferViews in which it is currently
172 * visible. If successful return a pointer to the owning Buffer.
174 Buffer const * const updateInset(InsetBase const *) const;
176 /// returns true if this view has the focus.
177 virtual bool hasFocus() const = 0;
179 /// show the error list to the user
180 void showErrorList(std::string const &);
182 /// connect to signals in the given BufferView
183 void connectBufferView(BufferView & bv);
184 /// disconnect from signals in the given BufferView
185 void disconnectBufferView();
188 /// current work area (screen view of a BufferView).
190 \todo FIXME: there is only one workArea per LyXView for now.
192 frontend::WorkArea * work_area_;
195 boost::scoped_ptr<Menubar> menubar_;
199 * setWindowTitle - set title of window
200 * @param t main window title
201 * @param it iconified (short) title
203 virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
205 /// called on timeout
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_;
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();
238 /// BufferView messages signal connection
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_;
248 /// Bind methods for BufferView messages signal connection
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);
259 /// notify readonly status
260 void showReadonly(bool);
263 /// view's command buffer controller
264 // this has to be declared _after_ lyxfunc_ as its initialization depends
266 typedef boost::scoped_ptr<frontend::ControlCommandBuffer>
269 CommandBufferPtr const controlcommand_;
273 std::vector<int> work_area_ids_;