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>
49 inline flags operator|(flags const f, flags const g)
51 return static_cast<flags>(int(f) | int(g));
54 inline flags operator&(flags const f, flags const g)
56 return static_cast<flags>(int(f) & int(g));
63 * A buffer view encapsulates a view onto a particular
64 * buffer, and allows access to operate upon it. A view
65 * is a sliding window of the entire document rendering.
67 * Eventually we will allow several views onto a single
68 * buffer, but not yet.
70 class BufferView : boost::noncopyable {
73 * Create a view with the given owner main window,
74 * of the given dimensions.
76 BufferView(LyXView * owner, int w, int h);
80 /// set the buffer we are viewing
81 void setBuffer(Buffer * b);
82 /// return the buffer being viewed
83 Buffer * buffer() const;
85 /// return the painter object for drawing onto the view
86 Painter & painter() const;
87 /// return the screen object for handling re-drawing
88 LyXScreen & screen() const;
89 /// return the owning main view
90 LyXView * owner() const;
92 /// resize event has happened
95 /// reload the contained buffer
97 /// create a new buffer based on template
98 void newFile(std::string const & fname, std::string const & tname,
100 /// load a buffer into the view
101 bool loadLyXFile(std::string const & name, bool tolastfiles = true);
103 /** perform pending painting updates. \c fitcursor means first
104 * to do a fitcursor, and to force an update if screen
105 * position changes. \c forceupdate means to force an update
109 void update(Update::flags flags = Update::FitCursor | Update::Force);
110 /// move the screen to fit the cursor. Only to be called with
111 /// good y coordinates (after a bv::metrics)
113 /// reset the scrollbar to reflect current view position
114 void updateScrollbar();
117 bool available() const;
119 /// Save the current position as bookmark i
120 void savePosition(unsigned int i);
121 /// Restore the position from bookmark i
122 void restorePosition(unsigned int i);
123 /// does the given bookmark have a saved position ?
124 bool isSavedPosition(unsigned int i);
125 /// save bookmarks to .lyx/session
126 void saveSavedPositions();
128 /// return the current change at the cursor
129 Change const getCurrentChange();
131 /// return the lyxtext we are using
132 LyXText * getLyXText();
134 /// return the lyxtext we are using
135 LyXText const * getLyXText() const;
137 /// simple replacing. Use the font of the first selected character
138 void replaceSelectionWithString(std::string const & str);
140 /// move cursor to the named label
141 void gotoLabel(std::string const & label);
143 /// get the stored error list
144 ErrorList const & getErrorList() const;
145 /// show the error list to the user
146 void showErrorList(std::string const &) const;
147 /// set the cursor based on the given TeX source row
148 void setCursorFromRow(int row);
150 /// hide the cursor if it is visible
153 /// center the document view around the cursor
155 /// scroll document by the given number of lines of default height
156 void scroll(int lines);
157 /// Scroll the view by a number of pixels
158 void scrollDocView(int pixels);
160 /// return the pixel width of the document view
161 int workWidth() const;
162 /// return the pixel height of the document view
163 int workHeight() const;
165 /// switch between primary and secondary keymaps for RTL entry
168 /// get the contents of the window system clipboard
169 std::string const getClipboard() const;
170 /// fill the window system clipboard
171 void stuffClipboard(std::string const &) const;
172 /// tell the window system we have a selection
173 void haveSelection(bool sel);
175 /// return true for events that will handle
176 FuncStatus getStatus(FuncRequest const & cmd);
177 /// execute the given function
178 bool dispatch(FuncRequest const & argument);
181 void selectionRequested();
183 void selectionLost();
186 void workAreaResize();
188 /// Receive a keypress
189 void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
191 /// a function should be executed from the workarea
192 bool workAreaDispatch(FuncRequest const & ev);
194 /// clear the X selection
198 int offset_ref() const;
200 lyx::pit_type anchor_ref() const;
202 /// access to full cursor
204 /// access to full cursor
205 LCursor const & cursor() const;
207 LyXText * text() const;
208 /// sets cursor and open all relevant collapsable insets.
209 void setCursor(DocIterator const &);
210 /// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
211 void mouseSetCursor(LCursor & cur);
213 /* Sets the selection. When \c backwards == false, set anchor
214 * to \c cur and cursor to \c cur + \c length. When \c
215 * backwards == true, set anchor to \c cur and cursor to \c
218 void putSelectionAt(DocIterator const & cur,
219 int length, bool backwards);
221 bool const repaintAll() const;
223 void const repaintAll(bool r) const;
229 friend class BufferView::Pimpl;
234 #endif // BUFFERVIEW_H