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
65 /// LyXView inherited methods.
67 int id() const { return id_; };
69 BufferView * currentBufferView();
70 BufferView const * currentBufferView() const;
71 BufferView * documentBufferView();
72 BufferView const * documentBufferView() const;
73 void setBuffer(Buffer * b);
75 bool closeBufferAll();
76 bool hasFocus() const;
77 Buffer * loadDocument(support::FileName const & name,
78 bool tolastfiles = true);
79 void newDocument(std::string const & filename,
81 void message(docstring const &);
82 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
83 bool dispatch(FuncRequest const & cmd);
85 void updateCompletion(Cursor & cur, bool start, bool keep);
89 /// add toolbar, if newline==true, add a toolbar break before the toolbar
90 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
91 void updateStatusBar();
93 /// updates the possible layouts selectable
94 void updateLayoutList();
95 void updateToolbars();
96 QMenu * createPopupMenu();
99 LayoutBox * getLayoutDialog() const;
101 /// hides the workarea and makes sure it is clean
102 bool hideWorkArea(GuiWorkArea * wa);
103 /// closes the workarea
104 bool closeWorkArea(GuiWorkArea * wa);
106 void openDocument(std::string const & filename);
108 void importDocument(std::string const &);
110 /// GuiBufferDelegate.
112 void resetAutosaveTimers();
113 void errors(std::string const &, bool from_master = false);
114 void structureChanged();
115 void updateTocItem(std::string const &, DocIterator const &);
119 TocModels & tocModels();
121 /// called on timeout
124 /** redraw \c inset in all the BufferViews in which it is currently
125 * visible. If successful return a pointer to the owning Buffer.
127 Buffer const * updateInset(Inset const *);
129 /// \return the \c Workarea associated to \p Buffer
130 /// \retval 0 if no \c WorkArea is found.
131 GuiWorkArea * workArea(Buffer & buffer);
133 /// Add a \c WorkArea
134 /// \return the \c Workarea associated to \p Buffer
135 /// \retval 0 if no \c WorkArea is found.
136 GuiWorkArea * addWorkArea(Buffer & buffer);
137 /// \param work_area The current \c WorkArea, or \c NULL
138 void setCurrentWorkArea(GuiWorkArea * work_area);
140 void removeWorkArea(GuiWorkArea * work_area);
141 /// return the current WorkArea (the one that has the focus).
142 GuiWorkArea const * currentWorkArea() const;
143 /// return the current WorkArea (the one that has the focus).
144 GuiWorkArea * currentWorkArea();
146 /// return the current document WorkArea (it may not have the focus).
147 GuiWorkArea const * currentMainWorkArea() const;
148 /// return the current document WorkArea (it may not have the focus).
149 GuiWorkArea * currentMainWorkArea();
156 /// clear any temporary message and replace with current status.
161 void updateWindowTitle(GuiWorkArea * wa);
163 void resetWindowTitleAndIconText();
166 void on_currentWorkAreaChanged(GuiWorkArea *);
168 void on_lastWorkAreaRemoved();
170 /// slots to change the icon size
171 void smallSizedIcons();
172 void normalSizedIcons();
173 void bigSizedIcons();
177 TabWorkArea * addTabWorkArea();
179 /// connect to signals in the given BufferView
180 void connectBufferView(BufferView & bv);
181 /// disconnect from signals in the given BufferView
182 void disconnectBufferView();
183 /// connect to signals in the given buffer
184 void connectBuffer(Buffer & buf);
185 /// disconnect from signals in the given buffer
186 void disconnectBuffer();
188 void dragEnterEvent(QDragEnterEvent * ev);
190 void dropEvent(QDropEvent * ev);
191 /// make sure we quit cleanly
192 void closeEvent(QCloseEvent * e);
194 void showEvent(QShowEvent *);
196 /// in order to catch Tab key press.
197 bool event(QEvent * e);
198 bool focusNextPrevChild(bool);
201 struct GuiViewPrivate;
206 /// dialogs for this view
212 /// Hide all visible dialogs
213 void hideAll() const;
215 /// Update all visible dialogs.
217 * Check the status of all visible dialogs and disable or reenable
218 * them as appropriate.
220 * Disabling is needed for example when a dialog is open and the
221 * cursor moves to a position where the corresponding inset is not
224 void updateDialogs();
226 /** \param name == "bibtex", "citation" etc; an identifier used to
227 launch a particular dialog.
228 \param data is a string representation of the Inset contents.
229 It is often little more than the output from Inset::write.
230 It is passed to, and parsed by, the frontend dialog.
231 Several of these dialogs do not need any data,
232 so it defaults to string().
233 \param inset ownership is _not_ passed to the frontend dialog.
234 It is stored internally and used by the kernel to ascertain
235 what to do with the FuncRequest dispatched from the frontend
236 dialog on 'Apply'; should it be used to create a new inset at
237 the current cursor position or modify an existing, 'open' inset?
239 void showDialog(std::string const & name,
240 std::string const & data, Inset * inset = 0);
242 /** \param name == "citation", "bibtex" etc; an identifier used
243 to reset the contents of a particular dialog with \param data.
244 See the comments to 'show', above.
246 void updateDialog(std::string const & name, std::string const & data);
248 /** All Dialogs of the given \param name will be closed if they are
249 connected to the given \param inset.
251 void hideDialog(std::string const & name, Inset * inset);
253 void disconnectDialog(std::string const & name);
257 void saveLayout() const;
259 bool restoreLayout();
261 GuiToolbar * toolbar(std::string const & name);
263 void constructToolbars();
267 void lfunUiToggle(FuncRequest const & cmd);
269 void toggleFullScreen();
271 void insertLyXFile(docstring const & fname);
273 void insertPlaintextFile(docstring const & fname,
276 /// Save a buffer as a new file.
278 Write a buffer to a new file name and rename the buffer
279 according to the new file name.
281 This function is e.g. used by menu callbacks and
282 LFUN_BUFFER_WRITE_AS.
284 If 'newname' is empty, the user is asked via a
285 dialog for the buffer's new name and location.
287 If 'newname' is non-empty and has an absolute path, that is used.
288 Otherwise the base directory of the buffer is used as the base
289 for any relative path in 'newname'.
291 bool renameBuffer(Buffer & b, docstring const & newname);
293 bool saveBuffer(Buffer & b);
294 /// closes a workarea, if close_buffer is true the buffer will
295 /// also be released, otherwise the buffer will be hidden.
296 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
297 /// closes the tabworkarea and all tabs. If we are in a close event,
298 /// all buffers will be closed, otherwise they will be hidden.
299 bool closeTabWorkArea(TabWorkArea * twa);
300 /// gives the user the possibility to save his work
301 /// or to discard the changes. If hiding is true, the
302 /// document will be reloaded.
303 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
304 /// closes all workareas
305 bool closeWorkAreaAll();
306 /// write all open workareas into the session file
307 void writeSession() const;
308 /// is the buffer in this workarea also shown in another tab ?
309 /// This tab can either be in the same view or in another one.
310 bool inMultiTabs(GuiWorkArea * wa);
311 /// is the buffer in this workarea also shown in another view ?
312 bool inMultiViews(GuiWorkArea * wa);
314 enum NextOrPrevious {
319 void gotoNextOrPreviousBuffer(NextOrPrevious np);
322 Inset * getOpenInset(std::string const & name) const;
324 /// Is the dialog currently visible?
325 bool isDialogVisible(std::string const & name) const;
327 Dialog * findOrBuild(std::string const & name, bool hide_it);
329 Dialog * build(std::string const & name);
334 /// flag to avoid two concurrent close events.
338 } // namespace frontend