4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alfredo Braustein
8 * \author Lars Gullik Bjønnes
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
18 #include "update_flags.h"
20 #include "support/strfwd.h"
21 #include "support/types.h"
25 namespace support { class FileName; }
27 namespace frontend { class Painter; }
28 namespace frontend { class GuiBufferViewDelegate; }
41 class ParagraphMetrics;
52 /// Scrollbar Parameters.
53 struct ScrollbarParameters
55 /// Minimum scrollbar position in pixels.
57 /// Maximum scrollbar position in pixels.
59 /// Current position in the document in pixels.
61 /// Line-scroll amount in pixels.
63 /// Page-scroll amount in pixels.
67 /// Screen view of a Buffer.
69 * A BufferView encapsulates a view onto a particular
70 * buffer, and allows access to operate upon it. A view
71 * is a sliding window of the entire document rendering.
72 * It is the official interface between the LyX core and
73 * the frontend WorkArea.
82 explicit BufferView(Buffer & buffer);
86 /// return the buffer being viewed.
88 Buffer const & buffer() const;
91 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
94 int rightMargin() const;
97 int leftMargin() const;
99 /// perform pending metrics updates.
100 /** \c Update::FitCursor means first to do a FitCursor, and to
101 * force an update if screen position changes.
102 * \c Update::Force means to force an update in any case.
103 * \retval true if a screen redraw is needed
105 void processUpdateFlags(Update::flags flags);
107 /// move the screen to fit the cursor.
108 /// Only to be called with good y coordinates (after a bv::metrics)
110 /// reset the scrollbar to reflect current view position.
111 void updateScrollbar();
112 /// return the Scrollbar Parameters.
113 ScrollbarParameters const & scrollbarParameters() const;
114 /// \return Tool tip for the given position.
115 docstring toolTip(int x, int y) const;
116 /// \return the context menu for the given position.
117 docstring contextMenu(int x, int y) const;
119 /// Save the current position as bookmark.
120 /// if idx == 0, save to temp_bookmark
121 void saveBookmark(unsigned int idx);
122 /// goto a specified position, try top_id first, and then bottom_pit.
123 /// \return true if success
125 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
126 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
127 int top_id, ///< Paragraph ID, \sa Paragraph
128 pos_type top_pos ///< Position in the \c Paragraph
130 /// return the current change at the cursor.
131 Change const getCurrentChange() const;
133 /// move cursor to the named label.
134 void gotoLabel(docstring const & label);
136 /// set the cursor based on the given TeX source row.
137 void setCursorFromRow(int row);
139 /// Ensure that the BufferView cursor is visible.
140 /// This method will automatically scroll and update the BufferView
143 /// Ensure the passed cursor \p dit is visible.
144 /// This method will automatically scroll and update the BufferView
146 void showCursor(DocIterator const & dit);
147 /// LFUN_SCROLL Helper.
148 void lfunScroll(FuncRequest const & cmd);
149 /// scroll down document by the given number of pixels.
150 void scrollDown(int pixels);
151 /// scroll up document by the given number of pixels.
152 void scrollUp(int pixels);
153 /// scroll document by the given number of pixels.
154 void scroll(int pixels);
155 /// Scroll the view by a number of pixels.
156 void scrollDocView(int pixels);
157 /// Set the cursor position based on the scrollbar one.
158 void setCursorFromScrollbar();
160 /// return the pixel width of the document view.
161 int workWidth() const;
162 /// return the pixel height of the document view.
163 int workHeight() const;
165 /// return the inline completion postfix.
166 docstring const & inlineCompletion() const;
167 /// return the number of unique characters in the inline completion.
168 size_t const & inlineCompletionUniqueChars() const;
169 /// return the position in the buffer of the inline completion postfix.
170 DocIterator const & inlineCompletionPos() const;
171 /// set the inline completion postfix and its position in the buffer.
172 /// Updates the updateFlags in \c cur.
173 void setInlineCompletion(Cursor & cur, DocIterator const & pos,
174 docstring const & completion, size_t uniqueChars = 0);
176 /// translate and insert a character, using the correct keymap.
177 void translateAndInsert(char_type c, Text * t, Cursor & cur);
179 /// return true for events that will handle.
180 FuncStatus getStatus(FuncRequest const & cmd);
181 /// execute the given function.
182 /// \return true if the function has been processed.
183 bool dispatch(FuncRequest const & argument);
185 /// request an X11 selection.
186 /// \return the selected string.
187 docstring const requestSelection();
188 /// clear the X11 selection.
189 void clearSelection();
191 /// resize the BufferView.
193 void resize(int width, int height);
195 /// dispatch method helper for \c WorkArea
197 void mouseEventDispatch(FuncRequest const & ev);
199 /// access to anchor.
200 pit_type anchor_ref() const;
203 CursorStatus cursorStatus(DocIterator const & dit) const;
204 /// access to full cursor.
206 /// access to full cursor.
207 Cursor const & cursor() const;
209 /// This will also open all relevant collapsable insets.
210 void setCursor(DocIterator const &);
211 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
212 /// \retval true if an update was needed.
213 bool checkDepm(Cursor & cur, Cursor & old);
215 /// This is used when handling LFUN_MOUSE_PRESS.
216 bool mouseSetCursor(Cursor & cur, bool select = false);
218 /// sets the selection.
219 /* When \c backwards == false, set anchor
220 * to \c cur and cursor to \c cur + \c length. When \c
221 * backwards == true, set anchor to \c cur and cursor to \c
224 void putSelectionAt(DocIterator const & cur,
225 int length, bool backwards);
227 /// update the internal \c ViewMetricsInfo.
228 void updateMetrics();
231 TextMetrics const & textMetrics(Text const * t) const;
232 TextMetrics & textMetrics(Text const * t);
234 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
237 CoordCache & coordCache();
239 CoordCache const & coordCache() const;
242 Point getPos(DocIterator const & dit, bool boundary) const;
246 void draw(frontend::Painter & pain);
248 /// get this view's keyboard map handler.
251 Intl const & getIntl() const;
254 // Messages to the GUI
256 /// This signal is emitted when some message shows up.
257 void message(docstring const & msg);
259 /// This signal is emitted when some dialog needs to be shown.
260 void showDialog(std::string const & name);
262 /// This signal is emitted when some dialog needs to be shown with
264 void showDialog(std::string const & name, std::string const & data,
267 /// This signal is emitted when some dialogs needs to be updated.
268 void updateDialog(std::string const & name, std::string const & data);
271 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
274 docstring contentsOfPlaintextFile(support::FileName const & f);
275 // Insert plain text file (if filename is empty, prompt for one)
276 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
278 void insertLyXFile(support::FileName const & f);
282 BufferView(BufferView const &);
283 void operator=(BufferView const &);
285 // the position relative to (0, baseline) of outermost paragraph
286 Point coordOffset(DocIterator const & dit, bool boundary) const;
287 /// Update current paragraph metrics.
288 /// \return true if no further update is needed.
289 bool singleParUpdate();
291 /// Search recursively for the the innermost inset that covers (x, y) position.
292 /// \retval 0 if no inset is found.
293 Inset const * getCoveringInset(
294 Text const & text, //< The Text where we start searching.
295 int x, //< x-coordinate on screen
296 int y //< y-coordinate on screen
312 /// some space for drawing the 'nested' markers (in pixel)
313 inline int nestMargin() { return 15; }
315 /// margin for changebar
316 inline int changebarMargin() { return 12; }
320 #endif // BUFFERVIEW_H