Prepare ANNOUNCE and NEWS for rc2
[lyx.git] / src / BufferView.h
blob791e01231d6cf1d4b4af6cff6f629823c3d0c110
1 // -*- C++ -*-
2 /**
3 * \file BufferView.h
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
9 * \author John Levon
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
15 #ifndef BUFFER_VIEW_H
16 #define BUFFER_VIEW_H
18 #include "update_flags.h"
20 #include "support/strfwd.h"
21 #include "support/types.h"
23 namespace lyx {
25 namespace support { class FileName; }
27 namespace frontend { class Painter; }
28 namespace frontend { class GuiBufferViewDelegate; }
30 class Buffer;
31 class Change;
32 class CoordCache;
33 class Cursor;
34 class DocIterator;
35 class FuncRequest;
36 class FuncStatus;
37 class Intl;
38 class Inset;
39 class ParIterator;
40 class ParagraphMetrics;
41 class Point;
42 class Text;
43 class TextMetrics;
45 enum CursorStatus {
46 CUR_INSIDE,
47 CUR_ABOVE,
48 CUR_BELOW
51 /// Scrollbar Parameters.
52 struct ScrollbarParameters
54 ScrollbarParameters()
55 : min(0), max(0), position(0), single_step(1), page_step(1)
57 /// Minimum scrollbar position in pixels.
58 int min;
59 /// Maximum scrollbar position in pixels.
60 int max;
61 /// Current position in the document in pixels.
62 int position;
63 /// Line-scroll amount in pixels.
64 int single_step;
65 /// Page-scroll amount in pixels.
66 int page_step;
69 /// Screen view of a Buffer.
70 /**
71 * A BufferView encapsulates a view onto a particular
72 * buffer, and allows access to operate upon it. A view
73 * is a sliding window of the entire document rendering.
74 * It is the official interface between the LyX core and
75 * the frontend WorkArea.
77 * \sa WorkArea
78 * \sa Buffer
79 * \sa CoordCache
81 class BufferView {
82 public:
83 ///
84 explicit BufferView(Buffer & buffer);
85 ///
86 ~BufferView();
88 /// return the buffer being viewed.
89 Buffer & buffer();
90 Buffer const & buffer() const;
92 ///
93 void setFullScreen(bool full_screen) { full_screen_ = full_screen; }
95 /// right margin
96 int rightMargin() const;
98 /// left margin
99 int leftMargin() const;
101 /// \return true if the BufferView is at the top of the document.
102 bool isTopScreen() const;
104 /// \return true if the BufferView is at the bottom of the document.
105 bool isBottomScreen() const;
107 /// perform pending metrics updates.
108 /** \c Update::FitCursor means first to do a FitCursor, and to
109 * force an update if screen position changes.
110 * \c Update::Force means to force an update in any case.
111 * \retval true if a screen redraw is needed
113 void processUpdateFlags(Update::flags flags);
115 /// move the screen to fit the cursor.
116 /// Only to be called with good y coordinates (after a bv::metrics)
117 bool fitCursor();
118 /// reset the scrollbar to reflect current view position.
119 void updateScrollbar();
120 /// return the Scrollbar Parameters.
121 ScrollbarParameters const & scrollbarParameters() const;
122 /// \return Tool tip for the given position.
123 docstring toolTip(int x, int y) const;
124 /// \return the context menu for the given position.
125 docstring contextMenu(int x, int y) const;
127 /// Save the current position as bookmark.
128 /// if idx == 0, save to temp_bookmark
129 void saveBookmark(unsigned int idx);
130 /// goto a specified position, try top_id first, and then bottom_pit.
131 /// \return true if success
132 bool moveToPosition(
133 pit_type bottom_pit, ///< Paragraph pit, used when par_id is zero or invalid.
134 pos_type bottom_pos, ///< Paragraph pit, used when par_id is zero or invalid.
135 int top_id, ///< Paragraph ID, \sa Paragraph
136 pos_type top_pos ///< Position in the \c Paragraph
138 /// return the current change at the cursor.
139 Change const getCurrentChange() const;
141 /// move cursor to the named label.
142 void gotoLabel(docstring const & label);
144 /// set the cursor based on the given TeX source row.
145 void setCursorFromRow(int row);
147 /// Ensure that the BufferView cursor is visible.
148 /// This method will automatically scroll and update the BufferView
149 /// if needed.
150 void showCursor();
151 /// Ensure the passed cursor \p dit is visible.
152 /// This method will automatically scroll and update the BufferView
153 /// if needed.
154 void showCursor(DocIterator const & dit);
155 /// LFUN_SCROLL Helper.
156 void lfunScroll(FuncRequest const & cmd);
157 /// scroll down document by the given number of pixels.
158 int scrollDown(int pixels);
159 /// scroll up document by the given number of pixels.
160 int scrollUp(int pixels);
161 /// scroll document by the given number of pixels.
162 int scroll(int pixels);
163 /// Scroll the view by a number of pixels.
164 void scrollDocView(int pixels);
165 /// Set the cursor position based on the scrollbar one.
166 void setCursorFromScrollbar();
168 /// return the pixel width of the document view.
169 int workWidth() const;
170 /// return the pixel height of the document view.
171 int workHeight() const;
173 /// return the inline completion postfix.
174 docstring const & inlineCompletion() const;
175 /// return the number of unique characters in the inline completion.
176 size_t const & inlineCompletionUniqueChars() const;
177 /// return the position in the buffer of the inline completion postfix.
178 DocIterator const & inlineCompletionPos() const;
179 /// set the inline completion postfix and its position in the buffer.
180 /// Updates the updateFlags in \c cur.
181 void setInlineCompletion(Cursor & cur, DocIterator const & pos,
182 docstring const & completion, size_t uniqueChars = 0);
184 /// translate and insert a character, using the correct keymap.
185 void translateAndInsert(char_type c, Text * t, Cursor & cur);
187 /// return true for events that will handle.
188 FuncStatus getStatus(FuncRequest const & cmd);
189 /// execute the given function.
190 /// \return true if the function has been processed.
191 bool dispatch(FuncRequest const & argument);
193 /// request an X11 selection.
194 /// \return the selected string.
195 docstring const requestSelection();
196 /// clear the X11 selection.
197 void clearSelection();
199 /// resize the BufferView.
200 /// \sa WorkArea
201 void resize(int width, int height);
203 /// dispatch method helper for \c WorkArea
204 /// \sa WorkArea
205 void mouseEventDispatch(FuncRequest const & ev);
207 /// access to anchor.
208 pit_type anchor_ref() const;
211 CursorStatus cursorStatus(DocIterator const & dit) const;
212 /// access to full cursor.
213 Cursor & cursor();
214 /// access to full cursor.
215 Cursor const & cursor() const;
216 /// sets cursor.
217 /// This will also open all relevant collapsable insets.
218 void setCursor(DocIterator const &);
219 /// Check deleteEmptyParagraphMechanism and update metrics if needed.
220 /// \retval true if an update was needed.
221 bool checkDepm(Cursor & cur, Cursor & old);
222 /// sets cursor.
223 /// This is used when handling LFUN_MOUSE_PRESS.
224 bool mouseSetCursor(Cursor & cur, bool select = false);
226 /// sets the selection.
227 /* When \c backwards == false, set anchor
228 * to \c cur and cursor to \c cur + \c length. When \c
229 * backwards == true, set anchor to \c cur and cursor to \c
230 * cur + \c length.
232 void putSelectionAt(DocIterator const & cur,
233 int length, bool backwards);
235 /// update the internal \c ViewMetricsInfo.
236 void updateMetrics();
239 TextMetrics const & textMetrics(Text const * t) const;
240 TextMetrics & textMetrics(Text const * t);
242 ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
245 CoordCache & coordCache();
247 CoordCache const & coordCache() const;
250 Point getPos(DocIterator const & dit, bool boundary) const;
254 void draw(frontend::Painter & pain);
256 /// get this view's keyboard map handler.
257 Intl & getIntl();
259 Intl const & getIntl() const;
262 // Messages to the GUI
264 /// This signal is emitted when some message shows up.
265 void message(docstring const & msg);
267 /// This signal is emitted when some dialog needs to be shown.
268 void showDialog(std::string const & name);
270 /// This signal is emitted when some dialog needs to be shown with
271 /// some data.
272 void showDialog(std::string const & name, std::string const & data,
273 Inset * inset = 0);
275 /// This signal is emitted when some dialogs needs to be updated.
276 void updateDialog(std::string const & name, std::string const & data);
279 void setGuiDelegate(frontend::GuiBufferViewDelegate *);
282 docstring contentsOfPlaintextFile(support::FileName const & f);
283 // Insert plain text file (if filename is empty, prompt for one)
284 void insertPlaintextFile(support::FileName const & f, bool asParagraph);
286 void insertLyXFile(support::FileName const & f);
288 private:
289 /// noncopyable
290 BufferView(BufferView const &);
291 void operator=(BufferView const &);
293 // the position relative to (0, baseline) of outermost paragraph
294 Point coordOffset(DocIterator const & dit, bool boundary) const;
295 /// Update current paragraph metrics.
296 /// \return true if no further update is needed.
297 bool singleParUpdate();
299 /// Search recursively for the the innermost inset that covers (x, y) position.
300 /// \retval 0 if no inset is found.
301 Inset const * getCoveringInset(
302 Text const & text, //< The Text where we start searching.
303 int x, //< x-coordinate on screen
304 int y //< y-coordinate on screen
305 ) const;
308 int width_;
310 int height_;
312 bool full_screen_;
314 Buffer & buffer_;
316 struct Private;
317 Private * const d;
320 /// some space for drawing the 'nested' markers (in pixel)
321 inline int nestMargin() { return 15; }
323 /// margin for changebar
324 inline int changebarMargin() { return 12; }
326 } // namespace lyx
328 #endif // BUFFERVIEW_H