]> git.lyx.org Git - lyx.git/blob - src/BufferView2.C
fix "make dist" target
[lyx.git] / src / BufferView2.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #include <fstream>
15 #include <algorithm>
16
17 #include "BufferView.h"
18 #include "buffer.h"
19 #include "lyxcursor.h"
20 #include "lyxtext.h"
21 #include "insets/inseterror.h"
22 #include "insets/insetinfo.h"
23 #include "insets/insetspecialchar.h"
24 #include "LyXView.h"
25 #include "bufferlist.h"
26 #include "support/FileInfo.h"
27 #include "lyxscreen.h"
28 #include "support/filetools.h"
29 #include "lyx_gui_misc.h"
30 #include "LaTeX.h"
31 #include "BufferView_pimpl.h"
32 #include "insets/insetcommand.h" //ChangeRefs
33 #include "support/lyxfunctional.h" //equal_1st_in_pair
34 #include "language.h"
35 #include "gettext.h"
36
37 extern BufferList bufferlist;
38
39 using std::pair;
40 using std::endl;
41 using std::ifstream;
42 using std::vector;
43 using std::find;
44 using std::count;
45 using std::count_if;
46
47 // Inserts a file into current document
48 bool BufferView::insertLyXFile(string const & filen)
49         //
50         // Copyright CHT Software Service GmbH
51         // Uwe C. Schroeder
52         //
53         // Insert a Lyxformat - file into current buffer
54         //
55         // Moved from lyx_cb.C (Lgb)
56 {
57         if (filen.empty()) return false;
58
59         string const fname = MakeAbsPath(filen);
60
61         // check if file exist
62         FileInfo const fi(fname);
63
64         if (!fi.readable()) {
65                 WriteAlert(_("Error!"),
66                            _("Specified file is unreadable: "),
67                            MakeDisplayPath(fname, 50));
68                 return false;
69         }
70         
71         beforeChange(text);
72
73         ifstream ifs(fname.c_str());
74         if (!ifs) {
75                 WriteAlert(_("Error!"),
76                            _("Cannot open specified file: "),
77                            MakeDisplayPath(fname, 50));
78                 return false;
79         }
80         
81         char const c = ifs.peek();
82        
83         LyXLex lex(0, 0);
84         lex.setStream(ifs);
85
86         bool res = true;
87
88         if (c == '#') {
89                 lyxerr.debug() << "Will insert file with header" << endl;
90                 res = buffer()->readFile(lex, text->cursor.par());
91         } else {
92                 lyxerr.debug() << "Will insert file without header" << endl;
93                 res = buffer()->readLyXformat2(lex, text->cursor.par());
94         }
95
96         resize();
97         return res;
98 }
99
100
101 bool BufferView::removeAutoInsets()
102 {
103         LyXParagraph * par = buffer()->paragraph;
104
105         LyXCursor tmpcursor = text->cursor;
106         LyXCursor cursor;
107
108         bool a = false;
109
110         while (par) {
111                 // this has to be done before the delete
112                 text->SetCursor(this, cursor, par, 0);
113                 if (par->AutoDeleteInsets()){
114                         a = true;
115                         text->RedoParagraphs(this, cursor,
116                                              cursor.par()->next());
117                         text->FullRebreak(this);
118                 }
119                 par = par->next();
120         }
121
122         // avoid forbidden cursor positions caused by error removing
123         if (tmpcursor.pos() > tmpcursor.par()->size())
124                 tmpcursor.pos(tmpcursor.par()->size());
125
126         text->SetCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
127
128         return a;
129 }
130
131
132 void BufferView::insertErrors(TeXErrors & terr)
133 {
134         // Save the cursor position
135         LyXCursor cursor = text->cursor;
136
137         for (TeXErrors::Errors::const_iterator cit = terr.begin();
138              cit != terr.end();
139              ++cit) {
140                 string const desctext((*cit).error_desc);
141                 string const errortext((*cit).error_text);
142                 string const msgtxt = desctext + '\n' + errortext;
143                 int const errorrow = (*cit).error_in_line;
144
145                 // Insert error string for row number
146                 int tmpid = -1; 
147                 int tmppos = -1;
148
149                 if (buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos)) {
150                         buffer()->texrow.increasePos(tmpid, tmppos);
151                 }
152                 
153                 LyXParagraph * texrowpar = 0;
154
155                 if (tmpid == -1) {
156                         texrowpar = text->FirstParagraph();
157                         tmppos = 0;
158                 } else {
159                         texrowpar = text->GetParFromID(tmpid);
160                 }
161
162                 if (texrowpar == 0)
163                         continue;
164
165                 InsetError * new_inset = new InsetError(msgtxt);
166                 text->SetCursorIntern(this, texrowpar, tmppos);
167                 text->InsertInset(this, new_inset);
168                 text->FullRebreak(this);
169         }
170         // Restore the cursor position
171         text->SetCursorIntern(this, cursor.par(), cursor.pos());
172 }
173
174
175 void BufferView::setCursorFromRow(int row)
176 {
177         int tmpid = -1; 
178         int tmppos = -1;
179
180         buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
181
182         LyXParagraph * texrowpar;
183
184         if (tmpid == -1) {
185                 texrowpar = text->FirstParagraph();
186                 tmppos = 0;
187         } else {
188                 texrowpar = text->GetParFromID(tmpid);
189         }
190         text->SetCursor(this, texrowpar, tmppos);
191 }
192
193
194 bool BufferView::insertInset(Inset * inset, string const & lout,
195                              bool /*no_table*/)
196 {
197         // if we are in a locking inset we should try to insert the
198         // inset there otherwise this is a illegal function now
199         if (theLockingInset()) {
200                 if (theLockingInset()->InsertInsetAllowed(inset))
201                     return theLockingInset()->InsertInset(this, inset);
202                 return false;
203         }
204
205         // not quite sure if we want this...
206         text->SetCursorParUndo(buffer());
207         text->FreezeUndo();
208         
209         beforeChange(text);
210         if (!lout.empty()) {
211                 update(text, BufferView::SELECT|BufferView::FITCUR);
212                 text->BreakParagraph(this);
213                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
214
215                 if (text->cursor.par()->size()) {
216                         text->CursorLeft(this);
217                         
218                         text->BreakParagraph(this);
219                         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
220                 }
221
222                 pair<bool, LyXTextClass::size_type> lres =
223                         textclasslist.NumberOfLayout(buffer()->params
224                                                      .textclass, lout);
225                 LyXTextClass::size_type lay;
226                 if (lres.first != false) {
227                         // layout found
228                         lay = lres.second;
229                 } else {
230                         // layout not fount using default "Standard" (0)
231                         lay = 0;
232                 }
233                  
234                 text->SetLayout(this, lay);
235                 
236                 text->SetParagraph(this, 0, 0,
237                                    0, 0,
238                                    VSpace(VSpace::NONE), VSpace(VSpace::NONE),
239                                    LYX_ALIGN_LAYOUT, 
240                                    string(),
241                                    0);
242                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
243                 
244                 text->current_font.setLatex(LyXFont::OFF);
245         }
246         
247         text->InsertInset(this, inset);
248         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
249
250         text->UnFreezeUndo();
251         return true;
252 }
253
254
255 /* This is also a buffer property (ale) */
256 // Not so sure about that. a goto Label function can not be buffer local, just
257 // think how this will work in a multiwindo/buffer environment, all the
258 // cursors in all the views showing this buffer will move. (Lgb)
259 // OK, then no cursor action should be allowed in buffer. (ale)
260 bool BufferView::gotoLabel(string const & label)
261
262 {
263         for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
264              it != buffer()->inset_iterator_end(); ++it) {
265                 vector<string> labels = (*it)->getLabelList();
266                 if (find(labels.begin(),labels.end(),label)
267                      != labels.end()) {
268                         beforeChange(text);
269                         text->SetCursor(this, it.getPar(), it.getPos());
270                         text->sel_cursor = text->cursor;
271                         update(text, BufferView::SELECT|BufferView::FITCUR);
272                         return true;
273                 }
274         }
275         return false;
276 }
277
278
279 void BufferView::menuUndo()
280 {
281         if (available()) {
282                 owner()->message(_("Undo"));
283                 hideCursor();
284                 beforeChange(text);
285                 update(text, BufferView::SELECT|BufferView::FITCUR);
286                 if (!text->TextUndo(this))
287                         owner()->message(_("No forther undo information"));
288                 else
289                         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
290                 setState();
291         }
292 }
293
294
295 void BufferView::menuRedo()
296 {
297         if (theLockingInset()) {
298                 owner()->message(_("Redo not yet supported in math mode"));
299                 return;
300         }    
301    
302         if (available()) {
303                 owner()->message(_("Redo"));
304                 hideCursor();
305                 beforeChange(text);
306                 update(text, BufferView::SELECT|BufferView::FITCUR);
307                 if (!text->TextRedo(this))
308                         owner()->message(_("No further redo information"));
309                 else
310                         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
311                 setState();
312         }
313 }
314
315
316 void BufferView::hyphenationPoint()
317 {
318         if (available()) {
319                 hideCursor();
320                 update(text, BufferView::SELECT|BufferView::FITCUR);
321                 InsetSpecialChar * new_inset = 
322                         new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
323                 insertInset(new_inset);
324         }
325 }
326
327
328 void BufferView::ldots()
329 {
330         if (available())  {
331                 hideCursor();
332                 update(text, BufferView::SELECT|BufferView::FITCUR);
333                 InsetSpecialChar * new_inset = 
334                         new InsetSpecialChar(InsetSpecialChar::LDOTS);
335                 insertInset(new_inset);
336         }
337 }
338
339
340 void BufferView::endOfSentenceDot()
341 {
342         if (available()) {
343                 hideCursor();
344                 update(text, BufferView::SELECT|BufferView::FITCUR);
345                 InsetSpecialChar * new_inset = 
346                         new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
347                 insertInset(new_inset);
348         }
349 }
350
351
352 void BufferView::menuSeparator()
353 {
354         if (available()) {
355                 hideCursor();
356                 update(text, BufferView::SELECT|BufferView::FITCUR);
357                 InsetSpecialChar * new_inset = 
358                         new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
359                 insertInset(new_inset);
360         }
361 }
362
363
364 void BufferView::newline()
365 {
366         if (available()) {
367                 hideCursor();
368                 update(text, BufferView::SELECT|BufferView::FITCUR);
369                 text->InsertChar(this, LyXParagraph::META_NEWLINE);
370                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
371         }
372 }
373
374
375 void BufferView::protectedBlank(LyXText * lt)
376 {
377         if (available()) {
378                 hideCursor();
379                 update(lt, BufferView::SELECT|BufferView::FITCUR);
380                 InsetSpecialChar * new_inset =
381                         new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
382                 if (!insertInset(new_inset))
383                         delete new_inset;
384                 else
385                         updateInset(new_inset, true);
386         }
387 }
388
389
390 void BufferView::hfill()
391 {
392         if (available()) {
393                 hideCursor();
394                 update(text, BufferView::SELECT|BufferView::FITCUR);
395                 text->InsertChar(this, LyXParagraph::META_HFILL);
396                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
397         }
398 }
399
400
401 void BufferView::copyEnvironment()
402 {
403         if (available()) {
404                 text->copyEnvironmentType();
405                 // clear the selection, even if mark_set
406                 toggleSelection();
407                 text->ClearSelection(this);
408                 update(text, BufferView::SELECT|BufferView::FITCUR);
409                 owner()->message(_("Paragraph environment type copied"));
410         }
411 }
412
413
414 void BufferView::pasteEnvironment()
415 {
416         if (available()) {
417                 text->pasteEnvironmentType(this);
418                 owner()->message(_("Paragraph environment type set"));
419                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
420         }
421 }
422
423
424 void BufferView::copy()
425 {
426         if (available()) {
427                 text->CopySelection(this);
428                 // clear the selection, even if mark_set
429                 toggleSelection();
430                 text->ClearSelection(this);
431                 update(text, BufferView::SELECT|BufferView::FITCUR);
432                 owner()->message(_("Copy"));
433         }
434 }
435
436 void BufferView::cut()
437 {
438         if (available()) {
439                 hideCursor();
440                 update(text, BufferView::SELECT|BufferView::FITCUR);
441                 text->CutSelection(this);
442                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
443                 owner()->message(_("Cut"));
444         }
445 }
446
447
448 void BufferView::paste()
449 {
450         if (!available()) return;
451
452         owner()->message(_("Paste"));
453
454         hideCursor();
455         // clear the selection
456         toggleSelection();
457         text->ClearSelection(this);
458         update(text, BufferView::SELECT|BufferView::FITCUR);
459         
460         // paste
461         text->PasteSelection(this);
462         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
463         
464         // clear the selection 
465         toggleSelection();
466         text->ClearSelection(this);
467         update(text, BufferView::SELECT|BufferView::FITCUR);
468 }
469
470
471 void BufferView::gotoInset(std::vector<Inset::Code> const & codes,
472                            bool same_content)
473 {
474         if (!available()) return;
475    
476         hideCursor();
477         beforeChange(text);
478         update(text, BufferView::SELECT|BufferView::FITCUR);
479
480         string contents;
481         if (same_content &&
482             text->cursor.par()->GetChar(text->cursor.pos()) == LyXParagraph::META_INSET) {
483                 Inset const * inset = text->cursor.par()->GetInset(text->cursor.pos());
484                 if (find(codes.begin(), codes.end(), inset->LyxCode())
485                     != codes.end())
486                         contents =
487                                 static_cast<InsetCommand const *>(inset)->getContents();
488         }
489         
490         if (!text->GotoNextInset(this, codes, contents)) {
491                 if (text->cursor.pos() 
492                     || text->cursor.par() != text->FirstParagraph()) {
493                                 LyXCursor tmp = text->cursor;
494                                 text->cursor.par(text->FirstParagraph());
495                                 text->cursor.pos(0);
496                                 if (!text->GotoNextInset(this, codes, contents)) {
497                                         text->cursor = tmp;
498                                         owner()->message(_("No more insets"));
499                                 }
500                         } else {
501                                 owner()->message(_("No more insets"));
502                         }
503         }
504         update(text, BufferView::SELECT|BufferView::FITCUR);
505         text->sel_cursor = text->cursor;
506 }
507
508
509 void BufferView::gotoInset(Inset::Code code, bool same_content)
510 {
511         gotoInset(vector<Inset::Code>(1, code), same_content);
512 }
513
514
515 void BufferView::insertCorrectQuote()
516 {
517         char c;
518
519         if (text->cursor.pos())
520                 c = text->cursor.par()->GetChar(text->cursor.pos() - 1);
521         else 
522                 c = ' ';
523
524         insertInset(new InsetQuotes(c, buffer()->params));
525 }
526
527
528 /* these functions are for the spellchecker */ 
529 string const BufferView::nextWord(float & value)
530 {
531         if (!available()) {
532                 value = 1;
533                 return string();
534         }
535
536         return text->SelectNextWord(this, value);
537 }
538
539   
540 void BufferView::selectLastWord()
541 {
542         if (!available()) return;
543    
544         hideCursor();
545         beforeChange(text);
546         text->SelectSelectedWord(this);
547         toggleSelection(false);
548         update(text, BufferView::SELECT|BufferView::FITCUR);
549 }
550
551
552 void BufferView::endOfSpellCheck()
553 {
554         if (!available()) return;
555    
556         hideCursor();
557         beforeChange(text);
558         text->SelectSelectedWord(this);
559         text->ClearSelection(this);
560         update(text, BufferView::SELECT|BufferView::FITCUR);
561 }
562
563
564 void BufferView::replaceWord(string const & replacestring)
565 {
566         if (!available()) return;
567
568         hideCursor();
569         update(text, BufferView::SELECT|BufferView::FITCUR);
570    
571         /* clear the selection (if there is any) */ 
572         toggleSelection(false);
573         update(text, BufferView::SELECT|BufferView::FITCUR);
574    
575         /* clear the selection (if there is any) */ 
576         toggleSelection(false);
577         text->ReplaceSelectionWithString(this, replacestring);
578    
579         text->SetSelectionOverString(this, replacestring);
580
581         // Go back so that replacement string is also spellchecked
582         for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
583                 text->CursorLeft(this);
584         }
585         update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
586 }
587 // End of spellchecker stuff
588
589
590 bool BufferView::lockInset(UpdatableInset * inset)
591 {
592         if (!theLockingInset() && inset) {
593                 theLockingInset(inset);
594                 return true;
595         } else if (inset) {
596             return theLockingInset()->LockInsetInInset(this, inset);
597         }
598         return false;
599 }
600
601
602 void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
603 {
604         if (theLockingInset() && available()) {
605                 LyXCursor cursor = text->cursor;
606                 if ((cursor.pos() - 1 >= 0) &&
607                     (cursor.par()->GetChar(cursor.pos() - 1) ==
608                      LyXParagraph::META_INSET) &&
609                     (cursor.par()->GetInset(cursor.pos() - 1) ==
610                      theLockingInset()->GetLockingInset()))
611                         text->SetCursor(this, cursor,
612                                         cursor.par(), cursor.pos() - 1);
613                 LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
614                 LyXText * txt = getLyXText();
615                 if (theLockingInset()->GetLockingInset()->LyxCode() ==
616                     Inset::TEXT_CODE &&
617                     (txt->real_current_font.language() !=
618                      buffer()->params.language
619                      || txt->real_current_font.isVisibleRightToLeft()
620                      != buffer()->params.language->RightToLeft()))
621                         shape = (txt->real_current_font.isVisibleRightToLeft())
622                                 ? LyXScreen::REVERSED_L_SHAPE
623                                 : LyXScreen::L_SHAPE;
624                 y += cursor.y() + theLockingInset()->InsetInInsetY();
625                 pimpl_->screen_->ShowManualCursor(text, x, y, asc, desc,
626                                                   shape);
627         }
628 }
629
630
631 void BufferView::hideLockedInsetCursor()
632 {
633         if (theLockingInset() && available()) {
634                 pimpl_->screen_->HideCursor();
635         }
636 }
637
638
639 void BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
640 {
641         if (theLockingInset() && available()) {
642                 y += text->cursor.y() + theLockingInset()->InsetInInsetY();
643                 if (pimpl_->screen_->FitManualCursor(text, this, x, y, asc, desc))
644                         updateScrollbar();
645         }
646 }
647
648
649 int BufferView::unlockInset(UpdatableInset * inset)
650 {
651         if (inset && theLockingInset() == inset) {
652                 inset->InsetUnlock(this);
653                 theLockingInset(0);
654                 text->FinishUndo();
655                 return 0;
656         } else if (inset && theLockingInset() &&
657                    theLockingInset()->UnlockInsetInInset(this, inset)) {
658                 text->FinishUndo();
659                 return 0;
660         }
661         return bufferlist.unlockInset(inset);
662 }
663
664
665 void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
666 {
667         if (!theLockingInset())
668                 return; // shouldn't happen
669         if (kind == Undo::EDIT) // in this case insets would not be stored!
670                 kind = Undo::FINISH;
671         text->SetUndo(buffer(), kind,
672                       text->cursor.par()->previous(), 
673                       text->cursor.par()->next());
674 }
675
676
677 void BufferView::updateInset(Inset * inset, bool mark_dirty)
678 {
679         if (!inset)
680                 return;
681
682         // first check for locking insets
683         if (theLockingInset()) {
684                 if (theLockingInset() == inset) {
685                         if (text->UpdateInset(this, inset)) {
686                                 update();
687                                 if (mark_dirty) {
688                                         buffer()->markDirty();
689                                 }
690                                 updateScrollbar();
691                                 return;
692                         }
693                 } else if (theLockingInset()->UpdateInsetInInset(this,inset)) {
694                         if (text->UpdateInset(this, theLockingInset())) {
695                                 update();
696                                 if (mark_dirty){
697                                         buffer()->markDirty();
698                                 }
699                                 updateScrollbar();
700                                 return;
701                         }
702                 }
703         }
704   
705         // then check the current buffer
706         if (available()) {
707                 hideCursor();
708                 update(text, BufferView::UPDATE);
709                 if (text->UpdateInset(this, inset)) {
710                         if (mark_dirty)
711                                 update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
712                         else 
713                                 update(text, SELECT);
714                         return;
715                 }
716         }
717 }
718
719
720 bool BufferView::ChangeInsets(Inset::Code code,
721                               string const & from, string const & to)
722 {
723         bool flag = false;
724         LyXParagraph * par = buffer()->paragraph;
725         LyXCursor cursor = text->cursor;
726         LyXCursor tmpcursor = cursor;
727         cursor.par(tmpcursor.par());
728         cursor.pos(tmpcursor.pos());
729
730         while (par) {
731                 bool flag2 = false;
732                 for (LyXParagraph::inset_iterator it = par->inset_iterator_begin();
733                      it != par->inset_iterator_end(); ++it) {
734                         if ((*it)->LyxCode() == code) {
735                                 InsetCommand * inset = static_cast<InsetCommand *>(*it);
736                                 if (inset->getContents() == from) {
737                                         inset->setContents(to);
738                                         flag2 = true;
739                                 }
740                         }
741                 }
742                 if (flag2) {
743                         flag = true;
744                         // this is possible now, since SetCursor takes
745                         // care about footnotes
746                         text->SetCursorIntern(this, par, 0);
747                         text->RedoParagraphs(this, text->cursor,
748                                              text->cursor.par()->next());
749                         text->FullRebreak(this);
750                 }
751                 par = par->next();
752         }
753         text->SetCursorIntern(this, cursor.par(), cursor.pos());
754         return flag;
755 }
756
757
758 bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
759 {
760         // Check if the label 'from' appears more than once
761         vector<string> labels = buffer()->getLabelList();
762         if (count(labels.begin(), labels.end(), from) > 1)
763                 return false;
764
765         return ChangeInsets(Inset::REF_CODE, from, to);
766 }
767
768
769 bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
770 {
771
772         vector<pair<string,string> > keys = buffer()->getBibkeyList();  
773         if (count_if(keys.begin(), keys.end(), 
774                      lyx::equal_1st_in_pair<string,string>(from)) 
775             > 1)
776                 return false;
777
778         return ChangeInsets(Inset::CITE_CODE, from, to);
779 }
780
781 UpdatableInset * BufferView::theLockingInset() const
782 {
783         // If NULL is not allowed we should put an Assert here. (Lgb)
784         if (text)
785                 return text->the_locking_inset;
786         return 0;
787 }
788
789
790 void BufferView::theLockingInset(UpdatableInset * inset)
791 {
792         text->the_locking_inset = inset;
793 }
794
795
796 LyXText * BufferView::getLyXText() const
797 {
798         if (theLockingInset()) {
799                 LyXText * txt = theLockingInset()->getLyXText(this, true);
800                 if (txt)
801                         return txt;
802         }
803         return text;
804 }
805
806
807 LyXText * BufferView::getParentText(Inset * inset) const
808 {
809         if (inset->owner()) {
810                 LyXText * txt = inset->getLyXText(this);
811                 inset = inset->owner();
812                 while (inset && inset->getLyXText(this) == txt)
813                         inset = inset->owner();
814                 if (inset)
815                         return inset->getLyXText(this);
816         }
817         return text;
818 }
819
820
821 Language const * BufferView::getParentLanguage(Inset * inset) const
822 {
823         LyXText * text = getParentText(inset);
824         return text->cursor.par()->GetFontSettings(buffer()->params,
825                                                    text->cursor.pos()).language();
826 }