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/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 /// redisplay the referenced buffer.
98 /// load a buffer into the view.
99 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
101 /// perform pending metrics updates.
102 /** \c Update::FitCursor means first to do a FitCursor, and to
103 * force an update if screen position changes.
104 * \c Update::Force means to force an update in any case.
105 * \retval true if a screen redraw is needed
107 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, try par_id first, and then par_pit
121 /// return the par_pit and par_id of the new paragraph
122 boost::tuple<pit_type, int> moveToPosition(
123 pit_type par_pit, ///< Paragraph pit, used when par_id is zero or invalid.
124 int par_id, ///< Paragraph ID, \sa Paragraph
125 pos_type par_pos ///< Position in the \c Paragraph
127 /// return the current change at the cursor.
128 Change const getCurrentChange() const;
130 /// return the lyxtext we are using.
131 LyXText * getLyXText();
133 /// return the lyxtext we are using.
134 LyXText const * getLyXText() const;
136 /// move cursor to the named label.
137 void gotoLabel(docstring const & label);
139 /// set the cursor based on the given TeX source row.
140 void setCursorFromRow(int row);
142 /// center the document view around the cursor.
144 /// scroll document by the given number of lines of default height.
145 void scroll(int lines);
146 /// Scroll the view by a number of pixels.
147 void scrollDocView(int pixels);
148 /// Set the cursor position based on the scrollbar one.
149 void setCursorFromScrollbar();
151 /// return the pixel width of the document view.
152 int workWidth() const;
153 /// return the pixel height of the document view.
154 int workHeight() const;
156 /// switch between primary and secondary keymaps for RTL entry.
159 /// return true for events that will handle.
160 FuncStatus getStatus(FuncRequest const & cmd);
161 /// execute the given function.
162 bool dispatch(FuncRequest const & argument);
164 /// request an X11 selection.
165 /// \return the selected string.
166 docstring const requestSelection();
167 /// clear the X11 selection.
168 void clearSelection();
170 /// resize method helper for \c WorkArea
173 void workAreaResize(int width, int height);
175 /// dispatch method helper for \c WorkArea
177 /// \retval true if a redraw is needed
178 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 &);
190 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
191 /// \retval true if an update was needed.
192 bool checkDepm(LCursor & cur, LCursor & old);
194 /// This is used when handling LFUN_MOUSE_PRESS.
195 bool mouseSetCursor(LCursor & cur);
197 /// sets the selection.
198 /* When \c backwards == false, set anchor
199 * to \c cur and cursor to \c cur + \c length. When \c
200 * backwards == true, set anchor to \c cur and cursor to \c
203 void putSelectionAt(DocIterator const & cur,
204 int length, bool backwards);
206 /// return the internal \c ViewMetricsInfo.
207 /// This is used specifically by the \c Workrea.
209 /// \sa ViewMetricsInfo
210 ViewMetricsInfo const & viewMetricsInfo();
211 /// update the internal \c ViewMetricsInfo.
212 /// \param singlepar indicates wether
213 void updateMetrics(bool singlepar = false);
216 TextMetrics const & textMetrics(LyXText const * t) const;
217 TextMetrics & textMetrics(LyXText const * t);
219 ParagraphMetrics const & parMetrics(LyXText const *, pit_type) const;
222 CoordCache & coordCache() {
226 CoordCache const & coordCache() const {
229 /// get this view's keyboard map handler.
230 Intl & getIntl() { return *intl_.get(); }
232 Intl const & getIntl() const { return *intl_.get(); }
234 /// This signal is emitted when some message shows up.
235 boost::signal<void(docstring)> message;
237 /// This signal is emitted when some dialog needs to be shown.
238 boost::signal<void(std::string name)> showDialog;
240 /// This signal is emitted when some dialog needs to be shown with
242 boost::signal<void(std::string name,
243 std::string data)> showDialogWithData;
245 /// This signal is emitted when some inset dialogs needs to be shown.
246 boost::signal<void(std::string name, std::string data,
247 InsetBase * inset)> showInsetDialog;
249 /// This signal is emitted when some dialogs needs to be updated.
250 boost::signal<void(std::string name,
251 std::string data)> updateDialog;
253 /// This signal is emitted when the layout at the cursor is changed.
254 boost::signal<void(std::string layout)> layoutChanged;
264 ScrollbarParameters scrollbarParameters_;
267 ViewMetricsInfo metrics_info_;
269 CoordCache coord_cache_;
273 /// Estimated average par height for scrollbar.
276 void menuInsertLyXFile(std::string const & filen);
278 /// this is used to handle XSelection events in the right manner.
287 bool multiparsel_cache_;
289 pit_type anchor_ref_;
293 /// keyboard mapping object.
294 boost::scoped_ptr<Intl> const intl_;
296 /// last visited inset (kept to send setMouseHover(false) )
297 InsetBase * last_inset_;
299 /// A map from a LyXText to the associated text metrics
300 typedef std::map<LyXText const *, TextMetrics> TextMetricsCache;
301 mutable TextMetricsCache text_metrics_;
307 #endif // BUFFERVIEW_H