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.
19 #include "metricsinfo.h"
21 #include "frontends/LyXKeySym.h"
23 #include "support/types.h"
25 #include <boost/utility.hpp>
26 #include <boost/signal.hpp>
40 class ViewMetricsInfo;
50 inline flags operator|(flags const f, flags const g)
52 return static_cast<flags>(int(f) | int(g));
55 inline flags operator&(flags const f, flags const g)
57 return static_cast<flags>(int(f) & int(g));
62 /// Scrollbar Parameters
63 struct ScrollbarParameters
65 void reset(int h = 0, int p = 0, int l = 0)
72 /// The total document height in pixels
74 /// The current position in the document, in pixels
76 /// the line-scroll amount, in pixels
81 * A buffer view encapsulates a view onto a particular
82 * buffer, and allows access to operate upon it. A view
83 * is a sliding window of the entire document rendering.
85 * Eventually we will allow several views onto a single
86 * buffer, but not yet.
88 class BufferView : boost::noncopyable {
91 * Create a view with the given owner main window,
92 * of the given dimensions.
94 BufferView(LyXView * owner);
98 /// set the buffer we are viewing
99 void setBuffer(Buffer * b);
100 /// return the buffer being viewed
101 Buffer * buffer() const;
103 /// return the owning main view
104 LyXView * owner() const;
106 /// resize event has happened
109 /// reload the contained buffer
111 /// load a buffer into the view
112 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
114 /** perform pending painting updates. \c fitcursor means first
115 * to do a fitcursor, and to force an update if screen
116 * position changes. \c forceupdate means to force an update
118 * \return true if a full updateMetrics() is needed.
120 bool update(Update::flags flags = Update::FitCursor | Update::Force);
122 /// move the screen to fit the cursor. Only to be called with
123 /// good y coordinates (after a bv::metrics)
125 /// reset the scrollbar to reflect current view position
126 void updateScrollbar();
127 /// return the Scrollbar Parameters
128 ScrollbarParameters const & scrollbarParameters() const;
130 /// Save the current position as bookmark i
131 void savePosition(unsigned int i);
132 /// Restore the position from bookmark i
133 void restorePosition(unsigned int i);
134 /// does the given bookmark have a saved position ?
135 bool isSavedPosition(unsigned int i);
136 /// save bookmarks to .lyx/session
137 void saveSavedPositions();
139 /// return the current change at the cursor
140 Change const getCurrentChange();
142 /// return the lyxtext we are using
143 LyXText * getLyXText();
145 /// return the lyxtext we are using
146 LyXText const * getLyXText() const;
148 /// move cursor to the named label
149 void gotoLabel(std::string const & label);
151 /// set the cursor based on the given TeX source row
152 void setCursorFromRow(int row);
154 /// center the document view around the cursor
156 /// scroll document by the given number of lines of default height
157 void scroll(int lines);
158 /// Scroll the view by a number of pixels
159 void scrollDocView(int pixels);
160 /// Set the cursor position based on the scrollbar one.
161 void setCursorFromScrollbar();
163 /// return the pixel width of the document view
164 int workWidth() const;
165 /// return the pixel height of the document view
166 int workHeight() const;
168 /// switch between primary and secondary keymaps for RTL entry
171 /// return true for events that will handle
172 FuncStatus getStatus(FuncRequest const & cmd);
173 /// execute the given function
174 bool dispatch(FuncRequest const & argument);
177 lyx::docstring const requestSelection();
179 void clearSelection();
182 void workAreaResize(int width, int height);
184 /// a function should be executed from the workarea
185 bool workAreaDispatch(FuncRequest const & ev);
187 /// clear the X selection
191 int offset_ref() const;
193 lyx::pit_type anchor_ref() const;
195 /// access to full cursor
197 /// access to full cursor
198 LCursor const & cursor() const;
199 /// sets cursor and open all relevant collapsable insets.
200 void setCursor(DocIterator const &);
201 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
202 void mouseSetCursor(LCursor & cur);
204 /* Sets the selection. When \c backwards == false, set anchor
205 * to \c cur and cursor to \c cur + \c length. When \c
206 * backwards == true, set anchor to \c cur and cursor to \c
209 void putSelectionAt(DocIterator const & cur,
210 int length, bool backwards);
212 ViewMetricsInfo const & viewMetricsInfo();
214 void updateMetrics(bool singlepar = false);
216 /// This signal is emitted when some message shows up.
217 boost::signal<void(lyx::docstring)> message;
227 ScrollbarParameters scrollbarParameters_;
229 /// track changes for the document
233 ViewMetricsInfo metrics_info_;
240 /// Estimated average par height for scrollbar
246 std::string filename;
247 /// Cursor paragraph Id
250 lyx::pos_type par_pos;
252 Position() : par_id(0), par_pos(0) {}
254 Position(std::string const & f, int id, lyx::pos_type pos)
255 : filename(f), par_id(id), par_pos(pos) {}
258 std::vector<Position> saved_positions;
260 void menuInsertLyXFile(std::string const & filen);
262 /// this is used to handle XSelection events in the right manner
271 bool multiparsel_cache_;
273 lyx::pit_type anchor_ref_;
278 #endif // BUFFERVIEW_H