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