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>
41 class ViewMetricsInfo;
51 inline flags operator|(flags const f, flags const g)
53 return static_cast<flags>(int(f) | int(g));
56 inline flags operator&(flags const f, flags const g)
58 return static_cast<flags>(int(f) & int(g));
63 /// Scrollbar Parameters
64 struct ScrollbarParameters
66 void reset(int h = 0, int p = 0, int l = 0)
73 /// The total document height in pixels
75 /// The current position in the document, in pixels
77 /// the line-scroll amount, in pixels
82 * A buffer view encapsulates a view onto a particular
83 * buffer, and allows access to operate upon it. A view
84 * is a sliding window of the entire document rendering.
86 * Eventually we will allow several views onto a single
87 * buffer, but not yet.
89 class BufferView : boost::noncopyable {
92 * Create a view with the given owner main window,
93 * of the given dimensions.
95 BufferView(LyXView * owner);
99 /// set the buffer we are viewing
100 void setBuffer(Buffer * b);
101 /// return the buffer being viewed
102 Buffer * buffer() const;
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;
131 /// Save the current position as bookmark i
132 void savePosition(unsigned int i);
133 /// Restore the position from bookmark i
134 void restorePosition(unsigned int i);
135 /// does the given bookmark have a saved position ?
136 bool isSavedPosition(unsigned int i);
137 /// save bookmarks to .lyx/session
138 void saveSavedPositions();
140 /// return the current change at the cursor
141 Change const getCurrentChange();
143 /// return the lyxtext we are using
144 LyXText * getLyXText();
146 /// return the lyxtext we are using
147 LyXText const * getLyXText() const;
149 /// move cursor to the named label
150 void gotoLabel(std::string const & label);
152 /// set the cursor based on the given TeX source row
153 void setCursorFromRow(int row);
155 /// center the document view around the cursor
157 /// scroll document by the given number of lines of default height
158 void scroll(int lines);
159 /// Scroll the view by a number of pixels
160 void scrollDocView(int pixels);
161 /// Set the cursor position based on the scrollbar one.
162 void setCursorFromScrollbar();
164 /// return the pixel width of the document view
165 int workWidth() const;
166 /// return the pixel height of the document view
167 int workHeight() const;
169 /// switch between primary and secondary keymaps for RTL entry
172 /// return true for events that will handle
173 FuncStatus getStatus(FuncRequest const & cmd);
174 /// execute the given function
175 bool dispatch(FuncRequest const & argument);
178 lyx::docstring const requestSelection();
180 void clearSelection();
183 void workAreaResize(int width, int height);
185 /// a function should be executed from the workarea
186 bool workAreaDispatch(FuncRequest const & ev);
189 lyx::pit_type anchor_ref() const;
191 /// access to full cursor
193 /// access to full cursor
194 LCursor const & cursor() const;
195 /// sets cursor and open all relevant collapsable insets.
196 void setCursor(DocIterator const &);
197 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
198 void mouseSetCursor(LCursor & cur);
200 /* Sets the selection. When \c backwards == false, set anchor
201 * to \c cur and cursor to \c cur + \c length. When \c
202 * backwards == true, set anchor to \c cur and cursor to \c
205 void putSelectionAt(DocIterator const & cur,
206 int length, bool backwards);
208 ViewMetricsInfo const & viewMetricsInfo();
210 void updateMetrics(bool singlepar = false);
212 /// get this view's keyboard map handler
213 Intl & getIntl() { return *intl_.get(); }
215 Intl const & getIntl() const { return *intl_.get(); }
217 /// This signal is emitted when some message shows up.
218 boost::signal<void(lyx::docstring)> message;
220 /// This signal is emitted when some dialog needs to be shown.
221 boost::signal<void(std::string name)> showDialog;
223 /// This signal is emitted when some dialog needs to be shown with
225 boost::signal<void(std::string name,
226 std::string data)> showDialogWithData;
228 /// This signal is emitted when some inset dialogs needs to be shown.
229 boost::signal<void(std::string name, std::string data,
230 InsetBase * inset)> showInsetDialog;
232 /// This signal is emitted when some dialogs needs to be updated.
233 boost::signal<void(std::string name,
234 std::string data)> updateDialog;
244 ScrollbarParameters scrollbarParameters_;
246 /// track changes for the document
250 ViewMetricsInfo metrics_info_;
257 /// Estimated average par height for scrollbar
263 std::string filename;
264 /// Cursor paragraph Id
267 lyx::pos_type par_pos;
269 Position() : par_id(0), par_pos(0) {}
271 Position(std::string const & f, int id, lyx::pos_type pos)
272 : filename(f), par_id(id), par_pos(pos) {}
275 std::vector<Position> saved_positions;
277 void menuInsertLyXFile(std::string const & filen);
279 /// this is used to handle XSelection events in the right manner
288 bool multiparsel_cache_;
290 lyx::pit_type anchor_ref_;
294 /// keyboard mapping object
295 boost::scoped_ptr<Intl> const intl_;
298 #endif // BUFFERVIEW_H