1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
17 #include "bufferparams.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
26 #include "frontends/screen.h"
27 #include "frontends/WorkArea.h"
28 #include "bufferview_funcs.h"
29 #include "BufferView.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "paragraph_funcs.h"
35 #include "rowpainter.h"
37 #include "insets/insettext.h"
39 #include "support/textutils.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
51 /// top, right, bottom pixel margin
52 extern int const PAPER_MARGIN = 20;
53 /// margin for changebar
54 extern int const CHANGEBAR_MARGIN = 10;
56 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
58 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
61 BufferView * LyXText::bv()
63 lyx::Assert(bv_owner != 0);
68 BufferView * LyXText::bv() const
70 lyx::Assert(bv_owner != 0);
75 int LyXText::top_y() const
81 for (Row * row = firstrow;
82 row && row != anchor_row_; row = row->next()) {
85 return y + anchor_row_offset_;
89 void LyXText::top_y(int newy)
93 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
96 Row * row = getRowNearY(y);
98 if (row == anchor_row_ && anchor_row_offset_ == newy - y) {
99 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
104 anchor_row_offset_ = newy - y;
105 lyxerr[Debug::GUI] << "changing reference to row: " << anchor_row_
106 << " offset: " << anchor_row_offset_ << endl;
111 void LyXText::anchor_row(Row * row)
114 anchor_row_offset_ = 0;
116 anchor_row_offset_ = old_y - top_y();
117 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
118 << anchor_row_ << " offset: " << anchor_row_offset_
123 int LyXText::workWidth() const
126 // FIXME: pass (const ?) ref
127 return inset_owner->textWidth(bv());
129 return bv()->workWidth();
133 int LyXText::workWidth(Inset * inset) const
135 Paragraph * par = inset->parOwner();
138 pos_type pos = par->getPositionOfInset(inset);
139 lyx::Assert(pos != -1);
141 LyXLayout_ptr const & layout = par->layout();
143 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
144 // Optimization here: in most cases, the real row is
145 // not needed, but only the par/pos values. So we just
146 // construct a dummy row for leftMargin. (JMarc)
150 return workWidth() - leftMargin(&dummyrow);
153 Row * row = getRow(par, pos, dummy_y);
155 while (frow->previous() && frow->par() == frow->previous()->par())
156 frow = frow->previous();
158 // FIXME: I don't understand this code - jbl
160 unsigned int maxw = 0;
161 while (!frow->isParEnd()) {
162 if ((frow != row) && (maxw < frow->width()))
163 maxw = frow->width();
174 int LyXText::getRealCursorX() const
177 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
178 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
183 unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
186 if (!Encodings::is_arabic(c))
187 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
188 return c + (0xb0 - '0');
192 unsigned char const prev_char = pos > 0 ? par->getChar(pos-1) : ' ';
193 unsigned char next_char = ' ';
195 for (pos_type i = pos+1; i < par->size(); ++i)
196 if (!Encodings::IsComposeChar_arabic(par->getChar(i))) {
197 next_char = par->getChar(i);
201 if (Encodings::is_arabic(next_char)) {
202 if (Encodings::is_arabic(prev_char) &&
203 !Encodings::is_arabic_special(prev_char))
204 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
206 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
208 if (Encodings::is_arabic(prev_char) &&
209 !Encodings::is_arabic_special(prev_char))
210 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
212 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
216 // This is the comments that some of the warnings below refers to.
217 // There are some issues in this file and I don't think they are
218 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
219 // this is a problem that has been here almost from day one and that a
220 // larger userbase with differenct access patters triggers the bad
221 // behaviour. (segfaults.) What I think happen is: In several places
222 // we store the paragraph in the current cursor and then moves the
223 // cursor. This movement of the cursor will delete paragraph at the
224 // old position if it is now empty. This will make the temporary
225 // pointer to the old cursor paragraph invalid and dangerous to use.
226 // And is some cases this will trigger a segfault. I have marked some
227 // of the cases where this happens with a warning, but I am sure there
228 // are others in this file and in text2.C. There is also a note in
229 // Delete() that you should read. In Delete I store the paragraph->id
230 // instead of a pointer to the paragraph. I am pretty sure this faulty
231 // use of temporary pointers to paragraphs that might have gotten
232 // invalidated (through a cursor movement) before they are used, are
233 // the cause of the strange crashes we get reported often.
235 // It is very tiresom to change this code, especially when it is as
236 // hard to read as it is. Help to fix all the cases where this is done
237 // would be greately appreciated.
241 int LyXText::singleWidth(Paragraph * par,
244 if (pos >= par->size())
247 char const c = par->getChar(pos);
248 return singleWidth(par, pos, c);
252 int LyXText::singleWidth(Paragraph * par,
253 pos_type pos, char c) const
255 if (pos >= par->size())
258 LyXFont const font = getFont(bv()->buffer(), par, pos);
260 // The most common case is handled first (Asger)
261 if (IsPrintable(c)) {
262 if (font.language()->RightToLeft()) {
263 if (font.language()->lang() == "arabic" &&
264 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
265 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
266 if (Encodings::IsComposeChar_arabic(c))
269 c = transformChar(c, par, pos);
270 } else if (font.language()->lang() == "hebrew" &&
271 Encodings::IsComposeChar_hebrew(c))
274 return font_metrics::width(c, font);
278 if (c == Paragraph::META_INSET) {
279 Inset * tmpinset = par->getInset(pos);
281 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
282 // Because of the representation as vertical lines
286 #warning inset->update FIXME
287 // this IS needed otherwise on initialitation we don't get the fill
288 // of the row right (ONLY on initialization if we read a file!)
289 // should be changed! (Jug 20011204)
290 tmpinset->update(bv());
292 return tmpinset->width(bv(), font);
297 if (IsSeparatorChar(c))
299 return font_metrics::width(c, font);
303 void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
305 bidi_same_direction = true;
306 if (!lyxrc.rtl_support) {
311 Inset * inset = row->par()->inInset();
312 if (inset && inset->owner() &&
313 inset->owner()->lyxCode() == Inset::ERT_CODE) {
318 bidi_start = row->pos();
319 bidi_end = row->lastPrintablePos();
321 if (bidi_start > bidi_end) {
326 if (bidi_end + 2 - bidi_start >
327 static_cast<pos_type>(log2vis_list.size())) {
329 (bidi_end + 2 - bidi_start < 500) ?
330 500 : 2 * (bidi_end + 2 - bidi_start);
331 log2vis_list.resize(new_size);
332 vis2log_list.resize(new_size);
333 bidi_levels.resize(new_size);
336 vis2log_list[bidi_end + 1 - bidi_start] = -1;
337 log2vis_list[bidi_end + 1 - bidi_start] = -1;
341 row->par()->isRightToLeftPar(buf->params);
345 pos_type const body_pos = row->par()->beginningOfBody();
347 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
348 bool is_space = row->par()->isLineSeparator(lpos);
350 (is_space && lpos + 1 <= bidi_end &&
351 !row->par()->isLineSeparator(lpos + 1) &&
352 !row->par()->isNewline(lpos + 1))
354 LyXFont font = row->par()->getFontSettings(buf->params, pos);
355 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
356 font.number() == LyXFont::ON &&
357 row->par()->getFontSettings(buf->params, lpos - 1).number()
359 font = row->par()->getFontSettings(buf->params, lpos);
364 bool new_rtl = font.isVisibleRightToLeft();
365 bool new_rtl0 = font.isRightToLeft();
368 if (lpos == body_pos - 1
369 && row->pos() < body_pos - 1
371 new_level = (rtl_par) ? 1 : 0;
372 new_rtl = new_rtl0 = rtl_par;
374 new_level = (new_rtl) ? 1 : 2;
376 new_level = (rtl_par) ? 2 : 0;
378 if (is_space && new_level >= level) {
384 int new_level2 = new_level;
386 if (level == new_level && rtl0 != new_rtl0) {
388 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
389 } else if (level < new_level) {
390 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
391 if (new_level > rtl_par)
392 bidi_same_direction = false;
394 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
397 bidi_levels[lpos - bidi_start] = new_level;
399 while (level > new_level2) {
400 pos_type old_lpos = stack[--level];
401 int delta = lpos - old_lpos - 1;
404 log2vis_list[lpos - bidi_start] += delta;
405 log2vis_list[old_lpos - bidi_start] += delta;
407 while (level < new_level)
408 stack[level++] = lpos;
412 pos_type const old_lpos = stack[--level];
413 int delta = bidi_end - old_lpos;
416 log2vis_list[old_lpos - bidi_start] += delta;
419 pos_type vpos = bidi_start - 1;
420 for (pos_type lpos = bidi_start;
421 lpos <= bidi_end; ++lpos) {
422 vpos += log2vis_list[lpos - bidi_start];
423 vis2log_list[vpos - bidi_start] = lpos;
424 log2vis_list[lpos - bidi_start] = vpos;
429 // This method requires a previous call to ComputeBidiTables()
430 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
433 if (!lyxrc.rtl_support || pos == 0)
436 if (!bidi_InRange(pos - 1)) {
437 /// This can happen if pos is the first char of a row.
438 /// Returning false in this case is incorrect!
442 bool const rtl = bidi_level(pos - 1) % 2;
443 bool const rtl2 = bidi_InRange(pos)
444 ? bidi_level(pos) % 2
445 : par->isRightToLeftPar(buf->params);
450 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
451 pos_type pos, LyXFont const & font) const
453 if (!lyxrc.rtl_support)
454 return false; // This is just for speedup
456 bool const rtl = font.isVisibleRightToLeft();
457 bool const rtl2 = bidi_InRange(pos)
458 ? bidi_level(pos) % 2
459 : par->isRightToLeftPar(buf->params);
464 int LyXText::leftMargin(Row const * row) const
468 if (row->pos() < row->par()->size())
469 if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
470 (ins = row->par()->getInset(row->pos())) &&
471 (ins->needFullRow() || ins->display()))
474 LyXTextClass const & tclass =
475 bv()->buffer()->params.getLyXTextClass();
476 LyXLayout_ptr const & layout = row->par()->layout();
478 string parindent = layout->parindent;
482 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
484 // this is the way, LyX handles the LaTeX-Environments.
485 // I have had this idea very late, so it seems to be a
486 // later added hack and this is true
487 if (!row->par()->getDepth()) {
488 if (row->par()->layout() == tclass.defaultLayout()) {
489 // find the previous same level paragraph
490 if (row->par()->previous()) {
491 Paragraph * newpar = row->par()
492 ->depthHook(row->par()->getDepth());
494 newpar->layout()->nextnoindent)
499 // find the next level paragraph
501 Paragraph * newpar = row->par()->outerHook();
503 // make a corresponding row. Needed to call LeftMargin()
505 // check wether it is a sufficent paragraph
506 if (newpar && newpar->layout()->isEnvironment()) {
508 dummyrow.par(newpar);
509 dummyrow.pos(newpar->size());
510 x = leftMargin(&dummyrow);
512 // this is no longer an error, because this function
513 // is used to clear impossible depths after changing
514 // a layout. Since there is always a redo,
515 // LeftMargin() is always called
516 row->par()->params().depth(0);
519 if (newpar && row->par()->layout() == tclass.defaultLayout()) {
520 if (newpar->params().noindent())
523 parindent = newpar->layout()->parindent;
529 LyXFont const labelfont = getLabelFont(bv()->buffer(), row->par());
530 switch (layout->margintype) {
532 if (!layout->leftmargin.empty()) {
533 x += font_metrics::signedWidth(layout->leftmargin,
534 tclass.defaultfont());
536 if (!row->par()->getLabelstring().empty()) {
537 x += font_metrics::signedWidth(layout->labelindent,
539 x += font_metrics::width(row->par()->getLabelstring(),
541 x += font_metrics::width(layout->labelsep, labelfont);
545 x += font_metrics::signedWidth(layout->labelindent, labelfont);
546 // The width of an empty par, even with manual label, should be 0
547 if (!row->par()->empty() && row->pos() >= row->par()->beginningOfBody()) {
548 if (!row->par()->getLabelWidthString().empty()) {
549 x += font_metrics::width(row->par()->getLabelWidthString(),
551 x += font_metrics::width(layout->labelsep, labelfont);
556 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
557 / (row->par()->getDepth() + 4);
559 case MARGIN_FIRST_DYNAMIC:
560 if (layout->labeltype == LABEL_MANUAL) {
561 if (row->pos() >= row->par()->beginningOfBody()) {
562 x += font_metrics::signedWidth(layout->leftmargin,
565 x += font_metrics::signedWidth(layout->labelindent,
568 } else if (row->pos()
569 // Special case to fix problems with
571 || (layout->labeltype == LABEL_STATIC
572 && layout->latextype == LATEX_ENVIRONMENT
573 && ! row->par()->isFirstInSequence())) {
574 x += font_metrics::signedWidth(layout->leftmargin,
576 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
577 && layout->labeltype != LABEL_BIBLIO
578 && layout->labeltype !=
579 LABEL_CENTERED_TOP_ENVIRONMENT) {
580 x += font_metrics::signedWidth(layout->labelindent,
582 x += font_metrics::width(layout->labelsep, labelfont);
583 x += font_metrics::width(row->par()->getLabelstring(),
588 case MARGIN_RIGHT_ADDRESS_BOX:
590 // ok, a terrible hack. The left margin depends on the widest
591 // row in this paragraph. Do not care about footnotes, they
592 // are *NOT* allowed in the LaTeX realisation of this layout.
594 // find the first row of this paragraph
595 Row const * tmprow = row;
596 while (tmprow->previous()
597 && tmprow->previous()->par() == row->par())
598 tmprow = tmprow->previous();
600 int minfill = tmprow->fill();
601 while (tmprow->next() && tmprow->next()->par() == row->par()) {
602 tmprow = tmprow->next();
603 if (tmprow->fill() < minfill)
604 minfill = tmprow->fill();
607 x += font_metrics::signedWidth(layout->leftmargin,
608 tclass.defaultfont());
614 if ((workWidth() > 0) &&
615 !row->par()->params().leftIndent().zero())
617 LyXLength const len = row->par()->params().leftIndent();
618 int const tw = inset_owner ?
619 inset_owner->latexTextWidth(bv()) : workWidth();
620 x += len.inPixels(tw);
623 LyXAlignment align; // wrong type
625 if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
626 align = layout->align;
628 align = row->par()->params().align();
630 // set the correct parindent
631 if (row->pos() == 0) {
632 if ((layout->labeltype == LABEL_NO_LABEL
633 || layout->labeltype == LABEL_TOP_ENVIRONMENT
634 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
635 || (layout->labeltype == LABEL_STATIC
636 && layout->latextype == LATEX_ENVIRONMENT
637 && ! row->par()->isFirstInSequence()))
638 && align == LYX_ALIGN_BLOCK
639 && !row->par()->params().noindent()
640 // in tabulars and ert paragraphs are never indented!
641 && (!row->par()->inInset() || !row->par()->inInset()->owner() ||
642 (row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
643 row->par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
644 && (row->par()->layout() != tclass.defaultLayout() ||
645 bv()->buffer()->params.paragraph_separation ==
646 BufferParams::PARSEP_INDENT)) {
647 x += font_metrics::signedWidth(parindent,
648 tclass.defaultfont());
649 } else if (layout->labeltype == LABEL_BIBLIO) {
650 // ale970405 Right width for bibitems
651 x += bibitemMaxWidth(bv(), tclass.defaultfont());
659 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
663 if (row.pos() < row.par()->size())
664 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
665 (ins=row.par()->getInset(row.pos())) &&
666 (ins->needFullRow() || ins->display()))
669 LyXTextClass const & tclass = buf.params.getLyXTextClass();
670 LyXLayout_ptr const & layout = row.par()->layout();
673 + font_metrics::signedWidth(tclass.rightmargin(),
674 tclass.defaultfont());
676 // this is the way, LyX handles the LaTeX-Environments.
677 // I have had this idea very late, so it seems to be a
678 // later added hack and this is true
679 if (row.par()->getDepth()) {
680 // find the next level paragraph
682 Paragraph const * newpar = row.par();
685 newpar = newpar->previous();
687 && newpar->getDepth() >= row.par()->getDepth());
689 // make a corresponding row. Needed to call LeftMargin()
691 // check wether it is a sufficent paragraph
692 if (newpar && newpar->layout()->isEnvironment()) {
694 dummyrow.par(const_cast<Paragraph *>(newpar));
696 x = rightMargin(buf, dummyrow);
698 // this is no longer an error, because this function
699 // is used to clear impossible depths after changing
700 // a layout. Since there is always a redo,
701 // LeftMargin() is always called
702 row.par()->params().depth(0);
706 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
707 x += font_metrics::signedWidth(layout->rightmargin,
708 tclass.defaultfont())
709 * 4 / (row.par()->getDepth() + 4);
714 int LyXText::labelEnd(Row const & row) const
716 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
718 tmprow.pos(row.par()->size());
719 // return the beginning of the body
720 return leftMargin(&tmprow);
723 // LabelEnd is only needed if the layout
724 // fills a flushleft label.
731 // this needs special handling - only newlines count as a break point
732 pos_type addressBreakPoint(pos_type i, Paragraph * par)
734 for (; i < par->size(); ++i) {
735 if (par->isNewline(i))
746 LyXText::rowBreakPoint(Row const & row) const
748 Paragraph * par = row.par();
750 // maximum pixel width of a row.
751 int width = workWidth() - rightMargin(*bv()->buffer(), row);
753 // inset->textWidth() returns -1 via workWidth(),
758 LyXLayout_ptr const & layout = par->layout();
760 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
761 return addressBreakPoint(row.pos(), par);
763 pos_type const pos = row.pos();
764 pos_type const body_pos = par->beginningOfBody();
765 pos_type const last = par->size();
766 pos_type point = last;
771 // Now we iterate through until we reach the right margin
772 // or the end of the par, then choose the possible break
775 int const left = leftMargin(&row);
778 // pixel width since last breakpoint
782 for (; i < last; ++i) {
784 if (par->isNewline(i)) {
789 char const c = par->getChar(i);
791 int thiswidth = singleWidth(par, i, c);
793 // add the auto-hfill from label end to the body
794 if (body_pos && i == body_pos) {
795 thiswidth += font_metrics::width(layout->labelsep,
796 getLabelFont(bv()->buffer(), par));
797 if (par->isLineSeparator(i - 1))
798 thiswidth -= singleWidth(par, i - 1);
799 int left_margin = labelEnd(row);
800 if (thiswidth < left_margin)
801 thiswidth = left_margin;
805 chunkwidth += thiswidth;
807 Inset * in = par->isInset(i) ? par->getInset(i) : 0;
808 bool fullrow = (in && (in->display() || in->needFullRow()));
810 // break before a character that will fall off
811 // the right of the row
813 // if no break before or we are at an inset
814 // that will take up a row, break here
815 if (point == last || fullrow || chunkwidth >= (width - left)) {
824 if (!in || in->isChar()) {
825 // some insets are line separators too
826 if (par->isLineSeparator(i)) {
836 // full row insets start at a new row
838 if (pos < last - 1) {
840 if (par->isLineSeparator(i + 1))
843 // to avoid extra rows
852 if (point == last && x >= width) {
853 // didn't find one, break at the point we reached the edge
855 } else if (i == last && x < width) {
856 // found one, but we fell off the end of the par, so prefer
861 // manual labels cannot be broken in LaTeX
862 if (body_pos && point < body_pos)
863 point = body_pos - 1;
869 // returns the minimum space a row needs on the screen in pixel
870 int LyXText::fill(Row & row, int paper_width) const
876 // get the pure distance
877 pos_type const last = row.lastPrintablePos();
879 // special handling of the right address boxes
880 if (row.par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
881 int const tmpfill = row.fill();
882 row.fill(0); // the minfill in MarginLeft()
883 w = leftMargin(&row);
886 w = leftMargin(&row);
888 Paragraph * par = row.par();
889 LyXLayout_ptr const & layout = par->layout();
891 pos_type const body_pos = par->beginningOfBody();
892 pos_type i = row.pos();
895 if (body_pos > 0 && i == body_pos) {
896 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), par));
897 if (par->isLineSeparator(i - 1))
898 w -= singleWidth(par, i - 1);
899 int left_margin = labelEnd(row);
903 w += singleWidth(par, i);
906 if (body_pos > 0 && body_pos > last) {
907 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), par));
908 if (last >= 0 && par->isLineSeparator(last))
909 w -= singleWidth(par, last);
910 int const left_margin = labelEnd(row);
915 int const fill = paper_width - w - rightMargin(*bv()->buffer(), row);
920 // returns the minimum space a manual label needs on the screen in pixel
921 int LyXText::labelFill(Row const & row) const
923 pos_type last = row.par()->beginningOfBody();
925 lyx::Assert(last > 0);
927 // -1 because a label ends either with a space that is in the label,
928 // or with the beginning of a footnote that is outside the label.
931 // a separator at this end does not count
932 if (row.par()->isLineSeparator(last))
936 pos_type i = row.pos();
938 w += singleWidth(row.par(), i);
943 string const & labwidstr = row.par()->params().labelWidthString();
944 if (!labwidstr.empty()) {
945 LyXFont const labfont = getLabelFont(bv()->buffer(), row.par());
946 int const labwidth = font_metrics::width(labwidstr, labfont);
947 fill = max(labwidth - w, 0);
954 LColor::color LyXText::backgroundColor() const
957 return inset_owner->backgroundColor();
959 return LColor::background;
962 void LyXText::setHeightOfRow(Row * row)
964 // get the maximum ascent and the maximum descent
968 float layoutdesc = 0;
971 Inset * tmpinset = 0;
973 // ok , let us initialize the maxasc and maxdesc value.
974 // This depends in LaTeX of the font of the last character
975 // in the paragraph. The hack below is necessary because
976 // of the possibility of open footnotes
978 // Correction: only the fontsize count. The other properties
979 // are taken from the layoutfont. Nicer on the screen :)
980 Paragraph * par = row->par();
981 Paragraph * firstpar = row->par();
983 LyXLayout_ptr const & layout = firstpar->layout();
985 // as max get the first character of this row then it can increase but not
986 // decrease the height. Just some point to start with so we don't have to
987 // do the assignment below too often.
988 LyXFont font = getFont(bv()->buffer(), par, row->pos());
989 LyXFont::FONT_SIZE const tmpsize = font.size();
990 font = getLayoutFont(bv()->buffer(), par);
991 LyXFont::FONT_SIZE const size = font.size();
992 font.setSize(tmpsize);
994 LyXFont labelfont = getLabelFont(bv()->buffer(), par);
996 float spacing_val = 1.0;
997 if (!row->par()->params().spacing().isDefault()) {
998 spacing_val = row->par()->params().spacing().getValue();
1000 spacing_val = bv()->buffer()->params.spacing.getValue();
1002 //lyxerr << "spacing_val = " << spacing_val << endl;
1004 int maxasc = int(font_metrics::maxAscent(font) *
1005 layout->spacing.getValue() *
1007 int maxdesc = int(font_metrics::maxDescent(font) *
1008 layout->spacing.getValue() *
1011 pos_type const pos_end = row->lastPos();
1015 if (!row->par()->empty()) {
1016 // Check if any insets are larger
1017 for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
1018 if (row->par()->isInset(pos)) {
1019 tmpfont = getFont(bv()->buffer(), row->par(), pos);
1020 tmpinset = row->par()->getInset(pos);
1022 #if 1 // this is needed for deep update on initialitation
1023 #warning inset->update FIXME
1024 tmpinset->update(bv());
1026 asc = tmpinset->ascent(bv(), tmpfont);
1027 desc = tmpinset->descent(bv(), tmpfont);
1028 maxwidth += tmpinset->width(bv(), tmpfont);
1029 maxasc = max(maxasc, asc);
1030 maxdesc = max(maxdesc, desc);
1033 maxwidth += singleWidth(row->par(), pos);
1038 // Check if any custom fonts are larger (Asger)
1039 // This is not completely correct, but we can live with the small,
1040 // cosmetic error for now.
1041 LyXFont::FONT_SIZE maxsize =
1042 row->par()->highestFontInRange(row->pos(), pos_end, size);
1043 if (maxsize > font.size()) {
1044 font.setSize(maxsize);
1046 asc = font_metrics::maxAscent(font);
1047 desc = font_metrics::maxDescent(font);
1054 // This is nicer with box insets:
1058 row->ascent_of_text(maxasc);
1060 // is it a top line?
1061 if (!row->pos() && (row->par() == firstpar)) {
1063 // some parksips VERY EASY IMPLEMENTATION
1064 if (bv()->buffer()->params.paragraph_separation ==
1065 BufferParams::PARSEP_SKIP)
1067 if (layout->isParagraph()
1068 && firstpar->getDepth() == 0
1069 && firstpar->previous())
1071 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1072 } else if (firstpar->previous() &&
1073 firstpar->previous()->layout()->isParagraph() &&
1074 firstpar->previous()->getDepth() == 0)
1076 // is it right to use defskip here too? (AS)
1077 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1082 if (!row->par()->previous() && !isInInset())
1083 maxasc += PAPER_MARGIN;
1085 // add the vertical spaces, that the user added
1086 maxasc += getLengthMarkerHeight(*bv(), firstpar->params().spaceTop());
1088 // do not forget the DTP-lines!
1089 // there height depends on the font of the nearest character
1090 if (firstpar->params().lineTop())
1092 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1094 // and now the pagebreaks
1095 if (firstpar->params().pagebreakTop())
1096 maxasc += 3 * defaultRowHeight();
1098 if (firstpar->params().startOfAppendix())
1099 maxasc += 3 * defaultRowHeight();
1101 // This is special code for the chapter, since the label of this
1102 // layout is printed in an extra row
1103 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1104 && bv()->buffer()->params.secnumdepth >= 0)
1106 float spacing_val = 1.0;
1107 if (!row->par()->params().spacing().isDefault()) {
1108 spacing_val = row->par()->params().spacing().getValue();
1110 spacing_val = bv()->buffer()->params.spacing.getValue();
1113 labeladdon = int(font_metrics::maxDescent(labelfont) *
1114 layout->spacing.getValue() *
1116 + int(font_metrics::maxAscent(labelfont) *
1117 layout->spacing.getValue() *
1121 // special code for the top label
1122 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1123 || layout->labeltype == LABEL_BIBLIO
1124 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1125 && row->par()->isFirstInSequence()
1126 && !row->par()->getLabelstring().empty())
1128 float spacing_val = 1.0;
1129 if (!row->par()->params().spacing().isDefault()) {
1130 spacing_val = row->par()->params().spacing().getValue();
1132 spacing_val = bv()->buffer()->params.spacing.getValue();
1136 (font_metrics::maxAscent(labelfont) *
1137 layout->spacing.getValue() *
1139 +(font_metrics::maxDescent(labelfont) *
1140 layout->spacing.getValue() *
1142 + layout->topsep * defaultRowHeight()
1143 + layout->labelbottomsep * defaultRowHeight());
1146 // and now the layout spaces, for example before and after a section,
1147 // or between the items of a itemize or enumerate environment
1149 if (!firstpar->params().pagebreakTop()) {
1150 Paragraph * prev = row->par()->previous();
1152 prev = row->par()->depthHook(row->par()->getDepth());
1153 if (prev && prev->layout() == firstpar->layout() &&
1154 prev->getDepth() == firstpar->getDepth() &&
1155 prev->getLabelWidthString() == firstpar->getLabelWidthString())
1157 layoutasc = (layout->itemsep * defaultRowHeight());
1158 } else if (row->previous()) {
1159 tmptop = layout->topsep;
1161 if (row->previous()->par()->getDepth() >= row->par()->getDepth())
1162 tmptop -= row->previous()->par()->layout()->bottomsep;
1165 layoutasc = (tmptop * defaultRowHeight());
1166 } else if (row->par()->params().lineTop()) {
1167 tmptop = layout->topsep;
1170 layoutasc = (tmptop * defaultRowHeight());
1173 prev = row->par()->outerHook();
1175 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1177 if (firstpar->previous() &&
1178 firstpar->previous()->getDepth() == 0 &&
1179 firstpar->previous()->layout() !=
1183 } else if (firstpar->previous()) {
1184 maxasc += int(layout->parsep * defaultRowHeight());
1190 // is it a bottom line?
1191 if (row->par() == par
1192 && (!row->next() || row->next()->par() != row->par())) {
1193 // the bottom margin
1194 if (!par->next() && !isInInset())
1195 maxdesc += PAPER_MARGIN;
1197 // add the vertical spaces, that the user added
1198 maxdesc += getLengthMarkerHeight(*bv(), firstpar->params().spaceBottom());
1200 // do not forget the DTP-lines!
1201 // there height depends on the font of the nearest character
1202 if (firstpar->params().lineBottom())
1203 maxdesc += 2 * font_metrics::ascent('x',
1204 getFont(bv()->buffer(),
1206 max(pos_type(0), par->size() - 1)));
1208 // and now the pagebreaks
1209 if (firstpar->params().pagebreakBottom())
1210 maxdesc += 3 * defaultRowHeight();
1212 // and now the layout spaces, for example before and after
1213 // a section, or between the items of a itemize or enumerate
1215 if (!firstpar->params().pagebreakBottom()
1216 && row->par()->next()) {
1217 Paragraph * nextpar = row->par()->next();
1218 Paragraph * comparepar = row->par();
1222 if (comparepar->getDepth() > nextpar->getDepth()) {
1223 usual = (comparepar->layout()->bottomsep * defaultRowHeight());
1224 comparepar = comparepar->depthHook(nextpar->getDepth());
1225 if (comparepar->layout()!= nextpar->layout()
1226 || nextpar->getLabelWidthString() !=
1227 comparepar->getLabelWidthString())
1229 unusual = (comparepar->layout()->bottomsep * defaultRowHeight());
1231 if (unusual > usual)
1232 layoutdesc = unusual;
1235 } else if (comparepar->getDepth() == nextpar->getDepth()) {
1237 if (comparepar->layout() != nextpar->layout()
1238 || nextpar->getLabelWidthString() !=
1239 comparepar->getLabelWidthString())
1240 layoutdesc = int(comparepar->layout()->bottomsep * defaultRowHeight());
1245 // incalculate the layout spaces
1246 maxasc += int(layoutasc * 2 / (2 + firstpar->getDepth()));
1247 maxdesc += int(layoutdesc * 2 / (2 + firstpar->getDepth()));
1249 // calculate the new height of the text
1250 height -= row->height();
1252 row->height(maxasc + maxdesc + labeladdon);
1253 row->baseline(maxasc + labeladdon);
1255 height += row->height();
1257 row->top_of_text(row->baseline() - font_metrics::maxAscent(font));
1260 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1263 row->width(maxwidth);
1264 prepareToPrint(row, x, dummy, dummy, dummy, false);
1266 row->width(int(maxwidth + x));
1269 width = max(0, workWidth());
1271 if (r->width() > width)
1279 // Appends the implicit specified paragraph before the specified row,
1280 // start at the implicit given position
1281 void LyXText::appendParagraph(Row * row)
1283 pos_type const last = row->par()->size();
1287 pos_type z = rowBreakPoint(*row);
1293 insertRow(row, row->par(), z);
1300 // Set the dimensions of the row
1301 // fixed fill setting now by calling inset->update() in
1302 // SingleWidth when needed!
1303 tmprow->fill(fill(*tmprow, workWidth()));
1304 setHeightOfRow(tmprow);
1310 // Do we even need this at all ? Code that uses RowPainter *already*
1311 // sets need_break_row when it sees a CHANGED_IN_DRAW, though not
1313 void LyXText::markChangeInDraw(Row * row, Row * prev)
1315 if (prev && prev->par() == row->par()) {
1316 breakAgainOneRow(prev);
1317 if (prev->next() != row) {
1318 // breakAgainOneRow() has removed row_
1319 need_break_row = prev;
1321 need_break_row = row;
1324 need_break_row = firstrow;
1326 need_break_row = prev->next();
1328 setCursor(cursor.par(), cursor.pos());
1333 void LyXText::breakAgain(Row * row)
1335 bool not_ready = true;
1338 pos_type z = rowBreakPoint(*row);
1341 if (z < row->par()->size()) {
1342 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1345 insertRow(row, row->par(), z);
1351 if (row->pos() == z)
1352 not_ready = false; // the rest will not change
1358 // if there are some rows too much, delete them
1359 // only if you broke the whole paragraph!
1360 Row * tmprow2 = row;
1361 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1362 tmprow2 = tmprow2->next();
1364 while (tmprow2 != row) {
1365 tmprow2 = tmprow2->previous();
1366 removeRow(tmprow2->next());
1371 // set the dimensions of the row
1372 tmprow->fill(fill(*tmprow, workWidth()));
1373 setHeightOfRow(tmprow);
1374 } while (not_ready);
1378 // this is just a little changed version of break again
1379 void LyXText::breakAgainOneRow(Row * row)
1381 pos_type z = rowBreakPoint(*row);
1384 if (z < row->par()->size()) {
1386 || (row->next() && row->next()->par() != row->par())) {
1389 insertRow(row, row->par(), z);
1395 if (row->pos() != z)
1399 // if there are some rows too much, delete them
1400 // only if you broke the whole paragraph!
1401 Row * tmprow2 = row;
1402 while (tmprow2->next()
1403 && tmprow2->next()->par() == row->par()) {
1404 tmprow2 = tmprow2->next();
1406 while (tmprow2 != row) {
1407 tmprow2 = tmprow2->previous();
1408 removeRow(tmprow2->next());
1412 // set the dimensions of the row
1413 tmprow->fill(fill(*tmprow, workWidth()));
1414 setHeightOfRow(tmprow);
1418 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1420 // allow only if at start or end, or all previous is new text
1421 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1422 && cursor.par()->isChangeEdited(0, cursor.pos()))
1425 LyXTextClass const & tclass =
1426 bv()->buffer()->params.getLyXTextClass();
1427 LyXLayout_ptr const & layout = cursor.par()->layout();
1429 // this is only allowed, if the current paragraph is not empty or caption
1430 // and if it has not the keepempty flag aktive
1431 if (cursor.par()->empty()
1432 && layout->labeltype != LABEL_SENSITIVE
1433 && !layout->keepempty)
1436 setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next());
1438 // Always break behind a space
1440 // It is better to erase the space (Dekel)
1441 if (cursor.pos() < cursor.par()->size()
1442 && cursor.par()->isLineSeparator(cursor.pos()))
1443 cursor.par()->erase(cursor.pos());
1444 // cursor.pos(cursor.pos() + 1);
1446 // break the paragraph
1450 keep_layout = layout->isEnvironment();
1452 // we need to set this before we insert the paragraph. IMO the
1453 // breakParagraph call should return a bool if it inserts the
1454 // paragraph before or behind and we should react on that one
1455 // but we can fix this in 1.3.0 (Jug 20020509)
1456 bool const isempty = (layout->keepempty && cursor.par()->empty());
1457 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1460 // well this is the caption hack since one caption is really enough
1461 if (layout->labeltype == LABEL_SENSITIVE) {
1463 // set to standard-layout
1464 cursor.par()->applyLayout(tclass.defaultLayout());
1466 // set to standard-layout
1467 cursor.par()->next()->applyLayout(tclass.defaultLayout());
1470 // if the cursor is at the beginning of a row without prior newline,
1472 // This touches only the screen-update. Otherwise we would may have
1473 // an empty row on the screen
1474 if (cursor.pos() && !cursor.row()->par()->isNewline(cursor.row()->pos() - 1)
1475 && cursor.row()->pos() == cursor.pos())
1480 int y = cursor.y() - cursor.row()->baseline();
1482 // Do not forget the special right address boxes
1483 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1484 Row * r = cursor.row();
1485 while (r->previous() && r->previous()->par() == r->par()) {
1493 removeParagraph(cursor.row());
1495 // set the dimensions of the cursor row
1496 cursor.row()->fill(fill(*cursor.row(), workWidth()));
1498 setHeightOfRow(cursor.row());
1500 #warning Trouble Point! (Lgb)
1501 // When ::breakParagraph is called from within an inset we must
1502 // ensure that the correct ParagraphList is used. Today that is not
1503 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1504 while (!cursor.par()->next()->empty()
1505 && cursor.par()->next()->isNewline(0))
1506 cursor.par()->next()->erase(0);
1508 insertParagraph(cursor.par()->next(), cursor.row());
1512 // This check is necessary. Otherwise the new empty paragraph will
1513 // be deleted automatically. And it is more friendly for the user!
1514 if (cursor.pos() || isempty)
1515 setCursor(cursor.par()->next(), 0);
1517 setCursor(cursor.par(), 0);
1519 if (cursor.row()->next())
1520 breakAgain(cursor.row()->next());
1526 // Just a macro to make some thing easier.
1527 void LyXText::redoParagraph()
1530 redoParagraphs(cursor, cursor.par()->next());
1531 setCursorIntern(cursor.par(), cursor.pos());
1535 // insert a character, moves all the following breaks in the
1536 // same Paragraph one to the right and make a rebreak
1537 void LyXText::insertChar(char c)
1539 setUndo(bv(), Undo::INSERT, cursor.par(), cursor.par()->next());
1541 // When the free-spacing option is set for the current layout,
1542 // disable the double-space checking
1544 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1545 cursor.row()->par()->isFreeSpacing();
1547 if (lyxrc.auto_number) {
1548 static string const number_operators = "+-/*";
1549 static string const number_unary_operators = "+-";
1550 static string const number_seperators = ".,:";
1552 if (current_font.number() == LyXFont::ON) {
1553 if (!IsDigit(c) && !contains(number_operators, c) &&
1554 !(contains(number_seperators, c) &&
1555 cursor.pos() >= 1 &&
1556 cursor.pos() < cursor.par()->size() &&
1557 getFont(bv()->buffer(),
1559 cursor.pos()).number() == LyXFont::ON &&
1560 getFont(bv()->buffer(),
1562 cursor.pos() - 1).number() == LyXFont::ON)
1564 number(bv()); // Set current_font.number to OFF
1565 } else if (IsDigit(c) &&
1566 real_current_font.isVisibleRightToLeft()) {
1567 number(bv()); // Set current_font.number to ON
1569 if (cursor.pos() > 0) {
1570 char const c = cursor.par()->getChar(cursor.pos() - 1);
1571 if (contains(number_unary_operators, c) &&
1572 (cursor.pos() == 1 ||
1573 cursor.par()->isSeparator(cursor.pos() - 2) ||
1574 cursor.par()->isNewline(cursor.pos() - 2))
1576 setCharFont(bv()->buffer(),
1580 } else if (contains(number_seperators, c) &&
1581 cursor.pos() >= 2 &&
1582 getFont(bv()->buffer(),
1584 cursor.pos() - 2).number() == LyXFont::ON) {
1585 setCharFont(bv()->buffer(),
1595 // First check, if there will be two blanks together or a blank at
1596 // the beginning of a paragraph.
1597 // I decided to handle blanks like normal characters, the main
1598 // difference are the special checks when calculating the row.fill
1599 // (blank does not count at the end of a row) and the check here
1601 // The bug is triggered when we type in a description environment:
1602 // The current_font is not changed when we go from label to main text
1603 // and it should (along with realtmpfont) when we type the space.
1604 // CHECK There is a bug here! (Asger)
1606 LyXFont realtmpfont = real_current_font;
1607 LyXFont rawtmpfont = current_font;
1608 // store the current font. This is because of the use of cursor
1609 // movements. The moving cursor would refresh the current font
1611 // Get the font that is used to calculate the baselineskip
1612 pos_type const lastpos = cursor.par()->size();
1613 LyXFont rawparfont =
1614 cursor.par()->getFontSettings(bv()->buffer()->params,
1617 bool jumped_over_space = false;
1619 if (!freeSpacing && IsLineSeparatorChar(c)) {
1620 if ((cursor.pos() > 0
1621 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1622 || (cursor.pos() > 0
1623 && cursor.par()->isNewline(cursor.pos() - 1))
1624 || (cursor.pos() == 0)) {
1625 static bool sent_space_message = false;
1626 if (!sent_space_message) {
1627 if (cursor.pos() == 0)
1628 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1630 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1631 sent_space_message = true;
1638 // the display inset stuff
1639 if (cursor.row()->pos() < cursor.row()->par()->size()
1640 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1641 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1642 if (inset && (inset->display() || inset->needFullRow())) {
1643 // force a new break
1644 cursor.row()->fill(-1); // to force a new break
1648 // get the cursor row fist
1649 Row * row = cursor.row();
1650 int y = cursor.y() - row->baseline();
1651 if (c != Paragraph::META_INSET) {
1652 // Here case LyXText::InsertInset already insertet the character
1653 cursor.par()->insertChar(cursor.pos(), c);
1655 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1657 if (!jumped_over_space) {
1658 // refresh the positions
1660 while (tmprow->next() && tmprow->next()->par() == row->par()) {
1661 tmprow = tmprow->next();
1662 tmprow->pos(tmprow->pos() + 1);
1666 // Is there a break one row above
1667 if (row->previous() && row->previous()->par() == row->par()
1668 && (cursor.par()->isLineSeparator(cursor.pos())
1669 || cursor.par()->isNewline(cursor.pos())
1670 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1671 cursor.par()->isInset(cursor.pos() + 1))
1672 || cursor.row()->fill() == -1))
1674 pos_type z = rowBreakPoint(*row->previous());
1676 if (z >= row->pos()) {
1679 // set the dimensions of the row above
1680 row->previous()->fill(fill(
1684 setHeightOfRow(row->previous());
1686 y -= row->previous()->height();
1690 breakAgainOneRow(row);
1692 current_font = rawtmpfont;
1693 real_current_font = realtmpfont;
1694 setCursor(cursor.par(), cursor.pos() + 1,
1695 false, cursor.boundary());
1696 // cursor MUST be in row now.
1698 if (row->next() && row->next()->par() == row->par())
1699 need_break_row = row->next();
1703 // check, wether the last characters font has changed.
1704 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1705 && rawparfont != rawtmpfont)
1706 redoHeightOfParagraph();
1713 // recalculate the fill of the row
1714 if (row->fill() >= 0) {
1715 // needed because a newline will set fill to -1. Otherwise
1716 // we would not get a rebreak!
1717 row->fill(fill(*row, workWidth()));
1720 if (c == Paragraph::META_INSET || row->fill() < 0) {
1722 breakAgainOneRow(row);
1723 // will the cursor be in another row now?
1724 if (row->lastPos() <= cursor.pos() + 1 && row->next()) {
1725 if (row->next() && row->next()->par() == row->par())
1726 // this should always be true
1728 breakAgainOneRow(row);
1730 current_font = rawtmpfont;
1731 real_current_font = realtmpfont;
1733 setCursor(cursor.par(), cursor.pos() + 1, false,
1735 if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
1736 != cursor.boundary())
1737 setCursor(cursor.par(), cursor.pos(), false,
1738 !cursor.boundary());
1739 if (row->next() && row->next()->par() == row->par())
1740 need_break_row = row->next();
1744 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1745 int const tmpheight = row->height();
1747 setHeightOfRow(row);
1749 if (tmpheight == row->height()) {
1750 postRowPaint(row, y);
1755 current_font = rawtmpfont;
1756 real_current_font = realtmpfont;
1757 setCursor(cursor.par(), cursor.pos() + 1, false,
1761 // check, wether the last characters font has changed.
1762 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1763 && rawparfont != rawtmpfont) {
1764 redoHeightOfParagraph();
1766 // now the special right address boxes
1767 if (cursor.par()->layout()->margintype
1768 == MARGIN_RIGHT_ADDRESS_BOX) {
1769 redoDrawingOfParagraph(cursor);
1777 void LyXText::charInserted()
1779 // Here we could call FinishUndo for every 20 characters inserted.
1780 // This is from my experience how emacs does it.
1781 static unsigned int counter;
1791 void LyXText::prepareToPrint(Row * row, float & x,
1792 float & fill_separator,
1794 float & fill_label_hfill,
1800 float w = row->fill();
1802 fill_label_hfill = 0;
1804 fill_label_hfill = 0;
1807 row->par()->isRightToLeftPar(bv()->buffer()->params);
1809 x = (workWidth() > 0)
1810 ? rightMargin(*bv()->buffer(), *row) : 0;
1812 x = (workWidth() > 0)
1813 ? leftMargin(row) : 0;
1815 // is there a manual margin with a manual label
1816 LyXLayout_ptr const & layout = row->par()->layout();
1818 if (layout->margintype == MARGIN_MANUAL
1819 && layout->labeltype == LABEL_MANUAL) {
1820 /// We might have real hfills in the label part
1821 nlh = row->numberOfLabelHfills();
1823 // A manual label par (e.g. List) has an auto-hfill
1824 // between the label text and the body of the
1826 // But we don't want to do this auto hfill if the par
1828 if (!row->par()->empty())
1831 if (nlh && !row->par()->getLabelWidthString().empty()) {
1832 fill_label_hfill = labelFill(*row) / nlh;
1836 // are there any hfills in the row?
1837 float const nh = row->numberOfHfills();
1841 fill_hfill = w / nh;
1842 // we don't have to look at the alignment if it is ALIGN_LEFT and
1843 // if the row is already larger then the permitted width as then
1844 // we force the LEFT_ALIGN'edness!
1845 } else if (static_cast<int>(row->width()) < workWidth()) {
1846 // is it block, flushleft or flushright?
1847 // set x how you need it
1849 if (row->par()->params().align() == LYX_ALIGN_LAYOUT) {
1850 align = layout->align;
1852 align = row->par()->params().align();
1855 // center displayed insets
1857 if (row->pos() < row->par()->size()
1858 && row->par()->isInset(row->pos())
1859 && (inset = row->par()->getInset(row->pos()))
1860 && (inset->display())) // || (inset->scroll() < 0)))
1861 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1862 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1863 // ERT insets should always be LEFT ALIGNED on screen
1864 inset = row->par()->inInset();
1865 if (inset && inset->owner() &&
1866 inset->owner()->lyxCode() == Inset::ERT_CODE)
1868 align = LYX_ALIGN_LEFT;
1872 case LYX_ALIGN_BLOCK:
1873 ns = row->numberOfSeparators();
1874 if (ns && row->next() && row->next()->par() == row->par() &&
1875 !(row->next()->par()->isNewline(row->next()->pos() - 1))
1876 && !(row->next()->par()->isInset(row->next()->pos())
1877 && row->next()->par()->getInset(row->next()->pos())
1878 && row->next()->par()->getInset(row->next()->pos())->display())
1881 fill_separator = w / ns;
1882 } else if (is_rtl) {
1886 case LYX_ALIGN_RIGHT:
1889 case LYX_ALIGN_CENTER:
1897 computeBidiTables(bv()->buffer(), row);
1899 pos_type body_pos = row->par()->beginningOfBody();
1900 pos_type last = row->lastPos();
1903 (body_pos - 1 > last ||
1904 !row->par()->isLineSeparator(body_pos - 1))) {
1905 x += font_metrics::width(layout->labelsep,
1906 getLabelFont(bv()->buffer(), row->par()));
1907 if (body_pos - 1 <= last)
1908 x += fill_label_hfill;
1914 // important for the screen
1917 // the cursor set functions have a special mechanism. When they
1918 // realize, that you left an empty paragraph, they will delete it.
1919 // They also delete the corresponding row
1921 void LyXText::cursorRightOneWord()
1923 // treat floats, HFills and Insets as words
1924 LyXCursor tmpcursor = cursor;
1925 // CHECK See comment on top of text.C
1927 if (tmpcursor.pos() == tmpcursor.par()->size()
1928 && tmpcursor.par()->next()) {
1929 tmpcursor.par(tmpcursor.par()->next());
1934 // Skip through initial nonword stuff.
1935 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1936 ! tmpcursor.par()->isWord(tmpcursor.pos())) {
1937 // printf("Current pos1 %d", tmpcursor.pos()) ;
1938 tmpcursor.pos(tmpcursor.pos() + 1);
1941 // Advance through word.
1942 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1943 tmpcursor.par()->isWord(tmpcursor.pos())) {
1944 // printf("Current pos2 %d", tmpcursor.pos()) ;
1945 tmpcursor.pos(tmpcursor.pos() + 1);
1949 setCursor(tmpcursor.par(), tmpcursor.pos());
1953 void LyXText::cursorTab()
1955 LyXCursor tmpcursor = cursor;
1956 while (tmpcursor.pos() < tmpcursor.par()->size()
1957 && !tmpcursor.par()->isNewline(tmpcursor.pos()))
1958 tmpcursor.pos(tmpcursor.pos() + 1);
1960 if (tmpcursor.pos() == tmpcursor.par()->size()) {
1961 if (tmpcursor.par()->next()) {
1962 tmpcursor.par(tmpcursor.par()->next());
1966 tmpcursor.pos(tmpcursor.pos() + 1);
1967 setCursor(tmpcursor.par(), tmpcursor.pos());
1971 // Skip initial whitespace at end of word and move cursor to *start*
1972 // of prior word, not to end of next prior word.
1973 void LyXText::cursorLeftOneWord()
1975 LyXCursor tmpcursor = cursor;
1976 cursorLeftOneWord(tmpcursor);
1977 setCursor(tmpcursor.par(), tmpcursor.pos());
1981 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1983 // treat HFills, floats and Insets as words
1986 && (cur.par()->isSeparator(cur.pos() - 1)
1987 || cur.par()->isKomma(cur.pos() - 1)
1988 || cur.par()->isNewline(cur.pos() - 1))
1989 && !(cur.par()->isHfill(cur.pos() - 1)
1990 || cur.par()->isInset(cur.pos() - 1)))
1991 cur.pos(cur.pos() - 1);
1994 && (cur.par()->isInset(cur.pos() - 1)
1995 || cur.par()->isHfill(cur.pos() - 1))) {
1996 cur.pos(cur.pos() - 1);
1997 } else if (!cur.pos()) {
1998 if (cur.par()->previous()) {
1999 cur.par(cur.par()->previous());
2000 cur.pos(cur.par()->size());
2002 } else { // Here, cur != 0
2003 while (cur.pos() > 0 &&
2004 cur.par()->isWord(cur.pos() - 1))
2005 cur.pos(cur.pos() - 1);
2010 // Select current word. This depends on behaviour of
2011 // CursorLeftOneWord(), so it is patched as well.
2012 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2013 word_location const loc)
2015 // first put the cursor where we wana start to select the word
2018 case WHOLE_WORD_STRICT:
2019 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2020 || cursor.par()->isSeparator(cursor.pos())
2021 || cursor.par()->isKomma(cursor.pos())
2022 || cursor.par()->isNewline(cursor.pos())
2023 || cursor.par()->isSeparator(cursor.pos() - 1)
2024 || cursor.par()->isKomma(cursor.pos() - 1)
2025 || cursor.par()->isNewline(cursor.pos() - 1)) {
2029 // no break here, we go to the next
2032 // Move cursor to the beginning, when not already there.
2033 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2034 && !(from.par()->isKomma(from.pos() - 1)
2035 || from.par()->isNewline(from.pos() - 1)))
2036 cursorLeftOneWord(from);
2039 // always move the cursor to the beginning of previous word
2040 cursorLeftOneWord(from);
2043 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2049 while (to.pos() < to.par()->size()
2050 && !to.par()->isSeparator(to.pos())
2051 && !to.par()->isKomma(to.pos())
2052 && !to.par()->isNewline(to.pos())
2053 && !to.par()->isHfill(to.pos())
2054 && !to.par()->isInset(to.pos()))
2056 to.pos(to.pos() + 1);
2061 void LyXText::selectWord(word_location loc)
2065 getWord(from, to, loc);
2067 setCursor(from.par(), from.pos());
2070 selection.cursor = cursor;
2071 setCursor(to.par(), to.pos());
2076 // Select the word currently under the cursor when no
2077 // selection is currently set
2078 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2080 if (!selection.set()) {
2082 return selection.set();
2088 void LyXText::acceptChange()
2090 if (!selection.set() && cursor.par()->size())
2095 if (selection.start.par() == selection.end.par()) {
2096 LyXCursor & startc = selection.start;
2097 LyXCursor & endc = selection.end;
2098 setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
2099 startc.par()->acceptChange(startc.pos(), endc.pos());
2102 redoParagraphs(startc, startc.par()->next());
2103 setCursorIntern(startc.par(), 0);
2105 #warning handle multi par selection
2109 void LyXText::rejectChange()
2111 if (!selection.set() && cursor.par()->size())
2116 if (selection.start.par() == selection.end.par()) {
2117 LyXCursor & startc = selection.start;
2118 LyXCursor & endc = selection.end;
2119 setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
2120 startc.par()->rejectChange(startc.pos(), endc.pos());
2123 redoParagraphs(startc, startc.par()->next());
2124 setCursorIntern(startc.par(), 0);
2126 #warning handle multi par selection
2130 // This function is only used by the spellchecker for NextWord().
2131 // It doesn't handle LYX_ACCENTs and probably never will.
2133 LyXText::selectNextWordToSpellcheck(float & value)
2135 if (the_locking_inset) {
2136 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2137 if (!word.word().empty()) {
2138 value += float(cursor.y());
2139 value /= float(height);
2142 // we have to go on checking so move cursor to the next char
2143 if (cursor.pos() == cursor.par()->size()) {
2144 if (!cursor.par()->next())
2146 cursor.par(cursor.par()->next());
2149 cursor.pos(cursor.pos() + 1);
2151 Paragraph * tmppar = cursor.par();
2153 // If this is not the very first word, skip rest of
2154 // current word because we are probably in the middle
2155 // of a word if there is text here.
2156 if (cursor.pos() || cursor.par()->previous()) {
2157 while (cursor.pos() < cursor.par()->size()
2158 && cursor.par()->isLetter(cursor.pos()))
2159 cursor.pos(cursor.pos() + 1);
2162 // Now, skip until we have real text (will jump paragraphs)
2164 Paragraph * cpar(cursor.par());
2165 pos_type const cpos(cursor.pos());
2167 if (cpos == cpar->size()) {
2169 cursor.par(cpar->next());
2176 bool const is_bad_inset(cpar->isInset(cpos)
2177 && !cpar->getInset(cpos)->allowSpellcheck());
2179 if (cpar->isLetter(cpos) && !isDeletedText(*cpar, cpos)
2183 cursor.pos(cpos + 1);
2186 // now check if we hit an inset so it has to be a inset containing text!
2187 if (cursor.pos() < cursor.par()->size() &&
2188 cursor.par()->isInset(cursor.pos())) {
2190 cursor.par()->getInset(cursor.pos())->edit(bv());
2191 // now call us again to do the above trick
2192 // but obviously we have to start from down below ;)
2193 return bv()->text->selectNextWordToSpellcheck(value);
2196 // Update the value if we changed paragraphs
2197 if (cursor.par() != tmppar) {
2198 setCursor(cursor.par(), cursor.pos());
2199 value = float(cursor.y())/float(height);
2202 // Start the selection from here
2203 selection.cursor = cursor;
2206 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2207 .language()->code());
2208 // and find the end of the word (insets like optional hyphens
2209 // and ligature break are part of a word)
2210 while (cursor.pos() < cursor.par()->size()
2211 && cursor.par()->isLetter(cursor.pos())
2212 && !isDeletedText(*cursor.par(), cursor.pos()))
2213 cursor.pos(cursor.pos() + 1);
2215 // Finally, we copy the word to a string and return it
2217 if (selection.cursor.pos() < cursor.pos()) {
2219 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2220 if (!cursor.par()->isInset(i))
2221 str += cursor.par()->getChar(i);
2224 return WordLangTuple(str, lang_code);
2228 // This one is also only for the spellchecker
2229 void LyXText::selectSelectedWord()
2231 if (the_locking_inset) {
2232 the_locking_inset->selectSelectedWord(bv());
2235 // move cursor to the beginning
2236 setCursor(selection.cursor.par(), selection.cursor.pos());
2238 // set the sel cursor
2239 selection.cursor = cursor;
2241 // now find the end of the word
2242 while (cursor.pos() < cursor.par()->size()
2243 && (cursor.par()->isLetter(cursor.pos())))
2244 cursor.pos(cursor.pos() + 1);
2246 setCursor(cursor.par(), cursor.pos());
2248 // finally set the selection
2253 // Delete from cursor up to the end of the current or next word.
2254 void LyXText::deleteWordForward()
2256 if (cursor.par()->empty())
2259 LyXCursor tmpcursor = cursor;
2260 tmpcursor.row(0); //Â ??
2261 selection.set(true); // to avoid deletion
2262 cursorRightOneWord();
2263 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2264 selection.cursor = cursor;
2268 // Great, CutSelection() gets rid of multiple spaces.
2269 cutSelection(true, false);
2274 // Delete from cursor to start of current or prior word.
2275 void LyXText::deleteWordBackward()
2277 if (cursor.par()->empty())
2280 LyXCursor tmpcursor = cursor;
2281 tmpcursor.row(0); // ??
2282 selection.set(true); // to avoid deletion
2283 cursorLeftOneWord();
2284 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2285 selection.cursor = cursor;
2288 cutSelection(true, false);
2293 // Kill to end of line.
2294 void LyXText::deleteLineForward()
2296 if (cursor.par()->empty())
2297 // Paragraph is empty, so we just go to the right
2300 LyXCursor tmpcursor = cursor;
2301 // We can't store the row over a regular setCursor
2302 // so we set it to 0 and reset it afterwards.
2303 tmpcursor.row(0); //Â ??
2304 selection.set(true); // to avoid deletion
2306 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2307 selection.cursor = cursor;
2310 // What is this test for ??? (JMarc)
2311 if (!selection.set()) {
2312 deleteWordForward();
2314 cutSelection(true, false);
2320 void LyXText::changeCase(LyXText::TextCase action)
2325 if (selection.set()) {
2326 from = selection.start;
2329 getWord(from, to, PARTIAL_WORD);
2330 setCursor(to.par(), to.pos() + 1);
2333 lyx::Assert(from <= to);
2335 setUndo(bv(), Undo::FINISH, from.par(), to.par()->next());
2337 pos_type pos = from.pos();
2338 Paragraph * par = from.par();
2340 while (par && (pos != to.pos() || par != to.par())) {
2341 if (pos == par->size()) {
2346 unsigned char c = par->getChar(pos);
2347 if (!IsInsetChar(c)) {
2349 case text_lowercase:
2352 case text_capitalization:
2354 action = text_lowercase;
2356 case text_uppercase:
2362 par->setChar(pos, c);
2363 checkParagraph(par, pos);
2368 if (to.row() != from.row())
2369 postPaint(from.y() - from.row()->baseline());
2373 void LyXText::transposeChars()
2375 Paragraph * tmppar = cursor.par();
2377 setUndo(bv(), Undo::FINISH, tmppar, tmppar->next());
2379 pos_type tmppos = cursor.pos();
2381 // First decide if it is possible to transpose at all
2383 if (tmppos == 0 || tmppos == tmppar->size())
2386 if (isDeletedText(*tmppar, tmppos - 1)
2387 || isDeletedText(*tmppar, tmppos))
2390 unsigned char c1 = tmppar->getChar(tmppos);
2391 unsigned char c2 = tmppar->getChar(tmppos - 1);
2393 // We should have an implementation that handles insets
2394 // as well, but that will have to come later. (Lgb)
2395 if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
2398 bool const erased = tmppar->erase(tmppos - 1, tmppos + 1);
2399 pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
2401 tmppar->insertChar(ipos, c1);
2402 tmppar->insertChar(ipos + 1, c2);
2404 checkParagraph(tmppar, tmppos);
2408 void LyXText::Delete()
2410 // this is a very easy implementation
2412 LyXCursor old_cursor = cursor;
2413 int const old_cur_par_id = old_cursor.par()->id();
2414 int const old_cur_par_prev_id = old_cursor.par()->previous() ?
2415 old_cursor.par()->previous()->id() : -1;
2417 // just move to the right
2420 // CHECK Look at the comment here.
2421 // This check is not very good...
2422 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2423 // and that can very well delete the par or par->previous in
2424 // old_cursor. Will a solution where we compare paragraph id's
2426 if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
2427 == old_cur_par_prev_id
2428 && cursor.par()->id() != old_cur_par_id) {
2429 // delete-empty-paragraph-mechanism has done it
2433 // if you had success make a backspace
2434 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2435 LyXCursor tmpcursor = cursor;
2436 // to make sure undo gets the right cursor position
2437 cursor = old_cursor;
2438 setUndo(bv(), Undo::DELETE,
2439 cursor.par(), cursor.par()->next());
2446 void LyXText::backspace()
2448 // Get the font that is used to calculate the baselineskip
2449 pos_type lastpos = cursor.par()->size();
2450 LyXFont rawparfont =
2451 cursor.par()->getFontSettings(bv()->buffer()->params,
2454 if (cursor.pos() == 0) {
2455 // The cursor is at the beginning of a paragraph,
2456 // so the the backspace will collapse two paragraphs into one.
2458 // but it's not allowed unless it's new
2459 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2462 // we may paste some paragraphs
2464 // is it an empty paragraph?
2467 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2468 // This is an empty paragraph and we delete it just by moving the cursor one step
2469 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2470 // of the paragraph.
2472 if (cursor.par()->previous()) {
2473 Paragraph * tmppar = cursor.par()->previous();
2474 if (cursor.par()->layout() == tmppar->layout()
2475 && cursor.par()->getAlign() == tmppar->getAlign()) {
2476 // Inherit bottom DTD from the paragraph below.
2477 // (the one we are deleting)
2478 tmppar->params().lineBottom(cursor.par()->params().lineBottom());
2479 tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
2480 tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2485 // the layout things can change the height of a row !
2486 int const tmpheight = cursor.row()->height();
2487 setHeightOfRow(cursor.row());
2488 if (cursor.row()->height() != tmpheight) {
2489 postPaint(cursor.y() - cursor.row()->baseline());
2495 if (cursor.par()->previous()) {
2496 setUndo(bv(), Undo::DELETE,
2497 cursor.par()->previous(), cursor.par()->next());
2500 Paragraph * tmppar = cursor.par();
2501 Row * tmprow = cursor.row();
2503 // We used to do cursorLeftIntern() here, but it is
2504 // not a good idea since it triggers the auto-delete
2505 // mechanism. So we do a cursorLeftIntern()-lite,
2506 // without the dreaded mechanism. (JMarc)
2507 if (cursor.par()->previous()) {
2508 // steps into the above paragraph.
2509 setCursorIntern(cursor.par()->previous(),
2510 cursor.par()->previous()->size(),
2514 // Pasting is not allowed, if the paragraphs have different
2515 // layout. I think it is a real bug of all other
2516 // word processors to allow it. It confuses the user.
2517 // Even so with a footnote paragraph and a non-footnote
2518 // paragraph. I will not allow pasting in this case,
2519 // because the user would be confused if the footnote behaves
2520 // different wether it is open or closed.
2522 // Correction: Pasting is always allowed with standard-layout
2523 LyXTextClass const & tclass =
2524 bv()->buffer()->params.getLyXTextClass();
2526 if (cursor.par() != tmppar
2527 && (cursor.par()->layout() == tmppar->layout()
2528 || tmppar->layout() == tclass.defaultLayout())
2529 && cursor.par()->getAlign() == tmppar->getAlign()) {
2530 removeParagraph(tmprow);
2532 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2534 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2535 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2536 // strangely enough it seems that commenting out the line above removes
2537 // most or all of the segfaults. I will however also try to move the
2538 // two Remove... lines in front of the PasteParagraph too.
2541 cursor.pos(cursor.pos() - 1);
2543 postPaint(cursor.y() - cursor.row()->baseline());
2545 // remove the lost paragraph
2546 // This one is not safe, since the paragraph that the tmprow and the
2547 // following rows belong to has been deleted by the PasteParagraph
2548 // above. The question is... could this be moved in front of the
2550 //RemoveParagraph(tmprow);
2551 //RemoveRow(tmprow);
2553 // This rebuilds the rows.
2554 appendParagraph(cursor.row());
2557 // the row may have changed, block, hfills etc.
2558 setCursor(cursor.par(), cursor.pos(), false);
2561 // this is the code for a normal backspace, not pasting
2563 setUndo(bv(), Undo::DELETE,
2564 cursor.par(), cursor.par()->next());
2565 // We used to do cursorLeftIntern() here, but it is
2566 // not a good idea since it triggers the auto-delete
2567 // mechanism. So we do a cursorLeftIntern()-lite,
2568 // without the dreaded mechanism. (JMarc)
2569 setCursorIntern(cursor.par(), cursor.pos()- 1,
2570 false, cursor.boundary());
2572 if (cursor.par()->isInset(cursor.pos())) {
2573 // force complete redo when erasing display insets
2574 // this is a cruel method but safe..... Matthias
2575 if (cursor.par()->getInset(cursor.pos())->display() ||
2576 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2577 cursor.par()->erase(cursor.pos());
2583 Row * row = cursor.row();
2584 int y = cursor.y() - row->baseline();
2586 // remember that a space at the end of a row doesnt count
2587 // when calculating the fill
2588 if (cursor.pos() < row->lastPos() ||
2589 !cursor.par()->isLineSeparator(cursor.pos())) {
2590 row->fill(row->fill() + singleWidth(
2595 // some special code when deleting a newline. This is similar
2596 // to the behavior when pasting paragraphs
2597 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2598 cursor.par()->erase(cursor.pos());
2599 // refresh the positions
2601 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2602 tmprow = tmprow->next();
2603 tmprow->pos(tmprow->pos() - 1);
2605 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2606 cursor.pos(cursor.pos() - 1);
2608 if (cursor.pos() < cursor.par()->size()
2609 && !cursor.par()->isSeparator(cursor.pos())) {
2610 cursor.par()->insertChar(cursor.pos(), ' ');
2611 setCharFont(bv()->buffer(), cursor.par(),
2612 cursor.pos(), current_font);
2613 // refresh the positions
2615 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2616 tmprow = tmprow->next();
2617 tmprow->pos(tmprow->pos() + 1);
2621 cursor.par()->erase(cursor.pos());
2623 // refresh the positions
2625 while (tmprow->next()
2626 && tmprow->next()->par() == row->par()) {
2627 tmprow = tmprow->next();
2628 tmprow->pos(tmprow->pos() - 1);
2631 // delete newlines at the beginning of paragraphs
2632 while (!cursor.par()->empty() &&
2633 cursor.pos() < cursor.par()->size() &&
2634 cursor.par()->isNewline(cursor.pos()) &&
2635 cursor.pos() == cursor.par()->beginningOfBody()) {
2636 cursor.par()->erase(cursor.pos());
2637 // refresh the positions
2639 while (tmprow->next() &&
2640 tmprow->next()->par() == row->par()) {
2641 tmprow = tmprow->next();
2642 tmprow->pos(tmprow->pos() - 1);
2647 // is there a break one row above
2648 if (row->previous() && row->previous()->par() == row->par()) {
2649 z = rowBreakPoint(*row->previous());
2650 if (z >= row->pos()) {
2653 Row * tmprow = row->previous();
2655 // maybe the current row is now empty
2656 if (row->pos() >= row->par()->size()) {
2661 breakAgainOneRow(row);
2662 if (row->next() && row->next()->par() == row->par())
2663 need_break_row = row->next();
2668 // set the dimensions of the row above
2669 y -= tmprow->height();
2670 tmprow->fill(fill(*tmprow, workWidth()));
2671 setHeightOfRow(tmprow);
2675 setCursor(cursor.par(), cursor.pos(),
2676 false, cursor.boundary());
2677 //current_font = rawtmpfont;
2678 //real_current_font = realtmpfont;
2679 // check, whether the last character's font has changed.
2681 cursor.par()->getFontSettings(bv()->buffer()->params,
2682 cursor.par()->size() - 1))
2683 redoHeightOfParagraph();
2688 // break the cursor row again
2689 if (row->next() && row->next()->par() == row->par() &&
2690 (row->lastPos() == row->par()->size() - 1 ||
2691 rowBreakPoint(*row) != row->lastPos())) {
2693 // it can happen that a paragraph loses one row
2694 // without a real breakup. This is when a word
2695 // is to long to be broken. Well, I don t care this
2697 if (row->lastPos() == row->par()->size() - 1)
2698 removeRow(row->next());
2702 breakAgainOneRow(row);
2703 // will the cursor be in another row now?
2704 if (row->next() && row->next()->par() == row->par() &&
2705 row->lastPos() <= cursor.pos()) {
2707 breakAgainOneRow(row);
2710 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2712 if (row->next() && row->next()->par() == row->par())
2713 need_break_row = row->next();
2717 // set the dimensions of the row
2718 row->fill(fill(*row, workWidth()));
2719 int const tmpheight = row->height();
2720 setHeightOfRow(row);
2721 if (tmpheight == row->height()) {
2722 postRowPaint(row, y);
2726 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2730 // current_font = rawtmpfont;
2731 // real_current_font = realtmpfont;
2733 if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
2734 != cursor.boundary())
2735 setCursor(cursor.par(), cursor.pos(), false,
2736 !cursor.boundary());
2738 lastpos = cursor.par()->size();
2739 if (cursor.pos() == lastpos)
2742 // check, whether the last characters font has changed.
2744 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2745 redoHeightOfParagraph();
2747 // now the special right address boxes
2748 if (cursor.par()->layout()->margintype
2749 == MARGIN_RIGHT_ADDRESS_BOX) {
2750 redoDrawingOfParagraph(cursor);
2756 // returns pointer to a specified row
2757 Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
2762 Row * tmprow = firstrow;
2765 // find the first row of the specified paragraph
2766 while (tmprow->next() && tmprow->par() != par) {
2767 y += tmprow->height();
2768 tmprow = tmprow->next();
2771 // now find the wanted row
2772 while (tmprow->pos() < pos
2774 && tmprow->next()->par() == par
2775 && tmprow->next()->pos() <= pos) {
2776 y += tmprow->height();
2777 tmprow = tmprow->next();
2784 Row * LyXText::getRowNearY(int & y) const
2787 // If possible we should optimize this method. (Lgb)
2788 Row * tmprow = firstrow;
2791 while (tmprow->next() && tmpy + tmprow->height() <= y) {
2792 tmpy += tmprow->height();
2793 tmprow = tmprow->next();
2796 y = tmpy; // return the real y
2798 //lyxerr << "returned y = " << y << endl;
2802 // Search from the current cursor position.
2804 Row * tmprow = cursor.row();
2805 int tmpy = cursor.y() - tmprow->baseline();
2807 lyxerr << "cursor.y() = " << tmpy << endl;
2808 lyxerr << "tmprow->height() = " << tmprow->height() << endl;
2809 lyxerr << "tmprow->baseline() = " << tmprow->baseline() << endl;
2810 lyxerr << "first = " << first << endl;
2811 lyxerr << "y = " << y << endl;
2814 lyxerr << "up" << endl;
2816 tmpy -= tmprow->height();
2817 tmprow = tmprow->previous();
2818 } while (tmprow && tmpy - tmprow->height() >= y);
2819 } else if (y > tmpy) {
2820 lyxerr << "down" << endl;
2822 while (tmprow->next() && tmpy + tmprow->height() <= y) {
2823 tmpy += tmprow->height();
2824 tmprow = tmprow->next();
2827 lyxerr << "equal" << endl;
2830 y = tmpy; // return the real y
2832 lyxerr << "returned y = " << y << endl;
2840 int LyXText::getDepth() const
2842 return cursor.par()->getDepth();