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 /// center the document view around the cursor.
130 /// scroll down document by the given number of pixels.
131 void scrollDown(int pixels);
132 /// scroll up document by the given number of pixels.
133 void scrollUp(int pixels);
134 /// scroll document by the given number of pixels.
135 void scroll(int pixels);
136 /// Scroll the view by a number of pixels.
137 void scrollDocView(int pixels);
138 /// Set the cursor position based on the scrollbar one.
139 void setCursorFromScrollbar();
141 /// return the pixel width of the document view.
142 int workWidth() const;
143 /// return the pixel height of the document view.
144 int workHeight() const;
146 /// translate and insert a character, using the correct keymap.
147 void translateAndInsert(char_type c, Text * t, Cursor & cur);
149 /// return true for events that will handle.
150 FuncStatus getStatus(FuncRequest const & cmd);
151 /// execute the given function.
152 /// \return the Update::flags for further metrics update.
153 Update::flags dispatch(FuncRequest const & argument);
155 /// request an X11 selection.
156 /// \return the selected string.
157 docstring const requestSelection();
158 /// clear the X11 selection.
159 void clearSelection();
161 /// resize the BufferView.
163 void resize(int width, int height);
165 /// dispatch method helper for \c WorkArea
167 void mouseEventDispatch(FuncRequest const & ev);
169 /// access to anchor.
170 pit_type anchor_ref() const;
173 CursorStatus cursorStatus(DocIterator const & dit) const;
174 /// access to full cursor.
176 /// access to full cursor.
177 Cursor const & cursor() const;
179 /// This will also open all relevant collapsable insets.
180 void setCursor(DocIterator const &);
181 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
182 /// \retval true if an update was needed.
183 bool checkDepm(Cursor & cur, Cursor & old);
185 /// This is used when handling LFUN_MOUSE_PRESS.
186 bool mouseSetCursor(Cursor & cur, bool select = false);
188 /// sets the selection.
189 /* When \c backwards == false, set anchor
190 * to \c cur and cursor to \c cur + \c length. When \c
191 * backwards == true, set anchor to \c cur and cursor to \c
194 void putSelectionAt(DocIterator const & cur,
195 int length, bool backwards);
197 /// update the internal \c ViewMetricsInfo.
198 void updateMetrics();
201 TextMetrics const & textMetrics(Text const * t) const;
202 TextMetrics & textMetrics(Text const * t);
204 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
207 CoordCache & coordCache();
209 CoordCache const & coordCache() const;
212 Point getPos(DocIterator const & dit, bool boundary) const;
216 void draw(frontend::Painter & pain);
218 /// get this view's keyboard map handler.
221 Intl const & getIntl() const;
224 // Messages to the GUI
226 /// This signal is emitted when some message shows up.
227 void message(docstring const & msg);
229 /// This signal is emitted when some dialog needs to be shown.
230 void showDialog(std::string const & name);
232 /// This signal is emitted when some dialog needs to be shown with
234 void showDialog(std::string const & name, std::string const & data,
237 /// This signal is emitted when some dialogs needs to be updated.
238 void updateDialog(std::string const & name, std::string const & data);
241 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
244 docstring contentsOfPlaintextFile(std::string const & f, bool asParagraph);
245 // Insert plain text file (if filename is empty, prompt for one)
246 void insertPlaintextFile(std::string const & fileName, bool asParagraph);
250 BufferView(BufferView const &);
251 void operator=(BufferView const &);
253 // the position relative to (0, baseline) of outermost paragraph
254 Point coordOffset(DocIterator const & dit, bool boundary) const;
255 /// Update current paragraph metrics.
256 /// \return true if no further update is needed.
257 bool singleParUpdate();
259 /// Search recursively for the the innermost inset that covers (x, y) position.
260 /// \retval 0 if no inset is found.
261 Inset const * getCoveringInset(
262 Text const & text, //< The Text where we start searching.
263 int x, //< x-coordinate on screen
264 int y //< y-coordinate on screen
275 void menuInsertLyXFile(std::string const & filen);
277 void updateOffsetRef();
283 /// some space for drawing the 'nested' markers (in pixel)
284 inline int nestMargin() { return 15; }
286 /// margin for changebar
287 inline int changebarMargin() { return 12; }
290 inline int rightMargin() { return 10; }
294 #endif // BUFFERVIEW_H