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