]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
fix some C++ parsing bugs
[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, //< repaint
48                 SELECT = 1 //< reset selection to current cursor pos
49         };
50
51         /**
52          * Create a view with the given owner main window,
53          * of the given dimensions.
54          */
55         BufferView(LyXView * owner, int x, int y, int w, int h);
56
57         ~BufferView();
58
59         /// set the buffer we are viewing
60         void buffer(Buffer * b);
61         /// return the buffer being viewed
62         Buffer * buffer() const;
63
64         /// return the painter object for drawing onto the view
65         Painter & painter() const;
66         /// return the screen object for handling re-drawing
67         LyXScreen & screen() const;
68         /// return the owning main view
69         LyXView * owner() const;
70
71         /// resize event has happened
72         void resize();
73         /**
74          * Repaint the pixmap. Used for when we don't want
75          * to go through the full update() logic, just a simple
76          * repaint of the whole screen.
77          */
78         void repaint();
79
80         /// reload the contained buffer
81         void reload();
82
83         /// fit the user cursor within the visible view
84         bool fitCursor();
85         /// perform pending painting updates
86         void update();
87         // update for a particular lyxtext
88         void update(LyXText *, UpdateCodes uc);
89         /// update for the top-level lyxtext
90         void update(UpdateCodes uc);
91         /// update for a particular inset
92         void updateInset(Inset * inset);
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(Inset * 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         bool gotoLabel(string const & label);
148
149         /// copy the environment type from current paragraph
150         void copyEnvironment();
151         /// set the current paragraph's environment type
152         void pasteEnvironment();
153
154         /// undo last action
155         void undo();
156         /// redo last action
157         void redo();
158
159         /// removes all autodeletable insets
160         bool removeAutoInsets();
161         /// insert all errors found when running latex
162         void insertErrors(TeXErrors & terr);
163         /// set the cursor based on the given TeX source row
164         void setCursorFromRow(int row);
165
166         /**
167          * Insert an inset into the buffer.
168          * Place it in a layout of lout,
169          */
170         bool insertInset(Inset * inset, string const & lout = string());
171
172         /// Inserts a lyx file at cursor position. return false if it fails
173         bool insertLyXFile(string const & file);
174
175         /// show the user cursor
176         void showCursor();
177         /// hide the user cursor
178         void hideCursor();
179         /// FIXME
180         void showLockedInsetCursor(int x, int y, int asc, int desc);
181         /// FIXME
182         void hideLockedInsetCursor();
183         /// FIXME
184         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
185         /// FIXME
186         void lockedInsetStoreUndo(Undo::undo_kind kind);
187         /// FIXME
188         void toggleSelection(bool = true);
189         /// FIXME: my word !
190         void toggleToggle();
191
192         /// center the document view around the cursor
193         void center();
194         /// scroll document by the given number of lines of default height
195         void scroll(int lines);
196         /// Scroll the view by a number of pixels
197         void scrollDocView(int);
198
199         /// return the pixel width of the document view
200         int workWidth() const;
201         /// return the pixel height of the document view
202         int workHeight() const;
203
204         /// switch between primary and secondary keymaps for RTL entry
205         void switchKeyMap();
206
207         /// FIXME
208         bool ChangeRefsIfUnique(string const & from, string const & to);
209         /// FIXME
210         bool ChangeCitationsIfUnique(string const & from, string const & to);
211
212         /// get the contents of the window system clipboard
213         string const getClipboard() const;
214         /// fill the window system clipboard
215         void stuffClipboard(string const &) const;
216         /// tell the window system we have a selection
217         void haveSelection(bool sel);
218
219         /// execute the given function
220         bool dispatch(FuncRequest const & argument);
221
222 private:
223         /// Set the current locking inset
224         void theLockingInset(UpdatableInset * inset);
225
226         /// return the lyxtext containing this inset
227         LyXText * getParentText(Inset * inset) const;
228
229         /**
230          * Change all insets with the given code's contents to a new
231          * string. May only be used with InsetCommand-derived insets
232          * Returns true if a screen update is needed.
233          */
234         bool ChangeInsets(Inset::Code code, string const & from,
235                           string const & to);
236
237
238         struct Pimpl;
239         friend struct BufferView::Pimpl;
240
241         Pimpl * pimpl_;
242 };
243
244
245 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
246                                   BufferView::UpdateCodes uc2);
247
248 #endif // BUFFERVIEW_H