]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
d6beddec1a0e1b6e805c808811643a433d7597b4
[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 InsetBase;
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 TeXErrors;
37 class UpdatableInset;
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         /// simple replacing. Use the font of the first selected character 
123         void replaceSelectionWithString(std::string const & str);
124
125         /// move cursor to the named label
126         void gotoLabel(std::string const & label);
127
128         /// undo last action
129         void undo();
130         /// redo last action
131         void redo();
132
133         /// get the stored error list
134         ErrorList const & getErrorList() const;
135         /// show the error list to the user
136         void showErrorList(std::string const &) const;
137         /// set the cursor based on the given TeX source row
138         void setCursorFromRow(int row);
139
140         /**
141          * Insert an inset into the buffer.
142          * Place it in a layout of lout,
143          */
144         bool insertInset(InsetBase * inset, std::string const & lout = std::string());
145
146         /// Inserts a lyx file at cursor position. return false if it fails
147         bool insertLyXFile(std::string const & file);
148
149         /// FIXME
150         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
151
152         /// hide the cursor if it is visible
153         void hideCursor();
154
155         /// center the document view around the cursor
156         void center();
157         /// scroll document by the given number of lines of default height
158         void scroll(int lines);
159         /// Scroll the view by a number of pixels
160         void scrollDocView(int);
161
162         /// return the pixel width of the document view
163         int workWidth() const;
164         /// return the pixel height of the document view
165         int workHeight() const;
166
167         /// switch between primary and secondary keymaps for RTL entry
168         void switchKeyMap();
169
170         /// FIXME
171         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
172
173         /// get the contents of the window system clipboard
174         std::string const getClipboard() const;
175         /// fill the window system clipboard
176         void stuffClipboard(std::string const &) const;
177         /// tell the window system we have a selection
178         void haveSelection(bool sel);
179
180         /// execute the given function
181         bool dispatch(FuncRequest const & argument);
182         
183         /// clear the X selection
184         void unsetXSel();
185
186         /// access to full cursor
187         LCursor & cursor();
188         /// access to full cursor
189         LCursor const & cursor() const;
190         ///
191         LyXText * text() const;
192         ///
193         void putSelectionAt(PosIterator const & cur, int length, bool backwards);
194
195 private:
196         ///
197         struct Pimpl;
198         ///
199         friend struct BufferView::Pimpl;
200         ///
201         Pimpl * pimpl_;
202 };
203
204 #endif // BUFFERVIEW_H