]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
hopefully fix tex2lyx linking.
[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 "coordcache.h"
19 #include "cursor.h"
20 #include "metricsinfo.h"
21 #include "UpdateFlags.h"
22 #include "support/types.h"
23
24 #include <boost/utility.hpp>
25 #include <boost/signal.hpp>
26
27 #include <utility>
28 #include <string>
29
30
31 namespace lyx {
32
33 class Buffer;
34 class Change;
35 class DocIterator;
36 class FuncRequest;
37 class FuncStatus;
38 class Intl;
39 class Language;
40 class LCursor;
41 class LyXText;
42 class ParIterator;
43 class ViewMetricsInfo;
44
45 /// Scrollbar Parameters.
46 struct ScrollbarParameters
47 {
48         void reset(int h = 0, int p = 0, int l = 0)
49         {
50                 height = h;
51                 position = p;
52                 lineScrollHeight = l;
53         }
54
55         /// Total document height in pixels.
56         int height;
57         /// Current position in the document in pixels.
58         int position;
59         /// Line-scroll amount in pixels.
60         int lineScrollHeight;
61 };
62
63 /// Screen view of a Buffer.
64 /**
65  * A BufferView encapsulates a view onto a particular
66  * buffer, and allows access to operate upon it. A view
67  * is a sliding window of the entire document rendering.
68  * It is the official interface between the LyX core and
69  * the frontend WorkArea.
70  * 
71  * \sa WorkArea
72  * \sa Buffer
73  * \sa CoordCache
74  */
75 class BufferView : boost::noncopyable {
76 public:
77         BufferView();
78
79         ~BufferView();
80
81         /// set the buffer we are viewing.
82         /// \todo FIXME: eventually, we will create a new BufferView
83         /// when switching Buffers, so this method should go.
84         void setBuffer(Buffer * b);
85         /// return the buffer being viewed.
86         Buffer * buffer() const;
87
88         /// resize the BufferView.
89         void resize();
90
91         /// redisplay the referenced buffer.
92         void reload();
93         /// load a buffer into the view.
94         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
95
96         /// perform pending painting updates.
97         /** \c fitcursor means first
98          *  to do a fitcursor, and to force an update if screen
99          *  position changes. \c forceupdate means to force an update
100          *  in any case.
101          * \retval (false, xxx) if no redraw is required
102          * \retval (true, true) if a single paragraph redraw is needed
103          * \retval (true, false) if a full redraw is needed
104          */
105         std::pair<bool, bool> update(Update::flags flags = Update::FitCursor | Update::Force);
106
107         /// move the screen to fit the cursor.
108         /// Only to be called with good y coordinates (after a bv::metrics)
109         bool fitCursor();
110         /// reset the scrollbar to reflect current view position.
111         void updateScrollbar();
112         /// return the Scrollbar Parameters.
113         ScrollbarParameters const & scrollbarParameters() const;
114
115         /// Save the current position as bookmark.
116         /// if persistent=false, save to temp_bookmark
117         void saveBookmark(bool persistent);
118         /// goto a specified position.
119         void moveToPosition(
120                 int par_id, ///< Paragraph ID, \sa Paragraph
121                 pos_type par_pos ///< Position in the \c Paragraph
122                 );
123         /// return the current change at the cursor.
124         Change const getCurrentChange() const;
125
126         /// return the lyxtext we are using.
127         LyXText * getLyXText();
128
129         /// return the lyxtext we are using.
130         LyXText const * getLyXText() const;
131
132         /// move cursor to the named label.
133         void gotoLabel(docstring const & label);
134
135         /// set the cursor based on the given TeX source row.
136         void setCursorFromRow(int row);
137
138         /// center the document view around the cursor.
139         void center();
140         /// scroll document by the given number of lines of default height.
141         void scroll(int lines);
142         /// Scroll the view by a number of pixels.
143         void scrollDocView(int pixels);
144         /// Set the cursor position based on the scrollbar one.
145         void setCursorFromScrollbar();
146
147         /// return the pixel width of the document view.
148         int workWidth() const;
149         /// return the pixel height of the document view.
150         int workHeight() const;
151
152         /// switch between primary and secondary keymaps for RTL entry.
153         void switchKeyMap();
154
155         /// return true for events that will handle.
156         FuncStatus getStatus(FuncRequest const & cmd);
157         /// execute the given function.
158         bool dispatch(FuncRequest const & argument);
159
160         /// request an X11 selection.
161         /// \return the selected string.
162         docstring const requestSelection();
163         /// clear the X11 selection.
164         void clearSelection();
165
166         /// resize method helper for \c WorkArea
167         /// \sa WorkArea
168         /// \sa resise
169         void workAreaResize(int width, int height);
170
171         /// dispatch method helper for \c WorkArea
172         /// \sa WorkArea
173         /// \retval (false, xxx) if no redraw is required
174         /// \retval (true, true) if a single paragraph redraw is needed
175         /// \retval (true, false) if a full redraw is needed
176         std::pair<bool, bool> workAreaDispatch(FuncRequest const & ev);
177
178         /// access to anchor.
179         pit_type anchor_ref() const;
180
181         /// access to full cursor.
182         LCursor & cursor();
183         /// access to full cursor.
184         LCursor const & cursor() const;
185         /// sets cursor.
186         /// This will also open all relevant collapsable insets.
187         void setCursor(DocIterator const &);
188         /// sets cursor.
189         /// This is used when handling LFUN_MOUSE_PRESS.
190         void mouseSetCursor(LCursor & cur);
191
192         /// sets the selection.
193         /* When \c backwards == false, set anchor
194          * to \c cur and cursor to \c cur + \c length. When \c
195          * backwards == true, set anchor to \c cur and cursor to \c
196          * cur + \c length.
197          */
198         void putSelectionAt(DocIterator const & cur,
199                 int length, bool backwards);
200
201         /// return the internal \c ViewMetricsInfo.
202         /// This is used specifically by the \c Workrea.
203         /// \sa WorkArea
204         /// \sa ViewMetricsInfo
205         ViewMetricsInfo const & viewMetricsInfo();
206         /// update the internal \c ViewMetricsInfo.
207         /// \param singlepar indicates wether
208         void updateMetrics(bool singlepar = false);
209
210         ///
211         CoordCache & coordCache() {
212                 return coord_cache_;
213         }
214         ///
215         CoordCache const & coordCache() const {
216                 return coord_cache_;
217         }
218         /// get this view's keyboard map handler.
219         Intl & getIntl() { return *intl_.get(); }
220         ///
221         Intl const & getIntl() const { return *intl_.get(); }
222
223         /// This signal is emitted when some message shows up.
224         boost::signal<void(docstring)> message;
225
226         /// This signal is emitted when some dialog needs to be shown.
227         boost::signal<void(std::string name)> showDialog;
228
229         /// This signal is emitted when some dialog needs to be shown with
230         /// some data.
231         boost::signal<void(std::string name,
232                 std::string data)> showDialogWithData;
233
234         /// This signal is emitted when some inset dialogs needs to be shown.
235         boost::signal<void(std::string name, std::string data,
236                 InsetBase * inset)> showInsetDialog;
237
238         /// This signal is emitted when some dialogs needs to be updated.
239         boost::signal<void(std::string name,
240                 std::string data)> updateDialog;
241
242         /// This signal is emitted when the layout at the cursor is changed.
243         boost::signal<void(std::string layout)> layoutChanged;
244
245 private:
246         ///
247         bool multiParSel();
248         ///
249         int width_;
250         ///
251         int height_;
252         ///
253         ScrollbarParameters scrollbarParameters_;
254
255         ///
256         ViewMetricsInfo metrics_info_;
257         ///
258         CoordCache coord_cache_;
259         ///
260         Buffer * buffer_;
261
262         /// Estimated average par height for scrollbar.
263         int wh_;
264         ///
265         void menuInsertLyXFile(std::string const & filen);
266
267         /// this is used to handle XSelection events in the right manner.
268         struct {
269                 CursorSlice cursor;
270                 CursorSlice anchor;
271                 bool set;
272         } xsel_cache_;
273         ///
274         LCursor cursor_;
275         ///
276         bool multiparsel_cache_;
277         ///
278         pit_type anchor_ref_;
279         ///
280         int offset_ref_;
281
282         /// keyboard mapping object.
283         boost::scoped_ptr<Intl> const intl_;
284 };
285
286
287 } // namespace lyx
288
289 #endif // BUFFERVIEW_H