]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
better lib building
[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         /// FIXME
171         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
172         /// FIXME
173         void lockedInsetStoreUndo(Undo::undo_kind kind);
174         /// FIXME
175         void toggleSelection(bool = true);
176         /// FIXME: my word !
177         void toggleToggle();
178
179         /// hide the cursor if it is visible
180         void hideCursor();
181
182         /// center the document view around the cursor
183         void center();
184         /// scroll document by the given number of lines of default height
185         void scroll(int lines);
186         /// Scroll the view by a number of pixels
187         void scrollDocView(int);
188
189         /// return the pixel width of the document view
190         int workWidth() const;
191         /// return the pixel height of the document view
192         int workHeight() const;
193
194         /// switch between primary and secondary keymaps for RTL entry
195         void switchKeyMap();
196
197         /// FIXME
198         bool ChangeRefsIfUnique(string const & from, string const & to);
199         /// FIXME
200         bool ChangeCitationsIfUnique(string const & from, string const & to);
201
202         /// get the contents of the window system clipboard
203         string const getClipboard() const;
204         /// fill the window system clipboard
205         void stuffClipboard(string const &) const;
206         /// tell the window system we have a selection
207         void haveSelection(bool sel);
208
209         /// execute the given function
210         bool dispatch(FuncRequest const & argument);
211
212 private:
213         /// Set the current locking inset
214         void theLockingInset(UpdatableInset * inset);
215
216         /// return the lyxtext containing this inset
217         LyXText * getParentText(Inset * inset) const;
218
219         /**
220          * Change all insets with the given code's contents to a new
221          * string. May only be used with InsetCommand-derived insets
222          * Returns true if a screen update is needed.
223          */
224         bool ChangeInsets(Inset::Code code, string const & from,
225                           string const & to);
226
227
228         struct Pimpl;
229         friend struct BufferView::Pimpl;
230
231         Pimpl * pimpl_;
232 };
233
234
235 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
236                                   BufferView::UpdateCodes uc2);
237
238 #endif // BUFFERVIEW_H