1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #include "lyxparagraph.h"
19 #include "support/textutils.h"
20 #include "insets/insetbib.h"
21 #include "insets/insettext.h"
22 #include "lyx_gui_misc.h"
24 #include "bufferparams.h"
26 #include "minibuffer.h"
35 #include "lyxscreen.h"
36 #include "bufferview_funcs.h"
43 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
48 int LyXText::workWidth(BufferView * bview) const
51 return inset_owner->textWidth(bview->painter());
53 return bview->workWidth();
57 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
58 LyXParagraph::size_type pos) const
60 if (!Encodings::is_arabic(c))
61 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
62 return c + (0xb0 - '0');
66 unsigned char prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
67 unsigned char next_char = ' ';
68 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
69 if (!Encodings::IsComposeChar_arabic(par->GetChar(i))) {
70 next_char = par->GetChar(i);
74 if (Encodings::is_arabic(next_char)) {
75 if (Encodings::is_arabic(prev_char))
76 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
78 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
80 if (Encodings::is_arabic(prev_char))
81 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
83 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
87 // This is the comments that some of the warnings below refers to.
88 // There are some issues in this file and I don't think they are
89 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
90 // this is a problem that has been here almost from day one and that a
91 // larger userbase with differenct access patters triggers the bad
92 // behaviour. (segfaults.) What I think happen is: In several places
93 // we store the paragraph in the current cursor and then moves the
94 // cursor. This movement of the cursor will delete paragraph at the
95 // old position if it is now empty. This will make the temporary
96 // pointer to the old cursor paragraph invalid and dangerous to use.
97 // And is some cases this will trigger a segfault. I have marked some
98 // of the cases where this happens with a warning, but I am sure there
99 // are others in this file and in text2.C. There is also a note in
100 // Delete() that you should read. In Delete I store the paragraph->id
101 // instead of a pointer to the paragraph. I am pretty sure this faulty
102 // use of temporary pointers to paragraphs that might have gotten
103 // invalidated (through a cursor movement) before they are used, are
104 // the cause of the strange crashes we get reported often.
106 // It is very tiresom to change this code, especially when it is as
107 // hard to read as it is. Help to fix all the cases where this is done
108 // would be greately appreciated.
112 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
113 LyXParagraph::size_type pos) const
115 char const c = par->GetChar(pos);
116 return SingleWidth(bview, par, pos, c);
120 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
121 LyXParagraph::size_type pos, char c) const
123 LyXFont font = GetFont(bview->buffer(), par, pos);
125 // The most common case is handled first (Asger)
126 if (IsPrintable(c)) {
127 if (font.language()->RightToLeft()) {
128 if (font.language()->lang() == "arabic" &&
129 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
130 lyxrc.font_norm_type == LyXRC::ISO_10646_1))
131 if (Encodings::IsComposeChar_arabic(c))
134 c = TransformChar(c, par, pos);
135 else if (font.language()->lang() == "hebrew" &&
136 Encodings::IsComposeChar_hebrew(c))
139 return lyxfont::width(c, font);
141 } else if (IsHfillChar(c)) {
142 return 3; /* Because of the representation
143 * as vertical lines */
145 } else if (c == LyXParagraph::META_FOOTNOTE ||
146 c == LyXParagraph::META_MARGIN ||
147 c == LyXParagraph::META_FIG ||
148 c == LyXParagraph::META_TAB ||
149 c == LyXParagraph::META_WIDE_FIG ||
150 c == LyXParagraph::META_WIDE_TAB ||
151 c == LyXParagraph::META_ALGORITHM) {
154 case LyXParagraph::META_MARGIN:
157 case LyXParagraph::META_FIG:
160 case LyXParagraph::META_TAB:
163 case LyXParagraph::META_ALGORITHM:
166 case LyXParagraph::META_WIDE_FIG:
169 case LyXParagraph::META_WIDE_TAB:
172 case LyXParagraph::META_FOOTNOTE:
178 return lyxfont::width(fs, font);
180 } else if (c == LyXParagraph::META_INSET) {
181 Inset * tmpinset = par->GetInset(pos);
183 tmpinset->update(bview, font);
184 return tmpinset->width(bview, font);
188 } else if (IsSeparatorChar(c))
190 else if (IsNewlineChar(c))
192 return lyxfont::width(c, font);
196 // Returns the paragraph position of the last character in the specified row
197 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
199 if (row->next() == 0)
200 return row->par()->Last() - 1;
201 else if (row->next()->par() != row->par())
202 return row->par()->Last() - 1;
204 return row->next()->pos() - 1;
208 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
210 LyXParagraph::size_type last = RowLast(row);
211 if (last >= row->pos()
213 && row->next()->par() == row->par()
214 && row->par()->IsSeparator(last))
221 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
223 bidi_same_direction = true;
224 if (!lyxrc.rtl_support) {
229 bidi_start = row->pos();
230 bidi_end = RowLastPrintable(row);
232 if (bidi_start > bidi_end) {
237 if (bidi_end + 2 - bidi_start >
238 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
239 LyXParagraph::size_type new_size =
240 (bidi_end + 2 - bidi_start < 500) ?
241 500 : 2 * (bidi_end + 2 - bidi_start);
242 log2vis_list.resize(new_size);
243 vis2log_list.resize(new_size);
244 bidi_levels.resize(new_size);
247 vis2log_list[bidi_end + 1 - bidi_start] = -1;
248 log2vis_list[bidi_end + 1 - bidi_start] = -1;
250 LyXParagraph::size_type stack[2];
251 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
255 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
257 for (LyXParagraph::size_type lpos = bidi_start;
258 lpos <= bidi_end; ++lpos) {
259 bool is_space = row->par()->IsLineSeparator(lpos);
260 LyXParagraph::size_type pos =
261 (is_space && lpos + 1 <= bidi_end &&
262 !row->par()->IsLineSeparator(lpos + 1) &&
263 !row->par()->IsNewline(lpos + 1))
265 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
266 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
267 font.number() == LyXFont::ON &&
268 row->par()->GetFontSettings(buf->params, lpos-1).number()
270 font = row->par()->GetFontSettings(buf->params, lpos);
275 bool new_rtl = font.isVisibleRightToLeft();
276 bool new_rtl0 = font.isRightToLeft();
279 if (lpos == main_body - 1
280 && row->pos() < main_body - 1
282 new_level = (rtl_par) ? 1 : 0;
283 new_rtl = new_rtl0 = rtl_par;
285 new_level = (new_rtl) ? 1 : 2;
287 new_level = (rtl_par) ? 2 : 0;
289 if (is_space && new_level >= level) {
295 int new_level2 = new_level;
297 if (level == new_level && rtl0 != new_rtl0) {
299 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
300 } else if (level < new_level) {
301 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
302 if (new_level > rtl_par)
303 bidi_same_direction = false;
305 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
308 bidi_levels[lpos - bidi_start] = new_level;
310 while (level > new_level2) {
311 LyXParagraph::size_type old_lpos =
313 int delta = lpos - old_lpos - 1;
316 log2vis_list[lpos - bidi_start] += delta;
317 log2vis_list[old_lpos - bidi_start] += delta;
319 while (level < new_level)
320 stack[level++] = lpos;
324 LyXParagraph::size_type old_lpos = stack[--level];
325 int delta = bidi_end - old_lpos;
328 log2vis_list[old_lpos - bidi_start] += delta;
331 LyXParagraph::size_type vpos = bidi_start - 1;
332 for (LyXParagraph::size_type lpos = bidi_start;
333 lpos <= bidi_end; ++lpos) {
334 vpos += log2vis_list[lpos - bidi_start];
335 vis2log_list[vpos - bidi_start] = lpos;
336 log2vis_list[lpos - bidi_start] = vpos;
341 // This method requires a previous call to ComputeBidiTables()
342 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
343 LyXParagraph::size_type pos) const
345 if (!lyxrc.rtl_support)
346 return false; // This is just for speedup
348 if (!bidi_InRange(pos - 1))
351 bool const rtl = bidi_level(pos - 1) % 2;
353 if (pos == par->Last())
354 rtl2 = par->isRightToLeftPar(buf->params);
355 else if (bidi_InRange(pos))
356 rtl2 = bidi_level(pos) % 2;
361 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
362 LyXParagraph::size_type pos,
363 LyXFont const & font) const
365 if (!lyxrc.rtl_support)
366 return false; // This is just for speedup
368 bool const rtl = font.isVisibleRightToLeft();
370 if (pos == par->Last())
371 rtl2 = par->isRightToLeftPar(buf->params);
372 else if (bidi_InRange(pos))
373 rtl2 = bidi_level(pos) % 2;
378 void LyXText::draw(BufferView * bview, Row const * row,
379 LyXParagraph::size_type & vpos,
380 int offset, float & x, bool cleared)
382 Painter & pain = bview->painter();
384 LyXParagraph::size_type pos = vis2log(vpos);
385 char c = row->par()->GetChar(pos);
388 if (IsNewlineChar(c)) {
390 // Draw end-of-line marker
391 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
392 int wid = lyxfont::width('n', font);
393 int asc = lyxfont::maxAscent(font);
394 int y = offset + row->baseline();
397 if (bidi_level(pos) % 2 == 0) {
398 xp[0] = int(x + wid * 0.375);
399 yp[0] = int(y - 0.875 * asc * 0.75);
402 yp[1] = int(y - 0.500 * asc * 0.75);
404 xp[2] = int(x + wid * 0.375);
405 yp[2] = int(y - 0.125 * asc * 0.75);
407 pain.lines(xp, yp, 3, LColor::eolmarker);
410 yp[0] = int(y - 0.500 * asc * 0.75);
412 xp[1] = int(x + wid);
413 yp[1] = int(y - 0.500 * asc * 0.75);
415 xp[2] = int(x + wid);
416 yp[2] = int(y - asc * 0.75);
418 pain.lines(xp, yp, 3, LColor::eolmarker);
420 xp[0] = int(x + wid * 0.625);
421 yp[0] = int(y - 0.875 * asc * 0.75);
423 xp[1] = int(x + wid);
424 yp[1] = int(y - 0.500 * asc * 0.75);
426 xp[2] = int(x + wid * 0.625);
427 yp[2] = int(y - 0.125 * asc * 0.75);
429 pain.lines(xp, yp, 3, LColor::eolmarker);
431 xp[0] = int(x + wid);
432 yp[0] = int(y - 0.500 * asc * 0.75);
435 yp[1] = int(y - 0.500 * asc * 0.75);
438 yp[2] = int(y - asc * 0.75);
440 pain.lines(xp, yp, 3, LColor::eolmarker);
446 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
447 LyXFont font2 = font;
449 if (c == LyXParagraph::META_FOOTNOTE
450 || c == LyXParagraph::META_MARGIN
451 || c == LyXParagraph::META_FIG
452 || c == LyXParagraph::META_TAB
453 || c == LyXParagraph::META_WIDE_FIG
454 || c == LyXParagraph::META_WIDE_TAB
455 || c == LyXParagraph::META_ALGORITHM) {
458 case LyXParagraph::META_MARGIN:
461 case LyXParagraph::META_FIG:
464 case LyXParagraph::META_TAB:
467 case LyXParagraph::META_ALGORITHM:
470 case LyXParagraph::META_WIDE_FIG:
473 case LyXParagraph::META_WIDE_TAB:
476 case LyXParagraph::META_FOOTNOTE:
483 // calculate the position of the footnotemark
484 int y = (row->baseline() - lyxfont::maxAscent(font2)
485 + lyxfont::maxAscent(font));
487 font.setColor(LColor::footnote);
489 // draw it and set new x position
491 pain.text(int(x), offset + y, fs, font);
492 x += lyxfont::width(fs, font);
493 pain.line(int(tmpx), offset + row->baseline(),
494 int(x), offset + row->baseline(),
501 if (c == LyXParagraph::META_INSET) {
502 Inset * tmpinset = row->par()->GetInset(pos);
504 // tmpinset->update(bview, font, false);
505 tmpinset->draw(bview, font, offset+row->baseline(), x,
507 if (status == CHANGED_IN_DRAW) {
508 UpdateInset(bview, tmpinset);
509 status = CHANGED_IN_DRAW;
514 if (lyxrc.mark_foreign_language &&
515 font.language() != bview->buffer()->params.language) {
516 int y = offset + row->height() - 1;
517 pain.line(int(tmpx), y, int(x), y,
524 /* usual characters, no insets */
526 // Collect character that we can draw in one command
528 // This is dirty, but fast. Notice that it will never be too small.
529 // For the record, I'll note that Microsoft Word has a limit
530 // of 768 here. We have none :-) (Asger)
531 // Ok. I am the first to admit that the use of std::string will be
532 // a tiny bit slower than using a POD char array. However, I claim
533 // that this slowdown is so small that it is close to inperceptive.
534 // So IMHO we should go with the easier and clearer implementation.
535 // And even if 1024 is a large number here it might overflow, string
536 // will only overflow if the machine is out of memory...
537 static string textstring;
541 LyXParagraph::size_type last = RowLastPrintable(row);
543 if (font.language()->lang() == "hebrew") {
544 if (Encodings::IsComposeChar_hebrew(c)) {
545 int width = lyxfont::width(c, font2);
547 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
548 c = row->par()->GetChar(i);
549 if (!Encodings::IsComposeChar_hebrew(c)) {
550 if (IsPrintableNonspace(c)) {
551 int width2 = SingleWidth(bview, row->par(), i, c);
552 dx = (c == 'ø' || c == 'ã') // dalet / resh
553 ? width2 - width : (width2 - width) / 2;
559 pain.text(int(x) + dx, offset + row->baseline(),
562 while (vpos <= last &&
563 (pos = vis2log(vpos)) >= 0
564 && IsPrintableNonspace(c = row->par()->GetChar(pos))
565 && !Encodings::IsComposeChar_hebrew(c)
566 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
570 // Draw text and set the new x position
571 pain.text(int(x), offset + row->baseline(),
573 x += lyxfont::width(textstring, font);
575 } else if (font.language()->lang() == "arabic" &&
576 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
577 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
578 if (Encodings::IsComposeChar_arabic(c)) {
579 c = TransformChar(c, row->par(), pos);
581 int width = lyxfont::width(c, font2);
583 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
584 c = row->par()->GetChar(i);
585 if (!Encodings::IsComposeChar_arabic(c)) {
586 if (IsPrintableNonspace(c)) {
587 int width2 = SingleWidth(bview, row->par(), i, c);
588 dx = (width2 - width) / 2;
594 pain.text(int(x) + dx, offset + row->baseline(),
597 textstring = TransformChar(c, row->par(), pos);
598 while (vpos <= last &&
599 (pos = vis2log(vpos)) >= 0
600 && IsPrintableNonspace(c = row->par()->GetChar(pos))
601 && !Encodings::IsComposeChar_arabic(c)
602 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
603 c = TransformChar(c, row->par(), pos);
607 // Draw text and set the new x position
608 pain.text(int(x), offset + row->baseline(),
610 x += lyxfont::width(textstring, font);
613 while (vpos <= last &&
614 (pos = vis2log(vpos)) >= 0
615 && IsPrintableNonspace(c = row->par()->GetChar(pos))
616 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
620 // Draw text and set the new x position
621 pain.text(int(x), offset + row->baseline(), textstring, font);
622 x += lyxfont::width(textstring, font);
625 if (lyxrc.mark_foreign_language &&
626 font.language() != bview->buffer()->params.language) {
627 int y = offset + row->height() - 1;
628 pain.line(int(tmpx), y, int(x), y,
632 // If we want ulem.sty support, drawing
633 // routines should go here. (Asger)
634 // Why shouldn't LyXFont::drawText handle it internally?
638 // Returns the left beginning of the text.
639 // This information cannot be taken from the layouts-objekt, because in
640 // LaTeX the beginning of the text fits in some cases (for example sections)
641 // exactly the label-width.
642 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
644 LyXLayout const & layout =
645 textclasslist.Style(bview->buffer()->params.textclass,
646 row->par()->GetLayout());
648 string parindent = layout.parindent;
650 int x = LYX_PAPER_MARGIN;
652 x += lyxfont::signedWidth(textclasslist
653 .TextClass(bview->buffer()->params.textclass)
656 .TextClass(bview->buffer()->params.textclass)
659 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
660 LyXFont font(LyXFont::ALL_SANE);
661 font.setSize(LyXFont::SIZE_SMALL);
662 x += lyxfont::width("Mwide-figM", font)
663 + LYX_PAPER_MARGIN/2;
666 // this is the way, LyX handles the LaTeX-Environments.
667 // I have had this idea very late, so it seems to be a
668 // later added hack and this is true
669 if (!row->par()->GetDepth()) {
670 if (!row->par()->GetLayout()) {
671 // find the previous same level paragraph
673 if (row->par()->FirstPhysicalPar()->Previous()) {
675 if (row->par()->Previous()) {
677 LyXParagraph * newpar = row->par()
678 ->DepthHook(row->par()->GetDepth());
680 textclasslist.Style(bview->buffer()->params.textclass,
687 // find the next level paragraph
689 LyXParagraph * newpar =
690 row->par()->DepthHook(row->par()->GetDepth()-1);
692 // make a corresponding row. Needed to call LeftMargin()
694 // check wether it is a sufficent paragraph
697 && newpar->footnoteflag == row->par()->footnoteflag
700 .Style(bview->buffer()->params.textclass,
701 newpar->GetLayout()).isEnvironment()) {
703 dummyrow.par(newpar);
704 dummyrow.pos(newpar->Last());
705 x = LeftMargin(bview, &dummyrow);
707 // this is no longer an error, because this function
708 // is used to clear impossible depths after changing
709 // a layout. Since there is always a redo,
710 // LeftMargin() is always called
712 row->par()->FirstPhysicalPar()->depth = 0;
714 row->par()->depth = 0;
718 if (newpar && !row->par()->GetLayout()) {
720 if (newpar->FirstPhysicalPar()->noindent)
722 if (newpar->noindent)
726 parindent = textclasslist
727 .Style(bview->buffer()->params.textclass,
728 newpar->GetLayout()).parindent;
733 LyXFont const labelfont = GetFont(bview->buffer(), row->par(), -2);
734 switch (layout.margintype) {
736 if (!layout.leftmargin.empty()) {
737 x += lyxfont::signedWidth(layout.leftmargin,
739 .TextClass(bview->buffer()->params.
743 if (!row->par()->GetLabelstring().empty()) {
744 x += lyxfont::signedWidth(layout.labelindent,
746 x += lyxfont::width(row->par()->GetLabelstring(),
748 x += lyxfont::width(layout.labelsep, labelfont);
752 x += lyxfont::signedWidth(layout.labelindent, labelfont);
753 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
754 if (!row->par()->GetLabelWidthString().empty()) {
755 x += lyxfont::width(row->par()->GetLabelWidthString(),
757 x += lyxfont::width(layout.labelsep, labelfont);
762 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
763 / (row->par()->GetDepth() + 4);
765 case MARGIN_FIRST_DYNAMIC:
766 if (layout.labeltype == LABEL_MANUAL) {
767 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
768 x += lyxfont::signedWidth(layout.leftmargin,
771 x += lyxfont::signedWidth(layout.labelindent,
774 } else if (row->pos()
775 // Special case to fix problems with
777 || (layout.labeltype == LABEL_STATIC
778 && layout.latextype == LATEX_ENVIRONMENT
779 && ! row->par()->IsFirstInSequence())) {
780 x += lyxfont::signedWidth(layout.leftmargin,
782 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
783 && layout.labeltype != LABEL_BIBLIO
784 && layout.labeltype !=
785 LABEL_CENTERED_TOP_ENVIRONMENT) {
786 x += lyxfont::signedWidth(layout.labelindent,
788 x += lyxfont::width(layout.labelsep, labelfont);
789 x += lyxfont::width(row->par()->GetLabelstring(),
794 case MARGIN_RIGHT_ADDRESS_BOX:
796 // ok, a terrible hack. The left margin depends on the widest
797 // row in this paragraph. Do not care about footnotes, they
798 // are *NOT* allowed in the LaTeX realisation of this layout.
800 // find the first row of this paragraph
801 Row const * tmprow = row;
802 while (tmprow->previous()
803 && tmprow->previous()->par() == row->par())
804 tmprow = tmprow->previous();
806 int minfill = tmprow->fill();
807 while (tmprow->next() && tmprow->next()->par() == row->par()) {
808 tmprow = tmprow->next();
809 if (tmprow->fill() < minfill)
810 minfill = tmprow->fill();
813 x += lyxfont::signedWidth(layout.leftmargin,
815 .TextClass(bview->buffer()->params.textclass)
821 if ((workWidth(bview) > 0) &&
822 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT)) {
823 if (!row->par()->pextra_widthp.empty()) {
824 x += workWidth(bview) *
825 lyx::atoi(row->par()->pextra_widthp) / 100;
826 } else if (!row->par()->pextra_width.empty()) {
827 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
828 if (xx > workWidth(bview))
829 xx = workWidth(bview) * 80 / 100;
831 } else { // should not happen
832 LyXFont font(LyXFont::ALL_SANE);
833 x += lyxfont::width("XXXXXX", font);
837 int align; // wrong type
839 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
840 align = layout.align;
842 align = row->par()->FirstPhysicalPar()->align;
844 if (row->par()->align == LYX_ALIGN_LAYOUT)
845 align = layout.align;
847 align = row->par()->align;
849 // set the correct parindent
850 if (row->pos() == 0) {
851 if ((layout.labeltype == LABEL_NO_LABEL
852 || layout.labeltype == LABEL_TOP_ENVIRONMENT
853 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
854 || (layout.labeltype == LABEL_STATIC
855 && layout.latextype == LATEX_ENVIRONMENT
856 && ! row->par()->IsFirstInSequence()))
858 && row->par() == row->par()->FirstPhysicalPar()
860 && align == LYX_ALIGN_BLOCK
861 && !row->par()->noindent
862 && (row->par()->layout ||
863 bview->buffer()->params.paragraph_separation ==
864 BufferParams::PARSEP_INDENT))
865 x += lyxfont::signedWidth(parindent,
867 .TextClass(bview->buffer()->params
870 else if (layout.labeltype == LABEL_BIBLIO) {
871 // ale970405 Right width for bibitems
872 x += bibitemMaxWidth(bview,textclasslist
873 .TextClass(bview->buffer()->params
882 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
884 LyXLayout const & layout =
885 textclasslist.Style(buf->params.textclass,
886 row->par()->GetLayout());
888 int x = LYX_PAPER_MARGIN
889 + lyxfont::signedWidth(textclasslist
890 .TextClass(buf->params.textclass)
893 .TextClass(buf->params.textclass)
897 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
898 x += LYX_PAPER_MARGIN / 2;
901 // this is the way, LyX handles the LaTeX-Environments.
902 // I have had this idea very late, so it seems to be a
903 // later added hack and this is true
904 if (row->par()->GetDepth()) {
905 // find the next level paragraph
907 LyXParagraph * newpar = row->par();
911 newpar = newpar->FirstPhysicalPar()->Previous();
913 newpar = newpar->FirstPhysicalPar();
914 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
915 && newpar->footnoteflag == row->par()->footnoteflag);
918 newpar = newpar->Previous();
920 && newpar->GetDepth() >= row->par()->GetDepth());
923 // make a corresponding row. Needed to call LeftMargin()
925 // check wether it is a sufficent paragraph
928 && newpar->footnoteflag == row->par()->footnoteflag
930 && textclasslist.Style(buf->params.textclass,
934 dummyrow.par(newpar);
936 x = RightMargin(buf, &dummyrow);
938 // this is no longer an error, because this function
939 // is used to clear impossible depths after changing
940 // a layout. Since there is always a redo,
941 // LeftMargin() is always called
943 row->par()->FirstPhysicalPar()->depth = 0;
945 row->par()->depth = 0;
950 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
951 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
952 .TextClass(buf->params.textclass)
953 .defaultfont()) * 4 / (row->par()->GetDepth()
959 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
961 if (textclasslist.Style(bview->buffer()->params.textclass,
962 row->par()->GetLayout()).margintype
966 tmprow.pos(row->par()->Last());
967 return LeftMargin(bview, &tmprow); /* just the beginning
970 return 0; /* LabelEnd is only needed, if the
971 layout fills a flushleft
976 // get the next breakpoint in a given paragraph
977 LyXParagraph::size_type
978 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
980 LyXParagraph * par = row->par();
981 LyXParagraph::size_type pos = row->pos();
986 // position of the last possible breakpoint
987 // -1 isn't a suitable value, but a flag
988 LyXParagraph::size_type last_separator = -1;
989 width -= RightMargin(bview->buffer(), row);
991 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
992 LyXLayout const & layout =
993 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
994 LyXParagraph::size_type i = pos;
996 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
997 /* special code for right address boxes, only newlines count */
998 while (i < par->Last()) {
999 if (par->IsNewline(i)) {
1001 i = par->Last() - 1; // this means break
1003 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1004 par->GetInset(i) && par->GetInset(i)->display()){
1005 par->GetInset(i)->display(false);
1010 // Last position is an invariant
1011 LyXParagraph::size_type const last =
1013 // this is the usual handling
1014 int x = LeftMargin(bview, row);
1015 bool doitonetime = true;
1016 while (doitonetime || ((x < width) && (i < last))) {
1017 doitonetime = false;
1018 char c = par->GetChar(i);
1019 if (IsNewlineChar(c)) {
1021 x = width; // this means break
1022 } else if (c == LyXParagraph::META_INSET &&
1025 // check wether a Display() inset is
1026 // valid here. if not, change it to
1028 if (par->GetInset(i)->display() &&
1029 (layout.isCommand() ||
1030 ((layout.labeltype == LABEL_MANUAL) &&
1031 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1032 // display istn't allowd
1033 par->GetInset(i)->display(false);
1034 x += SingleWidth(bview, par, i, c);
1035 } else if (par->GetInset(i)->display() ||
1036 par->GetInset(i)->needFullRow()) {
1037 // So break the line here
1041 if (IsLineSeparatorChar(par->GetChar(i+1)))
1044 last_separator = last; // to avoid extra rows
1046 last_separator = i - 1;
1047 x = width; // this means break
1053 x += SingleWidth(bview, par, i, c);
1057 if (IsLineSeparatorChar(c))
1059 x += SingleWidth(bview, par, i, c);
1062 if (i == main_body) {
1063 x += lyxfont::width(layout.labelsep,
1064 GetFont(bview->buffer(), par, -2));
1065 if (par->IsLineSeparator(i - 1))
1066 x-= SingleWidth(bview, par, i - 1);
1067 int left_margin = LabelEnd(bview, row);
1068 if (x < left_margin)
1072 // end of paragraph is always a suitable separator
1073 if (i == last && x < width)
1077 // well, if last_separator is still 0, the line isn't breakable.
1078 // don't care and cut simply at the end
1079 if (last_separator < 0) {
1083 // manual labels cannot be broken in LaTeX, do not care
1084 if (main_body && last_separator < main_body)
1085 last_separator = main_body - 1;
1087 return last_separator;
1091 // returns the minimum space a row needs on the screen in pixel
1092 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1094 if (paper_width < 0)
1098 // get the pure distance
1099 LyXParagraph::size_type last = RowLastPrintable(row);
1101 // special handling of the right address boxes
1102 if (textclasslist.Style(bview->buffer()->params.textclass,
1103 row->par()->GetLayout()).margintype
1104 == MARGIN_RIGHT_ADDRESS_BOX) {
1105 int tmpfill = row->fill();
1106 row->fill(0); // the minfill in MarginLeft()
1107 w = LeftMargin(bview, row);
1110 w = LeftMargin(bview, row);
1112 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1113 row->par()->GetLayout());
1114 LyXParagraph::size_type main_body =
1115 BeginningOfMainBody(bview->buffer(), row->par());
1116 LyXParagraph::size_type i = row->pos();
1119 if (main_body > 0 && i == main_body) {
1120 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1121 if (row->par()->IsLineSeparator(i - 1))
1122 w -= SingleWidth(bview, row->par(), i - 1);
1123 int left_margin = LabelEnd(bview, row);
1124 if (w < left_margin)
1127 w += SingleWidth(bview, row->par(), i);
1130 if (main_body > 0 && main_body > last) {
1131 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1132 if (last >= 0 && row->par()->IsLineSeparator(last))
1133 w -= SingleWidth(bview, row->par(), last);
1134 int left_margin = LabelEnd(bview, row);
1135 if (w < left_margin)
1139 int const fill = paper_width - w - RightMargin(bview->buffer(), row);
1144 // returns the minimum space a manual label needs on the screen in pixel
1145 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1147 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par()) - 1;
1148 // -1 because a label ends either with a space that is in the label,
1149 // or with the beginning of a footnote that is outside the label.
1151 // I don't understand this code in depth, but sometimes "last" is
1152 // less than 0 and this causes a crash. This fix seems to work
1153 // correctly, but I bet the real error is elsewhere. The bug is
1154 // triggered when you have an open footnote in a paragraph
1155 // environment with a manual label. (Asger)
1156 if (last < 0) last = 0;
1158 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1165 w += SingleWidth(bview, row->par(), i);
1170 if (!row->par()->labelwidthstring.empty()) {
1171 fill = max(lyxfont::width(row->par()->labelwidthstring,
1172 GetFont(bview->buffer(), row->par(), -2)) - w,
1180 // returns the number of separators in the specified row. The separator
1181 // on the very last column doesnt count
1182 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1184 LyXParagraph::size_type const last = RowLast(row);
1185 LyXParagraph::size_type p =
1186 max(row->pos(), BeginningOfMainBody(buf, row->par()));
1188 for (; p < last; ++p) {
1189 if (row->par()->IsSeparator(p)) {
1197 // returns the number of hfills in the specified row. The LyX-Hfill is
1198 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1199 // ignored. This is *MUCH* more usefull than not to ignore!
1200 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1202 LyXParagraph::size_type const last = RowLast(row);
1203 LyXParagraph::size_type first = row->pos();
1204 if (first) { /* hfill *DO* count at the beginning
1206 while(first <= last && row->par()->IsHfill(first))
1210 first = max(first, BeginningOfMainBody(buf, row->par()));
1212 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1213 if (row->par()->IsHfill(p)) {
1221 // like NumberOfHfills, but only those in the manual label!
1222 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1224 LyXParagraph::size_type last = RowLast(row);
1225 LyXParagraph::size_type first = row->pos();
1226 if (first) { /* hfill *DO* count at the beginning
1228 while(first < last && row->par()->IsHfill(first))
1232 last = min(last, BeginningOfMainBody(buf, row->par()));
1234 for (LyXParagraph::size_type p = first;
1235 p < last; ++p) { // last, because the end is ignored!
1236 if (row->par()->IsHfill(p)) {
1244 // returns true, if a expansion is needed.
1245 // Rules are given by LaTeX
1246 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1247 LyXParagraph::size_type pos) const
1249 // by the way, is it a hfill?
1250 if (!row_ptr->par()->IsHfill(pos))
1253 // at the end of a row it does not count
1254 if (pos >= RowLast(row_ptr))
1257 // at the beginning of a row it does not count, if it is not
1258 // the first row of a paragaph
1259 if (!row_ptr->pos())
1262 // in some labels it does not count
1263 if (textclasslist.Style(buf->params.textclass,
1264 row_ptr->par()->GetLayout()).margintype
1266 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1269 // if there is anything between the first char of the row and
1270 // the sepcified position that is not a newline and not a hfill,
1271 // the hfill will count, otherwise not
1272 LyXParagraph::size_type i = row_ptr->pos();
1273 while (i < pos && (row_ptr->par()->IsNewline(i)
1274 || row_ptr->par()->IsHfill(i)))
1281 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1283 /* get the maximum ascent and the maximum descent */
1286 float layoutasc = 0;
1287 float layoutdesc = 0;
1290 Inset * tmpinset = 0;
1292 /* this must not happen before the currentrow for clear reasons.
1293 so the trick is just to set the current row onto this row */
1295 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1297 /* ok , let us initialize the maxasc and maxdesc value.
1298 * This depends in LaTeX of the font of the last character
1299 * in the paragraph. The hack below is necessary because
1300 * of the possibility of open footnotes */
1302 /* Correction: only the fontsize count. The other properties
1303 are taken from the layoutfont. Nicer on the screen :) */
1305 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1306 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1308 LyXParagraph * par = row_ptr->par();
1309 LyXParagraph * firstpar = row_ptr->par();
1312 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1313 firstpar->GetLayout());
1315 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1316 LyXFont::FONT_SIZE size = font.size();
1317 font = GetFont(bview->buffer(), par, -1);
1320 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1322 float spacing_val = 1.0;
1323 if (!row_ptr->par()->spacing.isDefault()) {
1324 spacing_val = row_ptr->par()->spacing.getValue();
1326 spacing_val = bview->buffer()->params.spacing.getValue();
1328 //lyxerr << "spacing_val = " << spacing_val << endl;
1330 int maxasc = int(lyxfont::maxAscent(font) *
1331 layout.spacing.getValue() *
1333 int maxdesc = int(lyxfont::maxDescent(font) *
1334 layout.spacing.getValue() *
1336 int pos_end = RowLast(row_ptr);
1340 // Check if any insets are larger
1341 for (int pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1342 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1343 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1344 tmpinset = row_ptr->par()->GetInset(pos);
1346 tmpinset->update(bview, tmpfont);
1347 asc = tmpinset->ascent(bview, tmpfont);
1348 desc = tmpinset->descent(bview, tmpfont);
1349 maxwidth += tmpinset->width(bview, tmpfont);
1350 maxasc = max(maxasc, asc);
1351 maxdesc = max(maxdesc, desc);
1354 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1358 // Check if any custom fonts are larger (Asger)
1359 // This is not completely correct, but we can live with the small,
1360 // cosmetic error for now.
1361 LyXFont::FONT_SIZE maxsize =
1362 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1364 if (maxsize > font.size()) {
1365 font.setSize(maxsize);
1367 asc = lyxfont::maxAscent(font);
1368 desc = lyxfont::maxDescent(font);
1375 // This is nicer with box insets:
1379 row_ptr->ascent_of_text(maxasc);
1381 /* is it a top line? */
1382 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1384 /* some parksips VERY EASY IMPLEMENTATION */
1385 if (bview->buffer()->params.paragraph_separation ==
1386 BufferParams::PARSEP_SKIP) {
1387 if (layout.isParagraph()
1388 && firstpar->GetDepth() == 0
1389 && firstpar->Previous())
1390 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1391 else if (firstpar->Previous()
1392 && textclasslist.Style(bview->buffer()->params.textclass,
1393 firstpar->Previous()->GetLayout()).isParagraph()
1394 && firstpar->Previous()->GetDepth() == 0)
1395 // is it right to use defskip here too? (AS)
1396 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1399 /* the paper margins */
1400 if (!row_ptr->par()->previous && bv_owner)
1401 maxasc += LYX_PAPER_MARGIN;
1403 /* add the vertical spaces, that the user added */
1404 if (firstpar->added_space_top.kind() != VSpace::NONE)
1405 maxasc += int(firstpar->added_space_top.inPixels(bview));
1407 /* do not forget the DTP-lines!
1408 * there height depends on the font of the nearest character */
1409 if (firstpar->line_top)
1410 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1413 /* and now the pagebreaks */
1414 if (firstpar->pagebreak_top)
1415 maxasc += 3 * DefaultHeight();
1417 /* this is special code for the chapter, since the label of this
1418 * layout is printed in an extra row */
1419 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1420 && bview->buffer()->params.secnumdepth >= 0) {
1421 float spacing_val = 1.0;
1422 if (!row_ptr->par()->spacing.isDefault()) {
1423 spacing_val = row_ptr->par()->spacing.getValue();
1425 spacing_val = bview->buffer()->params.spacing.getValue();
1428 labeladdon = int(lyxfont::maxDescent(labelfont) *
1429 layout.spacing.getValue() *
1431 + int(lyxfont::maxAscent(labelfont) *
1432 layout.spacing.getValue() *
1436 /* special code for the top label */
1437 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1438 || layout.labeltype == LABEL_BIBLIO
1439 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1440 && row_ptr->par()->IsFirstInSequence()
1441 && !row_ptr->par()->GetLabelstring().empty()) {
1442 float spacing_val = 1.0;
1443 if (!row_ptr->par()->spacing.isDefault()) {
1444 spacing_val = row_ptr->par()->spacing.getValue();
1446 spacing_val = bview->buffer()->params.spacing.getValue();
1450 (lyxfont::maxAscent(labelfont) *
1451 layout.spacing.getValue() *
1453 +(lyxfont::maxDescent(labelfont) *
1454 layout.spacing.getValue() *
1456 + layout.topsep * DefaultHeight()
1457 + layout.labelbottomsep * DefaultHeight());
1460 /* and now the layout spaces, for example before and after a section,
1461 * or between the items of a itemize or enumerate environment */
1463 if (!firstpar->pagebreak_top) {
1464 LyXParagraph * prev = row_ptr->par()->Previous();
1466 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1467 if (prev && prev->GetLayout() == firstpar->GetLayout()
1468 && prev->GetDepth() == firstpar->GetDepth()
1469 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1471 layoutasc = (layout.itemsep * DefaultHeight());
1473 else if (row_ptr->previous()) {
1474 tmptop = layout.topsep;
1476 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1477 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1478 row_ptr->previous()->par()->
1479 GetLayout()).bottomsep;
1482 layoutasc = (tmptop * DefaultHeight());
1484 else if (row_ptr->par()->line_top){
1485 tmptop = layout.topsep;
1488 layoutasc = (tmptop * DefaultHeight());
1491 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1493 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1494 prev->GetLayout()).parsep * DefaultHeight());
1497 if (firstpar->Previous()
1498 && firstpar->Previous()->GetDepth() == 0
1499 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1502 else if (firstpar->Previous()){
1503 maxasc += int(layout.parsep * DefaultHeight());
1509 /* is it a bottom line? */
1512 row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1514 row_ptr->par() == par
1516 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1518 /* the paper margins */
1519 if (!par->next && bv_owner)
1520 maxdesc += LYX_PAPER_MARGIN;
1522 /* add the vertical spaces, that the user added */
1523 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1524 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1526 /* do not forget the DTP-lines!
1527 * there height depends on the font of the nearest character */
1528 if (firstpar->line_bottom)
1529 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1530 par, par->Last() - 1));
1532 /* and now the pagebreaks */
1533 if (firstpar->pagebreak_bottom)
1534 maxdesc += 3 * DefaultHeight();
1536 /* and now the layout spaces, for example before and after a section,
1537 * or between the items of a itemize or enumerate environment */
1538 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1539 LyXParagraph * nextpar = row_ptr->par()->Next();
1540 LyXParagraph * comparepar = row_ptr->par();
1544 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1545 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1546 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1547 if (comparepar->GetLayout()!= nextpar->GetLayout()
1548 || nextpar->GetLabelWidthString() !=
1549 comparepar->GetLabelWidthString())
1550 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1552 if (unusual > usual)
1553 layoutdesc = unusual;
1557 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1559 if (comparepar->GetLayout()!= nextpar->GetLayout()
1560 || nextpar->GetLabelWidthString() !=
1561 comparepar->GetLabelWidthString())
1562 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1567 /* incalculate the layout spaces */
1568 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1569 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1571 /* calculate the new height of the text */
1572 height -= row_ptr->height();
1574 row_ptr->height(maxasc + maxdesc + labeladdon);
1575 row_ptr->baseline(maxasc + labeladdon);
1577 height += row_ptr->height();
1579 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1580 row_ptr->width(int(maxwidth + x));
1583 width = max(0,workWidth(bview));
1585 if (r->width() > width)
1593 /* Appends the implicit specified paragraph behind the specified row,
1594 * start at the implicit given position */
1595 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1597 bool not_ready = true;
1599 // The last character position of a paragraph is an invariant so we can
1600 // safely get it here. (Asger)
1601 int const lastposition = row->par()->Last();
1604 // Get the next breakpoint
1605 int z = NextBreakPoint(bview, row, workWidth(bview));
1609 // Insert the new row
1610 if (z < lastposition) {
1612 InsertRow(row, row->par(), z);
1619 // Set the dimensions of the row
1620 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1621 SetHeightOfRow(bview, tmprow);
1623 } while (not_ready);
1627 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1629 bool not_ready = true;
1632 /* get the next breakpoint */
1633 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1636 if (z < row->par()->Last() ) {
1637 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1640 InsertRow(row, row->par(), z);
1646 if (row->pos() == z)
1647 not_ready = false; // the rest will not change
1653 /* if there are some rows too much, delete them */
1654 /* only if you broke the whole paragraph! */
1655 Row * tmprow2 = row;
1656 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1657 tmprow2 = tmprow2->next();
1659 while (tmprow2 != row) {
1660 tmprow2 = tmprow2->previous();
1661 RemoveRow(tmprow2->next());
1666 /* set the dimensions of the row */
1667 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1668 SetHeightOfRow(bview, tmprow);
1669 } while (not_ready);
1673 // this is just a little changed version of break again
1674 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1676 // get the next breakpoint
1677 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1680 if (z < row->par()->Last() ) {
1682 || (row->next() && row->next()->par() != row->par())) {
1683 /* insert a new row */
1685 InsertRow(row, row->par(), z);
1691 if (row->pos() != z)
1695 // if there are some rows too much, delete them
1696 // only if you broke the whole paragraph!
1697 Row * tmprow2 = row;
1698 while (tmprow2->next()
1699 && tmprow2->next()->par() == row->par()) {
1700 tmprow2 = tmprow2->next();
1702 while (tmprow2 != row) {
1703 tmprow2 = tmprow2->previous();
1704 RemoveRow(tmprow2->next());
1708 // set the dimensions of the row
1709 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1710 SetHeightOfRow(bview, tmprow);
1714 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1716 LyXLayout const & layout =
1717 textclasslist.Style(bview->buffer()->params.textclass,
1718 cursor.par()->GetLayout());
1720 // this is only allowed, if the current paragraph is not empty or caption
1721 if ((cursor.par()->Last() <= 0
1723 && !cursor.par()->IsDummy()
1727 layout.labeltype!= LABEL_SENSITIVE)
1730 SetUndo(bview->buffer(), Undo::INSERT,
1732 cursor.par()->ParFromPos(cursor.pos())->previous,
1733 cursor.par()->ParFromPos(cursor.pos())->next
1735 cursor.par()->previous,
1740 // please break always behind a space
1741 if (cursor.pos() < cursor.par()->Last()
1742 && cursor.par()->IsLineSeparator(cursor.pos()))
1743 cursor.pos(cursor.pos() + 1);
1745 // break the paragraph
1749 keep_layout = layout.isEnvironment();
1750 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1753 // well this is the caption hack since one caption is really enough
1754 if (layout.labeltype == LABEL_SENSITIVE) {
1756 // set to standard-layout
1757 cursor.par()->SetLayout(bview->buffer()->params, 0);
1759 // set to standard-layout
1760 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1763 /* if the cursor is at the beginning of a row without prior newline,
1765 * This touches only the screen-update. Otherwise we would may have
1766 * an empty row on the screen */
1767 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1768 cursor.row()->pos() == cursor.pos()) {
1772 status = LyXText::NEED_MORE_REFRESH;
1773 refresh_row = cursor.row();
1774 refresh_y = cursor.y() - cursor.row()->baseline();
1776 // Do not forget the special right address boxes
1777 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1778 while (refresh_row->previous() &&
1779 refresh_row->previous()->par() == refresh_row->par()) {
1780 refresh_row = refresh_row->previous();
1781 refresh_y -= refresh_row->height();
1784 RemoveParagraph(cursor.row());
1786 // set the dimensions of the cursor row
1787 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1789 SetHeightOfRow(bview, cursor.row());
1791 while (cursor.par()->Next()->Last()
1792 && cursor.par()->Next()->IsNewline(0))
1793 cursor.par()->Next()->Erase(0);
1795 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1797 UpdateCounters(bview, cursor.row()->previous());
1799 /* This check is necessary. Otherwise the new empty paragraph will
1800 * be deleted automatically. And it is more friendly for the user! */
1802 SetCursor(bview, cursor.par()->Next(), 0);
1804 SetCursor(bview, cursor.par(), 0);
1806 if (cursor.row()->next())
1807 BreakAgain(bview, cursor.row()->next());
1814 void LyXText::OpenFootnote(BufferView * bview)
1816 LyXParagraph * endpar,* tmppar;
1819 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1821 /* if there is no footnote in this paragraph, just return. */
1823 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1826 /* ok, move the cursor right before the footnote */
1828 /* just a little faster than using CursorRight() */
1830 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1831 cursor.pos(cursor.pos() + 1);
1834 /* now the cursor is at the beginning of the physical par */
1835 SetCursor(bview, cursor.par(),
1836 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1838 /* the cursor must be exactly before the footnote */
1839 par = cursor.par()->ParFromPos(cursor.pos());
1841 status = LyXText::NEED_MORE_REFRESH;
1842 refresh_row = cursor.row();
1843 refresh_y = cursor.y() - cursor.row()->baseline();
1845 tmppar = cursor.par();
1846 endpar = cursor.par()->Next();
1849 tmppar->OpenFootnote(cursor.pos());
1850 RemoveParagraph(row);
1851 /* set the dimensions of the cursor row */
1852 row->fill(Fill(bview, row, workWidth(bview)));
1853 SetHeightOfRow(bview, row);
1854 // CHECK See comment on top of text.C
1855 tmppar = tmppar->Next();
1857 while (tmppar != endpar) {
1859 InsertParagraph(bview, tmppar, row);
1860 while (row->next() && row->next()->par() == tmppar)
1862 tmppar = tmppar->Next();
1865 SetCursor(bview, par->next, 0);
1866 sel_cursor = cursor;
1871 // Just a macro to make some thing easier.
1872 void LyXText::RedoParagraph(BufferView * bview) const
1875 RedoParagraphs(bview, cursor, cursor.par()->Next());
1876 SetCursorIntern(bview, cursor.par(), cursor.pos());
1880 /* insert a character, moves all the following breaks in the
1881 * same Paragraph one to the right and make a rebreak */
1882 void LyXText::InsertChar(BufferView * bview, char c)
1884 SetUndo(bview->buffer(), Undo::INSERT,
1886 cursor.par()->ParFromPos(cursor.pos())->previous,
1887 cursor.par()->ParFromPos(cursor.pos())->next
1889 cursor.par()->previous,
1894 // When the free-spacing option is set for the current layout,
1895 // disable the double-space checking
1898 textclasslist.Style(bview->buffer()->params.textclass,
1899 cursor.row()->par()->GetLayout()).free_spacing;
1902 if (lyxrc.auto_number) {
1903 if (current_font.number() == LyXFont::ON) {
1904 if (!isdigit(c) && !strchr("+-/*", c) &&
1906 cursor.pos() >= 1 &&
1907 cursor.pos() < cursor.par()->size() &&
1908 GetFont(bview->buffer(),
1910 cursor.pos()).number() == LyXFont::ON &&
1911 GetFont(bview->buffer(),
1913 cursor.pos()-1).number() == LyXFont::ON)
1915 Number(bview); // Set current_font.number to OFF
1916 } else if (isdigit(c) &&
1917 real_current_font.isVisibleRightToLeft()) {
1918 Number(bview); // Set current_font.number to ON
1920 if (cursor.pos() > 0) {
1921 char c = cursor.par()->GetChar(cursor.pos() - 1);
1922 if (strchr("+-",c) &&
1923 (cursor.pos() == 1 ||
1924 cursor.par()->IsSeparator(cursor.pos() - 2) ||
1925 cursor.par()->IsNewline(cursor.pos() - 2) )
1927 SetCharFont(bview->buffer(),
1931 } else if (strchr(".", c) &&
1932 cursor.pos() >= 2 &&
1933 GetFont(bview->buffer(),
1935 cursor.pos()-2).number() == LyXFont::ON) {
1936 SetCharFont(bview->buffer(),
1946 /* First check, if there will be two blanks together or a blank at
1947 the beginning of a paragraph.
1948 I decided to handle blanks like normal characters, the main
1949 difference are the special checks when calculating the row.fill
1950 (blank does not count at the end of a row) and the check here */
1952 // The bug is triggered when we type in a description environment:
1953 // The current_font is not changed when we go from label to main text
1954 // and it should (along with realtmpfont) when we type the space.
1955 // CHECK There is a bug here! (Asger)
1957 LyXFont realtmpfont = real_current_font;
1958 LyXFont rawtmpfont = current_font; /* store the current font.
1959 * This is because of the use
1960 * of cursor movements. The moving
1961 * cursor would refresh the
1964 // Get the font that is used to calculate the baselineskip
1965 LyXParagraph::size_type lastpos = cursor.par()->Last();
1966 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
1969 bool jumped_over_space = false;
1971 if (!freeSpacing && IsLineSeparatorChar(c)) {
1972 if ((cursor.pos() > 0
1973 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
1974 || (cursor.pos() > 0
1975 && cursor.par()->IsNewline(cursor.pos() - 1))
1976 || (cursor.pos() == 0
1978 && !(cursor.par()->Previous()
1979 && cursor.par()->Previous()->footnoteflag
1980 == LyXParagraph::OPEN_FOOTNOTE)
1983 if (cursor.pos() == 0 )
1984 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1986 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
1990 } else if (IsNewlineChar(c)) {
1992 if (cursor.par()->FirstPhysicalPar() == cursor.par()
1994 if (cursor.par() == cursor.par()
1996 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2000 /* No newline at first position
2001 * of a paragraph or behind labels.
2002 * TeX does not allow that. */
2004 if (cursor.pos() < cursor.par()->Last() &&
2005 cursor.par()->IsLineSeparator(cursor.pos()))
2006 // newline always after a blank!
2008 cursor.row()->fill(-1); // to force a new break
2011 // the display inset stuff
2012 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2013 && cursor.row()->par()->GetInset(cursor.row()->pos())
2014 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2015 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2016 cursor.row()->fill(-1); // to force a new break
2018 // get the cursor row fist
2019 Row * row = cursor.row();
2020 int y = cursor.y() - row->baseline();
2021 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2022 * already insertet the character */
2023 cursor.par()->InsertChar(cursor.pos(), c);
2024 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2026 if (!jumped_over_space) {
2027 // refresh the positions
2029 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2030 tmprow = tmprow->next();
2031 tmprow->pos(tmprow->pos() + 1);
2035 // Is there a break one row above
2036 if ((cursor.par()->IsLineSeparator(cursor.pos())
2037 || cursor.par()->IsNewline(cursor.pos())
2038 || cursor.row()->fill() == -1)
2039 && row->previous() && row->previous()->par() == row->par()) {
2040 LyXParagraph::size_type z = NextBreakPoint(bview,
2043 if ( z >= row->pos()) {
2046 // set the dimensions of the row above
2047 row->previous()->fill(Fill(bview,
2051 SetHeightOfRow(bview, row->previous());
2053 y -= row->previous()->height();
2055 refresh_row = row->previous();
2056 status = LyXText::NEED_MORE_REFRESH;
2058 BreakAgainOneRow(bview, row);
2060 current_font = rawtmpfont;
2061 real_current_font = realtmpfont;
2062 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2063 false, cursor.boundary());
2064 // cursor MUST be in row now.
2066 if (row->next() && row->next()->par() == row->par())
2067 need_break_row = row->next();
2071 // check, wether the last characters font has changed.
2072 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2073 && rawparfont != rawtmpfont)
2074 RedoHeightOfParagraph(bview, cursor);
2081 // recalculate the fill of the row
2082 if (row->fill() >= 0) /* needed because a newline
2083 * will set fill to -1. Otherwise
2084 * we would not get a rebreak! */
2085 row->fill(Fill(bview, row, workWidth(bview)));
2086 if (row->fill() < 0 ) {
2089 refresh_x = cursor.x();
2090 refresh_pos = cursor.pos();
2091 status = LyXText::NEED_MORE_REFRESH;
2092 BreakAgainOneRow(bview, row);
2093 // will the cursor be in another row now?
2094 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2095 if (row->next() && row->next()->par() == row->par())
2096 // this should always be true
2098 BreakAgainOneRow(bview, row);
2100 current_font = rawtmpfont;
2101 real_current_font = realtmpfont;
2103 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2105 if (row->next() && row->next()->par() == row->par())
2106 need_break_row = row->next();
2111 refresh_x = cursor.x();
2113 refresh_pos = cursor.pos();
2115 int tmpheight = row->height();
2116 SetHeightOfRow(bview, row);
2117 if (tmpheight == row->height())
2118 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2120 status = LyXText::NEED_MORE_REFRESH;
2122 current_font = rawtmpfont;
2123 real_current_font = realtmpfont;
2124 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2128 // check, wether the last characters font has changed.
2129 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2130 && rawparfont != rawtmpfont) {
2131 RedoHeightOfParagraph(bview, cursor);
2133 // now the special right address boxes
2134 if (textclasslist.Style(bview->buffer()->params.textclass,
2135 cursor.par()->GetLayout()).margintype
2136 == MARGIN_RIGHT_ADDRESS_BOX) {
2137 RedoDrawingOfParagraph(bview, cursor);
2145 void LyXText::charInserted()
2147 // Here we could call FinishUndo for every 20 characters inserted.
2148 // This is from my experience how emacs does it.
2149 static unsigned int counter = 0;
2159 void LyXText::PrepareToPrint(BufferView * bview,
2160 Row * row, float & x,
2161 float & fill_separator,
2163 float & fill_label_hfill,
2168 float w = row->fill();
2170 fill_label_hfill = 0;
2172 fill_label_hfill = 0;
2174 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2178 x = RightMargin(bview->buffer(), row);
2179 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2180 LyXFont font(LyXFont::ALL_SANE);
2181 font.setSize(LyXFont::SIZE_SMALL);
2182 x += lyxfont::width("Mwide-figM", font);
2186 if (workWidth(bview) > 0)
2187 x = LeftMargin(bview, row);
2191 // is there a manual margin with a manual label
2192 if (textclasslist.Style(bview->buffer()->params.textclass,
2193 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2194 && textclasslist.Style(bview->buffer()->params.textclass,
2195 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2197 /* one more since labels are left aligned */
2198 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2199 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2200 fill_label_hfill = LabelFill(bview, row) / nlh;
2204 // are there any hfills in the row?
2205 float const nh = NumberOfHfills(bview->buffer(), row);
2208 fill_hfill = w / nh;
2210 // is it block, flushleft or flushright?
2211 // set x how you need it
2214 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2215 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2217 align = row->par()->FirstPhysicalPar()->align;
2219 if (row->par()->align == LYX_ALIGN_LAYOUT)
2220 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2222 align = row->par()->align;
2225 // center displayed insets
2227 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2228 && (inset=row->par()->GetInset(row->pos()))
2229 && (inset->display())) // || (inset->scroll() < 0)))
2230 align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
2231 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
2234 case LYX_ALIGN_BLOCK:
2235 ns = NumberOfSeparators(bview->buffer(), row);
2236 if (ns && row->next() && row->next()->par() == row->par() &&
2237 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2238 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2239 && row->next()->par()->GetInset(row->next()->pos())
2240 && row->next()->par()->GetInset(row->next()->pos())->display())
2242 fill_separator = w / ns;
2246 case LYX_ALIGN_RIGHT:
2249 case LYX_ALIGN_CENTER:
2257 ComputeBidiTables(bview->buffer(), row);
2259 LyXParagraph::size_type main_body =
2260 BeginningOfMainBody(bview->buffer(), row->par());
2261 LyXParagraph::size_type last = RowLast(row);
2263 if (main_body > 0 &&
2264 (main_body-1 > last ||
2265 !row->par()->IsLineSeparator(main_body-1))) {
2266 LyXLayout const & layout =
2267 textclasslist.Style(bview->buffer()->params.textclass,
2268 row->par()->GetLayout());
2269 x += lyxfont::width(layout.labelsep,
2270 GetFont(bview->buffer(), row->par(), -2));
2271 if (main_body-1 <= last)
2272 x += fill_label_hfill;
2277 /* important for the screen */
2280 /* the cursor set functions have a special mechanism. When they
2281 * realize, that you left an empty paragraph, they will delete it.
2282 * They also delete the corresponding row */
2284 void LyXText::CursorRightOneWord(BufferView * bview) const
2286 // treat floats, HFills and Insets as words
2287 LyXCursor tmpcursor = cursor;
2288 // CHECK See comment on top of text.C
2290 if (tmpcursor.pos() == tmpcursor.par()->Last()
2291 && tmpcursor.par()->Next()) {
2292 tmpcursor.par(tmpcursor.par()->Next());
2297 // Skip through initial nonword stuff.
2298 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
2299 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2301 // printf("Current pos1 %d", tmpcursor.pos()) ;
2302 tmpcursor.pos(tmpcursor.pos() + 1);
2305 // Advance through word.
2306 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
2307 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
2309 // printf("Current pos2 %d", tmpcursor.pos()) ;
2310 tmpcursor.pos(tmpcursor.pos() + 1);
2314 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2318 void LyXText::CursorTab(BufferView * bview) const
2320 LyXCursor tmpcursor = cursor;
2321 while (tmpcursor.pos() < tmpcursor.par()->Last()
2322 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
2323 tmpcursor.pos(tmpcursor.pos() + 1);
2325 if (tmpcursor.pos() == tmpcursor.par()->Last()){
2326 if (tmpcursor.par()->Next()) {
2327 tmpcursor.par(tmpcursor.par()->Next());
2331 tmpcursor.pos(tmpcursor.pos() + 1);
2332 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2336 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2337 of prior word, not to end of next prior word. */
2339 void LyXText::CursorLeftOneWord(BufferView * bview) const
2341 // treat HFills, floats and Insets as words
2342 LyXCursor tmpcursor = cursor;
2343 while (tmpcursor.pos()
2344 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
2345 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
2346 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
2348 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2350 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
2351 tmpcursor.pos(tmpcursor.pos() - 1);
2354 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
2356 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
2358 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
2359 tmpcursor.pos(tmpcursor.pos() - 1);
2360 } else if (!tmpcursor.pos()) {
2361 if (tmpcursor.par()->Previous()){
2362 tmpcursor.par(tmpcursor.par()->Previous());
2363 tmpcursor.pos(tmpcursor.par()->Last());
2365 } else { // Here, tmpcursor != 0
2366 while (tmpcursor.pos() > 0 &&
2367 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
2368 tmpcursor.pos(tmpcursor.pos() - 1);
2370 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
2373 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2376 void LyXText::SelectWord(BufferView * bview)
2378 // Move cursor to the beginning, when not already there.
2380 && !cursor.par()->IsSeparator(cursor.pos()-1)
2381 && !cursor.par()->IsKomma(cursor.pos()-1) )
2382 CursorLeftOneWord(bview);
2384 // set the sel cursor
2385 sel_cursor = cursor;
2387 while ( cursor.pos() < cursor.par()->Last()
2388 && !cursor.par()->IsSeparator(cursor.pos())
2389 && !cursor.par()->IsKomma(cursor.pos()) )
2390 cursor.pos(cursor.pos() + 1);
2391 SetCursor(bview, cursor.par(), cursor.pos() );
2393 // finally set the selection
2398 /* -------> Select the word currently under the cursor when:
2399 1: no selection is currently set,
2400 2: the cursor is not at the borders of the word. */
2402 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
2405 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
2406 && !cursor.par()->IsSeparator(cursor.pos())
2407 && !cursor.par()->IsKomma(cursor.pos())
2408 && !cursor.par()->IsSeparator(cursor.pos() -1)
2409 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
2417 // This function is only used by the spellchecker for NextWord().
2418 // It doesn't handle LYX_ACCENTs and probably never will.
2419 string const LyXText::SelectNextWord(BufferView * bview,
2420 float & value) const
2422 LyXParagraph * tmppar = cursor.par();
2424 // If this is not the very first word, skip rest of
2425 // current word because we are probably in the middle
2426 // of a word if there is text here.
2427 if (cursor.pos() || cursor.par()->previous) {
2428 while (cursor.pos() < cursor.par()->Last()
2429 && cursor.par()->IsLetter(cursor.pos()))
2430 cursor.pos(cursor.pos() + 1);
2432 // Now, skip until we have real text (will jump paragraphs)
2433 while ((cursor.par()->Last() > cursor.pos()
2434 && (!cursor.par()->IsLetter(cursor.pos())
2435 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
2436 .latex() == LyXFont::ON))
2437 || (cursor.par()->Last() == cursor.pos()
2438 && cursor.par()->Next())){
2439 if (cursor.pos() == cursor.par()->Last()) {
2440 cursor.par(cursor.par()->Next());
2443 cursor.pos(cursor.pos() + 1);
2446 // Update the value if we changed paragraphs
2447 if (cursor.par() != tmppar){
2448 SetCursor(bview, cursor.par(), cursor.pos());
2449 value = float(cursor.y())/float(height);
2452 // Start the selection from here
2453 sel_cursor = cursor;
2455 std::ostringstream latex;
2457 // and find the end of the word
2458 // (optional hyphens are part of a word)
2459 while (cursor.pos() < cursor.par()->Last()
2460 && (cursor.par()->IsLetter(cursor.pos()))
2461 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2462 && cursor.par()->GetInset(cursor.pos()) != 0
2463 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2464 && latex.str() == "\\-"
2466 cursor.pos(cursor.pos() + 1);
2468 // Finally, we copy the word to a string and return it
2470 if (sel_cursor.pos() < cursor.pos()) {
2471 LyXParagraph::size_type i;
2472 for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
2473 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
2474 str += cursor.par()->GetChar(i);
2481 // This one is also only for the spellchecker
2482 void LyXText::SelectSelectedWord(BufferView * bview)
2484 // move cursor to the beginning
2485 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
2487 // set the sel cursor
2488 sel_cursor = cursor;
2490 std::ostringstream latex;
2492 // now find the end of the word
2493 while (cursor.pos() < cursor.par()->Last()
2494 && (cursor.par()->IsLetter(cursor.pos())
2495 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
2496 && cursor.par()->GetInset(cursor.pos()) != 0
2497 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
2498 && latex.str() == "\\-"
2500 cursor.pos(cursor.pos() + 1);
2502 SetCursor(bview, cursor.par(), cursor.pos());
2504 // finally set the selection
2509 /* -------> Delete from cursor up to the end of the current or next word. */
2510 void LyXText::DeleteWordForward(BufferView * bview)
2512 if (!cursor.par()->Last())
2515 LyXCursor tmpcursor = cursor;
2516 tmpcursor.row(0); //Â ??
2517 selection = true; // to avoid deletion
2518 CursorRightOneWord(bview);
2519 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2520 sel_cursor = cursor;
2524 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2525 CutSelection(bview);
2530 /* -------> Delete from cursor to start of current or prior word. */
2531 void LyXText::DeleteWordBackward(BufferView * bview)
2533 if (!cursor.par()->Last())
2536 LyXCursor tmpcursor = cursor;
2537 tmpcursor.row(0); // ??
2538 selection = true; // to avoid deletion
2539 CursorLeftOneWord(bview);
2540 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2541 sel_cursor = cursor;
2544 CutSelection(bview);
2549 /* -------> Kill to end of line. */
2550 void LyXText::DeleteLineForward(BufferView * bview)
2552 if (!cursor.par()->Last())
2553 // Paragraph is empty, so we just go to the right
2556 LyXCursor tmpcursor = cursor;
2557 // We can't store the row over a regular SetCursor
2558 // so we set it to 0 and reset it afterwards.
2559 tmpcursor.row(0); //Â ??
2560 selection = true; // to avoid deletion
2562 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
2563 sel_cursor = cursor;
2566 // What is this test for ??? (JMarc)
2568 DeleteWordForward(bview);
2570 CutSelection(bview);
2576 // Change the case of a word at cursor position.
2577 // This function directly manipulates LyXParagraph::text because there
2578 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2579 // that it is correct. I guess part of it should be moved to
2580 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2581 // it does not access outside of the allocated array as the older
2582 // version did. (JMarc)
2583 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
2586 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
2588 LyXParagraph * tmppar = cursor.par();
2591 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
2594 LyXParagraph::size_type tmppos =
2595 cursor.par()->PositionInParFromPos(cursor.pos());
2597 LyXParagraph::size_type tmppos = cursor.pos();
2599 while (tmppos < tmppar->size()) {
2600 unsigned char c = tmppar->GetChar(tmppos);
2601 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2603 if (c != LyXParagraph::META_INSET) {
2605 case text_lowercase:
2608 case text_capitalization:
2610 action = text_lowercase;
2612 case text_uppercase:
2618 //tmppar->text[tmppos] = c;
2619 tmppar->SetChar(tmppos, c);
2622 CheckParagraph(bview, tmppar, tmppos);
2623 CursorRightOneWord(bview);
2627 void LyXText::Delete(BufferView * bview)
2629 // this is a very easy implementation
2631 LyXCursor old_cursor = cursor;
2632 int old_cur_par_id = old_cursor.par()->id();
2633 int old_cur_par_prev_id = old_cursor.par()->previous ?
2634 old_cursor.par()->previous->id() : 0;
2636 // just move to the right
2639 // CHECK Look at the comment here.
2640 // This check is not very good...
2641 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2642 // and that can very well delete the par or par->previous in
2643 // old_cursor. Will a solution where we compare paragraph id's
2645 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
2646 == old_cur_par_prev_id
2647 && cursor.par()->id() != old_cur_par_id)
2648 return; // delete-empty-paragraph-mechanism has done it
2650 // if you had success make a backspace
2651 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2652 LyXCursor tmpcursor = cursor;
2653 cursor = old_cursor; // to make sure undo gets the right cursor position
2654 SetUndo(bview->buffer(), Undo::DELETE,
2656 cursor.par()->ParFromPos(cursor.pos())->previous,
2657 cursor.par()->ParFromPos(cursor.pos())->next
2659 cursor.par()->previous,
2669 void LyXText::Backspace(BufferView * bview)
2671 // Get the font that is used to calculate the baselineskip
2672 LyXParagraph::size_type lastpos = cursor.par()->Last();
2673 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2676 if (cursor.pos() == 0) {
2677 // The cursor is at the beginning of a paragraph,
2678 // so the the backspace will collapse two paragraphs into one.
2680 // we may paste some paragraphs
2682 // is it an empty paragraph?
2685 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
2687 && !(cursor.par()->Next()
2688 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
2689 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
2692 // This is an empty paragraph and we delete it just by moving the cursor one step
2693 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2694 // of the paragraph.
2696 if (cursor.par()->previous) {
2698 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
2700 LyXParagraph * tmppar = cursor.par()->previous;
2702 if (cursor.par()->GetLayout() == tmppar->GetLayout()
2704 && cursor.par()->footnoteflag == tmppar->footnoteflag
2706 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2707 // Inherit botom DTD from the paragraph below.
2708 // (the one we are deleting)
2709 tmppar->line_bottom = cursor.par()->line_bottom;
2710 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
2711 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
2716 // the layout things can change the height of a row !
2717 int tmpheight = cursor.row()->height();
2718 SetHeightOfRow(bview, cursor.row());
2719 if (cursor.row()->height() != tmpheight) {
2720 refresh_y = cursor.y() - cursor.row()->baseline();
2721 refresh_row = cursor.row();
2722 status = LyXText::NEED_MORE_REFRESH;
2729 if (cursor.par()->ParFromPos(cursor.pos())->previous){
2730 SetUndo(bview->buffer(), Undo::DELETE,
2731 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
2732 cursor.par()->ParFromPos(cursor.pos())->next);
2735 if (cursor.par()->previous) {
2736 SetUndo(bview->buffer(), Undo::DELETE,
2737 cursor.par()->previous->previous,
2738 cursor.par()->next);
2742 LyXParagraph * tmppar = cursor.par();
2743 Row * tmprow = cursor.row();
2745 // We used to do CursorLeftIntern() here, but it is
2746 // not a good idea since it triggers the auto-delete
2747 // mechanism. So we do a CursorLeftIntern()-lite,
2748 // without the dreaded mechanism. (JMarc)
2749 if (cursor.par()->Previous()) {
2750 // steps into the above paragraph.
2751 SetCursorIntern(bview, cursor.par()->Previous(),
2752 cursor.par()->Previous()->Last(), false);
2755 /* Pasting is not allowed, if the paragraphs have different
2756 layout. I think it is a real bug of all other
2757 word processors to allow it. It confuses the user.
2758 Even so with a footnote paragraph and a non-footnote
2759 paragraph. I will not allow pasting in this case,
2760 because the user would be confused if the footnote behaves
2761 different wether it is open or closed.
2763 Correction: Pasting is always allowed with standard-layout
2765 if (cursor.par() != tmppar
2766 && (cursor.par()->GetLayout() == tmppar->GetLayout()
2767 || tmppar->GetLayout() == 0 /*standard*/)
2769 && cursor.par()->footnoteflag == tmppar->footnoteflag
2771 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
2773 RemoveParagraph(tmprow);
2775 cursor.par()->PasteParagraph(bview->buffer()->params);
2777 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
2778 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
2779 // strangely enough it seems that commenting out the line above removes
2780 // most or all of the segfaults. I will however also try to move the
2781 // two Remove... lines in front of the PasteParagraph too.
2784 cursor.pos(cursor.pos() - 1);
2786 status = LyXText::NEED_MORE_REFRESH;
2787 refresh_row = cursor.row();
2788 refresh_y = cursor.y() - cursor.row()->baseline();
2790 // remove the lost paragraph
2791 // This one is not safe, since the paragraph that the tmprow and the
2792 // following rows belong to has been deleted by the PasteParagraph
2793 // above. The question is... could this be moved in front of the
2795 //RemoveParagraph(tmprow);
2796 //RemoveRow(tmprow);
2798 // This rebuilds the rows.
2799 AppendParagraph(bview, cursor.row());
2800 UpdateCounters(bview, cursor.row());
2802 // the row may have changed, block, hfills etc.
2803 SetCursor(bview, cursor.par(), cursor.pos(), false);
2806 /* this is the code for a normal backspace, not pasting
2808 SetUndo(bview->buffer(), Undo::DELETE,
2810 cursor.par()->ParFromPos(cursor.pos())->previous,
2811 cursor.par()->ParFromPos(cursor.pos())->next
2813 cursor.par()->previous,
2817 // We used to do CursorLeftIntern() here, but it is
2818 // not a good idea since it triggers the auto-delete
2819 // mechanism. So we do a CursorLeftIntern()-lite,
2820 // without the dreaded mechanism. (JMarc)
2821 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
2822 false, cursor.boundary());
2824 // some insets are undeletable here
2825 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2826 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2828 // force complete redo when erasing display insets
2829 // this is a cruel method but safe..... Matthias
2830 if (cursor.par()->GetInset(cursor.pos())->display() ||
2831 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
2832 cursor.par()->Erase(cursor.pos());
2833 RedoParagraph(bview);
2838 Row * row = cursor.row();
2839 int y = cursor.y() - row->baseline();
2840 LyXParagraph::size_type z;
2841 /* remember that a space at the end of a row doesnt count
2842 * when calculating the fill */
2843 if (cursor.pos() < RowLast(row) ||
2844 !cursor.par()->IsLineSeparator(cursor.pos())) {
2845 row->fill(row->fill() + SingleWidth(bview,
2850 /* some special code when deleting a newline. This is similar
2851 * to the behavior when pasting paragraphs */
2852 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
2853 cursor.par()->Erase(cursor.pos());
2854 // refresh the positions
2856 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2857 tmprow = tmprow->next();
2858 tmprow->pos(tmprow->pos() - 1);
2860 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
2861 cursor.pos(cursor.pos() - 1);
2863 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
2864 cursor.par()->InsertChar(cursor.pos(), ' ');
2865 // refresh the positions
2867 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2868 tmprow = tmprow->next();
2869 tmprow->pos(tmprow->pos() + 1);
2873 cursor.par()->Erase(cursor.pos());
2875 // refresh the positions
2877 while (tmprow->next()
2878 && tmprow->next()->par() == row->par()) {
2879 tmprow = tmprow->next();
2880 tmprow->pos(tmprow->pos() - 1);
2883 // delete newlines at the beginning of paragraphs
2884 while (cursor.par()->Last() &&
2885 cursor.par()->IsNewline(cursor.pos()) &&
2886 cursor.pos() == BeginningOfMainBody(bview->buffer(),
2888 cursor.par()->Erase(cursor.pos());
2889 // refresh the positions
2891 while (tmprow->next() &&
2892 tmprow->next()->par() == row->par()) {
2893 tmprow = tmprow->next();
2894 tmprow->pos(tmprow->pos() - 1);
2899 // is there a break one row above
2900 if (row->previous() && row->previous()->par() == row->par()) {
2901 z = NextBreakPoint(bview, row->previous(),
2903 if ( z >= row->pos()) {
2906 Row * tmprow = row->previous();
2908 // maybe the current row is now empty
2909 if (row->pos() >= row->par()->Last()) {
2914 BreakAgainOneRow(bview, row);
2915 if (row->next() && row->next()->par() == row->par())
2916 need_break_row = row->next();
2921 // set the dimensions of the row above
2922 y -= tmprow->height();
2923 tmprow->fill(Fill(bview, tmprow,
2925 SetHeightOfRow(bview, tmprow);
2928 refresh_row = tmprow;
2929 status = LyXText::NEED_MORE_REFRESH;
2930 SetCursor(bview, cursor.par(), cursor.pos(),
2931 false, cursor.boundary());
2932 //current_font = rawtmpfont;
2933 //real_current_font = realtmpfont;
2934 // check, whether the last character's font has changed.
2936 cursor.par()->GetFontSettings(bview->buffer()->params,
2937 cursor.par()->Last() - 1))
2938 RedoHeightOfParagraph(bview, cursor);
2943 // break the cursor row again
2944 if (row->next() && row->next()->par() == row->par() &&
2945 (RowLast(row) == row->par()->Last() - 1 ||
2946 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
2948 /* it can happen that a paragraph loses one row
2949 * without a real breakup. This is when a word
2950 * is to long to be broken. Well, I don t care this
2952 if (RowLast(row) == row->par()->Last() - 1)
2953 RemoveRow(row->next());
2957 status = LyXText::NEED_MORE_REFRESH;
2959 BreakAgainOneRow(bview, row);
2960 // will the cursor be in another row now?
2961 if (row->next() && row->next()->par() == row->par() &&
2962 RowLast(row) <= cursor.pos()) {
2964 BreakAgainOneRow(bview, row);
2967 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2969 if (row->next() && row->next()->par() == row->par())
2970 need_break_row = row->next();
2974 // set the dimensions of the row
2975 row->fill(Fill(bview, row, workWidth(bview)));
2976 int tmpheight = row->height();
2977 SetHeightOfRow(bview, row);
2978 if (tmpheight == row->height())
2979 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2981 status = LyXText::NEED_MORE_REFRESH;
2984 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
2988 // current_font = rawtmpfont;
2989 // real_current_font = realtmpfont;
2991 lastpos = cursor.par()->Last();
2992 if (cursor.pos() == lastpos) {
2993 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2994 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2995 SetCurrentFont(bview);
2998 // check, wether the last characters font has changed.
3000 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3001 RedoHeightOfParagraph(bview, cursor);
3003 // now the special right address boxes
3004 if (textclasslist.Style(bview->buffer()->params.textclass,
3005 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3006 RedoDrawingOfParagraph(bview, cursor);
3012 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3013 Row * row_ptr, int y, bool cleared)
3015 /* returns a printed row */
3016 Painter & pain = bview->painter();
3018 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3019 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3021 LyXParagraph::size_type vpos, pos;
3027 LyXFont font(LyXFont::ALL_SANE);
3029 if (row_ptr->height() <= 0) {
3030 lyxerr << "LYX_ERROR: row.height: "
3031 << row_ptr->height() << endl;
3035 float fill_separator;
3037 float fill_label_hfill;
3038 PrepareToPrint(bview, row_ptr, x, fill_separator,
3039 fill_hfill, fill_label_hfill);
3041 if (inset_owner && (x < 0))
3045 // clear the area where we want to paint/print
3046 int ww = bview->workWidth();
3048 bool clear_area = true;
3051 if (!bview->screen()->forceClear() && (last == row_ptr->pos()) &&
3052 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3053 (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
3054 clear_area = inset->doClearArea();
3056 // we don't need to clear it's already done!!!
3059 } else if (clear_area) {
3060 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
3061 int w = (inset_owner ? inset_owner->width(bview, font)-2 : ww);
3062 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3063 } else if (inset != 0) {
3064 int h = row_ptr->baseline() - inset->ascent(bview, font);
3066 int w = (inset_owner ?
3067 inset_owner->width(bview, font) : ww);
3068 pain.fillRectangle(x_offset, y_offset, w, h);
3070 h += inset->ascent(bview, font) + inset->descent(bview, font);
3071 if ((row_ptr->height() - h) > 0) {
3072 int w = (inset_owner ?
3073 inset_owner->width(bview, font) : ww);
3074 pain.fillRectangle(x_offset,y_offset+h, w, row_ptr->height()-h);
3076 if (!inset_owner && !inset->display() && !inset->needFullRow())
3078 int w = inset->width(bview, font) + int(x);
3079 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3084 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3085 /* selection code */
3086 if (bidi_same_direction) {
3087 if (sel_start_cursor.row() == row_ptr &&
3088 sel_end_cursor.row() == row_ptr) {
3089 if (sel_start_cursor.x() < sel_end_cursor.x())
3090 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3092 sel_end_cursor.x() - sel_start_cursor.x(),
3096 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3098 sel_start_cursor.x() - sel_end_cursor.x(),
3101 } else if (sel_start_cursor.row() == row_ptr) {
3103 pain.fillRectangle(x_offset, y_offset,
3104 sel_start_cursor.x(),
3108 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3110 w - sel_start_cursor.x(),
3113 } else if (sel_end_cursor.row() == row_ptr) {
3115 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3117 w - sel_end_cursor.x(),
3121 pain.fillRectangle(x_offset, y_offset,
3125 } else if (y > sel_start_cursor.y()
3126 && y < sel_end_cursor.y()) {
3127 pain.fillRectangle(x_offset, y_offset, w,
3131 } else if ( sel_start_cursor.row() != row_ptr &&
3132 sel_end_cursor.row() != row_ptr &&
3133 y > sel_start_cursor.y()
3134 && y < sel_end_cursor.y()) {
3135 pain.fillRectangle(x_offset, y_offset, w,
3138 } else if (sel_start_cursor.row() == row_ptr ||
3139 sel_end_cursor.row() == row_ptr) {
3141 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3142 (sel_end_cursor.row() != row_ptr && is_rtl))
3143 pain.fillRectangle(x_offset, y_offset,
3147 LyXParagraph::size_type main_body =
3148 BeginningOfMainBody(bview->buffer(),
3151 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3152 pos = vis2log(vpos);
3153 float old_tmpx = tmpx;
3154 if (main_body > 0 && pos == main_body-1) {
3155 tmpx += fill_label_hfill +
3156 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3157 row_ptr->par()->GetLayout()).labelsep,
3158 GetFont(bview->buffer(),row_ptr->par(), -2));
3159 if (row_ptr->par()->IsLineSeparator(main_body-1))
3160 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3162 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3163 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3164 if (pos >= main_body)
3167 tmpx += fill_label_hfill;
3169 else if (row_ptr->par()->IsSeparator(pos)) {
3170 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3171 if (pos >= main_body)
3172 tmpx += fill_separator;
3174 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3176 if ( (sel_start_cursor.row() != row_ptr ||
3177 sel_start_cursor.pos() <= pos) &&
3178 (sel_end_cursor.row() != row_ptr ||
3179 pos < sel_end_cursor.pos()) )
3180 pain.fillRectangle(x_offset + int(old_tmpx),
3182 int(tmpx - old_tmpx + 1),
3187 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3188 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3189 pain.fillRectangle(x_offset + int(tmpx),
3199 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3200 LyXFont font(LyXFont::ALL_SANE);
3201 font.setSize(LyXFont::SIZE_FOOTNOTE);
3202 font.setColor(LColor::footnote);
3204 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3205 if (row_ptr->previous() &&
3206 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3208 switch (row_ptr->par()->footnotekind) {
3209 case LyXParagraph::MARGIN:
3212 case LyXParagraph::FIG:
3215 case LyXParagraph::TAB:
3218 case LyXParagraph::WIDE_FIG:
3221 case LyXParagraph::WIDE_TAB:
3224 case LyXParagraph::ALGORITHM:
3227 case LyXParagraph::FOOTNOTE:
3232 pain.fillRectangle(LYX_PAPER_MARGIN,
3234 box_x - LYX_PAPER_MARGIN,
3235 int(lyxfont::maxAscent(font)
3236 + lyxfont::maxDescent(font)),
3237 LColor::footnotebg);
3239 pain.line(LYX_PAPER_MARGIN, y_offset,
3240 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3241 LColor::footnoteframe);
3243 pain.text(LYX_PAPER_MARGIN,
3244 y_offset + int(lyxfont::maxAscent(font)) + 1,
3247 pain.line(LYX_PAPER_MARGIN, y_offset,
3249 y_offset + int(lyxfont::maxAscent(font)
3250 + lyxfont::maxDescent(font)),
3251 LColor::footnoteframe);
3253 pain.line(LYX_PAPER_MARGIN,
3254 y_offset + int(lyxfont::maxAscent(font)
3255 + lyxfont::maxDescent(font)) + 1,
3257 y_offset + int(lyxfont::maxAscent(font)
3258 + lyxfont::maxDescent(font)) + 1,
3259 LColor::footnoteframe);
3263 /* draw the open floats in a red box */
3264 pain.line(box_x, y_offset,
3265 box_x, y_offset + row_ptr->height(),
3266 LColor::footnoteframe);
3268 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
3270 workWidth(bview) - LYX_PAPER_MARGIN,
3271 y_offset + row_ptr->height(),
3272 LColor::footnoteframe);
3275 // Draw appendix lines
3276 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
3278 pain.line(1, y_offset,
3279 1, y_offset + row_ptr->height(),
3280 LColor::appendixline);
3281 pain.line(workWidth(bview) - 2, y_offset,
3282 workWidth(bview) - 2,
3283 y_offset + row_ptr->height(),
3284 LColor::appendixline);
3287 // Draw minipage line
3288 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
3290 pain.line(LYX_PAPER_MARGIN/5, y_offset,
3292 y_offset + row_ptr->height() - 1,
3293 LColor::minipageline);
3296 int depth = p->GetDepth();
3297 for (int i = 1; i <= depth; ++i) {
3298 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
3299 pain.line(line_x, y_offset, line_x,
3300 y_offset + row_ptr->height() - 1,
3303 } else if (row_ptr->previous() &&
3304 row_ptr->previous()->par()->footnoteflag
3305 == LyXParagraph::OPEN_FOOTNOTE) {
3306 LyXFont font(LyXFont::ALL_SANE);
3307 font.setSize(LyXFont::SIZE_FOOTNOTE);
3309 int box_x = LYX_PAPER_MARGIN;
3310 box_x += lyxfont::width(" wide-tab ", font);
3312 pain.line(box_x, y_offset,
3313 workWidth(bview) - LYX_PAPER_MARGIN,
3314 y_offset, LColor::footnote);
3317 // Draw appendix lines
3319 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
3321 LyXParagraph * firstpar = row_ptr->par();
3323 if (firstpar->appendix){
3324 pain.line(1, y_offset,
3325 1, y_offset + row_ptr->height(),
3326 LColor::appendixline);
3327 pain.line(ww - 2, y_offset,
3328 ww - 2, y_offset + row_ptr->height(),
3329 LColor::appendixline);
3332 // Draw minipage line
3333 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
3335 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
3336 LYX_PAPER_MARGIN/5 + box_x,
3337 y_offset + row_ptr->height() - 1,
3338 LColor::minipageline);
3341 int depth = firstpar->GetDepth();
3345 if (row_ptr->next())
3347 if (row_ptr->par()->footnoteflag ==
3348 row_ptr->next()->par()->footnoteflag)
3349 next_depth = row_ptr->next()->par()->GetDepth();
3350 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3353 next_depth = row_ptr->next()->par()->GetDepth();
3355 if (row_ptr->previous())
3357 if (row_ptr->par()->footnoteflag ==
3358 row_ptr->previous()->par()->footnoteflag)
3359 prev_depth = row_ptr->previous()->par()->GetDepth();
3360 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
3363 prev_depth = row_ptr->previous()->par()->GetDepth();
3366 for (int i = 1; i <= depth; ++i) {
3367 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
3368 pain.line(line_x, y_offset, line_x,
3369 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
3373 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
3376 pain.fillRectangle(line_x,
3377 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
3378 LYX_PAPER_MARGIN / 5, 2,
3384 LyXLayout const & layout =
3385 textclasslist.Style(bview->buffer()->params.textclass,
3386 row_ptr->par()->GetLayout());
3389 y_bottom = row_ptr->height();
3391 /* is it a first row? */
3392 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
3394 /* start of appendix? */
3395 if (row_ptr->par()->start_of_appendix){
3396 pain.line(1, y_offset,
3398 LColor::appendixline);
3401 /* think about the margins */
3402 if (!row_ptr->previous() && bv_owner)
3403 y_top += LYX_PAPER_MARGIN;
3405 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
3407 pb_font.setColor(LColor::pagebreak).decSize();
3408 int w = 0, a = 0, d = 0;
3409 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
3411 y_offset + y_top + 2 * DefaultHeight(),
3413 Painter::line_onoffdash)
3416 _("Page Break (top)"),
3419 LColor::background, false, w, a, d);
3420 pain.rectText((ww - w)/2,
3421 y_offset + y_top + 2 * DefaultHeight() + d,
3422 _("Page Break (top)"),
3425 LColor::background);
3426 y_top += 3 * DefaultHeight();
3429 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
3430 /* draw a vfill top */
3431 pain.line(0, y_offset + 2 + y_top,
3432 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
3435 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
3437 y_offset + y_top + 3 * DefaultHeight(),
3440 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
3441 LYX_PAPER_MARGIN / 2,
3442 y_offset + y_top + 3 * DefaultHeight(),
3445 y_top += 3 * DefaultHeight();
3448 /* think about user added space */
3449 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
3451 /* think about the parskip */
3452 /* some parskips VERY EASY IMPLEMENTATION */
3453 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3454 if (layout.latextype == LATEX_PARAGRAPH
3455 && firstpar->GetDepth() == 0
3456 && firstpar->Previous())
3457 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3458 else if (firstpar->Previous()
3459 && textclasslist.Style(bview->buffer()->params.textclass,
3460 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3461 && firstpar->Previous()->GetDepth() == 0)
3462 // is it right to use defskip here, too? (AS)
3463 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
3466 if (row_ptr->par()->line_top) { /* draw a top line */
3467 y_top += lyxfont::ascent('x',
3468 GetFont(bview->buffer(),
3469 row_ptr->par(), 0));
3470 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3471 int xp = static_cast<int>(inset_owner ? x : 0);
3472 pain.line(xp, y_offset + y_top,
3473 w, y_offset + y_top,
3475 Painter::line_solid,
3476 Painter::line_thick);
3478 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
3479 row_ptr->par(), 0));
3482 /* should we print a label? */
3483 if (layout.labeltype >= LABEL_STATIC
3484 && (layout.labeltype != LABEL_STATIC
3485 || layout.latextype != LATEX_ENVIRONMENT
3486 || row_ptr->par()->IsFirstInSequence())) {
3487 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3488 if (!row_ptr->par()->GetLabelstring().empty()) {
3490 string tmpstring = row_ptr->par()->GetLabelstring();
3492 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3493 if (bview->buffer()->params.secnumdepth >= 0) {
3494 /* this is special code for the chapter layout. This is printed in
3495 * an extra row and has a pagebreak at the top. */
3496 float spacing_val = 1.0;
3497 if (!row_ptr->par()->spacing.isDefault()) {
3498 spacing_val = row_ptr->par()->spacing.getValue();
3500 spacing_val = bview->buffer()->params.spacing.getValue();
3503 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3504 + int(layout.parsep) * DefaultHeight();
3506 tmpx = ww - LeftMargin(bview, row_ptr) -
3507 lyxfont::width(tmpstring, font);
3508 pain.text(int(tmpx),
3509 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
3514 tmpx = ww - LeftMargin(bview, row_ptr)
3515 + lyxfont::width(layout.labelsep, font);
3517 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3518 LyXFont font(LyXFont::ALL_SANE);
3519 font.setSize(LyXFont::SIZE_SMALL);
3520 tmpx += lyxfont::width("Mwide-fixM", font);
3524 tmpx = x - lyxfont::width(layout.labelsep, font)
3525 - lyxfont::width(tmpstring, font);
3528 pain.text(int(tmpx),
3529 y_offset + row_ptr->baseline(),
3533 /* the labels at the top of an environment. More or less for bibliography */
3534 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3535 layout.labeltype == LABEL_BIBLIO ||
3536 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3537 if (row_ptr->par()->IsFirstInSequence()) {
3538 font = GetFont(bview->buffer(),
3539 row_ptr->par(), -2);
3540 if (!row_ptr->par()->GetLabelstring().empty()) {
3541 string tmpstring = row_ptr->par()->GetLabelstring();
3542 float spacing_val = 1.0;
3543 if (!row_ptr->par()->spacing.isDefault()) {
3544 spacing_val = row_ptr->par()->spacing.getValue();
3546 spacing_val = bview->buffer()->params.spacing.getValue();
3549 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3550 + (layout.labelbottomsep * DefaultHeight()));
3553 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3554 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
3555 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
3556 tmpx -= lyxfont::width(tmpstring, font) / 2;
3558 tmpx = ww - LeftMargin(bview, row_ptr) -
3559 lyxfont::width(tmpstring, font);
3560 pain.text(int(tmpx),
3561 y_offset + row_ptr->baseline()
3562 - row_ptr->ascent_of_text()
3568 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
3569 font = GetFont(bview->buffer(), row_ptr->par(), -1);
3571 tmpx = ww - LeftMargin(bview, row_ptr)
3572 + lyxfont::width(layout.labelsep, font);
3574 tmpx = x - lyxfont::width(layout.labelsep, font)
3575 - row_ptr->par()->bibkey->width(bview, font);
3576 row_ptr->par()->bibkey->draw(bview, font,
3577 y_offset + row_ptr->baseline(),
3582 /* is it a last row? */
3584 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
3586 LyXParagraph * par = row_ptr->par();
3590 (row_ptr->par()->ParFromPos(last + 1) == par)
3592 (row_ptr->par() == par)
3594 && (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
3596 /* think about the margins */
3597 if (!row_ptr->next() && bv_owner)
3598 y_bottom -= LYX_PAPER_MARGIN;
3600 /* draw a bottom pagebreak */
3601 if (firstpar->pagebreak_bottom) {
3603 pb_font.setColor(LColor::pagebreak).decSize();
3604 int w = 0, a = 0, d = 0;
3606 y_offset + y_bottom - 2 * DefaultHeight(),
3608 y_offset + y_bottom - 2 * DefaultHeight(),
3610 Painter::line_onoffdash)
3613 _("Page Break (bottom)"),
3616 LColor::background, false, w, a, d);
3617 pain.rectText((ww - w) / 2,
3618 y_offset + y_top + 2 * DefaultHeight() + d,
3619 _("Page Break (bottom)"),
3622 LColor::background);
3623 y_bottom -= 3 * DefaultHeight();
3626 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3627 /* draw a vfill bottom */
3628 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
3630 y_offset + y_bottom - 3 * DefaultHeight(),
3632 pain.line(0, y_offset + y_bottom - 2,
3634 y_offset + y_bottom - 2,
3636 pain.line(LYX_PAPER_MARGIN / 2,
3637 y_offset + y_bottom - 3 * DefaultHeight(),
3638 LYX_PAPER_MARGIN / 2,
3639 y_offset + y_bottom - 2,
3641 y_bottom -= 3 * DefaultHeight();
3644 /* think about user added space */
3645 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
3647 if (firstpar->line_bottom) {
3648 /* draw a bottom line */
3649 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3650 par, par->Last() - 1));
3651 int w = (inset_owner ? inset_owner->width(bview, font) : ww);
3652 int xp = static_cast<int>(inset_owner ? x : 0);
3653 pain.line(xp, y_offset + y_bottom,
3654 w, y_offset + y_bottom,
3655 LColor::topline, Painter::line_solid,
3656 Painter::line_thick);
3657 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
3658 par, par->Last() - 1));
3662 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
3665 case END_LABEL_FILLED_BOX:
3667 LyXFont font = GetFont(bview->buffer(),
3668 row_ptr->par(), last);
3669 int size = int(0.75 * lyxfont::maxAscent(font));
3670 int y = (y_offset + row_ptr->baseline()) - size;
3671 int x = is_rtl ? LYX_PAPER_MARGIN
3672 : ww - LYX_PAPER_MARGIN - size;
3674 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3676 LyXFont font(LyXFont::ALL_SANE);
3677 font.setSize(LyXFont::SIZE_SMALL);
3678 x += lyxfont::width("Mwide-figM", font);
3680 x -= LYX_PAPER_MARGIN/2;
3682 if (row_ptr->fill() <= size)
3683 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
3684 if (endlabel == END_LABEL_BOX) {
3685 pain.line(x, y, x, y + size,
3687 pain.line(x + size, y, x + size , y + size,
3689 pain.line(x, y, x + size, y,
3691 pain.line(x, y + size, x + size, y + size,
3694 pain.fillRectangle(x, y, size, size,
3698 case END_LABEL_STATIC:
3700 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
3701 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
3702 layout).endlabelstring();
3703 font = GetFont(bview->buffer(), row_ptr->par(), -2);
3704 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
3705 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
3706 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
3709 case END_LABEL_NO_LABEL:
3714 /* draw the text in the pixmap */
3716 vpos = row_ptr->pos();
3718 LyXParagraph::size_type main_body =
3719 BeginningOfMainBody(bview->buffer(), row_ptr->par());
3720 if (main_body > 0 &&
3721 (main_body-1 > last ||
3722 !row_ptr->par()->IsLineSeparator(main_body - 1)))
3725 while (vpos <= last) {
3726 pos = vis2log(vpos);
3727 if (main_body > 0 && pos == main_body - 1) {
3728 x += fill_label_hfill
3729 + lyxfont::width(layout.labelsep,
3730 GetFont(bview->buffer(),
3731 row_ptr->par(), -2))
3732 - SingleWidth(bview,
3737 if (row_ptr->par() ->IsHfill(pos)) {
3740 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3742 y_offset + row_ptr->baseline(),
3745 if (HfillExpansion(bview->buffer(),
3747 if (pos >= main_body) {
3749 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3750 int(x + fill_hfill),
3751 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3753 Painter::line_onoffdash);
3757 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3758 int(x + fill_label_hfill),
3759 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
3761 Painter::line_onoffdash);
3763 x += fill_label_hfill;
3766 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
3768 y_offset + row_ptr->baseline(),
3773 } else if (row_ptr->par()->IsSeparator(pos)) {
3774 x += SingleWidth(bview,
3775 row_ptr->par(), pos);
3776 if (pos >= main_body)
3777 x += fill_separator;
3780 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
3785 int LyXText::DefaultHeight() const
3787 LyXFont font(LyXFont::ALL_SANE);
3788 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
3792 /* returns the column near the specified x-coordinate of the row
3793 * x is set to the real beginning of this column */
3794 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
3795 bool & boundary) const
3798 float fill_separator, fill_hfill, fill_label_hfill;
3800 PrepareToPrint(bview, row, tmpx, fill_separator,
3801 fill_hfill, fill_label_hfill);
3803 LyXParagraph::size_type vc = row->pos();
3804 LyXParagraph::size_type last = RowLastPrintable(row);
3805 LyXParagraph::size_type c = 0;
3806 LyXLayout const & layout =
3807 textclasslist.Style(bview->buffer()->params.textclass,
3808 row->par()->GetLayout());
3809 bool left_side = false;
3811 LyXParagraph::size_type
3812 main_body = BeginningOfMainBody(bview->buffer(), row->par());
3813 float last_tmpx = tmpx;
3815 if (main_body > 0 &&
3816 (main_body-1 > last ||
3817 !row->par()->IsLineSeparator(main_body - 1)))
3820 while (vc <= last && tmpx <= x) {
3823 if (main_body > 0 && c == main_body-1) {
3824 tmpx += fill_label_hfill +
3825 lyxfont::width(layout.labelsep,
3826 GetFont(bview->buffer(), row->par(), -2));
3827 if (row->par()->IsLineSeparator(main_body - 1))
3828 tmpx -= SingleWidth(bview, row->par(), main_body-1);
3831 if (HfillExpansion(bview->buffer(), row, c)) {
3832 x += SingleWidth(bview, row->par(), c);
3836 tmpx += fill_label_hfill;
3838 else if (row->par()->IsSeparator(c)) {
3839 tmpx += SingleWidth(bview, row->par(), c);
3841 tmpx+= fill_separator;
3843 tmpx += SingleWidth(bview, row->par(), c);
3847 if ((tmpx + last_tmpx) / 2 > x) {
3852 if (vc > last + 1) // This shouldn't happen.
3856 bool lastrow = lyxrc.rtl_support // This is not needed, but gives
3857 // some speedup if rtl_support=false
3858 && (!row->next() || row->next()->par() != row->par());
3859 bool rtl = (lastrow)
3860 ? row->par()->isRightToLeftPar(bview->buffer()->params)
3861 : false; // If lastrow is false, we don't need to compute
3862 // the value of rtl.
3864 if (row->pos() > last) // Row is empty?
3867 ( ( rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
3868 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5) ))
3870 else if (vc == row->pos()) {
3872 if (bidi_level(c) % 2 == 1)
3875 c = vis2log(vc - 1);
3876 bool rtl = (bidi_level(c) % 2 == 1);
3877 if (left_side == rtl) {
3879 boundary = IsBoundary(bview->buffer(), row->par(), c);
3883 if (row->pos() <= last && c > last
3884 && row->par()->IsNewline(last)) {
3885 if (bidi_level(last) % 2 == 0)
3886 tmpx -= SingleWidth(bview, row->par(), last);
3888 tmpx += SingleWidth(bview, row->par(), last);
3899 /* turn the selection into a new environment. If there is no selection,
3900 * create an empty environment */
3901 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
3902 LyXParagraph::footnote_kind kind)
3904 /* no footnoteenvironment in a footnoteenvironment */
3905 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3906 WriteAlert(_("Impossible operation"),
3907 _("You can't insert a float in a float!"),
3911 /* no marginpars in minipages */
3912 if (kind == LyXParagraph::MARGIN
3913 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3914 WriteAlert(_("Impossible operation"),
3915 _("You can't insert a marginpar in a minipage!"),
3920 /* this doesnt make sense, if there is no selection */
3921 bool dummy_selection = false;
3923 sel_start_cursor = cursor; /* dummy selection */
3924 sel_end_cursor = cursor;
3925 dummy_selection = true;
3928 LyXParagraph * tmppar;
3930 /* a test to make sure there is not already a footnote
3931 * in the selection. */
3933 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
3935 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
3936 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3937 tmppar = tmppar->next;
3939 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
3940 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3941 WriteAlert(_("Impossible operation"),
3942 _("Float would include float!"),
3947 /* ok we have a selection. This is always between sel_start_cursor
3948 * and sel_end cursor */
3950 SetUndo(bview->buffer(), Undo::FINISH,
3951 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
3952 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
3954 if (sel_end_cursor.pos() > 0
3955 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
3956 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
3957 /* please break before a space at the end */
3958 if (sel_start_cursor.par() == sel_end_cursor.par()
3959 && sel_start_cursor.pos() > sel_end_cursor.pos())
3960 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
3962 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
3964 sel_end_cursor.par(sel_end_cursor.par()->Next());
3965 sel_end_cursor.pos(0);
3967 // don't forget to insert a dummy layout paragraph if necessary
3968 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
3969 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
3970 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
3971 sel_end_cursor.par(sel_end_cursor.par()->next);
3974 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
3976 cursor = sel_end_cursor;
3978 /* please break behind a space, if there is one. The space should
3980 if (sel_start_cursor.pos() > 0
3981 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
3982 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
3983 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
3984 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
3987 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
3988 sel_start_cursor.pos());
3989 tmppar = sel_start_cursor.par()->Next();
3991 if (dummy_selection) {
3993 if (kind == LyXParagraph::TAB
3994 || kind == LyXParagraph::FIG
3995 || kind == LyXParagraph::WIDE_TAB
3996 || kind == LyXParagraph::WIDE_FIG
3997 || kind == LyXParagraph::ALGORITHM) {
3998 pair<bool, LyXTextClass::size_type> lres =
3999 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4001 LyXTextClass::size_type lay;
4007 lay = 0; // use default layout "Standard" (0)
4009 tmppar->SetLayout(bview->buffer()->params, lay);
4012 if (sel_start_cursor.pos() > 0) {
4013 /* the footnote-environment should begin with a standard layout.
4014 * Imagine you insert a footnote within an enumeration, you
4015 * certainly do not want an enumerated footnote! */
4018 /* this is a exception the user would sometimes expect, I hope */
4019 sel_start_cursor.par()->Clear();
4023 while (tmppar != sel_end_cursor.par()) {
4024 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4025 tmppar->footnotekind = kind;
4026 tmppar = tmppar->Next();
4029 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4031 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4038 // returns pointer to a specified row
4039 Row * LyXText::GetRow(LyXParagraph * par,
4040 LyXParagraph::size_type pos, int & y) const
4045 Row * tmprow = firstrow;
4048 // find the first row of the specified paragraph
4049 while (tmprow->next() && tmprow->par() != par) {
4050 y += tmprow->height();
4051 tmprow = tmprow->next();
4054 // now find the wanted row
4055 while (tmprow->pos() < pos
4057 && tmprow->next()->par() == par
4058 && tmprow->next()->pos() <= pos) {
4059 y += tmprow->height();
4060 tmprow = tmprow->next();