]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
a05c38e84cac282c18549eb1715528adf461ce61
[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         /// center the document view around the cursor
164         void center();
165         /// scroll document by the given number of lines of default height
166         void scroll(int lines);
167         /// Scroll the view by a number of pixels
168         void scrollDocView(int pixels);
169
170         /// return the pixel width of the document view
171         int workWidth() const;
172         /// return the pixel height of the document view
173         int workHeight() const;
174
175         /// switch between primary and secondary keymaps for RTL entry
176         void switchKeyMap();
177
178         /// return true for events that will handle
179         FuncStatus getStatus(FuncRequest const & cmd);
180         /// execute the given function
181         bool dispatch(FuncRequest const & argument);
182
183         ///
184         void selectionRequested();
185         ///
186         void selectionLost();
187
188         ///
189         void workAreaResize(int width, int height);
190
191         /// Receive a keypress
192         void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
193
194         /// a function should be executed from the workarea
195         bool workAreaDispatch(FuncRequest const & ev);
196
197         /// clear the X selection
198         void unsetXSel();
199
200         /// access to offset
201         int offset_ref() const;
202         /// access to anchor
203         lyx::pit_type anchor_ref() const;
204
205         /// access to full cursor
206         LCursor & cursor();
207         /// access to full cursor
208         LCursor const & cursor() const;
209         ///
210         LyXText * text() const;
211         /// sets cursor and open all relevant collapsable insets.
212         void setCursor(DocIterator const &);
213         /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
214         void mouseSetCursor(LCursor & cur);
215
216         /* Sets the selection. When \c backwards == false, set anchor
217          * to \c cur and cursor to \c cur + \c length. When \c
218          * backwards == true, set anchor to \c cur and cursor to \c
219          * cur + \c length.
220          */
221         void putSelectionAt(DocIterator const & cur,
222                 int length, bool backwards);
223
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