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 "UpdateFlags.h"
24 #include "support/types.h"
26 #include <boost/utility.hpp>
27 #include <boost/signal.hpp>
35 namespace support { class FileName; }
46 class ParagraphMetrics;
47 class ViewMetricsInfo;
49 /// Scrollbar Parameters.
50 struct ScrollbarParameters
52 void reset(int h = 0, int p = 0, int l = 0)
59 /// Total document height in pixels.
61 /// Current position in the document in pixels.
63 /// Line-scroll amount in pixels.
67 /// Screen view of a Buffer.
69 * A BufferView encapsulates a view onto a particular
70 * buffer, and allows access to operate upon it. A view
71 * is a sliding window of the entire document rendering.
72 * It is the official interface between the LyX core and
73 * the frontend WorkArea.
79 class BufferView : boost::noncopyable {
85 /// set the buffer we are viewing.
86 /// \todo FIXME: eventually, we will create a new BufferView
87 /// when switching Buffers, so this method should go.
88 void setBuffer(Buffer * b);
89 /// return the buffer being viewed.
90 Buffer * buffer() const;
92 /// resize the BufferView.
95 /// redisplay the referenced buffer.
97 /// load a buffer into the view.
98 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
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 persistent=false, save to temp_bookmark
118 void saveBookmark(bool persistent);
119 /// goto a specified position.
121 int par_id, ///< Paragraph ID, \sa Paragraph
122 pos_type par_pos ///< Position in the \c Paragraph
124 /// return the current change at the cursor.
125 Change const getCurrentChange() const;
127 /// return the lyxtext we are using.
128 LyXText * getLyXText();
130 /// return the lyxtext we are using.
131 LyXText const * getLyXText() const;
133 /// move cursor to the named label.
134 void gotoLabel(docstring const & label);
136 /// set the cursor based on the given TeX source row.
137 void setCursorFromRow(int row);
139 /// center the document view around the cursor.
141 /// scroll document by the given number of lines of default height.
142 void scroll(int lines);
143 /// Scroll the view by a number of pixels.
144 void scrollDocView(int pixels);
145 /// Set the cursor position based on the scrollbar one.
146 void setCursorFromScrollbar();
148 /// return the pixel width of the document view.
149 int workWidth() const;
150 /// return the pixel height of the document view.
151 int workHeight() const;
153 /// switch between primary and secondary keymaps for RTL entry.
156 /// return true for events that will handle.
157 FuncStatus getStatus(FuncRequest const & cmd);
158 /// execute the given function.
159 bool dispatch(FuncRequest const & argument);
161 /// request an X11 selection.
162 /// \return the selected string.
163 docstring const requestSelection();
164 /// clear the X11 selection.
165 void clearSelection();
167 /// resize method helper for \c WorkArea
170 void workAreaResize(int width, int height);
172 /// dispatch method helper for \c WorkArea
174 /// \retval true if a redraw is needed
175 bool workAreaDispatch(FuncRequest const & ev);
177 /// access to anchor.
178 pit_type anchor_ref() const;
180 /// access to full cursor.
182 /// access to full cursor.
183 LCursor const & cursor() const;
185 /// This will also open all relevant collapsable insets.
186 void setCursor(DocIterator const &);
187 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
188 /// \retval true if an update was needed.
189 bool checkDepm(LCursor & cur, LCursor & old);
191 /// This is used when handling LFUN_MOUSE_PRESS.
192 bool 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 TextMetrics const & textMetrics(LyXText const * t) const;
214 TextMetrics & textMetrics(LyXText const * t);
216 ParagraphMetrics const & parMetrics(LyXText const *, pit_type) const;
219 CoordCache & coordCache() {
223 CoordCache const & coordCache() const {
226 /// get this view's keyboard map handler.
227 Intl & getIntl() { return *intl_.get(); }
229 Intl const & getIntl() const { return *intl_.get(); }
231 /// This signal is emitted when some message shows up.
232 boost::signal<void(docstring)> message;
234 /// This signal is emitted when some dialog needs to be shown.
235 boost::signal<void(std::string name)> showDialog;
237 /// This signal is emitted when some dialog needs to be shown with
239 boost::signal<void(std::string name,
240 std::string data)> showDialogWithData;
242 /// This signal is emitted when some inset dialogs needs to be shown.
243 boost::signal<void(std::string name, std::string data,
244 InsetBase * inset)> showInsetDialog;
246 /// This signal is emitted when some dialogs needs to be updated.
247 boost::signal<void(std::string name,
248 std::string data)> updateDialog;
250 /// This signal is emitted when the layout at the cursor is changed.
251 boost::signal<void(std::string layout)> layoutChanged;
261 ScrollbarParameters scrollbarParameters_;
264 ViewMetricsInfo metrics_info_;
266 CoordCache coord_cache_;
270 /// Estimated average par height for scrollbar.
273 void menuInsertLyXFile(std::string const & filen);
275 /// this is used to handle XSelection events in the right manner.
284 bool multiparsel_cache_;
286 pit_type anchor_ref_;
290 /// keyboard mapping object.
291 boost::scoped_ptr<Intl> const intl_;
293 /// last visited inset (kept to send setMouseHover(false) )
294 InsetBase * last_inset_;
296 /// A map from a LyXText to the associated text metrics
297 typedef std::map<LyXText const *, TextMetrics> TextMetricsCache;
298 mutable TextMetricsCache text_metrics_;
304 #endif // BUFFERVIEW_H