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 /// returns the buffer or 0 if not loaded
98 Buffer * loadLyXFile(support::FileName const & name, bool auto_open = false);
100 /// perform pending metrics updates.
101 /** \c Update::FitCursor means first to do a FitCursor, and to
102 * force an update if screen position changes.
103 * \c Update::Force means to force an update in any case.
104 * \retval true if a screen redraw is needed
106 bool update(Update::flags flags = Update::FitCursor | Update::Force);
108 /// move the screen to fit the cursor.
109 /// Only to be called with good y coordinates (after a bv::metrics)
111 /// reset the scrollbar to reflect current view position.
112 void updateScrollbar();
113 /// return the Scrollbar Parameters.
114 ScrollbarParameters const & scrollbarParameters() const;
116 /// Save the current position as bookmark.
117 /// if idx == 0, save to temp_bookmark
118 void saveBookmark(unsigned int idx);
119 /// goto a specified position, try top_id first, and then bottom_pit
120 /// return the bottom_pit and top_id of the new paragraph
121 boost::tuple<pit_type, pos_type, int> moveToPosition(
122 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
123 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
124 int top_id, ///< Paragraph ID, \sa Paragraph
125 pos_type top_pos ///< Position in the \c Paragraph
127 /// return the current change at the cursor.
128 Change const getCurrentChange() const;
130 /// move cursor to the named label.
131 void gotoLabel(docstring const & label);
133 /// set the cursor based on the given TeX source row.
134 void setCursorFromRow(int row);
136 /// center the document view around the cursor.
138 /// scroll document by the given number of lines of default height.
139 void scroll(int lines);
140 /// Scroll the view by a number of pixels.
141 void scrollDocView(int pixels);
142 /// Set the cursor position based on the scrollbar one.
143 void setCursorFromScrollbar();
145 /// return the pixel width of the document view.
146 int workWidth() const;
147 /// return the pixel height of the document view.
148 int workHeight() const;
150 /// translate and insert a character, using the correct keymap.
151 void translateAndInsert(char_type c, Text * t, Cursor & cur);
153 /// return true for events that will handle.
154 FuncStatus getStatus(FuncRequest const & cmd);
155 /// execute the given function.
156 /// \return the Update::flags for further metrics update.
157 Update::flags dispatch(FuncRequest const & argument);
159 /// request an X11 selection.
160 /// \return the selected string.
161 docstring const requestSelection();
162 /// clear the X11 selection.
163 void clearSelection();
165 /// resize method helper for \c WorkArea
168 void workAreaResize(int width, int height);
170 /// dispatch method helper for \c WorkArea
172 /// \retval true if a redraw is needed
173 bool workAreaDispatch(FuncRequest const & ev);
175 /// access to anchor.
176 pit_type anchor_ref() const;
178 /// access to full cursor.
180 /// access to full cursor.
181 Cursor const & cursor() const;
183 /// This will also open all relevant collapsable insets.
184 void setCursor(DocIterator const &);
185 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
186 /// \retval true if an update was needed.
187 bool checkDepm(Cursor & cur, Cursor & old);
189 /// This is used when handling LFUN_MOUSE_PRESS.
190 bool mouseSetCursor(Cursor & cur);
192 /// sets the selection.
193 /* When \c backwards == false, set anchor
194 * to \c cur and cursor to \c cur + \c length. When \c
195 * backwards == true, set anchor to \c cur and cursor to \c
198 void putSelectionAt(DocIterator const & cur,
199 int length, bool backwards);
201 /// return the internal \c ViewMetricsInfo.
202 /// This is used specifically by the \c Workrea.
204 /// \sa ViewMetricsInfo
205 ViewMetricsInfo const & viewMetricsInfo();
206 /// update the internal \c ViewMetricsInfo.
207 /// \param singlepar indicates wether
208 void updateMetrics(bool singlepar = false);
211 TextMetrics const & textMetrics(Text const * t) const;
212 TextMetrics & textMetrics(Text const * t);
214 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
217 CoordCache & coordCache() {
221 CoordCache const & coordCache() const {
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(std::string 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 /// 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_;
311 #endif // BUFFERVIEW_H