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>
35 * A buffer view encapsulates a view onto a particular
36 * buffer, and allows access to operate upon it. A view
37 * is a sliding window of the entire document rendering.
39 * Eventually we will allow several views onto a single
40 * buffer, but not yet.
42 class BufferView : boost::noncopyable {
45 * Codes to store necessary pending updates
46 * of the document rendering.
50 SELECT = 1, //< selection change
51 FITCUR = 2, //< the cursor needs fitting into the view
52 CHANGE = 4 //< document data has changed
56 * Create a view with the given owner main window,
57 * of the given dimensions.
59 BufferView(LyXView * owner, int x, int y, int w, int h);
63 /// set the buffer we are viewing
64 void buffer(Buffer * b);
65 /// return the buffer being viewed
66 Buffer * buffer() const;
68 /// return the painter object for drawing onto the view
69 Painter & painter() const;
70 /// return the screen object for handling re-drawing
71 LyXScreen & screen() const;
72 /// return the owning main view
73 LyXView * owner() const;
75 /// resize event has happened
78 * Repaint the pixmap. Used for when we don't want
79 * to go through the full update() logic, just a simple
80 * repaint of the whole screen.
84 /// fit the user cursor within the visible view
86 /// perform pending painting updates
88 // update for a particular lyxtext
89 void update(LyXText *, UpdateCodes uc);
90 /// update for a particular inset
91 void updateInset(Inset * inset, bool mark_dirty);
92 /// reset the scrollbar to reflect current view position
93 void updateScrollbar();
95 void redoCurrentBuffer();
98 bool available() const;
101 void beforeChange(LyXText *);
103 /// Save the current position as bookmark i
104 void savePosition(unsigned int i);
105 /// Restore the position from bookmark i
106 void restorePosition(unsigned int i);
107 /// does the given bookmark have a saved position ?
108 bool isSavedPosition(unsigned int i);
111 * This holds the mapping between buffer paragraphs and screen rows.
112 * This should be private...but not yet. (Lgb)
115 /// return the lyxtext we are using
116 LyXText * getLyXText() const;
118 /// Return the current inset we are "locked" in
119 UpdatableInset * theLockingInset() const;
120 /// lock the given inset FIXME: return value ?
121 bool lockInset(UpdatableInset * inset);
122 /// unlock the given inset
123 int unlockInset(UpdatableInset * inset);
124 /// unlock the currently locked inset
127 /// return the parent language of the given inset
128 Language const * getParentLanguage(Inset * inset) const;
130 /// Select the "current" word
131 void selectLastWord();
132 /// replace the currently selected word
133 void replaceWord(string const & replacestring);
134 /// Update after spellcheck finishes
135 void endOfSpellCheck();
136 /// return the next word
137 WordLangTuple const nextWord(float & value);
139 /// move cursor to the named label
140 bool gotoLabel(string const & label);
142 /// copy the environment type from current paragraph
143 void copyEnvironment();
144 /// set the current paragraph's environment type
145 void pasteEnvironment();
152 /// removes all autodeletable insets
153 bool removeAutoInsets();
154 /// insert all errors found when running latex
155 void insertErrors(TeXErrors & terr);
156 /// set the cursor based on the given TeX source row
157 void setCursorFromRow(int row);
160 * Insert an inset into the buffer.
161 * Place it in a layout of lout,
163 bool insertInset(Inset * inset, string const & lout = string());
165 /// Inserts a lyx file at cursor position. return false if it fails
166 bool insertLyXFile(string const & file);
168 /// show the user cursor
170 /// hide the user cursor
173 void showLockedInsetCursor(int x, int y, int asc, int desc);
175 void hideLockedInsetCursor();
177 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
179 void lockedInsetStoreUndo(Undo::undo_kind kind);
181 void toggleSelection(bool = true);
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 /// height of a normal line in pixels (zoom factor considered)
193 int defaultHeight() const;
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