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 /// The total document height in pixels
56 /// The current position in the document, in pixels
58 /// the line-scroll amount, in pixels
63 * A buffer view encapsulates a view onto a particular
64 * buffer, and allows access to operate upon it. A view
65 * is a sliding window of the entire document rendering.
67 * Eventually we will allow several views onto a single
68 * buffer, but not yet.
70 class BufferView : boost::noncopyable {
76 /// set the buffer we are viewing
77 void setBuffer(Buffer * b);
78 /// return the buffer being viewed
79 Buffer * buffer() const;
81 /// resize event has happened
84 /// reload the contained buffer
86 /// load a buffer into the view
87 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
89 /** perform pending painting updates. \c fitcursor means first
90 * to do a fitcursor, and to force an update if screen
91 * position changes. \c forceupdate means to force an update
93 * \return true if a full updateMetrics() is needed.
95 bool update(Update::flags flags = Update::FitCursor | Update::Force);
97 /// move the screen to fit the cursor. Only to be called with
98 /// good y coordinates (after a bv::metrics)
100 /// reset the scrollbar to reflect current view position
101 void updateScrollbar();
102 /// return the Scrollbar Parameters
103 ScrollbarParameters const & scrollbarParameters() const;
105 /// Save the current position as bookmark, if persistent=false, save to temp_bookmark
106 void saveBookmark(bool persistent);
107 /// goto a specified position
108 void moveToPosition(int par_id, pos_type par_pos);
109 /// return the current change at the cursor
110 Change const getCurrentChange() const;
112 /// return the lyxtext we are using
113 LyXText * getLyXText();
115 /// return the lyxtext we are using
116 LyXText const * getLyXText() const;
118 /// move cursor to the named label
119 void gotoLabel(docstring const & label);
121 /// set the cursor based on the given TeX source row
122 void setCursorFromRow(int row);
124 /// center the document view around the cursor
126 /// scroll document by the given number of lines of default height
127 void scroll(int lines);
128 /// Scroll the view by a number of pixels
129 void scrollDocView(int pixels);
130 /// Set the cursor position based on the scrollbar one.
131 void setCursorFromScrollbar();
133 /// return the pixel width of the document view
134 int workWidth() const;
135 /// return the pixel height of the document view
136 int workHeight() const;
138 /// switch between primary and secondary keymaps for RTL entry
141 /// return true for events that will handle
142 FuncStatus getStatus(FuncRequest const & cmd);
143 /// execute the given function
144 bool dispatch(FuncRequest const & argument);
147 docstring const requestSelection();
149 void clearSelection();
152 void workAreaResize(int width, int height);
154 /// dispatch method that should be executed from the workarea
155 /// \return true if a full redraw is needed.
156 bool workAreaDispatch(FuncRequest const & ev);
159 pit_type anchor_ref() const;
161 /// access to full cursor
163 /// access to full cursor
164 LCursor const & cursor() const;
165 /// sets cursor and open all relevant collapsable insets.
166 void setCursor(DocIterator const &);
167 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
168 void mouseSetCursor(LCursor & cur);
170 /* Sets the selection. When \c backwards == false, set anchor
171 * to \c cur and cursor to \c cur + \c length. When \c
172 * backwards == true, set anchor to \c cur and cursor to \c
175 void putSelectionAt(DocIterator const & cur,
176 int length, bool backwards);
178 ViewMetricsInfo const & viewMetricsInfo();
180 void updateMetrics(bool singlepar = false);
183 CoordCache & coordCache() {
187 CoordCache const & coordCache() const {
190 /// get this view's keyboard map handler
191 Intl & getIntl() { return *intl_.get(); }
193 Intl const & getIntl() const { return *intl_.get(); }
195 /// This signal is emitted when some message shows up.
196 boost::signal<void(docstring)> message;
198 /// This signal is emitted when some dialog needs to be shown.
199 boost::signal<void(std::string name)> showDialog;
201 /// This signal is emitted when some dialog needs to be shown with
203 boost::signal<void(std::string name,
204 std::string data)> showDialogWithData;
206 /// This signal is emitted when some inset dialogs needs to be shown.
207 boost::signal<void(std::string name, std::string data,
208 InsetBase * inset)> showInsetDialog;
210 /// This signal is emitted when some dialogs needs to be updated.
211 boost::signal<void(std::string name,
212 std::string data)> updateDialog;
214 /// This signal is emitted when the layout at the cursor is changed.
215 boost::signal<void(std::string layout)> layoutChanged;
225 ScrollbarParameters scrollbarParameters_;
228 ViewMetricsInfo metrics_info_;
229 CoordCache coord_cache_;
233 /// Estimated average par height for scrollbar
237 void menuInsertLyXFile(std::string const & filen);
239 /// this is used to handle XSelection events in the right manner
248 bool multiparsel_cache_;
250 pit_type anchor_ref_;
254 /// keyboard mapping object
255 boost::scoped_ptr<Intl> const intl_;
261 #endif // BUFFERVIEW_H