4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Lars Gullik Bjønnes
15 #include "insets/inset.h"
17 #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
82 /// create a new buffer based on template
83 bool newFile(string const & fname, string const & tname,
85 /// load a buffer into the view
86 bool loadLyXFile(string const & name, bool tolastfiles = true);
88 /// fit the user cursor within the visible view
90 /// perform pending painting updates
92 // update for a particular lyxtext
93 void update(LyXText *, UpdateCodes uc);
94 /// update for the top-level lyxtext
95 void update(UpdateCodes uc);
96 /// update for a particular inset
97 void updateInset(InsetOld * inset);
98 /// reset the scrollbar to reflect current view position
99 void updateScrollbar();
101 void redoCurrentBuffer();
104 bool available() const;
107 void beforeChange(LyXText *);
109 /// Save the current position as bookmark i
110 void savePosition(unsigned int i);
111 /// Restore the position from bookmark i
112 void restorePosition(unsigned int i);
113 /// does the given bookmark have a saved position ?
114 bool isSavedPosition(unsigned int i);
116 /// return the current change at the cursor
117 Change const getCurrentChange();
120 * This holds the mapping between buffer paragraphs and screen rows.
121 * This should be private...but not yet. (Lgb)
124 /// return the lyxtext we are using
125 LyXText * getLyXText() const;
127 /// Return the current inset we are "locked" in
128 UpdatableInset * theLockingInset() const;
129 /// lock the given inset FIXME: return value ?
130 bool lockInset(UpdatableInset * inset);
131 /// unlock the given inset
132 int unlockInset(UpdatableInset * inset);
133 /// unlock the currently locked inset
136 /// return the current encoding at the cursor
137 Encoding const * getEncoding() const;
139 /// return the parent language of the given inset
140 Language const * getParentLanguage(InsetOld * inset) const;
142 /// Select the "current" word
143 void selectLastWord();
144 /// replace the currently selected word
145 void replaceWord(string const & replacestring);
146 /// Update after spellcheck finishes
147 void endOfSpellCheck();
148 /// return the next word
149 WordLangTuple const nextWord(float & value);
151 /// move cursor to the named label
152 void gotoLabel(string const & label);
159 /// get the stored error list
160 ErrorList const & getErrorList() const;
161 /// show the error list to the user
162 void showErrorList(string const &) const;
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(InsetOld * inset, string const & lout = string());
172 /// Inserts a lyx file at cursor position. return false if it fails
173 bool insertLyXFile(string const & file);
176 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
178 void toggleSelection(bool = true);
180 /// hide the cursor if it is visible
183 /// center the document view around the cursor
185 /// scroll document by the given number of lines of default height
186 void scroll(int lines);
187 /// Scroll the view by a number of pixels
188 void scrollDocView(int);
190 /// return the pixel width of the document view
191 int workWidth() const;
192 /// return the pixel height of the document view
193 int workHeight() const;
195 /// switch between primary and secondary keymaps for RTL entry
199 bool ChangeRefsIfUnique(string const & from, string const & to);
201 /// get the contents of the window system clipboard
202 string const getClipboard() const;
203 /// fill the window system clipboard
204 void stuffClipboard(string const &) const;
205 /// tell the window system we have a selection
206 void haveSelection(bool sel);
208 /// execute the given function
209 bool dispatch(FuncRequest const & argument);
212 /// Set the current locking inset
213 void theLockingInset(UpdatableInset * inset);
215 /// return the lyxtext containing this inset
216 LyXText * getParentText(InsetOld * inset) const;
219 * Change all insets with the given code's contents to a new
220 * string. May only be used with InsetCommand-derived insets
221 * Returns true if a screen update is needed.
223 bool ChangeInsets(InsetOld::Code code, string const & from,
228 friend struct BufferView::Pimpl;
234 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
235 BufferView::UpdateCodes uc2);
237 #endif // BUFFERVIEW_H