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 "DocumentClassPtr.h"
19 #include "update_flags.h"
21 #include "support/strfwd.h"
22 #include "support/types.h"
26 namespace support { class FileName; }
28 namespace frontend { class Painter; }
29 namespace frontend { class GuiBufferViewDelegate; }
45 class ParagraphMetrics;
57 /// Scrollbar Parameters.
58 struct ScrollbarParameters
61 : min(0), max(0), position(0), single_step(1), page_step(1)
63 /// Minimum scrollbar position in pixels.
65 /// Maximum scrollbar position in pixels.
67 /// Current position in the document in pixels.
69 /// Line-scroll amount in pixels.
71 /// Page-scroll amount in pixels.
75 /// Screen view of a Buffer.
77 * A BufferView encapsulates a view onto a particular
78 * buffer, and allows access to operate upon it. A view
79 * is a sliding window of the entire document rendering.
80 * It is the official interface between the LyX core and
81 * the frontend WorkArea.
90 explicit BufferView(Buffer & buffer);
94 /// return the buffer being viewed.
96 Buffer const & buffer() const;
99 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
102 int rightMargin() const;
105 int leftMargin() const;
107 /// \return true if the BufferView is at the top of the document.
108 bool isTopScreen() const;
110 /// \return true if the BufferView is at the bottom of the document.
111 bool isBottomScreen() const;
113 /// perform pending metrics updates.
114 /** \c Update::FitCursor means first to do a FitCursor, and to
115 * force an update if screen position changes.
116 * \c Update::Force means to force an update in any case.
117 * \retval true if a screen redraw is needed
119 void processUpdateFlags(Update::flags flags);
121 /// return true if one shall move the screen to fit the cursor.
122 /// Only to be called with good y coordinates (after a bv::metrics)
123 bool needsFitCursor() const;
125 // Returns the amount of horizontal scrolling applied to the
126 // top-level row where the cursor lies
127 int horizScrollOffset() const;
129 // Points to the top-level row where the cursor lies (during draw).
130 CursorSlice const & currentRowSlice() const;
132 // Points to the top-level row where the cursor lied at last draw event.
133 CursorSlice const & lastRowSlice() const;
135 /// reset the scrollbar to reflect current view position.
136 void updateScrollbar();
137 /// return the Scrollbar Parameters.
138 ScrollbarParameters const & scrollbarParameters() const;
139 /// \return Tool tip for the given position.
140 docstring toolTip(int x, int y) const;
141 /// \return the context menu for the given position.
142 std::string contextMenu(int x, int y) const;
144 /// Save the current position as bookmark.
145 /// if idx == 0, save to temp_bookmark
146 void saveBookmark(unsigned int idx);
147 /// goto a specified position, try top_id first, and then bottom_pit.
148 /// \return true if success
150 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
151 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
152 int top_id, ///< Paragraph ID, \sa Paragraph
153 pos_type top_pos ///< Position in the \c Paragraph
155 /// return the current change at the cursor.
156 Change const getCurrentChange() const;
158 /// move cursor to the named label.
159 void gotoLabel(docstring const & label);
161 /// set the cursor based on the given TeX source row.
162 void setCursorFromRow(int row);
164 void setCursorFromRow(int row, TexRow const & texrow);
166 /// set cursor to the given inset. Return true if found.
167 bool setCursorFromInset(Inset const *);
168 /// Recenters the BufferView such that the passed cursor
169 /// is in the center.
171 /// Ensure that the BufferView cursor is visible.
172 /// This method will automatically scroll and update the BufferView
173 /// (metrics+drawing) if needed.
175 /// Ensure the passed cursor \p dit is visible.
176 /// This method will automatically scroll and update the BufferView
177 /// (metrics+drawing) if needed.
178 /// \param recenter Whether the cursor should be centered on screen
179 void showCursor(DocIterator const & dit, bool recenter,
181 /// Scroll to the cursor.
182 void scrollToCursor();
183 /// Scroll to the cursor.
184 /// \param recenter Whether the cursor should be centered on screen
185 bool scrollToCursor(DocIterator const & dit, bool recenter);
186 /// scroll down document by the given number of pixels.
187 int scrollDown(int pixels);
188 /// scroll up document by the given number of pixels.
189 int scrollUp(int pixels);
190 /// scroll document by the given number of pixels.
191 int scroll(int pixels);
192 /// Scroll the view by a number of pixels.
193 void scrollDocView(int pixels, bool update);
194 /// Set the cursor position based on the scrollbar one.
195 void setCursorFromScrollbar();
197 /// return the pixel width of the document view.
198 int workWidth() const;
199 /// return the pixel height of the document view.
200 int workHeight() const;
202 /// return the inline completion postfix.
203 docstring const & inlineCompletion() const;
204 /// return the number of unique characters in the inline completion.
205 size_t const & inlineCompletionUniqueChars() const;
206 /// return the position in the buffer of the inline completion postfix.
207 DocIterator const & inlineCompletionPos() const;
208 /// make sure inline completion position is OK
209 void resetInlineCompletionPos();
210 /// set the inline completion postfix and its position in the buffer.
211 /// Updates the updateFlags in \c cur.
212 void setInlineCompletion(Cursor const & cur, DocIterator const & pos,
213 docstring const & completion, size_t uniqueChars = 0);
215 /// translate and insert a character, using the correct keymap.
216 void translateAndInsert(char_type c, Text * t, Cursor & cur);
218 /// \return true if we've made a decision
219 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
220 /// execute the given function.
221 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
223 /// request an X11 selection.
224 /// \return the selected string.
225 docstring const requestSelection();
226 /// clear the X11 selection.
227 void clearSelection();
229 /// resize the BufferView.
231 void resize(int width, int height);
233 /// dispatch method helper for \c WorkArea
235 void mouseEventDispatch(FuncRequest const & ev);
237 /// access to anchor.
238 pit_type anchor_ref() const;
241 CursorStatus cursorStatus(DocIterator const & dit) const;
242 /// access to full cursor.
244 /// access to full cursor.
245 Cursor const & cursor() const;
247 /// This will also open all relevant collapsable insets.
248 void setCursor(DocIterator const &);
249 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
250 /// \retval true if an update was needed.
251 bool checkDepm(Cursor & cur, Cursor & old);
253 /// This is used when handling LFUN_MOUSE_PRESS.
254 bool mouseSetCursor(Cursor & cur, bool select = false);
256 /// sets the selection.
257 /* When \c backwards == false, set anchor
258 * to \c cur and cursor to \c cur + \c length. When \c
259 * backwards == true, set anchor to \c cur and cursor to \c
262 void putSelectionAt(DocIterator const & cur,
263 int length, bool backwards);
265 /// selects the item at cursor if its paragraph is empty.
266 bool selectIfEmpty(DocIterator & cur);
268 /// update the internal \c ViewMetricsInfo.
269 void updateMetrics();
272 TextMetrics const & textMetrics(Text const * t) const;
273 TextMetrics & textMetrics(Text const * t);
275 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
278 CoordCache & coordCache();
280 CoordCache const & coordCache() const;
283 Point getPos(DocIterator const & dit) const;
284 /// is the paragraph of the cursor visible ?
285 bool paragraphVisible(DocIterator const & dit) const;
286 /// is the cursor currently visible in the view
287 bool cursorInView(Point const & p, int h) const;
288 /// get the position and height of the cursor
289 void cursorPosAndHeight(Point & p, int & h) const;
293 void draw(frontend::Painter & pain);
295 /// get this view's keyboard map handler.
298 Intl const & getIntl() const;
301 // Messages to the GUI
303 /// This signal is emitted when some message shows up.
304 void message(docstring const & msg);
306 /// This signal is emitted when some dialog needs to be shown.
307 void showDialog(std::string const & name);
309 /// This signal is emitted when some dialog needs to be shown with
311 void showDialog(std::string const & name, std::string const & data,
314 /// This signal is emitted when some dialogs needs to be updated.
315 void updateDialog(std::string const & name, std::string const & data);
318 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
321 docstring contentsOfPlaintextFile(support::FileName const & f);
322 // Insert plain text file (if filename is empty, prompt for one)
323 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
325 void insertLyXFile(support::FileName const & f);
326 /// save temporary bookmark for jump back navigation
327 void bookmarkEditPosition();
328 /// Find and return the inset associated with given dialog name.
329 Inset * editedInset(std::string const & name) const;
330 /// Associate an inset associated with given dialog name.
331 void editInset(std::string const & name, Inset * inset);
333 void clearLastInset(Inset * inset) const;
334 /// Is the mouse hovering a clickable inset or element?
335 bool clickableInset() const;
337 void makeDocumentClass();
341 BufferView(BufferView const &);
342 void operator=(BufferView const &);
344 /// the position relative to (0, baseline) of outermost paragraph
345 Point coordOffset(DocIterator const & dit) const;
346 /// Update current paragraph metrics.
347 /// \return true if no further update is needed.
348 bool singleParUpdate();
350 // Set the row on which the cursor lives.
351 void setCurrentRowSlice(CursorSlice const & rowSlice);
353 // Check whether the row where the cursor lives needs to be scrolled.
354 // Update the drawing strategy if needed.
355 void checkCursorScrollOffset(PainterInfo & pi);
357 /// The minimal size of the document that is visible. Used
358 /// when it is allowed to scroll below the document.
359 int minVisiblePart();
361 /// Search recursively for the innermost inset that covers (x, y) position.
362 /// \retval 0 if no inset is found.
363 Inset const * getCoveringInset(
364 Text const & text, //< The Text where we start searching.
365 int x, //< x-coordinate on screen
366 int y //< y-coordinate on screen
369 /// Update the hovering status of the insets. This is called when
370 /// either the screen is updated or when the buffer has scolled.
371 void updateHoveredInset() const;
374 void updateDocumentClass(DocumentClassConstPtr olddc);
388 /// some space for drawing the 'nested' markers (in pixel)
389 inline int nestMargin() { return 15; }
391 /// margin for changebar
392 inline int changebarMargin() { return 12; }
396 #endif // BUFFERVIEW_H