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 void setBuffer(Buffer * b);
90 /// return the buffer being viewed.
91 Buffer * buffer() const;
93 /// resize the BufferView.
96 /// load a buffer into the view.
97 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
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 bool update(Update::flags flags = Update::FitCursor | Update::Force);
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 the bottom_pit and top_id of the new paragraph
120 boost::tuple<pit_type, pos_type, int> moveToPosition(
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 document by the given number of lines of default height.
138 void scroll(int lines);
139 /// Scroll the view by a number of pixels.
140 void scrollDocView(int pixels);
141 /// Set the cursor position based on the scrollbar one.
142 void setCursorFromScrollbar();
144 /// return the pixel width of the document view.
145 int workWidth() const;
146 /// return the pixel height of the document view.
147 int workHeight() const;
149 /// switch between primary and secondary keymaps for RTL entry.
152 /// return true for events that will handle.
153 FuncStatus getStatus(FuncRequest const & cmd);
154 /// execute the given function.
155 /// \return the Update::flags for further metrics update.
156 Update::flags dispatch(FuncRequest const & argument);
158 /// request an X11 selection.
159 /// \return the selected string.
160 docstring const requestSelection();
161 /// clear the X11 selection.
162 void clearSelection();
164 /// resize method helper for \c WorkArea
167 void workAreaResize(int width, int height);
169 /// dispatch method helper for \c WorkArea
171 /// \retval true if a redraw is needed
172 bool workAreaDispatch(FuncRequest const & ev);
174 /// access to anchor.
175 pit_type anchor_ref() const;
177 /// access to full cursor.
179 /// access to full cursor.
180 Cursor const & cursor() const;
182 /// This will also open all relevant collapsable insets.
183 void setCursor(DocIterator const &);
184 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
185 /// \retval true if an update was needed.
186 bool checkDepm(Cursor & cur, Cursor & old);
188 /// This is used when handling LFUN_MOUSE_PRESS.
189 bool mouseSetCursor(Cursor & cur);
191 /// sets the selection.
192 /* When \c backwards == false, set anchor
193 * to \c cur and cursor to \c cur + \c length. When \c
194 * backwards == true, set anchor to \c cur and cursor to \c
197 void putSelectionAt(DocIterator const & cur,
198 int length, bool backwards);
200 /// return the internal \c ViewMetricsInfo.
201 /// This is used specifically by the \c Workrea.
203 /// \sa ViewMetricsInfo
204 ViewMetricsInfo const & viewMetricsInfo();
205 /// update the internal \c ViewMetricsInfo.
206 /// \param singlepar indicates wether
207 void updateMetrics(bool singlepar = false);
210 TextMetrics const & textMetrics(Text const * t) const;
211 TextMetrics & textMetrics(Text const * t);
213 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
216 CoordCache & coordCache() {
220 CoordCache const & coordCache() const {
223 /// get this view's keyboard map handler.
224 Intl & getIntl() { return *intl_.get(); }
226 Intl const & getIntl() const { return *intl_.get(); }
228 /// This signal is emitted when some message shows up.
229 boost::signal<void(docstring)> message;
231 /// This signal is emitted when some dialog needs to be shown.
232 boost::signal<void(std::string name)> showDialog;
234 /// This signal is emitted when some dialog needs to be shown with
236 boost::signal<void(std::string name,
237 std::string data)> showDialogWithData;
239 /// This signal is emitted when some inset dialogs needs to be shown.
240 boost::signal<void(std::string name, std::string data,
241 Inset * inset)> showInsetDialog;
243 /// This signal is emitted when some dialogs needs to be updated.
244 boost::signal<void(std::string name,
245 std::string data)> updateDialog;
247 /// This signal is emitted when the layout at the cursor is changed.
248 boost::signal<void(std::string layout)> layoutChanged;
254 /// Search recursively for the the innermost inset that covers (x, y) position.
255 /// \retval 0 if no inset is found.
256 Inset const * getCoveringInset(
257 Text const & text, //< The Text where we start searching.
258 int x, //< x-coordinate on screen
259 int y //< y-coordinate on screen
267 ScrollbarParameters scrollbarParameters_;
270 ViewMetricsInfo metrics_info_;
272 CoordCache coord_cache_;
276 /// Estimated average par height for scrollbar.
279 void menuInsertLyXFile(std::string const & filen);
281 /// this is used to handle XSelection events in the right manner.
290 bool multiparsel_cache_;
292 pit_type anchor_ref_;
296 /// keyboard mapping object.
297 boost::scoped_ptr<Intl> const intl_;
299 /// last visited inset (kept to send setMouseHover(false) )
302 /// A map from a Text to the associated text metrics
303 typedef std::map<Text const *, TextMetrics> TextMetricsCache;
304 mutable TextMetricsCache text_metrics_;
310 #endif // BUFFERVIEW_H