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; }
41 class ParagraphMetrics;
52 /// Scrollbar Parameters.
53 struct ScrollbarParameters
55 /// Minimum scrollbar position in pixels.
57 /// Maximum scrollbar position in pixels.
59 /// Current position in the document in pixels.
61 /// Line-scroll amount in pixels.
63 /// Page-scroll amount in pixels.
67 /// Screen view of a Buffer.
69 * A BufferView encapsulates a view onto a particular
70 * buffer, and allows access to operate upon it. A view
71 * is a sliding window of the entire document rendering.
72 * It is the official interface between the LyX core and
73 * the frontend WorkArea.
82 BufferView(Buffer & buffer);
86 /// return the buffer being viewed.
88 Buffer const & buffer() const;
90 /// perform pending metrics updates.
91 /** \c Update::FitCursor means first to do a FitCursor, and to
92 * force an update if screen position changes.
93 * \c Update::Force means to force an update in any case.
94 * \retval true if a screen redraw is needed
96 void processUpdateFlags(Update::flags flags);
98 /// move the screen to fit the cursor.
99 /// Only to be called with good y coordinates (after a bv::metrics)
101 /// reset the scrollbar to reflect current view position.
102 void updateScrollbar();
103 /// return the Scrollbar Parameters.
104 ScrollbarParameters const & scrollbarParameters() const;
105 /// \return Tool tip for the given position.
106 docstring toolTip(int x, int y) const;
107 /// \return the context menu for the given position.
108 docstring contextMenu(int x, int y) const;
110 /// Save the current position as bookmark.
111 /// if idx == 0, save to temp_bookmark
112 void saveBookmark(unsigned int idx);
113 /// goto a specified position, try top_id first, and then bottom_pit.
114 /// \return true if success
116 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
117 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
118 int top_id, ///< Paragraph ID, \sa Paragraph
119 pos_type top_pos ///< Position in the \c Paragraph
121 /// return the current change at the cursor.
122 Change const getCurrentChange() const;
124 /// move cursor to the named label.
125 void gotoLabel(docstring const & label);
127 /// set the cursor based on the given TeX source row.
128 void setCursorFromRow(int row);
130 /// Ensure that the BufferView cursor is visible.
131 /// This method will automatically scroll and update the BufferView
134 /// Ensure the passed cursor \p dit is visible.
135 /// This method will automatically scroll and update the BufferView
137 void showCursor(DocIterator const & dit);
138 /// LFUN_SCROLL Helper.
139 void lfunScroll(FuncRequest const & cmd);
140 /// scroll down document by the given number of pixels.
141 void scrollDown(int pixels);
142 /// scroll up document by the given number of pixels.
143 void scrollUp(int pixels);
144 /// scroll document by the given number of pixels.
145 void scroll(int pixels);
146 /// Scroll the view by a number of pixels.
147 void scrollDocView(int pixels);
148 /// Set the cursor position based on the scrollbar one.
149 void setCursorFromScrollbar();
151 /// return the pixel width of the document view.
152 int workWidth() const;
153 /// return the pixel height of the document view.
154 int workHeight() const;
157 /// translate and insert a character, using the correct keymap.
158 void translateAndInsert(char_type c, Text * t, Cursor & cur);
160 /// return true for events that will handle.
161 FuncStatus getStatus(FuncRequest const & cmd);
162 /// execute the given function.
163 /// \return true if the function has been processed.
164 bool dispatch(FuncRequest const & argument);
166 /// request an X11 selection.
167 /// \return the selected string.
168 docstring const requestSelection();
169 /// clear the X11 selection.
170 void clearSelection();
172 /// resize the BufferView.
174 void resize(int width, int height);
176 /// dispatch method helper for \c WorkArea
178 void mouseEventDispatch(FuncRequest const & ev);
180 /// access to anchor.
181 pit_type anchor_ref() const;
184 CursorStatus cursorStatus(DocIterator const & dit) const;
185 /// access to full cursor.
187 /// access to full cursor.
188 Cursor const & cursor() const;
190 /// This will also open all relevant collapsable insets.
191 void setCursor(DocIterator const &);
192 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
193 /// \retval true if an update was needed.
194 bool checkDepm(Cursor & cur, Cursor & old);
196 /// This is used when handling LFUN_MOUSE_PRESS.
197 bool mouseSetCursor(Cursor & cur, bool select = false);
199 /// sets the selection.
200 /* When \c backwards == false, set anchor
201 * to \c cur and cursor to \c cur + \c length. When \c
202 * backwards == true, set anchor to \c cur and cursor to \c
205 void putSelectionAt(DocIterator const & cur,
206 int length, bool backwards);
208 /// update the internal \c ViewMetricsInfo.
209 void updateMetrics();
212 TextMetrics const & textMetrics(Text const * t) const;
213 TextMetrics & textMetrics(Text const * t);
215 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
218 CoordCache & coordCache();
220 CoordCache const & coordCache() const;
223 Point getPos(DocIterator const & dit, bool boundary) const;
227 void draw(frontend::Painter & pain);
229 /// get this view's keyboard map handler.
232 Intl const & getIntl() const;
235 // Messages to the GUI
237 /// This signal is emitted when some message shows up.
238 void message(docstring const & msg);
240 /// This signal is emitted when some dialog needs to be shown.
241 void showDialog(std::string const & name);
243 /// This signal is emitted when some dialog needs to be shown with
245 void showDialog(std::string const & name, std::string const & data,
248 /// This signal is emitted when some dialogs needs to be updated.
249 void updateDialog(std::string const & name, std::string const & data);
252 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
255 docstring contentsOfPlaintextFile(support::FileName const & f);
256 // Insert plain text file (if filename is empty, prompt for one)
257 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
259 void insertLyXFile(support::FileName const & f);
263 BufferView(BufferView const &);
264 void operator=(BufferView const &);
266 // the position relative to (0, baseline) of outermost paragraph
267 Point coordOffset(DocIterator const & dit, bool boundary) const;
268 /// Update current paragraph metrics.
269 /// \return true if no further update is needed.
270 bool singleParUpdate();
272 /// Search recursively for the the innermost inset that covers (x, y) position.
273 /// \retval 0 if no inset is found.
274 Inset const * getCoveringInset(
275 Text const & text, //< The Text where we start searching.
276 int x, //< x-coordinate on screen
277 int y //< y-coordinate on screen
291 /// some space for drawing the 'nested' markers (in pixel)
292 inline int nestMargin() { return 15; }
294 /// margin for changebar
295 inline int changebarMargin() { return 12; }
298 inline int rightMargin() { return 10; }
302 #endif // BUFFERVIEW_H