]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
f304f07f098274ef0f1d702b6d6c906a199c4019
[lyx.git] / src / BufferView.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alfredo Braustein
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFER_VIEW_H
16 #define BUFFER_VIEW_H
17
18 #include <boost/utility.hpp>
19
20 #include <string>
21
22
23 class Buffer;
24 class Change;
25 class Encoding;
26 class ErrorList;
27 class FuncRequest;
28 class InsetOld;
29 class Language;
30 class LCursor;
31 class LyXText;
32 class LyXScreen;
33 class LyXView;
34 class Painter;
35 class TeXErrors;
36 class UpdatableInset;
37
38
39 /**
40  * A buffer view encapsulates a view onto a particular
41  * buffer, and allows access to operate upon it. A view
42  * is a sliding window of the entire document rendering.
43  *
44  * Eventually we will allow several views onto a single
45  * buffer, but not yet.
46  */
47 class BufferView : boost::noncopyable {
48 public:
49         /**
50          * Create a view with the given owner main window,
51          * of the given dimensions.
52          */
53         BufferView(LyXView * owner, int x, int y, int w, int h);
54
55         ~BufferView();
56
57         /// set the buffer we are viewing
58         void buffer(Buffer * b);
59         /// return the buffer being viewed
60         Buffer * buffer() const;
61
62         /// return the painter object for drawing onto the view
63         Painter & painter() const;
64         /// return the screen object for handling re-drawing
65         LyXScreen & screen() const;
66         /// return the owning main view
67         LyXView * owner() const;
68
69         /// return the visible top y
70         int top_y() const;
71
72         /// set the visible top y
73         void top_y(int);
74
75         /// resize event has happened
76         void resize();
77
78         /// reload the contained buffer
79         void reload();
80         /// create a new buffer based on template
81         bool newFile(std::string const & fname, std::string const & tname,
82                      bool named = true);
83         /// load a buffer into the view
84         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
85
86         /// fit the user cursor within the visible view
87         bool fitCursor();
88         /// perform pending painting updates
89         void update();
90         /** update for a particular inset. Gets a pointer and not a
91          *  reference because we really need the pointer information
92          *  to find it in the buffer.
93          */
94         void updateInset(InsetOld const *);
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(InsetOld * inset) const;
138
139         /// replace the currently selected word
140         void replaceWord(std::string const & replacestring);
141
142         /// move cursor to the named label
143         void gotoLabel(std::string const & label);
144
145         /// undo last action
146         void undo();
147         /// redo last action
148         void redo();
149
150         /// get the stored error list
151         ErrorList const & getErrorList() const;
152         /// show the error list to the user
153         void showErrorList(std::string const &) const;
154         /// set the cursor based on the given TeX source row
155         void setCursorFromRow(int row);
156
157         /**
158          * Insert an inset into the buffer.
159          * Place it in a layout of lout,
160          */
161         bool insertInset(InsetOld * inset, std::string const & lout = std::string());
162
163         /// Inserts a lyx file at cursor position. return false if it fails
164         bool insertLyXFile(std::string const & file);
165
166         /// FIXME
167         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
168
169         /// hide the cursor if it is visible
170         void hideCursor();
171
172         /// center the document view around the cursor
173         void center();
174         /// scroll document by the given number of lines of default height
175         void scroll(int lines);
176         /// Scroll the view by a number of pixels
177         void scrollDocView(int);
178
179         /// return the pixel width of the document view
180         int workWidth() const;
181         /// return the pixel height of the document view
182         int workHeight() const;
183
184         /// switch between primary and secondary keymaps for RTL entry
185         void switchKeyMap();
186
187         /// FIXME
188         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
189
190         /// get the contents of the window system clipboard
191         std::string const getClipboard() const;
192         /// fill the window system clipboard
193         void stuffClipboard(std::string const &) const;
194         /// tell the window system we have a selection
195         void haveSelection(bool sel);
196
197         /// execute the given function
198         bool dispatch(FuncRequest const & argument);
199         
200         /// set target x position of cursor
201         void BufferView::x_target(int x);
202         /// return target x position of cursor
203         int BufferView::x_target() const;
204
205         /// access to cursor
206         LCursor & cursor();
207         /// access to cursor
208         LCursor const & cursor() const;
209
210 private:
211         /// Set the current locking inset
212         void theLockingInset(UpdatableInset * inset);
213
214         struct Pimpl;
215         friend struct BufferView::Pimpl;
216
217         Pimpl * pimpl_;
218
219         /**
220          * The target x position of the cursor. This is used for when
221          * we have text like :
222          *
223          * blah blah blah blah| blah blah blah
224          * blah blah blah
225          * blah blah blah blah blah blah
226          *
227          * When we move onto row 3, we would like to be vertically aligned
228          * with where we were in row 1, despite the fact that row 2 is
229          * shorter than x()
230          */
231         int x_target_;
232
233 };
234
235 #endif // BUFFERVIEW_H