Consider the case where there is not any layout name.
[lyx.git] / src / BufferView.h
blob531b38f08bc67830f7d52b5695970440bbacab78
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.
7 * \author Alfredo Braustein
8 * \author Lars Gullik Bjønnes
9 * \author John Levon
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
15 #ifndef BUFFER_VIEW_H
16 #define BUFFER_VIEW_H
18 #include "support/types.h"
20 #include <boost/utility.hpp>
22 #include <string>
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;
39 namespace Update {
40 enum flags {
41 FitCursor = 1,
42 Force = 2,
43 SinglePar = 4
46 inline flags operator|(flags const f, flags const g)
48 return static_cast<flags>(int(f) | int(g));
51 inline flags operator&(flags const f, flags const g)
53 return static_cast<flags>(int(f) & int(g));
56 } // namespace
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.
64 * Eventually we will allow several views onto a single
65 * buffer, but not yet.
67 class BufferView : boost::noncopyable {
68 public:
69 /**
70 * Create a view with the given owner main window,
71 * of the given dimensions.
73 BufferView(LyXView * owner, int w, int h);
75 ~BufferView();
77 /// set the buffer we are viewing
78 void setBuffer(Buffer * b);
79 /// return the buffer being viewed
80 Buffer * buffer() const;
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;
89 /// resize event has happened
90 void resize();
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);
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.
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();
113 /// FIXME
114 bool available() const;
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);
123 /// return the current change at the cursor
124 Change const getCurrentChange();
126 /// return the lyxtext we are using
127 LyXText * getLyXText();
129 /// return the lyxtext we are using
130 LyXText const * getLyXText() const;
132 /// simple replacing. Use the font of the first selected character
133 void replaceSelectionWithString(std::string const & str);
135 /// move cursor to the named label
136 void gotoLabel(std::string const & label);
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);
145 /// hide the cursor if it is visible
146 void hideCursor();
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);
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;
160 /// switch between primary and secondary keymaps for RTL entry
161 void switchKeyMap();
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);
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);
175 /// clear the X selection
176 void unsetXSel();
178 /// access to offset
179 int offset_ref() const;
180 /// access to anchor
181 lyx::pit_type anchor_ref() const;
183 /// access to full cursor
184 LCursor & cursor();
185 /// access to full cursor
186 LCursor const & cursor() const;
188 LyXText * text() const;
190 void setCursor(DocIterator const &);
191 /* Sets the selection. When \c backwards == false, set anchor
192 * to \c cur and cursor to \c cur + \c length. When \c
193 * backwards == true, set anchor to \c cur and cursor to \c
194 * cur + \c length.
196 void putSelectionAt(DocIterator const & cur,
197 int length, bool backwards);
200 private:
202 class Pimpl;
204 friend class BufferView::Pimpl;
206 Pimpl * pimpl_;
209 #endif // BUFFERVIEW_H