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 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 /// \retval true if a redraw is needed
169 bool workAreaDispatch(FuncRequest const & ev);
171 /// access to anchor.
172 pit_type anchor_ref() 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);
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 /// return the internal \c ViewMetricsInfo.
198 /// This is used specifically by the \c Workrea.
200 /// \sa ViewMetricsInfo
201 ViewMetricsInfo const & viewMetricsInfo();
202 /// update the internal \c ViewMetricsInfo.
203 /// \param singlepar indicates wether
204 void updateMetrics(bool singlepar = false);
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() {
217 CoordCache const & coordCache() const {
222 void draw(frontend::Painter & pain);
224 /// get this view's keyboard map handler.
225 Intl & getIntl() { return *intl_.get(); }
227 Intl const & getIntl() const { return *intl_.get(); }
229 /// This signal is emitted when some message shows up.
230 boost::signal<void(docstring)> message;
232 /// This signal is emitted when some dialog needs to be shown.
233 boost::signal<void(std::string name)> showDialog;
235 /// This signal is emitted when some dialog needs to be shown with
237 boost::signal<void(std::string name,
238 std::string data)> showDialogWithData;
240 /// This signal is emitted when some inset dialogs needs to be shown.
241 boost::signal<void(std::string name, std::string data,
242 Inset * inset)> showInsetDialog;
244 /// This signal is emitted when some dialogs needs to be updated.
245 boost::signal<void(std::string name,
246 std::string data)> updateDialog;
248 /// This signal is emitted when the layout at the cursor is changed.
249 boost::signal<void(docstring layout)> layoutChanged;
255 /// Search recursively for the the innermost inset that covers (x, y) position.
256 /// \retval 0 if no inset is found.
257 Inset const * getCoveringInset(
258 Text const & text, //< The Text where we start searching.
259 int x, //< x-coordinate on screen
260 int y //< y-coordinate on screen
268 ScrollbarParameters scrollbarParameters_;
271 ViewMetricsInfo metrics_info_;
273 CoordCache coord_cache_;
277 /// Estimated average par height for scrollbar.
280 void menuInsertLyXFile(std::string const & filen);
282 /// this is used to handle XSelection events in the right manner.
291 bool multiparsel_cache_;
293 pit_type anchor_ref_;
297 void updateOffsetRef();
299 bool need_centering_;
301 /// keyboard mapping object.
302 boost::scoped_ptr<Intl> const intl_;
304 /// last visited inset (kept to send setMouseHover(false) )
307 /// A map from a Text to the associated text metrics
308 typedef std::map<Text const *, TextMetrics> TextMetricsCache;
309 mutable TextMetricsCache text_metrics_;
312 /// some space for drawing the 'nested' markers (in pixel)
313 inline int nestMargin() { return 15; }
315 /// margin for changebar
316 inline int changebarMargin() { return 12; }
319 inline int rightMargin() { return 10; }
323 #endif // BUFFERVIEW_H