]> git.lyx.org Git - lyx.git/blob - src/BufferView.C
* remove various xforms relicts, in particular:
[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 #include "metricsinfo.h"
41
42 #include "frontends/Alert.h"
43 #include "frontends/Clipboard.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
46 #include "frontends/Gui.h"
47
48 #include "insets/insetcommand.h" // ChangeRefs
49 #include "insets/insettext.h"
50
51
52 using lyx::support::bformat;
53
54 using lyx::cap::setSelectionRange;
55
56 using std::distance;
57 using std::find;
58 using std::string;
59 using std::vector;
60
61
62 extern BufferList bufferlist;
63
64
65 BufferView::BufferView(LyXView * owner)
66         : pimpl_(new Pimpl(*this, owner))
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 LyXView * BufferView::owner() const
89 {
90         return pimpl_->owner_;
91 }
92
93
94 void BufferView::setBuffer(Buffer * b)
95 {
96         pimpl_->setBuffer(b);
97 }
98
99
100 void BufferView::newFile(string const & fn, string const & tn, bool named)
101 {
102         pimpl_->newFile(fn, tn, named);
103 }
104
105
106 bool BufferView::loadLyXFile(string const & fn, bool tl)
107 {
108         return pimpl_->loadLyXFile(fn, tl);
109 }
110
111
112 void BufferView::reload()
113 {
114         string const fn = buffer()->fileName();
115         if (bufferlist.close(buffer(), false))
116                 loadLyXFile(fn);
117 }
118
119
120 void BufferView::resize()
121 {
122         if (pimpl_->buffer_)
123                 pimpl_->resizeCurrentBuffer();
124 }
125
126
127 bool BufferView::fitCursor()
128 {
129         return pimpl_->fitCursor();
130 }
131
132
133 void BufferView::update(Update::flags flags)
134 {
135         pimpl_->update(flags);
136 }
137
138
139 void BufferView::updateScrollbar()
140 {
141         pimpl_->updateScrollbar();
142 }
143
144
145 ScrollbarParameters const & BufferView::scrollbarParameters() const
146 {
147         return pimpl_->scrollbarParameters();
148 }
149
150
151 void BufferView::scrollDocView(int value)
152 {
153         pimpl_->scrollDocView(value);
154 }
155
156
157 bool BufferView::available() const
158 {
159         return pimpl_->available();
160 }
161
162
163 Change const BufferView::getCurrentChange()
164 {
165         return pimpl_->getCurrentChange();
166 }
167
168
169 void BufferView::savePosition(unsigned int i)
170 {
171         pimpl_->savePosition(i);
172 }
173
174
175 void BufferView::restorePosition(unsigned int i)
176 {
177         pimpl_->restorePosition(i);
178 }
179
180
181 bool BufferView::isSavedPosition(unsigned int i)
182 {
183         return pimpl_->isSavedPosition(i);
184 }
185
186 void BufferView::saveSavedPositions()
187 {
188         return pimpl_->saveSavedPositions();
189 }
190
191 void BufferView::switchKeyMap()
192 {
193         pimpl_->switchKeyMap();
194 }
195
196
197 int BufferView::workWidth() const
198 {
199         return pimpl_->width();
200 }
201
202
203 void BufferView::center()
204 {
205         pimpl_->center();
206 }
207
208
209 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
210 {
211         return pimpl_->getStatus(cmd);
212 }
213
214
215 bool BufferView::dispatch(FuncRequest const & ev)
216 {
217         return pimpl_->dispatch(ev);
218 }
219
220
221 void BufferView::selectionRequested()
222 {
223         pimpl_->selectionRequested();
224 }
225
226
227 void BufferView::selectionLost()
228 {
229         pimpl_->selectionLost();
230 }
231
232
233 void BufferView::workAreaResize(int width, int height)
234 {
235         pimpl_->workAreaResize(width, height);
236 }
237
238
239 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
240 {
241         pimpl_->workAreaKeyPress(key, state);
242 }
243
244
245 bool BufferView::workAreaDispatch(FuncRequest const & ev)
246 {
247         return pimpl_->workAreaDispatch(ev);
248 }
249
250
251 void BufferView::scroll(int lines)
252 {
253         pimpl_->scroll(lines);
254 }
255
256
257 void BufferView::showErrorList(string const & action) const
258 {
259         if (getErrorList().size()) {
260                 string const title = bformat(_("%1$s Errors (%2$s)"),
261                         action, buffer()->fileName());
262                 owner()->getDialogs().show("errorlist", title);
263                 pimpl_->errorlist_.clear();
264         }
265 }
266
267
268 ErrorList const & BufferView::getErrorList() const
269 {
270         return pimpl_->errorlist_;
271 }
272
273
274 void BufferView::setCursorFromRow(int row)
275 {
276         int tmpid = -1;
277         int tmppos = -1;
278
279         buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
280
281         if (tmpid == -1)
282                 text()->setCursor(cursor(), 0, 0);
283         else
284                 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
285 }
286
287
288 void BufferView::gotoLabel(string const & label)
289 {
290         for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
291                 vector<string> labels;
292                 it->getLabelList(*buffer(), labels);
293                 if (find(labels.begin(),labels.end(),label) != labels.end()) {
294                         setCursor(it);
295                         update();
296                         return;
297                 }
298         }
299 }
300
301
302 void BufferView::hideCursor()
303 {
304         pimpl_->gui().guiCursor().hide();
305 }
306
307 LyXText * BufferView::getLyXText()
308 {
309         LyXText * text = cursor().innerText();
310         BOOST_ASSERT(text);
311         return text;
312 }
313
314
315 LyXText const * BufferView::getLyXText() const
316 {
317         LyXText const * text = cursor().innerText();
318         BOOST_ASSERT(text);
319         return text;
320 }
321
322
323 int BufferView::workHeight() const
324 {
325         return pimpl_->height();
326 }
327
328
329 LyXText * BufferView::text() const
330 {
331         return buffer() ? &buffer()->text() : 0;
332 }
333
334
335 void BufferView::setCursor(DocIterator const & dit)
336 {
337         size_t const n = dit.depth();
338         for (size_t i = 0; i < n; ++i)
339                 dit[i].inset().edit(cursor(), true);
340
341         cursor().setCursor(dit);
342         cursor().selection() = false;
343 }
344
345
346 void BufferView::mouseSetCursor(LCursor & cur)
347 {
348         BOOST_ASSERT(&cur.bv() == this);
349
350         // Has the cursor just left the inset?
351         if (&cursor().inset() != &cur.inset())
352                 cursor().inset().notifyCursorLeaves(cursor());
353
354         // do the dEPM magic if needed
355         if (cursor().inTexted())
356                 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
357
358         cursor() = cur;
359         cursor().clearSelection();
360         cursor().setTargetX();
361         finishUndo();
362
363 }
364
365
366 void BufferView::putSelectionAt(DocIterator const & cur,
367                                 int length, bool backwards)
368 {
369         cursor().clearSelection();
370
371         setCursor(cur);
372
373         if (length) {
374                 if (backwards) {
375                         cursor().pos() += length;
376                         cursor().setSelection(cursor(), -length);
377                 } else
378                         cursor().setSelection(cursor(), length);
379         }
380 }
381
382
383 LCursor & BufferView::cursor()
384 {
385         return pimpl_->cursor_;
386 }
387
388
389 LCursor const & BufferView::cursor() const
390 {
391         return pimpl_->cursor_;
392 }
393
394
395 lyx::pit_type BufferView::anchor_ref() const
396 {
397         return pimpl_->anchor_ref_;
398 }
399
400
401 int BufferView::offset_ref() const
402 {
403         return pimpl_->offset_ref_;
404 }
405
406
407 ViewMetricsInfo const & BufferView::viewMetricsInfo()
408 {
409         return pimpl_->viewMetricsInfo();
410 }