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 /// simple replacing. Use the font of the first selected character
152 void replaceSelectionWithString(std::string const & str);
154 /// move cursor to the named label
155 void gotoLabel(std::string const & label);
157 /// set the cursor based on the given TeX source row
158 void setCursorFromRow(int row);
160 /// center the document view around the cursor
162 /// scroll document by the given number of lines of default height
163 void scroll(int lines);
164 /// Scroll the view by a number of pixels
165 void scrollDocView(int pixels);
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 /// Receive a keypress
189 void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
191 /// a function should be executed from the workarea
192 bool workAreaDispatch(FuncRequest const & ev);
194 /// clear the X selection
198 int offset_ref() const;
200 lyx::pit_type anchor_ref() const;
202 /// access to full cursor
204 /// access to full cursor
205 LCursor const & cursor() const;
207 LyXText * text() const;
208 /// sets cursor and open all relevant collapsable insets.
209 void setCursor(DocIterator const &);
210 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
211 void mouseSetCursor(LCursor & cur);
213 /* Sets the selection. When \c backwards == false, set anchor
214 * to \c cur and cursor to \c cur + \c length. When \c
215 * backwards == true, set anchor to \c cur and cursor to \c
218 void putSelectionAt(DocIterator const & cur,
219 int length, bool backwards);
221 ViewMetricsInfo const & viewMetricsInfo();
223 void updateMetrics(bool singlepar = false);
229 friend class BufferView::Pimpl;
234 #endif // BUFFERVIEW_H