]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
076361c14ea53f47b62b0a5758f014e581a101f3
[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 "LString.h"
19
20 #include "insets/inset.h"
21
22 #include <boost/utility.hpp>
23
24 class Change;
25 class LyXView;
26 class LyXText;
27 class TeXErrors;
28 class Buffer;
29 class LyXScreen;
30 class Language;
31 class Painter;
32 class UpdatableInset;
33 class WordLangTuple;
34 class Encoding;
35 class ErrorList;
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         /// resize event has happened
68         void resize();
69
70         /// reload the contained buffer
71         void reload();
72         /// create a new buffer based on template
73         bool newFile(string const & fname, string const & tname,
74                      bool named = true);
75         /// load a buffer into the view
76         bool loadLyXFile(string const & name, bool tolastfiles = true);
77
78         /// fit the user cursor within the visible view
79         bool fitCursor();
80         /// perform pending painting updates
81         void update();
82         /** update for a particular inset. Gets a pointer and not a
83          *  reference because we really need the pointer information
84          *  to find it in the buffer.
85          */
86         void updateInset(InsetOld const *);
87         /// reset the scrollbar to reflect current view position
88         void updateScrollbar();
89         /// FIXME
90         void redoCurrentBuffer();
91
92         /// FIXME
93         bool available() const;
94
95         /// FIXME
96         void beforeChange(LyXText *);
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         /**
109          * This holds the mapping between buffer paragraphs and screen rows.
110          * This should be private...but not yet. (Lgb)
111          */
112         LyXText * text;
113         /// return the lyxtext we are using
114         LyXText * getLyXText() const;
115
116         /// Return the current inset we are "locked" in
117         UpdatableInset * theLockingInset() const;
118         /// lock the given inset FIXME: return value ?
119         bool lockInset(UpdatableInset * inset);
120         /// unlock the given inset
121         int unlockInset(UpdatableInset * inset);
122         /// unlock the currently locked inset
123         void insetUnlock();
124
125         /// return the current encoding at the cursor
126         Encoding const * getEncoding() const;
127
128         /// return the parent language of the given inset
129         Language const * getParentLanguage(InsetOld * inset) const;
130
131         /// Select the "current" word
132         void selectLastWord();
133         /// replace the currently selected word
134         void replaceWord(string const & replacestring);
135         /// Update after spellcheck finishes
136         void endOfSpellCheck();
137         /// return the next word
138         WordLangTuple const nextWord(float & value);
139
140         /// move cursor to the named label
141         void gotoLabel(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(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, string const & lout = string());
160
161         /// Inserts a lyx file at cursor position. return false if it fails
162         bool insertLyXFile(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(string const & from, string const & to);
187
188         /// get the contents of the window system clipboard
189         string const getClipboard() const;
190         /// fill the window system clipboard
191         void stuffClipboard(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 private:
199         /// Set the current locking inset
200         void theLockingInset(UpdatableInset * inset);
201
202         /// return the lyxtext containing this inset
203         LyXText * getParentText(InsetOld * inset) const;
204
205         /**
206          * Change all insets with the given code's contents to a new
207          * string. May only be used with InsetCommand-derived insets
208          * Returns true if a screen update is needed.
209          */
210         bool ChangeInsets(InsetOld::Code code, string const & from,
211                           string const & to);
212
213
214         struct Pimpl;
215         friend struct BufferView::Pimpl;
216
217         Pimpl * pimpl_;
218 };
219
220 #endif // BUFFERVIEW_H