]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
Alfredo's second patch
[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         void gotoLabel(string const & label);
148
149         /// undo last action
150         void undo();
151         /// redo last action
152         void redo();
153
154         /// removes all autodeletable insets
155         bool removeAutoInsets();
156         /// insert all errors found when running latex
157         void insertErrors(TeXErrors & terr);
158         /// set the cursor based on the given TeX source row
159         void setCursorFromRow(int row);
160
161         /**
162          * Insert an inset into the buffer.
163          * Place it in a layout of lout,
164          */
165         bool insertInset(Inset * inset, string const & lout = string());
166
167         /// Inserts a lyx file at cursor position. return false if it fails
168         bool insertLyXFile(string const & file);
169
170         /// show the user cursor
171         void showCursor();
172         /// hide the user cursor
173         void hideCursor();
174         /// FIXME
175         void showLockedInsetCursor(int x, int y, int asc, int desc);
176         /// FIXME
177         void hideLockedInsetCursor();
178         /// FIXME
179         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
180         /// FIXME
181         void lockedInsetStoreUndo(Undo::undo_kind kind);
182         /// FIXME
183         void toggleSelection(bool = true);
184         /// FIXME: my word !
185         void toggleToggle();
186
187         /// center the document view around the cursor
188         void center();
189         /// scroll document by the given number of lines of default height
190         void scroll(int lines);
191         /// Scroll the view by a number of pixels
192         void scrollDocView(int);
193
194         /// return the pixel width of the document view
195         int workWidth() const;
196         /// return the pixel height of the document view
197         int workHeight() const;
198
199         /// switch between primary and secondary keymaps for RTL entry
200         void switchKeyMap();
201
202         /// FIXME
203         bool ChangeRefsIfUnique(string const & from, string const & to);
204         /// FIXME
205         bool ChangeCitationsIfUnique(string const & from, string const & to);
206
207         /// get the contents of the window system clipboard
208         string const getClipboard() const;
209         /// fill the window system clipboard
210         void stuffClipboard(string const &) const;
211         /// tell the window system we have a selection
212         void haveSelection(bool sel);
213
214         /// execute the given function
215         bool dispatch(FuncRequest const & argument);
216
217 private:
218         /// Set the current locking inset
219         void theLockingInset(UpdatableInset * inset);
220
221         /// return the lyxtext containing this inset
222         LyXText * getParentText(Inset * inset) const;
223
224         /**
225          * Change all insets with the given code's contents to a new
226          * string. May only be used with InsetCommand-derived insets
227          * Returns true if a screen update is needed.
228          */
229         bool ChangeInsets(Inset::Code code, string const & from,
230                           string const & to);
231
232
233         struct Pimpl;
234         friend struct BufferView::Pimpl;
235
236         Pimpl * pimpl_;
237 };
238
239
240 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
241                                   BufferView::UpdateCodes uc2);
242
243 #endif // BUFFERVIEW_H