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>
33 * A buffer view encapsulates a view onto a particular
34 * buffer, and allows access to operate upon it. A view
35 * is a sliding window of the entire document rendering.
37 * Eventually we will allow several views onto a single
38 * buffer, but not yet.
40 class BufferView : boost::noncopyable {
43 * Codes to store necessary pending updates
44 * of the document rendering.
47 UPDATE = 0, //< repaint
48 SELECT = 1 //< reset selection to current cursor pos
52 * Create a view with the given owner main window,
53 * of the given dimensions.
55 BufferView(LyXView * owner, int x, int y, int w, int h);
59 /// set the buffer we are viewing
60 void buffer(Buffer * b);
61 /// return the buffer being viewed
62 Buffer * buffer() const;
64 /// return the painter object for drawing onto the view
65 Painter & painter() const;
66 /// return the screen object for handling re-drawing
67 LyXScreen & screen() const;
68 /// return the owning main view
69 LyXView * owner() const;
71 /// resize event has happened
74 * Repaint the pixmap. Used for when we don't want
75 * to go through the full update() logic, just a simple
76 * repaint of the whole screen.
80 /// reload the contained buffer
83 /// fit the user cursor within the visible view
85 /// perform pending painting updates
87 // update for a particular lyxtext
88 void update(LyXText *, UpdateCodes uc);
89 /// update for the top-level lyxtext
90 void update(UpdateCodes uc);
91 /// update for a particular inset
92 void updateInset(Inset * inset);
93 /// reset the scrollbar to reflect current view position
94 void updateScrollbar();
96 void redoCurrentBuffer();
99 bool available() const;
102 void beforeChange(LyXText *);
104 /// Save the current position as bookmark i
105 void savePosition(unsigned int i);
106 /// Restore the position from bookmark i
107 void restorePosition(unsigned int i);
108 /// does the given bookmark have a saved position ?
109 bool isSavedPosition(unsigned int i);
111 /// return the current change at the cursor
112 Change const getCurrentChange();
115 * This holds the mapping between buffer paragraphs and screen rows.
116 * This should be private...but not yet. (Lgb)
119 /// return the lyxtext we are using
120 LyXText * getLyXText() const;
122 /// Return the current inset we are "locked" in
123 UpdatableInset * theLockingInset() const;
124 /// lock the given inset FIXME: return value ?
125 bool lockInset(UpdatableInset * inset);
126 /// unlock the given inset
127 int unlockInset(UpdatableInset * inset);
128 /// unlock the currently locked inset
131 /// return the current encoding at the cursor
132 Encoding const * getEncoding() const;
134 /// return the parent language of the given inset
135 Language const * getParentLanguage(Inset * inset) const;
137 /// Select the "current" word
138 void selectLastWord();
139 /// replace the currently selected word
140 void replaceWord(string const & replacestring);
141 /// Update after spellcheck finishes
142 void endOfSpellCheck();
143 /// return the next word
144 WordLangTuple const nextWord(float & value);
146 /// move cursor to the named label
147 bool gotoLabel(string const & label);
149 /// copy the environment type from current paragraph
150 void copyEnvironment();
151 /// set the current paragraph's environment type
152 void pasteEnvironment();
159 /// removes all autodeletable insets
160 bool removeAutoInsets();
161 /// insert all errors found when running latex
162 void insertErrors(TeXErrors & terr);
163 /// set the cursor based on the given TeX source row
164 void setCursorFromRow(int row);
167 * Insert an inset into the buffer.
168 * Place it in a layout of lout,
170 bool insertInset(Inset * inset, string const & lout = string());
172 /// Inserts a lyx file at cursor position. return false if it fails
173 bool insertLyXFile(string const & file);
175 /// show the user cursor
177 /// hide the user cursor
180 void showLockedInsetCursor(int x, int y, int asc, int desc);
182 void hideLockedInsetCursor();
184 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
186 void lockedInsetStoreUndo(Undo::undo_kind kind);
188 void toggleSelection(bool = true);
192 /// center the document view around the cursor
194 /// scroll document by the given number of lines of default height
195 void scroll(int lines);
196 /// Scroll the view by a number of pixels
197 void scrollDocView(int);
199 /// return the pixel width of the document view
200 int workWidth() const;
201 /// return the pixel height of the document view
202 int workHeight() const;
204 /// switch between primary and secondary keymaps for RTL entry
208 bool ChangeRefsIfUnique(string const & from, string const & to);
210 bool ChangeCitationsIfUnique(string const & from, string const & to);
212 /// get the contents of the window system clipboard
213 string const getClipboard() const;
214 /// fill the window system clipboard
215 void stuffClipboard(string const &) const;
216 /// tell the window system we have a selection
217 void haveSelection(bool sel);
219 /// execute the given function
220 bool dispatch(FuncRequest const & argument);
223 /// Set the current locking inset
224 void theLockingInset(UpdatableInset * inset);
226 /// return the lyxtext containing this inset
227 LyXText * getParentText(Inset * inset) const;
230 * Change all insets with the given code's contents to a new
231 * string. May only be used with InsetCommand-derived insets
232 * Returns true if a screen update is needed.
234 bool ChangeInsets(Inset::Code code, string const & from,
239 friend struct BufferView::Pimpl;
245 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
246 BufferView::UpdateCodes uc2);
248 #endif // BUFFERVIEW_H