4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjornes
9 * \author Abdelrazak Younes
10 * \author Peter Kümmel
12 * Full author contact details are available in file CREDITS.
18 #include "frontends/Delegates.h"
20 #include "support/strfwd.h"
22 #include <QMainWindow>
25 class QDragEnterEvent;
33 namespace support { class FileName; }
54 * GuiView - Qt4 main LyX window
56 * This class represents the main LyX window and provides
57 * accessor functions to its content.
59 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
60 * is deleted. This might be useful for closing other dialogs
61 * depending on a given GuiView.
63 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
64 public GuiBufferDelegate
69 /// create a main window of the given dimensions
74 /// closes the view such that the view knows that is closed
75 /// programmatically and not by the user clicking the x.
76 bool closeScheduled();
78 int id() const { return id_; }
85 /// \name Generic accessor functions
87 /// The current BufferView refers to the BufferView that has the focus,
88 /// including for example the one that is created when you use the
89 /// advanced search and replace pane.
90 /// \return the currently selected buffer view.
91 BufferView * currentBufferView();
92 BufferView const * currentBufferView() const;
94 /// The document BufferView always refers to the view's main document
95 /// BufferView. So, even if the BufferView in e.g., the advanced
96 /// search and replace pane has the focus.
97 /// \return the current document buffer view.
98 BufferView * documentBufferView();
99 BufferView const * documentBufferView() const;
101 void newDocument(std::string const & filename,
104 /// display a message in the view
105 /// could be called from any thread
106 void message(docstring const &);
108 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
109 /// dispatch command.
110 /// \return true if the \c FuncRequest has been dispatched.
111 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
113 void restartCursor();
114 /// Update the completion popup and the inline completion state.
115 /// If \c start is true, then a new completion might be started.
116 /// If \c keep is true, an active completion will be kept active
117 /// even though the cursor moved. The update flags of \c cur might
119 void updateCompletion(Cursor & cur, bool start, bool keep);
125 void focusInEvent(QFocusEvent * e);
126 /// set a buffer to the current workarea.
127 void setBuffer(Buffer * b); ///< \c Buffer to set.
129 /// load a document into the current workarea.
130 Buffer * loadDocument(
131 support::FileName const & name, ///< File to load.
132 bool tolastfiles = true ///< append to the "Open recent" menu?
135 /// add toolbar, if newline==true, add a toolbar break before the toolbar
136 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
137 void updateStatusBar();
139 /// updates the possible layouts selectable
140 void updateLayoutList();
141 void updateToolbars();
142 QMenu * createPopupMenu();
145 LayoutBox * getLayoutDialog() const;
147 /// hides the workarea and makes sure it is clean
148 bool hideWorkArea(GuiWorkArea * wa);
149 /// closes the workarea
150 bool closeWorkArea(GuiWorkArea * wa);
151 /// closes the buffer
152 bool closeBuffer(Buffer & buf);
154 void openDocument(std::string const & filename);
156 void importDocument(std::string const &);
158 /// \name GuiBufferDelegate.
160 void resetAutosaveTimers();
161 void errors(std::string const &, bool from_master = false);
162 void structureChanged();
163 void updateTocItem(std::string const &, DocIterator const &);
167 TocModels & tocModels();
169 /// called on timeout
172 /// check for external change of any opened buffer, mainly for svn usage
173 void checkExternallyModifiedBuffers();
175 /** redraw \c inset in all the BufferViews in which it is currently
176 * visible. If successful return a pointer to the owning Buffer.
178 Buffer const * updateInset(Inset const *);
180 /// \return the \c Workarea associated to \p Buffer
181 /// \retval 0 if no \c WorkArea is found.
182 GuiWorkArea * workArea(Buffer & buffer);
184 /// Add a \c WorkArea
185 /// \return the \c Workarea associated to \p Buffer
186 /// \retval 0 if no \c WorkArea is found.
187 GuiWorkArea * addWorkArea(Buffer & buffer);
188 /// \param work_area The current \c WorkArea, or \c NULL
189 void setCurrentWorkArea(GuiWorkArea * work_area);
191 void removeWorkArea(GuiWorkArea * work_area);
192 /// return the current WorkArea (the one that has the focus).
193 GuiWorkArea const * currentWorkArea() const;
194 /// return the current WorkArea (the one that has the focus).
195 GuiWorkArea * currentWorkArea();
197 /// return the current document WorkArea (it may not have the focus).
198 GuiWorkArea const * currentMainWorkArea() const;
199 /// return the current document WorkArea (it may not have the focus).
200 GuiWorkArea * currentMainWorkArea();
204 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
208 /// clear any temporary message and replace with current status.
213 void updateWindowTitle(GuiWorkArea * wa);
215 void resetWindowTitleAndIconText();
218 void on_currentWorkAreaChanged(GuiWorkArea *);
220 void on_lastWorkAreaRemoved();
222 /// slots to change the icon size
223 void smallSizedIcons();
224 void normalSizedIcons();
225 void bigSizedIcons();
227 /// For completion of autosave or exporrt threads.
228 void threadFinished();
230 /// must be called in GUI thread
231 void doShowDialog(QString const & qname, QString const & qdata,
234 /// must be called from GUI thread
235 void updateStatusBarMessage(QString const & str);
236 void clearMessageText();
239 /// Open given child document in current buffer directory.
240 void openChildDocument(std::string const & filename);
241 /// Close current document buffer.
243 /// Close all document buffers.
244 bool closeBufferAll();
246 TabWorkArea * addTabWorkArea();
248 /// connect to signals in the given BufferView
249 void connectBufferView(BufferView & bv);
250 /// disconnect from signals in the given BufferView
251 void disconnectBufferView();
252 /// connect to signals in the given buffer
253 void connectBuffer(Buffer & buf);
254 /// disconnect from signals in the given buffer
255 void disconnectBuffer();
257 void dragEnterEvent(QDragEnterEvent * ev);
259 void dropEvent(QDropEvent * ev);
260 /// make sure we quit cleanly
261 void closeEvent(QCloseEvent * e);
263 void showEvent(QShowEvent *);
265 /// in order to catch Tab key press.
266 bool event(QEvent * e);
267 bool focusNextPrevChild(bool);
270 bool goToFileRow(std::string const & argument);
273 struct GuiViewPrivate;
278 /// dialogs for this view
284 /// Hide all visible dialogs
285 void hideAll() const;
287 /// Update all visible dialogs.
289 * Check the status of all visible dialogs and disable or reenable
290 * them as appropriate.
292 * Disabling is needed for example when a dialog is open and the
293 * cursor moves to a position where the corresponding inset is not
296 void updateDialogs();
298 /** Show dialog could be called from arbitrary threads.
299 \param name == "bibtex", "citation" etc; an identifier used to
300 launch a particular dialog.
301 \param data is a string representation of the Inset contents.
302 It is often little more than the output from Inset::write.
303 It is passed to, and parsed by, the frontend dialog.
304 Several of these dialogs do not need any data,
305 so it defaults to string().
306 \param inset ownership is _not_ passed to the frontend dialog.
307 It is stored internally and used by the kernel to ascertain
308 what to do with the FuncRequest dispatched from the frontend
309 dialog on 'Apply'; should it be used to create a new inset at
310 the current cursor position or modify an existing, 'open' inset?
312 void showDialog(std::string const & name,
313 std::string const & data, Inset * inset = 0);
315 /** \param name == "citation", "bibtex" etc; an identifier used
316 to reset the contents of a particular dialog with \param data.
317 See the comments to 'show', above.
319 void updateDialog(std::string const & name, std::string const & data);
321 /** All Dialogs of the given \param name will be closed if they are
322 connected to the given \param inset.
324 void hideDialog(std::string const & name, Inset * inset);
326 void disconnectDialog(std::string const & name);
330 void saveLayout() const;
332 bool restoreLayout();
334 GuiToolbar * toolbar(std::string const & name);
336 void constructToolbars();
340 bool lfunUiToggle(std::string const & ui_component);
342 void toggleFullScreen();
344 void insertLyXFile(docstring const & fname);
346 void insertPlaintextFile(docstring const & fname,
349 /// Save a buffer as a new file.
351 Write a buffer to a new file name and rename the buffer
352 according to the new file name.
354 This function is e.g. used by menu callbacks and
355 LFUN_BUFFER_WRITE_AS.
357 If 'newname' is empty, the user is asked via a
358 dialog for the buffer's new name and location.
360 If 'newname' is non-empty and has an absolute path, that is used.
361 Otherwise the base directory of the buffer is used as the base
362 for any relative path in 'newname'.
364 bool renameBuffer(Buffer & b, docstring const & newname);
366 bool saveBuffer(Buffer & b);
367 /// closes a workarea, if close_buffer is true the buffer will
368 /// also be released, otherwise the buffer will be hidden.
369 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
370 /// closes the tabworkarea and all tabs. If we are in a close event,
371 /// all buffers will be closed, otherwise they will be hidden.
372 bool closeTabWorkArea(TabWorkArea * twa);
373 /// gives the user the possibility to save his work
374 /// or to discard the changes. If hiding is true, the
375 /// document will be reloaded.
376 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
377 /// closes all workareas
378 bool closeWorkAreaAll();
379 /// write all open workareas into the session file
380 void writeSession() const;
381 /// is the buffer in this workarea also shown in another tab ?
382 /// This tab can either be in the same view or in another one.
383 bool inMultiTabs(GuiWorkArea * wa);
384 /// is the buffer in this workarea also shown in another view ?
385 bool inMultiViews(GuiWorkArea * wa);
387 enum NextOrPrevious {
392 void gotoNextOrPreviousBuffer(NextOrPrevious np);
394 /// Is the dialog currently visible?
395 bool isDialogVisible(std::string const & name) const;
397 Dialog * findOrBuild(std::string const & name, bool hide_it);
399 Dialog * build(std::string const & name);
403 void dispatchVC(FuncRequest const & cmd);
410 /// flag to avoid two concurrent close events.
412 /// if the view is busy the cursor shouldn't blink for instance.
416 } // namespace frontend