]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
move some selection related stuff over to textcursor.C
[lyx.git] / src / BufferView.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  *  \author Lars Gullik Bjønnes
8 */
9
10 #ifndef BUFFER_VIEW_H
11 #define BUFFER_VIEW_H
12
13 #include "LString.h"
14 #include "undo.h"
15
16 #include "insets/inset.h"
17
18 #include <boost/utility.hpp>
19
20 class Change;
21 class LyXView;
22 class LyXText;
23 class TeXErrors;
24 class Buffer;
25 class LyXScreen;
26 class Language;
27 class Painter;
28 class UpdatableInset;
29 class WordLangTuple;
30 class Encoding;
31 class ErrorList;
32
33 /**
34  * A buffer view encapsulates a view onto a particular
35  * buffer, and allows access to operate upon it. A view
36  * is a sliding window of the entire document rendering.
37  *
38  * Eventually we will allow several views onto a single
39  * buffer, but not yet.
40  */
41 class BufferView : boost::noncopyable {
42 public:
43         /**
44          * Codes to store necessary pending updates
45          * of the document rendering.
46          */
47         enum UpdateCodes {
48                 UPDATE = 0, //< repaint
49                 SELECT = 1 //< reset selection to current cursor pos
50         };
51
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         /// resize event has happened
73         void resize();
74         /**
75          * Repaint the pixmap. Used for when we don't want
76          * to go through the full update() logic, just a simple
77          * repaint of the whole screen.
78          */
79         void repaint();
80
81         /// reload the contained buffer
82         void reload();
83         /// load a buffer into the view
84         bool loadLyXFile(string const & name, bool tolastfiles = true);
85
86         /// fit the user cursor within the visible view
87         bool fitCursor();
88         /// perform pending painting updates
89         void update();
90         // update for a particular lyxtext
91         void update(LyXText *, UpdateCodes uc);
92         /// update for the top-level lyxtext
93         void update(UpdateCodes uc);
94         /// update for a particular inset
95         void updateInset(Inset * inset);
96         /// reset the scrollbar to reflect current view position
97         void updateScrollbar();
98         /// FIXME
99         void redoCurrentBuffer();
100
101         /// FIXME
102         bool available() const;
103
104         /// FIXME
105         void beforeChange(LyXText *);
106
107         /// Save the current position as bookmark i
108         void savePosition(unsigned int i);
109         /// Restore the position from bookmark i
110         void restorePosition(unsigned int i);
111         /// does the given bookmark have a saved position ?
112         bool isSavedPosition(unsigned int i);
113
114         /// return the current change at the cursor
115         Change const getCurrentChange();
116
117         /**
118          * This holds the mapping between buffer paragraphs and screen rows.
119          * This should be private...but not yet. (Lgb)
120          */
121         LyXText * text;
122         /// return the lyxtext we are using
123         LyXText * getLyXText() const;
124
125         /// Return the current inset we are "locked" in
126         UpdatableInset * theLockingInset() const;
127         /// lock the given inset FIXME: return value ?
128         bool lockInset(UpdatableInset * inset);
129         /// unlock the given inset
130         int unlockInset(UpdatableInset * inset);
131         /// unlock the currently locked inset
132         void insetUnlock();
133
134         /// return the current encoding at the cursor
135         Encoding const * getEncoding() const;
136
137         /// return the parent language of the given inset
138         Language const * getParentLanguage(Inset * inset) const;
139
140         /// Select the "current" word
141         void selectLastWord();
142         /// replace the currently selected word
143         void replaceWord(string const & replacestring);
144         /// Update after spellcheck finishes
145         void endOfSpellCheck();
146         /// return the next word
147         WordLangTuple const nextWord(float & value);
148
149         /// move cursor to the named label
150         void gotoLabel(string const & label);
151
152         /// undo last action
153         void undo();
154         /// redo last action
155         void redo();
156
157         /// get the stored error list
158         ErrorList const & getErrorList() const;
159         /// show the error list to the user
160         void showErrorList(string const &) const;
161         /// set the cursor based on the given TeX source row
162         void setCursorFromRow(int row);
163
164         /**
165          * Insert an inset into the buffer.
166          * Place it in a layout of lout,
167          */
168         bool insertInset(Inset * inset, string const & lout = string());
169
170         /// Inserts a lyx file at cursor position. return false if it fails
171         bool insertLyXFile(string const & file);
172
173         /// FIXME
174         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
175         /// FIXME
176         void lockedInsetStoreUndo(Undo::undo_kind kind);
177         /// FIXME
178         void toggleSelection(bool = true);
179         /// FIXME: my word !
180         void toggleToggle();
181
182         /// hide the cursor if it is visible
183         void hideCursor();
184
185         /// center the document view around the cursor
186         void center();
187         /// scroll document by the given number of lines of default height
188         void scroll(int lines);
189         /// Scroll the view by a number of pixels
190         void scrollDocView(int);
191
192         /// return the pixel width of the document view
193         int workWidth() const;
194         /// return the pixel height of the document view
195         int workHeight() const;
196
197         /// switch between primary and secondary keymaps for RTL entry
198         void switchKeyMap();
199
200         /// FIXME
201         bool ChangeRefsIfUnique(string const & from, string const & to);
202         /// FIXME
203         bool ChangeCitationsIfUnique(string const & from, string const & to);
204
205         /// get the contents of the window system clipboard
206         string const getClipboard() const;
207         /// fill the window system clipboard
208         void stuffClipboard(string const &) const;
209         /// tell the window system we have a selection
210         void haveSelection(bool sel);
211
212         /// execute the given function
213         bool dispatch(FuncRequest const & argument);
214
215 private:
216         /// Set the current locking inset
217         void theLockingInset(UpdatableInset * inset);
218
219         /// return the lyxtext containing this inset
220         LyXText * getParentText(Inset * inset) const;
221
222         /**
223          * Change all insets with the given code's contents to a new
224          * string. May only be used with InsetCommand-derived insets
225          * Returns true if a screen update is needed.
226          */
227         bool ChangeInsets(Inset::Code code, string const & from,
228                           string const & to);
229
230
231         struct Pimpl;
232         friend struct BufferView::Pimpl;
233
234         Pimpl * pimpl_;
235 };
236
237
238 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
239                                   BufferView::UpdateCodes uc2);
240
241 #endif // BUFFERVIEW_H