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>
33 namespace support { class FileName; }
45 class ViewMetricsInfo;
47 /// Scrollbar Parameters.
48 struct ScrollbarParameters
50 void reset(int h = 0, int p = 0, int l = 0)
57 /// Total document height in pixels.
59 /// Current position in the document in pixels.
61 /// Line-scroll amount in pixels.
65 /// Screen view of a Buffer.
67 * A BufferView encapsulates a view onto a particular
68 * buffer, and allows access to operate upon it. A view
69 * is a sliding window of the entire document rendering.
70 * It is the official interface between the LyX core and
71 * the frontend WorkArea.
77 class BufferView : boost::noncopyable {
83 /// set the buffer we are viewing.
84 /// \todo FIXME: eventually, we will create a new BufferView
85 /// when switching Buffers, so this method should go.
86 void setBuffer(Buffer * b);
87 /// return the buffer being viewed.
88 Buffer * buffer() const;
90 /// resize the BufferView.
93 /// redisplay the referenced buffer.
95 /// load a buffer into the view.
96 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
98 /// perform pending painting updates.
99 /** \c fitcursor means first
100 * to do a fitcursor, and to force an update if screen
101 * position changes. \c forceupdate means to force an update
103 * \retval (false, xxx) if no redraw is required
104 * \retval (true, true) if a single paragraph redraw is needed
105 * \retval (true, false) if a full redraw is needed
107 std::pair<bool, bool> update(Update::flags flags = Update::FitCursor | Update::Force);
109 /// move the screen to fit the cursor.
110 /// Only to be called with good y coordinates (after a bv::metrics)
112 /// reset the scrollbar to reflect current view position.
113 void updateScrollbar();
114 /// return the Scrollbar Parameters.
115 ScrollbarParameters const & scrollbarParameters() const;
117 /// Save the current position as bookmark.
118 /// if persistent=false, save to temp_bookmark
119 void saveBookmark(bool persistent);
120 /// goto a specified position.
122 int par_id, ///< Paragraph ID, \sa Paragraph
123 pos_type par_pos ///< Position in the \c Paragraph
125 /// return the current change at the cursor.
126 Change const getCurrentChange() const;
128 /// return the lyxtext we are using.
129 LyXText * getLyXText();
131 /// return the lyxtext we are using.
132 LyXText const * getLyXText() const;
134 /// move cursor to the named label.
135 void gotoLabel(docstring const & label);
137 /// set the cursor based on the given TeX source row.
138 void setCursorFromRow(int row);
140 /// center the document view around the cursor.
142 /// scroll document by the given number of lines of default height.
143 void scroll(int lines);
144 /// Scroll the view by a number of pixels.
145 void scrollDocView(int pixels);
146 /// Set the cursor position based on the scrollbar one.
147 void setCursorFromScrollbar();
149 /// return the pixel width of the document view.
150 int workWidth() const;
151 /// return the pixel height of the document view.
152 int workHeight() const;
154 /// switch between primary and secondary keymaps for RTL entry.
157 /// return true for events that will handle.
158 FuncStatus getStatus(FuncRequest const & cmd);
159 /// execute the given function.
160 bool dispatch(FuncRequest const & argument);
162 /// request an X11 selection.
163 /// \return the selected string.
164 docstring const requestSelection();
165 /// clear the X11 selection.
166 void clearSelection();
168 /// resize method helper for \c WorkArea
171 void workAreaResize(int width, int height);
173 /// dispatch method helper for \c WorkArea
175 /// \retval (false, xxx) if no redraw is required
176 /// \retval (true, true) if a single paragraph redraw is needed
177 /// \retval (true, false) if a full redraw is needed
178 std::pair<bool, bool> workAreaDispatch(FuncRequest const & ev);
180 /// access to anchor.
181 pit_type anchor_ref() const;
183 /// access to full cursor.
185 /// access to full cursor.
186 LCursor const & cursor() const;
188 /// This will also open all relevant collapsable insets.
189 void setCursor(DocIterator const &);
191 /// This is used when handling LFUN_MOUSE_PRESS.
192 void mouseSetCursor(LCursor & cur);
194 /// sets the selection.
195 /* When \c backwards == false, set anchor
196 * to \c cur and cursor to \c cur + \c length. When \c
197 * backwards == true, set anchor to \c cur and cursor to \c
200 void putSelectionAt(DocIterator const & cur,
201 int length, bool backwards);
203 /// return the internal \c ViewMetricsInfo.
204 /// This is used specifically by the \c Workrea.
206 /// \sa ViewMetricsInfo
207 ViewMetricsInfo const & viewMetricsInfo();
208 /// update the internal \c ViewMetricsInfo.
209 /// \param singlepar indicates wether
210 void updateMetrics(bool singlepar = false);
213 CoordCache & coordCache() {
217 CoordCache const & coordCache() const {
220 /// get this view's keyboard map handler.
221 Intl & getIntl() { return *intl_.get(); }
223 Intl const & getIntl() const { return *intl_.get(); }
225 /// This signal is emitted when some message shows up.
226 boost::signal<void(docstring)> message;
228 /// This signal is emitted when some dialog needs to be shown.
229 boost::signal<void(std::string name)> showDialog;
231 /// This signal is emitted when some dialog needs to be shown with
233 boost::signal<void(std::string name,
234 std::string data)> showDialogWithData;
236 /// This signal is emitted when some inset dialogs needs to be shown.
237 boost::signal<void(std::string name, std::string data,
238 InsetBase * inset)> showInsetDialog;
240 /// This signal is emitted when some dialogs needs to be updated.
241 boost::signal<void(std::string name,
242 std::string data)> updateDialog;
244 /// This signal is emitted when the layout at the cursor is changed.
245 boost::signal<void(std::string layout)> layoutChanged;
255 ScrollbarParameters scrollbarParameters_;
258 ViewMetricsInfo metrics_info_;
260 CoordCache coord_cache_;
264 /// Estimated average par height for scrollbar.
267 void menuInsertLyXFile(std::string const & filen);
269 /// this is used to handle XSelection events in the right manner.
278 bool multiparsel_cache_;
280 pit_type anchor_ref_;
284 /// keyboard mapping object.
285 boost::scoped_ptr<Intl> const intl_;
291 #endif // BUFFERVIEW_H