]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
34b9b25cba5609e2a2b5ea1a212719e96cb98b0b
[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 LyXText;
31 class LyXScreen;
32 class LyXView;
33 class Painter;
34 class TeXErrors;
35 class UpdatableInset;
36
37 /**
38  * A buffer view encapsulates a view onto a particular
39  * buffer, and allows access to operate upon it. A view
40  * is a sliding window of the entire document rendering.
41  *
42  * Eventually we will allow several views onto a single
43  * buffer, but not yet.
44  */
45 class BufferView : boost::noncopyable {
46 public:
47         /**
48          * Create a view with the given owner main window,
49          * of the given dimensions.
50          */
51         BufferView(LyXView * owner, int x, int y, int w, int h);
52
53         ~BufferView();
54
55         /// set the buffer we are viewing
56         void buffer(Buffer * b);
57         /// return the buffer being viewed
58         Buffer * buffer() const;
59
60         /// return the painter object for drawing onto the view
61         Painter & painter() const;
62         /// return the screen object for handling re-drawing
63         LyXScreen & screen() const;
64         /// return the owning main view
65         LyXView * owner() const;
66
67         /// return the visible top y
68         int top_y() const;
69
70         /// set the visible top y
71         void top_y(int);
72
73         /// resize event has happened
74         void resize();
75
76         /// reload the contained buffer
77         void reload();
78         /// create a new buffer based on template
79         bool newFile(std::string const & fname, std::string const & tname,
80                      bool named = true);
81         /// load a buffer into the view
82         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
83
84         /// fit the user cursor within the visible view
85         bool fitCursor();
86         /// perform pending painting updates
87         void update();
88         /** update for a particular inset. Gets a pointer and not a
89          *  reference because we really need the pointer information
90          *  to find it in the buffer.
91          */
92         void updateInset(InsetOld const *);
93         /// reset the scrollbar to reflect current view position
94         void updateScrollbar();
95         /// FIXME
96         void redoCurrentBuffer();
97
98         /// FIXME
99         bool available() const;
100
101         /// FIXME
102         void beforeChange(LyXText *);
103
104         /// Save the current position as bookmark i
105         void savePosition(unsigned int i);
106         /// Restore the position from bookmark i
107         void restorePosition(unsigned int i);
108         /// does the given bookmark have a saved position ?
109         bool isSavedPosition(unsigned int i);
110
111         /// return the current change at the cursor
112         Change const getCurrentChange();
113
114         /**
115          * This holds the mapping between buffer paragraphs and screen rows.
116          * This should be private...but not yet. (Lgb)
117          */
118         LyXText * text;
119         /// return the lyxtext we are using
120         LyXText * getLyXText() const;
121
122         /// Return the current inset we are "locked" in
123         UpdatableInset * theLockingInset() const;
124         /// lock the given inset FIXME: return value ?
125         bool lockInset(UpdatableInset * inset);
126         /// unlock the given inset
127         int unlockInset(UpdatableInset * inset);
128         /// unlock the currently locked inset
129         void insetUnlock();
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 private:
204         /// Set the current locking inset
205         void theLockingInset(UpdatableInset * inset);
206
207         struct Pimpl;
208         friend struct BufferView::Pimpl;
209
210         Pimpl * pimpl_;
211
212         /**
213          * The target x position of the cursor. This is used for when
214          * we have text like :
215          *
216          * blah blah blah blah| blah blah blah
217          * blah blah blah
218          * blah blah blah blah blah blah
219          *
220          * When we move onto row 3, we would like to be vertically aligned
221          * with where we were in row 1, despite the fact that row 2 is
222          * shorter than x()
223          */
224         int x_target_;
225
226 };
227
228 #endif // BUFFERVIEW_H