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