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 void reset(int h = 0, int p = 0, int l = 0)
61 /// Total document height in pixels.
63 /// Current position in the document in pixels.
65 /// Line-scroll amount in pixels.
69 /// Screen view of a Buffer.
71 * A BufferView encapsulates a view onto a particular
72 * buffer, and allows access to operate upon it. A view
73 * is a sliding window of the entire document rendering.
74 * It is the official interface between the LyX core and
75 * the frontend WorkArea.
84 BufferView(Buffer & buffer);
88 /// return the buffer being viewed.
90 Buffer const & buffer() const;
92 /// perform pending metrics updates.
93 /** \c Update::FitCursor means first to do a FitCursor, and to
94 * force an update if screen position changes.
95 * \c Update::Force means to force an update in any case.
96 * \retval true if a screen redraw is needed
98 void processUpdateFlags(Update::flags flags);
100 /// move the screen to fit the cursor.
101 /// Only to be called with good y coordinates (after a bv::metrics)
103 /// reset the scrollbar to reflect current view position.
104 void updateScrollbar();
105 /// return the Scrollbar Parameters.
106 ScrollbarParameters const & scrollbarParameters() const;
108 /// Save the current position as bookmark.
109 /// if idx == 0, save to temp_bookmark
110 void saveBookmark(unsigned int idx);
111 /// goto a specified position, try top_id first, and then bottom_pit.
112 /// \return true if success
114 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
115 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
116 int top_id, ///< Paragraph ID, \sa Paragraph
117 pos_type top_pos ///< Position in the \c Paragraph
119 /// return the current change at the cursor.
120 Change const getCurrentChange() const;
122 /// move cursor to the named label.
123 void gotoLabel(docstring const & label);
125 /// set the cursor based on the given TeX source row.
126 void setCursorFromRow(int row);
128 /// Ensure the cursor is visible.
129 /// This method will automatically scroll and update the BufferView and updated
132 /// scroll down document by the given number of pixels.
133 void scrollDown(int pixels);
134 /// scroll up document by the given number of pixels.
135 void scrollUp(int pixels);
136 /// scroll document by the given number of pixels.
137 void scroll(int pixels);
138 /// Scroll the view by a number of pixels.
139 void scrollDocView(int pixels);
140 /// Set the cursor position based on the scrollbar one.
141 void setCursorFromScrollbar();
143 /// return the pixel width of the document view.
144 int workWidth() const;
145 /// return the pixel height of the document view.
146 int workHeight() const;
148 /// translate and insert a character, using the correct keymap.
149 void translateAndInsert(char_type c, Text * t, Cursor & cur);
151 /// return true for events that will handle.
152 FuncStatus getStatus(FuncRequest const & cmd);
153 /// execute the given function.
154 /// \return the Update::flags for further metrics update.
155 Update::flags dispatch(FuncRequest const & argument);
157 /// request an X11 selection.
158 /// \return the selected string.
159 docstring const requestSelection();
160 /// clear the X11 selection.
161 void clearSelection();
163 /// resize the BufferView.
165 void resize(int width, int height);
167 /// dispatch method helper for \c WorkArea
169 void mouseEventDispatch(FuncRequest const & ev);
171 /// access to anchor.
172 pit_type anchor_ref() const;
175 CursorStatus cursorStatus(DocIterator const & dit) const;
176 /// access to full cursor.
178 /// access to full cursor.
179 Cursor const & cursor() const;
181 /// This will also open all relevant collapsable insets.
182 void setCursor(DocIterator const &);
183 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
184 /// \retval true if an update was needed.
185 bool checkDepm(Cursor & cur, Cursor & old);
187 /// This is used when handling LFUN_MOUSE_PRESS.
188 bool mouseSetCursor(Cursor & cur, bool select = false);
190 /// sets the selection.
191 /* When \c backwards == false, set anchor
192 * to \c cur and cursor to \c cur + \c length. When \c
193 * backwards == true, set anchor to \c cur and cursor to \c
196 void putSelectionAt(DocIterator const & cur,
197 int length, bool backwards);
199 /// update the internal \c ViewMetricsInfo.
200 void updateMetrics();
203 TextMetrics const & textMetrics(Text const * t) const;
204 TextMetrics & textMetrics(Text const * t);
206 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
209 CoordCache & coordCache();
211 CoordCache const & coordCache() const;
214 Point getPos(DocIterator const & dit, bool boundary) const;
218 void draw(frontend::Painter & pain);
220 /// get this view's keyboard map handler.
223 Intl const & getIntl() const;
226 // Messages to the GUI
228 /// This signal is emitted when some message shows up.
229 void message(docstring const & msg);
231 /// This signal is emitted when some dialog needs to be shown.
232 void showDialog(std::string const & name);
234 /// This signal is emitted when some dialog needs to be shown with
236 void showDialog(std::string const & name, std::string const & data,
239 /// This signal is emitted when some dialogs needs to be updated.
240 void updateDialog(std::string const & name, std::string const & data);
243 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
246 docstring contentsOfPlaintextFile(support::FileName const & f);
247 // Insert plain text file (if filename is empty, prompt for one)
248 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
250 void insertLyXFile(support::FileName const & f);
254 BufferView(BufferView const &);
255 void operator=(BufferView const &);
257 // the position relative to (0, baseline) of outermost paragraph
258 Point coordOffset(DocIterator const & dit, bool boundary) const;
259 /// Update current paragraph metrics.
260 /// \return true if no further update is needed.
261 bool singleParUpdate();
263 /// Search recursively for the the innermost inset that covers (x, y) position.
264 /// \retval 0 if no inset is found.
265 Inset const * getCoveringInset(
266 Text const & text, //< The Text where we start searching.
267 int x, //< x-coordinate on screen
268 int y //< y-coordinate on screen
282 /// some space for drawing the 'nested' markers (in pixel)
283 inline int nestMargin() { return 15; }
285 /// margin for changebar
286 inline int changebarMargin() { return 12; }
289 inline int rightMargin() { return 10; }
293 #endif // BUFFERVIEW_H