]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
added a parseError signal to Buffer and use it
[lyx.git] / src / BufferView.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  *  \author Lars Gullik Bjønnes
8 */
9
10 #ifndef BUFFER_VIEW_H
11 #define BUFFER_VIEW_H
12
13 #include "LString.h"
14 #include "undo.h"
15
16 #include "insets/inset.h"
17
18 #include <boost/utility.hpp>
19
20 class Change;
21 class LyXView;
22 class LyXText;
23 class TeXErrors;
24 class Buffer;
25 class LyXScreen;
26 class Language;
27 class Painter;
28 class UpdatableInset;
29 class WordLangTuple;
30 class Encoding;
31 class ErrorList;
32 class ErrorItem;
33
34 /**
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.
38  *
39  * Eventually we will allow several views onto a single
40  * buffer, but not yet.
41  */
42 class BufferView : boost::noncopyable {
43 public:
44         /**
45          * Codes to store necessary pending updates
46          * of the document rendering.
47          */
48         enum UpdateCodes {
49                 UPDATE = 0, //< repaint
50                 SELECT = 1 //< reset selection to current cursor pos
51         };
52
53         /**
54          * Create a view with the given owner main window,
55          * of the given dimensions.
56          */
57         BufferView(LyXView * owner, int x, int y, int w, int h);
58
59         ~BufferView();
60
61         /// set the buffer we are viewing
62         void buffer(Buffer * b);
63         /// return the buffer being viewed
64         Buffer * buffer() const;
65
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;
72
73         /// resize event has happened
74         void resize();
75         /**
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.
79          */
80         void repaint();
81
82         /// reload the contained buffer
83         void reload();
84         /// load a buffer into the view
85         bool loadLyXFile(string const & name, bool tolastfiles = true);
86
87         /// fit the user cursor within the visible view
88         bool fitCursor();
89         /// perform pending painting updates
90         void update();
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();
99         /// FIXME
100         void redoCurrentBuffer();
101
102         /// FIXME
103         bool available() const;
104
105         /// FIXME
106         void beforeChange(LyXText *);
107
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);
114
115         /// return the current change at the cursor
116         Change const getCurrentChange();
117
118         /**
119          * This holds the mapping between buffer paragraphs and screen rows.
120          * This should be private...but not yet. (Lgb)
121          */
122         LyXText * text;
123         /// return the lyxtext we are using
124         LyXText * getLyXText() const;
125
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
133         void insetUnlock();
134
135         /// return the current encoding at the cursor
136         Encoding const * getEncoding() const;
137
138         /// return the parent language of the given inset
139         Language const * getParentLanguage(Inset * inset) const;
140
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);
149
150         /// move cursor to the named label
151         void gotoLabel(string const & label);
152
153         /// undo last action
154         void undo();
155         /// redo last action
156         void redo();
157
158         /// get the stored error list
159         ErrorList const & getErrorList() const;
160         /// clears the stored error list
161         void resetErrorList();
162         /// stored this  error list
163         void setErrorList(ErrorList const &);
164         /// show the error list to the user
165         void showErrorList(string const &) const;
166         /// set the cursor based on the given TeX source row
167         void setCursorFromRow(int row);
168
169         /**
170          * Insert an inset into the buffer.
171          * Place it in a layout of lout,
172          */
173         bool insertInset(Inset * inset, string const & lout = string());
174
175         /// Inserts a lyx file at cursor position. return false if it fails
176         bool insertLyXFile(string const & file);
177
178         /// FIXME
179         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
180         /// FIXME
181         void lockedInsetStoreUndo(Undo::undo_kind kind);
182         /// FIXME
183         void toggleSelection(bool = true);
184         /// FIXME: my word !
185         void toggleToggle();
186
187         /// hide the cursor if it is visible
188         void hideCursor();
189
190         /// center the document view around the cursor
191         void center();
192         /// scroll document by the given number of lines of default height
193         void scroll(int lines);
194         /// Scroll the view by a number of pixels
195         void scrollDocView(int);
196
197         /// return the pixel width of the document view
198         int workWidth() const;
199         /// return the pixel height of the document view
200         int workHeight() const;
201
202         /// switch between primary and secondary keymaps for RTL entry
203         void switchKeyMap();
204
205         /// FIXME
206         bool ChangeRefsIfUnique(string const & from, string const & to);
207         /// FIXME
208         bool ChangeCitationsIfUnique(string const & from, string const & to);
209
210         /// get the contents of the window system clipboard
211         string const getClipboard() const;
212         /// fill the window system clipboard
213         void stuffClipboard(string const &) const;
214         /// tell the window system we have a selection
215         void haveSelection(bool sel);
216
217         /// execute the given function
218         bool dispatch(FuncRequest const & argument);
219
220 private:
221         /// Set the current locking inset
222         void theLockingInset(UpdatableInset * inset);
223
224         /// return the lyxtext containing this inset
225         LyXText * getParentText(Inset * inset) const;
226
227         /**
228          * Change all insets with the given code's contents to a new
229          * string. May only be used with InsetCommand-derived insets
230          * Returns true if a screen update is needed.
231          */
232         bool ChangeInsets(Inset::Code code, string const & from,
233                           string const & to);
234
235
236         struct Pimpl;
237         friend struct BufferView::Pimpl;
238
239         Pimpl * pimpl_;
240 };
241
242
243 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
244                                   BufferView::UpdateCodes uc2);
245
246 #endif // BUFFERVIEW_H