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.
48 SELECT = 1, //< selection change
49 FITCUR = 2, //< the cursor needs fitting into the view
50 CHANGE = 4 //< document data has changed
54 * Create a view with the given owner main window,
55 * of the given dimensions.
57 BufferView(LyXView * owner, int x, int y, int w, int h);
61 /// set the buffer we are viewing
62 void buffer(Buffer * b);
63 /// return the buffer being viewed
64 Buffer * buffer() const;
66 /// return the painter object for drawing onto the view
67 Painter & painter() const;
68 /// return the screen object for handling re-drawing
69 LyXScreen & screen() const;
70 /// return the owning main view
71 LyXView * owner() const;
73 /// resize event has happened
76 * Repaint the pixmap. Used for when we don't want
77 * to go through the full update() logic, just a simple
78 * repaint of the whole screen.
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 a particular inset
89 void updateInset(Inset * inset, bool mark_dirty);
90 /// reset the scrollbar to reflect current view position
91 void updateScrollbar();
93 void redoCurrentBuffer();
96 bool available() const;
99 void beforeChange(LyXText *);
101 /// Save the current position as bookmark i
102 void savePosition(unsigned int i);
103 /// Restore the position from bookmark i
104 void restorePosition(unsigned int i);
105 /// does the given bookmark have a saved position ?
106 bool isSavedPosition(unsigned int i);
108 /// return the current change at the cursor
109 Change const getCurrentChange();
112 * This holds the mapping between buffer paragraphs and screen rows.
113 * This should be private...but not yet. (Lgb)
116 /// return the lyxtext we are using
117 LyXText * getLyXText() const;
119 /// Return the current inset we are "locked" in
120 UpdatableInset * theLockingInset() const;
121 /// lock the given inset FIXME: return value ?
122 bool lockInset(UpdatableInset * inset);
123 /// unlock the given inset
124 int unlockInset(UpdatableInset * inset);
125 /// unlock the currently locked inset
128 /// return the current encoding at the cursor
129 Encoding const * getEncoding() const;
131 /// return the parent language of the given inset
132 Language const * getParentLanguage(Inset * inset) const;
134 /// Select the "current" word
135 void selectLastWord();
136 /// replace the currently selected word
137 void replaceWord(string const & replacestring);
138 /// Update after spellcheck finishes
139 void endOfSpellCheck();
140 /// return the next word
141 WordLangTuple const nextWord(float & value);
143 /// move cursor to the named label
144 bool gotoLabel(string const & label);
146 /// copy the environment type from current paragraph
147 void copyEnvironment();
148 /// set the current paragraph's environment type
149 void pasteEnvironment();
156 /// removes all autodeletable insets
157 bool removeAutoInsets();
158 /// insert all errors found when running latex
159 void insertErrors(TeXErrors & terr);
160 /// set the cursor based on the given TeX source row
161 void setCursorFromRow(int row);
164 * Insert an inset into the buffer.
165 * Place it in a layout of lout,
167 bool insertInset(Inset * inset, string const & lout = string());
169 /// Inserts a lyx file at cursor position. return false if it fails
170 bool insertLyXFile(string const & file);
172 /// show the user cursor
174 /// hide the user cursor
177 void showLockedInsetCursor(int x, int y, int asc, int desc);
179 void hideLockedInsetCursor();
181 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
183 void lockedInsetStoreUndo(Undo::undo_kind kind);
185 void toggleSelection(bool = true);
189 /// center the document view around the cursor
191 /// scroll document by the given number of lines of default height
192 void scroll(int lines);
193 /// Scroll the view by a number of pixels
194 void scrollDocView(int);
196 /// return the pixel width of the document view
197 int workWidth() const;
198 /// return the pixel height of the document view
199 int workHeight() const;
201 /// switch between primary and secondary keymaps for RTL entry
205 bool ChangeRefsIfUnique(string const & from, string const & to);
207 bool ChangeCitationsIfUnique(string const & from, string const & to);
209 /// get the contents of the window system clipboard
210 string const getClipboard() const;
211 /// fill the window system clipboard
212 void stuffClipboard(string const &) const;
213 /// tell the window system we have a selection
214 void haveSelection(bool sel);
216 /// execute the given function
217 bool dispatch(FuncRequest const & argument);
220 /// Set the current locking inset
221 void theLockingInset(UpdatableInset * inset);
223 /// return the lyxtext containing this inset
224 LyXText * getParentText(Inset * inset) const;
227 * Change all insets with the given code's contents to a new
228 * string. May only be used with InsetCommand-derived insets
229 * Returns true if a screen update is needed.
231 bool ChangeInsets(Inset::Code code, string const & from,
236 friend struct BufferView::Pimpl;
242 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
243 BufferView::UpdateCodes uc2);
245 #endif // BUFFERVIEW_H