2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 * ======================================================
23 #pragma implementation
26 #include "insettext.h"
31 #include "commandtags.h"
34 #include "BufferView.h"
35 #include "support/textutils.h"
37 #include "insetlatexaccent.h"
38 #include "insetquotes.h"
39 #include "mathed/formulamacro.h"
41 #include "insetinfo.h"
42 #include "insetinclude.h"
44 #include "insetcommand.h"
45 #include "insetindex.h"
46 #include "insetlabel.h"
48 //#include "insettabular.h"
50 #include "insetspecialchar.h"
51 #include "LaTeXFeatures.h"
53 #include "lyx_gui_misc.h"
54 #include "support/LAssert.h"
56 extern unsigned char getCurrentTextClass(Buffer *);
58 InsetText::InsetText(Buffer * buf)
60 par = new LyXParagraph();
61 the_locking_inset = 0;
63 cursor_visible = false;
64 maxWidth = old_x = -1;
65 actpos = selection_start = selection_end = 0;
69 maxAscent = maxDescent = insetWidth = widthOffset = 0;
70 autoBreakRows = false;
75 InsetText::InsetText(InsetText const & ins, Buffer * buf)
77 par = new LyXParagraph(ins.par);
78 the_locking_inset = 0;
80 cursor_visible = false;
81 maxWidth = old_x = -1;
82 actpos = selection_start = selection_end = 0;
86 maxAscent = maxDescent = insetWidth = widthOffset = 0;
87 autoBreakRows = false;
92 InsetText::~InsetText()
98 Inset * InsetText::Clone() const
100 InsetText * t = new InsetText(*this, buffer);
105 void InsetText::Write(ostream & os) const
108 WriteParagraphData(os);
112 void InsetText::WriteParagraphData(ostream & os) const
114 par->writeFile(os, buffer->params, 0, 0);
118 void InsetText::Read(LyXLex & lex)
120 string token, tmptok;
122 LyXParagraph * return_par = 0;
123 char depth = 0; // signed or unsigned?
124 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
125 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
126 LyXFont font(LyXFont::ALL_INHERIT);
129 par = new LyXParagraph;
133 token = lex.GetString();
136 if (token == "\\end_inset")
138 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
142 // the_end read this should NEVER happen
143 lex.printError("\\the_end read in inset! Error in document!");
147 if (token != "\\end_inset") {
148 lex.printError("Missing \\end_inset at this point. "
155 int InsetText::ascent(Painter & pain, LyXFont const & font) const
158 computeTextRows(pain, xpos);
163 return font.maxAscent();
167 int InsetText::descent(Painter & pain, LyXFont const & font) const
170 computeTextRows(pain, xpos);
175 return font.maxDescent();
179 int InsetText::width(Painter & pain, LyXFont const &) const
182 computeTextRows(pain, xpos);
189 void InsetText::draw(Painter & pain, LyXFont const & f,
190 int baseline, float & x) const
193 computeTextRows(pain, x);
194 UpdatableInset::draw(pain, f, baseline, x);
196 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
198 top_baseline = baseline;
199 computeBaselines(baseline);
200 for(RowList::size_type r = 0; r < rows.size() - 1; ++r) {
201 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
202 rows[r].baseline, x);
203 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
206 if (!the_locking_inset && do_reset_pos) {
207 // HideInsetCursor(bv);
209 // ShowInsetCursor(bv);
214 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
215 int row, int baseline, float x) const
221 if (selection_start > selection_end) {
222 s_start = selection_end;
223 s_end = selection_start;
225 s_start = selection_start;
226 s_end = selection_end;
228 if ((s_start > endpos) || (s_end < startpos))
232 int ssel_x = esel_x = int(x);
235 for(; p < endpos; ++p) {
238 if ((p >= s_start) && (p <= s_end))
240 char ch = par->GetChar(p);
241 font = GetFont(par,p);
242 if (IsFloatChar(ch)) {
244 } else if (ch == LyXParagraph::META_INSET) {
245 Inset const * tmpinset = par->GetInset(p);
246 x += tmpinset->width(pain, font);
248 x += pain.width(ch,font);
253 if ((p >= s_start) && (p <= s_end))
255 if (ssel_x < esel_x) {
256 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
257 int(esel_x - ssel_x),
258 rows[row].asc + rows[row].desc,
264 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
265 int baseline, float x) const
267 Assert(endpos <= par->Last());
269 for(int p = startpos; p < endpos; ++p) {
270 char ch = par->GetChar(p);
271 LyXFont font = GetFont(par,p);
272 if (IsFloatChar(ch)) {
274 } else if (ch == LyXParagraph::META_INSET) {
275 Inset * tmpinset = par->GetInset(p);
277 tmpinset->draw(pain, font, baseline, x);
279 pain.text(int(x), baseline, ch, font);
280 x += pain.width(ch,font);
286 char const * InsetText::EditMessage() const
288 return _("Opened Text Inset");
292 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
294 UpdatableInset::Edit(bv, x, y, button);
297 the_locking_inset = 0;
298 inset_pos = inset_x = inset_y = 0;
301 selection_start = selection_end = actpos;
302 current_font = real_current_font = GetFont(par, actpos);
306 void InsetText::InsetUnlock(BufferView * bv)
308 if (the_locking_inset)
309 the_locking_inset->InsetUnlock(bv);
311 if (hasSelection()) {
312 selection_start = selection_end = actpos;
313 UpdateLocal(bv, false);
315 the_locking_inset = 0;
316 no_selection = false;
320 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
322 if (!the_locking_inset)
324 if (the_locking_inset == inset) {
325 the_locking_inset->InsetUnlock(bv);
326 the_locking_inset = 0;
328 moveRight(bv, false);
331 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
335 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
337 if (!the_locking_inset)
339 if (the_locking_inset != inset)
340 return the_locking_inset->UpdateInsetInInset(bv, inset);
342 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
343 UpdateLocal(bv, true);
348 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
350 if (the_locking_inset) {
351 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
354 no_selection = false;
358 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
360 if (hasSelection()) {
361 selection_start = selection_end = actpos;
362 UpdateLocal(bv, false);
364 no_selection = false;
365 if (the_locking_inset) {
366 setPos(bv, x, y, false);
369 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
370 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
371 if (the_locking_inset == inset) {
372 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
375 // otherwise unlock the_locking_inset and lock the new inset
379 the_locking_inset->InsetUnlock(bv);
380 the_locking_inset = inset;
381 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
384 // otherwise only unlock the_locking_inset
385 the_locking_inset->InsetUnlock(bv);
388 the_locking_inset = 0;
390 selection_start = selection_end = actpos;
391 if (!the_locking_inset)
396 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
398 if (the_locking_inset) {
399 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
404 int old = selection_end;
405 setPos(bv, x, y, false);
406 selection_end = actpos;
407 if (old != selection_end)
408 UpdateLocal(bv, false);
410 no_selection = false;
414 void InsetText::InsetKeyPress(XKeyEvent * xke)
416 if (the_locking_inset) {
417 the_locking_inset->InsetKeyPress(xke);
423 UpdatableInset::RESULT
424 InsetText::LocalDispatch(BufferView * bv,
425 int action, string const & arg)
427 no_selection = false;
428 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
433 UpdatableInset::RESULT
436 if ((action < 0) && arg.empty())
439 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
440 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
442 if (the_locking_inset) {
443 result = the_locking_inset->LocalDispatch(bv, action, arg);
444 if (result == DISPATCHED) {
445 the_locking_inset->ToggleInsetCursor(bv);
446 UpdateLocal(bv, false);
447 the_locking_inset->ToggleInsetCursor(bv);
449 } else if (result == FINISHED) {
450 if ((action == LFUN_RIGHT) || (action == -1)) {
451 actpos = inset_pos + 1;
454 the_locking_inset = 0;
462 par->InsertChar(actpos,arg[0]);
463 par->SetFont(actpos,real_current_font);
464 UpdateLocal(bv, true);
466 selection_start = selection_end = actpos;
469 // --- Cursor Movements ---------------------------------------------
471 moveRight(bv, false);
472 selection_end = actpos;
473 UpdateLocal(bv, false);
476 result= DISPATCH_RESULT(moveRight(bv));
477 if (hasSelection()) {
478 selection_start = selection_end = actpos;
479 UpdateLocal(bv, false);
481 selection_start = selection_end = actpos;
486 selection_end = actpos;
487 UpdateLocal(bv, false);
490 result= DISPATCH_RESULT(moveLeft(bv));
491 if (hasSelection()) {
492 selection_start = selection_end = actpos;
493 UpdateLocal(bv, false);
495 selection_start = selection_end = actpos;
500 selection_end = actpos;
501 UpdateLocal(bv, false);
504 result= DISPATCH_RESULT(moveDown(bv));
505 if (hasSelection()) {
506 selection_start = selection_end = actpos;
507 UpdateLocal(bv, false);
509 selection_start = selection_end = actpos;
514 selection_end = actpos;
515 UpdateLocal(bv, false);
518 result= DISPATCH_RESULT(moveUp(bv));
519 if (hasSelection()) {
520 selection_start = selection_end = actpos;
521 UpdateLocal(bv, false);
523 selection_start = selection_end = actpos;
527 if (!actpos || par->IsNewline(actpos-1)) {
528 if (hasSelection()) {
529 selection_start = selection_end = actpos;
530 UpdateLocal(bv, false);
536 if (Delete()) { // we need update
537 selection_start = selection_end = actpos;
538 UpdateLocal(bv, true);
539 } else if (hasSelection()) {
540 selection_start = selection_end = actpos;
541 UpdateLocal(bv, false);
545 for(; actpos > rows[actrow].pos; --actpos)
546 cx -= SingleWidth(bv->getPainter(), par, actpos);
547 cx -= SingleWidth(bv->getPainter(), par, actpos);
548 if (hasSelection()) {
549 selection_start = selection_end = actpos;
550 UpdateLocal(bv, false);
552 selection_start = selection_end = actpos;
556 for(; actpos < rows[actrow + 1].pos; ++actpos)
557 cx += SingleWidth(bv->getPainter(), par, actpos);
558 if (hasSelection()) {
559 selection_start = selection_end = actpos;
560 UpdateLocal(bv, false);
562 selection_start = selection_end = actpos;
565 case LFUN_MATH_MODE: // Open or create a math inset
566 InsertInset(bv, new InsetFormula);
567 if (hasSelection()) {
568 selection_start = selection_end = actpos;
569 UpdateLocal(bv, false);
571 selection_start = selection_end = actpos;
575 result = UNDISPATCHED;
578 if (result != FINISHED) {
579 if (!the_locking_inset)
582 bv->unlockInset(this);
587 int InsetText::Latex(ostream & os, signed char /*fragile*/,
588 #ifdef USE_OSTREAM_ONLY
594 #ifdef USE_OSTREAM_ONLY
596 int ret = par->SimpleTeXOnePar(os, texrow);
601 int i = Latex(fstr, fragile, free_spc);
608 #ifndef USE_OSTREAM_ONLY
609 int InsetText::Latex(string & file, signed char /* fragile */) const
613 return par->SimpleTeXOnePar(file, texrow);
618 void InsetText::Validate(LaTeXFeatures & features) const
620 par->validate(features);
624 // Returns the width of a character at a certain spot
625 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
627 LyXFont font = GetFont(par, pos);
628 char c = par->GetChar(pos);
630 if (IsPrintable(c)) {
631 return font.width(c);
632 } else if (c == LyXParagraph::META_INSET) {
633 Inset const * tmpinset = par->GetInset(pos);
635 return tmpinset->width(pain, font);
638 } else if (IsSeparatorChar(c))
640 else if (IsNewlineChar(c))
642 return font.width(c);
646 // Returns the width of a character at a certain spot
647 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
648 int & asc, int & desc) const
650 LyXFont font = GetFont(par, pos);
651 char c = par->GetChar(pos);
654 if (c == LyXParagraph::META_INSET) {
655 Inset const * tmpinset=par->GetInset(pos);
657 asc = tmpinset->ascent(pain, font);
658 desc = tmpinset->descent(pain, font);
661 asc = font.maxAscent();
662 desc = font.maxDescent();
668 // Gets the fully instantiated font at a given position in a paragraph
669 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
670 // The difference is that this one is used for displaying, and thus we
671 // are allowed to make cosmetic improvements. For instance make footnotes
673 // If position is -1, we get the layout font of the paragraph.
674 // If position is -2, we get the font of the manual label of the paragraph.
675 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
677 char par_depth = par->GetDepth();
679 LyXLayout const & layout =
680 textclasslist.Style(buffer->params.textclass, par->GetLayout());
682 // We specialize the 95% common case:
683 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
686 if (layout.labeltype == LABEL_MANUAL
687 && pos < BeginningOfMainBody(par)) {
689 return par->GetFontSettings(pos).realize(layout.reslabelfont);
691 return par->GetFontSettings(pos).realize(layout.resfont);
694 // process layoutfont for pos == -1 and labelfont for pos < -1
696 return layout.resfont;
698 return layout.reslabelfont;
701 // The uncommon case need not be optimized as much
703 LyXFont layoutfont, tmpfont;
707 if (pos < BeginningOfMainBody(par)) {
709 layoutfont = layout.labelfont;
712 layoutfont = layout.font;
714 tmpfont = par->GetFontSettings(pos);
715 tmpfont.realize(layoutfont);
718 // process layoutfont for pos == -1 and labelfont for pos < -1
720 tmpfont = layout.font;
722 tmpfont = layout.labelfont;
725 // Resolve against environment font information
726 //if (par->GetDepth()){ // already in while condition
727 while (par && par_depth && !tmpfont.resolved()) {
728 par = par->DepthHook(par_depth - 1);
730 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
731 par->GetLayout()).font);
732 par_depth = par->GetDepth();
735 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
741 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
743 if (textclasslist.Style(buffer->params.textclass,
744 par->GetLayout()).labeltype != LABEL_MANUAL)
747 return par->BeginningOfMainBody();
751 void InsetText::GetCursorPos(int & x, int & y) const
758 int InsetText::InsetInInsetY()
760 if (!the_locking_inset)
764 return (y + the_locking_inset->InsetInInsetY());
768 void InsetText::ToggleInsetCursor(BufferView * bv)
770 if (the_locking_inset) {
771 the_locking_inset->ToggleInsetCursor(bv);
775 LyXFont font = GetFont(par, actpos);
777 int asc = font.maxAscent();
778 int desc = font.maxDescent();
781 bv->hideLockedInsetCursor();
783 bv->showLockedInsetCursor(cx, cy, asc, desc);
784 cursor_visible = !cursor_visible;
788 void InsetText::ShowInsetCursor(BufferView * bv)
790 if (!cursor_visible) {
791 LyXFont font = GetFont(par, actpos);
793 int asc = font.maxAscent();
794 int desc = font.maxDescent();
795 bv->fitLockedInsetCursor(cx, cy, asc, desc);
796 bv->showLockedInsetCursor(cx, cy, asc, desc);
797 cursor_visible = true;
802 void InsetText::HideInsetCursor(BufferView * bv)
805 ToggleInsetCursor(bv);
809 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
814 // search right X-pos x==0 -> top_x
818 for(unsigned int i = 1;
819 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
820 cy = rows[i].baseline;
821 actpos = rows[i].pos;
829 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
830 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
832 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
835 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
836 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
839 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
841 static_cast<UpdatableInset*>(par->GetInset(actpos));
842 inset_x = cx - top_x;
845 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
850 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
852 if (actpos >= par->Last())
854 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
856 static_cast<UpdatableInset*>(par->GetInset(actpos));
857 inset_x = cx - top_x;
860 the_locking_inset->Edit(bv, 0, 0, 0);
869 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
874 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
876 static_cast<UpdatableInset*>(par->GetInset(actpos));
878 inset_x = cx - top_x;
881 the_locking_inset->Edit(bv, the_locking_inset->
882 width(bv->getPainter(), GetFont(par,actpos)),
891 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
895 cy = rows[actrow - 1].baseline - top_baseline;
896 setPos(bv, cx - top_x, cy, activate_inset);
901 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
903 if (actrow >= int(rows.size() - 2))
905 cy = rows[actrow + 1].baseline - top_baseline;
906 setPos(bv, cx - top_x, cy, activate_inset);
911 void InsetText::resetPos(BufferView * bv)
913 int old_pos = actpos;
917 for(int i = 0; rows[i].pos <= actpos; ++i) {
918 cy = rows[i].baseline;
922 setPos(bv, 0, cy, false);
924 while(actpos < old_pos) {
925 cx += SingleWidth(bv->getPainter(), par,actpos);
931 bool InsetText::Delete()
933 /* some insets are undeletable here */
934 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
935 /* force complete redo when erasing display insets */
936 /* this is a cruel mathod but save..... Matthias */
937 if (par->GetInset(actpos)->Deletable() &&
938 par->GetInset(actpos)->display()) {
949 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
951 if (inset->Editable() == Inset::IS_EDITABLE) {
952 UpdatableInset *i = (UpdatableInset *)inset;
953 i->setOwner((UpdatableInset *)this);
955 par->InsertChar(actpos, LyXParagraph::META_INSET);
956 par->InsertInset(actpos, inset);
957 UpdateLocal(bv, true);
958 the_locking_inset = static_cast<UpdatableInset*>(inset);
959 inset_x = cx - top_x;
962 inset->Edit(bv, 0, 0, 0);
967 UpdatableInset * InsetText::GetLockingInset()
969 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
973 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
975 // if there is no selection just set the current_font
976 if (!hasSelection()) {
977 // Determine basis font
979 if (actpos < BeginningOfMainBody(par))
980 layoutfont = GetFont(par, -2);
982 layoutfont = GetFont(par, -1);
984 // Update current font
985 real_current_font.update(font, toggleall);
987 // Reduce to implicit settings
988 current_font = real_current_font;
989 current_font.reduce(layoutfont);
990 // And resolve it completely
991 real_current_font.realize(layoutfont);
996 if (selection_start > selection_end) {
997 s_start = selection_end;
998 s_end = selection_start;
1000 s_start = selection_start;
1001 s_end = selection_end;
1004 while(s_start < s_end) {
1005 newfont = GetFont(par,s_start);
1006 newfont.update(font, toggleall);
1007 SetCharFont(s_start, newfont);
1010 UpdateLocal(bv, true);
1014 void InsetText::SetCharFont(int pos, LyXFont const & f)
1016 /* let the insets convert their font */
1019 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1020 if (par->GetInset(pos))
1021 font = par->GetInset(pos)->ConvertFont(font);
1023 LyXLayout const & layout =
1024 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1026 // Get concrete layout font to reduce against
1029 if (pos < BeginningOfMainBody(par))
1030 layoutfont = layout.labelfont;
1032 layoutfont = layout.font;
1035 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1038 // Now, reduce font against full layout font
1039 font.reduce(layoutfont);
1041 par->SetFont(pos, font);
1045 void InsetText::computeTextRows(Painter & pain, float x) const
1060 int width = wordAscent = wordDescent = 0;
1061 insetWidth = maxAscent = maxDescent = 0;
1066 rows.push_back(row);
1067 if (!autoBreakRows) {
1068 for(p = 0; p < par->Last(); ++p) {
1069 insetWidth += SingleWidth(pain, par, p);
1070 SingleHeight(pain, par, p, asc, desc);
1071 maxAscent = max(maxAscent, asc);
1072 maxDescent = max(maxDescent, desc);
1074 rows[0].asc = maxAscent;
1075 rows[0].desc = maxDescent;
1076 // alocate a dummy row for the endpos
1077 row.pos = par->Last();
1078 rows.push_back(row);
1082 bool is_first_word_in_row = true;
1084 int cw, lastWordWidth = 0;
1086 maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset;
1087 for(p = 0; p < par->Last(); ++p) {
1088 cw = SingleWidth(pain, par, p);
1090 lastWordWidth += cw;
1091 SingleHeight(pain, par, p, asc, desc);
1092 wordAscent = max(wordAscent, asc);
1093 wordDescent = max(wordDescent, desc);
1094 Inset const * inset = 0;
1095 if (((p + 1) < par->Last()) &&
1096 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1097 inset = par->GetInset(p + 1);
1098 if (inset && inset->display()) {
1099 if (!is_first_word_in_row && (width >= (maxWidth - x))) {
1100 // we have to split also the row above
1101 rows.back().asc = oasc;
1102 rows.back().desc = odesc;
1104 rows.push_back(row);
1106 odesc = wordDescent;
1107 insetWidth = max(insetWidth, owidth);
1108 width = lastWordWidth;
1111 oasc = max(oasc, wordAscent);
1112 odesc = max(odesc, wordDescent);
1114 rows.back().asc = oasc;
1115 rows.back().desc = odesc;
1117 rows.push_back(row);
1118 SingleHeight(pain, par, p, asc, desc);
1119 rows.back().asc = asc;
1120 rows.back().desc = desc;
1121 row.pos = nwp = p + 1;
1122 rows.push_back(row);
1123 oasc = odesc = width = lastWordWidth = 0;
1124 is_first_word_in_row = true;
1125 wordAscent = wordDescent = 0;
1128 } else if (par->IsSeparator(p)) {
1129 if (width >= maxWidth - x) {
1130 if (is_first_word_in_row) {
1131 rows.back().asc = wordAscent;
1132 rows.back().desc = wordDescent;
1134 rows.push_back(row);
1135 oasc = odesc = width = 0;
1137 rows.back().asc = oasc;
1138 rows.back().desc = odesc;
1140 rows.push_back(row);
1142 odesc = wordDescent;
1143 insetWidth = max(insetWidth, owidth);
1144 width = lastWordWidth;
1146 wordAscent = wordDescent = lastWordWidth = 0;
1152 oasc = max(oasc, wordAscent);
1153 odesc = max(odesc, wordDescent);
1154 wordAscent = wordDescent = lastWordWidth = 0;
1156 is_first_word_in_row = false;
1159 // if we have some data in the paragraph we have ascent/descent
1161 if (width >= (maxWidth - x)) {
1163 rows.back().asc = oasc;
1164 rows.back().desc = odesc;
1165 // assign and allocate lower row
1167 rows.push_back(row);
1168 rows.back().asc = wordAscent;
1169 rows.back().desc = wordDescent;
1170 width -= lastWordWidth;
1172 // assign last row data
1173 // width = lastWordWidth;
1174 // lastWordWidth = 0;
1175 rows.back().asc = max(oasc, wordAscent);
1176 rows.back().desc = max(odesc, wordDescent);
1179 insetWidth = max(insetWidth, width);
1180 // alocate a dummy row for the endpos
1181 row.pos = par->Last();
1182 rows.push_back(row);
1183 // calculate maxAscent/Descent
1184 maxAscent = rows[0].asc;
1185 maxDescent = rows[0].desc;
1186 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1187 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1190 if (the_locking_inset) {
1191 computeBaselines(top_baseline);
1194 inset_x = cx - top_x;
1201 void InsetText::computeBaselines(int baseline) const
1203 rows[0].baseline = baseline;
1204 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1205 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1206 rows[i].asc + interline_space;
1210 void InsetText::UpdateLocal(BufferView *bv, bool flag)
1213 bv->updateInset(this, flag);