4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alfredo Braustein
8 * \author Lars Gullik Bjønnes
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
18 #include "frontends/LyXKeySym.h"
20 #include "support/types.h"
22 #include <boost/utility.hpp>
52 inline flags operator|(flags const f, flags const g)
54 return static_cast<flags>(int(f) | int(g));
57 inline flags operator&(flags const f, flags const g)
59 return static_cast<flags>(int(f) & int(g));
66 * A buffer view encapsulates a view onto a particular
67 * buffer, and allows access to operate upon it. A view
68 * is a sliding window of the entire document rendering.
70 * Eventually we will allow several views onto a single
71 * buffer, but not yet.
73 class BufferView : boost::noncopyable {
76 * Create a view with the given owner main window,
77 * of the given dimensions.
79 BufferView(LyXView * owner, int w, int h);
83 /// set the buffer we are viewing
84 void setBuffer(Buffer * b);
85 /// return the buffer being viewed
86 Buffer * buffer() const;
88 /// return the painter object for drawing onto the view
89 lyx::frontend::Painter & painter() const;
91 /// return the owning main view
92 LyXView * owner() const;
94 /// resize event has happened
97 /// reload the contained buffer
99 /// create a new buffer based on template
100 void newFile(std::string const & fname, std::string const & tname,
102 /// load a buffer into the view
103 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
105 /** perform pending painting updates. \c fitcursor means first
106 * to do a fitcursor, and to force an update if screen
107 * position changes. \c forceupdate means to force an update
111 void update(Update::flags flags = Update::FitCursor | Update::Force);
112 /// move the screen to fit the cursor. Only to be called with
113 /// good y coordinates (after a bv::metrics)
115 /// reset the scrollbar to reflect current view position
116 void updateScrollbar();
119 bool available() const;
121 /// Save the current position as bookmark i
122 void savePosition(unsigned int i);
123 /// Restore the position from bookmark i
124 void restorePosition(unsigned int i);
125 /// does the given bookmark have a saved position ?
126 bool isSavedPosition(unsigned int i);
127 /// save bookmarks to .lyx/session
128 void saveSavedPositions();
130 /// return the current change at the cursor
131 Change const getCurrentChange();
133 /// return the lyxtext we are using
134 LyXText * getLyXText();
136 /// return the lyxtext we are using
137 LyXText const * getLyXText() const;
139 /// simple replacing. Use the font of the first selected character
140 void replaceSelectionWithString(std::string const & str);
142 /// move cursor to the named label
143 void gotoLabel(std::string const & label);
145 /// get the stored error list
146 ErrorList const & getErrorList() const;
147 /// show the error list to the user
148 void showErrorList(std::string const &) const;
149 /// set the cursor based on the given TeX source row
150 void setCursorFromRow(int row);
152 /// hide the cursor if it is visible
155 /// center the document view around the cursor
157 /// scroll document by the given number of lines of default height
158 void scroll(int lines);
159 /// Scroll the view by a number of pixels
160 void scrollDocView(int pixels);
162 /// return the pixel width of the document view
163 int workWidth() const;
164 /// return the pixel height of the document view
165 int workHeight() const;
167 /// switch between primary and secondary keymaps for RTL entry
170 /// get the contents of the window system clipboard
171 std::string const getClipboard() const;
172 /// fill the window system clipboard
173 void stuffClipboard(std::string const &) const;
174 /// tell the window system we have a selection
175 void haveSelection(bool sel);
177 /// return true for events that will handle
178 FuncStatus getStatus(FuncRequest const & cmd);
179 /// execute the given function
180 bool dispatch(FuncRequest const & argument);
183 void selectionRequested();
185 void selectionLost();
188 void workAreaResize();
190 /// Receive a keypress
191 void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
193 /// a function should be executed from the workarea
194 bool workAreaDispatch(FuncRequest const & ev);
196 /// clear the X selection
200 int offset_ref() const;
202 lyx::pit_type anchor_ref() const;
204 /// access to full cursor
206 /// access to full cursor
207 LCursor const & cursor() const;
209 LyXText * text() const;
210 /// sets cursor and open all relevant collapsable insets.
211 void setCursor(DocIterator const &);
212 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
213 void mouseSetCursor(LCursor & cur);
215 /* Sets the selection. When \c backwards == false, set anchor
216 * to \c cur and cursor to \c cur + \c length. When \c
217 * backwards == true, set anchor to \c cur and cursor to \c
220 void putSelectionAt(DocIterator const & cur,
221 int length, bool backwards);
223 bool const repaintAll() const;
225 void const repaintAll(bool r) const;
231 friend class BufferView::Pimpl;
236 #endif // BUFFERVIEW_H