]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
3f8ff3eab05e6333d60aa5b36e3746bb0b8e3154
[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 ErrorList;
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         /// return the first layout of the Buffer.
102         std::string firstLayout();
103
104         /// return the owning main view
105         LyXView * owner() const;
106
107         /// resize event has happened
108         void resize();
109
110         /// reload the contained buffer
111         void reload();
112         /// load a buffer into the view
113         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
114
115         /** perform pending painting updates. \c fitcursor means first
116          *  to do a fitcursor, and to force an update if screen
117          *  position changes. \c forceupdate means to force an update
118          *  in any case.
119          */
120
121         void update(Update::flags flags = Update::FitCursor | Update::Force);
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         /// simple replacing. Use the font of the first selected character
152         void replaceSelectionWithString(std::string const & str);
153
154         /// move cursor to the named label
155         void gotoLabel(std::string const & label);
156
157         /// get the stored error list
158         ErrorList const & getErrorList() const;
159         /// show the error list to the user
160         void showErrorList(std::string const &) const;
161         /// set the cursor based on the given TeX source row
162         void setCursorFromRow(int row);
163
164         /// center the document view around the cursor
165         void center();
166         /// scroll document by the given number of lines of default height
167         void scroll(int lines);
168         /// Scroll the view by a number of pixels
169         void scrollDocView(int pixels);
170
171         /// return the pixel width of the document view
172         int workWidth() const;
173         /// return the pixel height of the document view
174         int workHeight() const;
175
176         /// switch between primary and secondary keymaps for RTL entry
177         void switchKeyMap();
178
179         /// return true for events that will handle
180         FuncStatus getStatus(FuncRequest const & cmd);
181         /// execute the given function
182         bool dispatch(FuncRequest const & argument);
183
184         ///
185         void selectionRequested();
186         ///
187         void selectionLost();
188
189         ///
190         void workAreaResize(int width, int height);
191
192         /// Receive a keypress
193         void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
194
195         /// a function should be executed from the workarea
196         bool workAreaDispatch(FuncRequest const & ev);
197
198         /// clear the X selection
199         void unsetXSel();
200
201         /// access to offset
202         int offset_ref() const;
203         /// access to anchor
204         lyx::pit_type anchor_ref() const;
205
206         /// access to full cursor
207         LCursor & cursor();
208         /// access to full cursor
209         LCursor const & cursor() const;
210         ///
211         LyXText * text() const;
212         /// sets cursor and open all relevant collapsable insets.
213         void setCursor(DocIterator const &);
214         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
215         void mouseSetCursor(LCursor & cur);
216
217         /* Sets the selection. When \c backwards == false, set anchor
218          * to \c cur and cursor to \c cur + \c length. When \c
219          * backwards == true, set anchor to \c cur and cursor to \c
220          * cur + \c length.
221          */
222         void putSelectionAt(DocIterator const & cur,
223                 int length, bool backwards);
224         ///
225         ViewMetricsInfo const & viewMetricsInfo();
226
227         ///
228         bool needsRedraw() const;
229         void needsRedraw(bool redraw_needed);
230 private:
231         ///
232         class Pimpl;
233         ///
234         friend class BufferView::Pimpl;
235         ///
236         Pimpl * pimpl_;
237 };
238
239 #endif // BUFFERVIEW_H