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; }
42 class ControlCommandBuffer;
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 virtual void setFocus() = 0;
73 std::vector<int> const & workAreaIds() const { return work_area_ids_; }
75 /// FIXME: rename to setCurrentWorkArea()
76 void setWorkArea(WorkArea * work_area);
78 /// return the current WorkArea (the one that has the focus).
79 WorkArea const * currentWorkArea() const;
80 /// FIXME: This non-const access is needed because of
81 /// a mis-designed \c ControlSpellchecker.
82 WorkArea * currentWorkArea();
85 * This is called after the concrete view has been created.
86 * We have to have the toolbar and the other stuff created
87 * before we can populate it with this call.
89 virtual void init() = 0;
94 HorizontallyMaximized,
99 virtual void setGeometry(
104 unsigned int iconSizeXY,
105 const std::string & geometryArg) = 0;
107 /// save the geometry state in the session manager.
108 virtual void saveGeometry() = 0;
111 virtual void busy(bool) = 0;
113 virtual Toolbars::ToolbarPtr makeToolbar(ToolbarInfo const & tbinfo, bool newline) = 0;
115 //@{ generic accessor functions
117 /** return the current buffer view
118 Returned as a shared_ptr so that anything wanting to cache the
119 buffer view can do so safely using a boost::weak_ptr.
121 BufferView * view() const;
123 /// return the buffer currently shown in this window
124 Buffer * buffer() const;
126 /// return the toolbar for this view
127 Toolbars & getToolbars() { return *toolbars_.get(); }
129 Toolbars const & getToolbars() const { return *toolbars_.get(); }
131 /// return the menubar for this view
132 Menubar & getMenubar() { return *menubar_.get(); }
134 Menubar const & getMenubar() const { return *menubar_.get(); }
136 /// get access to the dialogs
137 Dialogs & getDialogs() { return *dialogs_.get(); }
139 Dialogs const & getDialogs() const { return *dialogs_.get(); }
143 /// load a buffer into the current workarea.
144 bool loadLyXFile(support::FileName const & name, ///< File to load.
145 bool tolastfiles = true, ///< append to the "Open recent" menu?
146 bool child_document = false, ///< Is this a child document?
147 bool auto_open = false); ///< Is this being opened by LyX itself?
149 /// set a buffer to the current workarea.
150 void setBuffer(Buffer * b, ///< \c Buffer to set.
151 bool child_document = false); ///< Is this a child document?
153 /// updates the possible layouts selectable
154 void updateLayoutChoice();
156 /// update the toolbar
157 void updateToolbars();
159 ToolbarInfo * getToolbarInfo(std::string const & name);
160 /// toggle toolbar state
161 void toggleToolbarState(std::string const & name, bool allowauto);
162 /// update the menubar
163 void updateMenubar();
164 /// update the status bar
165 virtual void updateStatusBar() = 0;
167 /// focus the command buffer (minibuffer)
168 boost::signal<void()> focus_command_buffer;
170 /// display a message in the view
171 virtual void message(docstring const &) = 0;
173 /// clear any temporary message and replace with current status
174 virtual void clearMessage() = 0;
176 /// updates the title of the window
177 void updateWindowTitle();
179 /// updates the tab view
180 virtual void updateTab() = 0;
182 /// reset autosave timer
183 void resetAutosaveTimer();
185 /// dispatch to current BufferView
186 void dispatch(FuncRequest const & cmd);
188 /** redraw \c inset in all the BufferViews in which it is currently
189 * visible. If successful return a pointer to the owning Buffer.
191 Buffer const * const updateInset(Inset const *) const;
193 /// returns true if this view has the focus.
194 virtual bool hasFocus() const = 0;
196 /// show the error list to the user
197 void showErrorList(std::string const &);
199 /// connect to signals in the given BufferView
200 void connectBufferView(BufferView & bv);
201 /// disconnect from signals in the given BufferView
202 void disconnectBufferView();
205 /// current work area (screen view of a BufferView).
207 \todo FIXME: there is only one workArea per LyXView for now.
209 frontend::WorkArea * work_area_;
212 boost::scoped_ptr<Menubar> menubar_;
216 * setWindowTitle - set title of window
217 * @param t main window title
218 * @param it iconified (short) title
220 virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
222 /// called on timeout
226 boost::scoped_ptr<Toolbars> toolbars_;
227 /// auto-saving of buffers
228 boost::scoped_ptr<Timeout> const autosave_timeout_;
229 /// our function handler
230 boost::scoped_ptr<LyXFunc> lyxfunc_;
231 /// dialogs for this view
232 boost::scoped_ptr<Dialogs> dialogs_;
234 /// buffer changed signal connection
235 boost::signals::connection bufferChangedConnection_;
236 /// buffer structure changed signal connection
237 boost::signals::connection bufferStructureChangedConnection_;
238 /// buffer errors signal connection
239 boost::signals::connection errorsConnection_;
240 /// buffer messages signal connection
241 boost::signals::connection messageConnection_;
242 /// buffer busy status signal connection
243 boost::signals::connection busyConnection_;
244 /// buffer title changed signal connection
245 boost::signals::connection titleConnection_;
246 /// buffer reset timers signal connection
247 boost::signals::connection timerConnection_;
248 /// buffer readonly status changed signal connection
249 boost::signals::connection readonlyConnection_;
250 /// buffer closing signal connection
251 boost::signals::connection closingConnection_;
252 /// connect to signals in the given buffer
253 void connectBuffer(Buffer & buf);
254 /// disconnect from signals in the given buffer
255 /// NOTE: Do not call this unless you really want no buffer
256 /// to be connected---for example, when closing the last open
257 /// buffer. If you are switching buffers, just call
258 /// connectBuffer(), and the old buffer will be disconnected
259 /// automatically. This ensures that we do not leave LyX in a
260 /// state in which no buffer is connected.
261 void disconnectBuffer();
263 /// BufferView messages signal connection
265 boost::signals::connection message_connection_;
266 boost::signals::connection show_dialog_connection_;
267 boost::signals::connection show_dialog_with_data_connection_;
268 boost::signals::connection show_inset_dialog_connection_;
269 boost::signals::connection update_dialog_connection_;
270 boost::signals::connection layout_changed_connection_;
273 /// Bind methods for BufferView messages signal connection
275 void showDialog(std::string const & name);
276 void showDialogWithData(std::string const & name,
277 std::string const & data);
278 void showInsetDialog(std::string const & name,
279 std::string const & data, Inset * inset);
280 void updateDialog(std::string const & name,
281 std::string const & data);
284 /// notify readonly status
285 void showReadonly(bool);
291 /// view's command buffer controller
292 // this has to be declared _after_ lyxfunc_ as its initialization depends
294 typedef boost::scoped_ptr<ControlCommandBuffer>
297 CommandBufferPtr const controlcommand_;
301 std::vector<int> work_area_ids_;
304 } // namespace frontend