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