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>
34 * A buffer view encapsulates a view onto a particular
35 * buffer, and allows access to operate upon it. A view
36 * is a sliding window of the entire document rendering.
38 * Eventually we will allow several views onto a single
39 * buffer, but not yet.
41 class BufferView : boost::noncopyable {
44 * Codes to store necessary pending updates
45 * of the document rendering.
48 UPDATE = 0, //< repaint
49 SELECT = 1 //< reset selection to current cursor pos
53 * Create a view with the given owner main window,
54 * of the given dimensions.
56 BufferView(LyXView * owner, int x, int y, int w, int h);
60 /// set the buffer we are viewing
61 void buffer(Buffer * b);
62 /// return the buffer being viewed
63 Buffer * buffer() const;
65 /// return the painter object for drawing onto the view
66 Painter & painter() const;
67 /// return the screen object for handling re-drawing
68 LyXScreen & screen() const;
69 /// return the owning main view
70 LyXView * owner() const;
72 /// resize event has happened
75 * Repaint the pixmap. Used for when we don't want
76 * to go through the full update() logic, just a simple
77 * repaint of the whole screen.
81 /// reload the contained buffer
83 /// load a buffer into the view
84 bool loadLyXFile(string const & name, bool tolastfiles = true);
86 /// fit the user cursor within the visible view
88 /// perform pending painting updates
90 // update for a particular lyxtext
91 void update(LyXText *, UpdateCodes uc);
92 /// update for the top-level lyxtext
93 void update(UpdateCodes uc);
94 /// update for a particular inset
95 void updateInset(Inset * inset);
96 /// reset the scrollbar to reflect current view position
97 void updateScrollbar();
99 void redoCurrentBuffer();
102 bool available() const;
105 void beforeChange(LyXText *);
107 /// Save the current position as bookmark i
108 void savePosition(unsigned int i);
109 /// Restore the position from bookmark i
110 void restorePosition(unsigned int i);
111 /// does the given bookmark have a saved position ?
112 bool isSavedPosition(unsigned int i);
114 /// return the current change at the cursor
115 Change const getCurrentChange();
118 * This holds the mapping between buffer paragraphs and screen rows.
119 * This should be private...but not yet. (Lgb)
122 /// return the lyxtext we are using
123 LyXText * getLyXText() const;
125 /// Return the current inset we are "locked" in
126 UpdatableInset * theLockingInset() const;
127 /// lock the given inset FIXME: return value ?
128 bool lockInset(UpdatableInset * inset);
129 /// unlock the given inset
130 int unlockInset(UpdatableInset * inset);
131 /// unlock the currently locked inset
134 /// return the current encoding at the cursor
135 Encoding const * getEncoding() const;
137 /// return the parent language of the given inset
138 Language const * getParentLanguage(Inset * inset) const;
140 /// Select the "current" word
141 void selectLastWord();
142 /// replace the currently selected word
143 void replaceWord(string const & replacestring);
144 /// Update after spellcheck finishes
145 void endOfSpellCheck();
146 /// return the next word
147 WordLangTuple const nextWord(float & value);
149 /// move cursor to the named label
150 void gotoLabel(string const & label);
157 /// get the stored error list
158 ErrorList const & getErrorList() const;
159 /// show the error list to the user
160 void showErrorList(string const &) const;
161 /// set the cursor based on the given TeX source row
162 void setCursorFromRow(int row);
165 * Insert an inset into the buffer.
166 * Place it in a layout of lout,
168 bool insertInset(Inset * inset, string const & lout = string());
170 /// Inserts a lyx file at cursor position. return false if it fails
171 bool insertLyXFile(string const & file);
174 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
176 void lockedInsetStoreUndo(Undo::undo_kind kind);
178 void toggleSelection(bool = true);
182 /// hide the cursor if it is visible
185 /// center the document view around the cursor
187 /// scroll document by the given number of lines of default height
188 void scroll(int lines);
189 /// Scroll the view by a number of pixels
190 void scrollDocView(int);
192 /// return the pixel width of the document view
193 int workWidth() const;
194 /// return the pixel height of the document view
195 int workHeight() const;
197 /// switch between primary and secondary keymaps for RTL entry
201 bool ChangeRefsIfUnique(string const & from, string const & to);
203 bool ChangeCitationsIfUnique(string const & from, string const & to);
205 /// get the contents of the window system clipboard
206 string const getClipboard() const;
207 /// fill the window system clipboard
208 void stuffClipboard(string const &) const;
209 /// tell the window system we have a selection
210 void haveSelection(bool sel);
212 /// execute the given function
213 bool dispatch(FuncRequest const & argument);
216 /// Set the current locking inset
217 void theLockingInset(UpdatableInset * inset);
219 /// return the lyxtext containing this inset
220 LyXText * getParentText(Inset * inset) const;
223 * Change all insets with the given code's contents to a new
224 * string. May only be used with InsetCommand-derived insets
225 * Returns true if a screen update is needed.
227 bool ChangeInsets(Inset::Code code, string const & from,
232 friend struct BufferView::Pimpl;
238 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
239 BufferView::UpdateCodes uc2);
241 #endif // BUFFERVIEW_H