]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
some renaming + safety stuff
[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 PosIterator;
36 class Selection;
37 class TeXErrors;
38 class UpdatableInset;
39
40
41 // The structure that keeps track of the selections set.
42 struct Selection {
43         Selection()
44                 : set_(false), mark_(false)
45                 {}
46         bool set() const {
47                 return set_;
48         }
49         void set(bool s) {
50                 set_ = s;
51         }
52         bool mark() const {
53                 return mark_;
54         }
55         void mark(bool m) {
56                 mark_ = m;
57         }
58 private:
59         bool set_; // former selection
60         bool mark_; // former mark_set
61 };
62
63 /**
64  * A buffer view encapsulates a view onto a particular
65  * buffer, and allows access to operate upon it. A view
66  * is a sliding window of the entire document rendering.
67  *
68  * Eventually we will allow several views onto a single
69  * buffer, but not yet.
70  */
71 class BufferView : boost::noncopyable {
72 public:
73         /**
74          * Create a view with the given owner main window,
75          * of the given dimensions.
76          */
77         BufferView(LyXView * owner, int x, int y, int w, int h);
78
79         ~BufferView();
80
81         /// set the buffer we are viewing
82         void buffer(Buffer * b);
83         /// return the buffer being viewed
84         Buffer * buffer() const;
85
86         /// return the painter object for drawing onto the view
87         Painter & painter() const;
88         /// return the screen object for handling re-drawing
89         LyXScreen & screen() const;
90         /// return the owning main view
91         LyXView * owner() const;
92
93         /// return the visible top y
94         int top_y() const;
95
96         /// set the visible top y
97         void top_y(int);
98
99         /// resize event has happened
100         void resize();
101
102         /// reload the contained buffer
103         void reload();
104         /// create a new buffer based on template
105         bool newFile(std::string const & fname, std::string const & tname,
106                      bool named = true);
107         /// load a buffer into the view
108         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
109
110         /// fit the user cursor within the visible view
111         bool fitCursor();
112         /// perform pending painting updates
113         void update();
114         /// reset the scrollbar to reflect current view position
115         void updateScrollbar();
116         /// FIXME
117         void redoCurrentBuffer();
118
119         /// FIXME
120         bool available() const;
121
122         /// Save the current position as bookmark i
123         void savePosition(unsigned int i);
124         /// Restore the position from bookmark i
125         void restorePosition(unsigned int i);
126         /// does the given bookmark have a saved position ?
127         bool isSavedPosition(unsigned int i);
128
129         /// return the current change at the cursor
130         Change const getCurrentChange();
131
132         /// return the lyxtext we are using
133         LyXText * getLyXText() const;
134
135         /// update paragraph dialogs
136         void updateParagraphDialog();
137
138         /// return the current encoding at the cursor
139         Encoding const * getEncoding() const;
140
141         /// return the parent language of the given inset
142         Language const * getParentLanguage(InsetOld * inset) const;
143
144         /// replace the currently selected word
145         void replaceWord(std::string const & replacestring);
146         /// simple replacing. Use the font of the first selected character 
147         void replaceSelectionWithString(std::string const & str);
148
149         /// move cursor to the named label
150         void gotoLabel(std::string const & label);
151
152         /// undo last action
153         void undo();
154         /// redo last action
155         void redo();
156
157         /// get the stored error list
158         ErrorList const & getErrorList() const;
159         /// show the error list to the user
160         void showErrorList(std::string const &) const;
161         /// set the cursor based on the given TeX source row
162         void setCursorFromRow(int row);
163
164         /**
165          * Insert an inset into the buffer.
166          * Place it in a layout of lout,
167          */
168         bool insertInset(InsetOld * inset, std::string const & lout = std::string());
169
170         /// Inserts a lyx file at cursor position. return false if it fails
171         bool insertLyXFile(std::string const & file);
172
173         /// FIXME
174         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
175
176         /// hide the cursor if it is visible
177         void hideCursor();
178
179         /// center the document view around the cursor
180         void center();
181         /// scroll document by the given number of lines of default height
182         void scroll(int lines);
183         /// Scroll the view by a number of pixels
184         void scrollDocView(int);
185
186         /// return the pixel width of the document view
187         int workWidth() const;
188         /// return the pixel height of the document view
189         int workHeight() const;
190
191         /// switch between primary and secondary keymaps for RTL entry
192         void switchKeyMap();
193
194         /// FIXME
195         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
196
197         /// get the contents of the window system clipboard
198         std::string const getClipboard() const;
199         /// fill the window system clipboard
200         void stuffClipboard(std::string const &) const;
201         /// tell the window system we have a selection
202         void haveSelection(bool sel);
203
204         /// execute the given function
205         bool dispatch(FuncRequest const & argument);
206         
207         /// set target x position of cursor
208         void x_target(int x);
209         /// return target x position of cursor
210         int x_target() const;
211
212         /// clear the X selection
213         void unsetXSel();
214
215         /// access to full cursor
216         LCursor & fullCursor();
217         /// access to full cursor
218         void fullCursor(LCursor const &);
219         /// access to full cursor
220         LCursor const & fullCursor() const;
221         /// access to topmost cursor slice
222         CursorSlice & cursor();
223         /// access to topmost cursor slice
224         CursorSlice const & cursor() const;
225         /// access to selection anchor
226         CursorSlice & anchor();
227         /// access to selection anchor
228         CursorSlice const & anchor() const;
229         ///
230         UpdatableInset * innerInset() const;
231         ///
232         LyXText * text() const;
233         /// 
234         void resetAnchor();
235         ///
236         Selection & selection();
237         ///
238         Selection const & selection() const;
239         ///
240         CursorSlice & selStart();
241         ///
242         CursorSlice const & selStart() const;
243         ///
244         CursorSlice & selEnd();
245         ///
246         CursorSlice const & selEnd() const;
247         ///
248         void setSelection();
249         ///
250         void clearSelection();
251         ///
252         void putSelectionAt(PosIterator const & cur, int length, bool backwards);
253
254         ///
255         Selection selection_;
256
257 private:
258         ///
259         struct Pimpl;
260         ///
261         friend struct BufferView::Pimpl;
262         ///
263         Pimpl * pimpl_;
264
265         /**
266          * The target x position of the cursor. This is used for when
267          * we have text like :
268          *
269          * blah blah blah blah| blah blah blah
270          * blah blah blah
271          * blah blah blah blah blah blah
272          *
273          * When we move onto row 3, we would like to be vertically aligned
274          * with where we were in row 1, despite the fact that row 2 is
275          * shorter than x()
276          */
277         int x_target_;
278
279 };
280
281 #endif // BUFFERVIEW_H