4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Lars Gullik Bjønnes
20 #include "insets/inset.h"
22 #include <boost/utility.hpp>
37 * A buffer view encapsulates a view onto a particular
38 * buffer, and allows access to operate upon it. A view
39 * is a sliding window of the entire document rendering.
41 * Eventually we will allow several views onto a single
42 * buffer, but not yet.
44 class BufferView : boost::noncopyable {
47 * Codes to store necessary pending updates
48 * of the document rendering.
52 SELECT = 1, //< selection change
53 FITCUR = 2, //< the cursor needs fitting into the view
54 CHANGE = 4 //< document data has changed
58 * Create a view with the given owner main window,
59 * of the given dimensions.
61 BufferView(LyXView * owner, int x, int y, int w, int h);
65 /// set the buffer we are viewing
66 void buffer(Buffer * b);
67 /// return the buffer being viewed
68 Buffer * buffer() const;
70 /// return the painter object for drawing onto the view
71 Painter & painter() const;
72 /// return the screen object for handling re-drawing
73 LyXScreen & screen() const;
74 /// return the owning main view
75 LyXView * owner() const;
77 /// resize event has happened
80 * Repaint the pixmap. Used for when we don't want
81 * to go through the full update() logic, just a simple
82 * repaint of the whole screen.
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 a particular inset
93 void updateInset(Inset * inset, bool mark_dirty);
94 /// reset the scrollbar to reflect current view position
95 void updateScrollbar();
97 void redoCurrentBuffer();
100 bool available() const;
103 void beforeChange(LyXText *);
105 /// Save the current position as bookmark i
106 void savePosition(unsigned int i);
107 /// Restore the position from bookmark i
108 void restorePosition(unsigned int i);
109 /// does the given bookmark have a saved position ?
110 bool isSavedPosition(unsigned int i);
112 /// return the current change at the cursor
113 Change const getCurrentChange();
116 * This holds the mapping between buffer paragraphs and screen rows.
117 * This should be private...but not yet. (Lgb)
120 /// return the lyxtext we are using
121 LyXText * getLyXText() const;
123 /// Return the current inset we are "locked" in
124 UpdatableInset * theLockingInset() const;
125 /// lock the given inset FIXME: return value ?
126 bool lockInset(UpdatableInset * inset);
127 /// unlock the given inset
128 int unlockInset(UpdatableInset * inset);
129 /// unlock the currently locked inset
132 /// return the current encoding at the cursor
133 Encoding const * getEncoding() const;
135 /// return the parent language of the given inset
136 Language const * getParentLanguage(Inset * inset) const;
138 /// Select the "current" word
139 void selectLastWord();
140 /// replace the currently selected word
141 void replaceWord(string const & replacestring);
142 /// Update after spellcheck finishes
143 void endOfSpellCheck();
144 /// return the next word
145 WordLangTuple const nextWord(float & value);
147 /// move cursor to the named label
148 bool gotoLabel(string const & label);
150 /// copy the environment type from current paragraph
151 void copyEnvironment();
152 /// set the current paragraph's environment type
153 void pasteEnvironment();
160 /// removes all autodeletable insets
161 bool removeAutoInsets();
162 /// insert all errors found when running latex
163 void insertErrors(TeXErrors & terr);
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);
176 /// show the user cursor
178 /// hide the user cursor
181 void showLockedInsetCursor(int x, int y, int asc, int desc);
183 void hideLockedInsetCursor();
185 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
187 void lockedInsetStoreUndo(Undo::undo_kind kind);
189 void toggleSelection(bool = true);
193 /// center the document view around the cursor
195 /// scroll document by the given number of lines of default height
196 void scroll(int lines);
197 /// Scroll the view by a number of pixels
198 void scrollDocView(int);
200 /// height of a normal line in pixels (zoom factor considered)
201 int defaultHeight() const;
202 /// return the pixel width of the document view
203 int workWidth() const;
204 /// return the pixel height of the document view
205 int workHeight() const;
207 /// switch between primary and secondary keymaps for RTL entry
211 bool ChangeRefsIfUnique(string const & from, string const & to);
213 bool ChangeCitationsIfUnique(string const & from, string const & to);
215 /// get the contents of the window system clipboard
216 string const getClipboard() const;
217 /// fill the window system clipboard
218 void stuffClipboard(string const &) const;
219 /// tell the window system we have a selection
220 void haveSelection(bool sel);
222 /// execute the given function
223 bool dispatch(FuncRequest const & argument);
226 /// Set the current locking inset
227 void theLockingInset(UpdatableInset * inset);
229 /// return the lyxtext containing this inset
230 LyXText * getParentText(Inset * inset) const;
233 * Change all insets with the given code's contents to a new
234 * string. May only be used with InsetCommand-derived insets
235 * Returns true if a screen update is needed.
237 bool ChangeInsets(Inset::Code code, string const & from,
242 friend struct BufferView::Pimpl;
248 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
249 BufferView::UpdateCodes uc2);
251 #endif // BUFFERVIEW_H