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 newDocument(std::string const & filename,
75 void message(docstring const &);
76 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
77 bool dispatch(FuncRequest const & cmd);
79 void updateCompletion(Cursor & cur, bool start, bool keep);
83 /// set a buffer to the current workarea.
84 void setBuffer(Buffer * b); ///< \c Buffer to set.
86 /// load a document into the current workarea.
87 Buffer * loadDocument(
88 support::FileName const & name, ///< File to load.
89 bool tolastfiles = true ///< append to the "Open recent" menu?
92 /// add toolbar, if newline==true, add a toolbar break before the toolbar
93 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
94 void updateStatusBar();
96 /// updates the possible layouts selectable
97 void updateLayoutList();
98 void updateToolbars();
99 QMenu * createPopupMenu();
102 LayoutBox * getLayoutDialog() const;
104 /// hides the workarea and makes sure it is clean
105 bool hideWorkArea(GuiWorkArea * wa);
106 /// closes the workarea
107 bool closeWorkArea(GuiWorkArea * wa);
108 /// closes the buffer
109 bool closeBuffer(Buffer & buf);
111 void openDocument(std::string const & filename);
113 void importDocument(std::string const &);
115 /// GuiBufferDelegate.
117 void resetAutosaveTimers();
118 void errors(std::string const &, bool from_master = false);
119 void structureChanged();
120 void updateTocItem(std::string const &, DocIterator const &);
124 TocModels & tocModels();
126 /// called on timeout
129 /// check for external change of any opened buffer, mainly for svn usage
130 void checkExternallyModifiedBuffers();
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 /// \return the \c Workarea associated to \p Buffer
138 /// \retval 0 if no \c WorkArea is found.
139 GuiWorkArea * workArea(Buffer & buffer);
141 /// Add a \c WorkArea
142 /// \return the \c Workarea associated to \p Buffer
143 /// \retval 0 if no \c WorkArea is found.
144 GuiWorkArea * addWorkArea(Buffer & buffer);
145 /// \param work_area The current \c WorkArea, or \c NULL
146 void setCurrentWorkArea(GuiWorkArea * work_area);
148 void removeWorkArea(GuiWorkArea * work_area);
149 /// return the current WorkArea (the one that has the focus).
150 GuiWorkArea const * currentWorkArea() const;
151 /// return the current WorkArea (the one that has the focus).
152 GuiWorkArea * currentWorkArea();
154 /// return the current document WorkArea (it may not have the focus).
155 GuiWorkArea const * currentMainWorkArea() const;
156 /// return the current document WorkArea (it may not have the focus).
157 GuiWorkArea * currentMainWorkArea();
164 /// clear any temporary message and replace with current status.
169 void updateWindowTitle(GuiWorkArea * wa);
171 void resetWindowTitleAndIconText();
174 void on_currentWorkAreaChanged(GuiWorkArea *);
176 void on_lastWorkAreaRemoved();
178 /// slots to change the icon size
179 void smallSizedIcons();
180 void normalSizedIcons();
181 void bigSizedIcons();
184 /// Open given child document in current buffer directory.
185 void openChildDocument(std::string const & filename);
186 /// Close current document buffer.
188 /// Close all document buffers.
189 bool closeBufferAll();
191 TabWorkArea * addTabWorkArea();
193 /// connect to signals in the given BufferView
194 void connectBufferView(BufferView & bv);
195 /// disconnect from signals in the given BufferView
196 void disconnectBufferView();
197 /// connect to signals in the given buffer
198 void connectBuffer(Buffer & buf);
199 /// disconnect from signals in the given buffer
200 void disconnectBuffer();
202 void dragEnterEvent(QDragEnterEvent * ev);
204 void dropEvent(QDropEvent * ev);
205 /// make sure we quit cleanly
206 void closeEvent(QCloseEvent * e);
208 void showEvent(QShowEvent *);
210 /// in order to catch Tab key press.
211 bool event(QEvent * e);
212 bool focusNextPrevChild(bool);
215 bool goToFileRow(std::string const & argument);
218 struct GuiViewPrivate;
223 /// dialogs for this view
229 /// Hide all visible dialogs
230 void hideAll() const;
232 /// Update all visible dialogs.
234 * Check the status of all visible dialogs and disable or reenable
235 * them as appropriate.
237 * Disabling is needed for example when a dialog is open and the
238 * cursor moves to a position where the corresponding inset is not
241 void updateDialogs();
243 /** \param name == "bibtex", "citation" etc; an identifier used to
244 launch a particular dialog.
245 \param data is a string representation of the Inset contents.
246 It is often little more than the output from Inset::write.
247 It is passed to, and parsed by, the frontend dialog.
248 Several of these dialogs do not need any data,
249 so it defaults to string().
250 \param inset ownership is _not_ passed to the frontend dialog.
251 It is stored internally and used by the kernel to ascertain
252 what to do with the FuncRequest dispatched from the frontend
253 dialog on 'Apply'; should it be used to create a new inset at
254 the current cursor position or modify an existing, 'open' inset?
256 void showDialog(std::string const & name,
257 std::string const & data, Inset * inset = 0);
259 /** \param name == "citation", "bibtex" etc; an identifier used
260 to reset the contents of a particular dialog with \param data.
261 See the comments to 'show', above.
263 void updateDialog(std::string const & name, std::string const & data);
265 /** All Dialogs of the given \param name will be closed if they are
266 connected to the given \param inset.
268 void hideDialog(std::string const & name, Inset * inset);
270 void disconnectDialog(std::string const & name);
274 void saveLayout() const;
276 bool restoreLayout();
278 GuiToolbar * toolbar(std::string const & name);
280 void constructToolbars();
284 void lfunUiToggle(FuncRequest const & cmd);
286 void toggleFullScreen();
288 void insertLyXFile(docstring const & fname);
290 void insertPlaintextFile(docstring const & fname,
293 /// Save a buffer as a new file.
295 Write a buffer to a new file name and rename the buffer
296 according to the new file name.
298 This function is e.g. used by menu callbacks and
299 LFUN_BUFFER_WRITE_AS.
301 If 'newname' is empty, the user is asked via a
302 dialog for the buffer's new name and location.
304 If 'newname' is non-empty and has an absolute path, that is used.
305 Otherwise the base directory of the buffer is used as the base
306 for any relative path in 'newname'.
308 bool renameBuffer(Buffer & b, docstring const & newname);
310 bool saveBuffer(Buffer & b);
311 /// closes a workarea, if close_buffer is true the buffer will
312 /// also be released, otherwise the buffer will be hidden.
313 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
314 /// closes the tabworkarea and all tabs. If we are in a close event,
315 /// all buffers will be closed, otherwise they will be hidden.
316 bool closeTabWorkArea(TabWorkArea * twa);
317 /// gives the user the possibility to save his work
318 /// or to discard the changes. If hiding is true, the
319 /// document will be reloaded.
320 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
321 /// closes all workareas
322 bool closeWorkAreaAll();
323 /// write all open workareas into the session file
324 void writeSession() const;
325 /// is the buffer in this workarea also shown in another tab ?
326 /// This tab can either be in the same view or in another one.
327 bool inMultiTabs(GuiWorkArea * wa);
328 /// is the buffer in this workarea also shown in another view ?
329 bool inMultiViews(GuiWorkArea * wa);
331 enum NextOrPrevious {
336 void gotoNextOrPreviousBuffer(NextOrPrevious np);
338 /// Is the dialog currently visible?
339 bool isDialogVisible(std::string const & name) const;
341 Dialog * findOrBuild(std::string const & name, bool hide_it);
343 Dialog * build(std::string const & name);
346 void reloadBuffer(Buffer * buf);
348 void dispatchVC(FuncRequest const & cmd);
355 /// flag to avoid two concurrent close events.
359 } // namespace frontend