]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
Fix bug 2195: Slowness in rendering inside insets, especially on the Mac
[lyx.git] / src / BufferView.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alfredo Braustein
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFER_VIEW_H
16 #define BUFFER_VIEW_H
17
18 #include "support/types.h"
19
20 #include <boost/utility.hpp>
21
22 #include <string>
23
24 class Buffer;
25 class Change;
26 class DocIterator;
27 class ErrorList;
28 class FuncRequest;
29 class FuncStatus;
30 class Language;
31 class LCursor;
32 class LyXText;
33 class LyXScreen;
34 class LyXView;
35 class Painter;
36 class ParIterator;
37
38
39 namespace Update {
40         enum flags {
41                 FitCursor = 1,
42                 Force = 2,
43                 SinglePar = 4,
44                 MultiParSel = 8
45         };
46
47 inline flags operator|(flags const f, flags const g)
48 {
49         return static_cast<flags>(int(f) | int(g));
50 }
51
52 inline flags operator&(flags const f, flags const g)
53 {
54         return static_cast<flags>(int(f) & int(g));
55 }
56
57 } // namespace
58
59
60 /**
61  * A buffer view encapsulates a view onto a particular
62  * buffer, and allows access to operate upon it. A view
63  * is a sliding window of the entire document rendering.
64  *
65  * Eventually we will allow several views onto a single
66  * buffer, but not yet.
67  */
68 class BufferView : boost::noncopyable {
69 public:
70         /**
71          * Create a view with the given owner main window,
72          * of the given dimensions.
73          */
74         BufferView(LyXView * owner, int w, int h);
75
76         ~BufferView();
77
78         /// set the buffer we are viewing
79         void setBuffer(Buffer * b);
80         /// return the buffer being viewed
81         Buffer * buffer() const;
82
83         /// return the painter object for drawing onto the view
84         Painter & painter() const;
85         /// return the screen object for handling re-drawing
86         LyXScreen & screen() const;
87         /// return the owning main view
88         LyXView * owner() const;
89
90         /// resize event has happened
91         void resize();
92
93         /// reload the contained buffer
94         void reload();
95         /// create a new buffer based on template
96         void newFile(std::string const & fname, std::string const & tname,
97                      bool named = true);
98         /// load a buffer into the view
99         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
100
101         /** perform pending painting updates. \c fitcursor means first
102          *  to do a fitcursor, and to force an update if screen
103          *  position changes. \c forceupdate means to force an update
104          *  in any case.
105          */
106
107         void update(Update::flags flags = Update::FitCursor | Update::Force);
108         /// move the screen to fit the cursor. Only to be called with
109         /// good y coordinates (after a bv::metrics)
110         bool fitCursor();
111         /// reset the scrollbar to reflect current view position
112         void updateScrollbar();
113
114         /// FIXME
115         bool available() const;
116
117         /// Save the current position as bookmark i
118         void savePosition(unsigned int i);
119         /// Restore the position from bookmark i
120         void restorePosition(unsigned int i);
121         /// does the given bookmark have a saved position ?
122         bool isSavedPosition(unsigned int i);
123
124         /// return the current change at the cursor
125         Change const getCurrentChange();
126
127         /// return the lyxtext we are using
128         LyXText * getLyXText();
129
130         /// return the lyxtext we are using
131         LyXText const * getLyXText() const;
132
133         /// simple replacing. Use the font of the first selected character
134         void replaceSelectionWithString(std::string const & str);
135
136         /// move cursor to the named label
137         void gotoLabel(std::string const & label);
138
139         /// get the stored error list
140         ErrorList const & getErrorList() const;
141         /// show the error list to the user
142         void showErrorList(std::string const &) const;
143         /// set the cursor based on the given TeX source row
144         void setCursorFromRow(int row);
145
146         /// hide the cursor if it is visible
147         void hideCursor();
148
149         /// center the document view around the cursor
150         void center();
151         /// scroll document by the given number of lines of default height
152         void scroll(int lines);
153         /// Scroll the view by a number of pixels
154         void scrollDocView(int pixels);
155
156         /// return the pixel width of the document view
157         int workWidth() const;
158         /// return the pixel height of the document view
159         int workHeight() const;
160
161         /// switch between primary and secondary keymaps for RTL entry
162         void switchKeyMap();
163
164         /// get the contents of the window system clipboard
165         std::string const getClipboard() const;
166         /// fill the window system clipboard
167         void stuffClipboard(std::string const &) const;
168         /// tell the window system we have a selection
169         void haveSelection(bool sel);
170
171         /// return true for events that will handle
172         FuncStatus getStatus(FuncRequest const & cmd);
173         /// execute the given function
174         bool dispatch(FuncRequest const & argument);
175
176         /// clear the X selection
177         void unsetXSel();
178
179         /// access to offset
180         int offset_ref() const;
181         /// access to anchor
182         lyx::pit_type anchor_ref() const;
183
184         /// access to full cursor
185         LCursor & cursor();
186         /// access to full cursor
187         LCursor const & cursor() const;
188         ///
189         LyXText * text() const;
190         /// sets cursor and open all relevant collapsable insets.
191         void setCursor(DocIterator const &);
192         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
193         void mouseSetCursor(LCursor & cur);
194
195         /* Sets the selection. When \c backwards == false, set anchor
196          * to \c cur and cursor to \c cur + \c length. When \c
197          * backwards == true, set anchor to \c cur and cursor to \c
198          * cur + \c length.
199          */
200         void putSelectionAt(DocIterator const & cur,
201                 int length, bool backwards);
202         ///
203         bool const repaintAll() const;
204         ///
205         void const repaintAll(bool r) const;
206
207 private:
208         ///
209         class Pimpl;
210         ///
211         friend class BufferView::Pimpl;
212         ///
213         Pimpl * pimpl_;
214 };
215
216 #endif // BUFFERVIEW_H