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 inset
87 void updateInset(InsetOld * inset);
88 /// reset the scrollbar to reflect current view position
89 void updateScrollbar();
91 void redoCurrentBuffer();
94 bool available() const;
97 void beforeChange(LyXText *);
99 /// Save the current position as bookmark i
100 void savePosition(unsigned int i);
101 /// Restore the position from bookmark i
102 void restorePosition(unsigned int i);
103 /// does the given bookmark have a saved position ?
104 bool isSavedPosition(unsigned int i);
106 /// return the current change at the cursor
107 Change const getCurrentChange();
110 * This holds the mapping between buffer paragraphs and screen rows.
111 * This should be private...but not yet. (Lgb)
114 /// return the lyxtext we are using
115 LyXText * getLyXText() const;
117 /// Return the current inset we are "locked" in
118 UpdatableInset * theLockingInset() const;
119 /// lock the given inset FIXME: return value ?
120 bool lockInset(UpdatableInset * inset);
121 /// unlock the given inset
122 int unlockInset(UpdatableInset * inset);
123 /// unlock the currently locked inset
126 /// return the current encoding at the cursor
127 Encoding const * getEncoding() const;
129 /// return the parent language of the given inset
130 Language const * getParentLanguage(InsetOld * inset) const;
132 /// Select the "current" word
133 void selectLastWord();
134 /// replace the currently selected word
135 void replaceWord(string const & replacestring);
136 /// Update after spellcheck finishes
137 void endOfSpellCheck();
138 /// return the next word
139 WordLangTuple const nextWord(float & value);
141 /// move cursor to the named label
142 void gotoLabel(string const & label);
149 /// get the stored error list
150 ErrorList const & getErrorList() const;
151 /// show the error list to the user
152 void showErrorList(string const &) const;
153 /// set the cursor based on the given TeX source row
154 void setCursorFromRow(int row);
157 * Insert an inset into the buffer.
158 * Place it in a layout of lout,
160 bool insertInset(InsetOld * inset, string const & lout = string());
162 /// Inserts a lyx file at cursor position. return false if it fails
163 bool insertLyXFile(string const & file);
166 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
168 void toggleSelection(bool = true);
170 /// hide the cursor if it is visible
173 /// center the document view around the cursor
175 /// scroll document by the given number of lines of default height
176 void scroll(int lines);
177 /// Scroll the view by a number of pixels
178 void scrollDocView(int);
180 /// return the pixel width of the document view
181 int workWidth() const;
182 /// return the pixel height of the document view
183 int workHeight() const;
185 /// switch between primary and secondary keymaps for RTL entry
189 bool ChangeRefsIfUnique(string const & from, string const & to);
191 /// get the contents of the window system clipboard
192 string const getClipboard() const;
193 /// fill the window system clipboard
194 void stuffClipboard(string const &) const;
195 /// tell the window system we have a selection
196 void haveSelection(bool sel);
198 /// execute the given function
199 bool dispatch(FuncRequest const & argument);
202 /// Set the current locking inset
203 void theLockingInset(UpdatableInset * inset);
205 /// return the lyxtext containing this inset
206 LyXText * getParentText(InsetOld * inset) const;
209 * Change all insets with the given code's contents to a new
210 * string. May only be used with InsetCommand-derived insets
211 * Returns true if a screen update is needed.
213 bool ChangeInsets(InsetOld::Code code, string const & from,
218 friend struct BufferView::Pimpl;
224 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
225 BufferView::UpdateCodes uc2);
227 #endif // BUFFERVIEW_H