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 = 0;
70 autoBreakRows = false;
74 InsetText::InsetText(InsetText const & ins, Buffer * buf)
76 par = new LyXParagraph(ins.par);
77 the_locking_inset = 0;
79 cursor_visible = false;
80 maxWidth = old_x = -1;
81 actpos = selection_start = selection_end = 0;
85 maxAscent = maxDescent = insetWidth = 0;
86 autoBreakRows = false;
90 InsetText::~InsetText()
96 Inset * InsetText::Clone() const
98 InsetText * t = new InsetText(*this, buffer);
103 void InsetText::Write(ostream & os) const
106 WriteParagraphData(os);
110 void InsetText::WriteParagraphData(ostream & os) const
112 par->writeFile(os, buffer->params, 0, 0);
116 void InsetText::Read(LyXLex & lex)
118 string token, tmptok;
120 LyXParagraph * return_par = 0;
121 char depth = 0; // signed or unsigned?
122 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
123 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
124 LyXFont font(LyXFont::ALL_INHERIT);
127 par = new LyXParagraph;
131 token = lex.GetString();
134 if (token == "\\end_inset")
136 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
140 // the_end read this should NEVER happen
141 lex.printError("\\the_end read in inset! Error in document!");
145 if (token != "\\end_inset") {
146 lex.printError("Missing \\end_inset at this point. "
153 int InsetText::ascent(Painter & pain, LyXFont const & font) const
156 computeTextRows(pain);
161 return font.maxAscent();
165 int InsetText::descent(Painter & pain, LyXFont const & font) const
168 computeTextRows(pain);
173 return font.maxDescent();
177 int InsetText::width(Painter & pain, LyXFont const &) const
180 computeTextRows(pain);
187 int InsetText::getMaxWidth(UpdatableInset * inset) const
189 if (!the_locking_inset) {
190 lyxerr << "Text: No locking inset in this inset.\n";
194 if (the_locking_inset == inset)
197 return the_locking_inset->getMaxWidth(inset);
201 void InsetText::draw(Painter & pain, LyXFont const & f,
202 int baseline, float & x) const
205 computeTextRows(pain, x);
206 // init_inset = false;
208 UpdatableInset::draw(pain, f, baseline, x);
210 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
212 top_baseline = baseline;
213 computeBaselines(baseline);
214 for(RowList::size_type r = 0; r < rows.size() - 1; ++r) {
215 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
216 rows[r].baseline, x);
217 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
220 if (!the_locking_inset && do_reset_pos) {
221 // HideInsetCursor(bv);
223 // ShowInsetCursor(bv);
228 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
229 int row, int baseline, float x) const
235 if (selection_start > selection_end) {
236 s_start = selection_end;
237 s_end = selection_start;
239 s_start = selection_start;
240 s_end = selection_end;
242 if ((s_start > endpos) || (s_end < startpos))
246 int ssel_x = esel_x = int(x);
249 for(; p < endpos; ++p) {
252 if ((p >= s_start) && (p <= s_end))
254 char ch = par->GetChar(p);
255 font = GetFont(par,p);
256 if (IsFloatChar(ch)) {
258 } else if (ch == LyXParagraph::META_INSET) {
259 Inset const * tmpinset = par->GetInset(p);
260 x += tmpinset->width(pain, font);
262 x += pain.width(ch,font);
267 if ((p >= s_start) && (p <= s_end))
269 if (ssel_x < esel_x) {
270 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
271 int(esel_x - ssel_x),
272 rows[row].asc + rows[row].desc,
278 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
279 int baseline, float x) const
281 Assert(endpos <= par->Last());
283 for(int p = startpos; p < endpos; ++p) {
284 char ch = par->GetChar(p);
285 LyXFont font = GetFont(par,p);
286 if (IsFloatChar(ch)) {
288 } else if (ch == LyXParagraph::META_INSET) {
289 Inset * tmpinset = par->GetInset(p);
291 tmpinset->draw(pain, font, baseline, x);
293 pain.text(int(x), baseline, ch, font);
294 x += pain.width(ch,font);
300 char const * InsetText::EditMessage() const
302 return _("Opened Text Inset");
306 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
308 UpdatableInset::Edit(bv, x, y, button);
311 the_locking_inset = 0;
312 inset_pos = inset_x = inset_y = 0;
315 selection_start = selection_end = actpos;
316 current_font = real_current_font = GetFont(par, actpos);
320 void InsetText::InsetUnlock(BufferView * bv)
322 if (the_locking_inset)
323 the_locking_inset->InsetUnlock(bv);
325 if (hasSelection()) {
326 selection_start = selection_end = actpos;
327 bv->updateInset(this, false);
329 the_locking_inset = 0;
330 no_selection = false;
334 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
336 if (!the_locking_inset)
338 if (the_locking_inset == inset) {
339 the_locking_inset->InsetUnlock(bv);
340 the_locking_inset = 0;
342 moveRight(bv, false);
345 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
349 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
351 if (!the_locking_inset)
353 if (the_locking_inset != inset)
354 return the_locking_inset->UpdateInsetInInset(bv, inset);
356 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
357 bv->updateInset(this, true);
362 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
364 if (the_locking_inset) {
365 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
368 no_selection = false;
372 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
374 if (hasSelection()) {
375 selection_start = selection_end = actpos;
376 bv->updateInset(this, false);
378 no_selection = false;
379 if (the_locking_inset) {
380 setPos(bv, x, y, false);
383 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
384 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
385 if (the_locking_inset == inset) {
386 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
389 // otherwise unlock the_locking_inset and lock the new inset
393 the_locking_inset->InsetUnlock(bv);
394 the_locking_inset = inset;
395 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
398 // otherwise only unlock the_locking_inset
399 the_locking_inset->InsetUnlock(bv);
402 the_locking_inset = 0;
404 selection_start = selection_end = actpos;
405 if (!the_locking_inset)
410 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
412 if (the_locking_inset) {
413 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
418 int old = selection_end;
419 setPos(bv, x, y, false);
420 selection_end = actpos;
421 if (old != selection_end)
422 bv->updateInset(this, false);
424 no_selection = false;
428 void InsetText::InsetKeyPress(XKeyEvent * xke)
430 if (the_locking_inset) {
431 the_locking_inset->InsetKeyPress(xke);
437 UpdatableInset::RESULT
438 InsetText::LocalDispatch(BufferView * bv,
439 int action, string const & arg)
441 no_selection = false;
442 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
447 UpdatableInset::RESULT
450 if ((action < 0) && arg.empty())
453 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
454 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
456 if (the_locking_inset) {
457 result = the_locking_inset->LocalDispatch(bv, action, arg);
458 if (result == DISPATCHED) {
459 the_locking_inset->ToggleInsetCursor(bv);
460 bv->updateInset(this, false);
461 the_locking_inset->ToggleInsetCursor(bv);
463 } else if (result == FINISHED) {
464 if ((action == LFUN_RIGHT) || (action == -1)) {
465 actpos = inset_pos + 1;
468 the_locking_inset = 0;
476 par->InsertChar(actpos,arg[0]);
477 par->SetFont(actpos,real_current_font);
478 computeTextRows(bv->getPainter());
479 bv->updateInset(this, true);
481 selection_start = selection_end = actpos;
484 // --- Cursor Movements ---------------------------------------------
486 moveRight(bv, false);
487 selection_end = actpos;
488 bv->updateInset(this, false);
491 result= DISPATCH_RESULT(moveRight(bv));
492 if (hasSelection()) {
493 selection_start = selection_end = actpos;
494 bv->updateInset(this, false);
496 selection_start = selection_end = actpos;
501 selection_end = actpos;
502 bv->updateInset(this, false);
505 result= DISPATCH_RESULT(moveLeft(bv));
506 if (hasSelection()) {
507 selection_start = selection_end = actpos;
508 bv->updateInset(this, false);
510 selection_start = selection_end = actpos;
515 selection_end = actpos;
516 bv->updateInset(this, false);
519 result= DISPATCH_RESULT(moveDown(bv));
520 if (hasSelection()) {
521 selection_start = selection_end = actpos;
522 bv->updateInset(this, false);
524 selection_start = selection_end = actpos;
529 selection_end = actpos;
530 bv->updateInset(this, false);
533 result= DISPATCH_RESULT(moveUp(bv));
534 if (hasSelection()) {
535 selection_start = selection_end = actpos;
536 bv->updateInset(this, false);
538 selection_start = selection_end = actpos;
542 if (!actpos || par->IsNewline(actpos-1)) {
543 if (hasSelection()) {
544 selection_start = selection_end = actpos;
545 bv->updateInset(this, false);
551 if (Delete()) { // we need update
552 selection_start = selection_end = actpos;
553 computeTextRows(bv->getPainter());
554 bv->updateInset(this, true);
555 } else if (hasSelection()) {
556 selection_start = selection_end = actpos;
557 bv->updateInset(this, false);
561 for(; actpos > rows[actrow].pos; --actpos)
562 cx -= SingleWidth(bv->getPainter(), par, actpos);
563 cx -= SingleWidth(bv->getPainter(), par, actpos);
564 if (hasSelection()) {
565 selection_start = selection_end = actpos;
566 bv->updateInset(this, false);
568 selection_start = selection_end = actpos;
572 for(; actpos < rows[actrow + 1].pos; ++actpos)
573 cx += SingleWidth(bv->getPainter(), par, actpos);
574 if (hasSelection()) {
575 selection_start = selection_end = actpos;
576 bv->updateInset(this, false);
578 selection_start = selection_end = actpos;
581 case LFUN_MATH_MODE: // Open or create a math inset
582 InsertInset(bv, new InsetFormula);
583 if (hasSelection()) {
584 selection_start = selection_end = actpos;
585 bv->updateInset(this, false);
587 selection_start = selection_end = actpos;
591 result = UNDISPATCHED;
594 if (result != FINISHED) {
595 if (!the_locking_inset)
598 bv->unlockInset(this);
603 int InsetText::Latex(ostream & os, signed char /*fragile*/) const
605 #ifdef USE_OSTREAM_ONLY
607 int ret = par->SimpleTeXOnePar(os, texrow);
612 int i = Latex(fstr, fragile);
619 #ifndef USE_OSTREAM_ONLY
620 int InsetText::Latex(string & file, signed char /* fragile */) const
624 return par->SimpleTeXOnePar(file, texrow);
629 void InsetText::Validate(LaTeXFeatures & features) const
631 par->validate(features);
635 // Returns the width of a character at a certain spot
636 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
638 LyXFont font = GetFont(par, pos);
639 char c = par->GetChar(pos);
641 if (IsPrintable(c)) {
642 return font.width(c);
643 } else if (c == LyXParagraph::META_INSET) {
644 Inset const * tmpinset = par->GetInset(pos);
646 return tmpinset->width(pain, font);
649 } else if (IsSeparatorChar(c))
651 else if (IsNewlineChar(c))
653 return font.width(c);
657 // Returns the width of a character at a certain spot
658 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
659 int & asc, int & desc) const
661 LyXFont font = GetFont(par, pos);
662 char c = par->GetChar(pos);
665 if (c == LyXParagraph::META_INSET) {
666 Inset const * tmpinset=par->GetInset(pos);
668 asc = tmpinset->ascent(pain, font);
669 desc = tmpinset->descent(pain, font);
672 asc = font.maxAscent();
673 desc = font.maxDescent();
679 // Gets the fully instantiated font at a given position in a paragraph
680 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
681 // The difference is that this one is used for displaying, and thus we
682 // are allowed to make cosmetic improvements. For instance make footnotes
684 // If position is -1, we get the layout font of the paragraph.
685 // If position is -2, we get the font of the manual label of the paragraph.
686 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
688 char par_depth = par->GetDepth();
690 LyXLayout const & layout =
691 textclasslist.Style(buffer->params.textclass, par->GetLayout());
693 // We specialize the 95% common case:
694 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
697 if (layout.labeltype == LABEL_MANUAL
698 && pos < BeginningOfMainBody(par)) {
700 return par->GetFontSettings(pos).realize(layout.reslabelfont);
702 return par->GetFontSettings(pos).realize(layout.resfont);
705 // process layoutfont for pos == -1 and labelfont for pos < -1
707 return layout.resfont;
709 return layout.reslabelfont;
712 // The uncommon case need not be optimized as much
714 LyXFont layoutfont, tmpfont;
718 if (pos < BeginningOfMainBody(par)) {
720 layoutfont = layout.labelfont;
723 layoutfont = layout.font;
725 tmpfont = par->GetFontSettings(pos);
726 tmpfont.realize(layoutfont);
729 // process layoutfont for pos == -1 and labelfont for pos < -1
731 tmpfont = layout.font;
733 tmpfont = layout.labelfont;
736 // Resolve against environment font information
737 //if (par->GetDepth()){ // already in while condition
738 while (par && par_depth && !tmpfont.resolved()) {
739 par = par->DepthHook(par_depth - 1);
741 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
742 par->GetLayout()).font);
743 par_depth = par->GetDepth();
746 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
752 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
754 if (textclasslist.Style(buffer->params.textclass,
755 par->GetLayout()).labeltype != LABEL_MANUAL)
758 return par->BeginningOfMainBody();
762 void InsetText::GetCursorPos(int & x, int & y) const
769 int InsetText::InsetInInsetY()
771 if (!the_locking_inset)
775 return (y + the_locking_inset->InsetInInsetY());
779 void InsetText::ToggleInsetCursor(BufferView * bv)
781 if (the_locking_inset) {
782 the_locking_inset->ToggleInsetCursor(bv);
786 LyXFont font = GetFont(par, actpos);
788 int asc = font.maxAscent();
789 int desc = font.maxDescent();
792 bv->hideLockedInsetCursor();
794 bv->showLockedInsetCursor(cx, cy, asc, desc);
795 cursor_visible = !cursor_visible;
799 void InsetText::ShowInsetCursor(BufferView * bv)
801 if (!cursor_visible) {
802 LyXFont font = GetFont(par, actpos);
804 int asc = font.maxAscent();
805 int desc = font.maxDescent();
806 bv->fitLockedInsetCursor(cx, cy, asc, desc);
807 bv->showLockedInsetCursor(cx, cy, asc, desc);
808 cursor_visible = true;
813 void InsetText::HideInsetCursor(BufferView * bv)
816 ToggleInsetCursor(bv);
820 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
825 // search right X-pos x==0 -> top_x
829 for(unsigned int i = 1;
830 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
831 cy = rows[i].baseline;
832 actpos = rows[i].pos;
840 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
841 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
843 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
846 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
847 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
850 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
852 static_cast<UpdatableInset*>(par->GetInset(actpos));
853 inset_x = cx - top_x;
856 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
861 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
863 if (actpos >= par->Last())
865 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
867 static_cast<UpdatableInset*>(par->GetInset(actpos));
868 inset_x = cx - top_x;
871 the_locking_inset->Edit(bv, 0, 0, 0);
880 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
885 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
887 static_cast<UpdatableInset*>(par->GetInset(actpos));
889 inset_x = cx - top_x;
892 the_locking_inset->Edit(bv, the_locking_inset->
893 width(bv->getPainter(), GetFont(par,actpos)),
902 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
906 cy = rows[actrow - 1].baseline - top_baseline;
907 setPos(bv, cx - top_x, cy, activate_inset);
912 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
914 if (actrow >= int(rows.size() - 2))
916 cy = rows[actrow + 1].baseline - top_baseline;
917 setPos(bv, cx - top_x, cy, activate_inset);
922 void InsetText::resetPos(BufferView * bv)
924 int old_pos = actpos;
928 for(int i = 0; rows[i].pos <= actpos; ++i) {
929 cy = rows[i].baseline;
933 setPos(bv, 0, cy, false);
935 while(actpos < old_pos) {
936 cx += SingleWidth(bv->getPainter(), par,actpos);
942 bool InsetText::Delete()
944 /* some insets are undeletable here */
945 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
946 /* force complete redo when erasing display insets */
947 /* this is a cruel mathod but save..... Matthias */
948 if (par->GetInset(actpos)->Deletable() &&
949 par->GetInset(actpos)->display()) {
960 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
962 par->InsertChar(actpos, LyXParagraph::META_INSET);
963 par->InsertInset(actpos, inset);
964 computeTextRows(bv->getPainter());
965 bv->updateInset(this, true);
966 the_locking_inset = static_cast<UpdatableInset*>(inset);
967 inset_x = cx - top_x;
970 inset->Edit(bv, 0, 0, 0);
975 UpdatableInset * InsetText::GetLockingInset()
977 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
981 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
983 // if there is no selection just set the current_font
984 if (!hasSelection()) {
985 // Determine basis font
987 if (actpos < BeginningOfMainBody(par))
988 layoutfont = GetFont(par, -2);
990 layoutfont = GetFont(par, -1);
992 // Update current font
993 real_current_font.update(font, toggleall);
995 // Reduce to implicit settings
996 current_font = real_current_font;
997 current_font.reduce(layoutfont);
998 // And resolve it completely
999 real_current_font.realize(layoutfont);
1004 if (selection_start > selection_end) {
1005 s_start = selection_end;
1006 s_end = selection_start;
1008 s_start = selection_start;
1009 s_end = selection_end;
1012 while(s_start < s_end) {
1013 newfont = GetFont(par,s_start);
1014 newfont.update(font, toggleall);
1015 SetCharFont(s_start, newfont);
1018 computeTextRows(bv->getPainter());
1019 bv->updateInset(this, true);
1023 void InsetText::SetCharFont(int pos, LyXFont const & f)
1025 /* let the insets convert their font */
1028 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1029 if (par->GetInset(pos))
1030 font = par->GetInset(pos)->ConvertFont(font);
1032 LyXLayout const & layout =
1033 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1035 // Get concrete layout font to reduce against
1038 if (pos < BeginningOfMainBody(par))
1039 layoutfont = layout.labelfont;
1041 layoutfont = layout.font;
1044 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1047 // Now, reduce font against full layout font
1048 font.reduce(layoutfont);
1050 par->SetFont(pos, font);
1054 // Ok, Jürgen. Here is my small secret message to you. As you can see I
1055 // played a bit witht he Textinset. (But only through the InsetERT so far).
1056 // As you can see below I have changed the code to use max/min instead of
1057 // the if < construct, imo this makes it faster and easier to read. I have
1058 // also changed rows[rows.size() - 1] to rows.back() makes it clearer that
1059 // we speak about the last element in the vector. I added a second arg to
1060 // to this func as well. This makes it possible to take the position of the
1061 // inset into account when drawing the inset, this is especially needed when
1062 // the ERT inset is first in a paragraph. I am not sure, but this might have
1063 // made short ERT (less than one line, just a couple of words) draw
1064 // incorrectly. You should perhaps have a look yourselves at this.
1065 // Also (phu...) I use pain to get at paperWidth().
1066 // This is beginning to look like a very nice Inset (speaking of the ERT
1067 // inset that is), but in afterthought, do we really need it? Wouldn't a
1068 // non dynamic inset working in the same way as the floats be more usefull
1069 // and easier to work with? Jean-Marc has already aired this thought.
1070 // I tested also a bit on the raw insettext, it seems that it can't break
1071 // over several lines properly. Other than that it seems to create the basis
1072 // for insetfloat, insetmarginal and insetfoot just fine. How about a
1073 // updatable inset that does not open, unless you click on it? uff... I just
1074 // ramble on. Feel free to remove my comments after you have read them.
1076 void InsetText::computeTextRows(Painter & pain, float x) const
1091 //rows.erase(rows.begin(),rows.end());
1092 int width = wordAscent = wordDescent = 0;
1093 insetWidth = maxAscent = maxDescent = 0;
1098 rows.push_back(row);
1099 if (!autoBreakRows) {
1100 for(p = 0; p < par->Last(); ++p) {
1101 insetWidth += SingleWidth(pain, par, p);
1102 SingleHeight(pain, par, p, asc, desc);
1103 maxAscent = max(maxAscent, asc);
1104 //if (asc > maxAscent)
1106 maxDescent = max(maxDescent, desc);
1107 //if (desc > maxDescent)
1108 //maxDescent = desc;
1110 rows[0].asc = maxAscent;
1111 rows[0].desc = maxDescent;
1112 // alocate a dummy row for the endpos
1113 row.pos = par->Last();
1114 rows.push_back(row);
1118 bool is_first_word_in_row = true;
1120 int cw, lastWordWidth = 0;
1122 //maxWidth = buffer->getUser()->paperWidth();
1123 maxWidth = pain.paperWidth();
1124 for(p = 0; p < par->Last(); ++p) {
1125 cw = SingleWidth(pain, par, p);
1127 lastWordWidth += cw;
1128 SingleHeight(pain, par, p, asc, desc);
1129 wordAscent = max(wordAscent, asc);
1130 //if (asc > wordAscent)
1131 // wordAscent = asc;
1132 wordDescent = max(wordDescent, desc);
1133 //if (desc > wordDescent)
1134 // wordDescent = desc;
1135 Inset const * inset = 0;
1136 if (((p + 1) < par->Last()) &&
1137 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1138 inset = par->GetInset(p + 1);
1139 if (inset && inset->display()) {
1140 if (!is_first_word_in_row && (width >= maxWidth - x)) {
1141 // we have to split also the row above
1142 rows.back().asc = oasc;
1143 rows.back().desc = odesc;
1145 rows.push_back(row);
1147 odesc = wordDescent;
1148 insetWidth = max(insetWidth, owidth);
1149 //if (insetWidth < owidth)
1150 // insetWidth = owidth;
1151 width = lastWordWidth;
1154 oasc = max(oasc, wordAscent);
1155 //if (oasc < wordAscent)
1156 //oasc = wordAscent;
1157 odesc = max(odesc, wordDescent);
1158 //if (odesc < wordDescent)
1159 //odesc = wordDescent;
1161 rows.back().asc = oasc;
1162 rows.back().desc = odesc;
1164 rows.push_back(row);
1165 SingleHeight(pain, par, p, asc, desc);
1166 rows.back().asc = asc;
1167 rows.back().desc = desc;
1168 row.pos = nwp = p + 1;
1169 rows.push_back(row);
1170 oasc = odesc = width = lastWordWidth = 0;
1171 is_first_word_in_row = true;
1172 wordAscent = wordDescent = 0;
1175 } else if (par->IsSeparator(p)) {
1176 if (width >= maxWidth - x) {
1177 if (is_first_word_in_row) {
1178 rows.back().asc = wordAscent;
1179 rows.back().desc = wordDescent;
1181 rows.push_back(row);
1182 oasc = odesc = width = 0;
1184 rows.back().asc = oasc;
1185 rows.back().desc = odesc;
1187 rows.push_back(row);
1189 odesc = wordDescent;
1190 insetWidth = max(insetWidth, owidth);
1191 //if (insetWidth < owidth)
1192 //insetWidth = owidth;
1193 width = lastWordWidth;
1195 wordAscent = wordDescent = lastWordWidth = 0;
1201 oasc = max(oasc, wordAscent);
1202 //if (oasc < wordAscent)
1203 //oasc = wordAscent;
1204 odesc = max(odesc, wordDescent);
1205 //if (odesc < wordDescent)
1206 //odesc = wordDescent;
1207 wordAscent = wordDescent = lastWordWidth = 0;
1209 is_first_word_in_row = false;
1213 // if we have some data in the paragraph we have ascent/descent
1215 if (width >= maxWidth) {
1217 rows.back().asc = oasc;
1218 rows.back().desc = odesc;
1219 // assign and allocate lower row
1221 rows.push_back(row);
1222 rows.back().asc = wordAscent;
1223 rows.back().desc = wordDescent;
1224 insetWidth = max(insetWidth, owidth);
1225 //if (insetWidth < owidth)
1226 //insetWidth = owidth;
1228 insetWidth = max(insetWidth, width);
1229 //if (insetWidth < width)
1230 //insetWidth = width;
1232 // assign last row data
1233 oasc = max(oasc, wordAscent);
1234 //if (oasc < wordAscent)
1235 //oasc = wordAscent;
1236 odesc = min(odesc, wordDescent);
1237 //if (odesc < wordDescent)
1238 //odesc = wordDescent;
1239 rows.back().asc = oasc;
1240 rows.back().desc = odesc;
1243 // alocate a dummy row for the endpos
1244 row.pos = par->Last();
1245 rows.push_back(row);
1246 // calculate maxAscent/Descent
1247 maxAscent = rows[0].asc;
1248 maxDescent = rows[0].desc;
1249 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1250 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1252 lyxerr << "Rows: " << rows.size() << endl;
1254 if (the_locking_inset) {
1255 computeBaselines(top_baseline);
1258 inset_x = cx - top_x;
1265 void InsetText::computeBaselines(int baseline) const
1267 rows[0].baseline = baseline;
1268 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1269 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1270 rows[i].asc + interline_space;