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