]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
d3ec1cb83351a6d304d8d27be12939a979897466
[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 class Buffer;
23 class Change;
24 class Encoding;
25 class ErrorList;
26 class FuncRequest;
27 class InsetOld;
28 class Language;
29 class LCursor;
30 class LyXText;
31 class LyXScreen;
32 class LyXView;
33 class Painter;
34 class TeXErrors;
35 class UpdatableInset;
36
37
38 /**
39  * A buffer view encapsulates a view onto a particular
40  * buffer, and allows access to operate upon it. A view
41  * is a sliding window of the entire document rendering.
42  *
43  * Eventually we will allow several views onto a single
44  * buffer, but not yet.
45  */
46 class BufferView : boost::noncopyable {
47 public:
48         /**
49          * Create a view with the given owner main window,
50          * of the given dimensions.
51          */
52         BufferView(LyXView * owner, int x, int y, int w, int h);
53
54         ~BufferView();
55
56         /// set the buffer we are viewing
57         void buffer(Buffer * b);
58         /// return the buffer being viewed
59         Buffer * buffer() const;
60
61         /// return the painter object for drawing onto the view
62         Painter & painter() const;
63         /// return the screen object for handling re-drawing
64         LyXScreen & screen() const;
65         /// return the owning main view
66         LyXView * owner() const;
67
68         /// return the visible top y
69         int top_y() const;
70
71         /// set the visible top y
72         void top_y(int);
73
74         /// resize event has happened
75         void resize();
76
77         /// reload the contained buffer
78         void reload();
79         /// create a new buffer based on template
80         bool newFile(std::string const & fname, std::string const & tname,
81                      bool named = true);
82         /// load a buffer into the view
83         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
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 inset. Gets a pointer and not a
90          *  reference because we really need the pointer information
91          *  to find it in the buffer.
92    *
93          * Extracted from Matthias notes:
94          *
95          * If a inset wishes any redraw and/or update it just has to call
96          * updateInset(this). It's is completly irrelevant, where the inset is.
97    * UpdateInset will find it in any paragraph in any buffer.
98          * Of course the insets in the current paragraph/buffer
99          * are checked first, so no performance problem should occur.
100          */
101         void updateInset(InsetOld const *);
102         /// reset the scrollbar to reflect current view position
103         void updateScrollbar();
104         /// FIXME
105         void redoCurrentBuffer();
106
107         /// FIXME
108         bool available() const;
109
110         /// Save the current position as bookmark i
111         void savePosition(unsigned int i);
112         /// Restore the position from bookmark i
113         void restorePosition(unsigned int i);
114         /// does the given bookmark have a saved position ?
115         bool isSavedPosition(unsigned int i);
116
117         /// return the current change at the cursor
118         Change const getCurrentChange();
119
120         /**
121          * This holds the mapping between buffer paragraphs and screen rows.
122          * This should be private...but not yet. (Lgb)
123          */
124         LyXText * text;
125         /// return the lyxtext we are using
126         LyXText * getLyXText() const;
127
128         /// update paragraph dialogs
129         void updateParagraphDialog();
130
131         /// return the current encoding at the cursor
132         Encoding const * getEncoding() const;
133
134         /// return the parent language of the given inset
135         Language const * getParentLanguage(InsetOld * inset) const;
136
137         /// replace the currently selected word
138         void replaceWord(std::string const & replacestring);
139
140         /// move cursor to the named label
141         void gotoLabel(std::string const & label);
142
143         /// undo last action
144         void undo();
145         /// redo last action
146         void redo();
147
148         /// get the stored error list
149         ErrorList const & getErrorList() const;
150         /// show the error list to the user
151         void showErrorList(std::string const &) const;
152         /// set the cursor based on the given TeX source row
153         void setCursorFromRow(int row);
154
155         /**
156          * Insert an inset into the buffer.
157          * Place it in a layout of lout,
158          */
159         bool insertInset(InsetOld * inset, std::string const & lout = std::string());
160
161         /// Inserts a lyx file at cursor position. return false if it fails
162         bool insertLyXFile(std::string const & file);
163
164         /// FIXME
165         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
166
167         /// hide the cursor if it is visible
168         void hideCursor();
169
170         /// center the document view around the cursor
171         void center();
172         /// scroll document by the given number of lines of default height
173         void scroll(int lines);
174         /// Scroll the view by a number of pixels
175         void scrollDocView(int);
176
177         /// return the pixel width of the document view
178         int workWidth() const;
179         /// return the pixel height of the document view
180         int workHeight() const;
181
182         /// switch between primary and secondary keymaps for RTL entry
183         void switchKeyMap();
184
185         /// FIXME
186         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
187
188         /// get the contents of the window system clipboard
189         std::string const getClipboard() const;
190         /// fill the window system clipboard
191         void stuffClipboard(std::string const &) const;
192         /// tell the window system we have a selection
193         void haveSelection(bool sel);
194
195         /// execute the given function
196         bool dispatch(FuncRequest const & argument);
197         
198         /// set target x position of cursor
199         void BufferView::x_target(int x);
200         /// return target x position of cursor
201         int BufferView::x_target() const;
202
203         /// access to cursor
204         LCursor & cursor();
205         /// access to cursor
206         LCursor const & cursor() const;
207         ///
208         UpdatableInset * innerInset() const;
209
210 private:
211         struct Pimpl;
212         friend struct BufferView::Pimpl;
213
214         Pimpl * pimpl_;
215
216         /**
217          * The target x position of the cursor. This is used for when
218          * we have text like :
219          *
220          * blah blah blah blah| blah blah blah
221          * blah blah blah
222          * blah blah blah blah blah blah
223          *
224          * When we move onto row 3, we would like to be vertically aligned
225          * with where we were in row 1, despite the fact that row 2 is
226          * shorter than x()
227          */
228         int x_target_;
229
230 };
231
232 #endif // BUFFERVIEW_H