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