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