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_; }
86 /// \name Generic accessor functions
88 /// The current BufferView refers to the BufferView that has the focus,
89 /// including for example the one that is created when you use the
90 /// advanced search and replace pane.
91 /// \return the currently selected buffer view.
92 BufferView * currentBufferView();
93 BufferView const * currentBufferView() const;
95 /// The document BufferView always refers to the view's main document
96 /// BufferView. So, even if the BufferView in e.g., the advanced
97 /// search and replace pane has the focus.
98 /// \return the current document buffer view.
99 BufferView * documentBufferView();
100 BufferView const * documentBufferView() const;
102 void newDocument(std::string const & filename,
105 /// display a message in the view
106 /// could be called from any thread
107 void message(docstring const &);
109 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
110 /// dispatch command.
111 /// \return true if the \c FuncRequest has been dispatched.
112 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
114 void restartCursor();
115 /// Update the completion popup and the inline completion state.
116 /// If \c start is true, then a new completion might be started.
117 /// If \c keep is true, an active completion will be kept active
118 /// even though the cursor moved. The update flags of \c cur might
120 void updateCompletion(Cursor & cur, bool start, bool keep);
126 void focusInEvent(QFocusEvent * e);
127 /// set a buffer to the current workarea.
128 void setBuffer(Buffer * b); ///< \c Buffer to set.
130 /// load a document into the current workarea.
131 Buffer * loadDocument(
132 support::FileName const & name, ///< File to load.
133 bool tolastfiles = true ///< append to the "Open recent" menu?
136 /// add toolbar, if newline==true, add a toolbar break before the toolbar
137 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
138 void updateStatusBar();
140 /// updates the possible layouts selectable
141 void updateLayoutList();
142 void updateToolbars();
143 QMenu * createPopupMenu();
146 LayoutBox * getLayoutDialog() const;
148 /// hides the workarea and makes sure it is clean
149 bool hideWorkArea(GuiWorkArea * wa);
150 /// closes the workarea
151 bool closeWorkArea(GuiWorkArea * wa);
152 /// closes the buffer
153 bool closeBuffer(Buffer & buf);
155 void openDocument(std::string const & filename);
157 void importDocument(std::string const &);
159 /// \name GuiBufferDelegate.
161 void resetAutosaveTimers();
162 void errors(std::string const &, bool from_master = false);
163 void structureChanged();
164 void updateTocItem(std::string const &, DocIterator const &);
168 TocModels & tocModels();
170 /// called on timeout
173 /// check for external change of any opened buffer, mainly for svn usage
174 void checkExternallyModifiedBuffers();
176 /** redraw \c inset in all the BufferViews in which it is currently
177 * visible. If successful return a pointer to the owning Buffer.
179 Buffer const * updateInset(Inset const *);
181 /// \return the \c Workarea associated to \p Buffer
182 /// \retval 0 if no \c WorkArea is found.
183 GuiWorkArea * workArea(Buffer & buffer);
184 /// \return the \c Workarea at index \c index
185 GuiWorkArea * workArea(int index);
187 /// Add a \c WorkArea
188 /// \return the \c Workarea associated to \p Buffer
189 /// \retval 0 if no \c WorkArea is found.
190 GuiWorkArea * addWorkArea(Buffer & buffer);
191 /// \param work_area The current \c WorkArea, or \c NULL
192 void setCurrentWorkArea(GuiWorkArea * work_area);
194 void removeWorkArea(GuiWorkArea * work_area);
195 /// return the current WorkArea (the one that has the focus).
196 GuiWorkArea const * currentWorkArea() const;
197 /// return the current WorkArea (the one that has the focus).
198 GuiWorkArea * currentWorkArea();
200 /// return the current document WorkArea (it may not have the focus).
201 GuiWorkArea const * currentMainWorkArea() const;
202 /// return the current document WorkArea (it may not have the focus).
203 GuiWorkArea * currentMainWorkArea();
207 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
211 /// clear any temporary message and replace with current status.
216 void updateWindowTitle(GuiWorkArea * wa);
218 void resetWindowTitleAndIconText();
221 void on_currentWorkAreaChanged(GuiWorkArea *);
223 void on_lastWorkAreaRemoved();
225 /// slots to change the icon size
226 void smallSizedIcons();
227 void normalSizedIcons();
228 void bigSizedIcons();
230 /// For completion of autosave or export threads.
231 void processingThreadStarted();
232 void processingThreadFinished(bool show_errors);
233 void processingThreadFinished();
234 void autoSaveThreadFinished();
236 /// must be called in GUI thread
237 void doShowDialog(QString const & qname, QString const & qdata,
240 /// must be called from GUI thread
241 void updateStatusBarMessage(QString const & str);
242 void clearMessageText();
245 /// Open given child document in current buffer directory.
246 void openChildDocument(std::string const & filename);
247 /// Close current document buffer.
249 /// Close all document buffers.
250 bool closeBufferAll();
252 TabWorkArea * addTabWorkArea();
254 /// connect to signals in the given BufferView
255 void connectBufferView(BufferView & bv);
256 /// disconnect from signals in the given BufferView
257 void disconnectBufferView();
258 /// connect to signals in the given buffer
259 void connectBuffer(Buffer & buf);
260 /// disconnect from signals in the given buffer
261 void disconnectBuffer();
263 void dragEnterEvent(QDragEnterEvent * ev);
265 void dropEvent(QDropEvent * ev);
266 /// make sure we quit cleanly
267 void closeEvent(QCloseEvent * e);
269 void showEvent(QShowEvent *);
271 /// in order to catch Tab key press.
272 bool event(QEvent * e);
273 bool focusNextPrevChild(bool);
276 bool goToFileRow(std::string const & argument);
279 struct GuiViewPrivate;
284 /// dialogs for this view
290 /// Hide all visible dialogs
291 void hideAll() const;
293 /// Update all visible dialogs.
295 * Check the status of all visible dialogs and disable or reenable
296 * them as appropriate.
298 * Disabling is needed for example when a dialog is open and the
299 * cursor moves to a position where the corresponding inset is not
302 void updateDialogs();
304 /** Show dialog could be called from arbitrary threads.
305 \param name == "bibtex", "citation" etc; an identifier used to
306 launch a particular dialog.
307 \param data is a string representation of the Inset contents.
308 It is often little more than the output from Inset::write.
309 It is passed to, and parsed by, the frontend dialog.
310 Several of these dialogs do not need any data,
311 so it defaults to string().
312 \param inset ownership is _not_ passed to the frontend dialog.
313 It is stored internally and used by the kernel to ascertain
314 what to do with the FuncRequest dispatched from the frontend
315 dialog on 'Apply'; should it be used to create a new inset at
316 the current cursor position or modify an existing, 'open' inset?
318 void showDialog(std::string const & name,
319 std::string const & data, Inset * inset = 0);
321 /** \param name == "citation", "bibtex" etc; an identifier used
322 to reset the contents of a particular dialog with \param data.
323 See the comments to 'show', above.
325 void updateDialog(std::string const & name, std::string const & data);
327 /** All Dialogs of the given \param name will be closed if they are
328 connected to the given \param inset.
330 void hideDialog(std::string const & name, Inset * inset);
332 void disconnectDialog(std::string const & name);
335 /// Saves the layout and geometry of the window
336 void saveLayout() const;
337 /// Saves the settings of toolbars and all dialogs
338 void saveUISettings() const;
340 bool restoreLayout();
342 GuiToolbar * toolbar(std::string const & name);
344 void constructToolbars();
348 bool lfunUiToggle(std::string const & ui_component);
350 void toggleFullScreen();
352 void insertLyXFile(docstring const & fname);
354 void insertPlaintextFile(docstring const & fname,
357 /// Save a buffer as a new file.
359 Write a buffer to a new file name and rename the buffer
360 according to the new file name.
362 This function is e.g. used by menu callbacks and
363 LFUN_BUFFER_WRITE_AS.
365 If 'newname' is empty, the user is asked via a
366 dialog for the buffer's new name and location.
368 If 'newname' is non-empty and has an absolute path, that is used.
369 Otherwise the base directory of the buffer is used as the base
370 for any relative path in 'newname'.
372 bool renameBuffer(Buffer & b, docstring const & newname);
374 bool saveBuffer(Buffer & b);
375 /// save and rename buffer to fn. If fn is empty, the buffer
376 /// is just saved as the filename it already has.
377 bool saveBuffer(Buffer & b, support::FileName const & fn);
378 /// closes a workarea, if close_buffer is true the buffer will
379 /// also be released, otherwise the buffer will be hidden.
380 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
381 /// closes the tabworkarea and all tabs. If we are in a close event,
382 /// all buffers will be closed, otherwise they will be hidden.
383 bool closeTabWorkArea(TabWorkArea * twa);
384 /// gives the user the possibility to save his work
385 /// or to discard the changes. If hiding is true, the
386 /// document will be reloaded.
387 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
388 /// closes all workareas
389 bool closeWorkAreaAll();
390 /// write all open workareas into the session file
391 void writeSession() const;
392 /// is the buffer in this workarea also shown in another tab ?
393 /// This tab can either be in the same view or in another one.
394 bool inMultiTabs(GuiWorkArea * wa);
395 /// is the buffer shown in some other view ?
396 bool inOtherView(Buffer & buf);
398 enum NextOrPrevious {
403 void gotoNextOrPreviousBuffer(NextOrPrevious np);
405 /// Is the dialog currently visible?
406 bool isDialogVisible(std::string const & name) const;
408 Dialog * findOrBuild(std::string const & name, bool hide_it);
410 Dialog * build(std::string const & name);
412 bool reloadBuffer(Buffer & buffer);
414 void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
416 void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
423 /// flag to avoid two concurrent close events.
425 /// if the view is busy the cursor shouldn't blink for instance.
426 /// This counts the number of times more often we called
427 /// setBusy(true) compared to setBusy(false), so we can nest
428 /// functions that call setBusy;
433 } // namespace frontend