2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 * ======================================================
20 #pragma implementation
23 #include "insettext.h"
28 #include "commandtags.h"
31 #include "BufferView.h"
32 #include "support/textutils.h"
34 #include "insetlatexaccent.h"
35 #include "insetquotes.h"
36 #include "mathed/formulamacro.h"
38 #include "insetinfo.h"
39 #include "insetinclude.h"
41 #include "insetcommand.h"
42 #include "insetindex.h"
43 #include "insetlabel.h"
45 //#include "insettabular.h"
47 #include "insetspecialchar.h"
48 #include "LaTeXFeatures.h"
50 #include "lyx_gui_misc.h"
51 #include "support/LAssert.h"
53 extern unsigned char getCurrentTextClass(Buffer *);
55 InsetText::InsetText(Buffer * buf)
57 par = new LyXParagraph();
58 the_locking_inset = 0;
60 cursor_visible = false;
61 maxWidth = old_x = -1;
62 actpos = selection_start = selection_end = 0;
66 maxAscent = maxDescent = insetWidth = 0;
67 autoBreakRows = false;
71 InsetText::InsetText(InsetText const & ins, Buffer * buf)
73 par = new LyXParagraph(ins.par);
74 the_locking_inset = 0;
76 cursor_visible = false;
77 maxWidth = old_x = -1;
78 actpos = selection_start = selection_end = 0;
82 maxAscent = maxDescent = insetWidth = 0;
83 autoBreakRows = false;
87 InsetText::~InsetText()
93 Inset * InsetText::Clone() const
95 InsetText * t = new InsetText(*this, buffer);
100 void InsetText::Write(ostream & os) const
103 WriteParagraphData(os);
107 void InsetText::WriteParagraphData(ostream & os) const
109 par->writeFile(os, buffer->params, 0, 0);
113 void InsetText::Read(LyXLex & lex)
115 string token, tmptok;
117 LyXParagraph * return_par = 0;
118 char depth = 0; // signed or unsigned?
119 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
120 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
121 LyXFont font(LyXFont::ALL_INHERIT);
124 par = new LyXParagraph;
128 token = lex.GetString();
131 if (token == "\\end_inset")
133 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
137 // the_end read this should NEVER happen
138 lex.printError("\\the_end read in inset! Error in document!");
142 if (token != "\\end_inset") {
143 lex.printError("Missing \\end_inset at this point. "
150 int InsetText::ascent(Painter & pain, LyXFont const & font) const
153 computeTextRows(pain);
158 return font.maxAscent();
162 int InsetText::descent(Painter & pain, LyXFont const & font) const
165 computeTextRows(pain);
170 return font.maxDescent();
174 int InsetText::width(Painter & pain, LyXFont const &) const
177 computeTextRows(pain);
184 int InsetText::getMaxWidth(UpdatableInset * inset) const
186 if (!the_locking_inset) {
187 lyxerr << "Text: No locking inset in this inset.\n";
191 if (the_locking_inset == inset)
194 return the_locking_inset->getMaxWidth(inset);
198 void InsetText::draw(Painter & pain, LyXFont const & f,
199 int baseline, float & x) const
202 computeTextRows(pain, x);
203 // init_inset = false;
205 UpdatableInset::draw(pain, f, baseline, x);
207 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
209 top_baseline = baseline;
210 computeBaselines(baseline);
211 for(RowList::size_type r = 0; r < rows.size() - 1; ++r) {
212 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
213 rows[r].baseline, x);
214 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
217 if (!the_locking_inset && do_reset_pos) {
218 // HideInsetCursor(bv);
220 // ShowInsetCursor(bv);
225 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
226 int row, int baseline, float x) const
232 if (selection_start > selection_end) {
233 s_start = selection_end;
234 s_end = selection_start;
236 s_start = selection_start;
237 s_end = selection_end;
239 if ((s_start > endpos) || (s_end < startpos))
243 int ssel_x = esel_x = int(x);
246 for(; p < endpos; ++p) {
249 if ((p >= s_start) && (p <= s_end))
251 char ch = par->GetChar(p);
252 font = GetFont(par,p);
253 if (IsFloatChar(ch)) {
255 } else if (ch == LyXParagraph::META_INSET) {
256 Inset const * tmpinset = par->GetInset(p);
257 x += tmpinset->width(pain, font);
259 x += pain.width(ch,font);
264 if ((p >= s_start) && (p <= s_end))
266 if (ssel_x < esel_x) {
267 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
268 int(esel_x - ssel_x),
269 rows[row].asc + rows[row].desc,
275 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
276 int baseline, float x) const
278 Assert(endpos <= par->Last());
280 for(int p = startpos; p < endpos; ++p) {
281 char ch = par->GetChar(p);
282 LyXFont font = GetFont(par,p);
283 if (IsFloatChar(ch)) {
285 } else if (ch == LyXParagraph::META_INSET) {
286 Inset * tmpinset = par->GetInset(p);
288 tmpinset->draw(pain, font, baseline, x);
290 pain.text(int(x), baseline, ch, font);
291 x += pain.width(ch,font);
297 char const * InsetText::EditMessage() const
299 return _("Opened Text Inset");
303 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
305 UpdatableInset::Edit(bv, x, y, button);
308 the_locking_inset = 0;
309 inset_pos = inset_x = inset_y = 0;
312 selection_start = selection_end = actpos;
313 current_font = real_current_font = GetFont(par, actpos);
317 void InsetText::InsetUnlock(BufferView * bv)
319 if (the_locking_inset)
320 the_locking_inset->InsetUnlock(bv);
322 if (hasSelection()) {
323 selection_start = selection_end = actpos;
324 bv->updateInset(this, false);
326 the_locking_inset = 0;
327 no_selection = false;
331 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
333 if (!the_locking_inset)
335 if (the_locking_inset == inset) {
336 the_locking_inset->InsetUnlock(bv);
337 the_locking_inset = 0;
339 moveRight(bv, false);
342 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
346 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
348 if (!the_locking_inset)
350 if (the_locking_inset != inset)
351 return the_locking_inset->UpdateInsetInInset(bv, inset);
353 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
354 bv->updateInset(this, true);
359 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
361 if (the_locking_inset) {
362 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
365 no_selection = false;
369 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
371 if (hasSelection()) {
372 selection_start = selection_end = actpos;
373 bv->updateInset(this, false);
375 no_selection = false;
376 if (the_locking_inset) {
377 setPos(bv, x, y, false);
380 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
381 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
382 if (the_locking_inset == inset) {
383 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
386 // otherwise unlock the_locking_inset and lock the new inset
390 the_locking_inset->InsetUnlock(bv);
391 the_locking_inset = inset;
392 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
395 // otherwise only unlock the_locking_inset
396 the_locking_inset->InsetUnlock(bv);
399 the_locking_inset = 0;
401 selection_start = selection_end = actpos;
402 if (!the_locking_inset)
407 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
409 if (the_locking_inset) {
410 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
415 int old = selection_end;
416 setPos(bv, x, y, false);
417 selection_end = actpos;
418 if (old != selection_end)
419 bv->updateInset(this, false);
421 no_selection = false;
425 void InsetText::InsetKeyPress(XKeyEvent * xke)
427 if (the_locking_inset) {
428 the_locking_inset->InsetKeyPress(xke);
434 UpdatableInset::RESULT
435 InsetText::LocalDispatch(BufferView * bv,
436 int action, string const & arg)
438 no_selection = false;
439 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
444 UpdatableInset::RESULT
447 if ((action < 0) && arg.empty())
450 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
451 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
453 if (the_locking_inset) {
454 result = the_locking_inset->LocalDispatch(bv, action, arg);
455 if (result == DISPATCHED) {
456 the_locking_inset->ToggleInsetCursor(bv);
457 bv->updateInset(this, false);
458 the_locking_inset->ToggleInsetCursor(bv);
460 } else if (result == FINISHED) {
461 if ((action == LFUN_RIGHT) || (action == -1)) {
462 actpos = inset_pos + 1;
465 the_locking_inset = 0;
473 par->InsertChar(actpos,arg[0]);
474 par->SetFont(actpos,real_current_font);
475 computeTextRows(bv->getPainter());
476 bv->updateInset(this, true);
478 selection_start = selection_end = actpos;
481 // --- Cursor Movements ---------------------------------------------
483 moveRight(bv, false);
484 selection_end = actpos;
485 bv->updateInset(this, false);
488 result= DISPATCH_RESULT(moveRight(bv));
489 if (hasSelection()) {
490 selection_start = selection_end = actpos;
491 bv->updateInset(this, false);
493 selection_start = selection_end = actpos;
498 selection_end = actpos;
499 bv->updateInset(this, false);
502 result= DISPATCH_RESULT(moveLeft(bv));
503 if (hasSelection()) {
504 selection_start = selection_end = actpos;
505 bv->updateInset(this, false);
507 selection_start = selection_end = actpos;
512 selection_end = actpos;
513 bv->updateInset(this, false);
516 result= DISPATCH_RESULT(moveDown(bv));
517 if (hasSelection()) {
518 selection_start = selection_end = actpos;
519 bv->updateInset(this, false);
521 selection_start = selection_end = actpos;
526 selection_end = actpos;
527 bv->updateInset(this, false);
530 result= DISPATCH_RESULT(moveUp(bv));
531 if (hasSelection()) {
532 selection_start = selection_end = actpos;
533 bv->updateInset(this, false);
535 selection_start = selection_end = actpos;
539 if (!actpos || par->IsNewline(actpos-1)) {
540 if (hasSelection()) {
541 selection_start = selection_end = actpos;
542 bv->updateInset(this, false);
548 if (Delete()) { // we need update
549 selection_start = selection_end = actpos;
550 computeTextRows(bv->getPainter());
551 bv->updateInset(this, true);
552 } else if (hasSelection()) {
553 selection_start = selection_end = actpos;
554 bv->updateInset(this, false);
558 for(; actpos > rows[actrow].pos; --actpos)
559 cx -= SingleWidth(bv->getPainter(), par, actpos);
560 cx -= SingleWidth(bv->getPainter(), par, actpos);
561 if (hasSelection()) {
562 selection_start = selection_end = actpos;
563 bv->updateInset(this, false);
565 selection_start = selection_end = actpos;
569 for(; actpos < rows[actrow + 1].pos; ++actpos)
570 cx += SingleWidth(bv->getPainter(), par, actpos);
571 if (hasSelection()) {
572 selection_start = selection_end = actpos;
573 bv->updateInset(this, false);
575 selection_start = selection_end = actpos;
578 case LFUN_MATH_MODE: // Open or create a math inset
579 InsertInset(bv, new InsetFormula);
580 if (hasSelection()) {
581 selection_start = selection_end = actpos;
582 bv->updateInset(this, false);
584 selection_start = selection_end = actpos;
588 result = UNDISPATCHED;
591 if (result != FINISHED) {
592 if (!the_locking_inset)
595 bv->unlockInset(this);
600 int InsetText::Latex(ostream & os, signed char /*fragile*/) const
602 #ifdef USE_OSTREAM_ONLY
604 int ret = par->SimpleTeXOnePar(os, texrow);
609 int i = Latex(fstr, fragile);
616 #ifndef USE_OSTREAM_ONLY
617 int InsetText::Latex(string & file, signed char /* fragile */) const
621 return par->SimpleTeXOnePar(file, texrow);
626 void InsetText::Validate(LaTeXFeatures & features) const
628 par->validate(features);
632 // Returns the width of a character at a certain spot
633 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
635 LyXFont font = GetFont(par, pos);
636 char c = par->GetChar(pos);
638 if (IsPrintable(c)) {
639 return font.width(c);
640 } else if (c == LyXParagraph::META_INSET) {
641 Inset const * tmpinset = par->GetInset(pos);
643 return tmpinset->width(pain, font);
646 } else if (IsSeparatorChar(c))
648 else if (IsNewlineChar(c))
650 return font.width(c);
654 // Returns the width of a character at a certain spot
655 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
656 int & asc, int & desc) const
658 LyXFont font = GetFont(par, pos);
659 char c = par->GetChar(pos);
662 if (c == LyXParagraph::META_INSET) {
663 Inset const * tmpinset=par->GetInset(pos);
665 asc = tmpinset->ascent(pain, font);
666 desc = tmpinset->descent(pain, font);
669 asc = font.maxAscent();
670 desc = font.maxDescent();
676 // Gets the fully instantiated font at a given position in a paragraph
677 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
678 // The difference is that this one is used for displaying, and thus we
679 // are allowed to make cosmetic improvements. For instance make footnotes
681 // If position is -1, we get the layout font of the paragraph.
682 // If position is -2, we get the font of the manual label of the paragraph.
683 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
685 char par_depth = par->GetDepth();
687 LyXLayout const & layout =
688 textclasslist.Style(buffer->params.textclass, par->GetLayout());
690 // We specialize the 95% common case:
691 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
694 if (layout.labeltype == LABEL_MANUAL
695 && pos < BeginningOfMainBody(par)) {
697 return par->GetFontSettings(pos).realize(layout.reslabelfont);
699 return par->GetFontSettings(pos).realize(layout.resfont);
702 // process layoutfont for pos == -1 and labelfont for pos < -1
704 return layout.resfont;
706 return layout.reslabelfont;
709 // The uncommon case need not be optimized as much
711 LyXFont layoutfont, tmpfont;
715 if (pos < BeginningOfMainBody(par)) {
717 layoutfont = layout.labelfont;
720 layoutfont = layout.font;
722 tmpfont = par->GetFontSettings(pos);
723 tmpfont.realize(layoutfont);
726 // process layoutfont for pos == -1 and labelfont for pos < -1
728 tmpfont = layout.font;
730 tmpfont = layout.labelfont;
733 // Resolve against environment font information
734 //if (par->GetDepth()){ // already in while condition
735 while (par && par_depth && !tmpfont.resolved()) {
736 par = par->DepthHook(par_depth - 1);
738 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
739 par->GetLayout()).font);
740 par_depth = par->GetDepth();
743 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
749 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
751 if (textclasslist.Style(buffer->params.textclass,
752 par->GetLayout()).labeltype != LABEL_MANUAL)
755 return par->BeginningOfMainBody();
759 void InsetText::GetCursorPos(int & x, int & y) const
766 int InsetText::InsetInInsetY()
768 if (!the_locking_inset)
772 return (y + the_locking_inset->InsetInInsetY());
776 void InsetText::ToggleInsetCursor(BufferView * bv)
778 if (the_locking_inset) {
779 the_locking_inset->ToggleInsetCursor(bv);
783 LyXFont font = GetFont(par, actpos);
785 int asc = font.maxAscent();
786 int desc = font.maxDescent();
789 bv->hideLockedInsetCursor();
791 bv->showLockedInsetCursor(cx, cy, asc, desc);
792 cursor_visible = !cursor_visible;
796 void InsetText::ShowInsetCursor(BufferView * bv)
798 if (!cursor_visible) {
799 LyXFont font = GetFont(par, actpos);
801 int asc = font.maxAscent();
802 int desc = font.maxDescent();
803 bv->fitLockedInsetCursor(cx, cy, asc, desc);
804 bv->showLockedInsetCursor(cx, cy, asc, desc);
805 cursor_visible = true;
810 void InsetText::HideInsetCursor(BufferView * bv)
813 ToggleInsetCursor(bv);
817 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
822 // search right X-pos x==0 -> top_x
826 for(unsigned int i = 1;
827 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
828 cy = rows[i].baseline;
829 actpos = rows[i].pos;
837 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
838 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
840 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
843 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
844 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
847 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
849 static_cast<UpdatableInset*>(par->GetInset(actpos));
850 inset_x = cx - top_x;
853 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
858 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
860 if (actpos >= par->Last())
862 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
864 static_cast<UpdatableInset*>(par->GetInset(actpos));
865 inset_x = cx - top_x;
868 the_locking_inset->Edit(bv, 0, 0, 0);
877 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
882 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
884 static_cast<UpdatableInset*>(par->GetInset(actpos));
886 inset_x = cx - top_x;
889 the_locking_inset->Edit(bv, the_locking_inset->
890 width(bv->getPainter(), GetFont(par,actpos)),
899 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
903 cy = rows[actrow - 1].baseline - top_baseline;
904 setPos(bv, cx - top_x, cy, activate_inset);
909 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
911 if (actrow >= int(rows.size() - 2))
913 cy = rows[actrow + 1].baseline - top_baseline;
914 setPos(bv, cx - top_x, cy, activate_inset);
919 void InsetText::resetPos(BufferView * bv)
921 int old_pos = actpos;
925 for(int i = 0; rows[i].pos <= actpos; ++i) {
926 cy = rows[i].baseline;
930 setPos(bv, 0, cy, false);
932 while(actpos < old_pos) {
933 cx += SingleWidth(bv->getPainter(), par,actpos);
939 bool InsetText::Delete()
941 /* some insets are undeletable here */
942 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
943 /* force complete redo when erasing display insets */
944 /* this is a cruel mathod but save..... Matthias */
945 if (par->GetInset(actpos)->Deletable() &&
946 par->GetInset(actpos)->display()) {
957 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
959 par->InsertChar(actpos, LyXParagraph::META_INSET);
960 par->InsertInset(actpos, inset);
961 computeTextRows(bv->getPainter());
962 bv->updateInset(this, true);
963 the_locking_inset = static_cast<UpdatableInset*>(inset);
964 inset_x = cx - top_x;
967 inset->Edit(bv, 0, 0, 0);
972 UpdatableInset * InsetText::GetLockingInset()
974 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
978 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
980 // if there is no selection just set the current_font
981 if (!hasSelection()) {
982 // Determine basis font
984 if (actpos < BeginningOfMainBody(par))
985 layoutfont = GetFont(par, -2);
987 layoutfont = GetFont(par, -1);
989 // Update current font
990 real_current_font.update(font, toggleall);
992 // Reduce to implicit settings
993 current_font = real_current_font;
994 current_font.reduce(layoutfont);
995 // And resolve it completely
996 real_current_font.realize(layoutfont);
1001 if (selection_start > selection_end) {
1002 s_start = selection_end;
1003 s_end = selection_start;
1005 s_start = selection_start;
1006 s_end = selection_end;
1009 while(s_start < s_end) {
1010 newfont = GetFont(par,s_start);
1011 newfont.update(font, toggleall);
1012 SetCharFont(s_start, newfont);
1015 computeTextRows(bv->getPainter());
1016 bv->updateInset(this, true);
1020 void InsetText::SetCharFont(int pos, LyXFont const & f)
1022 /* let the insets convert their font */
1025 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1026 if (par->GetInset(pos))
1027 font = par->GetInset(pos)->ConvertFont(font);
1029 LyXLayout const & layout =
1030 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1032 // Get concrete layout font to reduce against
1035 if (pos < BeginningOfMainBody(par))
1036 layoutfont = layout.labelfont;
1038 layoutfont = layout.font;
1041 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1044 // Now, reduce font against full layout font
1045 font.reduce(layoutfont);
1047 par->SetFont(pos, font);
1051 // Ok, Jürgen. Here is my small secret message to you. As you can see I
1052 // played a bit witht he Textinset. (But only through the InsetERT so far).
1053 // As you can see below I have changed the code to use max/min instead of
1054 // the if < construct, imo this makes it faster and easier to read. I have
1055 // also changed rows[rows.size() - 1] to rows.back() makes it clearer that
1056 // we speak about the last element in the vector. I added a second arg to
1057 // to this func as well. This makes it possible to take the position of the
1058 // inset into account when drawing the inset, this is especially needed when
1059 // the ERT inset is first in a paragraph. I am not sure, but this might have
1060 // made short ERT (less than one line, just a couple of words) draw
1061 // incorrectly. You should perhaps have a look yourselves at this.
1062 // Also (phu...) I use pain to get at paperWidth().
1063 // This is beginning to look like a very nice Inset (speaking of the ERT
1064 // inset that is), but in afterthought, do we really need it? Wouldn't a
1065 // non dynamic inset working in the same way as the floats be more usefull
1066 // and easier to work with? Jean-Marc has already aired this thought.
1067 // I tested also a bit on the raw insettext, it seems that it can't break
1068 // over several lines properly. Other than that it seems to create the basis
1069 // for insetfloat, insetmarginal and insetfoot just fine. How about a
1070 // updatable inset that does not open, unless you click on it? uff... I just
1071 // ramble on. Feel free to remove my comments after you have read them.
1073 void InsetText::computeTextRows(Painter & pain, float x) const
1088 //rows.erase(rows.begin(),rows.end());
1089 int width = wordAscent = wordDescent = 0;
1090 insetWidth = maxAscent = maxDescent = 0;
1095 rows.push_back(row);
1096 if (!autoBreakRows) {
1097 for(p = 0; p < par->Last(); ++p) {
1098 insetWidth += SingleWidth(pain, par, p);
1099 SingleHeight(pain, par, p, asc, desc);
1100 maxAscent = max(maxAscent, asc);
1101 //if (asc > maxAscent)
1103 maxDescent = max(maxDescent, desc);
1104 //if (desc > maxDescent)
1105 //maxDescent = desc;
1107 rows[0].asc = maxAscent;
1108 rows[0].desc = maxDescent;
1109 // alocate a dummy row for the endpos
1110 row.pos = par->Last();
1111 rows.push_back(row);
1115 bool is_first_word_in_row = true;
1117 int cw, lastWordWidth = 0;
1119 //maxWidth = buffer->getUser()->paperWidth();
1120 maxWidth = pain.paperWidth();
1121 for(p = 0; p < par->Last(); ++p) {
1122 cw = SingleWidth(pain, par, p);
1124 lastWordWidth += cw;
1125 SingleHeight(pain, par, p, asc, desc);
1126 wordAscent = max(wordAscent, asc);
1127 //if (asc > wordAscent)
1128 // wordAscent = asc;
1129 wordDescent = max(wordDescent, desc);
1130 //if (desc > wordDescent)
1131 // wordDescent = desc;
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 //if (insetWidth < owidth)
1147 // insetWidth = owidth;
1148 width = lastWordWidth;
1151 oasc = max(oasc, wordAscent);
1152 //if (oasc < wordAscent)
1153 //oasc = wordAscent;
1154 odesc = max(odesc, wordDescent);
1155 //if (odesc < wordDescent)
1156 //odesc = wordDescent;
1158 rows.back().asc = oasc;
1159 rows.back().desc = odesc;
1161 rows.push_back(row);
1162 SingleHeight(pain, par, p, asc, desc);
1163 rows.back().asc = asc;
1164 rows.back().desc = desc;
1165 row.pos = nwp = p + 1;
1166 rows.push_back(row);
1167 oasc = odesc = width = lastWordWidth = 0;
1168 is_first_word_in_row = true;
1169 wordAscent = wordDescent = 0;
1172 } else if (par->IsSeparator(p)) {
1173 if (width >= maxWidth - x) {
1174 if (is_first_word_in_row) {
1175 rows.back().asc = wordAscent;
1176 rows.back().desc = wordDescent;
1178 rows.push_back(row);
1179 oasc = odesc = width = 0;
1181 rows.back().asc = oasc;
1182 rows.back().desc = odesc;
1184 rows.push_back(row);
1186 odesc = wordDescent;
1187 insetWidth = max(insetWidth, owidth);
1188 //if (insetWidth < owidth)
1189 //insetWidth = owidth;
1190 width = lastWordWidth;
1192 wordAscent = wordDescent = lastWordWidth = 0;
1198 oasc = max(oasc, wordAscent);
1199 //if (oasc < wordAscent)
1200 //oasc = wordAscent;
1201 odesc = max(odesc, wordDescent);
1202 //if (odesc < wordDescent)
1203 //odesc = wordDescent;
1204 wordAscent = wordDescent = lastWordWidth = 0;
1206 is_first_word_in_row = false;
1210 // if we have some data in the paragraph we have ascent/descent
1212 if (width >= maxWidth) {
1214 rows.back().asc = oasc;
1215 rows.back().desc = odesc;
1216 // assign and allocate lower row
1218 rows.push_back(row);
1219 rows.back().asc = wordAscent;
1220 rows.back().desc = wordDescent;
1221 insetWidth = max(insetWidth, owidth);
1222 //if (insetWidth < owidth)
1223 //insetWidth = owidth;
1225 insetWidth = max(insetWidth, width);
1226 //if (insetWidth < width)
1227 //insetWidth = width;
1229 // assign last row data
1230 oasc = max(oasc, wordAscent);
1231 //if (oasc < wordAscent)
1232 //oasc = wordAscent;
1233 odesc = min(odesc, wordDescent);
1234 //if (odesc < wordDescent)
1235 //odesc = wordDescent;
1236 rows.back().asc = oasc;
1237 rows.back().desc = odesc;
1240 // alocate a dummy row for the endpos
1241 row.pos = par->Last();
1242 rows.push_back(row);
1243 // calculate maxAscent/Descent
1244 maxAscent = rows[0].asc;
1245 maxDescent = rows[0].desc;
1246 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1247 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1249 lyxerr << "Rows: " << rows.size() << endl;
1251 if (the_locking_inset) {
1252 computeBaselines(top_baseline);
1255 inset_x = cx - top_x;
1262 void InsetText::computeBaselines(int baseline) const
1264 rows[0].baseline = baseline;
1265 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1266 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1267 rows[i].asc + interline_space;