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)
348 return false; // This is just for speedup
350 if (!bidi_InRange(pos - 1))
353 bool const rtl = bidi_level(pos - 1) % 2;
355 if (pos == par->Last())
356 rtl2 = par->isRightToLeftPar(buf->params);
357 else if (bidi_InRange(pos))
358 rtl2 = bidi_level(pos) % 2;
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();
372 if (pos == par->Last())
373 rtl2 = par->isRightToLeftPar(buf->params);
374 else if (bidi_InRange(pos))
375 rtl2 = bidi_level(pos) % 2;
380 void LyXText::draw(BufferView * bview, Row const * row,
381 LyXParagraph::size_type & vpos,
382 int offset, float & x, bool cleared)
384 Painter & pain = bview->painter();
386 LyXParagraph::size_type pos = vis2log(vpos);
387 char c = row->par()->GetChar(pos);
390 if (IsNewlineChar(c)) {
392 // Draw end-of-line marker
393 LyXFont const font = GetFont(bview->buffer(), row->par(), pos);
394 int const wid = lyxfont::width('n', font);
395 int const asc = lyxfont::maxAscent(font);
396 int const y = offset + row->baseline();
399 if (bidi_level(pos) % 2 == 0) {
400 xp[0] = int(x + wid * 0.375);
401 yp[0] = int(y - 0.875 * asc * 0.75);
404 yp[1] = int(y - 0.500 * asc * 0.75);
406 xp[2] = int(x + wid * 0.375);
407 yp[2] = int(y - 0.125 * asc * 0.75);
409 pain.lines(xp, yp, 3, LColor::eolmarker);
412 yp[0] = int(y - 0.500 * asc * 0.75);
414 xp[1] = int(x + wid);
415 yp[1] = int(y - 0.500 * asc * 0.75);
417 xp[2] = int(x + wid);
418 yp[2] = int(y - asc * 0.75);
420 pain.lines(xp, yp, 3, LColor::eolmarker);
422 xp[0] = int(x + wid * 0.625);
423 yp[0] = int(y - 0.875 * asc * 0.75);
425 xp[1] = int(x + wid);
426 yp[1] = int(y - 0.500 * asc * 0.75);
428 xp[2] = int(x + wid * 0.625);
429 yp[2] = int(y - 0.125 * asc * 0.75);
431 pain.lines(xp, yp, 3, LColor::eolmarker);
433 xp[0] = int(x + wid);
434 yp[0] = int(y - 0.500 * asc * 0.75);
437 yp[1] = int(y - 0.500 * asc * 0.75);
440 yp[2] = int(y - asc * 0.75);
442 pain.lines(xp, yp, 3, LColor::eolmarker);
448 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
449 LyXFont font2 = font;
451 if (c == LyXParagraph::META_FOOTNOTE
452 || c == LyXParagraph::META_MARGIN
453 || c == LyXParagraph::META_FIG
454 || c == LyXParagraph::META_TAB
455 || c == LyXParagraph::META_WIDE_FIG
456 || c == LyXParagraph::META_WIDE_TAB
457 || c == LyXParagraph::META_ALGORITHM) {
460 case LyXParagraph::META_MARGIN:
463 case LyXParagraph::META_FIG:
466 case LyXParagraph::META_TAB:
469 case LyXParagraph::META_ALGORITHM:
472 case LyXParagraph::META_WIDE_FIG:
475 case LyXParagraph::META_WIDE_TAB:
478 case LyXParagraph::META_FOOTNOTE:
485 // calculate the position of the footnotemark
486 int const y = (row->baseline() - lyxfont::maxAscent(font2)
487 + lyxfont::maxAscent(font));
489 font.setColor(LColor::footnote);
491 // draw it and set new x position
493 pain.text(int(x), offset + y, fs, font);
494 x += lyxfont::width(fs, font);
495 pain.line(int(tmpx), offset + row->baseline(),
496 int(x), offset + row->baseline(),
503 if (c == LyXParagraph::META_INSET) {
504 Inset * tmpinset = row->par()->GetInset(pos);
506 // tmpinset->update(bview, font, false);
507 tmpinset->draw(bview, font, offset+row->baseline(), x,
509 if (status == CHANGED_IN_DRAW) {
510 UpdateInset(bview, tmpinset);
511 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 (row->next() && row->next()->par() == row->par())
2117 need_break_row = row->next();
2122 refresh_x = cursor.x();
2124 refresh_pos = cursor.pos();
2126 int const tmpheight = row->height();
2127 SetHeightOfRow(bview, row);
2128 if (tmpheight == row->height())
2129 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2131 status = LyXText::NEED_MORE_REFRESH;
2133 current_font = rawtmpfont;
2134 real_current_font = realtmpfont;
2135 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2139 // check, wether the last characters font has changed.
2140 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2141 && rawparfont != rawtmpfont) {
2142 RedoHeightOfParagraph(bview, cursor);
2144 // now the special right address boxes
2145 if (textclasslist.Style(bview->buffer()->params.textclass,
2146 cursor.par()->GetLayout()).margintype
2147 == MARGIN_RIGHT_ADDRESS_BOX) {
2148 RedoDrawingOfParagraph(bview, cursor);
2156 void LyXText::charInserted()
2158 // Here we could call FinishUndo for every 20 characters inserted.
2159 // This is from my experience how emacs does it.
2160 static unsigned int counter = 0;
2170 void LyXText::PrepareToPrint(BufferView * bview,
2171 Row * row, float & x,
2172 float & fill_separator,
2174 float & fill_label_hfill,
2179 float w = row->fill();
2181 fill_label_hfill = 0;
2183 fill_label_hfill = 0;
2186 row->par()->isRightToLeftPar(bview->buffer()->params);
2190 x = RightMargin(bview->buffer(), row);
2191 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2192 LyXFont font(LyXFont::ALL_SANE);
2193 font.setSize(LyXFont::SIZE_SMALL);
2194 x += lyxfont::width("Mwide-figM", font);
2198 if (workWidth(bview) > 0)
2199 x = LeftMargin(bview, row);
2203 // is there a manual margin with a manual label
2204 if (textclasslist.Style(bview->buffer()->params.textclass,
2205 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2206 && textclasslist.Style(bview->buffer()->params.textclass,
2207 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2209 /* one more since labels are left aligned */
2210 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2211 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2212 fill_label_hfill = LabelFill(bview, row) / nlh;
2216 // are there any hfills in the row?
2217 float const nh = NumberOfHfills(bview->buffer(), row);
2220 fill_hfill = w / nh;
2222 // is it block, flushleft or flushright?
2223 // set x how you need it
2226 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2227 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2229 align = row->par()->FirstPhysicalPar()->align;
2231 if (row->par()->align == LYX_ALIGN_LAYOUT)
2232 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2234 align = row->par()->align;
2237 // center displayed insets
2239 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2240 && (inset=row->par()->GetInset(row->pos()))
2241 && (inset->display())) // || (inset->scroll() < 0)))
2242 align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
2243 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
2246 case LYX_ALIGN_BLOCK:
2247 ns = NumberOfSeparators(bview->buffer(), row);
2248 if (ns && row->next() && row->next()->par() == row->par() &&
2249 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2250 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2251 && row->next()->par()->GetInset(row->next()->pos())
2252 && row->next()->par()->GetInset(row->next()->pos())->display())
2254 fill_separator = w / ns;
2258 case LYX_ALIGN_RIGHT:
2261 case LYX_ALIGN_CENTER:
2269 ComputeBidiTables(bview->buffer(), row);
2271 LyXParagraph::size_type main_body =
2272 BeginningOfMainBody(bview->buffer(), row->par());
2273 LyXParagraph::size_type last = RowLast(row);
2275 if (main_body > 0 &&
2276 (main_body-1 > last ||
2277 !row->par()->IsLineSeparator(main_body-1))) {
2278 LyXLayout const & layout =
2279 textclasslist.Style(bview->buffer()->params.textclass,
2280 row->par()->GetLayout());
2281 x += lyxfont::width(layout.labelsep,
2282 GetFont(bview->buffer(), row->par(), -2));
2283 if (main_body-1 <= last)
2284 x += fill_label_hfill;
2289 /* important for the screen */
2292 /* the cursor set functions have a special mechanism. When they
2293 * realize, that you left an empty paragraph, they will delete it.
2294 * They also delete the corresponding row */
2296 void LyXText::CursorRightOneWord(BufferView * bview) const
2298 // treat floats, HFills and Insets as words
2299 LyXCursor tmpcursor = cursor;
2300 // CHECK See comment on top of text.C
2302 if (tmpcursor.pos() == tmpcursor.par()->Last()
2303 && tmpcursor.par()->Next()) {
2304 tmpcursor.par(tmpcursor.par()->Next());
2309 // Skip through initial nonword stuff.
2310 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2311 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2313 // printf("Current pos1 %d", tmpcursor.pos()) ;
2314 tmpcursor.pos(tmpcursor.pos() + 1);
2317 // Advance through word.
2318 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2319 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2321 // printf("Current pos2 %d", tmpcursor.pos()) ;
2322 tmpcursor.pos(tmpcursor.pos() + 1);
2326 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2330 void LyXText::CursorTab(BufferView * bview) const
2332 LyXCursor tmpcursor = cursor;
2333 while (tmpcursor.pos() < tmpcursor.par()->Last()
2334 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
2335 tmpcursor.pos(tmpcursor.pos() + 1);
2337 if (tmpcursor.pos() == tmpcursor.par()->Last()){
2338 if (tmpcursor.par()->Next()) {
2339 tmpcursor.par(tmpcursor.par()->Next());
2343 tmpcursor.pos(tmpcursor.pos() + 1);
2344 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2348 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2349 of prior word, not to end of next prior word. */
2351 void LyXText::CursorLeftOneWord(BufferView * bview) const
2353 // treat HFills, floats and Insets as words
2354 LyXCursor tmpcursor = cursor;
2355 while (tmpcursor.pos()
2356 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
2357 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
2358 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
2360 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2362 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
2363 tmpcursor.pos(tmpcursor.pos() - 1);
2366 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
2368 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2370 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
2371 tmpcursor.pos(tmpcursor.pos() - 1);
2372 } else if (!tmpcursor.pos()) {
2373 if (tmpcursor.par()->Previous()){
2374 tmpcursor.par(tmpcursor.par()->Previous());
2375 tmpcursor.pos(tmpcursor.par()->Last());
2377 } else { // Here, tmpcursor != 0
2378 while (tmpcursor.pos() > 0 &&
2379 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
2380 tmpcursor.pos(tmpcursor.pos() - 1);
2382 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2385 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2388 void LyXText::SelectWord(BufferView * bview)
2390 // Move cursor to the beginning, when not already there.
2392 && !cursor.par()->IsSeparator(cursor.pos()-1)
2393 && !cursor.par()->IsKomma(cursor.pos()-1) )
2394 CursorLeftOneWord(bview);
2396 // set the sel cursor
2397 sel_cursor = cursor;
2399 while (cursor.pos() < cursor.par()->Last()
2400 && !cursor.par()->IsSeparator(cursor.pos())
2401 && !cursor.par()->IsKomma(cursor.pos()) )
2402 cursor.pos(cursor.pos() + 1);
2403 SetCursor(bview, cursor.par(), cursor.pos() );
2405 // finally set the selection
2410 /* -------> Select the word currently under the cursor when:
2411 1: no selection is currently set,
2412 2: the cursor is not at the borders of the word. */
2414 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
2417 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
2418 && !cursor.par()->IsSeparator(cursor.pos())
2419 && !cursor.par()->IsKomma(cursor.pos())
2420 && !cursor.par()->IsSeparator(cursor.pos() -1)
2421 && !cursor.par()->IsKomma(cursor.pos() -1)) {
2429 // This function is only used by the spellchecker for NextWord().
2430 // It doesn't handle LYX_ACCENTs and probably never will.
2431 string const LyXText::SelectNextWord(BufferView * bview,
2432 float & value) const
2434 LyXParagraph * tmppar = cursor.par();
2436 // If this is not the very first word, skip rest of
2437 // current word because we are probably in the middle
2438 // of a word if there is text here.
2439 if (cursor.pos() || cursor.par()->previous) {
2440 while (cursor.pos() < cursor.par()->Last()
2441 && cursor.par()->IsLetter(cursor.pos()))
2442 cursor.pos(cursor.pos() + 1);
2444 // Now, skip until we have real text (will jump paragraphs)
2445 while ((cursor.par()->Last() > cursor.pos()
2446 && (!cursor.par()->IsLetter(cursor.pos())
2447 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
2448 .latex() == LyXFont::ON))
2449 || (cursor.par()->Last() == cursor.pos()
2450 && cursor.par()->Next())){
2451 if (cursor.pos() == cursor.par()->Last()) {
2452 cursor.par(cursor.par()->Next());
2455 cursor.pos(cursor.pos() + 1);
2458 // Update the value if we changed paragraphs
2459 if (cursor.par() != tmppar){
2460 SetCursor(bview, cursor.par(), cursor.pos());
2461 value = float(cursor.y())/float(height);
2464 // Start the selection from here
2465 sel_cursor = cursor;
2467 std::ostringstream latex;
2469 // and find the end of the word
2470 // (optional hyphens are part of a word)
2471 while (cursor.pos() < cursor.par()->Last()
2472 && (cursor.par()->IsLetter(cursor.pos()))
2473 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2474 && cursor.par()->GetInset(cursor.pos()) != 0
2475 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2476 && latex.str() == "\\-"
2478 cursor.pos(cursor.pos() + 1);
2480 // Finally, we copy the word to a string and return it
2482 if (sel_cursor.pos() < cursor.pos()) {
2483 LyXParagraph::size_type i;
2484 for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
2485 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
2486 str += cursor.par()->GetChar(i);
2493 // This one is also only for the spellchecker
2494 void LyXText::SelectSelectedWord(BufferView * bview)
2496 // move cursor to the beginning
2497 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
2499 // set the sel cursor
2500 sel_cursor = cursor;
2502 std::ostringstream latex;
2504 // now find the end of the word
2505 while (cursor.pos() < cursor.par()->Last()
2506 && (cursor.par()->IsLetter(cursor.pos())
2507 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2508 && cursor.par()->GetInset(cursor.pos()) != 0
2509 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2510 && latex.str() == "\\-"
2512 cursor.pos(cursor.pos() + 1);
2514 SetCursor(bview, cursor.par(), cursor.pos());
2516 // finally set the selection
2521 /* -------> Delete from cursor up to the end of the current or next word. */
2522 void LyXText::DeleteWordForward(BufferView * bview)
2524 if (!cursor.par()->Last())
2527 LyXCursor tmpcursor = cursor;
2528 tmpcursor.row(0); //Â ??
2529 selection = true; // to avoid deletion
2530 CursorRightOneWord(bview);
2531 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2532 sel_cursor = cursor;
2536 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2537 CutSelection(bview);
2542 /* -------> Delete from cursor to start of current or prior word. */
2543 void LyXText::DeleteWordBackward(BufferView * bview)
2545 if (!cursor.par()->Last())
2548 LyXCursor tmpcursor = cursor;
2549 tmpcursor.row(0); // ??
2550 selection = true; // to avoid deletion
2551 CursorLeftOneWord(bview);
2552 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2553 sel_cursor = cursor;
2556 CutSelection(bview);
2561 /* -------> Kill to end of line. */
2562 void LyXText::DeleteLineForward(BufferView * bview)
2564 if (!cursor.par()->Last())
2565 // Paragraph is empty, so we just go to the right
2568 LyXCursor tmpcursor = cursor;
2569 // We can't store the row over a regular SetCursor
2570 // so we set it to 0 and reset it afterwards.
2571 tmpcursor.row(0); //Â ??
2572 selection = true; // to avoid deletion
2574 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2575 sel_cursor = cursor;
2578 // What is this test for ??? (JMarc)
2580 DeleteWordForward(bview);
2582 CutSelection(bview);
2588 // Change the case of a word at cursor position.
2589 // This function directly manipulates LyXParagraph::text because there
2590 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2591 // that it is correct. I guess part of it should be moved to
2592 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2593 // it does not access outside of the allocated array as the older
2594 // version did. (JMarc)
2595 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
2598 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
2600 LyXParagraph * tmppar = cursor.par();
2603 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
2606 LyXParagraph::size_type tmppos =
2607 cursor.par()->PositionInParFromPos(cursor.pos());
2609 LyXParagraph::size_type tmppos = cursor.pos();
2611 while (tmppos < tmppar->size()) {
2612 unsigned char c = tmppar->GetChar(tmppos);
2613 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2615 if (c != LyXParagraph::META_INSET) {
2617 case text_lowercase:
2620 case text_capitalization:
2622 action = text_lowercase;
2624 case text_uppercase:
2630 //tmppar->text[tmppos] = c;
2631 tmppar->SetChar(tmppos, c);
2634 CheckParagraph(bview, tmppar, tmppos);
2635 CursorRightOneWord(bview);
2639 void LyXText::Delete(BufferView * bview)
2641 // this is a very easy implementation
2643 LyXCursor old_cursor = cursor;
2644 int const old_cur_par_id = old_cursor.par()->id();
2645 int const old_cur_par_prev_id = old_cursor.par()->previous ?
2646 old_cursor.par()->previous->id() : 0;
2648 // just move to the right
2651 // CHECK Look at the comment here.
2652 // This check is not very good...
2653 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2654 // and that can very well delete the par or par->previous in
2655 // old_cursor. Will a solution where we compare paragraph id's
2657 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
2658 == old_cur_par_prev_id
2659 && cursor.par()->id() != old_cur_par_id)
2660 return; // delete-empty-paragraph-mechanism has done it
2662 // if you had success make a backspace
2663 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2664 LyXCursor tmpcursor = cursor;
2665 cursor = old_cursor; // to make sure undo gets the right cursor position
2666 SetUndo(bview->buffer(), Undo::DELETE,
2668 cursor.par()->ParFromPos(cursor.pos())->previous,
2669 cursor.par()->ParFromPos(cursor.pos())->next
2671 cursor.par()->previous,
2681 void LyXText::Backspace(BufferView * bview)
2683 // Get the font that is used to calculate the baselineskip
2684 LyXParagraph::size_type lastpos = cursor.par()->Last();
2685 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2688 if (cursor.pos() == 0) {
2689 // The cursor is at the beginning of a paragraph,
2690 // so the the backspace will collapse two paragraphs into one.
2692 // we may paste some paragraphs
2694 // is it an empty paragraph?
2697 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
2699 && !(cursor.par()->Next()
2700 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
2701 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
2704 // This is an empty paragraph and we delete it just by moving the cursor one step
2705 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2706 // of the paragraph.
2708 if (cursor.par()->previous) {
2710 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
2712 LyXParagraph * tmppar = cursor.par()->previous;
2714 if (cursor.par()->GetLayout() == tmppar->GetLayout()
2716 && cursor.par()->footnoteflag == tmppar->footnoteflag
2718 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2719 // Inherit botom DTD from the paragraph below.
2720 // (the one we are deleting)
2721 tmppar->line_bottom = cursor.par()->line_bottom;
2722 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
2723 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
2728 // the layout things can change the height of a row !
2729 int const tmpheight = cursor.row()->height();
2730 SetHeightOfRow(bview, cursor.row());
2731 if (cursor.row()->height() != tmpheight) {
2732 refresh_y = cursor.y() - cursor.row()->baseline();
2733 refresh_row = cursor.row();
2734 status = LyXText::NEED_MORE_REFRESH;
2741 if (cursor.par()->ParFromPos(cursor.pos())->previous){
2742 SetUndo(bview->buffer(), Undo::DELETE,
2743 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
2744 cursor.par()->ParFromPos(cursor.pos())->next);
2747 if (cursor.par()->previous) {
2748 SetUndo(bview->buffer(), Undo::DELETE,
2749 cursor.par()->previous->previous,
2750 cursor.par()->next);
2754 LyXParagraph * tmppar = cursor.par();
2755 Row * tmprow = cursor.row();
2757 // We used to do CursorLeftIntern() here, but it is
2758 // not a good idea since it triggers the auto-delete
2759 // mechanism. So we do a CursorLeftIntern()-lite,
2760 // without the dreaded mechanism. (JMarc)
2761 if (cursor.par()->Previous()) {
2762 // steps into the above paragraph.
2763 SetCursorIntern(bview, cursor.par()->Previous(),
2764 cursor.par()->Previous()->Last(), false);
2767 /* Pasting is not allowed, if the paragraphs have different
2768 layout. I think it is a real bug of all other
2769 word processors to allow it. It confuses the user.
2770 Even so with a footnote paragraph and a non-footnote
2771 paragraph. I will not allow pasting in this case,
2772 because the user would be confused if the footnote behaves
2773 different wether it is open or closed.
2775 Correction: Pasting is always allowed with standard-layout
2777 if (cursor.par() != tmppar
2778 && (cursor.par()->GetLayout() == tmppar->GetLayout()
2779 || tmppar->GetLayout() == 0 /*standard*/)
2781 && cursor.par()->footnoteflag == tmppar->footnoteflag
2783 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2785 RemoveParagraph(tmprow);
2787 cursor.par()->PasteParagraph(bview->buffer()->params);
2789 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
2790 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
2791 // strangely enough it seems that commenting out the line above removes
2792 // most or all of the segfaults. I will however also try to move the
2793 // two Remove... lines in front of the PasteParagraph too.
2796 cursor.pos(cursor.pos() - 1);
2798 status = LyXText::NEED_MORE_REFRESH;
2799 refresh_row = cursor.row();
2800 refresh_y = cursor.y() - cursor.row()->baseline();
2802 // remove the lost paragraph
2803 // This one is not safe, since the paragraph that the tmprow and the
2804 // following rows belong to has been deleted by the PasteParagraph
2805 // above. The question is... could this be moved in front of the
2807 //RemoveParagraph(tmprow);
2808 //RemoveRow(tmprow);
2810 // This rebuilds the rows.
2811 AppendParagraph(bview, cursor.row());
2812 UpdateCounters(bview, cursor.row());
2814 // the row may have changed, block, hfills etc.
2815 SetCursor(bview, cursor.par(), cursor.pos(), false);
2818 /* this is the code for a normal backspace, not pasting
2820 SetUndo(bview->buffer(), Undo::DELETE,
2822 cursor.par()->ParFromPos(cursor.pos())->previous,
2823 cursor.par()->ParFromPos(cursor.pos())->next
2825 cursor.par()->previous,
2829 // We used to do CursorLeftIntern() here, but it is
2830 // not a good idea since it triggers the auto-delete
2831 // mechanism. So we do a CursorLeftIntern()-lite,
2832 // without the dreaded mechanism. (JMarc)
2833 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
2834 false, cursor.boundary());
2836 // some insets are undeletable here
2837 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2838 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2840 // force complete redo when erasing display insets
2841 // this is a cruel method but safe..... Matthias
2842 if (cursor.par()->GetInset(cursor.pos())->display() ||
2843 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
2844 cursor.par()->Erase(cursor.pos());
2845 RedoParagraph(bview);
2850 Row * row = cursor.row();
2851 int y = cursor.y() - row->baseline();
2852 LyXParagraph::size_type z;
2853 /* remember that a space at the end of a row doesnt count
2854 * when calculating the fill */
2855 if (cursor.pos() < RowLast(row) ||
2856 !cursor.par()->IsLineSeparator(cursor.pos())) {
2857 row->fill(row->fill() + SingleWidth(bview,
2862 /* some special code when deleting a newline. This is similar
2863 * to the behavior when pasting paragraphs */
2864 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
2865 cursor.par()->Erase(cursor.pos());
2866 // refresh the positions
2868 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2869 tmprow = tmprow->next();
2870 tmprow->pos(tmprow->pos() - 1);
2872 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
2873 cursor.pos(cursor.pos() - 1);
2875 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
2876 cursor.par()->InsertChar(cursor.pos(), ' ');
2877 // refresh the positions
2879 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2880 tmprow = tmprow->next();
2881 tmprow->pos(tmprow->pos() + 1);
2885 cursor.par()->Erase(cursor.pos());
2887 // refresh the positions
2889 while (tmprow->next()
2890 && tmprow->next()->par() == row->par()) {
2891 tmprow = tmprow->next();
2892 tmprow->pos(tmprow->pos() - 1);
2895 // delete newlines at the beginning of paragraphs
2896 while (cursor.par()->Last() &&
2897 cursor.par()->IsNewline(cursor.pos()) &&
2898 cursor.pos() == BeginningOfMainBody(bview->buffer(),
2900 cursor.par()->Erase(cursor.pos());
2901 // refresh the positions
2903 while (tmprow->next() &&
2904 tmprow->next()->par() == row->par()) {
2905 tmprow = tmprow->next();
2906 tmprow->pos(tmprow->pos() - 1);
2911 // is there a break one row above
2912 if (row->previous() && row->previous()->par() == row->par()) {
2913 z = NextBreakPoint(bview, row->previous(),
2915 if (z >= row->pos()) {
2918 Row * tmprow = row->previous();
2920 // maybe the current row is now empty
2921 if (row->pos() >= row->par()->Last()) {
2926 BreakAgainOneRow(bview, row);
2927 if (row->next() && row->next()->par() == row->par())
2928 need_break_row = row->next();
2933 // set the dimensions of the row above
2934 y -= tmprow->height();
2935 tmprow->fill(Fill(bview, tmprow,
2937 SetHeightOfRow(bview, tmprow);
2940 refresh_row = tmprow;
2941 status = LyXText::NEED_MORE_REFRESH;
2942 SetCursor(bview, cursor.par(), cursor.pos(),
2943 false, cursor.boundary());
2944 //current_font = rawtmpfont;
2945 //real_current_font = realtmpfont;
2946 // check, whether the last character's font has changed.
2948 cursor.par()->GetFontSettings(bview->buffer()->params,
2949 cursor.par()->Last() - 1))
2950 RedoHeightOfParagraph(bview, cursor);
2955 // break the cursor row again
2956 if (row->next() && row->next()->par() == row->par() &&
2957 (RowLast(row) == row->par()->Last() - 1 ||
2958 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
2960 /* it can happen that a paragraph loses one row
2961 * without a real breakup. This is when a word
2962 * is to long to be broken. Well, I don t care this
2964 if (RowLast(row) == row->par()->Last() - 1)
2965 RemoveRow(row->next());
2969 status = LyXText::NEED_MORE_REFRESH;
2971 BreakAgainOneRow(bview, row);
2972 // will the cursor be in another row now?
2973 if (row->next() && row->next()->par() == row->par() &&
2974 RowLast(row) <= cursor.pos()) {
2976 BreakAgainOneRow(bview, row);
2979 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2981 if (row->next() && row->next()->par() == row->par())
2982 need_break_row = row->next();
2986 // set the dimensions of the row
2987 row->fill(Fill(bview, row, workWidth(bview)));
2988 int const tmpheight = row->height();
2989 SetHeightOfRow(bview, row);
2990 if (tmpheight == row->height())
2991 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2993 status = LyXText::NEED_MORE_REFRESH;
2996 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3000 // current_font = rawtmpfont;
3001 // real_current_font = realtmpfont;
3003 lastpos = cursor.par()->Last();
3004 if (cursor.pos() == lastpos) {
3005 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3006 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3007 SetCurrentFont(bview);
3010 // check, wether the last characters font has changed.
3012 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3013 RedoHeightOfParagraph(bview, cursor);
3015 // now the special right address boxes
3016 if (textclasslist.Style(bview->buffer()->params.textclass,
3017 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3018 RedoDrawingOfParagraph(bview, cursor);
3024 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3025 Row * row_ptr, int y, bool cleared)
3027 /* returns a printed row */
3028 Painter & pain = bview->painter();
3031 row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3033 LyXParagraph::size_type const last = RowLastPrintable(row_ptr);
3035 LyXParagraph::size_type vpos, pos;
3041 LyXFont font(LyXFont::ALL_SANE);
3043 if (row_ptr->height() <= 0) {
3044 lyxerr << "LYX_ERROR: row.height: "
3045 << row_ptr->height() << endl;
3049 float fill_separator;
3051 float fill_label_hfill;
3052 PrepareToPrint(bview, row_ptr, x, fill_separator,
3053 fill_hfill, fill_label_hfill);
3055 if (inset_owner && (x < 0))
3059 // clear the area where we want to paint/print
3060 int ww = bview->workWidth();
3062 bool clear_area = true;
3065 if (!bview->screen()->forceClear() && last == row_ptr->pos()
3066 && row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET
3067 && (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
3068 clear_area = inset->doClearArea();
3070 // we don't need to clear it's already done!!!
3073 } else if (clear_area) {
3074 #ifdef WITH_WARNINGS
3075 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
3077 int const w = (inset_owner ?
3078 inset_owner->width(bview, font)-2 : ww);
3079 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3080 } else if (inset != 0) {
3081 int h = row_ptr->baseline() - inset->ascent(bview, font);
3083 int const w = (inset_owner ?
3084 inset_owner->width(bview, font) : ww);
3085 pain.fillRectangle(x_offset, y_offset, w, h);
3087 h += inset->ascent(bview, font) + inset->descent(bview, font);
3088 if ((row_ptr->height() - h) > 0) {
3089 int const w = (inset_owner ?
3090 inset_owner->width(bview, font) : ww);
3091 pain.fillRectangle(x_offset, y_offset + h,
3092 w, row_ptr->height() - h);
3094 if (!inset_owner && !inset->display() && !inset->needFullRow())
3096 int const w = inset->width(bview, font) + int(x);
3097 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3102 int const w = (inset_owner ?
3103 inset_owner->width(bview, font) : ww);
3104 /* selection code */
3105 if (bidi_same_direction) {
3106 if (sel_start_cursor.row() == row_ptr &&
3107 sel_end_cursor.row() == row_ptr) {
3108 if (sel_start_cursor.x() < sel_end_cursor.x())
3109 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3111 sel_end_cursor.x() - sel_start_cursor.x(),
3115 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3117 sel_start_cursor.x() - sel_end_cursor.x(),
3120 } else if (sel_start_cursor.row() == row_ptr) {
3122 pain.fillRectangle(x_offset, y_offset,
3123 sel_start_cursor.x(),
3127 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3129 w - sel_start_cursor.x(),
3132 } else if (sel_end_cursor.row() == row_ptr) {
3134 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3136 w - sel_end_cursor.x(),
3140 pain.fillRectangle(x_offset, y_offset,
3144 } else if (y > sel_start_cursor.y()
3145 && y < sel_end_cursor.y()) {
3146 pain.fillRectangle(x_offset, y_offset, w,
3150 } else if (sel_start_cursor.row() != row_ptr &&
3151 sel_end_cursor.row() != row_ptr &&
3152 y > sel_start_cursor.y()
3153 && y < sel_end_cursor.y()) {
3154 pain.fillRectangle(x_offset, y_offset, w,
3157 } else if (sel_start_cursor.row() == row_ptr ||
3158 sel_end_cursor.row() == row_ptr) {
3160 if ((sel_start_cursor.row() != row_ptr && !is_rtl) ||
3161 (sel_end_cursor.row() != row_ptr && is_rtl))
3162 pain.fillRectangle(x_offset, y_offset,
3166 LyXParagraph::size_type main_body =
3167 BeginningOfMainBody(bview->buffer(),
3170 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3171 pos = vis2log(vpos);
3172 float const old_tmpx = tmpx;
3173 if (main_body > 0 && pos == main_body-1) {
3174 tmpx += fill_label_hfill +
3175 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3176 row_ptr->par()->GetLayout()).labelsep,
3177 GetFont(bview->buffer(),row_ptr->par(), -2));
3178 if (row_ptr->par()->IsLineSeparator(main_body-1))
3179 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3181 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3182 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3183 if (pos >= main_body)
3186 tmpx += fill_label_hfill;
3188 else if (row_ptr->par()->IsSeparator(pos)) {
3189 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3190 if (pos >= main_body)
3191 tmpx += fill_separator;
3193 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3195 if ((sel_start_cursor.row() != row_ptr ||
3196 sel_start_cursor.pos() <= pos) &&
3197 (sel_end_cursor.row() != row_ptr ||
3198 pos < sel_end_cursor.pos()) )
3199 pain.fillRectangle(x_offset + int(old_tmpx),
3201 int(tmpx - old_tmpx + 1),
3206 if ((sel_start_cursor.row() != row_ptr && is_rtl) ||
3207 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3208 pain.fillRectangle(x_offset + int(tmpx),
3218 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3219 LyXFont font(LyXFont::ALL_SANE);
3220 font.setSize(LyXFont::SIZE_FOOTNOTE);
3221 font.setColor(LColor::footnote);
3223 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3224 if (row_ptr->previous() &&
3225 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3227 switch (row_ptr->par()->footnotekind) {
3228 case LyXParagraph::MARGIN:
3231 case LyXParagraph::FIG:
3234 case LyXParagraph::TAB:
3237 case LyXParagraph::WIDE_FIG:
3240 case LyXParagraph::WIDE_TAB:
3243 case LyXParagraph::ALGORITHM:
3246 case LyXParagraph::FOOTNOTE:
3251 pain.fillRectangle(LYX_PAPER_MARGIN,
3253 box_x - LYX_PAPER_MARGIN,
3254 int(lyxfont::maxAscent(font)
3255 + lyxfont::maxDescent(font)),
3256 LColor::footnotebg);
3258 pain.line(LYX_PAPER_MARGIN, y_offset,
3259 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3260 LColor::footnoteframe);
3262 pain.text(LYX_PAPER_MARGIN,
3263 y_offset + int(lyxfont::maxAscent(font)) + 1,
3266 pain.line(LYX_PAPER_MARGIN, y_offset,
3268 y_offset + int(lyxfont::maxAscent(font)
3269 + lyxfont::maxDescent(font)),
3270 LColor::footnoteframe);
3272 pain.line(LYX_PAPER_MARGIN,
3273 y_offset + int(lyxfont::maxAscent(font)
3274 + lyxfont::maxDescent(font)) + 1,
3276 y_offset + int(lyxfont::maxAscent(font)
3277 + lyxfont::maxDescent(font)) + 1,
3278 LColor::footnoteframe);
3282 /* draw the open floats in a red box */
3283 pain.line(box_x, y_offset,
3284 box_x, y_offset + row_ptr->height(),
3285 LColor::footnoteframe);
3287 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
3289 workWidth(bview) - LYX_PAPER_MARGIN,
3290 y_offset + row_ptr->height(),
3291 LColor::footnoteframe);
3294 // Draw appendix lines
3295 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
3297 pain.line(1, y_offset,
3298 1, y_offset + row_ptr->height(),
3299 LColor::appendixline);
3300 pain.line(workWidth(bview) - 2, y_offset,
3301 workWidth(bview) - 2,
3302 y_offset + row_ptr->height(),
3303 LColor::appendixline);
3306 // Draw minipage line
3307 bool const minipage =
3308 (p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3310 pain.line(LYX_PAPER_MARGIN/5, y_offset,
3312 y_offset + row_ptr->height() - 1,
3313 LColor::minipageline);
3316 int const depth = p->GetDepth();
3317 for (int i = 1; i <= depth; ++i) {
3318 int const line_x = (LYX_PAPER_MARGIN / 5) *
3320 pain.line(line_x, y_offset, line_x,
3321 y_offset + row_ptr->height() - 1,
3324 } else if (row_ptr->previous() &&
3325 row_ptr->previous()->par()->footnoteflag
3326 == LyXParagraph::OPEN_FOOTNOTE) {
3327 LyXFont font(LyXFont::ALL_SANE);
3328 font.setSize(LyXFont::SIZE_FOOTNOTE);
3330 int const box_x = LYX_PAPER_MARGIN
3331 + lyxfont::width(" wide-tab ", font);
3333 pain.line(box_x, y_offset,
3334 workWidth(bview) - LYX_PAPER_MARGIN,
3335 y_offset, LColor::footnote);
3338 // Draw appendix lines
3340 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
3342 LyXParagraph * firstpar = row_ptr->par();
3344 if (firstpar->appendix){
3345 pain.line(1, y_offset,
3346 1, y_offset + row_ptr->height(),
3347 LColor::appendixline);
3348 pain.line(ww - 2, y_offset,
3349 ww - 2, y_offset + row_ptr->height(),
3350 LColor::appendixline);
3353 // Draw minipage line
3354 bool const minipage =
3355 (firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3357 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
3358 LYX_PAPER_MARGIN/5 + box_x,
3359 y_offset + row_ptr->height() - 1,
3360 LColor::minipageline);
3363 int const depth = firstpar->GetDepth();
3367 if (row_ptr->next())
3369 if (row_ptr->par()->footnoteflag ==
3370 row_ptr->next()->par()->footnoteflag)
3371 next_depth = row_ptr->next()->par()->GetDepth();
3372 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3375 next_depth = row_ptr->next()->par()->GetDepth();
3377 if (row_ptr->previous())
3379 if (row_ptr->par()->footnoteflag ==
3380 row_ptr->previous()->par()->footnoteflag)
3381 prev_depth = row_ptr->previous()->par()->GetDepth();
3382 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3385 prev_depth = row_ptr->previous()->par()->GetDepth();
3388 for (int i = 1; i <= depth; ++i) {
3389 int const line_x = (LYX_PAPER_MARGIN / 5) *
3390 (i + minipage) + box_x;
3391 pain.line(line_x, y_offset, line_x,
3392 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
3396 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
3399 pain.fillRectangle(line_x,
3400 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
3401 LYX_PAPER_MARGIN / 5, 2,
3407 LyXLayout const & layout =
3408 textclasslist.Style(bview->buffer()->params.textclass,
3409 row_ptr->par()->GetLayout());
3412 y_bottom = row_ptr->height();
3414 /* is it a first row? */
3415 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
3417 /* start of appendix? */
3418 if (row_ptr->par()->start_of_appendix){
3419 pain.line(1, y_offset,
3421 LColor::appendixline);
3424 /* think about the margins */
3425 if (!row_ptr->previous() && bv_owner)
3426 y_top += LYX_PAPER_MARGIN;
3428 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
3430 pb_font.setColor(LColor::pagebreak).decSize();
3431 int w = 0, a = 0, d = 0;
3432 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
3434 y_offset + y_top + 2 * DefaultHeight(),
3436 Painter::line_onoffdash)
3439 _("Page Break (top)"),
3442 LColor::background, false, w, a, d);
3443 pain.rectText((ww - w)/2,
3444 y_offset + y_top + 2 * DefaultHeight() + d,
3445 _("Page Break (top)"),
3448 LColor::background);
3449 y_top += 3 * DefaultHeight();
3452 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
3453 /* draw a vfill top */
3454 pain.line(0, y_offset + 2 + y_top,
3455 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
3458 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
3460 y_offset + y_top + 3 * DefaultHeight(),
3463 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
3464 LYX_PAPER_MARGIN / 2,
3465 y_offset + y_top + 3 * DefaultHeight(),
3468 y_top += 3 * DefaultHeight();
3471 /* think about user added space */
3472 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
3474 /* think about the parskip */
3475 /* some parskips VERY EASY IMPLEMENTATION */
3476 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3477 if (layout.latextype == LATEX_PARAGRAPH
3478 && firstpar->GetDepth() == 0
3479 && firstpar->Previous())
3480 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3481 else if (firstpar->Previous()
3482 && textclasslist.Style(bview->buffer()->params.textclass,
3483 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3484 && firstpar->Previous()->GetDepth() == 0)
3485 // is it right to use defskip here, too? (AS)
3486 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3489 if (row_ptr->par()->line_top) { /* draw a top line */
3490 y_top += lyxfont::ascent('x',
3491 GetFont(bview->buffer(),
3492 row_ptr->par(), 0));
3493 int const w = (inset_owner ?
3494 inset_owner->width(bview, font) : ww);
3495 int const xp = static_cast<int>(inset_owner ? x : 0);
3496 pain.line(xp, y_offset + y_top,
3497 w, y_offset + y_top,
3499 Painter::line_solid,
3500 Painter::line_thick);
3502 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
3503 row_ptr->par(), 0));
3506 /* should we print a label? */
3507 if (layout.labeltype >= LABEL_STATIC
3508 && (layout.labeltype != LABEL_STATIC
3509 || layout.latextype != LATEX_ENVIRONMENT
3510 || row_ptr->par()->IsFirstInSequence())) {
3511 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3512 if (!row_ptr->par()->GetLabelstring().empty()) {
3514 string const tmpstring =
3515 row_ptr->par()->GetLabelstring();
3517 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3518 if (bview->buffer()->params.secnumdepth >= 0) {
3519 /* this is special code for the chapter layout. This is printed in
3520 * an extra row and has a pagebreak at the top. */
3521 float spacing_val = 1.0;
3522 if (!row_ptr->par()->spacing.isDefault()) {
3523 spacing_val = row_ptr->par()->spacing.getValue();
3525 spacing_val = bview->buffer()->params.spacing.getValue();
3528 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3529 + int(layout.parsep) * DefaultHeight();
3531 tmpx = ww - LeftMargin(bview, row_ptr) -
3532 lyxfont::width(tmpstring, font);
3533 pain.text(int(tmpx),
3534 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
3539 tmpx = ww - LeftMargin(bview, row_ptr)
3540 + lyxfont::width(layout.labelsep, font);
3542 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3543 LyXFont font(LyXFont::ALL_SANE);
3544 font.setSize(LyXFont::SIZE_SMALL);
3545 tmpx += lyxfont::width("Mwide-fixM", font);
3549 tmpx = x - lyxfont::width(layout.labelsep, font)
3550 - lyxfont::width(tmpstring, font);
3553 pain.text(int(tmpx),
3554 y_offset + row_ptr->baseline(),
3558 /* the labels at the top of an environment. More or less for bibliography */
3559 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3560 layout.labeltype == LABEL_BIBLIO ||
3561 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3562 if (row_ptr->par()->IsFirstInSequence()) {
3563 font = GetFont(bview->buffer(),
3564 row_ptr->par(), -2);
3565 if (!row_ptr->par()->GetLabelstring().empty()) {
3566 string const tmpstring =
3567 row_ptr->par()->GetLabelstring();
3568 float spacing_val = 1.0;
3569 if (!row_ptr->par()->spacing.isDefault()) {
3570 spacing_val = row_ptr->par()->spacing.getValue();
3572 spacing_val = bview->buffer()->params.spacing.getValue();
3575 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3576 + (layout.labelbottomsep * DefaultHeight()));
3579 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3580 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
3581 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
3582 tmpx -= lyxfont::width(tmpstring, font) / 2;
3584 tmpx = ww - LeftMargin(bview, row_ptr) -
3585 lyxfont::width(tmpstring, font);
3586 pain.text(int(tmpx),
3587 y_offset + row_ptr->baseline()
3588 - row_ptr->ascent_of_text()
3594 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
3595 font = GetFont(bview->buffer(), row_ptr->par(), -1);
3597 tmpx = ww - LeftMargin(bview, row_ptr)
3598 + lyxfont::width(layout.labelsep, font);
3600 tmpx = x - lyxfont::width(layout.labelsep, font)
3601 - row_ptr->par()->bibkey->width(bview, font);
3602 row_ptr->par()->bibkey->draw(bview, font,
3603 y_offset + row_ptr->baseline(),
3608 /* is it a last row? */
3610 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
3612 LyXParagraph * par = row_ptr->par();
3616 row_ptr->par()->ParFromPos(last + 1) == par
3618 row_ptr->par() == par
3620 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par()))
3622 /* think about the margins */
3623 if (!row_ptr->next() && bv_owner)
3624 y_bottom -= LYX_PAPER_MARGIN;
3626 /* draw a bottom pagebreak */
3627 if (firstpar->pagebreak_bottom) {
3629 pb_font.setColor(LColor::pagebreak).decSize();
3630 int w = 0, a = 0, d = 0;
3632 y_offset + y_bottom - 2 * DefaultHeight(),
3634 y_offset + y_bottom - 2 * DefaultHeight(),
3636 Painter::line_onoffdash)
3639 _("Page Break (bottom)"),
3642 LColor::background, false, w, a, d);
3643 pain.rectText((ww - w) / 2,
3644 y_offset + y_top + 2 * DefaultHeight() + d,
3645 _("Page Break (bottom)"),
3648 LColor::background);
3649 y_bottom -= 3 * DefaultHeight();
3652 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3653 /* draw a vfill bottom */
3654 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
3656 y_offset + y_bottom - 3 * DefaultHeight(),
3658 pain.line(0, y_offset + y_bottom - 2,
3660 y_offset + y_bottom - 2,
3662 pain.line(LYX_PAPER_MARGIN / 2,
3663 y_offset + y_bottom - 3 * DefaultHeight(),
3664 LYX_PAPER_MARGIN / 2,
3665 y_offset + y_bottom - 2,
3667 y_bottom -= 3 * DefaultHeight();
3670 /* think about user added space */
3671 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
3673 if (firstpar->line_bottom) {
3674 /* draw a bottom line */
3675 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3676 par, par->Last() - 1));
3677 int const w = (inset_owner ?
3678 inset_owner->width(bview, font) : ww);
3679 int const xp = static_cast<int>(inset_owner ? x : 0);
3680 pain.line(xp, y_offset + y_bottom,
3681 w, y_offset + y_bottom,
3682 LColor::topline, Painter::line_solid,
3683 Painter::line_thick);
3684 y_bottom -= lyxfont::ascent('x',
3685 GetFont(bview->buffer(),
3691 int const endlabel =
3692 row_ptr->par()->GetEndLabel(bview->buffer()->params);
3695 case END_LABEL_FILLED_BOX:
3697 LyXFont const font = GetFont(bview->buffer(),
3698 row_ptr->par(), last);
3699 int const size = int(0.75 * lyxfont::maxAscent(font));
3700 int const y = (y_offset + row_ptr->baseline()) - size;
3701 int x = is_rtl ? LYX_PAPER_MARGIN
3702 : ww - LYX_PAPER_MARGIN - size;
3704 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3706 LyXFont font(LyXFont::ALL_SANE);
3707 font.setSize(LyXFont::SIZE_SMALL);
3708 x += lyxfont::width("Mwide-figM", font);
3710 x -= LYX_PAPER_MARGIN/2;
3712 if (row_ptr->fill() <= size)
3713 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
3714 if (endlabel == END_LABEL_BOX) {
3715 pain.line(x, y, x, y + size,
3717 pain.line(x + size, y, x + size , y + size,
3719 pain.line(x, y, x + size, y,
3721 pain.line(x, y + size, x + size, y + size,
3724 pain.fillRectangle(x, y, size, size,
3728 case END_LABEL_STATIC:
3730 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
3731 string const tmpstring = textclasslist.
3732 Style(bview->buffer()->params.textclass,
3733 layout).endlabelstring();
3734 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3735 int const tmpx = is_rtl ?
3736 int(x) - lyxfont::width(tmpstring, font)
3737 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
3738 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
3741 case END_LABEL_NO_LABEL:
3746 /* draw the text in the pixmap */
3748 vpos = row_ptr->pos();
3750 LyXParagraph::size_type main_body =
3751 BeginningOfMainBody(bview->buffer(), row_ptr->par());
3752 if (main_body > 0 &&
3753 (main_body-1 > last ||
3754 !row_ptr->par()->IsLineSeparator(main_body - 1)))
3757 while (vpos <= last) {
3758 pos = vis2log(vpos);
3759 if (main_body > 0 && pos == main_body - 1) {
3760 x += fill_label_hfill
3761 + lyxfont::width(layout.labelsep,
3762 GetFont(bview->buffer(),
3763 row_ptr->par(), -2))
3764 - SingleWidth(bview,
3769 if (row_ptr->par() ->IsHfill(pos)) {
3772 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3774 y_offset + row_ptr->baseline(),
3777 if (HfillExpansion(bview->buffer(),
3779 if (pos >= main_body) {
3781 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3782 int(x + fill_hfill),
3783 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3785 Painter::line_onoffdash);
3789 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3790 int(x + fill_label_hfill),
3791 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3793 Painter::line_onoffdash);
3795 x += fill_label_hfill;
3798 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3800 y_offset + row_ptr->baseline(),
3805 } else if (row_ptr->par()->IsSeparator(pos)) {
3806 x += SingleWidth(bview,
3807 row_ptr->par(), pos);
3808 if (pos >= main_body)
3809 x += fill_separator;
3812 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
3817 int LyXText::DefaultHeight() const
3819 LyXFont font(LyXFont::ALL_SANE);
3820 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
3824 /* returns the column near the specified x-coordinate of the row
3825 * x is set to the real beginning of this column */
3826 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
3827 bool & boundary) const
3830 float fill_separator, fill_hfill, fill_label_hfill;
3832 PrepareToPrint(bview, row, tmpx, fill_separator,
3833 fill_hfill, fill_label_hfill);
3835 LyXParagraph::size_type vc = row->pos();
3836 LyXParagraph::size_type last = RowLastPrintable(row);
3837 LyXParagraph::size_type c = 0;
3838 LyXLayout const & layout =
3839 textclasslist.Style(bview->buffer()->params.textclass,
3840 row->par()->GetLayout());
3841 bool left_side = false;
3843 LyXParagraph::size_type
3844 main_body = BeginningOfMainBody(bview->buffer(), row->par());
3845 float last_tmpx = tmpx;
3847 if (main_body > 0 &&
3848 (main_body-1 > last ||
3849 !row->par()->IsLineSeparator(main_body - 1)))
3852 while (vc <= last && tmpx <= x) {
3855 if (main_body > 0 && c == main_body-1) {
3856 tmpx += fill_label_hfill +
3857 lyxfont::width(layout.labelsep,
3858 GetFont(bview->buffer(), row->par(), -2));
3859 if (row->par()->IsLineSeparator(main_body - 1))
3860 tmpx -= SingleWidth(bview, row->par(), main_body-1);
3863 if (HfillExpansion(bview->buffer(), row, c)) {
3864 x += SingleWidth(bview, row->par(), c);
3868 tmpx += fill_label_hfill;
3870 else if (row->par()->IsSeparator(c)) {
3871 tmpx += SingleWidth(bview, row->par(), c);
3873 tmpx+= fill_separator;
3875 tmpx += SingleWidth(bview, row->par(), c);
3879 if ((tmpx + last_tmpx) / 2 > x) {
3884 if (vc > last + 1) // This shouldn't happen.
3888 bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
3889 // some speedup if rtl_support=false
3890 && (!row->next() || row->next()->par() != row->par());
3891 bool const rtl = (lastrow)
3892 ? row->par()->isRightToLeftPar(bview->buffer()->params)
3893 : false; // If lastrow is false, we don't need to compute
3894 // the value of rtl.
3896 if (row->pos() > last) // Row is empty?
3899 ( ( rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
3900 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5) ))
3902 else if (vc == row->pos()) {
3904 if (bidi_level(c) % 2 == 1)
3907 c = vis2log(vc - 1);
3908 bool const rtl = (bidi_level(c) % 2 == 1);
3909 if (left_side == rtl) {
3911 boundary = IsBoundary(bview->buffer(), row->par(), c);
3915 if (row->pos() <= last && c > last
3916 && row->par()->IsNewline(last)) {
3917 if (bidi_level(last) % 2 == 0)
3918 tmpx -= SingleWidth(bview, row->par(), last);
3920 tmpx += SingleWidth(bview, row->par(), last);
3931 /* turn the selection into a new environment. If there is no selection,
3932 * create an empty environment */
3933 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
3934 LyXParagraph::footnote_kind kind)
3936 /* no footnoteenvironment in a footnoteenvironment */
3937 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3938 WriteAlert(_("Impossible operation"),
3939 _("You can't insert a float in a float!"),
3943 /* no marginpars in minipages */
3944 if (kind == LyXParagraph::MARGIN
3945 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3946 WriteAlert(_("Impossible operation"),
3947 _("You can't insert a marginpar in a minipage!"),
3952 /* this doesnt make sense, if there is no selection */
3953 bool dummy_selection = false;
3955 sel_start_cursor = cursor; /* dummy selection */
3956 sel_end_cursor = cursor;
3957 dummy_selection = true;
3960 LyXParagraph * tmppar;
3962 /* a test to make sure there is not already a footnote
3963 * in the selection. */
3965 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
3967 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
3968 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3969 tmppar = tmppar->next;
3971 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
3972 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3973 WriteAlert(_("Impossible operation"),
3974 _("Float would include float!"),
3979 /* ok we have a selection. This is always between sel_start_cursor
3980 * and sel_end cursor */
3982 SetUndo(bview->buffer(), Undo::FINISH,
3983 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
3984 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
3986 if (sel_end_cursor.pos() > 0
3987 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
3988 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
3989 /* please break before a space at the end */
3990 if (sel_start_cursor.par() == sel_end_cursor.par()
3991 && sel_start_cursor.pos() > sel_end_cursor.pos())
3992 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
3994 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
3996 sel_end_cursor.par(sel_end_cursor.par()->Next());
3997 sel_end_cursor.pos(0);
3999 // don't forget to insert a dummy layout paragraph if necessary
4000 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4001 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4002 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4003 sel_end_cursor.par(sel_end_cursor.par()->next);
4006 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4008 cursor = sel_end_cursor;
4010 /* please break behind a space, if there is one. The space should
4012 if (sel_start_cursor.pos() > 0
4013 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4014 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4015 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4016 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4019 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4020 sel_start_cursor.pos());
4021 tmppar = sel_start_cursor.par()->Next();
4023 if (dummy_selection) {
4025 if (kind == LyXParagraph::TAB
4026 || kind == LyXParagraph::FIG
4027 || kind == LyXParagraph::WIDE_TAB
4028 || kind == LyXParagraph::WIDE_FIG
4029 || kind == LyXParagraph::ALGORITHM) {
4030 pair<bool, LyXTextClass::size_type> lres =
4031 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4033 LyXTextClass::size_type lay;
4039 lay = 0; // use default layout "Standard" (0)
4041 tmppar->SetLayout(bview->buffer()->params, lay);
4044 if (sel_start_cursor.pos() > 0) {
4045 /* the footnote-environment should begin with a standard layout.
4046 * Imagine you insert a footnote within an enumeration, you
4047 * certainly do not want an enumerated footnote! */
4050 /* this is a exception the user would sometimes expect, I hope */
4051 sel_start_cursor.par()->Clear();
4055 while (tmppar != sel_end_cursor.par()) {
4056 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4057 tmppar->footnotekind = kind;
4058 tmppar = tmppar->Next();
4061 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4063 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4070 // returns pointer to a specified row
4071 Row * LyXText::GetRow(LyXParagraph * par,
4072 LyXParagraph::size_type pos, int & y) const
4077 Row * tmprow = firstrow;
4080 // find the first row of the specified paragraph
4081 while (tmprow->next() && tmprow->par() != par) {
4082 y += tmprow->height();
4083 tmprow = tmprow->next();
4086 // now find the wanted row
4087 while (tmprow->pos() < pos
4089 && tmprow->next()->par() == par
4090 && tmprow->next()->pos() <= pos) {
4091 y += tmprow->height();
4092 tmprow = tmprow->next();