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