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>
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.
49 UPDATE = 0, //< repaint
50 SELECT = 1 //< reset selection to current cursor pos
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 /// reload the contained buffer
84 /// load a buffer into the view
85 bool loadLyXFile(string const & name, bool tolastfiles = true);
87 /// fit the user cursor within the visible view
89 /// perform pending painting updates
91 // update for a particular lyxtext
92 void update(LyXText *, UpdateCodes uc);
93 /// update for the top-level lyxtext
94 void update(UpdateCodes uc);
95 /// update for a particular inset
96 void updateInset(Inset * inset);
97 /// reset the scrollbar to reflect current view position
98 void updateScrollbar();
100 void redoCurrentBuffer();
103 bool available() const;
106 void beforeChange(LyXText *);
108 /// Save the current position as bookmark i
109 void savePosition(unsigned int i);
110 /// Restore the position from bookmark i
111 void restorePosition(unsigned int i);
112 /// does the given bookmark have a saved position ?
113 bool isSavedPosition(unsigned int i);
115 /// return the current change at the cursor
116 Change const getCurrentChange();
119 * This holds the mapping between buffer paragraphs and screen rows.
120 * This should be private...but not yet. (Lgb)
123 /// return the lyxtext we are using
124 LyXText * getLyXText() const;
126 /// Return the current inset we are "locked" in
127 UpdatableInset * theLockingInset() const;
128 /// lock the given inset FIXME: return value ?
129 bool lockInset(UpdatableInset * inset);
130 /// unlock the given inset
131 int unlockInset(UpdatableInset * inset);
132 /// unlock the currently locked inset
135 /// return the current encoding at the cursor
136 Encoding const * getEncoding() const;
138 /// return the parent language of the given inset
139 Language const * getParentLanguage(Inset * inset) const;
141 /// Select the "current" word
142 void selectLastWord();
143 /// replace the currently selected word
144 void replaceWord(string const & replacestring);
145 /// Update after spellcheck finishes
146 void endOfSpellCheck();
147 /// return the next word
148 WordLangTuple const nextWord(float & value);
150 /// move cursor to the named label
151 void gotoLabel(string const & label);
158 /// get the stored error list
159 ErrorList const & getErrorList() const;
160 /// show the error list to the user
161 void showErrorList(string const &) const;
162 /// set the cursor based on the given TeX source row
163 void setCursorFromRow(int row);
166 * Insert an inset into the buffer.
167 * Place it in a layout of lout,
169 bool insertInset(Inset * inset, string const & lout = string());
171 /// Inserts a lyx file at cursor position. return false if it fails
172 bool insertLyXFile(string const & file);
175 bool fitLockedInsetCursor(int x, int y, int asc, int desc);
177 void lockedInsetStoreUndo(Undo::undo_kind kind);
179 void toggleSelection(bool = true);
183 /// hide the cursor if it is visible
186 /// center the document view around the cursor
188 /// scroll document by the given number of lines of default height
189 void scroll(int lines);
190 /// Scroll the view by a number of pixels
191 void scrollDocView(int);
193 /// return the pixel width of the document view
194 int workWidth() const;
195 /// return the pixel height of the document view
196 int workHeight() const;
198 /// switch between primary and secondary keymaps for RTL entry
202 bool ChangeRefsIfUnique(string const & from, string const & to);
204 bool ChangeCitationsIfUnique(string const & from, string const & to);
206 /// get the contents of the window system clipboard
207 string const getClipboard() const;
208 /// fill the window system clipboard
209 void stuffClipboard(string const &) const;
210 /// tell the window system we have a selection
211 void haveSelection(bool sel);
213 /// execute the given function
214 bool dispatch(FuncRequest const & argument);
217 /// Set the current locking inset
218 void theLockingInset(UpdatableInset * inset);
220 /// return the lyxtext containing this inset
221 LyXText * getParentText(Inset * inset) const;
224 * Change all insets with the given code's contents to a new
225 * string. May only be used with InsetCommand-derived insets
226 * Returns true if a screen update is needed.
228 bool ChangeInsets(Inset::Code code, string const & from,
233 friend struct BufferView::Pimpl;
239 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
240 BufferView::UpdateCodes uc2);
242 #endif // BUFFERVIEW_H