4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Lars Gullik Bjønnes
16 #include "insets/inset.h"
18 #include <boost/utility.hpp>
35 * A buffer view encapsulates a view onto a particular
36 * buffer, and allows access to operate upon it. A view
37 * is a sliding window of the entire document rendering.
39 * Eventually we will allow several views onto a single
40 * buffer, but not yet.
42 class BufferView : boost::noncopyable {
45 * Codes to store necessary pending updates
46 * of the document rendering.
49 UPDATE = 0, //< repaint
50 SELECT = 1 //< reset selection to current cursor pos
54 * Create a view with the given owner main window,
55 * of the given dimensions.
57 BufferView(LyXView * owner, int x, int y, int w, int h);
61 /// set the buffer we are viewing
62 void buffer(Buffer * b);
63 /// return the buffer being viewed
64 Buffer * buffer() const;
66 /// return the painter object for drawing onto the view
67 Painter & painter() const;
68 /// return the screen object for handling re-drawing
69 LyXScreen & screen() const;
70 /// return the owning main view
71 LyXView * owner() const;
73 /// resize event has happened
76 * Repaint the pixmap. Used for when we don't want
77 * to go through the full update() logic, just a simple
78 * repaint of the whole screen.
82 /// reload the contained buffer
85 /// fit the user cursor within the visible view
87 /// perform pending painting updates
89 // update for a particular lyxtext
90 void update(LyXText *, UpdateCodes uc);
91 /// update for the top-level lyxtext
92 void update(UpdateCodes uc);
93 /// update for a particular inset
94 void updateInset(Inset * inset);
95 /// reset the scrollbar to reflect current view position
96 void updateScrollbar();
98 void redoCurrentBuffer();
101 bool available() const;
104 void beforeChange(LyXText *);
106 /// Save the current position as bookmark i
107 void savePosition(unsigned int i);
108 /// Restore the position from bookmark i
109 void restorePosition(unsigned int i);
110 /// does the given bookmark have a saved position ?
111 bool isSavedPosition(unsigned int i);
113 /// return the current change at the cursor
114 Change const getCurrentChange();
117 * This holds the mapping between buffer paragraphs and screen rows.
118 * This should be private...but not yet. (Lgb)
121 /// return the lyxtext we are using
122 LyXText * getLyXText() const;
124 /// Return the current inset we are "locked" in
125 UpdatableInset * theLockingInset() const;
126 /// lock the given inset FIXME: return value ?
127 bool lockInset(UpdatableInset * inset);
128 /// unlock the given inset
129 int unlockInset(UpdatableInset * inset);
130 /// unlock the currently locked inset
133 /// return the current encoding at the cursor
134 Encoding const * getEncoding() const;
136 /// return the parent language of the given inset
137 Language const * getParentLanguage(Inset * inset) const;
139 /// Select the "current" word
140 void selectLastWord();
141 /// replace the currently selected word
142 void replaceWord(string const & replacestring);
143 /// Update after spellcheck finishes
144 void endOfSpellCheck();
145 /// return the next word
146 WordLangTuple const nextWord(float & value);
148 /// move cursor to the named label
149 void gotoLabel(string const & label);
156 /// get the stored error list
157 ErrorList const & getErrorList() const;
158 /// clears the stored error list
159 void resetErrorList();
160 /// stored this error list
161 void setErrorList(ErrorList const &);
162 /// adds a single error to the list
163 void addError(ErrorItem const &);
164 /// show the error list to the user
165 void showErrorList(string const &) const;
166 /// set the cursor based on the given TeX source row
167 void setCursorFromRow(int row);
170 * Insert an inset into the buffer.
171 * Place it in a layout of lout,
173 bool insertInset(Inset * inset, string const & lout = string());
175 /// Inserts a lyx file at cursor position. return false if it fails
176 bool insertLyXFile(string const & file);
179 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
181 void lockedInsetStoreUndo(Undo::undo_kind kind);
183 void toggleSelection(bool = true);
187 /// hide the cursor if it is visible
190 /// center the document view around the cursor
192 /// scroll document by the given number of lines of default height
193 void scroll(int lines);
194 /// Scroll the view by a number of pixels
195 void scrollDocView(int);
197 /// return the pixel width of the document view
198 int workWidth() const;
199 /// return the pixel height of the document view
200 int workHeight() const;
202 /// switch between primary and secondary keymaps for RTL entry
206 bool ChangeRefsIfUnique(string const & from, string const & to);
208 bool ChangeCitationsIfUnique(string const & from, string const & to);
210 /// get the contents of the window system clipboard
211 string const getClipboard() const;
212 /// fill the window system clipboard
213 void stuffClipboard(string const &) const;
214 /// tell the window system we have a selection
215 void haveSelection(bool sel);
217 /// execute the given function
218 bool dispatch(FuncRequest const & argument);
221 /// Set the current locking inset
222 void theLockingInset(UpdatableInset * inset);
224 /// return the lyxtext containing this inset
225 LyXText * getParentText(Inset * inset) const;
228 * Change all insets with the given code's contents to a new
229 * string. May only be used with InsetCommand-derived insets
230 * Returns true if a screen update is needed.
232 bool ChangeInsets(Inset::Code code, string const & from,
237 friend struct BufferView::Pimpl;
243 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
244 BufferView::UpdateCodes uc2);
246 #endif // BUFFERVIEW_H