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;
102 /// return the owning main view
103 LyXView * owner() const;
105 /// resize event has happened
108 /// reload the contained buffer
110 /// load a buffer into the view
111 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
113 /** perform pending painting updates. \c fitcursor means first
114 * to do a fitcursor, and to force an update if screen
115 * position changes. \c forceupdate means to force an update
117 * \return true if a full updateMetrics() is needed.
119 bool update(Update::flags flags = Update::FitCursor | Update::Force);
121 /// move the screen to fit the cursor. Only to be called with
122 /// good y coordinates (after a bv::metrics)
124 /// reset the scrollbar to reflect current view position
125 void updateScrollbar();
126 /// return the Scrollbar Parameters
127 ScrollbarParameters const & scrollbarParameters() const;
130 bool available() const;
132 /// Save the current position as bookmark i
133 void savePosition(unsigned int i);
134 /// Restore the position from bookmark i
135 void restorePosition(unsigned int i);
136 /// does the given bookmark have a saved position ?
137 bool isSavedPosition(unsigned int i);
138 /// save bookmarks to .lyx/session
139 void saveSavedPositions();
141 /// return the current change at the cursor
142 Change const getCurrentChange();
144 /// return the lyxtext we are using
145 LyXText * getLyXText();
147 /// return the lyxtext we are using
148 LyXText const * getLyXText() const;
150 /// move cursor to the named label
151 void gotoLabel(std::string const & label);
153 /// set the cursor based on the given TeX source row
154 void setCursorFromRow(int row);
156 /// center the document view around the cursor
158 /// scroll document by the given number of lines of default height
159 void scroll(int lines);
160 /// Scroll the view by a number of pixels
161 void scrollDocView(int pixels);
162 /// Set the cursor position based on the scrollbar one.
163 void setCursorFromScrollbar();
165 /// return the pixel width of the document view
166 int workWidth() const;
167 /// return the pixel height of the document view
168 int workHeight() const;
170 /// switch between primary and secondary keymaps for RTL entry
173 /// return true for events that will handle
174 FuncStatus getStatus(FuncRequest const & cmd);
175 /// execute the given function
176 bool dispatch(FuncRequest const & argument);
179 void selectionRequested();
181 void selectionLost();
184 void workAreaResize(int width, int height);
186 /// a function should be executed from the workarea
187 bool workAreaDispatch(FuncRequest const & ev);
189 /// clear the X selection
193 int offset_ref() const;
195 lyx::pit_type anchor_ref() const;
197 /// access to full cursor
199 /// access to full cursor
200 LCursor const & cursor() const;
202 LyXText * text() const;
203 /// sets cursor and open all relevant collapsable insets.
204 void setCursor(DocIterator const &);
205 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
206 void mouseSetCursor(LCursor & cur);
208 /* Sets the selection. When \c backwards == false, set anchor
209 * to \c cur and cursor to \c cur + \c length. When \c
210 * backwards == true, set anchor to \c cur and cursor to \c
213 void putSelectionAt(DocIterator const & cur,
214 int length, bool backwards);
216 ViewMetricsInfo const & viewMetricsInfo();
218 void updateMetrics(bool singlepar = false);
220 /// This signal is emitted when some message shows up.
221 boost::signal<void(lyx::docstring)> message;
227 friend class BufferView::Pimpl;
232 #endif // BUFFERVIEW_H