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 metrics updates.
99 /** \c Update::FitCursor means first to do a FitCursor, and to
100 * force an update if screen position changes.
101 * \c Update::Force means to force an update in any case.
102 * \retval true if a screen redraw is needed
104 bool update(Update::flags flags = Update::FitCursor | Update::Force);
106 /// move the screen to fit the cursor.
107 /// Only to be called with good y coordinates (after a bv::metrics)
109 /// reset the scrollbar to reflect current view position.
110 void updateScrollbar();
111 /// return the Scrollbar Parameters.
112 ScrollbarParameters const & scrollbarParameters() const;
114 /// Save the current position as bookmark.
115 /// if persistent=false, save to temp_bookmark
116 void saveBookmark(bool persistent);
117 /// goto a specified position.
119 int par_id, ///< Paragraph ID, \sa Paragraph
120 pos_type par_pos ///< Position in the \c Paragraph
122 /// return the current change at the cursor.
123 Change const getCurrentChange() const;
125 /// return the lyxtext we are using.
126 LyXText * getLyXText();
128 /// return the lyxtext we are using.
129 LyXText const * getLyXText() const;
131 /// move cursor to the named label.
132 void gotoLabel(docstring const & label);
134 /// set the cursor based on the given TeX source row.
135 void setCursorFromRow(int row);
137 /// center the document view around the cursor.
139 /// scroll document by the given number of lines of default height.
140 void scroll(int lines);
141 /// Scroll the view by a number of pixels.
142 void scrollDocView(int pixels);
143 /// Set the cursor position based on the scrollbar one.
144 void setCursorFromScrollbar();
146 /// return the pixel width of the document view.
147 int workWidth() const;
148 /// return the pixel height of the document view.
149 int workHeight() const;
151 /// switch between primary and secondary keymaps for RTL entry.
154 /// return true for events that will handle.
155 FuncStatus getStatus(FuncRequest const & cmd);
156 /// execute the given function.
157 bool 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 LCursor const & cursor() const;
183 /// This will also open all relevant collapsable insets.
184 void setCursor(DocIterator const &);
186 /// This is used when handling LFUN_MOUSE_PRESS.
187 bool mouseSetCursor(LCursor & 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 CoordCache & coordCache() {
212 CoordCache const & coordCache() const {
215 /// get this view's keyboard map handler.
216 Intl & getIntl() { return *intl_.get(); }
218 Intl const & getIntl() const { return *intl_.get(); }
220 /// This signal is emitted when some message shows up.
221 boost::signal<void(docstring)> message;
223 /// This signal is emitted when some dialog needs to be shown.
224 boost::signal<void(std::string name)> showDialog;
226 /// This signal is emitted when some dialog needs to be shown with
228 boost::signal<void(std::string name,
229 std::string data)> showDialogWithData;
231 /// This signal is emitted when some inset dialogs needs to be shown.
232 boost::signal<void(std::string name, std::string data,
233 InsetBase * inset)> showInsetDialog;
235 /// This signal is emitted when some dialogs needs to be updated.
236 boost::signal<void(std::string name,
237 std::string data)> updateDialog;
239 /// This signal is emitted when the layout at the cursor is changed.
240 boost::signal<void(std::string layout)> layoutChanged;
250 ScrollbarParameters scrollbarParameters_;
253 ViewMetricsInfo metrics_info_;
255 CoordCache coord_cache_;
259 /// Estimated average par height for scrollbar.
262 void menuInsertLyXFile(std::string const & filen);
264 /// this is used to handle XSelection events in the right manner.
273 bool multiparsel_cache_;
275 pit_type anchor_ref_;
279 /// keyboard mapping object.
280 boost::scoped_ptr<Intl> const intl_;
282 /// last visited inset (kept to send setMouseHover(false) )
283 InsetBase * last_inset_;
289 #endif // BUFFERVIEW_H