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>
42 class ViewMetricsInfo;
52 inline flags operator|(flags const f, flags const g)
54 return static_cast<flags>(int(f) | int(g));
57 inline flags operator&(flags const f, flags const g)
59 return static_cast<flags>(int(f) & int(g));
64 /// Scrollbar Parameters
65 struct ScrollbarParameters
67 void reset(int h = 0, int p = 0, int l = 0)
74 /// The total document height in pixels
76 /// The current position in the document, in pixels
78 /// the line-scroll amount, in pixels
83 * A buffer view encapsulates a view onto a particular
84 * buffer, and allows access to operate upon it. A view
85 * is a sliding window of the entire document rendering.
87 * Eventually we will allow several views onto a single
88 * buffer, but not yet.
90 class BufferView : boost::noncopyable {
96 /// set the buffer we are viewing
97 void setBuffer(Buffer * b);
98 /// return the buffer being viewed
99 Buffer * buffer() const;
101 /// resize event has happened
104 /// reload the contained buffer
106 /// load a buffer into the view
107 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
109 /** perform pending painting updates. \c fitcursor means first
110 * to do a fitcursor, and to force an update if screen
111 * position changes. \c forceupdate means to force an update
113 * \return true if a full updateMetrics() is needed.
115 bool update(Update::flags flags = Update::FitCursor | Update::Force);
117 /// move the screen to fit the cursor. Only to be called with
118 /// good y coordinates (after a bv::metrics)
120 /// reset the scrollbar to reflect current view position
121 void updateScrollbar();
122 /// return the Scrollbar Parameters
123 ScrollbarParameters const & scrollbarParameters() const;
125 /// Save the current position as bookmark i
126 void savePosition(unsigned int i);
127 /// Restore the position from bookmark i
128 void restorePosition(unsigned int i);
129 /// does the given bookmark have a saved position ?
130 bool isSavedPosition(unsigned int i);
131 /// save bookmarks to .lyx/session
132 void saveSavedPositions();
134 /// return the current change at the cursor
135 Change const getCurrentChange() const;
137 /// return the lyxtext we are using
138 LyXText * getLyXText();
140 /// return the lyxtext we are using
141 LyXText const * getLyXText() const;
143 /// move cursor to the named label
144 void gotoLabel(docstring const & label);
146 /// set the cursor based on the given TeX source row
147 void setCursorFromRow(int row);
149 /// center the document view around the cursor
151 /// scroll document by the given number of lines of default height
152 void scroll(int lines);
153 /// Scroll the view by a number of pixels
154 void scrollDocView(int pixels);
155 /// Set the cursor position based on the scrollbar one.
156 void setCursorFromScrollbar();
158 /// return the pixel width of the document view
159 int workWidth() const;
160 /// return the pixel height of the document view
161 int workHeight() const;
163 /// switch between primary and secondary keymaps for RTL entry
166 /// return true for events that will handle
167 FuncStatus getStatus(FuncRequest const & cmd);
168 /// execute the given function
169 bool dispatch(FuncRequest const & argument);
172 docstring const requestSelection();
174 void clearSelection();
177 void workAreaResize(int width, int height);
179 /// a function should be executed from the workarea
180 bool workAreaDispatch(FuncRequest const & ev);
183 pit_type anchor_ref() const;
185 /// access to full cursor
187 /// access to full cursor
188 LCursor const & cursor() const;
189 /// sets cursor and open all relevant collapsable insets.
190 void setCursor(DocIterator const &);
191 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
192 void mouseSetCursor(LCursor & cur);
194 /* Sets the selection. When \c backwards == false, set anchor
195 * to \c cur and cursor to \c cur + \c length. When \c
196 * backwards == true, set anchor to \c cur and cursor to \c
199 void putSelectionAt(DocIterator const & cur,
200 int length, bool backwards);
202 ViewMetricsInfo const & viewMetricsInfo();
204 void updateMetrics(bool singlepar = false);
207 CoordCache & coordCache() {
211 CoordCache const & coordCache() const {
214 /// get this view's keyboard map handler
215 Intl & getIntl() { return *intl_.get(); }
217 Intl const & getIntl() const { return *intl_.get(); }
219 /// This signal is emitted when some message shows up.
220 boost::signal<void(docstring)> message;
222 /// This signal is emitted when some dialog needs to be shown.
223 boost::signal<void(std::string name)> showDialog;
225 /// This signal is emitted when some dialog needs to be shown with
227 boost::signal<void(std::string name,
228 std::string data)> showDialogWithData;
230 /// This signal is emitted when some inset dialogs needs to be shown.
231 boost::signal<void(std::string name, std::string data,
232 InsetBase * inset)> showInsetDialog;
234 /// This signal is emitted when some dialogs needs to be updated.
235 boost::signal<void(std::string name,
236 std::string data)> updateDialog;
238 /// This signal is emitted when the layout at the cursor is changed.
239 boost::signal<void(std::string layout)> layoutChanged;
249 ScrollbarParameters scrollbarParameters_;
252 ViewMetricsInfo metrics_info_;
253 CoordCache coord_cache_;
257 /// Estimated average par height for scrollbar
263 std::string filename;
264 /// Cursor paragraph Id
269 Position() : par_id(0), par_pos(0) {}
271 Position(std::string const & f, int id, pos_type pos)
272 : filename(f), par_id(id), par_pos(pos) {}
275 std::vector<Position> saved_positions;
277 void menuInsertLyXFile(std::string const & filen);
279 /// this is used to handle XSelection events in the right manner
288 bool multiparsel_cache_;
290 pit_type anchor_ref_;
294 /// keyboard mapping object
295 boost::scoped_ptr<Intl> const intl_;
301 #endif // BUFFERVIEW_H