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