]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
056e405dcc0bf679e554ce38b34c9d94acfa734c
[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
85         /// fit the user cursor within the visible view
86         bool fitCursor();
87         /// perform pending painting updates
88         void update();
89         // update for a particular lyxtext
90         void update(LyXText *, UpdateCodes uc);
91         /// update for the top-level lyxtext
92         void update(UpdateCodes uc);
93         /// update for a particular inset
94         void updateInset(Inset * inset);
95         /// reset the scrollbar to reflect current view position
96         void updateScrollbar();
97         /// FIXME
98         void redoCurrentBuffer();
99
100         /// FIXME
101         bool available() const;
102
103         /// FIXME
104         void beforeChange(LyXText *);
105
106         /// Save the current position as bookmark i
107         void savePosition(unsigned int i);
108         /// Restore the position from bookmark i
109         void restorePosition(unsigned int i);
110         /// does the given bookmark have a saved position ?
111         bool isSavedPosition(unsigned int i);
112
113         /// return the current change at the cursor
114         Change const getCurrentChange();
115
116         /**
117          * This holds the mapping between buffer paragraphs and screen rows.
118          * This should be private...but not yet. (Lgb)
119          */
120         LyXText * text;
121         /// return the lyxtext we are using
122         LyXText * getLyXText() const;
123
124         /// Return the current inset we are "locked" in
125         UpdatableInset * theLockingInset() const;
126         /// lock the given inset FIXME: return value ?
127         bool lockInset(UpdatableInset * inset);
128         /// unlock the given inset
129         int unlockInset(UpdatableInset * inset);
130         /// unlock the currently locked inset
131         void insetUnlock();
132
133         /// return the current encoding at the cursor
134         Encoding const * getEncoding() const;
135
136         /// return the parent language of the given inset
137         Language const * getParentLanguage(Inset * inset) const;
138
139         /// Select the "current" word
140         void selectLastWord();
141         /// replace the currently selected word
142         void replaceWord(string const & replacestring);
143         /// Update after spellcheck finishes
144         void endOfSpellCheck();
145         /// return the next word
146         WordLangTuple const nextWord(float & value);
147
148         /// move cursor to the named label
149         void gotoLabel(string const & label);
150
151         /// undo last action
152         void undo();
153         /// redo last action
154         void redo();
155
156         /// removes all autodeletable insets
157         bool removeAutoInsets();
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         /// adds a single error to the list
165         void addError(ErrorItem const &);
166         /// show the error list to the user
167         void showErrorList(string const &) const;
168         /// set the cursor based on the given TeX source row
169         void setCursorFromRow(int row);
170
171         /**
172          * Insert an inset into the buffer.
173          * Place it in a layout of lout,
174          */
175         bool insertInset(Inset * inset, string const & lout = string());
176
177         /// Inserts a lyx file at cursor position. return false if it fails
178         bool insertLyXFile(string const & file);
179
180         /// FIXME
181         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
182         /// FIXME
183         void lockedInsetStoreUndo(Undo::undo_kind kind);
184         /// FIXME
185         void toggleSelection(bool = true);
186         /// FIXME: my word !
187         void toggleToggle();
188
189         /// hide the cursor if it is visible
190         void hideCursor();
191
192         /// center the document view around the cursor
193         void center();
194         /// scroll document by the given number of lines of default height
195         void scroll(int lines);
196         /// Scroll the view by a number of pixels
197         void scrollDocView(int);
198
199         /// return the pixel width of the document view
200         int workWidth() const;
201         /// return the pixel height of the document view
202         int workHeight() const;
203
204         /// switch between primary and secondary keymaps for RTL entry
205         void switchKeyMap();
206
207         /// FIXME
208         bool ChangeRefsIfUnique(string const & from, string const & to);
209         /// FIXME
210         bool ChangeCitationsIfUnique(string const & from, string const & to);
211
212         /// get the contents of the window system clipboard
213         string const getClipboard() const;
214         /// fill the window system clipboard
215         void stuffClipboard(string const &) const;
216         /// tell the window system we have a selection
217         void haveSelection(bool sel);
218
219         /// execute the given function
220         bool dispatch(FuncRequest const & argument);
221
222 private:
223         /// Set the current locking inset
224         void theLockingInset(UpdatableInset * inset);
225
226         /// return the lyxtext containing this inset
227         LyXText * getParentText(Inset * inset) const;
228
229         /**
230          * Change all insets with the given code's contents to a new
231          * string. May only be used with InsetCommand-derived insets
232          * Returns true if a screen update is needed.
233          */
234         bool ChangeInsets(Inset::Code code, string const & from,
235                           string const & to);
236
237
238         struct Pimpl;
239         friend struct BufferView::Pimpl;
240
241         Pimpl * pimpl_;
242 };
243
244
245 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
246                                   BufferView::UpdateCodes uc2);
247
248 #endif // BUFFERVIEW_H