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 "support/types.h"
23 #include <boost/utility.hpp>
24 #include <boost/signal.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 {
92 /// set the buffer we are viewing
93 void setBuffer(Buffer * b);
94 /// return the buffer being viewed
95 Buffer * buffer() const;
97 /// resize event has happened
100 /// reload the contained buffer
102 /// load a buffer into the view
103 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
105 /** perform pending painting updates. \c fitcursor means first
106 * to do a fitcursor, and to force an update if screen
107 * position changes. \c forceupdate means to force an update
109 * \return true if a full updateMetrics() is needed.
111 bool update(Update::flags flags = Update::FitCursor | Update::Force);
113 /// move the screen to fit the cursor. Only to be called with
114 /// good y coordinates (after a bv::metrics)
116 /// reset the scrollbar to reflect current view position
117 void updateScrollbar();
118 /// return the Scrollbar Parameters
119 ScrollbarParameters const & scrollbarParameters() const;
121 /// Save the current position as bookmark i
122 void savePosition(unsigned int i);
123 /// Restore the position from bookmark i
124 void restorePosition(unsigned int i);
125 /// does the given bookmark have a saved position ?
126 bool isSavedPosition(unsigned int i);
127 /// save bookmarks to .lyx/session
128 void saveSavedPositions();
130 /// return the current change at the cursor
131 Change const getCurrentChange();
133 /// return the lyxtext we are using
134 LyXText * getLyXText();
136 /// return the lyxtext we are using
137 LyXText const * getLyXText() const;
139 /// move cursor to the named label
140 void gotoLabel(std::string const & label);
142 /// set the cursor based on the given TeX source row
143 void setCursorFromRow(int row);
145 /// center the document view around the cursor
147 /// scroll document by the given number of lines of default height
148 void scroll(int lines);
149 /// Scroll the view by a number of pixels
150 void scrollDocView(int pixels);
151 /// Set the cursor position based on the scrollbar one.
152 void setCursorFromScrollbar();
154 /// return the pixel width of the document view
155 int workWidth() const;
156 /// return the pixel height of the document view
157 int workHeight() const;
159 /// switch between primary and secondary keymaps for RTL entry
162 /// return true for events that will handle
163 FuncStatus getStatus(FuncRequest const & cmd);
164 /// execute the given function
165 bool dispatch(FuncRequest const & argument);
168 lyx::docstring const requestSelection();
170 void clearSelection();
173 void workAreaResize(int width, int height);
175 /// a function should be executed from the workarea
176 bool workAreaDispatch(FuncRequest const & ev);
179 lyx::pit_type anchor_ref() const;
181 /// access to full cursor
183 /// access to full cursor
184 LCursor const & cursor() const;
185 /// sets cursor and open all relevant collapsable insets.
186 void setCursor(DocIterator const &);
187 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
188 void mouseSetCursor(LCursor & cur);
190 /* Sets the selection. When \c backwards == false, set anchor
191 * to \c cur and cursor to \c cur + \c length. When \c
192 * backwards == true, set anchor to \c cur and cursor to \c
195 void putSelectionAt(DocIterator const & cur,
196 int length, bool backwards);
198 ViewMetricsInfo const & viewMetricsInfo();
200 void updateMetrics(bool singlepar = false);
202 /// get this view's keyboard map handler
203 Intl & getIntl() { return *intl_.get(); }
205 Intl const & getIntl() const { return *intl_.get(); }
207 /// This signal is emitted when some message shows up.
208 boost::signal<void(lyx::docstring)> message;
210 /// This signal is emitted when some dialog needs to be shown.
211 boost::signal<void(std::string name)> showDialog;
213 /// This signal is emitted when some dialog needs to be shown with
215 boost::signal<void(std::string name,
216 std::string data)> showDialogWithData;
218 /// This signal is emitted when some inset dialogs needs to be shown.
219 boost::signal<void(std::string name, std::string data,
220 InsetBase * inset)> showInsetDialog;
222 /// This signal is emitted when some dialogs needs to be updated.
223 boost::signal<void(std::string name,
224 std::string data)> updateDialog;
226 /// This signal is emitted when the layout at the cursor is changed.
227 boost::signal<void(std::string layout)> layoutChanged;
237 ScrollbarParameters scrollbarParameters_;
240 ViewMetricsInfo metrics_info_;
245 /// Estimated average par height for scrollbar
251 std::string filename;
252 /// Cursor paragraph Id
255 lyx::pos_type par_pos;
257 Position() : par_id(0), par_pos(0) {}
259 Position(std::string const & f, int id, lyx::pos_type pos)
260 : filename(f), par_id(id), par_pos(pos) {}
263 std::vector<Position> saved_positions;
265 void menuInsertLyXFile(std::string const & filen);
267 /// this is used to handle XSelection events in the right manner
276 bool multiparsel_cache_;
278 lyx::pit_type anchor_ref_;
282 /// keyboard mapping object
283 boost::scoped_ptr<Intl> const intl_;
286 #endif // BUFFERVIEW_H