]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
get rid of broken_header.h and some unneeded tests
[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 "support/types.h"
19
20 #include <boost/utility.hpp>
21
22 #include <string>
23
24 class Buffer;
25 class Change;
26 class DocIterator;
27 class ErrorList;
28 class FuncRequest;
29 class FuncStatus;
30 class Language;
31 class LCursor;
32 class LyXText;
33 class LyXScreen;
34 class LyXView;
35 class Painter;
36 class ParIterator;
37
38 /**
39  * A buffer view encapsulates a view onto a particular
40  * buffer, and allows access to operate upon it. A view
41  * is a sliding window of the entire document rendering.
42  *
43  * Eventually we will allow several views onto a single
44  * buffer, but not yet.
45  */
46 class BufferView : boost::noncopyable {
47 public:
48         /**
49          * Create a view with the given owner main window,
50          * of the given dimensions.
51          */
52         BufferView(LyXView * owner, int w, int h);
53
54         ~BufferView();
55
56         /// set the buffer we are viewing
57         void setBuffer(Buffer * b);
58         /// return the buffer being viewed
59         Buffer * buffer() const;
60
61         /// return the painter object for drawing onto the view
62         Painter & painter() const;
63         /// return the screen object for handling re-drawing
64         LyXScreen & screen() const;
65         /// return the owning main view
66         LyXView * owner() const;
67
68         /// resize event has happened
69         void resize();
70
71         /// reload the contained buffer
72         void reload();
73         /// create a new buffer based on template
74         void newFile(std::string const & fname, std::string const & tname,
75                      bool named = true);
76         /// load a buffer into the view
77         bool loadLyXFile(std::string const & name, bool tolastfiles = true);
78
79         /** perform pending painting updates. \c fitcursor means first
80          *  to do a fitcursor, and to force an update if screen
81          *  position changes. \c forceupdate means to force an update
82          *  in any case. 
83          */
84         void update(bool fitcursor = true, bool forceupdate = true);
85         /// move the screen to fit the cursor. Only to be called with
86         /// good y coordinates (after a bv::metrics)
87         bool fitCursor();
88         /// reset the scrollbar to reflect current view position
89         void updateScrollbar();
90
91         /// FIXME
92         bool available() const;
93
94         /// Save the current position as bookmark i
95         void savePosition(unsigned int i);
96         /// Restore the position from bookmark i
97         void restorePosition(unsigned int i);
98         /// does the given bookmark have a saved position ?
99         bool isSavedPosition(unsigned int i);
100
101         /// return the current change at the cursor
102         Change const getCurrentChange();
103
104         /// return the lyxtext we are using
105         LyXText * getLyXText() const;
106
107         /// simple replacing. Use the font of the first selected character
108         void replaceSelectionWithString(std::string const & str);
109
110         /// move cursor to the named label
111         void gotoLabel(std::string const & label);
112
113         /// get the stored error list
114         ErrorList const & getErrorList() const;
115         /// show the error list to the user
116         void showErrorList(std::string const &) const;
117         /// set the cursor based on the given TeX source row
118         void setCursorFromRow(int row);
119
120         /// hide the cursor if it is visible
121         void hideCursor();
122
123         /// center the document view around the cursor
124         void center();
125         /// scroll document by the given number of lines of default height
126         void scroll(int lines);
127         /// Scroll the view by a number of pixels
128         void scrollDocView(int pixels);
129
130         /// return the pixel width of the document view
131         int workWidth() const;
132         /// return the pixel height of the document view
133         int workHeight() const;
134
135         /// switch between primary and secondary keymaps for RTL entry
136         void switchKeyMap();
137
138         /// get the contents of the window system clipboard
139         std::string const getClipboard() const;
140         /// fill the window system clipboard
141         void stuffClipboard(std::string const &) const;
142         /// tell the window system we have a selection
143         void haveSelection(bool sel);
144
145         /// return true for events that will handle
146         FuncStatus getStatus(FuncRequest const & cmd);
147         /// execute the given function
148         bool dispatch(FuncRequest const & argument);
149
150         /// clear the X selection
151         void unsetXSel();
152
153         /// access to offset
154         int offset_ref() const;
155         /// access to anchor
156         lyx::pit_type anchor_ref() const;
157         
158         /// access to full cursor
159         LCursor & cursor();
160         /// access to full cursor
161         LCursor const & cursor() const;
162         ///
163         LyXText * text() const;
164         ///
165         void setCursor(ParIterator const & par, lyx::pos_type pos);
166         /* Sets the selection. When \c backwards == false, set anchor
167          * to \c cur and cursor to \c cur + \c length. When \c
168          * backwards == true, set anchor to \c cur and cursor to \c
169          * cur + \c length.
170          */
171         void putSelectionAt(DocIterator const & cur,
172                 int length, bool backwards);
173
174
175 private:
176         ///
177         struct Pimpl;
178         ///
179         friend struct BufferView::Pimpl;
180         ///
181         Pimpl * pimpl_;
182 };
183
184 #endif // BUFFERVIEW_H