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 /// create a new buffer based on template
84 bool newFile(string const & fname, string const & tname,
86 /// load a buffer into the view
87 bool loadLyXFile(string const & name, bool tolastfiles = true);
89 /// fit the user cursor within the visible view
91 /// perform pending painting updates
93 // update for a particular lyxtext
94 void update(LyXText *, UpdateCodes uc);
95 /// update for the top-level lyxtext
96 void update(UpdateCodes uc);
97 /// update for a particular inset
98 void updateInset(Inset * inset);
99 /// reset the scrollbar to reflect current view position
100 void updateScrollbar();
102 void redoCurrentBuffer();
105 bool available() const;
108 void beforeChange(LyXText *);
110 /// Save the current position as bookmark i
111 void savePosition(unsigned int i);
112 /// Restore the position from bookmark i
113 void restorePosition(unsigned int i);
114 /// does the given bookmark have a saved position ?
115 bool isSavedPosition(unsigned int i);
117 /// return the current change at the cursor
118 Change const getCurrentChange();
121 * This holds the mapping between buffer paragraphs and screen rows.
122 * This should be private...but not yet. (Lgb)
125 /// return the lyxtext we are using
126 LyXText * getLyXText() const;
128 /// Return the current inset we are "locked" in
129 UpdatableInset * theLockingInset() const;
130 /// lock the given inset FIXME: return value ?
131 bool lockInset(UpdatableInset * inset);
132 /// unlock the given inset
133 int unlockInset(UpdatableInset * inset);
134 /// unlock the currently locked inset
137 /// return the current encoding at the cursor
138 Encoding const * getEncoding() const;
140 /// return the parent language of the given inset
141 Language const * getParentLanguage(Inset * inset) const;
143 /// Select the "current" word
144 void selectLastWord();
145 /// replace the currently selected word
146 void replaceWord(string const & replacestring);
147 /// Update after spellcheck finishes
148 void endOfSpellCheck();
149 /// return the next word
150 WordLangTuple const nextWord(float & value);
152 /// move cursor to the named label
153 void gotoLabel(string const & label);
160 /// get the stored error list
161 ErrorList const & getErrorList() const;
162 /// show the error list to the user
163 void showErrorList(string const &) const;
164 /// set the cursor based on the given TeX source row
165 void setCursorFromRow(int row);
168 * Insert an inset into the buffer.
169 * Place it in a layout of lout,
171 bool insertInset(Inset * inset, string const & lout = string());
173 /// Inserts a lyx file at cursor position. return false if it fails
174 bool insertLyXFile(string const & file);
177 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
179 void lockedInsetStoreUndo(Undo::undo_kind kind);
181 void toggleSelection(bool = true);
185 /// hide the cursor if it is visible
188 /// center the document view around the cursor
190 /// scroll document by the given number of lines of default height
191 void scroll(int lines);
192 /// Scroll the view by a number of pixels
193 void scrollDocView(int);
195 /// return the pixel width of the document view
196 int workWidth() const;
197 /// return the pixel height of the document view
198 int workHeight() const;
200 /// switch between primary and secondary keymaps for RTL entry
204 bool ChangeRefsIfUnique(string const & from, string const & to);
206 bool ChangeCitationsIfUnique(string const & from, string const & to);
208 /// get the contents of the window system clipboard
209 string const getClipboard() const;
210 /// fill the window system clipboard
211 void stuffClipboard(string const &) const;
212 /// tell the window system we have a selection
213 void haveSelection(bool sel);
215 /// execute the given function
216 bool dispatch(FuncRequest const & argument);
219 /// Set the current locking inset
220 void theLockingInset(UpdatableInset * inset);
222 /// return the lyxtext containing this inset
223 LyXText * getParentText(Inset * inset) const;
226 * Change all insets with the given code's contents to a new
227 * string. May only be used with InsetCommand-derived insets
228 * Returns true if a screen update is needed.
230 bool ChangeInsets(Inset::Code code, string const & from,
235 friend struct BufferView::Pimpl;
241 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
242 BufferView::UpdateCodes uc2);
244 #endif // BUFFERVIEW_H