]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
A bunch of conversion to docstring.
[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 "metricsinfo.h"
19
20 #include "frontends/LyXKeySym.h"
21
22 #include "support/types.h"
23
24 #include <boost/utility.hpp>
25 #include <boost/signal.hpp>
26
27 #include <string>
28
29 class Buffer;
30 class Change;
31 class DocIterator;
32 class FuncRequest;
33 class FuncStatus;
34 class Language;
35 class LCursor;
36 class LyXText;
37 class LyXView;
38 class ParIterator;
39 class ViewMetricsInfo;
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 /// Scrollbar Parameters
62 struct ScrollbarParameters
63 {
64         void reset(int h = 0, int p = 0, int l = 0)
65         {
66                 height = h;
67                 position = p;
68                 lineScrollHeight = l;
69         }
70
71         /// The total document height in pixels
72         int height;
73         /// The current position in the document, in pixels
74         int position;
75         /// the line-scroll amount, in pixels
76         int lineScrollHeight;
77 };
78
79 /**
80  * A buffer view encapsulates a view onto a particular
81  * buffer, and allows access to operate upon it. A view
82  * is a sliding window of the entire document rendering.
83  *
84  * Eventually we will allow several views onto a single
85  * buffer, but not yet.
86  */
87 class BufferView : boost::noncopyable {
88 public:
89         /**
90          * Create a view with the given owner main window,
91          * of the given dimensions.
92          */
93         BufferView(LyXView * owner);
94
95         ~BufferView();
96
97         /// set the buffer we are viewing
98         void setBuffer(Buffer * b);
99         /// return the buffer being viewed
100         Buffer * buffer() const;
101
102         /// return the owning main view
103         LyXView * owner() const;
104
105         /// resize event has happened
106         void resize();
107
108         /// reload the contained buffer
109         void reload();
110         /// load a buffer into the view
111         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
112
113         /** perform pending painting updates. \c fitcursor means first
114          *  to do a fitcursor, and to force an update if screen
115          *  position changes. \c forceupdate means to force an update
116          *  in any case.
117          * \return true if a full updateMetrics() is needed.
118          */
119         bool update(Update::flags flags = Update::FitCursor | Update::Force);
120
121         /// move the screen to fit the cursor. Only to be called with
122         /// good y coordinates (after a bv::metrics)
123         bool fitCursor();
124         /// reset the scrollbar to reflect current view position
125         void updateScrollbar();
126         /// return the Scrollbar Parameters
127         ScrollbarParameters const & scrollbarParameters() const;
128
129         /// FIXME
130         bool available() const;
131
132         /// Save the current position as bookmark i
133         void savePosition(unsigned int i);
134         /// Restore the position from bookmark i
135         void restorePosition(unsigned int i);
136         /// does the given bookmark have a saved position ?
137         bool isSavedPosition(unsigned int i);
138         /// save bookmarks to .lyx/session
139         void saveSavedPositions();
140
141         /// return the current change at the cursor
142         Change const getCurrentChange();
143
144         /// return the lyxtext we are using
145         LyXText * getLyXText();
146
147         /// return the lyxtext we are using
148         LyXText const * getLyXText() const;
149
150         /// move cursor to the named label
151         void gotoLabel(std::string const & label);
152
153         /// set the cursor based on the given TeX source row
154         void setCursorFromRow(int row);
155
156         /// center the document view around the cursor
157         void center();
158         /// scroll document by the given number of lines of default height
159         void scroll(int lines);
160         /// Scroll the view by a number of pixels
161         void scrollDocView(int pixels);
162         /// Set the cursor position based on the scrollbar one.
163         void setCursorFromScrollbar();
164
165         /// return the pixel width of the document view
166         int workWidth() const;
167         /// return the pixel height of the document view
168         int workHeight() const;
169
170         /// switch between primary and secondary keymaps for RTL entry
171         void switchKeyMap();
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         ///
179         void selectionRequested();
180         ///
181         void selectionLost();
182
183         ///
184         void workAreaResize(int width, int height);
185
186         /// a function should be executed from the workarea
187         bool workAreaDispatch(FuncRequest const & ev);
188
189         /// clear the X selection
190         void unsetXSel();
191
192         /// access to offset
193         int offset_ref() const;
194         /// access to anchor
195         lyx::pit_type anchor_ref() const;
196
197         /// access to full cursor
198         LCursor & cursor();
199         /// access to full cursor
200         LCursor const & cursor() const;
201         ///
202         LyXText * text() const;
203         /// sets cursor and open all relevant collapsable insets.
204         void setCursor(DocIterator const &);
205         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
206         void mouseSetCursor(LCursor & cur);
207
208         /* Sets the selection. When \c backwards == false, set anchor
209          * to \c cur and cursor to \c cur + \c length. When \c
210          * backwards == true, set anchor to \c cur and cursor to \c
211          * cur + \c length.
212          */
213         void putSelectionAt(DocIterator const & cur,
214                 int length, bool backwards);
215         ///
216         ViewMetricsInfo const & viewMetricsInfo();
217         ///
218         void updateMetrics(bool singlepar = false);
219
220         /// This signal is emitted when some message shows up.
221         boost::signal<void(lyx::docstring)> message;
222
223 private:
224         ///
225         class Pimpl;
226         ///
227         friend class BufferView::Pimpl;
228         ///
229         Pimpl * pimpl_;
230 };
231
232 #endif // BUFFERVIEW_H