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 #pragma implementation "table.h"
21 #include "lyxparagraph.h"
23 #include "support/textutils.h"
24 #include "insets/insetbib.h"
25 #include "insets/insettext.h"
26 #include "lyx_gui_misc.h"
28 #include "bufferparams.h"
30 #include "minibuffer.h"
45 static const int LYX_PAPER_MARGIN = 20;
46 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
49 int LyXText::workWidth(BufferView * bview) const
52 return inset_owner->textWidth(bview->painter());
54 return bview->workWidth();
58 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
59 LyXParagraph::size_type pos) const
61 if (!Encoding::is_arabic(c))
62 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
63 return c + (0xb0 - '0');
67 unsigned char prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
68 unsigned char next_char = ' ';
69 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
70 if (!Encoding::IsComposeChar_arabic(par->GetChar(i))) {
71 next_char = par->GetChar(i);
75 if (Encoding::is_arabic(next_char))
76 if (Encoding::is_arabic(prev_char))
77 return Encoding::TransformChar(c, Encoding::FORM_MEDIAL);
79 return Encoding::TransformChar(c, Encoding::FORM_INITIAL);
81 if (Encoding::is_arabic(prev_char))
82 return Encoding::TransformChar(c, Encoding::FORM_FINAL);
84 return Encoding::TransformChar(c, Encoding::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 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 (Encoding::IsComposeChar_arabic(c))
134 c = TransformChar(c, par, pos);
135 else if (font.language()->lang() == "hebrew" &&
136 Encoding::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) &&
264 || !row->par()->IsNewline(lpos + 1)) )
266 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
267 bool new_rtl = font.isVisibleRightToLeft();
268 bool new_rtl0 = font.isRightToLeft();
272 if (row->par()->table && row->par()->IsNewline(lpos)) {
274 new_rtl = new_rtl0 = false;
277 if (lpos == main_body - 1
278 && row->pos() < main_body - 1
279 && row->par()->IsLineSeparator(lpos)) {
280 new_level = (rtl_par) ? 1 : 0;
281 new_rtl = new_rtl0 = rtl_par;
283 new_level = (new_rtl) ? 1 : 2;
285 new_level = (rtl_par) ? 2 : 0;
287 if (is_space && new_level >= level) {
293 int new_level2 = new_level;
295 if (level == new_level && rtl0 != new_rtl0) {
297 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
298 } else if (level < new_level) {
299 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
300 if (new_level > rtl_par)
301 bidi_same_direction = false;
303 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
306 bidi_levels[lpos - bidi_start] = new_level;
308 while (level > new_level2) {
309 LyXParagraph::size_type old_lpos =
311 int delta = lpos - old_lpos - 1;
314 log2vis_list[lpos - bidi_start] += delta;
315 log2vis_list[old_lpos - bidi_start] += delta;
317 while (level < new_level)
318 stack[level++] = lpos;
322 LyXParagraph::size_type old_lpos = stack[--level];
323 int delta = bidi_end - old_lpos;
326 log2vis_list[old_lpos - bidi_start] += delta;
329 LyXParagraph::size_type vpos = bidi_start - 1;
330 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
331 vpos += log2vis_list[lpos - bidi_start];
332 vis2log_list[vpos - bidi_start] = lpos;
333 log2vis_list[lpos - bidi_start] = vpos;
338 // This method requires a previous call to ComputeBidiTables()
339 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
340 LyXParagraph::size_type pos) const
342 if (!lyxrc.rtl_support)
343 return false; // This is just for speedup
345 if (!bidi_InRange(pos - 1) ||
346 (par->table && par->IsNewline(pos-1)) )
349 bool rtl = bidi_level(pos - 1) % 2;
351 if (pos == par->Last() ||
352 (par->table && par->IsNewline(pos)))
353 rtl2 = par->isRightToLeftPar(buf->params);
354 else if (bidi_InRange(pos))
355 rtl2 = bidi_level(pos) % 2;
360 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
361 LyXParagraph::size_type pos,
362 LyXFont const & font) const
364 if (!lyxrc.rtl_support)
365 return false; // This is just for speedup
367 bool rtl = font.isVisibleRightToLeft();
369 if (pos == par->Last() ||
370 (par->table && par->IsNewline(pos)))
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);
512 if (lyxrc.mark_foreign_language &&
513 font.language() != bview->buffer()->params.language_info) {
514 int y = offset + row->height() - 1;
515 pain.line(int(tmpx), y, int(x), y,
522 /* usual characters, no insets */
524 // Collect character that we can draw in one command
526 // This is dirty, but fast. Notice that it will never be too small.
527 // For the record, I'll note that Microsoft Word has a limit
528 // of 768 here. We have none :-) (Asger)
529 // Ok. I am the first to admit that the use of std::string will be
530 // a tiny bit slower than using a POD char array. However, I claim
531 // that this slowdown is so small that it is close to inperceptive.
532 // So IMHO we should go with the easier and clearer implementation.
533 // And even if 1024 is a large number here it might overflow, string
534 // will only overflow if the machine is out of memory...
535 static string textstring;
539 LyXParagraph::size_type last = RowLastPrintable(row);
541 if (font.language()->lang() == "hebrew") {
542 if (Encoding::IsComposeChar_hebrew(c)) {
543 int width = lyxfont::width(c, font2);
545 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
546 c = row->par()->GetChar(i);
547 if (!Encoding::IsComposeChar_hebrew(c)) {
548 if (IsPrintableNonspace(c)) {
549 int width2 = SingleWidth(bview, row->par(), i, c);
550 dx = (c == 'ø' || c == 'ã') // dalet / resh
551 ? width2 - width : (width2 - width) / 2;
557 pain.text(int(x) + dx, offset + row->baseline(),
560 while (vpos <= last &&
561 (pos = vis2log(vpos)) >= 0
562 && IsPrintableNonspace(c = row->par()->GetChar(pos))
563 && !Encoding::IsComposeChar_hebrew(c)
564 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
568 // Draw text and set the new x position
569 pain.text(int(x), offset + row->baseline(),
571 x += lyxfont::width(textstring, font);
573 } else if (font.language()->lang() == "arabic" &&
574 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
575 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
576 if (Encoding::IsComposeChar_arabic(c)) {
577 c = TransformChar(c, row->par(), pos);
579 int width = lyxfont::width(c, font2);
581 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
582 c = row->par()->GetChar(i);
583 if (!Encoding::IsComposeChar_arabic(c)) {
584 if (IsPrintableNonspace(c)) {
585 int width2 = SingleWidth(bview, row->par(), i, c);
586 dx = (width2 - width) / 2;
592 pain.text(int(x) + dx, offset + row->baseline(),
595 textstring = TransformChar(c, row->par(), pos);
596 while (vpos <= last &&
597 (pos = vis2log(vpos)) >= 0
598 && IsPrintableNonspace(c = row->par()->GetChar(pos))
599 && !Encoding::IsComposeChar_arabic(c)
600 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
601 c = TransformChar(c, row->par(), pos);
605 // Draw text and set the new x position
606 pain.text(int(x), offset + row->baseline(),
608 x += lyxfont::width(textstring, font);
611 while (vpos <= last &&
612 (pos = vis2log(vpos)) >= 0
613 && IsPrintableNonspace(c = row->par()->GetChar(pos))
614 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
618 // Draw text and set the new x position
619 pain.text(int(x), offset + row->baseline(), textstring, font);
620 x += lyxfont::width(textstring, font);
623 if (lyxrc.mark_foreign_language &&
624 font.language() != bview->buffer()->params.language_info) {
625 int y = offset + row->height() - 1;
626 pain.line(int(tmpx), y, int(x), y,
630 // If we want ulem.sty support, drawing
631 // routines should go here. (Asger)
632 // Why shouldn't LyXFont::drawText handle it internally?
636 // Returns the left beginning of the text.
637 // This information cannot be taken from the layouts-objekt, because in
638 // LaTeX the beginning of the text fits in some cases (for example sections)
639 // exactly the label-width.
640 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
642 LyXLayout const & layout =
643 textclasslist.Style(bview->buffer()->params.textclass,
644 row->par()->GetLayout());
646 string parindent = layout.parindent;
649 /* table stuff -- begin */
650 if (row->par()->table)
652 /* table stuff -- end */
654 int x = LYX_PAPER_MARGIN;
656 x += lyxfont::signedWidth(textclasslist
657 .TextClass(bview->buffer()->params.textclass)
660 .TextClass(bview->buffer()->params.textclass)
663 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
664 LyXFont font(LyXFont::ALL_SANE);
665 font.setSize(LyXFont::SIZE_SMALL);
666 x += lyxfont::width("Mwide-figM", font)
667 + LYX_PAPER_MARGIN/2;
670 // this is the way, LyX handles the LaTeX-Environments.
671 // I have had this idea very late, so it seems to be a
672 // later added hack and this is true
673 if (!row->par()->GetDepth()) {
674 if (!row->par()->GetLayout()) {
675 // find the previous same level paragraph
676 if (row->par()->FirstPhysicalPar()->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
695 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
697 .Style(bview->buffer()->params.textclass,
698 newpar->GetLayout()).isEnvironment()) {
700 dummyrow.par(newpar);
701 dummyrow.pos(newpar->Last());
702 x = LeftMargin(bview, &dummyrow);
704 // this is no longer an error, because this function
705 // is used to clear impossible depths after changing
706 // a layout. Since there is always a redo,
707 // LeftMargin() is always called
708 row->par()->FirstPhysicalPar()->depth = 0;
711 if (newpar && !row->par()->GetLayout()) {
712 if (newpar->FirstPhysicalPar()->noindent)
715 parindent = textclasslist
716 .Style(bview->buffer()->params.textclass,
717 newpar->GetLayout()).parindent;
722 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
723 switch (layout.margintype) {
725 if (!layout.leftmargin.empty()) {
726 x += lyxfont::signedWidth(layout.leftmargin,
728 .TextClass(bview->buffer()->params.
732 if (!row->par()->GetLabelstring().empty()) {
733 x += lyxfont::signedWidth(layout.labelindent,
735 x += lyxfont::width(row->par()->GetLabelstring(),
737 x += lyxfont::width(layout.labelsep, labelfont);
741 x += lyxfont::signedWidth(layout.labelindent, labelfont);
742 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
743 if (!row->par()->GetLabelWidthString().empty()) {
744 x += lyxfont::width(row->par()->GetLabelWidthString(),
746 x += lyxfont::width(layout.labelsep, labelfont);
751 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
752 / (row->par()->GetDepth() + 4);
754 case MARGIN_FIRST_DYNAMIC:
755 if (layout.labeltype == LABEL_MANUAL) {
756 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
757 x += lyxfont::signedWidth(layout.leftmargin,
760 x += lyxfont::signedWidth(layout.labelindent,
763 } else if (row->pos()
764 // Special case to fix problems with
766 || (layout.labeltype == LABEL_STATIC
767 && layout.latextype == LATEX_ENVIRONMENT
768 && ! row->par()->IsFirstInSequence())) {
769 x += lyxfont::signedWidth(layout.leftmargin,
771 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
772 && layout.labeltype != LABEL_BIBLIO
773 && layout.labeltype !=
774 LABEL_CENTERED_TOP_ENVIRONMENT) {
775 x += lyxfont::signedWidth(layout.labelindent,
777 x += lyxfont::width(layout.labelsep, labelfont);
778 x += lyxfont::width(row->par()->GetLabelstring(),
783 case MARGIN_RIGHT_ADDRESS_BOX:
785 // ok, a terrible hack. The left margin depends on the widest
786 // row in this paragraph. Do not care about footnotes, they
787 // are *NOT* allowed in the LaTeX realisation of this layout.
789 // find the first row of this paragraph
790 Row const * tmprow = row;
791 while (tmprow->previous()
792 && tmprow->previous()->par() == row->par())
793 tmprow = tmprow->previous();
795 int minfill = tmprow->fill();
796 while (tmprow->next() && tmprow->next()->par() == row->par()) {
797 tmprow = tmprow->next();
798 if (tmprow->fill() < minfill)
799 minfill = tmprow->fill();
802 x += lyxfont::signedWidth(layout.leftmargin,
804 .TextClass(bview->buffer()->params.textclass)
810 if ((workWidth(bview) > 0) &&
811 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
813 if (!row->par()->pextra_widthp.empty()) {
814 x += workWidth(bview) *
815 atoi(row->par()->pextra_widthp.c_str()) / 100;
816 } else if (!row->par()->pextra_width.empty()) {
817 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
818 if (xx > workWidth(bview))
819 xx = workWidth(bview) * 80 / 100;
821 } else { // should not happen
822 LyXFont font(LyXFont::ALL_SANE);
823 x += lyxfont::width("XXXXXX", font);
827 int align; // wrong type
828 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
829 align = layout.align;
831 align = row->par()->FirstPhysicalPar()->align;
833 // set the correct parindent
834 if (row->pos() == 0) {
835 if ((layout.labeltype == LABEL_NO_LABEL
836 || layout.labeltype == LABEL_TOP_ENVIRONMENT
837 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
838 || (layout.labeltype == LABEL_STATIC
839 && layout.latextype == LATEX_ENVIRONMENT
840 && ! row->par()->IsFirstInSequence()))
841 && row->par() == row->par()->FirstPhysicalPar()
842 && align == LYX_ALIGN_BLOCK
843 && !row->par()->noindent
844 && (row->par()->layout ||
845 bview->buffer()->params.paragraph_separation ==
846 BufferParams::PARSEP_INDENT))
847 x += lyxfont::signedWidth(parindent,
849 .TextClass(bview->buffer()->params
852 else if (layout.labeltype == LABEL_BIBLIO) {
853 // ale970405 Right width for bibitems
854 x += bibitemMaxWidth(bview,textclasslist
855 .TextClass(bview->buffer()->params
864 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
866 LyXLayout const & layout =
867 textclasslist.Style(buf->params.textclass,
868 row->par()->GetLayout());
870 int x = LYX_PAPER_MARGIN
871 + lyxfont::signedWidth(textclasslist
872 .TextClass(buf->params.textclass)
875 .TextClass(buf->params.textclass)
879 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
880 x += LYX_PAPER_MARGIN / 2;
883 // this is the way, LyX handles the LaTeX-Environments.
884 // I have had this idea very late, so it seems to be a
885 // later added hack and this is true
886 if (row->par()->GetDepth()) {
887 // find the next level paragraph
889 LyXParagraph * newpar = row->par();
892 newpar = newpar->FirstPhysicalPar()->Previous();
894 newpar = newpar->FirstPhysicalPar();
895 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
896 && newpar->footnoteflag == row->par()->footnoteflag);
898 // make a corresponding row. Needed to call LeftMargin()
900 // check wether it is a sufficent paragraph
901 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
902 && textclasslist.Style(buf->params.textclass,
906 dummyrow.par(newpar);
908 x = RightMargin(buf, &dummyrow);
910 // this is no longer an error, because this function
911 // is used to clear impossible depths after changing
912 // a layout. Since there is always a redo,
913 // LeftMargin() is always called
914 row->par()->FirstPhysicalPar()->depth = 0;
918 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
919 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
920 .TextClass(buf->params.textclass)
921 .defaultfont()) * 4 / (row->par()->GetDepth()
927 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
929 if (textclasslist.Style(bview->buffer()->params.textclass,
930 row->par()->GetLayout()).margintype
934 tmprow.pos(row->par()->Last());
935 return LeftMargin(bview, &tmprow); /* just the beginning
938 return 0; /* LabelEnd is only needed, if the
939 layout fills a flushleft
945 /* table stuff -- begin*/
946 int LyXText::NumberOfCell(LyXParagraph * par,
947 LyXParagraph::size_type pos) const
950 LyXParagraph::size_type tmp_pos = 0;
951 while (tmp_pos < pos) {
952 if (par->IsNewline(tmp_pos))
960 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
961 LyXParagraph::size_type & pos) const
964 while (pos < par->Last() && !par->IsNewline(pos)) {
965 w += SingleWidth(bview, par, pos);
968 if (par->IsNewline(pos))
974 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
977 float fill_separator, fill_hfill, fill_label_hfill;
978 if (!row->par()->table)
980 PrepareToPrint(bview, row, tmpx, fill_separator,
981 fill_hfill, fill_label_hfill, false);
982 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
986 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
988 Row * row = GetRowNearY(y);
989 return HitInTable(bview, row, x);
993 /* table stuff -- end*/
997 // get the next breakpoint in a given paragraph
998 LyXParagraph::size_type
999 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1001 LyXParagraph * par = row->par();
1002 LyXParagraph::size_type pos = row->pos();
1007 /* table stuff -- begin*/
1009 while (pos < par->size()
1010 && (!par->IsNewline(pos)
1011 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1012 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1013 par->GetInset(pos) && par->GetInset(pos)->display()){
1014 par->GetInset(pos)->display(false);
1020 /* table stuff -- end*/
1022 // position of the last possible breakpoint
1023 // -1 isn't a suitable value, but a flag
1024 LyXParagraph::size_type last_separator = -1;
1025 width -= RightMargin(bview->buffer(), row);
1027 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1028 LyXLayout const & layout =
1029 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1030 LyXParagraph::size_type i = pos;
1032 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1033 /* special code for right address boxes, only newlines count */
1034 while (i < par->Last()) {
1035 if (par->IsNewline(i)) {
1037 i = par->Last() - 1; // this means break
1039 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1040 par->GetInset(i) && par->GetInset(i)->display()){
1041 par->GetInset(i)->display(false);
1046 // Last position is an invariant
1047 LyXParagraph::size_type const last =
1049 // this is the usual handling
1050 int x = LeftMargin(bview, row);
1051 bool doitonetime = true;
1052 while (doitonetime || ((x < width) && (i < last))) {
1053 doitonetime = false;
1054 char c = par->GetChar(i);
1055 if (IsNewlineChar(c)) {
1057 x = width; // this means break
1058 } else if (c == LyXParagraph::META_INSET &&
1061 // check wether a Display() inset is
1062 // valid here. if not, change it to
1064 if (par->GetInset(i)->display() &&
1065 (layout.isCommand() ||
1066 ((layout.labeltype == LABEL_MANUAL) &&
1067 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1068 // display istn't allowd
1069 par->GetInset(i)->display(false);
1070 x += SingleWidth(bview, par, i, c);
1071 } else if (par->GetInset(i)->display() ||
1072 par->GetInset(i)->needFullRow()) {
1073 // So break the line here
1077 if (IsLineSeparatorChar(par->GetChar(i+1)))
1080 last_separator = last; // to avoid extra rows
1082 last_separator = i - 1;
1083 x = width; // this means break
1089 x += SingleWidth(bview, par, i, c);
1093 if (IsLineSeparatorChar(c))
1095 x += SingleWidth(bview, par, i, c);
1098 if (i == main_body) {
1099 x += lyxfont::width(layout.labelsep,
1100 GetFont(bview->buffer(), par, -2));
1101 if (par->IsLineSeparator(i - 1))
1102 x-= SingleWidth(bview, par, i - 1);
1103 int left_margin = LabelEnd(bview, row);
1104 if (x < left_margin)
1108 // end of paragraph is always a suitable separator
1109 if (i == last && x < width)
1113 // well, if last_separator is still 0, the line isn't breakable.
1114 // don't care and cut simply at the end
1115 if (last_separator < 0) {
1119 // manual labels cannot be broken in LaTeX, do not care
1120 if (main_body && last_separator < main_body)
1121 last_separator = main_body - 1;
1123 return last_separator;
1127 // returns the minimum space a row needs on the screen in pixel
1128 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1130 if (paper_width < 0)
1134 // get the pure distance
1135 LyXParagraph::size_type last = RowLastPrintable(row);
1137 /* table stuff -- begin */
1138 if (row->par()->table) {
1139 // for tables FILL does calculate the widthes of each cell in
1141 LyXParagraph::size_type pos = row->pos();
1142 int cell = NumberOfCell(row->par(), pos);
1145 row->par()->table->SetWidthOfCell(cell,
1150 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1151 // don't forget the very last table cell without characters
1152 if (cell == row->par()->table->GetNumberOfCells() - 1)
1153 row->par()->table->SetWidthOfCell(cell,
1158 return 0; /* width of table cannot be returned since
1159 * we cannot guarantee its correct value at
1162 /* table stuff -- end*/
1165 // special handling of the right address boxes
1166 if (textclasslist.Style(bview->buffer()->params.textclass,
1167 row->par()->GetLayout()).margintype
1168 == MARGIN_RIGHT_ADDRESS_BOX) {
1169 int tmpfill = row->fill();
1170 row->fill(0); // the minfill in MarginLeft()
1171 w = LeftMargin(bview, row);
1174 w = LeftMargin(bview, row);
1176 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1177 row->par()->GetLayout());
1178 LyXParagraph::size_type main_body =
1179 BeginningOfMainBody(bview->buffer(), row->par());
1180 LyXParagraph::size_type i = row->pos();
1183 if (main_body > 0 && i == main_body) {
1184 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1185 if (row->par()->IsLineSeparator(i - 1))
1186 w -= SingleWidth(bview, row->par(), i - 1);
1187 int left_margin = LabelEnd(bview, row);
1188 if (w < left_margin)
1191 w += SingleWidth(bview, row->par(), i);
1194 if (main_body > 0 && main_body > last) {
1195 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1196 if (last >= 0 && row->par()->IsLineSeparator(last))
1197 w -= SingleWidth(bview, row->par(), last);
1198 int left_margin = LabelEnd(bview, row);
1199 if (w < left_margin)
1203 fill = paper_width - w - RightMargin(bview->buffer(), row);
1208 // returns the minimum space a manual label needs on the screen in pixel
1209 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1211 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1212 // -1 because a label ends either with a space that is in the label,
1213 // or with the beginning of a footnote that is outside the label.
1215 // I don't understand this code in depth, but sometimes "last" is
1216 // less than 0 and this causes a crash. This fix seems to work
1217 // correctly, but I bet the real error is elsewhere. The bug is
1218 // triggered when you have an open footnote in a paragraph
1219 // environment with a manual label. (Asger)
1220 if (last < 0) last = 0;
1222 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1229 w += SingleWidth(bview, row->par(), i);
1234 if (!row->par()->labelwidthstring.empty()) {
1235 fill = max(lyxfont::width(row->par()->labelwidthstring,
1236 GetFont(bview->buffer(), row->par(), -2)) - w,
1244 // returns the number of separators in the specified row. The separator
1245 // on the very last column doesnt count
1246 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1248 int last = RowLast(row);
1249 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1251 for (; p < last; ++p) {
1252 if (row->par()->IsSeparator(p)) {
1260 // returns the number of hfills in the specified row. The LyX-Hfill is
1261 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1262 // ignored. This is *MUCH* more usefull than not to ignore!
1263 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1265 int last = RowLast(row);
1266 int first = row->pos();
1267 if (first) { /* hfill *DO* count at the beginning
1269 while(first <= last && row->par()->IsHfill(first))
1273 first = max(first, BeginningOfMainBody(buf, row->par()));
1275 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1276 if (row->par()->IsHfill(p)) {
1284 // like NumberOfHfills, but only those in the manual label!
1285 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1287 LyXParagraph::size_type last = RowLast(row);
1288 LyXParagraph::size_type first = row->pos();
1289 if (first) { /* hfill *DO* count at the beginning
1291 while(first < last && row->par()->IsHfill(first))
1295 last = min(last, BeginningOfMainBody(buf, row->par()));
1297 for (LyXParagraph::size_type p = first;
1298 p < last; ++p) { // last, because the end is ignored!
1299 if (row->par()->IsHfill(p)) {
1307 // returns true, if a expansion is needed.
1308 // Rules are given by LaTeX
1309 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1310 LyXParagraph::size_type pos) const
1312 // by the way, is it a hfill?
1313 if (!row_ptr->par()->IsHfill(pos))
1316 // at the end of a row it does not count
1317 if (pos >= RowLast(row_ptr))
1320 // at the beginning of a row it does not count, if it is not
1321 // the first row of a paragaph
1322 if (!row_ptr->pos())
1325 // in some labels it does not count
1326 if (textclasslist.Style(buf->params.textclass,
1327 row_ptr->par()->GetLayout()).margintype
1329 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1332 // if there is anything between the first char of the row and
1333 // the sepcified position that is not a newline and not a hfill,
1334 // the hfill will count, otherwise not
1335 LyXParagraph::size_type i = row_ptr->pos();
1336 while (i < pos && (row_ptr->par()->IsNewline(i)
1337 || row_ptr->par()->IsHfill(i)))
1344 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1346 /* get the maximum ascent and the maximum descent */
1347 int asc = 0, desc = 0, pos = 0;
1348 float layoutasc = 0;
1349 float layoutdesc = 0;
1352 Inset * tmpinset = 0;
1354 /* this must not happen before the currentrow for clear reasons.
1355 so the trick is just to set the current row onto this row */
1357 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1359 /* ok , let us initialize the maxasc and maxdesc value.
1360 * This depends in LaTeX of the font of the last character
1361 * in the paragraph. The hack below is necessary because
1362 * of the possibility of open footnotes */
1364 /* Correction: only the fontsize count. The other properties
1365 are taken from the layoutfont. Nicer on the screen :) */
1367 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1368 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1370 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1371 firstpar->GetLayout());
1373 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1374 LyXFont::FONT_SIZE size = font.size();
1375 font = GetFont(bview->buffer(), par, -1);
1378 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1380 float spacing_val = 1.0;
1381 if (!row_ptr->par()->spacing.isDefault()) {
1382 spacing_val = row_ptr->par()->spacing.getValue();
1384 spacing_val = bview->buffer()->params.spacing.getValue();
1386 //lyxerr << "spacing_val = " << spacing_val << endl;
1388 int maxasc = int(lyxfont::maxAscent(font) *
1389 layout.spacing.getValue() *
1391 int maxdesc = int(lyxfont::maxDescent(font) *
1392 layout.spacing.getValue() *
1394 int pos_end = RowLast(row_ptr);
1398 // Check if any insets are larger
1399 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1400 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1401 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1402 tmpinset = row_ptr->par()->GetInset(pos);
1404 tmpinset->update(bview, tmpfont);
1405 asc = tmpinset->ascent(bview, tmpfont);
1406 desc = tmpinset->descent(bview, tmpfont);
1407 maxwidth += tmpinset->width(bview, tmpfont);
1408 maxasc = max(maxasc, asc);
1409 maxdesc = max(maxdesc, desc);
1412 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1416 // Check if any custom fonts are larger (Asger)
1417 // This is not completely correct, but we can live with the small,
1418 // cosmetic error for now.
1419 LyXFont::FONT_SIZE maxsize =
1420 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1422 if (maxsize > font.size()) {
1423 font.setSize(maxsize);
1425 asc = lyxfont::maxAscent(font);
1426 desc = lyxfont::maxDescent(font);
1434 /* table stuff -- begin*/
1435 if (row_ptr->par()->table){
1436 // stretch the rows a bit
1440 /* table stuff -- end*/
1443 // This is nicer with box insets:
1447 row_ptr->ascent_of_text(maxasc);
1449 /* is it a top line? */
1450 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1452 /* some parksips VERY EASY IMPLEMENTATION */
1453 if (bview->buffer()->params.paragraph_separation ==
1454 BufferParams::PARSEP_SKIP) {
1455 if (layout.isParagraph()
1456 && firstpar->GetDepth() == 0
1457 && firstpar->Previous())
1458 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1459 else if (firstpar->Previous()
1460 && textclasslist.Style(bview->buffer()->params.textclass,
1461 firstpar->Previous()->GetLayout()).isParagraph()
1462 && firstpar->Previous()->GetDepth() == 0)
1463 // is it right to use defskip here too? (AS)
1464 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1467 /* the paper margins */
1468 if (!row_ptr->par()->previous && bv_owner)
1469 maxasc += LYX_PAPER_MARGIN;
1471 /* add the vertical spaces, that the user added */
1472 if (firstpar->added_space_top.kind() != VSpace::NONE)
1473 maxasc += int(firstpar->added_space_top.inPixels(bview));
1475 /* do not forget the DTP-lines!
1476 * there height depends on the font of the nearest character */
1477 if (firstpar->line_top)
1478 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1481 /* and now the pagebreaks */
1482 if (firstpar->pagebreak_top)
1483 maxasc += 3 * DefaultHeight();
1485 /* this is special code for the chapter, since the label of this
1486 * layout is printed in an extra row */
1487 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1488 && bview->buffer()->params.secnumdepth >= 0) {
1489 float spacing_val = 1.0;
1490 if (!row_ptr->par()->spacing.isDefault()) {
1491 spacing_val = row_ptr->par()->spacing.getValue();
1493 spacing_val = bview->buffer()->params.spacing.getValue();
1496 labeladdon = int(lyxfont::maxDescent(labelfont) *
1497 layout.spacing.getValue() *
1499 + int(lyxfont::maxAscent(labelfont) *
1500 layout.spacing.getValue() *
1504 /* special code for the top label */
1505 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1506 || layout.labeltype == LABEL_BIBLIO
1507 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1508 && row_ptr->par()->IsFirstInSequence()
1509 && !row_ptr->par()->GetLabelstring().empty()) {
1510 float spacing_val = 1.0;
1511 if (!row_ptr->par()->spacing.isDefault()) {
1512 spacing_val = row_ptr->par()->spacing.getValue();
1514 spacing_val = bview->buffer()->params.spacing.getValue();
1518 (lyxfont::maxAscent(labelfont) *
1519 layout.spacing.getValue() *
1521 +(lyxfont::maxDescent(labelfont) *
1522 layout.spacing.getValue() *
1524 + layout.topsep * DefaultHeight()
1525 + layout.labelbottomsep * DefaultHeight());
1528 /* and now the layout spaces, for example before and after a section,
1529 * or between the items of a itemize or enumerate environment */
1531 if (!firstpar->pagebreak_top) {
1532 LyXParagraph * prev = row_ptr->par()->Previous();
1534 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1535 if (prev && prev->GetLayout() == firstpar->GetLayout()
1536 && prev->GetDepth() == firstpar->GetDepth()
1537 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1539 layoutasc = (layout.itemsep * DefaultHeight());
1541 else if (row_ptr->previous()) {
1542 tmptop = layout.topsep;
1544 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1545 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1546 row_ptr->previous()->par()->
1547 GetLayout()).bottomsep;
1550 layoutasc = (tmptop * DefaultHeight());
1552 else if (row_ptr->par()->line_top){
1553 tmptop = layout.topsep;
1556 layoutasc = (tmptop * DefaultHeight());
1559 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1561 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1562 prev->GetLayout()).parsep * DefaultHeight());
1565 if (firstpar->Previous()
1566 && firstpar->Previous()->GetDepth() == 0
1567 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1570 else if (firstpar->Previous()){
1571 maxasc += int(layout.parsep * DefaultHeight());
1577 /* is it a bottom line? */
1578 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1579 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1581 /* the paper margins */
1582 if (!par->next && bv_owner)
1583 maxdesc += LYX_PAPER_MARGIN;
1585 /* add the vertical spaces, that the user added */
1586 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1587 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1589 /* do not forget the DTP-lines!
1590 * there height depends on the font of the nearest character */
1591 if (firstpar->line_bottom)
1592 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1593 par, par->Last() - 1));
1595 /* and now the pagebreaks */
1596 if (firstpar->pagebreak_bottom)
1597 maxdesc += 3 * DefaultHeight();
1599 /* and now the layout spaces, for example before and after a section,
1600 * or between the items of a itemize or enumerate environment */
1601 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1602 LyXParagraph * nextpar = row_ptr->par()->Next();
1603 LyXParagraph * comparepar = row_ptr->par();
1607 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1608 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1609 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1610 if (comparepar->GetLayout()!= nextpar->GetLayout()
1611 || nextpar->GetLabelWidthString() !=
1612 comparepar->GetLabelWidthString())
1613 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1615 if (unusual > usual)
1616 layoutdesc = unusual;
1620 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1622 if (comparepar->GetLayout()!= nextpar->GetLayout()
1623 || nextpar->GetLabelWidthString() !=
1624 comparepar->GetLabelWidthString())
1625 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1630 /* incalculate the layout spaces */
1631 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1632 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1635 /* table stuff -- begin*/
1636 if (row_ptr->par()->table){
1637 maxasc += row_ptr->par()->table->
1638 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1640 /* table stuff -- end*/
1642 /* calculate the new height of the text */
1643 height -= row_ptr->height();
1645 row_ptr->height(maxasc + maxdesc + labeladdon);
1646 row_ptr->baseline(maxasc + labeladdon);
1648 height += row_ptr->height();
1650 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
1651 row_ptr->width(maxwidth+x);
1654 width = max(0,workWidth(bview));
1656 if (r->width() > width)
1664 /* Appends the implicit specified paragraph behind the specified row,
1665 * start at the implicit given position */
1666 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1668 bool not_ready = true;
1670 // The last character position of a paragraph is an invariant so we can
1671 // safely get it here. (Asger)
1672 int lastposition = row->par()->Last();
1675 // Get the next breakpoint
1676 int z = NextBreakPoint(bview, row, workWidth(bview));
1680 // Insert the new row
1681 if (z < lastposition) {
1683 InsertRow(row, row->par(), z);
1690 // Set the dimensions of the row
1691 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1692 SetHeightOfRow(bview, tmprow);
1694 } while (not_ready);
1698 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1700 bool not_ready = true;
1703 /* get the next breakpoint */
1704 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1707 if (z < row->par()->Last() ) {
1708 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1711 InsertRow(row, row->par(), z);
1717 if (row->pos() == z)
1718 not_ready = false; // the rest will not change
1724 /* if there are some rows too much, delete them */
1725 /* only if you broke the whole paragraph! */
1726 Row * tmprow2 = row;
1727 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1728 tmprow2 = tmprow2->next();
1730 while (tmprow2 != row) {
1731 tmprow2 = tmprow2->previous();
1732 RemoveRow(tmprow2->next());
1737 /* set the dimensions of the row */
1738 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1739 SetHeightOfRow(bview, tmprow);
1740 } while (not_ready);
1744 // this is just a little changed version of break again
1745 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1747 // get the next breakpoint
1748 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1751 if (z < row->par()->Last() ) {
1753 || (row->next() && row->next()->par() != row->par())) {
1754 /* insert a new row */
1756 InsertRow(row, row->par(), z);
1762 if (row->pos() != z)
1766 // if there are some rows too much, delete them
1767 // only if you broke the whole paragraph!
1768 Row * tmprow2 = row;
1769 while (tmprow2->next()
1770 && tmprow2->next()->par() == row->par()) {
1771 tmprow2 = tmprow2->next();
1773 while (tmprow2 != row) {
1774 tmprow2 = tmprow2->previous();
1775 RemoveRow(tmprow2->next());
1779 // set the dimensions of the row
1780 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1781 SetHeightOfRow(bview, tmprow);
1785 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1787 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1788 cursor.par()->GetLayout());
1790 /* table stuff -- begin */
1791 if (cursor.par()->table) {
1792 // breaking of tables is only allowed at the beginning or the end */
1793 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1794 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1795 return; // no breaking of tables allowed
1797 /* table stuff -- end */
1799 // this is only allowed, if the current paragraph is not empty or caption
1800 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1802 layout.labeltype!= LABEL_SENSITIVE)
1805 SetUndo(bview->buffer(), Undo::INSERT,
1806 cursor.par()->ParFromPos(cursor.pos())->previous,
1807 cursor.par()->ParFromPos(cursor.pos())->next);
1810 /* table stuff -- begin */
1811 if (cursor.par()->table) {
1812 int cell = NumberOfCell(cursor.par(), cursor.pos());
1813 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1814 SetCursor(bview, cursor.par(), cursor.par()->size());
1816 /* table stuff -- end */
1818 // please break always behind a space
1819 if (cursor.pos() < cursor.par()->Last()
1820 && cursor.par()->IsLineSeparator(cursor.pos()))
1821 cursor.pos(cursor.pos() + 1);
1823 // break the paragraph
1827 keep_layout = layout.isEnvironment();
1828 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1831 /* table stuff -- begin */
1832 if (cursor.par()->table){
1833 // the table should stay with the contents
1835 cursor.par()->Next()->table = cursor.par()->table;
1836 cursor.par()->table = 0;
1839 /* table stuff -- end */
1841 // well this is the caption hack since one caption is really enough
1842 if (layout.labeltype == LABEL_SENSITIVE) {
1844 // set to standard-layout
1845 cursor.par()->SetLayout(bview->buffer()->params, 0);
1847 // set to standard-layout
1848 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1851 /* if the cursor is at the beginning of a row without prior newline,
1853 * This touches only the screen-update. Otherwise we would may have
1854 * an empty row on the screen */
1855 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1856 cursor.row()->pos() == cursor.pos()) {
1860 status = LyXText::NEED_MORE_REFRESH;
1861 refresh_row = cursor.row();
1862 refresh_y = cursor.y() - cursor.row()->baseline();
1864 // Do not forget the special right address boxes
1865 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1866 while (refresh_row->previous() &&
1867 refresh_row->previous()->par() == refresh_row->par()) {
1868 refresh_row = refresh_row->previous();
1869 refresh_y -= refresh_row->height();
1872 RemoveParagraph(cursor.row());
1874 // set the dimensions of the cursor row
1875 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1877 SetHeightOfRow(bview, cursor.row());
1879 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1880 && cursor.par()->Next()->IsNewline(0))
1881 cursor.par()->Next()->Erase(0);
1883 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1885 UpdateCounters(bview, cursor.row()->previous());
1887 /* This check is necessary. Otherwise the new empty paragraph will
1888 * be deleted automatically. And it is more friendly for the user! */
1890 SetCursor(bview, cursor.par()->Next(), 0);
1892 SetCursor(bview, cursor.par(), 0);
1894 if (cursor.row()->next())
1895 BreakAgain(bview, cursor.row()->next());
1902 void LyXText::OpenFootnote(BufferView * bview)
1904 LyXParagraph * endpar,* tmppar;
1907 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1909 /* if there is no footnote in this paragraph, just return. */
1911 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1914 /* ok, move the cursor right before the footnote */
1916 /* just a little faster than using CursorRight() */
1918 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1919 cursor.pos(cursor.pos() + 1);
1922 /* now the cursor is at the beginning of the physical par */
1923 SetCursor(bview, cursor.par(),
1924 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1926 /* the cursor must be exactly before the footnote */
1927 par = cursor.par()->ParFromPos(cursor.pos());
1929 status = LyXText::NEED_MORE_REFRESH;
1930 refresh_row = cursor.row();
1931 refresh_y = cursor.y() - cursor.row()->baseline();
1933 tmppar = cursor.par();
1934 endpar = cursor.par()->Next();
1937 tmppar->OpenFootnote(cursor.pos());
1938 RemoveParagraph(row);
1939 /* set the dimensions of the cursor row */
1940 row->fill(Fill(bview, row, workWidth(bview)));
1941 SetHeightOfRow(bview, row);
1942 // CHECK See comment on top of text.C
1943 tmppar = tmppar->Next();
1945 while (tmppar != endpar) {
1947 InsertParagraph(bview, tmppar, row);
1948 while (row->next() && row->next()->par() == tmppar)
1950 tmppar = tmppar->Next();
1953 SetCursor(bview, par->next, 0);
1954 sel_cursor = cursor;
1960 /* table stuff -- begin*/
1962 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
1964 if (!cursor.par()->table)
1965 return; /* this should never happen */
1967 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1968 SetUndo(bview->buffer(), Undo::FINISH,
1969 cursor.par()->ParFromPos(cursor.pos())->previous,
1970 cursor.par()->ParFromPos(cursor.pos())->next);
1973 case LyXTable::SET_PWIDTH:
1974 cursor.par()->table->SetPWidth(actCell, val);
1976 case LyXTable::SET_SPECIAL_COLUMN:
1977 case LyXTable::SET_SPECIAL_MULTI:
1978 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
1983 RedoParagraph(bview);
1987 void LyXText::TableFeatures(BufferView * bview, int feature) const
1990 int setAlign = LYX_ALIGN_LEFT;
1994 if (!cursor.par()->table)
1995 return; /* this should never happen */
1997 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1998 SetUndo(bview->buffer(), Undo::FINISH,
1999 cursor.par()->ParFromPos(cursor.pos())->previous,
2000 cursor.par()->ParFromPos(cursor.pos())->next);
2003 case LyXTable::ALIGN_LEFT:
2004 setAlign= LYX_ALIGN_LEFT;
2006 case LyXTable::ALIGN_RIGHT:
2007 setAlign= LYX_ALIGN_RIGHT;
2009 case LyXTable::ALIGN_CENTER:
2010 setAlign= LYX_ALIGN_CENTER;
2016 case LyXTable::APPEND_ROW: {
2017 LyXParagraph::size_type pos = cursor.pos();
2019 /* move to the next row */
2020 int cell_org = actCell;
2021 int cell = cell_org;
2023 // if there is a ContRow following this row I have to add
2024 // the row after the ContRow's
2025 if ((pos < cursor.par()->Last()) &&
2026 cursor.par()->table->RowHasContRow(cell_org)) {
2027 while((pos < cursor.par()->Last()) &&
2028 !cursor.par()->table->IsContRow(cell)) {
2029 while (pos < cursor.par()->Last() &&
2030 !cursor.par()->IsNewline(pos))
2032 if (pos < cursor.par()->Last())
2036 while((pos < cursor.par()->Last()) &&
2037 cursor.par()->table->IsContRow(cell)) {
2038 while (pos < cursor.par()->Last() &&
2039 !cursor.par()->IsNewline(pos))
2041 if (pos < cursor.par()->Last())
2046 if (pos < cursor.par()->Last())
2049 while (pos < cursor.par()->Last() &&
2050 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2051 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2053 if (pos < cursor.par()->Last())
2058 /* insert the new cells */
2059 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2060 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2061 LyXFont font(LyXFont::ALL_INHERIT,lang);
2062 for (int i = 0; i < number; ++i) {
2063 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2066 /* append the row into the table */
2067 cursor.par()->table->AppendRow(cell_org);
2068 RedoParagraph(bview);
2071 case LyXTable::APPEND_CONT_ROW: {
2072 LyXParagraph::size_type pos = cursor.pos();
2073 /* move to the next row */
2074 int cell_org = actCell;
2075 int cell = cell_org;
2077 // if there is already a controw but not for this cell
2078 // the AppendContRow sets only the right values but does
2079 // not actually add a row
2080 if (cursor.par()->table->RowHasContRow(cell_org) &&
2081 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2082 cursor.par()->table->AppendContRow(cell_org);
2083 RedoParagraph(bview);
2086 while (pos < cursor.par()->Last() &&
2088 || !cursor.par()->table->IsFirstCell(cell))){
2089 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2091 if (pos < cursor.par()->Last())
2096 /* insert the new cells */
2097 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2098 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2099 LyXFont font(LyXFont::ALL_INHERIT,lang);
2100 for (int i = 0; i < number; ++i) {
2101 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2104 /* append the row into the table */
2105 cursor.par()->table->AppendContRow(cell_org);
2106 RedoParagraph(bview);
2109 case LyXTable::APPEND_COLUMN: {
2110 LyXParagraph::size_type pos = 0;
2111 int cell_org = actCell;
2113 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2114 LyXFont font(LyXFont::ALL_INHERIT,lang);
2116 if (pos && (cursor.par()->IsNewline(pos-1))){
2117 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2118 cursor.par()->InsertChar(pos,
2119 LyXParagraph::META_NEWLINE,
2121 if (pos <= cursor.pos())
2122 cursor.pos(cursor.pos() + 1);
2128 } while (pos <= cursor.par()->Last());
2129 /* remember that the very last cell doesn't end with a newline.
2130 This saves one byte memory per table ;-) */
2131 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2132 LyXParagraph::size_type last = cursor.par()->Last();
2133 cursor.par()->InsertChar(last,
2134 LyXParagraph::META_NEWLINE, font);
2137 /* append the column into the table */
2138 cursor.par()->table->AppendColumn(cell_org);
2140 RedoParagraph(bview);
2143 case LyXTable::DELETE_ROW:
2144 if (bview->the_locking_inset)
2145 bview->unlockInset(bview->the_locking_inset);
2146 RemoveTableRow(cursor);
2147 RedoParagraph(bview);
2150 case LyXTable::DELETE_COLUMN: {
2151 LyXParagraph::size_type pos = 0;
2152 int cell_org = actCell;
2154 if (bview->the_locking_inset)
2155 bview->unlockInset(bview->the_locking_inset);
2157 if (!pos || (cursor.par()->IsNewline(pos-1))){
2158 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2160 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2161 cursor.par()->Erase(pos);
2162 if (pos < cursor.par()->Last())
2163 cursor.par()->Erase(pos);
2165 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2166 --pos; // because of pos++ below
2171 } while (pos <= cursor.par()->Last());
2173 /* delete the column from the table */
2174 cursor.par()->table->DeleteColumn(cell_org);
2176 /* set the cursor to the beginning of the table, where else? */
2178 RedoParagraph(bview);
2181 case LyXTable::TOGGLE_LINE_TOP:
2182 lineSet = !cursor.par()->table->TopLine(actCell);
2184 cursor.par()->table->SetTopLine(actCell, lineSet);
2186 LyXParagraph::size_type i;
2188 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2189 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2190 cursor.par()->table->SetTopLine(n, lineSet);
2195 RedoParagraph(bview);
2198 case LyXTable::TOGGLE_LINE_BOTTOM:
2199 lineSet = !cursor.par()->table->BottomLine(actCell);
2201 cursor.par()->table->SetBottomLine(actCell, lineSet);
2203 LyXParagraph::size_type i;
2205 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2206 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2207 cursor.par()->table->SetBottomLine(n, lineSet);
2212 RedoParagraph(bview);
2215 case LyXTable::TOGGLE_LINE_LEFT:
2216 lineSet = !cursor.par()->table->LeftLine(actCell);
2218 cursor.par()->table->SetLeftLine(actCell, lineSet);
2220 LyXParagraph::size_type i;
2222 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2223 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2224 cursor.par()->table->SetLeftLine(n, lineSet);
2229 RedoParagraph(bview);
2232 case LyXTable::TOGGLE_LINE_RIGHT:
2233 lineSet = !cursor.par()->table->RightLine(actCell);
2235 cursor.par()->table->SetRightLine(actCell, lineSet);
2238 LyXParagraph::size_type i = sel_start_cursor.pos();
2239 for (; i <= sel_end_cursor.pos(); ++i) {
2240 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2241 cursor.par()->table->SetRightLine(n, lineSet);
2246 RedoParagraph(bview);
2249 case LyXTable::ALIGN_LEFT:
2250 case LyXTable::ALIGN_RIGHT:
2251 case LyXTable::ALIGN_CENTER:
2253 cursor.par()->table->SetAlignment(actCell, setAlign);
2256 LyXParagraph::size_type i = sel_start_cursor.pos();
2257 for (; i <= sel_end_cursor.pos(); ++i) {
2258 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2259 cursor.par()->table->SetAlignment(n, setAlign);
2264 RedoParagraph(bview);
2267 case LyXTable::DELETE_TABLE:
2268 SetCursorIntern(bview, cursor.par(), 0);
2269 delete cursor.par()->table;
2270 cursor.par()->table = 0;
2271 // temporary: Should put table in simple_cut_buffer (with before and after
2272 // dummy-paragraph !!
2273 // not necessar anymore with UNDO :)
2274 for (LyXParagraph::size_type i =
2275 cursor.par()->size() - 1; i >= 0; --i)
2276 cursor.par()->Erase(i);
2277 RedoParagraph(bview);
2280 case LyXTable::MULTICOLUMN: {
2282 // check wether we are completly in a multicol
2283 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2284 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2285 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2286 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2290 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2291 LyXParagraph::size_type pos = cursor.pos();
2292 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2294 for (; newlines; --newlines)
2295 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2296 RedoParagraph(bview);
2300 // selection must be in one row (or no selection)
2302 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2305 RedoParagraph(bview);
2309 if (sel_start_cursor.row() == sel_end_cursor.row()){
2310 LyXParagraph::size_type i;
2312 for (i = sel_start_cursor.pos();
2313 i < sel_end_cursor.pos(); ++i){
2314 if (sel_start_cursor.par()->IsNewline(i)){
2315 sel_start_cursor.par()->Erase(i);
2316 // check for double-blanks
2317 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2319 (i < sel_start_cursor.par()->Last()
2320 && !sel_start_cursor.par()->IsLineSeparator(i)))
2321 sel_start_cursor.par()->InsertChar(i, ' ');
2323 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2329 cursor.par()->table->
2330 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2331 sel_start_cursor.pos()),
2333 cursor.pos(sel_start_cursor.pos());
2334 RedoParagraph(bview);
2338 WriteAlert(_("Impossible Operation!"),
2339 _("Multicolumns can only be horizontally."),
2346 case LyXTable::SET_ALL_LINES:
2348 case LyXTable::UNSET_ALL_LINES:
2350 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2354 LyXParagraph::size_type i;
2356 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2357 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2358 cursor.par()->table->SetAllLines(n, setLines);
2363 RedoParagraph(bview);
2365 case LyXTable::SET_LONGTABLE:
2366 cursor.par()->table->SetLongTable(true);
2368 case LyXTable::UNSET_LONGTABLE:
2369 cursor.par()->table->SetLongTable(false);
2371 case LyXTable::SET_ROTATE_TABLE:
2372 cursor.par()->table->SetRotateTable(true);
2374 case LyXTable::UNSET_ROTATE_TABLE:
2375 cursor.par()->table->SetRotateTable(false);
2377 case LyXTable::SET_ROTATE_CELL:
2379 cursor.par()->table->SetRotateCell(actCell, true);
2381 LyXParagraph::size_type i;
2383 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2384 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2385 cursor.par()->table->SetRotateCell(n, true);
2391 case LyXTable::UNSET_ROTATE_CELL:
2393 cursor.par()->table->SetRotateCell(actCell, false);
2396 LyXParagraph::size_type i = sel_start_cursor.pos();
2397 for (; i <= sel_end_cursor.pos(); ++i) {
2398 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2399 cursor.par()->table->SetRotateCell(n, false);
2405 case LyXTable::SET_LINEBREAKS:
2406 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2408 cursor.par()->table->SetLinebreaks(actCell, what);
2410 LyXParagraph::size_type i;
2412 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2413 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2414 cursor.par()->table->SetLinebreaks(n, what);
2420 case LyXTable::SET_LTFIRSTHEAD:
2421 cursor.par()->table->SetLTHead(actCell, true);
2423 case LyXTable::SET_LTHEAD:
2424 cursor.par()->table->SetLTHead(actCell, false);
2426 case LyXTable::SET_LTFOOT:
2427 cursor.par()->table->SetLTFoot(actCell, false);
2429 case LyXTable::SET_LTLASTFOOT:
2430 cursor.par()->table->SetLTFoot(actCell, true);
2432 case LyXTable::SET_LTNEWPAGE:
2433 what = !cursor.par()->table->LTNewPage(actCell);
2434 cursor.par()->table->SetLTNewPage(actCell, what);
2440 void LyXText::InsertCharInTable(BufferView * bview, char c)
2445 bool jumped_over_space;
2447 /* first check, if there will be two blanks together or a blank at
2448 * the beginning of a paragraph.
2449 * I decided to handle blanks like normal characters, the main
2450 * difference are the special checks when calculating the row.fill
2451 * (blank does not count at the end of a row) and the check here */
2453 LyXFont realtmpfont = real_current_font;
2454 LyXFont rawtmpfont = current_font; /* store the current font.
2455 * This is because of the use
2456 * of cursor movements. The moving
2457 * cursor would refresh the
2460 // Get the font that is used to calculate the baselineskip
2461 LyXParagraph::size_type const lastpos =
2462 cursor.par()->Last();
2463 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2466 jumped_over_space = false;
2467 if (IsLineSeparatorChar(c)) {
2468 if ((cursor.pos() > 0 &&
2469 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2470 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2471 || (cursor.pos() == 0 &&
2472 !(cursor.par()->Previous()
2473 && cursor.par()->Previous()->footnoteflag
2474 == LyXParagraph::OPEN_FOOTNOTE)))
2476 } else if (IsNewlineChar(c)) {
2477 if (!IsEmptyTableCell()) {
2478 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2485 y = cursor.y() - row->baseline();
2486 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2487 * already inserted the character */
2488 cursor.par()->InsertChar(cursor.pos(), c);
2489 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2491 if (!jumped_over_space) {
2492 /* refresh the positions */
2494 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2495 tmprow = tmprow->next();
2496 tmprow->pos(tmprow->pos() + 1);
2500 cursor.pos(cursor.pos() + 1);
2502 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2504 current_font = rawtmpfont;
2505 real_current_font = realtmpfont;
2507 /* check, whether the last character's font has changed. */
2508 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2509 && rawparfont != rawtmpfont)
2510 RedoHeightOfParagraph(bview, cursor);
2514 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2515 LyXParagraph::size_type pos)
2518 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2519 par->GetInset(pos) && par->GetInset(pos)->display()){
2520 par->GetInset(pos)->display(false);
2524 Row * row = GetRow(par, pos, y);
2526 int tmpheight = row->height();
2527 SetHeightOfRow(bview, row);
2529 LyXParagraph::size_type tmp_pos = pos;
2530 /* update the table information */
2531 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2533 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2534 WidthOfCell(bview, par, tmp_pos))) {
2535 LyXCursor tmpcursor = cursor;
2536 SetCursorIntern(bview, par, pos, false);
2537 /* make a complete redraw */
2538 RedoDrawingOfParagraph(bview, cursor);
2542 /* redraw only the row */
2543 LyXCursor tmpcursor = cursor;
2544 SetCursorIntern(bview, par, pos);
2545 //CHECK See comment on top of text.C
2547 refresh_x = cursor.x();
2549 refresh_pos = cursor.pos();
2552 if (tmpheight == row->height())
2553 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2555 status = LyXText::NEED_MORE_REFRESH;
2557 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2562 void LyXText::BackspaceInTable(BufferView * bview)
2564 Row * tmprow, * row;
2567 LyXFont rawtmpfont = current_font;
2568 LyXFont realtmpfont = real_current_font;
2570 // Get the font that is used to calculate the baselineskip
2571 int const lastpos = cursor.par()->Last();
2572 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2575 if (cursor.pos() == 0) {
2576 /* no pasting of table paragraphs */
2580 /* this is the code for a normal backspace, not pasting
2582 SetUndo(bview->buffer(), Undo::DELETE,
2583 cursor.par()->ParFromPos(cursor.pos())->previous,
2584 cursor.par()->ParFromPos(cursor.pos())->next);
2586 CursorLeftIntern(bview);
2588 /* some insets are undeletable here */
2589 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2590 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2595 y = cursor.y() - row->baseline();
2597 /* some special code when deleting a newline. */
2598 if (cursor.par()->IsNewline(cursor.pos())) {
2602 cursor.par()->Erase(cursor.pos());
2604 /* refresh the positions */
2606 while (tmprow->next()
2607 && tmprow->next()->par() == row->par()) {
2608 tmprow = tmprow->next();
2609 tmprow->pos(tmprow->pos() - 1);
2613 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2615 /* check, wether the last characters font has changed. */
2616 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2617 && rawparfont != rawtmpfont)
2618 RedoHeightOfParagraph(bview, cursor);
2620 /* restore the current font
2621 * That is what a user expects! */
2622 current_font = rawtmpfont;
2623 real_current_font = realtmpfont;
2625 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2627 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2628 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2631 /* table stuff -- end*/
2635 // Just a macro to make some thing easier.
2636 void LyXText::RedoParagraph(BufferView * bview) const
2639 RedoParagraphs(bview, cursor, cursor.par()->Next());
2640 SetCursorIntern(bview, cursor.par(), cursor.pos());
2644 /* insert a character, moves all the following breaks in the
2645 * same Paragraph one to the right and make a rebreak */
2646 void LyXText::InsertChar(BufferView * bview, char c)
2648 SetUndo(bview->buffer(), Undo::INSERT,
2649 cursor.par()->ParFromPos(cursor.pos())->previous,
2650 cursor.par()->ParFromPos(cursor.pos())->next);
2652 // When the free-spacing option is set for the current layout,
2653 // disable the double-space checking
2656 textclasslist.Style(bview->buffer()->params.textclass,
2657 cursor.row()->par()->GetLayout()).free_spacing;
2660 /* table stuff -- begin*/
2661 if (cursor.par()->table) {
2662 InsertCharInTable(bview, c);
2666 /* table stuff -- end*/
2668 /* First check, if there will be two blanks together or a blank at
2669 the beginning of a paragraph.
2670 I decided to handle blanks like normal characters, the main
2671 difference are the special checks when calculating the row.fill
2672 (blank does not count at the end of a row) and the check here */
2674 // The bug is triggered when we type in a description environment:
2675 // The current_font is not changed when we go from label to main text
2676 // and it should (along with realtmpfont) when we type the space.
2677 // CHECK There is a bug here! (Asger)
2679 LyXFont realtmpfont = real_current_font;
2680 LyXFont rawtmpfont = current_font; /* store the current font.
2681 * This is because of the use
2682 * of cursor movements. The moving
2683 * cursor would refresh the
2686 // Get the font that is used to calculate the baselineskip
2687 LyXParagraph::size_type lastpos = cursor.par()->Last();
2688 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2691 bool jumped_over_space = false;
2693 if (!freeSpacing && IsLineSeparatorChar(c)) {
2694 if ((cursor.pos() > 0
2695 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2696 || (cursor.pos() > 0
2697 && cursor.par()->IsNewline(cursor.pos() - 1))
2698 || (cursor.pos() == 0
2699 && !(cursor.par()->Previous()
2700 && cursor.par()->Previous()->footnoteflag
2701 == LyXParagraph::OPEN_FOOTNOTE))) {
2702 if (cursor.pos() == 0 )
2703 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2705 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2709 } else if (IsNewlineChar(c)) {
2710 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2711 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2715 /* No newline at first position
2716 * of a paragraph or behind labels.
2717 * TeX does not allow that. */
2719 if (cursor.pos() < cursor.par()->Last() &&
2720 cursor.par()->IsLineSeparator(cursor.pos()))
2721 // newline always after a blank!
2722 CursorRightIntern(bview);
2723 cursor.row()->fill(-1); // to force a new break
2726 // the display inset stuff
2727 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2728 && cursor.row()->par()->GetInset(cursor.row()->pos())
2729 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2730 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2731 cursor.row()->fill(-1); // to force a new break
2733 // get the cursor row fist
2734 Row * row = cursor.row();
2735 long y = cursor.y() - row->baseline();
2736 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2737 * already insertet the character */
2738 cursor.par()->InsertChar(cursor.pos(), c);
2739 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2741 if (!jumped_over_space) {
2742 // refresh the positions
2744 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2745 tmprow = tmprow->next();
2746 tmprow->pos(tmprow->pos() + 1);
2750 // Is there a break one row above
2751 if ((cursor.par()->IsLineSeparator(cursor.pos())
2752 || cursor.par()->IsNewline(cursor.pos())
2753 || cursor.row()->fill() == -1)
2754 && row->previous() && row->previous()->par() == row->par()) {
2755 LyXParagraph::size_type z = NextBreakPoint(bview,
2758 if ( z >= row->pos()) {
2761 // set the dimensions of the row above
2762 row->previous()->fill(Fill(bview,
2766 SetHeightOfRow(bview, row->previous());
2768 y -= row->previous()->height();
2770 refresh_row = row->previous();
2771 status = LyXText::NEED_MORE_REFRESH;
2773 BreakAgainOneRow(bview, row);
2775 current_font = rawtmpfont;
2776 real_current_font = realtmpfont;
2777 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2778 false, cursor.boundary());
2779 // cursor MUST be in row now.
2781 if (row->next() && row->next()->par() == row->par())
2782 need_break_row = row->next();
2786 // check, wether the last characters font has changed.
2787 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2788 && rawparfont != rawtmpfont)
2789 RedoHeightOfParagraph(bview, cursor);
2796 // recalculate the fill of the row
2797 if (row->fill() >= 0) /* needed because a newline
2798 * will set fill to -1. Otherwise
2799 * we would not get a rebreak! */
2800 row->fill(Fill(bview, row, workWidth(bview)));
2801 if (row->fill() < 0 ) {
2804 refresh_x = cursor.x();
2805 refresh_pos = cursor.pos();
2806 status = LyXText::NEED_MORE_REFRESH;
2807 BreakAgainOneRow(bview, row);
2808 // will the cursor be in another row now?
2809 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2810 if (row->next() && row->next()->par() == row->par())
2811 // this should always be true
2813 BreakAgainOneRow(bview, row);
2815 current_font = rawtmpfont;
2816 real_current_font = realtmpfont;
2818 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2820 if (row->next() && row->next()->par() == row->par())
2821 need_break_row = row->next();
2826 refresh_x = cursor.x();
2828 refresh_pos = cursor.pos();
2830 int tmpheight = row->height();
2831 SetHeightOfRow(bview, row);
2832 if (tmpheight == row->height())
2833 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2835 status = LyXText::NEED_MORE_REFRESH;
2837 current_font = rawtmpfont;
2838 real_current_font = realtmpfont;
2839 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2843 // check, wether the last characters font has changed.
2844 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2845 && rawparfont != rawtmpfont) {
2846 RedoHeightOfParagraph(bview, cursor);
2848 // now the special right address boxes
2849 if (textclasslist.Style(bview->buffer()->params.textclass,
2850 cursor.par()->GetLayout()).margintype
2851 == MARGIN_RIGHT_ADDRESS_BOX) {
2852 RedoDrawingOfParagraph(bview, cursor);
2860 void LyXText::charInserted()
2862 // Here we could call FinishUndo for every 20 characters inserted.
2863 // This is from my experience how emacs does it.
2864 static unsigned int counter = 0;
2874 void LyXText::PrepareToPrint(BufferView * bview,
2875 Row * row, float & x,
2876 float & fill_separator,
2878 float & fill_label_hfill,
2883 float w = row->fill();
2885 fill_label_hfill = 0;
2887 fill_label_hfill = 0;
2890 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2893 x = RightMargin(bview->buffer(), row);
2894 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2895 LyXFont font(LyXFont::ALL_SANE);
2896 font.setSize(LyXFont::SIZE_SMALL);
2897 x += lyxfont::width("Mwide-figM", font);
2901 if (workWidth(bview) > 0)
2902 x = LeftMargin(bview, row);
2906 // is there a manual margin with a manual label
2907 if (textclasslist.Style(bview->buffer()->params.textclass,
2908 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2909 && textclasslist.Style(bview->buffer()->params.textclass,
2910 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2912 /* one more since labels are left aligned */
2913 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2914 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2915 fill_label_hfill = LabelFill(bview, row) / nlh;
2919 // are there any hfills in the row?
2920 float nh = NumberOfHfills(bview->buffer(), row);
2923 /* table stuff -- begin*/
2924 if (row->par()->table) {
2925 w = workWidth(bview) - row->par()->table->WidthOfTable()
2926 - x - RightMargin(bview->buffer(), row);
2927 nh = 0; /* ignore hfills in tables */
2929 /* table stuff -- end*/
2934 // is it block, flushleft or flushright?
2935 // set x how you need it
2937 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2938 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2940 align = row->par()->FirstPhysicalPar()->align;
2942 // center displayed insets
2943 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2944 && row->par()->GetInset(row->pos())
2945 && row->par()->GetInset(row->pos())->display())
2946 align = LYX_ALIGN_CENTER;
2949 case LYX_ALIGN_BLOCK:
2950 ns = NumberOfSeparators(bview->buffer(), row);
2951 if (ns && row->next() && row->next()->par() == row->par() &&
2952 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2953 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2954 && row->next()->par()->GetInset(row->next()->pos())
2955 && row->next()->par()->GetInset(row->next()->pos())->display())
2957 fill_separator = w / ns;
2961 case LYX_ALIGN_RIGHT:
2964 case LYX_ALIGN_CENTER:
2972 ComputeBidiTables(bview->buffer(), row);
2974 LyXParagraph::size_type main_body =
2975 BeginningOfMainBody(bview->buffer(), row->par());
2976 LyXParagraph::size_type last = RowLast(row);
2978 if (main_body > 0 &&
2979 (main_body-1 > last ||
2980 !row->par()->IsLineSeparator(main_body-1))) {
2981 LyXLayout const & layout =
2982 textclasslist.Style(bview->buffer()->params.textclass,
2983 row->par()->GetLayout());
2984 x += lyxfont::width(layout.labelsep,
2985 GetFont(bview->buffer(), row->par(), -2));
2986 if (main_body-1 <= last)
2987 x += fill_label_hfill;
2992 /* important for the screen */
2995 /* the cursor set functions have a special mechanism. When they
2996 * realize, that you left an empty paragraph, they will delete it.
2997 * They also delete the corresponding row */
2999 void LyXText::CursorRightOneWord(BufferView * bview) const
3001 // treat floats, HFills and Insets as words
3002 LyXCursor tmpcursor = cursor;
3003 // CHECK See comment on top of text.C
3005 if (tmpcursor.pos() == tmpcursor.par()->Last()
3006 && tmpcursor.par()->Next()) {
3007 tmpcursor.par(tmpcursor.par()->Next());
3012 // Skip through initial nonword stuff.
3013 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3014 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3016 // printf("Current pos1 %d", tmpcursor.pos()) ;
3017 tmpcursor.pos(tmpcursor.pos() + 1);
3020 // Advance through word.
3021 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3022 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3024 // printf("Current pos2 %d", tmpcursor.pos()) ;
3025 tmpcursor.pos(tmpcursor.pos() + 1);
3029 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3033 void LyXText::CursorTab(BufferView * bview) const
3036 if (cursor.par()->table) {
3037 int cell = NumberOfCell(cursor.par(), cursor.pos());
3038 while(cursor.par()->table->IsContRow(cell)) {
3040 cell = NumberOfCell(cursor.par(), cursor.pos());
3042 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3043 TableFeatures(bview, LyXTable::APPEND_ROW);
3046 LyXCursor tmpcursor = cursor;
3047 while (tmpcursor.pos() < tmpcursor.par()->Last()
3048 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3049 tmpcursor.pos(tmpcursor.pos() + 1);
3051 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3052 if (tmpcursor.par()->Next()) {
3053 tmpcursor.par(tmpcursor.par()->Next());
3057 tmpcursor.pos(tmpcursor.pos() + 1);
3058 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3060 if (cursor.par()->table) {
3061 int cell = NumberOfCell(cursor.par(), cursor.pos());
3062 while (cursor.par()->table->IsContRow(cell) &&
3063 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3065 while (tmpcursor.pos() < tmpcursor.par()->Last()
3066 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3067 tmpcursor.pos(tmpcursor.pos() + 1);
3069 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3070 if (tmpcursor.par()->Next()) {
3071 tmpcursor.par(tmpcursor.par()->Next());
3075 tmpcursor.pos(tmpcursor.pos() + 1);
3076 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3077 cell = NumberOfCell(cursor.par(), cursor.pos());
3084 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3085 of prior word, not to end of next prior word. */
3087 void LyXText::CursorLeftOneWord(BufferView * bview) const
3089 // treat HFills, floats and Insets as words
3090 LyXCursor tmpcursor = cursor;
3091 while (tmpcursor.pos()
3092 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3093 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3094 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3095 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3096 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3097 tmpcursor.pos(tmpcursor.pos() - 1);
3100 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3101 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3102 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3103 tmpcursor.pos(tmpcursor.pos() - 1);
3104 } else if (!tmpcursor.pos()) {
3105 if (tmpcursor.par()->Previous()){
3106 tmpcursor.par(tmpcursor.par()->Previous());
3107 tmpcursor.pos(tmpcursor.par()->Last());
3109 } else { // Here, tmpcursor != 0
3110 while (tmpcursor.pos() > 0 &&
3111 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3112 tmpcursor.pos(tmpcursor.pos() - 1);
3114 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3117 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3120 void LyXText::SelectWord(BufferView * bview)
3122 // Move cursor to the beginning, when not already there.
3124 && !cursor.par()->IsSeparator(cursor.pos()-1)
3125 && !cursor.par()->IsKomma(cursor.pos()-1) )
3126 CursorLeftOneWord(bview);
3128 // set the sel cursor
3129 sel_cursor = cursor;
3131 while ( cursor.pos() < cursor.par()->Last()
3132 && !cursor.par()->IsSeparator(cursor.pos())
3133 && !cursor.par()->IsKomma(cursor.pos()) )
3134 cursor.pos(cursor.pos() + 1);
3135 SetCursor(bview, cursor.par(), cursor.pos() );
3137 // finally set the selection
3142 /* -------> Select the word currently under the cursor when:
3143 1: no selection is currently set,
3144 2: the cursor is not at the borders of the word. */
3146 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3149 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3150 && !cursor.par()->IsSeparator(cursor.pos())
3151 && !cursor.par()->IsKomma(cursor.pos())
3152 && !cursor.par()->IsSeparator(cursor.pos() -1)
3153 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3161 // This function is only used by the spellchecker for NextWord().
3162 // It doesn't handle LYX_ACCENTs and probably never will.
3163 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3165 LyXParagraph * tmppar = cursor.par();
3167 // If this is not the very first word, skip rest of
3168 // current word because we are probably in the middle
3169 // of a word if there is text here.
3170 if (cursor.pos() || cursor.par()->previous) {
3171 while (cursor.pos() < cursor.par()->Last()
3172 && cursor.par()->IsLetter(cursor.pos()))
3173 cursor.pos(cursor.pos() + 1);
3175 // Now, skip until we have real text (will jump paragraphs)
3176 while ((cursor.par()->Last() > cursor.pos()
3177 && (!cursor.par()->IsLetter(cursor.pos())
3178 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3179 .latex() == LyXFont::ON))
3180 || (cursor.par()->Last() == cursor.pos()
3181 && cursor.par()->Next())){
3182 if (cursor.pos() == cursor.par()->Last()) {
3183 cursor.par(cursor.par()->Next());
3186 cursor.pos(cursor.pos() + 1);
3189 // Update the value if we changed paragraphs
3190 if (cursor.par() != tmppar){
3191 SetCursor(bview, cursor.par(), cursor.pos());
3192 value = float(cursor.y())/float(height);
3195 // Start the selection from here
3196 sel_cursor = cursor;
3199 std::ostringstream latex;
3203 // and find the end of the word
3204 // (optional hyphens are part of a word)
3205 while (cursor.pos() < cursor.par()->Last()
3206 && (cursor.par()->IsLetter(cursor.pos()))
3207 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3208 && cursor.par()->GetInset(cursor.pos()) != 0
3209 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3211 && latex.str() == "\\-"
3213 && latex.str() // protect against null pointers
3214 && string(latex.str(), 3) == "\\-" // this is not nice at all
3217 cursor.pos(cursor.pos() + 1);
3219 #ifndef HAVE_SSTREAM
3220 delete [] latex.str();
3222 // Finally, we copy the word to a string and return it
3225 if (sel_cursor.pos() < cursor.pos()) {
3226 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3227 LyXParagraph::size_type i, j;
3228 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3229 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3230 str[j++] = cursor.par()->GetChar(i);
3238 // This one is also only for the spellchecker
3239 void LyXText::SelectSelectedWord(BufferView * bview)
3241 // move cursor to the beginning
3242 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3244 // set the sel cursor
3245 sel_cursor = cursor;
3248 std::ostringstream latex;
3253 // now find the end of the word
3254 while (cursor.pos() < cursor.par()->Last()
3255 && (cursor.par()->IsLetter(cursor.pos())
3256 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3257 && cursor.par()->GetInset(cursor.pos()) != 0
3258 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3260 && latex.str() == "\\-"
3262 && string(latex.str(), 3) == "\\-"
3265 cursor.pos(cursor.pos() + 1);
3267 #ifndef HAVE_SSTREAM
3268 delete [] latex.str();
3270 SetCursor(bview, cursor.par(), cursor.pos());
3272 // finally set the selection
3277 /* -------> Delete from cursor up to the end of the current or next word. */
3278 void LyXText::DeleteWordForward(BufferView * bview)
3280 if (!cursor.par()->Last())
3283 LyXCursor tmpcursor = cursor;
3284 tmpcursor.row(0); //Â ??
3285 selection = true; // to avoid deletion
3286 CursorRightOneWord(bview);
3287 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3288 sel_cursor = cursor;
3292 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3293 CutSelection(bview);
3298 /* -------> Delete from cursor to start of current or prior word. */
3299 void LyXText::DeleteWordBackward(BufferView * bview)
3301 if (!cursor.par()->Last())
3304 LyXCursor tmpcursor = cursor;
3305 tmpcursor.row(0); // ??
3306 selection = true; // to avoid deletion
3307 CursorLeftOneWord(bview);
3308 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3309 sel_cursor = cursor;
3312 CutSelection(bview);
3317 /* -------> Kill to end of line. */
3318 void LyXText::DeleteLineForward(BufferView * bview)
3320 if (!cursor.par()->Last())
3321 // Paragraph is empty, so we just go to the right
3324 LyXCursor tmpcursor = cursor;
3325 // We can't store the row over a regular SetCursor
3326 // so we set it to 0 and reset it afterwards.
3327 tmpcursor.row(0); //Â ??
3328 selection = true; // to avoid deletion
3330 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3331 sel_cursor = cursor;
3334 // What is this test for ??? (JMarc)
3336 DeleteWordForward(bview);
3338 CutSelection(bview);
3344 // Change the case of a word at cursor position.
3345 // This function directly manipulates LyXParagraph::text because there
3346 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3347 // that it is correct. I guess part of it should be moved to
3348 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3349 // it does not access outside of the allocated array as the older
3350 // version did. (JMarc)
3351 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3353 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3355 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3357 LyXParagraph::size_type tmppos =
3358 cursor.par()->PositionInParFromPos(cursor.pos());
3359 while (tmppos < tmppar->size()) {
3360 unsigned char c = tmppar->GetChar(tmppos);
3361 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3363 if (c != LyXParagraph::META_INSET) {
3365 case text_lowercase:
3368 case text_capitalization:
3370 action = text_lowercase;
3372 case text_uppercase:
3378 //tmppar->text[tmppos] = c;
3379 tmppar->SetChar(tmppos, c);
3382 CheckParagraph(bview, tmppar, tmppos);
3383 CursorRightOneWord(bview);
3387 void LyXText::Delete(BufferView * bview)
3389 // this is a very easy implementation
3391 LyXCursor old_cursor = cursor;
3392 int old_cur_par_id = old_cursor.par()->id();
3393 int old_cur_par_prev_id = old_cursor.par()->previous ?
3394 old_cursor.par()->previous->id() : 0;
3396 // just move to the right
3397 CursorRightIntern(bview);
3399 // CHECK Look at the comment here.
3400 // This check is not very good...
3401 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3402 // and that can very well delete the par or par->previous in
3403 // old_cursor. Will a solution where we compare paragraph id's
3405 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3406 == old_cur_par_prev_id
3407 && cursor.par()->id() != old_cur_par_id)
3408 return; // delete-empty-paragraph-mechanism has done it
3410 // if you had success make a backspace
3411 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3412 LyXCursor tmpcursor = cursor;
3413 cursor = old_cursor; // to make sure undo gets the right cursor position
3414 SetUndo(bview->buffer(), Undo::DELETE,
3415 cursor.par()->ParFromPos(cursor.pos())->previous,
3416 cursor.par()->ParFromPos(cursor.pos())->next);
3423 void LyXText::Backspace(BufferView * bview)
3426 /* table stuff -- begin */
3427 if (cursor.par()->table) {
3428 BackspaceInTable(bview);
3431 /* table stuff -- end */
3433 // LyXFont rawtmpfont = current_font;
3434 // LyXFont realtmpfont = real_current_font;
3435 // We don't need the above variables as calling to SetCursor() with third
3436 // argument eqaul to false, will not change current_font & real_current_font
3438 // Get the font that is used to calculate the baselineskip
3439 LyXParagraph::size_type lastpos = cursor.par()->Last();
3440 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3443 if (cursor.pos() == 0) {
3444 // The cursor is at the beginning of a paragraph, so the the backspace
3445 // will collapse two paragraphs into one.
3447 // we may paste some paragraphs
3449 // is it an empty paragraph?
3452 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3453 && !(cursor.par()->Next()
3454 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3455 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3456 // This is an empty paragraph and we delete it just by moving the cursor one step
3457 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3458 // of the paragraph.
3460 if (cursor.par()->previous) {
3461 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3462 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3463 && cursor.par()->footnoteflag == tmppar->footnoteflag
3464 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3465 // Inherit botom DTD from the paragraph below.
3466 // (the one we are deleting)
3467 tmppar->line_bottom = cursor.par()->line_bottom;
3468 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3469 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3472 CursorLeftIntern(bview);
3474 // the layout things can change the height of a row !
3475 int tmpheight = cursor.row()->height();
3476 SetHeightOfRow(bview, cursor.row());
3477 if (cursor.row()->height() != tmpheight) {
3478 refresh_y = cursor.y() - cursor.row()->baseline();
3479 refresh_row = cursor.row();
3480 status = LyXText::NEED_MORE_REFRESH;
3486 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3487 SetUndo(bview->buffer(), Undo::DELETE,
3488 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3489 cursor.par()->ParFromPos(cursor.pos())->next);
3492 LyXParagraph * tmppar = cursor.par();
3493 Row * tmprow = cursor.row();
3495 // We used to do CursorLeftIntern() here, but it is
3496 // not a good idea since it triggers the auto-delete
3497 // mechanism. So we do a CursorLeftIntern()-lite,
3498 // without the dreaded mechanism. (JMarc)
3499 if (cursor.par()->Previous()) {
3500 // steps into the above paragraph.
3501 SetCursorIntern(bview, cursor.par()->Previous(),
3502 cursor.par()->Previous()->Last(), false);
3505 /* Pasting is not allowed, if the paragraphs have different
3506 layout. I think it is a real bug of all other
3507 word processors to allow it. It confuses the user.
3508 Even so with a footnote paragraph and a non-footnote
3509 paragraph. I will not allow pasting in this case,
3510 because the user would be confused if the footnote behaves
3511 different wether it is open or closed.
3513 Correction: Pasting is always allowed with standard-layout
3515 if (cursor.par() != tmppar
3516 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3517 || tmppar->GetLayout() == 0 /*standard*/)
3518 && cursor.par()->footnoteflag == tmppar->footnoteflag
3520 /* table stuff -- begin*/
3521 && !cursor.par()->table /* no pasting of tables */
3522 /* table stuff -- end*/
3524 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3526 RemoveParagraph(tmprow);
3528 cursor.par()->PasteParagraph(bview->buffer()->params);
3530 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3531 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3532 // strangely enough it seems that commenting out the line above removes
3533 // most or all of the segfaults. I will however also try to move the
3534 // two Remove... lines in front of the PasteParagraph too.
3537 cursor.pos(cursor.pos() - 1);
3539 status = LyXText::NEED_MORE_REFRESH;
3540 refresh_row = cursor.row();
3541 refresh_y = cursor.y() - cursor.row()->baseline();
3543 // remove the lost paragraph
3544 // This one is not safe, since the paragraph that the tmprow and the
3545 // following rows belong to has been deleted by the PasteParagraph
3546 // above. The question is... could this be moved in front of the
3548 //RemoveParagraph(tmprow);
3549 //RemoveRow(tmprow);
3551 // This rebuilds the rows.
3552 AppendParagraph(bview, cursor.row());
3553 UpdateCounters(bview, cursor.row());
3555 // the row may have changed, block, hfills etc.
3556 SetCursor(bview, cursor.par(), cursor.pos(), false);
3559 /* this is the code for a normal backspace, not pasting
3561 SetUndo(bview->buffer(), Undo::DELETE,
3562 cursor.par()->ParFromPos(cursor.pos())->previous,
3563 cursor.par()->ParFromPos(cursor.pos())->next);
3564 // We used to do CursorLeftIntern() here, but it is
3565 // not a good idea since it triggers the auto-delete
3566 // mechanism. So we do a CursorLeftIntern()-lite,
3567 // without the dreaded mechanism. (JMarc)
3568 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3569 false, cursor.boundary());
3571 // some insets are undeletable here
3572 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3573 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3575 // force complete redo when erasing display insets
3576 // this is a cruel method but safe..... Matthias
3577 if (cursor.par()->GetInset(cursor.pos())->display() ||
3578 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
3579 cursor.par()->Erase(cursor.pos());
3580 RedoParagraph(bview);
3585 Row * row = cursor.row();
3586 long y = cursor.y() - row->baseline();
3587 LyXParagraph::size_type z;
3588 /* remember that a space at the end of a row doesnt count
3589 * when calculating the fill */
3590 if (cursor.pos() < RowLast(row) ||
3591 !cursor.par()->IsLineSeparator(cursor.pos())) {
3592 row->fill(row->fill() + SingleWidth(bview,
3597 /* some special code when deleting a newline. This is similar
3598 * to the behavior when pasting paragraphs */
3599 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3600 cursor.par()->Erase(cursor.pos());
3601 // refresh the positions
3603 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3604 tmprow = tmprow->next();
3605 tmprow->pos(tmprow->pos() - 1);
3607 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3608 cursor.pos(cursor.pos() - 1);
3610 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3611 cursor.par()->InsertChar(cursor.pos(), ' ');
3612 // refresh the positions
3614 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3615 tmprow = tmprow->next();
3616 tmprow->pos(tmprow->pos() + 1);
3620 cursor.par()->Erase(cursor.pos());
3622 // refresh the positions
3624 while (tmprow->next()
3625 && tmprow->next()->par() == row->par()) {
3626 tmprow = tmprow->next();
3627 tmprow->pos(tmprow->pos() - 1);
3630 // delete newlines at the beginning of paragraphs
3631 while (cursor.par()->Last() &&
3632 cursor.par()->IsNewline(cursor.pos()) &&
3633 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3635 cursor.par()->Erase(cursor.pos());
3636 // refresh the positions
3638 while (tmprow->next() &&
3639 tmprow->next()->par() == row->par()) {
3640 tmprow = tmprow->next();
3641 tmprow->pos(tmprow->pos() - 1);
3646 // is there a break one row above
3647 if (row->previous() && row->previous()->par() == row->par()) {
3648 z = NextBreakPoint(bview, row->previous(),
3650 if ( z >= row->pos()) {
3653 Row * tmprow = row->previous();
3655 // maybe the current row is now empty
3656 if (row->pos() >= row->par()->Last()) {
3661 BreakAgainOneRow(bview, row);
3662 if (row->next() && row->next()->par() == row->par())
3663 need_break_row = row->next();
3668 // set the dimensions of the row above
3669 y -= tmprow->height();
3670 tmprow->fill(Fill(bview, tmprow,
3672 SetHeightOfRow(bview, tmprow);
3675 refresh_row = tmprow;
3676 status = LyXText::NEED_MORE_REFRESH;
3677 SetCursor(bview, cursor.par(), cursor.pos(),
3678 false, cursor.boundary());
3679 //current_font = rawtmpfont;
3680 //real_current_font = realtmpfont;
3681 // check, whether the last character's font has changed.
3683 cursor.par()->GetFontSettings(bview->buffer()->params,
3684 cursor.par()->Last() - 1))
3685 RedoHeightOfParagraph(bview, cursor);
3690 // break the cursor row again
3691 z = NextBreakPoint(bview, row, workWidth(bview));
3693 if (z != RowLast(row) ||
3694 (row->next() && row->next()->par() == row->par() &&
3695 RowLast(row) == row->par()->Last() - 1)){
3697 /* it can happen that a paragraph loses one row
3698 * without a real breakup. This is when a word
3699 * is to long to be broken. Well, I don t care this
3701 if (row->next() && row->next()->par() == row->par() &&
3702 RowLast(row) == row->par()->Last() - 1)
3703 RemoveRow(row->next());
3707 status = LyXText::NEED_MORE_REFRESH;
3709 BreakAgainOneRow(bview, row);
3710 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3711 // cursor MUST be in row now
3713 if (row->next() && row->next()->par() == row->par())
3714 need_break_row = row->next();
3718 // set the dimensions of the row
3719 row->fill(Fill(bview, row, workWidth(bview)));
3720 int tmpheight = row->height();
3721 SetHeightOfRow(bview, row);
3722 if (tmpheight == row->height())
3723 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3725 status = LyXText::NEED_MORE_REFRESH;
3728 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3732 // current_font = rawtmpfont;
3733 // real_current_font = realtmpfont;
3735 lastpos = cursor.par()->Last();
3736 if (cursor.pos() == lastpos) {
3737 SetCurrentFont(bview);
3738 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3739 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3742 // check, wether the last characters font has changed.
3744 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3745 RedoHeightOfParagraph(bview, cursor);
3747 // now the special right address boxes
3748 if (textclasslist.Style(bview->buffer()->params.textclass,
3749 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3750 RedoDrawingOfParagraph(bview, cursor);
3756 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3757 Row * row_ptr, long y, bool cleared)
3759 /* returns a printed row */
3760 Painter & pain = bview->painter();
3762 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3763 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3765 LyXParagraph::size_type vpos, pos;
3767 int y_top, y_bottom;
3768 float fill_separator, fill_hfill, fill_label_hfill;
3770 LyXFont font(LyXFont::ALL_SANE);
3772 if (row_ptr->height() <= 0) {
3773 lyxerr << "LYX_ERROR: row.height: "
3774 << row_ptr->height() << endl;
3777 PrepareToPrint(bview, row_ptr, x, fill_separator,
3778 fill_hfill, fill_label_hfill);
3780 if (inset_owner && (x < 0))
3784 // clear the area where we want to paint/print
3786 ww = bview->workWidth();
3788 bool clear_area = true;
3791 if ((last == row_ptr->pos()) &&
3792 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3793 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3795 clear_area = inset->doClearArea();
3797 if (cleared) { // we don't need to clear it's already done!!!
3799 } else if (clear_area) {
3802 w = inset_owner->width(bview, font);
3805 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3806 } else if (inset != 0) {
3807 int h = row_ptr->baseline() - inset->ascent(bview, font);
3811 w = inset_owner->width(bview, font);
3814 pain.fillRectangle(x_offset, y_offset, w, h);
3819 /* selection code */
3820 if (bidi_same_direction) {
3821 if (sel_start_cursor.row() == row_ptr &&
3822 sel_end_cursor.row() == row_ptr) {
3823 if (sel_start_cursor.x() < sel_end_cursor.x())
3824 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3826 sel_end_cursor.x() - sel_start_cursor.x(),
3830 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3832 sel_start_cursor.x() - sel_end_cursor.x(),
3835 } else if (sel_start_cursor.row() == row_ptr) {
3837 pain.fillRectangle(x_offset, y_offset,
3838 sel_start_cursor.x(),
3842 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3844 ww - sel_start_cursor.x(),
3847 } else if (sel_end_cursor.row() == row_ptr) {
3849 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3851 ww - sel_end_cursor.x(),
3855 pain.fillRectangle(x_offset, y_offset,
3859 } else if (y > long(sel_start_cursor.y())
3860 && y < long(sel_end_cursor.y())) {
3861 pain.fillRectangle(x_offset, y_offset, ww,
3865 } else if ( sel_start_cursor.row() != row_ptr &&
3866 sel_end_cursor.row() != row_ptr &&
3867 y > long(sel_start_cursor.y())
3868 && y < long(sel_end_cursor.y())) {
3869 pain.fillRectangle(x_offset, y_offset, ww,
3872 } else if (sel_start_cursor.row() == row_ptr ||
3873 sel_end_cursor.row() == row_ptr) {
3877 if (row_ptr->par()->table) {
3878 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3879 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3882 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3883 (sel_end_cursor.row() != row_ptr && is_rtl))
3884 pain.fillRectangle(x_offset, y_offset,
3889 if (row_ptr->par()->table) {
3891 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3892 pos = vis2log(vpos);
3893 float old_tmpx = tmpx;
3894 if (row_ptr->par()->IsNewline(pos)) {
3895 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3898 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3900 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3902 if ( (sel_start_cursor.row() != row_ptr ||
3903 sel_start_cursor.pos() <= pos) &&
3904 (sel_end_cursor.row() != row_ptr ||
3905 pos < sel_end_cursor.pos()) )
3906 pain.fillRectangle(x_offset + int(old_tmpx),
3908 int(tmpx - old_tmpx + 1),
3914 LyXParagraph::size_type main_body =
3915 BeginningOfMainBody(bview->buffer(),
3918 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3919 pos = vis2log(vpos);
3920 float old_tmpx = tmpx;
3921 if (main_body > 0 && pos == main_body-1) {
3922 tmpx += fill_label_hfill +
3923 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3924 row_ptr->par()->GetLayout()).labelsep,
3925 GetFont(bview->buffer(),row_ptr->par(), -2));
3926 if (row_ptr->par()->IsLineSeparator(main_body-1))
3927 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3929 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3930 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3931 if (pos >= main_body)
3934 tmpx += fill_label_hfill;
3936 else if (row_ptr->par()->IsSeparator(pos)) {
3937 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3938 if (pos >= main_body)
3939 tmpx += fill_separator;
3941 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3943 if ( (sel_start_cursor.row() != row_ptr ||
3944 sel_start_cursor.pos() <= pos) &&
3945 (sel_end_cursor.row() != row_ptr ||
3946 pos < sel_end_cursor.pos()) )
3947 pain.fillRectangle(x_offset + int(old_tmpx),
3949 int(tmpx - old_tmpx + 1),
3956 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3957 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3958 pain.fillRectangle(x_offset + int(tmpx),
3968 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3969 LyXFont font(LyXFont::ALL_SANE);
3970 font.setSize(LyXFont::SIZE_FOOTNOTE);
3971 font.setColor(LColor::footnote);
3973 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3974 if (row_ptr->previous() &&
3975 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3977 switch (row_ptr->par()->footnotekind) {
3978 case LyXParagraph::MARGIN:
3981 case LyXParagraph::FIG:
3984 case LyXParagraph::TAB:
3987 case LyXParagraph::WIDE_FIG:
3990 case LyXParagraph::WIDE_TAB:
3993 case LyXParagraph::ALGORITHM:
3996 case LyXParagraph::FOOTNOTE:
4001 pain.fillRectangle(LYX_PAPER_MARGIN,
4003 box_x - LYX_PAPER_MARGIN,
4004 int(lyxfont::maxAscent(font)
4005 + lyxfont::maxDescent(font)),
4006 LColor::footnotebg);
4008 pain.line(LYX_PAPER_MARGIN, y_offset,
4009 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4010 LColor::footnoteframe);
4012 pain.text(LYX_PAPER_MARGIN,
4013 y_offset + int(lyxfont::maxAscent(font)) + 1,
4016 pain.line(LYX_PAPER_MARGIN, y_offset,
4018 y_offset + int(lyxfont::maxAscent(font)
4019 + lyxfont::maxDescent(font)),
4020 LColor::footnoteframe);
4022 pain.line(LYX_PAPER_MARGIN,
4023 y_offset + int(lyxfont::maxAscent(font)
4024 + lyxfont::maxDescent(font)) + 1,
4026 y_offset + int(lyxfont::maxAscent(font)
4027 + lyxfont::maxDescent(font)) + 1,
4028 LColor::footnoteframe);
4032 /* draw the open floats in a red box */
4033 pain.line(box_x, y_offset,
4034 box_x, y_offset + row_ptr->height(),
4035 LColor::footnoteframe);
4037 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4039 workWidth(bview) - LYX_PAPER_MARGIN,
4040 y_offset + row_ptr->height(),
4041 LColor::footnoteframe);
4044 // Draw appendix lines
4045 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4047 pain.line(1, y_offset,
4048 1, y_offset + row_ptr->height(),
4049 LColor::appendixline);
4050 pain.line(workWidth(bview) - 2, y_offset,
4051 workWidth(bview) - 2,
4052 y_offset + row_ptr->height(),
4053 LColor::appendixline);
4056 // Draw minipage line
4057 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4059 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4061 y_offset + row_ptr->height() - 1,
4062 LColor::minipageline);
4065 int depth = p->GetDepth();
4066 for (int i = 1; i <= depth; ++i) {
4067 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4068 pain.line(line_x, y_offset, line_x,
4069 y_offset + row_ptr->height() - 1,
4072 } else if (row_ptr->previous() &&
4073 row_ptr->previous()->par()->footnoteflag
4074 == LyXParagraph::OPEN_FOOTNOTE) {
4075 LyXFont font(LyXFont::ALL_SANE);
4076 font.setSize(LyXFont::SIZE_FOOTNOTE);
4078 int box_x = LYX_PAPER_MARGIN;
4079 box_x += lyxfont::width(" wide-tab ", font);
4081 pain.line(box_x, y_offset,
4082 workWidth(bview) - LYX_PAPER_MARGIN,
4083 y_offset, LColor::footnote);
4086 // Draw appendix lines
4087 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4088 if (firstpar->appendix){
4089 pain.line(1, y_offset,
4090 1, y_offset + row_ptr->height(),
4091 LColor::appendixline);
4092 pain.line(ww - 2, y_offset,
4093 ww - 2, y_offset + row_ptr->height(),
4094 LColor::appendixline);
4097 // Draw minipage line
4098 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4100 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4101 LYX_PAPER_MARGIN/5 + box_x,
4102 y_offset + row_ptr->height() - 1,
4103 LColor::minipageline);
4106 int depth = firstpar->GetDepth();
4110 if (row_ptr->next())
4111 if (row_ptr->par()->footnoteflag ==
4112 row_ptr->next()->par()->footnoteflag)
4113 next_depth = row_ptr->next()->par()->GetDepth();
4114 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4117 if (row_ptr->previous())
4118 if (row_ptr->par()->footnoteflag ==
4119 row_ptr->previous()->par()->footnoteflag)
4120 prev_depth = row_ptr->previous()->par()->GetDepth();
4121 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4124 for (int i = 1; i <= depth; ++i) {
4125 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4126 pain.line(line_x, y_offset, line_x,
4127 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4131 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4134 pain.fillRectangle(line_x,
4135 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4136 LYX_PAPER_MARGIN / 5, 2,
4142 LyXLayout const & layout =
4143 textclasslist.Style(bview->buffer()->params.textclass,
4144 row_ptr->par()->GetLayout());
4147 y_bottom = row_ptr->height();
4149 /* is it a first row? */
4150 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4152 /* start of appendix? */
4153 if (row_ptr->par()->start_of_appendix){
4154 pain.line(1, y_offset,
4156 LColor::appendixline);
4159 /* think about the margins */
4160 if (!row_ptr->previous() && bv_owner)
4161 y_top += LYX_PAPER_MARGIN;
4163 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4165 pb_font.setColor(LColor::pagebreak).decSize();
4166 int w = 0, a = 0, d = 0;
4167 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4169 y_offset + y_top + 2 * DefaultHeight(),
4171 Painter::line_onoffdash)
4174 _("Page Break (top)"),
4177 LColor::background, false, w, a, d);
4178 pain.rectText((ww - w)/2,
4179 y_offset + y_top + 2 * DefaultHeight() + d,
4180 _("Page Break (top)"),
4183 LColor::background);
4184 y_top += 3 * DefaultHeight();
4187 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4188 /* draw a vfill top */
4189 pain.line(0, y_offset + 2 + y_top,
4190 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4193 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4195 y_offset + y_top + 3 * DefaultHeight(),
4198 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4199 LYX_PAPER_MARGIN / 2,
4200 y_offset + y_top + 3 * DefaultHeight(),
4203 y_top += 3 * DefaultHeight();
4206 /* think about user added space */
4207 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4209 /* think about the parskip */
4210 /* some parskips VERY EASY IMPLEMENTATION */
4211 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4212 if (layout.latextype == LATEX_PARAGRAPH
4213 && firstpar->GetDepth() == 0
4214 && firstpar->Previous())
4215 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4216 else if (firstpar->Previous()
4217 && textclasslist.Style(bview->buffer()->params.textclass,
4218 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4219 && firstpar->Previous()->GetDepth() == 0)
4220 // is it right to use defskip here, too? (AS)
4221 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4224 if (row_ptr->par()->line_top) { /* draw a top line */
4225 y_top += lyxfont::ascent('x',
4226 GetFont(bview->buffer(),
4227 row_ptr->par(), 0));
4229 pain.line(0, y_offset + y_top,
4230 ww, y_offset + y_top,
4232 Painter::line_solid,
4233 Painter::line_thick);
4235 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4236 row_ptr->par(), 0));
4239 /* should we print a label? */
4240 if (layout.labeltype >= LABEL_STATIC
4241 && (layout.labeltype != LABEL_STATIC
4242 || layout.latextype != LATEX_ENVIRONMENT
4243 || row_ptr->par()->IsFirstInSequence())) {
4244 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4245 if (!row_ptr->par()->GetLabelstring().empty()) {
4247 string tmpstring = row_ptr->par()->GetLabelstring();
4249 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4250 if (bview->buffer()->params.secnumdepth >= 0) {
4251 /* this is special code for the chapter layout. This is printed in
4252 * an extra row and has a pagebreak at the top. */
4253 float spacing_val = 1.0;
4254 if (!row_ptr->par()->spacing.isDefault()) {
4255 spacing_val = row_ptr->par()->spacing.getValue();
4257 spacing_val = bview->buffer()->params.spacing.getValue();
4260 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4261 + int(layout.parsep) * DefaultHeight();
4263 tmpx = ww - LeftMargin(bview, row_ptr) -
4264 lyxfont::width(tmpstring, font);
4265 pain.text(int(tmpx),
4266 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4271 tmpx = ww - LeftMargin(bview, row_ptr)
4272 + lyxfont::width(layout.labelsep, font);
4273 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4274 LyXFont font(LyXFont::ALL_SANE);
4275 font.setSize(LyXFont::SIZE_SMALL);
4276 tmpx += lyxfont::width("Mwide-fixM", font);
4279 tmpx = x - lyxfont::width(layout.labelsep, font)
4280 - lyxfont::width(tmpstring, font);
4283 pain.text(int(tmpx),
4284 y_offset + row_ptr->baseline(),
4288 /* the labels at the top of an environment. More or less for bibliography */
4289 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4290 layout.labeltype == LABEL_BIBLIO ||
4291 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4292 if (row_ptr->par()->IsFirstInSequence()) {
4293 font = GetFont(bview->buffer(),
4294 row_ptr->par(), -2);
4295 if (!row_ptr->par()->GetLabelstring().empty()) {
4296 string tmpstring = row_ptr->par()->GetLabelstring();
4297 float spacing_val = 1.0;
4298 if (!row_ptr->par()->spacing.isDefault()) {
4299 spacing_val = row_ptr->par()->spacing.getValue();
4301 spacing_val = bview->buffer()->params.spacing.getValue();
4304 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4305 + (layout.labelbottomsep * DefaultHeight()));
4308 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4309 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4310 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4311 tmpx -= lyxfont::width(tmpstring, font) / 2;
4313 tmpx = ww - LeftMargin(bview, row_ptr) -
4314 lyxfont::width(tmpstring, font);
4315 pain.text(int(tmpx),
4316 y_offset + row_ptr->baseline()
4317 - row_ptr->ascent_of_text()
4323 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4324 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4326 tmpx = ww - LeftMargin(bview, row_ptr)
4327 + lyxfont::width(layout.labelsep, font);
4329 tmpx = x - lyxfont::width(layout.labelsep, font)
4330 - row_ptr->par()->bibkey->width(bview, font);
4331 row_ptr->par()->bibkey->draw(bview, font,
4332 y_offset + row_ptr->baseline(),
4337 /* is it a last row? */
4338 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4339 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4340 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4342 /* think about the margins */
4343 if (!row_ptr->next() && bv_owner)
4344 y_bottom -= LYX_PAPER_MARGIN;
4346 /* draw a bottom pagebreak */
4347 if (firstpar->pagebreak_bottom) {
4349 pb_font.setColor(LColor::pagebreak).decSize();
4350 int w = 0, a = 0, d = 0;
4352 y_offset + y_bottom - 2 * DefaultHeight(),
4354 y_offset + y_bottom - 2 * DefaultHeight(),
4356 Painter::line_onoffdash)
4359 _("Page Break (bottom)"),
4362 LColor::background, false, w, a, d);
4363 pain.rectText((ww - w) / 2,
4364 y_offset + y_top + 2 * DefaultHeight() + d,
4365 _("Page Break (bottom)"),
4368 LColor::background);
4369 y_bottom -= 3 * DefaultHeight();
4372 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4373 /* draw a vfill bottom */
4374 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4376 y_offset + y_bottom - 3 * DefaultHeight(),
4378 pain.line(0, y_offset + y_bottom - 2,
4380 y_offset + y_bottom - 2,
4382 pain.line(LYX_PAPER_MARGIN / 2,
4383 y_offset + y_bottom - 3 * DefaultHeight(),
4384 LYX_PAPER_MARGIN / 2,
4385 y_offset + y_bottom - 2,
4387 y_bottom -= 3 * DefaultHeight();
4390 /* think about user added space */
4391 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4393 if (firstpar->line_bottom) {
4394 /* draw a bottom line */
4395 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4396 par, par->Last() - 1));
4397 pain.line(0, y_offset + y_bottom,
4398 ww, y_offset + y_bottom,
4399 LColor::topline, Painter::line_solid,
4400 Painter::line_thick);
4401 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4402 par, par->Last() - 1));
4406 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4409 case END_LABEL_FILLED_BOX:
4411 LyXFont font = GetFont(bview->buffer(),
4412 row_ptr->par(), last);
4413 int size = int(0.75 * lyxfont::maxAscent(font));
4414 int y = (y_offset + row_ptr->baseline()) - size;
4415 int x = is_rtl ? LYX_PAPER_MARGIN
4416 : ww - LYX_PAPER_MARGIN - size;
4417 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4419 LyXFont font(LyXFont::ALL_SANE);
4420 font.setSize(LyXFont::SIZE_SMALL);
4421 x += lyxfont::width("Mwide-figM", font);
4423 x -= LYX_PAPER_MARGIN/2;
4424 if (row_ptr->fill() <= size)
4425 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4426 if (endlabel == END_LABEL_BOX) {
4427 pain.line(x, y, x, y + size,
4429 pain.line(x + size, y, x + size , y + size,
4431 pain.line(x, y, x + size, y,
4433 pain.line(x, y + size, x + size, y + size,
4436 pain.fillRectangle(x, y, size, size,
4440 case END_LABEL_STATIC:
4442 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4443 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4444 layout).endlabelstring();
4445 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4446 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4447 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4448 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4451 case END_LABEL_NO_LABEL:
4456 /* draw the text in the pixmap */
4458 vpos = row_ptr->pos();
4460 /* table stuff -- begin*/
4461 if (row_ptr->par()->table) {
4463 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4465 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4467 while (vpos <= last) {
4468 pos = vis2log(vpos);
4469 if (row_ptr->par()->IsNewline(pos)) {
4471 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4472 /* draw the table lines, still very simple */
4473 on_off = !row_ptr->par()->table->TopLine(cell);
4475 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4476 !row_ptr->par()->table->IsContRow(cell))
4477 pain.line(int(x_old),
4478 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4480 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4482 on_off ? Painter::line_onoffdash : Painter::line_solid);
4484 on_off = !row_ptr->par()->table->BottomLine(cell);
4485 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4486 row_ptr->par()->table->VeryLastRow(cell))
4488 pain.line(int(x_old),
4489 y_offset + y_bottom - 1,
4491 y_offset + y_bottom - 1,
4493 on_off ? Painter::line_onoffdash : Painter::line_solid);
4495 on_off = !row_ptr->par()->table->LeftLine(cell);
4497 pain.line(int(x_old),
4498 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4500 y_offset + y_bottom - 1,
4502 on_off ? Painter::line_onoffdash : Painter::line_solid);
4504 on_off = !row_ptr->par()->table->RightLine(cell);
4506 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4507 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4508 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4509 y_offset + y_bottom - 1,
4511 on_off ? Painter::line_onoffdash : Painter::line_solid);
4514 /* take care about the alignment and other spaces */
4516 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4517 if (row_ptr->par()->table->IsFirstCell(cell))
4518 --cell; // little hack, sorry
4520 } else if (row_ptr->par()->IsHfill(pos)) {
4524 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4526 y_offset + row_ptr->baseline(),
4531 } else if (row_ptr->par()->IsSeparator(pos)) {
4533 x+= SingleWidth(bview,
4534 row_ptr->par(), pos);
4537 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4540 /* do not forget the very last cell. This has no NEWLINE so
4541 * ignored by the code above*/
4542 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4543 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4544 on_off = !row_ptr->par()->table->TopLine(cell);
4546 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4547 !row_ptr->par()->table->IsContRow(cell))
4549 pain.line(int(x_old),
4550 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4552 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4554 on_off ? Painter::line_onoffdash : Painter::line_solid);
4555 on_off = !row_ptr->par()->table->BottomLine(cell);
4556 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4557 row_ptr->par()->table->VeryLastRow(cell))
4559 pain.line(int(x_old),
4560 y_offset + y_bottom - 1,
4562 y_offset + y_bottom - 1,
4564 on_off ? Painter::line_onoffdash : Painter::line_solid);
4566 on_off = !row_ptr->par()->table->LeftLine(cell);
4568 pain.line(int(x_old),
4569 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4571 y_offset + y_bottom - 1,
4573 on_off ? Painter::line_onoffdash : Painter::line_solid);
4575 on_off = !row_ptr->par()->table->RightLine(cell);
4577 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4578 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4579 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4580 y_offset + y_bottom - 1,
4582 on_off ? Painter::line_onoffdash : Painter::line_solid);
4585 /* table stuff -- end*/
4587 LyXParagraph::size_type main_body =
4588 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4589 if (main_body > 0 &&
4590 (main_body-1 > last ||
4591 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4594 while (vpos <= last) {
4595 pos = vis2log(vpos);
4596 if (main_body > 0 && pos == main_body - 1) {
4597 x += fill_label_hfill
4598 + lyxfont::width(layout.labelsep,
4599 GetFont(bview->buffer(),
4600 row_ptr->par(), -2))
4601 - SingleWidth(bview,
4606 if (row_ptr->par() ->IsHfill(pos)) {
4609 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4611 y_offset + row_ptr->baseline(),
4614 if (HfillExpansion(bview->buffer(),
4616 if (pos >= main_body) {
4618 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4619 int(x + fill_hfill),
4620 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4622 Painter::line_onoffdash);
4626 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4627 int(x + fill_label_hfill),
4628 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4630 Painter::line_onoffdash);
4632 x += fill_label_hfill;
4635 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4637 y_offset + row_ptr->baseline(),
4642 } else if (row_ptr->par()->IsSeparator(pos)) {
4643 x += SingleWidth(bview,
4644 row_ptr->par(), pos);
4645 if (pos >= main_body)
4646 x += fill_separator;
4649 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4657 int LyXText::DefaultHeight() const
4659 LyXFont font(LyXFont::ALL_SANE);
4660 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4664 /* returns the column near the specified x-coordinate of the row
4665 * x is set to the real beginning of this column */
4666 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4667 bool & boundary) const
4670 float fill_separator, fill_hfill, fill_label_hfill;
4672 PrepareToPrint(bview, row, tmpx, fill_separator,
4673 fill_hfill, fill_label_hfill);
4675 LyXParagraph::size_type vc = row->pos();
4676 LyXParagraph::size_type last = RowLastPrintable(row);
4677 LyXParagraph::size_type c = 0;
4678 LyXLayout const & layout =
4679 textclasslist.Style(bview->buffer()->params.textclass,
4680 row->par()->GetLayout());
4681 bool left_side = false;
4684 /* table stuff -- begin */
4685 if (row->par()->table) {
4686 //the last row doesn't need a newline at the end
4687 if (row->next() && row->next()->par() == row->par()
4688 && row->par()->IsNewline(last))
4690 int cell = NumberOfCell(row->par(), row->pos());
4691 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4692 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4693 float last_tmpx = tmpx;
4694 while (vc <= last && tmpx <= x) {
4697 if (row->par()->IsNewline(c)) {
4700 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4701 cell_x += row->par()->table->WidthOfColumn(cell);
4706 tmpx += SingleWidth(bview, row->par(), c);
4710 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4711 (tmpx + last_tmpx) / 2 > x) {
4716 /* table stuff -- end*/
4718 LyXParagraph::size_type
4719 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4720 float last_tmpx = tmpx;
4722 if (main_body > 0 &&
4723 (main_body-1 > last ||
4724 !row->par()->IsLineSeparator(main_body - 1)))
4727 while (vc <= last && tmpx <= x) {
4730 if (main_body > 0 && c == main_body-1) {
4731 tmpx += fill_label_hfill +
4732 lyxfont::width(layout.labelsep,
4733 GetFont(bview->buffer(), row->par(), -2));
4734 if (row->par()->IsLineSeparator(main_body - 1))
4735 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4738 if (HfillExpansion(bview->buffer(), row, c)) {
4739 x += SingleWidth(bview, row->par(), c);
4743 tmpx += fill_label_hfill;
4745 else if (row->par()->IsSeparator(c)) {
4746 tmpx += SingleWidth(bview, row->par(), c);
4748 tmpx+= fill_separator;
4750 tmpx += SingleWidth(bview, row->par(), c);
4754 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4763 if (vc > last + 1) // This shouldn't happen.
4768 if (row->pos() > last) // Row is empty?
4770 else if (vc == row->pos() ||
4772 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4774 if (bidi_level(c) % 2 == 1)
4777 c = vis2log(vc - 1);
4778 bool rtl = (bidi_level(c) % 2 == 1);
4779 if (left_side == rtl) {
4781 boundary = IsBoundary(bview->buffer(), row->par(), c);
4785 if (!row->par()->table && row->pos() <= last && c > last
4786 && row->par()->IsNewline(last)) {
4787 if (bidi_level(last) % 2 == 0)
4788 tmpx -= SingleWidth(bview, row->par(), last);
4790 tmpx += SingleWidth(bview, row->par(), last);
4801 /* turn the selection into a new environment. If there is no selection,
4802 * create an empty environment */
4803 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4804 LyXParagraph::footnote_kind kind)
4806 /* no footnoteenvironment in a footnoteenvironment */
4807 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4808 WriteAlert(_("Impossible operation"),
4809 _("You can't insert a float in a float!"),
4813 /* no marginpars in minipages */
4814 if (kind == LyXParagraph::MARGIN
4815 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4816 WriteAlert(_("Impossible operation"),
4817 _("You can't insert a marginpar in a minipage!"),
4822 /* this doesnt make sense, if there is no selection */
4823 bool dummy_selection = false;
4825 sel_start_cursor = cursor; /* dummy selection */
4826 sel_end_cursor = cursor;
4827 dummy_selection = true;
4830 LyXParagraph * tmppar;
4833 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4834 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4838 /* a test to make sure there is not already a footnote
4839 * in the selection. */
4841 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4843 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4844 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4845 tmppar = tmppar->next;
4847 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4848 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4849 WriteAlert(_("Impossible operation"),
4850 _("Float would include float!"),
4855 /* ok we have a selection. This is always between sel_start_cursor
4856 * and sel_end cursor */
4858 SetUndo(bview->buffer(), Undo::FINISH,
4859 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4860 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4862 if (sel_end_cursor.pos() > 0
4863 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4864 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4865 /* please break before a space at the end */
4866 if (sel_start_cursor.par() == sel_end_cursor.par()
4867 && sel_start_cursor.pos() > sel_end_cursor.pos())
4868 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4870 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4872 sel_end_cursor.par(sel_end_cursor.par()->Next());
4873 sel_end_cursor.pos(0);
4875 // don't forget to insert a dummy layout paragraph if necessary
4876 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4877 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4878 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4879 sel_end_cursor.par(sel_end_cursor.par()->next);
4882 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4884 cursor = sel_end_cursor;
4886 /* please break behind a space, if there is one. The space should
4888 if (sel_start_cursor.pos() > 0
4889 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4890 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4891 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4892 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4895 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4896 sel_start_cursor.pos());
4897 tmppar = sel_start_cursor.par()->Next();
4899 if (dummy_selection) {
4901 if (kind == LyXParagraph::TAB
4902 || kind == LyXParagraph::FIG
4903 || kind == LyXParagraph::WIDE_TAB
4904 || kind == LyXParagraph::WIDE_FIG
4905 || kind == LyXParagraph::ALGORITHM) {
4906 pair<bool, LyXTextClass::size_type> lres =
4907 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4909 LyXTextClass::size_type lay;
4915 lay = 0; // use default layout "Standard" (0)
4917 tmppar->SetLayout(bview->buffer()->params, lay);
4920 if (sel_start_cursor.pos() > 0) {
4921 /* the footnote-environment should begin with a standard layout.
4922 * Imagine you insert a footnote within an enumeration, you
4923 * certainly do not want an enumerated footnote! */
4926 /* this is a exception the user would sometimes expect, I hope */
4927 sel_start_cursor.par()->Clear();
4931 while (tmppar != sel_end_cursor.par()) {
4932 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4933 tmppar->footnotekind = kind;
4934 tmppar = tmppar->Next();
4937 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4939 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4946 // returns pointer to a specified row
4947 Row * LyXText::GetRow(LyXParagraph * par,
4948 LyXParagraph::size_type pos, long & y) const
4950 Row * tmprow = firstrow;
4953 // find the first row of the specified paragraph
4954 while (tmprow->next() && tmprow->par() != par) {
4955 y += tmprow->height();
4956 tmprow = tmprow->next();
4959 // now find the wanted row
4960 while (tmprow->pos() < pos
4962 && tmprow->next()->par() == par
4963 && tmprow->next()->pos() <= pos) {
4964 y += tmprow->height();
4965 tmprow = tmprow->next();