]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
revert recent change to development/FORMAT (don't change history)
[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         /// Set the cursor position based on the scrollbar one.
164         void setCursorFromScrollbar();
165
166         /// return the pixel width of the document view
167         int workWidth() const;
168         /// return the pixel height of the document view
169         int workHeight() const;
170
171         /// switch between primary and secondary keymaps for RTL entry
172         void switchKeyMap();
173
174         /// return true for events that will handle
175         FuncStatus getStatus(FuncRequest const & cmd);
176         /// execute the given function
177         bool dispatch(FuncRequest const & argument);
178
179         ///
180         void selectionRequested();
181         ///
182         void selectionLost();
183
184         ///
185         void workAreaResize(int width, int height);
186
187         /// a function should be executed from the workarea
188         bool workAreaDispatch(FuncRequest const & ev);
189
190         /// clear the X selection
191         void unsetXSel();
192
193         /// access to offset
194         int offset_ref() const;
195         /// access to anchor
196         lyx::pit_type anchor_ref() const;
197
198         /// access to full cursor
199         LCursor & cursor();
200         /// access to full cursor
201         LCursor const & cursor() const;
202         ///
203         LyXText * text() const;
204         /// sets cursor and open all relevant collapsable insets.
205         void setCursor(DocIterator const &);
206         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
207         void mouseSetCursor(LCursor & cur);
208
209         /* Sets the selection. When \c backwards == false, set anchor
210          * to \c cur and cursor to \c cur + \c length. When \c
211          * backwards == true, set anchor to \c cur and cursor to \c
212          * cur + \c length.
213          */
214         void putSelectionAt(DocIterator const & cur,
215                 int length, bool backwards);
216         ///
217         ViewMetricsInfo const & viewMetricsInfo();
218         ///
219         void updateMetrics(bool singlepar = false);
220
221 private:
222         ///
223         class Pimpl;
224         ///
225         friend class BufferView::Pimpl;
226         ///
227         Pimpl * pimpl_;
228 };
229
230 #endif // BUFFERVIEW_H