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