1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #include "lyxparagraph.h"
19 #include "support/textutils.h"
20 #include "insets/insetbib.h"
21 #include "insets/insettext.h"
22 #include "lyx_gui_misc.h"
24 #include "bufferparams.h"
26 #include "minibuffer.h"
35 #include "lyxscreen.h"
36 #include "bufferview_funcs.h"
43 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
48 int LyXText::workWidth(BufferView * bview) const
51 return inset_owner->textWidth(bview->painter());
53 return bview->workWidth();
57 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
58 LyXParagraph::size_type pos) const
60 if (!Encodings::is_arabic(c))
61 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
62 return c + (0xb0 - '0');
66 unsigned char const prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
67 unsigned char next_char = ' ';
68 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
69 if (!Encodings::IsComposeChar_arabic(par->GetChar(i))) {
70 next_char = par->GetChar(i);
74 if (Encodings::is_arabic(next_char)) {
75 if (Encodings::is_arabic(prev_char))
76 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
78 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
80 if (Encodings::is_arabic(prev_char))
81 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
83 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
87 // This is the comments that some of the warnings below refers to.
88 // There are some issues in this file and I don't think they are
89 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
90 // this is a problem that has been here almost from day one and that a
91 // larger userbase with differenct access patters triggers the bad
92 // behaviour. (segfaults.) What I think happen is: In several places
93 // we store the paragraph in the current cursor and then moves the
94 // cursor. This movement of the cursor will delete paragraph at the
95 // old position if it is now empty. This will make the temporary
96 // pointer to the old cursor paragraph invalid and dangerous to use.
97 // And is some cases this will trigger a segfault. I have marked some
98 // of the cases where this happens with a warning, but I am sure there
99 // are others in this file and in text2.C. There is also a note in
100 // Delete() that you should read. In Delete I store the paragraph->id
101 // instead of a pointer to the paragraph. I am pretty sure this faulty
102 // use of temporary pointers to paragraphs that might have gotten
103 // invalidated (through a cursor movement) before they are used, are
104 // the cause of the strange crashes we get reported often.
106 // It is very tiresom to change this code, especially when it is as
107 // hard to read as it is. Help to fix all the cases where this is done
108 // would be greately appreciated.
112 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
113 LyXParagraph::size_type pos) const
115 char const c = par->GetChar(pos);
116 return SingleWidth(bview, par, pos, c);
120 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
121 LyXParagraph::size_type pos, char c) const
123 LyXFont font = GetFont(bview->buffer(), par, pos);
125 // The most common case is handled first (Asger)
126 if (IsPrintable(c)) {
127 if (font.language()->RightToLeft()) {
128 if (font.language()->lang() == "arabic" &&
129 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
130 lyxrc.font_norm_type == LyXRC::ISO_10646_1))
131 if (Encodings::IsComposeChar_arabic(c))
134 c = TransformChar(c, par, pos);
135 else if (font.language()->lang() == "hebrew" &&
136 Encodings::IsComposeChar_hebrew(c))
139 return lyxfont::width(c, font);
141 } else if (IsHfillChar(c)) {
142 return 3; /* Because of the representation
143 * as vertical lines */
145 } else if (c == LyXParagraph::META_FOOTNOTE ||
146 c == LyXParagraph::META_MARGIN ||
147 c == LyXParagraph::META_FIG ||
148 c == LyXParagraph::META_TAB ||
149 c == LyXParagraph::META_WIDE_FIG ||
150 c == LyXParagraph::META_WIDE_TAB ||
151 c == LyXParagraph::META_ALGORITHM) {
154 case LyXParagraph::META_MARGIN:
157 case LyXParagraph::META_FIG:
160 case LyXParagraph::META_TAB:
163 case LyXParagraph::META_ALGORITHM:
166 case LyXParagraph::META_WIDE_FIG:
169 case LyXParagraph::META_WIDE_TAB:
172 case LyXParagraph::META_FOOTNOTE:
178 return lyxfont::width(fs, font);
180 } else if (c == LyXParagraph::META_INSET) {
181 Inset * tmpinset = par->GetInset(pos);
183 tmpinset->update(bview, font);
184 return tmpinset->width(bview, font);
188 } else if (IsSeparatorChar(c))
190 else if (IsNewlineChar(c))
192 return lyxfont::width(c, font);
196 // Returns the paragraph position of the last character in the specified row
197 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
199 if (row->next() == 0)
200 return row->par()->Last() - 1;
201 else if (row->next()->par() != row->par())
202 return row->par()->Last() - 1;
204 return row->next()->pos() - 1;
208 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
210 LyXParagraph::size_type const last = RowLast(row);
211 if (last >= row->pos()
213 && row->next()->par() == row->par()
214 && row->par()->IsSeparator(last))
221 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
223 bidi_same_direction = true;
224 if (!lyxrc.rtl_support) {
229 bidi_start = row->pos();
230 bidi_end = RowLastPrintable(row);
232 if (bidi_start > bidi_end) {
237 if (bidi_end + 2 - bidi_start >
238 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
239 LyXParagraph::size_type new_size =
240 (bidi_end + 2 - bidi_start < 500) ?
241 500 : 2 * (bidi_end + 2 - bidi_start);
242 log2vis_list.resize(new_size);
243 vis2log_list.resize(new_size);
244 bidi_levels.resize(new_size);
247 vis2log_list[bidi_end + 1 - bidi_start] = -1;
248 log2vis_list[bidi_end + 1 - bidi_start] = -1;
250 LyXParagraph::size_type stack[2];
252 row->par()->getParLanguage(buf->params)->RightToLeft();
256 LyXParagraph::size_type const main_body =
257 BeginningOfMainBody(buf, row->par());
259 for (LyXParagraph::size_type lpos = bidi_start;
260 lpos <= bidi_end; ++lpos) {
261 bool is_space = row->par()->IsLineSeparator(lpos);
262 LyXParagraph::size_type const pos =
263 (is_space && lpos + 1 <= bidi_end &&
264 !row->par()->IsLineSeparator(lpos + 1) &&
265 !row->par()->IsNewline(lpos + 1))
267 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
268 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
269 font.number() == LyXFont::ON &&
270 row->par()->GetFontSettings(buf->params, lpos-1).number()
272 font = row->par()->GetFontSettings(buf->params, lpos);
277 bool new_rtl = font.isVisibleRightToLeft();
278 bool new_rtl0 = font.isRightToLeft();
281 if (lpos == main_body - 1
282 && row->pos() < main_body - 1
284 new_level = (rtl_par) ? 1 : 0;
285 new_rtl = new_rtl0 = rtl_par;
287 new_level = (new_rtl) ? 1 : 2;
289 new_level = (rtl_par) ? 2 : 0;
291 if (is_space && new_level >= level) {
297 int new_level2 = new_level;
299 if (level == new_level && rtl0 != new_rtl0) {
301 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
302 } else if (level < new_level) {
303 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
304 if (new_level > rtl_par)
305 bidi_same_direction = false;
307 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
310 bidi_levels[lpos - bidi_start] = new_level;
312 while (level > new_level2) {
313 LyXParagraph::size_type old_lpos =
315 int delta = lpos - old_lpos - 1;
318 log2vis_list[lpos - bidi_start] += delta;
319 log2vis_list[old_lpos - bidi_start] += delta;
321 while (level < new_level)
322 stack[level++] = lpos;
326 LyXParagraph::size_type const old_lpos = stack[--level];
327 int delta = bidi_end - old_lpos;
330 log2vis_list[old_lpos - bidi_start] += delta;
333 LyXParagraph::size_type vpos = bidi_start - 1;
334 for (LyXParagraph::size_type lpos = bidi_start;
335 lpos <= bidi_end; ++lpos) {
336 vpos += log2vis_list[lpos - bidi_start];
337 vis2log_list[vpos - bidi_start] = lpos;
338 log2vis_list[lpos - bidi_start] = vpos;
343 // This method requires a previous call to ComputeBidiTables()
344 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
345 LyXParagraph::size_type pos) const
347 if (!lyxrc.rtl_support || pos == 0)
350 if (!bidi_InRange(pos - 1)) {
351 lyxerr << "LyXText::IsBoundary This shouldn't happen." << endl;
355 bool const rtl = bidi_level(pos - 1) % 2;
356 bool rtl2 = bidi_InRange(pos)
357 ? bidi_level(pos) % 2
358 : par->isRightToLeftPar(buf->params);
363 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
364 LyXParagraph::size_type pos,
365 LyXFont const & font) const
367 if (!lyxrc.rtl_support)
368 return false; // This is just for speedup
370 bool const rtl = font.isVisibleRightToLeft();
371 bool rtl2 = bidi_InRange(pos)
372 ? bidi_level(pos) % 2
373 : par->isRightToLeftPar(buf->params);
378 void LyXText::draw(BufferView * bview, Row const * row,
379 LyXParagraph::size_type & vpos,
380 int offset, float & x, bool cleared)
382 Painter & pain = bview->painter();
384 LyXParagraph::size_type pos = vis2log(vpos);
385 char c = row->par()->GetChar(pos);
388 if (IsNewlineChar(c)) {
390 // Draw end-of-line marker
391 LyXFont const font = GetFont(bview->buffer(), row->par(), pos);
392 int const wid = lyxfont::width('n', font);
393 int const asc = lyxfont::maxAscent(font);
394 int const y = offset + row->baseline();
397 if (bidi_level(pos) % 2 == 0) {
398 xp[0] = int(x + wid * 0.375);
399 yp[0] = int(y - 0.875 * asc * 0.75);
402 yp[1] = int(y - 0.500 * asc * 0.75);
404 xp[2] = int(x + wid * 0.375);
405 yp[2] = int(y - 0.125 * asc * 0.75);
407 pain.lines(xp, yp, 3, LColor::eolmarker);
410 yp[0] = int(y - 0.500 * asc * 0.75);
412 xp[1] = int(x + wid);
413 yp[1] = int(y - 0.500 * asc * 0.75);
415 xp[2] = int(x + wid);
416 yp[2] = int(y - asc * 0.75);
418 pain.lines(xp, yp, 3, LColor::eolmarker);
420 xp[0] = int(x + wid * 0.625);
421 yp[0] = int(y - 0.875 * asc * 0.75);
423 xp[1] = int(x + wid);
424 yp[1] = int(y - 0.500 * asc * 0.75);
426 xp[2] = int(x + wid * 0.625);
427 yp[2] = int(y - 0.125 * asc * 0.75);
429 pain.lines(xp, yp, 3, LColor::eolmarker);
431 xp[0] = int(x + wid);
432 yp[0] = int(y - 0.500 * asc * 0.75);
435 yp[1] = int(y - 0.500 * asc * 0.75);
438 yp[2] = int(y - asc * 0.75);
440 pain.lines(xp, yp, 3, LColor::eolmarker);
446 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
447 LyXFont font2 = font;
449 if (c == LyXParagraph::META_FOOTNOTE
450 || c == LyXParagraph::META_MARGIN
451 || c == LyXParagraph::META_FIG
452 || c == LyXParagraph::META_TAB
453 || c == LyXParagraph::META_WIDE_FIG
454 || c == LyXParagraph::META_WIDE_TAB
455 || c == LyXParagraph::META_ALGORITHM) {
458 case LyXParagraph::META_MARGIN:
461 case LyXParagraph::META_FIG:
464 case LyXParagraph::META_TAB:
467 case LyXParagraph::META_ALGORITHM:
470 case LyXParagraph::META_WIDE_FIG:
473 case LyXParagraph::META_WIDE_TAB:
476 case LyXParagraph::META_FOOTNOTE:
483 // calculate the position of the footnotemark
484 int const y = (row->baseline() - lyxfont::maxAscent(font2)
485 + lyxfont::maxAscent(font));
487 font.setColor(LColor::footnote);
489 // draw it and set new x position
491 pain.text(int(x), offset + y, fs, font);
492 x += lyxfont::width(fs, font);
493 pain.line(int(tmpx), offset + row->baseline(),
494 int(x), offset + row->baseline(),
501 if (c == LyXParagraph::META_INSET) {
502 Inset * tmpinset = row->par()->GetInset(pos);
504 // tmpinset->update(bview, font, false);
505 tmpinset->draw(bview, font, offset+row->baseline(), x,
507 #ifdef SEEMS_TO_BE_NOT_NEEDED
508 if (status == CHANGED_IN_DRAW) {
509 UpdateInset(bview, tmpinset);
510 status = CHANGED_IN_DRAW;
516 if (lyxrc.mark_foreign_language &&
517 font.language() != bview->buffer()->params.language) {
518 int const y = offset + row->height() - 1;
519 pain.line(int(tmpx), y, int(x), y,
526 /* usual characters, no insets */
528 // Collect character that we can draw in one command
530 // This is dirty, but fast. Notice that it will never be too small.
531 // For the record, I'll note that Microsoft Word has a limit
532 // of 768 here. We have none :-) (Asger)
533 // Ok. I am the first to admit that the use of std::string will be
534 // a tiny bit slower than using a POD char array. However, I claim
535 // that this slowdown is so small that it is close to inperceptive.
536 // So IMHO we should go with the easier and clearer implementation.
537 // And even if 1024 is a large number here it might overflow, string
538 // will only overflow if the machine is out of memory...
539 static string textstring;
543 LyXParagraph::size_type const last = RowLastPrintable(row);
545 if (font.language()->lang() == "hebrew") {
546 if (Encodings::IsComposeChar_hebrew(c)) {
547 int const width = lyxfont::width(c, font2);
549 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
550 c = row->par()->GetChar(i);
551 if (!Encodings::IsComposeChar_hebrew(c)) {
552 if (IsPrintableNonspace(c)) {
557 dx = (c == 'ø' || c == 'ã') // dalet / resh
558 ? width2 - width : (width2 - width) / 2;
564 pain.text(int(x) + dx, offset + row->baseline(),
567 while (vpos <= last &&
568 (pos = vis2log(vpos)) >= 0
569 && IsPrintableNonspace(c = row->par()->GetChar(pos))
570 && !Encodings::IsComposeChar_hebrew(c)
571 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
575 // Draw text and set the new x position
576 pain.text(int(x), offset + row->baseline(),
578 x += lyxfont::width(textstring, font);
580 } else if (font.language()->lang() == "arabic" &&
581 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
582 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
583 if (Encodings::IsComposeChar_arabic(c)) {
584 c = TransformChar(c, row->par(), pos);
586 int const width = lyxfont::width(c, font2);
588 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
589 c = row->par()->GetChar(i);
590 if (!Encodings::IsComposeChar_arabic(c)) {
591 if (IsPrintableNonspace(c)) {
596 dx = (width2 - width) / 2;
602 pain.text(int(x) + dx, offset + row->baseline(),
605 textstring = TransformChar(c, row->par(), pos);
606 while (vpos <= last &&
607 (pos = vis2log(vpos)) >= 0
608 && IsPrintableNonspace(c = row->par()->GetChar(pos))
609 && !Encodings::IsComposeChar_arabic(c)
610 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
611 c = TransformChar(c, row->par(), pos);
615 // Draw text and set the new x position
616 pain.text(int(x), offset + row->baseline(),
618 x += lyxfont::width(textstring, font);
621 while (vpos <= last &&
622 (pos = vis2log(vpos)) >= 0
623 && IsPrintableNonspace(c = row->par()->GetChar(pos))
624 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
628 // Draw text and set the new x position
629 pain.text(int(x), offset + row->baseline(), textstring, font);
630 x += lyxfont::width(textstring, font);
633 if (lyxrc.mark_foreign_language &&
634 font.language() != bview->buffer()->params.language) {
635 int const y = offset + row->height() - 1;
636 pain.line(int(tmpx), y, int(x), y,
640 // If we want ulem.sty support, drawing
641 // routines should go here. (Asger)
642 // Why shouldn't LyXFont::drawText handle it internally?
646 // Returns the left beginning of the text.
647 // This information cannot be taken from the layouts-objekt, because in
648 // LaTeX the beginning of the text fits in some cases (for example sections)
649 // exactly the label-width.
650 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
652 LyXLayout const & layout =
653 textclasslist.Style(bview->buffer()->params.textclass,
654 row->par()->GetLayout());
656 string parindent = layout.parindent;
658 int x = LYX_PAPER_MARGIN;
660 x += lyxfont::signedWidth(textclasslist
661 .TextClass(bview->buffer()->params.textclass)
664 .TextClass(bview->buffer()->params.textclass)
667 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
668 LyXFont font(LyXFont::ALL_SANE);
669 font.setSize(LyXFont::SIZE_SMALL);
670 x += lyxfont::width("Mwide-figM", font)
671 + LYX_PAPER_MARGIN/2;
674 // this is the way, LyX handles the LaTeX-Environments.
675 // I have had this idea very late, so it seems to be a
676 // later added hack and this is true
677 if (!row->par()->GetDepth()) {
678 if (!row->par()->GetLayout()) {
679 // find the previous same level paragraph
681 if (row->par()->FirstPhysicalPar()->Previous()) {
683 if (row->par()->Previous()) {
685 LyXParagraph * newpar = row->par()
686 ->DepthHook(row->par()->GetDepth());
688 textclasslist.Style(bview->buffer()->params.textclass,
695 // find the next level paragraph
697 LyXParagraph * newpar =
698 row->par()->DepthHook(row->par()->GetDepth()-1);
700 // make a corresponding row. Needed to call LeftMargin()
702 // check wether it is a sufficent paragraph
705 && newpar->footnoteflag == row->par()->footnoteflag
708 .Style(bview->buffer()->params.textclass,
709 newpar->GetLayout()).isEnvironment()) {
711 dummyrow.par(newpar);
712 dummyrow.pos(newpar->Last());
713 x = LeftMargin(bview, &dummyrow);
715 // this is no longer an error, because this function
716 // is used to clear impossible depths after changing
717 // a layout. Since there is always a redo,
718 // LeftMargin() is always called
720 row->par()->FirstPhysicalPar()->depth = 0;
722 row->par()->depth = 0;
726 if (newpar && !row->par()->GetLayout()) {
728 if (newpar->FirstPhysicalPar()->noindent)
730 if (newpar->noindent)
734 parindent = textclasslist
735 .Style(bview->buffer()->params.textclass,
736 newpar->GetLayout()).parindent;
741 LyXFont const labelfont = GetFont(bview->buffer(), row->par(), -2);
742 switch (layout.margintype) {
744 if (!layout.leftmargin.empty()) {
745 x += lyxfont::signedWidth(layout.leftmargin,
747 .TextClass(bview->buffer()->params.
751 if (!row->par()->GetLabelstring().empty()) {
752 x += lyxfont::signedWidth(layout.labelindent,
754 x += lyxfont::width(row->par()->GetLabelstring(),
756 x += lyxfont::width(layout.labelsep, labelfont);
760 x += lyxfont::signedWidth(layout.labelindent, labelfont);
761 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
762 if (!row->par()->GetLabelWidthString().empty()) {
763 x += lyxfont::width(row->par()->GetLabelWidthString(),
765 x += lyxfont::width(layout.labelsep, labelfont);
770 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
771 / (row->par()->GetDepth() + 4);
773 case MARGIN_FIRST_DYNAMIC:
774 if (layout.labeltype == LABEL_MANUAL) {
775 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
776 x += lyxfont::signedWidth(layout.leftmargin,
779 x += lyxfont::signedWidth(layout.labelindent,
782 } else if (row->pos()
783 // Special case to fix problems with
785 || (layout.labeltype == LABEL_STATIC
786 && layout.latextype == LATEX_ENVIRONMENT
787 && ! row->par()->IsFirstInSequence())) {
788 x += lyxfont::signedWidth(layout.leftmargin,
790 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
791 && layout.labeltype != LABEL_BIBLIO
792 && layout.labeltype !=
793 LABEL_CENTERED_TOP_ENVIRONMENT) {
794 x += lyxfont::signedWidth(layout.labelindent,
796 x += lyxfont::width(layout.labelsep, labelfont);
797 x += lyxfont::width(row->par()->GetLabelstring(),
802 case MARGIN_RIGHT_ADDRESS_BOX:
804 // ok, a terrible hack. The left margin depends on the widest
805 // row in this paragraph. Do not care about footnotes, they
806 // are *NOT* allowed in the LaTeX realisation of this layout.
808 // find the first row of this paragraph
809 Row const * tmprow = row;
810 while (tmprow->previous()
811 && tmprow->previous()->par() == row->par())
812 tmprow = tmprow->previous();
814 int minfill = tmprow->fill();
815 while (tmprow->next() && tmprow->next()->par() == row->par()) {
816 tmprow = tmprow->next();
817 if (tmprow->fill() < minfill)
818 minfill = tmprow->fill();
821 x += lyxfont::signedWidth(layout.leftmargin,
823 .TextClass(bview->buffer()->params.textclass)
829 if ((workWidth(bview) > 0) &&
830 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT)) {
831 if (!row->par()->pextra_widthp.empty()) {
832 x += workWidth(bview) *
833 lyx::atoi(row->par()->pextra_widthp) / 100;
834 } else if (!row->par()->pextra_width.empty()) {
835 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
836 if (xx > workWidth(bview))
837 xx = workWidth(bview) * 80 / 100;
839 } else { // should not happen
840 LyXFont font(LyXFont::ALL_SANE);
841 x += lyxfont::width("XXXXXX", font);
845 int align; // wrong type
847 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
848 align = layout.align;
850 align = row->par()->FirstPhysicalPar()->align;
852 if (row->par()->align == LYX_ALIGN_LAYOUT)
853 align = layout.align;
855 align = row->par()->align;
857 // set the correct parindent
858 if (row->pos() == 0) {
859 if ((layout.labeltype == LABEL_NO_LABEL
860 || layout.labeltype == LABEL_TOP_ENVIRONMENT
861 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
862 || (layout.labeltype == LABEL_STATIC
863 && layout.latextype == LATEX_ENVIRONMENT
864 && ! row->par()->IsFirstInSequence()))
866 && row->par() == row->par()->FirstPhysicalPar()
868 && align == LYX_ALIGN_BLOCK
869 && !row->par()->noindent
870 && (row->par()->layout ||
871 bview->buffer()->params.paragraph_separation ==
872 BufferParams::PARSEP_INDENT))
873 x += lyxfont::signedWidth(parindent,
875 .TextClass(bview->buffer()->params
878 else if (layout.labeltype == LABEL_BIBLIO) {
879 // ale970405 Right width for bibitems
880 x += bibitemMaxWidth(bview,textclasslist
881 .TextClass(bview->buffer()->params
890 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
892 LyXLayout const & layout =
893 textclasslist.Style(buf->params.textclass,
894 row->par()->GetLayout());
896 int x = LYX_PAPER_MARGIN
897 + lyxfont::signedWidth(textclasslist
898 .TextClass(buf->params.textclass)
901 .TextClass(buf->params.textclass)
905 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
906 x += LYX_PAPER_MARGIN / 2;
909 // this is the way, LyX handles the LaTeX-Environments.
910 // I have had this idea very late, so it seems to be a
911 // later added hack and this is true
912 if (row->par()->GetDepth()) {
913 // find the next level paragraph
915 LyXParagraph * newpar = row->par();
919 newpar = newpar->FirstPhysicalPar()->Previous();
921 newpar = newpar->FirstPhysicalPar();
922 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
923 && newpar->footnoteflag == row->par()->footnoteflag);
926 newpar = newpar->Previous();
928 && newpar->GetDepth() >= row->par()->GetDepth());
931 // make a corresponding row. Needed to call LeftMargin()
933 // check wether it is a sufficent paragraph
936 && newpar->footnoteflag == row->par()->footnoteflag
938 && textclasslist.Style(buf->params.textclass,
942 dummyrow.par(newpar);
944 x = RightMargin(buf, &dummyrow);
946 // this is no longer an error, because this function
947 // is used to clear impossible depths after changing
948 // a layout. Since there is always a redo,
949 // LeftMargin() is always called
951 row->par()->FirstPhysicalPar()->depth = 0;
953 row->par()->depth = 0;
958 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
959 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
960 .TextClass(buf->params.textclass)
961 .defaultfont()) * 4 / (row->par()->GetDepth()
967 int LyXText::LabelEnd(BufferView * bview, Row const * row) const
969 if (textclasslist.Style(bview->buffer()->params.textclass,
970 row->par()->GetLayout()).margintype
974 tmprow.pos(row->par()->Last());
975 return LeftMargin(bview, &tmprow); /* just the beginning
978 return 0; /* LabelEnd is only needed, if the
979 layout fills a flushleft
984 // get the next breakpoint in a given paragraph
985 LyXParagraph::size_type
986 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
988 LyXParagraph * par = row->par();
993 LyXParagraph::size_type const pos = row->pos();
996 // position of the last possible breakpoint
997 // -1 isn't a suitable value, but a flag
998 LyXParagraph::size_type last_separator = -1;
999 width -= RightMargin(bview->buffer(), row);
1001 LyXParagraph::size_type const main_body =
1002 BeginningOfMainBody(bview->buffer(), par);
1003 LyXLayout const & layout =
1004 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1005 LyXParagraph::size_type i = pos;
1007 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1008 /* special code for right address boxes, only newlines count */
1009 while (i < par->Last()) {
1010 if (par->IsNewline(i)) {
1012 i = par->Last() - 1; // this means break
1014 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1015 par->GetInset(i) && par->GetInset(i)->display()){
1016 par->GetInset(i)->display(false);
1021 // Last position is an invariant
1022 LyXParagraph::size_type const last =
1024 // this is the usual handling
1025 int x = LeftMargin(bview, row);
1026 bool doitonetime = true;
1027 while (doitonetime || ((x < width) && (i < last))) {
1028 doitonetime = false;
1029 char const c = par->GetChar(i);
1030 if (IsNewlineChar(c)) {
1032 x = width; // this means break
1033 } else if (c == LyXParagraph::META_INSET &&
1036 // check wether a Display() inset is
1037 // valid here. if not, change it to
1039 if (par->GetInset(i)->display() &&
1040 (layout.isCommand() ||
1041 (layout.labeltype == LABEL_MANUAL
1042 && i < BeginningOfMainBody(bview->buffer(), par)))) {
1043 // display istn't allowd
1044 par->GetInset(i)->display(false);
1045 x += SingleWidth(bview, par, i, c);
1046 } else if (par->GetInset(i)->display() ||
1047 par->GetInset(i)->needFullRow()) {
1048 // So break the line here
1052 if (IsLineSeparatorChar(par->GetChar(i+1)))
1055 last_separator = last; // to avoid extra rows
1057 last_separator = i - 1;
1058 x = width; // this means break
1064 x += SingleWidth(bview, par, i, c);
1068 if (IsLineSeparatorChar(c))
1070 x += SingleWidth(bview, par, i, c);
1073 if (i == main_body) {
1074 x += lyxfont::width(layout.labelsep,
1075 GetFont(bview->buffer(), par, -2));
1076 if (par->IsLineSeparator(i - 1))
1077 x-= SingleWidth(bview, par, i - 1);
1078 int left_margin = LabelEnd(bview, row);
1079 if (x < left_margin)
1083 // end of paragraph is always a suitable separator
1084 if (i == last && x < width)
1088 // well, if last_separator is still 0, the line isn't breakable.
1089 // don't care and cut simply at the end
1090 if (last_separator < 0) {
1094 // manual labels cannot be broken in LaTeX, do not care
1095 if (main_body && last_separator < main_body)
1096 last_separator = main_body - 1;
1098 return last_separator;
1102 // returns the minimum space a row needs on the screen in pixel
1103 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1105 if (paper_width < 0)
1109 // get the pure distance
1110 LyXParagraph::size_type const last = RowLastPrintable(row);
1112 // special handling of the right address boxes
1113 if (textclasslist.Style(bview->buffer()->params.textclass,
1114 row->par()->GetLayout()).margintype
1115 == MARGIN_RIGHT_ADDRESS_BOX) {
1116 int const tmpfill = row->fill();
1117 row->fill(0); // the minfill in MarginLeft()
1118 w = LeftMargin(bview, row);
1121 w = LeftMargin(bview, row);
1123 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1124 row->par()->GetLayout());
1125 LyXParagraph::size_type const main_body =
1126 BeginningOfMainBody(bview->buffer(), row->par());
1127 LyXParagraph::size_type i = row->pos();
1130 if (main_body > 0 && i == main_body) {
1131 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1132 if (row->par()->IsLineSeparator(i - 1))
1133 w -= SingleWidth(bview, row->par(), i - 1);
1134 int left_margin = LabelEnd(bview, row);
1135 if (w < left_margin)
1138 w += SingleWidth(bview, row->par(), i);
1141 if (main_body > 0 && main_body > last) {
1142 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1143 if (last >= 0 && row->par()->IsLineSeparator(last))
1144 w -= SingleWidth(bview, row->par(), last);
1145 int const left_margin = LabelEnd(bview, row);
1146 if (w < left_margin)
1150 int const fill = paper_width - w - RightMargin(bview->buffer(), row);
1155 // returns the minimum space a manual label needs on the screen in pixel
1156 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1158 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par()) - 1;
1159 // -1 because a label ends either with a space that is in the label,
1160 // or with the beginning of a footnote that is outside the label.
1162 // I don't understand this code in depth, but sometimes "last" is
1163 // less than 0 and this causes a crash. This fix seems to work
1164 // correctly, but I bet the real error is elsewhere. The bug is
1165 // triggered when you have an open footnote in a paragraph
1166 // environment with a manual label. (Asger)
1167 if (last < 0) last = 0;
1169 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1176 w += SingleWidth(bview, row->par(), i);
1181 if (!row->par()->labelwidthstring.empty()) {
1182 fill = max(lyxfont::width(row->par()->labelwidthstring,
1183 GetFont(bview->buffer(), row->par(), -2)) - w,
1191 // returns the number of separators in the specified row. The separator
1192 // on the very last column doesnt count
1193 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1195 LyXParagraph::size_type const last = RowLast(row);
1196 LyXParagraph::size_type p =
1197 max(row->pos(), BeginningOfMainBody(buf, row->par()));
1199 for (; p < last; ++p) {
1200 if (row->par()->IsSeparator(p)) {
1208 // returns the number of hfills in the specified row. The LyX-Hfill is
1209 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1210 // ignored. This is *MUCH* more usefull than not to ignore!
1211 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1213 LyXParagraph::size_type const last = RowLast(row);
1214 LyXParagraph::size_type first = row->pos();
1215 if (first) { /* hfill *DO* count at the beginning
1217 while(first <= last && row->par()->IsHfill(first))
1221 first = max(first, BeginningOfMainBody(buf, row->par()));
1223 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1224 if (row->par()->IsHfill(p)) {
1232 // like NumberOfHfills, but only those in the manual label!
1233 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1235 LyXParagraph::size_type last = RowLast(row);
1236 LyXParagraph::size_type first = row->pos();
1237 if (first) { /* hfill *DO* count at the beginning
1239 while(first < last && row->par()->IsHfill(first))
1243 last = min(last, BeginningOfMainBody(buf, row->par()));
1245 for (LyXParagraph::size_type p = first;
1246 p < last; ++p) { // last, because the end is ignored!
1247 if (row->par()->IsHfill(p)) {
1255 // returns true, if a expansion is needed.
1256 // Rules are given by LaTeX
1257 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1258 LyXParagraph::size_type pos) const
1260 // by the way, is it a hfill?
1261 if (!row_ptr->par()->IsHfill(pos))
1264 // at the end of a row it does not count
1265 if (pos >= RowLast(row_ptr))
1268 // at the beginning of a row it does not count, if it is not
1269 // the first row of a paragaph
1270 if (!row_ptr->pos())
1273 // in some labels it does not count
1274 if (textclasslist.Style(buf->params.textclass,
1275 row_ptr->par()->GetLayout()).margintype
1277 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1280 // if there is anything between the first char of the row and
1281 // the sepcified position that is not a newline and not a hfill,
1282 // the hfill will count, otherwise not
1283 LyXParagraph::size_type i = row_ptr->pos();
1284 while (i < pos && (row_ptr->par()->IsNewline(i)
1285 || row_ptr->par()->IsHfill(i)))
1292 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1294 /* get the maximum ascent and the maximum descent */
1297 float layoutasc = 0;
1298 float layoutdesc = 0;
1301 Inset * tmpinset = 0;
1303 /* this must not happen before the currentrow for clear reasons.
1304 so the trick is just to set the current row onto this row */
1306 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1308 /* ok , let us initialize the maxasc and maxdesc value.
1309 * This depends in LaTeX of the font of the last character
1310 * in the paragraph. The hack below is necessary because
1311 * of the possibility of open footnotes */
1313 /* Correction: only the fontsize count. The other properties
1314 are taken from the layoutfont. Nicer on the screen :) */
1316 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1317 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1319 LyXParagraph * par = row_ptr->par();
1320 LyXParagraph * firstpar = row_ptr->par();
1323 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1324 firstpar->GetLayout());
1326 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1327 LyXFont::FONT_SIZE const size = font.size();
1328 font = GetFont(bview->buffer(), par, -1);
1331 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1333 float spacing_val = 1.0;
1334 if (!row_ptr->par()->spacing.isDefault()) {
1335 spacing_val = row_ptr->par()->spacing.getValue();
1337 spacing_val = bview->buffer()->params.spacing.getValue();
1339 //lyxerr << "spacing_val = " << spacing_val << endl;
1341 int maxasc = int(lyxfont::maxAscent(font) *
1342 layout.spacing.getValue() *
1344 int maxdesc = int(lyxfont::maxDescent(font) *
1345 layout.spacing.getValue() *
1347 int const pos_end = RowLast(row_ptr);
1351 // Check if any insets are larger
1352 for (int pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1353 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1354 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1355 tmpinset = row_ptr->par()->GetInset(pos);
1357 tmpinset->update(bview, tmpfont);
1358 asc = tmpinset->ascent(bview, tmpfont);
1359 desc = tmpinset->descent(bview, tmpfont);
1360 maxwidth += tmpinset->width(bview, tmpfont);
1361 maxasc = max(maxasc, asc);
1362 maxdesc = max(maxdesc, desc);
1365 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1369 // Check if any custom fonts are larger (Asger)
1370 // This is not completely correct, but we can live with the small,
1371 // cosmetic error for now.
1372 LyXFont::FONT_SIZE const maxsize =
1373 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1375 if (maxsize > font.size()) {
1376 font.setSize(maxsize);
1378 asc = lyxfont::maxAscent(font);
1379 desc = lyxfont::maxDescent(font);
1386 // This is nicer with box insets:
1390 row_ptr->ascent_of_text(maxasc);
1392 /* is it a top line? */
1393 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1395 /* some parksips VERY EASY IMPLEMENTATION */
1396 if (bview->buffer()->params.paragraph_separation ==
1397 BufferParams::PARSEP_SKIP) {
1398 if (layout.isParagraph()
1399 && firstpar->GetDepth() == 0
1400 && firstpar->Previous())
1401 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1402 else if (firstpar->Previous()
1403 && textclasslist.Style(bview->buffer()->params.textclass,
1404 firstpar->Previous()->GetLayout()).isParagraph()
1405 && firstpar->Previous()->GetDepth() == 0)
1406 // is it right to use defskip here too? (AS)
1407 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1410 /* the paper margins */
1411 if (!row_ptr->par()->previous && bv_owner)
1412 maxasc += LYX_PAPER_MARGIN;
1414 /* add the vertical spaces, that the user added */
1415 if (firstpar->added_space_top.kind() != VSpace::NONE)
1416 maxasc += int(firstpar->added_space_top.inPixels(bview));
1418 /* do not forget the DTP-lines!
1419 * there height depends on the font of the nearest character */
1420 if (firstpar->line_top)
1421 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1424 /* and now the pagebreaks */
1425 if (firstpar->pagebreak_top)
1426 maxasc += 3 * DefaultHeight();
1428 /* this is special code for the chapter, since the label of this
1429 * layout is printed in an extra row */
1430 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1431 && bview->buffer()->params.secnumdepth >= 0) {
1432 float spacing_val = 1.0;
1433 if (!row_ptr->par()->spacing.isDefault()) {
1434 spacing_val = row_ptr->par()->spacing.getValue();
1436 spacing_val = bview->buffer()->params.spacing.getValue();
1439 labeladdon = int(lyxfont::maxDescent(labelfont) *
1440 layout.spacing.getValue() *
1442 + int(lyxfont::maxAscent(labelfont) *
1443 layout.spacing.getValue() *
1447 /* special code for the top label */
1448 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1449 || layout.labeltype == LABEL_BIBLIO
1450 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1451 && row_ptr->par()->IsFirstInSequence()
1452 && !row_ptr->par()->GetLabelstring().empty()) {
1453 float spacing_val = 1.0;
1454 if (!row_ptr->par()->spacing.isDefault()) {
1455 spacing_val = row_ptr->par()->spacing.getValue();
1457 spacing_val = bview->buffer()->params.spacing.getValue();
1461 (lyxfont::maxAscent(labelfont) *
1462 layout.spacing.getValue() *
1464 +(lyxfont::maxDescent(labelfont) *
1465 layout.spacing.getValue() *
1467 + layout.topsep * DefaultHeight()
1468 + layout.labelbottomsep * DefaultHeight());
1471 /* and now the layout spaces, for example before and after a section,
1472 * or between the items of a itemize or enumerate environment */
1474 if (!firstpar->pagebreak_top) {
1475 LyXParagraph * prev = row_ptr->par()->Previous();
1477 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1478 if (prev && prev->GetLayout() == firstpar->GetLayout()
1479 && prev->GetDepth() == firstpar->GetDepth()
1480 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1482 layoutasc = (layout.itemsep * DefaultHeight());
1484 else if (row_ptr->previous()) {
1485 tmptop = layout.topsep;
1487 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1488 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1489 row_ptr->previous()->par()->
1490 GetLayout()).bottomsep;
1493 layoutasc = (tmptop * DefaultHeight());
1495 else if (row_ptr->par()->line_top){
1496 tmptop = layout.topsep;
1499 layoutasc = (tmptop * DefaultHeight());
1502 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1504 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1505 prev->GetLayout()).parsep * DefaultHeight());
1508 if (firstpar->Previous()
1509 && firstpar->Previous()->GetDepth() == 0
1510 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1513 else if (firstpar->Previous()){
1514 maxasc += int(layout.parsep * DefaultHeight());
1520 /* is it a bottom line? */
1523 row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1525 row_ptr->par() == par
1527 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1529 /* the paper margins */
1530 if (!par->next && bv_owner)
1531 maxdesc += LYX_PAPER_MARGIN;
1533 /* add the vertical spaces, that the user added */
1534 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1535 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1537 /* do not forget the DTP-lines!
1538 * there height depends on the font of the nearest character */
1539 if (firstpar->line_bottom)
1540 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1541 par, par->Last() - 1));
1543 /* and now the pagebreaks */
1544 if (firstpar->pagebreak_bottom)
1545 maxdesc += 3 * DefaultHeight();
1547 /* and now the layout spaces, for example before and after a section,
1548 * or between the items of a itemize or enumerate environment */
1549 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1550 LyXParagraph * nextpar = row_ptr->par()->Next();
1551 LyXParagraph * comparepar = row_ptr->par();
1555 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1556 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1557 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1558 if (comparepar->GetLayout()!= nextpar->GetLayout()
1559 || nextpar->GetLabelWidthString() !=
1560 comparepar->GetLabelWidthString())
1561 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1563 if (unusual > usual)
1564 layoutdesc = unusual;
1568 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1570 if (comparepar->GetLayout()!= nextpar->GetLayout()
1571 || nextpar->GetLabelWidthString() !=
1572 comparepar->GetLabelWidthString())
1573 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1578 /* incalculate the layout spaces */
1579 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1580 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1582 /* calculate the new height of the text */
1583 height -= row_ptr->height();
1585 row_ptr->height(maxasc + maxdesc + labeladdon);
1586 row_ptr->baseline(maxasc + labeladdon);
1588 height += row_ptr->height();
1590 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1591 row_ptr->width(int(maxwidth + x));
1594 width = max(0,workWidth(bview));
1596 if (r->width() > width)
1604 /* Appends the implicit specified paragraph behind the specified row,
1605 * start at the implicit given position */
1606 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1608 bool not_ready = true;
1610 // The last character position of a paragraph is an invariant so we can
1611 // safely get it here. (Asger)
1612 int const lastposition = row->par()->Last();
1615 // Get the next breakpoint
1616 int z = NextBreakPoint(bview, row, workWidth(bview));
1620 // Insert the new row
1621 if (z < lastposition) {
1623 InsertRow(row, row->par(), z);
1630 // Set the dimensions of the row
1631 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1632 SetHeightOfRow(bview, tmprow);
1634 } while (not_ready);
1638 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1640 bool not_ready = true;
1643 /* get the next breakpoint */
1644 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1647 if (z < row->par()->Last()) {
1648 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1651 InsertRow(row, row->par(), z);
1657 if (row->pos() == z)
1658 not_ready = false; // the rest will not change
1664 /* if there are some rows too much, delete them */
1665 /* only if you broke the whole paragraph! */
1666 Row * tmprow2 = row;
1667 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1668 tmprow2 = tmprow2->next();
1670 while (tmprow2 != row) {
1671 tmprow2 = tmprow2->previous();
1672 RemoveRow(tmprow2->next());
1677 /* set the dimensions of the row */
1678 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1679 SetHeightOfRow(bview, tmprow);
1680 } while (not_ready);
1684 // this is just a little changed version of break again
1685 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1687 // get the next breakpoint
1688 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1691 if (z < row->par()->Last()) {
1693 || (row->next() && row->next()->par() != row->par())) {
1694 /* insert a new row */
1696 InsertRow(row, row->par(), z);
1702 if (row->pos() != z)
1706 // if there are some rows too much, delete them
1707 // only if you broke the whole paragraph!
1708 Row * tmprow2 = row;
1709 while (tmprow2->next()
1710 && tmprow2->next()->par() == row->par()) {
1711 tmprow2 = tmprow2->next();
1713 while (tmprow2 != row) {
1714 tmprow2 = tmprow2->previous();
1715 RemoveRow(tmprow2->next());
1719 // set the dimensions of the row
1720 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1721 SetHeightOfRow(bview, tmprow);
1725 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1727 LyXLayout const & layout =
1728 textclasslist.Style(bview->buffer()->params.textclass,
1729 cursor.par()->GetLayout());
1731 // this is only allowed, if the current paragraph is not empty or caption
1732 if ((cursor.par()->Last() <= 0
1734 && !cursor.par()->IsDummy()
1738 layout.labeltype!= LABEL_SENSITIVE)
1741 SetUndo(bview->buffer(), Undo::INSERT,
1743 cursor.par()->ParFromPos(cursor.pos())->previous,
1744 cursor.par()->ParFromPos(cursor.pos())->next
1746 cursor.par()->previous,
1751 // please break always behind a space
1752 if (cursor.pos() < cursor.par()->Last()
1753 && cursor.par()->IsLineSeparator(cursor.pos()))
1754 cursor.pos(cursor.pos() + 1);
1756 // break the paragraph
1760 keep_layout = layout.isEnvironment();
1761 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1764 // well this is the caption hack since one caption is really enough
1765 if (layout.labeltype == LABEL_SENSITIVE) {
1767 // set to standard-layout
1768 cursor.par()->SetLayout(bview->buffer()->params, 0);
1770 // set to standard-layout
1771 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1774 /* if the cursor is at the beginning of a row without prior newline,
1776 * This touches only the screen-update. Otherwise we would may have
1777 * an empty row on the screen */
1778 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1)
1779 && cursor.row()->pos() == cursor.pos()) {
1783 status = LyXText::NEED_MORE_REFRESH;
1784 refresh_row = cursor.row();
1785 refresh_y = cursor.y() - cursor.row()->baseline();
1787 // Do not forget the special right address boxes
1788 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1789 while (refresh_row->previous() &&
1790 refresh_row->previous()->par() == refresh_row->par()) {
1791 refresh_row = refresh_row->previous();
1792 refresh_y -= refresh_row->height();
1795 RemoveParagraph(cursor.row());
1797 // set the dimensions of the cursor row
1798 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1800 SetHeightOfRow(bview, cursor.row());
1802 while (cursor.par()->Next()->Last()
1803 && cursor.par()->Next()->IsNewline(0))
1804 cursor.par()->Next()->Erase(0);
1806 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1808 UpdateCounters(bview, cursor.row()->previous());
1810 /* This check is necessary. Otherwise the new empty paragraph will
1811 * be deleted automatically. And it is more friendly for the user! */
1813 SetCursor(bview, cursor.par()->Next(), 0);
1815 SetCursor(bview, cursor.par(), 0);
1817 if (cursor.row()->next())
1818 BreakAgain(bview, cursor.row()->next());
1825 void LyXText::OpenFootnote(BufferView * bview)
1827 LyXParagraph * endpar,* tmppar;
1830 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1832 /* if there is no footnote in this paragraph, just return. */
1834 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1837 /* ok, move the cursor right before the footnote */
1839 /* just a little faster than using CursorRight() */
1841 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1842 cursor.pos(cursor.pos() + 1);
1845 /* now the cursor is at the beginning of the physical par */
1846 SetCursor(bview, cursor.par(),
1847 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1849 /* the cursor must be exactly before the footnote */
1850 par = cursor.par()->ParFromPos(cursor.pos());
1852 status = LyXText::NEED_MORE_REFRESH;
1853 refresh_row = cursor.row();
1854 refresh_y = cursor.y() - cursor.row()->baseline();
1856 tmppar = cursor.par();
1857 endpar = cursor.par()->Next();
1860 tmppar->OpenFootnote(cursor.pos());
1861 RemoveParagraph(row);
1862 /* set the dimensions of the cursor row */
1863 row->fill(Fill(bview, row, workWidth(bview)));
1864 SetHeightOfRow(bview, row);
1865 // CHECK See comment on top of text.C
1866 tmppar = tmppar->Next();
1868 while (tmppar != endpar) {
1870 InsertParagraph(bview, tmppar, row);
1871 while (row->next() && row->next()->par() == tmppar)
1873 tmppar = tmppar->Next();
1876 SetCursor(bview, par->next, 0);
1877 sel_cursor = cursor;
1882 // Just a macro to make some thing easier.
1883 void LyXText::RedoParagraph(BufferView * bview) const
1886 RedoParagraphs(bview, cursor, cursor.par()->Next());
1887 SetCursorIntern(bview, cursor.par(), cursor.pos());
1891 /* insert a character, moves all the following breaks in the
1892 * same Paragraph one to the right and make a rebreak */
1893 void LyXText::InsertChar(BufferView * bview, char c)
1895 SetUndo(bview->buffer(), Undo::INSERT,
1897 cursor.par()->ParFromPos(cursor.pos())->previous,
1898 cursor.par()->ParFromPos(cursor.pos())->next
1900 cursor.par()->previous,
1905 // When the free-spacing option is set for the current layout,
1906 // disable the double-space checking
1908 bool const freeSpacing =
1909 textclasslist.Style(bview->buffer()->params.textclass,
1910 cursor.row()->par()->GetLayout()).free_spacing;
1913 if (lyxrc.auto_number) {
1914 if (current_font.number() == LyXFont::ON) {
1915 if (!isdigit(c) && !strchr("+-/*", c) &&
1917 cursor.pos() >= 1 &&
1918 cursor.pos() < cursor.par()->size() &&
1919 GetFont(bview->buffer(),
1921 cursor.pos()).number() == LyXFont::ON &&
1922 GetFont(bview->buffer(),
1924 cursor.pos()-1).number() == LyXFont::ON)
1926 Number(bview); // Set current_font.number to OFF
1927 } else if (isdigit(c) &&
1928 real_current_font.isVisibleRightToLeft()) {
1929 Number(bview); // Set current_font.number to ON
1931 if (cursor.pos() > 0) {
1932 char const c = cursor.par()->GetChar(cursor.pos() - 1);
1933 if (strchr("+-",c) &&
1934 (cursor.pos() == 1 ||
1935 cursor.par()->IsSeparator(cursor.pos() - 2) ||
1936 cursor.par()->IsNewline(cursor.pos() - 2) )
1938 SetCharFont(bview->buffer(),
1942 } else if (strchr(".,", c) &&
1943 cursor.pos() >= 2 &&
1944 GetFont(bview->buffer(),
1946 cursor.pos()-2).number() == LyXFont::ON) {
1947 SetCharFont(bview->buffer(),
1957 /* First check, if there will be two blanks together or a blank at
1958 the beginning of a paragraph.
1959 I decided to handle blanks like normal characters, the main
1960 difference are the special checks when calculating the row.fill
1961 (blank does not count at the end of a row) and the check here */
1963 // The bug is triggered when we type in a description environment:
1964 // The current_font is not changed when we go from label to main text
1965 // and it should (along with realtmpfont) when we type the space.
1966 // CHECK There is a bug here! (Asger)
1968 LyXFont realtmpfont = real_current_font;
1969 LyXFont rawtmpfont = current_font; /* store the current font.
1970 * This is because of the use
1971 * of cursor movements. The moving
1972 * cursor would refresh the
1975 // Get the font that is used to calculate the baselineskip
1976 LyXParagraph::size_type const lastpos = cursor.par()->Last();
1977 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
1980 bool jumped_over_space = false;
1982 if (!freeSpacing && IsLineSeparatorChar(c)) {
1983 if ((cursor.pos() > 0
1984 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
1985 || (cursor.pos() > 0
1986 && cursor.par()->IsNewline(cursor.pos() - 1))
1987 || (cursor.pos() == 0
1989 && !(cursor.par()->Previous()
1990 && cursor.par()->Previous()->footnoteflag
1991 == LyXParagraph::OPEN_FOOTNOTE)
1994 if (cursor.pos() == 0 )
1995 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1997 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2001 } else if (IsNewlineChar(c)) {
2003 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2005 if (cursor.par() == cursor.par()
2007 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2011 /* No newline at first position
2012 * of a paragraph or behind labels.
2013 * TeX does not allow that. */
2015 if (cursor.pos() < cursor.par()->Last() &&
2016 cursor.par()->IsLineSeparator(cursor.pos()))
2017 // newline always after a blank!
2019 cursor.row()->fill(-1); // to force a new break
2022 // the display inset stuff
2023 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2024 && cursor.row()->par()->GetInset(cursor.row()->pos())
2025 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2026 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2027 cursor.row()->fill(-1); // to force a new break
2029 // get the cursor row fist
2030 Row * row = cursor.row();
2031 int y = cursor.y() - row->baseline();
2032 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2033 * already insertet the character */
2034 cursor.par()->InsertChar(cursor.pos(), c);
2035 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2037 if (!jumped_over_space) {
2038 // refresh the positions
2040 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2041 tmprow = tmprow->next();
2042 tmprow->pos(tmprow->pos() + 1);
2046 // Is there a break one row above
2047 if ((cursor.par()->IsLineSeparator(cursor.pos())
2048 || cursor.par()->IsNewline(cursor.pos())
2049 || cursor.row()->fill() == -1)
2050 && row->previous() && row->previous()->par() == row->par()) {
2051 LyXParagraph::size_type z = NextBreakPoint(bview,
2054 if (z >= row->pos()) {
2057 // set the dimensions of the row above
2058 row->previous()->fill(Fill(bview,
2062 SetHeightOfRow(bview, row->previous());
2064 y -= row->previous()->height();
2066 refresh_row = row->previous();
2067 status = LyXText::NEED_MORE_REFRESH;
2069 BreakAgainOneRow(bview, row);
2071 current_font = rawtmpfont;
2072 real_current_font = realtmpfont;
2073 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2074 false, cursor.boundary());
2075 // cursor MUST be in row now.
2077 if (row->next() && row->next()->par() == row->par())
2078 need_break_row = row->next();
2082 // check, wether the last characters font has changed.
2083 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2084 && rawparfont != rawtmpfont)
2085 RedoHeightOfParagraph(bview, cursor);
2092 // recalculate the fill of the row
2093 if (row->fill() >= 0) /* needed because a newline
2094 * will set fill to -1. Otherwise
2095 * we would not get a rebreak! */
2096 row->fill(Fill(bview, row, workWidth(bview)));
2097 if (row->fill() < 0) {
2100 refresh_x = cursor.x();
2101 refresh_pos = cursor.pos();
2102 status = LyXText::NEED_MORE_REFRESH;
2103 BreakAgainOneRow(bview, row);
2104 // will the cursor be in another row now?
2105 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2106 if (row->next() && row->next()->par() == row->par())
2107 // this should always be true
2109 BreakAgainOneRow(bview, row);
2111 current_font = rawtmpfont;
2112 real_current_font = realtmpfont;
2114 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2116 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos())
2117 != cursor.boundary())
2118 SetCursor(bview, cursor.par(), cursor.pos(), false,
2119 !cursor.boundary());
2120 if (row->next() && row->next()->par() == row->par())
2121 need_break_row = row->next();
2126 refresh_x = cursor.x();
2128 refresh_pos = cursor.pos();
2130 int const tmpheight = row->height();
2131 SetHeightOfRow(bview, row);
2132 if (tmpheight == row->height())
2133 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2135 status = LyXText::NEED_MORE_REFRESH;
2137 current_font = rawtmpfont;
2138 real_current_font = realtmpfont;
2139 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2143 // check, wether the last characters font has changed.
2144 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2145 && rawparfont != rawtmpfont) {
2146 RedoHeightOfParagraph(bview, cursor);
2148 // now the special right address boxes
2149 if (textclasslist.Style(bview->buffer()->params.textclass,
2150 cursor.par()->GetLayout()).margintype
2151 == MARGIN_RIGHT_ADDRESS_BOX) {
2152 RedoDrawingOfParagraph(bview, cursor);
2160 void LyXText::charInserted()
2162 // Here we could call FinishUndo for every 20 characters inserted.
2163 // This is from my experience how emacs does it.
2164 static unsigned int counter = 0;
2174 void LyXText::PrepareToPrint(BufferView * bview,
2175 Row * row, float & x,
2176 float & fill_separator,
2178 float & fill_label_hfill,
2183 float w = row->fill();
2185 fill_label_hfill = 0;
2187 fill_label_hfill = 0;
2190 row->par()->isRightToLeftPar(bview->buffer()->params);
2194 x = RightMargin(bview->buffer(), row);
2195 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2196 LyXFont font(LyXFont::ALL_SANE);
2197 font.setSize(LyXFont::SIZE_SMALL);
2198 x += lyxfont::width("Mwide-figM", font);
2202 if (workWidth(bview) > 0)
2203 x = LeftMargin(bview, row);
2207 // is there a manual margin with a manual label
2208 if (textclasslist.Style(bview->buffer()->params.textclass,
2209 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2210 && textclasslist.Style(bview->buffer()->params.textclass,
2211 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2213 /* one more since labels are left aligned */
2214 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2215 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2216 fill_label_hfill = LabelFill(bview, row) / nlh;
2220 // are there any hfills in the row?
2221 float const nh = NumberOfHfills(bview->buffer(), row);
2224 fill_hfill = w / nh;
2226 // is it block, flushleft or flushright?
2227 // set x how you need it
2230 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2231 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2233 align = row->par()->FirstPhysicalPar()->align;
2235 if (row->par()->align == LYX_ALIGN_LAYOUT)
2236 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2238 align = row->par()->align;
2241 // center displayed insets
2243 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2244 && (inset=row->par()->GetInset(row->pos()))
2245 && (inset->display())) // || (inset->scroll() < 0)))
2246 align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
2247 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
2250 case LYX_ALIGN_BLOCK:
2251 ns = NumberOfSeparators(bview->buffer(), row);
2252 if (ns && row->next() && row->next()->par() == row->par() &&
2253 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2254 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2255 && row->next()->par()->GetInset(row->next()->pos())
2256 && row->next()->par()->GetInset(row->next()->pos())->display())
2258 fill_separator = w / ns;
2262 case LYX_ALIGN_RIGHT:
2265 case LYX_ALIGN_CENTER:
2273 ComputeBidiTables(bview->buffer(), row);
2275 LyXParagraph::size_type main_body =
2276 BeginningOfMainBody(bview->buffer(), row->par());
2277 LyXParagraph::size_type last = RowLast(row);
2279 if (main_body > 0 &&
2280 (main_body-1 > last ||
2281 !row->par()->IsLineSeparator(main_body-1))) {
2282 LyXLayout const & layout =
2283 textclasslist.Style(bview->buffer()->params.textclass,
2284 row->par()->GetLayout());
2285 x += lyxfont::width(layout.labelsep,
2286 GetFont(bview->buffer(), row->par(), -2));
2287 if (main_body-1 <= last)
2288 x += fill_label_hfill;
2293 /* important for the screen */
2296 /* the cursor set functions have a special mechanism. When they
2297 * realize, that you left an empty paragraph, they will delete it.
2298 * They also delete the corresponding row */
2300 void LyXText::CursorRightOneWord(BufferView * bview) const
2302 // treat floats, HFills and Insets as words
2303 LyXCursor tmpcursor = cursor;
2304 // CHECK See comment on top of text.C
2306 if (tmpcursor.pos() == tmpcursor.par()->Last()
2307 && tmpcursor.par()->Next()) {
2308 tmpcursor.par(tmpcursor.par()->Next());
2313 // Skip through initial nonword stuff.
2314 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2315 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2317 // printf("Current pos1 %d", tmpcursor.pos()) ;
2318 tmpcursor.pos(tmpcursor.pos() + 1);
2321 // Advance through word.
2322 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2323 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2325 // printf("Current pos2 %d", tmpcursor.pos()) ;
2326 tmpcursor.pos(tmpcursor.pos() + 1);
2330 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2334 void LyXText::CursorTab(BufferView * bview) const
2336 LyXCursor tmpcursor = cursor;
2337 while (tmpcursor.pos() < tmpcursor.par()->Last()
2338 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
2339 tmpcursor.pos(tmpcursor.pos() + 1);
2341 if (tmpcursor.pos() == tmpcursor.par()->Last()){
2342 if (tmpcursor.par()->Next()) {
2343 tmpcursor.par(tmpcursor.par()->Next());
2347 tmpcursor.pos(tmpcursor.pos() + 1);
2348 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2352 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2353 of prior word, not to end of next prior word. */
2355 void LyXText::CursorLeftOneWord(BufferView * bview) const
2357 // treat HFills, floats and Insets as words
2358 LyXCursor tmpcursor = cursor;
2359 while (tmpcursor.pos()
2360 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
2361 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
2362 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
2364 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2366 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
2367 tmpcursor.pos(tmpcursor.pos() - 1);
2370 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
2372 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2374 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
2375 tmpcursor.pos(tmpcursor.pos() - 1);
2376 } else if (!tmpcursor.pos()) {
2377 if (tmpcursor.par()->Previous()){
2378 tmpcursor.par(tmpcursor.par()->Previous());
2379 tmpcursor.pos(tmpcursor.par()->Last());
2381 } else { // Here, tmpcursor != 0
2382 while (tmpcursor.pos() > 0 &&
2383 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
2384 tmpcursor.pos(tmpcursor.pos() - 1);
2386 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2389 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2392 void LyXText::SelectWord(BufferView * bview)
2394 // Move cursor to the beginning, when not already there.
2396 && !cursor.par()->IsSeparator(cursor.pos()-1)
2397 && !cursor.par()->IsKomma(cursor.pos()-1) )
2398 CursorLeftOneWord(bview);
2400 // set the sel cursor
2401 sel_cursor = cursor;
2403 while (cursor.pos() < cursor.par()->Last()
2404 && !cursor.par()->IsSeparator(cursor.pos())
2405 && !cursor.par()->IsKomma(cursor.pos()) )
2406 cursor.pos(cursor.pos() + 1);
2407 SetCursor(bview, cursor.par(), cursor.pos() );
2409 // finally set the selection
2414 /* -------> Select the word currently under the cursor when:
2415 1: no selection is currently set,
2416 2: the cursor is not at the borders of the word. */
2418 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
2421 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
2422 && !cursor.par()->IsSeparator(cursor.pos())
2423 && !cursor.par()->IsKomma(cursor.pos())
2424 && !cursor.par()->IsSeparator(cursor.pos() -1)
2425 && !cursor.par()->IsKomma(cursor.pos() -1)) {
2433 // This function is only used by the spellchecker for NextWord().
2434 // It doesn't handle LYX_ACCENTs and probably never will.
2435 string const LyXText::SelectNextWord(BufferView * bview,
2436 float & value) const
2438 LyXParagraph * tmppar = cursor.par();
2440 // If this is not the very first word, skip rest of
2441 // current word because we are probably in the middle
2442 // of a word if there is text here.
2443 if (cursor.pos() || cursor.par()->previous) {
2444 while (cursor.pos() < cursor.par()->Last()
2445 && cursor.par()->IsLetter(cursor.pos()))
2446 cursor.pos(cursor.pos() + 1);
2448 // Now, skip until we have real text (will jump paragraphs)
2449 while ((cursor.par()->Last() > cursor.pos()
2450 && (!cursor.par()->IsLetter(cursor.pos())
2451 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
2452 .latex() == LyXFont::ON))
2453 || (cursor.par()->Last() == cursor.pos()
2454 && cursor.par()->Next())){
2455 if (cursor.pos() == cursor.par()->Last()) {
2456 cursor.par(cursor.par()->Next());
2459 cursor.pos(cursor.pos() + 1);
2462 // Update the value if we changed paragraphs
2463 if (cursor.par() != tmppar){
2464 SetCursor(bview, cursor.par(), cursor.pos());
2465 value = float(cursor.y())/float(height);
2468 // Start the selection from here
2469 sel_cursor = cursor;
2471 std::ostringstream latex;
2473 // and find the end of the word
2474 // (optional hyphens are part of a word)
2475 while (cursor.pos() < cursor.par()->Last()
2476 && (cursor.par()->IsLetter(cursor.pos()))
2477 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2478 && cursor.par()->GetInset(cursor.pos()) != 0
2479 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2480 && latex.str() == "\\-"
2482 cursor.pos(cursor.pos() + 1);
2484 // Finally, we copy the word to a string and return it
2486 if (sel_cursor.pos() < cursor.pos()) {
2487 LyXParagraph::size_type i;
2488 for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
2489 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
2490 str += cursor.par()->GetChar(i);
2497 // This one is also only for the spellchecker
2498 void LyXText::SelectSelectedWord(BufferView * bview)
2500 // move cursor to the beginning
2501 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
2503 // set the sel cursor
2504 sel_cursor = cursor;
2506 std::ostringstream latex;
2508 // now find the end of the word
2509 while (cursor.pos() < cursor.par()->Last()
2510 && (cursor.par()->IsLetter(cursor.pos())
2511 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2512 && cursor.par()->GetInset(cursor.pos()) != 0
2513 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2514 && latex.str() == "\\-"
2516 cursor.pos(cursor.pos() + 1);
2518 SetCursor(bview, cursor.par(), cursor.pos());
2520 // finally set the selection
2525 /* -------> Delete from cursor up to the end of the current or next word. */
2526 void LyXText::DeleteWordForward(BufferView * bview)
2528 if (!cursor.par()->Last())
2531 LyXCursor tmpcursor = cursor;
2532 tmpcursor.row(0); //Â ??
2533 selection = true; // to avoid deletion
2534 CursorRightOneWord(bview);
2535 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2536 sel_cursor = cursor;
2540 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2541 CutSelection(bview);
2546 /* -------> Delete from cursor to start of current or prior word. */
2547 void LyXText::DeleteWordBackward(BufferView * bview)
2549 if (!cursor.par()->Last())
2552 LyXCursor tmpcursor = cursor;
2553 tmpcursor.row(0); // ??
2554 selection = true; // to avoid deletion
2555 CursorLeftOneWord(bview);
2556 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2557 sel_cursor = cursor;
2560 CutSelection(bview);
2565 /* -------> Kill to end of line. */
2566 void LyXText::DeleteLineForward(BufferView * bview)
2568 if (!cursor.par()->Last())
2569 // Paragraph is empty, so we just go to the right
2572 LyXCursor tmpcursor = cursor;
2573 // We can't store the row over a regular SetCursor
2574 // so we set it to 0 and reset it afterwards.
2575 tmpcursor.row(0); //Â ??
2576 selection = true; // to avoid deletion
2578 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2579 sel_cursor = cursor;
2582 // What is this test for ??? (JMarc)
2584 DeleteWordForward(bview);
2586 CutSelection(bview);
2592 // Change the case of a word at cursor position.
2593 // This function directly manipulates LyXParagraph::text because there
2594 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2595 // that it is correct. I guess part of it should be moved to
2596 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2597 // it does not access outside of the allocated array as the older
2598 // version did. (JMarc)
2599 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
2602 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
2604 LyXParagraph * tmppar = cursor.par();
2607 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
2610 LyXParagraph::size_type tmppos =
2611 cursor.par()->PositionInParFromPos(cursor.pos());
2613 LyXParagraph::size_type tmppos = cursor.pos();
2615 while (tmppos < tmppar->size()) {
2616 unsigned char c = tmppar->GetChar(tmppos);
2617 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2619 if (c != LyXParagraph::META_INSET) {
2621 case text_lowercase:
2624 case text_capitalization:
2626 action = text_lowercase;
2628 case text_uppercase:
2634 //tmppar->text[tmppos] = c;
2635 tmppar->SetChar(tmppos, c);
2638 CheckParagraph(bview, tmppar, tmppos);
2639 CursorRightOneWord(bview);
2643 void LyXText::Delete(BufferView * bview)
2645 // this is a very easy implementation
2647 LyXCursor old_cursor = cursor;
2648 int const old_cur_par_id = old_cursor.par()->id();
2649 int const old_cur_par_prev_id = old_cursor.par()->previous ?
2650 old_cursor.par()->previous->id() : 0;
2652 // just move to the right
2655 // CHECK Look at the comment here.
2656 // This check is not very good...
2657 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2658 // and that can very well delete the par or par->previous in
2659 // old_cursor. Will a solution where we compare paragraph id's
2661 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
2662 == old_cur_par_prev_id
2663 && cursor.par()->id() != old_cur_par_id)
2664 return; // delete-empty-paragraph-mechanism has done it
2666 // if you had success make a backspace
2667 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2668 LyXCursor tmpcursor = cursor;
2669 cursor = old_cursor; // to make sure undo gets the right cursor position
2670 SetUndo(bview->buffer(), Undo::DELETE,
2672 cursor.par()->ParFromPos(cursor.pos())->previous,
2673 cursor.par()->ParFromPos(cursor.pos())->next
2675 cursor.par()->previous,
2685 void LyXText::Backspace(BufferView * bview)
2687 // Get the font that is used to calculate the baselineskip
2688 LyXParagraph::size_type lastpos = cursor.par()->Last();
2689 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2692 if (cursor.pos() == 0) {
2693 // The cursor is at the beginning of a paragraph,
2694 // so the the backspace will collapse two paragraphs into one.
2696 // we may paste some paragraphs
2698 // is it an empty paragraph?
2701 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
2703 && !(cursor.par()->Next()
2704 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
2705 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
2708 // This is an empty paragraph and we delete it just by moving the cursor one step
2709 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2710 // of the paragraph.
2712 if (cursor.par()->previous) {
2714 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
2716 LyXParagraph * tmppar = cursor.par()->previous;
2718 if (cursor.par()->GetLayout() == tmppar->GetLayout()
2720 && cursor.par()->footnoteflag == tmppar->footnoteflag
2722 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2723 // Inherit botom DTD from the paragraph below.
2724 // (the one we are deleting)
2725 tmppar->line_bottom = cursor.par()->line_bottom;
2726 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
2727 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
2732 // the layout things can change the height of a row !
2733 int const tmpheight = cursor.row()->height();
2734 SetHeightOfRow(bview, cursor.row());
2735 if (cursor.row()->height() != tmpheight) {
2736 refresh_y = cursor.y() - cursor.row()->baseline();
2737 refresh_row = cursor.row();
2738 status = LyXText::NEED_MORE_REFRESH;
2745 if (cursor.par()->ParFromPos(cursor.pos())->previous){
2746 SetUndo(bview->buffer(), Undo::DELETE,
2747 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
2748 cursor.par()->ParFromPos(cursor.pos())->next);
2751 if (cursor.par()->previous) {
2752 SetUndo(bview->buffer(), Undo::DELETE,
2753 cursor.par()->previous->previous,
2754 cursor.par()->next);
2758 LyXParagraph * tmppar = cursor.par();
2759 Row * tmprow = cursor.row();
2761 // We used to do CursorLeftIntern() here, but it is
2762 // not a good idea since it triggers the auto-delete
2763 // mechanism. So we do a CursorLeftIntern()-lite,
2764 // without the dreaded mechanism. (JMarc)
2765 if (cursor.par()->Previous()) {
2766 // steps into the above paragraph.
2767 SetCursorIntern(bview, cursor.par()->Previous(),
2768 cursor.par()->Previous()->Last(), false);
2771 /* Pasting is not allowed, if the paragraphs have different
2772 layout. I think it is a real bug of all other
2773 word processors to allow it. It confuses the user.
2774 Even so with a footnote paragraph and a non-footnote
2775 paragraph. I will not allow pasting in this case,
2776 because the user would be confused if the footnote behaves
2777 different wether it is open or closed.
2779 Correction: Pasting is always allowed with standard-layout
2781 if (cursor.par() != tmppar
2782 && (cursor.par()->GetLayout() == tmppar->GetLayout()
2783 || tmppar->GetLayout() == 0 /*standard*/)
2785 && cursor.par()->footnoteflag == tmppar->footnoteflag
2787 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2789 RemoveParagraph(tmprow);
2791 cursor.par()->PasteParagraph(bview->buffer()->params);
2793 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
2794 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
2795 // strangely enough it seems that commenting out the line above removes
2796 // most or all of the segfaults. I will however also try to move the
2797 // two Remove... lines in front of the PasteParagraph too.
2800 cursor.pos(cursor.pos() - 1);
2802 status = LyXText::NEED_MORE_REFRESH;
2803 refresh_row = cursor.row();
2804 refresh_y = cursor.y() - cursor.row()->baseline();
2806 // remove the lost paragraph
2807 // This one is not safe, since the paragraph that the tmprow and the
2808 // following rows belong to has been deleted by the PasteParagraph
2809 // above. The question is... could this be moved in front of the
2811 //RemoveParagraph(tmprow);
2812 //RemoveRow(tmprow);
2814 // This rebuilds the rows.
2815 AppendParagraph(bview, cursor.row());
2816 UpdateCounters(bview, cursor.row());
2818 // the row may have changed, block, hfills etc.
2819 SetCursor(bview, cursor.par(), cursor.pos(), false);
2822 /* this is the code for a normal backspace, not pasting
2824 SetUndo(bview->buffer(), Undo::DELETE,
2826 cursor.par()->ParFromPos(cursor.pos())->previous,
2827 cursor.par()->ParFromPos(cursor.pos())->next
2829 cursor.par()->previous,
2833 // We used to do CursorLeftIntern() here, but it is
2834 // not a good idea since it triggers the auto-delete
2835 // mechanism. So we do a CursorLeftIntern()-lite,
2836 // without the dreaded mechanism. (JMarc)
2837 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
2838 false, cursor.boundary());
2840 // some insets are undeletable here
2841 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2842 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2844 // force complete redo when erasing display insets
2845 // this is a cruel method but safe..... Matthias
2846 if (cursor.par()->GetInset(cursor.pos())->display() ||
2847 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
2848 cursor.par()->Erase(cursor.pos());
2849 RedoParagraph(bview);
2854 Row * row = cursor.row();
2855 int y = cursor.y() - row->baseline();
2856 LyXParagraph::size_type z;
2857 /* remember that a space at the end of a row doesnt count
2858 * when calculating the fill */
2859 if (cursor.pos() < RowLast(row) ||
2860 !cursor.par()->IsLineSeparator(cursor.pos())) {
2861 row->fill(row->fill() + SingleWidth(bview,
2866 /* some special code when deleting a newline. This is similar
2867 * to the behavior when pasting paragraphs */
2868 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
2869 cursor.par()->Erase(cursor.pos());
2870 // refresh the positions
2872 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2873 tmprow = tmprow->next();
2874 tmprow->pos(tmprow->pos() - 1);
2876 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
2877 cursor.pos(cursor.pos() - 1);
2879 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
2880 cursor.par()->InsertChar(cursor.pos(), ' ');
2881 // refresh the positions
2883 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2884 tmprow = tmprow->next();
2885 tmprow->pos(tmprow->pos() + 1);
2889 cursor.par()->Erase(cursor.pos());
2891 // refresh the positions
2893 while (tmprow->next()
2894 && tmprow->next()->par() == row->par()) {
2895 tmprow = tmprow->next();
2896 tmprow->pos(tmprow->pos() - 1);
2899 // delete newlines at the beginning of paragraphs
2900 while (cursor.par()->Last() &&
2901 cursor.par()->IsNewline(cursor.pos()) &&
2902 cursor.pos() == BeginningOfMainBody(bview->buffer(),
2904 cursor.par()->Erase(cursor.pos());
2905 // refresh the positions
2907 while (tmprow->next() &&
2908 tmprow->next()->par() == row->par()) {
2909 tmprow = tmprow->next();
2910 tmprow->pos(tmprow->pos() - 1);
2915 // is there a break one row above
2916 if (row->previous() && row->previous()->par() == row->par()) {
2917 z = NextBreakPoint(bview, row->previous(),
2919 if (z >= row->pos()) {
2922 Row * tmprow = row->previous();
2924 // maybe the current row is now empty
2925 if (row->pos() >= row->par()->Last()) {
2930 BreakAgainOneRow(bview, row);
2931 if (row->next() && row->next()->par() == row->par())
2932 need_break_row = row->next();
2937 // set the dimensions of the row above
2938 y -= tmprow->height();
2939 tmprow->fill(Fill(bview, tmprow,
2941 SetHeightOfRow(bview, tmprow);
2944 refresh_row = tmprow;
2945 status = LyXText::NEED_MORE_REFRESH;
2946 SetCursor(bview, cursor.par(), cursor.pos(),
2947 false, cursor.boundary());
2948 //current_font = rawtmpfont;
2949 //real_current_font = realtmpfont;
2950 // check, whether the last character's font has changed.
2952 cursor.par()->GetFontSettings(bview->buffer()->params,
2953 cursor.par()->Last() - 1))
2954 RedoHeightOfParagraph(bview, cursor);
2959 // break the cursor row again
2960 if (row->next() && row->next()->par() == row->par() &&
2961 (RowLast(row) == row->par()->Last() - 1 ||
2962 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
2964 /* it can happen that a paragraph loses one row
2965 * without a real breakup. This is when a word
2966 * is to long to be broken. Well, I don t care this
2968 if (RowLast(row) == row->par()->Last() - 1)
2969 RemoveRow(row->next());
2973 status = LyXText::NEED_MORE_REFRESH;
2975 BreakAgainOneRow(bview, row);
2976 // will the cursor be in another row now?
2977 if (row->next() && row->next()->par() == row->par() &&
2978 RowLast(row) <= cursor.pos()) {
2980 BreakAgainOneRow(bview, row);
2983 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2985 if (row->next() && row->next()->par() == row->par())
2986 need_break_row = row->next();
2990 // set the dimensions of the row
2991 row->fill(Fill(bview, row, workWidth(bview)));
2992 int const tmpheight = row->height();
2993 SetHeightOfRow(bview, row);
2994 if (tmpheight == row->height())
2995 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2997 status = LyXText::NEED_MORE_REFRESH;
3000 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3004 // current_font = rawtmpfont;
3005 // real_current_font = realtmpfont;
3007 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos())
3008 != cursor.boundary())
3009 SetCursor(bview, cursor.par(), cursor.pos(), false,
3010 !cursor.boundary());
3012 lastpos = cursor.par()->Last();
3013 if (cursor.pos() == lastpos)
3014 SetCurrentFont(bview);
3016 // check, whether the last characters font has changed.
3018 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3019 RedoHeightOfParagraph(bview, cursor);
3021 // now the special right address boxes
3022 if (textclasslist.Style(bview->buffer()->params.textclass,
3023 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3024 RedoDrawingOfParagraph(bview, cursor);
3030 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3031 Row * row_ptr, int y, bool cleared)
3033 /* returns a printed row */
3034 Painter & pain = bview->painter();
3037 row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3039 LyXParagraph::size_type const last = RowLastPrintable(row_ptr);
3041 LyXParagraph::size_type vpos, pos;
3047 LyXFont font(LyXFont::ALL_SANE);
3049 if (row_ptr->height() <= 0) {
3050 lyxerr << "LYX_ERROR: row.height: "
3051 << row_ptr->height() << endl;
3055 float fill_separator;
3057 float fill_label_hfill;
3058 PrepareToPrint(bview, row_ptr, x, fill_separator,
3059 fill_hfill, fill_label_hfill);
3061 if (inset_owner && (x < 0))
3065 // clear the area where we want to paint/print
3066 int ww = bview->workWidth();
3068 bool clear_area = true;
3071 if (!bview->screen()->forceClear() && last == row_ptr->pos()
3072 && row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET
3073 && (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
3074 clear_area = inset->doClearArea();
3076 // we don't need to clear it's already done!!!
3079 } else if (clear_area) {
3080 #ifdef WITH_WARNINGS
3081 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
3083 int const w = (inset_owner ?
3084 inset_owner->width(bview, font)-2 : ww);
3085 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3086 } else if (inset != 0) {
3087 int h = row_ptr->baseline() - inset->ascent(bview, font);
3089 int const w = (inset_owner ?
3090 inset_owner->width(bview, font) : ww);
3091 pain.fillRectangle(x_offset, y_offset, w, h);
3093 h += inset->ascent(bview, font) + inset->descent(bview, font);
3094 if ((row_ptr->height() - h) > 0) {
3095 int const w = (inset_owner ?
3096 inset_owner->width(bview, font) : ww);
3097 pain.fillRectangle(x_offset, y_offset + h,
3098 w, row_ptr->height() - h);
3100 if (!inset_owner && !inset->display() && !inset->needFullRow())
3102 int const w = inset->width(bview, font) + int(x);
3103 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3108 int const w = (inset_owner ?
3109 inset_owner->width(bview, font) : ww);
3110 /* selection code */
3111 if (bidi_same_direction) {
3112 if (sel_start_cursor.row() == row_ptr &&
3113 sel_end_cursor.row() == row_ptr) {
3114 if (sel_start_cursor.x() < sel_end_cursor.x())
3115 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3117 sel_end_cursor.x() - sel_start_cursor.x(),
3121 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3123 sel_start_cursor.x() - sel_end_cursor.x(),
3126 } else if (sel_start_cursor.row() == row_ptr) {
3128 pain.fillRectangle(x_offset, y_offset,
3129 sel_start_cursor.x(),
3133 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3135 w - sel_start_cursor.x(),
3138 } else if (sel_end_cursor.row() == row_ptr) {
3140 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3142 w - sel_end_cursor.x(),
3146 pain.fillRectangle(x_offset, y_offset,
3150 } else if (y > sel_start_cursor.y()
3151 && y < sel_end_cursor.y()) {
3152 pain.fillRectangle(x_offset, y_offset, w,
3156 } else if (sel_start_cursor.row() != row_ptr &&
3157 sel_end_cursor.row() != row_ptr &&
3158 y > sel_start_cursor.y()
3159 && y < sel_end_cursor.y()) {
3160 pain.fillRectangle(x_offset, y_offset, w,
3163 } else if (sel_start_cursor.row() == row_ptr ||
3164 sel_end_cursor.row() == row_ptr) {
3166 if ((sel_start_cursor.row() != row_ptr && !is_rtl) ||
3167 (sel_end_cursor.row() != row_ptr && is_rtl))
3168 pain.fillRectangle(x_offset, y_offset,
3172 LyXParagraph::size_type main_body =
3173 BeginningOfMainBody(bview->buffer(),
3176 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3177 pos = vis2log(vpos);
3178 float const old_tmpx = tmpx;
3179 if (main_body > 0 && pos == main_body-1) {
3180 tmpx += fill_label_hfill +
3181 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3182 row_ptr->par()->GetLayout()).labelsep,
3183 GetFont(bview->buffer(),row_ptr->par(), -2));
3184 if (row_ptr->par()->IsLineSeparator(main_body-1))
3185 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3187 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3188 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3189 if (pos >= main_body)
3192 tmpx += fill_label_hfill;
3194 else if (row_ptr->par()->IsSeparator(pos)) {
3195 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3196 if (pos >= main_body)
3197 tmpx += fill_separator;
3199 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3201 if ((sel_start_cursor.row() != row_ptr ||
3202 sel_start_cursor.pos() <= pos) &&
3203 (sel_end_cursor.row() != row_ptr ||
3204 pos < sel_end_cursor.pos()) )
3205 pain.fillRectangle(x_offset + int(old_tmpx),
3207 int(tmpx - old_tmpx + 1),
3212 if ((sel_start_cursor.row() != row_ptr && is_rtl) ||
3213 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3214 pain.fillRectangle(x_offset + int(tmpx),
3224 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3225 LyXFont font(LyXFont::ALL_SANE);
3226 font.setSize(LyXFont::SIZE_FOOTNOTE);
3227 font.setColor(LColor::footnote);
3229 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3230 if (row_ptr->previous() &&
3231 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3233 switch (row_ptr->par()->footnotekind) {
3234 case LyXParagraph::MARGIN:
3237 case LyXParagraph::FIG:
3240 case LyXParagraph::TAB:
3243 case LyXParagraph::WIDE_FIG:
3246 case LyXParagraph::WIDE_TAB:
3249 case LyXParagraph::ALGORITHM:
3252 case LyXParagraph::FOOTNOTE:
3257 pain.fillRectangle(LYX_PAPER_MARGIN,
3259 box_x - LYX_PAPER_MARGIN,
3260 int(lyxfont::maxAscent(font)
3261 + lyxfont::maxDescent(font)),
3262 LColor::footnotebg);
3264 pain.line(LYX_PAPER_MARGIN, y_offset,
3265 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3266 LColor::footnoteframe);
3268 pain.text(LYX_PAPER_MARGIN,
3269 y_offset + int(lyxfont::maxAscent(font)) + 1,
3272 pain.line(LYX_PAPER_MARGIN, y_offset,
3274 y_offset + int(lyxfont::maxAscent(font)
3275 + lyxfont::maxDescent(font)),
3276 LColor::footnoteframe);
3278 pain.line(LYX_PAPER_MARGIN,
3279 y_offset + int(lyxfont::maxAscent(font)
3280 + lyxfont::maxDescent(font)) + 1,
3282 y_offset + int(lyxfont::maxAscent(font)
3283 + lyxfont::maxDescent(font)) + 1,
3284 LColor::footnoteframe);
3288 /* draw the open floats in a red box */
3289 pain.line(box_x, y_offset,
3290 box_x, y_offset + row_ptr->height(),
3291 LColor::footnoteframe);
3293 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
3295 workWidth(bview) - LYX_PAPER_MARGIN,
3296 y_offset + row_ptr->height(),
3297 LColor::footnoteframe);
3300 // Draw appendix lines
3301 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
3303 pain.line(1, y_offset,
3304 1, y_offset + row_ptr->height(),
3305 LColor::appendixline);
3306 pain.line(workWidth(bview) - 2, y_offset,
3307 workWidth(bview) - 2,
3308 y_offset + row_ptr->height(),
3309 LColor::appendixline);
3312 // Draw minipage line
3313 bool const minipage =
3314 (p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3316 pain.line(LYX_PAPER_MARGIN/5, y_offset,
3318 y_offset + row_ptr->height() - 1,
3319 LColor::minipageline);
3322 int const depth = p->GetDepth();
3323 for (int i = 1; i <= depth; ++i) {
3324 int const line_x = (LYX_PAPER_MARGIN / 5) *
3326 pain.line(line_x, y_offset, line_x,
3327 y_offset + row_ptr->height() - 1,
3330 } else if (row_ptr->previous() &&
3331 row_ptr->previous()->par()->footnoteflag
3332 == LyXParagraph::OPEN_FOOTNOTE) {
3333 LyXFont font(LyXFont::ALL_SANE);
3334 font.setSize(LyXFont::SIZE_FOOTNOTE);
3336 int const box_x = LYX_PAPER_MARGIN
3337 + lyxfont::width(" wide-tab ", font);
3339 pain.line(box_x, y_offset,
3340 workWidth(bview) - LYX_PAPER_MARGIN,
3341 y_offset, LColor::footnote);
3344 // Draw appendix lines
3346 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
3348 LyXParagraph * firstpar = row_ptr->par();
3350 if (firstpar->appendix){
3351 pain.line(1, y_offset,
3352 1, y_offset + row_ptr->height(),
3353 LColor::appendixline);
3354 pain.line(ww - 2, y_offset,
3355 ww - 2, y_offset + row_ptr->height(),
3356 LColor::appendixline);
3359 // Draw minipage line
3360 bool const minipage =
3361 (firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3363 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
3364 LYX_PAPER_MARGIN/5 + box_x,
3365 y_offset + row_ptr->height() - 1,
3366 LColor::minipageline);
3369 int const depth = firstpar->GetDepth();
3373 if (row_ptr->next())
3375 if (row_ptr->par()->footnoteflag ==
3376 row_ptr->next()->par()->footnoteflag)
3377 next_depth = row_ptr->next()->par()->GetDepth();
3378 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3381 next_depth = row_ptr->next()->par()->GetDepth();
3383 if (row_ptr->previous())
3385 if (row_ptr->par()->footnoteflag ==
3386 row_ptr->previous()->par()->footnoteflag)
3387 prev_depth = row_ptr->previous()->par()->GetDepth();
3388 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3391 prev_depth = row_ptr->previous()->par()->GetDepth();
3394 for (int i = 1; i <= depth; ++i) {
3395 int const line_x = (LYX_PAPER_MARGIN / 5) *
3396 (i + minipage) + box_x + x_offset;
3397 pain.line(line_x, y_offset, line_x,
3398 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
3402 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
3405 pain.fillRectangle(line_x,
3406 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
3407 LYX_PAPER_MARGIN / 5, 2,
3413 LyXLayout const & layout =
3414 textclasslist.Style(bview->buffer()->params.textclass,
3415 row_ptr->par()->GetLayout());
3418 y_bottom = row_ptr->height();
3420 /* is it a first row? */
3421 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
3423 /* start of appendix? */
3424 if (row_ptr->par()->start_of_appendix){
3425 pain.line(1, y_offset,
3427 LColor::appendixline);
3430 /* think about the margins */
3431 if (!row_ptr->previous() && bv_owner)
3432 y_top += LYX_PAPER_MARGIN;
3434 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
3436 pb_font.setColor(LColor::pagebreak).decSize();
3437 int w = 0, a = 0, d = 0;
3438 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
3440 y_offset + y_top + 2 * DefaultHeight(),
3442 Painter::line_onoffdash)
3445 _("Page Break (top)"),
3448 LColor::background, false, w, a, d);
3449 pain.rectText((ww - w)/2,
3450 y_offset + y_top + 2 * DefaultHeight() + d,
3451 _("Page Break (top)"),
3454 LColor::background);
3455 y_top += 3 * DefaultHeight();
3458 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
3459 /* draw a vfill top */
3460 pain.line(0, y_offset + 2 + y_top,
3461 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
3464 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
3466 y_offset + y_top + 3 * DefaultHeight(),
3469 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
3470 LYX_PAPER_MARGIN / 2,
3471 y_offset + y_top + 3 * DefaultHeight(),
3474 y_top += 3 * DefaultHeight();
3477 /* think about user added space */
3478 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
3480 /* think about the parskip */
3481 /* some parskips VERY EASY IMPLEMENTATION */
3482 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3483 if (layout.latextype == LATEX_PARAGRAPH
3484 && firstpar->GetDepth() == 0
3485 && firstpar->Previous())
3486 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3487 else if (firstpar->Previous()
3488 && textclasslist.Style(bview->buffer()->params.textclass,
3489 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3490 && firstpar->Previous()->GetDepth() == 0)
3491 // is it right to use defskip here, too? (AS)
3492 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3495 if (row_ptr->par()->line_top) { /* draw a top line */
3496 y_top += lyxfont::ascent('x',
3497 GetFont(bview->buffer(),
3498 row_ptr->par(), 0));
3499 int const w = (inset_owner ?
3500 inset_owner->width(bview, font) : ww);
3501 int const xp = static_cast<int>(inset_owner ? x : 0);
3502 pain.line(xp, y_offset + y_top,
3503 w, y_offset + y_top,
3505 Painter::line_solid,
3506 Painter::line_thick);
3508 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
3509 row_ptr->par(), 0));
3512 /* should we print a label? */
3513 if (layout.labeltype >= LABEL_STATIC
3514 && (layout.labeltype != LABEL_STATIC
3515 || layout.latextype != LATEX_ENVIRONMENT
3516 || row_ptr->par()->IsFirstInSequence())) {
3517 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3518 if (!row_ptr->par()->GetLabelstring().empty()) {
3520 string const tmpstring =
3521 row_ptr->par()->GetLabelstring();
3523 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3524 if (bview->buffer()->params.secnumdepth >= 0) {
3525 /* this is special code for the chapter layout. This is printed in
3526 * an extra row and has a pagebreak at the top. */
3527 float spacing_val = 1.0;
3528 if (!row_ptr->par()->spacing.isDefault()) {
3529 spacing_val = row_ptr->par()->spacing.getValue();
3531 spacing_val = bview->buffer()->params.spacing.getValue();
3534 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3535 + int(layout.parsep) * DefaultHeight();
3537 tmpx = ww - LeftMargin(bview, row_ptr) -
3538 lyxfont::width(tmpstring, font);
3539 pain.text(int(tmpx),
3540 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
3545 tmpx = ww - LeftMargin(bview, row_ptr)
3546 + lyxfont::width(layout.labelsep, font);
3548 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3549 LyXFont font(LyXFont::ALL_SANE);
3550 font.setSize(LyXFont::SIZE_SMALL);
3551 tmpx += lyxfont::width("Mwide-fixM", font);
3555 tmpx = x - lyxfont::width(layout.labelsep, font)
3556 - lyxfont::width(tmpstring, font);
3559 pain.text(int(tmpx),
3560 y_offset + row_ptr->baseline(),
3564 /* the labels at the top of an environment. More or less for bibliography */
3565 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3566 layout.labeltype == LABEL_BIBLIO ||
3567 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3568 if (row_ptr->par()->IsFirstInSequence()) {
3569 font = GetFont(bview->buffer(),
3570 row_ptr->par(), -2);
3571 if (!row_ptr->par()->GetLabelstring().empty()) {
3572 string const tmpstring =
3573 row_ptr->par()->GetLabelstring();
3574 float spacing_val = 1.0;
3575 if (!row_ptr->par()->spacing.isDefault()) {
3576 spacing_val = row_ptr->par()->spacing.getValue();
3578 spacing_val = bview->buffer()->params.spacing.getValue();
3581 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3582 + (layout.labelbottomsep * DefaultHeight()));
3585 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3586 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
3587 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
3588 tmpx -= lyxfont::width(tmpstring, font) / 2;
3590 tmpx = ww - LeftMargin(bview, row_ptr) -
3591 lyxfont::width(tmpstring, font);
3592 pain.text(int(tmpx),
3593 y_offset + row_ptr->baseline()
3594 - row_ptr->ascent_of_text()
3600 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
3601 font = GetFont(bview->buffer(), row_ptr->par(), -1);
3603 tmpx = ww - LeftMargin(bview, row_ptr)
3604 + lyxfont::width(layout.labelsep, font);
3606 tmpx = x - lyxfont::width(layout.labelsep, font)
3607 - row_ptr->par()->bibkey->width(bview, font);
3608 row_ptr->par()->bibkey->draw(bview, font,
3609 y_offset + row_ptr->baseline(),
3614 /* is it a last row? */
3616 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
3618 LyXParagraph * par = row_ptr->par();
3622 row_ptr->par()->ParFromPos(last + 1) == par
3624 row_ptr->par() == par
3626 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par()))
3628 /* think about the margins */
3629 if (!row_ptr->next() && bv_owner)
3630 y_bottom -= LYX_PAPER_MARGIN;
3632 /* draw a bottom pagebreak */
3633 if (firstpar->pagebreak_bottom) {
3635 pb_font.setColor(LColor::pagebreak).decSize();
3636 int w = 0, a = 0, d = 0;
3638 y_offset + y_bottom - 2 * DefaultHeight(),
3640 y_offset + y_bottom - 2 * DefaultHeight(),
3642 Painter::line_onoffdash)
3645 _("Page Break (bottom)"),
3648 LColor::background, false, w, a, d);
3649 pain.rectText((ww - w) / 2,
3650 y_offset + y_top + 2 * DefaultHeight() + d,
3651 _("Page Break (bottom)"),
3654 LColor::background);
3655 y_bottom -= 3 * DefaultHeight();
3658 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3659 /* draw a vfill bottom */
3660 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
3662 y_offset + y_bottom - 3 * DefaultHeight(),
3664 pain.line(0, y_offset + y_bottom - 2,
3666 y_offset + y_bottom - 2,
3668 pain.line(LYX_PAPER_MARGIN / 2,
3669 y_offset + y_bottom - 3 * DefaultHeight(),
3670 LYX_PAPER_MARGIN / 2,
3671 y_offset + y_bottom - 2,
3673 y_bottom -= 3 * DefaultHeight();
3676 /* think about user added space */
3677 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
3679 if (firstpar->line_bottom) {
3680 /* draw a bottom line */
3681 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3682 par, par->Last() - 1));
3683 int const w = (inset_owner ?
3684 inset_owner->width(bview, font) : ww);
3685 int const xp = static_cast<int>(inset_owner ? x : 0);
3686 pain.line(xp, y_offset + y_bottom,
3687 w, y_offset + y_bottom,
3688 LColor::topline, Painter::line_solid,
3689 Painter::line_thick);
3690 y_bottom -= lyxfont::ascent('x',
3691 GetFont(bview->buffer(),
3697 int const endlabel =
3698 row_ptr->par()->GetEndLabel(bview->buffer()->params);
3701 case END_LABEL_FILLED_BOX:
3703 LyXFont const font = GetFont(bview->buffer(),
3704 row_ptr->par(), last);
3705 int const size = int(0.75 * lyxfont::maxAscent(font));
3706 int const y = (y_offset + row_ptr->baseline()) - size;
3707 int x = is_rtl ? LYX_PAPER_MARGIN
3708 : ww - LYX_PAPER_MARGIN - size;
3710 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3712 LyXFont font(LyXFont::ALL_SANE);
3713 font.setSize(LyXFont::SIZE_SMALL);
3714 x += lyxfont::width("Mwide-figM", font);
3716 x -= LYX_PAPER_MARGIN/2;
3718 if (row_ptr->fill() <= size)
3719 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
3720 if (endlabel == END_LABEL_BOX) {
3721 pain.line(x, y, x, y + size,
3723 pain.line(x + size, y, x + size , y + size,
3725 pain.line(x, y, x + size, y,
3727 pain.line(x, y + size, x + size, y + size,
3730 pain.fillRectangle(x, y, size, size,
3734 case END_LABEL_STATIC:
3736 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
3737 string const tmpstring = textclasslist.
3738 Style(bview->buffer()->params.textclass,
3739 layout).endlabelstring();
3740 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3741 int const tmpx = is_rtl ?
3742 int(x) - lyxfont::width(tmpstring, font)
3743 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
3744 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
3747 case END_LABEL_NO_LABEL:
3752 /* draw the text in the pixmap */
3754 vpos = row_ptr->pos();
3756 LyXParagraph::size_type main_body =
3757 BeginningOfMainBody(bview->buffer(), row_ptr->par());
3758 if (main_body > 0 &&
3759 (main_body-1 > last ||
3760 !row_ptr->par()->IsLineSeparator(main_body - 1)))
3763 while (vpos <= last) {
3764 pos = vis2log(vpos);
3765 if (main_body > 0 && pos == main_body - 1) {
3766 x += fill_label_hfill
3767 + lyxfont::width(layout.labelsep,
3768 GetFont(bview->buffer(),
3769 row_ptr->par(), -2))
3770 - SingleWidth(bview,
3775 if (row_ptr->par() ->IsHfill(pos)) {
3778 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3780 y_offset + row_ptr->baseline(),
3783 if (HfillExpansion(bview->buffer(),
3785 if (pos >= main_body) {
3787 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3788 int(x + fill_hfill),
3789 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3791 Painter::line_onoffdash);
3795 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3796 int(x + fill_label_hfill),
3797 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3799 Painter::line_onoffdash);
3801 x += fill_label_hfill;
3804 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3806 y_offset + row_ptr->baseline(),
3811 } else if (row_ptr->par()->IsSeparator(pos)) {
3812 x += SingleWidth(bview,
3813 row_ptr->par(), pos);
3814 if (pos >= main_body)
3815 x += fill_separator;
3818 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
3823 int LyXText::DefaultHeight() const
3825 LyXFont font(LyXFont::ALL_SANE);
3826 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
3830 /* returns the column near the specified x-coordinate of the row
3831 * x is set to the real beginning of this column */
3832 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
3833 bool & boundary) const
3836 float fill_separator, fill_hfill, fill_label_hfill;
3838 PrepareToPrint(bview, row, tmpx, fill_separator,
3839 fill_hfill, fill_label_hfill);
3841 LyXParagraph::size_type vc = row->pos();
3842 LyXParagraph::size_type last = RowLastPrintable(row);
3843 LyXParagraph::size_type c = 0;
3844 LyXLayout const & layout =
3845 textclasslist.Style(bview->buffer()->params.textclass,
3846 row->par()->GetLayout());
3847 bool left_side = false;
3849 LyXParagraph::size_type
3850 main_body = BeginningOfMainBody(bview->buffer(), row->par());
3851 float last_tmpx = tmpx;
3853 if (main_body > 0 &&
3854 (main_body-1 > last ||
3855 !row->par()->IsLineSeparator(main_body - 1)))
3858 while (vc <= last && tmpx <= x) {
3861 if (main_body > 0 && c == main_body-1) {
3862 tmpx += fill_label_hfill +
3863 lyxfont::width(layout.labelsep,
3864 GetFont(bview->buffer(), row->par(), -2));
3865 if (row->par()->IsLineSeparator(main_body - 1))
3866 tmpx -= SingleWidth(bview, row->par(), main_body-1);
3869 if (HfillExpansion(bview->buffer(), row, c)) {
3870 x += SingleWidth(bview, row->par(), c);
3874 tmpx += fill_label_hfill;
3876 else if (row->par()->IsSeparator(c)) {
3877 tmpx += SingleWidth(bview, row->par(), c);
3879 tmpx+= fill_separator;
3881 tmpx += SingleWidth(bview, row->par(), c);
3885 if ((tmpx + last_tmpx) / 2 > x) {
3890 if (vc > last + 1) // This shouldn't happen.
3894 bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
3895 // some speedup if rtl_support=false
3896 && (!row->next() || row->next()->par() != row->par());
3897 bool const rtl = (lastrow)
3898 ? row->par()->isRightToLeftPar(bview->buffer()->params)
3899 : false; // If lastrow is false, we don't need to compute
3900 // the value of rtl.
3902 if (row->pos() > last) // Row is empty?
3905 ( ( rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
3906 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5) ))
3908 else if (vc == row->pos()) {
3910 if (bidi_level(c) % 2 == 1)
3913 c = vis2log(vc - 1);
3914 bool const rtl = (bidi_level(c) % 2 == 1);
3915 if (left_side == rtl) {
3917 boundary = IsBoundary(bview->buffer(), row->par(), c);
3921 if (row->pos() <= last && c > last
3922 && row->par()->IsNewline(last)) {
3923 if (bidi_level(last) % 2 == 0)
3924 tmpx -= SingleWidth(bview, row->par(), last);
3926 tmpx += SingleWidth(bview, row->par(), last);
3937 /* turn the selection into a new environment. If there is no selection,
3938 * create an empty environment */
3939 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
3940 LyXParagraph::footnote_kind kind)
3942 /* no footnoteenvironment in a footnoteenvironment */
3943 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3944 WriteAlert(_("Impossible operation"),
3945 _("You can't insert a float in a float!"),
3949 /* no marginpars in minipages */
3950 if (kind == LyXParagraph::MARGIN
3951 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3952 WriteAlert(_("Impossible operation"),
3953 _("You can't insert a marginpar in a minipage!"),
3958 /* this doesnt make sense, if there is no selection */
3959 bool dummy_selection = false;
3961 sel_start_cursor = cursor; /* dummy selection */
3962 sel_end_cursor = cursor;
3963 dummy_selection = true;
3966 LyXParagraph * tmppar;
3968 /* a test to make sure there is not already a footnote
3969 * in the selection. */
3971 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
3973 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
3974 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3975 tmppar = tmppar->next;
3977 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
3978 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3979 WriteAlert(_("Impossible operation"),
3980 _("Float would include float!"),
3985 /* ok we have a selection. This is always between sel_start_cursor
3986 * and sel_end cursor */
3988 SetUndo(bview->buffer(), Undo::FINISH,
3989 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
3990 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
3992 if (sel_end_cursor.pos() > 0
3993 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
3994 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
3995 /* please break before a space at the end */
3996 if (sel_start_cursor.par() == sel_end_cursor.par()
3997 && sel_start_cursor.pos() > sel_end_cursor.pos())
3998 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4000 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4002 sel_end_cursor.par(sel_end_cursor.par()->Next());
4003 sel_end_cursor.pos(0);
4005 // don't forget to insert a dummy layout paragraph if necessary
4006 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4007 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4008 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4009 sel_end_cursor.par(sel_end_cursor.par()->next);
4012 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4014 cursor = sel_end_cursor;
4016 /* please break behind a space, if there is one. The space should
4018 if (sel_start_cursor.pos() > 0
4019 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4020 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4021 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4022 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4025 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4026 sel_start_cursor.pos());
4027 tmppar = sel_start_cursor.par()->Next();
4029 if (dummy_selection) {
4031 if (kind == LyXParagraph::TAB
4032 || kind == LyXParagraph::FIG
4033 || kind == LyXParagraph::WIDE_TAB
4034 || kind == LyXParagraph::WIDE_FIG
4035 || kind == LyXParagraph::ALGORITHM) {
4036 pair<bool, LyXTextClass::size_type> lres =
4037 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4039 LyXTextClass::size_type lay;
4045 lay = 0; // use default layout "Standard" (0)
4047 tmppar->SetLayout(bview->buffer()->params, lay);
4050 if (sel_start_cursor.pos() > 0) {
4051 /* the footnote-environment should begin with a standard layout.
4052 * Imagine you insert a footnote within an enumeration, you
4053 * certainly do not want an enumerated footnote! */
4056 /* this is a exception the user would sometimes expect, I hope */
4057 sel_start_cursor.par()->Clear();
4061 while (tmppar != sel_end_cursor.par()) {
4062 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4063 tmppar->footnotekind = kind;
4064 tmppar = tmppar->Next();
4067 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4069 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4076 // returns pointer to a specified row
4077 Row * LyXText::GetRow(LyXParagraph * par,
4078 LyXParagraph::size_type pos, int & y) const
4083 Row * tmprow = firstrow;
4086 // find the first row of the specified paragraph
4087 while (tmprow->next() && tmprow->par() != par) {
4088 y += tmprow->height();
4089 tmprow = tmprow->next();
4092 // now find the wanted row
4093 while (tmprow->pos() < pos
4095 && tmprow->next()->par() == par
4096 && tmprow->next()->pos() <= pos) {
4097 y += tmprow->height();
4098 tmprow = tmprow->next();