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;
107 /// \return Tool tip for the given position.
108 docstring toolTip(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 /// scroll down document by the given number of pixels.
135 void scrollDown(int pixels);
136 /// scroll up document by the given number of pixels.
137 void scrollUp(int pixels);
138 /// scroll document by the given number of pixels.
139 void scroll(int pixels);
140 /// Scroll the view by a number of pixels.
141 void scrollDocView(int pixels);
142 /// Set the cursor position based on the scrollbar one.
143 void setCursorFromScrollbar();
145 /// return the pixel width of the document view.
146 int workWidth() const;
147 /// return the pixel height of the document view.
148 int workHeight() const;
151 /// translate and insert a character, using the correct keymap.
152 void translateAndInsert(char_type c, Text * t, Cursor & cur);
154 /// return true for events that will handle.
155 FuncStatus getStatus(FuncRequest const & cmd);
156 /// execute the given function.
157 /// \return true if the function has been processed.
158 bool dispatch(FuncRequest const & argument);
160 /// request an X11 selection.
161 /// \return the selected string.
162 docstring const requestSelection();
163 /// clear the X11 selection.
164 void clearSelection();
166 /// resize the BufferView.
168 void resize(int width, int height);
170 /// dispatch method helper for \c WorkArea
172 void mouseEventDispatch(FuncRequest const & ev);
174 /// access to anchor.
175 pit_type anchor_ref() const;
178 CursorStatus cursorStatus(DocIterator const & dit) const;
179 /// access to full cursor.
181 /// access to full cursor.
182 Cursor const & cursor() const;
184 /// This will also open all relevant collapsable insets.
185 void setCursor(DocIterator const &);
186 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
187 /// \retval true if an update was needed.
188 bool checkDepm(Cursor & cur, Cursor & old);
190 /// This is used when handling LFUN_MOUSE_PRESS.
191 bool mouseSetCursor(Cursor & cur, bool select = false);
193 /// sets the selection.
194 /* When \c backwards == false, set anchor
195 * to \c cur and cursor to \c cur + \c length. When \c
196 * backwards == true, set anchor to \c cur and cursor to \c
199 void putSelectionAt(DocIterator const & cur,
200 int length, bool backwards);
202 /// update the internal \c ViewMetricsInfo.
203 void updateMetrics();
206 TextMetrics const & textMetrics(Text const * t) const;
207 TextMetrics & textMetrics(Text const * t);
209 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
212 CoordCache & coordCache();
214 CoordCache const & coordCache() const;
217 Point getPos(DocIterator const & dit, bool boundary) const;
221 void draw(frontend::Painter & pain);
223 /// get this view's keyboard map handler.
226 Intl const & getIntl() const;
229 // Messages to the GUI
231 /// This signal is emitted when some message shows up.
232 void message(docstring const & msg);
234 /// This signal is emitted when some dialog needs to be shown.
235 void showDialog(std::string const & name);
237 /// This signal is emitted when some dialog needs to be shown with
239 void showDialog(std::string const & name, std::string const & data,
242 /// This signal is emitted when some dialogs needs to be updated.
243 void updateDialog(std::string const & name, std::string const & data);
246 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
249 docstring contentsOfPlaintextFile(support::FileName const & f);
250 // Insert plain text file (if filename is empty, prompt for one)
251 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
253 void insertLyXFile(support::FileName const & f);
257 BufferView(BufferView const &);
258 void operator=(BufferView const &);
260 // the position relative to (0, baseline) of outermost paragraph
261 Point coordOffset(DocIterator const & dit, bool boundary) const;
262 /// Update current paragraph metrics.
263 /// \return true if no further update is needed.
264 bool singleParUpdate();
266 /// Search recursively for the the innermost inset that covers (x, y) position.
267 /// \retval 0 if no inset is found.
268 Inset const * getCoveringInset(
269 Text const & text, //< The Text where we start searching.
270 int x, //< x-coordinate on screen
271 int y //< y-coordinate on screen
285 /// some space for drawing the 'nested' markers (in pixel)
286 inline int nestMargin() { return 15; }
288 /// margin for changebar
289 inline int changebarMargin() { return 12; }
292 inline int rightMargin() { return 10; }
296 #endif // BUFFERVIEW_H