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 the cursor is visible.
131 /// This method will automatically scroll and update the BufferView and updated
134 /// LFUN_SCROLL Helper.
135 void lfunScroll(FuncRequest const & cmd);
136 /// scroll down document by the given number of pixels.
137 void scrollDown(int pixels);
138 /// scroll up document by the given number of pixels.
139 void scrollUp(int pixels);
140 /// scroll document by the given number of pixels.
141 void scroll(int pixels);
142 /// Scroll the view by a number of pixels.
143 void scrollDocView(int pixels);
144 /// Set the cursor position based on the scrollbar one.
145 void setCursorFromScrollbar();
147 /// return the pixel width of the document view.
148 int workWidth() const;
149 /// return the pixel height of the document view.
150 int workHeight() const;
153 /// translate and insert a character, using the correct keymap.
154 void translateAndInsert(char_type c, Text * t, Cursor & cur);
156 /// return true for events that will handle.
157 FuncStatus getStatus(FuncRequest const & cmd);
158 /// execute the given function.
159 /// \return true if the function has been processed.
160 bool dispatch(FuncRequest const & argument);
162 /// request an X11 selection.
163 /// \return the selected string.
164 docstring const requestSelection();
165 /// clear the X11 selection.
166 void clearSelection();
168 /// resize the BufferView.
170 void resize(int width, int height);
172 /// dispatch method helper for \c WorkArea
174 void mouseEventDispatch(FuncRequest const & ev);
176 /// access to anchor.
177 pit_type anchor_ref() const;
180 CursorStatus cursorStatus(DocIterator const & dit) const;
181 /// access to full cursor.
183 /// access to full cursor.
184 Cursor const & cursor() const;
186 /// This will also open all relevant collapsable insets.
187 void setCursor(DocIterator const &);
188 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
189 /// \retval true if an update was needed.
190 bool checkDepm(Cursor & cur, Cursor & old);
192 /// This is used when handling LFUN_MOUSE_PRESS.
193 bool mouseSetCursor(Cursor & cur, bool select = false);
195 /// sets the selection.
196 /* When \c backwards == false, set anchor
197 * to \c cur and cursor to \c cur + \c length. When \c
198 * backwards == true, set anchor to \c cur and cursor to \c
201 void putSelectionAt(DocIterator const & cur,
202 int length, bool backwards);
204 /// update the internal \c ViewMetricsInfo.
205 void updateMetrics();
208 TextMetrics const & textMetrics(Text const * t) const;
209 TextMetrics & textMetrics(Text const * t);
211 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
214 CoordCache & coordCache();
216 CoordCache const & coordCache() const;
219 Point getPos(DocIterator const & dit, bool boundary) const;
223 void draw(frontend::Painter & pain);
225 /// get this view's keyboard map handler.
228 Intl const & getIntl() const;
231 // Messages to the GUI
233 /// This signal is emitted when some message shows up.
234 void message(docstring const & msg);
236 /// This signal is emitted when some dialog needs to be shown.
237 void showDialog(std::string const & name);
239 /// This signal is emitted when some dialog needs to be shown with
241 void showDialog(std::string const & name, std::string const & data,
244 /// This signal is emitted when some dialogs needs to be updated.
245 void updateDialog(std::string const & name, std::string const & data);
248 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
251 docstring contentsOfPlaintextFile(support::FileName const & f);
252 // Insert plain text file (if filename is empty, prompt for one)
253 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
255 void insertLyXFile(support::FileName const & f);
259 BufferView(BufferView const &);
260 void operator=(BufferView const &);
262 // the position relative to (0, baseline) of outermost paragraph
263 Point coordOffset(DocIterator const & dit, bool boundary) const;
264 /// Update current paragraph metrics.
265 /// \return true if no further update is needed.
266 bool singleParUpdate();
268 /// Search recursively for the the innermost inset that covers (x, y) position.
269 /// \retval 0 if no inset is found.
270 Inset const * getCoveringInset(
271 Text const & text, //< The Text where we start searching.
272 int x, //< x-coordinate on screen
273 int y //< y-coordinate on screen
287 /// some space for drawing the 'nested' markers (in pixel)
288 inline int nestMargin() { return 15; }
290 /// margin for changebar
291 inline int changebarMargin() { return 12; }
294 inline int rightMargin() { return 10; }
298 #endif // BUFFERVIEW_H