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 /// reload the contained buffer
76 /// create a new buffer based on template
77 bool newFile(string const & fname, string const & tname,
79 /// load a buffer into the view
80 bool loadLyXFile(string const & name, bool tolastfiles = true);
82 /// fit the user cursor within the visible view
84 /// perform pending painting updates
86 // update for a particular lyxtext
87 void update(LyXText *, UpdateCodes uc);
88 /// update for the top-level lyxtext
89 void update(UpdateCodes uc);
90 /// update for a particular inset
91 void updateInset(InsetOld * inset);
92 /// reset the scrollbar to reflect current view position
93 void updateScrollbar();
95 void redoCurrentBuffer();
98 bool available() const;
101 void beforeChange(LyXText *);
103 /// Save the current position as bookmark i
104 void savePosition(unsigned int i);
105 /// Restore the position from bookmark i
106 void restorePosition(unsigned int i);
107 /// does the given bookmark have a saved position ?
108 bool isSavedPosition(unsigned int i);
110 /// return the current change at the cursor
111 Change const getCurrentChange();
114 * This holds the mapping between buffer paragraphs and screen rows.
115 * This should be private...but not yet. (Lgb)
118 /// return the lyxtext we are using
119 LyXText * getLyXText() const;
121 /// Return the current inset we are "locked" in
122 UpdatableInset * theLockingInset() const;
123 /// lock the given inset FIXME: return value ?
124 bool lockInset(UpdatableInset * inset);
125 /// unlock the given inset
126 int unlockInset(UpdatableInset * inset);
127 /// unlock the currently locked inset
130 /// return the current encoding at the cursor
131 Encoding const * getEncoding() const;
133 /// return the parent language of the given inset
134 Language const * getParentLanguage(InsetOld * inset) const;
136 /// Select the "current" word
137 void selectLastWord();
138 /// replace the currently selected word
139 void replaceWord(string const & replacestring);
140 /// Update after spellcheck finishes
141 void endOfSpellCheck();
142 /// return the next word
143 WordLangTuple const nextWord(float & value);
145 /// move cursor to the named label
146 void gotoLabel(string const & label);
153 /// get the stored error list
154 ErrorList const & getErrorList() const;
155 /// show the error list to the user
156 void showErrorList(string const &) const;
157 /// set the cursor based on the given TeX source row
158 void setCursorFromRow(int row);
161 * Insert an inset into the buffer.
162 * Place it in a layout of lout,
164 bool insertInset(InsetOld * inset, string const & lout = string());
166 /// Inserts a lyx file at cursor position. return false if it fails
167 bool insertLyXFile(string const & file);
170 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
172 void toggleSelection(bool = true);
174 /// hide the cursor if it is visible
177 /// center the document view around the cursor
179 /// scroll document by the given number of lines of default height
180 void scroll(int lines);
181 /// Scroll the view by a number of pixels
182 void scrollDocView(int);
184 /// return the pixel width of the document view
185 int workWidth() const;
186 /// return the pixel height of the document view
187 int workHeight() const;
189 /// switch between primary and secondary keymaps for RTL entry
193 bool ChangeRefsIfUnique(string const & from, string const & to);
195 /// get the contents of the window system clipboard
196 string const getClipboard() const;
197 /// fill the window system clipboard
198 void stuffClipboard(string const &) const;
199 /// tell the window system we have a selection
200 void haveSelection(bool sel);
202 /// execute the given function
203 bool dispatch(FuncRequest const & argument);
206 /// Set the current locking inset
207 void theLockingInset(UpdatableInset * inset);
209 /// return the lyxtext containing this inset
210 LyXText * getParentText(InsetOld * inset) const;
213 * Change all insets with the given code's contents to a new
214 * string. May only be used with InsetCommand-derived insets
215 * Returns true if a screen update is needed.
217 bool ChangeInsets(InsetOld::Code code, string const & from,
222 friend struct BufferView::Pimpl;
228 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
229 BufferView::UpdateCodes uc2);
231 #endif // BUFFERVIEW_H