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