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; }
47 class ParagraphMetrics;
48 class ViewMetricsInfo;
50 /// Scrollbar Parameters.
51 struct ScrollbarParameters
53 void reset(int h = 0, int p = 0, int l = 0)
60 /// Total document height in pixels.
62 /// Current position in the document in pixels.
64 /// Line-scroll amount in pixels.
68 /// Screen view of a Buffer.
70 * A BufferView encapsulates a view onto a particular
71 * buffer, and allows access to operate upon it. A view
72 * is a sliding window of the entire document rendering.
73 * It is the official interface between the LyX core and
74 * the frontend WorkArea.
80 class BufferView : boost::noncopyable {
86 /// set the buffer we are viewing.
87 /// \todo FIXME: eventually, we will create a new BufferView
88 /// when switching Buffers, so this method should go.
89 /// returns the buffer currently set
90 Buffer * setBuffer(Buffer * b);
91 /// return the buffer being viewed.
92 Buffer * buffer() const;
94 /// resize the BufferView.
97 /// perform pending metrics updates.
98 /** \c Update::FitCursor means first to do a FitCursor, and to
99 * force an update if screen position changes.
100 * \c Update::Force means to force an update in any case.
101 * \retval true if a screen redraw is needed
103 bool update(Update::flags flags = Update::FitCursor | Update::Force);
105 /// move the screen to fit the cursor.
106 /// Only to be called with good y coordinates (after a bv::metrics)
108 /// reset the scrollbar to reflect current view position.
109 void updateScrollbar();
110 /// return the Scrollbar Parameters.
111 ScrollbarParameters const & scrollbarParameters() const;
113 /// Save the current position as bookmark.
114 /// if idx == 0, save to temp_bookmark
115 void saveBookmark(unsigned int idx);
116 /// goto a specified position, try top_id first, and then bottom_pit
117 /// return the bottom_pit and top_id of the new paragraph
118 boost::tuple<pit_type, pos_type, int> moveToPosition(
119 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
120 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
121 int top_id, ///< Paragraph ID, \sa Paragraph
122 pos_type top_pos ///< Position in the \c Paragraph
124 /// return the current change at the cursor.
125 Change const getCurrentChange() const;
127 /// move cursor to the named label.
128 void gotoLabel(docstring const & label);
130 /// set the cursor based on the given TeX source row.
131 void setCursorFromRow(int row);
133 /// center the document view around the cursor.
135 /// scroll document by the given number of lines of default height.
136 void scroll(int lines);
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 method helper for \c WorkArea
165 void workAreaResize(int width, int height);
167 /// dispatch method helper for \c WorkArea
169 /// \retval true if a redraw is needed
170 bool workAreaDispatch(FuncRequest const & ev);
172 /// access to anchor.
173 pit_type anchor_ref() 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);
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 /// \param singlepar indicates wether
205 void updateMetrics(bool singlepar = false);
208 TextMetrics const & textMetrics(Text const * t) const;
209 TextMetrics & textMetrics(Text const * t);
211 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
214 CoordCache & coordCache() {
218 CoordCache const & coordCache() const {
221 /// get this view's keyboard map handler.
222 Intl & getIntl() { return *intl_.get(); }
224 Intl const & getIntl() const { return *intl_.get(); }
226 /// This signal is emitted when some message shows up.
227 boost::signal<void(docstring)> message;
229 /// This signal is emitted when some dialog needs to be shown.
230 boost::signal<void(std::string name)> showDialog;
232 /// This signal is emitted when some dialog needs to be shown with
234 boost::signal<void(std::string name,
235 std::string data)> showDialogWithData;
237 /// This signal is emitted when some inset dialogs needs to be shown.
238 boost::signal<void(std::string name, std::string data,
239 Inset * inset)> showInsetDialog;
241 /// This signal is emitted when some dialogs needs to be updated.
242 boost::signal<void(std::string name,
243 std::string data)> updateDialog;
245 /// This signal is emitted when the layout at the cursor is changed.
246 boost::signal<void(docstring layout)> layoutChanged;
252 /// Search recursively for the the innermost inset that covers (x, y) position.
253 /// \retval 0 if no inset is found.
254 Inset const * getCoveringInset(
255 Text const & text, //< The Text where we start searching.
256 int x, //< x-coordinate on screen
257 int y //< y-coordinate on screen
265 ScrollbarParameters scrollbarParameters_;
268 ViewMetricsInfo metrics_info_;
270 CoordCache coord_cache_;
274 /// Estimated average par height for scrollbar.
277 void menuInsertLyXFile(std::string const & filen);
279 /// this is used to handle XSelection events in the right manner.
288 bool multiparsel_cache_;
290 pit_type anchor_ref_;
294 /// keyboard mapping object.
295 boost::scoped_ptr<Intl> const intl_;
297 /// last visited inset (kept to send setMouseHover(false) )
300 /// A map from a Text to the associated text metrics
301 typedef std::map<Text const *, TextMetrics> TextMetricsCache;
302 mutable TextMetricsCache text_metrics_;
308 #endif // BUFFERVIEW_H