]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.C
waste cycles for simpler InsetText::localUpdate
[lyx.git] / src / insets / insettext.C
1 /**
2  * \file insettext.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "insettext.h"
14
15 #include "buffer.h"
16 #include "BufferView.h"
17 #include "bufferview_funcs.h"
18 #include "CutAndPaste.h"
19 #include "debug.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23 #include "errorlist.h"
24 #include "intl.h"
25 #include "LaTeXFeatures.h"
26 #include "LColor.h"
27 #include "Lsstream.h"
28 #include "lyxfont.h"
29 #include "lyxcursor.h"
30 #include "lyxfind.h"
31 #include "lyxlex.h"
32 #include "lyxrow.h"
33 #include "lyxrc.h"
34 #include "lyxtext.h"
35 #include "paragraph.h"
36 #include "ParagraphParameters.h"
37 #include "trans_mgr.h"
38 #include "undo_funcs.h"
39 #include "WordLangTuple.h"
40 #include "paragraph_funcs.h"
41 #include "sgml.h"
42 #include "rowpainter.h"
43 #include "insetnewline.h"
44 #include "metricsinfo.h"
45
46 #include "frontends/Alert.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/font_metrics.h"
49 #include "frontends/LyXView.h"
50 #include "frontends/Painter.h"
51 #include "frontends/screen.h"
52
53 #include "support/textutils.h"
54 #include "support/LAssert.h"
55 #include "support/lstrings.h"
56 #include "support/lyxalgo.h" // lyx::count
57
58 #include <boost/bind.hpp>
59
60 #include <fstream>
61 #include <algorithm>
62 #include <cstdlib>
63
64 using std::ostream;
65 using std::ifstream;
66 using std::endl;
67 using std::min;
68 using std::max;
69 using std::make_pair;
70 using std::vector;
71 using std::pair;
72 using std::for_each;
73 using std::auto_ptr;
74
75 using namespace lyx::support;
76 using namespace lyx::graphics;
77 using namespace bv_funcs;
78
79 using lyx::pos_type;
80 using lyx::textclass_type;
81
82
83 // we should get rid of these (Andre')
84
85 void InsetText::saveLyXTextState() const
86 {
87         // check if my paragraphs are still valid
88         ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin();
89         ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end();
90         for (; it != end; ++it)
91                 if (it == text_.cursor.par())
92                         break;
93
94         if (it != end && text_.cursor.pos() <= it->size())
95                 sstate = text_; // slicing intended
96         else
97                 sstate.cursor.par(end);
98 }
99
100
101 void InsetText::restoreLyXTextState() const
102 {
103         if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
104                 return;
105
106         text_.selection.set(true);
107         // at this point just to avoid the DEPM when setting the cursor
108         text_.selection.mark(sstate.selection.mark());
109         if (sstate.selection.set()) {
110                 text_.setCursor(sstate.selection.start.par(),
111                         sstate.selection.start.pos(),
112                         true, sstate.selection.start.boundary());
113                 text_.selection.cursor = text_.cursor;
114                 text_.setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
115                         true, sstate.selection.end.boundary());
116                 text_.setSelection();
117                 text_.setCursor(sstate.cursor.par(), sstate.cursor.pos());
118         } else {
119                 text_.setCursor(sstate.cursor.par(), sstate.cursor.pos(),
120                         true, sstate.cursor.boundary());
121                 text_.selection.cursor = text_.cursor;
122                 text_.selection.set(false);
123         }
124 }
125
126
127 InsetText::InsetText(BufferParams const & bp)
128         : UpdatableInset(), text_(0, this)
129 {
130         paragraphs.push_back(Paragraph());
131         paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
132         if (bp.tracking_changes)
133                 paragraphs.begin()->trackChanges();
134         init(0);
135 }
136
137
138 InsetText::InsetText(InsetText const & in)
139         : UpdatableInset(in), text_(0, this)
140 {
141         init(&in);
142 }
143
144
145 InsetText & InsetText::operator=(InsetText const & it)
146 {
147         init(&it);
148         return *this;
149 }
150
151
152 void InsetText::init(InsetText const * ins)
153 {
154         if (ins) {
155                 textwidth_ = ins->textwidth_;
156                 text_.bv_owner = ins->text_.bv_owner;
157                 setParagraphData(ins->paragraphs);
158                 autoBreakRows = ins->autoBreakRows;
159                 drawFrame_ = ins->drawFrame_;
160                 frame_color = ins->frame_color;
161         } else {
162                 textwidth_ = 0; // broken
163                 drawFrame_ = NEVER;
164                 frame_color = LColor::insetframe;
165                 autoBreakRows = false;
166         }
167         the_locking_inset = 0;
168         for_each(paragraphs.begin(), paragraphs.end(),
169                  boost::bind(&Paragraph::setInsetOwner, _1, this));
170         top_y = 0;
171         no_selection = true;
172         need_update = FULL;
173         drawTextXOffset = 0;
174         drawTextYOffset = 0;
175         locked = false;
176         old_par = paragraphs.end();
177         last_drawn_width = -1;
178         sstate.cursor.par(paragraphs.end());
179         in_insetAllowed = false;
180 }
181
182
183 void InsetText::clear(bool just_mark_erased)
184 {
185         if (just_mark_erased) {
186                 ParagraphList::iterator it = paragraphs.begin();
187                 ParagraphList::iterator end = paragraphs.end();
188                 for (; it != end; ++it) {
189                         it->markErased();
190                 }
191                 need_update = FULL;
192                 return;
193         }
194
195         // This is a gross hack...
196         LyXLayout_ptr old_layout = paragraphs.begin()->layout();
197
198         paragraphs.clear();
199         paragraphs.push_back(Paragraph());
200         paragraphs.begin()->setInsetOwner(this);
201         paragraphs.begin()->layout(old_layout);
202
203         reinitLyXText();
204         need_update = INIT;
205 }
206
207
208 auto_ptr<InsetBase> InsetText::clone() const
209 {
210         return auto_ptr<InsetBase>(new InsetText(*this));
211 }
212
213
214 void InsetText::write(Buffer const * buf, ostream & os) const
215 {
216         os << "Text\n";
217         writeParagraphData(buf, os);
218 }
219
220
221 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
222 {
223         ParagraphList::const_iterator it = paragraphs.begin();
224         ParagraphList::const_iterator end = paragraphs.end();
225         Paragraph::depth_type dth = 0;
226         for (; it != end; ++it) {
227                 it->write(buf, os, buf->params, dth);
228         }
229 }
230
231
232 void InsetText::read(Buffer const * buf, LyXLex & lex)
233 {
234         string token;
235         Paragraph::depth_type depth = 0;
236
237         clear(false);
238
239         if (buf->params.tracking_changes)
240                 paragraphs.begin()->trackChanges();
241
242         // delete the initial paragraph
243         paragraphs.clear();
244         ParagraphList::iterator pit = paragraphs.begin();
245
246         while (lex.isOK()) {
247                 lex.nextToken();
248                 token = lex.getString();
249                 if (token.empty())
250                         continue;
251                 if (token == "\\end_inset") {
252                         break;
253                 }
254
255                 if (token == "\\end_document") {
256                         lex.printError("\\end_document read in inset! Error in document!");
257                         return;
258                 }
259
260                 // FIXME: ugly.
261                 const_cast<Buffer*>(buf)->readParagraph(lex, token, paragraphs, pit, depth);
262         }
263
264         pit = paragraphs.begin();
265         ParagraphList::iterator const end = paragraphs.end();
266         for (; pit != end; ++pit)
267                 pit->setInsetOwner(this);
268
269         if (token != "\\end_inset") {
270                 lex.printError("Missing \\end_inset at this point. "
271                                            "Read: `$$Token'");
272         }
273         need_update = FULL;
274 }
275
276
277 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
278 {
279         //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
280
281         textwidth_ = mi.base.textwidth;
282         BufferView * bv = mi.base.bv;
283         setViewCache(bv);
284         text_.metrics(mi, dim);
285         dim.asc += TEXT_TO_INSET_OFFSET;
286         dim.des += TEXT_TO_INSET_OFFSET;
287         dim.wid += 2 * TEXT_TO_INSET_OFFSET;
288         dim.wid = max(dim.wid, 10);
289         dim_ = dim;
290 }
291
292
293 int InsetText::textWidth() const
294 {
295         return textwidth_;
296 }
297
298
299 void InsetText::draw(PainterInfo & pi, int x, int baseline) const
300 {
301         // update our idea of where we are. Clearly, we should
302         // not have to know this information.
303         top_x = x;
304
305         int const start_x = x;
306
307         BufferView * bv = pi.base.bv;
308         Painter & pain = pi.pain;
309
310         // repaint the background if needed
311         if (backgroundColor() != LColor::background)
312                 clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
313
314         // no draw is necessary !!!
315         if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
316                 top_baseline = baseline;
317                 need_update = NONE;
318                 return;
319         }
320
321         bv->hideCursor();
322
323         if (!owner())
324                 x += scroll();
325
326         top_baseline = baseline;
327         top_y = baseline - dim_.asc;
328
329         if (last_drawn_width != dim_.wid) {
330                 need_update |= FULL;
331                 last_drawn_width = dim_.wid;
332         }
333
334         if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) {
335                 inset_x = cix() - x + drawTextXOffset;
336                 inset_y = ciy() + drawTextYOffset;
337         }
338
339         x += TEXT_TO_INSET_OFFSET;
340
341         RowList::iterator rit = text_.rows().begin();
342         RowList::iterator end = text_.rows().end();
343
344         int y_offset = baseline - rit->ascent_of_text();
345         int y2 = pain.paperHeight();
346         int first = 0;
347         int y = y_offset;
348         while (rit != end && y + rit->height() <= 0) {
349                 y += rit->height();
350                 first += rit->height();
351                 ++rit;
352         }
353         if (y_offset < 0) {
354                 text_.top_y(-y_offset);
355                 first = y;
356                 y_offset = 0;
357         } else {
358                 text_.top_y(first);
359                 first = 0;
360         }
361
362         int yo = y_offset + first;
363
364         paintRows(*bv, text_, rit, x, 0, yo, y2, yo);
365
366         if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked))
367                 drawFrame(pain, int(start_x));
368
369         if (need_update != INIT)
370                 need_update = NONE;
371 }
372
373
374 void InsetText::drawFrame(Painter & pain, int x) const
375 {
376         static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
377         frame_x = x + ttoD2;
378         frame_y = top_baseline - dim_.asc + ttoD2;
379         frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
380         frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
381         pain.rectangle(frame_x, frame_y, frame_w, frame_h,
382                        frame_color);
383 }
384
385
386 void InsetText::setUpdateStatus(int what) const
387 {
388         need_update |= what;
389 }
390
391
392 void InsetText::updateLocal(BufferView * bv, bool mark_dirty)
393 {
394         if (!bv)
395                 return;
396
397         if (!autoBreakRows && paragraphs.size() > 1)
398                 collapseParagraphs(bv);
399
400         text_.partialRebreak();
401         setUpdateStatus(FULL);
402         bool flag = mark_dirty || need_update != NONE || text_.selection.set();
403         if (!text_.selection.set())
404                 text_.selection.cursor = text_.cursor;
405
406         bv->fitCursor();
407
408         if (flag)
409                 bv->updateInset(const_cast<InsetText *>(this));
410
411         bv->owner()->view_state_changed();
412         bv->owner()->updateMenubar();
413         bv->owner()->updateToolbar();
414         if (old_par != cpar()) {
415                 bv->owner()->setLayout(cpar()->layout()->name());
416                 old_par = cpar();
417         }
418 }
419
420
421 string const InsetText::editMessage() const
422 {
423         return _("Opened Text Inset");
424 }
425
426
427 void InsetText::insetUnlock(BufferView * bv)
428 {
429         if (the_locking_inset) {
430                 the_locking_inset->insetUnlock(bv);
431                 the_locking_inset = 0;
432                 updateLocal(bv, false);
433         }
434         no_selection = true;
435         locked = false;
436         int code = NONE;
437
438         if (text_.selection.set()) {
439                 text_.clearSelection();
440                 code = FULL;
441         } else if (owner()) {
442                 bv->owner()->setLayout(owner()->getLyXText(bv)
443                                        ->cursor.par()->layout()->name());
444         } else
445                 bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
446         // hack for deleteEmptyParMech
447         ParagraphList::iterator first_par = paragraphs.begin();
448         if (!first_par->empty()) {
449                 text_.setCursor(first_par, 0);
450         } else if (paragraphs.size() > 1) {
451                 text_.setCursor(boost::next(first_par), 0);
452         }
453         if (code != NONE)
454                 setUpdateStatus(code);
455 }
456
457
458 void InsetText::lockInset(BufferView * bv)
459 {
460         locked = true;
461         the_locking_inset = 0;
462         inset_pos = inset_x = inset_y = 0;
463         inset_boundary = false;
464         inset_par = paragraphs.end();
465         old_par = paragraphs.end();
466         text_.setCursorIntern(paragraphs.begin(), 0);
467         text_.clearSelection();
468         finishUndo();
469         // If the inset is empty set the language of the current font to the
470         // language to the surronding text (if different).
471         if (paragraphs.begin()->empty() && paragraphs.size() == 1 &&
472                 bv->getParentLanguage(this) != text_.current_font.language()) {
473                 LyXFont font(LyXFont::ALL_IGNORE);
474                 font.setLanguage(bv->getParentLanguage(this));
475                 setFont(bv, font, false);
476         }
477         setUpdateStatus(FULL);
478 }
479
480
481 void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset)
482 {
483         the_locking_inset = inset;
484         inset_x = cix() - top_x + drawTextXOffset;
485         inset_y = ciy() + drawTextYOffset;
486         inset_pos = cpos();
487         inset_par = cpar();
488         inset_boundary = cboundary();
489 }
490
491
492 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
493 {
494         lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
495                               << inset << "): " << endl;
496         if (!inset)
497                 return false;
498         if (!the_locking_inset) {
499                 ParagraphList::iterator pit = paragraphs.begin();
500                 ParagraphList::iterator pend = paragraphs.end();
501
502                 int const id = inset->id();
503                 for (; pit != pend; ++pit) {
504                         InsetList::iterator it = pit->insetlist.begin();
505                         InsetList::iterator const end = pit->insetlist.end();
506                         for (; it != end; ++it) {
507                                 if (it->inset == inset) {
508                                         lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
509                                         text_.setCursorIntern(pit, it->pos);
510                                         lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
511                                         lyxerr << "bv: " << bv << " inset: " << inset << endl;
512                                         lockInset(bv, inset);
513                                         lyxerr << "InsetText::lockInsetInInset: 1 c" << endl;
514                                         return true;
515                                 }
516                                 if (it->inset->getInsetFromID(id)) {
517                                         lyxerr << "InsetText::lockInsetInInset: 2" << endl;
518                                         text_.setCursorIntern(pit, it->pos);
519                                         it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
520                                         return the_locking_inset->lockInsetInInset(bv, inset);
521                                 }
522                         }
523                 }
524                 lyxerr << "InsetText::lockInsetInInset: 3" << endl;
525                 return false;
526         }
527         if (inset == cpar()->getInset(cpos())) {
528                 lyxerr[Debug::INSETS] << "OK" << endl;
529                 lockInset(bv, inset);
530                 return true;
531         }
532
533         if (the_locking_inset && the_locking_inset == inset) {
534                 if (cpar() == inset_par && cpos() == inset_pos) {
535                         lyxerr[Debug::INSETS] << "OK" << endl;
536                         inset_x = cix() - top_x + drawTextXOffset;
537                         inset_y = ciy() + drawTextYOffset;
538                 } else {
539                         lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
540                 }
541         } else if (the_locking_inset) {
542                 lyxerr[Debug::INSETS] << "MAYBE" << endl;
543                 return the_locking_inset->lockInsetInInset(bv, inset);
544         }
545         lyxerr[Debug::INSETS] << "NOT OK" << endl;
546         return false;
547 }
548
549
550 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
551                                    bool lr)
552 {
553         if (!the_locking_inset)
554                 return false;
555         if (the_locking_inset == inset) {
556                 the_locking_inset->insetUnlock(bv);
557                 getLyXText(bv)->updateInset(inset);
558                 the_locking_inset = 0;
559                 if (lr)
560                         moveRightIntern(bv, true, false);
561                 old_par = paragraphs.end(); // force layout setting
562                 if (scroll())
563                         scroll(bv, 0.0F);
564                 else
565                         updateLocal(bv, false);
566                 return true;
567         }
568         return the_locking_inset->unlockInsetInInset(bv, inset, lr);
569 }
570
571
572 bool InsetText::updateInsetInInset(BufferView * bv, InsetOld * inset)
573 {
574         if (!autoBreakRows && paragraphs.size() > 1)
575                 collapseParagraphs(bv);
576
577         if (inset == this)
578                 return true;
579
580         if (inset->owner() != this) {
581                 bool found = false;
582                 UpdatableInset * tl_inset = the_locking_inset;
583                 if (tl_inset)
584                         found = tl_inset->updateInsetInInset(bv, inset);
585                 if (!found) {
586                         tl_inset = static_cast<UpdatableInset *>(inset);
587                         while(tl_inset->owner() && tl_inset->owner() != this)
588                                 tl_inset = static_cast<UpdatableInset *>(tl_inset->owner());
589                         if (!tl_inset->owner())
590                                 return false;
591                         found = tl_inset->updateInsetInInset(bv, inset);
592                 } else {
593                         text_.updateInset(tl_inset);
594                         setUpdateStatus(FULL);
595                 }
596                 return found;
597         }
598         bool found = text_.updateInset(inset);
599         if (found) {
600                 setUpdateStatus(FULL);
601                 if (the_locking_inset &&
602                     cpar() == inset_par && cpos() == inset_pos)
603                 {
604                         inset_x = cix() - top_x + drawTextXOffset;
605                         inset_y = ciy() + drawTextYOffset;
606                 }
607         }
608         return found;
609 }
610
611
612 void InsetText::lfunMousePress(FuncRequest const & cmd)
613 {
614         no_selection = true;
615
616         // use this to check mouse motion for selection!
617         mouse_x = cmd.x;
618         mouse_y = cmd.y;
619
620         BufferView * bv = cmd.view();
621         FuncRequest cmd1 = cmd;
622         cmd1.x -= inset_x;
623         cmd1.y -= inset_y;
624         if (!locked)
625                 lockInset(bv);
626
627         int tmp_x = cmd.x - drawTextXOffset;
628         int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
629         InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
630
631         if (the_locking_inset) {
632                 if (the_locking_inset == inset) {
633                         the_locking_inset->localDispatch(cmd1);
634                         return;
635                 }
636                 // otherwise only unlock the_locking_inset
637                 the_locking_inset->insetUnlock(bv);
638                 the_locking_inset = 0;
639         }
640         if (!inset)
641                 no_selection = false;
642
643         if (bv->theLockingInset()) {
644                 if (isHighlyEditableInset(inset)) {
645                         // We just have to lock the inset before calling a
646                         // PressEvent on it!
647                         UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
648                         if (!bv->lockInset(uinset)) {
649                                 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
650                         }
651                         inset->localDispatch(cmd1);
652                         if (the_locking_inset)
653                                 updateLocal(bv, false);
654                         return;
655                 }
656         }
657         if (!inset) {
658                 bool paste_internally = false;
659                 if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
660                         localDispatch(FuncRequest(bv, LFUN_COPY));
661                         paste_internally = true;
662                 }
663                 int old_top_y = text_.top_y();
664
665                 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
666                                              cmd.y + dim_.asc);
667                 // set the selection cursor!
668                 text_.selection.cursor = text_.cursor;
669                 text_.cursor.x_fix(text_.cursor.x());
670
671                 text_.clearSelection();
672                 updateLocal(bv, false);
673
674                 bv->owner()->setLayout(cpar()->layout()->name());
675
676                 // we moved the view we cannot do mouse selection in this case!
677                 if (getLyXText(bv)->top_y() != old_top_y)
678                         no_selection = true;
679                 old_par = cpar();
680                 // Insert primary selection with middle mouse
681                 // if there is a local selection in the current buffer,
682                 // insert this
683                 if (cmd.button() == mouse_button::button2) {
684                         if (paste_internally)
685                                 localDispatch(FuncRequest(bv, LFUN_PASTE));
686                         else
687                                 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
688                 }
689         } else {
690                 getLyXText(bv)->clearSelection();
691         }
692 }
693
694
695 bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
696 {
697         BufferView * bv = cmd.view();
698         FuncRequest cmd1 = cmd;
699         cmd1.x -= inset_x;
700         cmd1.y -= inset_y;
701
702         no_selection = true;
703         if (the_locking_inset)
704                 return the_locking_inset->localDispatch(cmd1);
705
706         int tmp_x = cmd.x - drawTextXOffset;
707         int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
708         InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
709         bool ret = false;
710         if (inset) {
711 // This code should probably be removed now. Simple insets
712 // (!highlyEditable) can actually take the localDispatch,
713 // and turn it into edit() if necessary. But we still
714 // need to deal properly with the whole relative vs.
715 // absolute mouse co-ords thing in a realiable, sensible way
716 #if 0
717                 if (isHighlyEditableInset(inset))
718                         ret = inset->localDispatch(cmd1);
719                 else {
720                         inset_x = cix(bv) - top_x + drawTextXOffset;
721                         inset_y = ciy() + drawTextYOffset;
722                         cmd1.x = cmd.x - inset_x;
723                         cmd1.y = cmd.x - inset_y;
724                         inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
725                         ret = true;
726                 }
727 #endif
728                 ret = inset->localDispatch(cmd1);
729                 updateLocal(bv, false);
730
731         }
732         return ret;
733 }
734
735
736 void InsetText::lfunMouseMotion(FuncRequest const & cmd)
737 {
738         FuncRequest cmd1 = cmd;
739         cmd1.x -= inset_x;
740         cmd1.y -= inset_y;
741
742         if (the_locking_inset) {
743                 the_locking_inset->localDispatch(cmd1);
744                 return;
745         }
746
747         if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
748                 return;
749
750         BufferView * bv = cmd.view();
751         LyXCursor cur = text_.cursor;
752         text_.setCursorFromCoordinates
753                 (cmd.x - drawTextXOffset, cmd.y + dim_.asc);
754         text_.cursor.x_fix(text_.cursor.x());
755         if (cur == text_.cursor)
756                 return;
757         text_.setSelection();
758         updateLocal(bv, false);
759 }
760
761
762 InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
763 {
764         BufferView * bv = cmd.view();
765         setViewCache(bv);
766
767         switch (cmd.action) {
768         case LFUN_INSET_EDIT: {
769                 UpdatableInset::localDispatch(cmd);
770
771                 if (!bv->lockInset(this)) {
772                         lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
773                         return DISPATCHED;
774                 }
775
776                 locked = true;
777                 the_locking_inset = 0;
778                 inset_pos = 0;
779                 inset_x = 0;
780                 inset_y = 0;
781                 inset_boundary = false;
782                 inset_par = paragraphs.end();
783                 old_par = paragraphs.end();
784
785
786                 if (cmd.argument.size()) {
787                         if (cmd.argument == "left")
788                                 text_.setCursorIntern(paragraphs.begin(), 0);
789                         else {
790                                 ParagraphList::iterator it = boost::prior(paragraphs.end());
791                                 text_.setCursor(it, it->size());
792                         }
793                 } else {
794                         int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
795                         // we put here -1 and not button as now the button in the
796                         // edit call should not be needed we will fix this in 1.3.x
797                         // cycle hopefully (Jug 20020509)
798                         // FIXME: GUII I've changed this to none: probably WRONG
799                         if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
800                                 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
801                                                                         cmd.y + dim_.asc);
802                                 text_.cursor.x_fix(text_.cursor.x());
803                         }
804                 }
805
806                 text_.clearSelection();
807                 finishUndo();
808
809                 // If the inset is empty set the language of the current font to the
810                 // language to the surronding text (if different).
811                 if (paragraphs.begin()->empty() &&
812                     paragraphs.size() == 1 &&
813                     bv->getParentLanguage(this) != text_.current_font.language())
814                 {
815                         LyXFont font(LyXFont::ALL_IGNORE);
816                         font.setLanguage(bv->getParentLanguage(this));
817                         setFont(bv, font, false);
818                 }
819
820                 updateLocal(bv, false);
821                 // Tell the paragraph dialog that we've entered an insettext.
822                 bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
823                 return DISPATCHED;
824         }
825
826         case LFUN_MOUSE_PRESS:
827                 lfunMousePress(cmd);
828                 return DISPATCHED;
829
830         case LFUN_MOUSE_MOTION:
831                 lfunMouseMotion(cmd);
832                 return DISPATCHED;
833
834         case LFUN_MOUSE_RELEASE:
835                 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
836
837         default:
838                 break;
839         }
840
841         bool was_empty = (paragraphs.begin()->empty() &&
842                           paragraphs.size() == 1);
843
844         no_selection = false;
845         RESULT result = UpdatableInset::localDispatch(cmd);
846         if (result != UNDISPATCHED)
847                 return DISPATCHED;
848
849         result = DISPATCHED;
850         if (cmd.action < 0 && cmd.argument.empty())
851                 return FINISHED;
852
853         if (the_locking_inset) {
854                 result = the_locking_inset->localDispatch(cmd);
855                 if (result == DISPATCHED_NOUPDATE)
856                         return result;
857                 if (result == DISPATCHED) {
858                         updateLocal(bv, false);
859                         return result;
860                 }
861                 if (result >= FINISHED) {
862                         switch (result) {
863                         case FINISHED_RIGHT:
864                                 moveRightIntern(bv, false, false);
865                                 result = DISPATCHED;
866                                 break;
867                         case FINISHED_UP:
868                                 result = moveUp(bv);
869                                 if (result >= FINISHED) {
870                                         updateLocal(bv, false);
871                                         bv->unlockInset(this);
872                                 }
873                                 break;
874                         case FINISHED_DOWN:
875                                 result = moveDown(bv);
876                                 if (result >= FINISHED) {
877                                         updateLocal(bv, false);
878                                         bv->unlockInset(this);
879                                 }
880                                 break;
881                         default:
882                                 result = DISPATCHED;
883                                 break;
884                         }
885                         the_locking_inset = 0;
886                         updateLocal(bv, false);
887                         // make sure status gets reset immediately
888                         bv->owner()->clearMessage();
889                         return result;
890                 }
891         }
892         bool updwhat = false;
893         bool updflag = false;
894
895         switch (cmd.action) {
896
897         // Normal chars
898         case LFUN_SELFINSERT:
899                 if (bv->buffer()->isReadonly()) {
900 //          setErrorMessage(N_("Document is read only"));
901                         break;
902                 }
903                 if (!cmd.argument.empty()) {
904                         /* Automatically delete the currently selected
905                          * text and replace it with what is being
906                          * typed in now. Depends on lyxrc settings
907                          * "auto_region_delete", which defaults to
908                          * true (on). */
909 #if 0
910                         // This should not be needed here and is also WRONG!
911                         recordUndo(bv, Undo::INSERT, text_.cursor.par());
912 #endif
913                         bv->switchKeyMap();
914                         if (lyxrc.auto_region_delete) {
915                                 if (text_.selection.set()) {
916                                         text_.cutSelection(false, false);
917                                 }
918                         }
919                         text_.clearSelection();
920                         for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
921                                 bv->owner()->getIntl().getTransManager().
922                                         TranslateAndInsert(cmd.argument[i], &text_);
923                         }
924                 }
925                 text_.selection.cursor = text_.cursor;
926                 updwhat = true;
927                 updflag = true;
928                 result = DISPATCHED_NOUPDATE;
929                 break;
930
931         // cursor movements that need special handling
932
933         case LFUN_RIGHT:
934                 result = moveRight(bv);
935                 finishUndo();
936                 updwhat = true;
937                 break;
938         case LFUN_LEFT:
939                 finishUndo();
940                 result = moveLeft(bv);
941                 updwhat = true;
942                 break;
943         case LFUN_DOWN:
944                 finishUndo();
945                 result = moveDown(bv);
946                 updwhat = true;
947                 break;
948         case LFUN_UP:
949                 finishUndo();
950                 result = moveUp(bv);
951                 updwhat = true;
952                 break;
953
954         case LFUN_PRIOR:
955                 if (crow() == text_.rows().begin())
956                         result = FINISHED_UP;
957                 else {
958                         text_.cursorPrevious();
959                         text_.clearSelection();
960                         result = DISPATCHED_NOUPDATE;
961                 }
962                 updwhat = true;
963                 break;
964
965         case LFUN_NEXT:
966                 if (boost::next(crow()) == text_.rows().end())
967                         result = FINISHED_DOWN;
968                 else {
969                         text_.cursorNext();
970                         text_.clearSelection();
971                         result = DISPATCHED_NOUPDATE;
972                 }
973                 updwhat = true;
974                 break;
975
976         case LFUN_BACKSPACE: {
977                 if (text_.selection.set())
978                         text_.cutSelection(true, false);
979                 else
980                         text_.backspace();
981                 updwhat = true;
982                 updflag = true;
983                 break;
984         }
985
986         case LFUN_DELETE: {
987                 if (text_.selection.set()) {
988                         text_.cutSelection(true, false);
989                 } else {
990                         text_.Delete();
991                 }
992                 updwhat = true;
993                 updflag = true;
994                 break;
995         }
996
997         case LFUN_CUT: {
998                 text_.cutSelection(true, true);
999                 updwhat = true;
1000                 updflag = true;
1001                 break;
1002         }
1003
1004         case LFUN_COPY:
1005                 finishUndo();
1006                 text_.copySelection();
1007                 updwhat = true;
1008                 break;
1009
1010         case LFUN_PASTESELECTION:
1011         {
1012                 string const clip(bv->getClipboard());
1013
1014                 if (clip.empty())
1015                         break;
1016                 if (cmd.argument == "paragraph") {
1017                         text_.insertStringAsParagraphs(clip);
1018                 } else {
1019                         text_.insertStringAsLines(clip);
1020                 }
1021                 // bug 393
1022                 text_.clearSelection();
1023
1024                 updwhat = true;
1025                 updflag = true;
1026                 break;
1027         }
1028
1029         case LFUN_PASTE: {
1030                 if (!autoBreakRows) {
1031                         if (CutAndPaste::nrOfParagraphs() > 1) {
1032 #ifdef WITH_WARNINGS
1033 #warning FIXME horrendously bad UI
1034 #endif
1035                                 Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
1036                                 break;
1037                         }
1038                 }
1039
1040                 replaceSelection(bv->getLyXText());
1041                 size_t sel_index = 0;
1042                 string const & arg = cmd.argument;
1043                 if (isStrUnsignedInt(arg)) {
1044                         size_t const paste_arg = strToUnsignedInt(arg);
1045 #warning FIXME Check if the arg is in the domain of available selections.
1046                         sel_index = paste_arg;
1047                 }
1048                 text_.pasteSelection(sel_index);
1049                 // bug 393
1050                 text_.clearSelection();
1051                 updwhat = true;
1052                 updflag = true;
1053                 break;
1054         }
1055
1056         case LFUN_BREAKPARAGRAPH:
1057                 if (!autoBreakRows) {
1058                         result = DISPATCHED;
1059                         break;
1060                 }
1061                 replaceSelection(bv->getLyXText());
1062                 text_.breakParagraph(paragraphs, 0);
1063                 updwhat = true;
1064                 updflag = true;
1065                 break;
1066
1067         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1068                 if (!autoBreakRows) {
1069                         result = DISPATCHED;
1070                         break;
1071                 }
1072                 replaceSelection(bv->getLyXText());
1073                 text_.breakParagraph(paragraphs, 1);
1074                 updwhat = true;
1075                 updflag = true;
1076                 break;
1077
1078         case LFUN_BREAKLINE: {
1079                 if (!autoBreakRows) {
1080                         result = DISPATCHED;
1081                         break;
1082                 }
1083
1084                 replaceSelection(bv->getLyXText());
1085                 text_.insertInset(new InsetNewline);
1086                 updwhat = true;
1087                 updflag = true;
1088                 break;
1089         }
1090
1091         case LFUN_LAYOUT:
1092                 // do not set layouts on non breakable textinsets
1093                 if (autoBreakRows) {
1094                         string cur_layout = cpar()->layout()->name();
1095
1096                         // Derive layout number from given argument (string)
1097                         // and current buffer's textclass (number). */
1098                         LyXTextClass const & tclass =
1099                                 bv->buffer()->params.getLyXTextClass();
1100                         string layout = cmd.argument;
1101                         bool hasLayout = tclass.hasLayout(layout);
1102
1103                         // If the entry is obsolete, use the new one instead.
1104                         if (hasLayout) {
1105                                 string const & obs =
1106                                         tclass[layout]->obsoleted_by();
1107                                 if (!obs.empty())
1108                                         layout = obs;
1109                         }
1110
1111                         // see if we found the layout number:
1112                         if (!hasLayout) {
1113                                 FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
1114                                 bv->owner()->dispatch(lf);
1115                                 break;
1116                         }
1117
1118                         if (cur_layout != layout) {
1119                                 cur_layout = layout;
1120                                 text_.setLayout(layout);
1121                                 bv->owner()->setLayout(cpar()->layout()->name());
1122                                 updwhat = true;
1123                                 updflag = true;
1124                         }
1125                 } else {
1126                         // reset the layout box
1127                         bv->owner()->setLayout(cpar()->layout()->name());
1128                 }
1129                 break;
1130         case LFUN_PARAGRAPH_SPACING:
1131                 // This one is absolutely not working. When fiddling with this
1132                 // it also seems to me that the paragraphs inside the insettext
1133                 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1134                 // FIXME: how old is this comment ? ...
1135         {
1136                 ParagraphList::iterator pit = text_.cursor.par();
1137                 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
1138                 float cur_value = 1.0;
1139                 if (cur_spacing == Spacing::Other) {
1140                         cur_value = pit->params().spacing().getValue();
1141                 }
1142
1143                 istringstream istr(STRCONV(cmd.argument));
1144                 string tmp;
1145                 istr >> tmp;
1146                 Spacing::Space new_spacing = cur_spacing;
1147                 float new_value = cur_value;
1148                 if (tmp.empty()) {
1149                         lyxerr << "Missing argument to `paragraph-spacing'"
1150                                    << endl;
1151                 } else if (tmp == "single") {
1152                         new_spacing = Spacing::Single;
1153                 } else if (tmp == "onehalf") {
1154                         new_spacing = Spacing::Onehalf;
1155                 } else if (tmp == "double") {
1156                         new_spacing = Spacing::Double;
1157                 } else if (tmp == "other") {
1158                         new_spacing = Spacing::Other;
1159                         float tmpval = 0.0;
1160                         istr >> tmpval;
1161                         lyxerr << "new_value = " << tmpval << endl;
1162                         if (tmpval != 0.0)
1163                                 new_value = tmpval;
1164                 } else if (tmp == "default") {
1165                         new_spacing = Spacing::Default;
1166                 } else {
1167                         lyxerr << _("Unknown spacing argument: ")
1168                                    << cmd.argument << endl;
1169                 }
1170                 if (cur_spacing != new_spacing || cur_value != new_value) {
1171                         pit->params().spacing(Spacing(new_spacing, new_value));
1172                         updwhat = true;
1173                         updflag = true;
1174                 }
1175         }
1176         break;
1177
1178         // These need to do repaints but don't require
1179         // special handling otherwise. A *lot* of the
1180         // above could probably be done similarly ...
1181
1182         case LFUN_HOME:
1183         case LFUN_END:
1184         case LFUN_WORDLEFT:
1185         case LFUN_WORDRIGHT:
1186         // these two are really unhandled ...
1187         case LFUN_ENDBUF:
1188         case LFUN_BEGINNINGBUF:
1189                 updwhat = true;
1190                 if (!bv->dispatch(cmd))
1191                         result = UNDISPATCHED;
1192                 break;
1193
1194         case LFUN_RIGHTSEL:
1195         case LFUN_UPSEL:
1196         case LFUN_DOWNSEL:
1197         case LFUN_LEFTSEL:
1198         case LFUN_HOMESEL:
1199         case LFUN_ENDSEL:
1200         case LFUN_WORDLEFTSEL:
1201         case LFUN_WORDRIGHTSEL:
1202                 updwhat = true;
1203
1204                 // fallthrough
1205
1206         default:
1207                 if (!bv->dispatch(cmd))
1208                         result = UNDISPATCHED;
1209                 break;
1210         }
1211
1212         if (updwhat)
1213                 updateLocal(bv, updflag);
1214         /// If the action has deleted all text in the inset, we need to change the
1215         // language to the language of the surronding text.
1216         if (!was_empty && paragraphs.begin()->empty() &&
1217             paragraphs.size() == 1) {
1218                 LyXFont font(LyXFont::ALL_IGNORE);
1219                 font.setLanguage(bv->getParentLanguage(this));
1220                 setFont(bv, font, false);
1221         }
1222
1223         if (result >= FINISHED)
1224                 bv->unlockInset(this);
1225
1226         if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
1227                 result = DISPATCHED;
1228         return result;
1229 }
1230
1231
1232 int InsetText::latex(Buffer const * buf, ostream & os,
1233                      LatexRunParams const & runparams) const
1234 {
1235         TexRow texrow;
1236         latexParagraphs(buf, paragraphs, os, texrow, runparams);
1237         return texrow.rows();
1238 }
1239
1240
1241 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1242 {
1243         unsigned int lines = 0;
1244
1245         ParagraphList::const_iterator beg = paragraphs.begin();
1246         ParagraphList::const_iterator end = paragraphs.end();
1247         ParagraphList::const_iterator it = beg;
1248         for (; it != end; ++it) {
1249                 string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
1250                 lines += lyx::count(tmp.begin(), tmp.end(), '\n');
1251                 os << tmp;
1252         }
1253         return lines;
1254 }
1255
1256
1257 int InsetText::linuxdoc(Buffer const * buf, ostream & os) const
1258 {
1259         ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1260         ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1261
1262         // There is a confusion between the empty paragraph and the default paragraph
1263         // The default paragraph is <p></p>, the empty paragraph is *empty*
1264         // Since none of the floats of linuxdoc accepts standard paragraphs
1265         // I disable them. I don't expect problems. (jamatos 2003/07/27)
1266         for (; pit != pend; ++pit) {
1267                 const string name = pit->layout()->latexname();
1268                 if (name != "p")
1269                         sgml::openTag(os, 1, 0, name);
1270                 buf->simpleLinuxDocOnePar(os, pit, 0);
1271                 if (name != "p")
1272                         sgml::closeTag(os, 1, 0, name);
1273         }
1274         return 0;
1275 }
1276
1277
1278 int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1279 {
1280         unsigned int lines = 0;
1281
1282         vector<string> environment_stack(10);
1283         vector<string> environment_inner(10);
1284
1285         int const command_depth = 0;
1286         string item_name;
1287
1288         Paragraph::depth_type depth = 0; // paragraph depth
1289
1290         ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1291         ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1292
1293         for (; pit != pend; ++pit) {
1294                 string sgmlparam;
1295                 int desc_on = 0; // description mode
1296
1297                 LyXLayout_ptr const & style = pit->layout();
1298
1299                 // environment tag closing
1300                 for (; depth > pit->params().depth(); --depth) {
1301                         if (environment_inner[depth] != "!-- --") {
1302                                 item_name = "listitem";
1303                                 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1304                                 if (environment_inner[depth] == "varlistentry")
1305                                         lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
1306                         }
1307                         lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1308                         environment_stack[depth].erase();
1309                         environment_inner[depth].erase();
1310                 }
1311
1312                 if (depth == pit->params().depth()
1313                    && environment_stack[depth] != style->latexname()
1314                    && !environment_stack[depth].empty()) {
1315                         if (environment_inner[depth] != "!-- --") {
1316                                 item_name= "listitem";
1317                                 lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
1318                                 if (environment_inner[depth] == "varlistentry")
1319                                         lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1320                         }
1321
1322                         lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1323
1324                         environment_stack[depth].erase();
1325                         environment_inner[depth].erase();
1326                 }
1327
1328                 // Write opening SGML tags.
1329                 switch (style->latextype) {
1330                 case LATEX_PARAGRAPH:
1331                         lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1332                         break;
1333
1334                 case LATEX_COMMAND:
1335                         buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
1336                         return -1;
1337                         break;
1338
1339                 case LATEX_ENVIRONMENT:
1340                 case LATEX_ITEM_ENVIRONMENT:
1341                         if (depth < pit->params().depth()) {
1342                                 depth = pit->params().depth();
1343                                 environment_stack[depth].erase();
1344                         }
1345
1346                         if (environment_stack[depth] != style->latexname()) {
1347                                 if (environment_stack.size() == depth + 1) {
1348                                         environment_stack.push_back("!-- --");
1349                                         environment_inner.push_back("!-- --");
1350                                 }
1351                                 environment_stack[depth] = style->latexname();
1352                                 environment_inner[depth] = "!-- --";
1353                                 lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1354                         } else {
1355                                 if (environment_inner[depth] != "!-- --") {
1356                                         item_name= "listitem";
1357                                         lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1358                                         if (environment_inner[depth] == "varlistentry")
1359                                                 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1360                                 }
1361                         }
1362
1363                         if (style->latextype == LATEX_ENVIRONMENT) {
1364                                 if (!style->latexparam().empty()) {
1365                                         if (style->latexparam() == "CDATA")
1366                                                 os << "<![CDATA[";
1367                                         else
1368                                           lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
1369                                 }
1370                                 break;
1371                         }
1372
1373                         desc_on = (style->labeltype == LABEL_MANUAL);
1374
1375                         environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1376                         lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
1377
1378                         item_name = desc_on ? "term" : "para";
1379                         lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
1380
1381                         break;
1382                 default:
1383                         lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1384                         break;
1385                 }
1386
1387                 buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
1388
1389                 string end_tag;
1390                 // write closing SGML tags
1391                 switch (style->latextype) {
1392                 case LATEX_ENVIRONMENT:
1393                         if (!style->latexparam().empty()) {
1394                                 if (style->latexparam() == "CDATA")
1395                                         os << "]]>";
1396                                 else
1397                                         lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
1398                         }
1399                         break;
1400                 case LATEX_ITEM_ENVIRONMENT:
1401                         if (desc_on == 1) break;
1402                         end_tag= "para";
1403                         lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
1404                         break;
1405                 case LATEX_PARAGRAPH:
1406                         lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1407                         break;
1408                 default:
1409                         lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1410                         break;
1411                 }
1412         }
1413
1414         // Close open tags
1415         for (int d = depth; d >= 0; --d) {
1416                 if (!environment_stack[depth].empty()) {
1417                         if (environment_inner[depth] != "!-- --") {
1418                                 item_name = "listitem";
1419                                 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1420                                if (environment_inner[depth] == "varlistentry")
1421                                        lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1422                         }
1423
1424                         lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1425                 }
1426         }
1427
1428         return lines;
1429 }
1430
1431
1432 void InsetText::validate(LaTeXFeatures & features) const
1433 {
1434         for_each(paragraphs.begin(), paragraphs.end(),
1435                  boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1436 }
1437
1438
1439 void InsetText::getCursor(BufferView & bv, int & x, int & y) const
1440 {
1441         if (the_locking_inset) {
1442                 the_locking_inset->getCursor(bv, x, y);
1443                 return;
1444         }
1445         x = cx();
1446         y = cy() + InsetText::y();
1447 }
1448
1449
1450 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
1451 {
1452         if (the_locking_inset) {
1453                 the_locking_inset->getCursorPos(bv, x, y);
1454                 return;
1455         }
1456         x = cx() - top_x - TEXT_TO_INSET_OFFSET;
1457         y = cy() - TEXT_TO_INSET_OFFSET;
1458 }
1459
1460
1461 int InsetText::insetInInsetY() const
1462 {
1463         if (!the_locking_inset)
1464                 return 0;
1465
1466         return inset_y + the_locking_inset->insetInInsetY();
1467 }
1468
1469
1470 void InsetText::fitInsetCursor(BufferView * bv) const
1471 {
1472         if (the_locking_inset) {
1473                 the_locking_inset->fitInsetCursor(bv);
1474                 return;
1475         }
1476
1477         LyXFont const font = text_.getFont(cpar(), cpos());
1478
1479         int const asc = font_metrics::maxAscent(font);
1480         int const desc = font_metrics::maxDescent(font);
1481
1482         if (bv->fitLockedInsetCursor(cx(), cy(), asc, desc))
1483                 need_update |= FULL;
1484 }
1485
1486
1487 InsetOld::RESULT
1488 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1489 {
1490         if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1491                 return moveLeftIntern(bv, false, activate_inset, selecting);
1492         else
1493                 return moveRightIntern(bv, true, activate_inset, selecting);
1494 }
1495
1496
1497 InsetOld::RESULT
1498 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1499 {
1500         if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1501                 return moveRightIntern(bv, true, activate_inset, selecting);
1502         else
1503                 return moveLeftIntern(bv, false, activate_inset, selecting);
1504 }
1505
1506
1507 InsetOld::RESULT
1508 InsetText::moveRightIntern(BufferView * bv, bool front,
1509                            bool activate_inset, bool selecting)
1510 {
1511         ParagraphList::iterator c_par = cpar();
1512
1513         if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
1514                 return FINISHED_RIGHT;
1515         if (activate_inset && checkAndActivateInset(bv, front))
1516                 return DISPATCHED;
1517         text_.cursorRight(bv);
1518         if (!selecting)
1519                 text_.clearSelection();
1520         return DISPATCHED_NOUPDATE;
1521 }
1522
1523
1524 InsetOld::RESULT
1525 InsetText::moveLeftIntern(BufferView * bv, bool front,
1526                           bool activate_inset, bool selecting)
1527 {
1528         if (cpar() == paragraphs.begin() && cpos() <= 0)
1529                 return FINISHED;
1530         text_.cursorLeft(bv);
1531         if (!selecting)
1532                 text_.clearSelection();
1533         if (activate_inset && checkAndActivateInset(bv, front))
1534                 return DISPATCHED;
1535         return DISPATCHED_NOUPDATE;
1536 }
1537
1538
1539 InsetOld::RESULT InsetText::moveUp(BufferView * bv)
1540 {
1541         if (crow() == text_.rows().begin())
1542                 return FINISHED_UP;
1543         text_.cursorUp(bv);
1544         text_.clearSelection();
1545         return DISPATCHED_NOUPDATE;
1546 }
1547
1548
1549 InsetOld::RESULT InsetText::moveDown(BufferView * bv)
1550 {
1551         if (boost::next(crow()) == text_.rows().end())
1552                 return FINISHED_DOWN;
1553         text_.cursorDown(bv);
1554         text_.clearSelection();
1555         return DISPATCHED_NOUPDATE;
1556 }
1557
1558
1559 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
1560 {
1561         if (the_locking_inset) {
1562                 if (the_locking_inset->insetAllowed(inset))
1563                         return the_locking_inset->insertInset(bv, inset);
1564                 return false;
1565         }
1566         inset->setOwner(this);
1567         text_.insertInset(inset);
1568         bv->fitCursor();
1569         updateLocal(bv, true);
1570         return true;
1571 }
1572
1573
1574 bool InsetText::insetAllowed(InsetOld::Code code) const
1575 {
1576         // in_insetAllowed is a really gross hack,
1577         // to allow us to call the owner's insetAllowed
1578         // without stack overflow, which can happen
1579         // when the owner uses InsetCollapsable::insetAllowed()
1580         bool ret = true;
1581         if (in_insetAllowed)
1582                 return ret;
1583         in_insetAllowed = true;
1584         if (the_locking_inset)
1585                 ret = the_locking_inset->insetAllowed(code);
1586         else if (owner())
1587                 ret = owner()->insetAllowed(code);
1588         in_insetAllowed = false;
1589         return ret;
1590 }
1591
1592
1593 UpdatableInset * InsetText::getLockingInset() const
1594 {
1595         return the_locking_inset ? the_locking_inset->getLockingInset() :
1596                 const_cast<InsetText *>(this);
1597 }
1598
1599
1600 UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c)
1601 {
1602         if (c == lyxCode())
1603                 return this;
1604         if (the_locking_inset)
1605                 return the_locking_inset->getFirstLockingInsetOfType(c);
1606         return 0;
1607 }
1608
1609
1610 bool InsetText::showInsetDialog(BufferView * bv) const
1611 {
1612         if (the_locking_inset)
1613                 return the_locking_inset->showInsetDialog(bv);
1614         return false;
1615 }
1616
1617
1618 void InsetText::getLabelList(std::vector<string> & list) const
1619 {
1620         ParagraphList::const_iterator pit = paragraphs.begin();
1621         ParagraphList::const_iterator pend = paragraphs.end();
1622         for (; pit != pend; ++pit) {
1623                 InsetList::const_iterator beg = pit->insetlist.begin();
1624                 InsetList::const_iterator end = pit->insetlist.end();
1625                 for (; beg != end; ++beg)
1626                         beg->inset->getLabelList(list);
1627         }
1628 }
1629
1630
1631 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1632                         bool selectall)
1633 {
1634         if (the_locking_inset) {
1635                 the_locking_inset->setFont(bv, font, toggleall, selectall);
1636                 return;
1637         }
1638
1639         if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
1640             || cpar()->empty()) {
1641                 text_.setFont(font, toggleall);
1642                 return;
1643         }
1644
1645
1646         if (text_.selection.set())
1647                 recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
1648
1649         if (selectall) {
1650                 text_.cursorTop();
1651                 text_.selection.cursor = text_.cursor;
1652                 text_.cursorBottom();
1653                 text_.setSelection();
1654         }
1655
1656         text_.toggleFree(font, toggleall);
1657
1658         if (selectall)
1659                 text_.clearSelection();
1660
1661         bv->fitCursor();
1662         updateLocal(bv, true);
1663 }
1664
1665
1666 bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
1667 {
1668         InsetOld * inset = cpar()->getInset(cpos());
1669         if (!isHighlyEditableInset(inset))
1670                 return false;
1671         FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
1672         inset->localDispatch(cmd);
1673         if (!the_locking_inset)
1674                 return false;
1675         updateLocal(bv, false);
1676         return true;
1677 }
1678
1679
1680 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1681                                       mouse_button::state button)
1682 {
1683         x -= drawTextXOffset;
1684         int dummyx = x;
1685         int dummyy = y + dim_.asc;
1686         InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
1687         // we only do the edit() call if the inset was hit by the mouse
1688         // or if it is a highly editable inset. So we should call this
1689         // function from our own edit with button < 0.
1690         // FIXME: GUII jbl. I've changed this to ::none for now which is probably
1691         // WRONG
1692         if (button == mouse_button::none && !isHighlyEditableInset(inset))
1693                 return false;
1694
1695         if (!inset)
1696                 return false;
1697         if (x < 0)
1698                 x = dim_.wid;
1699         if (y < 0)
1700                 y = dim_.des;
1701         inset_x = cix() - top_x + drawTextXOffset;
1702         inset_y = ciy() + drawTextYOffset;
1703         FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
1704         inset->localDispatch(cmd);
1705         if (!the_locking_inset)
1706                 return false;
1707         updateLocal(bv, false);
1708         return true;
1709 }
1710
1711
1712 void InsetText::setParagraphData(ParagraphList const & plist)
1713 {
1714         // we have to unlock any locked inset otherwise we're in troubles
1715         the_locking_inset = 0;
1716
1717         // But it it makes no difference that is a lot better.
1718 #warning FIXME.
1719         // See if this can be simplified when std::list is in effect.
1720         paragraphs.clear();
1721
1722         ParagraphList::const_iterator it = plist.begin();
1723         ParagraphList::const_iterator end = plist.end();
1724         for (; it != end; ++it) {
1725                 paragraphs.push_back(*it);
1726                 paragraphs.back().setInsetOwner(this);
1727         }
1728
1729         reinitLyXText();
1730         need_update = INIT;
1731 }
1732
1733
1734 void InsetText::markNew(bool track_changes)
1735 {
1736         ParagraphList::iterator pit = paragraphs.begin();
1737         ParagraphList::iterator pend = paragraphs.end();
1738         for (; pit != pend; ++pit) {
1739                 if (track_changes) {
1740                         pit->trackChanges();
1741                 } else {
1742                         // no-op when not tracking
1743                         pit->cleanChanges();
1744                 }
1745         }
1746 }
1747
1748
1749 void InsetText::setText(string const & data, LyXFont const & font)
1750 {
1751         clear(false);
1752         for (unsigned int i = 0; i < data.length(); ++i)
1753                 paragraphs.begin()->insertChar(i, data[i], font);
1754         reinitLyXText();
1755 }
1756
1757
1758 void InsetText::setAutoBreakRows(bool flag)
1759 {
1760         if (flag != autoBreakRows) {
1761                 autoBreakRows = flag;
1762                 if (!flag)
1763                         removeNewlines();
1764                 need_update = INIT;
1765         }
1766 }
1767
1768
1769 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1770 {
1771         if (how != drawFrame_) {
1772                 drawFrame_ = how;
1773                 if (bv)
1774                         updateLocal(bv, false);
1775         }
1776 }
1777
1778
1779 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1780 {
1781         if (frame_color != col) {
1782                 frame_color = col;
1783                 if (bv)
1784                         updateLocal(bv, false);
1785         }
1786 }
1787
1788
1789 int InsetText::cx() const
1790 {
1791         int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1792         if (the_locking_inset) {
1793                 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1794                 if (font.isVisibleRightToLeft())
1795                         x -= the_locking_inset->width();
1796         }
1797         return x;
1798 }
1799
1800
1801 int InsetText::cix() const
1802 {
1803         int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
1804         if (the_locking_inset) {
1805                 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1806                 if (font.isVisibleRightToLeft())
1807                         x -= the_locking_inset->width();
1808         }
1809         return x;
1810 }
1811
1812
1813 int InsetText::cy() const
1814 {
1815         return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
1816 }
1817
1818
1819 int InsetText::ciy() const
1820 {
1821         return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
1822 }
1823
1824
1825 pos_type InsetText::cpos() const
1826 {
1827         return text_.cursor.pos();
1828 }
1829
1830
1831 ParagraphList::iterator InsetText::cpar() const
1832 {
1833         return text_.cursor.par();
1834 }
1835
1836
1837 bool InsetText::cboundary() const
1838 {
1839         return text_.cursor.boundary();
1840 }
1841
1842
1843 RowList::iterator InsetText::crow() const
1844 {
1845         return text_.cursorRow();
1846 }
1847
1848
1849 LyXText * InsetText::getLyXText(BufferView const * bv,
1850                                 bool const recursive) const
1851 {
1852         setViewCache(bv);
1853         if (recursive && the_locking_inset)
1854                 return the_locking_inset->getLyXText(bv, true);
1855         return &text_;
1856 }
1857
1858
1859 void InsetText::setViewCache(BufferView const * bv) const
1860 {
1861         if (bv)
1862                 text_.bv_owner = const_cast<BufferView *>(bv);
1863 }
1864
1865
1866 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1867 {
1868         if (recursive) {
1869                 /// then remove all LyXText in text-insets
1870                 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1871                          const_cast<ParagraphList&>(paragraphs).end(),
1872                          boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
1873         }
1874 }
1875
1876
1877 void InsetText::resizeLyXText(BufferView * bv, bool /*force*/) const
1878 {
1879         if (paragraphs.size() == 1 && paragraphs.begin()->empty())
1880                 return;
1881
1882         if (!bv)
1883                 return;
1884
1885         Assert(bv);
1886         setViewCache(bv);
1887
1888         for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1889                  const_cast<ParagraphList&>(paragraphs).end(),
1890                  boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1891
1892         saveLyXTextState();
1893         text_.init(bv);
1894         restoreLyXTextState();
1895
1896         // seems to be unneeded
1897 #if 1
1898         if (the_locking_inset) {
1899                 inset_x = cix() - top_x + drawTextXOffset;
1900                 inset_y = ciy() + drawTextYOffset;
1901         }
1902
1903         text_.top_y(bv->screen().topCursorVisible(&text_));
1904         if (!owner()) {
1905                 const_cast<InsetText*>(this)->updateLocal(bv, false);
1906                 // this will scroll the screen such that the cursor becomes visible
1907                 bv->updateScrollbar();
1908         } else {
1909                 need_update |= FULL;
1910         }
1911 #endif
1912 }
1913
1914
1915 void InsetText::reinitLyXText() const
1916 {
1917         BufferView * bv = text_.bv_owner;
1918
1919         if (!bv)
1920                 return;
1921
1922         saveLyXTextState();
1923
1924         for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1925                  const_cast<ParagraphList&>(paragraphs).end(),
1926                  boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1927
1928         text_.init(bv);
1929         restoreLyXTextState();
1930         if (the_locking_inset) {
1931                 inset_x = cix() - top_x + drawTextXOffset;
1932                 inset_y = ciy() + drawTextYOffset;
1933         }
1934         text_.top_y(bv->screen().topCursorVisible(&text_));
1935         if (!owner()) {
1936                 // this will scroll the screen such that the cursor becomes visible
1937                 bv->updateScrollbar();
1938         } else {
1939                 need_update = FULL;
1940         }
1941 }
1942
1943
1944 void InsetText::removeNewlines()
1945 {
1946         bool changed = false;
1947
1948         ParagraphList::iterator it = paragraphs.begin();
1949         ParagraphList::iterator end = paragraphs.end();
1950         for (; it != end; ++it) {
1951                 for (int i = 0; i < it->size(); ++i) {
1952                         if (it->isNewline(i)) {
1953                                 changed = true;
1954                                 it->erase(i);
1955                         }
1956                 }
1957         }
1958         if (changed)
1959                 reinitLyXText();
1960 }
1961
1962
1963 int InsetText::scroll(bool recursive) const
1964 {
1965         int sx = UpdatableInset::scroll(false);
1966
1967         if (recursive && the_locking_inset)
1968                 sx += the_locking_inset->scroll(recursive);
1969
1970         return sx;
1971 }
1972
1973
1974 void InsetText::clearSelection(BufferView * bv)
1975 {
1976         getLyXText(bv)->clearSelection();
1977 }
1978
1979
1980 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
1981 {
1982         Painter & pain = bv->painter();
1983         int w = dim_.wid;
1984         int h = dim_.asc + dim_.des;
1985         int ty = baseline - dim_.asc;
1986
1987         if (ty < 0) {
1988                 h += ty;
1989                 ty = 0;
1990         }
1991         if (ty + h > pain.paperHeight())
1992                 h = pain.paperHeight();
1993         if (top_x + drawTextXOffset + w > pain.paperWidth())
1994                 w = pain.paperWidth();
1995         pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
1996         need_update = FULL;
1997 }
1998
1999
2000 ParagraphList * InsetText::getParagraphs(int i) const
2001 {
2002         return (i == 0) ? const_cast<ParagraphList*>(&paragraphs) : 0;
2003 }
2004
2005
2006 LyXCursor const & InsetText::cursor(BufferView * bv) const
2007 {
2008         if (the_locking_inset)
2009                 return the_locking_inset->cursor(bv);
2010         return getLyXText(bv)->cursor;
2011 }
2012
2013
2014 InsetOld * InsetText::getInsetFromID(int id_arg) const
2015 {
2016         if (id_arg == id())
2017                 return const_cast<InsetText *>(this);
2018
2019         ParagraphList::const_iterator pit = paragraphs.begin();
2020         ParagraphList::const_iterator pend = paragraphs.end();
2021         for (; pit != pend; ++pit) {
2022                 InsetList::const_iterator it = pit->insetlist.begin();
2023                 InsetList::const_iterator end = pit->insetlist.end();
2024                 for (; it != end; ++it) {
2025                         if (it->inset->id() == id_arg)
2026                                 return it->inset;
2027                         InsetOld * in = it->inset->getInsetFromID(id_arg);
2028                         if (in)
2029                                 return in;
2030                 }
2031         }
2032         return 0;
2033 }
2034
2035
2036 WordLangTuple const
2037 InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2038 {
2039         WordLangTuple word;
2040         if (the_locking_inset) {
2041                 word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
2042                 if (!word.word().empty()) {
2043                         value += cy();
2044                         return word;
2045                 }
2046                 // we have to go on checking so move cursor to the next char
2047                 text_.cursor.pos(text_.cursor.pos() + 1);
2048         }
2049         word = text_.selectNextWordToSpellcheck(value);
2050         if (word.word().empty())
2051                 bv->unlockInset(const_cast<InsetText *>(this));
2052         else
2053                 value = cy();
2054         return word;
2055 }
2056
2057
2058 void InsetText::selectSelectedWord(BufferView * bv)
2059 {
2060         if (the_locking_inset) {
2061                 the_locking_inset->selectSelectedWord(bv);
2062                 return;
2063         }
2064         getLyXText(bv)->selectSelectedWord();
2065         updateLocal(bv, false);
2066 }
2067
2068
2069 bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
2070 {
2071         if (the_locking_inset) {
2072                 if (the_locking_inset->nextChange(bv, length))
2073                         return true;
2074                 text_.cursorRight(true);
2075         }
2076         lyx::find::SearchResult result =
2077                 lyx::find::findNextChange(bv, &text_, length);
2078
2079         if (result == lyx::find::SR_FOUND) {
2080                 LyXCursor cur = text_.cursor;
2081                 bv->unlockInset(bv->theLockingInset());
2082                 if (bv->lockInset(this))
2083                         locked = true;
2084                 text_.cursor = cur;
2085                 text_.setSelectionRange(length);
2086                 updateLocal(bv, false);
2087         }
2088         return result != lyx::find::SR_NOT_FOUND;
2089 }
2090
2091
2092 bool InsetText::searchForward(BufferView * bv, string const & str,
2093                               bool cs, bool mw)
2094 {
2095         if (the_locking_inset) {
2096                 if (the_locking_inset->searchForward(bv, str, cs, mw))
2097                         return true;
2098                 text_.cursorRight(true);
2099         }
2100         lyx::find::SearchResult result =
2101                 lyx::find::find(bv, &text_, str, true, cs, mw);
2102
2103         if (result == lyx::find::SR_FOUND) {
2104                 LyXCursor cur = text_.cursor;
2105                 bv->unlockInset(bv->theLockingInset());
2106                 if (bv->lockInset(this))
2107                         locked = true;
2108                 text_.cursor = cur;
2109                 text_.setSelectionRange(str.length());
2110                 updateLocal(bv, false);
2111         }
2112         return result != lyx::find::SR_NOT_FOUND;
2113 }
2114
2115
2116 bool InsetText::searchBackward(BufferView * bv, string const & str,
2117                                bool cs, bool mw)
2118 {
2119         if (the_locking_inset) {
2120                 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2121                         return true;
2122         }
2123         if (!locked) {
2124                 ParagraphList::iterator pit = paragraphs.begin();
2125                 ParagraphList::iterator pend = paragraphs.end();
2126
2127                 while (boost::next(pit) != pend)
2128                         ++pit;
2129
2130                 text_.setCursor(pit, pit->size());
2131         }
2132         lyx::find::SearchResult result =
2133                 lyx::find::find(bv, &text_, str, false, cs, mw);
2134
2135         if (result == lyx::find::SR_FOUND) {
2136                 LyXCursor cur = text_.cursor;
2137                 bv->unlockInset(bv->theLockingInset());
2138                 if (bv->lockInset(this))
2139                         locked = true;
2140                 text_.cursor = cur;
2141                 text_.setSelectionRange(str.length());
2142                 updateLocal(bv, false);
2143         }
2144         return result != lyx::find::SR_NOT_FOUND;
2145 }
2146
2147
2148 bool InsetText::checkInsertChar(LyXFont & font)
2149 {
2150         if (owner())
2151                 return owner()->checkInsertChar(font);
2152         return true;
2153 }
2154
2155
2156 void InsetText::collapseParagraphs(BufferView * bv)
2157 {
2158         while (paragraphs.size() > 1) {
2159                 ParagraphList::iterator first_par = paragraphs.begin();
2160                 ParagraphList::iterator next_par = boost::next(first_par);
2161                 size_t const first_par_size = first_par->size();
2162
2163                 if (!first_par->empty() &&
2164                     !next_par->empty() &&
2165                     !first_par->isSeparator(first_par_size - 1)) {
2166                         first_par->insertChar(first_par_size, ' ');
2167                 }
2168
2169                 if (text_.selection.set()) {
2170                         if (text_.selection.start.par() == next_par) {
2171                                 text_.selection.start.par(first_par);
2172                                 text_.selection.start.pos(
2173                                         text_.selection.start.pos() + first_par_size);
2174                         }
2175                         if (text_.selection.end.par() == next_par) {
2176                                 text_.selection.end.par(first_par);
2177                                 text_.selection.end.pos(
2178                                         text_.selection.end.pos() + first_par_size);
2179                         }
2180                 }
2181
2182                 mergeParagraph(bv->buffer()->params, paragraphs, first_par);
2183         }
2184         reinitLyXText();
2185 }
2186
2187
2188 void InsetText::getDrawFont(LyXFont & font) const
2189 {
2190         if (!owner())
2191                 return;
2192         owner()->getDrawFont(font);
2193 }
2194
2195
2196 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
2197 {
2198 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
2199 // And it probably does. You have to take a look at this John. (Lgb)
2200 #warning John, have a look here. (Lgb)
2201         ParagraphList::iterator pit = plist.begin();
2202         ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
2203         ++pit;
2204         mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
2205
2206         ParagraphList::iterator pend = plist.end();
2207         for (; pit != pend; ++pit) {
2208                 paragraphs.push_back(*pit);
2209         }
2210
2211         reinitLyXText();
2212 }
2213
2214
2215 void InsetText::addPreview(PreviewLoader & loader) const
2216 {
2217         ParagraphList::const_iterator pit = paragraphs.begin();
2218         ParagraphList::const_iterator pend = paragraphs.end();
2219
2220         for (; pit != pend; ++pit) {
2221                 InsetList::const_iterator it  = pit->insetlist.begin();
2222                 InsetList::const_iterator end = pit->insetlist.end();
2223                 for (; it != end; ++it) {
2224                         it->inset->addPreview(loader);
2225                 }
2226         }
2227 }