1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #include "lyxparagraph.h"
19 #include "support/textutils.h"
20 #include "insets/insetbib.h"
21 #include "insets/insettext.h"
22 #include "lyx_gui_misc.h"
24 #include "bufferparams.h"
26 #include "minibuffer.h"
35 #include "lyxscreen.h"
36 #include "bufferview_funcs.h"
43 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
48 int LyXText::workWidth(BufferView * bview) const
51 return inset_owner->textWidth(bview->painter());
53 return bview->workWidth();
57 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
58 LyXParagraph::size_type pos) const
60 if (!Encodings::is_arabic(c))
61 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
62 return c + (0xb0 - '0');
66 unsigned char const prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
67 unsigned char next_char = ' ';
68 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
69 if (!Encodings::IsComposeChar_arabic(par->GetChar(i))) {
70 next_char = par->GetChar(i);
74 if (Encodings::is_arabic(next_char)) {
75 if (Encodings::is_arabic(prev_char))
76 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
78 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
80 if (Encodings::is_arabic(prev_char))
81 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
83 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
87 // This is the comments that some of the warnings below refers to.
88 // There are some issues in this file and I don't think they are
89 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
90 // this is a problem that has been here almost from day one and that a
91 // larger userbase with differenct access patters triggers the bad
92 // behaviour. (segfaults.) What I think happen is: In several places
93 // we store the paragraph in the current cursor and then moves the
94 // cursor. This movement of the cursor will delete paragraph at the
95 // old position if it is now empty. This will make the temporary
96 // pointer to the old cursor paragraph invalid and dangerous to use.
97 // And is some cases this will trigger a segfault. I have marked some
98 // of the cases where this happens with a warning, but I am sure there
99 // are others in this file and in text2.C. There is also a note in
100 // Delete() that you should read. In Delete I store the paragraph->id
101 // instead of a pointer to the paragraph. I am pretty sure this faulty
102 // use of temporary pointers to paragraphs that might have gotten
103 // invalidated (through a cursor movement) before they are used, are
104 // the cause of the strange crashes we get reported often.
106 // It is very tiresom to change this code, especially when it is as
107 // hard to read as it is. Help to fix all the cases where this is done
108 // would be greately appreciated.
112 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
113 LyXParagraph::size_type pos) const
115 char const c = par->GetChar(pos);
116 return SingleWidth(bview, par, pos, c);
120 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
121 LyXParagraph::size_type pos, char c) const
123 LyXFont font = GetFont(bview->buffer(), par, pos);
125 // The most common case is handled first (Asger)
126 if (IsPrintable(c)) {
127 if (font.language()->RightToLeft()) {
128 if (font.language()->lang() == "arabic" &&
129 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
130 lyxrc.font_norm_type == LyXRC::ISO_10646_1))
131 if (Encodings::IsComposeChar_arabic(c))
134 c = TransformChar(c, par, pos);
135 else if (font.language()->lang() == "hebrew" &&
136 Encodings::IsComposeChar_hebrew(c))
139 return lyxfont::width(c, font);
141 } else if (IsHfillChar(c)) {
142 return 3; /* Because of the representation
143 * as vertical lines */
145 } else if (c == LyXParagraph::META_FOOTNOTE ||
146 c == LyXParagraph::META_MARGIN ||
147 c == LyXParagraph::META_FIG ||
148 c == LyXParagraph::META_TAB ||
149 c == LyXParagraph::META_WIDE_FIG ||
150 c == LyXParagraph::META_WIDE_TAB ||
151 c == LyXParagraph::META_ALGORITHM) {
154 case LyXParagraph::META_MARGIN:
157 case LyXParagraph::META_FIG:
160 case LyXParagraph::META_TAB:
163 case LyXParagraph::META_ALGORITHM:
166 case LyXParagraph::META_WIDE_FIG:
169 case LyXParagraph::META_WIDE_TAB:
172 case LyXParagraph::META_FOOTNOTE:
178 return lyxfont::width(fs, font);
180 } else if (c == LyXParagraph::META_INSET) {
181 Inset * tmpinset = par->GetInset(pos);
183 tmpinset->update(bview, font);
184 return tmpinset->width(bview, font);
188 } else if (IsSeparatorChar(c))
190 else if (IsNewlineChar(c))
192 return lyxfont::width(c, font);
196 // Returns the paragraph position of the last character in the specified row
197 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
199 if (row->next() == 0)
200 return row->par()->Last() - 1;
201 else if (row->next()->par() != row->par())
202 return row->par()->Last() - 1;
204 return row->next()->pos() - 1;
208 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
210 LyXParagraph::size_type const last = RowLast(row);
211 if (last >= row->pos()
213 && row->next()->par() == row->par()
214 && row->par()->IsSeparator(last))
221 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
223 bidi_same_direction = true;
224 if (!lyxrc.rtl_support) {
229 bidi_start = row->pos();
230 bidi_end = RowLastPrintable(row);
232 if (bidi_start > bidi_end) {
237 if (bidi_end + 2 - bidi_start >
238 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
239 LyXParagraph::size_type new_size =
240 (bidi_end + 2 - bidi_start < 500) ?
241 500 : 2 * (bidi_end + 2 - bidi_start);
242 log2vis_list.resize(new_size);
243 vis2log_list.resize(new_size);
244 bidi_levels.resize(new_size);
247 vis2log_list[bidi_end + 1 - bidi_start] = -1;
248 log2vis_list[bidi_end + 1 - bidi_start] = -1;
250 LyXParagraph::size_type stack[2];
252 row->par()->getParLanguage(buf->params)->RightToLeft();
256 LyXParagraph::size_type const main_body =
257 BeginningOfMainBody(buf, row->par());
259 for (LyXParagraph::size_type lpos = bidi_start;
260 lpos <= bidi_end; ++lpos) {
261 bool is_space = row->par()->IsLineSeparator(lpos);
262 LyXParagraph::size_type const pos =
263 (is_space && lpos + 1 <= bidi_end &&
264 !row->par()->IsLineSeparator(lpos + 1) &&
265 !row->par()->IsNewline(lpos + 1))
267 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
268 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
269 font.number() == LyXFont::ON &&
270 row->par()->GetFontSettings(buf->params, lpos-1).number()
272 font = row->par()->GetFontSettings(buf->params, lpos);
277 bool new_rtl = font.isVisibleRightToLeft();
278 bool new_rtl0 = font.isRightToLeft();
281 if (lpos == main_body - 1
282 && row->pos() < main_body - 1
284 new_level = (rtl_par) ? 1 : 0;
285 new_rtl = new_rtl0 = rtl_par;
287 new_level = (new_rtl) ? 1 : 2;
289 new_level = (rtl_par) ? 2 : 0;
291 if (is_space && new_level >= level) {
297 int new_level2 = new_level;
299 if (level == new_level && rtl0 != new_rtl0) {
301 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
302 } else if (level < new_level) {
303 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
304 if (new_level > rtl_par)
305 bidi_same_direction = false;
307 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
310 bidi_levels[lpos - bidi_start] = new_level;
312 while (level > new_level2) {
313 LyXParagraph::size_type old_lpos =
315 int delta = lpos - old_lpos - 1;
318 log2vis_list[lpos - bidi_start] += delta;
319 log2vis_list[old_lpos - bidi_start] += delta;
321 while (level < new_level)
322 stack[level++] = lpos;
326 LyXParagraph::size_type const old_lpos = stack[--level];
327 int delta = bidi_end - old_lpos;
330 log2vis_list[old_lpos - bidi_start] += delta;
333 LyXParagraph::size_type vpos = bidi_start - 1;
334 for (LyXParagraph::size_type lpos = bidi_start;
335 lpos <= bidi_end; ++lpos) {
336 vpos += log2vis_list[lpos - bidi_start];
337 vis2log_list[vpos - bidi_start] = lpos;
338 log2vis_list[lpos - bidi_start] = vpos;
343 // This method requires a previous call to ComputeBidiTables()
344 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
345 LyXParagraph::size_type pos) const
347 if (!lyxrc.rtl_support || pos == 0)
350 if (!bidi_InRange(pos - 1)) {
351 /// This can happen if pos is the first char of a row.
352 /// Returning false in this case is incorrect!
356 bool const rtl = bidi_level(pos - 1) % 2;
357 bool rtl2 = bidi_InRange(pos)
358 ? bidi_level(pos) % 2
359 : par->isRightToLeftPar(buf->params);
364 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
365 LyXParagraph::size_type pos,
366 LyXFont const & font) const
368 if (!lyxrc.rtl_support)
369 return false; // This is just for speedup
371 bool const rtl = font.isVisibleRightToLeft();
372 bool rtl2 = bidi_InRange(pos)
373 ? bidi_level(pos) % 2
374 : par->isRightToLeftPar(buf->params);
379 void LyXText::draw(BufferView * bview, Row const * row,
380 LyXParagraph::size_type & vpos,
381 int offset, float & x, bool cleared)
383 Painter & pain = bview->painter();
385 LyXParagraph::size_type pos = vis2log(vpos);
386 char c = row->par()->GetChar(pos);
389 if (IsNewlineChar(c)) {
391 // Draw end-of-line marker
392 LyXFont const font = GetFont(bview->buffer(), row->par(), pos);
393 int const wid = lyxfont::width('n', font);
394 int const asc = lyxfont::maxAscent(font);
395 int const y = offset + row->baseline();
398 if (bidi_level(pos) % 2 == 0) {
399 xp[0] = int(x + wid * 0.375);
400 yp[0] = int(y - 0.875 * asc * 0.75);
403 yp[1] = int(y - 0.500 * asc * 0.75);
405 xp[2] = int(x + wid * 0.375);
406 yp[2] = int(y - 0.125 * asc * 0.75);
408 pain.lines(xp, yp, 3, LColor::eolmarker);
411 yp[0] = int(y - 0.500 * asc * 0.75);
413 xp[1] = int(x + wid);
414 yp[1] = int(y - 0.500 * asc * 0.75);
416 xp[2] = int(x + wid);
417 yp[2] = int(y - asc * 0.75);
419 pain.lines(xp, yp, 3, LColor::eolmarker);
421 xp[0] = int(x + wid * 0.625);
422 yp[0] = int(y - 0.875 * asc * 0.75);
424 xp[1] = int(x + wid);
425 yp[1] = int(y - 0.500 * asc * 0.75);
427 xp[2] = int(x + wid * 0.625);
428 yp[2] = int(y - 0.125 * asc * 0.75);
430 pain.lines(xp, yp, 3, LColor::eolmarker);
432 xp[0] = int(x + wid);
433 yp[0] = int(y - 0.500 * asc * 0.75);
436 yp[1] = int(y - 0.500 * asc * 0.75);
439 yp[2] = int(y - asc * 0.75);
441 pain.lines(xp, yp, 3, LColor::eolmarker);
447 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
448 LyXFont font2 = font;
450 if (c == LyXParagraph::META_FOOTNOTE
451 || c == LyXParagraph::META_MARGIN
452 || c == LyXParagraph::META_FIG
453 || c == LyXParagraph::META_TAB
454 || c == LyXParagraph::META_WIDE_FIG
455 || c == LyXParagraph::META_WIDE_TAB
456 || c == LyXParagraph::META_ALGORITHM) {
459 case LyXParagraph::META_MARGIN:
462 case LyXParagraph::META_FIG:
465 case LyXParagraph::META_TAB:
468 case LyXParagraph::META_ALGORITHM:
471 case LyXParagraph::META_WIDE_FIG:
474 case LyXParagraph::META_WIDE_TAB:
477 case LyXParagraph::META_FOOTNOTE:
484 // calculate the position of the footnotemark
485 int const y = (row->baseline() - lyxfont::maxAscent(font2)
486 + lyxfont::maxAscent(font));
488 font.setColor(LColor::footnote);
490 // draw it and set new x position
492 pain.text(int(x), offset + y, fs, font);
493 x += lyxfont::width(fs, font);
494 pain.line(int(tmpx), offset + row->baseline(),
495 int(x), offset + row->baseline(),
502 if (c == LyXParagraph::META_INSET) {
503 Inset * tmpinset = row->par()->GetInset(pos);
505 // tmpinset->update(bview, font, false);
506 tmpinset->draw(bview, font, offset+row->baseline(), x,
508 #ifdef SEEMS_TO_BE_NOT_NEEDED
509 if (status == CHANGED_IN_DRAW) {
510 UpdateInset(bview, tmpinset);
511 status = CHANGED_IN_DRAW;
517 if (lyxrc.mark_foreign_language &&
518 font.language() != bview->buffer()->params.language) {
519 int const y = offset + row->height() - 1;
520 pain.line(int(tmpx), y, int(x), y,
527 /* usual characters, no insets */
529 // Collect character that we can draw in one command
531 // This is dirty, but fast. Notice that it will never be too small.
532 // For the record, I'll note that Microsoft Word has a limit
533 // of 768 here. We have none :-) (Asger)
534 // Ok. I am the first to admit that the use of std::string will be
535 // a tiny bit slower than using a POD char array. However, I claim
536 // that this slowdown is so small that it is close to inperceptive.
537 // So IMHO we should go with the easier and clearer implementation.
538 // And even if 1024 is a large number here it might overflow, string
539 // will only overflow if the machine is out of memory...
540 static string textstring;
544 LyXParagraph::size_type const last = RowLastPrintable(row);
546 if (font.language()->lang() == "hebrew") {
547 if (Encodings::IsComposeChar_hebrew(c)) {
548 int const width = lyxfont::width(c, font2);
550 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
551 c = row->par()->GetChar(i);
552 if (!Encodings::IsComposeChar_hebrew(c)) {
553 if (IsPrintableNonspace(c)) {
558 dx = (c == 'ø' || c == 'ã') // dalet / resh
559 ? width2 - width : (width2 - width) / 2;
565 pain.text(int(x) + dx, offset + row->baseline(),
568 while (vpos <= last &&
569 (pos = vis2log(vpos)) >= 0
570 && IsPrintableNonspace(c = row->par()->GetChar(pos))
571 && !Encodings::IsComposeChar_hebrew(c)
572 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
576 // Draw text and set the new x position
577 pain.text(int(x), offset + row->baseline(),
579 x += lyxfont::width(textstring, font);
581 } else if (font.language()->lang() == "arabic" &&
582 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
583 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
584 if (Encodings::IsComposeChar_arabic(c)) {
585 c = TransformChar(c, row->par(), pos);
587 int const width = lyxfont::width(c, font2);
589 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
590 c = row->par()->GetChar(i);
591 if (!Encodings::IsComposeChar_arabic(c)) {
592 if (IsPrintableNonspace(c)) {
597 dx = (width2 - width) / 2;
603 pain.text(int(x) + dx, offset + row->baseline(),
606 textstring = TransformChar(c, row->par(), pos);
607 while (vpos <= last &&
608 (pos = vis2log(vpos)) >= 0
609 && IsPrintableNonspace(c = row->par()->GetChar(pos))
610 && !Encodings::IsComposeChar_arabic(c)
611 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
612 c = TransformChar(c, row->par(), pos);
616 // Draw text and set the new x position
617 pain.text(int(x), offset + row->baseline(),
619 x += lyxfont::width(textstring, font);
622 while (vpos <= last &&
623 (pos = vis2log(vpos)) >= 0
624 && IsPrintableNonspace(c = row->par()->GetChar(pos))
625 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
629 // Draw text and set the new x position
630 pain.text(int(x), offset + row->baseline(), textstring, font);
631 x += lyxfont::width(textstring, font);
634 if (lyxrc.mark_foreign_language &&
635 font.language() != bview->buffer()->params.language) {
636 int const y = offset + row->height() - 1;
637 pain.line(int(tmpx), y, int(x), y,
641 // If we want ulem.sty support, drawing
642 // routines should go here. (Asger)
643 // Why shouldn't LyXFont::drawText handle it internally?
647 // Returns the left beginning of the text.
648 // This information cannot be taken from the layouts-objekt, because in
649 // LaTeX the beginning of the text fits in some cases (for example sections)
650 // exactly the label-width.
651 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
653 LyXLayout const & layout =
654 textclasslist.Style(bview->buffer()->params.textclass,
655 row->par()->GetLayout());
657 string parindent = layout.parindent;
659 int x = LYX_PAPER_MARGIN;
661 x += lyxfont::signedWidth(textclasslist
662 .TextClass(bview->buffer()->params.textclass)
665 .TextClass(bview->buffer()->params.textclass)
668 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
669 LyXFont font(LyXFont::ALL_SANE);
670 font.setSize(LyXFont::SIZE_SMALL);
671 x += lyxfont::width("Mwide-figM", font)
672 + LYX_PAPER_MARGIN/2;
675 // this is the way, LyX handles the LaTeX-Environments.
676 // I have had this idea very late, so it seems to be a
677 // later added hack and this is true
678 if (!row->par()->GetDepth()) {
679 if (!row->par()->GetLayout()) {
680 // find the previous same level paragraph
682 if (row->par()->FirstPhysicalPar()->Previous()) {
684 if (row->par()->Previous()) {
686 LyXParagraph * newpar = row->par()
687 ->DepthHook(row->par()->GetDepth());
689 textclasslist.Style(bview->buffer()->params.textclass,
696 // find the next level paragraph
698 LyXParagraph * newpar =
699 row->par()->DepthHook(row->par()->GetDepth()-1);
701 // make a corresponding row. Needed to call LeftMargin()
703 // check wether it is a sufficent paragraph
706 && newpar->footnoteflag == row->par()->footnoteflag
709 .Style(bview->buffer()->params.textclass,
710 newpar->GetLayout()).isEnvironment()) {
712 dummyrow.par(newpar);
713 dummyrow.pos(newpar->Last());
714 x = LeftMargin(bview, &dummyrow);
716 // this is no longer an error, because this function
717 // is used to clear impossible depths after changing
718 // a layout. Since there is always a redo,
719 // LeftMargin() is always called
721 row->par()->FirstPhysicalPar()->depth = 0;
723 row->par()->depth = 0;
727 if (newpar && !row->par()->GetLayout()) {
729 if (newpar->FirstPhysicalPar()->noindent)
731 if (newpar->noindent)
735 parindent = textclasslist
736 .Style(bview->buffer()->params.textclass,
737 newpar->GetLayout()).parindent;
742 LyXFont const labelfont = GetFont(bview->buffer(), row->par(), -2);
743 switch (layout.margintype) {
745 if (!layout.leftmargin.empty()) {
746 x += lyxfont::signedWidth(layout.leftmargin,
748 .TextClass(bview->buffer()->params.
752 if (!row->par()->GetLabelstring().empty()) {
753 x += lyxfont::signedWidth(layout.labelindent,
755 x += lyxfont::width(row->par()->GetLabelstring(),
757 x += lyxfont::width(layout.labelsep, labelfont);
761 x += lyxfont::signedWidth(layout.labelindent, labelfont);
762 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
763 if (!row->par()->GetLabelWidthString().empty()) {
764 x += lyxfont::width(row->par()->GetLabelWidthString(),
766 x += lyxfont::width(layout.labelsep, labelfont);
771 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
772 / (row->par()->GetDepth() + 4);
774 case MARGIN_FIRST_DYNAMIC:
775 if (layout.labeltype == LABEL_MANUAL) {
776 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
777 x += lyxfont::signedWidth(layout.leftmargin,
780 x += lyxfont::signedWidth(layout.labelindent,
783 } else if (row->pos()
784 // Special case to fix problems with
786 || (layout.labeltype == LABEL_STATIC
787 && layout.latextype == LATEX_ENVIRONMENT
788 && ! row->par()->IsFirstInSequence())) {
789 x += lyxfont::signedWidth(layout.leftmargin,
791 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
792 && layout.labeltype != LABEL_BIBLIO
793 && layout.labeltype !=
794 LABEL_CENTERED_TOP_ENVIRONMENT) {
795 x += lyxfont::signedWidth(layout.labelindent,
797 x += lyxfont::width(layout.labelsep, labelfont);
798 x += lyxfont::width(row->par()->GetLabelstring(),
803 case MARGIN_RIGHT_ADDRESS_BOX:
805 // ok, a terrible hack. The left margin depends on the widest
806 // row in this paragraph. Do not care about footnotes, they
807 // are *NOT* allowed in the LaTeX realisation of this layout.
809 // find the first row of this paragraph
810 Row const * tmprow = row;
811 while (tmprow->previous()
812 && tmprow->previous()->par() == row->par())
813 tmprow = tmprow->previous();
815 int minfill = tmprow->fill();
816 while (tmprow->next() && tmprow->next()->par() == row->par()) {
817 tmprow = tmprow->next();
818 if (tmprow->fill() < minfill)
819 minfill = tmprow->fill();
822 x += lyxfont::signedWidth(layout.leftmargin,
824 .TextClass(bview->buffer()->params.textclass)
830 if ((workWidth(bview) > 0) &&
831 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT)) {
832 if (!row->par()->pextra_widthp.empty()) {
833 x += workWidth(bview) *
834 lyx::atoi(row->par()->pextra_widthp) / 100;
835 } else if (!row->par()->pextra_width.empty()) {
836 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
837 if (xx > workWidth(bview))
838 xx = workWidth(bview) * 80 / 100;
840 } else { // should not happen
841 LyXFont font(LyXFont::ALL_SANE);
842 x += lyxfont::width("XXXXXX", font);
846 int align; // wrong type
848 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
849 align = layout.align;
851 align = row->par()->FirstPhysicalPar()->align;
853 if (row->par()->align == LYX_ALIGN_LAYOUT)
854 align = layout.align;
856 align = row->par()->align;
858 // set the correct parindent
859 if (row->pos() == 0) {
860 if ((layout.labeltype == LABEL_NO_LABEL
861 || layout.labeltype == LABEL_TOP_ENVIRONMENT
862 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
863 || (layout.labeltype == LABEL_STATIC
864 && layout.latextype == LATEX_ENVIRONMENT
865 && ! row->par()->IsFirstInSequence()))
867 && row->par() == row->par()->FirstPhysicalPar()
869 && align == LYX_ALIGN_BLOCK
870 && !row->par()->noindent
871 && (row->par()->layout ||
872 bview->buffer()->params.paragraph_separation ==
873 BufferParams::PARSEP_INDENT))
874 x += lyxfont::signedWidth(parindent,
876 .TextClass(bview->buffer()->params
879 else if (layout.labeltype == LABEL_BIBLIO) {
880 // ale970405 Right width for bibitems
881 x += bibitemMaxWidth(bview,textclasslist
882 .TextClass(bview->buffer()->params
891 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
893 LyXLayout const & layout =
894 textclasslist.Style(buf->params.textclass,
895 row->par()->GetLayout());
897 int x = LYX_PAPER_MARGIN
898 + lyxfont::signedWidth(textclasslist
899 .TextClass(buf->params.textclass)
902 .TextClass(buf->params.textclass)
906 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
907 x += LYX_PAPER_MARGIN / 2;
910 // this is the way, LyX handles the LaTeX-Environments.
911 // I have had this idea very late, so it seems to be a
912 // later added hack and this is true
913 if (row->par()->GetDepth()) {
914 // find the next level paragraph
916 LyXParagraph * newpar = row->par();
920 newpar = newpar->FirstPhysicalPar()->Previous();
922 newpar = newpar->FirstPhysicalPar();
923 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
924 && newpar->footnoteflag == row->par()->footnoteflag);
927 newpar = newpar->Previous();
929 && newpar->GetDepth() >= row->par()->GetDepth());
932 // make a corresponding row. Needed to call LeftMargin()
934 // check wether it is a sufficent paragraph
937 && newpar->footnoteflag == row->par()->footnoteflag
939 && textclasslist.Style(buf->params.textclass,
943 dummyrow.par(newpar);
945 x = RightMargin(buf, &dummyrow);
947 // this is no longer an error, because this function
948 // is used to clear impossible depths after changing
949 // a layout. Since there is always a redo,
950 // LeftMargin() is always called
952 row->par()->FirstPhysicalPar()->depth = 0;
954 row->par()->depth = 0;
959 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
960 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
961 .TextClass(buf->params.textclass)
962 .defaultfont()) * 4 / (row->par()->GetDepth()
968 int LyXText::LabelEnd(BufferView * bview, Row const * row) const
970 if (textclasslist.Style(bview->buffer()->params.textclass,
971 row->par()->GetLayout()).margintype
975 tmprow.pos(row->par()->Last());
976 return LeftMargin(bview, &tmprow); /* just the beginning
979 return 0; /* LabelEnd is only needed, if the
980 layout fills a flushleft
985 // get the next breakpoint in a given paragraph
986 LyXParagraph::size_type
987 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
989 LyXParagraph * par = row->par();
994 LyXParagraph::size_type const pos = row->pos();
997 // position of the last possible breakpoint
998 // -1 isn't a suitable value, but a flag
999 LyXParagraph::size_type last_separator = -1;
1000 width -= RightMargin(bview->buffer(), row);
1002 LyXParagraph::size_type const main_body =
1003 BeginningOfMainBody(bview->buffer(), par);
1004 LyXLayout const & layout =
1005 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1006 LyXParagraph::size_type i = pos;
1008 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1009 /* special code for right address boxes, only newlines count */
1010 while (i < par->Last()) {
1011 if (par->IsNewline(i)) {
1013 i = par->Last() - 1; // this means break
1015 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1016 par->GetInset(i) && par->GetInset(i)->display()){
1017 par->GetInset(i)->display(false);
1022 // Last position is an invariant
1023 LyXParagraph::size_type const last =
1025 // this is the usual handling
1026 int x = LeftMargin(bview, row);
1027 bool doitonetime = true;
1028 while (doitonetime || ((x < width) && (i < last))) {
1029 doitonetime = false;
1030 char const c = par->GetChar(i);
1031 if (IsNewlineChar(c)) {
1033 x = width; // this means break
1034 } else if (c == LyXParagraph::META_INSET &&
1037 // check wether a Display() inset is
1038 // valid here. if not, change it to
1040 if (par->GetInset(i)->display() &&
1041 (layout.isCommand() ||
1042 (layout.labeltype == LABEL_MANUAL
1043 && i < BeginningOfMainBody(bview->buffer(), par)))) {
1044 // display istn't allowd
1045 par->GetInset(i)->display(false);
1046 x += SingleWidth(bview, par, i, c);
1047 } else if (par->GetInset(i)->display() ||
1048 par->GetInset(i)->needFullRow()) {
1049 // So break the line here
1053 if (IsLineSeparatorChar(par->GetChar(i+1)))
1056 last_separator = last; // to avoid extra rows
1058 last_separator = i - 1;
1059 x = width; // this means break
1065 x += SingleWidth(bview, par, i, c);
1069 if (IsLineSeparatorChar(c))
1071 x += SingleWidth(bview, par, i, c);
1074 if (i == main_body) {
1075 x += lyxfont::width(layout.labelsep,
1076 GetFont(bview->buffer(), par, -2));
1077 if (par->IsLineSeparator(i - 1))
1078 x-= SingleWidth(bview, par, i - 1);
1079 int left_margin = LabelEnd(bview, row);
1080 if (x < left_margin)
1084 // end of paragraph is always a suitable separator
1085 if (i == last && x < width)
1089 // well, if last_separator is still 0, the line isn't breakable.
1090 // don't care and cut simply at the end
1091 if (last_separator < 0) {
1095 // manual labels cannot be broken in LaTeX, do not care
1096 if (main_body && last_separator < main_body)
1097 last_separator = main_body - 1;
1099 return last_separator;
1103 // returns the minimum space a row needs on the screen in pixel
1104 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1106 if (paper_width < 0)
1110 // get the pure distance
1111 LyXParagraph::size_type const last = RowLastPrintable(row);
1113 // special handling of the right address boxes
1114 if (textclasslist.Style(bview->buffer()->params.textclass,
1115 row->par()->GetLayout()).margintype
1116 == MARGIN_RIGHT_ADDRESS_BOX) {
1117 int const tmpfill = row->fill();
1118 row->fill(0); // the minfill in MarginLeft()
1119 w = LeftMargin(bview, row);
1122 w = LeftMargin(bview, row);
1124 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1125 row->par()->GetLayout());
1126 LyXParagraph::size_type const main_body =
1127 BeginningOfMainBody(bview->buffer(), row->par());
1128 LyXParagraph::size_type i = row->pos();
1131 if (main_body > 0 && i == main_body) {
1132 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1133 if (row->par()->IsLineSeparator(i - 1))
1134 w -= SingleWidth(bview, row->par(), i - 1);
1135 int left_margin = LabelEnd(bview, row);
1136 if (w < left_margin)
1139 w += SingleWidth(bview, row->par(), i);
1142 if (main_body > 0 && main_body > last) {
1143 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1144 if (last >= 0 && row->par()->IsLineSeparator(last))
1145 w -= SingleWidth(bview, row->par(), last);
1146 int const left_margin = LabelEnd(bview, row);
1147 if (w < left_margin)
1151 int const fill = paper_width - w - RightMargin(bview->buffer(), row);
1156 // returns the minimum space a manual label needs on the screen in pixel
1157 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1159 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par()) - 1;
1160 // -1 because a label ends either with a space that is in the label,
1161 // or with the beginning of a footnote that is outside the label.
1163 // I don't understand this code in depth, but sometimes "last" is
1164 // less than 0 and this causes a crash. This fix seems to work
1165 // correctly, but I bet the real error is elsewhere. The bug is
1166 // triggered when you have an open footnote in a paragraph
1167 // environment with a manual label. (Asger)
1168 if (last < 0) last = 0;
1170 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1177 w += SingleWidth(bview, row->par(), i);
1182 if (!row->par()->labelwidthstring.empty()) {
1183 fill = max(lyxfont::width(row->par()->labelwidthstring,
1184 GetFont(bview->buffer(), row->par(), -2)) - w,
1192 // returns the number of separators in the specified row. The separator
1193 // on the very last column doesnt count
1194 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1196 LyXParagraph::size_type const last = RowLast(row);
1197 LyXParagraph::size_type p =
1198 max(row->pos(), BeginningOfMainBody(buf, row->par()));
1200 for (; p < last; ++p) {
1201 if (row->par()->IsSeparator(p)) {
1209 // returns the number of hfills in the specified row. The LyX-Hfill is
1210 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1211 // ignored. This is *MUCH* more usefull than not to ignore!
1212 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1214 LyXParagraph::size_type const last = RowLast(row);
1215 LyXParagraph::size_type first = row->pos();
1216 if (first) { /* hfill *DO* count at the beginning
1218 while(first <= last && row->par()->IsHfill(first))
1222 first = max(first, BeginningOfMainBody(buf, row->par()));
1224 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1225 if (row->par()->IsHfill(p)) {
1233 // like NumberOfHfills, but only those in the manual label!
1234 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1236 LyXParagraph::size_type last = RowLast(row);
1237 LyXParagraph::size_type first = row->pos();
1238 if (first) { /* hfill *DO* count at the beginning
1240 while(first < last && row->par()->IsHfill(first))
1244 last = min(last, BeginningOfMainBody(buf, row->par()));
1246 for (LyXParagraph::size_type p = first;
1247 p < last; ++p) { // last, because the end is ignored!
1248 if (row->par()->IsHfill(p)) {
1256 // returns true, if a expansion is needed.
1257 // Rules are given by LaTeX
1258 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1259 LyXParagraph::size_type pos) const
1261 // by the way, is it a hfill?
1262 if (!row_ptr->par()->IsHfill(pos))
1265 // at the end of a row it does not count
1266 if (pos >= RowLast(row_ptr))
1269 // at the beginning of a row it does not count, if it is not
1270 // the first row of a paragaph
1271 if (!row_ptr->pos())
1274 // in some labels it does not count
1275 if (textclasslist.Style(buf->params.textclass,
1276 row_ptr->par()->GetLayout()).margintype
1278 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1281 // if there is anything between the first char of the row and
1282 // the sepcified position that is not a newline and not a hfill,
1283 // the hfill will count, otherwise not
1284 LyXParagraph::size_type i = row_ptr->pos();
1285 while (i < pos && (row_ptr->par()->IsNewline(i)
1286 || row_ptr->par()->IsHfill(i)))
1293 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1295 /* get the maximum ascent and the maximum descent */
1298 float layoutasc = 0;
1299 float layoutdesc = 0;
1302 Inset * tmpinset = 0;
1304 /* this must not happen before the currentrow for clear reasons.
1305 so the trick is just to set the current row onto this row */
1307 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1309 /* ok , let us initialize the maxasc and maxdesc value.
1310 * This depends in LaTeX of the font of the last character
1311 * in the paragraph. The hack below is necessary because
1312 * of the possibility of open footnotes */
1314 /* Correction: only the fontsize count. The other properties
1315 are taken from the layoutfont. Nicer on the screen :) */
1317 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1318 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1320 LyXParagraph * par = row_ptr->par();
1321 LyXParagraph * firstpar = row_ptr->par();
1324 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1325 firstpar->GetLayout());
1327 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1328 LyXFont::FONT_SIZE const size = font.size();
1329 font = GetFont(bview->buffer(), par, -1);
1332 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1334 float spacing_val = 1.0;
1335 if (!row_ptr->par()->spacing.isDefault()) {
1336 spacing_val = row_ptr->par()->spacing.getValue();
1338 spacing_val = bview->buffer()->params.spacing.getValue();
1340 //lyxerr << "spacing_val = " << spacing_val << endl;
1342 int maxasc = int(lyxfont::maxAscent(font) *
1343 layout.spacing.getValue() *
1345 int maxdesc = int(lyxfont::maxDescent(font) *
1346 layout.spacing.getValue() *
1348 int const pos_end = RowLast(row_ptr);
1352 // Check if any insets are larger
1353 for (int pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1354 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1355 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1356 tmpinset = row_ptr->par()->GetInset(pos);
1358 tmpinset->update(bview, tmpfont);
1359 asc = tmpinset->ascent(bview, tmpfont);
1360 desc = tmpinset->descent(bview, tmpfont);
1361 maxwidth += tmpinset->width(bview, tmpfont);
1362 maxasc = max(maxasc, asc);
1363 maxdesc = max(maxdesc, desc);
1366 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1370 // Check if any custom fonts are larger (Asger)
1371 // This is not completely correct, but we can live with the small,
1372 // cosmetic error for now.
1373 LyXFont::FONT_SIZE const maxsize =
1374 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1376 if (maxsize > font.size()) {
1377 font.setSize(maxsize);
1379 asc = lyxfont::maxAscent(font);
1380 desc = lyxfont::maxDescent(font);
1387 // This is nicer with box insets:
1391 row_ptr->ascent_of_text(maxasc);
1393 /* is it a top line? */
1394 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1396 /* some parksips VERY EASY IMPLEMENTATION */
1397 if (bview->buffer()->params.paragraph_separation ==
1398 BufferParams::PARSEP_SKIP) {
1399 if (layout.isParagraph()
1400 && firstpar->GetDepth() == 0
1401 && firstpar->Previous())
1402 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1403 else if (firstpar->Previous()
1404 && textclasslist.Style(bview->buffer()->params.textclass,
1405 firstpar->Previous()->GetLayout()).isParagraph()
1406 && firstpar->Previous()->GetDepth() == 0)
1407 // is it right to use defskip here too? (AS)
1408 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1411 /* the paper margins */
1412 if (!row_ptr->par()->previous && bv_owner)
1413 maxasc += LYX_PAPER_MARGIN;
1415 /* add the vertical spaces, that the user added */
1416 if (firstpar->added_space_top.kind() != VSpace::NONE)
1417 maxasc += int(firstpar->added_space_top.inPixels(bview));
1419 /* do not forget the DTP-lines!
1420 * there height depends on the font of the nearest character */
1421 if (firstpar->line_top)
1422 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1425 /* and now the pagebreaks */
1426 if (firstpar->pagebreak_top)
1427 maxasc += 3 * DefaultHeight();
1429 /* this is special code for the chapter, since the label of this
1430 * layout is printed in an extra row */
1431 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1432 && bview->buffer()->params.secnumdepth >= 0) {
1433 float spacing_val = 1.0;
1434 if (!row_ptr->par()->spacing.isDefault()) {
1435 spacing_val = row_ptr->par()->spacing.getValue();
1437 spacing_val = bview->buffer()->params.spacing.getValue();
1440 labeladdon = int(lyxfont::maxDescent(labelfont) *
1441 layout.spacing.getValue() *
1443 + int(lyxfont::maxAscent(labelfont) *
1444 layout.spacing.getValue() *
1448 /* special code for the top label */
1449 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1450 || layout.labeltype == LABEL_BIBLIO
1451 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1452 && row_ptr->par()->IsFirstInSequence()
1453 && !row_ptr->par()->GetLabelstring().empty()) {
1454 float spacing_val = 1.0;
1455 if (!row_ptr->par()->spacing.isDefault()) {
1456 spacing_val = row_ptr->par()->spacing.getValue();
1458 spacing_val = bview->buffer()->params.spacing.getValue();
1462 (lyxfont::maxAscent(labelfont) *
1463 layout.spacing.getValue() *
1465 +(lyxfont::maxDescent(labelfont) *
1466 layout.spacing.getValue() *
1468 + layout.topsep * DefaultHeight()
1469 + layout.labelbottomsep * DefaultHeight());
1472 /* and now the layout spaces, for example before and after a section,
1473 * or between the items of a itemize or enumerate environment */
1475 if (!firstpar->pagebreak_top) {
1476 LyXParagraph * prev = row_ptr->par()->Previous();
1478 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1479 if (prev && prev->GetLayout() == firstpar->GetLayout()
1480 && prev->GetDepth() == firstpar->GetDepth()
1481 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1483 layoutasc = (layout.itemsep * DefaultHeight());
1485 else if (row_ptr->previous()) {
1486 tmptop = layout.topsep;
1488 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1489 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1490 row_ptr->previous()->par()->
1491 GetLayout()).bottomsep;
1494 layoutasc = (tmptop * DefaultHeight());
1496 else if (row_ptr->par()->line_top){
1497 tmptop = layout.topsep;
1500 layoutasc = (tmptop * DefaultHeight());
1503 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1505 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1506 prev->GetLayout()).parsep * DefaultHeight());
1509 if (firstpar->Previous()
1510 && firstpar->Previous()->GetDepth() == 0
1511 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1514 else if (firstpar->Previous()){
1515 maxasc += int(layout.parsep * DefaultHeight());
1521 /* is it a bottom line? */
1524 row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1526 row_ptr->par() == par
1528 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1530 /* the paper margins */
1531 if (!par->next && bv_owner)
1532 maxdesc += LYX_PAPER_MARGIN;
1534 /* add the vertical spaces, that the user added */
1535 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1536 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1538 /* do not forget the DTP-lines!
1539 * there height depends on the font of the nearest character */
1540 if (firstpar->line_bottom)
1541 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1542 par, par->Last() - 1));
1544 /* and now the pagebreaks */
1545 if (firstpar->pagebreak_bottom)
1546 maxdesc += 3 * DefaultHeight();
1548 /* and now the layout spaces, for example before and after a section,
1549 * or between the items of a itemize or enumerate environment */
1550 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1551 LyXParagraph * nextpar = row_ptr->par()->Next();
1552 LyXParagraph * comparepar = row_ptr->par();
1556 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1557 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1558 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1559 if (comparepar->GetLayout()!= nextpar->GetLayout()
1560 || nextpar->GetLabelWidthString() !=
1561 comparepar->GetLabelWidthString())
1562 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1564 if (unusual > usual)
1565 layoutdesc = unusual;
1569 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1571 if (comparepar->GetLayout()!= nextpar->GetLayout()
1572 || nextpar->GetLabelWidthString() !=
1573 comparepar->GetLabelWidthString())
1574 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1579 /* incalculate the layout spaces */
1580 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1581 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1583 /* calculate the new height of the text */
1584 height -= row_ptr->height();
1586 row_ptr->height(maxasc + maxdesc + labeladdon);
1587 row_ptr->baseline(maxasc + labeladdon);
1589 height += row_ptr->height();
1591 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1592 row_ptr->width(int(maxwidth + x));
1595 width = max(0,workWidth(bview));
1597 if (r->width() > width)
1605 /* Appends the implicit specified paragraph behind the specified row,
1606 * start at the implicit given position */
1607 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1609 bool not_ready = true;
1611 // The last character position of a paragraph is an invariant so we can
1612 // safely get it here. (Asger)
1613 int const lastposition = row->par()->Last();
1616 // Get the next breakpoint
1617 int z = NextBreakPoint(bview, row, workWidth(bview));
1621 // Insert the new row
1622 if (z < lastposition) {
1624 InsertRow(row, row->par(), z);
1631 // Set the dimensions of the row
1632 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1633 SetHeightOfRow(bview, tmprow);
1635 } while (not_ready);
1639 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1641 bool not_ready = true;
1644 /* get the next breakpoint */
1645 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1648 if (z < row->par()->Last()) {
1649 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1652 InsertRow(row, row->par(), z);
1658 if (row->pos() == z)
1659 not_ready = false; // the rest will not change
1665 /* if there are some rows too much, delete them */
1666 /* only if you broke the whole paragraph! */
1667 Row * tmprow2 = row;
1668 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1669 tmprow2 = tmprow2->next();
1671 while (tmprow2 != row) {
1672 tmprow2 = tmprow2->previous();
1673 RemoveRow(tmprow2->next());
1678 /* set the dimensions of the row */
1679 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1680 SetHeightOfRow(bview, tmprow);
1681 } while (not_ready);
1685 // this is just a little changed version of break again
1686 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1688 // get the next breakpoint
1689 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1692 if (z < row->par()->Last()) {
1694 || (row->next() && row->next()->par() != row->par())) {
1695 /* insert a new row */
1697 InsertRow(row, row->par(), z);
1703 if (row->pos() != z)
1707 // if there are some rows too much, delete them
1708 // only if you broke the whole paragraph!
1709 Row * tmprow2 = row;
1710 while (tmprow2->next()
1711 && tmprow2->next()->par() == row->par()) {
1712 tmprow2 = tmprow2->next();
1714 while (tmprow2 != row) {
1715 tmprow2 = tmprow2->previous();
1716 RemoveRow(tmprow2->next());
1720 // set the dimensions of the row
1721 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1722 SetHeightOfRow(bview, tmprow);
1726 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1728 LyXLayout const & layout =
1729 textclasslist.Style(bview->buffer()->params.textclass,
1730 cursor.par()->GetLayout());
1732 // this is only allowed, if the current paragraph is not empty or caption
1733 if ((cursor.par()->Last() <= 0
1735 && !cursor.par()->IsDummy()
1739 layout.labeltype!= LABEL_SENSITIVE)
1742 SetUndo(bview->buffer(), Undo::INSERT,
1744 cursor.par()->ParFromPos(cursor.pos())->previous,
1745 cursor.par()->ParFromPos(cursor.pos())->next
1747 cursor.par()->previous,
1752 // Always break behind a space
1754 // It is better to erase the space (Dekel)
1755 if (cursor.pos() < cursor.par()->Last()
1756 && cursor.par()->IsLineSeparator(cursor.pos()))
1757 cursor.par()->Erase(cursor.pos());
1758 // cursor.pos(cursor.pos() + 1);
1760 // break the paragraph
1764 keep_layout = layout.isEnvironment();
1765 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1768 // well this is the caption hack since one caption is really enough
1769 if (layout.labeltype == LABEL_SENSITIVE) {
1771 // set to standard-layout
1772 cursor.par()->SetLayout(bview->buffer()->params, 0);
1774 // set to standard-layout
1775 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1778 /* if the cursor is at the beginning of a row without prior newline,
1780 * This touches only the screen-update. Otherwise we would may have
1781 * an empty row on the screen */
1782 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1)
1783 && cursor.row()->pos() == cursor.pos()) {
1787 status = LyXText::NEED_MORE_REFRESH;
1788 refresh_row = cursor.row();
1789 refresh_y = cursor.y() - cursor.row()->baseline();
1791 // Do not forget the special right address boxes
1792 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1793 while (refresh_row->previous() &&
1794 refresh_row->previous()->par() == refresh_row->par()) {
1795 refresh_row = refresh_row->previous();
1796 refresh_y -= refresh_row->height();
1799 RemoveParagraph(cursor.row());
1801 // set the dimensions of the cursor row
1802 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1804 SetHeightOfRow(bview, cursor.row());
1806 while (cursor.par()->Next()->Last()
1807 && cursor.par()->Next()->IsNewline(0))
1808 cursor.par()->Next()->Erase(0);
1810 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1812 UpdateCounters(bview, cursor.row()->previous());
1814 /* This check is necessary. Otherwise the new empty paragraph will
1815 * be deleted automatically. And it is more friendly for the user! */
1817 SetCursor(bview, cursor.par()->Next(), 0);
1819 SetCursor(bview, cursor.par(), 0);
1821 if (cursor.row()->next())
1822 BreakAgain(bview, cursor.row()->next());
1829 void LyXText::OpenFootnote(BufferView * bview)
1831 LyXParagraph * endpar,* tmppar;
1834 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1836 /* if there is no footnote in this paragraph, just return. */
1838 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1841 /* ok, move the cursor right before the footnote */
1843 /* just a little faster than using CursorRight() */
1845 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1846 cursor.pos(cursor.pos() + 1);
1849 /* now the cursor is at the beginning of the physical par */
1850 SetCursor(bview, cursor.par(),
1851 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1853 /* the cursor must be exactly before the footnote */
1854 par = cursor.par()->ParFromPos(cursor.pos());
1856 status = LyXText::NEED_MORE_REFRESH;
1857 refresh_row = cursor.row();
1858 refresh_y = cursor.y() - cursor.row()->baseline();
1860 tmppar = cursor.par();
1861 endpar = cursor.par()->Next();
1864 tmppar->OpenFootnote(cursor.pos());
1865 RemoveParagraph(row);
1866 /* set the dimensions of the cursor row */
1867 row->fill(Fill(bview, row, workWidth(bview)));
1868 SetHeightOfRow(bview, row);
1869 // CHECK See comment on top of text.C
1870 tmppar = tmppar->Next();
1872 while (tmppar != endpar) {
1874 InsertParagraph(bview, tmppar, row);
1875 while (row->next() && row->next()->par() == tmppar)
1877 tmppar = tmppar->Next();
1880 SetCursor(bview, par->next, 0);
1881 sel_cursor = cursor;
1886 // Just a macro to make some thing easier.
1887 void LyXText::RedoParagraph(BufferView * bview) const
1890 RedoParagraphs(bview, cursor, cursor.par()->Next());
1891 SetCursorIntern(bview, cursor.par(), cursor.pos());
1895 /* insert a character, moves all the following breaks in the
1896 * same Paragraph one to the right and make a rebreak */
1897 void LyXText::InsertChar(BufferView * bview, char c)
1899 SetUndo(bview->buffer(), Undo::INSERT,
1901 cursor.par()->ParFromPos(cursor.pos())->previous,
1902 cursor.par()->ParFromPos(cursor.pos())->next
1904 cursor.par()->previous,
1909 // When the free-spacing option is set for the current layout,
1910 // disable the double-space checking
1912 bool const freeSpacing =
1913 textclasslist.Style(bview->buffer()->params.textclass,
1914 cursor.row()->par()->GetLayout()).free_spacing;
1917 if (lyxrc.auto_number) {
1918 static string const number_operators = "+-/*";
1919 static string const number_unary_operators = "+-";
1920 static string const number_seperators = ".,:";
1922 if (current_font.number() == LyXFont::ON) {
1923 if (!isdigit(c) && !contains(number_operators, c) &&
1924 !(contains(number_seperators, c) &&
1925 cursor.pos() >= 1 &&
1926 cursor.pos() < cursor.par()->size() &&
1927 GetFont(bview->buffer(),
1929 cursor.pos()).number() == LyXFont::ON &&
1930 GetFont(bview->buffer(),
1932 cursor.pos()-1).number() == LyXFont::ON)
1934 Number(bview); // Set current_font.number to OFF
1935 } else if (isdigit(c) &&
1936 real_current_font.isVisibleRightToLeft()) {
1937 Number(bview); // Set current_font.number to ON
1939 if (cursor.pos() > 0) {
1940 char const c = cursor.par()->GetChar(cursor.pos() - 1);
1941 if (contains(number_unary_operators, c) &&
1942 (cursor.pos() == 1 ||
1943 cursor.par()->IsSeparator(cursor.pos() - 2) ||
1944 cursor.par()->IsNewline(cursor.pos() - 2) )
1946 SetCharFont(bview->buffer(),
1950 } else if (contains(number_seperators, c) &&
1951 cursor.pos() >= 2 &&
1952 GetFont(bview->buffer(),
1954 cursor.pos()-2).number() == LyXFont::ON) {
1955 SetCharFont(bview->buffer(),
1965 /* First check, if there will be two blanks together or a blank at
1966 the beginning of a paragraph.
1967 I decided to handle blanks like normal characters, the main
1968 difference are the special checks when calculating the row.fill
1969 (blank does not count at the end of a row) and the check here */
1971 // The bug is triggered when we type in a description environment:
1972 // The current_font is not changed when we go from label to main text
1973 // and it should (along with realtmpfont) when we type the space.
1974 // CHECK There is a bug here! (Asger)
1976 LyXFont realtmpfont = real_current_font;
1977 LyXFont rawtmpfont = current_font; /* store the current font.
1978 * This is because of the use
1979 * of cursor movements. The moving
1980 * cursor would refresh the
1983 // Get the font that is used to calculate the baselineskip
1984 LyXParagraph::size_type const lastpos = cursor.par()->Last();
1985 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
1988 bool jumped_over_space = false;
1990 if (!freeSpacing && IsLineSeparatorChar(c)) {
1991 if ((cursor.pos() > 0
1992 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
1993 || (cursor.pos() > 0
1994 && cursor.par()->IsNewline(cursor.pos() - 1))
1995 || (cursor.pos() == 0
1997 && !(cursor.par()->Previous()
1998 && cursor.par()->Previous()->footnoteflag
1999 == LyXParagraph::OPEN_FOOTNOTE)
2002 if (cursor.pos() == 0 )
2003 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2005 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2009 } else if (IsNewlineChar(c)) {
2011 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2013 if (cursor.par() == cursor.par()
2015 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2019 /* No newline at first position
2020 * of a paragraph or behind labels.
2021 * TeX does not allow that. */
2023 if (cursor.pos() < cursor.par()->Last() &&
2024 cursor.par()->IsLineSeparator(cursor.pos()))
2025 // newline always after a blank!
2027 cursor.row()->fill(-1); // to force a new break
2030 // the display inset stuff
2031 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2032 && cursor.row()->par()->GetInset(cursor.row()->pos())
2033 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2034 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2035 cursor.row()->fill(-1); // to force a new break
2037 // get the cursor row fist
2038 Row * row = cursor.row();
2039 int y = cursor.y() - row->baseline();
2040 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2041 * already insertet the character */
2042 cursor.par()->InsertChar(cursor.pos(), c);
2043 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2045 if (!jumped_over_space) {
2046 // refresh the positions
2048 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2049 tmprow = tmprow->next();
2050 tmprow->pos(tmprow->pos() + 1);
2054 // Is there a break one row above
2055 if ((cursor.par()->IsLineSeparator(cursor.pos())
2056 || cursor.par()->IsNewline(cursor.pos())
2057 || cursor.row()->fill() == -1)
2058 && row->previous() && row->previous()->par() == row->par()) {
2059 LyXParagraph::size_type z = NextBreakPoint(bview,
2062 if (z >= row->pos()) {
2065 // set the dimensions of the row above
2066 row->previous()->fill(Fill(bview,
2070 SetHeightOfRow(bview, row->previous());
2072 y -= row->previous()->height();
2074 refresh_row = row->previous();
2075 status = LyXText::NEED_MORE_REFRESH;
2077 BreakAgainOneRow(bview, row);
2079 current_font = rawtmpfont;
2080 real_current_font = realtmpfont;
2081 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2082 false, cursor.boundary());
2083 // cursor MUST be in row now.
2085 if (row->next() && row->next()->par() == row->par())
2086 need_break_row = row->next();
2090 // check, wether the last characters font has changed.
2091 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2092 && rawparfont != rawtmpfont)
2093 RedoHeightOfParagraph(bview, cursor);
2100 // recalculate the fill of the row
2101 if (row->fill() >= 0) /* needed because a newline
2102 * will set fill to -1. Otherwise
2103 * we would not get a rebreak! */
2104 row->fill(Fill(bview, row, workWidth(bview)));
2105 if (row->fill() < 0) {
2108 refresh_x = cursor.x();
2109 refresh_pos = cursor.pos();
2110 status = LyXText::NEED_MORE_REFRESH;
2111 BreakAgainOneRow(bview, row);
2112 // will the cursor be in another row now?
2113 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2114 if (row->next() && row->next()->par() == row->par())
2115 // this should always be true
2117 BreakAgainOneRow(bview, row);
2119 current_font = rawtmpfont;
2120 real_current_font = realtmpfont;
2122 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2124 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos())
2125 != cursor.boundary())
2126 SetCursor(bview, cursor.par(), cursor.pos(), false,
2127 !cursor.boundary());
2128 if (row->next() && row->next()->par() == row->par())
2129 need_break_row = row->next();
2134 refresh_x = cursor.x();
2136 refresh_pos = cursor.pos();
2138 int const tmpheight = row->height();
2139 SetHeightOfRow(bview, row);
2140 if (tmpheight == row->height())
2141 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2143 status = LyXText::NEED_MORE_REFRESH;
2145 current_font = rawtmpfont;
2146 real_current_font = realtmpfont;
2147 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2151 // check, wether the last characters font has changed.
2152 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2153 && rawparfont != rawtmpfont) {
2154 RedoHeightOfParagraph(bview, cursor);
2156 // now the special right address boxes
2157 if (textclasslist.Style(bview->buffer()->params.textclass,
2158 cursor.par()->GetLayout()).margintype
2159 == MARGIN_RIGHT_ADDRESS_BOX) {
2160 RedoDrawingOfParagraph(bview, cursor);
2168 void LyXText::charInserted()
2170 // Here we could call FinishUndo for every 20 characters inserted.
2171 // This is from my experience how emacs does it.
2172 static unsigned int counter = 0;
2182 void LyXText::PrepareToPrint(BufferView * bview,
2183 Row * row, float & x,
2184 float & fill_separator,
2186 float & fill_label_hfill,
2191 float w = row->fill();
2193 fill_label_hfill = 0;
2195 fill_label_hfill = 0;
2198 row->par()->isRightToLeftPar(bview->buffer()->params);
2202 x = RightMargin(bview->buffer(), row);
2203 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2204 LyXFont font(LyXFont::ALL_SANE);
2205 font.setSize(LyXFont::SIZE_SMALL);
2206 x += lyxfont::width("Mwide-figM", font);
2210 if (workWidth(bview) > 0)
2211 x = LeftMargin(bview, row);
2215 // is there a manual margin with a manual label
2216 if (textclasslist.Style(bview->buffer()->params.textclass,
2217 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2218 && textclasslist.Style(bview->buffer()->params.textclass,
2219 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2221 /* one more since labels are left aligned */
2222 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2223 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2224 fill_label_hfill = LabelFill(bview, row) / nlh;
2228 // are there any hfills in the row?
2229 float const nh = NumberOfHfills(bview->buffer(), row);
2232 fill_hfill = w / nh;
2234 // is it block, flushleft or flushright?
2235 // set x how you need it
2238 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2239 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2241 align = row->par()->FirstPhysicalPar()->align;
2243 if (row->par()->align == LYX_ALIGN_LAYOUT)
2244 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2246 align = row->par()->align;
2249 // center displayed insets
2251 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2252 && (inset=row->par()->GetInset(row->pos()))
2253 && (inset->display())) // || (inset->scroll() < 0)))
2254 align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
2255 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
2258 case LYX_ALIGN_BLOCK:
2259 ns = NumberOfSeparators(bview->buffer(), row);
2260 if (ns && row->next() && row->next()->par() == row->par() &&
2261 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2262 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2263 && row->next()->par()->GetInset(row->next()->pos())
2264 && row->next()->par()->GetInset(row->next()->pos())->display())
2266 fill_separator = w / ns;
2270 case LYX_ALIGN_RIGHT:
2273 case LYX_ALIGN_CENTER:
2281 ComputeBidiTables(bview->buffer(), row);
2283 LyXParagraph::size_type main_body =
2284 BeginningOfMainBody(bview->buffer(), row->par());
2285 LyXParagraph::size_type last = RowLast(row);
2287 if (main_body > 0 &&
2288 (main_body-1 > last ||
2289 !row->par()->IsLineSeparator(main_body-1))) {
2290 LyXLayout const & layout =
2291 textclasslist.Style(bview->buffer()->params.textclass,
2292 row->par()->GetLayout());
2293 x += lyxfont::width(layout.labelsep,
2294 GetFont(bview->buffer(), row->par(), -2));
2295 if (main_body-1 <= last)
2296 x += fill_label_hfill;
2301 /* important for the screen */
2304 /* the cursor set functions have a special mechanism. When they
2305 * realize, that you left an empty paragraph, they will delete it.
2306 * They also delete the corresponding row */
2308 void LyXText::CursorRightOneWord(BufferView * bview) const
2310 // treat floats, HFills and Insets as words
2311 LyXCursor tmpcursor = cursor;
2312 // CHECK See comment on top of text.C
2314 if (tmpcursor.pos() == tmpcursor.par()->Last()
2315 && tmpcursor.par()->Next()) {
2316 tmpcursor.par(tmpcursor.par()->Next());
2321 // Skip through initial nonword stuff.
2322 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2323 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2325 // printf("Current pos1 %d", tmpcursor.pos()) ;
2326 tmpcursor.pos(tmpcursor.pos() + 1);
2329 // Advance through word.
2330 while (tmpcursor.pos() < tmpcursor.par()->Last() &&
2331 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2333 // printf("Current pos2 %d", tmpcursor.pos()) ;
2334 tmpcursor.pos(tmpcursor.pos() + 1);
2338 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2342 void LyXText::CursorTab(BufferView * bview) const
2344 LyXCursor tmpcursor = cursor;
2345 while (tmpcursor.pos() < tmpcursor.par()->Last()
2346 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
2347 tmpcursor.pos(tmpcursor.pos() + 1);
2349 if (tmpcursor.pos() == tmpcursor.par()->Last()){
2350 if (tmpcursor.par()->Next()) {
2351 tmpcursor.par(tmpcursor.par()->Next());
2355 tmpcursor.pos(tmpcursor.pos() + 1);
2356 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2360 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2361 of prior word, not to end of next prior word. */
2363 void LyXText::CursorLeftOneWord(BufferView * bview) const
2365 // treat HFills, floats and Insets as words
2366 LyXCursor tmpcursor = cursor;
2367 while (tmpcursor.pos()
2368 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
2369 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
2370 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
2372 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2374 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
2375 tmpcursor.pos(tmpcursor.pos() - 1);
2378 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
2380 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2382 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
2383 tmpcursor.pos(tmpcursor.pos() - 1);
2384 } else if (!tmpcursor.pos()) {
2385 if (tmpcursor.par()->Previous()){
2386 tmpcursor.par(tmpcursor.par()->Previous());
2387 tmpcursor.pos(tmpcursor.par()->Last());
2389 } else { // Here, tmpcursor != 0
2390 while (tmpcursor.pos() > 0 &&
2391 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
2392 tmpcursor.pos(tmpcursor.pos() - 1);
2394 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2397 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2400 void LyXText::SelectWord(BufferView * bview)
2402 // Move cursor to the beginning, when not already there.
2404 && !cursor.par()->IsSeparator(cursor.pos()-1)
2405 && !cursor.par()->IsKomma(cursor.pos()-1) )
2406 CursorLeftOneWord(bview);
2408 // set the sel cursor
2409 sel_cursor = cursor;
2411 while (cursor.pos() < cursor.par()->Last()
2412 && !cursor.par()->IsSeparator(cursor.pos())
2413 && !cursor.par()->IsKomma(cursor.pos()) )
2414 cursor.pos(cursor.pos() + 1);
2415 SetCursor(bview, cursor.par(), cursor.pos() );
2417 // finally set the selection
2422 /* -------> Select the word currently under the cursor when:
2423 1: no selection is currently set,
2424 2: the cursor is not at the borders of the word. */
2426 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
2429 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
2430 && !cursor.par()->IsSeparator(cursor.pos())
2431 && !cursor.par()->IsKomma(cursor.pos())
2432 && !cursor.par()->IsSeparator(cursor.pos() -1)
2433 && !cursor.par()->IsKomma(cursor.pos() -1)) {
2441 // This function is only used by the spellchecker for NextWord().
2442 // It doesn't handle LYX_ACCENTs and probably never will.
2443 string const LyXText::SelectNextWord(BufferView * bview,
2444 float & value) const
2446 LyXParagraph * tmppar = cursor.par();
2448 // If this is not the very first word, skip rest of
2449 // current word because we are probably in the middle
2450 // of a word if there is text here.
2451 if (cursor.pos() || cursor.par()->previous) {
2452 while (cursor.pos() < cursor.par()->Last()
2453 && cursor.par()->IsLetter(cursor.pos()))
2454 cursor.pos(cursor.pos() + 1);
2456 // Now, skip until we have real text (will jump paragraphs)
2457 while ((cursor.par()->Last() > cursor.pos()
2458 && (!cursor.par()->IsLetter(cursor.pos())
2459 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
2460 .latex() == LyXFont::ON))
2461 || (cursor.par()->Last() == cursor.pos()
2462 && cursor.par()->Next())){
2463 if (cursor.pos() == cursor.par()->Last()) {
2464 cursor.par(cursor.par()->Next());
2467 cursor.pos(cursor.pos() + 1);
2470 // Update the value if we changed paragraphs
2471 if (cursor.par() != tmppar){
2472 SetCursor(bview, cursor.par(), cursor.pos());
2473 value = float(cursor.y())/float(height);
2476 // Start the selection from here
2477 sel_cursor = cursor;
2479 std::ostringstream latex;
2481 // and find the end of the word
2482 // (optional hyphens are part of a word)
2483 while (cursor.pos() < cursor.par()->Last()
2484 && (cursor.par()->IsLetter(cursor.pos()))
2485 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2486 && cursor.par()->GetInset(cursor.pos()) != 0
2487 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2488 && latex.str() == "\\-"
2490 cursor.pos(cursor.pos() + 1);
2492 // Finally, we copy the word to a string and return it
2494 if (sel_cursor.pos() < cursor.pos()) {
2495 LyXParagraph::size_type i;
2496 for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
2497 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
2498 str += cursor.par()->GetChar(i);
2505 // This one is also only for the spellchecker
2506 void LyXText::SelectSelectedWord(BufferView * bview)
2508 // move cursor to the beginning
2509 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
2511 // set the sel cursor
2512 sel_cursor = cursor;
2514 std::ostringstream latex;
2516 // now find the end of the word
2517 while (cursor.pos() < cursor.par()->Last()
2518 && (cursor.par()->IsLetter(cursor.pos())
2519 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2520 && cursor.par()->GetInset(cursor.pos()) != 0
2521 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2522 && latex.str() == "\\-"
2524 cursor.pos(cursor.pos() + 1);
2526 SetCursor(bview, cursor.par(), cursor.pos());
2528 // finally set the selection
2533 /* -------> Delete from cursor up to the end of the current or next word. */
2534 void LyXText::DeleteWordForward(BufferView * bview)
2536 if (!cursor.par()->Last())
2539 LyXCursor tmpcursor = cursor;
2540 tmpcursor.row(0); //Â ??
2541 selection = true; // to avoid deletion
2542 CursorRightOneWord(bview);
2543 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2544 sel_cursor = cursor;
2548 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2549 CutSelection(bview);
2554 /* -------> Delete from cursor to start of current or prior word. */
2555 void LyXText::DeleteWordBackward(BufferView * bview)
2557 if (!cursor.par()->Last())
2560 LyXCursor tmpcursor = cursor;
2561 tmpcursor.row(0); // ??
2562 selection = true; // to avoid deletion
2563 CursorLeftOneWord(bview);
2564 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2565 sel_cursor = cursor;
2568 CutSelection(bview);
2573 /* -------> Kill to end of line. */
2574 void LyXText::DeleteLineForward(BufferView * bview)
2576 if (!cursor.par()->Last())
2577 // Paragraph is empty, so we just go to the right
2580 LyXCursor tmpcursor = cursor;
2581 // We can't store the row over a regular SetCursor
2582 // so we set it to 0 and reset it afterwards.
2583 tmpcursor.row(0); //Â ??
2584 selection = true; // to avoid deletion
2586 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2587 sel_cursor = cursor;
2590 // What is this test for ??? (JMarc)
2592 DeleteWordForward(bview);
2594 CutSelection(bview);
2600 // Change the case of a word at cursor position.
2601 // This function directly manipulates LyXParagraph::text because there
2602 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2603 // that it is correct. I guess part of it should be moved to
2604 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2605 // it does not access outside of the allocated array as the older
2606 // version did. (JMarc)
2607 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
2610 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
2612 LyXParagraph * tmppar = cursor.par();
2615 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
2618 LyXParagraph::size_type tmppos =
2619 cursor.par()->PositionInParFromPos(cursor.pos());
2621 LyXParagraph::size_type tmppos = cursor.pos();
2623 while (tmppos < tmppar->size()) {
2624 unsigned char c = tmppar->GetChar(tmppos);
2625 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2627 if (c != LyXParagraph::META_INSET) {
2629 case text_lowercase:
2632 case text_capitalization:
2634 action = text_lowercase;
2636 case text_uppercase:
2642 //tmppar->text[tmppos] = c;
2643 tmppar->SetChar(tmppos, c);
2646 CheckParagraph(bview, tmppar, tmppos);
2647 CursorRightOneWord(bview);
2651 void LyXText::Delete(BufferView * bview)
2653 // this is a very easy implementation
2655 LyXCursor old_cursor = cursor;
2656 int const old_cur_par_id = old_cursor.par()->id();
2657 int const old_cur_par_prev_id = old_cursor.par()->previous ?
2658 old_cursor.par()->previous->id() : 0;
2660 // just move to the right
2663 // CHECK Look at the comment here.
2664 // This check is not very good...
2665 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2666 // and that can very well delete the par or par->previous in
2667 // old_cursor. Will a solution where we compare paragraph id's
2669 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
2670 == old_cur_par_prev_id
2671 && cursor.par()->id() != old_cur_par_id)
2672 return; // delete-empty-paragraph-mechanism has done it
2674 // if you had success make a backspace
2675 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2676 LyXCursor tmpcursor = cursor;
2677 cursor = old_cursor; // to make sure undo gets the right cursor position
2678 SetUndo(bview->buffer(), Undo::DELETE,
2680 cursor.par()->ParFromPos(cursor.pos())->previous,
2681 cursor.par()->ParFromPos(cursor.pos())->next
2683 cursor.par()->previous,
2693 void LyXText::Backspace(BufferView * bview)
2695 // Get the font that is used to calculate the baselineskip
2696 LyXParagraph::size_type lastpos = cursor.par()->Last();
2697 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2700 if (cursor.pos() == 0) {
2701 // The cursor is at the beginning of a paragraph,
2702 // so the the backspace will collapse two paragraphs into one.
2704 // we may paste some paragraphs
2706 // is it an empty paragraph?
2709 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
2711 && !(cursor.par()->Next()
2712 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
2713 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
2716 // This is an empty paragraph and we delete it just by moving the cursor one step
2717 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2718 // of the paragraph.
2720 if (cursor.par()->previous) {
2722 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
2724 LyXParagraph * tmppar = cursor.par()->previous;
2726 if (cursor.par()->GetLayout() == tmppar->GetLayout()
2728 && cursor.par()->footnoteflag == tmppar->footnoteflag
2730 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2731 // Inherit botom DTD from the paragraph below.
2732 // (the one we are deleting)
2733 tmppar->line_bottom = cursor.par()->line_bottom;
2734 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
2735 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
2740 // the layout things can change the height of a row !
2741 int const tmpheight = cursor.row()->height();
2742 SetHeightOfRow(bview, cursor.row());
2743 if (cursor.row()->height() != tmpheight) {
2744 refresh_y = cursor.y() - cursor.row()->baseline();
2745 refresh_row = cursor.row();
2746 status = LyXText::NEED_MORE_REFRESH;
2753 if (cursor.par()->ParFromPos(cursor.pos())->previous){
2754 SetUndo(bview->buffer(), Undo::DELETE,
2755 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
2756 cursor.par()->ParFromPos(cursor.pos())->next);
2759 if (cursor.par()->previous) {
2760 SetUndo(bview->buffer(), Undo::DELETE,
2761 cursor.par()->previous->previous,
2762 cursor.par()->next);
2766 LyXParagraph * tmppar = cursor.par();
2767 Row * tmprow = cursor.row();
2769 // We used to do CursorLeftIntern() here, but it is
2770 // not a good idea since it triggers the auto-delete
2771 // mechanism. So we do a CursorLeftIntern()-lite,
2772 // without the dreaded mechanism. (JMarc)
2773 if (cursor.par()->Previous()) {
2774 // steps into the above paragraph.
2775 SetCursorIntern(bview, cursor.par()->Previous(),
2776 cursor.par()->Previous()->Last(), false);
2779 /* Pasting is not allowed, if the paragraphs have different
2780 layout. I think it is a real bug of all other
2781 word processors to allow it. It confuses the user.
2782 Even so with a footnote paragraph and a non-footnote
2783 paragraph. I will not allow pasting in this case,
2784 because the user would be confused if the footnote behaves
2785 different wether it is open or closed.
2787 Correction: Pasting is always allowed with standard-layout
2789 if (cursor.par() != tmppar
2790 && (cursor.par()->GetLayout() == tmppar->GetLayout()
2791 || tmppar->GetLayout() == 0 /*standard*/)
2793 && cursor.par()->footnoteflag == tmppar->footnoteflag
2795 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2797 RemoveParagraph(tmprow);
2799 cursor.par()->PasteParagraph(bview->buffer()->params);
2801 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
2802 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
2803 // strangely enough it seems that commenting out the line above removes
2804 // most or all of the segfaults. I will however also try to move the
2805 // two Remove... lines in front of the PasteParagraph too.
2808 cursor.pos(cursor.pos() - 1);
2810 status = LyXText::NEED_MORE_REFRESH;
2811 refresh_row = cursor.row();
2812 refresh_y = cursor.y() - cursor.row()->baseline();
2814 // remove the lost paragraph
2815 // This one is not safe, since the paragraph that the tmprow and the
2816 // following rows belong to has been deleted by the PasteParagraph
2817 // above. The question is... could this be moved in front of the
2819 //RemoveParagraph(tmprow);
2820 //RemoveRow(tmprow);
2822 // This rebuilds the rows.
2823 AppendParagraph(bview, cursor.row());
2824 UpdateCounters(bview, cursor.row());
2826 // the row may have changed, block, hfills etc.
2827 SetCursor(bview, cursor.par(), cursor.pos(), false);
2830 /* this is the code for a normal backspace, not pasting
2832 SetUndo(bview->buffer(), Undo::DELETE,
2834 cursor.par()->ParFromPos(cursor.pos())->previous,
2835 cursor.par()->ParFromPos(cursor.pos())->next
2837 cursor.par()->previous,
2841 // We used to do CursorLeftIntern() here, but it is
2842 // not a good idea since it triggers the auto-delete
2843 // mechanism. So we do a CursorLeftIntern()-lite,
2844 // without the dreaded mechanism. (JMarc)
2845 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
2846 false, cursor.boundary());
2848 // some insets are undeletable here
2849 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2850 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2852 // force complete redo when erasing display insets
2853 // this is a cruel method but safe..... Matthias
2854 if (cursor.par()->GetInset(cursor.pos())->display() ||
2855 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
2856 cursor.par()->Erase(cursor.pos());
2857 RedoParagraph(bview);
2862 Row * row = cursor.row();
2863 int y = cursor.y() - row->baseline();
2864 LyXParagraph::size_type z;
2865 /* remember that a space at the end of a row doesnt count
2866 * when calculating the fill */
2867 if (cursor.pos() < RowLast(row) ||
2868 !cursor.par()->IsLineSeparator(cursor.pos())) {
2869 row->fill(row->fill() + SingleWidth(bview,
2874 /* some special code when deleting a newline. This is similar
2875 * to the behavior when pasting paragraphs */
2876 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
2877 cursor.par()->Erase(cursor.pos());
2878 // refresh the positions
2880 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2881 tmprow = tmprow->next();
2882 tmprow->pos(tmprow->pos() - 1);
2884 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
2885 cursor.pos(cursor.pos() - 1);
2887 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
2888 cursor.par()->InsertChar(cursor.pos(), ' ');
2889 SetCharFont(bview->buffer(), cursor.par(),
2890 cursor.pos(), current_font);
2891 // refresh the positions
2893 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2894 tmprow = tmprow->next();
2895 tmprow->pos(tmprow->pos() + 1);
2899 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);
2909 // delete newlines at the beginning of paragraphs
2910 while (cursor.par()->Last() &&
2911 cursor.par()->IsNewline(cursor.pos()) &&
2912 cursor.pos() == BeginningOfMainBody(bview->buffer(),
2914 cursor.par()->Erase(cursor.pos());
2915 // refresh the positions
2917 while (tmprow->next() &&
2918 tmprow->next()->par() == row->par()) {
2919 tmprow = tmprow->next();
2920 tmprow->pos(tmprow->pos() - 1);
2925 // is there a break one row above
2926 if (row->previous() && row->previous()->par() == row->par()) {
2927 z = NextBreakPoint(bview, row->previous(),
2929 if (z >= row->pos()) {
2932 Row * tmprow = row->previous();
2934 // maybe the current row is now empty
2935 if (row->pos() >= row->par()->Last()) {
2940 BreakAgainOneRow(bview, row);
2941 if (row->next() && row->next()->par() == row->par())
2942 need_break_row = row->next();
2947 // set the dimensions of the row above
2948 y -= tmprow->height();
2949 tmprow->fill(Fill(bview, tmprow,
2951 SetHeightOfRow(bview, tmprow);
2954 refresh_row = tmprow;
2955 status = LyXText::NEED_MORE_REFRESH;
2956 SetCursor(bview, cursor.par(), cursor.pos(),
2957 false, cursor.boundary());
2958 //current_font = rawtmpfont;
2959 //real_current_font = realtmpfont;
2960 // check, whether the last character's font has changed.
2962 cursor.par()->GetFontSettings(bview->buffer()->params,
2963 cursor.par()->Last() - 1))
2964 RedoHeightOfParagraph(bview, cursor);
2969 // break the cursor row again
2970 if (row->next() && row->next()->par() == row->par() &&
2971 (RowLast(row) == row->par()->Last() - 1 ||
2972 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
2974 /* it can happen that a paragraph loses one row
2975 * without a real breakup. This is when a word
2976 * is to long to be broken. Well, I don t care this
2978 if (RowLast(row) == row->par()->Last() - 1)
2979 RemoveRow(row->next());
2983 status = LyXText::NEED_MORE_REFRESH;
2985 BreakAgainOneRow(bview, row);
2986 // will the cursor be in another row now?
2987 if (row->next() && row->next()->par() == row->par() &&
2988 RowLast(row) <= cursor.pos()) {
2990 BreakAgainOneRow(bview, row);
2993 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2995 if (row->next() && row->next()->par() == row->par())
2996 need_break_row = row->next();
3000 // set the dimensions of the row
3001 row->fill(Fill(bview, row, workWidth(bview)));
3002 int const tmpheight = row->height();
3003 SetHeightOfRow(bview, row);
3004 if (tmpheight == row->height())
3005 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3007 status = LyXText::NEED_MORE_REFRESH;
3010 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3014 // current_font = rawtmpfont;
3015 // real_current_font = realtmpfont;
3017 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos())
3018 != cursor.boundary())
3019 SetCursor(bview, cursor.par(), cursor.pos(), false,
3020 !cursor.boundary());
3022 lastpos = cursor.par()->Last();
3023 if (cursor.pos() == lastpos)
3024 SetCurrentFont(bview);
3026 // check, whether the last characters font has changed.
3028 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3029 RedoHeightOfParagraph(bview, cursor);
3031 // now the special right address boxes
3032 if (textclasslist.Style(bview->buffer()->params.textclass,
3033 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3034 RedoDrawingOfParagraph(bview, cursor);
3040 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3041 Row * row_ptr, int y, bool cleared)
3043 /* returns a printed row */
3044 Painter & pain = bview->painter();
3047 row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3049 LyXParagraph::size_type const last = RowLastPrintable(row_ptr);
3051 LyXParagraph::size_type vpos, pos;
3057 LyXFont font(LyXFont::ALL_SANE);
3059 if (row_ptr->height() <= 0) {
3060 lyxerr << "LYX_ERROR: row.height: "
3061 << row_ptr->height() << endl;
3065 float fill_separator;
3067 float fill_label_hfill;
3068 PrepareToPrint(bview, row_ptr, x, fill_separator,
3069 fill_hfill, fill_label_hfill);
3071 if (inset_owner && (x < 0))
3075 // clear the area where we want to paint/print
3076 int ww = bview->workWidth();
3078 bool clear_area = true;
3081 if (!bview->screen()->forceClear() && last == row_ptr->pos()
3082 && row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET
3083 && (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
3084 clear_area = inset->doClearArea();
3086 // we don't need to clear it's already done!!!
3089 } else if (clear_area) {
3090 #ifdef WITH_WARNINGS
3091 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
3092 #warning Should we not fix this in the Painter, please have a look Lars! (Jug)
3094 int w = (inset_owner ? inset_owner->width(bview, font)-2 : ww);
3095 int h = row_ptr->height();
3103 pain.fillRectangle(x, y, w, h);
3104 } else if (inset != 0) {
3105 int h = row_ptr->baseline() - inset->ascent(bview, font);
3107 int const w = (inset_owner ?
3108 inset_owner->width(bview, font) : ww);
3109 pain.fillRectangle(x_offset, y_offset, w, h);
3111 h += inset->ascent(bview, font) + inset->descent(bview, font);
3112 if ((row_ptr->height() - h) > 0) {
3113 int const w = (inset_owner ?
3114 inset_owner->width(bview, font) : ww);
3115 pain.fillRectangle(x_offset, y_offset + h,
3116 w, row_ptr->height() - h);
3118 if (!inset_owner && !inset->display() && !inset->needFullRow())
3120 int const w = inset->width(bview, font) + int(x);
3121 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3126 int const w = (inset_owner ?
3127 inset_owner->width(bview, font) : ww);
3128 /* selection code */
3129 if (bidi_same_direction) {
3130 if (sel_start_cursor.row() == row_ptr &&
3131 sel_end_cursor.row() == row_ptr) {
3132 if (sel_start_cursor.x() < sel_end_cursor.x())
3133 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3135 sel_end_cursor.x() - sel_start_cursor.x(),
3139 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3141 sel_start_cursor.x() - sel_end_cursor.x(),
3144 } else if (sel_start_cursor.row() == row_ptr) {
3146 pain.fillRectangle(x_offset, y_offset,
3147 sel_start_cursor.x(),
3151 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3153 w - sel_start_cursor.x(),
3156 } else if (sel_end_cursor.row() == row_ptr) {
3158 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3160 w - sel_end_cursor.x(),
3164 pain.fillRectangle(x_offset, y_offset,
3168 } else if (y > sel_start_cursor.y()
3169 && y < sel_end_cursor.y()) {
3170 pain.fillRectangle(x_offset, y_offset, w,
3174 } else if (sel_start_cursor.row() != row_ptr &&
3175 sel_end_cursor.row() != row_ptr &&
3176 y > sel_start_cursor.y()
3177 && y < sel_end_cursor.y()) {
3178 pain.fillRectangle(x_offset, y_offset, w,
3181 } else if (sel_start_cursor.row() == row_ptr ||
3182 sel_end_cursor.row() == row_ptr) {
3184 if ((sel_start_cursor.row() != row_ptr && !is_rtl) ||
3185 (sel_end_cursor.row() != row_ptr && is_rtl))
3186 pain.fillRectangle(x_offset, y_offset,
3190 LyXParagraph::size_type main_body =
3191 BeginningOfMainBody(bview->buffer(),
3194 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3195 pos = vis2log(vpos);
3196 float const old_tmpx = tmpx;
3197 if (main_body > 0 && pos == main_body-1) {
3198 tmpx += fill_label_hfill +
3199 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3200 row_ptr->par()->GetLayout()).labelsep,
3201 GetFont(bview->buffer(),row_ptr->par(), -2));
3202 if (row_ptr->par()->IsLineSeparator(main_body-1))
3203 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3205 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3206 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3207 if (pos >= main_body)
3210 tmpx += fill_label_hfill;
3212 else if (row_ptr->par()->IsSeparator(pos)) {
3213 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3214 if (pos >= main_body)
3215 tmpx += fill_separator;
3217 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3219 if ((sel_start_cursor.row() != row_ptr ||
3220 sel_start_cursor.pos() <= pos) &&
3221 (sel_end_cursor.row() != row_ptr ||
3222 pos < sel_end_cursor.pos()) )
3223 pain.fillRectangle(x_offset + int(old_tmpx),
3225 int(tmpx - old_tmpx + 1),
3230 if ((sel_start_cursor.row() != row_ptr && is_rtl) ||
3231 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3232 pain.fillRectangle(x_offset + int(tmpx),
3242 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3243 LyXFont font(LyXFont::ALL_SANE);
3244 font.setSize(LyXFont::SIZE_FOOTNOTE);
3245 font.setColor(LColor::footnote);
3247 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3248 if (row_ptr->previous() &&
3249 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3251 switch (row_ptr->par()->footnotekind) {
3252 case LyXParagraph::MARGIN:
3255 case LyXParagraph::FIG:
3258 case LyXParagraph::TAB:
3261 case LyXParagraph::WIDE_FIG:
3264 case LyXParagraph::WIDE_TAB:
3267 case LyXParagraph::ALGORITHM:
3270 case LyXParagraph::FOOTNOTE:
3275 pain.fillRectangle(LYX_PAPER_MARGIN,
3277 box_x - LYX_PAPER_MARGIN,
3278 int(lyxfont::maxAscent(font)
3279 + lyxfont::maxDescent(font)),
3280 LColor::footnotebg);
3282 pain.line(LYX_PAPER_MARGIN, y_offset,
3283 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3284 LColor::footnoteframe);
3286 pain.text(LYX_PAPER_MARGIN,
3287 y_offset + int(lyxfont::maxAscent(font)) + 1,
3290 pain.line(LYX_PAPER_MARGIN, y_offset,
3292 y_offset + int(lyxfont::maxAscent(font)
3293 + lyxfont::maxDescent(font)),
3294 LColor::footnoteframe);
3296 pain.line(LYX_PAPER_MARGIN,
3297 y_offset + int(lyxfont::maxAscent(font)
3298 + lyxfont::maxDescent(font)) + 1,
3300 y_offset + int(lyxfont::maxAscent(font)
3301 + lyxfont::maxDescent(font)) + 1,
3302 LColor::footnoteframe);
3306 /* draw the open floats in a red box */
3307 pain.line(box_x, y_offset,
3308 box_x, y_offset + row_ptr->height(),
3309 LColor::footnoteframe);
3311 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
3313 workWidth(bview) - LYX_PAPER_MARGIN,
3314 y_offset + row_ptr->height(),
3315 LColor::footnoteframe);
3318 // Draw appendix lines
3319 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
3321 pain.line(1, y_offset,
3322 1, y_offset + row_ptr->height(),
3323 LColor::appendixline);
3324 pain.line(workWidth(bview) - 2, y_offset,
3325 workWidth(bview) - 2,
3326 y_offset + row_ptr->height(),
3327 LColor::appendixline);
3330 // Draw minipage line
3331 bool const minipage =
3332 (p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3334 pain.line(LYX_PAPER_MARGIN/5, y_offset,
3336 y_offset + row_ptr->height() - 1,
3337 LColor::minipageline);
3340 int const depth = p->GetDepth();
3341 for (int i = 1; i <= depth; ++i) {
3342 int const line_x = (LYX_PAPER_MARGIN / 5) *
3344 pain.line(line_x, y_offset, line_x,
3345 y_offset + row_ptr->height() - 1,
3348 } else if (row_ptr->previous() &&
3349 row_ptr->previous()->par()->footnoteflag
3350 == LyXParagraph::OPEN_FOOTNOTE) {
3351 LyXFont font(LyXFont::ALL_SANE);
3352 font.setSize(LyXFont::SIZE_FOOTNOTE);
3354 int const box_x = LYX_PAPER_MARGIN
3355 + lyxfont::width(" wide-tab ", font);
3357 pain.line(box_x, y_offset,
3358 workWidth(bview) - LYX_PAPER_MARGIN,
3359 y_offset, LColor::footnote);
3362 // Draw appendix lines
3364 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
3366 LyXParagraph * firstpar = row_ptr->par();
3368 if (firstpar->appendix){
3369 pain.line(1, y_offset,
3370 1, y_offset + row_ptr->height(),
3371 LColor::appendixline);
3372 pain.line(ww - 2, y_offset,
3373 ww - 2, y_offset + row_ptr->height(),
3374 LColor::appendixline);
3377 // Draw minipage line
3378 bool const minipage =
3379 (firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE);
3381 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
3382 LYX_PAPER_MARGIN/5 + box_x,
3383 y_offset + row_ptr->height() - 1,
3384 LColor::minipageline);
3387 int const depth = firstpar->GetDepth();
3391 if (row_ptr->next())
3393 if (row_ptr->par()->footnoteflag ==
3394 row_ptr->next()->par()->footnoteflag)
3395 next_depth = row_ptr->next()->par()->GetDepth();
3396 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3399 next_depth = row_ptr->next()->par()->GetDepth();
3401 if (row_ptr->previous())
3403 if (row_ptr->par()->footnoteflag ==
3404 row_ptr->previous()->par()->footnoteflag)
3405 prev_depth = row_ptr->previous()->par()->GetDepth();
3406 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3409 prev_depth = row_ptr->previous()->par()->GetDepth();
3412 for (int i = 1; i <= depth; ++i) {
3413 int const line_x = (LYX_PAPER_MARGIN / 5) *
3414 (i + minipage) + box_x + x_offset;
3415 pain.line(line_x, y_offset, line_x,
3416 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
3420 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
3423 pain.fillRectangle(line_x,
3424 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
3425 LYX_PAPER_MARGIN / 5, 2,
3431 LyXLayout const & layout =
3432 textclasslist.Style(bview->buffer()->params.textclass,
3433 row_ptr->par()->GetLayout());
3436 y_bottom = row_ptr->height();
3438 /* is it a first row? */
3439 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
3441 /* start of appendix? */
3442 if (row_ptr->par()->start_of_appendix){
3443 pain.line(1, y_offset,
3445 LColor::appendixline);
3448 /* think about the margins */
3449 if (!row_ptr->previous() && bv_owner)
3450 y_top += LYX_PAPER_MARGIN;
3452 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
3454 pb_font.setColor(LColor::pagebreak).decSize();
3455 int w = 0, a = 0, d = 0;
3456 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
3458 y_offset + y_top + 2 * DefaultHeight(),
3460 Painter::line_onoffdash)
3463 _("Page Break (top)"),
3466 LColor::background, false, w, a, d);
3467 pain.rectText((ww - w)/2,
3468 y_offset + y_top + 2 * DefaultHeight() + d,
3469 _("Page Break (top)"),
3472 LColor::background);
3473 y_top += 3 * DefaultHeight();
3476 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
3477 /* draw a vfill top */
3478 pain.line(0, y_offset + 2 + y_top,
3479 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
3482 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
3484 y_offset + y_top + 3 * DefaultHeight(),
3487 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
3488 LYX_PAPER_MARGIN / 2,
3489 y_offset + y_top + 3 * DefaultHeight(),
3492 y_top += 3 * DefaultHeight();
3495 /* think about user added space */
3496 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
3498 /* think about the parskip */
3499 /* some parskips VERY EASY IMPLEMENTATION */
3500 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3501 if (layout.latextype == LATEX_PARAGRAPH
3502 && firstpar->GetDepth() == 0
3503 && firstpar->Previous())
3504 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3505 else if (firstpar->Previous()
3506 && textclasslist.Style(bview->buffer()->params.textclass,
3507 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3508 && firstpar->Previous()->GetDepth() == 0)
3509 // is it right to use defskip here, too? (AS)
3510 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3513 if (row_ptr->par()->line_top) { /* draw a top line */
3514 y_top += lyxfont::ascent('x',
3515 GetFont(bview->buffer(),
3516 row_ptr->par(), 0));
3517 int const w = (inset_owner ?
3518 inset_owner->width(bview, font) : ww);
3519 int const xp = static_cast<int>(inset_owner ? x : 0);
3520 pain.line(xp, y_offset + y_top,
3521 w, y_offset + y_top,
3523 Painter::line_solid,
3524 Painter::line_thick);
3526 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
3527 row_ptr->par(), 0));
3530 /* should we print a label? */
3531 if (layout.labeltype >= LABEL_STATIC
3532 && (layout.labeltype != LABEL_STATIC
3533 || layout.latextype != LATEX_ENVIRONMENT
3534 || row_ptr->par()->IsFirstInSequence())) {
3535 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3536 if (!row_ptr->par()->GetLabelstring().empty()) {
3538 string const tmpstring =
3539 row_ptr->par()->GetLabelstring();
3541 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3542 if (bview->buffer()->params.secnumdepth >= 0) {
3543 /* this is special code for the chapter layout. This is printed in
3544 * an extra row and has a pagebreak at the top. */
3545 float spacing_val = 1.0;
3546 if (!row_ptr->par()->spacing.isDefault()) {
3547 spacing_val = row_ptr->par()->spacing.getValue();
3549 spacing_val = bview->buffer()->params.spacing.getValue();
3552 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3553 + int(layout.parsep) * DefaultHeight();
3555 tmpx = ww - LeftMargin(bview, row_ptr) -
3556 lyxfont::width(tmpstring, font);
3557 pain.text(int(tmpx),
3558 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
3563 tmpx = ww - LeftMargin(bview, row_ptr)
3564 + lyxfont::width(layout.labelsep, font);
3566 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3567 LyXFont font(LyXFont::ALL_SANE);
3568 font.setSize(LyXFont::SIZE_SMALL);
3569 tmpx += lyxfont::width("Mwide-fixM", font);
3573 tmpx = x - lyxfont::width(layout.labelsep, font)
3574 - lyxfont::width(tmpstring, font);
3577 pain.text(int(tmpx),
3578 y_offset + row_ptr->baseline(),
3582 /* the labels at the top of an environment. More or less for bibliography */
3583 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3584 layout.labeltype == LABEL_BIBLIO ||
3585 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3586 if (row_ptr->par()->IsFirstInSequence()) {
3587 font = GetFont(bview->buffer(),
3588 row_ptr->par(), -2);
3589 if (!row_ptr->par()->GetLabelstring().empty()) {
3590 string const tmpstring =
3591 row_ptr->par()->GetLabelstring();
3592 float spacing_val = 1.0;
3593 if (!row_ptr->par()->spacing.isDefault()) {
3594 spacing_val = row_ptr->par()->spacing.getValue();
3596 spacing_val = bview->buffer()->params.spacing.getValue();
3599 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3600 + (layout.labelbottomsep * DefaultHeight()));
3603 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3604 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
3605 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
3606 tmpx -= lyxfont::width(tmpstring, font) / 2;
3608 tmpx = ww - LeftMargin(bview, row_ptr) -
3609 lyxfont::width(tmpstring, font);
3610 pain.text(int(tmpx),
3611 y_offset + row_ptr->baseline()
3612 - row_ptr->ascent_of_text()
3618 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
3619 font = GetFont(bview->buffer(), row_ptr->par(), -1);
3621 tmpx = ww - LeftMargin(bview, row_ptr)
3622 + lyxfont::width(layout.labelsep, font);
3624 tmpx = x - lyxfont::width(layout.labelsep, font)
3625 - row_ptr->par()->bibkey->width(bview, font);
3626 row_ptr->par()->bibkey->draw(bview, font,
3627 y_offset + row_ptr->baseline(),
3632 /* is it a last row? */
3634 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
3636 LyXParagraph * par = row_ptr->par();
3640 row_ptr->par()->ParFromPos(last + 1) == par
3642 row_ptr->par() == par
3644 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par()))
3646 /* think about the margins */
3647 if (!row_ptr->next() && bv_owner)
3648 y_bottom -= LYX_PAPER_MARGIN;
3650 /* draw a bottom pagebreak */
3651 if (firstpar->pagebreak_bottom) {
3653 pb_font.setColor(LColor::pagebreak).decSize();
3654 int w = 0, a = 0, d = 0;
3656 y_offset + y_bottom - 2 * DefaultHeight(),
3658 y_offset + y_bottom - 2 * DefaultHeight(),
3660 Painter::line_onoffdash)
3663 _("Page Break (bottom)"),
3666 LColor::background, false, w, a, d);
3667 pain.rectText((ww - w) / 2,
3668 y_offset + y_top + 2 * DefaultHeight() + d,
3669 _("Page Break (bottom)"),
3672 LColor::background);
3673 y_bottom -= 3 * DefaultHeight();
3676 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3677 /* draw a vfill bottom */
3678 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
3680 y_offset + y_bottom - 3 * DefaultHeight(),
3682 pain.line(0, y_offset + y_bottom - 2,
3684 y_offset + y_bottom - 2,
3686 pain.line(LYX_PAPER_MARGIN / 2,
3687 y_offset + y_bottom - 3 * DefaultHeight(),
3688 LYX_PAPER_MARGIN / 2,
3689 y_offset + y_bottom - 2,
3691 y_bottom -= 3 * DefaultHeight();
3694 /* think about user added space */
3695 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
3697 if (firstpar->line_bottom) {
3698 /* draw a bottom line */
3699 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3700 par, par->Last() - 1));
3701 int const w = (inset_owner ?
3702 inset_owner->width(bview, font) : ww);
3703 int const xp = static_cast<int>(inset_owner ? x : 0);
3704 pain.line(xp, y_offset + y_bottom,
3705 w, y_offset + y_bottom,
3706 LColor::topline, Painter::line_solid,
3707 Painter::line_thick);
3708 y_bottom -= lyxfont::ascent('x',
3709 GetFont(bview->buffer(),
3715 int const endlabel =
3716 row_ptr->par()->GetEndLabel(bview->buffer()->params);
3719 case END_LABEL_FILLED_BOX:
3721 LyXFont const font = GetFont(bview->buffer(),
3722 row_ptr->par(), last);
3723 int const size = int(0.75 * lyxfont::maxAscent(font));
3724 int const y = (y_offset + row_ptr->baseline()) - size;
3725 int x = is_rtl ? LYX_PAPER_MARGIN
3726 : ww - LYX_PAPER_MARGIN - size;
3728 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3730 LyXFont font(LyXFont::ALL_SANE);
3731 font.setSize(LyXFont::SIZE_SMALL);
3732 x += lyxfont::width("Mwide-figM", font);
3734 x -= LYX_PAPER_MARGIN/2;
3736 if (row_ptr->fill() <= size)
3737 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
3738 if (endlabel == END_LABEL_BOX) {
3739 pain.line(x, y, x, y + size,
3741 pain.line(x + size, y, x + size , y + size,
3743 pain.line(x, y, x + size, y,
3745 pain.line(x, y + size, x + size, y + size,
3748 pain.fillRectangle(x, y, size, size,
3752 case END_LABEL_STATIC:
3754 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
3755 string const tmpstring = textclasslist.
3756 Style(bview->buffer()->params.textclass,
3757 layout).endlabelstring();
3758 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3759 int const tmpx = is_rtl ?
3760 int(x) - lyxfont::width(tmpstring, font)
3761 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
3762 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
3765 case END_LABEL_NO_LABEL:
3770 /* draw the text in the pixmap */
3772 vpos = row_ptr->pos();
3774 LyXParagraph::size_type main_body =
3775 BeginningOfMainBody(bview->buffer(), row_ptr->par());
3776 if (main_body > 0 &&
3777 (main_body-1 > last ||
3778 !row_ptr->par()->IsLineSeparator(main_body - 1)))
3781 while (vpos <= last) {
3782 pos = vis2log(vpos);
3783 if (main_body > 0 && pos == main_body - 1) {
3784 x += fill_label_hfill
3785 + lyxfont::width(layout.labelsep,
3786 GetFont(bview->buffer(),
3787 row_ptr->par(), -2))
3788 - SingleWidth(bview,
3793 if (row_ptr->par() ->IsHfill(pos)) {
3796 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3798 y_offset + row_ptr->baseline(),
3801 if (HfillExpansion(bview->buffer(),
3803 if (pos >= main_body) {
3805 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3806 int(x + fill_hfill),
3807 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3809 Painter::line_onoffdash);
3813 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3814 int(x + fill_label_hfill),
3815 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3817 Painter::line_onoffdash);
3819 x += fill_label_hfill;
3822 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3824 y_offset + row_ptr->baseline(),
3829 } else if (row_ptr->par()->IsSeparator(pos)) {
3830 x += SingleWidth(bview,
3831 row_ptr->par(), pos);
3832 if (pos >= main_body)
3833 x += fill_separator;
3836 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
3841 int LyXText::DefaultHeight() const
3843 LyXFont font(LyXFont::ALL_SANE);
3844 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
3848 /* returns the column near the specified x-coordinate of the row
3849 * x is set to the real beginning of this column */
3850 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
3851 bool & boundary) const
3854 float fill_separator, fill_hfill, fill_label_hfill;
3856 PrepareToPrint(bview, row, tmpx, fill_separator,
3857 fill_hfill, fill_label_hfill);
3859 LyXParagraph::size_type vc = row->pos();
3860 LyXParagraph::size_type last = RowLastPrintable(row);
3861 LyXParagraph::size_type c = 0;
3862 LyXLayout const & layout =
3863 textclasslist.Style(bview->buffer()->params.textclass,
3864 row->par()->GetLayout());
3865 bool left_side = false;
3867 LyXParagraph::size_type
3868 main_body = BeginningOfMainBody(bview->buffer(), row->par());
3869 float last_tmpx = tmpx;
3871 if (main_body > 0 &&
3872 (main_body-1 > last ||
3873 !row->par()->IsLineSeparator(main_body - 1)))
3876 while (vc <= last && tmpx <= x) {
3879 if (main_body > 0 && c == main_body-1) {
3880 tmpx += fill_label_hfill +
3881 lyxfont::width(layout.labelsep,
3882 GetFont(bview->buffer(), row->par(), -2));
3883 if (row->par()->IsLineSeparator(main_body - 1))
3884 tmpx -= SingleWidth(bview, row->par(), main_body-1);
3887 if (HfillExpansion(bview->buffer(), row, c)) {
3888 x += SingleWidth(bview, row->par(), c);
3892 tmpx += fill_label_hfill;
3894 else if (row->par()->IsSeparator(c)) {
3895 tmpx += SingleWidth(bview, row->par(), c);
3897 tmpx+= fill_separator;
3899 tmpx += SingleWidth(bview, row->par(), c);
3903 if ((tmpx + last_tmpx) / 2 > x) {
3908 if (vc > last + 1) // This shouldn't happen.
3912 bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
3913 // some speedup if rtl_support=false
3914 && (!row->next() || row->next()->par() != row->par());
3915 bool const rtl = (lastrow)
3916 ? row->par()->isRightToLeftPar(bview->buffer()->params)
3917 : false; // If lastrow is false, we don't need to compute
3918 // the value of rtl.
3920 if (row->pos() > last) // Row is empty?
3923 ( ( rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
3924 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5) ))
3926 else if (vc == row->pos()) {
3928 if (bidi_level(c) % 2 == 1)
3931 c = vis2log(vc - 1);
3932 bool const rtl = (bidi_level(c) % 2 == 1);
3933 if (left_side == rtl) {
3935 boundary = IsBoundary(bview->buffer(), row->par(), c);
3939 if (row->pos() <= last && c > last
3940 && row->par()->IsNewline(last)) {
3941 if (bidi_level(last) % 2 == 0)
3942 tmpx -= SingleWidth(bview, row->par(), last);
3944 tmpx += SingleWidth(bview, row->par(), last);
3955 /* turn the selection into a new environment. If there is no selection,
3956 * create an empty environment */
3957 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
3958 LyXParagraph::footnote_kind kind)
3960 /* no footnoteenvironment in a footnoteenvironment */
3961 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3962 WriteAlert(_("Impossible operation"),
3963 _("You can't insert a float in a float!"),
3967 /* no marginpars in minipages */
3968 if (kind == LyXParagraph::MARGIN
3969 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3970 WriteAlert(_("Impossible operation"),
3971 _("You can't insert a marginpar in a minipage!"),
3976 /* this doesnt make sense, if there is no selection */
3977 bool dummy_selection = false;
3979 sel_start_cursor = cursor; /* dummy selection */
3980 sel_end_cursor = cursor;
3981 dummy_selection = true;
3984 LyXParagraph * tmppar;
3986 /* a test to make sure there is not already a footnote
3987 * in the selection. */
3989 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
3991 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
3992 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3993 tmppar = tmppar->next;
3995 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
3996 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3997 WriteAlert(_("Impossible operation"),
3998 _("Float would include float!"),
4003 /* ok we have a selection. This is always between sel_start_cursor
4004 * and sel_end cursor */
4006 SetUndo(bview->buffer(), Undo::FINISH,
4007 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4008 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4010 if (sel_end_cursor.pos() > 0
4011 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4012 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4013 /* please break before a space at the end */
4014 if (sel_start_cursor.par() == sel_end_cursor.par()
4015 && sel_start_cursor.pos() > sel_end_cursor.pos())
4016 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4018 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4020 sel_end_cursor.par(sel_end_cursor.par()->Next());
4021 sel_end_cursor.pos(0);
4023 // don't forget to insert a dummy layout paragraph if necessary
4024 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4025 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4026 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4027 sel_end_cursor.par(sel_end_cursor.par()->next);
4030 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4032 cursor = sel_end_cursor;
4034 /* please break behind a space, if there is one. The space should
4036 if (sel_start_cursor.pos() > 0
4037 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4038 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4039 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4040 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4043 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4044 sel_start_cursor.pos());
4045 tmppar = sel_start_cursor.par()->Next();
4047 if (dummy_selection) {
4049 if (kind == LyXParagraph::TAB
4050 || kind == LyXParagraph::FIG
4051 || kind == LyXParagraph::WIDE_TAB
4052 || kind == LyXParagraph::WIDE_FIG
4053 || kind == LyXParagraph::ALGORITHM) {
4054 pair<bool, LyXTextClass::size_type> lres =
4055 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4057 LyXTextClass::size_type lay;
4063 lay = 0; // use default layout "Standard" (0)
4065 tmppar->SetLayout(bview->buffer()->params, lay);
4068 if (sel_start_cursor.pos() > 0) {
4069 /* the footnote-environment should begin with a standard layout.
4070 * Imagine you insert a footnote within an enumeration, you
4071 * certainly do not want an enumerated footnote! */
4074 /* this is a exception the user would sometimes expect, I hope */
4075 sel_start_cursor.par()->Clear();
4079 while (tmppar != sel_end_cursor.par()) {
4080 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4081 tmppar->footnotekind = kind;
4082 tmppar = tmppar->Next();
4085 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4087 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4094 // returns pointer to a specified row
4095 Row * LyXText::GetRow(LyXParagraph * par,
4096 LyXParagraph::size_type pos, int & y) const
4101 Row * tmprow = firstrow;
4104 // find the first row of the specified paragraph
4105 while (tmprow->next() && tmprow->par() != par) {
4106 y += tmprow->height();
4107 tmprow = tmprow->next();
4110 // now find the wanted row
4111 while (tmprow->pos() < pos
4113 && tmprow->next()->par() == par
4114 && tmprow->next()->pos() <= pos) {
4115 y += tmprow->height();
4116 tmprow = tmprow->next();