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;
44 class ViewMetricsInfo;
52 /// Scrollbar Parameters.
53 struct ScrollbarParameters
55 void reset(int h = 0, int p = 0, int l = 0)
62 /// Total document height in pixels.
64 /// Current position in the document in pixels.
66 /// Line-scroll amount in pixels.
70 /// Screen view of a Buffer.
72 * A BufferView encapsulates a view onto a particular
73 * buffer, and allows access to operate upon it. A view
74 * is a sliding window of the entire document rendering.
75 * It is the official interface between the LyX core and
76 * the frontend WorkArea.
85 BufferView(Buffer & buffer);
89 /// return the buffer being viewed.
91 Buffer const & buffer() const;
93 /// perform pending metrics updates.
94 /** \c Update::FitCursor means first to do a FitCursor, and to
95 * force an update if screen position changes.
96 * \c Update::Force means to force an update in any case.
97 * \retval true if a screen redraw is needed
99 void processUpdateFlags(Update::flags flags);
101 /// move the screen to fit the cursor.
102 /// Only to be called with good y coordinates (after a bv::metrics)
104 /// reset the scrollbar to reflect current view position.
105 void updateScrollbar();
106 /// return the Scrollbar Parameters.
107 ScrollbarParameters const & scrollbarParameters() const;
109 /// Save the current position as bookmark.
110 /// if idx == 0, save to temp_bookmark
111 void saveBookmark(unsigned int idx);
112 /// goto a specified position, try top_id first, and then bottom_pit.
113 /// \return true if success
115 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
116 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
117 int top_id, ///< Paragraph ID, \sa Paragraph
118 pos_type top_pos ///< Position in the \c Paragraph
120 /// return the current change at the cursor.
121 Change const getCurrentChange() const;
123 /// move cursor to the named label.
124 void gotoLabel(docstring const & label);
126 /// set the cursor based on the given TeX source row.
127 void setCursorFromRow(int row);
129 /// center the document view around the cursor.
131 /// scroll down document by the given number of pixels.
132 void scrollDown(int pixels);
133 /// scroll up document by the given number of pixels.
134 void scrollUp(int pixels);
135 /// scroll document by the given number of pixels.
136 void scroll(int pixels);
137 /// Scroll the view by a number of pixels.
138 void scrollDocView(int pixels);
139 /// Set the cursor position based on the scrollbar one.
140 void setCursorFromScrollbar();
142 /// return the pixel width of the document view.
143 int workWidth() const;
144 /// return the pixel height of the document view.
145 int workHeight() const;
147 /// translate and insert a character, using the correct keymap.
148 void translateAndInsert(char_type c, Text * t, Cursor & cur);
150 /// return true for events that will handle.
151 FuncStatus getStatus(FuncRequest const & cmd);
152 /// execute the given function.
153 /// \return the Update::flags for further metrics update.
154 Update::flags dispatch(FuncRequest const & argument);
156 /// request an X11 selection.
157 /// \return the selected string.
158 docstring const requestSelection();
159 /// clear the X11 selection.
160 void clearSelection();
162 /// resize the BufferView.
164 void resize(int width, int height);
166 /// dispatch method helper for \c WorkArea
168 void mouseEventDispatch(FuncRequest const & ev);
170 /// access to anchor.
171 pit_type anchor_ref() const;
174 CursorStatus cursorStatus(DocIterator const & dit) const;
175 /// access to full cursor.
177 /// access to full cursor.
178 Cursor const & cursor() const;
180 /// This will also open all relevant collapsable insets.
181 void setCursor(DocIterator const &);
182 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
183 /// \retval true if an update was needed.
184 bool checkDepm(Cursor & cur, Cursor & old);
186 /// This is used when handling LFUN_MOUSE_PRESS.
187 bool mouseSetCursor(Cursor & cur, bool select = false);
189 /// sets the selection.
190 /* When \c backwards == false, set anchor
191 * to \c cur and cursor to \c cur + \c length. When \c
192 * backwards == true, set anchor to \c cur and cursor to \c
195 void putSelectionAt(DocIterator const & cur,
196 int length, bool backwards);
198 /// return the internal \c ViewMetricsInfo.
199 /// This is used specifically by the \c Workrea.
201 /// \sa ViewMetricsInfo
202 ViewMetricsInfo const & viewMetricsInfo();
203 /// update the internal \c ViewMetricsInfo.
204 void updateMetrics();
207 TextMetrics const & textMetrics(Text const * t) const;
208 TextMetrics & textMetrics(Text const * t);
210 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
213 CoordCache & coordCache();
215 CoordCache const & coordCache() const;
218 Point getPos(DocIterator const & dit, bool boundary) const;
222 void draw(frontend::Painter & pain);
224 /// get this view's keyboard map handler.
227 Intl const & getIntl() const;
230 // Messages to the GUI
232 /// This signal is emitted when some message shows up.
233 void message(docstring const & msg);
235 /// This signal is emitted when some dialog needs to be shown.
236 void showDialog(std::string const & name);
238 /// This signal is emitted when some dialog needs to be shown with
240 void showDialogWithData(std::string const & name, std::string const & data);
242 /// This signal is emitted when some inset dialogs needs to be shown.
243 void showInsetDialog(std::string const & name, std::string const & data,
246 /// This signal is emitted when some dialogs needs to be updated.
247 void updateDialog(std::string const & name, std::string const & data);
250 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
253 docstring contentsOfPlaintextFile(std::string const & f, bool asParagraph);
254 // Insert plain text file (if filename is empty, prompt for one)
255 void insertPlaintextFile(std::string const & fileName, bool asParagraph);
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
284 void menuInsertLyXFile(std::string const & filen);
286 void updateOffsetRef();
292 /// some space for drawing the 'nested' markers (in pixel)
293 inline int nestMargin() { return 15; }
295 /// margin for changebar
296 inline int changebarMargin() { return 12; }
299 inline int rightMargin() { return 10; }
303 #endif // BUFFERVIEW_H