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