]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
f517a0893f4892c6f89e28acf766e0e66ebc7a05
[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
15 #include "insets/inset.h"
16
17 #include <boost/utility.hpp>
18
19 class Change;
20 class LyXView;
21 class LyXText;
22 class TeXErrors;
23 class Buffer;
24 class LyXScreen;
25 class Language;
26 class Painter;
27 class UpdatableInset;
28 class WordLangTuple;
29 class Encoding;
30 class ErrorList;
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         /// reload the contained buffer
75         void reload();
76         /// create a new buffer based on template
77         bool newFile(string const & fname, string const & tname,
78                      bool named = true);
79         /// load a buffer into the view
80         bool loadLyXFile(string const & name, bool tolastfiles = true);
81
82         /// fit the user cursor within the visible view
83         bool fitCursor();
84         /// perform pending painting updates
85         void update();
86         /// update for a particular inset
87         void updateInset(InsetOld * inset);
88         /// reset the scrollbar to reflect current view position
89         void updateScrollbar();
90         /// FIXME
91         void redoCurrentBuffer();
92
93         /// FIXME
94         bool available() const;
95
96         /// FIXME
97         void beforeChange(LyXText *);
98
99         /// Save the current position as bookmark i
100         void savePosition(unsigned int i);
101         /// Restore the position from bookmark i
102         void restorePosition(unsigned int i);
103         /// does the given bookmark have a saved position ?
104         bool isSavedPosition(unsigned int i);
105
106         /// return the current change at the cursor
107         Change const getCurrentChange();
108
109         /**
110          * This holds the mapping between buffer paragraphs and screen rows.
111          * This should be private...but not yet. (Lgb)
112          */
113         LyXText * text;
114         /// return the lyxtext we are using
115         LyXText * getLyXText() const;
116
117         /// Return the current inset we are "locked" in
118         UpdatableInset * theLockingInset() const;
119         /// lock the given inset FIXME: return value ?
120         bool lockInset(UpdatableInset * inset);
121         /// unlock the given inset
122         int unlockInset(UpdatableInset * inset);
123         /// unlock the currently locked inset
124         void insetUnlock();
125
126         /// return the current encoding at the cursor
127         Encoding const * getEncoding() const;
128
129         /// return the parent language of the given inset
130         Language const * getParentLanguage(InsetOld * inset) const;
131
132         /// Select the "current" word
133         void selectLastWord();
134         /// replace the currently selected word
135         void replaceWord(string const & replacestring);
136         /// Update after spellcheck finishes
137         void endOfSpellCheck();
138         /// return the next word
139         WordLangTuple const nextWord(float & value);
140
141         /// move cursor to the named label
142         void gotoLabel(string const & label);
143
144         /// undo last action
145         void undo();
146         /// redo last action
147         void redo();
148
149         /// get the stored error list
150         ErrorList const & getErrorList() const;
151         /// show the error list to the user
152         void showErrorList(string const &) const;
153         /// set the cursor based on the given TeX source row
154         void setCursorFromRow(int row);
155
156         /**
157          * Insert an inset into the buffer.
158          * Place it in a layout of lout,
159          */
160         bool insertInset(InsetOld * inset, string const & lout = string());
161
162         /// Inserts a lyx file at cursor position. return false if it fails
163         bool insertLyXFile(string const & file);
164
165         /// FIXME
166         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
167         /// FIXME
168         void toggleSelection(bool = true);
169
170         /// hide the cursor if it is visible
171         void hideCursor();
172
173         /// center the document view around the cursor
174         void center();
175         /// scroll document by the given number of lines of default height
176         void scroll(int lines);
177         /// Scroll the view by a number of pixels
178         void scrollDocView(int);
179
180         /// return the pixel width of the document view
181         int workWidth() const;
182         /// return the pixel height of the document view
183         int workHeight() const;
184
185         /// switch between primary and secondary keymaps for RTL entry
186         void switchKeyMap();
187
188         /// FIXME
189         bool ChangeRefsIfUnique(string const & from, string const & to);
190
191         /// get the contents of the window system clipboard
192         string const getClipboard() const;
193         /// fill the window system clipboard
194         void stuffClipboard(string const &) const;
195         /// tell the window system we have a selection
196         void haveSelection(bool sel);
197
198         /// execute the given function
199         bool dispatch(FuncRequest const & argument);
200
201 private:
202         /// Set the current locking inset
203         void theLockingInset(UpdatableInset * inset);
204
205         /// return the lyxtext containing this inset
206         LyXText * getParentText(InsetOld * inset) const;
207
208         /**
209          * Change all insets with the given code's contents to a new
210          * string. May only be used with InsetCommand-derived insets
211          * Returns true if a screen update is needed.
212          */
213         bool ChangeInsets(InsetOld::Code code, string const & from,
214                           string const & to);
215
216
217         struct Pimpl;
218         friend struct BufferView::Pimpl;
219
220         Pimpl * pimpl_;
221 };
222
223
224 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
225                                   BufferView::UpdateCodes uc2);
226
227 #endif // BUFFERVIEW_H