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; }
42 class ParagraphMetrics;
53 /// Scrollbar Parameters.
54 struct ScrollbarParameters
57 : min(0), max(0), position(0), single_step(1), page_step(1)
59 /// Minimum scrollbar position in pixels.
61 /// Maximum scrollbar position in pixels.
63 /// Current position in the document in pixels.
65 /// Line-scroll amount in pixels.
67 /// Page-scroll amount in pixels.
71 /// Screen view of a Buffer.
73 * A BufferView encapsulates a view onto a particular
74 * buffer, and allows access to operate upon it. A view
75 * is a sliding window of the entire document rendering.
76 * It is the official interface between the LyX core and
77 * the frontend WorkArea.
86 explicit BufferView(Buffer & buffer);
90 /// return the buffer being viewed.
92 Buffer const & buffer() const;
95 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
98 int rightMargin() const;
101 int leftMargin() const;
103 /// \return true if the BufferView is at the top of the document.
104 bool isTopScreen() const;
106 /// \return true if the BufferView is at the bottom of the document.
107 bool isBottomScreen() const;
109 /// perform pending metrics updates.
110 /** \c Update::FitCursor means first to do a FitCursor, and to
111 * force an update if screen position changes.
112 * \c Update::Force means to force an update in any case.
113 * \retval true if a screen redraw is needed
115 void processUpdateFlags(Update::flags flags);
117 /// move the screen to fit the cursor.
118 /// Only to be called with good y coordinates (after a bv::metrics)
120 /// reset the scrollbar to reflect current view position.
121 void updateScrollbar();
122 /// return the Scrollbar Parameters.
123 ScrollbarParameters const & scrollbarParameters() const;
124 /// \return Tool tip for the given position.
125 docstring toolTip(int x, int y) const;
126 /// \return the context menu for the given position.
127 std::string contextMenu(int x, int y) const;
129 /// Save the current position as bookmark.
130 /// if idx == 0, save to temp_bookmark
131 void saveBookmark(unsigned int idx);
132 /// goto a specified position, try top_id first, and then bottom_pit.
133 /// \return true if success
135 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
136 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
137 int top_id, ///< Paragraph ID, \sa Paragraph
138 pos_type top_pos ///< Position in the \c Paragraph
140 /// return the current change at the cursor.
141 Change const getCurrentChange() const;
143 /// move cursor to the named label.
144 void gotoLabel(docstring const & label);
146 /// set the cursor based on the given TeX source row.
147 void setCursorFromRow(int row);
149 /// set cursor to the given inset. Return true if found.
150 bool setCursorFromInset(Inset const *);
151 /// Recenters the BufferView such that the passed cursor
152 /// is in the center.
154 /// Ensure that the BufferView cursor is visible.
155 /// This method will automatically scroll and update the BufferView
158 /// Ensure the passed cursor \p dit is visible.
159 /// This method will automatically scroll and update the BufferView
161 /// \param recenter Whether the cursor should be centered on screen
162 void showCursor(DocIterator const & dit, bool recenter,
164 /// Scroll to the cursor.
165 void scrollToCursor();
166 /// Scroll to the cursor.
167 /// \param recenter Whether the cursor should be centered on screen
168 bool scrollToCursor(DocIterator const & dit, bool recenter);
169 /// scroll down document by the given number of pixels.
170 int scrollDown(int pixels);
171 /// scroll up document by the given number of pixels.
172 int scrollUp(int pixels);
173 /// scroll document by the given number of pixels.
174 int scroll(int pixels);
175 /// Scroll the view by a number of pixels.
176 void scrollDocView(int pixels, bool update);
177 /// Set the cursor position based on the scrollbar one.
178 void setCursorFromScrollbar();
180 /// return the pixel width of the document view.
181 int workWidth() const;
182 /// return the pixel height of the document view.
183 int workHeight() const;
185 /// return the inline completion postfix.
186 docstring const & inlineCompletion() const;
187 /// return the number of unique characters in the inline completion.
188 size_t const & inlineCompletionUniqueChars() const;
189 /// return the position in the buffer of the inline completion postfix.
190 DocIterator const & inlineCompletionPos() const;
191 /// make sure inline completion position is OK
192 void resetInlineCompletionPos();
193 /// set the inline completion postfix and its position in the buffer.
194 /// Updates the updateFlags in \c cur.
195 void setInlineCompletion(Cursor const & cur, DocIterator const & pos,
196 docstring const & completion, size_t uniqueChars = 0);
198 /// translate and insert a character, using the correct keymap.
199 void translateAndInsert(char_type c, Text * t, Cursor & cur);
201 /// \return true if we've made a decision
202 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
203 /// execute the given function.
204 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
206 /// request an X11 selection.
207 /// \return the selected string.
208 docstring const requestSelection();
209 /// clear the X11 selection.
210 void clearSelection();
212 /// resize the BufferView.
214 void resize(int width, int height);
216 /// dispatch method helper for \c WorkArea
218 void mouseEventDispatch(FuncRequest const & ev);
220 /// access to anchor.
221 pit_type anchor_ref() const;
224 CursorStatus cursorStatus(DocIterator const & dit) const;
225 /// access to full cursor.
227 /// access to full cursor.
228 Cursor const & cursor() const;
230 /// This will also open all relevant collapsable insets.
231 void setCursor(DocIterator const &);
232 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
233 /// \retval true if an update was needed.
234 bool checkDepm(Cursor & cur, Cursor & old);
236 /// This is used when handling LFUN_MOUSE_PRESS.
237 bool mouseSetCursor(Cursor & cur, bool select = false);
239 /// sets the selection.
240 /* When \c backwards == false, set anchor
241 * to \c cur and cursor to \c cur + \c length. When \c
242 * backwards == true, set anchor to \c cur and cursor to \c
245 void putSelectionAt(DocIterator const & cur,
246 int length, bool backwards);
248 /// selects the item at cursor if its paragraph is empty.
249 bool selectIfEmpty(DocIterator & cur);
251 /// update the internal \c ViewMetricsInfo.
252 void updateMetrics();
255 TextMetrics const & textMetrics(Text const * t) const;
256 TextMetrics & textMetrics(Text const * t);
258 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
261 CoordCache & coordCache();
263 CoordCache const & coordCache() const;
266 Point getPos(DocIterator const & dit) const;
267 /// is the paragraph of the cursor visible ?
268 bool paragraphVisible(DocIterator const & dit) const;
269 /// is the cursor currently visible in the view
270 bool cursorInView(Point const & p, int h) const;
271 /// get the position and height of the cursor
272 void cursorPosAndHeight(Point & p, int & h) const;
276 void draw(frontend::Painter & pain);
278 /// get this view's keyboard map handler.
281 Intl const & getIntl() const;
284 // Messages to the GUI
286 /// This signal is emitted when some message shows up.
287 void message(docstring const & msg);
289 /// This signal is emitted when some dialog needs to be shown.
290 void showDialog(std::string const & name);
292 /// This signal is emitted when some dialog needs to be shown with
294 void showDialog(std::string const & name, std::string const & data,
297 /// This signal is emitted when some dialogs needs to be updated.
298 void updateDialog(std::string const & name, std::string const & data);
301 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
304 docstring contentsOfPlaintextFile(support::FileName const & f);
305 // Insert plain text file (if filename is empty, prompt for one)
306 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
308 void insertLyXFile(support::FileName const & f);
309 /// save temporary bookmark for jump back navigation
310 void bookmarkEditPosition();
311 /// Find and return the inset associated with given dialog name.
312 Inset * editedInset(std::string const & name) const;
313 /// Associate an inset associated with given dialog name.
314 void editInset(std::string const & name, Inset * inset);
316 void clearLastInset(Inset * inset) const;
317 /// Is the mouse hovering a clickable inset or element?
318 bool clickableInset() const;
322 BufferView(BufferView const &);
323 void operator=(BufferView const &);
325 /// the position relative to (0, baseline) of outermost paragraph
326 Point coordOffset(DocIterator const & dit) const;
327 /// Update current paragraph metrics.
328 /// \return true if no further update is needed.
329 bool singleParUpdate();
331 /// The minimal size of the document that is visible. Used
332 /// when it is allowed to scroll below the document.
333 int minVisiblePart();
335 /// Search recursively for the the innermost inset that covers (x, y) position.
336 /// \retval 0 if no inset is found.
337 Inset const * getCoveringInset(
338 Text const & text, //< The Text where we start searching.
339 int x, //< x-coordinate on screen
340 int y //< y-coordinate on screen
343 /// Update the hovering status of the insets. This is called when
344 /// either the screen is updated or when the buffer has scolled.
345 void updateHoveredInset() const;
348 void updateDocumentClass(DocumentClass const * const olddc);
362 /// some space for drawing the 'nested' markers (in pixel)
363 inline int nestMargin() { return 15; }
365 /// margin for changebar
366 inline int changebarMargin() { return 12; }
370 #endif // BUFFERVIEW_H