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