]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
b047df3904a4c7a559a6647208097d2d5821c749
[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 "support/types.h"
19
20 #include <boost/utility.hpp>
21
22 #include <string>
23
24 class Buffer;
25 class Change;
26 class Encoding;
27 class ErrorList;
28 class FuncRequest;
29 class InsetBase;
30 class InsetOld;
31 class Language;
32 class LCursor;
33 class LyXText;
34 class LyXScreen;
35 class LyXView;
36 class Painter;
37 class ParIterator;
38 class PosIterator;
39 class TeXErrors;
40 class UpdatableInset;
41
42 /**
43  * A buffer view encapsulates a view onto a particular
44  * buffer, and allows access to operate upon it. A view
45  * is a sliding window of the entire document rendering.
46  *
47  * Eventually we will allow several views onto a single
48  * buffer, but not yet.
49  */
50 class BufferView : boost::noncopyable {
51 public:
52         /**
53          * Create a view with the given owner main window,
54          * of the given dimensions.
55          */
56         BufferView(LyXView * owner, int x, int y, int w, int h);
57
58         ~BufferView();
59
60         /// set the buffer we are viewing
61         void buffer(Buffer * b);
62         /// return the buffer being viewed
63         Buffer * buffer() const;
64
65         /// return the painter object for drawing onto the view
66         Painter & painter() const;
67         /// return the screen object for handling re-drawing
68         LyXScreen & screen() const;
69         /// return the owning main view
70         LyXView * owner() const;
71
72         /// return the visible top y
73         int top_y() const;
74
75         /// set the visible top y
76         void top_y(int);
77
78         /// resize event has happened
79         void resize();
80
81         /// reload the contained buffer
82         void reload();
83         /// create a new buffer based on template
84         bool newFile(std::string const & fname, std::string const & tname,
85                      bool named = true);
86         /// load a buffer into the view
87         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
88
89         /// fit the user cursor within the visible view
90         bool fitCursor();
91         /// perform pending painting updates
92         void update();
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         /// Save the current position as bookmark i
102         void savePosition(unsigned int i);
103         /// Restore the position from bookmark i
104         void restorePosition(unsigned int i);
105         /// does the given bookmark have a saved position ?
106         bool isSavedPosition(unsigned int i);
107
108         /// return the current change at the cursor
109         Change const getCurrentChange();
110
111         /// return the lyxtext we are using
112         LyXText * getLyXText() const;
113
114         /// update paragraph dialogs
115         void updateParagraphDialog();
116
117         /// return the current encoding at the cursor
118         Encoding const * getEncoding() const;
119
120         /// return the parent language of the given inset
121         Language const * getParentLanguage(InsetOld * inset) const;
122
123         /// replace the currently selected word
124         void replaceWord(std::string const & replacestring);
125         /// simple replacing. Use the font of the first selected character 
126         void replaceSelectionWithString(std::string const & str);
127
128         /// move cursor to the named label
129         void gotoLabel(std::string const & label);
130
131         /// undo last action
132         void undo();
133         /// redo last action
134         void redo();
135
136         /// get the stored error list
137         ErrorList const & getErrorList() const;
138         /// show the error list to the user
139         void showErrorList(std::string const &) const;
140         /// set the cursor based on the given TeX source row
141         void setCursorFromRow(int row);
142
143         /// Insert an inset into the buffer, in a layout of lout.
144         void insertInset(InsetBase * inset,
145                 std::string const & lout = std::string());
146
147         /// Inserts a lyx file at cursor position. return false if it fails
148         bool insertLyXFile(std::string const & file);
149
150         /// FIXME
151         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
152
153         /// hide the cursor if it is visible
154         void hideCursor();
155
156         /// center the document view around the cursor
157         void center();
158         /// scroll document by the given number of lines of default height
159         void scroll(int lines);
160         /// Scroll the view by a number of pixels
161         void scrollDocView(int);
162
163         /// return the pixel width of the document view
164         int workWidth() const;
165         /// return the pixel height of the document view
166         int workHeight() const;
167
168         /// switch between primary and secondary keymaps for RTL entry
169         void switchKeyMap();
170
171         /// FIXME
172         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
173
174         /// get the contents of the window system clipboard
175         std::string const getClipboard() const;
176         /// fill the window system clipboard
177         void stuffClipboard(std::string const &) const;
178         /// tell the window system we have a selection
179         void haveSelection(bool sel);
180
181         /// execute the given function
182         bool dispatch(FuncRequest const & argument);
183         
184         /// clear the X selection
185         void unsetXSel();
186
187         /// access to full cursor
188         LCursor & cursor();
189         /// access to full cursor
190         LCursor const & cursor() const;
191         ///
192         LyXText * text() const;
193         ///
194         void setCursor(ParIterator const & par, lyx::pos_type pos);
195         ///
196         void putSelectionAt(PosIterator const & cur, int length, bool backwards);
197
198 private:
199         ///
200         struct Pimpl;
201         ///
202         friend struct BufferView::Pimpl;
203         ///
204         Pimpl * pimpl_;
205 };
206
207 #endif // BUFFERVIEW_H