]> git.lyx.org Git - lyx.git/blob - src/BufferView.C
Compile fixes following Alfredo's setTitle changes.
[lyx.git] / src / BufferView.C
1 /**
2  * \file BufferView.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author unknown
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #include "BufferView.h"
13 #include "BufferView_pimpl.h"
14
15 #include "LaTeX.h"
16 #include "ParagraphParameters.h"
17 #include "WordLangTuple.h"
18 #include "buffer.h"
19 #include "bufferlist.h"
20 #include "debug.h"
21 #include "gettext.h"
22 #include "errorlist.h"
23 #include "iterators.h"
24 #include "language.h"
25 #include "lyxcursor.h"
26 #include "lyxlex.h"
27 #include "lyxtext.h"
28 #include "undo_funcs.h"
29 #include "changes.h"
30 #include "paragraph_funcs.h"
31
32 #include "frontends/Alert.h"
33 #include "frontends/Dialogs.h"
34 #include "frontends/LyXView.h"
35 #include "frontends/WorkArea.h"
36 #include "frontends/screen.h"
37
38 #include "insets/insetcommand.h" // ChangeRefs
39 #include "insets/inseterror.h"
40 #include "insets/updatableinset.h"
41
42 #include "support/FileInfo.h"
43 #include "support/filetools.h"
44 #include "support/lyxfunctional.h" // equal_1st_in_pair
45 #include "support/types.h"
46 #include "support/lyxalgo.h" // lyx_count
47
48 #include <fstream>
49
50 extern BufferList bufferlist;
51
52 using lyx::pos_type;
53
54 using std::pair;
55 using std::endl;
56 using std::ifstream;
57 using std::vector;
58 using std::find;
59 using std::count_if;
60
61
62 BufferView::BufferView(LyXView * owner, int xpos, int ypos,
63                        int width, int height)
64         : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height))
65 {
66         text = 0;
67 }
68
69
70 BufferView::~BufferView()
71 {
72         delete text;
73         delete pimpl_;
74 }
75
76
77 Buffer * BufferView::buffer() const
78 {
79         return pimpl_->buffer_;
80 }
81
82
83 LyXScreen & BufferView::screen() const
84 {
85         return pimpl_->screen();
86 }
87
88
89 LyXView * BufferView::owner() const
90 {
91         return pimpl_->owner_;
92 }
93
94
95 Painter & BufferView::painter() const
96 {
97         return pimpl_->painter();
98 }
99
100
101 void BufferView::buffer(Buffer * b)
102 {
103         pimpl_->buffer(b);
104 }
105
106
107 void BufferView::reload()
108 {
109         string const fn = buffer()->fileName();
110         if (bufferlist.close(buffer(), false))
111                 buffer(bufferlist.loadLyXFile(fn));
112 }
113
114
115 void BufferView::resize()
116 {
117         if (pimpl_->buffer_) {
118                 pimpl_->resizeCurrentBuffer();
119         }
120 }
121
122
123 void BufferView::repaint()
124 {
125         pimpl_->repaint();
126 }
127
128
129 bool BufferView::fitCursor()
130 {
131         return pimpl_->fitCursor();
132 }
133
134
135 void BufferView::update()
136 {
137         pimpl_->update();
138 }
139
140
141 void BufferView::updateScrollbar()
142 {
143         pimpl_->updateScrollbar();
144 }
145
146
147 void BufferView::scrollDocView(int value)
148 {
149         pimpl_->scrollDocView(value);
150 }
151
152
153 void BufferView::redoCurrentBuffer()
154 {
155         pimpl_->redoCurrentBuffer();
156 }
157
158
159 bool BufferView::available() const
160 {
161         return pimpl_->available();
162 }
163
164
165 Change const BufferView::getCurrentChange()
166 {
167         return pimpl_->getCurrentChange();
168 }
169
170
171 void BufferView::beforeChange(LyXText * text)
172 {
173         pimpl_->beforeChange(text);
174 }
175
176
177 void BufferView::savePosition(unsigned int i)
178 {
179         pimpl_->savePosition(i);
180 }
181
182
183 void BufferView::restorePosition(unsigned int i)
184 {
185         pimpl_->restorePosition(i);
186 }
187
188
189 bool BufferView::isSavedPosition(unsigned int i)
190 {
191         return pimpl_->isSavedPosition(i);
192 }
193
194
195 void BufferView::update(LyXText * text, UpdateCodes f)
196 {
197         pimpl_->update(text, f);
198 }
199
200
201 void BufferView::update(UpdateCodes f)
202 {
203         pimpl_->update(f);
204 }
205
206
207 void BufferView::switchKeyMap()
208 {
209         pimpl_->switchKeyMap();
210 }
211
212
213 void BufferView::insetUnlock()
214 {
215         pimpl_->insetUnlock();
216 }
217
218
219 int BufferView::workWidth() const
220 {
221         return pimpl_->workarea().workWidth();
222 }
223
224
225 void BufferView::toggleSelection(bool b)
226 {
227         pimpl_->toggleSelection(b);
228 }
229
230
231 void BufferView::toggleToggle()
232 {
233         pimpl_->toggleToggle();
234 }
235
236
237 void BufferView::center()
238 {
239         pimpl_->center();
240 }
241
242
243 string const BufferView::getClipboard() const
244 {
245         return pimpl_->workarea().getClipboard();
246 }
247
248
249 void BufferView::stuffClipboard(string const & stuff) const
250 {
251         pimpl_->stuffClipboard(stuff);
252 }
253
254
255 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
256                                   BufferView::UpdateCodes uc2)
257 {
258         return static_cast<BufferView::UpdateCodes>
259                 (static_cast<int>(uc1) | static_cast<int>(uc2));
260 }
261
262
263 bool BufferView::dispatch(FuncRequest const & ev)
264 {
265         return pimpl_->dispatch(ev);
266 }
267
268
269 void BufferView::scroll(int lines)
270 {
271         pimpl_->scroll(lines);
272 }
273
274
275 // Inserts a file into current document
276 bool BufferView::insertLyXFile(string const & filen)
277         //
278         // Copyright CHT Software Service GmbH
279         // Uwe C. Schroeder
280         //
281         // Insert a LyXformat - file into current buffer
282         //
283         // Moved from lyx_cb.C (Lgb)
284 {
285         if (filen.empty())
286                 return false;
287
288         string const fname = MakeAbsPath(filen);
289
290         // check if file exist
291         FileInfo const fi(fname);
292
293         if (!fi.readable()) {
294                 string const file = MakeDisplayPath(fname, 50);
295                 string const text =
296                         bformat(_("The specified document\n%1$s\ncould not be read."), file);
297                 Alert::error(_("Could not read document"), text);
298                 return false;
299         }
300
301         beforeChange(text);
302
303         ifstream ifs(fname.c_str());
304         if (!ifs) {
305                 string const file = MakeDisplayPath(fname, 50);
306                 string const text =
307                         bformat(_("Could not open the specified document %1$s\n"), file);
308                 Alert::error(_("Could not open file"), text);
309                 return false;
310         }
311
312         int const c = ifs.peek();
313
314         LyXLex lex(0, 0);
315         lex.setStream(ifs);
316
317         bool res = true;
318
319         if (c == '#') {
320                 // FIXME: huh ? No we won't !
321                 lyxerr[Debug::INFO] << "Will insert file with header" << endl;
322                 res = buffer()->readFile(lex, fname, ParagraphList::iterator(text->cursor.par()));
323         } else {
324                 lyxerr[Debug::INFO] << "Will insert file without header"
325                                     << endl;
326                 res = buffer()->readBody(lex, ParagraphList::iterator(text->cursor.par()));
327         }
328
329         resize();
330         return res;
331 }
332
333
334 bool BufferView::removeAutoInsets()
335 {
336         // keep track of which pos and par the cursor was on
337         Paragraph * cursor_par = &*text->cursor.par();
338         Paragraph * cursor_par_prev = cursor_par ? cursor_par->previous() : 0;
339         Paragraph * cursor_par_next = cursor_par ? cursor_par->next() : 0;
340         pos_type cursor_pos = text->cursor.pos();
341
342         bool found = false;
343
344         // Trap the deletion of the paragraph the cursor is in.
345         // Iterate until we find a paragraph that won't be immediately deleted.
346         // In reality this should mean we only execute the body of the while
347         // loop once at most.  However for safety we iterate rather than just
348         // make this an if () conditional.
349         while ((cursor_par_prev || cursor_par_next)
350                && text->setCursor(
351                                   cursor_par_prev ? cursor_par_prev : cursor_par_next,
352                                   0)) {
353                 // We just removed cursor_par so have to fix the "cursor"
354                 if (cursor_par_prev) {
355                         // '.' = cursor_par
356                         //  a -> a.
357                         // .
358                         cursor_par = cursor_par_prev;
359                         cursor_pos = cursor_par->size();
360                 } else {
361                         // .  -> .a
362                         //  a
363                         cursor_par = cursor_par_next;
364                         cursor_pos = 0;
365                 }
366                 cursor_par_prev = cursor_par->previous();
367                 cursor_par_next = cursor_par->next();
368         }
369
370         // Iterate through the paragraphs removing autoDelete insets as we go.
371         // If the paragraph ends up empty after all the autoDelete insets are
372         // removed that paragraph will be removed by the next setCursor() call.
373         ParIterator it = buffer()->par_iterator_begin();
374         ParIterator end = buffer()->par_iterator_end();
375         for (; it != end; ++it) {
376                 Paragraph * par = &*(*it);
377                 Paragraph * par_prev = par ? par->previous() : 0;
378                 bool removed = false;
379
380                 if (text->setCursor(par, 0)
381                     && cursor_par == par_prev) {
382                         // The previous setCursor line was deleted and that
383                         // was the cursor_par line.  This can only happen if an
384                         // error box was the sole item on cursor_par.
385                         // It is possible for cursor_par_prev to be stray if
386                         // the line it pointed to only had a error box on it
387                         // so we have to set it to a known correct value.
388                         // This is often the same value it already had.
389                         cursor_par_prev = par->previous();
390                         if (cursor_par_prev) {
391                                 // '|' = par, '.' = cursor_par, 'E' = error box
392                                 // First step below may occur before while{}
393                                 //  a    |a      a     a     a.
394                                 //  E -> .E -> |.E -> .  -> |b
395                                 // .      b      b    |b
396                                 //  b
397                                 cursor_par = cursor_par_prev;
398                                 cursor_pos = cursor_par_prev->size();
399                                 cursor_par_prev = cursor_par->previous();
400                                 // cursor_par_next remains the same
401                         } else if (cursor_par_next) {
402                                 // First step below may occur before while{}
403                                 // .
404                                 //  E -> |.E -> |.  -> . -> .|a
405                                 //  a      a      a    |a
406                                 cursor_par = cursor_par_next;
407                                 cursor_pos = 0;
408                                 // cursor_par_prev remains unset
409                                 cursor_par_next = cursor_par->next();
410                         } else {
411                                 // I can't find a way to trigger this
412                                 // so it should be unreachable code
413                                 // unless the buffer is corrupted.
414                                 lyxerr << "BufferView::removeAutoInsets() is bad\n";
415                         }
416                 }
417
418                 InsetList::iterator pit = par->insetlist.begin();
419                 InsetList::iterator pend = par->insetlist.end();
420
421                 while (pit != pend) {
422                         if (pit.getInset()->autoDelete()) {
423                                 removed = true;
424                                 pos_type const pos = pit.getPos();
425
426                                 par->erase(pos);
427                                 // We just invalidated par's inset iterators so
428                                 // we get the next valid iterator position
429                                 pit = par->insetlist.insetIterator(pos);
430                                 // and ensure we have a valid end iterator.
431                                 pend = par->insetlist.end();
432
433                                 if (cursor_par == par) {
434                                         // update the saved cursor position
435                                         if (cursor_pos > pos)
436                                                 --cursor_pos;
437                                 }
438                         } else {
439                                 ++pit;
440                         }
441                 }
442                 if (removed) {
443                         found = true;
444                         text->redoParagraph();
445                 }
446         }
447
448         // It is possible that the last line is empty if it was cursor_par
449         // and/or only had an error inset on it.  So we set the cursor to the
450         // start of the doc to force its removal and ensure a valid saved cursor
451         if (text->setCursor(&*text->ownerParagraphs().begin(), 0)
452             && 0 == cursor_par_next) {
453                 cursor_par = cursor_par_prev;
454                 cursor_pos = cursor_par->size();
455         } else if (cursor_pos > cursor_par->size()) {
456                 // Some C-Enter lines were removed by the setCursor call which
457                 // then invalidated cursor_pos. It could still be "wrong" because
458                 // the cursor may appear to have jumped but since we collapsed
459                 // some C-Enter lines this should be a reasonable compromise.
460                 cursor_pos = cursor_par->size();
461         }
462
463         // restore the original cursor in its corrected location.
464         text->setCursorIntern(cursor_par, cursor_pos);
465
466         return found;
467 }
468
469
470 void BufferView::resetErrorList()
471 {
472         pimpl_->errorlist_.clear();
473 }
474
475
476 void BufferView::setErrorList(ErrorList const & el)
477 {
478         pimpl_->errorlist_ = el;
479 }
480
481
482 void BufferView::addError(ErrorItem const & ei)
483 {
484         pimpl_->errorlist_.push_back(ei);
485
486 }
487
488
489 void BufferView::showErrorList(string const & action) const
490 {
491         if (getErrorList().size()) {
492                 string const title = bformat(_("LyX: %1$s errors (%2$s)"), action, buffer()->fileName());
493                 owner()->getDialogs().show("errorlist", title);
494         }
495 }
496
497
498 ErrorList const &
499 BufferView::getErrorList() const
500 {
501         return pimpl_->errorlist_;
502 }
503
504
505 void BufferView::setCursorFromRow(int row)
506 {
507         int tmpid = -1;
508         int tmppos = -1;
509
510         buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
511
512         ParagraphList::iterator texrowpar;
513
514         if (tmpid == -1) {
515                 texrowpar = text->ownerParagraphs().begin();
516                 tmppos = 0;
517         } else {
518                 texrowpar = *buffer()->getParFromID(tmpid);
519         }
520         text->setCursor(texrowpar, tmppos);
521 }
522
523
524 bool BufferView::insertInset(Inset * inset, string const & lout)
525 {
526         return pimpl_->insertInset(inset, lout);
527 }
528
529
530 void BufferView::gotoLabel(string const & label)
531 {
532         for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
533              it != buffer()->inset_iterator_end(); ++it) {
534                 vector<string> labels = it->getLabelList();
535                 if (find(labels.begin(),labels.end(),label)
536                      != labels.end()) {
537                         beforeChange(text);
538                         text->setCursor(it.getPar(), it.getPos());
539                         text->selection.cursor = text->cursor;
540                         update(text, BufferView::SELECT);
541                         return;
542                 }
543         }
544 }
545
546
547 void BufferView::undo()
548 {
549         if (!available())
550                 return;
551
552         owner()->message(_("Undo"));
553         beforeChange(text);
554         update(text, BufferView::SELECT);
555         if (!textUndo(this))
556                 owner()->message(_("No further undo information"));
557         else
558                 update(text, BufferView::SELECT);
559         switchKeyMap();
560 }
561
562
563 void BufferView::redo()
564 {
565         if (!available())
566                 return;
567
568         owner()->message(_("Redo"));
569         beforeChange(text);
570         update(text, BufferView::SELECT);
571         if (!textRedo(this))
572                 owner()->message(_("No further redo information"));
573         else
574                 update(text, BufferView::SELECT);
575         switchKeyMap();
576 }
577
578
579 // these functions are for the spellchecker
580 WordLangTuple const BufferView::nextWord(float & value)
581 {
582         if (!available()) {
583                 value = 1;
584                 return WordLangTuple();
585         }
586
587         return text->selectNextWordToSpellcheck(value);
588 }
589
590
591 void BufferView::selectLastWord()
592 {
593         if (!available())
594                 return;
595
596         LyXCursor cur = text->selection.cursor;
597         beforeChange(text);
598         text->selection.cursor = cur;
599         text->selectSelectedWord();
600         toggleSelection(false);
601         update(text, BufferView::SELECT);
602 }
603
604
605 void BufferView::endOfSpellCheck()
606 {
607         if (!available()) return;
608
609         beforeChange(text);
610         text->selectSelectedWord();
611         text->clearSelection();
612         update(text, BufferView::SELECT);
613 }
614
615
616 void BufferView::replaceWord(string const & replacestring)
617 {
618         if (!available())
619                 return;
620
621         LyXText * tt = getLyXText();
622         update(tt, BufferView::SELECT);
623
624         // clear the selection (if there is any)
625         toggleSelection(false);
626         update(tt, BufferView::SELECT);
627
628         // clear the selection (if there is any)
629         toggleSelection(false);
630         tt->replaceSelectionWithString(replacestring);
631
632         tt->setSelectionRange(replacestring.length());
633
634         // Go back so that replacement string is also spellchecked
635         for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
636                 tt->cursorLeft(this);
637         }
638         update(tt, BufferView::SELECT);
639
640         // FIXME: should be done through LFUN
641         buffer()->markDirty();
642         fitCursor();
643 }
644 // End of spellchecker stuff
645
646
647 bool BufferView::lockInset(UpdatableInset * inset)
648 {
649         if (!inset)
650                 return false;
651         // don't relock if we're already locked
652         if (theLockingInset() == inset)
653                 return true;
654         if (!theLockingInset()) {
655                 // first check if it's the inset under the cursor we want lock
656                 // should be most of the time
657                 if (text->cursor.pos() < text->cursor.par()->size()
658                     && text->cursor.par()->getChar(text->cursor.pos()) ==
659                     Paragraph::META_INSET) {
660                         Inset * in = text->cursor.par()->getInset(text->cursor.pos());
661                         if (inset == in) {
662                                 theLockingInset(inset);
663                                 return true;
664                         }
665                 }
666                 // Then do a deep look of the inset and lock the right one
667                 int const id = inset->id();
668                 ParagraphList::iterator pit = buffer()->paragraphs.begin();
669                 ParagraphList::iterator pend = buffer()->paragraphs.end();
670                 for (; pit != pend; ++pit) {
671                         InsetList::iterator it = pit->insetlist.begin();
672                         InsetList::iterator end = pit->insetlist.end();
673                         for (; it != end; ++it) {
674                                 if (it.getInset() == inset) {
675                                         text->setCursorIntern(pit, it.getPos());
676                                         theLockingInset(inset);
677                                         return true;
678                                 }
679                                 if (it.getInset()->getInsetFromID(id)) {
680                                         text->setCursorIntern(pit, it.getPos());
681                                         FuncRequest cmd(this, LFUN_INSET_EDIT, "left");
682                                         it.getInset()->localDispatch(cmd);
683                                         return theLockingInset()->lockInsetInInset(this, inset);
684                                 }
685                         }
686                 }
687                 return false;
688         }
689         return theLockingInset()->lockInsetInInset(this, inset);
690 }
691
692
693 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
694 {
695         if (theLockingInset() && available()) {
696                 y += text->cursor.iy() + theLockingInset()->insetInInsetY();
697                 if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
698                         updateScrollbar();
699                         return true;
700                 }
701         }
702         return false;
703 }
704
705
706 void BufferView::hideCursor()
707 {
708         screen().hideCursor();
709 }
710
711
712 int BufferView::unlockInset(UpdatableInset * inset)
713 {
714         if (!inset)
715                 return 0;
716         if (inset && theLockingInset() == inset) {
717                 inset->insetUnlock(this);
718                 theLockingInset(0);
719                 // make sure we update the combo !
720                 owner()->setLayout(getLyXText()->cursor.par()->layout()->name());
721                 // Tell the paragraph dialog that we changed paragraph
722                 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
723                 finishUndo();
724                 return 0;
725         } else if (inset && theLockingInset() &&
726                    theLockingInset()->unlockInsetInInset(this, inset)) {
727                 // Tell the paragraph dialog that we changed paragraph
728                 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
729                 // owner inset has updated the layout combo
730                 finishUndo();
731                 return 0;
732         }
733         return 1;
734 }
735
736
737 void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
738 {
739         if (!theLockingInset())
740                 return; // shouldn't happen
741         if (kind == Undo::EDIT) // in this case insets would not be stored!
742                 kind = Undo::FINISH;
743         setUndo(this, kind,
744                 text->cursor.par(),
745                 boost::next(text->cursor.par()));
746 }
747
748
749 void BufferView::updateInset(Inset * inset)
750 {
751         pimpl_->updateInset(inset);
752 }
753
754
755 bool BufferView::ChangeInsets(Inset::Code code,
756                               string const & from, string const & to)
757 {
758         bool need_update = false;
759         LyXCursor cursor = text->cursor;
760         LyXCursor tmpcursor = cursor;
761         cursor.par(tmpcursor.par());
762         cursor.pos(tmpcursor.pos());
763
764         ParIterator end = buffer()->par_iterator_end();
765         for (ParIterator it = buffer()->par_iterator_begin();
766              it != end; ++it) {
767                 bool changed_inset = false;
768                 for (InsetList::iterator it2 = it->insetlist.begin();
769                      it2 != it->insetlist.end(); ++it2) {
770                         if (it2.getInset()->lyxCode() == code) {
771                                 InsetCommand * inset = static_cast<InsetCommand *>(it2.getInset());
772                                 if (inset->getContents() == from) {
773                                         inset->setContents(to);
774                                         changed_inset = true;
775                                 }
776                         }
777                 }
778                 if (changed_inset) {
779                         need_update = true;
780
781                         // FIXME
782
783                         // The test it.size()==1 was needed to prevent crashes.
784                         // How to set the cursor corretly when it.size()>1 ??
785                         if (it.size() == 1) {
786                                 text->setCursorIntern(*it, 0);
787                                 text->redoParagraphs(text->cursor,
788                                                      boost::next(text->cursor.par()));
789                                 text->fullRebreak();
790                         }
791                 }
792         }
793         text->setCursorIntern(cursor.par(), cursor.pos());
794         return need_update;
795 }
796
797
798 bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
799 {
800         // Check if the label 'from' appears more than once
801         vector<string> labels = buffer()->getLabelList();
802
803         if (lyx::count(labels.begin(), labels.end(), from) > 1)
804                 return false;
805
806         return ChangeInsets(Inset::REF_CODE, from, to);
807 }
808
809
810 bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
811 {
812         typedef pair<string, string> StringPair;
813
814         vector<StringPair> keys;
815         buffer()->fillWithBibKeys(keys);
816         if (count_if(keys.begin(), keys.end(),
817                      lyx::equal_1st_in_pair<StringPair>(from))
818             > 1)
819                 return false;
820
821         return ChangeInsets(Inset::CITE_CODE, from, to);
822 }
823
824
825 UpdatableInset * BufferView::theLockingInset() const
826 {
827         // If NULL is not allowed we should put an Assert here. (Lgb)
828         if (text)
829                 return text->the_locking_inset;
830         return 0;
831 }
832
833
834 void BufferView::theLockingInset(UpdatableInset * inset)
835 {
836         text->the_locking_inset = inset;
837 }
838
839
840 LyXText * BufferView::getLyXText() const
841 {
842         if (theLockingInset()) {
843                 LyXText * txt = theLockingInset()->getLyXText(this, true);
844                 if (txt)
845                         return txt;
846         }
847         return text;
848 }
849
850
851 LyXText * BufferView::getParentText(Inset * inset) const
852 {
853         if (inset->owner()) {
854                 LyXText * txt = inset->getLyXText(this);
855                 inset = inset->owner();
856                 while (inset && inset->getLyXText(this) == txt)
857                         inset = inset->owner();
858                 if (inset)
859                         return inset->getLyXText(this);
860         }
861         return text;
862 }
863
864
865 Language const * BufferView::getParentLanguage(Inset * inset) const
866 {
867         LyXText * text = getParentText(inset);
868         return text->cursor.par()->getFontSettings(buffer()->params,
869                                                    text->cursor.pos()).language();
870 }
871
872
873 Encoding const * BufferView::getEncoding() const
874 {
875         LyXText * t = getLyXText();
876         if (!t)
877                 return 0;
878
879         LyXCursor const & c = t->cursor;
880         LyXFont const font = c.par()->getFont(buffer()->params, c.pos(),
881                                               outerFont(c.par(), t->ownerParagraphs()));
882         return font.language()->encoding();
883 }
884
885
886 void BufferView::haveSelection(bool sel)
887 {
888         pimpl_->workarea().haveSelection(sel);
889 }
890
891
892 int BufferView::workHeight() const
893 {
894         return pimpl_->workarea().workHeight();
895 }