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*/) const
589 #ifdef USE_OSTREAM_ONLY
591 int ret = par->SimpleTeXOnePar(os, texrow);
596 int i = Latex(fstr, fragile);
603 #ifndef USE_OSTREAM_ONLY
604 int InsetText::Latex(string & file, signed char /* fragile */) const
608 return par->SimpleTeXOnePar(file, texrow);
613 void InsetText::Validate(LaTeXFeatures & features) const
615 par->validate(features);
619 // Returns the width of a character at a certain spot
620 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
622 LyXFont font = GetFont(par, pos);
623 char c = par->GetChar(pos);
625 if (IsPrintable(c)) {
626 return font.width(c);
627 } else if (c == LyXParagraph::META_INSET) {
628 Inset const * tmpinset = par->GetInset(pos);
630 return tmpinset->width(pain, font);
633 } else if (IsSeparatorChar(c))
635 else if (IsNewlineChar(c))
637 return font.width(c);
641 // Returns the width of a character at a certain spot
642 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
643 int & asc, int & desc) const
645 LyXFont font = GetFont(par, pos);
646 char c = par->GetChar(pos);
649 if (c == LyXParagraph::META_INSET) {
650 Inset const * tmpinset=par->GetInset(pos);
652 asc = tmpinset->ascent(pain, font);
653 desc = tmpinset->descent(pain, font);
656 asc = font.maxAscent();
657 desc = font.maxDescent();
663 // Gets the fully instantiated font at a given position in a paragraph
664 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
665 // The difference is that this one is used for displaying, and thus we
666 // are allowed to make cosmetic improvements. For instance make footnotes
668 // If position is -1, we get the layout font of the paragraph.
669 // If position is -2, we get the font of the manual label of the paragraph.
670 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
672 char par_depth = par->GetDepth();
674 LyXLayout const & layout =
675 textclasslist.Style(buffer->params.textclass, par->GetLayout());
677 // We specialize the 95% common case:
678 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
681 if (layout.labeltype == LABEL_MANUAL
682 && pos < BeginningOfMainBody(par)) {
684 return par->GetFontSettings(pos).realize(layout.reslabelfont);
686 return par->GetFontSettings(pos).realize(layout.resfont);
689 // process layoutfont for pos == -1 and labelfont for pos < -1
691 return layout.resfont;
693 return layout.reslabelfont;
696 // The uncommon case need not be optimized as much
698 LyXFont layoutfont, tmpfont;
702 if (pos < BeginningOfMainBody(par)) {
704 layoutfont = layout.labelfont;
707 layoutfont = layout.font;
709 tmpfont = par->GetFontSettings(pos);
710 tmpfont.realize(layoutfont);
713 // process layoutfont for pos == -1 and labelfont for pos < -1
715 tmpfont = layout.font;
717 tmpfont = layout.labelfont;
720 // Resolve against environment font information
721 //if (par->GetDepth()){ // already in while condition
722 while (par && par_depth && !tmpfont.resolved()) {
723 par = par->DepthHook(par_depth - 1);
725 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
726 par->GetLayout()).font);
727 par_depth = par->GetDepth();
730 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
736 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
738 if (textclasslist.Style(buffer->params.textclass,
739 par->GetLayout()).labeltype != LABEL_MANUAL)
742 return par->BeginningOfMainBody();
746 void InsetText::GetCursorPos(int & x, int & y) const
753 int InsetText::InsetInInsetY()
755 if (!the_locking_inset)
759 return (y + the_locking_inset->InsetInInsetY());
763 void InsetText::ToggleInsetCursor(BufferView * bv)
765 if (the_locking_inset) {
766 the_locking_inset->ToggleInsetCursor(bv);
770 LyXFont font = GetFont(par, actpos);
772 int asc = font.maxAscent();
773 int desc = font.maxDescent();
776 bv->hideLockedInsetCursor();
778 bv->showLockedInsetCursor(cx, cy, asc, desc);
779 cursor_visible = !cursor_visible;
783 void InsetText::ShowInsetCursor(BufferView * bv)
785 if (!cursor_visible) {
786 LyXFont font = GetFont(par, actpos);
788 int asc = font.maxAscent();
789 int desc = font.maxDescent();
790 bv->fitLockedInsetCursor(cx, cy, asc, desc);
791 bv->showLockedInsetCursor(cx, cy, asc, desc);
792 cursor_visible = true;
797 void InsetText::HideInsetCursor(BufferView * bv)
800 ToggleInsetCursor(bv);
804 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
809 // search right X-pos x==0 -> top_x
813 for(unsigned int i = 1;
814 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
815 cy = rows[i].baseline;
816 actpos = rows[i].pos;
824 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
825 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
827 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
830 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
831 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
834 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
836 static_cast<UpdatableInset*>(par->GetInset(actpos));
837 inset_x = cx - top_x;
840 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
845 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
847 if (actpos >= par->Last())
849 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
851 static_cast<UpdatableInset*>(par->GetInset(actpos));
852 inset_x = cx - top_x;
855 the_locking_inset->Edit(bv, 0, 0, 0);
864 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
869 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
871 static_cast<UpdatableInset*>(par->GetInset(actpos));
873 inset_x = cx - top_x;
876 the_locking_inset->Edit(bv, the_locking_inset->
877 width(bv->getPainter(), GetFont(par,actpos)),
886 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
890 cy = rows[actrow - 1].baseline - top_baseline;
891 setPos(bv, cx - top_x, cy, activate_inset);
896 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
898 if (actrow >= int(rows.size() - 2))
900 cy = rows[actrow + 1].baseline - top_baseline;
901 setPos(bv, cx - top_x, cy, activate_inset);
906 void InsetText::resetPos(BufferView * bv)
908 int old_pos = actpos;
912 for(int i = 0; rows[i].pos <= actpos; ++i) {
913 cy = rows[i].baseline;
917 setPos(bv, 0, cy, false);
919 while(actpos < old_pos) {
920 cx += SingleWidth(bv->getPainter(), par,actpos);
926 bool InsetText::Delete()
928 /* some insets are undeletable here */
929 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
930 /* force complete redo when erasing display insets */
931 /* this is a cruel mathod but save..... Matthias */
932 if (par->GetInset(actpos)->Deletable() &&
933 par->GetInset(actpos)->display()) {
944 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
946 if (inset->Editable() == Inset::IS_EDITABLE) {
947 UpdatableInset *i = (UpdatableInset *)inset;
948 i->setOwner((UpdatableInset *)this);
950 par->InsertChar(actpos, LyXParagraph::META_INSET);
951 par->InsertInset(actpos, inset);
952 UpdateLocal(bv, true);
953 the_locking_inset = static_cast<UpdatableInset*>(inset);
954 inset_x = cx - top_x;
957 inset->Edit(bv, 0, 0, 0);
962 UpdatableInset * InsetText::GetLockingInset()
964 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
968 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
970 // if there is no selection just set the current_font
971 if (!hasSelection()) {
972 // Determine basis font
974 if (actpos < BeginningOfMainBody(par))
975 layoutfont = GetFont(par, -2);
977 layoutfont = GetFont(par, -1);
979 // Update current font
980 real_current_font.update(font, toggleall);
982 // Reduce to implicit settings
983 current_font = real_current_font;
984 current_font.reduce(layoutfont);
985 // And resolve it completely
986 real_current_font.realize(layoutfont);
991 if (selection_start > selection_end) {
992 s_start = selection_end;
993 s_end = selection_start;
995 s_start = selection_start;
996 s_end = selection_end;
999 while(s_start < s_end) {
1000 newfont = GetFont(par,s_start);
1001 newfont.update(font, toggleall);
1002 SetCharFont(s_start, newfont);
1005 UpdateLocal(bv, true);
1009 void InsetText::SetCharFont(int pos, LyXFont const & f)
1011 /* let the insets convert their font */
1014 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1015 if (par->GetInset(pos))
1016 font = par->GetInset(pos)->ConvertFont(font);
1018 LyXLayout const & layout =
1019 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1021 // Get concrete layout font to reduce against
1024 if (pos < BeginningOfMainBody(par))
1025 layoutfont = layout.labelfont;
1027 layoutfont = layout.font;
1030 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1033 // Now, reduce font against full layout font
1034 font.reduce(layoutfont);
1036 par->SetFont(pos, font);
1040 void InsetText::computeTextRows(Painter & pain, float x) const
1055 int width = wordAscent = wordDescent = 0;
1056 insetWidth = maxAscent = maxDescent = 0;
1061 rows.push_back(row);
1062 if (!autoBreakRows) {
1063 for(p = 0; p < par->Last(); ++p) {
1064 insetWidth += SingleWidth(pain, par, p);
1065 SingleHeight(pain, par, p, asc, desc);
1066 maxAscent = max(maxAscent, asc);
1067 maxDescent = max(maxDescent, desc);
1069 rows[0].asc = maxAscent;
1070 rows[0].desc = maxDescent;
1071 // alocate a dummy row for the endpos
1072 row.pos = par->Last();
1073 rows.push_back(row);
1077 bool is_first_word_in_row = true;
1079 int cw, lastWordWidth = 0;
1081 maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset;
1082 for(p = 0; p < par->Last(); ++p) {
1083 cw = SingleWidth(pain, par, p);
1085 lastWordWidth += cw;
1086 SingleHeight(pain, par, p, asc, desc);
1087 wordAscent = max(wordAscent, asc);
1088 wordDescent = max(wordDescent, desc);
1089 Inset const * inset = 0;
1090 if (((p + 1) < par->Last()) &&
1091 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1092 inset = par->GetInset(p + 1);
1093 if (inset && inset->display()) {
1094 if (!is_first_word_in_row && (width >= (maxWidth - x))) {
1095 // we have to split also the row above
1096 rows.back().asc = oasc;
1097 rows.back().desc = odesc;
1099 rows.push_back(row);
1101 odesc = wordDescent;
1102 insetWidth = max(insetWidth, owidth);
1103 width = lastWordWidth;
1106 oasc = max(oasc, wordAscent);
1107 odesc = max(odesc, wordDescent);
1109 rows.back().asc = oasc;
1110 rows.back().desc = odesc;
1112 rows.push_back(row);
1113 SingleHeight(pain, par, p, asc, desc);
1114 rows.back().asc = asc;
1115 rows.back().desc = desc;
1116 row.pos = nwp = p + 1;
1117 rows.push_back(row);
1118 oasc = odesc = width = lastWordWidth = 0;
1119 is_first_word_in_row = true;
1120 wordAscent = wordDescent = 0;
1123 } else if (par->IsSeparator(p)) {
1124 if (width >= maxWidth - x) {
1125 if (is_first_word_in_row) {
1126 rows.back().asc = wordAscent;
1127 rows.back().desc = wordDescent;
1129 rows.push_back(row);
1130 oasc = odesc = width = 0;
1132 rows.back().asc = oasc;
1133 rows.back().desc = odesc;
1135 rows.push_back(row);
1137 odesc = wordDescent;
1138 insetWidth = max(insetWidth, owidth);
1139 width = lastWordWidth;
1141 wordAscent = wordDescent = lastWordWidth = 0;
1147 oasc = max(oasc, wordAscent);
1148 odesc = max(odesc, wordDescent);
1149 wordAscent = wordDescent = lastWordWidth = 0;
1151 is_first_word_in_row = false;
1154 // if we have some data in the paragraph we have ascent/descent
1156 if (width >= (maxWidth - x)) {
1158 rows.back().asc = oasc;
1159 rows.back().desc = odesc;
1160 // assign and allocate lower row
1162 rows.push_back(row);
1163 rows.back().asc = wordAscent;
1164 rows.back().desc = wordDescent;
1165 width -= lastWordWidth;
1167 // assign last row data
1168 // width = lastWordWidth;
1169 // lastWordWidth = 0;
1170 rows.back().asc = max(oasc, wordAscent);
1171 rows.back().desc = max(odesc, wordDescent);
1174 insetWidth = max(insetWidth, width);
1175 // alocate a dummy row for the endpos
1176 row.pos = par->Last();
1177 rows.push_back(row);
1178 // calculate maxAscent/Descent
1179 maxAscent = rows[0].asc;
1180 maxDescent = rows[0].desc;
1181 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1182 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1185 if (the_locking_inset) {
1186 computeBaselines(top_baseline);
1189 inset_x = cx - top_x;
1196 void InsetText::computeBaselines(int baseline) const
1198 rows[0].baseline = baseline;
1199 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1200 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1201 rows[i].asc + interline_space;
1205 void InsetText::UpdateLocal(BufferView *bv, bool flag)
1208 bv->updateInset(this, flag);