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"
19 #include "frontends/LyXView.h"
21 #include "support/strfwd.h"
23 #include <QMainWindow>
26 class QDragEnterEvent;
47 * GuiView - Qt4 implementation of LyXView
49 * qt4-private implementation of the main LyX window.
51 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
52 * is deleted. This might be useful for closing other dialogs
53 * depending on a given GuiView.
55 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
56 public GuiBufferDelegate
60 /// create a main window of the given dimensions
66 int id() const { return id_; }
69 /// returns true if this view has the focus.
70 bool hasFocus() const;
72 /// add toolbar, if newline==true, add a toolbar break before the toolbar
73 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
74 virtual void updateStatusBar();
75 virtual void message(docstring const & str);
77 /// updates the possible layouts selectable
78 void updateLayoutList();
79 void updateToolbars();
80 QMenu * createPopupMenu();
81 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
82 bool dispatch(FuncRequest const & cmd);
85 LayoutBox * getLayoutDialog() const;
87 /// \return the buffer currently selected in this window
88 virtual Buffer * buffer();
89 virtual Buffer const * buffer() const;
91 /// \return the document buffer in this window
92 virtual Buffer * documentBuffer();
93 virtual Buffer const * documentBuffer() const;
95 /// set a buffer to the current workarea.
96 void setBuffer(Buffer * b); ///< \c Buffer to set.
97 /// closes the current active buffer
99 /// hides the workarea and makes sure it is clean
100 bool hideWorkArea(GuiWorkArea * wa);
101 /// closes the workarea
102 bool closeWorkArea(GuiWorkArea * wa);
103 /// load a document into the current workarea.
104 Buffer * loadDocument(support::FileName const & name, ///< File to load.
105 bool tolastfiles = true); ///< append to the "Open recent" menu?
107 void openDocument(std::string const & filename);
109 void importDocument(std::string const &);
111 void newDocument(std::string const & filename, bool fromTemplate);
113 /// GuiBufferDelegate.
115 void resetAutosaveTimers();
116 void errors(std::string const &, bool from_master = false);
117 void structureChanged();
118 void updateTocItem(std::string const &, DocIterator const &);
122 TocModels & tocModels();
124 /// called on timeout
127 /// \return the currently selected buffer view.
129 /// \return the current document buffer view.
130 BufferView * documentBufferView();
132 /** redraw \c inset in all the BufferViews in which it is currently
133 * visible. If successful return a pointer to the owning Buffer.
135 Buffer const * updateInset(Inset const *);
137 void restartCursor();
139 /// \return the \c Workarea associated to \p Buffer
140 /// \retval 0 if no \c WorkArea is found.
141 GuiWorkArea * workArea(Buffer & buffer);
143 /// Add a \c WorkArea
144 /// \return the \c Workarea associated to \p Buffer
145 /// \retval 0 if no \c WorkArea is found.
146 GuiWorkArea * addWorkArea(Buffer & buffer);
147 /// \param work_area The current \c WorkArea, or \c NULL
148 void setCurrentWorkArea(GuiWorkArea * work_area);
150 void removeWorkArea(GuiWorkArea * work_area);
151 /// return the current WorkArea (the one that has the focus).
152 GuiWorkArea const * currentWorkArea() const;
153 /// return the current WorkArea (the one that has the focus).
154 GuiWorkArea * currentWorkArea();
156 /// return the current document WorkArea (it may not have the focus).
157 GuiWorkArea const * currentMainWorkArea() const;
158 /// return the current document WorkArea (it may not have the focus).
159 GuiWorkArea * currentMainWorkArea();
166 /// clear any temporary message and replace with current status.
171 void updateWindowTitle(GuiWorkArea * wa);
173 void resetWindowTitleAndIconText();
176 void on_currentWorkAreaChanged(GuiWorkArea *);
178 void on_lastWorkAreaRemoved();
180 /// slots to change the icon size
181 void smallSizedIcons();
182 void normalSizedIcons();
183 void bigSizedIcons();
187 TabWorkArea * addTabWorkArea();
189 /// connect to signals in the given BufferView
190 void connectBufferView(BufferView & bv);
191 /// disconnect from signals in the given BufferView
192 void disconnectBufferView();
193 /// connect to signals in the given buffer
194 void connectBuffer(Buffer & buf);
195 /// disconnect from signals in the given buffer
196 void disconnectBuffer();
198 void dragEnterEvent(QDragEnterEvent * ev);
200 void dropEvent(QDropEvent * ev);
201 /// make sure we quit cleanly
202 void closeEvent(QCloseEvent * e);
204 void showEvent(QShowEvent *);
206 /// in order to catch Tab key press.
207 bool event(QEvent * e);
208 bool focusNextPrevChild(bool);
211 struct GuiViewPrivate;
216 /// dialogs for this view
222 /// Hide all visible dialogs
223 void hideAll() const;
225 /// Update all visible dialogs.
227 * Check the status of all visible dialogs and disable or reenable
228 * them as appropriate.
230 * Disabling is needed for example when a dialog is open and the
231 * cursor moves to a position where the corresponding inset is not
234 void updateDialogs();
236 /** \param name == "bibtex", "citation" etc; an identifier used to
237 launch a particular dialog.
238 \param data is a string representation of the Inset contents.
239 It is often little more than the output from Inset::write.
240 It is passed to, and parsed by, the frontend dialog.
241 Several of these dialogs do not need any data,
242 so it defaults to string().
243 \param inset ownership is _not_ passed to the frontend dialog.
244 It is stored internally and used by the kernel to ascertain
245 what to do with the FuncRequest dispatched from the frontend
246 dialog on 'Apply'; should it be used to create a new inset at
247 the current cursor position or modify an existing, 'open' inset?
249 void showDialog(std::string const & name,
250 std::string const & data, Inset * inset = 0);
252 /** \param name == "citation", "bibtex" etc; an identifier used
253 to reset the contents of a particular dialog with \param data.
254 See the comments to 'show', above.
256 void updateDialog(std::string const & name, std::string const & data);
258 /** All Dialogs of the given \param name will be closed if they are
259 connected to the given \param inset.
261 void hideDialog(std::string const & name, Inset * inset);
263 void disconnectDialog(std::string const & name);
266 void updateCompletion(Cursor & cur, bool start, bool keep);
270 void saveLayout() const;
272 bool restoreLayout();
274 GuiToolbar * toolbar(std::string const & name);
276 void constructToolbars();
280 void lfunUiToggle(FuncRequest const & cmd);
282 void toggleFullScreen();
284 void insertLyXFile(docstring const & fname);
286 void insertPlaintextFile(docstring const & fname,
289 /// Save a buffer as a new file.
291 Write a buffer to a new file name and rename the buffer
292 according to the new file name.
294 This function is e.g. used by menu callbacks and
295 LFUN_BUFFER_WRITE_AS.
297 If 'newname' is empty, the user is asked via a
298 dialog for the buffer's new name and location.
300 If 'newname' is non-empty and has an absolute path, that is used.
301 Otherwise the base directory of the buffer is used as the base
302 for any relative path in 'newname'.
304 bool renameBuffer(Buffer & b, docstring const & newname);
306 bool saveBuffer(Buffer & b);
307 /// closes a workarea, if close_buffer is true the buffer will
308 /// also be released, otherwise the buffer will be hidden.
309 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
310 /// closes the tabworkarea and all tabs. If we are in a close event,
311 /// all buffers will be closed, otherwise they will be hidden.
312 bool closeTabWorkArea(TabWorkArea * twa);
313 /// gives the user the possibility to save his work
314 /// or to discard the changes. If hiding is true, the
315 /// document will be reloaded.
316 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
317 /// closes all workareas and all hidden buffers
318 bool closeBufferAll();
319 /// closes all workareas
320 bool closeWorkAreaAll();
321 /// write all open workareas into the session file
322 void writeSession() const;
323 /// is the buffer in this workarea also shown in another tab ?
324 /// This tab can either be in the same view or in another one.
325 bool inMultiTabs(GuiWorkArea * wa);
326 /// is the buffer in this workarea also shown in another view ?
327 bool inMultiViews(GuiWorkArea * wa);
329 enum NextOrPrevious {
334 void gotoNextOrPreviousBuffer(NextOrPrevious np);
337 Inset * getOpenInset(std::string const & name) const;
339 /// Is the dialog currently visible?
340 bool isDialogVisible(std::string const & name) const;
342 Dialog * findOrBuild(std::string const & name, bool hide_it);
344 Dialog * build(std::string const & name);
349 /// flag to avoid two concurrent close events.
353 } // namespace frontend