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>
38 class ViewMetricsInfo;
48 inline flags operator|(flags const f, flags const g)
50 return static_cast<flags>(int(f) | int(g));
53 inline flags operator&(flags const f, flags const g)
55 return static_cast<flags>(int(f) & int(g));
60 /// Scrollbar Parameters
61 struct ScrollbarParameters
63 void reset(int h = 0, int p = 0, int l = 0)
70 /// The total document height in pixels
72 /// The current position in the document, in pixels
74 /// the line-scroll amount, in pixels
79 * A buffer view encapsulates a view onto a particular
80 * buffer, and allows access to operate upon it. A view
81 * is a sliding window of the entire document rendering.
83 * Eventually we will allow several views onto a single
84 * buffer, but not yet.
86 class BufferView : boost::noncopyable {
89 * Create a view with the given owner main window,
90 * of the given dimensions.
92 BufferView(LyXView * owner);
96 /// set the buffer we are viewing
97 void setBuffer(Buffer * b);
98 /// return the buffer being viewed
99 Buffer * buffer() const;
100 /// return the first layout of the Buffer.
101 std::string firstLayout();
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;
131 bool available() const;
133 /// Save the current position as bookmark i
134 void savePosition(unsigned int i);
135 /// Restore the position from bookmark i
136 void restorePosition(unsigned int i);
137 /// does the given bookmark have a saved position ?
138 bool isSavedPosition(unsigned int i);
139 /// save bookmarks to .lyx/session
140 void saveSavedPositions();
142 /// return the current change at the cursor
143 Change const getCurrentChange();
145 /// return the lyxtext we are using
146 LyXText * getLyXText();
148 /// return the lyxtext we are using
149 LyXText const * getLyXText() const;
151 /// move cursor to the named label
152 void gotoLabel(std::string const & label);
154 /// set the cursor based on the given TeX source row
155 void setCursorFromRow(int row);
157 /// center the document view around the cursor
159 /// scroll document by the given number of lines of default height
160 void scroll(int lines);
161 /// Scroll the view by a number of pixels
162 void scrollDocView(int pixels);
163 /// Set the cursor position based on the scrollbar one.
164 void setCursorFromScrollbar();
166 /// return the pixel width of the document view
167 int workWidth() const;
168 /// return the pixel height of the document view
169 int workHeight() const;
171 /// switch between primary and secondary keymaps for RTL entry
174 /// return true for events that will handle
175 FuncStatus getStatus(FuncRequest const & cmd);
176 /// execute the given function
177 bool dispatch(FuncRequest const & argument);
180 void selectionRequested();
182 void selectionLost();
185 void workAreaResize(int width, int height);
187 /// a function should be executed from the workarea
188 bool workAreaDispatch(FuncRequest const & ev);
190 /// clear the X selection
194 int offset_ref() const;
196 lyx::pit_type anchor_ref() const;
198 /// access to full cursor
200 /// access to full cursor
201 LCursor const & cursor() const;
203 LyXText * text() const;
204 /// sets cursor and open all relevant collapsable insets.
205 void setCursor(DocIterator const &);
206 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
207 void mouseSetCursor(LCursor & cur);
209 /* Sets the selection. When \c backwards == false, set anchor
210 * to \c cur and cursor to \c cur + \c length. When \c
211 * backwards == true, set anchor to \c cur and cursor to \c
214 void putSelectionAt(DocIterator const & cur,
215 int length, bool backwards);
217 ViewMetricsInfo const & viewMetricsInfo();
219 void updateMetrics(bool singlepar = false);
225 friend class BufferView::Pimpl;
230 #endif // BUFFERVIEW_H