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 "UpdateFlags.h"
22 #include "support/types.h"
24 #include <boost/utility.hpp>
25 #include <boost/signal.hpp>
43 class ViewMetricsInfo;
45 /// Scrollbar Parameters.
46 struct ScrollbarParameters
48 void reset(int h = 0, int p = 0, int l = 0)
55 /// Total document height in pixels.
57 /// Current position in the document in pixels.
59 /// Line-scroll amount in pixels.
63 /// Screen view of a Buffer.
65 * A BufferView encapsulates a view onto a particular
66 * buffer, and allows access to operate upon it. A view
67 * is a sliding window of the entire document rendering.
68 * It is the official interface between the LyX core and
69 * the frontend WorkArea.
75 class BufferView : boost::noncopyable {
81 /// set the buffer we are viewing.
82 /// \todo FIXME: eventually, we will create a new BufferView
83 /// when switching Buffers, so this method should go.
84 void setBuffer(Buffer * b);
85 /// return the buffer being viewed.
86 Buffer * buffer() const;
88 /// resize the BufferView.
91 /// redisplay the referenced buffer.
93 /// load a buffer into the view.
94 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
96 /// perform pending painting updates.
97 /** \c fitcursor means first
98 * to do a fitcursor, and to force an update if screen
99 * position changes. \c forceupdate means to force an update
101 * \retval (false, xxx) if no redraw is required
102 * \retval (true, true) if a single paragraph redraw is needed
103 * \retval (true, false) if a full redraw is needed
105 std::pair<bool, 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 persistent=false, save to temp_bookmark
117 void saveBookmark(bool persistent);
118 /// goto a specified position.
120 int par_id, ///< Paragraph ID, \sa Paragraph
121 pos_type par_pos ///< Position in the \c Paragraph
123 /// return the current change at the cursor.
124 Change const getCurrentChange() const;
126 /// return the lyxtext we are using.
127 LyXText * getLyXText();
129 /// return the lyxtext we are using.
130 LyXText const * getLyXText() const;
132 /// move cursor to the named label.
133 void gotoLabel(docstring const & label);
135 /// set the cursor based on the given TeX source row.
136 void setCursorFromRow(int row);
138 /// center the document view around the cursor.
140 /// scroll document by the given number of lines of default height.
141 void scroll(int lines);
142 /// Scroll the view by a number of pixels.
143 void scrollDocView(int pixels);
144 /// Set the cursor position based on the scrollbar one.
145 void setCursorFromScrollbar();
147 /// return the pixel width of the document view.
148 int workWidth() const;
149 /// return the pixel height of the document view.
150 int workHeight() const;
152 /// switch between primary and secondary keymaps for RTL entry.
155 /// return true for events that will handle.
156 FuncStatus getStatus(FuncRequest const & cmd);
157 /// execute the given function.
158 bool dispatch(FuncRequest const & argument);
160 /// request an X11 selection.
161 /// \return the selected string.
162 docstring const requestSelection();
163 /// clear the X11 selection.
164 void clearSelection();
166 /// resize method helper for \c WorkArea
169 void workAreaResize(int width, int height);
171 /// dispatch method helper for \c WorkArea
173 /// \retval (false, xxx) if no redraw is required
174 /// \retval (true, true) if a single paragraph redraw is needed
175 /// \retval (true, false) if a full redraw is needed
176 std::pair<bool, bool> workAreaDispatch(FuncRequest const & ev);
178 /// access to anchor.
179 pit_type anchor_ref() const;
181 /// access to full cursor.
183 /// access to full cursor.
184 LCursor const & cursor() const;
186 /// This will also open all relevant collapsable insets.
187 void setCursor(DocIterator const &);
189 /// This is used when handling LFUN_MOUSE_PRESS.
190 void mouseSetCursor(LCursor & 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 CoordCache & coordCache() {
215 CoordCache const & coordCache() const {
218 /// get this view's keyboard map handler.
219 Intl & getIntl() { return *intl_.get(); }
221 Intl const & getIntl() const { return *intl_.get(); }
223 /// This signal is emitted when some message shows up.
224 boost::signal<void(docstring)> message;
226 /// This signal is emitted when some dialog needs to be shown.
227 boost::signal<void(std::string name)> showDialog;
229 /// This signal is emitted when some dialog needs to be shown with
231 boost::signal<void(std::string name,
232 std::string data)> showDialogWithData;
234 /// This signal is emitted when some inset dialogs needs to be shown.
235 boost::signal<void(std::string name, std::string data,
236 InsetBase * inset)> showInsetDialog;
238 /// This signal is emitted when some dialogs needs to be updated.
239 boost::signal<void(std::string name,
240 std::string data)> updateDialog;
242 /// This signal is emitted when the layout at the cursor is changed.
243 boost::signal<void(std::string layout)> layoutChanged;
253 ScrollbarParameters scrollbarParameters_;
256 ViewMetricsInfo metrics_info_;
258 CoordCache coord_cache_;
262 /// Estimated average par height for scrollbar.
265 void menuInsertLyXFile(std::string const & filen);
267 /// this is used to handle XSelection events in the right manner.
276 bool multiparsel_cache_;
278 pit_type anchor_ref_;
282 /// keyboard mapping object.
283 boost::scoped_ptr<Intl> const intl_;
289 #endif // BUFFERVIEW_H