]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
ws changes only
[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 class WordLangTuple;
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         /** update for a particular inset. Gets a pointer and not a
90          *  reference because we really need the pointer information
91          *  to find it in the buffer.
92          */
93         void updateInset(InsetOld const *);
94         /// reset the scrollbar to reflect current view position
95         void updateScrollbar();
96         /// FIXME
97         void redoCurrentBuffer();
98
99         /// FIXME
100         bool available() const;
101
102         /// FIXME
103         void beforeChange(LyXText *);
104
105         /// Save the current position as bookmark i
106         void savePosition(unsigned int i);
107         /// Restore the position from bookmark i
108         void restorePosition(unsigned int i);
109         /// does the given bookmark have a saved position ?
110         bool isSavedPosition(unsigned int i);
111
112         /// return the current change at the cursor
113         Change const getCurrentChange();
114
115         /**
116          * This holds the mapping between buffer paragraphs and screen rows.
117          * This should be private...but not yet. (Lgb)
118          */
119         LyXText * text;
120         /// return the lyxtext we are using
121         LyXText * getLyXText() const;
122
123         /// Return the current inset we are "locked" in
124         UpdatableInset * theLockingInset() const;
125         /// lock the given inset FIXME: return value ?
126         bool lockInset(UpdatableInset * inset);
127         /// unlock the given inset
128         int unlockInset(UpdatableInset * inset);
129         /// unlock the currently locked inset
130         void insetUnlock();
131
132         /// return the current encoding at the cursor
133         Encoding const * getEncoding() const;
134
135         /// return the parent language of the given inset
136         Language const * getParentLanguage(InsetOld * inset) const;
137
138         /// Select the "current" word
139         void selectLastWord();
140         /// replace the currently selected word
141         void replaceWord(std::string const & replacestring);
142         /// Update after spellcheck finishes
143         void endOfSpellCheck();
144         /// return the next word
145         WordLangTuple const nextWord(float & value);
146
147         /// move cursor to the named label
148         void gotoLabel(std::string const & label);
149
150         /// undo last action
151         void undo();
152         /// redo last action
153         void redo();
154
155         /// get the stored error list
156         ErrorList const & getErrorList() const;
157         /// show the error list to the user
158         void showErrorList(std::string const &) const;
159         /// set the cursor based on the given TeX source row
160         void setCursorFromRow(int row);
161
162         /**
163          * Insert an inset into the buffer.
164          * Place it in a layout of lout,
165          */
166         bool insertInset(InsetOld * inset, std::string const & lout = std::string());
167
168         /// Inserts a lyx file at cursor position. return false if it fails
169         bool insertLyXFile(std::string const & file);
170
171         /// FIXME
172         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
173
174         /// hide the cursor if it is visible
175         void hideCursor();
176
177         /// center the document view around the cursor
178         void center();
179         /// scroll document by the given number of lines of default height
180         void scroll(int lines);
181         /// Scroll the view by a number of pixels
182         void scrollDocView(int);
183
184         /// return the pixel width of the document view
185         int workWidth() const;
186         /// return the pixel height of the document view
187         int workHeight() const;
188
189         /// switch between primary and secondary keymaps for RTL entry
190         void switchKeyMap();
191
192         /// FIXME
193         bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
194
195         /// get the contents of the window system clipboard
196         std::string const getClipboard() const;
197         /// fill the window system clipboard
198         void stuffClipboard(std::string const &) const;
199         /// tell the window system we have a selection
200         void haveSelection(bool sel);
201
202         /// execute the given function
203         bool dispatch(FuncRequest const & argument);
204
205 private:
206         /// Set the current locking inset
207         void theLockingInset(UpdatableInset * inset);
208
209         struct Pimpl;
210         friend struct BufferView::Pimpl;
211
212         Pimpl * pimpl_;
213 };
214
215 #endif // BUFFERVIEW_H