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; }
40 class ParagraphMetrics;
51 /// Scrollbar Parameters.
52 struct ScrollbarParameters
55 : min(0), max(0), position(0), single_step(1), page_step(1)
57 /// Minimum scrollbar position in pixels.
59 /// Maximum scrollbar position in pixels.
61 /// Current position in the document in pixels.
63 /// Line-scroll amount in pixels.
65 /// Page-scroll amount in pixels.
69 /// Screen view of a Buffer.
71 * A BufferView encapsulates a view onto a particular
72 * buffer, and allows access to operate upon it. A view
73 * is a sliding window of the entire document rendering.
74 * It is the official interface between the LyX core and
75 * the frontend WorkArea.
84 explicit BufferView(Buffer & buffer);
88 /// return the buffer being viewed.
90 Buffer const & buffer() const;
93 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
96 int rightMargin() const;
99 int leftMargin() const;
101 /// \return true if the BufferView is at the top of the document.
102 bool isTopScreen() const;
104 /// \return true if the BufferView is at the bottom of the document.
105 bool isBottomScreen() const;
107 /// perform pending metrics updates.
108 /** \c Update::FitCursor means first to do a FitCursor, and to
109 * force an update if screen position changes.
110 * \c Update::Force means to force an update in any case.
111 * \retval true if a screen redraw is needed
113 void processUpdateFlags(Update::flags flags);
115 /// move the screen to fit the cursor.
116 /// Only to be called with good y coordinates (after a bv::metrics)
118 /// reset the scrollbar to reflect current view position.
119 void updateScrollbar();
120 /// return the Scrollbar Parameters.
121 ScrollbarParameters const & scrollbarParameters() const;
122 /// \return Tool tip for the given position.
123 docstring toolTip(int x, int y) const;
124 /// \return the context menu for the given position.
125 docstring contextMenu(int x, int y) const;
127 /// Save the current position as bookmark.
128 /// if idx == 0, save to temp_bookmark
129 void saveBookmark(unsigned int idx);
130 /// goto a specified position, try top_id first, and then bottom_pit.
131 /// \return true if success
133 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
134 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
135 int top_id, ///< Paragraph ID, \sa Paragraph
136 pos_type top_pos ///< Position in the \c Paragraph
138 /// return the current change at the cursor.
139 Change const getCurrentChange() const;
141 /// move cursor to the named label.
142 void gotoLabel(docstring const & label);
144 /// set the cursor based on the given TeX source row.
145 void setCursorFromRow(int row);
147 /// set cursor to the given inset. Return true if found.
148 bool setCursorFromInset(Inset const *);
149 /// Recenters the BufferView such that the passed cursor
150 /// is in the center.
152 /// Ensure that the BufferView cursor is visible.
153 /// This method will automatically scroll and update the BufferView
156 /// Ensure the passed cursor \p dit is visible.
157 /// This method will automatically scroll and update the BufferView
159 /// \param recenter Whether the cursor should be centered on screen
160 void showCursor(DocIterator const & dit, bool recenter = false);
161 /// LFUN_SCROLL Helper.
162 void lfunScroll(FuncRequest const & cmd);
163 /// scroll down document by the given number of pixels.
164 int scrollDown(int pixels);
165 /// scroll up document by the given number of pixels.
166 int scrollUp(int pixels);
167 /// scroll document by the given number of pixels.
168 int scroll(int pixels);
169 /// Scroll the view by a number of pixels.
170 void scrollDocView(int pixels);
171 /// Set the cursor position based on the scrollbar one.
172 void setCursorFromScrollbar();
174 /// return the pixel width of the document view.
175 int workWidth() const;
176 /// return the pixel height of the document view.
177 int workHeight() const;
179 /// return the inline completion postfix.
180 docstring const & inlineCompletion() const;
181 /// return the number of unique characters in the inline completion.
182 size_t const & inlineCompletionUniqueChars() const;
183 /// return the position in the buffer of the inline completion postfix.
184 DocIterator const & inlineCompletionPos() const;
185 /// set the inline completion postfix and its position in the buffer.
186 /// Updates the updateFlags in \c cur.
187 void setInlineCompletion(Cursor & cur, DocIterator const & pos,
188 docstring const & completion, size_t uniqueChars = 0);
190 /// translate and insert a character, using the correct keymap.
191 void translateAndInsert(char_type c, Text * t, Cursor & cur);
193 /// return true for events that will handle.
194 FuncStatus getStatus(FuncRequest const & cmd);
195 /// execute the given function.
196 /// \return true if the function has been processed.
197 bool dispatch(FuncRequest const & argument);
199 /// request an X11 selection.
200 /// \return the selected string.
201 docstring const requestSelection();
202 /// clear the X11 selection.
203 void clearSelection();
205 /// resize the BufferView.
207 void resize(int width, int height);
209 /// dispatch method helper for \c WorkArea
211 void mouseEventDispatch(FuncRequest const & ev);
213 /// access to anchor.
214 pit_type anchor_ref() const;
217 CursorStatus cursorStatus(DocIterator const & dit) const;
218 /// access to full cursor.
220 /// access to full cursor.
221 Cursor const & cursor() const;
223 /// This will also open all relevant collapsable insets.
224 void setCursor(DocIterator const &);
225 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
226 /// \retval true if an update was needed.
227 bool checkDepm(Cursor & cur, Cursor & old);
229 /// This is used when handling LFUN_MOUSE_PRESS.
230 bool mouseSetCursor(Cursor & cur, bool select = false);
232 /// sets the selection.
233 /* When \c backwards == false, set anchor
234 * to \c cur and cursor to \c cur + \c length. When \c
235 * backwards == true, set anchor to \c cur and cursor to \c
238 void putSelectionAt(DocIterator const & cur,
239 int length, bool backwards);
241 /// update the internal \c ViewMetricsInfo.
242 void updateMetrics();
245 TextMetrics const & textMetrics(Text const * t) const;
246 TextMetrics & textMetrics(Text const * t);
248 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
251 CoordCache & coordCache();
253 CoordCache const & coordCache() const;
256 Point getPos(DocIterator const & dit, bool boundary) const;
257 /// is the paragraph of the cursor visible ?
258 bool paragraphVisible(DocIterator const & dit) const;
262 void draw(frontend::Painter & pain);
264 /// get this view's keyboard map handler.
267 Intl const & getIntl() const;
270 // Messages to the GUI
272 /// This signal is emitted when some message shows up.
273 void message(docstring const & msg);
275 /// This signal is emitted when some dialog needs to be shown.
276 void showDialog(std::string const & name);
278 /// This signal is emitted when some dialog needs to be shown with
280 void showDialog(std::string const & name, std::string const & data,
283 /// This signal is emitted when some dialogs needs to be updated.
284 void updateDialog(std::string const & name, std::string const & data);
287 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
290 docstring contentsOfPlaintextFile(support::FileName const & f);
291 // Insert plain text file (if filename is empty, prompt for one)
292 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
294 void insertLyXFile(support::FileName const & f);
295 /// save temporary bookmark for jump back navigation
296 void bookmarkEditPosition();
300 BufferView(BufferView const &);
301 void operator=(BufferView const &);
303 // the position relative to (0, baseline) of outermost paragraph
304 Point coordOffset(DocIterator const & dit, bool boundary) const;
305 /// Update current paragraph metrics.
306 /// \return true if no further update is needed.
307 bool singleParUpdate();
309 /// Search recursively for the the innermost inset that covers (x, y) position.
310 /// \retval 0 if no inset is found.
311 Inset const * getCoveringInset(
312 Text const & text, //< The Text where we start searching.
313 int x, //< x-coordinate on screen
314 int y //< y-coordinate on screen
330 /// some space for drawing the 'nested' markers (in pixel)
331 inline int nestMargin() { return 15; }
333 /// margin for changebar
334 inline int changebarMargin() { return 12; }
338 #endif // BUFFERVIEW_H