]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
b2261ff69f638f0d131307924e0a8ce35c391662
[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
32 /**
33  * A buffer view encapsulates a view onto a particular
34  * buffer, and allows access to operate upon it. A view
35  * is a sliding window of the entire document rendering.
36  *
37  * Eventually we will allow several views onto a single
38  * buffer, but not yet.
39  */
40 class BufferView : boost::noncopyable {
41 public:
42         /**
43          * Codes to store necessary pending updates
44          * of the document rendering.
45          */
46         enum UpdateCodes {
47                 UPDATE = 0, //< FIXME
48                 SELECT = 1, //< selection change
49                 FITCUR = 2, //< the cursor needs fitting into the view
50                 CHANGE = 4  //< document data has changed
51         };
52
53         /**
54          * Create a view with the given owner main window,
55          * of the given dimensions.
56          */
57         BufferView(LyXView * owner, int x, int y, int w, int h);
58
59         ~BufferView();
60
61         /// set the buffer we are viewing
62         void buffer(Buffer * b);
63         /// return the buffer being viewed
64         Buffer * buffer() const;
65
66         /// return the painter object for drawing onto the view
67         Painter & painter() const;
68         /// return the screen object for handling re-drawing
69         LyXScreen & screen() const;
70         /// return the owning main view
71         LyXView * owner() const;
72
73         /// resize event has happened
74         void resize();
75         /**
76          * Repaint the pixmap. Used for when we don't want
77          * to go through the full update() logic, just a simple
78          * repaint of the whole screen.
79          */
80         void repaint();
81
82         /// fit the user cursor within the visible view
83         bool fitCursor();
84         /// perform pending painting updates
85         void update();
86         // update for a particular lyxtext
87         void update(LyXText *, UpdateCodes uc);
88         /// update for a particular inset
89         void updateInset(Inset * inset, bool mark_dirty);
90         /// reset the scrollbar to reflect current view position
91         void updateScrollbar();
92         /// FIXME
93         void redoCurrentBuffer();
94
95         /// FIXME
96         bool available() const;
97
98         /// FIXME
99         void beforeChange(LyXText *);
100
101         /// Save the current position as bookmark i
102         void savePosition(unsigned int i);
103         /// Restore the position from bookmark i
104         void restorePosition(unsigned int i);
105         /// does the given bookmark have a saved position ?
106         bool isSavedPosition(unsigned int i);
107  
108         /// return the current change at the cursor
109         Change const getCurrentChange();
110
111         /**
112          * This holds the mapping between buffer paragraphs and screen rows.
113          * This should be private...but not yet. (Lgb)
114          */
115         LyXText * text;
116         /// return the lyxtext we are using
117         LyXText * getLyXText() const;
118
119         /// Return the current inset we are "locked" in
120         UpdatableInset * theLockingInset() const;
121         /// lock the given inset FIXME: return value ?
122         bool lockInset(UpdatableInset * inset);
123         /// unlock the given inset
124         int unlockInset(UpdatableInset * inset);
125         /// unlock the currently locked inset
126         void insetUnlock();
127
128         /// return the current encoding at the cursor
129         Encoding const * getEncoding() const;
130
131         /// return the parent language of the given inset
132         Language const * getParentLanguage(Inset * inset) const;
133
134         /// Select the "current" word
135         void selectLastWord();
136         /// replace the currently selected word
137         void replaceWord(string const & replacestring);
138         /// Update after spellcheck finishes
139         void endOfSpellCheck();
140         /// return the next word
141         WordLangTuple const nextWord(float & value);
142
143         /// move cursor to the named label
144         bool gotoLabel(string const & label);
145
146         /// copy the environment type from current paragraph
147         void copyEnvironment();
148         /// set the current paragraph's environment type
149         void pasteEnvironment();
150
151         /// undo last action
152         void undo();
153         /// redo last action
154         void redo();
155
156         /// removes all autodeletable insets
157         bool removeAutoInsets();
158         /// insert all errors found when running latex
159         void insertErrors(TeXErrors & terr);
160         /// set the cursor based on the given TeX source row
161         void setCursorFromRow(int row);
162
163         /**
164          * Insert an inset into the buffer.
165          * Place it in a layout of lout,
166          */
167         bool insertInset(Inset * inset, string const & lout = string());
168
169         /// Inserts a lyx file at cursor position. return false if it fails
170         bool insertLyXFile(string const & file);
171
172         /// show the user cursor
173         void showCursor();
174         /// hide the user cursor
175         void hideCursor();
176         /// FIXME
177         void showLockedInsetCursor(int x, int y, int asc, int desc);
178         /// FIXME
179         void hideLockedInsetCursor();
180         /// FIXME
181         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
182         /// FIXME
183         void lockedInsetStoreUndo(Undo::undo_kind kind);
184         /// FIXME
185         void toggleSelection(bool = true);
186         /// FIXME: my word !
187         void toggleToggle();
188
189         /// center the document view around the cursor
190         void center();
191         /// scroll document by the given number of lines of default height
192         void scroll(int lines);
193         /// Scroll the view by a number of pixels
194         void scrollDocView(int);
195
196         /// return the pixel width of the document view
197         int workWidth() const;
198         /// return the pixel height of the document view
199         int workHeight() const;
200
201         /// switch between primary and secondary keymaps for RTL entry
202         void switchKeyMap();
203
204         /// FIXME
205         bool ChangeRefsIfUnique(string const & from, string const & to);
206         /// FIXME
207         bool ChangeCitationsIfUnique(string const & from, string const & to);
208
209         /// get the contents of the window system clipboard
210         string const getClipboard() const;
211         /// fill the window system clipboard
212         void stuffClipboard(string const &) const;
213         /// tell the window system we have a selection
214         void haveSelection(bool sel);
215
216         /// execute the given function
217         bool dispatch(FuncRequest const & argument);
218
219 private:
220         /// Set the current locking inset
221         void theLockingInset(UpdatableInset * inset);
222
223         /// return the lyxtext containing this inset
224         LyXText * getParentText(Inset * inset) const;
225
226         /**
227          * Change all insets with the given code's contents to a new
228          * string. May only be used with InsetCommand-derived insets
229          * Returns true if a screen update is needed.
230          */
231         bool ChangeInsets(Inset::Code code, string const & from,
232                           string const & to);
233
234
235         struct Pimpl;
236         friend struct BufferView::Pimpl;
237
238         Pimpl * pimpl_;
239 };
240
241
242 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
243                                   BufferView::UpdateCodes uc2);
244
245 #endif // BUFFERVIEW_H