]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
74483502ebf1e044cf9c29bdc65201187312db48
[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 <string>
28
29
30 namespace lyx {
31
32 class Buffer;
33 class Change;
34 class DocIterator;
35 class FuncRequest;
36 class FuncStatus;
37 class Intl;
38 class Language;
39 class LCursor;
40 class LyXText;
41 class ParIterator;
42 class ViewMetricsInfo;
43
44 /// Scrollbar Parameters
45 struct ScrollbarParameters
46 {
47         void reset(int h = 0, int p = 0, int l = 0)
48         {
49                 height = h;
50                 position = p;
51                 lineScrollHeight = l;
52         }
53
54         /// The total document height in pixels
55         int height;
56         /// The current position in the document, in pixels
57         int position;
58         /// the line-scroll amount, in pixels
59         int lineScrollHeight;
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         BufferView();
73
74         ~BufferView();
75
76         /// set the buffer we are viewing
77         void setBuffer(Buffer * b);
78         /// return the buffer being viewed
79         Buffer * buffer() const;
80
81         /// resize event has happened
82         void resize();
83
84         /// reload the contained buffer
85         void reload();
86         /// load a buffer into the view
87         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
88
89         /** perform pending painting updates. \c fitcursor means first
90          *  to do a fitcursor, and to force an update if screen
91          *  position changes. \c forceupdate means to force an update
92          *  in any case.
93          * \return true if a full updateMetrics() is needed.
94          */
95         bool update(Update::flags flags = Update::FitCursor | Update::Force);
96
97         /// move the screen to fit the cursor. Only to be called with
98         /// good y coordinates (after a bv::metrics)
99         bool fitCursor();
100         /// reset the scrollbar to reflect current view position
101         void updateScrollbar();
102         /// return the Scrollbar Parameters
103         ScrollbarParameters const & scrollbarParameters() const;
104
105         /// Save the current position as bookmark, if persistent=false, save to temp_bookmark
106         void saveBookmark(bool persistent);
107         /// goto a specified position
108         void moveToPosition(int par_id, pos_type par_pos);
109         /// return the current change at the cursor
110         Change const getCurrentChange() const;
111
112         /// return the lyxtext we are using
113         LyXText * getLyXText();
114
115         /// return the lyxtext we are using
116         LyXText const * getLyXText() const;
117
118         /// move cursor to the named label
119         void gotoLabel(docstring const & label);
120
121         /// set the cursor based on the given TeX source row
122         void setCursorFromRow(int row);
123
124         /// center the document view around the cursor
125         void center();
126         /// scroll document by the given number of lines of default height
127         void scroll(int lines);
128         /// Scroll the view by a number of pixels
129         void scrollDocView(int pixels);
130         /// Set the cursor position based on the scrollbar one.
131         void setCursorFromScrollbar();
132
133         /// return the pixel width of the document view
134         int workWidth() const;
135         /// return the pixel height of the document view
136         int workHeight() const;
137
138         /// switch between primary and secondary keymaps for RTL entry
139         void switchKeyMap();
140
141         /// return true for events that will handle
142         FuncStatus getStatus(FuncRequest const & cmd);
143         /// execute the given function
144         bool dispatch(FuncRequest const & argument);
145
146         ///
147         docstring const requestSelection();
148         ///
149         void clearSelection();
150
151         ///
152         void workAreaResize(int width, int height);
153
154         /// a function should be executed from the workarea
155         bool workAreaDispatch(FuncRequest const & ev);
156
157         /// access to anchor
158         pit_type anchor_ref() const;
159
160         /// access to full cursor
161         LCursor & cursor();
162         /// access to full cursor
163         LCursor const & cursor() const;
164         /// sets cursor and open all relevant collapsable insets.
165         void setCursor(DocIterator const &);
166         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
167         void mouseSetCursor(LCursor & cur);
168
169         /* Sets the selection. When \c backwards == false, set anchor
170          * to \c cur and cursor to \c cur + \c length. When \c
171          * backwards == true, set anchor to \c cur and cursor to \c
172          * cur + \c length.
173          */
174         void putSelectionAt(DocIterator const & cur,
175                 int length, bool backwards);
176         ///
177         ViewMetricsInfo const & viewMetricsInfo();
178         ///
179         void updateMetrics(bool singlepar = false);
180
181         ///
182         CoordCache & coordCache() {
183                 return coord_cache_;
184         }
185         ///
186         CoordCache const & coordCache() const {
187                 return coord_cache_;
188         }
189         /// get this view's keyboard map handler
190         Intl & getIntl() { return *intl_.get(); }
191         ///
192         Intl const & getIntl() const { return *intl_.get(); }
193
194         /// This signal is emitted when some message shows up.
195         boost::signal<void(docstring)> message;
196
197         /// This signal is emitted when some dialog needs to be shown.
198         boost::signal<void(std::string name)> showDialog;
199
200         /// This signal is emitted when some dialog needs to be shown with
201         /// some data
202         boost::signal<void(std::string name,
203                 std::string data)> showDialogWithData;
204
205         /// This signal is emitted when some inset dialogs needs to be shown.
206         boost::signal<void(std::string name, std::string data,
207                 InsetBase * inset)> showInsetDialog;
208
209         /// This signal is emitted when some dialogs needs to be updated.
210         boost::signal<void(std::string name,
211                 std::string data)> updateDialog;
212
213         /// This signal is emitted when the layout at the cursor is changed.
214         boost::signal<void(std::string layout)> layoutChanged;
215
216 private:
217         ///
218         bool multiParSel();
219         ///
220         int width_;
221         ///
222         int height_;
223         ///
224         ScrollbarParameters scrollbarParameters_;
225
226         ///
227         ViewMetricsInfo metrics_info_;
228         CoordCache coord_cache_;
229         ///
230         Buffer * buffer_;
231
232         /// Estimated average par height for scrollbar
233         int wh_;
234         ///
235         ///
236         void menuInsertLyXFile(std::string const & filen);
237
238         /// this is used to handle XSelection events in the right manner
239         struct {
240                 CursorSlice cursor;
241                 CursorSlice anchor;
242                 bool set;
243         } xsel_cache_;
244         ///
245         LCursor cursor_;
246         ///
247         bool multiparsel_cache_;
248         ///
249         pit_type anchor_ref_;
250         ///
251         int offset_ref_;
252
253         /// keyboard mapping object
254         boost::scoped_ptr<Intl> const intl_;
255 };
256
257
258 } // namespace lyx
259
260 #endif // BUFFERVIEW_H