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"
22 #include "support/types.h"
24 #include <boost/utility.hpp>
25 #include <boost/signal.hpp>
39 class ViewMetricsInfo;
49 inline flags operator|(flags const f, flags const g)
51 return static_cast<flags>(int(f) | int(g));
54 inline flags operator&(flags const f, flags const g)
56 return static_cast<flags>(int(f) & int(g));
61 /// Scrollbar Parameters
62 struct ScrollbarParameters
64 void reset(int h = 0, int p = 0, int l = 0)
71 /// The total document height in pixels
73 /// The current position in the document, in pixels
75 /// the line-scroll amount, in pixels
80 * A buffer view encapsulates a view onto a particular
81 * buffer, and allows access to operate upon it. A view
82 * is a sliding window of the entire document rendering.
84 * Eventually we will allow several views onto a single
85 * buffer, but not yet.
87 class BufferView : boost::noncopyable {
93 /// set the buffer we are viewing
94 void setBuffer(Buffer * b);
95 /// return the buffer being viewed
96 Buffer * buffer() const;
98 /// resize event has happened
101 /// reload the contained buffer
103 /// load a buffer into the view
104 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
106 /** perform pending painting updates. \c fitcursor means first
107 * to do a fitcursor, and to force an update if screen
108 * position changes. \c forceupdate means to force an update
110 * \return true if a full updateMetrics() is needed.
112 bool update(Update::flags flags = Update::FitCursor | Update::Force);
114 /// move the screen to fit the cursor. Only to be called with
115 /// good y coordinates (after a bv::metrics)
117 /// reset the scrollbar to reflect current view position
118 void updateScrollbar();
119 /// return the Scrollbar Parameters
120 ScrollbarParameters const & scrollbarParameters() const;
122 /// Save the current position as bookmark i
123 void savePosition(unsigned int i);
124 /// Restore the position from bookmark i
125 void restorePosition(unsigned int i);
126 /// does the given bookmark have a saved position ?
127 bool isSavedPosition(unsigned int i);
128 /// save bookmarks to .lyx/session
129 void saveSavedPositions();
131 /// return the current change at the cursor
132 Change const getCurrentChange() const;
134 /// return the lyxtext we are using
135 LyXText * getLyXText();
137 /// return the lyxtext we are using
138 LyXText const * getLyXText() const;
140 /// move cursor to the named label
141 void gotoLabel(lyx::docstring const & label);
143 /// set the cursor based on the given TeX source row
144 void setCursorFromRow(int row);
146 /// center the document view around the cursor
148 /// scroll document by the given number of lines of default height
149 void scroll(int lines);
150 /// Scroll the view by a number of pixels
151 void scrollDocView(int pixels);
152 /// Set the cursor position based on the scrollbar one.
153 void setCursorFromScrollbar();
155 /// return the pixel width of the document view
156 int workWidth() const;
157 /// return the pixel height of the document view
158 int workHeight() const;
160 /// switch between primary and secondary keymaps for RTL entry
163 /// return true for events that will handle
164 FuncStatus getStatus(FuncRequest const & cmd);
165 /// execute the given function
166 bool dispatch(FuncRequest const & argument);
169 lyx::docstring const requestSelection();
171 void clearSelection();
174 void workAreaResize(int width, int height);
176 /// a function should be executed from the workarea
177 bool workAreaDispatch(FuncRequest const & ev);
180 lyx::pit_type anchor_ref() const;
182 /// access to full cursor
184 /// access to full cursor
185 LCursor const & cursor() const;
186 /// sets cursor and open all relevant collapsable insets.
187 void setCursor(DocIterator const &);
188 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
189 void mouseSetCursor(LCursor & cur);
191 /* Sets the selection. 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 ViewMetricsInfo const & viewMetricsInfo();
201 void updateMetrics(bool singlepar = false);
204 lyx::CoordCache & coordCache() {
208 lyx::CoordCache const & coordCache() const {
211 /// get this view's keyboard map handler
212 Intl & getIntl() { return *intl_.get(); }
214 Intl const & getIntl() const { return *intl_.get(); }
216 /// This signal is emitted when some message shows up.
217 boost::signal<void(lyx::docstring)> message;
219 /// This signal is emitted when some dialog needs to be shown.
220 boost::signal<void(std::string name)> showDialog;
222 /// This signal is emitted when some dialog needs to be shown with
224 boost::signal<void(std::string name,
225 std::string data)> showDialogWithData;
227 /// This signal is emitted when some inset dialogs needs to be shown.
228 boost::signal<void(std::string name, std::string data,
229 InsetBase * inset)> showInsetDialog;
231 /// This signal is emitted when some dialogs needs to be updated.
232 boost::signal<void(std::string name,
233 std::string data)> updateDialog;
235 /// This signal is emitted when the layout at the cursor is changed.
236 boost::signal<void(std::string layout)> layoutChanged;
246 ScrollbarParameters scrollbarParameters_;
249 ViewMetricsInfo metrics_info_;
250 lyx::CoordCache coord_cache_;
254 /// Estimated average par height for scrollbar
260 std::string filename;
261 /// Cursor paragraph Id
264 lyx::pos_type par_pos;
266 Position() : par_id(0), par_pos(0) {}
268 Position(std::string const & f, int id, lyx::pos_type pos)
269 : filename(f), par_id(id), par_pos(pos) {}
272 std::vector<Position> saved_positions;
274 void menuInsertLyXFile(std::string const & filen);
276 /// this is used to handle XSelection events in the right manner
285 bool multiparsel_cache_;
287 lyx::pit_type anchor_ref_;
291 /// keyboard mapping object
292 boost::scoped_ptr<Intl> const intl_;
295 #endif // BUFFERVIEW_H