]> git.lyx.org Git - lyx.git/blob - src/BufferView.C
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[lyx.git] / src / BufferView.C
1 /**
2  * \file BufferView.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author André Pönitz
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #include <config.h>
16
17 #include "BufferView.h"
18
19 #include "buffer.h"
20 #include "bufferlist.h"
21 #include "bufferparams.h"
22 #include "BufferView_pimpl.h"
23 #include "CutAndPaste.h"
24 #include "coordcache.h"
25 #include "debug.h"
26 #include "funcrequest.h"
27 #include "FuncStatus.h"
28 #include "gettext.h"
29 #include "insetiterator.h"
30 #include "language.h"
31 #include "lyxlayout.h"
32 #include "lyxtext.h"
33 #include "lyxtextclass.h"
34 #include "paragraph.h"
35 #include "paragraph_funcs.h"
36 #include "pariterator.h"
37 #include "texrow.h"
38 #include "undo.h"
39 #include "WordLangTuple.h"
40
41 #include "frontends/Alert.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
44 #include "frontends/screen.h"
45 #include "frontends/WorkArea.h"
46
47 #include "insets/insetcommand.h" // ChangeRefs
48 #include "insets/updatableinset.h"
49 #include "insets/insettext.h"
50
51 using lyx::support::bformat;
52
53 using lyx::cap::setSelectionRange;
54
55 using std::distance;
56 using std::find;
57 using std::string;
58 using std::swap;
59 using std::vector;
60
61
62 extern BufferList bufferlist;
63
64
65 BufferView::BufferView(LyXView * owner, int width, int height)
66         : pimpl_(new Pimpl(*this, owner, width, height))
67 {}
68
69
70 BufferView::~BufferView()
71 {
72         delete pimpl_;
73 }
74
75
76 void BufferView::unsetXSel()
77 {
78         pimpl_->xsel_cache_.set = false;
79 }
80
81
82 Buffer * BufferView::buffer() const
83 {
84         return pimpl_->buffer_;
85 }
86
87
88 LyXScreen & BufferView::screen() const
89 {
90         return pimpl_->screen();
91 }
92
93
94 LyXView * BufferView::owner() const
95 {
96         return pimpl_->owner_;
97 }
98
99
100 Painter & BufferView::painter() const
101 {
102         return pimpl_->painter();
103 }
104
105
106 void BufferView::setBuffer(Buffer * b)
107 {
108         pimpl_->setBuffer(b);
109 }
110
111
112 void BufferView::newFile(string const & fn, string const & tn, bool named)
113 {
114         pimpl_->newFile(fn, tn, named);
115 }
116
117
118 bool BufferView::loadLyXFile(string const & fn, bool tl)
119 {
120         return pimpl_->loadLyXFile(fn, tl);
121 }
122
123
124 void BufferView::reload()
125 {
126         string const fn = buffer()->fileName();
127         if (bufferlist.close(buffer(), false))
128                 loadLyXFile(fn);
129 }
130
131
132 void BufferView::resize()
133 {
134         if (pimpl_->buffer_)
135                 pimpl_->resizeCurrentBuffer();
136 }
137
138
139 bool BufferView::fitCursor()
140 {
141         return pimpl_->fitCursor();
142 }
143
144
145 void BufferView::update(bool fitcursor, bool forceupdate)
146 {
147         pimpl_->update(fitcursor, forceupdate);
148 }
149
150
151 void BufferView::updateScrollbar()
152 {
153         pimpl_->updateScrollbar();
154 }
155
156
157 void BufferView::scrollDocView(int value)
158 {
159         pimpl_->scrollDocView(value);
160 }
161
162
163 bool BufferView::available() const
164 {
165         return pimpl_->available();
166 }
167
168
169 Change const BufferView::getCurrentChange()
170 {
171         return pimpl_->getCurrentChange();
172 }
173
174
175 void BufferView::savePosition(unsigned int i)
176 {
177         pimpl_->savePosition(i);
178 }
179
180
181 void BufferView::restorePosition(unsigned int i)
182 {
183         pimpl_->restorePosition(i);
184 }
185
186
187 bool BufferView::isSavedPosition(unsigned int i)
188 {
189         return pimpl_->isSavedPosition(i);
190 }
191
192
193 void BufferView::switchKeyMap()
194 {
195         pimpl_->switchKeyMap();
196 }
197
198
199 int BufferView::workWidth() const
200 {
201         return pimpl_->workarea().workWidth();
202 }
203
204
205 void BufferView::center()
206 {
207         pimpl_->center();
208 }
209
210
211 string const BufferView::getClipboard() const
212 {
213         return pimpl_->workarea().getClipboard();
214 }
215
216
217 void BufferView::stuffClipboard(string const & stuff) const
218 {
219         pimpl_->stuffClipboard(stuff);
220 }
221
222
223 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
224 {
225         return pimpl_->getStatus(cmd);
226 }
227
228
229 bool BufferView::dispatch(FuncRequest const & ev)
230 {
231         return pimpl_->dispatch(ev);
232 }
233
234
235 void BufferView::scroll(int lines)
236 {
237         pimpl_->scroll(lines);
238 }
239
240
241 void BufferView::showErrorList(string const & action) const
242 {
243         if (getErrorList().size()) {
244                 string const title = bformat(_("LyX: %1$s errors (%2$s)"),
245                         action, buffer()->fileName());
246                 owner()->getDialogs().show("errorlist", title);
247                 pimpl_->errorlist_.clear();
248         }
249 }
250
251
252 ErrorList const & BufferView::getErrorList() const
253 {
254         return pimpl_->errorlist_;
255 }
256
257
258 void BufferView::setCursorFromRow(int row)
259 {
260         int tmpid = -1;
261         int tmppos = -1;
262
263         buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
264
265         if (tmpid == -1)
266                 text()->setCursor(cursor(), 0, 0);
267         else
268                 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
269 }
270
271
272 void BufferView::gotoLabel(string const & label)
273 {
274         for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
275                 vector<string> labels;
276                 it->getLabelList(*buffer(), labels);
277                 if (find(labels.begin(),labels.end(),label) != labels.end()) {
278                         cursor().clearSelection();
279                         text()->setCursor(cursor(), it.pit(), it.pos());
280                         cursor().resetAnchor();
281                         update();
282                         return;
283                 }
284         }
285 }
286
287
288 void BufferView::hideCursor()
289 {
290         screen().hideCursor();
291 }
292
293
294 LyXText * BufferView::getLyXText() const
295 {
296         LyXText * text = cursor().innerText();
297         BOOST_ASSERT(text);
298         return text;
299 }
300
301
302 void BufferView::haveSelection(bool sel)
303 {
304         pimpl_->workarea().haveSelection(sel);
305 }
306
307
308 int BufferView::workHeight() const
309 {
310         return pimpl_->workarea().workHeight();
311 }
312
313
314 LyXText * BufferView::text() const
315 {
316         return buffer() ? &buffer()->text() : 0;
317 }
318
319
320 void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
321 {
322         for (int i = 0, n = par.size(); i < n; ++i)
323                 par[i].inset().edit(cursor(), true);
324
325         cursor().setCursor(makeDocIterator(par, pos));
326         cursor().selection() = false;
327 }
328
329
330 void BufferView::putSelectionAt(DocIterator const & cur,
331                                 int length, bool backwards)
332 {
333         ParIterator par(cur);
334
335         cursor().clearSelection();
336
337         setCursor(par, cur.pos());
338
339         if (length) {
340                 if (backwards) {
341                         cursor().pos() += length;
342                         cursor().setSelection(cursor(), -length);
343                 } else
344                         cursor().setSelection(cursor(), length);
345         }
346 }
347
348
349 LCursor & BufferView::cursor()
350 {
351         return pimpl_->cursor_;
352 }
353
354
355 LCursor const & BufferView::cursor() const
356 {
357         return pimpl_->cursor_;
358 }
359
360
361 lyx::pit_type BufferView::anchor_ref() const
362 {
363         return pimpl_->anchor_ref_;
364 }
365
366
367 int BufferView::offset_ref() const
368 {
369         return pimpl_->offset_ref_;
370 }