2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 * ======================================================
22 #pragma implementation
25 #include "insettext.h"
30 #include "commandtags.h"
33 #include "BufferView.h"
34 #include "support/textutils.h"
36 #include "insetlatexaccent.h"
37 #include "insetquotes.h"
38 #include "mathed/formulamacro.h"
40 #include "insetinfo.h"
41 #include "insetinclude.h"
43 #include "insetcommand.h"
44 #include "insetindex.h"
45 #include "insetlabel.h"
47 //#include "insettabular.h"
49 #include "insetspecialchar.h"
50 #include "LaTeXFeatures.h"
52 #include "lyx_gui_misc.h"
53 #include "support/LAssert.h"
55 extern unsigned char getCurrentTextClass(Buffer *);
57 InsetText::InsetText(Buffer * buf)
59 par = new LyXParagraph();
60 the_locking_inset = 0;
62 cursor_visible = false;
63 maxWidth = old_x = -1;
64 actpos = selection_start = selection_end = 0;
68 maxAscent = maxDescent = insetWidth = 0;
69 autoBreakRows = false;
73 InsetText::InsetText(InsetText const & ins, Buffer * buf)
75 par = new LyXParagraph(ins.par);
76 the_locking_inset = 0;
78 cursor_visible = false;
79 maxWidth = old_x = -1;
80 actpos = selection_start = selection_end = 0;
84 maxAscent = maxDescent = insetWidth = 0;
85 autoBreakRows = false;
89 InsetText::~InsetText()
95 Inset * InsetText::Clone() const
97 InsetText * t = new InsetText(*this, buffer);
102 void InsetText::Write(ostream & os) const
105 WriteParagraphData(os);
109 void InsetText::WriteParagraphData(ostream & os) const
111 par->writeFile(os, buffer->params, 0, 0);
115 void InsetText::Read(LyXLex & lex)
117 string token, tmptok;
119 LyXParagraph * return_par = 0;
120 char depth = 0; // signed or unsigned?
121 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
122 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
123 LyXFont font(LyXFont::ALL_INHERIT);
126 par = new LyXParagraph;
130 token = lex.GetString();
133 if (token == "\\end_inset")
135 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
139 // the_end read this should NEVER happen
140 lex.printError("\\the_end read in inset! Error in document!");
144 if (token != "\\end_inset") {
145 lex.printError("Missing \\end_inset at this point. "
152 int InsetText::ascent(Painter & pain, LyXFont const & font) const
155 computeTextRows(pain);
160 return font.maxAscent();
164 int InsetText::descent(Painter & pain, LyXFont const & font) const
167 computeTextRows(pain);
172 return font.maxDescent();
176 int InsetText::width(Painter & pain, LyXFont const &) const
179 computeTextRows(pain);
186 int InsetText::getMaxWidth(UpdatableInset * inset) const
188 if (!the_locking_inset) {
189 lyxerr << "Text: No locking inset in this inset.\n";
193 if (the_locking_inset == inset)
196 return the_locking_inset->getMaxWidth(inset);
200 void InsetText::draw(Painter & pain, LyXFont const & f,
201 int baseline, float & x) const
204 computeTextRows(pain, x);
205 // init_inset = false;
207 UpdatableInset::draw(pain, f, baseline, x);
209 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
211 top_baseline = baseline;
212 computeBaselines(baseline);
213 for(RowList::size_type r = 0; r < rows.size() - 1; ++r) {
214 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
215 rows[r].baseline, x);
216 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
219 if (!the_locking_inset && do_reset_pos) {
220 // HideInsetCursor(bv);
222 // ShowInsetCursor(bv);
227 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
228 int row, int baseline, float x) const
234 if (selection_start > selection_end) {
235 s_start = selection_end;
236 s_end = selection_start;
238 s_start = selection_start;
239 s_end = selection_end;
241 if ((s_start > endpos) || (s_end < startpos))
245 int ssel_x = esel_x = int(x);
248 for(; p < endpos; ++p) {
251 if ((p >= s_start) && (p <= s_end))
253 char ch = par->GetChar(p);
254 font = GetFont(par,p);
255 if (IsFloatChar(ch)) {
257 } else if (ch == LyXParagraph::META_INSET) {
258 Inset const * tmpinset = par->GetInset(p);
259 x += tmpinset->width(pain, font);
261 x += pain.width(ch,font);
266 if ((p >= s_start) && (p <= s_end))
268 if (ssel_x < esel_x) {
269 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
270 int(esel_x - ssel_x),
271 rows[row].asc + rows[row].desc,
277 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
278 int baseline, float x) const
280 Assert(endpos <= par->Last());
282 for(int p = startpos; p < endpos; ++p) {
283 char ch = par->GetChar(p);
284 LyXFont font = GetFont(par,p);
285 if (IsFloatChar(ch)) {
287 } else if (ch == LyXParagraph::META_INSET) {
288 Inset * tmpinset = par->GetInset(p);
290 tmpinset->draw(pain, font, baseline, x);
292 pain.text(int(x), baseline, ch, font);
293 x += pain.width(ch,font);
299 char const * InsetText::EditMessage() const
301 return _("Opened Text Inset");
305 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
307 UpdatableInset::Edit(bv, x, y, button);
310 the_locking_inset = 0;
311 inset_pos = inset_x = inset_y = 0;
314 selection_start = selection_end = actpos;
315 current_font = real_current_font = GetFont(par, actpos);
319 void InsetText::InsetUnlock(BufferView * bv)
321 if (the_locking_inset)
322 the_locking_inset->InsetUnlock(bv);
324 if (hasSelection()) {
325 selection_start = selection_end = actpos;
326 bv->updateInset(this, false);
328 the_locking_inset = 0;
329 no_selection = false;
333 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
335 if (!the_locking_inset)
337 if (the_locking_inset == inset) {
338 the_locking_inset->InsetUnlock(bv);
339 the_locking_inset = 0;
341 moveRight(bv, false);
344 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
348 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
350 if (!the_locking_inset)
352 if (the_locking_inset != inset)
353 return the_locking_inset->UpdateInsetInInset(bv, inset);
355 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
356 bv->updateInset(this, true);
361 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
363 if (the_locking_inset) {
364 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
367 no_selection = false;
371 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
373 if (hasSelection()) {
374 selection_start = selection_end = actpos;
375 bv->updateInset(this, false);
377 no_selection = false;
378 if (the_locking_inset) {
379 setPos(bv, x, y, false);
382 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
383 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
384 if (the_locking_inset == inset) {
385 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
388 // otherwise unlock the_locking_inset and lock the new inset
392 the_locking_inset->InsetUnlock(bv);
393 the_locking_inset = inset;
394 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
397 // otherwise only unlock the_locking_inset
398 the_locking_inset->InsetUnlock(bv);
401 the_locking_inset = 0;
403 selection_start = selection_end = actpos;
404 if (!the_locking_inset)
409 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
411 if (the_locking_inset) {
412 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
417 int old = selection_end;
418 setPos(bv, x, y, false);
419 selection_end = actpos;
420 if (old != selection_end)
421 bv->updateInset(this, false);
423 no_selection = false;
427 void InsetText::InsetKeyPress(XKeyEvent * xke)
429 if (the_locking_inset) {
430 the_locking_inset->InsetKeyPress(xke);
436 UpdatableInset::RESULT
437 InsetText::LocalDispatch(BufferView * bv,
438 int action, string const & arg)
440 no_selection = false;
441 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
446 UpdatableInset::RESULT
449 if ((action < 0) && arg.empty())
452 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
453 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
455 if (the_locking_inset) {
456 result = the_locking_inset->LocalDispatch(bv, action, arg);
457 if (result == DISPATCHED) {
458 the_locking_inset->ToggleInsetCursor(bv);
459 bv->updateInset(this, false);
460 the_locking_inset->ToggleInsetCursor(bv);
462 } else if (result == FINISHED) {
463 if ((action == LFUN_RIGHT) || (action == -1)) {
464 actpos = inset_pos + 1;
467 the_locking_inset = 0;
475 par->InsertChar(actpos,arg[0]);
476 par->SetFont(actpos,real_current_font);
477 computeTextRows(bv->getPainter());
478 bv->updateInset(this, true);
480 selection_start = selection_end = actpos;
483 // --- Cursor Movements ---------------------------------------------
485 moveRight(bv, false);
486 selection_end = actpos;
487 bv->updateInset(this, false);
490 result= DISPATCH_RESULT(moveRight(bv));
491 if (hasSelection()) {
492 selection_start = selection_end = actpos;
493 bv->updateInset(this, false);
495 selection_start = selection_end = actpos;
500 selection_end = actpos;
501 bv->updateInset(this, false);
504 result= DISPATCH_RESULT(moveLeft(bv));
505 if (hasSelection()) {
506 selection_start = selection_end = actpos;
507 bv->updateInset(this, false);
509 selection_start = selection_end = actpos;
514 selection_end = actpos;
515 bv->updateInset(this, false);
518 result= DISPATCH_RESULT(moveDown(bv));
519 if (hasSelection()) {
520 selection_start = selection_end = actpos;
521 bv->updateInset(this, false);
523 selection_start = selection_end = actpos;
528 selection_end = actpos;
529 bv->updateInset(this, false);
532 result= DISPATCH_RESULT(moveUp(bv));
533 if (hasSelection()) {
534 selection_start = selection_end = actpos;
535 bv->updateInset(this, false);
537 selection_start = selection_end = actpos;
541 if (!actpos || par->IsNewline(actpos-1)) {
542 if (hasSelection()) {
543 selection_start = selection_end = actpos;
544 bv->updateInset(this, false);
550 if (Delete()) { // we need update
551 selection_start = selection_end = actpos;
552 computeTextRows(bv->getPainter());
553 bv->updateInset(this, true);
554 } else if (hasSelection()) {
555 selection_start = selection_end = actpos;
556 bv->updateInset(this, false);
560 for(; actpos > rows[actrow].pos; --actpos)
561 cx -= SingleWidth(bv->getPainter(), par, actpos);
562 cx -= SingleWidth(bv->getPainter(), par, actpos);
563 if (hasSelection()) {
564 selection_start = selection_end = actpos;
565 bv->updateInset(this, false);
567 selection_start = selection_end = actpos;
571 for(; actpos < rows[actrow + 1].pos; ++actpos)
572 cx += SingleWidth(bv->getPainter(), par, actpos);
573 if (hasSelection()) {
574 selection_start = selection_end = actpos;
575 bv->updateInset(this, false);
577 selection_start = selection_end = actpos;
580 case LFUN_MATH_MODE: // Open or create a math inset
581 InsertInset(bv, new InsetFormula);
582 if (hasSelection()) {
583 selection_start = selection_end = actpos;
584 bv->updateInset(this, false);
586 selection_start = selection_end = actpos;
590 result = UNDISPATCHED;
593 if (result != FINISHED) {
594 if (!the_locking_inset)
597 bv->unlockInset(this);
602 int InsetText::Latex(ostream & os, signed char /*fragile*/) const
604 #ifdef USE_OSTREAM_ONLY
606 int ret = par->SimpleTeXOnePar(os, texrow);
611 int i = Latex(fstr, fragile);
618 #ifndef USE_OSTREAM_ONLY
619 int InsetText::Latex(string & file, signed char /* fragile */) const
623 return par->SimpleTeXOnePar(file, texrow);
628 void InsetText::Validate(LaTeXFeatures & features) const
630 par->validate(features);
634 // Returns the width of a character at a certain spot
635 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
637 LyXFont font = GetFont(par, pos);
638 char c = par->GetChar(pos);
640 if (IsPrintable(c)) {
641 return font.width(c);
642 } else if (c == LyXParagraph::META_INSET) {
643 Inset const * tmpinset = par->GetInset(pos);
645 return tmpinset->width(pain, font);
648 } else if (IsSeparatorChar(c))
650 else if (IsNewlineChar(c))
652 return font.width(c);
656 // Returns the width of a character at a certain spot
657 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
658 int & asc, int & desc) const
660 LyXFont font = GetFont(par, pos);
661 char c = par->GetChar(pos);
664 if (c == LyXParagraph::META_INSET) {
665 Inset const * tmpinset=par->GetInset(pos);
667 asc = tmpinset->ascent(pain, font);
668 desc = tmpinset->descent(pain, font);
671 asc = font.maxAscent();
672 desc = font.maxDescent();
678 // Gets the fully instantiated font at a given position in a paragraph
679 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
680 // The difference is that this one is used for displaying, and thus we
681 // are allowed to make cosmetic improvements. For instance make footnotes
683 // If position is -1, we get the layout font of the paragraph.
684 // If position is -2, we get the font of the manual label of the paragraph.
685 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
687 char par_depth = par->GetDepth();
689 LyXLayout const & layout =
690 textclasslist.Style(buffer->params.textclass, par->GetLayout());
692 // We specialize the 95% common case:
693 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
696 if (layout.labeltype == LABEL_MANUAL
697 && pos < BeginningOfMainBody(par)) {
699 return par->GetFontSettings(pos).realize(layout.reslabelfont);
701 return par->GetFontSettings(pos).realize(layout.resfont);
704 // process layoutfont for pos == -1 and labelfont for pos < -1
706 return layout.resfont;
708 return layout.reslabelfont;
711 // The uncommon case need not be optimized as much
713 LyXFont layoutfont, tmpfont;
717 if (pos < BeginningOfMainBody(par)) {
719 layoutfont = layout.labelfont;
722 layoutfont = layout.font;
724 tmpfont = par->GetFontSettings(pos);
725 tmpfont.realize(layoutfont);
728 // process layoutfont for pos == -1 and labelfont for pos < -1
730 tmpfont = layout.font;
732 tmpfont = layout.labelfont;
735 // Resolve against environment font information
736 //if (par->GetDepth()){ // already in while condition
737 while (par && par_depth && !tmpfont.resolved()) {
738 par = par->DepthHook(par_depth - 1);
740 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
741 par->GetLayout()).font);
742 par_depth = par->GetDepth();
745 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
751 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
753 if (textclasslist.Style(buffer->params.textclass,
754 par->GetLayout()).labeltype != LABEL_MANUAL)
757 return par->BeginningOfMainBody();
761 void InsetText::GetCursorPos(int & x, int & y) const
768 int InsetText::InsetInInsetY()
770 if (!the_locking_inset)
774 return (y + the_locking_inset->InsetInInsetY());
778 void InsetText::ToggleInsetCursor(BufferView * bv)
780 if (the_locking_inset) {
781 the_locking_inset->ToggleInsetCursor(bv);
785 LyXFont font = GetFont(par, actpos);
787 int asc = font.maxAscent();
788 int desc = font.maxDescent();
791 bv->hideLockedInsetCursor();
793 bv->showLockedInsetCursor(cx, cy, asc, desc);
794 cursor_visible = !cursor_visible;
798 void InsetText::ShowInsetCursor(BufferView * bv)
800 if (!cursor_visible) {
801 LyXFont font = GetFont(par, actpos);
803 int asc = font.maxAscent();
804 int desc = font.maxDescent();
805 bv->fitLockedInsetCursor(cx, cy, asc, desc);
806 bv->showLockedInsetCursor(cx, cy, asc, desc);
807 cursor_visible = true;
812 void InsetText::HideInsetCursor(BufferView * bv)
815 ToggleInsetCursor(bv);
819 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
824 // search right X-pos x==0 -> top_x
828 for(unsigned int i = 1;
829 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
830 cy = rows[i].baseline;
831 actpos = rows[i].pos;
839 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
840 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
842 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
845 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
846 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
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, ox - inset_x, oy - inset_y, 0);
860 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
862 if (actpos >= par->Last())
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, 0, 0, 0);
879 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
884 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
886 static_cast<UpdatableInset*>(par->GetInset(actpos));
888 inset_x = cx - top_x;
891 the_locking_inset->Edit(bv, the_locking_inset->
892 width(bv->getPainter(), GetFont(par,actpos)),
901 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
905 cy = rows[actrow - 1].baseline - top_baseline;
906 setPos(bv, cx - top_x, cy, activate_inset);
911 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
913 if (actrow >= int(rows.size() - 2))
915 cy = rows[actrow + 1].baseline - top_baseline;
916 setPos(bv, cx - top_x, cy, activate_inset);
921 void InsetText::resetPos(BufferView * bv)
923 int old_pos = actpos;
927 for(int i = 0; rows[i].pos <= actpos; ++i) {
928 cy = rows[i].baseline;
932 setPos(bv, 0, cy, false);
934 while(actpos < old_pos) {
935 cx += SingleWidth(bv->getPainter(), par,actpos);
941 bool InsetText::Delete()
943 /* some insets are undeletable here */
944 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
945 /* force complete redo when erasing display insets */
946 /* this is a cruel mathod but save..... Matthias */
947 if (par->GetInset(actpos)->Deletable() &&
948 par->GetInset(actpos)->display()) {
959 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
961 par->InsertChar(actpos, LyXParagraph::META_INSET);
962 par->InsertInset(actpos, inset);
963 computeTextRows(bv->getPainter());
964 bv->updateInset(this, true);
965 the_locking_inset = static_cast<UpdatableInset*>(inset);
966 inset_x = cx - top_x;
969 inset->Edit(bv, 0, 0, 0);
974 UpdatableInset * InsetText::GetLockingInset()
976 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
980 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
982 // if there is no selection just set the current_font
983 if (!hasSelection()) {
984 // Determine basis font
986 if (actpos < BeginningOfMainBody(par))
987 layoutfont = GetFont(par, -2);
989 layoutfont = GetFont(par, -1);
991 // Update current font
992 real_current_font.update(font, toggleall);
994 // Reduce to implicit settings
995 current_font = real_current_font;
996 current_font.reduce(layoutfont);
997 // And resolve it completely
998 real_current_font.realize(layoutfont);
1003 if (selection_start > selection_end) {
1004 s_start = selection_end;
1005 s_end = selection_start;
1007 s_start = selection_start;
1008 s_end = selection_end;
1011 while(s_start < s_end) {
1012 newfont = GetFont(par,s_start);
1013 newfont.update(font, toggleall);
1014 SetCharFont(s_start, newfont);
1017 computeTextRows(bv->getPainter());
1018 bv->updateInset(this, true);
1022 void InsetText::SetCharFont(int pos, LyXFont const & f)
1024 /* let the insets convert their font */
1027 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1028 if (par->GetInset(pos))
1029 font = par->GetInset(pos)->ConvertFont(font);
1031 LyXLayout const & layout =
1032 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1034 // Get concrete layout font to reduce against
1037 if (pos < BeginningOfMainBody(par))
1038 layoutfont = layout.labelfont;
1040 layoutfont = layout.font;
1043 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1046 // Now, reduce font against full layout font
1047 font.reduce(layoutfont);
1049 par->SetFont(pos, font);
1053 // Ok, Jürgen. Here is my small secret message to you. As you can see I
1054 // played a bit witht he Textinset. (But only through the InsetERT so far).
1055 // As you can see below I have changed the code to use max/min instead of
1056 // the if < construct, imo this makes it faster and easier to read. I have
1057 // also changed rows[rows.size() - 1] to rows.back() makes it clearer that
1058 // we speak about the last element in the vector. I added a second arg to
1059 // to this func as well. This makes it possible to take the position of the
1060 // inset into account when drawing the inset, this is especially needed when
1061 // the ERT inset is first in a paragraph. I am not sure, but this might have
1062 // made short ERT (less than one line, just a couple of words) draw
1063 // incorrectly. You should perhaps have a look yourselves at this.
1064 // Also (phu...) I use pain to get at paperWidth().
1065 // This is beginning to look like a very nice Inset (speaking of the ERT
1066 // inset that is), but in afterthought, do we really need it? Wouldn't a
1067 // non dynamic inset working in the same way as the floats be more usefull
1068 // and easier to work with? Jean-Marc has already aired this thought.
1069 // I tested also a bit on the raw insettext, it seems that it can't break
1070 // over several lines properly. Other than that it seems to create the basis
1071 // for insetfloat, insetmarginal and insetfoot just fine. How about a
1072 // updatable inset that does not open, unless you click on it? uff... I just
1073 // ramble on. Feel free to remove my comments after you have read them.
1075 void InsetText::computeTextRows(Painter & pain, float x) const
1090 //rows.erase(rows.begin(),rows.end());
1091 int width = wordAscent = wordDescent = 0;
1092 insetWidth = maxAscent = maxDescent = 0;
1097 rows.push_back(row);
1098 if (!autoBreakRows) {
1099 for(p = 0; p < par->Last(); ++p) {
1100 insetWidth += SingleWidth(pain, par, p);
1101 SingleHeight(pain, par, p, asc, desc);
1102 maxAscent = max(maxAscent, asc);
1103 //if (asc > maxAscent)
1105 maxDescent = max(maxDescent, desc);
1106 //if (desc > maxDescent)
1107 //maxDescent = desc;
1109 rows[0].asc = maxAscent;
1110 rows[0].desc = maxDescent;
1111 // alocate a dummy row for the endpos
1112 row.pos = par->Last();
1113 rows.push_back(row);
1117 bool is_first_word_in_row = true;
1119 int cw, lastWordWidth = 0;
1121 //maxWidth = buffer->getUser()->paperWidth();
1122 maxWidth = pain.paperWidth();
1123 for(p = 0; p < par->Last(); ++p) {
1124 cw = SingleWidth(pain, par, p);
1126 lastWordWidth += cw;
1127 SingleHeight(pain, par, p, asc, desc);
1128 wordAscent = max(wordAscent, asc);
1129 //if (asc > wordAscent)
1130 // wordAscent = asc;
1131 wordDescent = max(wordDescent, desc);
1132 //if (desc > wordDescent)
1133 // wordDescent = desc;
1134 Inset const * inset = 0;
1135 if (((p + 1) < par->Last()) &&
1136 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1137 inset = par->GetInset(p + 1);
1138 if (inset && inset->display()) {
1139 if (!is_first_word_in_row && (width >= maxWidth - x)) {
1140 // we have to split also the row above
1141 rows.back().asc = oasc;
1142 rows.back().desc = odesc;
1144 rows.push_back(row);
1146 odesc = wordDescent;
1147 insetWidth = max(insetWidth, owidth);
1148 //if (insetWidth < owidth)
1149 // insetWidth = owidth;
1150 width = lastWordWidth;
1153 oasc = max(oasc, wordAscent);
1154 //if (oasc < wordAscent)
1155 //oasc = wordAscent;
1156 odesc = max(odesc, wordDescent);
1157 //if (odesc < wordDescent)
1158 //odesc = wordDescent;
1160 rows.back().asc = oasc;
1161 rows.back().desc = odesc;
1163 rows.push_back(row);
1164 SingleHeight(pain, par, p, asc, desc);
1165 rows.back().asc = asc;
1166 rows.back().desc = desc;
1167 row.pos = nwp = p + 1;
1168 rows.push_back(row);
1169 oasc = odesc = width = lastWordWidth = 0;
1170 is_first_word_in_row = true;
1171 wordAscent = wordDescent = 0;
1174 } else if (par->IsSeparator(p)) {
1175 if (width >= maxWidth - x) {
1176 if (is_first_word_in_row) {
1177 rows.back().asc = wordAscent;
1178 rows.back().desc = wordDescent;
1180 rows.push_back(row);
1181 oasc = odesc = width = 0;
1183 rows.back().asc = oasc;
1184 rows.back().desc = odesc;
1186 rows.push_back(row);
1188 odesc = wordDescent;
1189 insetWidth = max(insetWidth, owidth);
1190 //if (insetWidth < owidth)
1191 //insetWidth = owidth;
1192 width = lastWordWidth;
1194 wordAscent = wordDescent = lastWordWidth = 0;
1200 oasc = max(oasc, wordAscent);
1201 //if (oasc < wordAscent)
1202 //oasc = wordAscent;
1203 odesc = max(odesc, wordDescent);
1204 //if (odesc < wordDescent)
1205 //odesc = wordDescent;
1206 wordAscent = wordDescent = lastWordWidth = 0;
1208 is_first_word_in_row = false;
1212 // if we have some data in the paragraph we have ascent/descent
1214 if (width >= maxWidth) {
1216 rows.back().asc = oasc;
1217 rows.back().desc = odesc;
1218 // assign and allocate lower row
1220 rows.push_back(row);
1221 rows.back().asc = wordAscent;
1222 rows.back().desc = wordDescent;
1223 insetWidth = max(insetWidth, owidth);
1224 //if (insetWidth < owidth)
1225 //insetWidth = owidth;
1227 insetWidth = max(insetWidth, width);
1228 //if (insetWidth < width)
1229 //insetWidth = width;
1231 // assign last row data
1232 oasc = max(oasc, wordAscent);
1233 //if (oasc < wordAscent)
1234 //oasc = wordAscent;
1235 odesc = min(odesc, wordDescent);
1236 //if (odesc < wordDescent)
1237 //odesc = wordDescent;
1238 rows.back().asc = oasc;
1239 rows.back().desc = odesc;
1242 // alocate a dummy row for the endpos
1243 row.pos = par->Last();
1244 rows.push_back(row);
1245 // calculate maxAscent/Descent
1246 maxAscent = rows[0].asc;
1247 maxDescent = rows[0].desc;
1248 for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
1249 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1251 lyxerr << "Rows: " << rows.size() << endl;
1253 if (the_locking_inset) {
1254 computeBaselines(top_baseline);
1257 inset_x = cx - top_x;
1264 void InsetText::computeBaselines(int baseline) const
1266 rows[0].baseline = baseline;
1267 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1268 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1269 rows[i].asc + interline_space;