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;
56 /// Scrollbar Parameters.
57 struct ScrollbarParameters
60 : min(0), max(0), position(0), single_step(1), page_step(1)
62 /// Minimum scrollbar position in pixels.
64 /// Maximum scrollbar position in pixels.
66 /// Current position in the document in pixels.
68 /// Line-scroll amount in pixels.
70 /// Page-scroll amount in pixels.
74 /// Screen view of a Buffer.
76 * A BufferView encapsulates a view onto a particular
77 * buffer, and allows access to operate upon it. A view
78 * is a sliding window of the entire document rendering.
79 * It is the official interface between the LyX core and
80 * the frontend WorkArea.
89 explicit BufferView(Buffer & buffer);
93 /// return the buffer being viewed.
95 Buffer const & buffer() const;
98 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
101 int rightMargin() const;
104 int leftMargin() const;
106 /// \return true if the BufferView is at the top of the document.
107 bool isTopScreen() const;
109 /// \return true if the BufferView is at the bottom of the document.
110 bool isBottomScreen() const;
112 /// perform pending metrics updates.
113 /** \c Update::FitCursor means first to do a FitCursor, and to
114 * force an update if screen position changes.
115 * \c Update::Force means to force an update in any case.
116 * \retval true if a screen redraw is needed
118 void processUpdateFlags(Update::flags flags);
120 /// move the screen to fit the cursor.
121 /// Only to be called with good y coordinates (after a bv::metrics)
124 // Returns the amount of horizontal scrolling applied to the
125 // top-level row where the cursor lies
126 int horizScrollOffset() const;
128 // Points to the top-level row where the cursor lies (during draw).
129 CursorSlice const & currentRowSlice() const;
131 // Points to the top-level row where the cursor lied at last draw event.
132 CursorSlice const & lastRowSlice() const;
134 /// reset the scrollbar to reflect current view position.
135 void updateScrollbar();
136 /// return the Scrollbar Parameters.
137 ScrollbarParameters const & scrollbarParameters() const;
138 /// \return Tool tip for the given position.
139 docstring toolTip(int x, int y) const;
140 /// \return the context menu for the given position.
141 std::string contextMenu(int x, int y) const;
143 /// Save the current position as bookmark.
144 /// if idx == 0, save to temp_bookmark
145 void saveBookmark(unsigned int idx);
146 /// goto a specified position, try top_id first, and then bottom_pit.
147 /// \return true if success
149 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
150 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
151 int top_id, ///< Paragraph ID, \sa Paragraph
152 pos_type top_pos ///< Position in the \c Paragraph
154 /// return the current change at the cursor.
155 Change const getCurrentChange() const;
157 /// move cursor to the named label.
158 void gotoLabel(docstring const & label);
160 /// set the cursor based on the given TeX source row.
161 void setCursorFromRow(int row);
163 /// set cursor to the given inset. Return true if found.
164 bool setCursorFromInset(Inset const *);
165 /// Recenters the BufferView such that the passed cursor
166 /// is in the center.
168 /// Ensure that the BufferView cursor is visible.
169 /// This method will automatically scroll and update the BufferView
172 /// Ensure the passed cursor \p dit is visible.
173 /// This method will automatically scroll and update the BufferView
175 /// \param recenter Whether the cursor should be centered on screen
176 void showCursor(DocIterator const & dit, bool recenter,
178 /// Scroll to the cursor.
179 void scrollToCursor();
180 /// Scroll to the cursor.
181 /// \param recenter Whether the cursor should be centered on screen
182 bool scrollToCursor(DocIterator const & dit, bool recenter);
183 /// scroll down document by the given number of pixels.
184 int scrollDown(int pixels);
185 /// scroll up document by the given number of pixels.
186 int scrollUp(int pixels);
187 /// scroll document by the given number of pixels.
188 int scroll(int pixels);
189 /// Scroll the view by a number of pixels.
190 void scrollDocView(int pixels, bool update);
191 /// Set the cursor position based on the scrollbar one.
192 void setCursorFromScrollbar();
194 /// return the pixel width of the document view.
195 int workWidth() const;
196 /// return the pixel height of the document view.
197 int workHeight() const;
199 /// return the inline completion postfix.
200 docstring const & inlineCompletion() const;
201 /// return the number of unique characters in the inline completion.
202 size_t const & inlineCompletionUniqueChars() const;
203 /// return the position in the buffer of the inline completion postfix.
204 DocIterator const & inlineCompletionPos() const;
205 /// make sure inline completion position is OK
206 void resetInlineCompletionPos();
207 /// set the inline completion postfix and its position in the buffer.
208 /// Updates the updateFlags in \c cur.
209 void setInlineCompletion(Cursor const & cur, DocIterator const & pos,
210 docstring const & completion, size_t uniqueChars = 0);
212 /// translate and insert a character, using the correct keymap.
213 void translateAndInsert(char_type c, Text * t, Cursor & cur);
215 /// \return true if we've made a decision
216 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
217 /// execute the given function.
218 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
220 /// request an X11 selection.
221 /// \return the selected string.
222 docstring const requestSelection();
223 /// clear the X11 selection.
224 void clearSelection();
226 /// resize the BufferView.
228 void resize(int width, int height);
230 /// dispatch method helper for \c WorkArea
232 void mouseEventDispatch(FuncRequest const & ev);
234 /// access to anchor.
235 pit_type anchor_ref() const;
238 CursorStatus cursorStatus(DocIterator const & dit) const;
239 /// access to full cursor.
241 /// access to full cursor.
242 Cursor const & cursor() const;
244 /// This will also open all relevant collapsable insets.
245 void setCursor(DocIterator const &);
246 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
247 /// \retval true if an update was needed.
248 bool checkDepm(Cursor & cur, Cursor & old);
250 /// This is used when handling LFUN_MOUSE_PRESS.
251 bool mouseSetCursor(Cursor & cur, bool select = false);
253 /// sets the selection.
254 /* When \c backwards == false, set anchor
255 * to \c cur and cursor to \c cur + \c length. When \c
256 * backwards == true, set anchor to \c cur and cursor to \c
259 void putSelectionAt(DocIterator const & cur,
260 int length, bool backwards);
262 /// selects the item at cursor if its paragraph is empty.
263 bool selectIfEmpty(DocIterator & cur);
265 /// update the internal \c ViewMetricsInfo.
266 void updateMetrics();
269 TextMetrics const & textMetrics(Text const * t) const;
270 TextMetrics & textMetrics(Text const * t);
272 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
275 CoordCache & coordCache();
277 CoordCache const & coordCache() const;
280 Point getPos(DocIterator const & dit) const;
281 /// is the paragraph of the cursor visible ?
282 bool paragraphVisible(DocIterator const & dit) const;
283 /// is the cursor currently visible in the view
284 bool cursorInView(Point const & p, int h) const;
285 /// get the position and height of the cursor
286 void cursorPosAndHeight(Point & p, int & h) const;
290 void draw(frontend::Painter & pain);
292 /// get this view's keyboard map handler.
295 Intl const & getIntl() const;
298 // Messages to the GUI
300 /// This signal is emitted when some message shows up.
301 void message(docstring const & msg);
303 /// This signal is emitted when some dialog needs to be shown.
304 void showDialog(std::string const & name);
306 /// This signal is emitted when some dialog needs to be shown with
308 void showDialog(std::string const & name, std::string const & data,
311 /// This signal is emitted when some dialogs needs to be updated.
312 void updateDialog(std::string const & name, std::string const & data);
315 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
318 docstring contentsOfPlaintextFile(support::FileName const & f);
319 // Insert plain text file (if filename is empty, prompt for one)
320 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
322 void insertLyXFile(support::FileName const & f);
323 /// save temporary bookmark for jump back navigation
324 void bookmarkEditPosition();
325 /// Find and return the inset associated with given dialog name.
326 Inset * editedInset(std::string const & name) const;
327 /// Associate an inset associated with given dialog name.
328 void editInset(std::string const & name, Inset * inset);
330 void clearLastInset(Inset * inset) const;
331 /// Is the mouse hovering a clickable inset or element?
332 bool clickableInset() const;
334 void makeDocumentClass();
338 BufferView(BufferView const &);
339 void operator=(BufferView const &);
341 /// the position relative to (0, baseline) of outermost paragraph
342 Point coordOffset(DocIterator const & dit) const;
343 /// Update current paragraph metrics.
344 /// \return true if no further update is needed.
345 bool singleParUpdate();
347 // Set the row on which the cursor lives.
348 void setCurrentRowSlice(CursorSlice const & rowSlice);
350 // Check whether the row where the cursor lives needs to be scrolled.
351 // Update the drawing strategy if needed.
352 void checkCursorScrollOffset(PainterInfo & pi);
354 /// The minimal size of the document that is visible. Used
355 /// when it is allowed to scroll below the document.
356 int minVisiblePart();
358 /// Search recursively for the innermost inset that covers (x, y) position.
359 /// \retval 0 if no inset is found.
360 Inset const * getCoveringInset(
361 Text const & text, //< The Text where we start searching.
362 int x, //< x-coordinate on screen
363 int y //< y-coordinate on screen
366 /// Update the hovering status of the insets. This is called when
367 /// either the screen is updated or when the buffer has scolled.
368 void updateHoveredInset() const;
371 void updateDocumentClass(DocumentClassConstPtr olddc);
385 /// some space for drawing the 'nested' markers (in pixel)
386 inline int nestMargin() { return 15; }
388 /// margin for changebar
389 inline int changebarMargin() { return 12; }
393 #endif // BUFFERVIEW_H