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>
42 class ViewMetricsInfo;
44 /// Scrollbar Parameters.
45 struct ScrollbarParameters
47 void reset(int h = 0, int p = 0, int l = 0)
54 /// Total document height in pixels.
56 /// Current position in the document in pixels.
58 /// Line-scroll amount in pixels.
62 /// Screen view of a Buffer.
64 * A BufferView encapsulates a view onto a particular
65 * buffer, and allows access to operate upon it. A view
66 * is a sliding window of the entire document rendering.
67 * It is the official interface between the LyX core and
68 * the frontend WorkArea.
74 class BufferView : boost::noncopyable {
80 /// set the buffer we are viewing.
81 /// \todo FIXME: eventually, we will create a new BufferView
82 /// when switching Buffers, so this method should go.
83 void setBuffer(Buffer * b);
84 /// return the buffer being viewed.
85 Buffer * buffer() const;
87 /// resize the BufferView.
90 /// redisplay the referenced buffer.
92 /// load a buffer into the view.
93 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
95 /// perform pending painting updates.
96 /** \c fitcursor means first
97 * to do a fitcursor, and to force an update if screen
98 * position changes. \c forceupdate means to force an update
100 * \return true if a full updateMetrics() is needed.
102 bool update(Update::flags flags = Update::FitCursor | Update::Force);
104 /// move the screen to fit the cursor.
105 /// Only to be called with good y coordinates (after a bv::metrics)
107 /// reset the scrollbar to reflect current view position.
108 void updateScrollbar();
109 /// return the Scrollbar Parameters.
110 ScrollbarParameters const & scrollbarParameters() const;
112 /// Save the current position as bookmark.
113 /// if persistent=false, save to temp_bookmark
114 void saveBookmark(bool persistent);
115 /// goto a specified position.
117 int par_id, ///< Paragraph ID, \sa Paragraph
118 pos_type par_pos ///< Position in the \c Paragraph
120 /// return the current change at the cursor.
121 Change const getCurrentChange() const;
123 /// return the lyxtext we are using.
124 LyXText * getLyXText();
126 /// return the lyxtext we are using.
127 LyXText const * getLyXText() const;
129 /// move cursor to the named label.
130 void gotoLabel(docstring const & label);
132 /// set the cursor based on the given TeX source row.
133 void setCursorFromRow(int row);
135 /// center the document view around the cursor.
137 /// scroll document by the given number of lines of default height.
138 void scroll(int lines);
139 /// Scroll the view by a number of pixels.
140 void scrollDocView(int pixels);
141 /// Set the cursor position based on the scrollbar one.
142 void setCursorFromScrollbar();
144 /// return the pixel width of the document view.
145 int workWidth() const;
146 /// return the pixel height of the document view.
147 int workHeight() const;
149 /// switch between primary and secondary keymaps for RTL entry.
152 /// return true for events that will handle.
153 FuncStatus getStatus(FuncRequest const & cmd);
154 /// execute the given function.
155 bool 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 /// \return true if a full 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 &);
184 /// This is used when handling LFUN_MOUSE_PRESS.
185 void mouseSetCursor(LCursor & cur);
187 /// sets the selection.
188 /* When \c backwards == false, set anchor
189 * to \c cur and cursor to \c cur + \c length. When \c
190 * backwards == true, set anchor to \c cur and cursor to \c
193 void putSelectionAt(DocIterator const & cur,
194 int length, bool backwards);
196 /// return the internal \c ViewMetricsInfo.
197 /// This is used specifically by the \c Workrea.
199 /// \sa ViewMetricsInfo
200 ViewMetricsInfo const & viewMetricsInfo();
201 /// update the internal \c ViewMetricsInfo.
202 /// \param singlepar indicates wether
203 void updateMetrics(bool singlepar = false);
206 CoordCache & coordCache() {
210 CoordCache const & coordCache() const {
213 /// get this view's keyboard map handler.
214 Intl & getIntl() { return *intl_.get(); }
216 Intl const & getIntl() const { return *intl_.get(); }
218 /// This signal is emitted when some message shows up.
219 boost::signal<void(docstring)> message;
221 /// This signal is emitted when some dialog needs to be shown.
222 boost::signal<void(std::string name)> showDialog;
224 /// This signal is emitted when some dialog needs to be shown with
226 boost::signal<void(std::string name,
227 std::string data)> showDialogWithData;
229 /// This signal is emitted when some inset dialogs needs to be shown.
230 boost::signal<void(std::string name, std::string data,
231 InsetBase * inset)> showInsetDialog;
233 /// This signal is emitted when some dialogs needs to be updated.
234 boost::signal<void(std::string name,
235 std::string data)> updateDialog;
237 /// This signal is emitted when the layout at the cursor is changed.
238 boost::signal<void(std::string layout)> layoutChanged;
248 ScrollbarParameters scrollbarParameters_;
251 ViewMetricsInfo metrics_info_;
253 CoordCache coord_cache_;
257 /// Estimated average par height for scrollbar.
260 void menuInsertLyXFile(std::string const & filen);
262 /// this is used to handle XSelection events in the right manner.
271 bool multiparsel_cache_;
273 pit_type anchor_ref_;
277 /// keyboard mapping object.
278 boost::scoped_ptr<Intl> const intl_;
284 #endif // BUFFERVIEW_H