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 - Qt 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_; }
84 /// \name Generic accessor functions
86 /// The current BufferView refers to the BufferView that has the focus,
87 /// including for example the one that is created when you use the
88 /// advanced search and replace pane.
89 /// \return the currently selected buffer view.
90 BufferView * currentBufferView();
91 BufferView const * currentBufferView() const;
93 /// The document BufferView always refers to the view's main document
94 /// BufferView. So, even if the BufferView in e.g., the advanced
95 /// search and replace pane has the focus.
96 /// \return the current document buffer view.
97 BufferView * documentBufferView();
98 BufferView const * documentBufferView() const;
100 void newDocument(std::string const & filename,
103 /// display a message in the view
104 /// could be called from any thread
105 void message(docstring const &);
107 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
108 /// dispatch command.
109 /// \return true if the \c FuncRequest has been dispatched.
110 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
112 void restartCursor();
113 /// Update the completion popup and the inline completion state.
114 /// If \c start is true, then a new completion might be started.
115 /// If \c keep is true, an active completion will be kept active
116 /// even though the cursor moved. The update flags of \c cur might
118 void updateCompletion(Cursor & cur, bool start, bool keep);
124 void focusInEvent(QFocusEvent * e);
125 /// set a buffer to the current workarea.
126 void setBuffer(Buffer * b); ///< \c Buffer to set.
128 /// load a document into the current workarea.
129 Buffer * loadDocument(
130 support::FileName const & name, ///< File to load.
131 bool tolastfiles = true ///< append to the "Open recent" menu?
134 /// add toolbar, if newline==true, add a toolbar break before the toolbar
135 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
136 void updateStatusBar();
138 /// updates the possible layouts selectable
139 void updateLayoutList();
140 void updateToolbars();
141 QMenu * createPopupMenu();
144 LayoutBox * getLayoutDialog() const;
146 /// hides the workarea and makes sure it is clean
147 bool hideWorkArea(GuiWorkArea * wa);
148 /// closes workarea; close buffer only if no other workareas point to it
149 bool closeWorkArea(GuiWorkArea * wa);
150 /// closes the buffer
151 bool closeBuffer(Buffer & buf);
153 void openDocument(std::string const & filename);
155 void importDocument(std::string const &);
157 /// \name GuiBufferDelegate.
159 void resetAutosaveTimers();
160 void errors(std::string const &, bool from_master = false);
161 void structureChanged();
162 void updateTocItem(std::string const &, DocIterator const &);
166 TocModels & tocModels();
168 /// called on timeout
171 /// check for external change of any opened buffer, mainly for svn usage
172 void checkExternallyModifiedBuffers();
174 /** redraw \c inset in all the BufferViews in which it is currently
175 * visible. If successful return a pointer to the owning Buffer.
177 Buffer const * updateInset(Inset const *);
179 /// \return the \c Workarea associated to \p Buffer
180 /// \retval 0 if no \c WorkArea is found.
181 GuiWorkArea * workArea(Buffer & buffer);
182 /// \return the \c Workarea at index \c index
183 GuiWorkArea * workArea(int index);
185 /// Add a \c WorkArea
186 /// \return the \c Workarea associated to \p Buffer
187 /// \retval 0 if no \c WorkArea is found.
188 GuiWorkArea * addWorkArea(Buffer & buffer);
189 /// \param work_area The current \c WorkArea, or \c NULL
190 void setCurrentWorkArea(GuiWorkArea * work_area);
192 void removeWorkArea(GuiWorkArea * work_area);
193 /// return the current WorkArea (the one that has the focus).
194 GuiWorkArea const * currentWorkArea() const;
195 /// return the current WorkArea (the one that has the focus).
196 GuiWorkArea * currentWorkArea();
198 /// return the current document WorkArea (it may not have the focus).
199 GuiWorkArea const * currentMainWorkArea() const;
200 /// return the current document WorkArea (it may not have the focus).
201 GuiWorkArea * currentMainWorkArea();
203 /// Current ratio between physical pixels and device-independent pixels
204 double pixelRatio() const;
208 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
214 /// clear any temporary message and replace with current status.
219 void updateWindowTitle(GuiWorkArea * wa);
221 void resetWindowTitleAndIconText();
224 void on_currentWorkAreaChanged(GuiWorkArea *);
226 void on_lastWorkAreaRemoved();
228 /// slots to change the icon size
229 void smallSizedIcons();
230 void normalSizedIcons();
231 void bigSizedIcons();
232 void hugeSizedIcons();
233 void giantSizedIcons();
235 /// For completion of autosave or export threads.
236 void processingThreadStarted();
237 void processingThreadFinished();
238 void autoSaveThreadFinished();
240 /// must be called in GUI thread
241 void doShowDialog(QString const & qname, QString const & qdata,
244 /// must be called from GUI thread
245 void updateStatusBarMessage(QString const & str);
246 void clearMessageText();
249 /// Open given child document in current buffer directory.
250 void openChildDocument(std::string const & filename);
251 /// Close current document buffer.
253 /// Close all document buffers.
254 bool closeBufferAll();
256 TabWorkArea * addTabWorkArea();
258 /// connect to signals in the given BufferView
259 void connectBufferView(BufferView & bv);
260 /// disconnect from signals in the given BufferView
261 void disconnectBufferView();
262 /// connect to signals in the given buffer
263 void connectBuffer(Buffer & buf);
264 /// disconnect from signals in the given buffer
265 void disconnectBuffer();
267 void dragEnterEvent(QDragEnterEvent * ev);
269 void dropEvent(QDropEvent * ev);
270 /// make sure we quit cleanly
271 void closeEvent(QCloseEvent * e);
273 void showEvent(QShowEvent *);
275 /// in order to catch Tab key press.
276 bool event(QEvent * e);
277 bool focusNextPrevChild(bool);
280 bool goToFileRow(std::string const & argument);
283 struct GuiViewPrivate;
288 /// dialogs for this view
294 /// Hide all visible dialogs
295 void hideAll() const;
297 /// Update all visible dialogs.
299 * Check the status of all visible dialogs and disable or reenable
300 * them as appropriate.
302 * Disabling is needed for example when a dialog is open and the
303 * cursor moves to a position where the corresponding inset is not
306 void updateDialogs();
308 /** Show dialog could be called from arbitrary threads.
309 \param name == "bibtex", "citation" etc; an identifier used to
310 launch a particular dialog.
311 \param data is a string representation of the Inset contents.
312 It is often little more than the output from Inset::write.
313 It is passed to, and parsed by, the frontend dialog.
314 Several of these dialogs do not need any data,
315 so it defaults to string().
316 \param inset ownership is _not_ passed to the frontend dialog.
317 It is stored internally and used by the kernel to ascertain
318 what to do with the FuncRequest dispatched from the frontend
319 dialog on 'Apply'; should it be used to create a new inset at
320 the current cursor position or modify an existing, 'open' inset?
322 void showDialog(std::string const & name,
323 std::string const & data, Inset * inset = 0);
325 /** \param name == "citation", "bibtex" etc; an identifier used
326 to reset the contents of a particular dialog with \param data.
327 See the comments to 'show', above.
329 void updateDialog(std::string const & name, std::string const & data);
331 /** All Dialogs of the given \param name will be closed if they are
332 connected to the given \param inset.
334 void hideDialog(std::string const & name, Inset * inset);
336 void disconnectDialog(std::string const & name);
339 /// Saves the layout and geometry of the window
340 void saveLayout() const;
341 /// Saves the settings of toolbars and all dialogs
342 void saveUISettings() const;
344 bool restoreLayout();
346 GuiToolbar * toolbar(std::string const & name);
348 void constructToolbars();
352 void initToolbar(std::string const & name);
354 bool lfunUiToggle(std::string const & ui_component);
356 void toggleFullScreen();
358 void insertLyXFile(docstring const & fname);
360 void insertPlaintextFile(docstring const & fname,
362 /// Open Export As ... dialog. \p iformat is the format the
363 /// filter is initially set to.
364 bool exportBufferAs(Buffer & b, docstring const & iformat);
367 enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY };
368 /// Save a buffer as a new file.
370 Write a buffer to a new file name and rename the buffer
371 according to the new file name.
373 This function is e.g. used by menu callbacks and
374 LFUN_BUFFER_WRITE_AS.
376 If 'newname' is empty, the user is asked via a
377 dialog for the buffer's new name and location.
379 If 'newname' is non-empty and has an absolute path, that is used.
380 Otherwise the base directory of the buffer is used as the base
381 for any relative path in 'newname'.
383 \p kind controls what is done besides the pure renaming:
384 * LV_WRITE_AS => The buffer is written without version control actions.
385 * LV_VC_RENAME => The file is renamed in version control.
386 * LV_VC_COPY => The file is copied in version control.
388 bool renameBuffer(Buffer & b, docstring const & newname,
389 RenameKind kind = LV_WRITE_AS);
391 bool saveBuffer(Buffer & b);
392 /// save and rename buffer to fn. If fn is empty, the buffer
393 /// is just saved as the filename it already has.
394 bool saveBuffer(Buffer & b, support::FileName const & fn);
395 /// closes a workarea, if close_buffer is true the buffer will
396 /// also be released, otherwise the buffer will be hidden.
397 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
398 /// closes the tabworkarea and all tabs. If we are in a close event,
399 /// all buffers will be closed, otherwise they will be hidden.
400 bool closeTabWorkArea(TabWorkArea * twa);
401 /// gives the user the possibility to save his work
402 /// or to discard the changes. If hiding is true, the
403 /// document will be reloaded.
404 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
405 /// closes all workareas
406 bool closeWorkAreaAll();
407 /// write all open workareas into the session file
408 void writeSession() const;
409 /// is the buffer in this workarea also shown in another tab ?
410 /// This tab can either be in the same view or in another one.
411 bool inMultiTabs(GuiWorkArea * wa);
412 /// is the buffer shown in some other view ?
413 bool inOtherView(Buffer & buf);
415 enum NextOrPrevious {
420 void gotoNextOrPreviousBuffer(NextOrPrevious np);
422 /// Is the dialog currently visible?
423 bool isDialogVisible(std::string const & name) const;
425 Dialog * findOrBuild(std::string const & name, bool hide_it);
427 Dialog * build(std::string const & name);
429 bool reloadBuffer(Buffer & buffer);
431 void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
433 void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
440 /// flag to avoid two concurrent close events.
442 /// if the view is busy the cursor shouldn't blink for instance.
443 /// This counts the number of times more often we called
444 /// setBusy(true) compared to setBusy(false), so we can nest
445 /// functions that call setBusy;
450 } // namespace frontend