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