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