]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
Fix natbib bug spotted by JMarc.
[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 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "LString.h"
18 #include "undo.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
36 /**
37  * A buffer view encapsulates a view onto a particular
38  * buffer, and allows access to operate upon it. A view
39  * is a sliding window of the entire document rendering.
40  *
41  * Eventually we will allow several views onto a single
42  * buffer, but not yet.
43  */
44 class BufferView : boost::noncopyable {
45 public:
46         /**
47          * Codes to store necessary pending updates
48          * of the document rendering.
49          */
50         enum UpdateCodes {
51                 UPDATE = 0, //< FIXME
52                 SELECT = 1, //< selection change
53                 FITCUR = 2, //< the cursor needs fitting into the view
54                 CHANGE = 4  //< document data has changed
55         };
56
57         /**
58          * Create a view with the given owner main window,
59          * of the given dimensions.
60          */
61         BufferView(LyXView * owner, int x, int y, int w, int h);
62
63         ~BufferView();
64
65         /// set the buffer we are viewing
66         void buffer(Buffer * b);
67         /// return the buffer being viewed
68         Buffer * buffer() const;
69
70         /// return the painter object for drawing onto the view
71         Painter & painter() const;
72         /// return the screen object for handling re-drawing
73         LyXScreen & screen() const;
74         /// return the owning main view
75         LyXView * owner() const;
76
77         /// resize event has happened
78         void resize();
79         /**
80          * Repaint the pixmap. Used for when we don't want
81          * to go through the full update() logic, just a simple
82          * repaint of the whole screen.
83          */
84         void repaint();
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 a particular inset
93         void updateInset(Inset * inset, bool mark_dirty);
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(Inset * inset) const;
137
138         /// Select the "current" word
139         void selectLastWord();
140         /// replace the currently selected word
141         void replaceWord(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         bool gotoLabel(string const & label);
149
150         /// copy the environment type from current paragraph
151         void copyEnvironment();
152         /// set the current paragraph's environment type
153         void pasteEnvironment();
154
155         /// undo last action
156         void undo();
157         /// redo last action
158         void redo();
159
160         /// removes all autodeletable insets
161         bool removeAutoInsets();
162         /// insert all errors found when running latex
163         void insertErrors(TeXErrors & terr);
164         /// set the cursor based on the given TeX source row
165         void setCursorFromRow(int row);
166
167         /**
168          * Insert an inset into the buffer.
169          * Place it in a layout of lout,
170          */
171         bool insertInset(Inset * inset, string const & lout = string());
172
173         /// Inserts a lyx file at cursor position. return false if it fails
174         bool insertLyXFile(string const & file);
175
176         /// show the user cursor
177         void showCursor();
178         /// hide the user cursor
179         void hideCursor();
180         /// FIXME
181         void showLockedInsetCursor(int x, int y, int asc, int desc);
182         /// FIXME
183         void hideLockedInsetCursor();
184         /// FIXME
185         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
186         /// FIXME
187         void lockedInsetStoreUndo(Undo::undo_kind kind);
188         /// FIXME
189         void toggleSelection(bool = true);
190         /// FIXME: my word !
191         void toggleToggle();
192
193         /// center the document view around the cursor
194         void center();
195         /// scroll document by the given number of lines of default height
196         void scroll(int lines);
197         /// Scroll the view by a number of pixels
198         void scrollDocView(int);
199
200         /// height of a normal line in pixels (zoom factor considered)
201         int defaultHeight() const;
202         /// return the pixel width of the document view
203         int workWidth() const;
204         /// return the pixel height of the document view
205         int workHeight() const;
206
207         /// switch between primary and secondary keymaps for RTL entry
208         void switchKeyMap();
209
210         /// FIXME
211         bool ChangeRefsIfUnique(string const & from, string const & to);
212         /// FIXME
213         bool ChangeCitationsIfUnique(string const & from, string const & to);
214
215         /// get the contents of the window system clipboard
216         string const getClipboard() const;
217         /// fill the window system clipboard
218         void stuffClipboard(string const &) const;
219         /// tell the window system we have a selection
220         void haveSelection(bool sel);
221
222         /// execute the given function
223         bool dispatch(FuncRequest const & argument);
224
225 private:
226         /// Set the current locking inset
227         void theLockingInset(UpdatableInset * inset);
228
229         /// return the lyxtext containing this inset
230         LyXText * getParentText(Inset * inset) const;
231
232         /**
233          * Change all insets with the given code's contents to a new
234          * string. May only be used with InsetCommand-derived insets
235          * Returns true if a screen update is needed.
236          */
237         bool ChangeInsets(Inset::Code code, string const & from,
238                           string const & to);
239
240
241         struct Pimpl;
242         friend struct BufferView::Pimpl;
243
244         Pimpl * pimpl_;
245 };
246
247
248 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
249                                   BufferView::UpdateCodes uc2);
250
251 #endif // BUFFERVIEW_H