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>
30 namespace support { class FileName; }
45 class ControlCommandBuffer;
46 } // namespace frontend
50 * LyXView - main LyX window
52 * This class represents the main LyX window and provides
53 * accessor functions to its content.
55 * The eventual intention is that LyX will support a number
56 * of containing LyXViews. Currently a lot of code still
57 * relies on there being a single top-level view.
59 * Additionally we would like to support multiple views
60 * in a single LyXView.
62 class LyXView : public boost::signals::trackable, boost::noncopyable {
69 int const id() const { return id_; }
71 virtual void close() = 0;
73 virtual void setFocus() = 0;
75 std::vector<int> const & workAreaIds() const { return work_area_ids_; }
77 /// FIXME: rename to setCurrentWorkArea()
78 void setWorkArea(frontend::WorkArea * work_area);
80 /// return the current WorkArea (the one that has the focus).
81 frontend::WorkArea const * currentWorkArea() const;
82 /// FIXME: This non-const access is needed because of
83 /// a mis-designed \c ControlSpellchecker.
84 frontend::WorkArea * currentWorkArea();
87 * This is called after the concrete view has been created.
88 * We have to have the toolbar and the other stuff created
89 * before we can populate it with this call.
91 virtual void init() = 0;
96 HorizontallyMaximized,
101 virtual void setGeometry(
106 unsigned int iconSizeXY,
107 const std::string & geometryArg) = 0;
109 /// save the geometry state in the session manager.
110 virtual void saveGeometry() = 0;
113 virtual void busy(bool) = 0;
115 virtual Toolbars::ToolbarPtr makeToolbar(ToolbarInfo const & tbinfo, bool newline) = 0;
117 //@{ generic accessor functions
119 /** return the current buffer view
120 Returned as a shared_ptr so that anything wanting to cache the
121 buffer view can do so safely using a boost::weak_ptr.
123 BufferView * view() const;
125 /// return the buffer currently shown in this window
126 Buffer * buffer() const;
128 /// return the toolbar for this view
129 Toolbars & getToolbars() { return *toolbars_.get(); }
131 Toolbars const & getToolbars() const { return *toolbars_.get(); }
133 /// return the menubar for this view
134 Menubar & getMenubar() { return *menubar_.get(); }
136 Menubar const & getMenubar() const { return *menubar_.get(); }
138 /// get access to the dialogs
139 Dialogs & getDialogs() { return *dialogs_.get(); }
141 Dialogs const & getDialogs() const { return *dialogs_.get(); }
145 /// load a buffer into the current workarea
146 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
148 /// set a buffer to the current workarea
149 void setBuffer(Buffer * b);
151 /// updates the possible layouts selectable
152 void updateLayoutChoice();
154 /// update the toolbar
155 void updateToolbars();
156 /// get toolbar state
157 ToolbarInfo::Flags getToolbarState(std::string const & name);
158 /// toggle toolbar state
159 void toggleToolbarState(std::string const & name);
160 /// update the menubar
161 void updateMenubar();
162 /// update the status bar
163 virtual void updateStatusBar() = 0;
165 /// focus the command buffer (minibuffer)
166 boost::signal<void()> focus_command_buffer;
168 /// display a message in the view
169 virtual void message(docstring const &) = 0;
171 /// clear any temporary message and replace with current status
172 virtual void clearMessage() = 0;
174 /// updates the title of the window
175 void updateWindowTitle();
177 /// updates the tab view
178 virtual void updateTab() = 0;
180 /// reset autosave timer
181 void resetAutosaveTimer();
183 /// dispatch to current BufferView
184 void dispatch(FuncRequest const & cmd);
186 /** redraw \c inset in all the BufferViews in which it is currently
187 * visible. If successful return a pointer to the owning Buffer.
189 Buffer const * const updateInset(InsetBase const *) const;
191 /// returns true if this view has the focus.
192 virtual bool hasFocus() const = 0;
194 /// show the error list to the user
195 void showErrorList(std::string const &);
197 /// connect to signals in the given BufferView
198 void connectBufferView(BufferView & bv);
199 /// disconnect from signals in the given BufferView
200 void disconnectBufferView();
203 /// current work area (screen view of a BufferView).
205 \todo FIXME: there is only one workArea per LyXView for now.
207 frontend::WorkArea * work_area_;
210 boost::scoped_ptr<Menubar> menubar_;
214 * setWindowTitle - set title of window
215 * @param t main window title
216 * @param it iconified (short) title
218 virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
220 /// called on timeout
224 boost::scoped_ptr<Toolbars> toolbars_;
225 /// auto-saving of buffers
226 boost::scoped_ptr<Timeout> const autosave_timeout_;
227 /// our function handler
228 boost::scoped_ptr<LyXFunc> lyxfunc_;
229 /// dialogs for this view
230 boost::scoped_ptr<Dialogs> dialogs_;
232 /// buffer changed signal connection
233 boost::signals::connection bufferChangedConnection_;
234 /// buffer structure changed signal connection
235 boost::signals::connection bufferStructureChangedConnection_;
236 /// buffer errors signal connection
237 boost::signals::connection errorsConnection_;
238 /// buffer messages signal connection
239 boost::signals::connection messageConnection_;
240 /// buffer busy status signal connection
241 boost::signals::connection busyConnection_;
242 /// buffer title changed signal connection
243 boost::signals::connection titleConnection_;
244 /// buffer reset timers signal connection
245 boost::signals::connection timerConnection_;
246 /// buffer readonly status changed signal connection
247 boost::signals::connection readonlyConnection_;
248 /// buffer closing signal connection
249 boost::signals::connection closingConnection_;
250 /// connect to signals in the given buffer
251 void connectBuffer(Buffer & buf);
252 /// disconnect from signals in the given buffer
253 void disconnectBuffer();
255 /// BufferView messages signal connection
257 boost::signals::connection message_connection_;
258 boost::signals::connection show_dialog_connection_;
259 boost::signals::connection show_dialog_with_data_connection_;
260 boost::signals::connection show_inset_dialog_connection_;
261 boost::signals::connection update_dialog_connection_;
262 boost::signals::connection layout_changed_connection_;
265 /// Bind methods for BufferView messages signal connection
267 void showDialog(std::string const & name);
268 void showDialogWithData(std::string const & name,
269 std::string const & data);
270 void showInsetDialog(std::string const & name,
271 std::string const & data, InsetBase * inset);
272 void updateDialog(std::string const & name,
273 std::string const & data);
276 /// notify readonly status
277 void showReadonly(bool);
283 /// view's command buffer controller
284 // this has to be declared _after_ lyxfunc_ as its initialization depends
286 typedef boost::scoped_ptr<frontend::ControlCommandBuffer>
289 CommandBufferPtr const controlcommand_;
293 std::vector<int> work_area_ids_;