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 /// load a buffer into the view.
97 bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
99 /// perform pending metrics updates.
100 /** \c Update::FitCursor means first to do a FitCursor, and to
101 * force an update if screen position changes.
102 * \c Update::Force means to force an update in any case.
103 * \retval true if a screen redraw is needed
105 bool update(Update::flags flags = Update::FitCursor | Update::Force);
107 /// move the screen to fit the cursor.
108 /// Only to be called with good y coordinates (after a bv::metrics)
110 /// reset the scrollbar to reflect current view position.
111 void updateScrollbar();
112 /// return the Scrollbar Parameters.
113 ScrollbarParameters const & scrollbarParameters() const;
115 /// Save the current position as bookmark.
116 /// if persistent=false, save to temp_bookmark
117 void saveBookmark(bool persistent);
118 /// goto a specified position, try par_id first, and then par_pit
119 /// return the par_pit and par_id of the new paragraph
120 boost::tuple<pit_type, int> moveToPosition(
121 pit_type par_pit, ///< Paragraph pit, used when par_id is zero or invalid.
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 /// move cursor to the named label.
129 void gotoLabel(docstring const & label);
131 /// set the cursor based on the given TeX source row.
132 void setCursorFromRow(int row);
134 /// center the document view around the cursor.
136 /// scroll document by the given number of lines of default height.
137 void scroll(int lines);
138 /// Scroll the view by a number of pixels.
139 void scrollDocView(int pixels);
140 /// Set the cursor position based on the scrollbar one.
141 void setCursorFromScrollbar();
143 /// return the pixel width of the document view.
144 int workWidth() const;
145 /// return the pixel height of the document view.
146 int workHeight() const;
148 /// switch between primary and secondary keymaps for RTL entry.
151 /// return true for events that will handle.
152 FuncStatus getStatus(FuncRequest const & cmd);
153 /// execute the given function.
154 /// \return the Update::flags for further metrics update.
155 Update::flags dispatch(FuncRequest const & argument);
157 /// request an X11 selection.
158 /// \return the selected string.
159 docstring const requestSelection();
160 /// clear the X11 selection.
161 void clearSelection();
163 /// resize method helper for \c WorkArea
166 void workAreaResize(int width, int height);
168 /// dispatch method helper for \c WorkArea
170 /// \retval true if a redraw is needed
171 bool workAreaDispatch(FuncRequest const & ev);
173 /// access to anchor.
174 pit_type anchor_ref() const;
176 /// access to full cursor.
178 /// access to full cursor.
179 LCursor const & cursor() const;
181 /// This will also open all relevant collapsable insets.
182 void setCursor(DocIterator const &);
183 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
184 /// \retval true if an update was needed.
185 bool checkDepm(LCursor & cur, LCursor & old);
187 /// This is used when handling LFUN_MOUSE_PRESS.
188 bool mouseSetCursor(LCursor & cur);
190 /// sets the selection.
191 /* When \c backwards == false, set anchor
192 * to \c cur and cursor to \c cur + \c length. When \c
193 * backwards == true, set anchor to \c cur and cursor to \c
196 void putSelectionAt(DocIterator const & cur,
197 int length, bool backwards);
199 /// return the internal \c ViewMetricsInfo.
200 /// This is used specifically by the \c Workrea.
202 /// \sa ViewMetricsInfo
203 ViewMetricsInfo const & viewMetricsInfo();
204 /// update the internal \c ViewMetricsInfo.
205 /// \param singlepar indicates wether
206 void updateMetrics(bool singlepar = false);
209 TextMetrics const & textMetrics(LyXText const * t) const;
210 TextMetrics & textMetrics(LyXText const * t);
212 ParagraphMetrics const & parMetrics(LyXText const *, pit_type) const;
215 CoordCache & coordCache() {
219 CoordCache const & coordCache() const {
222 /// get this view's keyboard map handler.
223 Intl & getIntl() { return *intl_.get(); }
225 Intl const & getIntl() const { return *intl_.get(); }
227 /// This signal is emitted when some message shows up.
228 boost::signal<void(docstring)> message;
230 /// This signal is emitted when some dialog needs to be shown.
231 boost::signal<void(std::string name)> showDialog;
233 /// This signal is emitted when some dialog needs to be shown with
235 boost::signal<void(std::string name,
236 std::string data)> showDialogWithData;
238 /// This signal is emitted when some inset dialogs needs to be shown.
239 boost::signal<void(std::string name, std::string data,
240 InsetBase * inset)> showInsetDialog;
242 /// This signal is emitted when some dialogs needs to be updated.
243 boost::signal<void(std::string name,
244 std::string data)> updateDialog;
246 /// This signal is emitted when the layout at the cursor is changed.
247 boost::signal<void(std::string layout)> layoutChanged;
257 ScrollbarParameters scrollbarParameters_;
260 ViewMetricsInfo metrics_info_;
262 CoordCache coord_cache_;
266 /// Estimated average par height for scrollbar.
269 void menuInsertLyXFile(std::string const & filen);
271 /// this is used to handle XSelection events in the right manner.
280 bool multiparsel_cache_;
282 pit_type anchor_ref_;
286 /// keyboard mapping object.
287 boost::scoped_ptr<Intl> const intl_;
289 /// last visited inset (kept to send setMouseHover(false) )
290 InsetBase * last_inset_;
292 /// A map from a LyXText to the associated text metrics
293 typedef std::map<LyXText const *, TextMetrics> TextMetricsCache;
294 mutable TextMetricsCache text_metrics_;
300 #endif // BUFFERVIEW_H