]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
Fix bug 2485 and crash on middle mouse paste on math
[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         /// save bookmarks to .lyx/session
124         void saveSavedPositions();
125
126         /// return the current change at the cursor
127         Change const getCurrentChange();
128
129         /// return the lyxtext we are using
130         LyXText * getLyXText();
131
132         /// return the lyxtext we are using
133         LyXText const * getLyXText() const;
134
135         /// simple replacing. Use the font of the first selected character
136         void replaceSelectionWithString(std::string const & str);
137
138         /// move cursor to the named label
139         void gotoLabel(std::string const & label);
140
141         /// get the stored error list
142         ErrorList const & getErrorList() const;
143         /// show the error list to the user
144         void showErrorList(std::string const &) const;
145         /// set the cursor based on the given TeX source row
146         void setCursorFromRow(int row);
147
148         /// hide the cursor if it is visible
149         void hideCursor();
150
151         /// center the document view around the cursor
152         void center();
153         /// scroll document by the given number of lines of default height
154         void scroll(int lines);
155         /// Scroll the view by a number of pixels
156         void scrollDocView(int pixels);
157
158         /// return the pixel width of the document view
159         int workWidth() const;
160         /// return the pixel height of the document view
161         int workHeight() const;
162
163         /// switch between primary and secondary keymaps for RTL entry
164         void switchKeyMap();
165
166         /// get the contents of the window system clipboard
167         std::string const getClipboard() const;
168         /// fill the window system clipboard
169         void stuffClipboard(std::string const &) const;
170         /// tell the window system we have a selection
171         void haveSelection(bool sel);
172
173         /// return true for events that will handle
174         FuncStatus getStatus(FuncRequest const & cmd);
175         /// execute the given function
176         bool dispatch(FuncRequest const & argument);
177
178         /// clear the X selection
179         void unsetXSel();
180
181         /// access to offset
182         int offset_ref() const;
183         /// access to anchor
184         lyx::pit_type anchor_ref() const;
185
186         /// access to full cursor
187         LCursor & cursor();
188         /// access to full cursor
189         LCursor const & cursor() const;
190         ///
191         LyXText * text() const;
192         /// sets cursor and open all relevant collapsable insets.
193         void setCursor(DocIterator const &);
194         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
195         void mouseSetCursor(LCursor & cur);
196
197         /* Sets the selection. When \c backwards == false, set anchor
198          * to \c cur and cursor to \c cur + \c length. When \c
199          * backwards == true, set anchor to \c cur and cursor to \c
200          * cur + \c length.
201          */
202         void putSelectionAt(DocIterator const & cur,
203                 int length, bool backwards);
204         ///
205         bool const repaintAll() const;
206         ///
207         void const repaintAll(bool r) const;
208
209 private:
210         ///
211         class Pimpl;
212         ///
213         friend class BufferView::Pimpl;
214         ///
215         Pimpl * pimpl_;
216 };
217
218 #endif // BUFFERVIEW_H