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 "CoordCache.h"
20 #include "MetricsInfo.h"
21 #include "TextMetrics.h"
22 #include "update_flags.h"
24 #include "support/types.h"
26 #include <boost/tuple/tuple.hpp>
27 #include <boost/utility.hpp>
28 #include <boost/signal.hpp>
36 namespace support { class FileName; }
38 namespace frontend { class Painter; }
49 class ParagraphMetrics;
50 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.
82 class BufferView : boost::noncopyable {
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 bool update(Update::flags flags = Update::FitCursor | Update::Force);
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 document by the given number of lines of default height.
132 void scroll(int lines);
133 /// Scroll the view by a number of pixels.
134 void scrollDocView(int pixels);
135 /// Set the cursor position based on the scrollbar one.
136 void setCursorFromScrollbar();
138 /// return the pixel width of the document view.
139 int workWidth() const;
140 /// return the pixel height of the document view.
141 int workHeight() const;
143 /// translate and insert a character, using the correct keymap.
144 void translateAndInsert(char_type c, Text * t, Cursor & cur);
146 /// return true for events that will handle.
147 FuncStatus getStatus(FuncRequest const & cmd);
148 /// execute the given function.
149 /// \return the Update::flags for further metrics update.
150 Update::flags dispatch(FuncRequest const & argument);
152 /// request an X11 selection.
153 /// \return the selected string.
154 docstring const requestSelection();
155 /// clear the X11 selection.
156 void clearSelection();
158 /// resize the BufferView.
160 void resize(int width, int height);
162 /// dispatch method helper for \c WorkArea
164 /// \retval true if a redraw is needed
165 bool workAreaDispatch(FuncRequest const & ev);
167 /// access to anchor.
168 pit_type anchor_ref() const;
170 /// access to full cursor.
172 /// access to full cursor.
173 Cursor const & cursor() const;
175 /// This will also open all relevant collapsable insets.
176 void setCursor(DocIterator const &);
177 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
178 /// \retval true if an update was needed.
179 bool checkDepm(Cursor & cur, Cursor & old);
181 /// This is used when handling LFUN_MOUSE_PRESS.
182 bool mouseSetCursor(Cursor & cur);
184 /// sets the selection.
185 /* When \c backwards == false, set anchor
186 * to \c cur and cursor to \c cur + \c length. When \c
187 * backwards == true, set anchor to \c cur and cursor to \c
190 void putSelectionAt(DocIterator const & cur,
191 int length, bool backwards);
193 /// return the internal \c ViewMetricsInfo.
194 /// This is used specifically by the \c Workrea.
196 /// \sa ViewMetricsInfo
197 ViewMetricsInfo const & viewMetricsInfo();
198 /// update the internal \c ViewMetricsInfo.
199 /// \param singlepar indicates wether
200 void updateMetrics(bool singlepar = false);
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() {
213 CoordCache const & coordCache() const {
218 void draw(frontend::Painter & pain);
220 /// get this view's keyboard map handler.
221 Intl & getIntl() { return *intl_.get(); }
223 Intl const & getIntl() const { return *intl_.get(); }
225 /// This signal is emitted when some message shows up.
226 boost::signal<void(docstring)> message;
228 /// This signal is emitted when some dialog needs to be shown.
229 boost::signal<void(std::string name)> showDialog;
231 /// This signal is emitted when some dialog needs to be shown with
233 boost::signal<void(std::string name,
234 std::string data)> showDialogWithData;
236 /// This signal is emitted when some inset dialogs needs to be shown.
237 boost::signal<void(std::string name, std::string data,
238 Inset * inset)> showInsetDialog;
240 /// This signal is emitted when some dialogs needs to be updated.
241 boost::signal<void(std::string name,
242 std::string data)> updateDialog;
244 /// This signal is emitted when the layout at the cursor is changed.
245 boost::signal<void(docstring layout)> layoutChanged;
251 /// Search recursively for the the innermost inset that covers (x, y) position.
252 /// \retval 0 if no inset is found.
253 Inset const * getCoveringInset(
254 Text const & text, //< The Text where we start searching.
255 int x, //< x-coordinate on screen
256 int y //< y-coordinate on screen
264 ScrollbarParameters scrollbarParameters_;
267 ViewMetricsInfo metrics_info_;
269 CoordCache coord_cache_;
273 /// Estimated average par height for scrollbar.
276 void menuInsertLyXFile(std::string const & filen);
278 /// this is used to handle XSelection events in the right manner.
287 bool multiparsel_cache_;
289 pit_type anchor_ref_;
293 void updateOffsetRef();
295 bool need_centering_;
297 /// keyboard mapping object.
298 boost::scoped_ptr<Intl> const intl_;
300 /// last visited inset (kept to send setMouseHover(false) )
303 /// A map from a Text to the associated text metrics
304 typedef std::map<Text const *, TextMetrics> TextMetricsCache;
305 mutable TextMetricsCache text_metrics_;
308 /// some space for drawing the 'nested' markers (in pixel)
309 inline int nestMargin() { return 15; }
311 /// margin for changebar
312 inline int changebarMargin() { return 12; }
315 inline int rightMargin() { return 10; }
319 #endif // BUFFERVIEW_H