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>
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
83 /// fit the user cursor within the visible view
85 /// perform pending painting updates
87 // update for a particular lyxtext
88 void update(LyXText *, UpdateCodes uc);
89 /// update for the top-level lyxtext
90 void update(UpdateCodes uc);
91 /// update for a particular inset
92 void updateInset(Inset * inset);
93 /// reset the scrollbar to reflect current view position
94 void updateScrollbar();
96 void redoCurrentBuffer();
99 bool available() const;
102 void beforeChange(LyXText *);
104 /// Save the current position as bookmark i
105 void savePosition(unsigned int i);
106 /// Restore the position from bookmark i
107 void restorePosition(unsigned int i);
108 /// does the given bookmark have a saved position ?
109 bool isSavedPosition(unsigned int i);
111 /// return the current change at the cursor
112 Change const getCurrentChange();
115 * This holds the mapping between buffer paragraphs and screen rows.
116 * This should be private...but not yet. (Lgb)
119 /// return the lyxtext we are using
120 LyXText * getLyXText() const;
122 /// Return the current inset we are "locked" in
123 UpdatableInset * theLockingInset() const;
124 /// lock the given inset FIXME: return value ?
125 bool lockInset(UpdatableInset * inset);
126 /// unlock the given inset
127 int unlockInset(UpdatableInset * inset);
128 /// unlock the currently locked inset
131 /// return the current encoding at the cursor
132 Encoding const * getEncoding() const;
134 /// return the parent language of the given inset
135 Language const * getParentLanguage(Inset * inset) const;
137 /// Select the "current" word
138 void selectLastWord();
139 /// replace the currently selected word
140 void replaceWord(string const & replacestring);
141 /// Update after spellcheck finishes
142 void endOfSpellCheck();
143 /// return the next word
144 WordLangTuple const nextWord(float & value);
146 /// move cursor to the named label
147 void gotoLabel(string const & label);
154 /// removes all autodeletable insets
155 bool removeAutoInsets();
156 /// insert all errors found when running latex
157 void insertErrors(TeXErrors & terr);
158 /// set the cursor based on the given TeX source row
159 void setCursorFromRow(int row);
162 * Insert an inset into the buffer.
163 * Place it in a layout of lout,
165 bool insertInset(Inset * inset, string const & lout = string());
167 /// Inserts a lyx file at cursor position. return false if it fails
168 bool insertLyXFile(string const & file);
170 /// show the user cursor
172 /// hide the user cursor
175 void showLockedInsetCursor(int x, int y, int asc, int desc);
177 void hideLockedInsetCursor();
179 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
181 void lockedInsetStoreUndo(Undo::undo_kind kind);
183 void toggleSelection(bool = true);
187 /// center the document view around the cursor
189 /// scroll document by the given number of lines of default height
190 void scroll(int lines);
191 /// Scroll the view by a number of pixels
192 void scrollDocView(int);
194 /// return the pixel width of the document view
195 int workWidth() const;
196 /// return the pixel height of the document view
197 int workHeight() const;
199 /// switch between primary and secondary keymaps for RTL entry
203 bool ChangeRefsIfUnique(string const & from, string const & to);
205 bool ChangeCitationsIfUnique(string const & from, string const & to);
207 /// get the contents of the window system clipboard
208 string const getClipboard() const;
209 /// fill the window system clipboard
210 void stuffClipboard(string const &) const;
211 /// tell the window system we have a selection
212 void haveSelection(bool sel);
214 /// execute the given function
215 bool dispatch(FuncRequest const & argument);
218 /// Set the current locking inset
219 void theLockingInset(UpdatableInset * inset);
221 /// return the lyxtext containing this inset
222 LyXText * getParentText(Inset * inset) const;
225 * Change all insets with the given code's contents to a new
226 * string. May only be used with InsetCommand-derived insets
227 * Returns true if a screen update is needed.
229 bool ChangeInsets(Inset::Code code, string const & from,
234 friend struct BufferView::Pimpl;
240 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
241 BufferView::UpdateCodes uc2);
243 #endif // BUFFERVIEW_H