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/shared_ptr.h"
22 #include "support/strfwd.h"
23 #include "support/types.h"
27 namespace support { class FileName; }
29 namespace frontend { class Painter; }
30 namespace frontend { class GuiBufferViewDelegate; }
44 class ParagraphMetrics;
55 /// Scrollbar Parameters.
56 struct ScrollbarParameters
59 : min(0), max(0), position(0), single_step(1), page_step(1)
61 /// Minimum scrollbar position in pixels.
63 /// Maximum scrollbar position in pixels.
65 /// Current position in the document in pixels.
67 /// Line-scroll amount in pixels.
69 /// Page-scroll amount in pixels.
73 /// Screen view of a Buffer.
75 * A BufferView encapsulates a view onto a particular
76 * buffer, and allows access to operate upon it. A view
77 * is a sliding window of the entire document rendering.
78 * It is the official interface between the LyX core and
79 * the frontend WorkArea.
88 explicit BufferView(Buffer & buffer);
92 /// return the buffer being viewed.
94 Buffer const & buffer() const;
97 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
100 int rightMargin() const;
103 int leftMargin() const;
105 /// \return true if the BufferView is at the top of the document.
106 bool isTopScreen() const;
108 /// \return true if the BufferView is at the bottom of the document.
109 bool isBottomScreen() const;
111 /// perform pending metrics updates.
112 /** \c Update::FitCursor means first to do a FitCursor, and to
113 * force an update if screen position changes.
114 * \c Update::Force means to force an update in any case.
115 * \retval true if a screen redraw is needed
117 void processUpdateFlags(Update::flags flags);
119 /// move the screen to fit the cursor.
120 /// Only to be called with good y coordinates (after a bv::metrics)
122 /// reset the scrollbar to reflect current view position.
123 void updateScrollbar();
124 /// return the Scrollbar Parameters.
125 ScrollbarParameters const & scrollbarParameters() const;
126 /// \return Tool tip for the given position.
127 docstring toolTip(int x, int y) const;
128 /// \return the context menu for the given position.
129 std::string contextMenu(int x, int y) const;
131 /// Save the current position as bookmark.
132 /// if idx == 0, save to temp_bookmark
133 void saveBookmark(unsigned int idx);
134 /// goto a specified position, try top_id first, and then bottom_pit.
135 /// \return true if success
137 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
138 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
139 int top_id, ///< Paragraph ID, \sa Paragraph
140 pos_type top_pos ///< Position in the \c Paragraph
142 /// return the current change at the cursor.
143 Change const getCurrentChange() const;
145 /// move cursor to the named label.
146 void gotoLabel(docstring const & label);
148 /// set the cursor based on the given TeX source row.
149 void setCursorFromRow(int row);
151 /// set cursor to the given inset. Return true if found.
152 bool setCursorFromInset(Inset const *);
153 /// Recenters the BufferView such that the passed cursor
154 /// is in the center.
156 /// Ensure that the BufferView cursor is visible.
157 /// This method will automatically scroll and update the BufferView
160 /// Ensure the passed cursor \p dit is visible.
161 /// This method will automatically scroll and update the BufferView
163 /// \param recenter Whether the cursor should be centered on screen
164 void showCursor(DocIterator const & dit, bool recenter,
166 /// Scroll to the cursor.
167 void scrollToCursor();
168 /// Scroll to the cursor.
169 /// \param recenter Whether the cursor should be centered on screen
170 bool scrollToCursor(DocIterator const & dit, bool recenter);
171 /// scroll down document by the given number of pixels.
172 int scrollDown(int pixels);
173 /// scroll up document by the given number of pixels.
174 int scrollUp(int pixels);
175 /// scroll document by the given number of pixels.
176 int scroll(int pixels);
177 /// Scroll the view by a number of pixels.
178 void scrollDocView(int pixels, bool update);
179 /// Set the cursor position based on the scrollbar one.
180 void setCursorFromScrollbar();
182 /// return the pixel width of the document view.
183 int workWidth() const;
184 /// return the pixel height of the document view.
185 int workHeight() const;
187 /// return the inline completion postfix.
188 docstring const & inlineCompletion() const;
189 /// return the number of unique characters in the inline completion.
190 size_t const & inlineCompletionUniqueChars() const;
191 /// return the position in the buffer of the inline completion postfix.
192 DocIterator const & inlineCompletionPos() const;
193 /// make sure inline completion position is OK
194 void resetInlineCompletionPos();
195 /// set the inline completion postfix and its position in the buffer.
196 /// Updates the updateFlags in \c cur.
197 void setInlineCompletion(Cursor const & cur, DocIterator const & pos,
198 docstring const & completion, size_t uniqueChars = 0);
200 /// translate and insert a character, using the correct keymap.
201 void translateAndInsert(char_type c, Text * t, Cursor & cur);
203 /// \return true if we've made a decision
204 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
205 /// execute the given function.
206 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
208 /// request an X11 selection.
209 /// \return the selected string.
210 docstring const requestSelection();
211 /// clear the X11 selection.
212 void clearSelection();
214 /// resize the BufferView.
216 void resize(int width, int height);
218 /// dispatch method helper for \c WorkArea
220 void mouseEventDispatch(FuncRequest const & ev);
222 /// access to anchor.
223 pit_type anchor_ref() const;
226 CursorStatus cursorStatus(DocIterator const & dit) const;
227 /// access to full cursor.
229 /// access to full cursor.
230 Cursor const & cursor() const;
232 /// This will also open all relevant collapsable insets.
233 void setCursor(DocIterator const &);
234 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
235 /// \retval true if an update was needed.
236 bool checkDepm(Cursor & cur, Cursor & old);
238 /// This is used when handling LFUN_MOUSE_PRESS.
239 bool mouseSetCursor(Cursor & cur, bool select = false);
241 /// sets the selection.
242 /* When \c backwards == false, set anchor
243 * to \c cur and cursor to \c cur + \c length. When \c
244 * backwards == true, set anchor to \c cur and cursor to \c
247 void putSelectionAt(DocIterator const & cur,
248 int length, bool backwards);
250 /// selects the item at cursor if its paragraph is empty.
251 bool selectIfEmpty(DocIterator & cur);
253 /// update the internal \c ViewMetricsInfo.
254 void updateMetrics();
257 TextMetrics const & textMetrics(Text const * t) const;
258 TextMetrics & textMetrics(Text const * t);
260 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
263 CoordCache & coordCache();
265 CoordCache const & coordCache() const;
268 Point getPos(DocIterator const & dit) const;
269 /// is the paragraph of the cursor visible ?
270 bool paragraphVisible(DocIterator const & dit) const;
271 /// is the cursor currently visible in the view
272 bool cursorInView(Point const & p, int h) const;
273 /// get the position and height of the cursor
274 void cursorPosAndHeight(Point & p, int & h) const;
278 void draw(frontend::Painter & pain);
280 /// get this view's keyboard map handler.
283 Intl const & getIntl() const;
286 // Messages to the GUI
288 /// This signal is emitted when some message shows up.
289 void message(docstring const & msg);
291 /// This signal is emitted when some dialog needs to be shown.
292 void showDialog(std::string const & name);
294 /// This signal is emitted when some dialog needs to be shown with
296 void showDialog(std::string const & name, std::string const & data,
299 /// This signal is emitted when some dialogs needs to be updated.
300 void updateDialog(std::string const & name, std::string const & data);
303 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
306 docstring contentsOfPlaintextFile(support::FileName const & f);
307 // Insert plain text file (if filename is empty, prompt for one)
308 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
310 void insertLyXFile(support::FileName const & f);
311 /// save temporary bookmark for jump back navigation
312 void bookmarkEditPosition();
313 /// Find and return the inset associated with given dialog name.
314 Inset * editedInset(std::string const & name) const;
315 /// Associate an inset associated with given dialog name.
316 void editInset(std::string const & name, Inset * inset);
318 void clearLastInset(Inset * inset) const;
319 /// Is the mouse hovering a clickable inset or element?
320 bool clickableInset() const;
322 void makeDocumentClass();
326 BufferView(BufferView const &);
327 void operator=(BufferView const &);
329 /// the position relative to (0, baseline) of outermost paragraph
330 Point coordOffset(DocIterator const & dit) const;
331 /// Update current paragraph metrics.
332 /// \return true if no further update is needed.
333 bool singleParUpdate();
335 /// The minimal size of the document that is visible. Used
336 /// when it is allowed to scroll below the document.
337 int minVisiblePart();
339 /// Search recursively for the innermost inset that covers (x, y) position.
340 /// \retval 0 if no inset is found.
341 Inset const * getCoveringInset(
342 Text const & text, //< The Text where we start searching.
343 int x, //< x-coordinate on screen
344 int y //< y-coordinate on screen
347 /// Update the hovering status of the insets. This is called when
348 /// either the screen is updated or when the buffer has scolled.
349 void updateHoveredInset() const;
352 void updateDocumentClass(DocumentClassConstPtr olddc);
366 /// some space for drawing the 'nested' markers (in pixel)
367 inline int nestMargin() { return 15; }
369 /// margin for changebar
370 inline int changebarMargin() { return 12; }
374 #endif // BUFFERVIEW_H