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 (par->IsNewline(p)) {
275 // Draw end-of-line marker
276 int wid = font.width('n');
277 int asc = font.maxAscent();
281 xp[0] = int(x + wid * 0.375);
282 yp[0] = int(y - 0.875 * asc * 0.75);
285 yp[1] = int(y - 0.500 * asc * 0.75);
287 xp[2] = int(x + wid * 0.375);
288 yp[2] = int(y - 0.125 * asc * 0.75);
290 pain.lines(xp, yp, 3, LColor::eolmarker);
293 yp[0] = int(y - 0.500 * asc * 0.75);
295 xp[1] = int(x + wid);
296 yp[1] = int(y - 0.500 * asc * 0.75);
298 xp[2] = int(x + wid);
299 yp[2] = int(y - asc * 0.75);
301 pain.lines(xp, yp, 3, LColor::eolmarker);
303 } else if (ch == LyXParagraph::META_INSET) {
304 Inset * tmpinset = par->GetInset(p);
306 tmpinset->draw(pain, font, baseline, x);
308 pain.text(int(x), baseline, ch, font);
309 x += pain.width(ch,font);
315 char const * InsetText::EditMessage() const
317 return _("Opened Text Inset");
321 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
323 UpdatableInset::Edit(bv, x, y, button);
326 the_locking_inset = 0;
327 inset_pos = inset_x = inset_y = 0;
330 selection_start = selection_end = actpos;
331 current_font = real_current_font = GetFont(par, actpos);
335 void InsetText::InsetUnlock(BufferView * bv)
337 if (the_locking_inset)
338 the_locking_inset->InsetUnlock(bv);
340 if (hasSelection()) {
341 selection_start = selection_end = actpos;
342 UpdateLocal(bv, false);
344 the_locking_inset = 0;
345 no_selection = false;
349 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
351 if (!the_locking_inset)
353 if (the_locking_inset == inset) {
354 the_locking_inset->InsetUnlock(bv);
355 the_locking_inset = 0;
357 moveRight(bv, false);
360 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
364 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
366 if (!the_locking_inset)
368 if (the_locking_inset != inset)
369 return the_locking_inset->UpdateInsetInInset(bv, inset);
371 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
372 UpdateLocal(bv, true);
377 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
379 if (the_locking_inset) {
380 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
383 no_selection = false;
387 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
389 if (hasSelection()) {
390 selection_start = selection_end = actpos;
391 UpdateLocal(bv, false);
393 no_selection = false;
394 if (the_locking_inset) {
395 setPos(bv, x, y, false);
398 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
399 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
400 if (the_locking_inset == inset) {
401 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
404 // otherwise unlock the_locking_inset and lock the new inset
408 the_locking_inset->InsetUnlock(bv);
409 the_locking_inset = inset;
410 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
413 // otherwise only unlock the_locking_inset
414 the_locking_inset->InsetUnlock(bv);
417 the_locking_inset = 0;
419 selection_start = selection_end = actpos;
420 if (!the_locking_inset)
425 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
427 if (the_locking_inset) {
428 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
433 int old = selection_end;
434 setPos(bv, x, y, false);
435 selection_end = actpos;
436 if (old != selection_end)
437 UpdateLocal(bv, false);
439 no_selection = false;
443 void InsetText::InsetKeyPress(XKeyEvent * xke)
445 if (the_locking_inset) {
446 the_locking_inset->InsetKeyPress(xke);
452 UpdatableInset::RESULT
453 InsetText::LocalDispatch(BufferView * bv,
454 int action, string const & arg)
456 no_selection = false;
457 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
462 UpdatableInset::RESULT
465 if ((action < 0) && arg.empty())
468 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
469 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
471 if (the_locking_inset) {
472 result = the_locking_inset->LocalDispatch(bv, action, arg);
473 if (result == DISPATCHED) {
474 the_locking_inset->ToggleInsetCursor(bv);
475 UpdateLocal(bv, false);
476 the_locking_inset->ToggleInsetCursor(bv);
478 } else if (result == FINISHED) {
479 if ((action == LFUN_RIGHT) || (action == -1)) {
480 actpos = inset_pos + 1;
483 the_locking_inset = 0;
491 par->InsertChar(actpos,arg[0]);
492 par->SetFont(actpos,real_current_font);
493 UpdateLocal(bv, true);
495 selection_start = selection_end = actpos;
498 // --- Cursor Movements ---------------------------------------------
500 moveRight(bv, false);
501 selection_end = actpos;
502 UpdateLocal(bv, false);
505 result= DISPATCH_RESULT(moveRight(bv));
506 if (hasSelection()) {
507 selection_start = selection_end = actpos;
508 UpdateLocal(bv, false);
510 selection_start = selection_end = actpos;
515 selection_end = actpos;
516 UpdateLocal(bv, false);
519 result= DISPATCH_RESULT(moveLeft(bv));
520 if (hasSelection()) {
521 selection_start = selection_end = actpos;
522 UpdateLocal(bv, false);
524 selection_start = selection_end = actpos;
529 selection_end = actpos;
530 UpdateLocal(bv, false);
533 result= DISPATCH_RESULT(moveDown(bv));
534 if (hasSelection()) {
535 selection_start = selection_end = actpos;
536 UpdateLocal(bv, false);
538 selection_start = selection_end = actpos;
543 selection_end = actpos;
544 UpdateLocal(bv, false);
547 result= DISPATCH_RESULT(moveUp(bv));
548 if (hasSelection()) {
549 selection_start = selection_end = actpos;
550 UpdateLocal(bv, false);
552 selection_start = selection_end = actpos;
556 if (!actpos || par->IsNewline(actpos-1)) {
557 if (hasSelection()) {
558 selection_start = selection_end = actpos;
559 UpdateLocal(bv, false);
565 if (Delete()) { // we need update
566 selection_start = selection_end = actpos;
567 UpdateLocal(bv, true);
568 } else if (hasSelection()) {
569 selection_start = selection_end = actpos;
570 UpdateLocal(bv, false);
574 for(; actpos > rows[actrow].pos; --actpos)
575 cx -= SingleWidth(bv->getPainter(), par, actpos);
576 cx -= SingleWidth(bv->getPainter(), par, actpos);
577 if (hasSelection()) {
578 selection_start = selection_end = actpos;
579 UpdateLocal(bv, false);
581 selection_start = selection_end = actpos;
586 int checkpos = (int)rows[actrow + 1].pos;
587 if ((actrow + 2) < (int)rows.size())
589 for(; actpos < checkpos; ++actpos)
590 cx += SingleWidth(bv->getPainter(), par, actpos);
591 if (hasSelection()) {
592 selection_start = selection_end = actpos;
593 UpdateLocal(bv, false);
595 selection_start = selection_end = actpos;
599 case LFUN_MATH_MODE: // Open or create a math inset
600 InsertInset(bv, new InsetFormula);
601 if (hasSelection()) {
602 selection_start = selection_end = actpos;
603 UpdateLocal(bv, false);
605 selection_start = selection_end = actpos;
609 par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
610 par->SetFont(actpos,real_current_font);
611 UpdateLocal(bv, true);
613 selection_start = selection_end = actpos;
617 result = UNDISPATCHED;
620 if (result != FINISHED) {
621 if (!the_locking_inset)
624 bv->unlockInset(this);
629 int InsetText::Latex(ostream & os, signed char /*fragile*/, bool) const
632 int ret = par->SimpleTeXOnePar(os, texrow);
637 void InsetText::Validate(LaTeXFeatures & features) const
639 par->validate(features);
643 // Returns the width of a character at a certain spot
644 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
646 LyXFont font = GetFont(par, pos);
647 char c = par->GetChar(pos);
649 if (IsPrintable(c)) {
650 return font.width(c);
651 } else if (c == LyXParagraph::META_INSET) {
652 Inset const * tmpinset = par->GetInset(pos);
654 return tmpinset->width(pain, font);
657 } else if (IsSeparatorChar(c))
659 else if (IsNewlineChar(c))
661 return font.width(c);
665 // Returns the width of a character at a certain spot
666 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
667 int & asc, int & desc) const
669 LyXFont font = GetFont(par, pos);
670 char c = par->GetChar(pos);
673 if (c == LyXParagraph::META_INSET) {
674 Inset const * tmpinset=par->GetInset(pos);
676 asc = tmpinset->ascent(pain, font);
677 desc = tmpinset->descent(pain, font);
680 asc = font.maxAscent();
681 desc = font.maxDescent();
687 // Gets the fully instantiated font at a given position in a paragraph
688 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
689 // The difference is that this one is used for displaying, and thus we
690 // are allowed to make cosmetic improvements. For instance make footnotes
692 // If position is -1, we get the layout font of the paragraph.
693 // If position is -2, we get the font of the manual label of the paragraph.
694 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
696 char par_depth = par->GetDepth();
698 LyXLayout const & layout =
699 textclasslist.Style(buffer->params.textclass, par->GetLayout());
701 // We specialize the 95% common case:
702 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
705 if (layout.labeltype == LABEL_MANUAL
706 && pos < BeginningOfMainBody(par)) {
708 return par->GetFontSettings(pos).realize(layout.reslabelfont);
710 return par->GetFontSettings(pos).realize(layout.resfont);
713 // process layoutfont for pos == -1 and labelfont for pos < -1
715 return layout.resfont;
717 return layout.reslabelfont;
720 // The uncommon case need not be optimized as much
722 LyXFont layoutfont, tmpfont;
726 if (pos < BeginningOfMainBody(par)) {
728 layoutfont = layout.labelfont;
731 layoutfont = layout.font;
733 tmpfont = par->GetFontSettings(pos);
734 tmpfont.realize(layoutfont);
737 // process layoutfont for pos == -1 and labelfont for pos < -1
739 tmpfont = layout.font;
741 tmpfont = layout.labelfont;
744 // Resolve against environment font information
745 //if (par->GetDepth()){ // already in while condition
746 while (par && par_depth && !tmpfont.resolved()) {
747 par = par->DepthHook(par_depth - 1);
749 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
750 par->GetLayout()).font);
751 par_depth = par->GetDepth();
754 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
760 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
762 if (textclasslist.Style(buffer->params.textclass,
763 par->GetLayout()).labeltype != LABEL_MANUAL)
766 return par->BeginningOfMainBody();
770 void InsetText::GetCursorPos(int & x, int & y) const
777 int InsetText::InsetInInsetY()
779 if (!the_locking_inset)
783 return (y + the_locking_inset->InsetInInsetY());
787 void InsetText::ToggleInsetCursor(BufferView * bv)
789 if (the_locking_inset) {
790 the_locking_inset->ToggleInsetCursor(bv);
794 LyXFont font = GetFont(par, actpos);
796 int asc = font.maxAscent();
797 int desc = font.maxDescent();
800 bv->hideLockedInsetCursor();
802 bv->showLockedInsetCursor(cx, cy, asc, desc);
803 cursor_visible = !cursor_visible;
807 void InsetText::ShowInsetCursor(BufferView * bv)
809 if (!cursor_visible) {
810 LyXFont font = GetFont(par, actpos);
812 int asc = font.maxAscent();
813 int desc = font.maxDescent();
814 bv->fitLockedInsetCursor(cx, cy, asc, desc);
815 bv->showLockedInsetCursor(cx, cy, asc, desc);
816 cursor_visible = true;
821 void InsetText::HideInsetCursor(BufferView * bv)
824 ToggleInsetCursor(bv);
828 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
833 // search right X-pos x==0 -> top_x
837 for(unsigned int i = 1;
838 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
839 cy = rows[i].baseline;
840 actpos = rows[i].pos;
851 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
852 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
854 checkpos = rows[actrow + 1].pos;
855 if ((actrow+2) < (int)rows.size())
857 while ((actpos < checkpos) && ((cx + swh) < x)) {
860 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
861 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
864 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
866 static_cast<UpdatableInset*>(par->GetInset(actpos));
867 inset_x = cx - top_x;
870 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
875 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
877 if (actpos >= par->Last())
879 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
881 static_cast<UpdatableInset*>(par->GetInset(actpos));
882 inset_x = cx - top_x;
885 the_locking_inset->Edit(bv, 0, 0, 0);
894 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
899 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
901 static_cast<UpdatableInset*>(par->GetInset(actpos));
903 inset_x = cx - top_x;
906 the_locking_inset->Edit(bv, the_locking_inset->
907 width(bv->getPainter(), GetFont(par,actpos)),
916 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
920 cy = rows[actrow - 1].baseline - top_baseline;
921 setPos(bv, cx - top_x, cy, activate_inset);
926 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
928 if (actrow >= int(rows.size() - 2))
930 cy = rows[actrow + 1].baseline - top_baseline;
931 setPos(bv, cx - top_x, cy, activate_inset);
936 void InsetText::resetPos(BufferView * bv)
938 int old_pos = actpos;
942 for(unsigned int i = 0; (i < (rows.size()-1)) && (rows[i].pos <= actpos);
944 cy = rows[i].baseline;
948 setPos(bv, 0, cy, false);
950 while(actpos < old_pos) {
951 cx += SingleWidth(bv->getPainter(), par,actpos);
957 bool InsetText::Delete()
959 /* some insets are undeletable here */
960 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
961 /* force complete redo when erasing display insets */
962 /* this is a cruel mathod but save..... Matthias */
963 if (par->GetInset(actpos)->Deletable() &&
964 par->GetInset(actpos)->display()) {
975 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
977 if (inset->Editable() == Inset::IS_EDITABLE) {
978 UpdatableInset *i = (UpdatableInset *)inset;
979 i->setOwner((UpdatableInset *)this);
981 par->InsertChar(actpos, LyXParagraph::META_INSET);
982 par->InsertInset(actpos, inset);
983 UpdateLocal(bv, true);
984 the_locking_inset = static_cast<UpdatableInset*>(inset);
985 inset_x = cx - top_x;
988 inset->Edit(bv, 0, 0, 0);
993 UpdatableInset * InsetText::GetLockingInset()
995 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
999 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
1001 // if there is no selection just set the current_font
1002 if (!hasSelection()) {
1003 // Determine basis font
1005 if (actpos < BeginningOfMainBody(par))
1006 layoutfont = GetFont(par, -2);
1008 layoutfont = GetFont(par, -1);
1010 // Update current font
1011 real_current_font.update(font, bv->buffer()->params.language_info,
1014 // Reduce to implicit settings
1015 current_font = real_current_font;
1016 current_font.reduce(layoutfont);
1017 // And resolve it completely
1018 real_current_font.realize(layoutfont);
1023 if (selection_start > selection_end) {
1024 s_start = selection_end;
1025 s_end = selection_start;
1027 s_start = selection_start;
1028 s_end = selection_end;
1031 while(s_start < s_end) {
1032 newfont = GetFont(par,s_start);
1033 newfont.update(font, bv->buffer()->params.language_info, toggleall);
1034 SetCharFont(s_start, newfont);
1037 UpdateLocal(bv, true);
1041 void InsetText::SetCharFont(int pos, LyXFont const & f)
1043 /* let the insets convert their font */
1046 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1047 if (par->GetInset(pos))
1048 font = par->GetInset(pos)->ConvertFont(font);
1050 LyXLayout const & layout =
1051 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1053 // Get concrete layout font to reduce against
1056 if (pos < BeginningOfMainBody(par))
1057 layoutfont = layout.labelfont;
1059 layoutfont = layout.font;
1062 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1065 // Now, reduce font against full layout font
1066 font.reduce(layoutfont);
1068 par->SetFont(pos, font);
1072 void InsetText::computeTextRows(Painter & pain, float x) const
1087 int width = wordAscent = wordDescent = 0;
1088 insetWidth = maxAscent = maxDescent = 0;
1093 rows.push_back(row);
1094 if (!autoBreakRows) {
1095 for(p = 0; p < par->Last(); ++p) {
1096 insetWidth += SingleWidth(pain, par, p);
1097 SingleHeight(pain, par, p, asc, desc);
1098 maxAscent = max(maxAscent, asc);
1099 maxDescent = max(maxDescent, desc);
1101 rows[0].asc = maxAscent;
1102 rows[0].desc = maxDescent;
1103 // alocate a dummy row for the endpos
1104 row.pos = par->Last();
1105 rows.push_back(row);
1109 bool is_first_word_in_row = true;
1111 int cw, lastWordWidth = 0;
1113 maxWidth = getMaxWidth(pain) - widthOffset;
1114 for(p = 0; p < par->Last(); ++p) {
1115 cw = SingleWidth(pain, par, p);
1117 lastWordWidth += cw;
1118 SingleHeight(pain, par, p, asc, desc);
1119 wordAscent = max(wordAscent, asc);
1120 wordDescent = max(wordDescent, desc);
1121 if (par->IsNewline(p)) {
1122 rows.back().asc = wordAscent;
1123 rows.back().desc = wordDescent;
1125 rows.push_back(row);
1126 SingleHeight(pain, par, p, oasc, odesc);
1127 width = lastWordWidth = 0;
1128 is_first_word_in_row = true;
1129 wordAscent = wordDescent = 0;
1132 Inset const * inset = 0;
1133 if (((p + 1) < par->Last()) &&
1134 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1135 inset = par->GetInset(p + 1);
1136 if (inset && inset->display()) {
1137 if (!is_first_word_in_row && (width >= (maxWidth - x))) {
1138 // we have to split also the row above
1139 rows.back().asc = oasc;
1140 rows.back().desc = odesc;
1142 rows.push_back(row);
1144 odesc = wordDescent;
1145 insetWidth = max(insetWidth, owidth);
1146 width = lastWordWidth;
1149 oasc = max(oasc, wordAscent);
1150 odesc = max(odesc, wordDescent);
1152 rows.back().asc = oasc;
1153 rows.back().desc = odesc;
1155 rows.push_back(row);
1156 SingleHeight(pain, par, p, asc, desc);
1157 rows.back().asc = asc;
1158 rows.back().desc = desc;
1159 row.pos = nwp = p + 1;
1160 rows.push_back(row);
1161 oasc = odesc = width = lastWordWidth = 0;
1162 is_first_word_in_row = true;
1163 wordAscent = wordDescent = 0;
1165 } else if (par->IsSeparator(p)) {
1166 if (width >= maxWidth - x) {
1167 if (is_first_word_in_row) {
1168 rows.back().asc = wordAscent;
1169 rows.back().desc = wordDescent;
1171 rows.push_back(row);
1172 oasc = odesc = width = 0;
1174 rows.back().asc = oasc;
1175 rows.back().desc = odesc;
1177 rows.push_back(row);
1179 odesc = wordDescent;
1180 insetWidth = max(insetWidth, owidth);
1181 width = lastWordWidth;
1183 wordAscent = wordDescent = lastWordWidth = 0;
1188 oasc = max(oasc, wordAscent);
1189 odesc = max(odesc, wordDescent);
1190 wordAscent = wordDescent = lastWordWidth = 0;
1192 is_first_word_in_row = false;
1195 // if we have some data in the paragraph we have ascent/descent
1197 if (width >= (maxWidth - x)) {
1199 rows.back().asc = oasc;
1200 rows.back().desc = odesc;
1201 // assign and allocate lower row
1203 rows.push_back(row);
1204 rows.back().asc = wordAscent;
1205 rows.back().desc = wordDescent;
1206 width -= lastWordWidth;
1208 // assign last row data
1209 // width = lastWordWidth;
1210 // lastWordWidth = 0;
1211 rows.back().asc = max(oasc, wordAscent);
1212 rows.back().desc = max(odesc, wordDescent);
1215 insetWidth = max(insetWidth, width);
1216 // alocate a dummy row for the endpos
1217 row.pos = par->Last();
1218 rows.push_back(row);
1219 // calculate maxAscent/Descent
1220 maxAscent = rows[0].asc;
1221 maxDescent = rows[0].desc;
1222 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1223 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1226 if (the_locking_inset) {
1227 computeBaselines(top_baseline);
1230 inset_x = cx - top_x;
1237 void InsetText::computeBaselines(int baseline) const
1239 rows[0].baseline = baseline;
1240 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1241 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1242 rows[i].asc + interline_space;
1246 void InsetText::UpdateLocal(BufferView *bv, bool flag)
1249 bv->updateInset(this, flag);