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; }
43 class ParagraphMetrics;
54 /// Scrollbar Parameters.
55 struct ScrollbarParameters
58 : min(0), max(0), position(0), single_step(1), page_step(1)
60 /// Minimum scrollbar position in pixels.
62 /// Maximum scrollbar position in pixels.
64 /// Current position in the document in pixels.
66 /// Line-scroll amount in pixels.
68 /// Page-scroll amount in pixels.
72 /// Screen view of a Buffer.
74 * A BufferView encapsulates a view onto a particular
75 * buffer, and allows access to operate upon it. A view
76 * is a sliding window of the entire document rendering.
77 * It is the official interface between the LyX core and
78 * the frontend WorkArea.
87 explicit BufferView(Buffer & buffer);
91 /// return the buffer being viewed.
93 Buffer const & buffer() const;
96 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
99 int rightMargin() const;
102 int leftMargin() const;
104 /// \return true if the BufferView is at the top of the document.
105 bool isTopScreen() const;
107 /// \return true if the BufferView is at the bottom of the document.
108 bool isBottomScreen() const;
110 /// perform pending metrics updates.
111 /** \c Update::FitCursor means first to do a FitCursor, and to
112 * force an update if screen position changes.
113 * \c Update::Force means to force an update in any case.
114 * \retval true if a screen redraw is needed
116 void processUpdateFlags(Update::flags flags);
118 /// move the screen to fit the cursor.
119 /// Only to be called with good y coordinates (after a bv::metrics)
121 /// reset the scrollbar to reflect current view position.
122 void updateScrollbar();
123 /// return the Scrollbar Parameters.
124 ScrollbarParameters const & scrollbarParameters() const;
125 /// \return Tool tip for the given position.
126 docstring toolTip(int x, int y) const;
127 /// \return the context menu for the given position.
128 std::string contextMenu(int x, int y) const;
130 /// Save the current position as bookmark.
131 /// if idx == 0, save to temp_bookmark
132 void saveBookmark(unsigned int idx);
133 /// goto a specified position, try top_id first, and then bottom_pit.
134 /// \return true if success
136 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
137 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
138 int top_id, ///< Paragraph ID, \sa Paragraph
139 pos_type top_pos ///< Position in the \c Paragraph
141 /// return the current change at the cursor.
142 Change const getCurrentChange() const;
144 /// move cursor to the named label.
145 void gotoLabel(docstring const & label);
147 /// set the cursor based on the given TeX source row.
148 void setCursorFromRow(int row);
150 /// set cursor to the given inset. Return true if found.
151 bool setCursorFromInset(Inset const *);
152 /// Recenters the BufferView such that the passed cursor
153 /// is in the center.
155 /// Ensure that the BufferView cursor is visible.
156 /// This method will automatically scroll and update the BufferView
159 /// Ensure the passed cursor \p dit is visible.
160 /// This method will automatically scroll and update the BufferView
162 /// \param recenter Whether the cursor should be centered on screen
163 void showCursor(DocIterator const & dit, bool recenter,
165 /// Scroll to the cursor.
166 void scrollToCursor();
167 /// Scroll to the cursor.
168 /// \param recenter Whether the cursor should be centered on screen
169 bool scrollToCursor(DocIterator const & dit, bool recenter);
170 /// scroll down document by the given number of pixels.
171 int scrollDown(int pixels);
172 /// scroll up document by the given number of pixels.
173 int scrollUp(int pixels);
174 /// scroll document by the given number of pixels.
175 int scroll(int pixels);
176 /// Scroll the view by a number of pixels.
177 void scrollDocView(int pixels, bool update);
178 /// Set the cursor position based on the scrollbar one.
179 void setCursorFromScrollbar();
181 /// return the pixel width of the document view.
182 int workWidth() const;
183 /// return the pixel height of the document view.
184 int workHeight() const;
186 /// return the inline completion postfix.
187 docstring const & inlineCompletion() const;
188 /// return the number of unique characters in the inline completion.
189 size_t const & inlineCompletionUniqueChars() const;
190 /// return the position in the buffer of the inline completion postfix.
191 DocIterator const & inlineCompletionPos() const;
192 /// make sure inline completion position is OK
193 void resetInlineCompletionPos();
194 /// set the inline completion postfix and its position in the buffer.
195 /// Updates the updateFlags in \c cur.
196 void setInlineCompletion(Cursor const & cur, DocIterator const & pos,
197 docstring const & completion, size_t uniqueChars = 0);
199 /// translate and insert a character, using the correct keymap.
200 void translateAndInsert(char_type c, Text * t, Cursor & cur);
202 /// \return true if we've made a decision
203 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
204 /// execute the given function.
205 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
207 /// request an X11 selection.
208 /// \return the selected string.
209 docstring const requestSelection();
210 /// clear the X11 selection.
211 void clearSelection();
213 /// resize the BufferView.
215 void resize(int width, int height);
217 /// dispatch method helper for \c WorkArea
219 void mouseEventDispatch(FuncRequest const & ev);
221 /// access to anchor.
222 pit_type anchor_ref() const;
225 CursorStatus cursorStatus(DocIterator const & dit) const;
226 /// access to full cursor.
228 /// access to full cursor.
229 Cursor const & cursor() const;
231 /// This will also open all relevant collapsable insets.
232 void setCursor(DocIterator const &);
233 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
234 /// \retval true if an update was needed.
235 bool checkDepm(Cursor & cur, Cursor & old);
237 /// This is used when handling LFUN_MOUSE_PRESS.
238 bool mouseSetCursor(Cursor & cur, bool select = false);
240 /// sets the selection.
241 /* When \c backwards == false, set anchor
242 * to \c cur and cursor to \c cur + \c length. When \c
243 * backwards == true, set anchor to \c cur and cursor to \c
246 void putSelectionAt(DocIterator const & cur,
247 int length, bool backwards);
249 /// selects the item at cursor if its paragraph is empty.
250 bool selectIfEmpty(DocIterator & cur);
252 /// update the internal \c ViewMetricsInfo.
253 void updateMetrics();
256 TextMetrics const & textMetrics(Text const * t) const;
257 TextMetrics & textMetrics(Text const * t);
259 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
262 CoordCache & coordCache();
264 CoordCache const & coordCache() const;
267 Point getPos(DocIterator const & dit) const;
268 /// is the paragraph of the cursor visible ?
269 bool paragraphVisible(DocIterator const & dit) const;
270 /// is the cursor currently visible in the view
271 bool cursorInView(Point const & p, int h) const;
272 /// get the position and height of the cursor
273 void cursorPosAndHeight(Point & p, int & h) const;
277 void draw(frontend::Painter & pain);
279 /// get this view's keyboard map handler.
282 Intl const & getIntl() const;
285 // Messages to the GUI
287 /// This signal is emitted when some message shows up.
288 void message(docstring const & msg);
290 /// This signal is emitted when some dialog needs to be shown.
291 void showDialog(std::string const & name);
293 /// This signal is emitted when some dialog needs to be shown with
295 void showDialog(std::string const & name, std::string const & data,
298 /// This signal is emitted when some dialogs needs to be updated.
299 void updateDialog(std::string const & name, std::string const & data);
302 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
305 docstring contentsOfPlaintextFile(support::FileName const & f);
306 // Insert plain text file (if filename is empty, prompt for one)
307 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
309 void insertLyXFile(support::FileName const & f);
310 /// save temporary bookmark for jump back navigation
311 void bookmarkEditPosition();
312 /// Find and return the inset associated with given dialog name.
313 Inset * editedInset(std::string const & name) const;
314 /// Associate an inset associated with given dialog name.
315 void editInset(std::string const & name, Inset * inset);
317 void clearLastInset(Inset * inset) const;
318 /// Is the mouse hovering a clickable inset or element?
319 bool clickableInset() const;
321 void makeDocumentClass();
325 BufferView(BufferView const &);
326 void operator=(BufferView const &);
328 /// the position relative to (0, baseline) of outermost paragraph
329 Point coordOffset(DocIterator const & dit) const;
330 /// Update current paragraph metrics.
331 /// \return true if no further update is needed.
332 bool singleParUpdate();
334 /// The minimal size of the document that is visible. Used
335 /// when it is allowed to scroll below the document.
336 int minVisiblePart();
338 /// Search recursively for the innermost inset that covers (x, y) position.
339 /// \retval 0 if no inset is found.
340 Inset const * getCoveringInset(
341 Text const & text, //< The Text where we start searching.
342 int x, //< x-coordinate on screen
343 int y //< y-coordinate on screen
346 /// Update the hovering status of the insets. This is called when
347 /// either the screen is updated or when the buffer has scolled.
348 void updateHoveredInset() const;
351 void updateDocumentClass(DocumentClassConstPtr olddc);
365 /// some space for drawing the 'nested' markers (in pixel)
366 inline int nestMargin() { return 15; }
368 /// margin for changebar
369 inline int changebarMargin() { return 12; }
373 #endif // BUFFERVIEW_H