]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
Move BufferView::ChangeInsets to the Pimpl. As a result, can remove
[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 "support/std_string.h"
21
22 class Buffer;
23 class Change;
24 class Encoding;
25 class ErrorList;
26 class FuncRequest;
27 class InsetOld;
28 class Language;
29 class LyXText;
30 class LyXScreen;
31 class LyXView;
32 class Painter;
33 class TeXErrors;
34 class UpdatableInset;
35 class WordLangTuple;
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         /// return the visible top y
68         int top_y() const;
69
70         /// set the visible top y
71         void top_y(int);
72
73         /// resize event has happened
74         void resize();
75
76         /// reload the contained buffer
77         void reload();
78         /// create a new buffer based on template
79         bool newFile(string const & fname, string const & tname,
80                      bool named = true);
81         /// load a buffer into the view
82         bool loadLyXFile(string const & name, bool tolastfiles = true);
83
84         /// fit the user cursor within the visible view
85         bool fitCursor();
86         /// perform pending painting updates
87         void update();
88         /** update for a particular inset. Gets a pointer and not a
89          *  reference because we really need the pointer information
90          *  to find it in the buffer.
91          */
92         void updateInset(InsetOld const *);
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         /// FIXME
102         void beforeChange(LyXText *);
103
104         /// Save the current position as bookmark i
105         void savePosition(unsigned int i);
106         /// Restore the position from bookmark i
107         void restorePosition(unsigned int i);
108         /// does the given bookmark have a saved position ?
109         bool isSavedPosition(unsigned int i);
110
111         /// return the current change at the cursor
112         Change const getCurrentChange();
113
114         /**
115          * This holds the mapping between buffer paragraphs and screen rows.
116          * This should be private...but not yet. (Lgb)
117          */
118         LyXText * text;
119         /// return the lyxtext we are using
120         LyXText * getLyXText() const;
121
122         /// Return the current inset we are "locked" in
123         UpdatableInset * theLockingInset() const;
124         /// lock the given inset FIXME: return value ?
125         bool lockInset(UpdatableInset * inset);
126         /// unlock the given inset
127         int unlockInset(UpdatableInset * inset);
128         /// unlock the currently locked inset
129         void insetUnlock();
130
131         /// return the current encoding at the cursor
132         Encoding const * getEncoding() const;
133
134         /// return the parent language of the given inset
135         Language const * getParentLanguage(InsetOld * inset) const;
136
137         /// Select the "current" word
138         void selectLastWord();
139         /// replace the currently selected word
140         void replaceWord(string const & replacestring);
141         /// Update after spellcheck finishes
142         void endOfSpellCheck();
143         /// return the next word
144         WordLangTuple const nextWord(float & value);
145
146         /// move cursor to the named label
147         void gotoLabel(string const & label);
148
149         /// undo last action
150         void undo();
151         /// redo last action
152         void redo();
153
154         /// get the stored error list
155         ErrorList const & getErrorList() const;
156         /// show the error list to the user
157         void showErrorList(string const &) const;
158         /// set the cursor based on the given TeX source row
159         void setCursorFromRow(int row);
160
161         /**
162          * Insert an inset into the buffer.
163          * Place it in a layout of lout,
164          */
165         bool insertInset(InsetOld * inset, string const & lout = string());
166
167         /// Inserts a lyx file at cursor position. return false if it fails
168         bool insertLyXFile(string const & file);
169
170         /// FIXME
171         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
172
173         /// hide the cursor if it is visible
174         void hideCursor();
175
176         /// center the document view around the cursor
177         void center();
178         /// scroll document by the given number of lines of default height
179         void scroll(int lines);
180         /// Scroll the view by a number of pixels
181         void scrollDocView(int);
182
183         /// return the pixel width of the document view
184         int workWidth() const;
185         /// return the pixel height of the document view
186         int workHeight() const;
187
188         /// switch between primary and secondary keymaps for RTL entry
189         void switchKeyMap();
190
191         /// FIXME
192         bool ChangeRefsIfUnique(string const & from, string const & to);
193
194         /// get the contents of the window system clipboard
195         string const getClipboard() const;
196         /// fill the window system clipboard
197         void stuffClipboard(string const &) const;
198         /// tell the window system we have a selection
199         void haveSelection(bool sel);
200
201         /// execute the given function
202         bool dispatch(FuncRequest const & argument);
203
204 private:
205         /// Set the current locking inset
206         void theLockingInset(UpdatableInset * inset);
207
208         struct Pimpl;
209         friend struct BufferView::Pimpl;
210
211         Pimpl * pimpl_;
212 };
213
214 #endif // BUFFERVIEW_H