]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
8781866c5e76fea4a69fb82ec0473da769e77269
[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 CursorSlice;
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         /// reset the scrollbar to reflect current view position
91         void updateScrollbar();
92         /// FIXME
93         void redoCurrentBuffer();
94
95         /// FIXME
96         bool available() const;
97
98         /// Save the current position as bookmark i
99         void savePosition(unsigned int i);
100         /// Restore the position from bookmark i
101         void restorePosition(unsigned int i);
102         /// does the given bookmark have a saved position ?
103         bool isSavedPosition(unsigned int i);
104
105         /// return the current change at the cursor
106         Change const getCurrentChange();
107
108         /// return the lyxtext we are using
109         LyXText * getLyXText() const;
110
111         /// update paragraph dialogs
112         void updateParagraphDialog();
113
114         /// return the current encoding at the cursor
115         Encoding const * getEncoding() const;
116
117         /// return the parent language of the given inset
118         Language const * getParentLanguage(InsetOld * inset) const;
119
120         /// replace the currently selected word
121         void replaceWord(std::string const & replacestring);
122
123         /// move cursor to the named label
124         void gotoLabel(std::string const & label);
125
126         /// undo last action
127         void undo();
128         /// redo last action
129         void redo();
130
131         /// get the stored error list
132         ErrorList const & getErrorList() const;
133         /// show the error list to the user
134         void showErrorList(std::string const &) const;
135         /// set the cursor based on the given TeX source row
136         void setCursorFromRow(int row);
137
138         /**
139          * Insert an inset into the buffer.
140          * Place it in a layout of lout,
141          */
142         bool insertInset(InsetOld * inset, std::string const & lout = std::string());
143
144         /// Inserts a lyx file at cursor position. return false if it fails
145         bool insertLyXFile(std::string const & file);
146
147         /// FIXME
148         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
149
150         /// hide the cursor if it is visible
151         void hideCursor();
152
153         /// center the document view around the cursor
154         void center();
155         /// scroll document by the given number of lines of default height
156         void scroll(int lines);
157         /// Scroll the view by a number of pixels
158         void scrollDocView(int);
159
160         /// return the pixel width of the document view
161         int workWidth() const;
162         /// return the pixel height of the document view
163         int workHeight() const;
164
165         /// switch between primary and secondary keymaps for RTL entry
166         void switchKeyMap();
167
168         /// FIXME
169         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
170
171         /// get the contents of the window system clipboard
172         std::string const getClipboard() const;
173         /// fill the window system clipboard
174         void stuffClipboard(std::string const &) const;
175         /// tell the window system we have a selection
176         void haveSelection(bool sel);
177
178         /// execute the given function
179         bool dispatch(FuncRequest const & argument);
180         
181         /// set target x position of cursor
182         void x_target(int x);
183         /// return target x position of cursor
184         int x_target() const;
185
186         /// clear the X selection
187         void unsetXSel();
188
189         /// access to full cursor
190         LCursor & fullCursor();
191         /// access to full cursor
192         void fullCursor(LCursor const &);
193         /// access to full cursor
194         LCursor const & fullCursor() const;
195         /// access to topmost cursor slice
196         CursorSlice & cursor();
197         /// access to topmost cursor slice
198         CursorSlice const & cursor() const;
199         /// access to selection anchor
200         CursorSlice & anchor();
201         /// access to selection anchor
202         CursorSlice const & anchor() const;
203         ///
204         UpdatableInset * innerInset() const;
205         ///
206         LyXText * text() const;
207         /// 
208         void resetAnchor();
209
210 private:
211         ///
212         struct Pimpl;
213         ///
214         friend struct BufferView::Pimpl;
215         ///
216         Pimpl * pimpl_;
217
218         /**
219          * The target x position of the cursor. This is used for when
220          * we have text like :
221          *
222          * blah blah blah blah| blah blah blah
223          * blah blah blah
224          * blah blah blah blah blah blah
225          *
226          * When we move onto row 3, we would like to be vertically aligned
227          * with where we were in row 1, despite the fact that row 2 is
228          * shorter than x()
229          */
230         int x_target_;
231
232 };
233
234 #endif // BUFFERVIEW_H