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; }
47 class ParagraphMetrics;
48 class ViewMetricsInfo;
50 /// A map from paragraph index number to paragraph metrics
51 typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
53 /// Scrollbar Parameters.
54 struct ScrollbarParameters
56 void reset(int h = 0, int p = 0, int l = 0)
63 /// Total document height in pixels.
65 /// Current position in the document in pixels.
67 /// Line-scroll amount in pixels.
71 /// Screen view of a Buffer.
73 * A BufferView encapsulates a view onto a particular
74 * buffer, and allows access to operate upon it. A view
75 * is a sliding window of the entire document rendering.
76 * It is the official interface between the LyX core and
77 * the frontend WorkArea.
83 class BufferView : boost::noncopyable {
89 /// set the buffer we are viewing.
90 /// \todo FIXME: eventually, we will create a new BufferView
91 /// when switching Buffers, so this method should go.
92 void setBuffer(Buffer * b);
93 /// return the buffer being viewed.
94 Buffer * buffer() const;
96 /// resize the BufferView.
99 /// redisplay the referenced buffer.
101 /// load a buffer into the view.
102 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
104 /// perform pending metrics updates.
105 /** \c Update::FitCursor means first to do a FitCursor, and to
106 * force an update if screen position changes.
107 * \c Update::Force means to force an update in any case.
108 * \retval true if a screen redraw is needed
110 bool update(Update::flags flags = Update::FitCursor | Update::Force);
112 /// move the screen to fit the cursor.
113 /// Only to be called with good y coordinates (after a bv::metrics)
115 /// reset the scrollbar to reflect current view position.
116 void updateScrollbar();
117 /// return the Scrollbar Parameters.
118 ScrollbarParameters const & scrollbarParameters() const;
120 /// Save the current position as bookmark.
121 /// if persistent=false, save to temp_bookmark
122 void saveBookmark(bool persistent);
123 /// goto a specified position.
125 int par_id, ///< Paragraph ID, \sa Paragraph
126 pos_type par_pos ///< Position in the \c Paragraph
128 /// return the current change at the cursor.
129 Change const getCurrentChange() const;
131 /// return the lyxtext we are using.
132 LyXText * getLyXText();
134 /// return the lyxtext we are using.
135 LyXText const * getLyXText() const;
137 /// move cursor to the named label.
138 void gotoLabel(docstring const & label);
140 /// set the cursor based on the given TeX source row.
141 void setCursorFromRow(int row);
143 /// center the document view around the cursor.
145 /// scroll document by the given number of lines of default height.
146 void scroll(int lines);
147 /// Scroll the view by a number of pixels.
148 void scrollDocView(int pixels);
149 /// Set the cursor position based on the scrollbar one.
150 void setCursorFromScrollbar();
152 /// return the pixel width of the document view.
153 int workWidth() const;
154 /// return the pixel height of the document view.
155 int workHeight() const;
157 /// switch between primary and secondary keymaps for RTL entry.
160 /// return true for events that will handle.
161 FuncStatus getStatus(FuncRequest const & cmd);
162 /// execute the given function.
163 bool dispatch(FuncRequest const & argument);
165 /// request an X11 selection.
166 /// \return the selected string.
167 docstring const requestSelection();
168 /// clear the X11 selection.
169 void clearSelection();
171 /// resize method helper for \c WorkArea
174 void workAreaResize(int width, int height);
176 /// dispatch method helper for \c WorkArea
178 /// \retval true if a redraw is needed
179 bool workAreaDispatch(FuncRequest const & ev);
181 /// access to anchor.
182 pit_type anchor_ref() const;
184 /// access to full cursor.
186 /// access to full cursor.
187 LCursor const & cursor() const;
189 /// This will also open all relevant collapsable insets.
190 void setCursor(DocIterator const &);
192 /// This is used when handling LFUN_MOUSE_PRESS.
193 bool mouseSetCursor(LCursor & cur);
195 /// sets the selection.
196 /* When \c backwards == false, set anchor
197 * to \c cur and cursor to \c cur + \c length. When \c
198 * backwards == true, set anchor to \c cur and cursor to \c
201 void putSelectionAt(DocIterator const & cur,
202 int length, bool backwards);
204 /// return the internal \c ViewMetricsInfo.
205 /// This is used specifically by the \c Workrea.
207 /// \sa ViewMetricsInfo
208 ViewMetricsInfo const & viewMetricsInfo();
209 /// update the internal \c ViewMetricsInfo.
210 /// \param singlepar indicates wether
211 void updateMetrics(bool singlepar = false);
214 TextMetrics const & textMetrics(LyXText const * t) const;
215 TextMetrics & textMetrics(LyXText const * t);
217 ParagraphMetrics const & parMetrics(LyXText const *, pit_type) const;
220 CoordCache & coordCache() {
224 CoordCache const & coordCache() const {
227 /// get this view's keyboard map handler.
228 Intl & getIntl() { return *intl_.get(); }
230 Intl const & getIntl() const { return *intl_.get(); }
232 /// This signal is emitted when some message shows up.
233 boost::signal<void(docstring)> message;
235 /// This signal is emitted when some dialog needs to be shown.
236 boost::signal<void(std::string name)> showDialog;
238 /// This signal is emitted when some dialog needs to be shown with
240 boost::signal<void(std::string name,
241 std::string data)> showDialogWithData;
243 /// This signal is emitted when some inset dialogs needs to be shown.
244 boost::signal<void(std::string name, std::string data,
245 InsetBase * inset)> showInsetDialog;
247 /// This signal is emitted when some dialogs needs to be updated.
248 boost::signal<void(std::string name,
249 std::string data)> updateDialog;
251 /// This signal is emitted when the layout at the cursor is changed.
252 boost::signal<void(std::string layout)> layoutChanged;
262 ScrollbarParameters scrollbarParameters_;
265 ViewMetricsInfo metrics_info_;
267 CoordCache coord_cache_;
271 /// Estimated average par height for scrollbar.
274 void menuInsertLyXFile(std::string const & filen);
276 /// this is used to handle XSelection events in the right manner.
285 bool multiparsel_cache_;
287 pit_type anchor_ref_;
291 /// keyboard mapping object.
292 boost::scoped_ptr<Intl> const intl_;
294 /// last visited inset (kept to send setMouseHover(false) )
295 InsetBase * last_inset_;
297 /// A map from a LyXText to the associated text metrics
298 typedef std::map<LyXText const *, TextMetrics> TextMetricsCache;
299 mutable TextMetricsCache text_metrics_;
305 #endif // BUFFERVIEW_H