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(Painter &, 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->painter(), 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,
510 if (lyxrc.mark_foreign_language &&
511 font.language() != bview->buffer()->params.language_info) {
512 int y = offset + row->height() - 1;
513 pain.line(int(tmpx), y, int(x), y,
520 /* usual characters, no insets */
522 // Collect character that we can draw in one command
524 // This is dirty, but fast. Notice that it will never be too small.
525 // For the record, I'll note that Microsoft Word has a limit
526 // of 768 here. We have none :-) (Asger)
527 // Ok. I am the first to admit that the use of std::string will be
528 // a tiny bit slower than using a POD char array. However, I claim
529 // that this slowdown is so small that it is close to inperceptive.
530 // So IMHO we should go with the easier and clearer implementation.
531 // And even if 1024 is a large number here it might overflow, string
532 // will only overflow if the machine is out of memory...
533 static string textstring;
537 LyXParagraph::size_type last = RowLastPrintable(row);
539 if (font.language()->lang() == "hebrew") {
540 if (Encoding::IsComposeChar_hebrew(c)) {
541 int width = lyxfont::width(c, font2);
543 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
544 c = row->par()->GetChar(i);
545 if (!Encoding::IsComposeChar_hebrew(c)) {
546 if (IsPrintableNonspace(c)) {
547 int width2 = SingleWidth(bview, row->par(), i, c);
548 dx = (c == 'ø' || c == 'ã') // dalet / resh
549 ? width2 - width : (width2 - width) / 2;
555 pain.text(int(x) + dx, offset + row->baseline(),
558 while (vpos <= last &&
559 (pos = vis2log(vpos)) >= 0
560 && IsPrintableNonspace(c = row->par()->GetChar(pos))
561 && !Encoding::IsComposeChar_hebrew(c)
562 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
566 // Draw text and set the new x position
567 pain.text(int(x), offset + row->baseline(),
569 x += lyxfont::width(textstring, font);
571 } else if (font.language()->lang() == "arabic" &&
572 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
573 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
574 if (Encoding::IsComposeChar_arabic(c)) {
575 c = TransformChar(c, row->par(), pos);
577 int width = lyxfont::width(c, font2);
579 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
580 c = row->par()->GetChar(i);
581 if (!Encoding::IsComposeChar_arabic(c)) {
582 if (IsPrintableNonspace(c)) {
583 int width2 = SingleWidth(bview, row->par(), i, c);
584 dx = (width2 - width) / 2;
590 pain.text(int(x) + dx, offset + row->baseline(),
593 textstring = TransformChar(c, row->par(), pos);
594 while (vpos <= last &&
595 (pos = vis2log(vpos)) >= 0
596 && IsPrintableNonspace(c = row->par()->GetChar(pos))
597 && !Encoding::IsComposeChar_arabic(c)
598 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
599 c = TransformChar(c, row->par(), pos);
603 // Draw text and set the new x position
604 pain.text(int(x), offset + row->baseline(),
606 x += lyxfont::width(textstring, font);
609 while (vpos <= last &&
610 (pos = vis2log(vpos)) >= 0
611 && IsPrintableNonspace(c = row->par()->GetChar(pos))
612 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
616 // Draw text and set the new x position
617 pain.text(int(x), offset + row->baseline(), textstring, font);
618 x += lyxfont::width(textstring, font);
621 if (lyxrc.mark_foreign_language &&
622 font.language() != bview->buffer()->params.language_info) {
623 int y = offset + row->height() - 1;
624 pain.line(int(tmpx), y, int(x), y,
628 // If we want ulem.sty support, drawing
629 // routines should go here. (Asger)
630 // Why shouldn't LyXFont::drawText handle it internally?
634 // Returns the left beginning of the text.
635 // This information cannot be taken from the layouts-objekt, because in
636 // LaTeX the beginning of the text fits in some cases (for example sections)
637 // exactly the label-width.
638 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
640 LyXLayout const & layout =
641 textclasslist.Style(bview->buffer()->params.textclass,
642 row->par()->GetLayout());
644 string parindent = layout.parindent;
647 /* table stuff -- begin */
648 if (row->par()->table)
650 /* table stuff -- end */
652 int x = LYX_PAPER_MARGIN;
654 x += lyxfont::signedWidth(textclasslist
655 .TextClass(bview->buffer()->params.textclass)
658 .TextClass(bview->buffer()->params.textclass)
661 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
662 LyXFont font(LyXFont::ALL_SANE);
663 font.setSize(LyXFont::SIZE_SMALL);
664 x += lyxfont::width("Mwide-figM", font)
665 + LYX_PAPER_MARGIN/2;
668 // this is the way, LyX handles the LaTeX-Environments.
669 // I have had this idea very late, so it seems to be a
670 // later added hack and this is true
671 if (!row->par()->GetDepth()) {
672 if (!row->par()->GetLayout()) {
673 // find the previous same level paragraph
674 if (row->par()->FirstPhysicalPar()->Previous()) {
675 LyXParagraph * newpar = row->par()
676 ->DepthHook(row->par()->GetDepth());
678 textclasslist.Style(bview->buffer()->params.textclass,
685 // find the next level paragraph
687 LyXParagraph * newpar =
688 row->par()->DepthHook(row->par()->GetDepth()-1);
690 // make a corresponding row. Needed to call LeftMargin()
692 // check wether it is a sufficent paragraph
693 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
695 .Style(bview->buffer()->params.textclass,
696 newpar->GetLayout()).isEnvironment()) {
698 dummyrow.par(newpar);
699 dummyrow.pos(newpar->Last());
700 x = LeftMargin(bview, &dummyrow);
702 // this is no longer an error, because this function
703 // is used to clear impossible depths after changing
704 // a layout. Since there is always a redo,
705 // LeftMargin() is always called
706 row->par()->FirstPhysicalPar()->depth = 0;
709 if (newpar && !row->par()->GetLayout()) {
710 if (newpar->FirstPhysicalPar()->noindent)
713 parindent = textclasslist
714 .Style(bview->buffer()->params.textclass,
715 newpar->GetLayout()).parindent;
720 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
721 switch (layout.margintype) {
723 if (!layout.leftmargin.empty()) {
724 x += lyxfont::signedWidth(layout.leftmargin,
726 .TextClass(bview->buffer()->params.
730 if (!row->par()->GetLabelstring().empty()) {
731 x += lyxfont::signedWidth(layout.labelindent,
733 x += lyxfont::width(row->par()->GetLabelstring(),
735 x += lyxfont::width(layout.labelsep, labelfont);
739 x += lyxfont::signedWidth(layout.labelindent, labelfont);
740 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
741 if (!row->par()->GetLabelWidthString().empty()) {
742 x += lyxfont::width(row->par()->GetLabelWidthString(),
744 x += lyxfont::width(layout.labelsep, labelfont);
749 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
750 / (row->par()->GetDepth() + 4);
752 case MARGIN_FIRST_DYNAMIC:
753 if (layout.labeltype == LABEL_MANUAL) {
754 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
755 x += lyxfont::signedWidth(layout.leftmargin,
758 x += lyxfont::signedWidth(layout.labelindent,
761 } else if (row->pos()
762 // Special case to fix problems with
764 || (layout.labeltype == LABEL_STATIC
765 && layout.latextype == LATEX_ENVIRONMENT
766 && ! row->par()->IsFirstInSequence())) {
767 x += lyxfont::signedWidth(layout.leftmargin,
769 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
770 && layout.labeltype != LABEL_BIBLIO
771 && layout.labeltype !=
772 LABEL_CENTERED_TOP_ENVIRONMENT) {
773 x += lyxfont::signedWidth(layout.labelindent,
775 x += lyxfont::width(layout.labelsep, labelfont);
776 x += lyxfont::width(row->par()->GetLabelstring(),
781 case MARGIN_RIGHT_ADDRESS_BOX:
783 // ok, a terrible hack. The left margin depends on the widest
784 // row in this paragraph. Do not care about footnotes, they
785 // are *NOT* allowed in the LaTeX realisation of this layout.
787 // find the first row of this paragraph
788 Row const * tmprow = row;
789 while (tmprow->previous()
790 && tmprow->previous()->par() == row->par())
791 tmprow = tmprow->previous();
793 int minfill = tmprow->fill();
794 while (tmprow->next() && tmprow->next()->par() == row->par()) {
795 tmprow = tmprow->next();
796 if (tmprow->fill() < minfill)
797 minfill = tmprow->fill();
800 x += lyxfont::signedWidth(layout.leftmargin,
802 .TextClass(bview->buffer()->params.textclass)
808 if ((workWidth(bview) > 0) &&
809 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
811 if (!row->par()->pextra_widthp.empty()) {
812 x += workWidth(bview) *
813 atoi(row->par()->pextra_widthp.c_str()) / 100;
814 } else if (!row->par()->pextra_width.empty()) {
815 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
816 if (xx > workWidth(bview))
817 xx = workWidth(bview) * 80 / 100;
819 } else { // should not happen
820 LyXFont font(LyXFont::ALL_SANE);
821 x += lyxfont::width("XXXXXX", font);
825 int align; // wrong type
826 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
827 align = layout.align;
829 align = row->par()->FirstPhysicalPar()->align;
831 // set the correct parindent
832 if (row->pos() == 0) {
833 if ((layout.labeltype == LABEL_NO_LABEL
834 || layout.labeltype == LABEL_TOP_ENVIRONMENT
835 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
836 || (layout.labeltype == LABEL_STATIC
837 && layout.latextype == LATEX_ENVIRONMENT
838 && ! row->par()->IsFirstInSequence()))
839 && row->par() == row->par()->FirstPhysicalPar()
840 && align == LYX_ALIGN_BLOCK
841 && !row->par()->noindent
842 && (row->par()->layout ||
843 bview->buffer()->params.paragraph_separation ==
844 BufferParams::PARSEP_INDENT))
845 x += lyxfont::signedWidth(parindent,
847 .TextClass(bview->buffer()->params
850 else if (layout.labeltype == LABEL_BIBLIO) {
851 // ale970405 Right width for bibitems
852 x += bibitemMaxWidth(bview->painter(),
854 .TextClass(bview->buffer()->params
863 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
865 LyXLayout const & layout =
866 textclasslist.Style(buf->params.textclass,
867 row->par()->GetLayout());
869 int x = LYX_PAPER_MARGIN
870 + lyxfont::signedWidth(textclasslist
871 .TextClass(buf->params.textclass)
874 .TextClass(buf->params.textclass)
878 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
879 x += LYX_PAPER_MARGIN / 2;
882 // this is the way, LyX handles the LaTeX-Environments.
883 // I have had this idea very late, so it seems to be a
884 // later added hack and this is true
885 if (row->par()->GetDepth()) {
886 // find the next level paragraph
888 LyXParagraph * newpar = row->par();
891 newpar = newpar->FirstPhysicalPar()->Previous();
893 newpar = newpar->FirstPhysicalPar();
894 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
895 && newpar->footnoteflag == row->par()->footnoteflag);
897 // make a corresponding row. Needed to call LeftMargin()
899 // check wether it is a sufficent paragraph
900 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
901 && textclasslist.Style(buf->params.textclass,
905 dummyrow.par(newpar);
907 x = RightMargin(buf, &dummyrow);
909 // this is no longer an error, because this function
910 // is used to clear impossible depths after changing
911 // a layout. Since there is always a redo,
912 // LeftMargin() is always called
913 row->par()->FirstPhysicalPar()->depth = 0;
917 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
918 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
919 .TextClass(buf->params.textclass)
920 .defaultfont()) * 4 / (row->par()->GetDepth()
926 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
928 if (textclasslist.Style(bview->buffer()->params.textclass,
929 row->par()->GetLayout()).margintype
933 tmprow.pos(row->par()->Last());
934 return LeftMargin(bview, &tmprow); /* just the beginning
937 return 0; /* LabelEnd is only needed, if the
938 layout fills a flushleft
944 /* table stuff -- begin*/
945 int LyXText::NumberOfCell(LyXParagraph * par,
946 LyXParagraph::size_type pos) const
949 LyXParagraph::size_type tmp_pos = 0;
950 while (tmp_pos < pos) {
951 if (par->IsNewline(tmp_pos))
959 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
960 LyXParagraph::size_type & pos) const
963 while (pos < par->Last() && !par->IsNewline(pos)) {
964 w += SingleWidth(bview, par, pos);
967 if (par->IsNewline(pos))
973 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
976 float fill_separator, fill_hfill, fill_label_hfill;
977 if (!row->par()->table)
979 PrepareToPrint(bview, row, tmpx, fill_separator,
980 fill_hfill, fill_label_hfill, false);
981 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
985 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
987 Row * row = GetRowNearY(y);
988 return HitInTable(bview, row, x);
992 /* table stuff -- end*/
996 // get the next breakpoint in a given paragraph
997 LyXParagraph::size_type
998 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1000 LyXParagraph * par = row->par();
1001 LyXParagraph::size_type pos = row->pos();
1006 /* table stuff -- begin*/
1008 while (pos < par->size()
1009 && (!par->IsNewline(pos)
1010 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1011 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1012 par->GetInset(pos) && par->GetInset(pos)->display()){
1013 par->GetInset(pos)->display(false);
1019 /* table stuff -- end*/
1021 // position of the last possible breakpoint
1022 // -1 isn't a suitable value, but a flag
1023 LyXParagraph::size_type last_separator = -1;
1024 width -= RightMargin(bview->buffer(), row);
1026 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1027 LyXLayout const & layout =
1028 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1029 LyXParagraph::size_type i = pos;
1031 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1032 /* special code for right address boxes, only newlines count */
1033 while (i < par->Last()) {
1034 if (par->IsNewline(i)) {
1036 i = par->Last() - 1; // this means break
1038 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1039 par->GetInset(i) && par->GetInset(i)->display()){
1040 par->GetInset(i)->display(false);
1045 // Last position is an invariant
1046 LyXParagraph::size_type const last =
1048 // this is the usual handling
1049 int x = LeftMargin(bview, row);
1050 bool doitonetime = true;
1051 while (doitonetime || ((x < width) && (i < last))) {
1052 doitonetime = false;
1053 char c = par->GetChar(i);
1054 if (IsNewlineChar(c)) {
1056 x = width; // this means break
1057 } else if (c == LyXParagraph::META_INSET &&
1060 // check wether a Display() inset is
1061 // valid here. if not, change it to
1063 if (par->GetInset(i)->display() &&
1064 (layout.isCommand() ||
1065 ((layout.labeltype == LABEL_MANUAL) &&
1066 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1067 // display istn't allowd
1068 par->GetInset(i)->display(false);
1069 x += SingleWidth(bview, par, i, c);
1070 } else if (par->GetInset(i)->display() ||
1071 par->GetInset(i)->needFullRow()) {
1072 // So break the line here
1076 if (IsLineSeparatorChar(par->GetChar(i+1)))
1079 last_separator = last; // to avoid extra rows
1081 last_separator = i - 1;
1082 x = width; // this means break
1088 x += SingleWidth(bview, par, i, c);
1092 if (IsLineSeparatorChar(c))
1094 x += SingleWidth(bview, par, i, c);
1097 if (i == main_body) {
1098 x += lyxfont::width(layout.labelsep,
1099 GetFont(bview->buffer(), par, -2));
1100 if (par->IsLineSeparator(i - 1))
1101 x-= SingleWidth(bview, par, i - 1);
1102 int left_margin = LabelEnd(bview, row);
1103 if (x < left_margin)
1107 // end of paragraph is always a suitable separator
1108 if (i == last && x < width)
1112 // well, if last_separator is still 0, the line isn't breakable.
1113 // don't care and cut simply at the end
1114 if (last_separator < 0) {
1118 // manual labels cannot be broken in LaTeX, do not care
1119 if (main_body && last_separator < main_body)
1120 last_separator = main_body - 1;
1122 return last_separator;
1126 // returns the minimum space a row needs on the screen in pixel
1127 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1129 if (paper_width < 0)
1133 // get the pure distance
1134 LyXParagraph::size_type last = RowLastPrintable(row);
1136 /* table stuff -- begin */
1137 if (row->par()->table) {
1138 // for tables FILL does calculate the widthes of each cell in
1140 LyXParagraph::size_type pos = row->pos();
1141 int cell = NumberOfCell(row->par(), pos);
1144 row->par()->table->SetWidthOfCell(cell,
1149 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1150 // don't forget the very last table cell without characters
1151 if (cell == row->par()->table->GetNumberOfCells() - 1)
1152 row->par()->table->SetWidthOfCell(cell,
1157 return 0; /* width of table cannot be returned since
1158 * we cannot guarantee its correct value at
1161 /* table stuff -- end*/
1164 // special handling of the right address boxes
1165 if (textclasslist.Style(bview->buffer()->params.textclass,
1166 row->par()->GetLayout()).margintype
1167 == MARGIN_RIGHT_ADDRESS_BOX) {
1168 int tmpfill = row->fill();
1169 row->fill(0); // the minfill in MarginLeft()
1170 w = LeftMargin(bview, row);
1173 w = LeftMargin(bview, row);
1175 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1176 row->par()->GetLayout());
1177 LyXParagraph::size_type main_body =
1178 BeginningOfMainBody(bview->buffer(), row->par());
1179 LyXParagraph::size_type i = row->pos();
1182 if (main_body > 0 && i == main_body) {
1183 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1184 if (row->par()->IsLineSeparator(i - 1))
1185 w -= SingleWidth(bview, row->par(), i - 1);
1186 int left_margin = LabelEnd(bview, row);
1187 if (w < left_margin)
1190 w += SingleWidth(bview, row->par(), i);
1193 if (main_body > 0 && main_body > last) {
1194 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1195 if (last >= 0 && row->par()->IsLineSeparator(last))
1196 w -= SingleWidth(bview, row->par(), last);
1197 int left_margin = LabelEnd(bview, row);
1198 if (w < left_margin)
1202 fill = paper_width - w - RightMargin(bview->buffer(), row);
1207 // returns the minimum space a manual label needs on the screen in pixel
1208 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1210 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1211 // -1 because a label ends either with a space that is in the label,
1212 // or with the beginning of a footnote that is outside the label.
1214 // I don't understand this code in depth, but sometimes "last" is
1215 // less than 0 and this causes a crash. This fix seems to work
1216 // correctly, but I bet the real error is elsewhere. The bug is
1217 // triggered when you have an open footnote in a paragraph
1218 // environment with a manual label. (Asger)
1219 if (last < 0) last = 0;
1221 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1228 w += SingleWidth(bview, row->par(), i);
1233 if (!row->par()->labelwidthstring.empty()) {
1234 fill = max(lyxfont::width(row->par()->labelwidthstring,
1235 GetFont(bview->buffer(), row->par(), -2)) - w,
1243 // returns the number of separators in the specified row. The separator
1244 // on the very last column doesnt count
1245 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1247 int last = RowLast(row);
1248 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1250 for (; p < last; ++p) {
1251 if (row->par()->IsSeparator(p)) {
1259 // returns the number of hfills in the specified row. The LyX-Hfill is
1260 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1261 // ignored. This is *MUCH* more usefull than not to ignore!
1262 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1264 int last = RowLast(row);
1265 int first = row->pos();
1266 if (first) { /* hfill *DO* count at the beginning
1268 while(first <= last && row->par()->IsHfill(first))
1272 first = max(first, BeginningOfMainBody(buf, row->par()));
1274 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1275 if (row->par()->IsHfill(p)) {
1283 // like NumberOfHfills, but only those in the manual label!
1284 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1286 LyXParagraph::size_type last = RowLast(row);
1287 LyXParagraph::size_type first = row->pos();
1288 if (first) { /* hfill *DO* count at the beginning
1290 while(first < last && row->par()->IsHfill(first))
1294 last = min(last, BeginningOfMainBody(buf, row->par()));
1296 for (LyXParagraph::size_type p = first;
1297 p < last; ++p) { // last, because the end is ignored!
1298 if (row->par()->IsHfill(p)) {
1306 // returns true, if a expansion is needed.
1307 // Rules are given by LaTeX
1308 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1309 LyXParagraph::size_type pos) const
1311 // by the way, is it a hfill?
1312 if (!row_ptr->par()->IsHfill(pos))
1315 // at the end of a row it does not count
1316 if (pos >= RowLast(row_ptr))
1319 // at the beginning of a row it does not count, if it is not
1320 // the first row of a paragaph
1321 if (!row_ptr->pos())
1324 // in some labels it does not count
1325 if (textclasslist.Style(buf->params.textclass,
1326 row_ptr->par()->GetLayout()).margintype
1328 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1331 // if there is anything between the first char of the row and
1332 // the sepcified position that is not a newline and not a hfill,
1333 // the hfill will count, otherwise not
1334 LyXParagraph::size_type i = row_ptr->pos();
1335 while (i < pos && (row_ptr->par()->IsNewline(i)
1336 || row_ptr->par()->IsHfill(i)))
1343 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1345 /* get the maximum ascent and the maximum descent */
1346 int asc = 0, desc = 0, pos = 0;
1347 float layoutasc = 0;
1348 float layoutdesc = 0;
1351 Inset * tmpinset = 0;
1353 /* this must not happen before the currentrow for clear reasons.
1354 so the trick is just to set the current row onto this row */
1356 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1358 /* ok , let us initialize the maxasc and maxdesc value.
1359 * This depends in LaTeX of the font of the last character
1360 * in the paragraph. The hack below is necessary because
1361 * of the possibility of open footnotes */
1363 /* Correction: only the fontsize count. The other properties
1364 are taken from the layoutfont. Nicer on the screen :) */
1366 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1367 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1369 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1370 firstpar->GetLayout());
1372 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1373 LyXFont::FONT_SIZE size = font.size();
1374 font = GetFont(bview->buffer(), par, -1);
1377 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1379 float spacing_val = 1.0;
1380 if (!row_ptr->par()->spacing.isDefault()) {
1381 spacing_val = row_ptr->par()->spacing.getValue();
1383 spacing_val = bview->buffer()->params.spacing.getValue();
1385 //lyxerr << "spacing_val = " << spacing_val << endl;
1387 int maxasc = int(lyxfont::maxAscent(font) *
1388 layout.spacing.getValue() *
1390 int maxdesc = int(lyxfont::maxDescent(font) *
1391 layout.spacing.getValue() *
1393 int pos_end = RowLast(row_ptr);
1397 // Check if any insets are larger
1398 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1399 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1400 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1401 tmpinset = row_ptr->par()->GetInset(pos);
1403 tmpinset->update(bview, tmpfont);
1404 asc = tmpinset->ascent(bview->painter(), tmpfont);
1405 desc = tmpinset->descent(bview->painter(), tmpfont);
1406 maxwidth += tmpinset->width(bview->painter(), tmpfont);
1407 maxasc = max(maxasc, asc);
1408 maxdesc = max(maxdesc, desc);
1411 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1415 // Check if any custom fonts are larger (Asger)
1416 // This is not completely correct, but we can live with the small,
1417 // cosmetic error for now.
1418 LyXFont::FONT_SIZE maxsize =
1419 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1421 if (maxsize > font.size()) {
1422 font.setSize(maxsize);
1424 asc = lyxfont::maxAscent(font);
1425 desc = lyxfont::maxDescent(font);
1433 /* table stuff -- begin*/
1434 if (row_ptr->par()->table){
1435 // stretch the rows a bit
1439 /* table stuff -- end*/
1442 // This is nicer with box insets:
1446 row_ptr->ascent_of_text(maxasc);
1448 /* is it a top line? */
1449 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1451 /* some parksips VERY EASY IMPLEMENTATION */
1452 if (bview->buffer()->params.paragraph_separation ==
1453 BufferParams::PARSEP_SKIP) {
1454 if (layout.isParagraph()
1455 && firstpar->GetDepth() == 0
1456 && firstpar->Previous())
1457 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1458 else if (firstpar->Previous()
1459 && textclasslist.Style(bview->buffer()->params.textclass,
1460 firstpar->Previous()->GetLayout()).isParagraph()
1461 && firstpar->Previous()->GetDepth() == 0)
1462 // is it right to use defskip here too? (AS)
1463 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1466 /* the paper margins */
1467 if (!row_ptr->par()->previous && bv_owner)
1468 maxasc += LYX_PAPER_MARGIN;
1470 /* add the vertical spaces, that the user added */
1471 if (firstpar->added_space_top.kind() != VSpace::NONE)
1472 maxasc += int(firstpar->added_space_top.inPixels(bview));
1474 /* do not forget the DTP-lines!
1475 * there height depends on the font of the nearest character */
1476 if (firstpar->line_top)
1477 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1480 /* and now the pagebreaks */
1481 if (firstpar->pagebreak_top)
1482 maxasc += 3 * DefaultHeight();
1484 /* this is special code for the chapter, since the label of this
1485 * layout is printed in an extra row */
1486 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1487 && bview->buffer()->params.secnumdepth >= 0) {
1488 float spacing_val = 1.0;
1489 if (!row_ptr->par()->spacing.isDefault()) {
1490 spacing_val = row_ptr->par()->spacing.getValue();
1492 spacing_val = bview->buffer()->params.spacing.getValue();
1495 labeladdon = int(lyxfont::maxDescent(labelfont) *
1496 layout.spacing.getValue() *
1498 + int(lyxfont::maxAscent(labelfont) *
1499 layout.spacing.getValue() *
1503 /* special code for the top label */
1504 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1505 || layout.labeltype == LABEL_BIBLIO
1506 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1507 && row_ptr->par()->IsFirstInSequence()
1508 && !row_ptr->par()->GetLabelstring().empty()) {
1509 float spacing_val = 1.0;
1510 if (!row_ptr->par()->spacing.isDefault()) {
1511 spacing_val = row_ptr->par()->spacing.getValue();
1513 spacing_val = bview->buffer()->params.spacing.getValue();
1517 (lyxfont::maxAscent(labelfont) *
1518 layout.spacing.getValue() *
1520 +(lyxfont::maxDescent(labelfont) *
1521 layout.spacing.getValue() *
1523 + layout.topsep * DefaultHeight()
1524 + layout.labelbottomsep * DefaultHeight());
1527 /* and now the layout spaces, for example before and after a section,
1528 * or between the items of a itemize or enumerate environment */
1530 if (!firstpar->pagebreak_top) {
1531 LyXParagraph * prev = row_ptr->par()->Previous();
1533 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1534 if (prev && prev->GetLayout() == firstpar->GetLayout()
1535 && prev->GetDepth() == firstpar->GetDepth()
1536 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1538 layoutasc = (layout.itemsep * DefaultHeight());
1540 else if (row_ptr->previous()) {
1541 tmptop = layout.topsep;
1543 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1544 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1545 row_ptr->previous()->par()->
1546 GetLayout()).bottomsep;
1549 layoutasc = (tmptop * DefaultHeight());
1551 else if (row_ptr->par()->line_top){
1552 tmptop = layout.topsep;
1555 layoutasc = (tmptop * DefaultHeight());
1558 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1560 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1561 prev->GetLayout()).parsep * DefaultHeight());
1564 if (firstpar->Previous()
1565 && firstpar->Previous()->GetDepth() == 0
1566 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1569 else if (firstpar->Previous()){
1570 maxasc += int(layout.parsep * DefaultHeight());
1576 /* is it a bottom line? */
1577 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1578 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1580 /* the paper margins */
1581 if (!par->next && bv_owner)
1582 maxdesc += LYX_PAPER_MARGIN;
1584 /* add the vertical spaces, that the user added */
1585 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1586 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1588 /* do not forget the DTP-lines!
1589 * there height depends on the font of the nearest character */
1590 if (firstpar->line_bottom)
1591 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1592 par, par->Last() - 1));
1594 /* and now the pagebreaks */
1595 if (firstpar->pagebreak_bottom)
1596 maxdesc += 3 * DefaultHeight();
1598 /* and now the layout spaces, for example before and after a section,
1599 * or between the items of a itemize or enumerate environment */
1600 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1601 LyXParagraph * nextpar = row_ptr->par()->Next();
1602 LyXParagraph * comparepar = row_ptr->par();
1606 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1607 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1608 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1609 if (comparepar->GetLayout()!= nextpar->GetLayout()
1610 || nextpar->GetLabelWidthString() !=
1611 comparepar->GetLabelWidthString())
1612 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1614 if (unusual > usual)
1615 layoutdesc = unusual;
1619 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1621 if (comparepar->GetLayout()!= nextpar->GetLayout()
1622 || nextpar->GetLabelWidthString() !=
1623 comparepar->GetLabelWidthString())
1624 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1629 /* incalculate the layout spaces */
1630 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1631 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1634 /* table stuff -- begin*/
1635 if (row_ptr->par()->table){
1636 maxasc += row_ptr->par()->table->
1637 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1639 /* table stuff -- end*/
1641 /* calculate the new height of the text */
1642 height -= row_ptr->height();
1644 row_ptr->height(maxasc + maxdesc + labeladdon);
1645 row_ptr->baseline(maxasc + labeladdon);
1647 height += row_ptr->height();
1649 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
1650 row_ptr->width(maxwidth+x);
1653 width = max(0,workWidth(bview));
1655 if (r->width() > width)
1663 /* Appends the implicit specified paragraph behind the specified row,
1664 * start at the implicit given position */
1665 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1667 bool not_ready = true;
1669 // The last character position of a paragraph is an invariant so we can
1670 // safely get it here. (Asger)
1671 int lastposition = row->par()->Last();
1674 // Get the next breakpoint
1675 int z = NextBreakPoint(bview, row, workWidth(bview));
1679 // Insert the new row
1680 if (z < lastposition) {
1682 InsertRow(row, row->par(), z);
1689 // Set the dimensions of the row
1690 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1691 SetHeightOfRow(bview, tmprow);
1693 } while (not_ready);
1697 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1699 bool not_ready = true;
1702 /* get the next breakpoint */
1703 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1706 if (z < row->par()->Last() ) {
1707 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1710 InsertRow(row, row->par(), z);
1716 if (row->pos() == z)
1717 not_ready = false; // the rest will not change
1723 /* if there are some rows too much, delete them */
1724 /* only if you broke the whole paragraph! */
1725 Row * tmprow2 = row;
1726 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1727 tmprow2 = tmprow2->next();
1729 while (tmprow2 != row) {
1730 tmprow2 = tmprow2->previous();
1731 RemoveRow(tmprow2->next());
1736 /* set the dimensions of the row */
1737 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1738 SetHeightOfRow(bview, tmprow);
1739 } while (not_ready);
1743 // this is just a little changed version of break again
1744 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1746 // get the next breakpoint
1747 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1750 if (z < row->par()->Last() ) {
1752 || (row->next() && row->next()->par() != row->par())) {
1753 /* insert a new row */
1755 InsertRow(row, row->par(), z);
1761 if (row->pos() != z)
1765 // if there are some rows too much, delete them
1766 // only if you broke the whole paragraph!
1767 Row * tmprow2 = row;
1768 while (tmprow2->next()
1769 && tmprow2->next()->par() == row->par()) {
1770 tmprow2 = tmprow2->next();
1772 while (tmprow2 != row) {
1773 tmprow2 = tmprow2->previous();
1774 RemoveRow(tmprow2->next());
1778 // set the dimensions of the row
1779 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1780 SetHeightOfRow(bview, tmprow);
1784 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1786 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1787 cursor.par()->GetLayout());
1789 /* table stuff -- begin */
1790 if (cursor.par()->table) {
1791 // breaking of tables is only allowed at the beginning or the end */
1792 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1793 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1794 return; // no breaking of tables allowed
1796 /* table stuff -- end */
1798 // this is only allowed, if the current paragraph is not empty or caption
1799 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1801 layout.labeltype!= LABEL_SENSITIVE)
1804 SetUndo(bview->buffer(), Undo::INSERT,
1805 cursor.par()->ParFromPos(cursor.pos())->previous,
1806 cursor.par()->ParFromPos(cursor.pos())->next);
1809 /* table stuff -- begin */
1810 if (cursor.par()->table) {
1811 int cell = NumberOfCell(cursor.par(), cursor.pos());
1812 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1813 SetCursor(bview, cursor.par(), cursor.par()->size());
1815 /* table stuff -- end */
1817 // please break always behind a space
1818 if (cursor.pos() < cursor.par()->Last()
1819 && cursor.par()->IsLineSeparator(cursor.pos()))
1820 cursor.pos(cursor.pos() + 1);
1822 // break the paragraph
1826 keep_layout = layout.isEnvironment();
1827 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1830 /* table stuff -- begin */
1831 if (cursor.par()->table){
1832 // the table should stay with the contents
1834 cursor.par()->Next()->table = cursor.par()->table;
1835 cursor.par()->table = 0;
1838 /* table stuff -- end */
1840 // well this is the caption hack since one caption is really enough
1841 if (layout.labeltype == LABEL_SENSITIVE) {
1843 // set to standard-layout
1844 cursor.par()->SetLayout(bview->buffer()->params, 0);
1846 // set to standard-layout
1847 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1850 /* if the cursor is at the beginning of a row without prior newline,
1852 * This touches only the screen-update. Otherwise we would may have
1853 * an empty row on the screen */
1854 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1855 cursor.row()->pos() == cursor.pos()) {
1859 status = LyXText::NEED_MORE_REFRESH;
1860 refresh_row = cursor.row();
1861 refresh_y = cursor.y() - cursor.row()->baseline();
1863 // Do not forget the special right address boxes
1864 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1865 while (refresh_row->previous() &&
1866 refresh_row->previous()->par() == refresh_row->par()) {
1867 refresh_row = refresh_row->previous();
1868 refresh_y -= refresh_row->height();
1871 RemoveParagraph(cursor.row());
1873 // set the dimensions of the cursor row
1874 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1876 SetHeightOfRow(bview, cursor.row());
1878 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1879 && cursor.par()->Next()->IsNewline(0))
1880 cursor.par()->Next()->Erase(0);
1882 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1884 UpdateCounters(bview, cursor.row()->previous());
1886 /* This check is necessary. Otherwise the new empty paragraph will
1887 * be deleted automatically. And it is more friendly for the user! */
1889 SetCursor(bview, cursor.par()->Next(), 0);
1891 SetCursor(bview, cursor.par(), 0);
1893 if (cursor.row()->next())
1894 BreakAgain(bview, cursor.row()->next());
1901 void LyXText::OpenFootnote(BufferView * bview)
1903 LyXParagraph * endpar,* tmppar;
1906 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1908 /* if there is no footnote in this paragraph, just return. */
1910 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1913 /* ok, move the cursor right before the footnote */
1915 /* just a little faster than using CursorRight() */
1917 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1918 cursor.pos(cursor.pos() + 1);
1921 /* now the cursor is at the beginning of the physical par */
1922 SetCursor(bview, cursor.par(),
1923 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1925 /* the cursor must be exactly before the footnote */
1926 par = cursor.par()->ParFromPos(cursor.pos());
1928 status = LyXText::NEED_MORE_REFRESH;
1929 refresh_row = cursor.row();
1930 refresh_y = cursor.y() - cursor.row()->baseline();
1932 tmppar = cursor.par();
1933 endpar = cursor.par()->Next();
1936 tmppar->OpenFootnote(cursor.pos());
1937 RemoveParagraph(row);
1938 /* set the dimensions of the cursor row */
1939 row->fill(Fill(bview, row, workWidth(bview)));
1940 SetHeightOfRow(bview, row);
1941 // CHECK See comment on top of text.C
1942 tmppar = tmppar->Next();
1944 while (tmppar != endpar) {
1946 InsertParagraph(bview, tmppar, row);
1947 while (row->next() && row->next()->par() == tmppar)
1949 tmppar = tmppar->Next();
1952 SetCursor(bview, par->next, 0);
1953 sel_cursor = cursor;
1959 /* table stuff -- begin*/
1961 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
1963 if (!cursor.par()->table)
1964 return; /* this should never happen */
1966 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1967 SetUndo(bview->buffer(), Undo::FINISH,
1968 cursor.par()->ParFromPos(cursor.pos())->previous,
1969 cursor.par()->ParFromPos(cursor.pos())->next);
1972 case LyXTable::SET_PWIDTH:
1973 cursor.par()->table->SetPWidth(actCell, val);
1975 case LyXTable::SET_SPECIAL_COLUMN:
1976 case LyXTable::SET_SPECIAL_MULTI:
1977 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
1982 RedoParagraph(bview);
1986 void LyXText::TableFeatures(BufferView * bview, int feature) const
1989 int setAlign = LYX_ALIGN_LEFT;
1993 if (!cursor.par()->table)
1994 return; /* this should never happen */
1996 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1997 SetUndo(bview->buffer(), Undo::FINISH,
1998 cursor.par()->ParFromPos(cursor.pos())->previous,
1999 cursor.par()->ParFromPos(cursor.pos())->next);
2002 case LyXTable::ALIGN_LEFT:
2003 setAlign= LYX_ALIGN_LEFT;
2005 case LyXTable::ALIGN_RIGHT:
2006 setAlign= LYX_ALIGN_RIGHT;
2008 case LyXTable::ALIGN_CENTER:
2009 setAlign= LYX_ALIGN_CENTER;
2015 case LyXTable::APPEND_ROW: {
2016 LyXParagraph::size_type pos = cursor.pos();
2018 /* move to the next row */
2019 int cell_org = actCell;
2020 int cell = cell_org;
2022 // if there is a ContRow following this row I have to add
2023 // the row after the ContRow's
2024 if ((pos < cursor.par()->Last()) &&
2025 cursor.par()->table->RowHasContRow(cell_org)) {
2026 while((pos < cursor.par()->Last()) &&
2027 !cursor.par()->table->IsContRow(cell)) {
2028 while (pos < cursor.par()->Last() &&
2029 !cursor.par()->IsNewline(pos))
2031 if (pos < cursor.par()->Last())
2035 while((pos < cursor.par()->Last()) &&
2036 cursor.par()->table->IsContRow(cell)) {
2037 while (pos < cursor.par()->Last() &&
2038 !cursor.par()->IsNewline(pos))
2040 if (pos < cursor.par()->Last())
2045 if (pos < cursor.par()->Last())
2048 while (pos < cursor.par()->Last() &&
2049 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2050 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2052 if (pos < cursor.par()->Last())
2057 /* insert the new cells */
2058 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2059 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2060 LyXFont font(LyXFont::ALL_INHERIT,lang);
2061 for (int i = 0; i < number; ++i) {
2062 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2065 /* append the row into the table */
2066 cursor.par()->table->AppendRow(cell_org);
2067 RedoParagraph(bview);
2070 case LyXTable::APPEND_CONT_ROW: {
2071 LyXParagraph::size_type pos = cursor.pos();
2072 /* move to the next row */
2073 int cell_org = actCell;
2074 int cell = cell_org;
2076 // if there is already a controw but not for this cell
2077 // the AppendContRow sets only the right values but does
2078 // not actually add a row
2079 if (cursor.par()->table->RowHasContRow(cell_org) &&
2080 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2081 cursor.par()->table->AppendContRow(cell_org);
2082 RedoParagraph(bview);
2085 while (pos < cursor.par()->Last() &&
2087 || !cursor.par()->table->IsFirstCell(cell))){
2088 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2090 if (pos < cursor.par()->Last())
2095 /* insert the new cells */
2096 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2097 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2098 LyXFont font(LyXFont::ALL_INHERIT,lang);
2099 for (int i = 0; i < number; ++i) {
2100 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2103 /* append the row into the table */
2104 cursor.par()->table->AppendContRow(cell_org);
2105 RedoParagraph(bview);
2108 case LyXTable::APPEND_COLUMN: {
2109 LyXParagraph::size_type pos = 0;
2110 int cell_org = actCell;
2112 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2113 LyXFont font(LyXFont::ALL_INHERIT,lang);
2115 if (pos && (cursor.par()->IsNewline(pos-1))){
2116 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2117 cursor.par()->InsertChar(pos,
2118 LyXParagraph::META_NEWLINE,
2120 if (pos <= cursor.pos())
2121 cursor.pos(cursor.pos() + 1);
2127 } while (pos <= cursor.par()->Last());
2128 /* remember that the very last cell doesn't end with a newline.
2129 This saves one byte memory per table ;-) */
2130 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2131 LyXParagraph::size_type last = cursor.par()->Last();
2132 cursor.par()->InsertChar(last,
2133 LyXParagraph::META_NEWLINE, font);
2136 /* append the column into the table */
2137 cursor.par()->table->AppendColumn(cell_org);
2139 RedoParagraph(bview);
2142 case LyXTable::DELETE_ROW:
2143 if (bview->the_locking_inset)
2144 bview->unlockInset(bview->the_locking_inset);
2145 RemoveTableRow(cursor);
2146 RedoParagraph(bview);
2149 case LyXTable::DELETE_COLUMN: {
2150 LyXParagraph::size_type pos = 0;
2151 int cell_org = actCell;
2153 if (bview->the_locking_inset)
2154 bview->unlockInset(bview->the_locking_inset);
2156 if (!pos || (cursor.par()->IsNewline(pos-1))){
2157 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2159 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2160 cursor.par()->Erase(pos);
2161 if (pos < cursor.par()->Last())
2162 cursor.par()->Erase(pos);
2164 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2165 --pos; // because of pos++ below
2170 } while (pos <= cursor.par()->Last());
2172 /* delete the column from the table */
2173 cursor.par()->table->DeleteColumn(cell_org);
2175 /* set the cursor to the beginning of the table, where else? */
2177 RedoParagraph(bview);
2180 case LyXTable::TOGGLE_LINE_TOP:
2181 lineSet = !cursor.par()->table->TopLine(actCell);
2183 cursor.par()->table->SetTopLine(actCell, lineSet);
2185 LyXParagraph::size_type i;
2187 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2188 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2189 cursor.par()->table->SetTopLine(n, lineSet);
2194 RedoParagraph(bview);
2197 case LyXTable::TOGGLE_LINE_BOTTOM:
2198 lineSet = !cursor.par()->table->BottomLine(actCell);
2200 cursor.par()->table->SetBottomLine(actCell, lineSet);
2202 LyXParagraph::size_type i;
2204 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2205 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2206 cursor.par()->table->SetBottomLine(n, lineSet);
2211 RedoParagraph(bview);
2214 case LyXTable::TOGGLE_LINE_LEFT:
2215 lineSet = !cursor.par()->table->LeftLine(actCell);
2217 cursor.par()->table->SetLeftLine(actCell, lineSet);
2219 LyXParagraph::size_type i;
2221 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2222 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2223 cursor.par()->table->SetLeftLine(n, lineSet);
2228 RedoParagraph(bview);
2231 case LyXTable::TOGGLE_LINE_RIGHT:
2232 lineSet = !cursor.par()->table->RightLine(actCell);
2234 cursor.par()->table->SetRightLine(actCell, lineSet);
2237 LyXParagraph::size_type i = sel_start_cursor.pos();
2238 for (; i <= sel_end_cursor.pos(); ++i) {
2239 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2240 cursor.par()->table->SetRightLine(n, lineSet);
2245 RedoParagraph(bview);
2248 case LyXTable::ALIGN_LEFT:
2249 case LyXTable::ALIGN_RIGHT:
2250 case LyXTable::ALIGN_CENTER:
2252 cursor.par()->table->SetAlignment(actCell, setAlign);
2255 LyXParagraph::size_type i = sel_start_cursor.pos();
2256 for (; i <= sel_end_cursor.pos(); ++i) {
2257 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2258 cursor.par()->table->SetAlignment(n, setAlign);
2263 RedoParagraph(bview);
2266 case LyXTable::DELETE_TABLE:
2267 SetCursorIntern(bview, cursor.par(), 0);
2268 delete cursor.par()->table;
2269 cursor.par()->table = 0;
2270 // temporary: Should put table in simple_cut_buffer (with before and after
2271 // dummy-paragraph !!
2272 // not necessar anymore with UNDO :)
2273 for (LyXParagraph::size_type i =
2274 cursor.par()->size() - 1; i >= 0; --i)
2275 cursor.par()->Erase(i);
2276 RedoParagraph(bview);
2279 case LyXTable::MULTICOLUMN: {
2281 // check wether we are completly in a multicol
2282 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2283 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2284 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2285 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2289 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2290 LyXParagraph::size_type pos = cursor.pos();
2291 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2293 for (; newlines; --newlines)
2294 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2295 RedoParagraph(bview);
2299 // selection must be in one row (or no selection)
2301 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2304 RedoParagraph(bview);
2308 if (sel_start_cursor.row() == sel_end_cursor.row()){
2309 LyXParagraph::size_type i;
2311 for (i = sel_start_cursor.pos();
2312 i < sel_end_cursor.pos(); ++i){
2313 if (sel_start_cursor.par()->IsNewline(i)){
2314 sel_start_cursor.par()->Erase(i);
2315 // check for double-blanks
2316 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2318 (i < sel_start_cursor.par()->Last()
2319 && !sel_start_cursor.par()->IsLineSeparator(i)))
2320 sel_start_cursor.par()->InsertChar(i, ' ');
2322 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2328 cursor.par()->table->
2329 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2330 sel_start_cursor.pos()),
2332 cursor.pos(sel_start_cursor.pos());
2333 RedoParagraph(bview);
2337 WriteAlert(_("Impossible Operation!"),
2338 _("Multicolumns can only be horizontally."),
2345 case LyXTable::SET_ALL_LINES:
2347 case LyXTable::UNSET_ALL_LINES:
2349 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2353 LyXParagraph::size_type i;
2355 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2356 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2357 cursor.par()->table->SetAllLines(n, setLines);
2362 RedoParagraph(bview);
2364 case LyXTable::SET_LONGTABLE:
2365 cursor.par()->table->SetLongTable(true);
2367 case LyXTable::UNSET_LONGTABLE:
2368 cursor.par()->table->SetLongTable(false);
2370 case LyXTable::SET_ROTATE_TABLE:
2371 cursor.par()->table->SetRotateTable(true);
2373 case LyXTable::UNSET_ROTATE_TABLE:
2374 cursor.par()->table->SetRotateTable(false);
2376 case LyXTable::SET_ROTATE_CELL:
2378 cursor.par()->table->SetRotateCell(actCell, true);
2380 LyXParagraph::size_type i;
2382 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2383 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2384 cursor.par()->table->SetRotateCell(n, true);
2390 case LyXTable::UNSET_ROTATE_CELL:
2392 cursor.par()->table->SetRotateCell(actCell, false);
2395 LyXParagraph::size_type i = sel_start_cursor.pos();
2396 for (; i <= sel_end_cursor.pos(); ++i) {
2397 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2398 cursor.par()->table->SetRotateCell(n, false);
2404 case LyXTable::SET_LINEBREAKS:
2405 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2407 cursor.par()->table->SetLinebreaks(actCell, what);
2409 LyXParagraph::size_type i;
2411 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2412 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2413 cursor.par()->table->SetLinebreaks(n, what);
2419 case LyXTable::SET_LTFIRSTHEAD:
2420 cursor.par()->table->SetLTHead(actCell, true);
2422 case LyXTable::SET_LTHEAD:
2423 cursor.par()->table->SetLTHead(actCell, false);
2425 case LyXTable::SET_LTFOOT:
2426 cursor.par()->table->SetLTFoot(actCell, false);
2428 case LyXTable::SET_LTLASTFOOT:
2429 cursor.par()->table->SetLTFoot(actCell, true);
2431 case LyXTable::SET_LTNEWPAGE:
2432 what = !cursor.par()->table->LTNewPage(actCell);
2433 cursor.par()->table->SetLTNewPage(actCell, what);
2439 void LyXText::InsertCharInTable(BufferView * bview, char c)
2444 bool jumped_over_space;
2446 /* first check, if there will be two blanks together or a blank at
2447 * the beginning of a paragraph.
2448 * I decided to handle blanks like normal characters, the main
2449 * difference are the special checks when calculating the row.fill
2450 * (blank does not count at the end of a row) and the check here */
2452 LyXFont realtmpfont = real_current_font;
2453 LyXFont rawtmpfont = current_font; /* store the current font.
2454 * This is because of the use
2455 * of cursor movements. The moving
2456 * cursor would refresh the
2459 // Get the font that is used to calculate the baselineskip
2460 LyXParagraph::size_type const lastpos =
2461 cursor.par()->Last();
2462 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2465 jumped_over_space = false;
2466 if (IsLineSeparatorChar(c)) {
2467 if ((cursor.pos() > 0 &&
2468 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2469 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2470 || (cursor.pos() == 0 &&
2471 !(cursor.par()->Previous()
2472 && cursor.par()->Previous()->footnoteflag
2473 == LyXParagraph::OPEN_FOOTNOTE)))
2475 } else if (IsNewlineChar(c)) {
2476 if (!IsEmptyTableCell()) {
2477 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2484 y = cursor.y() - row->baseline();
2485 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2486 * already inserted the character */
2487 cursor.par()->InsertChar(cursor.pos(), c);
2488 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2490 if (!jumped_over_space) {
2491 /* refresh the positions */
2493 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2494 tmprow = tmprow->next();
2495 tmprow->pos(tmprow->pos() + 1);
2499 cursor.pos(cursor.pos() + 1);
2501 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2503 current_font = rawtmpfont;
2504 real_current_font = realtmpfont;
2506 /* check, whether the last character's font has changed. */
2507 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2508 && rawparfont != rawtmpfont)
2509 RedoHeightOfParagraph(bview, cursor);
2513 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2514 LyXParagraph::size_type pos)
2517 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2518 par->GetInset(pos) && par->GetInset(pos)->display()){
2519 par->GetInset(pos)->display(false);
2523 Row * row = GetRow(par, pos, y);
2525 int tmpheight = row->height();
2526 SetHeightOfRow(bview, row);
2528 LyXParagraph::size_type tmp_pos = pos;
2529 /* update the table information */
2530 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2532 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2533 WidthOfCell(bview, par, tmp_pos))) {
2534 LyXCursor tmpcursor = cursor;
2535 SetCursorIntern(bview, par, pos, false);
2536 /* make a complete redraw */
2537 RedoDrawingOfParagraph(bview, cursor);
2541 /* redraw only the row */
2542 LyXCursor tmpcursor = cursor;
2543 SetCursorIntern(bview, par, pos);
2544 //CHECK See comment on top of text.C
2546 refresh_x = cursor.x();
2548 refresh_pos = cursor.pos();
2551 if (tmpheight == row->height())
2552 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2554 status = LyXText::NEED_MORE_REFRESH;
2556 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2561 void LyXText::BackspaceInTable(BufferView * bview)
2563 Row * tmprow, * row;
2566 LyXFont rawtmpfont = current_font;
2567 LyXFont realtmpfont = real_current_font;
2569 // Get the font that is used to calculate the baselineskip
2570 int const lastpos = cursor.par()->Last();
2571 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2574 if (cursor.pos() == 0) {
2575 /* no pasting of table paragraphs */
2579 /* this is the code for a normal backspace, not pasting
2581 SetUndo(bview->buffer(), Undo::DELETE,
2582 cursor.par()->ParFromPos(cursor.pos())->previous,
2583 cursor.par()->ParFromPos(cursor.pos())->next);
2585 CursorLeftIntern(bview);
2587 /* some insets are undeletable here */
2588 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2589 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2594 y = cursor.y() - row->baseline();
2596 /* some special code when deleting a newline. */
2597 if (cursor.par()->IsNewline(cursor.pos())) {
2601 cursor.par()->Erase(cursor.pos());
2603 /* refresh the positions */
2605 while (tmprow->next()
2606 && tmprow->next()->par() == row->par()) {
2607 tmprow = tmprow->next();
2608 tmprow->pos(tmprow->pos() - 1);
2612 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2614 /* check, wether the last characters font has changed. */
2615 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2616 && rawparfont != rawtmpfont)
2617 RedoHeightOfParagraph(bview, cursor);
2619 /* restore the current font
2620 * That is what a user expects! */
2621 current_font = rawtmpfont;
2622 real_current_font = realtmpfont;
2624 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2626 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2627 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2630 /* table stuff -- end*/
2634 // Just a macro to make some thing easier.
2635 void LyXText::RedoParagraph(BufferView * bview) const
2638 RedoParagraphs(bview, cursor, cursor.par()->Next());
2639 SetCursorIntern(bview, cursor.par(), cursor.pos());
2643 /* insert a character, moves all the following breaks in the
2644 * same Paragraph one to the right and make a rebreak */
2645 void LyXText::InsertChar(BufferView * bview, char c)
2647 SetUndo(bview->buffer(), Undo::INSERT,
2648 cursor.par()->ParFromPos(cursor.pos())->previous,
2649 cursor.par()->ParFromPos(cursor.pos())->next);
2651 // When the free-spacing option is set for the current layout,
2652 // disable the double-space checking
2655 textclasslist.Style(bview->buffer()->params.textclass,
2656 cursor.row()->par()->GetLayout()).free_spacing;
2659 /* table stuff -- begin*/
2660 if (cursor.par()->table) {
2661 InsertCharInTable(bview, c);
2665 /* table stuff -- end*/
2667 /* First check, if there will be two blanks together or a blank at
2668 the beginning of a paragraph.
2669 I decided to handle blanks like normal characters, the main
2670 difference are the special checks when calculating the row.fill
2671 (blank does not count at the end of a row) and the check here */
2673 // The bug is triggered when we type in a description environment:
2674 // The current_font is not changed when we go from label to main text
2675 // and it should (along with realtmpfont) when we type the space.
2676 // CHECK There is a bug here! (Asger)
2678 LyXFont realtmpfont = real_current_font;
2679 LyXFont rawtmpfont = current_font; /* store the current font.
2680 * This is because of the use
2681 * of cursor movements. The moving
2682 * cursor would refresh the
2685 // Get the font that is used to calculate the baselineskip
2686 LyXParagraph::size_type lastpos = cursor.par()->Last();
2687 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2690 bool jumped_over_space = false;
2692 if (!freeSpacing && IsLineSeparatorChar(c)) {
2693 if ((cursor.pos() > 0
2694 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2695 || (cursor.pos() > 0
2696 && cursor.par()->IsNewline(cursor.pos() - 1))
2697 || (cursor.pos() == 0
2698 && !(cursor.par()->Previous()
2699 && cursor.par()->Previous()->footnoteflag
2700 == LyXParagraph::OPEN_FOOTNOTE))) {
2701 if (cursor.pos() == 0 )
2702 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2704 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2708 } else if (IsNewlineChar(c)) {
2709 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2710 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2714 /* No newline at first position
2715 * of a paragraph or behind labels.
2716 * TeX does not allow that. */
2718 if (cursor.pos() < cursor.par()->Last() &&
2719 cursor.par()->IsLineSeparator(cursor.pos()))
2720 // newline always after a blank!
2721 CursorRightIntern(bview);
2722 cursor.row()->fill(-1); // to force a new break
2725 // the display inset stuff
2726 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2727 && cursor.row()->par()->GetInset(cursor.row()->pos())
2728 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2729 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2730 cursor.row()->fill(-1); // to force a new break
2732 // get the cursor row fist
2733 Row * row = cursor.row();
2734 long y = cursor.y() - row->baseline();
2735 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2736 * already insertet the character */
2737 cursor.par()->InsertChar(cursor.pos(), c);
2738 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2740 if (!jumped_over_space) {
2741 // refresh the positions
2743 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2744 tmprow = tmprow->next();
2745 tmprow->pos(tmprow->pos() + 1);
2749 // Is there a break one row above
2750 if ((cursor.par()->IsLineSeparator(cursor.pos())
2751 || cursor.par()->IsNewline(cursor.pos())
2752 || cursor.row()->fill() == -1)
2753 && row->previous() && row->previous()->par() == row->par()) {
2754 LyXParagraph::size_type z = NextBreakPoint(bview,
2757 if ( z >= row->pos()) {
2760 // set the dimensions of the row above
2761 row->previous()->fill(Fill(bview,
2765 SetHeightOfRow(bview, row->previous());
2767 y -= row->previous()->height();
2769 refresh_row = row->previous();
2770 status = LyXText::NEED_MORE_REFRESH;
2772 BreakAgainOneRow(bview, row);
2774 current_font = rawtmpfont;
2775 real_current_font = realtmpfont;
2776 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2777 false, cursor.boundary());
2778 // cursor MUST be in row now.
2780 if (row->next() && row->next()->par() == row->par())
2781 need_break_row = row->next();
2785 // check, wether the last characters font has changed.
2786 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2787 && rawparfont != rawtmpfont)
2788 RedoHeightOfParagraph(bview, cursor);
2795 // recalculate the fill of the row
2796 if (row->fill() >= 0) /* needed because a newline
2797 * will set fill to -1. Otherwise
2798 * we would not get a rebreak! */
2799 row->fill(Fill(bview, row, workWidth(bview)));
2800 if (row->fill() < 0 ) {
2803 refresh_x = cursor.x();
2804 refresh_pos = cursor.pos();
2805 status = LyXText::NEED_MORE_REFRESH;
2806 BreakAgainOneRow(bview, row);
2807 // will the cursor be in another row now?
2808 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2809 if (row->next() && row->next()->par() == row->par())
2810 // this should always be true
2812 BreakAgainOneRow(bview, row);
2814 current_font = rawtmpfont;
2815 real_current_font = realtmpfont;
2817 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2819 if (row->next() && row->next()->par() == row->par())
2820 need_break_row = row->next();
2825 refresh_x = cursor.x();
2827 refresh_pos = cursor.pos();
2829 int tmpheight = row->height();
2830 SetHeightOfRow(bview, row);
2831 if (tmpheight == row->height())
2832 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2834 status = LyXText::NEED_MORE_REFRESH;
2836 current_font = rawtmpfont;
2837 real_current_font = realtmpfont;
2838 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2842 // check, wether the last characters font has changed.
2843 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2844 && rawparfont != rawtmpfont) {
2845 RedoHeightOfParagraph(bview, cursor);
2847 // now the special right address boxes
2848 if (textclasslist.Style(bview->buffer()->params.textclass,
2849 cursor.par()->GetLayout()).margintype
2850 == MARGIN_RIGHT_ADDRESS_BOX) {
2851 RedoDrawingOfParagraph(bview, cursor);
2859 void LyXText::charInserted()
2861 // Here we could call FinishUndo for every 20 characters inserted.
2862 // This is from my experience how emacs does it.
2863 static unsigned int counter = 0;
2873 void LyXText::PrepareToPrint(BufferView * bview,
2874 Row * row, float & x,
2875 float & fill_separator,
2877 float & fill_label_hfill,
2882 float w = row->fill();
2884 fill_label_hfill = 0;
2886 fill_label_hfill = 0;
2889 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2892 x = RightMargin(bview->buffer(), row);
2893 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2894 LyXFont font(LyXFont::ALL_SANE);
2895 font.setSize(LyXFont::SIZE_SMALL);
2896 x += lyxfont::width("Mwide-figM", font);
2900 if (workWidth(bview) > 0)
2901 x = LeftMargin(bview, row);
2905 // is there a manual margin with a manual label
2906 if (textclasslist.Style(bview->buffer()->params.textclass,
2907 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2908 && textclasslist.Style(bview->buffer()->params.textclass,
2909 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2911 /* one more since labels are left aligned */
2912 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2913 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2914 fill_label_hfill = LabelFill(bview, row) / nlh;
2918 // are there any hfills in the row?
2919 float nh = NumberOfHfills(bview->buffer(), row);
2922 /* table stuff -- begin*/
2923 if (row->par()->table) {
2924 w = workWidth(bview) - row->par()->table->WidthOfTable()
2925 - x - RightMargin(bview->buffer(), row);
2926 nh = 0; /* ignore hfills in tables */
2928 /* table stuff -- end*/
2933 // is it block, flushleft or flushright?
2934 // set x how you need it
2936 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2937 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2939 align = row->par()->FirstPhysicalPar()->align;
2941 // center displayed insets
2942 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2943 && row->par()->GetInset(row->pos())
2944 && row->par()->GetInset(row->pos())->display())
2945 align = LYX_ALIGN_CENTER;
2948 case LYX_ALIGN_BLOCK:
2949 ns = NumberOfSeparators(bview->buffer(), row);
2950 if (ns && row->next() && row->next()->par() == row->par() &&
2951 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2952 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2953 && row->next()->par()->GetInset(row->next()->pos())
2954 && row->next()->par()->GetInset(row->next()->pos())->display())
2956 fill_separator = w / ns;
2960 case LYX_ALIGN_RIGHT:
2963 case LYX_ALIGN_CENTER:
2971 ComputeBidiTables(bview->buffer(), row);
2973 LyXParagraph::size_type main_body =
2974 BeginningOfMainBody(bview->buffer(), row->par());
2975 LyXParagraph::size_type last = RowLast(row);
2977 if (main_body > 0 &&
2978 (main_body-1 > last ||
2979 !row->par()->IsLineSeparator(main_body-1))) {
2980 LyXLayout const & layout =
2981 textclasslist.Style(bview->buffer()->params.textclass,
2982 row->par()->GetLayout());
2983 x += lyxfont::width(layout.labelsep,
2984 GetFont(bview->buffer(), row->par(), -2));
2985 if (main_body-1 <= last)
2986 x += fill_label_hfill;
2991 /* important for the screen */
2994 /* the cursor set functions have a special mechanism. When they
2995 * realize, that you left an empty paragraph, they will delete it.
2996 * They also delete the corresponding row */
2998 void LyXText::CursorRightOneWord(BufferView * bview) const
3000 // treat floats, HFills and Insets as words
3001 LyXCursor tmpcursor = cursor;
3002 // CHECK See comment on top of text.C
3004 if (tmpcursor.pos() == tmpcursor.par()->Last()
3005 && tmpcursor.par()->Next()) {
3006 tmpcursor.par(tmpcursor.par()->Next());
3011 // Skip through initial nonword stuff.
3012 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3013 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3015 // printf("Current pos1 %d", tmpcursor.pos()) ;
3016 tmpcursor.pos(tmpcursor.pos() + 1);
3019 // Advance through word.
3020 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3021 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3023 // printf("Current pos2 %d", tmpcursor.pos()) ;
3024 tmpcursor.pos(tmpcursor.pos() + 1);
3028 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3032 void LyXText::CursorTab(BufferView * bview) const
3035 if (cursor.par()->table) {
3036 int cell = NumberOfCell(cursor.par(), cursor.pos());
3037 while(cursor.par()->table->IsContRow(cell)) {
3039 cell = NumberOfCell(cursor.par(), cursor.pos());
3041 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3042 TableFeatures(bview, LyXTable::APPEND_ROW);
3045 LyXCursor tmpcursor = cursor;
3046 while (tmpcursor.pos() < tmpcursor.par()->Last()
3047 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3048 tmpcursor.pos(tmpcursor.pos() + 1);
3050 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3051 if (tmpcursor.par()->Next()) {
3052 tmpcursor.par(tmpcursor.par()->Next());
3056 tmpcursor.pos(tmpcursor.pos() + 1);
3057 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3059 if (cursor.par()->table) {
3060 int cell = NumberOfCell(cursor.par(), cursor.pos());
3061 while (cursor.par()->table->IsContRow(cell) &&
3062 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3064 while (tmpcursor.pos() < tmpcursor.par()->Last()
3065 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3066 tmpcursor.pos(tmpcursor.pos() + 1);
3068 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3069 if (tmpcursor.par()->Next()) {
3070 tmpcursor.par(tmpcursor.par()->Next());
3074 tmpcursor.pos(tmpcursor.pos() + 1);
3075 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3076 cell = NumberOfCell(cursor.par(), cursor.pos());
3083 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3084 of prior word, not to end of next prior word. */
3086 void LyXText::CursorLeftOneWord(BufferView * bview) const
3088 // treat HFills, floats and Insets as words
3089 LyXCursor tmpcursor = cursor;
3090 while (tmpcursor.pos()
3091 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3092 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3093 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3094 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3095 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3096 tmpcursor.pos(tmpcursor.pos() - 1);
3099 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3100 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3101 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3102 tmpcursor.pos(tmpcursor.pos() - 1);
3103 } else if (!tmpcursor.pos()) {
3104 if (tmpcursor.par()->Previous()){
3105 tmpcursor.par(tmpcursor.par()->Previous());
3106 tmpcursor.pos(tmpcursor.par()->Last());
3108 } else { // Here, tmpcursor != 0
3109 while (tmpcursor.pos() > 0 &&
3110 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3111 tmpcursor.pos(tmpcursor.pos() - 1);
3113 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3116 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3119 void LyXText::SelectWord(BufferView * bview)
3121 // Move cursor to the beginning, when not already there.
3123 && !cursor.par()->IsSeparator(cursor.pos()-1)
3124 && !cursor.par()->IsKomma(cursor.pos()-1) )
3125 CursorLeftOneWord(bview);
3127 // set the sel cursor
3128 sel_cursor = cursor;
3130 while ( cursor.pos() < cursor.par()->Last()
3131 && !cursor.par()->IsSeparator(cursor.pos())
3132 && !cursor.par()->IsKomma(cursor.pos()) )
3133 cursor.pos(cursor.pos() + 1);
3134 SetCursor(bview, cursor.par(), cursor.pos() );
3136 // finally set the selection
3141 /* -------> Select the word currently under the cursor when:
3142 1: no selection is currently set,
3143 2: the cursor is not at the borders of the word. */
3145 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3148 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3149 && !cursor.par()->IsSeparator(cursor.pos())
3150 && !cursor.par()->IsKomma(cursor.pos())
3151 && !cursor.par()->IsSeparator(cursor.pos() -1)
3152 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3160 // This function is only used by the spellchecker for NextWord().
3161 // It doesn't handle LYX_ACCENTs and probably never will.
3162 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3164 LyXParagraph * tmppar = cursor.par();
3166 // If this is not the very first word, skip rest of
3167 // current word because we are probably in the middle
3168 // of a word if there is text here.
3169 if (cursor.pos() || cursor.par()->previous) {
3170 while (cursor.pos() < cursor.par()->Last()
3171 && cursor.par()->IsLetter(cursor.pos()))
3172 cursor.pos(cursor.pos() + 1);
3174 // Now, skip until we have real text (will jump paragraphs)
3175 while ((cursor.par()->Last() > cursor.pos()
3176 && (!cursor.par()->IsLetter(cursor.pos())
3177 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3178 .latex() == LyXFont::ON))
3179 || (cursor.par()->Last() == cursor.pos()
3180 && cursor.par()->Next())){
3181 if (cursor.pos() == cursor.par()->Last()) {
3182 cursor.par(cursor.par()->Next());
3185 cursor.pos(cursor.pos() + 1);
3188 // Update the value if we changed paragraphs
3189 if (cursor.par() != tmppar){
3190 SetCursor(bview, cursor.par(), cursor.pos());
3191 value = float(cursor.y())/float(height);
3194 // Start the selection from here
3195 sel_cursor = cursor;
3198 std::ostringstream latex;
3202 // and find the end of the word
3203 // (optional hyphens are part of a word)
3204 while (cursor.pos() < cursor.par()->Last()
3205 && (cursor.par()->IsLetter(cursor.pos()))
3206 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3207 && cursor.par()->GetInset(cursor.pos()) != 0
3208 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3210 && latex.str() == "\\-"
3212 && latex.str() // protect against null pointers
3213 && string(latex.str(), 3) == "\\-" // this is not nice at all
3216 cursor.pos(cursor.pos() + 1);
3218 #ifndef HAVE_SSTREAM
3219 delete [] latex.str();
3221 // Finally, we copy the word to a string and return it
3224 if (sel_cursor.pos() < cursor.pos()) {
3225 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3226 LyXParagraph::size_type i, j;
3227 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3228 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3229 str[j++] = cursor.par()->GetChar(i);
3237 // This one is also only for the spellchecker
3238 void LyXText::SelectSelectedWord(BufferView * bview)
3240 // move cursor to the beginning
3241 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3243 // set the sel cursor
3244 sel_cursor = cursor;
3247 std::ostringstream latex;
3252 // now find the end of the word
3253 while (cursor.pos() < cursor.par()->Last()
3254 && (cursor.par()->IsLetter(cursor.pos())
3255 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3256 && cursor.par()->GetInset(cursor.pos()) != 0
3257 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3259 && latex.str() == "\\-"
3261 && string(latex.str(), 3) == "\\-"
3264 cursor.pos(cursor.pos() + 1);
3266 #ifndef HAVE_SSTREAM
3267 delete [] latex.str();
3269 SetCursor(bview, cursor.par(), cursor.pos());
3271 // finally set the selection
3276 /* -------> Delete from cursor up to the end of the current or next word. */
3277 void LyXText::DeleteWordForward(BufferView * bview)
3279 if (!cursor.par()->Last())
3282 LyXCursor tmpcursor = cursor;
3283 tmpcursor.row(0); //Â ??
3284 selection = true; // to avoid deletion
3285 CursorRightOneWord(bview);
3286 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3287 sel_cursor = cursor;
3291 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3292 CutSelection(bview);
3297 /* -------> Delete from cursor to start of current or prior word. */
3298 void LyXText::DeleteWordBackward(BufferView * bview)
3300 if (!cursor.par()->Last())
3303 LyXCursor tmpcursor = cursor;
3304 tmpcursor.row(0); // ??
3305 selection = true; // to avoid deletion
3306 CursorLeftOneWord(bview);
3307 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3308 sel_cursor = cursor;
3311 CutSelection(bview);
3316 /* -------> Kill to end of line. */
3317 void LyXText::DeleteLineForward(BufferView * bview)
3319 if (!cursor.par()->Last())
3320 // Paragraph is empty, so we just go to the right
3323 LyXCursor tmpcursor = cursor;
3324 // We can't store the row over a regular SetCursor
3325 // so we set it to 0 and reset it afterwards.
3326 tmpcursor.row(0); //Â ??
3327 selection = true; // to avoid deletion
3329 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3330 sel_cursor = cursor;
3333 // What is this test for ??? (JMarc)
3335 DeleteWordForward(bview);
3337 CutSelection(bview);
3343 // Change the case of a word at cursor position.
3344 // This function directly manipulates LyXParagraph::text because there
3345 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3346 // that it is correct. I guess part of it should be moved to
3347 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3348 // it does not access outside of the allocated array as the older
3349 // version did. (JMarc)
3350 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3352 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3354 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3356 LyXParagraph::size_type tmppos =
3357 cursor.par()->PositionInParFromPos(cursor.pos());
3358 while (tmppos < tmppar->size()) {
3359 unsigned char c = tmppar->GetChar(tmppos);
3360 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3362 if (c != LyXParagraph::META_INSET) {
3364 case text_lowercase:
3367 case text_capitalization:
3369 action = text_lowercase;
3371 case text_uppercase:
3377 //tmppar->text[tmppos] = c;
3378 tmppar->SetChar(tmppos, c);
3381 CheckParagraph(bview, tmppar, tmppos);
3382 CursorRightOneWord(bview);
3386 void LyXText::Delete(BufferView * bview)
3388 // this is a very easy implementation
3390 LyXCursor old_cursor = cursor;
3391 int old_cur_par_id = old_cursor.par()->id();
3392 int old_cur_par_prev_id = old_cursor.par()->previous ?
3393 old_cursor.par()->previous->id() : 0;
3395 // just move to the right
3396 CursorRightIntern(bview);
3398 // CHECK Look at the comment here.
3399 // This check is not very good...
3400 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3401 // and that can very well delete the par or par->previous in
3402 // old_cursor. Will a solution where we compare paragraph id's
3404 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3405 == old_cur_par_prev_id
3406 && cursor.par()->id() != old_cur_par_id)
3407 return; // delete-empty-paragraph-mechanism has done it
3409 // if you had success make a backspace
3410 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3411 LyXCursor tmpcursor = cursor;
3412 cursor = old_cursor; // to make sure undo gets the right cursor position
3413 SetUndo(bview->buffer(), Undo::DELETE,
3414 cursor.par()->ParFromPos(cursor.pos())->previous,
3415 cursor.par()->ParFromPos(cursor.pos())->next);
3422 void LyXText::Backspace(BufferView * bview)
3425 /* table stuff -- begin */
3426 if (cursor.par()->table) {
3427 BackspaceInTable(bview);
3430 /* table stuff -- end */
3432 // LyXFont rawtmpfont = current_font;
3433 // LyXFont realtmpfont = real_current_font;
3434 // We don't need the above variables as calling to SetCursor() with third
3435 // argument eqaul to false, will not change current_font & real_current_font
3437 // Get the font that is used to calculate the baselineskip
3438 LyXParagraph::size_type lastpos = cursor.par()->Last();
3439 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3442 if (cursor.pos() == 0) {
3443 // The cursor is at the beginning of a paragraph, so the the backspace
3444 // will collapse two paragraphs into one.
3446 // we may paste some paragraphs
3448 // is it an empty paragraph?
3451 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3452 && !(cursor.par()->Next()
3453 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3454 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3455 // This is an empty paragraph and we delete it just by moving the cursor one step
3456 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3457 // of the paragraph.
3459 if (cursor.par()->previous) {
3460 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3461 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3462 && cursor.par()->footnoteflag == tmppar->footnoteflag
3463 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3464 // Inherit botom DTD from the paragraph below.
3465 // (the one we are deleting)
3466 tmppar->line_bottom = cursor.par()->line_bottom;
3467 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3468 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3471 CursorLeftIntern(bview);
3473 // the layout things can change the height of a row !
3474 int tmpheight = cursor.row()->height();
3475 SetHeightOfRow(bview, cursor.row());
3476 if (cursor.row()->height() != tmpheight) {
3477 refresh_y = cursor.y() - cursor.row()->baseline();
3478 refresh_row = cursor.row();
3479 status = LyXText::NEED_MORE_REFRESH;
3485 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3486 SetUndo(bview->buffer(), Undo::DELETE,
3487 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3488 cursor.par()->ParFromPos(cursor.pos())->next);
3491 LyXParagraph * tmppar = cursor.par();
3492 Row * tmprow = cursor.row();
3494 // We used to do CursorLeftIntern() here, but it is
3495 // not a good idea since it triggers the auto-delete
3496 // mechanism. So we do a CursorLeftIntern()-lite,
3497 // without the dreaded mechanism. (JMarc)
3498 if (cursor.par()->Previous()) {
3499 // steps into the above paragraph.
3500 SetCursorIntern(bview, cursor.par()->Previous(),
3501 cursor.par()->Previous()->Last(), false);
3504 /* Pasting is not allowed, if the paragraphs have different
3505 layout. I think it is a real bug of all other
3506 word processors to allow it. It confuses the user.
3507 Even so with a footnote paragraph and a non-footnote
3508 paragraph. I will not allow pasting in this case,
3509 because the user would be confused if the footnote behaves
3510 different wether it is open or closed.
3512 Correction: Pasting is always allowed with standard-layout
3514 if (cursor.par() != tmppar
3515 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3516 || tmppar->GetLayout() == 0 /*standard*/)
3517 && cursor.par()->footnoteflag == tmppar->footnoteflag
3519 /* table stuff -- begin*/
3520 && !cursor.par()->table /* no pasting of tables */
3521 /* table stuff -- end*/
3523 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3525 RemoveParagraph(tmprow);
3527 cursor.par()->PasteParagraph(bview->buffer()->params);
3529 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3530 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3531 // strangely enough it seems that commenting out the line above removes
3532 // most or all of the segfaults. I will however also try to move the
3533 // two Remove... lines in front of the PasteParagraph too.
3536 cursor.pos(cursor.pos() - 1);
3538 status = LyXText::NEED_MORE_REFRESH;
3539 refresh_row = cursor.row();
3540 refresh_y = cursor.y() - cursor.row()->baseline();
3542 // remove the lost paragraph
3543 // This one is not safe, since the paragraph that the tmprow and the
3544 // following rows belong to has been deleted by the PasteParagraph
3545 // above. The question is... could this be moved in front of the
3547 //RemoveParagraph(tmprow);
3548 //RemoveRow(tmprow);
3550 // This rebuilds the rows.
3551 AppendParagraph(bview, cursor.row());
3552 UpdateCounters(bview, cursor.row());
3554 // the row may have changed, block, hfills etc.
3555 SetCursor(bview, cursor.par(), cursor.pos(), false);
3558 /* this is the code for a normal backspace, not pasting
3560 SetUndo(bview->buffer(), Undo::DELETE,
3561 cursor.par()->ParFromPos(cursor.pos())->previous,
3562 cursor.par()->ParFromPos(cursor.pos())->next);
3563 // We used to do CursorLeftIntern() here, but it is
3564 // not a good idea since it triggers the auto-delete
3565 // mechanism. So we do a CursorLeftIntern()-lite,
3566 // without the dreaded mechanism. (JMarc)
3567 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3568 false, cursor.boundary());
3570 // some insets are undeletable here
3571 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3572 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3574 // force complete redo when erasing display insets
3575 // this is a cruel method but safe..... Matthias
3576 if (cursor.par()->GetInset(cursor.pos())->display() ||
3577 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
3578 cursor.par()->Erase(cursor.pos());
3579 RedoParagraph(bview);
3584 Row * row = cursor.row();
3585 long y = cursor.y() - row->baseline();
3586 LyXParagraph::size_type z;
3587 /* remember that a space at the end of a row doesnt count
3588 * when calculating the fill */
3589 if (cursor.pos() < RowLast(row) ||
3590 !cursor.par()->IsLineSeparator(cursor.pos())) {
3591 row->fill(row->fill() + SingleWidth(bview,
3596 /* some special code when deleting a newline. This is similar
3597 * to the behavior when pasting paragraphs */
3598 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3599 cursor.par()->Erase(cursor.pos());
3600 // refresh the positions
3602 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3603 tmprow = tmprow->next();
3604 tmprow->pos(tmprow->pos() - 1);
3606 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3607 cursor.pos(cursor.pos() - 1);
3609 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3610 cursor.par()->InsertChar(cursor.pos(), ' ');
3611 // refresh the positions
3613 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3614 tmprow = tmprow->next();
3615 tmprow->pos(tmprow->pos() + 1);
3619 cursor.par()->Erase(cursor.pos());
3621 // refresh the positions
3623 while (tmprow->next()
3624 && tmprow->next()->par() == row->par()) {
3625 tmprow = tmprow->next();
3626 tmprow->pos(tmprow->pos() - 1);
3629 // delete newlines at the beginning of paragraphs
3630 while (cursor.par()->Last() &&
3631 cursor.par()->IsNewline(cursor.pos()) &&
3632 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3634 cursor.par()->Erase(cursor.pos());
3635 // refresh the positions
3637 while (tmprow->next() &&
3638 tmprow->next()->par() == row->par()) {
3639 tmprow = tmprow->next();
3640 tmprow->pos(tmprow->pos() - 1);
3645 // is there a break one row above
3646 if (row->previous() && row->previous()->par() == row->par()) {
3647 z = NextBreakPoint(bview, row->previous(),
3649 if ( z >= row->pos()) {
3652 Row * tmprow = row->previous();
3654 // maybe the current row is now empty
3655 if (row->pos() >= row->par()->Last()) {
3660 BreakAgainOneRow(bview, row);
3661 if (row->next() && row->next()->par() == row->par())
3662 need_break_row = row->next();
3667 // set the dimensions of the row above
3668 y -= tmprow->height();
3669 tmprow->fill(Fill(bview, tmprow,
3671 SetHeightOfRow(bview, tmprow);
3674 refresh_row = tmprow;
3675 status = LyXText::NEED_MORE_REFRESH;
3676 SetCursor(bview, cursor.par(), cursor.pos(),
3677 false, cursor.boundary());
3678 //current_font = rawtmpfont;
3679 //real_current_font = realtmpfont;
3680 // check, whether the last character's font has changed.
3682 cursor.par()->GetFontSettings(bview->buffer()->params,
3683 cursor.par()->Last() - 1))
3684 RedoHeightOfParagraph(bview, cursor);
3689 // break the cursor row again
3690 z = NextBreakPoint(bview, row, workWidth(bview));
3692 if (z != RowLast(row) ||
3693 (row->next() && row->next()->par() == row->par() &&
3694 RowLast(row) == row->par()->Last() - 1)){
3696 /* it can happen that a paragraph loses one row
3697 * without a real breakup. This is when a word
3698 * is to long to be broken. Well, I don t care this
3700 if (row->next() && row->next()->par() == row->par() &&
3701 RowLast(row) == row->par()->Last() - 1)
3702 RemoveRow(row->next());
3706 status = LyXText::NEED_MORE_REFRESH;
3708 BreakAgainOneRow(bview, row);
3709 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3710 // cursor MUST be in row now
3712 if (row->next() && row->next()->par() == row->par())
3713 need_break_row = row->next();
3717 // set the dimensions of the row
3718 row->fill(Fill(bview, row, workWidth(bview)));
3719 int tmpheight = row->height();
3720 SetHeightOfRow(bview, row);
3721 if (tmpheight == row->height())
3722 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3724 status = LyXText::NEED_MORE_REFRESH;
3727 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3731 // current_font = rawtmpfont;
3732 // real_current_font = realtmpfont;
3734 lastpos = cursor.par()->Last();
3735 if (cursor.pos() == lastpos) {
3736 SetCurrentFont(bview);
3737 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3738 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3741 // check, wether the last characters font has changed.
3743 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3744 RedoHeightOfParagraph(bview, cursor);
3746 // now the special right address boxes
3747 if (textclasslist.Style(bview->buffer()->params.textclass,
3748 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3749 RedoDrawingOfParagraph(bview, cursor);
3755 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3756 Row * row_ptr, long y, bool cleared)
3758 /* returns a printed row */
3759 Painter & pain = bview->painter();
3761 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3762 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3764 LyXParagraph::size_type vpos, pos;
3766 int y_top, y_bottom;
3767 float fill_separator, fill_hfill, fill_label_hfill;
3769 LyXFont font(LyXFont::ALL_SANE);
3771 if (row_ptr->height() <= 0) {
3772 lyxerr << "LYX_ERROR: row.height: "
3773 << row_ptr->height() << endl;
3776 PrepareToPrint(bview, row_ptr, x, fill_separator,
3777 fill_hfill, fill_label_hfill);
3779 if (inset_owner && (x < 0))
3783 // clear the area where we want to paint/print
3785 ww = bview->workWidth();
3787 bool clear_area = true;
3790 if ((last == row_ptr->pos()) &&
3791 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3792 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3794 clear_area = inset->doClearArea();
3796 if (cleared) { // we don't need to clear it's already done!!!
3798 } else if (clear_area) {
3801 w = inset_owner->width(bview->painter(), font);
3804 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3805 } else if (inset != 0) {
3806 int h = row_ptr->baseline() - inset->ascent(pain, font);
3810 w = inset_owner->width(bview->painter(), font);
3813 pain.fillRectangle(x_offset, y_offset, w, h);
3818 /* selection code */
3819 if (bidi_same_direction) {
3820 if (sel_start_cursor.row() == row_ptr &&
3821 sel_end_cursor.row() == row_ptr) {
3822 if (sel_start_cursor.x() < sel_end_cursor.x())
3823 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3825 sel_end_cursor.x() - sel_start_cursor.x(),
3829 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3831 sel_start_cursor.x() - sel_end_cursor.x(),
3834 } else if (sel_start_cursor.row() == row_ptr) {
3836 pain.fillRectangle(x_offset, y_offset,
3837 sel_start_cursor.x(),
3841 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3843 ww - sel_start_cursor.x(),
3846 } else if (sel_end_cursor.row() == row_ptr) {
3848 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3850 ww - sel_end_cursor.x(),
3854 pain.fillRectangle(x_offset, y_offset,
3858 } else if (y > long(sel_start_cursor.y())
3859 && y < long(sel_end_cursor.y())) {
3860 pain.fillRectangle(x_offset, y_offset, ww,
3864 } else if ( sel_start_cursor.row() != row_ptr &&
3865 sel_end_cursor.row() != row_ptr &&
3866 y > long(sel_start_cursor.y())
3867 && y < long(sel_end_cursor.y())) {
3868 pain.fillRectangle(x_offset, y_offset, ww,
3871 } else if (sel_start_cursor.row() == row_ptr ||
3872 sel_end_cursor.row() == row_ptr) {
3876 if (row_ptr->par()->table) {
3877 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3878 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3881 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3882 (sel_end_cursor.row() != row_ptr && is_rtl))
3883 pain.fillRectangle(x_offset, y_offset,
3888 if (row_ptr->par()->table) {
3890 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3891 pos = vis2log(vpos);
3892 float old_tmpx = tmpx;
3893 if (row_ptr->par()->IsNewline(pos)) {
3894 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3897 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3899 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3901 if ( (sel_start_cursor.row() != row_ptr ||
3902 sel_start_cursor.pos() <= pos) &&
3903 (sel_end_cursor.row() != row_ptr ||
3904 pos < sel_end_cursor.pos()) )
3905 pain.fillRectangle(x_offset + int(old_tmpx),
3907 int(tmpx - old_tmpx + 1),
3913 LyXParagraph::size_type main_body =
3914 BeginningOfMainBody(bview->buffer(),
3917 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3918 pos = vis2log(vpos);
3919 float old_tmpx = tmpx;
3920 if (main_body > 0 && pos == main_body-1) {
3921 tmpx += fill_label_hfill +
3922 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3923 row_ptr->par()->GetLayout()).labelsep,
3924 GetFont(bview->buffer(),row_ptr->par(), -2));
3925 if (row_ptr->par()->IsLineSeparator(main_body-1))
3926 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3928 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3929 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3930 if (pos >= main_body)
3933 tmpx += fill_label_hfill;
3935 else if (row_ptr->par()->IsSeparator(pos)) {
3936 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3937 if (pos >= main_body)
3938 tmpx += fill_separator;
3940 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3942 if ( (sel_start_cursor.row() != row_ptr ||
3943 sel_start_cursor.pos() <= pos) &&
3944 (sel_end_cursor.row() != row_ptr ||
3945 pos < sel_end_cursor.pos()) )
3946 pain.fillRectangle(x_offset + int(old_tmpx),
3948 int(tmpx - old_tmpx + 1),
3955 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3956 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3957 pain.fillRectangle(x_offset + int(tmpx),
3967 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3968 LyXFont font(LyXFont::ALL_SANE);
3969 font.setSize(LyXFont::SIZE_FOOTNOTE);
3970 font.setColor(LColor::footnote);
3972 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3973 if (row_ptr->previous() &&
3974 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3976 switch (row_ptr->par()->footnotekind) {
3977 case LyXParagraph::MARGIN:
3980 case LyXParagraph::FIG:
3983 case LyXParagraph::TAB:
3986 case LyXParagraph::WIDE_FIG:
3989 case LyXParagraph::WIDE_TAB:
3992 case LyXParagraph::ALGORITHM:
3995 case LyXParagraph::FOOTNOTE:
4000 pain.fillRectangle(LYX_PAPER_MARGIN,
4002 box_x - LYX_PAPER_MARGIN,
4003 int(lyxfont::maxAscent(font)
4004 + lyxfont::maxDescent(font)),
4005 LColor::footnotebg);
4007 pain.line(LYX_PAPER_MARGIN, y_offset,
4008 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4009 LColor::footnoteframe);
4011 pain.text(LYX_PAPER_MARGIN,
4012 y_offset + int(lyxfont::maxAscent(font)) + 1,
4015 pain.line(LYX_PAPER_MARGIN, y_offset,
4017 y_offset + int(lyxfont::maxAscent(font)
4018 + lyxfont::maxDescent(font)),
4019 LColor::footnoteframe);
4021 pain.line(LYX_PAPER_MARGIN,
4022 y_offset + int(lyxfont::maxAscent(font)
4023 + lyxfont::maxDescent(font)) + 1,
4025 y_offset + int(lyxfont::maxAscent(font)
4026 + lyxfont::maxDescent(font)) + 1,
4027 LColor::footnoteframe);
4031 /* draw the open floats in a red box */
4032 pain.line(box_x, y_offset,
4033 box_x, y_offset + row_ptr->height(),
4034 LColor::footnoteframe);
4036 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4038 workWidth(bview) - LYX_PAPER_MARGIN,
4039 y_offset + row_ptr->height(),
4040 LColor::footnoteframe);
4043 // Draw appendix lines
4044 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4046 pain.line(1, y_offset,
4047 1, y_offset + row_ptr->height(),
4048 LColor::appendixline);
4049 pain.line(workWidth(bview) - 2, y_offset,
4050 workWidth(bview) - 2,
4051 y_offset + row_ptr->height(),
4052 LColor::appendixline);
4055 // Draw minipage line
4056 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4058 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4060 y_offset + row_ptr->height() - 1,
4061 LColor::minipageline);
4064 int depth = p->GetDepth();
4065 for (int i = 1; i <= depth; ++i) {
4066 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4067 pain.line(line_x, y_offset, line_x,
4068 y_offset + row_ptr->height() - 1,
4071 } else if (row_ptr->previous() &&
4072 row_ptr->previous()->par()->footnoteflag
4073 == LyXParagraph::OPEN_FOOTNOTE) {
4074 LyXFont font(LyXFont::ALL_SANE);
4075 font.setSize(LyXFont::SIZE_FOOTNOTE);
4077 int box_x = LYX_PAPER_MARGIN;
4078 box_x += lyxfont::width(" wide-tab ", font);
4080 pain.line(box_x, y_offset,
4081 workWidth(bview) - LYX_PAPER_MARGIN,
4082 y_offset, LColor::footnote);
4085 // Draw appendix lines
4086 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4087 if (firstpar->appendix){
4088 pain.line(1, y_offset,
4089 1, y_offset + row_ptr->height(),
4090 LColor::appendixline);
4091 pain.line(ww - 2, y_offset,
4092 ww - 2, y_offset + row_ptr->height(),
4093 LColor::appendixline);
4096 // Draw minipage line
4097 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4099 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4100 LYX_PAPER_MARGIN/5 + box_x,
4101 y_offset + row_ptr->height() - 1,
4102 LColor::minipageline);
4105 int depth = firstpar->GetDepth();
4109 if (row_ptr->next())
4110 if (row_ptr->par()->footnoteflag ==
4111 row_ptr->next()->par()->footnoteflag)
4112 next_depth = row_ptr->next()->par()->GetDepth();
4113 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4116 if (row_ptr->previous())
4117 if (row_ptr->par()->footnoteflag ==
4118 row_ptr->previous()->par()->footnoteflag)
4119 prev_depth = row_ptr->previous()->par()->GetDepth();
4120 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4123 for (int i = 1; i <= depth; ++i) {
4124 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4125 pain.line(line_x, y_offset, line_x,
4126 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4130 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4133 pain.fillRectangle(line_x,
4134 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4135 LYX_PAPER_MARGIN / 5, 2,
4141 LyXLayout const & layout =
4142 textclasslist.Style(bview->buffer()->params.textclass,
4143 row_ptr->par()->GetLayout());
4146 y_bottom = row_ptr->height();
4148 /* is it a first row? */
4149 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4151 /* start of appendix? */
4152 if (row_ptr->par()->start_of_appendix){
4153 pain.line(1, y_offset,
4155 LColor::appendixline);
4158 /* think about the margins */
4159 if (!row_ptr->previous() && bv_owner)
4160 y_top += LYX_PAPER_MARGIN;
4162 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4164 pb_font.setColor(LColor::pagebreak).decSize();
4165 int w = 0, a = 0, d = 0;
4166 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4168 y_offset + y_top + 2 * DefaultHeight(),
4170 Painter::line_onoffdash)
4173 _("Page Break (top)"),
4176 LColor::background, false, w, a, d);
4177 pain.rectText((ww - w)/2,
4178 y_offset + y_top + 2 * DefaultHeight() + d,
4179 _("Page Break (top)"),
4182 LColor::background);
4183 y_top += 3 * DefaultHeight();
4186 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4187 /* draw a vfill top */
4188 pain.line(0, y_offset + 2 + y_top,
4189 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4192 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4194 y_offset + y_top + 3 * DefaultHeight(),
4197 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4198 LYX_PAPER_MARGIN / 2,
4199 y_offset + y_top + 3 * DefaultHeight(),
4202 y_top += 3 * DefaultHeight();
4205 /* think about user added space */
4206 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4208 /* think about the parskip */
4209 /* some parskips VERY EASY IMPLEMENTATION */
4210 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4211 if (layout.latextype == LATEX_PARAGRAPH
4212 && firstpar->GetDepth() == 0
4213 && firstpar->Previous())
4214 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4215 else if (firstpar->Previous()
4216 && textclasslist.Style(bview->buffer()->params.textclass,
4217 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4218 && firstpar->Previous()->GetDepth() == 0)
4219 // is it right to use defskip here, too? (AS)
4220 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4223 if (row_ptr->par()->line_top) { /* draw a top line */
4224 y_top += lyxfont::ascent('x',
4225 GetFont(bview->buffer(),
4226 row_ptr->par(), 0));
4228 pain.line(0, y_offset + y_top,
4229 ww, y_offset + y_top,
4231 Painter::line_solid,
4232 Painter::line_thick);
4234 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4235 row_ptr->par(), 0));
4238 /* should we print a label? */
4239 if (layout.labeltype >= LABEL_STATIC
4240 && (layout.labeltype != LABEL_STATIC
4241 || layout.latextype != LATEX_ENVIRONMENT
4242 || row_ptr->par()->IsFirstInSequence())) {
4243 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4244 if (!row_ptr->par()->GetLabelstring().empty()) {
4246 string tmpstring = row_ptr->par()->GetLabelstring();
4248 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4249 if (bview->buffer()->params.secnumdepth >= 0) {
4250 /* this is special code for the chapter layout. This is printed in
4251 * an extra row and has a pagebreak at the top. */
4252 float spacing_val = 1.0;
4253 if (!row_ptr->par()->spacing.isDefault()) {
4254 spacing_val = row_ptr->par()->spacing.getValue();
4256 spacing_val = bview->buffer()->params.spacing.getValue();
4259 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4260 + int(layout.parsep) * DefaultHeight();
4262 tmpx = ww - LeftMargin(bview, row_ptr) -
4263 lyxfont::width(tmpstring, font);
4264 pain.text(int(tmpx),
4265 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4270 tmpx = ww - LeftMargin(bview, row_ptr)
4271 + lyxfont::width(layout.labelsep, font);
4272 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4273 LyXFont font(LyXFont::ALL_SANE);
4274 font.setSize(LyXFont::SIZE_SMALL);
4275 tmpx += lyxfont::width("Mwide-fixM", font);
4278 tmpx = x - lyxfont::width(layout.labelsep, font)
4279 - lyxfont::width(tmpstring, font);
4282 pain.text(int(tmpx),
4283 y_offset + row_ptr->baseline(),
4287 /* the labels at the top of an environment. More or less for bibliography */
4288 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4289 layout.labeltype == LABEL_BIBLIO ||
4290 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4291 if (row_ptr->par()->IsFirstInSequence()) {
4292 font = GetFont(bview->buffer(),
4293 row_ptr->par(), -2);
4294 if (!row_ptr->par()->GetLabelstring().empty()) {
4295 string tmpstring = row_ptr->par()->GetLabelstring();
4296 float spacing_val = 1.0;
4297 if (!row_ptr->par()->spacing.isDefault()) {
4298 spacing_val = row_ptr->par()->spacing.getValue();
4300 spacing_val = bview->buffer()->params.spacing.getValue();
4303 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4304 + (layout.labelbottomsep * DefaultHeight()));
4307 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4308 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4309 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4310 tmpx -= lyxfont::width(tmpstring, font) / 2;
4312 tmpx = ww - LeftMargin(bview, row_ptr) -
4313 lyxfont::width(tmpstring, font);
4314 pain.text(int(tmpx),
4315 y_offset + row_ptr->baseline()
4316 - row_ptr->ascent_of_text()
4322 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4323 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4325 tmpx = ww - LeftMargin(bview, row_ptr)
4326 + lyxfont::width(layout.labelsep, font);
4328 tmpx = x - lyxfont::width(layout.labelsep, font)
4329 - row_ptr->par()->bibkey->width(bview->painter(), font);
4330 row_ptr->par()->bibkey->draw(bview, font,
4331 y_offset + row_ptr->baseline(),
4336 /* is it a last row? */
4337 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4338 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4339 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4341 /* think about the margins */
4342 if (!row_ptr->next() && bv_owner)
4343 y_bottom -= LYX_PAPER_MARGIN;
4345 /* draw a bottom pagebreak */
4346 if (firstpar->pagebreak_bottom) {
4348 pb_font.setColor(LColor::pagebreak).decSize();
4349 int w = 0, a = 0, d = 0;
4351 y_offset + y_bottom - 2 * DefaultHeight(),
4353 y_offset + y_bottom - 2 * DefaultHeight(),
4355 Painter::line_onoffdash)
4358 _("Page Break (bottom)"),
4361 LColor::background, false, w, a, d);
4362 pain.rectText((ww - w) / 2,
4363 y_offset + y_top + 2 * DefaultHeight() + d,
4364 _("Page Break (bottom)"),
4367 LColor::background);
4368 y_bottom -= 3 * DefaultHeight();
4371 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4372 /* draw a vfill bottom */
4373 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4375 y_offset + y_bottom - 3 * DefaultHeight(),
4377 pain.line(0, y_offset + y_bottom - 2,
4379 y_offset + y_bottom - 2,
4381 pain.line(LYX_PAPER_MARGIN / 2,
4382 y_offset + y_bottom - 3 * DefaultHeight(),
4383 LYX_PAPER_MARGIN / 2,
4384 y_offset + y_bottom - 2,
4386 y_bottom -= 3 * DefaultHeight();
4389 /* think about user added space */
4390 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4392 if (firstpar->line_bottom) {
4393 /* draw a bottom line */
4394 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4395 par, par->Last() - 1));
4396 pain.line(0, y_offset + y_bottom,
4397 ww, y_offset + y_bottom,
4398 LColor::topline, Painter::line_solid,
4399 Painter::line_thick);
4400 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4401 par, par->Last() - 1));
4405 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4408 case END_LABEL_FILLED_BOX:
4410 LyXFont font = GetFont(bview->buffer(),
4411 row_ptr->par(), last);
4412 int size = int(0.75 * lyxfont::maxAscent(font));
4413 int y = (y_offset + row_ptr->baseline()) - size;
4414 int x = is_rtl ? LYX_PAPER_MARGIN
4415 : ww - LYX_PAPER_MARGIN - size;
4416 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4418 LyXFont font(LyXFont::ALL_SANE);
4419 font.setSize(LyXFont::SIZE_SMALL);
4420 x += lyxfont::width("Mwide-figM", font);
4422 x -= LYX_PAPER_MARGIN/2;
4423 if (row_ptr->fill() <= size)
4424 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4425 if (endlabel == END_LABEL_BOX) {
4426 pain.line(x, y, x, y + size,
4428 pain.line(x + size, y, x + size , y + size,
4430 pain.line(x, y, x + size, y,
4432 pain.line(x, y + size, x + size, y + size,
4435 pain.fillRectangle(x, y, size, size,
4439 case END_LABEL_STATIC:
4441 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4442 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4443 layout).endlabelstring();
4444 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4445 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4446 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4447 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4450 case END_LABEL_NO_LABEL:
4455 /* draw the text in the pixmap */
4457 vpos = row_ptr->pos();
4459 /* table stuff -- begin*/
4460 if (row_ptr->par()->table) {
4462 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4464 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4466 while (vpos <= last) {
4467 pos = vis2log(vpos);
4468 if (row_ptr->par()->IsNewline(pos)) {
4470 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4471 /* draw the table lines, still very simple */
4472 on_off = !row_ptr->par()->table->TopLine(cell);
4474 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4475 !row_ptr->par()->table->IsContRow(cell))
4476 pain.line(int(x_old),
4477 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4479 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4481 on_off ? Painter::line_onoffdash : Painter::line_solid);
4483 on_off = !row_ptr->par()->table->BottomLine(cell);
4484 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4485 row_ptr->par()->table->VeryLastRow(cell))
4487 pain.line(int(x_old),
4488 y_offset + y_bottom - 1,
4490 y_offset + y_bottom - 1,
4492 on_off ? Painter::line_onoffdash : Painter::line_solid);
4494 on_off = !row_ptr->par()->table->LeftLine(cell);
4496 pain.line(int(x_old),
4497 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4499 y_offset + y_bottom - 1,
4501 on_off ? Painter::line_onoffdash : Painter::line_solid);
4503 on_off = !row_ptr->par()->table->RightLine(cell);
4505 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4506 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4507 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4508 y_offset + y_bottom - 1,
4510 on_off ? Painter::line_onoffdash : Painter::line_solid);
4513 /* take care about the alignment and other spaces */
4515 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4516 if (row_ptr->par()->table->IsFirstCell(cell))
4517 --cell; // little hack, sorry
4519 } else if (row_ptr->par()->IsHfill(pos)) {
4523 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4525 y_offset + row_ptr->baseline(),
4530 } else if (row_ptr->par()->IsSeparator(pos)) {
4532 x+= SingleWidth(bview,
4533 row_ptr->par(), pos);
4536 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4539 /* do not forget the very last cell. This has no NEWLINE so
4540 * ignored by the code above*/
4541 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4542 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4543 on_off = !row_ptr->par()->table->TopLine(cell);
4545 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4546 !row_ptr->par()->table->IsContRow(cell))
4548 pain.line(int(x_old),
4549 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4551 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4553 on_off ? Painter::line_onoffdash : Painter::line_solid);
4554 on_off = !row_ptr->par()->table->BottomLine(cell);
4555 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4556 row_ptr->par()->table->VeryLastRow(cell))
4558 pain.line(int(x_old),
4559 y_offset + y_bottom - 1,
4561 y_offset + y_bottom - 1,
4563 on_off ? Painter::line_onoffdash : Painter::line_solid);
4565 on_off = !row_ptr->par()->table->LeftLine(cell);
4567 pain.line(int(x_old),
4568 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4570 y_offset + y_bottom - 1,
4572 on_off ? Painter::line_onoffdash : Painter::line_solid);
4574 on_off = !row_ptr->par()->table->RightLine(cell);
4576 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4577 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4578 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4579 y_offset + y_bottom - 1,
4581 on_off ? Painter::line_onoffdash : Painter::line_solid);
4584 /* table stuff -- end*/
4586 LyXParagraph::size_type main_body =
4587 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4588 if (main_body > 0 &&
4589 (main_body-1 > last ||
4590 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4593 while (vpos <= last) {
4594 pos = vis2log(vpos);
4595 if (main_body > 0 && pos == main_body - 1) {
4596 x += fill_label_hfill
4597 + lyxfont::width(layout.labelsep,
4598 GetFont(bview->buffer(),
4599 row_ptr->par(), -2))
4600 - SingleWidth(bview,
4605 if (row_ptr->par() ->IsHfill(pos)) {
4608 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4610 y_offset + row_ptr->baseline(),
4613 if (HfillExpansion(bview->buffer(),
4615 if (pos >= main_body) {
4617 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4618 int(x + fill_hfill),
4619 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4621 Painter::line_onoffdash);
4625 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4626 int(x + fill_label_hfill),
4627 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4629 Painter::line_onoffdash);
4631 x += fill_label_hfill;
4634 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4636 y_offset + row_ptr->baseline(),
4641 } else if (row_ptr->par()->IsSeparator(pos)) {
4642 x += SingleWidth(bview,
4643 row_ptr->par(), pos);
4644 if (pos >= main_body)
4645 x += fill_separator;
4648 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4656 int LyXText::DefaultHeight() const
4658 LyXFont font(LyXFont::ALL_SANE);
4659 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4663 /* returns the column near the specified x-coordinate of the row
4664 * x is set to the real beginning of this column */
4665 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4666 bool & boundary) const
4669 float fill_separator, fill_hfill, fill_label_hfill;
4671 PrepareToPrint(bview, row, tmpx, fill_separator,
4672 fill_hfill, fill_label_hfill);
4674 LyXParagraph::size_type vc = row->pos();
4675 LyXParagraph::size_type last = RowLastPrintable(row);
4676 LyXParagraph::size_type c = 0;
4677 LyXLayout const & layout =
4678 textclasslist.Style(bview->buffer()->params.textclass,
4679 row->par()->GetLayout());
4680 bool left_side = false;
4683 /* table stuff -- begin */
4684 if (row->par()->table) {
4685 //the last row doesn't need a newline at the end
4686 if (row->next() && row->next()->par() == row->par()
4687 && row->par()->IsNewline(last))
4689 int cell = NumberOfCell(row->par(), row->pos());
4690 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4691 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4692 float last_tmpx = tmpx;
4693 while (vc <= last && tmpx <= x) {
4696 if (row->par()->IsNewline(c)) {
4699 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4700 cell_x += row->par()->table->WidthOfColumn(cell);
4705 tmpx += SingleWidth(bview, row->par(), c);
4709 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4710 (tmpx + last_tmpx) / 2 > x) {
4715 /* table stuff -- end*/
4717 LyXParagraph::size_type
4718 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4719 float last_tmpx = tmpx;
4721 if (main_body > 0 &&
4722 (main_body-1 > last ||
4723 !row->par()->IsLineSeparator(main_body - 1)))
4726 while (vc <= last && tmpx <= x) {
4729 if (main_body > 0 && c == main_body-1) {
4730 tmpx += fill_label_hfill +
4731 lyxfont::width(layout.labelsep,
4732 GetFont(bview->buffer(), row->par(), -2));
4733 if (row->par()->IsLineSeparator(main_body - 1))
4734 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4737 if (HfillExpansion(bview->buffer(), row, c)) {
4738 x += SingleWidth(bview, row->par(), c);
4742 tmpx += fill_label_hfill;
4744 else if (row->par()->IsSeparator(c)) {
4745 tmpx += SingleWidth(bview, row->par(), c);
4747 tmpx+= fill_separator;
4749 tmpx += SingleWidth(bview, row->par(), c);
4753 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4762 if (vc > last + 1) // This shouldn't happen.
4767 if (row->pos() > last) // Row is empty?
4769 else if (vc == row->pos() ||
4771 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4773 if (bidi_level(c) % 2 == 1)
4776 c = vis2log(vc - 1);
4777 bool rtl = (bidi_level(c) % 2 == 1);
4778 if (left_side == rtl) {
4780 boundary = IsBoundary(bview->buffer(), row->par(), c);
4784 if (!row->par()->table && row->pos() <= last && c > last
4785 && row->par()->IsNewline(last)) {
4786 if (bidi_level(last) % 2 == 0)
4787 tmpx -= SingleWidth(bview, row->par(), last);
4789 tmpx += SingleWidth(bview, row->par(), last);
4800 /* turn the selection into a new environment. If there is no selection,
4801 * create an empty environment */
4802 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4803 LyXParagraph::footnote_kind kind)
4805 /* no footnoteenvironment in a footnoteenvironment */
4806 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4807 WriteAlert(_("Impossible operation"),
4808 _("You can't insert a float in a float!"),
4812 /* no marginpars in minipages */
4813 if (kind == LyXParagraph::MARGIN
4814 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4815 WriteAlert(_("Impossible operation"),
4816 _("You can't insert a marginpar in a minipage!"),
4821 /* this doesnt make sense, if there is no selection */
4822 bool dummy_selection = false;
4824 sel_start_cursor = cursor; /* dummy selection */
4825 sel_end_cursor = cursor;
4826 dummy_selection = true;
4829 LyXParagraph * tmppar;
4832 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4833 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4837 /* a test to make sure there is not already a footnote
4838 * in the selection. */
4840 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4842 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4843 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4844 tmppar = tmppar->next;
4846 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4847 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4848 WriteAlert(_("Impossible operation"),
4849 _("Float would include float!"),
4854 /* ok we have a selection. This is always between sel_start_cursor
4855 * and sel_end cursor */
4857 SetUndo(bview->buffer(), Undo::FINISH,
4858 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4859 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4861 if (sel_end_cursor.pos() > 0
4862 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4863 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4864 /* please break before a space at the end */
4865 if (sel_start_cursor.par() == sel_end_cursor.par()
4866 && sel_start_cursor.pos() > sel_end_cursor.pos())
4867 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4869 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4871 sel_end_cursor.par(sel_end_cursor.par()->Next());
4872 sel_end_cursor.pos(0);
4874 // don't forget to insert a dummy layout paragraph if necessary
4875 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4876 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4877 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4878 sel_end_cursor.par(sel_end_cursor.par()->next);
4881 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4883 cursor = sel_end_cursor;
4885 /* please break behind a space, if there is one. The space should
4887 if (sel_start_cursor.pos() > 0
4888 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4889 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4890 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4891 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4894 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4895 sel_start_cursor.pos());
4896 tmppar = sel_start_cursor.par()->Next();
4898 if (dummy_selection) {
4900 if (kind == LyXParagraph::TAB
4901 || kind == LyXParagraph::FIG
4902 || kind == LyXParagraph::WIDE_TAB
4903 || kind == LyXParagraph::WIDE_FIG
4904 || kind == LyXParagraph::ALGORITHM) {
4905 pair<bool, LyXTextClass::size_type> lres =
4906 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4908 LyXTextClass::size_type lay;
4914 lay = 0; // use default layout "Standard" (0)
4916 tmppar->SetLayout(bview->buffer()->params, lay);
4919 if (sel_start_cursor.pos() > 0) {
4920 /* the footnote-environment should begin with a standard layout.
4921 * Imagine you insert a footnote within an enumeration, you
4922 * certainly do not want an enumerated footnote! */
4925 /* this is a exception the user would sometimes expect, I hope */
4926 sel_start_cursor.par()->Clear();
4930 while (tmppar != sel_end_cursor.par()) {
4931 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4932 tmppar->footnotekind = kind;
4933 tmppar = tmppar->Next();
4936 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4938 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4945 // returns pointer to a specified row
4946 Row * LyXText::GetRow(LyXParagraph * par,
4947 LyXParagraph::size_type pos, long & y) const
4949 Row * tmprow = firstrow;
4952 // find the first row of the specified paragraph
4953 while (tmprow->next() && tmprow->par() != par) {
4954 y += tmprow->height();
4955 tmprow = tmprow->next();
4958 // now find the wanted row
4959 while (tmprow->pos() < pos
4961 && tmprow->next()->par() == par
4962 && tmprow->next()->pos() <= pos) {
4963 y += tmprow->height();
4964 tmprow = tmprow->next();