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"
42 static const int LYX_PAPER_MARGIN = 20;
44 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
47 int LyXText::workWidth(BufferView * bview) const
50 return inset_owner->textWidth(bview->painter());
52 return bview->workWidth();
56 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
57 LyXParagraph::size_type pos) const
59 if (!Encoding::is_arabic(c))
60 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
61 return c + (0xb0 - '0');
65 unsigned char prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
66 unsigned char next_char = ' ';
67 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
68 if (!Encoding::IsComposeChar_arabic(par->GetChar(i))) {
69 next_char = par->GetChar(i);
73 if (Encoding::is_arabic(next_char)) {
74 if (Encoding::is_arabic(prev_char))
75 return Encoding::TransformChar(c, Encoding::FORM_MEDIAL);
77 return Encoding::TransformChar(c, Encoding::FORM_INITIAL);
79 if (Encoding::is_arabic(prev_char))
80 return Encoding::TransformChar(c, Encoding::FORM_FINAL);
82 return Encoding::TransformChar(c, Encoding::FORM_ISOLATED);
86 // This is the comments that some of the warnings below refers to.
87 // There are some issues in this file and I don't think they are
88 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
89 // this is a problem that has been here almost from day one and that a
90 // larger userbase with differenct access patters triggers the bad
91 // behaviour. (segfaults.) What I think happen is: In several places
92 // we store the paragraph in the current cursor and then moves the
93 // cursor. This movement of the cursor will delete paragraph at the
94 // old position if it is now empty. This will make the temporary
95 // pointer to the old cursor paragraph invalid and dangerous to use.
96 // And is some cases this will trigger a segfault. I have marked some
97 // of the cases where this happens with a warning, but I am sure there
98 // are others in this file and in text2.C. There is also a note in
99 // Delete() that you should read. In Delete I store the paragraph->id
100 // instead of a pointer to the paragraph. I am pretty sure this faulty
101 // use of temporary pointers to paragraphs that might have gotten
102 // invalidated (through a cursor movement) before they are used, are
103 // the cause of the strange crashes we get reported often.
105 // It is very tiresom to change this code, especially when it is as
106 // hard to read as it is. Help to fix all the cases where this is done
107 // would be greately appreciated.
111 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
112 LyXParagraph::size_type pos) const
114 char const c = par->GetChar(pos);
115 return SingleWidth(bview, par, pos, c);
119 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
120 LyXParagraph::size_type pos, char c) const
122 LyXFont font = GetFont(bview->buffer(), par, pos);
124 // The most common case is handled first (Asger)
125 if (IsPrintable(c)) {
126 if (font.language()->RightToLeft()) {
127 if (font.language()->lang() == "arabic" &&
128 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
129 lyxrc.font_norm_type == LyXRC::ISO_10646_1))
130 if (Encoding::IsComposeChar_arabic(c))
133 c = TransformChar(c, par, pos);
134 else if (font.language()->lang() == "hebrew" &&
135 Encoding::IsComposeChar_hebrew(c))
138 return lyxfont::width(c, font);
140 } else if (IsHfillChar(c)) {
141 return 3; /* Because of the representation
142 * as vertical lines */
144 } else if (c == LyXParagraph::META_FOOTNOTE ||
145 c == LyXParagraph::META_MARGIN ||
146 c == LyXParagraph::META_FIG ||
147 c == LyXParagraph::META_TAB ||
148 c == LyXParagraph::META_WIDE_FIG ||
149 c == LyXParagraph::META_WIDE_TAB ||
150 c == LyXParagraph::META_ALGORITHM) {
153 case LyXParagraph::META_MARGIN:
156 case LyXParagraph::META_FIG:
159 case LyXParagraph::META_TAB:
162 case LyXParagraph::META_ALGORITHM:
165 case LyXParagraph::META_WIDE_FIG:
168 case LyXParagraph::META_WIDE_TAB:
171 case LyXParagraph::META_FOOTNOTE:
177 return lyxfont::width(fs, font);
179 } else if (c == LyXParagraph::META_INSET) {
180 Inset * tmpinset = par->GetInset(pos);
182 tmpinset->update(bview, font);
183 return tmpinset->width(bview, font);
187 } else if (IsSeparatorChar(c))
189 else if (IsNewlineChar(c))
191 return lyxfont::width(c, font);
195 // Returns the paragraph position of the last character in the specified row
196 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
198 if (row->next() == 0)
199 return row->par()->Last() - 1;
200 else if (row->next()->par() != row->par())
201 return row->par()->Last() - 1;
203 return row->next()->pos() - 1;
207 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
209 LyXParagraph::size_type last = RowLast(row);
210 if (last >= row->pos()
212 && row->next()->par() == row->par()
213 && row->par()->IsSeparator(last))
220 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
222 bidi_same_direction = true;
223 if (!lyxrc.rtl_support) {
228 bidi_start = row->pos();
229 bidi_end = RowLastPrintable(row);
231 if (bidi_start > bidi_end) {
236 if (bidi_end + 2 - bidi_start >
237 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
238 LyXParagraph::size_type new_size =
239 (bidi_end + 2 - bidi_start < 500) ?
240 500 : 2 * (bidi_end + 2 - bidi_start);
241 log2vis_list.resize(new_size);
242 vis2log_list.resize(new_size);
243 bidi_levels.resize(new_size);
246 vis2log_list[bidi_end + 1 - bidi_start] = -1;
247 log2vis_list[bidi_end + 1 - bidi_start] = -1;
249 LyXParagraph::size_type stack[2];
250 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
254 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
256 for (LyXParagraph::size_type lpos = bidi_start;
257 lpos <= bidi_end; ++lpos) {
258 bool is_space = row->par()->IsLineSeparator(lpos);
259 LyXParagraph::size_type pos =
260 (is_space && lpos + 1 <= bidi_end &&
261 !row->par()->IsLineSeparator(lpos + 1) &&
262 !row->par()->IsNewline(lpos + 1))
264 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
265 bool new_rtl = font.isVisibleRightToLeft();
266 bool new_rtl0 = font.isRightToLeft();
269 if (lpos == main_body - 1
270 && row->pos() < main_body - 1
271 && row->par()->IsLineSeparator(lpos)) {
272 new_level = (rtl_par) ? 1 : 0;
273 new_rtl = new_rtl0 = rtl_par;
275 new_level = (new_rtl) ? 1 : 2;
277 new_level = (rtl_par) ? 2 : 0;
279 if (is_space && new_level >= level) {
285 int new_level2 = new_level;
287 if (level == new_level && rtl0 != new_rtl0) {
289 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
290 } else if (level < new_level) {
291 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
292 if (new_level > rtl_par)
293 bidi_same_direction = false;
295 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
298 bidi_levels[lpos - bidi_start] = new_level;
300 while (level > new_level2) {
301 LyXParagraph::size_type old_lpos =
303 int delta = lpos - old_lpos - 1;
306 log2vis_list[lpos - bidi_start] += delta;
307 log2vis_list[old_lpos - bidi_start] += delta;
309 while (level < new_level)
310 stack[level++] = lpos;
314 LyXParagraph::size_type old_lpos = stack[--level];
315 int delta = bidi_end - old_lpos;
318 log2vis_list[old_lpos - bidi_start] += delta;
321 LyXParagraph::size_type vpos = bidi_start - 1;
322 for (LyXParagraph::size_type lpos = bidi_start;
323 lpos <= bidi_end; ++lpos) {
324 vpos += log2vis_list[lpos - bidi_start];
325 vis2log_list[vpos - bidi_start] = lpos;
326 log2vis_list[lpos - bidi_start] = vpos;
331 // This method requires a previous call to ComputeBidiTables()
332 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
333 LyXParagraph::size_type pos) const
335 if (!lyxrc.rtl_support)
336 return false; // This is just for speedup
338 if (!bidi_InRange(pos - 1))
341 bool const rtl = bidi_level(pos - 1) % 2;
343 if (pos == par->Last())
344 rtl2 = par->isRightToLeftPar(buf->params);
345 else if (bidi_InRange(pos))
346 rtl2 = bidi_level(pos) % 2;
351 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
352 LyXParagraph::size_type pos,
353 LyXFont const & font) const
355 if (!lyxrc.rtl_support)
356 return false; // This is just for speedup
358 bool const rtl = font.isVisibleRightToLeft();
360 if (pos == par->Last())
361 rtl2 = par->isRightToLeftPar(buf->params);
362 else if (bidi_InRange(pos))
363 rtl2 = bidi_level(pos) % 2;
368 void LyXText::draw(BufferView * bview, Row const * row,
369 LyXParagraph::size_type & vpos,
370 int offset, float & x, bool cleared)
372 Painter & pain = bview->painter();
374 LyXParagraph::size_type pos = vis2log(vpos);
375 char c = row->par()->GetChar(pos);
378 if (IsNewlineChar(c)) {
380 // Draw end-of-line marker
381 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
382 int wid = lyxfont::width('n', font);
383 int asc = lyxfont::maxAscent(font);
384 int y = offset + row->baseline();
387 if (bidi_level(pos) % 2 == 0) {
388 xp[0] = int(x + wid * 0.375);
389 yp[0] = int(y - 0.875 * asc * 0.75);
392 yp[1] = int(y - 0.500 * asc * 0.75);
394 xp[2] = int(x + wid * 0.375);
395 yp[2] = int(y - 0.125 * asc * 0.75);
397 pain.lines(xp, yp, 3, LColor::eolmarker);
400 yp[0] = int(y - 0.500 * asc * 0.75);
402 xp[1] = int(x + wid);
403 yp[1] = int(y - 0.500 * asc * 0.75);
405 xp[2] = int(x + wid);
406 yp[2] = int(y - asc * 0.75);
408 pain.lines(xp, yp, 3, LColor::eolmarker);
410 xp[0] = int(x + wid * 0.625);
411 yp[0] = int(y - 0.875 * 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 * 0.625);
417 yp[2] = int(y - 0.125 * asc * 0.75);
419 pain.lines(xp, yp, 3, LColor::eolmarker);
421 xp[0] = int(x + wid);
422 yp[0] = int(y - 0.500 * asc * 0.75);
425 yp[1] = int(y - 0.500 * asc * 0.75);
428 yp[2] = int(y - asc * 0.75);
430 pain.lines(xp, yp, 3, LColor::eolmarker);
436 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
437 LyXFont font2 = font;
439 if (c == LyXParagraph::META_FOOTNOTE
440 || c == LyXParagraph::META_MARGIN
441 || c == LyXParagraph::META_FIG
442 || c == LyXParagraph::META_TAB
443 || c == LyXParagraph::META_WIDE_FIG
444 || c == LyXParagraph::META_WIDE_TAB
445 || c == LyXParagraph::META_ALGORITHM) {
448 case LyXParagraph::META_MARGIN:
451 case LyXParagraph::META_FIG:
454 case LyXParagraph::META_TAB:
457 case LyXParagraph::META_ALGORITHM:
460 case LyXParagraph::META_WIDE_FIG:
463 case LyXParagraph::META_WIDE_TAB:
466 case LyXParagraph::META_FOOTNOTE:
473 // calculate the position of the footnotemark
474 int y = (row->baseline() - lyxfont::maxAscent(font2)
475 + lyxfont::maxAscent(font));
477 font.setColor(LColor::footnote);
479 // draw it and set new x position
481 pain.text(int(x), offset + y, fs, font);
482 x += lyxfont::width(fs, font);
483 pain.line(int(tmpx), offset + row->baseline(),
484 int(x), offset + row->baseline(),
491 if (c == LyXParagraph::META_INSET) {
492 Inset * tmpinset = row->par()->GetInset(pos);
494 // tmpinset->update(bview, font, false);
495 tmpinset->draw(bview, font, offset+row->baseline(), x,
497 if (status == CHANGED_IN_DRAW) {
498 UpdateInset(bview, tmpinset);
499 status = CHANGED_IN_DRAW;
504 if (lyxrc.mark_foreign_language &&
505 font.language() != bview->buffer()->params.language_info) {
506 int y = offset + row->height() - 1;
507 pain.line(int(tmpx), y, int(x), y,
514 /* usual characters, no insets */
516 // Collect character that we can draw in one command
518 // This is dirty, but fast. Notice that it will never be too small.
519 // For the record, I'll note that Microsoft Word has a limit
520 // of 768 here. We have none :-) (Asger)
521 // Ok. I am the first to admit that the use of std::string will be
522 // a tiny bit slower than using a POD char array. However, I claim
523 // that this slowdown is so small that it is close to inperceptive.
524 // So IMHO we should go with the easier and clearer implementation.
525 // And even if 1024 is a large number here it might overflow, string
526 // will only overflow if the machine is out of memory...
527 static string textstring;
531 LyXParagraph::size_type last = RowLastPrintable(row);
533 if (font.language()->lang() == "hebrew") {
534 if (Encoding::IsComposeChar_hebrew(c)) {
535 int width = lyxfont::width(c, font2);
537 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
538 c = row->par()->GetChar(i);
539 if (!Encoding::IsComposeChar_hebrew(c)) {
540 if (IsPrintableNonspace(c)) {
541 int width2 = SingleWidth(bview, row->par(), i, c);
542 dx = (c == 'ø' || c == 'ã') // dalet / resh
543 ? width2 - width : (width2 - width) / 2;
549 pain.text(int(x) + dx, offset + row->baseline(),
552 while (vpos <= last &&
553 (pos = vis2log(vpos)) >= 0
554 && IsPrintableNonspace(c = row->par()->GetChar(pos))
555 && !Encoding::IsComposeChar_hebrew(c)
556 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
560 // Draw text and set the new x position
561 pain.text(int(x), offset + row->baseline(),
563 x += lyxfont::width(textstring, font);
565 } else if (font.language()->lang() == "arabic" &&
566 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
567 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
568 if (Encoding::IsComposeChar_arabic(c)) {
569 c = TransformChar(c, row->par(), pos);
571 int width = lyxfont::width(c, font2);
573 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
574 c = row->par()->GetChar(i);
575 if (!Encoding::IsComposeChar_arabic(c)) {
576 if (IsPrintableNonspace(c)) {
577 int width2 = SingleWidth(bview, row->par(), i, c);
578 dx = (width2 - width) / 2;
584 pain.text(int(x) + dx, offset + row->baseline(),
587 textstring = TransformChar(c, row->par(), pos);
588 while (vpos <= last &&
589 (pos = vis2log(vpos)) >= 0
590 && IsPrintableNonspace(c = row->par()->GetChar(pos))
591 && !Encoding::IsComposeChar_arabic(c)
592 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
593 c = TransformChar(c, row->par(), pos);
597 // Draw text and set the new x position
598 pain.text(int(x), offset + row->baseline(),
600 x += lyxfont::width(textstring, font);
603 while (vpos <= last &&
604 (pos = vis2log(vpos)) >= 0
605 && IsPrintableNonspace(c = row->par()->GetChar(pos))
606 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
610 // Draw text and set the new x position
611 pain.text(int(x), offset + row->baseline(), textstring, font);
612 x += lyxfont::width(textstring, font);
615 if (lyxrc.mark_foreign_language &&
616 font.language() != bview->buffer()->params.language_info) {
617 int y = offset + row->height() - 1;
618 pain.line(int(tmpx), y, int(x), y,
622 // If we want ulem.sty support, drawing
623 // routines should go here. (Asger)
624 // Why shouldn't LyXFont::drawText handle it internally?
628 // Returns the left beginning of the text.
629 // This information cannot be taken from the layouts-objekt, because in
630 // LaTeX the beginning of the text fits in some cases (for example sections)
631 // exactly the label-width.
632 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
634 LyXLayout const & layout =
635 textclasslist.Style(bview->buffer()->params.textclass,
636 row->par()->GetLayout());
638 string parindent = layout.parindent;
640 int x = LYX_PAPER_MARGIN;
642 x += lyxfont::signedWidth(textclasslist
643 .TextClass(bview->buffer()->params.textclass)
646 .TextClass(bview->buffer()->params.textclass)
649 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
650 LyXFont font(LyXFont::ALL_SANE);
651 font.setSize(LyXFont::SIZE_SMALL);
652 x += lyxfont::width("Mwide-figM", font)
653 + LYX_PAPER_MARGIN/2;
656 // this is the way, LyX handles the LaTeX-Environments.
657 // I have had this idea very late, so it seems to be a
658 // later added hack and this is true
659 if (!row->par()->GetDepth()) {
660 if (!row->par()->GetLayout()) {
661 // find the previous same level paragraph
663 if (row->par()->FirstPhysicalPar()->Previous()) {
665 if (row->par()->Previous()) {
667 LyXParagraph * newpar = row->par()
668 ->DepthHook(row->par()->GetDepth());
670 textclasslist.Style(bview->buffer()->params.textclass,
677 // find the next level paragraph
679 LyXParagraph * newpar =
680 row->par()->DepthHook(row->par()->GetDepth()-1);
682 // make a corresponding row. Needed to call LeftMargin()
684 // check wether it is a sufficent paragraph
687 && newpar->footnoteflag == row->par()->footnoteflag
690 .Style(bview->buffer()->params.textclass,
691 newpar->GetLayout()).isEnvironment()) {
693 dummyrow.par(newpar);
694 dummyrow.pos(newpar->Last());
695 x = LeftMargin(bview, &dummyrow);
697 // this is no longer an error, because this function
698 // is used to clear impossible depths after changing
699 // a layout. Since there is always a redo,
700 // LeftMargin() is always called
702 row->par()->FirstPhysicalPar()->depth = 0;
704 row->par()->depth = 0;
708 if (newpar && !row->par()->GetLayout()) {
710 if (newpar->FirstPhysicalPar()->noindent)
712 if (newpar->noindent)
716 parindent = textclasslist
717 .Style(bview->buffer()->params.textclass,
718 newpar->GetLayout()).parindent;
723 LyXFont const labelfont = GetFont(bview->buffer(), row->par(), -2);
724 switch (layout.margintype) {
726 if (!layout.leftmargin.empty()) {
727 x += lyxfont::signedWidth(layout.leftmargin,
729 .TextClass(bview->buffer()->params.
733 if (!row->par()->GetLabelstring().empty()) {
734 x += lyxfont::signedWidth(layout.labelindent,
736 x += lyxfont::width(row->par()->GetLabelstring(),
738 x += lyxfont::width(layout.labelsep, labelfont);
742 x += lyxfont::signedWidth(layout.labelindent, labelfont);
743 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
744 if (!row->par()->GetLabelWidthString().empty()) {
745 x += lyxfont::width(row->par()->GetLabelWidthString(),
747 x += lyxfont::width(layout.labelsep, labelfont);
752 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
753 / (row->par()->GetDepth() + 4);
755 case MARGIN_FIRST_DYNAMIC:
756 if (layout.labeltype == LABEL_MANUAL) {
757 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
758 x += lyxfont::signedWidth(layout.leftmargin,
761 x += lyxfont::signedWidth(layout.labelindent,
764 } else if (row->pos()
765 // Special case to fix problems with
767 || (layout.labeltype == LABEL_STATIC
768 && layout.latextype == LATEX_ENVIRONMENT
769 && ! row->par()->IsFirstInSequence())) {
770 x += lyxfont::signedWidth(layout.leftmargin,
772 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
773 && layout.labeltype != LABEL_BIBLIO
774 && layout.labeltype !=
775 LABEL_CENTERED_TOP_ENVIRONMENT) {
776 x += lyxfont::signedWidth(layout.labelindent,
778 x += lyxfont::width(layout.labelsep, labelfont);
779 x += lyxfont::width(row->par()->GetLabelstring(),
784 case MARGIN_RIGHT_ADDRESS_BOX:
786 // ok, a terrible hack. The left margin depends on the widest
787 // row in this paragraph. Do not care about footnotes, they
788 // are *NOT* allowed in the LaTeX realisation of this layout.
790 // find the first row of this paragraph
791 Row const * tmprow = row;
792 while (tmprow->previous()
793 && tmprow->previous()->par() == row->par())
794 tmprow = tmprow->previous();
796 int minfill = tmprow->fill();
797 while (tmprow->next() && tmprow->next()->par() == row->par()) {
798 tmprow = tmprow->next();
799 if (tmprow->fill() < minfill)
800 minfill = tmprow->fill();
803 x += lyxfont::signedWidth(layout.leftmargin,
805 .TextClass(bview->buffer()->params.textclass)
811 if ((workWidth(bview) > 0) &&
812 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT)) {
813 if (!row->par()->pextra_widthp.empty()) {
814 x += workWidth(bview) *
815 lyx::atoi(row->par()->pextra_widthp) / 100;
816 } else if (!row->par()->pextra_width.empty()) {
817 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
818 if (xx > workWidth(bview))
819 xx = workWidth(bview) * 80 / 100;
821 } else { // should not happen
822 LyXFont font(LyXFont::ALL_SANE);
823 x += lyxfont::width("XXXXXX", font);
827 int align; // wrong type
829 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
830 align = layout.align;
832 align = row->par()->FirstPhysicalPar()->align;
834 if (row->par()->align == LYX_ALIGN_LAYOUT)
835 align = layout.align;
837 align = row->par()->align;
839 // set the correct parindent
840 if (row->pos() == 0) {
841 if ((layout.labeltype == LABEL_NO_LABEL
842 || layout.labeltype == LABEL_TOP_ENVIRONMENT
843 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
844 || (layout.labeltype == LABEL_STATIC
845 && layout.latextype == LATEX_ENVIRONMENT
846 && ! row->par()->IsFirstInSequence()))
848 && row->par() == row->par()->FirstPhysicalPar()
850 && align == LYX_ALIGN_BLOCK
851 && !row->par()->noindent
852 && (row->par()->layout ||
853 bview->buffer()->params.paragraph_separation ==
854 BufferParams::PARSEP_INDENT))
855 x += lyxfont::signedWidth(parindent,
857 .TextClass(bview->buffer()->params
860 else if (layout.labeltype == LABEL_BIBLIO) {
861 // ale970405 Right width for bibitems
862 x += bibitemMaxWidth(bview,textclasslist
863 .TextClass(bview->buffer()->params
872 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
874 LyXLayout const & layout =
875 textclasslist.Style(buf->params.textclass,
876 row->par()->GetLayout());
878 int x = LYX_PAPER_MARGIN
879 + lyxfont::signedWidth(textclasslist
880 .TextClass(buf->params.textclass)
883 .TextClass(buf->params.textclass)
887 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
888 x += LYX_PAPER_MARGIN / 2;
891 // this is the way, LyX handles the LaTeX-Environments.
892 // I have had this idea very late, so it seems to be a
893 // later added hack and this is true
894 if (row->par()->GetDepth()) {
895 // find the next level paragraph
897 LyXParagraph * newpar = row->par();
901 newpar = newpar->FirstPhysicalPar()->Previous();
903 newpar = newpar->FirstPhysicalPar();
904 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
905 && newpar->footnoteflag == row->par()->footnoteflag);
908 newpar = newpar->Previous();
910 && newpar->GetDepth() >= row->par()->GetDepth());
913 // make a corresponding row. Needed to call LeftMargin()
915 // check wether it is a sufficent paragraph
918 && newpar->footnoteflag == row->par()->footnoteflag
920 && textclasslist.Style(buf->params.textclass,
924 dummyrow.par(newpar);
926 x = RightMargin(buf, &dummyrow);
928 // this is no longer an error, because this function
929 // is used to clear impossible depths after changing
930 // a layout. Since there is always a redo,
931 // LeftMargin() is always called
933 row->par()->FirstPhysicalPar()->depth = 0;
935 row->par()->depth = 0;
940 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
941 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
942 .TextClass(buf->params.textclass)
943 .defaultfont()) * 4 / (row->par()->GetDepth()
949 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
951 if (textclasslist.Style(bview->buffer()->params.textclass,
952 row->par()->GetLayout()).margintype
956 tmprow.pos(row->par()->Last());
957 return LeftMargin(bview, &tmprow); /* just the beginning
960 return 0; /* LabelEnd is only needed, if the
961 layout fills a flushleft
966 // get the next breakpoint in a given paragraph
967 LyXParagraph::size_type
968 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
970 LyXParagraph * par = row->par();
971 LyXParagraph::size_type pos = row->pos();
976 // position of the last possible breakpoint
977 // -1 isn't a suitable value, but a flag
978 LyXParagraph::size_type last_separator = -1;
979 width -= RightMargin(bview->buffer(), row);
981 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
982 LyXLayout const & layout =
983 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
984 LyXParagraph::size_type i = pos;
986 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
987 /* special code for right address boxes, only newlines count */
988 while (i < par->Last()) {
989 if (par->IsNewline(i)) {
991 i = par->Last() - 1; // this means break
993 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
994 par->GetInset(i) && par->GetInset(i)->display()){
995 par->GetInset(i)->display(false);
1000 // Last position is an invariant
1001 LyXParagraph::size_type const last =
1003 // this is the usual handling
1004 int x = LeftMargin(bview, row);
1005 bool doitonetime = true;
1006 while (doitonetime || ((x < width) && (i < last))) {
1007 doitonetime = false;
1008 char c = par->GetChar(i);
1009 if (IsNewlineChar(c)) {
1011 x = width; // this means break
1012 } else if (c == LyXParagraph::META_INSET &&
1015 // check wether a Display() inset is
1016 // valid here. if not, change it to
1018 if (par->GetInset(i)->display() &&
1019 (layout.isCommand() ||
1020 ((layout.labeltype == LABEL_MANUAL) &&
1021 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1022 // display istn't allowd
1023 par->GetInset(i)->display(false);
1024 x += SingleWidth(bview, par, i, c);
1025 } else if (par->GetInset(i)->display() ||
1026 par->GetInset(i)->needFullRow()) {
1027 // So break the line here
1031 if (IsLineSeparatorChar(par->GetChar(i+1)))
1034 last_separator = last; // to avoid extra rows
1036 last_separator = i - 1;
1037 x = width; // this means break
1043 x += SingleWidth(bview, par, i, c);
1047 if (IsLineSeparatorChar(c))
1049 x += SingleWidth(bview, par, i, c);
1052 if (i == main_body) {
1053 x += lyxfont::width(layout.labelsep,
1054 GetFont(bview->buffer(), par, -2));
1055 if (par->IsLineSeparator(i - 1))
1056 x-= SingleWidth(bview, par, i - 1);
1057 int left_margin = LabelEnd(bview, row);
1058 if (x < left_margin)
1062 // end of paragraph is always a suitable separator
1063 if (i == last && x < width)
1067 // well, if last_separator is still 0, the line isn't breakable.
1068 // don't care and cut simply at the end
1069 if (last_separator < 0) {
1073 // manual labels cannot be broken in LaTeX, do not care
1074 if (main_body && last_separator < main_body)
1075 last_separator = main_body - 1;
1077 return last_separator;
1081 // returns the minimum space a row needs on the screen in pixel
1082 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1084 if (paper_width < 0)
1088 // get the pure distance
1089 LyXParagraph::size_type last = RowLastPrintable(row);
1091 // special handling of the right address boxes
1092 if (textclasslist.Style(bview->buffer()->params.textclass,
1093 row->par()->GetLayout()).margintype
1094 == MARGIN_RIGHT_ADDRESS_BOX) {
1095 int tmpfill = row->fill();
1096 row->fill(0); // the minfill in MarginLeft()
1097 w = LeftMargin(bview, row);
1100 w = LeftMargin(bview, row);
1102 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1103 row->par()->GetLayout());
1104 LyXParagraph::size_type main_body =
1105 BeginningOfMainBody(bview->buffer(), row->par());
1106 LyXParagraph::size_type i = row->pos();
1109 if (main_body > 0 && i == main_body) {
1110 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1111 if (row->par()->IsLineSeparator(i - 1))
1112 w -= SingleWidth(bview, row->par(), i - 1);
1113 int left_margin = LabelEnd(bview, row);
1114 if (w < left_margin)
1117 w += SingleWidth(bview, row->par(), i);
1120 if (main_body > 0 && main_body > last) {
1121 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1122 if (last >= 0 && row->par()->IsLineSeparator(last))
1123 w -= SingleWidth(bview, row->par(), last);
1124 int left_margin = LabelEnd(bview, row);
1125 if (w < left_margin)
1129 int const fill = paper_width - w - RightMargin(bview->buffer(), row);
1134 // returns the minimum space a manual label needs on the screen in pixel
1135 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1137 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par()) - 1;
1138 // -1 because a label ends either with a space that is in the label,
1139 // or with the beginning of a footnote that is outside the label.
1141 // I don't understand this code in depth, but sometimes "last" is
1142 // less than 0 and this causes a crash. This fix seems to work
1143 // correctly, but I bet the real error is elsewhere. The bug is
1144 // triggered when you have an open footnote in a paragraph
1145 // environment with a manual label. (Asger)
1146 if (last < 0) last = 0;
1148 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1155 w += SingleWidth(bview, row->par(), i);
1160 if (!row->par()->labelwidthstring.empty()) {
1161 fill = max(lyxfont::width(row->par()->labelwidthstring,
1162 GetFont(bview->buffer(), row->par(), -2)) - w,
1170 // returns the number of separators in the specified row. The separator
1171 // on the very last column doesnt count
1172 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1174 LyXParagraph::size_type const last = RowLast(row);
1175 LyXParagraph::size_type p =
1176 max(row->pos(), BeginningOfMainBody(buf, row->par()));
1178 for (; p < last; ++p) {
1179 if (row->par()->IsSeparator(p)) {
1187 // returns the number of hfills in the specified row. The LyX-Hfill is
1188 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1189 // ignored. This is *MUCH* more usefull than not to ignore!
1190 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1192 LyXParagraph::size_type const last = RowLast(row);
1193 LyXParagraph::size_type first = row->pos();
1194 if (first) { /* hfill *DO* count at the beginning
1196 while(first <= last && row->par()->IsHfill(first))
1200 first = max(first, BeginningOfMainBody(buf, row->par()));
1202 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1203 if (row->par()->IsHfill(p)) {
1211 // like NumberOfHfills, but only those in the manual label!
1212 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1214 LyXParagraph::size_type 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 last = min(last, BeginningOfMainBody(buf, row->par()));
1224 for (LyXParagraph::size_type p = first;
1225 p < last; ++p) { // last, because the end is ignored!
1226 if (row->par()->IsHfill(p)) {
1234 // returns true, if a expansion is needed.
1235 // Rules are given by LaTeX
1236 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1237 LyXParagraph::size_type pos) const
1239 // by the way, is it a hfill?
1240 if (!row_ptr->par()->IsHfill(pos))
1243 // at the end of a row it does not count
1244 if (pos >= RowLast(row_ptr))
1247 // at the beginning of a row it does not count, if it is not
1248 // the first row of a paragaph
1249 if (!row_ptr->pos())
1252 // in some labels it does not count
1253 if (textclasslist.Style(buf->params.textclass,
1254 row_ptr->par()->GetLayout()).margintype
1256 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1259 // if there is anything between the first char of the row and
1260 // the sepcified position that is not a newline and not a hfill,
1261 // the hfill will count, otherwise not
1262 LyXParagraph::size_type i = row_ptr->pos();
1263 while (i < pos && (row_ptr->par()->IsNewline(i)
1264 || row_ptr->par()->IsHfill(i)))
1271 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1273 /* get the maximum ascent and the maximum descent */
1276 float layoutasc = 0;
1277 float layoutdesc = 0;
1280 Inset * tmpinset = 0;
1282 /* this must not happen before the currentrow for clear reasons.
1283 so the trick is just to set the current row onto this row */
1285 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1287 /* ok , let us initialize the maxasc and maxdesc value.
1288 * This depends in LaTeX of the font of the last character
1289 * in the paragraph. The hack below is necessary because
1290 * of the possibility of open footnotes */
1292 /* Correction: only the fontsize count. The other properties
1293 are taken from the layoutfont. Nicer on the screen :) */
1295 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1296 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1298 LyXParagraph * par = row_ptr->par();
1299 LyXParagraph * firstpar = row_ptr->par();
1302 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1303 firstpar->GetLayout());
1305 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1306 LyXFont::FONT_SIZE size = font.size();
1307 font = GetFont(bview->buffer(), par, -1);
1310 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1312 float spacing_val = 1.0;
1313 if (!row_ptr->par()->spacing.isDefault()) {
1314 spacing_val = row_ptr->par()->spacing.getValue();
1316 spacing_val = bview->buffer()->params.spacing.getValue();
1318 //lyxerr << "spacing_val = " << spacing_val << endl;
1320 int maxasc = int(lyxfont::maxAscent(font) *
1321 layout.spacing.getValue() *
1323 int maxdesc = int(lyxfont::maxDescent(font) *
1324 layout.spacing.getValue() *
1326 int pos_end = RowLast(row_ptr);
1330 // Check if any insets are larger
1331 for (int pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1332 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1333 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1334 tmpinset = row_ptr->par()->GetInset(pos);
1336 tmpinset->update(bview, tmpfont);
1337 asc = tmpinset->ascent(bview, tmpfont);
1338 desc = tmpinset->descent(bview, tmpfont);
1339 maxwidth += tmpinset->width(bview, tmpfont);
1340 maxasc = max(maxasc, asc);
1341 maxdesc = max(maxdesc, desc);
1344 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1348 // Check if any custom fonts are larger (Asger)
1349 // This is not completely correct, but we can live with the small,
1350 // cosmetic error for now.
1351 LyXFont::FONT_SIZE maxsize =
1352 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1354 if (maxsize > font.size()) {
1355 font.setSize(maxsize);
1357 asc = lyxfont::maxAscent(font);
1358 desc = lyxfont::maxDescent(font);
1365 // This is nicer with box insets:
1369 row_ptr->ascent_of_text(maxasc);
1371 /* is it a top line? */
1372 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1374 /* some parksips VERY EASY IMPLEMENTATION */
1375 if (bview->buffer()->params.paragraph_separation ==
1376 BufferParams::PARSEP_SKIP) {
1377 if (layout.isParagraph()
1378 && firstpar->GetDepth() == 0
1379 && firstpar->Previous())
1380 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1381 else if (firstpar->Previous()
1382 && textclasslist.Style(bview->buffer()->params.textclass,
1383 firstpar->Previous()->GetLayout()).isParagraph()
1384 && firstpar->Previous()->GetDepth() == 0)
1385 // is it right to use defskip here too? (AS)
1386 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1389 /* the paper margins */
1390 if (!row_ptr->par()->previous && bv_owner)
1391 maxasc += LYX_PAPER_MARGIN;
1393 /* add the vertical spaces, that the user added */
1394 if (firstpar->added_space_top.kind() != VSpace::NONE)
1395 maxasc += int(firstpar->added_space_top.inPixels(bview));
1397 /* do not forget the DTP-lines!
1398 * there height depends on the font of the nearest character */
1399 if (firstpar->line_top)
1400 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1403 /* and now the pagebreaks */
1404 if (firstpar->pagebreak_top)
1405 maxasc += 3 * DefaultHeight();
1407 /* this is special code for the chapter, since the label of this
1408 * layout is printed in an extra row */
1409 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1410 && bview->buffer()->params.secnumdepth >= 0) {
1411 float spacing_val = 1.0;
1412 if (!row_ptr->par()->spacing.isDefault()) {
1413 spacing_val = row_ptr->par()->spacing.getValue();
1415 spacing_val = bview->buffer()->params.spacing.getValue();
1418 labeladdon = int(lyxfont::maxDescent(labelfont) *
1419 layout.spacing.getValue() *
1421 + int(lyxfont::maxAscent(labelfont) *
1422 layout.spacing.getValue() *
1426 /* special code for the top label */
1427 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1428 || layout.labeltype == LABEL_BIBLIO
1429 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1430 && row_ptr->par()->IsFirstInSequence()
1431 && !row_ptr->par()->GetLabelstring().empty()) {
1432 float spacing_val = 1.0;
1433 if (!row_ptr->par()->spacing.isDefault()) {
1434 spacing_val = row_ptr->par()->spacing.getValue();
1436 spacing_val = bview->buffer()->params.spacing.getValue();
1440 (lyxfont::maxAscent(labelfont) *
1441 layout.spacing.getValue() *
1443 +(lyxfont::maxDescent(labelfont) *
1444 layout.spacing.getValue() *
1446 + layout.topsep * DefaultHeight()
1447 + layout.labelbottomsep * DefaultHeight());
1450 /* and now the layout spaces, for example before and after a section,
1451 * or between the items of a itemize or enumerate environment */
1453 if (!firstpar->pagebreak_top) {
1454 LyXParagraph * prev = row_ptr->par()->Previous();
1456 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1457 if (prev && prev->GetLayout() == firstpar->GetLayout()
1458 && prev->GetDepth() == firstpar->GetDepth()
1459 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1461 layoutasc = (layout.itemsep * DefaultHeight());
1463 else if (row_ptr->previous()) {
1464 tmptop = layout.topsep;
1466 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1467 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1468 row_ptr->previous()->par()->
1469 GetLayout()).bottomsep;
1472 layoutasc = (tmptop * DefaultHeight());
1474 else if (row_ptr->par()->line_top){
1475 tmptop = layout.topsep;
1478 layoutasc = (tmptop * DefaultHeight());
1481 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1483 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1484 prev->GetLayout()).parsep * DefaultHeight());
1487 if (firstpar->Previous()
1488 && firstpar->Previous()->GetDepth() == 0
1489 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1492 else if (firstpar->Previous()){
1493 maxasc += int(layout.parsep * DefaultHeight());
1499 /* is it a bottom line? */
1502 row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1504 row_ptr->par() == par
1506 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1508 /* the paper margins */
1509 if (!par->next && bv_owner)
1510 maxdesc += LYX_PAPER_MARGIN;
1512 /* add the vertical spaces, that the user added */
1513 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1514 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1516 /* do not forget the DTP-lines!
1517 * there height depends on the font of the nearest character */
1518 if (firstpar->line_bottom)
1519 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1520 par, par->Last() - 1));
1522 /* and now the pagebreaks */
1523 if (firstpar->pagebreak_bottom)
1524 maxdesc += 3 * DefaultHeight();
1526 /* and now the layout spaces, for example before and after a section,
1527 * or between the items of a itemize or enumerate environment */
1528 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1529 LyXParagraph * nextpar = row_ptr->par()->Next();
1530 LyXParagraph * comparepar = row_ptr->par();
1534 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1535 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1536 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1537 if (comparepar->GetLayout()!= nextpar->GetLayout()
1538 || nextpar->GetLabelWidthString() !=
1539 comparepar->GetLabelWidthString())
1540 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1542 if (unusual > usual)
1543 layoutdesc = unusual;
1547 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1549 if (comparepar->GetLayout()!= nextpar->GetLayout()
1550 || nextpar->GetLabelWidthString() !=
1551 comparepar->GetLabelWidthString())
1552 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1557 /* incalculate the layout spaces */
1558 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1559 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1561 /* calculate the new height of the text */
1562 height -= row_ptr->height();
1564 row_ptr->height(maxasc + maxdesc + labeladdon);
1565 row_ptr->baseline(maxasc + labeladdon);
1567 height += row_ptr->height();
1569 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1570 row_ptr->width(int(maxwidth + x));
1573 width = max(0,workWidth(bview));
1575 if (r->width() > width)
1583 /* Appends the implicit specified paragraph behind the specified row,
1584 * start at the implicit given position */
1585 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1587 bool not_ready = true;
1589 // The last character position of a paragraph is an invariant so we can
1590 // safely get it here. (Asger)
1591 int const lastposition = row->par()->Last();
1594 // Get the next breakpoint
1595 int z = NextBreakPoint(bview, row, workWidth(bview));
1599 // Insert the new row
1600 if (z < lastposition) {
1602 InsertRow(row, row->par(), z);
1609 // Set the dimensions of the row
1610 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1611 SetHeightOfRow(bview, tmprow);
1613 } while (not_ready);
1617 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1619 bool not_ready = true;
1622 /* get the next breakpoint */
1623 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1626 if (z < row->par()->Last() ) {
1627 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1630 InsertRow(row, row->par(), z);
1636 if (row->pos() == z)
1637 not_ready = false; // the rest will not change
1643 /* if there are some rows too much, delete them */
1644 /* only if you broke the whole paragraph! */
1645 Row * tmprow2 = row;
1646 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1647 tmprow2 = tmprow2->next();
1649 while (tmprow2 != row) {
1650 tmprow2 = tmprow2->previous();
1651 RemoveRow(tmprow2->next());
1656 /* set the dimensions of the row */
1657 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1658 SetHeightOfRow(bview, tmprow);
1659 } while (not_ready);
1663 // this is just a little changed version of break again
1664 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1666 // get the next breakpoint
1667 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1670 if (z < row->par()->Last() ) {
1672 || (row->next() && row->next()->par() != row->par())) {
1673 /* insert a new row */
1675 InsertRow(row, row->par(), z);
1681 if (row->pos() != z)
1685 // if there are some rows too much, delete them
1686 // only if you broke the whole paragraph!
1687 Row * tmprow2 = row;
1688 while (tmprow2->next()
1689 && tmprow2->next()->par() == row->par()) {
1690 tmprow2 = tmprow2->next();
1692 while (tmprow2 != row) {
1693 tmprow2 = tmprow2->previous();
1694 RemoveRow(tmprow2->next());
1698 // set the dimensions of the row
1699 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1700 SetHeightOfRow(bview, tmprow);
1704 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1706 LyXLayout const & layout =
1707 textclasslist.Style(bview->buffer()->params.textclass,
1708 cursor.par()->GetLayout());
1710 // this is only allowed, if the current paragraph is not empty or caption
1711 if ((cursor.par()->Last() <= 0
1713 && !cursor.par()->IsDummy()
1717 layout.labeltype!= LABEL_SENSITIVE)
1720 SetUndo(bview->buffer(), Undo::INSERT,
1722 cursor.par()->ParFromPos(cursor.pos())->previous,
1723 cursor.par()->ParFromPos(cursor.pos())->next
1725 cursor.par()->previous,
1730 // please break always behind a space
1731 if (cursor.pos() < cursor.par()->Last()
1732 && cursor.par()->IsLineSeparator(cursor.pos()))
1733 cursor.pos(cursor.pos() + 1);
1735 // break the paragraph
1739 keep_layout = layout.isEnvironment();
1740 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1743 // well this is the caption hack since one caption is really enough
1744 if (layout.labeltype == LABEL_SENSITIVE) {
1746 // set to standard-layout
1747 cursor.par()->SetLayout(bview->buffer()->params, 0);
1749 // set to standard-layout
1750 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1753 /* if the cursor is at the beginning of a row without prior newline,
1755 * This touches only the screen-update. Otherwise we would may have
1756 * an empty row on the screen */
1757 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1758 cursor.row()->pos() == cursor.pos()) {
1762 status = LyXText::NEED_MORE_REFRESH;
1763 refresh_row = cursor.row();
1764 refresh_y = cursor.y() - cursor.row()->baseline();
1766 // Do not forget the special right address boxes
1767 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1768 while (refresh_row->previous() &&
1769 refresh_row->previous()->par() == refresh_row->par()) {
1770 refresh_row = refresh_row->previous();
1771 refresh_y -= refresh_row->height();
1774 RemoveParagraph(cursor.row());
1776 // set the dimensions of the cursor row
1777 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1779 SetHeightOfRow(bview, cursor.row());
1781 while (cursor.par()->Next()->Last()
1782 && cursor.par()->Next()->IsNewline(0))
1783 cursor.par()->Next()->Erase(0);
1785 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1787 UpdateCounters(bview, cursor.row()->previous());
1789 /* This check is necessary. Otherwise the new empty paragraph will
1790 * be deleted automatically. And it is more friendly for the user! */
1792 SetCursor(bview, cursor.par()->Next(), 0);
1794 SetCursor(bview, cursor.par(), 0);
1796 if (cursor.row()->next())
1797 BreakAgain(bview, cursor.row()->next());
1804 void LyXText::OpenFootnote(BufferView * bview)
1806 LyXParagraph * endpar,* tmppar;
1809 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1811 /* if there is no footnote in this paragraph, just return. */
1813 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1816 /* ok, move the cursor right before the footnote */
1818 /* just a little faster than using CursorRight() */
1820 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1821 cursor.pos(cursor.pos() + 1);
1824 /* now the cursor is at the beginning of the physical par */
1825 SetCursor(bview, cursor.par(),
1826 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1828 /* the cursor must be exactly before the footnote */
1829 par = cursor.par()->ParFromPos(cursor.pos());
1831 status = LyXText::NEED_MORE_REFRESH;
1832 refresh_row = cursor.row();
1833 refresh_y = cursor.y() - cursor.row()->baseline();
1835 tmppar = cursor.par();
1836 endpar = cursor.par()->Next();
1839 tmppar->OpenFootnote(cursor.pos());
1840 RemoveParagraph(row);
1841 /* set the dimensions of the cursor row */
1842 row->fill(Fill(bview, row, workWidth(bview)));
1843 SetHeightOfRow(bview, row);
1844 // CHECK See comment on top of text.C
1845 tmppar = tmppar->Next();
1847 while (tmppar != endpar) {
1849 InsertParagraph(bview, tmppar, row);
1850 while (row->next() && row->next()->par() == tmppar)
1852 tmppar = tmppar->Next();
1855 SetCursor(bview, par->next, 0);
1856 sel_cursor = cursor;
1861 // Just a macro to make some thing easier.
1862 void LyXText::RedoParagraph(BufferView * bview) const
1865 RedoParagraphs(bview, cursor, cursor.par()->Next());
1866 SetCursorIntern(bview, cursor.par(), cursor.pos());
1870 /* insert a character, moves all the following breaks in the
1871 * same Paragraph one to the right and make a rebreak */
1872 void LyXText::InsertChar(BufferView * bview, char c)
1874 SetUndo(bview->buffer(), Undo::INSERT,
1876 cursor.par()->ParFromPos(cursor.pos())->previous,
1877 cursor.par()->ParFromPos(cursor.pos())->next
1879 cursor.par()->previous,
1884 // When the free-spacing option is set for the current layout,
1885 // disable the double-space checking
1888 textclasslist.Style(bview->buffer()->params.textclass,
1889 cursor.row()->par()->GetLayout()).free_spacing;
1891 /* First check, if there will be two blanks together or a blank at
1892 the beginning of a paragraph.
1893 I decided to handle blanks like normal characters, the main
1894 difference are the special checks when calculating the row.fill
1895 (blank does not count at the end of a row) and the check here */
1897 // The bug is triggered when we type in a description environment:
1898 // The current_font is not changed when we go from label to main text
1899 // and it should (along with realtmpfont) when we type the space.
1900 // CHECK There is a bug here! (Asger)
1902 LyXFont realtmpfont = real_current_font;
1903 LyXFont rawtmpfont = current_font; /* store the current font.
1904 * This is because of the use
1905 * of cursor movements. The moving
1906 * cursor would refresh the
1909 // Get the font that is used to calculate the baselineskip
1910 LyXParagraph::size_type lastpos = cursor.par()->Last();
1911 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
1914 bool jumped_over_space = false;
1916 if (!freeSpacing && IsLineSeparatorChar(c)) {
1917 if ((cursor.pos() > 0
1918 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
1919 || (cursor.pos() > 0
1920 && cursor.par()->IsNewline(cursor.pos() - 1))
1921 || (cursor.pos() == 0
1923 && !(cursor.par()->Previous()
1924 && cursor.par()->Previous()->footnoteflag
1925 == LyXParagraph::OPEN_FOOTNOTE)
1928 if (cursor.pos() == 0 )
1929 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1931 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
1935 } else if (IsNewlineChar(c)) {
1937 if (cursor.par()->FirstPhysicalPar() == cursor.par()
1939 if (cursor.par() == cursor.par()
1941 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
1945 /* No newline at first position
1946 * of a paragraph or behind labels.
1947 * TeX does not allow that. */
1949 if (cursor.pos() < cursor.par()->Last() &&
1950 cursor.par()->IsLineSeparator(cursor.pos()))
1951 // newline always after a blank!
1953 cursor.row()->fill(-1); // to force a new break
1956 // the display inset stuff
1957 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
1958 && cursor.row()->par()->GetInset(cursor.row()->pos())
1959 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
1960 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
1961 cursor.row()->fill(-1); // to force a new break
1963 // get the cursor row fist
1964 Row * row = cursor.row();
1965 int y = cursor.y() - row->baseline();
1966 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
1967 * already insertet the character */
1968 cursor.par()->InsertChar(cursor.pos(), c);
1969 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1971 if (!jumped_over_space) {
1972 // refresh the positions
1974 while (tmprow->next() && tmprow->next()->par() == row->par()) {
1975 tmprow = tmprow->next();
1976 tmprow->pos(tmprow->pos() + 1);
1980 // Is there a break one row above
1981 if ((cursor.par()->IsLineSeparator(cursor.pos())
1982 || cursor.par()->IsNewline(cursor.pos())
1983 || cursor.row()->fill() == -1)
1984 && row->previous() && row->previous()->par() == row->par()) {
1985 LyXParagraph::size_type z = NextBreakPoint(bview,
1988 if ( z >= row->pos()) {
1991 // set the dimensions of the row above
1992 row->previous()->fill(Fill(bview,
1996 SetHeightOfRow(bview, row->previous());
1998 y -= row->previous()->height();
2000 refresh_row = row->previous();
2001 status = LyXText::NEED_MORE_REFRESH;
2003 BreakAgainOneRow(bview, row);
2005 current_font = rawtmpfont;
2006 real_current_font = realtmpfont;
2007 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2008 false, cursor.boundary());
2009 // cursor MUST be in row now.
2011 if (row->next() && row->next()->par() == row->par())
2012 need_break_row = row->next();
2016 // check, wether the last characters font has changed.
2017 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2018 && rawparfont != rawtmpfont)
2019 RedoHeightOfParagraph(bview, cursor);
2026 // recalculate the fill of the row
2027 if (row->fill() >= 0) /* needed because a newline
2028 * will set fill to -1. Otherwise
2029 * we would not get a rebreak! */
2030 row->fill(Fill(bview, row, workWidth(bview)));
2031 if (row->fill() < 0 ) {
2034 refresh_x = cursor.x();
2035 refresh_pos = cursor.pos();
2036 status = LyXText::NEED_MORE_REFRESH;
2037 BreakAgainOneRow(bview, row);
2038 // will the cursor be in another row now?
2039 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2040 if (row->next() && row->next()->par() == row->par())
2041 // this should always be true
2043 BreakAgainOneRow(bview, row);
2045 current_font = rawtmpfont;
2046 real_current_font = realtmpfont;
2048 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2050 if (row->next() && row->next()->par() == row->par())
2051 need_break_row = row->next();
2056 refresh_x = cursor.x();
2058 refresh_pos = cursor.pos();
2060 int tmpheight = row->height();
2061 SetHeightOfRow(bview, row);
2062 if (tmpheight == row->height())
2063 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2065 status = LyXText::NEED_MORE_REFRESH;
2067 current_font = rawtmpfont;
2068 real_current_font = realtmpfont;
2069 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2073 // check, wether the last characters font has changed.
2074 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2075 && rawparfont != rawtmpfont) {
2076 RedoHeightOfParagraph(bview, cursor);
2078 // now the special right address boxes
2079 if (textclasslist.Style(bview->buffer()->params.textclass,
2080 cursor.par()->GetLayout()).margintype
2081 == MARGIN_RIGHT_ADDRESS_BOX) {
2082 RedoDrawingOfParagraph(bview, cursor);
2090 void LyXText::charInserted()
2092 // Here we could call FinishUndo for every 20 characters inserted.
2093 // This is from my experience how emacs does it.
2094 static unsigned int counter = 0;
2104 void LyXText::PrepareToPrint(BufferView * bview,
2105 Row * row, float & x,
2106 float & fill_separator,
2108 float & fill_label_hfill,
2113 float w = row->fill();
2115 fill_label_hfill = 0;
2117 fill_label_hfill = 0;
2119 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2123 x = RightMargin(bview->buffer(), row);
2124 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2125 LyXFont font(LyXFont::ALL_SANE);
2126 font.setSize(LyXFont::SIZE_SMALL);
2127 x += lyxfont::width("Mwide-figM", font);
2131 if (workWidth(bview) > 0)
2132 x = LeftMargin(bview, row);
2136 // is there a manual margin with a manual label
2137 if (textclasslist.Style(bview->buffer()->params.textclass,
2138 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2139 && textclasslist.Style(bview->buffer()->params.textclass,
2140 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2142 /* one more since labels are left aligned */
2143 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2144 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2145 fill_label_hfill = LabelFill(bview, row) / nlh;
2149 // are there any hfills in the row?
2150 float const nh = NumberOfHfills(bview->buffer(), row);
2153 fill_hfill = w / nh;
2155 // is it block, flushleft or flushright?
2156 // set x how you need it
2159 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2160 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2162 align = row->par()->FirstPhysicalPar()->align;
2164 if (row->par()->align == LYX_ALIGN_LAYOUT)
2165 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2167 align = row->par()->align;
2170 // center displayed insets
2172 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2173 && (inset=row->par()->GetInset(row->pos()))
2174 && (inset->display())) // || (inset->scroll() < 0)))
2175 align = LYX_ALIGN_CENTER;
2178 case LYX_ALIGN_BLOCK:
2179 ns = NumberOfSeparators(bview->buffer(), row);
2180 if (ns && row->next() && row->next()->par() == row->par() &&
2181 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2182 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2183 && row->next()->par()->GetInset(row->next()->pos())
2184 && row->next()->par()->GetInset(row->next()->pos())->display())
2186 fill_separator = w / ns;
2190 case LYX_ALIGN_RIGHT:
2193 case LYX_ALIGN_CENTER:
2201 ComputeBidiTables(bview->buffer(), row);
2203 LyXParagraph::size_type main_body =
2204 BeginningOfMainBody(bview->buffer(), row->par());
2205 LyXParagraph::size_type last = RowLast(row);
2207 if (main_body > 0 &&
2208 (main_body-1 > last ||
2209 !row->par()->IsLineSeparator(main_body-1))) {
2210 LyXLayout const & layout =
2211 textclasslist.Style(bview->buffer()->params.textclass,
2212 row->par()->GetLayout());
2213 x += lyxfont::width(layout.labelsep,
2214 GetFont(bview->buffer(), row->par(), -2));
2215 if (main_body-1 <= last)
2216 x += fill_label_hfill;
2221 /* important for the screen */
2224 /* the cursor set functions have a special mechanism. When they
2225 * realize, that you left an empty paragraph, they will delete it.
2226 * They also delete the corresponding row */
2228 void LyXText::CursorRightOneWord(BufferView * bview) const
2230 // treat floats, HFills and Insets as words
2231 LyXCursor tmpcursor = cursor;
2232 // CHECK See comment on top of text.C
2234 if (tmpcursor.pos() == tmpcursor.par()->Last()
2235 && tmpcursor.par()->Next()) {
2236 tmpcursor.par(tmpcursor.par()->Next());
2241 // Skip through initial nonword stuff.
2242 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
2243 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2245 // printf("Current pos1 %d", tmpcursor.pos()) ;
2246 tmpcursor.pos(tmpcursor.pos() + 1);
2249 // Advance through word.
2250 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
2251 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2253 // printf("Current pos2 %d", tmpcursor.pos()) ;
2254 tmpcursor.pos(tmpcursor.pos() + 1);
2258 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2262 void LyXText::CursorTab(BufferView * bview) const
2264 LyXCursor tmpcursor = cursor;
2265 while (tmpcursor.pos() < tmpcursor.par()->Last()
2266 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
2267 tmpcursor.pos(tmpcursor.pos() + 1);
2269 if (tmpcursor.pos() == tmpcursor.par()->Last()){
2270 if (tmpcursor.par()->Next()) {
2271 tmpcursor.par(tmpcursor.par()->Next());
2275 tmpcursor.pos(tmpcursor.pos() + 1);
2276 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2280 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2281 of prior word, not to end of next prior word. */
2283 void LyXText::CursorLeftOneWord(BufferView * bview) const
2285 // treat HFills, floats and Insets as words
2286 LyXCursor tmpcursor = cursor;
2287 while (tmpcursor.pos()
2288 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
2289 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
2290 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
2292 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2294 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
2295 tmpcursor.pos(tmpcursor.pos() - 1);
2298 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
2300 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2302 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
2303 tmpcursor.pos(tmpcursor.pos() - 1);
2304 } else if (!tmpcursor.pos()) {
2305 if (tmpcursor.par()->Previous()){
2306 tmpcursor.par(tmpcursor.par()->Previous());
2307 tmpcursor.pos(tmpcursor.par()->Last());
2309 } else { // Here, tmpcursor != 0
2310 while (tmpcursor.pos() > 0 &&
2311 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
2312 tmpcursor.pos(tmpcursor.pos() - 1);
2314 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2317 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2320 void LyXText::SelectWord(BufferView * bview)
2322 // Move cursor to the beginning, when not already there.
2324 && !cursor.par()->IsSeparator(cursor.pos()-1)
2325 && !cursor.par()->IsKomma(cursor.pos()-1) )
2326 CursorLeftOneWord(bview);
2328 // set the sel cursor
2329 sel_cursor = cursor;
2331 while ( cursor.pos() < cursor.par()->Last()
2332 && !cursor.par()->IsSeparator(cursor.pos())
2333 && !cursor.par()->IsKomma(cursor.pos()) )
2334 cursor.pos(cursor.pos() + 1);
2335 SetCursor(bview, cursor.par(), cursor.pos() );
2337 // finally set the selection
2342 /* -------> Select the word currently under the cursor when:
2343 1: no selection is currently set,
2344 2: the cursor is not at the borders of the word. */
2346 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
2349 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
2350 && !cursor.par()->IsSeparator(cursor.pos())
2351 && !cursor.par()->IsKomma(cursor.pos())
2352 && !cursor.par()->IsSeparator(cursor.pos() -1)
2353 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
2361 // This function is only used by the spellchecker for NextWord().
2362 // It doesn't handle LYX_ACCENTs and probably never will.
2363 string const LyXText::SelectNextWord(BufferView * bview,
2364 float & value) const
2366 LyXParagraph * tmppar = cursor.par();
2368 // If this is not the very first word, skip rest of
2369 // current word because we are probably in the middle
2370 // of a word if there is text here.
2371 if (cursor.pos() || cursor.par()->previous) {
2372 while (cursor.pos() < cursor.par()->Last()
2373 && cursor.par()->IsLetter(cursor.pos()))
2374 cursor.pos(cursor.pos() + 1);
2376 // Now, skip until we have real text (will jump paragraphs)
2377 while ((cursor.par()->Last() > cursor.pos()
2378 && (!cursor.par()->IsLetter(cursor.pos())
2379 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
2380 .latex() == LyXFont::ON))
2381 || (cursor.par()->Last() == cursor.pos()
2382 && cursor.par()->Next())){
2383 if (cursor.pos() == cursor.par()->Last()) {
2384 cursor.par(cursor.par()->Next());
2387 cursor.pos(cursor.pos() + 1);
2390 // Update the value if we changed paragraphs
2391 if (cursor.par() != tmppar){
2392 SetCursor(bview, cursor.par(), cursor.pos());
2393 value = float(cursor.y())/float(height);
2396 // Start the selection from here
2397 sel_cursor = cursor;
2399 std::ostringstream latex;
2401 // and find the end of the word
2402 // (optional hyphens are part of a word)
2403 while (cursor.pos() < cursor.par()->Last()
2404 && (cursor.par()->IsLetter(cursor.pos()))
2405 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2406 && cursor.par()->GetInset(cursor.pos()) != 0
2407 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2408 && latex.str() == "\\-"
2410 cursor.pos(cursor.pos() + 1);
2412 // Finally, we copy the word to a string and return it
2414 if (sel_cursor.pos() < cursor.pos()) {
2415 LyXParagraph::size_type i;
2416 for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
2417 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
2418 str += cursor.par()->GetChar(i);
2425 // This one is also only for the spellchecker
2426 void LyXText::SelectSelectedWord(BufferView * bview)
2428 // move cursor to the beginning
2429 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
2431 // set the sel cursor
2432 sel_cursor = cursor;
2434 std::ostringstream latex;
2436 // now find the end of the word
2437 while (cursor.pos() < cursor.par()->Last()
2438 && (cursor.par()->IsLetter(cursor.pos())
2439 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2440 && cursor.par()->GetInset(cursor.pos()) != 0
2441 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2442 && latex.str() == "\\-"
2444 cursor.pos(cursor.pos() + 1);
2446 SetCursor(bview, cursor.par(), cursor.pos());
2448 // finally set the selection
2453 /* -------> Delete from cursor up to the end of the current or next word. */
2454 void LyXText::DeleteWordForward(BufferView * bview)
2456 if (!cursor.par()->Last())
2459 LyXCursor tmpcursor = cursor;
2460 tmpcursor.row(0); //Â ??
2461 selection = true; // to avoid deletion
2462 CursorRightOneWord(bview);
2463 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2464 sel_cursor = cursor;
2468 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2469 CutSelection(bview);
2474 /* -------> Delete from cursor to start of current or prior word. */
2475 void LyXText::DeleteWordBackward(BufferView * bview)
2477 if (!cursor.par()->Last())
2480 LyXCursor tmpcursor = cursor;
2481 tmpcursor.row(0); // ??
2482 selection = true; // to avoid deletion
2483 CursorLeftOneWord(bview);
2484 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2485 sel_cursor = cursor;
2488 CutSelection(bview);
2493 /* -------> Kill to end of line. */
2494 void LyXText::DeleteLineForward(BufferView * bview)
2496 if (!cursor.par()->Last())
2497 // Paragraph is empty, so we just go to the right
2500 LyXCursor tmpcursor = cursor;
2501 // We can't store the row over a regular SetCursor
2502 // so we set it to 0 and reset it afterwards.
2503 tmpcursor.row(0); //Â ??
2504 selection = true; // to avoid deletion
2506 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2507 sel_cursor = cursor;
2510 // What is this test for ??? (JMarc)
2512 DeleteWordForward(bview);
2514 CutSelection(bview);
2520 // Change the case of a word at cursor position.
2521 // This function directly manipulates LyXParagraph::text because there
2522 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2523 // that it is correct. I guess part of it should be moved to
2524 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2525 // it does not access outside of the allocated array as the older
2526 // version did. (JMarc)
2527 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
2530 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
2532 LyXParagraph * tmppar = cursor.par();
2535 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
2538 LyXParagraph::size_type tmppos =
2539 cursor.par()->PositionInParFromPos(cursor.pos());
2541 LyXParagraph::size_type tmppos = cursor.pos();
2543 while (tmppos < tmppar->size()) {
2544 unsigned char c = tmppar->GetChar(tmppos);
2545 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2547 if (c != LyXParagraph::META_INSET) {
2549 case text_lowercase:
2552 case text_capitalization:
2554 action = text_lowercase;
2556 case text_uppercase:
2562 //tmppar->text[tmppos] = c;
2563 tmppar->SetChar(tmppos, c);
2566 CheckParagraph(bview, tmppar, tmppos);
2567 CursorRightOneWord(bview);
2571 void LyXText::Delete(BufferView * bview)
2573 // this is a very easy implementation
2575 LyXCursor old_cursor = cursor;
2576 int old_cur_par_id = old_cursor.par()->id();
2577 int old_cur_par_prev_id = old_cursor.par()->previous ?
2578 old_cursor.par()->previous->id() : 0;
2580 // just move to the right
2583 // CHECK Look at the comment here.
2584 // This check is not very good...
2585 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2586 // and that can very well delete the par or par->previous in
2587 // old_cursor. Will a solution where we compare paragraph id's
2589 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
2590 == old_cur_par_prev_id
2591 && cursor.par()->id() != old_cur_par_id)
2592 return; // delete-empty-paragraph-mechanism has done it
2594 // if you had success make a backspace
2595 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2596 LyXCursor tmpcursor = cursor;
2597 cursor = old_cursor; // to make sure undo gets the right cursor position
2598 SetUndo(bview->buffer(), Undo::DELETE,
2600 cursor.par()->ParFromPos(cursor.pos())->previous,
2601 cursor.par()->ParFromPos(cursor.pos())->next
2603 cursor.par()->previous,
2613 void LyXText::Backspace(BufferView * bview)
2615 // Get the font that is used to calculate the baselineskip
2616 LyXParagraph::size_type lastpos = cursor.par()->Last();
2617 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2620 if (cursor.pos() == 0) {
2621 // The cursor is at the beginning of a paragraph,
2622 // so the the backspace will collapse two paragraphs into one.
2624 // we may paste some paragraphs
2626 // is it an empty paragraph?
2629 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
2631 && !(cursor.par()->Next()
2632 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
2633 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
2636 // This is an empty paragraph and we delete it just by moving the cursor one step
2637 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2638 // of the paragraph.
2640 if (cursor.par()->previous) {
2642 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
2644 LyXParagraph * tmppar = cursor.par()->previous;
2646 if (cursor.par()->GetLayout() == tmppar->GetLayout()
2648 && cursor.par()->footnoteflag == tmppar->footnoteflag
2650 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2651 // Inherit botom DTD from the paragraph below.
2652 // (the one we are deleting)
2653 tmppar->line_bottom = cursor.par()->line_bottom;
2654 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
2655 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
2660 // the layout things can change the height of a row !
2661 int tmpheight = cursor.row()->height();
2662 SetHeightOfRow(bview, cursor.row());
2663 if (cursor.row()->height() != tmpheight) {
2664 refresh_y = cursor.y() - cursor.row()->baseline();
2665 refresh_row = cursor.row();
2666 status = LyXText::NEED_MORE_REFRESH;
2673 if (cursor.par()->ParFromPos(cursor.pos())->previous){
2674 SetUndo(bview->buffer(), Undo::DELETE,
2675 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
2676 cursor.par()->ParFromPos(cursor.pos())->next);
2679 if (cursor.par()->previous) {
2680 SetUndo(bview->buffer(), Undo::DELETE,
2681 cursor.par()->previous->previous,
2682 cursor.par()->next);
2686 LyXParagraph * tmppar = cursor.par();
2687 Row * tmprow = cursor.row();
2689 // We used to do CursorLeftIntern() here, but it is
2690 // not a good idea since it triggers the auto-delete
2691 // mechanism. So we do a CursorLeftIntern()-lite,
2692 // without the dreaded mechanism. (JMarc)
2693 if (cursor.par()->Previous()) {
2694 // steps into the above paragraph.
2695 SetCursorIntern(bview, cursor.par()->Previous(),
2696 cursor.par()->Previous()->Last(), false);
2699 /* Pasting is not allowed, if the paragraphs have different
2700 layout. I think it is a real bug of all other
2701 word processors to allow it. It confuses the user.
2702 Even so with a footnote paragraph and a non-footnote
2703 paragraph. I will not allow pasting in this case,
2704 because the user would be confused if the footnote behaves
2705 different wether it is open or closed.
2707 Correction: Pasting is always allowed with standard-layout
2709 if (cursor.par() != tmppar
2710 && (cursor.par()->GetLayout() == tmppar->GetLayout()
2711 || tmppar->GetLayout() == 0 /*standard*/)
2713 && cursor.par()->footnoteflag == tmppar->footnoteflag
2715 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2717 RemoveParagraph(tmprow);
2719 cursor.par()->PasteParagraph(bview->buffer()->params);
2721 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
2722 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
2723 // strangely enough it seems that commenting out the line above removes
2724 // most or all of the segfaults. I will however also try to move the
2725 // two Remove... lines in front of the PasteParagraph too.
2728 cursor.pos(cursor.pos() - 1);
2730 status = LyXText::NEED_MORE_REFRESH;
2731 refresh_row = cursor.row();
2732 refresh_y = cursor.y() - cursor.row()->baseline();
2734 // remove the lost paragraph
2735 // This one is not safe, since the paragraph that the tmprow and the
2736 // following rows belong to has been deleted by the PasteParagraph
2737 // above. The question is... could this be moved in front of the
2739 //RemoveParagraph(tmprow);
2740 //RemoveRow(tmprow);
2742 // This rebuilds the rows.
2743 AppendParagraph(bview, cursor.row());
2744 UpdateCounters(bview, cursor.row());
2746 // the row may have changed, block, hfills etc.
2747 SetCursor(bview, cursor.par(), cursor.pos(), false);
2750 /* this is the code for a normal backspace, not pasting
2752 SetUndo(bview->buffer(), Undo::DELETE,
2754 cursor.par()->ParFromPos(cursor.pos())->previous,
2755 cursor.par()->ParFromPos(cursor.pos())->next
2757 cursor.par()->previous,
2761 // We used to do CursorLeftIntern() here, but it is
2762 // not a good idea since it triggers the auto-delete
2763 // mechanism. So we do a CursorLeftIntern()-lite,
2764 // without the dreaded mechanism. (JMarc)
2765 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
2766 false, cursor.boundary());
2768 // some insets are undeletable here
2769 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2770 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2772 // force complete redo when erasing display insets
2773 // this is a cruel method but safe..... Matthias
2774 if (cursor.par()->GetInset(cursor.pos())->display() ||
2775 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
2776 cursor.par()->Erase(cursor.pos());
2777 RedoParagraph(bview);
2782 Row * row = cursor.row();
2783 int y = cursor.y() - row->baseline();
2784 LyXParagraph::size_type z;
2785 /* remember that a space at the end of a row doesnt count
2786 * when calculating the fill */
2787 if (cursor.pos() < RowLast(row) ||
2788 !cursor.par()->IsLineSeparator(cursor.pos())) {
2789 row->fill(row->fill() + SingleWidth(bview,
2794 /* some special code when deleting a newline. This is similar
2795 * to the behavior when pasting paragraphs */
2796 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
2797 cursor.par()->Erase(cursor.pos());
2798 // refresh the positions
2800 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2801 tmprow = tmprow->next();
2802 tmprow->pos(tmprow->pos() - 1);
2804 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
2805 cursor.pos(cursor.pos() - 1);
2807 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
2808 cursor.par()->InsertChar(cursor.pos(), ' ');
2809 // refresh the positions
2811 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2812 tmprow = tmprow->next();
2813 tmprow->pos(tmprow->pos() + 1);
2817 cursor.par()->Erase(cursor.pos());
2819 // refresh the positions
2821 while (tmprow->next()
2822 && tmprow->next()->par() == row->par()) {
2823 tmprow = tmprow->next();
2824 tmprow->pos(tmprow->pos() - 1);
2827 // delete newlines at the beginning of paragraphs
2828 while (cursor.par()->Last() &&
2829 cursor.par()->IsNewline(cursor.pos()) &&
2830 cursor.pos() == BeginningOfMainBody(bview->buffer(),
2832 cursor.par()->Erase(cursor.pos());
2833 // refresh the positions
2835 while (tmprow->next() &&
2836 tmprow->next()->par() == row->par()) {
2837 tmprow = tmprow->next();
2838 tmprow->pos(tmprow->pos() - 1);
2843 // is there a break one row above
2844 if (row->previous() && row->previous()->par() == row->par()) {
2845 z = NextBreakPoint(bview, row->previous(),
2847 if ( z >= row->pos()) {
2850 Row * tmprow = row->previous();
2852 // maybe the current row is now empty
2853 if (row->pos() >= row->par()->Last()) {
2858 BreakAgainOneRow(bview, row);
2859 if (row->next() && row->next()->par() == row->par())
2860 need_break_row = row->next();
2865 // set the dimensions of the row above
2866 y -= tmprow->height();
2867 tmprow->fill(Fill(bview, tmprow,
2869 SetHeightOfRow(bview, tmprow);
2872 refresh_row = tmprow;
2873 status = LyXText::NEED_MORE_REFRESH;
2874 SetCursor(bview, cursor.par(), cursor.pos(),
2875 false, cursor.boundary());
2876 //current_font = rawtmpfont;
2877 //real_current_font = realtmpfont;
2878 // check, whether the last character's font has changed.
2880 cursor.par()->GetFontSettings(bview->buffer()->params,
2881 cursor.par()->Last() - 1))
2882 RedoHeightOfParagraph(bview, cursor);
2887 // break the cursor row again
2888 if (row->next() && row->next()->par() == row->par() &&
2889 (RowLast(row) == row->par()->Last() - 1 ||
2890 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
2892 /* it can happen that a paragraph loses one row
2893 * without a real breakup. This is when a word
2894 * is to long to be broken. Well, I don t care this
2896 if (RowLast(row) == row->par()->Last() - 1)
2897 RemoveRow(row->next());
2901 status = LyXText::NEED_MORE_REFRESH;
2903 BreakAgainOneRow(bview, row);
2904 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2905 // cursor MUST be in row now
2907 need_break_row = row->next();
2909 // set the dimensions of the row
2910 row->fill(Fill(bview, row, workWidth(bview)));
2911 int tmpheight = row->height();
2912 SetHeightOfRow(bview, row);
2913 if (tmpheight == row->height())
2914 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2916 status = LyXText::NEED_MORE_REFRESH;
2919 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2923 // current_font = rawtmpfont;
2924 // real_current_font = realtmpfont;
2926 lastpos = cursor.par()->Last();
2927 if (cursor.pos() == lastpos) {
2928 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2929 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2930 SetCurrentFont(bview);
2933 // check, wether the last characters font has changed.
2935 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
2936 RedoHeightOfParagraph(bview, cursor);
2938 // now the special right address boxes
2939 if (textclasslist.Style(bview->buffer()->params.textclass,
2940 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
2941 RedoDrawingOfParagraph(bview, cursor);
2947 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
2948 Row * row_ptr, int y, bool cleared)
2950 /* returns a printed row */
2951 Painter & pain = bview->painter();
2953 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
2954 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
2956 LyXParagraph::size_type vpos, pos;
2962 LyXFont font(LyXFont::ALL_SANE);
2964 if (row_ptr->height() <= 0) {
2965 lyxerr << "LYX_ERROR: row.height: "
2966 << row_ptr->height() << endl;
2970 float fill_separator;
2972 float fill_label_hfill;
2973 PrepareToPrint(bview, row_ptr, x, fill_separator,
2974 fill_hfill, fill_label_hfill);
2976 if (inset_owner && (x < 0))
2980 // clear the area where we want to paint/print
2981 int ww = bview->workWidth();
2983 bool clear_area = true;
2986 if (!bview->screen()->forceClear() && (last == row_ptr->pos()) &&
2987 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
2988 (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
2989 clear_area = inset->doClearArea();
2991 // we don't need to clear it's already done!!!
2994 } else if (clear_area) {
2995 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
2996 int w = (inset_owner ? inset_owner->width(bview, font)-2 : ww);
2997 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
2998 } else if (inset != 0) {
2999 int h = row_ptr->baseline() - inset->ascent(bview, font);
3001 int w = (inset_owner ?
3002 inset_owner->width(bview, font) : ww);
3003 pain.fillRectangle(x_offset, y_offset, w, h);
3005 h += inset->ascent(bview, font) + inset->descent(bview, font);
3006 if ((row_ptr->height() - h) > 0) {
3007 int w = (inset_owner ?
3008 inset_owner->width(bview, font) : ww);
3009 pain.fillRectangle(x_offset,y_offset+h, w, row_ptr->height()-h);
3011 if (!inset_owner && !inset->display() && !inset->needFullRow())
3013 int w = inset->width(bview, font) + int(x);
3014 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3019 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3020 /* selection code */
3021 if (bidi_same_direction) {
3022 if (sel_start_cursor.row() == row_ptr &&
3023 sel_end_cursor.row() == row_ptr) {
3024 if (sel_start_cursor.x() < sel_end_cursor.x())
3025 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3027 sel_end_cursor.x() - sel_start_cursor.x(),
3031 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3033 sel_start_cursor.x() - sel_end_cursor.x(),
3036 } else if (sel_start_cursor.row() == row_ptr) {
3038 pain.fillRectangle(x_offset, y_offset,
3039 sel_start_cursor.x(),
3043 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3045 w - sel_start_cursor.x(),
3048 } else if (sel_end_cursor.row() == row_ptr) {
3050 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3052 w - sel_end_cursor.x(),
3056 pain.fillRectangle(x_offset, y_offset,
3060 } else if (y > sel_start_cursor.y()
3061 && y < sel_end_cursor.y()) {
3062 pain.fillRectangle(x_offset, y_offset, w,
3066 } else if ( sel_start_cursor.row() != row_ptr &&
3067 sel_end_cursor.row() != row_ptr &&
3068 y > sel_start_cursor.y()
3069 && y < sel_end_cursor.y()) {
3070 pain.fillRectangle(x_offset, y_offset, w,
3073 } else if (sel_start_cursor.row() == row_ptr ||
3074 sel_end_cursor.row() == row_ptr) {
3076 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3077 (sel_end_cursor.row() != row_ptr && is_rtl))
3078 pain.fillRectangle(x_offset, y_offset,
3082 LyXParagraph::size_type main_body =
3083 BeginningOfMainBody(bview->buffer(),
3086 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3087 pos = vis2log(vpos);
3088 float old_tmpx = tmpx;
3089 if (main_body > 0 && pos == main_body-1) {
3090 tmpx += fill_label_hfill +
3091 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3092 row_ptr->par()->GetLayout()).labelsep,
3093 GetFont(bview->buffer(),row_ptr->par(), -2));
3094 if (row_ptr->par()->IsLineSeparator(main_body-1))
3095 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3097 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3098 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3099 if (pos >= main_body)
3102 tmpx += fill_label_hfill;
3104 else if (row_ptr->par()->IsSeparator(pos)) {
3105 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3106 if (pos >= main_body)
3107 tmpx += fill_separator;
3109 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3111 if ( (sel_start_cursor.row() != row_ptr ||
3112 sel_start_cursor.pos() <= pos) &&
3113 (sel_end_cursor.row() != row_ptr ||
3114 pos < sel_end_cursor.pos()) )
3115 pain.fillRectangle(x_offset + int(old_tmpx),
3117 int(tmpx - old_tmpx + 1),
3122 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3123 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3124 pain.fillRectangle(x_offset + int(tmpx),
3134 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3135 LyXFont font(LyXFont::ALL_SANE);
3136 font.setSize(LyXFont::SIZE_FOOTNOTE);
3137 font.setColor(LColor::footnote);
3139 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3140 if (row_ptr->previous() &&
3141 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3143 switch (row_ptr->par()->footnotekind) {
3144 case LyXParagraph::MARGIN:
3147 case LyXParagraph::FIG:
3150 case LyXParagraph::TAB:
3153 case LyXParagraph::WIDE_FIG:
3156 case LyXParagraph::WIDE_TAB:
3159 case LyXParagraph::ALGORITHM:
3162 case LyXParagraph::FOOTNOTE:
3167 pain.fillRectangle(LYX_PAPER_MARGIN,
3169 box_x - LYX_PAPER_MARGIN,
3170 int(lyxfont::maxAscent(font)
3171 + lyxfont::maxDescent(font)),
3172 LColor::footnotebg);
3174 pain.line(LYX_PAPER_MARGIN, y_offset,
3175 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3176 LColor::footnoteframe);
3178 pain.text(LYX_PAPER_MARGIN,
3179 y_offset + int(lyxfont::maxAscent(font)) + 1,
3182 pain.line(LYX_PAPER_MARGIN, y_offset,
3184 y_offset + int(lyxfont::maxAscent(font)
3185 + lyxfont::maxDescent(font)),
3186 LColor::footnoteframe);
3188 pain.line(LYX_PAPER_MARGIN,
3189 y_offset + int(lyxfont::maxAscent(font)
3190 + lyxfont::maxDescent(font)) + 1,
3192 y_offset + int(lyxfont::maxAscent(font)
3193 + lyxfont::maxDescent(font)) + 1,
3194 LColor::footnoteframe);
3198 /* draw the open floats in a red box */
3199 pain.line(box_x, y_offset,
3200 box_x, y_offset + row_ptr->height(),
3201 LColor::footnoteframe);
3203 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
3205 workWidth(bview) - LYX_PAPER_MARGIN,
3206 y_offset + row_ptr->height(),
3207 LColor::footnoteframe);
3210 // Draw appendix lines
3211 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
3213 pain.line(1, y_offset,
3214 1, y_offset + row_ptr->height(),
3215 LColor::appendixline);
3216 pain.line(workWidth(bview) - 2, y_offset,
3217 workWidth(bview) - 2,
3218 y_offset + row_ptr->height(),
3219 LColor::appendixline);
3222 // Draw minipage line
3223 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
3225 pain.line(LYX_PAPER_MARGIN/5, y_offset,
3227 y_offset + row_ptr->height() - 1,
3228 LColor::minipageline);
3231 int depth = p->GetDepth();
3232 for (int i = 1; i <= depth; ++i) {
3233 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
3234 pain.line(line_x, y_offset, line_x,
3235 y_offset + row_ptr->height() - 1,
3238 } else if (row_ptr->previous() &&
3239 row_ptr->previous()->par()->footnoteflag
3240 == LyXParagraph::OPEN_FOOTNOTE) {
3241 LyXFont font(LyXFont::ALL_SANE);
3242 font.setSize(LyXFont::SIZE_FOOTNOTE);
3244 int box_x = LYX_PAPER_MARGIN;
3245 box_x += lyxfont::width(" wide-tab ", font);
3247 pain.line(box_x, y_offset,
3248 workWidth(bview) - LYX_PAPER_MARGIN,
3249 y_offset, LColor::footnote);
3252 // Draw appendix lines
3254 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
3256 LyXParagraph * firstpar = row_ptr->par();
3258 if (firstpar->appendix){
3259 pain.line(1, y_offset,
3260 1, y_offset + row_ptr->height(),
3261 LColor::appendixline);
3262 pain.line(ww - 2, y_offset,
3263 ww - 2, y_offset + row_ptr->height(),
3264 LColor::appendixline);
3267 // Draw minipage line
3268 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
3270 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
3271 LYX_PAPER_MARGIN/5 + box_x,
3272 y_offset + row_ptr->height() - 1,
3273 LColor::minipageline);
3276 int depth = firstpar->GetDepth();
3280 if (row_ptr->next())
3282 if (row_ptr->par()->footnoteflag ==
3283 row_ptr->next()->par()->footnoteflag)
3284 next_depth = row_ptr->next()->par()->GetDepth();
3285 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3288 next_depth = row_ptr->next()->par()->GetDepth();
3290 if (row_ptr->previous())
3292 if (row_ptr->par()->footnoteflag ==
3293 row_ptr->previous()->par()->footnoteflag)
3294 prev_depth = row_ptr->previous()->par()->GetDepth();
3295 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3298 prev_depth = row_ptr->previous()->par()->GetDepth();
3301 for (int i = 1; i <= depth; ++i) {
3302 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
3303 pain.line(line_x, y_offset, line_x,
3304 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
3308 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
3311 pain.fillRectangle(line_x,
3312 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
3313 LYX_PAPER_MARGIN / 5, 2,
3319 LyXLayout const & layout =
3320 textclasslist.Style(bview->buffer()->params.textclass,
3321 row_ptr->par()->GetLayout());
3324 y_bottom = row_ptr->height();
3326 /* is it a first row? */
3327 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
3329 /* start of appendix? */
3330 if (row_ptr->par()->start_of_appendix){
3331 pain.line(1, y_offset,
3333 LColor::appendixline);
3336 /* think about the margins */
3337 if (!row_ptr->previous() && bv_owner)
3338 y_top += LYX_PAPER_MARGIN;
3340 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
3342 pb_font.setColor(LColor::pagebreak).decSize();
3343 int w = 0, a = 0, d = 0;
3344 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
3346 y_offset + y_top + 2 * DefaultHeight(),
3348 Painter::line_onoffdash)
3351 _("Page Break (top)"),
3354 LColor::background, false, w, a, d);
3355 pain.rectText((ww - w)/2,
3356 y_offset + y_top + 2 * DefaultHeight() + d,
3357 _("Page Break (top)"),
3360 LColor::background);
3361 y_top += 3 * DefaultHeight();
3364 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
3365 /* draw a vfill top */
3366 pain.line(0, y_offset + 2 + y_top,
3367 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
3370 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
3372 y_offset + y_top + 3 * DefaultHeight(),
3375 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
3376 LYX_PAPER_MARGIN / 2,
3377 y_offset + y_top + 3 * DefaultHeight(),
3380 y_top += 3 * DefaultHeight();
3383 /* think about user added space */
3384 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
3386 /* think about the parskip */
3387 /* some parskips VERY EASY IMPLEMENTATION */
3388 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3389 if (layout.latextype == LATEX_PARAGRAPH
3390 && firstpar->GetDepth() == 0
3391 && firstpar->Previous())
3392 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3393 else if (firstpar->Previous()
3394 && textclasslist.Style(bview->buffer()->params.textclass,
3395 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3396 && firstpar->Previous()->GetDepth() == 0)
3397 // is it right to use defskip here, too? (AS)
3398 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3401 if (row_ptr->par()->line_top) { /* draw a top line */
3402 y_top += lyxfont::ascent('x',
3403 GetFont(bview->buffer(),
3404 row_ptr->par(), 0));
3405 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3406 int xp = static_cast<int>(inset_owner ? x : 0);
3407 pain.line(xp, y_offset + y_top,
3408 w, y_offset + y_top,
3410 Painter::line_solid,
3411 Painter::line_thick);
3413 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
3414 row_ptr->par(), 0));
3417 /* should we print a label? */
3418 if (layout.labeltype >= LABEL_STATIC
3419 && (layout.labeltype != LABEL_STATIC
3420 || layout.latextype != LATEX_ENVIRONMENT
3421 || row_ptr->par()->IsFirstInSequence())) {
3422 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3423 if (!row_ptr->par()->GetLabelstring().empty()) {
3425 string tmpstring = row_ptr->par()->GetLabelstring();
3427 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3428 if (bview->buffer()->params.secnumdepth >= 0) {
3429 /* this is special code for the chapter layout. This is printed in
3430 * an extra row and has a pagebreak at the top. */
3431 float spacing_val = 1.0;
3432 if (!row_ptr->par()->spacing.isDefault()) {
3433 spacing_val = row_ptr->par()->spacing.getValue();
3435 spacing_val = bview->buffer()->params.spacing.getValue();
3438 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3439 + int(layout.parsep) * DefaultHeight();
3441 tmpx = ww - LeftMargin(bview, row_ptr) -
3442 lyxfont::width(tmpstring, font);
3443 pain.text(int(tmpx),
3444 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
3449 tmpx = ww - LeftMargin(bview, row_ptr)
3450 + lyxfont::width(layout.labelsep, font);
3452 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3453 LyXFont font(LyXFont::ALL_SANE);
3454 font.setSize(LyXFont::SIZE_SMALL);
3455 tmpx += lyxfont::width("Mwide-fixM", font);
3459 tmpx = x - lyxfont::width(layout.labelsep, font)
3460 - lyxfont::width(tmpstring, font);
3463 pain.text(int(tmpx),
3464 y_offset + row_ptr->baseline(),
3468 /* the labels at the top of an environment. More or less for bibliography */
3469 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3470 layout.labeltype == LABEL_BIBLIO ||
3471 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3472 if (row_ptr->par()->IsFirstInSequence()) {
3473 font = GetFont(bview->buffer(),
3474 row_ptr->par(), -2);
3475 if (!row_ptr->par()->GetLabelstring().empty()) {
3476 string tmpstring = row_ptr->par()->GetLabelstring();
3477 float spacing_val = 1.0;
3478 if (!row_ptr->par()->spacing.isDefault()) {
3479 spacing_val = row_ptr->par()->spacing.getValue();
3481 spacing_val = bview->buffer()->params.spacing.getValue();
3484 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3485 + (layout.labelbottomsep * DefaultHeight()));
3488 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3489 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
3490 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
3491 tmpx -= lyxfont::width(tmpstring, font) / 2;
3493 tmpx = ww - LeftMargin(bview, row_ptr) -
3494 lyxfont::width(tmpstring, font);
3495 pain.text(int(tmpx),
3496 y_offset + row_ptr->baseline()
3497 - row_ptr->ascent_of_text()
3503 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
3504 font = GetFont(bview->buffer(), row_ptr->par(), -1);
3506 tmpx = ww - LeftMargin(bview, row_ptr)
3507 + lyxfont::width(layout.labelsep, font);
3509 tmpx = x - lyxfont::width(layout.labelsep, font)
3510 - row_ptr->par()->bibkey->width(bview, font);
3511 row_ptr->par()->bibkey->draw(bview, font,
3512 y_offset + row_ptr->baseline(),
3517 /* is it a last row? */
3519 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
3521 LyXParagraph * par = row_ptr->par();
3525 (row_ptr->par()->ParFromPos(last + 1) == par)
3527 (row_ptr->par() == par)
3529 && (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
3531 /* think about the margins */
3532 if (!row_ptr->next() && bv_owner)
3533 y_bottom -= LYX_PAPER_MARGIN;
3535 /* draw a bottom pagebreak */
3536 if (firstpar->pagebreak_bottom) {
3538 pb_font.setColor(LColor::pagebreak).decSize();
3539 int w = 0, a = 0, d = 0;
3541 y_offset + y_bottom - 2 * DefaultHeight(),
3543 y_offset + y_bottom - 2 * DefaultHeight(),
3545 Painter::line_onoffdash)
3548 _("Page Break (bottom)"),
3551 LColor::background, false, w, a, d);
3552 pain.rectText((ww - w) / 2,
3553 y_offset + y_top + 2 * DefaultHeight() + d,
3554 _("Page Break (bottom)"),
3557 LColor::background);
3558 y_bottom -= 3 * DefaultHeight();
3561 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3562 /* draw a vfill bottom */
3563 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
3565 y_offset + y_bottom - 3 * DefaultHeight(),
3567 pain.line(0, y_offset + y_bottom - 2,
3569 y_offset + y_bottom - 2,
3571 pain.line(LYX_PAPER_MARGIN / 2,
3572 y_offset + y_bottom - 3 * DefaultHeight(),
3573 LYX_PAPER_MARGIN / 2,
3574 y_offset + y_bottom - 2,
3576 y_bottom -= 3 * DefaultHeight();
3579 /* think about user added space */
3580 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
3582 if (firstpar->line_bottom) {
3583 /* draw a bottom line */
3584 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3585 par, par->Last() - 1));
3586 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3587 int xp = static_cast<int>(inset_owner ? x : 0);
3588 pain.line(xp, y_offset + y_bottom,
3589 w, y_offset + y_bottom,
3590 LColor::topline, Painter::line_solid,
3591 Painter::line_thick);
3592 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3593 par, par->Last() - 1));
3597 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
3600 case END_LABEL_FILLED_BOX:
3602 LyXFont font = GetFont(bview->buffer(),
3603 row_ptr->par(), last);
3604 int size = int(0.75 * lyxfont::maxAscent(font));
3605 int y = (y_offset + row_ptr->baseline()) - size;
3606 int x = is_rtl ? LYX_PAPER_MARGIN
3607 : ww - LYX_PAPER_MARGIN - size;
3609 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3611 LyXFont font(LyXFont::ALL_SANE);
3612 font.setSize(LyXFont::SIZE_SMALL);
3613 x += lyxfont::width("Mwide-figM", font);
3615 x -= LYX_PAPER_MARGIN/2;
3617 if (row_ptr->fill() <= size)
3618 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
3619 if (endlabel == END_LABEL_BOX) {
3620 pain.line(x, y, x, y + size,
3622 pain.line(x + size, y, x + size , y + size,
3624 pain.line(x, y, x + size, y,
3626 pain.line(x, y + size, x + size, y + size,
3629 pain.fillRectangle(x, y, size, size,
3633 case END_LABEL_STATIC:
3635 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
3636 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
3637 layout).endlabelstring();
3638 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3639 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
3640 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
3641 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
3644 case END_LABEL_NO_LABEL:
3649 /* draw the text in the pixmap */
3651 vpos = row_ptr->pos();
3653 LyXParagraph::size_type main_body =
3654 BeginningOfMainBody(bview->buffer(), row_ptr->par());
3655 if (main_body > 0 &&
3656 (main_body-1 > last ||
3657 !row_ptr->par()->IsLineSeparator(main_body - 1)))
3660 while (vpos <= last) {
3661 pos = vis2log(vpos);
3662 if (main_body > 0 && pos == main_body - 1) {
3663 x += fill_label_hfill
3664 + lyxfont::width(layout.labelsep,
3665 GetFont(bview->buffer(),
3666 row_ptr->par(), -2))
3667 - SingleWidth(bview,
3672 if (row_ptr->par() ->IsHfill(pos)) {
3675 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3677 y_offset + row_ptr->baseline(),
3680 if (HfillExpansion(bview->buffer(),
3682 if (pos >= main_body) {
3684 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3685 int(x + fill_hfill),
3686 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3688 Painter::line_onoffdash);
3692 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3693 int(x + fill_label_hfill),
3694 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3696 Painter::line_onoffdash);
3698 x += fill_label_hfill;
3701 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3703 y_offset + row_ptr->baseline(),
3708 } else if (row_ptr->par()->IsSeparator(pos)) {
3709 x += SingleWidth(bview,
3710 row_ptr->par(), pos);
3711 if (pos >= main_body)
3712 x += fill_separator;
3715 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
3720 int LyXText::DefaultHeight() const
3722 LyXFont font(LyXFont::ALL_SANE);
3723 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
3727 /* returns the column near the specified x-coordinate of the row
3728 * x is set to the real beginning of this column */
3729 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
3730 bool & boundary) const
3733 float fill_separator, fill_hfill, fill_label_hfill;
3735 PrepareToPrint(bview, row, tmpx, fill_separator,
3736 fill_hfill, fill_label_hfill);
3738 LyXParagraph::size_type vc = row->pos();
3739 LyXParagraph::size_type last = RowLastPrintable(row);
3740 LyXParagraph::size_type c = 0;
3741 LyXLayout const & layout =
3742 textclasslist.Style(bview->buffer()->params.textclass,
3743 row->par()->GetLayout());
3744 bool left_side = false;
3746 LyXParagraph::size_type
3747 main_body = BeginningOfMainBody(bview->buffer(), row->par());
3748 float last_tmpx = tmpx;
3750 if (main_body > 0 &&
3751 (main_body-1 > last ||
3752 !row->par()->IsLineSeparator(main_body - 1)))
3755 while (vc <= last && tmpx <= x) {
3758 if (main_body > 0 && c == main_body-1) {
3759 tmpx += fill_label_hfill +
3760 lyxfont::width(layout.labelsep,
3761 GetFont(bview->buffer(), row->par(), -2));
3762 if (row->par()->IsLineSeparator(main_body - 1))
3763 tmpx -= SingleWidth(bview, row->par(), main_body-1);
3766 if (HfillExpansion(bview->buffer(), row, c)) {
3767 x += SingleWidth(bview, row->par(), c);
3771 tmpx += fill_label_hfill;
3773 else if (row->par()->IsSeparator(c)) {
3774 tmpx += SingleWidth(bview, row->par(), c);
3776 tmpx+= fill_separator;
3778 tmpx += SingleWidth(bview, row->par(), c);
3782 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
3787 if (vc > last + 1) // This shouldn't happen.
3791 #if 0 // currently unused
3792 bool lastrow = (!row->next() || row->next()->par() != row->par());
3793 bool rtl = (lastrow)
3794 ? row->par()->isRightToLeftPar(bview->buffer()->params)
3798 if (row->pos() > last) // Row is empty?
3800 #warning This is wrong, please have a look Dekel (Jug)
3803 ( (rtl && vc == row->pos()&& x < tmpx - 5) ||
3804 (!rtl && vc == last + 1 && x > tmpx + 5) ))
3807 else if (vc == row->pos()) {
3809 if (bidi_level(c) % 2 == 1)
3812 c = vis2log(vc - 1);
3813 bool rtl = (bidi_level(c) % 2 == 1);
3814 if (left_side == rtl) {
3816 boundary = IsBoundary(bview->buffer(), row->par(), c);
3820 if (row->pos() <= last && c > last
3821 && row->par()->IsNewline(last)) {
3822 if (bidi_level(last) % 2 == 0)
3823 tmpx -= SingleWidth(bview, row->par(), last);
3825 tmpx += SingleWidth(bview, row->par(), last);
3836 /* turn the selection into a new environment. If there is no selection,
3837 * create an empty environment */
3838 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
3839 LyXParagraph::footnote_kind kind)
3841 /* no footnoteenvironment in a footnoteenvironment */
3842 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3843 WriteAlert(_("Impossible operation"),
3844 _("You can't insert a float in a float!"),
3848 /* no marginpars in minipages */
3849 if (kind == LyXParagraph::MARGIN
3850 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3851 WriteAlert(_("Impossible operation"),
3852 _("You can't insert a marginpar in a minipage!"),
3857 /* this doesnt make sense, if there is no selection */
3858 bool dummy_selection = false;
3860 sel_start_cursor = cursor; /* dummy selection */
3861 sel_end_cursor = cursor;
3862 dummy_selection = true;
3865 LyXParagraph * tmppar;
3867 /* a test to make sure there is not already a footnote
3868 * in the selection. */
3870 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
3872 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
3873 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3874 tmppar = tmppar->next;
3876 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
3877 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3878 WriteAlert(_("Impossible operation"),
3879 _("Float would include float!"),
3884 /* ok we have a selection. This is always between sel_start_cursor
3885 * and sel_end cursor */
3887 SetUndo(bview->buffer(), Undo::FINISH,
3888 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
3889 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
3891 if (sel_end_cursor.pos() > 0
3892 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
3893 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
3894 /* please break before a space at the end */
3895 if (sel_start_cursor.par() == sel_end_cursor.par()
3896 && sel_start_cursor.pos() > sel_end_cursor.pos())
3897 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
3899 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
3901 sel_end_cursor.par(sel_end_cursor.par()->Next());
3902 sel_end_cursor.pos(0);
3904 // don't forget to insert a dummy layout paragraph if necessary
3905 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
3906 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
3907 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
3908 sel_end_cursor.par(sel_end_cursor.par()->next);
3911 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
3913 cursor = sel_end_cursor;
3915 /* please break behind a space, if there is one. The space should
3917 if (sel_start_cursor.pos() > 0
3918 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
3919 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
3920 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
3921 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
3924 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
3925 sel_start_cursor.pos());
3926 tmppar = sel_start_cursor.par()->Next();
3928 if (dummy_selection) {
3930 if (kind == LyXParagraph::TAB
3931 || kind == LyXParagraph::FIG
3932 || kind == LyXParagraph::WIDE_TAB
3933 || kind == LyXParagraph::WIDE_FIG
3934 || kind == LyXParagraph::ALGORITHM) {
3935 pair<bool, LyXTextClass::size_type> lres =
3936 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
3938 LyXTextClass::size_type lay;
3944 lay = 0; // use default layout "Standard" (0)
3946 tmppar->SetLayout(bview->buffer()->params, lay);
3949 if (sel_start_cursor.pos() > 0) {
3950 /* the footnote-environment should begin with a standard layout.
3951 * Imagine you insert a footnote within an enumeration, you
3952 * certainly do not want an enumerated footnote! */
3955 /* this is a exception the user would sometimes expect, I hope */
3956 sel_start_cursor.par()->Clear();
3960 while (tmppar != sel_end_cursor.par()) {
3961 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
3962 tmppar->footnotekind = kind;
3963 tmppar = tmppar->Next();
3966 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
3968 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
3975 // returns pointer to a specified row
3976 Row * LyXText::GetRow(LyXParagraph * par,
3977 LyXParagraph::size_type pos, int & y) const
3979 Row * tmprow = firstrow;
3982 // find the first row of the specified paragraph
3983 while (tmprow->next() && tmprow->par() != par) {
3984 y += tmprow->height();
3985 tmprow = tmprow->next();
3988 // now find the wanted row
3989 while (tmprow->pos() < pos
3991 && tmprow->next()->par() == par
3992 && tmprow->next()->pos() <= pos) {
3993 y += tmprow->height();
3994 tmprow = tmprow->next();