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 "metricsinfo.h"
20 #include "frontends/LyXKeySym.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 {
90 * Create a view with the given owner main window,
91 * of the given dimensions.
93 BufferView(LyXView * owner);
97 /// set the buffer we are viewing
98 void setBuffer(Buffer * b);
99 /// return the buffer being viewed
100 Buffer * buffer() const;
101 /// return the first layout of the Buffer.
102 std::string firstLayout();
104 /// return the owning main view
105 LyXView * owner() const;
107 /// resize event has happened
110 /// reload the contained buffer
112 /// load a buffer into the view
113 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
115 /** perform pending painting updates. \c fitcursor means first
116 * to do a fitcursor, and to force an update if screen
117 * position changes. \c forceupdate means to force an update
119 * \return true if a full updateMetrics() is needed.
121 bool update(Update::flags flags = Update::FitCursor | Update::Force);
123 /// move the screen to fit the cursor. Only to be called with
124 /// good y coordinates (after a bv::metrics)
126 /// reset the scrollbar to reflect current view position
127 void updateScrollbar();
128 /// return the Scrollbar Parameters
129 ScrollbarParameters const & scrollbarParameters() const;
132 bool available() const;
134 /// Save the current position as bookmark i
135 void savePosition(unsigned int i);
136 /// Restore the position from bookmark i
137 void restorePosition(unsigned int i);
138 /// does the given bookmark have a saved position ?
139 bool isSavedPosition(unsigned int i);
140 /// save bookmarks to .lyx/session
141 void saveSavedPositions();
143 /// return the current change at the cursor
144 Change const getCurrentChange();
146 /// return the lyxtext we are using
147 LyXText * getLyXText();
149 /// return the lyxtext we are using
150 LyXText const * getLyXText() const;
152 /// move cursor to the named label
153 void gotoLabel(std::string const & label);
155 /// set the cursor based on the given TeX source row
156 void setCursorFromRow(int row);
158 /// center the document view around the cursor
160 /// scroll document by the given number of lines of default height
161 void scroll(int lines);
162 /// Scroll the view by a number of pixels
163 void scrollDocView(int pixels);
164 /// Set the cursor position based on the scrollbar one.
165 void setCursorFromScrollbar();
167 /// return the pixel width of the document view
168 int workWidth() const;
169 /// return the pixel height of the document view
170 int workHeight() const;
172 /// switch between primary and secondary keymaps for RTL entry
175 /// return true for events that will handle
176 FuncStatus getStatus(FuncRequest const & cmd);
177 /// execute the given function
178 bool dispatch(FuncRequest const & argument);
181 void selectionRequested();
183 void selectionLost();
186 void workAreaResize(int width, int height);
188 /// a function should be executed from the workarea
189 bool workAreaDispatch(FuncRequest const & ev);
191 /// clear the X selection
195 int offset_ref() const;
197 lyx::pit_type anchor_ref() const;
199 /// access to full cursor
201 /// access to full cursor
202 LCursor const & cursor() const;
204 LyXText * text() const;
205 /// sets cursor and open all relevant collapsable insets.
206 void setCursor(DocIterator const &);
207 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
208 void mouseSetCursor(LCursor & cur);
210 /* Sets the selection. When \c backwards == false, set anchor
211 * to \c cur and cursor to \c cur + \c length. When \c
212 * backwards == true, set anchor to \c cur and cursor to \c
215 void putSelectionAt(DocIterator const & cur,
216 int length, bool backwards);
218 ViewMetricsInfo const & viewMetricsInfo();
220 void updateMetrics(bool singlepar = false);
222 /// This signal is emitted when some message shows up.
223 boost::signal<void(std::string)> message;
229 friend class BufferView::Pimpl;
234 #endif // BUFFERVIEW_H