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 "Dimension.h"
19 #include "update_flags.h"
21 #include "support/docstring.h"
22 #include "support/types.h"
24 #include <boost/noncopyable.hpp>
32 namespace support { class FileName; }
34 namespace frontend { class Painter; }
35 namespace frontend { class GuiBufferViewDelegate; }
47 class ParagraphMetrics;
50 class ViewMetricsInfo;
58 /// Scrollbar Parameters.
59 struct ScrollbarParameters
61 void reset(int h = 0, int p = 0, int l = 0)
68 /// Total document height in pixels.
70 /// Current position in the document in pixels.
72 /// Line-scroll amount in pixels.
76 /// Screen view of a Buffer.
78 * A BufferView encapsulates a view onto a particular
79 * buffer, and allows access to operate upon it. A view
80 * is a sliding window of the entire document rendering.
81 * It is the official interface between the LyX core and
82 * the frontend WorkArea.
88 class BufferView : boost::noncopyable {
91 BufferView(Buffer & buffer);
95 /// return the buffer being viewed.
97 Buffer const & buffer() const;
99 /// perform pending metrics updates.
100 /** \c Update::FitCursor means first to do a FitCursor, and to
101 * force an update if screen position changes.
102 * \c Update::Force means to force an update in any case.
103 * \retval true if a screen redraw is needed
105 void processUpdateFlags(Update::flags flags);
107 /// move the screen to fit the cursor.
108 /// Only to be called with good y coordinates (after a bv::metrics)
110 /// reset the scrollbar to reflect current view position.
111 void updateScrollbar();
112 /// return the Scrollbar Parameters.
113 ScrollbarParameters const & scrollbarParameters() const;
115 /// Save the current position as bookmark.
116 /// if idx == 0, save to temp_bookmark
117 void saveBookmark(unsigned int idx);
118 /// goto a specified position, try top_id first, and then bottom_pit.
119 /// \return true if success
121 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
122 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
123 int top_id, ///< Paragraph ID, \sa Paragraph
124 pos_type top_pos ///< Position in the \c Paragraph
126 /// return the current change at the cursor.
127 Change const getCurrentChange() const;
129 /// move cursor to the named label.
130 void gotoLabel(docstring const & label);
132 /// set the cursor based on the given TeX source row.
133 void setCursorFromRow(int row);
135 /// center the document view around the cursor.
137 /// scroll down document by the given number of pixels.
138 void scrollDown(int pixels);
139 /// scroll up document by the given number of pixels.
140 void scrollUp(int pixels);
141 /// scroll document by the given number of pixels.
142 void scroll(int pixels);
143 /// Scroll the view by a number of pixels.
144 void scrollDocView(int pixels);
145 /// Set the cursor position based on the scrollbar one.
146 void setCursorFromScrollbar();
148 /// return the pixel width of the document view.
149 int workWidth() const;
150 /// return the pixel height of the document view.
151 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 the Update::flags for further metrics update.
160 Update::flags 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 /// return the internal \c ViewMetricsInfo.
205 /// This is used specifically by the \c Workrea.
207 /// \sa ViewMetricsInfo
208 ViewMetricsInfo const & viewMetricsInfo();
209 /// update the internal \c ViewMetricsInfo.
210 /// \param singlepar indicates wether
211 void updateMetrics(bool singlepar = false);
214 TextMetrics const & textMetrics(Text const * t) const;
215 TextMetrics & textMetrics(Text const * t);
217 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
220 CoordCache & coordCache();
222 CoordCache const & coordCache() const;
225 Point getPos(DocIterator const & dit, bool boundary) const;
229 void draw(frontend::Painter & pain);
231 /// get this view's keyboard map handler.
234 Intl const & getIntl() const;
237 // Messages to the GUI
239 /// This signal is emitted when some message shows up.
240 void message(docstring const & msg);
242 /// This signal is emitted when some dialog needs to be shown.
243 void showDialog(std::string const & name);
245 /// This signal is emitted when some dialog needs to be shown with
247 void showDialogWithData(std::string const & name, std::string const & data);
249 /// This signal is emitted when some inset dialogs needs to be shown.
250 void showInsetDialog(std::string const & name, std::string const & data,
253 /// This signal is emitted when some dialogs needs to be updated.
254 void updateDialog(std::string const & name, std::string const & data);
257 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
260 docstring contentsOfPlaintextFile(std::string const & f, bool asParagraph);
261 // Insert plain text file (if filename is empty, prompt for one)
262 void insertPlaintextFile(std::string const & fileName, bool asParagraph);
265 // the position relative to (0, baseline) of outermost paragraph
266 Point coordOffset(DocIterator const & dit, bool boundary) const;
267 /// Update current paragraph metrics.
268 /// \return true if no further update is needed.
269 bool singleParUpdate();
273 /// Search recursively for the the innermost inset that covers (x, y) position.
274 /// \retval 0 if no inset is found.
275 Inset const * getCoveringInset(
276 Text const & text, //< The Text where we start searching.
277 int x, //< x-coordinate on screen
278 int y //< y-coordinate on screen
289 void menuInsertLyXFile(std::string const & filen);
291 void updateOffsetRef();
297 /// some space for drawing the 'nested' markers (in pixel)
298 inline int nestMargin() { return 15; }
300 /// margin for changebar
301 inline int changebarMargin() { return 12; }
304 inline int rightMargin() { return 10; }
308 #endif // BUFFERVIEW_H