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; }
40 class ParagraphMetrics;
51 /// Scrollbar Parameters.
52 struct ScrollbarParameters
54 /// Minimum scrollbar position in pixels.
56 /// Maximum scrollbar position in pixels.
58 /// Current position in the document in pixels.
60 /// Line-scroll amount in pixels.
62 /// Page-scroll amount in pixels.
66 /// Screen view of a Buffer.
68 * A BufferView encapsulates a view onto a particular
69 * buffer, and allows access to operate upon it. A view
70 * is a sliding window of the entire document rendering.
71 * It is the official interface between the LyX core and
72 * the frontend WorkArea.
81 explicit BufferView(Buffer & buffer);
85 /// return the buffer being viewed.
87 Buffer const & buffer() const;
90 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
93 int rightMargin() const;
96 int leftMargin() const;
98 /// \return true if the BufferView is at the top of the document.
99 bool isTopScreen() const;
101 /// \return true if the BufferView is at the bottom of the document.
102 bool isBottomScreen() const;
104 /// perform pending metrics updates.
105 /** \c Update::FitCursor means first to do a FitCursor, and to
106 * force an update if screen position changes.
107 * \c Update::Force means to force an update in any case.
108 * \retval true if a screen redraw is needed
110 void processUpdateFlags(Update::flags flags);
112 /// move the screen to fit the cursor.
113 /// Only to be called with good y coordinates (after a bv::metrics)
115 /// reset the scrollbar to reflect current view position.
116 void updateScrollbar();
117 /// return the Scrollbar Parameters.
118 ScrollbarParameters const & scrollbarParameters() const;
119 /// \return Tool tip for the given position.
120 docstring toolTip(int x, int y) const;
121 /// \return the context menu for the given position.
122 docstring contextMenu(int x, int y) const;
124 /// Save the current position as bookmark.
125 /// if idx == 0, save to temp_bookmark
126 void saveBookmark(unsigned int idx);
127 /// goto a specified position, try top_id first, and then bottom_pit.
128 /// \return true if success
130 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
131 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
132 int top_id, ///< Paragraph ID, \sa Paragraph
133 pos_type top_pos ///< Position in the \c Paragraph
135 /// return the current change at the cursor.
136 Change const getCurrentChange() const;
138 /// move cursor to the named label.
139 void gotoLabel(docstring const & label);
141 /// set the cursor based on the given TeX source row.
142 void setCursorFromRow(int row);
144 /// Ensure that the BufferView cursor is visible.
145 /// This method will automatically scroll and update the BufferView
148 /// Ensure the passed cursor \p dit is visible.
149 /// This method will automatically scroll and update the BufferView
151 void showCursor(DocIterator const & dit);
152 /// LFUN_SCROLL Helper.
153 void lfunScroll(FuncRequest const & cmd);
154 /// scroll down document by the given number of pixels.
155 void scrollDown(int pixels);
156 /// scroll up document by the given number of pixels.
157 void scrollUp(int pixels);
158 /// scroll document by the given number of pixels.
159 void scroll(int pixels);
160 /// Scroll the view by a number of pixels.
161 void scrollDocView(int pixels);
162 /// Set the cursor position based on the scrollbar one.
163 void setCursorFromScrollbar();
165 /// return the pixel width of the document view.
166 int workWidth() const;
167 /// return the pixel height of the document view.
168 int workHeight() const;
170 /// return the inline completion postfix.
171 docstring const & inlineCompletion() const;
172 /// return the number of unique characters in the inline completion.
173 size_t const & inlineCompletionUniqueChars() const;
174 /// return the position in the buffer of the inline completion postfix.
175 DocIterator const & inlineCompletionPos() const;
176 /// set the inline completion postfix and its position in the buffer.
177 /// Updates the updateFlags in \c cur.
178 void setInlineCompletion(Cursor & cur, DocIterator const & pos,
179 docstring const & completion, size_t uniqueChars = 0);
181 /// translate and insert a character, using the correct keymap.
182 void translateAndInsert(char_type c, Text * t, Cursor & cur);
184 /// return true for events that will handle.
185 FuncStatus getStatus(FuncRequest const & cmd);
186 /// execute the given function.
187 /// \return true if the function has been processed.
188 bool dispatch(FuncRequest const & argument);
190 /// request an X11 selection.
191 /// \return the selected string.
192 docstring const requestSelection();
193 /// clear the X11 selection.
194 void clearSelection();
196 /// resize the BufferView.
198 void resize(int width, int height);
200 /// dispatch method helper for \c WorkArea
202 void mouseEventDispatch(FuncRequest const & ev);
204 /// access to anchor.
205 pit_type anchor_ref() const;
208 CursorStatus cursorStatus(DocIterator const & dit) const;
209 /// access to full cursor.
211 /// access to full cursor.
212 Cursor const & cursor() const;
214 /// This will also open all relevant collapsable insets.
215 void setCursor(DocIterator const &);
216 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
217 /// \retval true if an update was needed.
218 bool checkDepm(Cursor & cur, Cursor & old);
220 /// This is used when handling LFUN_MOUSE_PRESS.
221 bool mouseSetCursor(Cursor & cur, bool select = false);
223 /// sets the selection.
224 /* When \c backwards == false, set anchor
225 * to \c cur and cursor to \c cur + \c length. When \c
226 * backwards == true, set anchor to \c cur and cursor to \c
229 void putSelectionAt(DocIterator const & cur,
230 int length, bool backwards);
232 /// update the internal \c ViewMetricsInfo.
233 void updateMetrics();
236 TextMetrics const & textMetrics(Text const * t) const;
237 TextMetrics & textMetrics(Text const * t);
239 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
242 CoordCache & coordCache();
244 CoordCache const & coordCache() const;
247 Point getPos(DocIterator const & dit, bool boundary) const;
251 void draw(frontend::Painter & pain);
253 /// get this view's keyboard map handler.
256 Intl const & getIntl() const;
259 // Messages to the GUI
261 /// This signal is emitted when some message shows up.
262 void message(docstring const & msg);
264 /// This signal is emitted when some dialog needs to be shown.
265 void showDialog(std::string const & name);
267 /// This signal is emitted when some dialog needs to be shown with
269 void showDialog(std::string const & name, std::string const & data,
272 /// This signal is emitted when some dialogs needs to be updated.
273 void updateDialog(std::string const & name, std::string const & data);
276 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
279 docstring contentsOfPlaintextFile(support::FileName const & f);
280 // Insert plain text file (if filename is empty, prompt for one)
281 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
283 void insertLyXFile(support::FileName const & f);
287 BufferView(BufferView const &);
288 void operator=(BufferView const &);
290 // the position relative to (0, baseline) of outermost paragraph
291 Point coordOffset(DocIterator const & dit, bool boundary) const;
292 /// Update current paragraph metrics.
293 /// \return true if no further update is needed.
294 bool singleParUpdate();
296 /// Search recursively for the the innermost inset that covers (x, y) position.
297 /// \retval 0 if no inset is found.
298 Inset const * getCoveringInset(
299 Text const & text, //< The Text where we start searching.
300 int x, //< x-coordinate on screen
301 int y //< y-coordinate on screen
317 /// some space for drawing the 'nested' markers (in pixel)
318 inline int nestMargin() { return 15; }
320 /// margin for changebar
321 inline int changebarMargin() { return 12; }
325 #endif // BUFFERVIEW_H