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"
44 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(Painter &, LyXFont const &);
47 static int iso885968x[] = {
48 0xbc, // 0xa8 = fathatan
49 0xbd, // 0xa9 = dammatan
50 0xbe, // 0xaa = kasratan
54 0xde, // 0xae = shadda
57 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
61 0xc2, // 0xc2 = ligature madda
62 0xc3, // 0xc3 = ligature hamza on alef
63 0xc4, // 0xc4 = ligature hamza on waw
64 0xc5, // 0xc5 = ligature hamza under alef
65 0xc0, // 0xc6 = ligature hamza on ya
68 0xc9, // 0xc9 = taa marbuta
87 0,0,0,0,0, // 0xdb- 0xdf
98 0xe9, // 0xe9 = alef maksura
104 bool is_arabic(unsigned char c)
106 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
111 bool is_nikud(unsigned char c)
113 return 192 <= c && c <= 210;
117 int LyXText::workWidth(BufferView * bview) const
120 return inset_owner->textWidth(bview->painter());
122 return bview->workWidth();
125 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
128 (form == FORM_INITIAL || form == FORM_MEDIAL) )
129 return iso885968x[c-0xa8];
135 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
136 LyXParagraph::size_type pos) const
140 return c + (0xb0 - '0');
144 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
145 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
147 return TransformChar(c,FORM_MEDIAL);
149 return TransformChar(c,FORM_INITIAL);
152 return TransformChar(c,FORM_FINAL);
154 return TransformChar(c,FORM_ISOLATED);
157 // This is the comments that some of the warnings below refers to.
158 // There are some issues in this file and I don't think they are
159 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
160 // this is a problem that has been here almost from day one and that a
161 // larger userbase with differenct access patters triggers the bad
162 // behaviour. (segfaults.) What I think happen is: In several places
163 // we store the paragraph in the current cursor and then moves the
164 // cursor. This movement of the cursor will delete paragraph at the
165 // old position if it is now empty. This will make the temporary
166 // pointer to the old cursor paragraph invalid and dangerous to use.
167 // And is some cases this will trigger a segfault. I have marked some
168 // of the cases where this happens with a warning, but I am sure there
169 // are others in this file and in text2.C. There is also a note in
170 // Delete() that you should read. In Delete I store the paragraph->id
171 // instead of a pointer to the paragraph. I am pretty sure this faulty
172 // use of temporary pointers to paragraphs that might have gotten
173 // invalidated (through a cursor movement) before they are used, are
174 // the cause of the strange crashes we get reported often.
176 // It is very tiresom to change this code, especially when it is as
177 // hard to read as it is. Help to fix all the cases where this is done
178 // would be greately appreciated.
182 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
183 LyXParagraph::size_type pos) const
185 char c = par->GetChar(pos);
186 return SingleWidth(bview, par, pos, c);
190 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
191 LyXParagraph::size_type pos, char c) const
193 LyXFont font = GetFont(bview->buffer(), par, pos);
195 // The most common case is handled first (Asger)
196 if (IsPrintable(c)) {
197 if (font.language()->RightToLeft()) {
198 if (font.language()->lang() == "arabic" &&
199 lyxrc.font_norm == "iso8859-6.8x")
200 c = TransformChar(c, par, pos);
201 else if (font.language()->lang() == "hebrew" &&
205 return lyxfont::width(c, font);
207 } else if (IsHfillChar(c)) {
208 return 3; /* Because of the representation
209 * as vertical lines */
211 } else if (c == LyXParagraph::META_FOOTNOTE ||
212 c == LyXParagraph::META_MARGIN ||
213 c == LyXParagraph::META_FIG ||
214 c == LyXParagraph::META_TAB ||
215 c == LyXParagraph::META_WIDE_FIG ||
216 c == LyXParagraph::META_WIDE_TAB ||
217 c == LyXParagraph::META_ALGORITHM) {
220 case LyXParagraph::META_MARGIN:
223 case LyXParagraph::META_FIG:
226 case LyXParagraph::META_TAB:
229 case LyXParagraph::META_ALGORITHM:
232 case LyXParagraph::META_WIDE_FIG:
235 case LyXParagraph::META_WIDE_TAB:
238 case LyXParagraph::META_FOOTNOTE:
244 return lyxfont::width(fs, font);
246 } else if (c == LyXParagraph::META_INSET) {
247 Inset * tmpinset = par->GetInset(pos);
249 tmpinset->update(bview, font);
250 return tmpinset->width(bview->painter(), font);
254 } else if (IsSeparatorChar(c))
256 else if (IsNewlineChar(c))
258 return lyxfont::width(c, font);
262 // Returns the paragraph position of the last character in the specified row
263 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
265 if (row->next() == 0)
266 return row->par()->Last() - 1;
267 else if (row->next()->par() != row->par())
268 return row->par()->Last() - 1;
270 return row->next()->pos() - 1;
274 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
276 LyXParagraph::size_type last = RowLast(row);
277 if (last >= row->pos()
279 && row->next()->par() == row->par()
280 && row->par()->IsSeparator(last))
287 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
289 bidi_same_direction = true;
290 if (!lyxrc.rtl_support) {
295 bidi_start = row->pos();
296 bidi_end = RowLastPrintable(row);
298 if (bidi_start > bidi_end) {
303 if (bidi_end + 2 - bidi_start >
304 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
305 LyXParagraph::size_type new_size =
306 (bidi_end + 2 - bidi_start < 500) ?
307 500 : 2 * (bidi_end + 2 - bidi_start);
308 log2vis_list.resize(new_size);
309 vis2log_list.resize(new_size);
310 bidi_levels.resize(new_size);
313 vis2log_list[bidi_end + 1 - bidi_start] = -1;
314 log2vis_list[bidi_end + 1 - bidi_start] = -1;
316 LyXParagraph::size_type stack[2];
317 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
321 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
323 for (LyXParagraph::size_type lpos = bidi_start;
324 lpos <= bidi_end; ++lpos) {
325 bool is_space = row->par()->IsLineSeparator(lpos);
326 LyXParagraph::size_type pos =
327 (is_space && lpos + 1 <= bidi_end &&
328 !row->par()->IsLineSeparator(lpos + 1) &&
330 || !row->par()->IsNewline(lpos + 1)) )
332 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
333 bool new_rtl = font.isVisibleRightToLeft();
334 bool new_rtl0 = font.isRightToLeft();
338 if (row->par()->table && row->par()->IsNewline(lpos)) {
340 new_rtl = new_rtl0 = false;
343 if (lpos == main_body - 1
344 && row->pos() < main_body - 1
345 && row->par()->IsLineSeparator(lpos)) {
346 new_level = (rtl_par) ? 1 : 0;
347 new_rtl = new_rtl0 = rtl_par;
349 new_level = (new_rtl) ? 1 : 2;
351 new_level = (rtl_par) ? 2 : 0;
353 if (is_space && new_level >= level) {
359 int new_level2 = new_level;
361 if (level == new_level && rtl0 != new_rtl0) {
363 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
364 } else if (level < new_level) {
365 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
366 if (new_level > rtl_par)
367 bidi_same_direction = false;
369 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
372 bidi_levels[lpos - bidi_start] = new_level;
374 while (level > new_level2) {
375 LyXParagraph::size_type old_lpos =
377 int delta = lpos - old_lpos - 1;
380 log2vis_list[lpos - bidi_start] += delta;
381 log2vis_list[old_lpos - bidi_start] += delta;
383 while (level < new_level)
384 stack[level++] = lpos;
388 LyXParagraph::size_type old_lpos = stack[--level];
389 int delta = bidi_end - old_lpos;
392 log2vis_list[old_lpos - bidi_start] += delta;
395 LyXParagraph::size_type vpos = bidi_start - 1;
396 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
397 vpos += log2vis_list[lpos - bidi_start];
398 vis2log_list[vpos - bidi_start] = lpos;
399 log2vis_list[lpos - bidi_start] = vpos;
404 // This method requires a previous call to ComputeBidiTables()
405 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
406 LyXParagraph::size_type pos) const
408 if (!lyxrc.rtl_support)
409 return false; // This is just for speedup
411 if (!bidi_InRange(pos - 1) ||
412 (par->table && par->IsNewline(pos-1)) )
415 bool rtl = bidi_level(pos - 1) % 2;
417 if (pos == par->Last() ||
418 (par->table && par->IsNewline(pos)))
419 rtl2 = par->isRightToLeftPar(buf->params);
420 else if (bidi_InRange(pos))
421 rtl2 = bidi_level(pos) % 2;
426 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
427 LyXParagraph::size_type pos,
428 LyXFont const & font) const
430 if (!lyxrc.rtl_support)
431 return false; // This is just for speedup
433 bool rtl = font.isVisibleRightToLeft();
435 if (pos == par->Last() ||
436 (par->table && par->IsNewline(pos)))
437 rtl2 = par->isRightToLeftPar(buf->params);
438 else if (bidi_InRange(pos))
439 rtl2 = bidi_level(pos) % 2;
444 void LyXText::draw(BufferView * bview, Row const * row,
445 LyXParagraph::size_type & vpos,
446 int offset, float & x, bool cleared)
448 Painter & pain = bview->painter();
450 LyXParagraph::size_type pos = vis2log(vpos);
451 char c = row->par()->GetChar(pos);
454 if (IsNewlineChar(c)) {
456 // Draw end-of-line marker
457 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
458 int wid = lyxfont::width('n', font);
459 int asc = lyxfont::maxAscent(font);
460 int y = offset + row->baseline();
463 if (bidi_level(pos) % 2 == 0) {
464 xp[0] = int(x + wid * 0.375);
465 yp[0] = int(y - 0.875 * asc * 0.75);
468 yp[1] = int(y - 0.500 * asc * 0.75);
470 xp[2] = int(x + wid * 0.375);
471 yp[2] = int(y - 0.125 * asc * 0.75);
473 pain.lines(xp, yp, 3, LColor::eolmarker);
476 yp[0] = int(y - 0.500 * asc * 0.75);
478 xp[1] = int(x + wid);
479 yp[1] = int(y - 0.500 * asc * 0.75);
481 xp[2] = int(x + wid);
482 yp[2] = int(y - asc * 0.75);
484 pain.lines(xp, yp, 3, LColor::eolmarker);
486 xp[0] = int(x + wid * 0.625);
487 yp[0] = int(y - 0.875 * asc * 0.75);
489 xp[1] = int(x + wid);
490 yp[1] = int(y - 0.500 * asc * 0.75);
492 xp[2] = int(x + wid * 0.625);
493 yp[2] = int(y - 0.125 * asc * 0.75);
495 pain.lines(xp, yp, 3, LColor::eolmarker);
497 xp[0] = int(x + wid);
498 yp[0] = int(y - 0.500 * asc * 0.75);
501 yp[1] = int(y - 0.500 * asc * 0.75);
504 yp[2] = int(y - asc * 0.75);
506 pain.lines(xp, yp, 3, LColor::eolmarker);
512 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
513 LyXFont font2 = font;
515 if (c == LyXParagraph::META_FOOTNOTE
516 || c == LyXParagraph::META_MARGIN
517 || c == LyXParagraph::META_FIG
518 || c == LyXParagraph::META_TAB
519 || c == LyXParagraph::META_WIDE_FIG
520 || c == LyXParagraph::META_WIDE_TAB
521 || c == LyXParagraph::META_ALGORITHM) {
524 case LyXParagraph::META_MARGIN:
527 case LyXParagraph::META_FIG:
530 case LyXParagraph::META_TAB:
533 case LyXParagraph::META_ALGORITHM:
536 case LyXParagraph::META_WIDE_FIG:
539 case LyXParagraph::META_WIDE_TAB:
542 case LyXParagraph::META_FOOTNOTE:
549 // calculate the position of the footnotemark
550 int y = (row->baseline() - lyxfont::maxAscent(font2)
551 + lyxfont::maxAscent(font));
553 font.setColor(LColor::footnote);
555 // draw it and set new x position
557 pain.text(int(x), offset + y, fs, font);
558 x += lyxfont::width(fs, font);
559 pain.line(int(tmpx), offset + row->baseline(),
560 int(x), offset + row->baseline(),
567 if (c == LyXParagraph::META_INSET) {
568 Inset * tmpinset = row->par()->GetInset(pos);
570 tmpinset->update(bview, font, false);
571 tmpinset->draw(bview, font, offset+row->baseline(), x,
576 if (lyxrc.mark_foreign_language &&
577 font.language() != bview->buffer()->params.language_info) {
578 int y = offset + row->height() - 1;
579 pain.line(int(tmpx), y, int(x), y,
586 /* usual characters, no insets */
588 // Collect character that we can draw in one command
590 // This is dirty, but fast. Notice that it will never be too small.
591 // For the record, I'll note that Microsoft Word has a limit
592 // of 768 here. We have none :-) (Asger)
593 // Ok. I am the first to admit that the use of std::string will be
594 // a tiny bit slower than using a POD char array. However, I claim
595 // that this slowdown is so small that it is close to inperceptive.
596 // So IMHO we should go with the easier and clearer implementation.
597 // And even if 1024 is a large number here it might overflow, string
598 // will only overflow if the machine is out of memory...
599 static string textstring;
603 LyXParagraph::size_type last = RowLastPrintable(row);
605 if (font.language()->lang() == "hebrew") {
607 LyXParagraph::size_type vpos2 = vpos;
608 int width = lyxfont::width(c, font2);
610 while (vpos2 <= last &&
611 (pos = vis2log(vpos2)) >= 0
612 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
615 if (static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
617 int width2 = SingleWidth(bview, row->par(), pos, c);
618 dx = (c == 'ø' || c == 'ã')
619 ? width2 - width : (width2 - width) / 2;
622 pain.text(int(x) + dx, offset + row->baseline(),
625 while (vpos <= last &&
626 (pos = vis2log(vpos)) >= 0
627 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
629 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
633 // Draw text and set the new x position
634 pain.text(int(x), offset + row->baseline(),
636 x += lyxfont::width(textstring, font);
638 } else if (font.language()->lang() == "arabic" &&
639 lyxrc.font_norm == "iso8859-6.8x") {
640 textstring = TransformChar(c, row->par(), pos);
641 while (vpos <= last &&
642 (pos = vis2log(vpos)) >= 0
643 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
644 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
645 c = TransformChar(c, row->par(), pos);
649 // Draw text and set the new x position
650 pain.text(int(x), offset + row->baseline(), textstring, font);
651 x += lyxfont::width(textstring, font);
653 while (vpos <= last &&
654 (pos = vis2log(vpos)) >= 0
655 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
656 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
660 // Draw text and set the new x position
661 pain.text(int(x), offset + row->baseline(), textstring, font);
662 x += lyxfont::width(textstring, font);
665 // what about underbars?
666 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
667 pain.line(int(tmpx), offset + row->baseline() + 2,
668 int(x), offset + row->baseline() + 2);
670 } else if (lyxrc.mark_foreign_language &&
671 font.language() != bview->buffer()->params.language_info) {
672 int y = offset + row->height() - 1;
673 pain.line(int(tmpx), y, int(x), y,
677 // If we want ulem.sty support, drawing
678 // routines should go here. (Asger)
679 // Why shouldn't LyXFont::drawText handle it internally?
683 // Returns the left beginning of the text.
684 // This information cannot be taken from the layouts-objekt, because in
685 // LaTeX the beginning of the text fits in some cases (for example sections)
686 // exactly the label-width.
687 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
689 LyXLayout const & layout =
690 textclasslist.Style(bview->buffer()->params.textclass,
691 row->par()->GetLayout());
693 string parindent = layout.parindent;
696 /* table stuff -- begin */
697 if (row->par()->table)
699 /* table stuff -- end */
701 int x = LYX_PAPER_MARGIN;
703 x += lyxfont::signedWidth(textclasslist
704 .TextClass(bview->buffer()->params.textclass)
707 .TextClass(bview->buffer()->params.textclass)
710 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
711 LyXFont font(LyXFont::ALL_SANE);
712 font.setSize(LyXFont::SIZE_SMALL);
713 x += lyxfont::width("Mwide-figM", font)
714 + LYX_PAPER_MARGIN/2;
717 // this is the way, LyX handles the LaTeX-Environments.
718 // I have had this idea very late, so it seems to be a
719 // later added hack and this is true
720 if (!row->par()->GetDepth()) {
721 if (!row->par()->GetLayout()) {
722 // find the previous same level paragraph
723 if (row->par()->FirstPhysicalPar()->Previous()) {
724 LyXParagraph * newpar = row->par()
725 ->DepthHook(row->par()->GetDepth());
727 textclasslist.Style(bview->buffer()->params.textclass,
734 // find the next level paragraph
736 LyXParagraph * newpar =
737 row->par()->DepthHook(row->par()->GetDepth()-1);
739 // make a corresponding row. Needed to call LeftMargin()
741 // check wether it is a sufficent paragraph
742 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
744 .Style(bview->buffer()->params.textclass,
745 newpar->GetLayout()).isEnvironment()) {
747 dummyrow.par(newpar);
748 dummyrow.pos(newpar->Last());
749 x = LeftMargin(bview, &dummyrow);
751 // this is no longer an error, because this function
752 // is used to clear impossible depths after changing
753 // a layout. Since there is always a redo,
754 // LeftMargin() is always called
755 row->par()->FirstPhysicalPar()->depth = 0;
758 if (newpar && !row->par()->GetLayout()) {
759 if (newpar->FirstPhysicalPar()->noindent)
762 parindent = textclasslist
763 .Style(bview->buffer()->params.textclass,
764 newpar->GetLayout()).parindent;
769 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
770 switch (layout.margintype) {
772 if (!layout.leftmargin.empty()) {
773 x += lyxfont::signedWidth(layout.leftmargin,
775 .TextClass(bview->buffer()->params.
779 if (!row->par()->GetLabelstring().empty()) {
780 x += lyxfont::signedWidth(layout.labelindent,
782 x += lyxfont::width(row->par()->GetLabelstring(),
784 x += lyxfont::width(layout.labelsep, labelfont);
788 x += lyxfont::signedWidth(layout.labelindent, labelfont);
789 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
790 if (!row->par()->GetLabelWidthString().empty()) {
791 x += lyxfont::width(row->par()->GetLabelWidthString(),
793 x += lyxfont::width(layout.labelsep, labelfont);
798 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
799 / (row->par()->GetDepth() + 4);
801 case MARGIN_FIRST_DYNAMIC:
802 if (layout.labeltype == LABEL_MANUAL) {
803 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
804 x += lyxfont::signedWidth(layout.leftmargin,
807 x += lyxfont::signedWidth(layout.labelindent,
810 } else if (row->pos()
811 // Special case to fix problems with
813 || (layout.labeltype == LABEL_STATIC
814 && layout.latextype == LATEX_ENVIRONMENT
815 && ! row->par()->IsFirstInSequence())) {
816 x += lyxfont::signedWidth(layout.leftmargin,
818 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
819 && layout.labeltype != LABEL_BIBLIO
820 && layout.labeltype !=
821 LABEL_CENTERED_TOP_ENVIRONMENT) {
822 x += lyxfont::signedWidth(layout.labelindent,
824 x += lyxfont::width(layout.labelsep, labelfont);
825 x += lyxfont::width(row->par()->GetLabelstring(),
830 case MARGIN_RIGHT_ADDRESS_BOX:
832 // ok, a terrible hack. The left margin depends on the widest
833 // row in this paragraph. Do not care about footnotes, they
834 // are *NOT* allowed in the LaTeX realisation of this layout.
836 // find the first row of this paragraph
837 Row const * tmprow = row;
838 while (tmprow->previous()
839 && tmprow->previous()->par() == row->par())
840 tmprow = tmprow->previous();
842 int minfill = tmprow->fill();
843 while (tmprow->next() && tmprow->next()->par() == row->par()) {
844 tmprow = tmprow->next();
845 if (tmprow->fill() < minfill)
846 minfill = tmprow->fill();
849 x += lyxfont::signedWidth(layout.leftmargin,
851 .TextClass(bview->buffer()->params.textclass)
857 if ((workWidth(bview) > 0) &&
858 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
860 if (!row->par()->pextra_widthp.empty()) {
861 x += workWidth(bview) *
862 atoi(row->par()->pextra_widthp.c_str()) / 100;
863 } else if (!row->par()->pextra_width.empty()) {
864 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
865 if (xx > workWidth(bview))
866 xx = workWidth(bview) * 80 / 100;
868 } else { // should not happen
869 LyXFont font(LyXFont::ALL_SANE);
870 x += lyxfont::width("XXXXXX", font);
874 int align; // wrong type
875 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
876 align = layout.align;
878 align = row->par()->FirstPhysicalPar()->align;
880 // set the correct parindent
881 if (row->pos() == 0) {
882 if ((layout.labeltype == LABEL_NO_LABEL
883 || layout.labeltype == LABEL_TOP_ENVIRONMENT
884 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
885 || (layout.labeltype == LABEL_STATIC
886 && layout.latextype == LATEX_ENVIRONMENT
887 && ! row->par()->IsFirstInSequence()))
888 && row->par() == row->par()->FirstPhysicalPar()
889 && align == LYX_ALIGN_BLOCK
890 && !row->par()->noindent
891 && (row->par()->layout ||
892 bview->buffer()->params.paragraph_separation ==
893 BufferParams::PARSEP_INDENT))
894 x += lyxfont::signedWidth(parindent,
896 .TextClass(bview->buffer()->params
899 else if (layout.labeltype == LABEL_BIBLIO) {
900 // ale970405 Right width for bibitems
901 x += bibitemMaxWidth(bview->painter(),
903 .TextClass(bview->buffer()->params
912 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
914 LyXLayout const & layout =
915 textclasslist.Style(buf->params.textclass,
916 row->par()->GetLayout());
918 int x = LYX_PAPER_MARGIN
919 + lyxfont::signedWidth(textclasslist
920 .TextClass(buf->params.textclass)
923 .TextClass(buf->params.textclass)
927 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
928 x += LYX_PAPER_MARGIN / 2;
931 // this is the way, LyX handles the LaTeX-Environments.
932 // I have had this idea very late, so it seems to be a
933 // later added hack and this is true
934 if (row->par()->GetDepth()) {
935 // find the next level paragraph
937 LyXParagraph * newpar = row->par();
940 newpar = newpar->FirstPhysicalPar()->Previous();
942 newpar = newpar->FirstPhysicalPar();
943 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
944 && newpar->footnoteflag == row->par()->footnoteflag);
946 // make a corresponding row. Needed to call LeftMargin()
948 // check wether it is a sufficent paragraph
949 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
950 && textclasslist.Style(buf->params.textclass,
954 dummyrow.par(newpar);
956 x = RightMargin(buf, &dummyrow);
958 // this is no longer an error, because this function
959 // is used to clear impossible depths after changing
960 // a layout. Since there is always a redo,
961 // LeftMargin() is always called
962 row->par()->FirstPhysicalPar()->depth = 0;
966 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
967 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
968 .TextClass(buf->params.textclass)
969 .defaultfont()) * 4 / (row->par()->GetDepth()
975 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
977 if (textclasslist.Style(bview->buffer()->params.textclass,
978 row->par()->GetLayout()).margintype
982 tmprow.pos(row->par()->Last());
983 return LeftMargin(bview, &tmprow); /* just the beginning
986 return 0; /* LabelEnd is only needed, if the
987 layout fills a flushleft
993 /* table stuff -- begin*/
994 int LyXText::NumberOfCell(LyXParagraph * par,
995 LyXParagraph::size_type pos) const
998 LyXParagraph::size_type tmp_pos = 0;
999 while (tmp_pos < pos) {
1000 if (par->IsNewline(tmp_pos))
1008 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
1009 LyXParagraph::size_type & pos) const
1012 while (pos < par->Last() && !par->IsNewline(pos)) {
1013 w += SingleWidth(bview, par, pos);
1016 if (par->IsNewline(pos))
1022 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
1025 float fill_separator, fill_hfill, fill_label_hfill;
1026 if (!row->par()->table)
1028 PrepareToPrint(bview, row, tmpx, fill_separator,
1029 fill_hfill, fill_label_hfill, false);
1030 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
1034 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
1036 Row * row = GetRowNearY(y);
1037 return HitInTable(bview, row, x);
1041 /* table stuff -- end*/
1045 // get the next breakpoint in a given paragraph
1046 LyXParagraph::size_type
1047 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1049 LyXParagraph * par = row->par();
1050 LyXParagraph::size_type pos = row->pos();
1055 /* table stuff -- begin*/
1057 while (pos < par->size()
1058 && (!par->IsNewline(pos)
1059 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1060 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1061 par->GetInset(pos) && par->GetInset(pos)->display()){
1062 par->GetInset(pos)->display(false);
1068 /* table stuff -- end*/
1070 // position of the last possible breakpoint
1071 // -1 isn't a suitable value, but a flag
1072 LyXParagraph::size_type last_separator = -1;
1073 width -= RightMargin(bview->buffer(), row);
1075 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1076 LyXLayout const & layout =
1077 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1078 LyXParagraph::size_type i = pos;
1080 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1081 /* special code for right address boxes, only newlines count */
1082 while (i < par->Last()) {
1083 if (par->IsNewline(i)) {
1085 i = par->Last() - 1; // this means break
1087 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1088 par->GetInset(i) && par->GetInset(i)->display()){
1089 par->GetInset(i)->display(false);
1094 // Last position is an invariant
1095 LyXParagraph::size_type const last =
1097 // this is the usual handling
1098 int x = LeftMargin(bview, row);
1099 bool doitonetime = true;
1100 while (doitonetime || ((x < width) && (i < last))) {
1101 doitonetime = false;
1102 char c = par->GetChar(i);
1103 if (IsNewlineChar(c)) {
1105 x = width; // this means break
1106 } else if (c == LyXParagraph::META_INSET &&
1109 // check wether a Display() inset is
1110 // valid here. if not, change it to
1112 if (par->GetInset(i)->display() &&
1113 (layout.isCommand() ||
1114 ((layout.labeltype == LABEL_MANUAL) &&
1115 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1116 // display istn't allowd
1117 par->GetInset(i)->display(false);
1118 x += SingleWidth(bview, par, i, c);
1119 } else if (par->GetInset(i)->display() ||
1120 par->GetInset(i)->needFullRow()) {
1121 // So break the line here
1125 if (IsLineSeparatorChar(par->GetChar(i+1)))
1128 last_separator = last; // to avoid extra rows
1130 last_separator = i - 1;
1131 x = width; // this means break
1137 x += SingleWidth(bview, par, i, c);
1141 if (IsLineSeparatorChar(c))
1143 x += SingleWidth(bview, par, i, c);
1146 if (i == main_body) {
1147 x += lyxfont::width(layout.labelsep,
1148 GetFont(bview->buffer(), par, -2));
1149 if (par->IsLineSeparator(i - 1))
1150 x-= SingleWidth(bview, par, i - 1);
1151 int left_margin = LabelEnd(bview, row);
1152 if (x < left_margin)
1156 // end of paragraph is always a suitable separator
1157 if (i == last && x < width)
1161 // well, if last_separator is still 0, the line isn't breakable.
1162 // don't care and cut simply at the end
1163 if (last_separator < 0) {
1167 // manual labels cannot be broken in LaTeX, do not care
1168 if (main_body && last_separator < main_body)
1169 last_separator = main_body - 1;
1171 return last_separator;
1175 // returns the minimum space a row needs on the screen in pixel
1176 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1178 if (paper_width < 0)
1182 // get the pure distance
1183 LyXParagraph::size_type last = RowLastPrintable(row);
1185 /* table stuff -- begin */
1186 if (row->par()->table) {
1187 // for tables FILL does calculate the widthes of each cell in
1189 LyXParagraph::size_type pos = row->pos();
1190 int cell = NumberOfCell(row->par(), pos);
1193 row->par()->table->SetWidthOfCell(cell,
1198 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1199 // don't forget the very last table cell without characters
1200 if (cell == row->par()->table->GetNumberOfCells() - 1)
1201 row->par()->table->SetWidthOfCell(cell,
1206 return 0; /* width of table cannot be returned since
1207 * we cannot guarantee its correct value at
1210 /* table stuff -- end*/
1213 // special handling of the right address boxes
1214 if (textclasslist.Style(bview->buffer()->params.textclass,
1215 row->par()->GetLayout()).margintype
1216 == MARGIN_RIGHT_ADDRESS_BOX) {
1217 int tmpfill = row->fill();
1218 row->fill(0); // the minfill in MarginLeft()
1219 w = LeftMargin(bview, row);
1222 w = LeftMargin(bview, row);
1224 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1225 row->par()->GetLayout());
1226 LyXParagraph::size_type main_body =
1227 BeginningOfMainBody(bview->buffer(), row->par());
1228 LyXParagraph::size_type i = row->pos();
1231 if (main_body > 0 && i == main_body) {
1232 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1233 if (row->par()->IsLineSeparator(i - 1))
1234 w -= SingleWidth(bview, row->par(), i - 1);
1235 int left_margin = LabelEnd(bview, row);
1236 if (w < left_margin)
1239 w += SingleWidth(bview, row->par(), i);
1242 if (main_body > 0 && main_body > last) {
1243 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1244 if (last >= 0 && row->par()->IsLineSeparator(last))
1245 w -= SingleWidth(bview, row->par(), last);
1246 int left_margin = LabelEnd(bview, row);
1247 if (w < left_margin)
1251 fill = paper_width - w - RightMargin(bview->buffer(), row);
1256 // returns the minimum space a manual label needs on the screen in pixel
1257 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1259 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1260 // -1 because a label ends either with a space that is in the label,
1261 // or with the beginning of a footnote that is outside the label.
1263 // I don't understand this code in depth, but sometimes "last" is
1264 // less than 0 and this causes a crash. This fix seems to work
1265 // correctly, but I bet the real error is elsewhere. The bug is
1266 // triggered when you have an open footnote in a paragraph
1267 // environment with a manual label. (Asger)
1268 if (last < 0) last = 0;
1270 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1277 w += SingleWidth(bview, row->par(), i);
1282 if (!row->par()->labelwidthstring.empty()) {
1283 fill = max(lyxfont::width(row->par()->labelwidthstring,
1284 GetFont(bview->buffer(), row->par(), -2)) - w,
1292 // returns the number of separators in the specified row. The separator
1293 // on the very last column doesnt count
1294 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1296 int last = RowLast(row);
1297 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1299 for (; p < last; ++p) {
1300 if (row->par()->IsSeparator(p)) {
1308 // returns the number of hfills in the specified row. The LyX-Hfill is
1309 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1310 // ignored. This is *MUCH* more usefull than not to ignore!
1311 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1313 int last = RowLast(row);
1314 int first = row->pos();
1315 if (first) { /* hfill *DO* count at the beginning
1317 while(first <= last && row->par()->IsHfill(first))
1321 first = max(first, BeginningOfMainBody(buf, row->par()));
1323 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1324 if (row->par()->IsHfill(p)) {
1332 // like NumberOfHfills, but only those in the manual label!
1333 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1335 LyXParagraph::size_type last = RowLast(row);
1336 LyXParagraph::size_type first = row->pos();
1337 if (first) { /* hfill *DO* count at the beginning
1339 while(first < last && row->par()->IsHfill(first))
1343 last = min(last, BeginningOfMainBody(buf, row->par()));
1345 for (LyXParagraph::size_type p = first;
1346 p < last; ++p) { // last, because the end is ignored!
1347 if (row->par()->IsHfill(p)) {
1355 // returns true, if a expansion is needed.
1356 // Rules are given by LaTeX
1357 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1358 LyXParagraph::size_type pos) const
1360 // by the way, is it a hfill?
1361 if (!row_ptr->par()->IsHfill(pos))
1364 // at the end of a row it does not count
1365 if (pos >= RowLast(row_ptr))
1368 // at the beginning of a row it does not count, if it is not
1369 // the first row of a paragaph
1370 if (!row_ptr->pos())
1373 // in some labels it does not count
1374 if (textclasslist.Style(buf->params.textclass,
1375 row_ptr->par()->GetLayout()).margintype
1377 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1380 // if there is anything between the first char of the row and
1381 // the sepcified position that is not a newline and not a hfill,
1382 // the hfill will count, otherwise not
1383 LyXParagraph::size_type i = row_ptr->pos();
1384 while (i < pos && (row_ptr->par()->IsNewline(i)
1385 || row_ptr->par()->IsHfill(i)))
1392 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1394 /* get the maximum ascent and the maximum descent */
1395 int asc = 0, desc = 0, pos = 0;
1396 float layoutasc = 0;
1397 float layoutdesc = 0;
1400 Inset * tmpinset = 0;
1402 /* this must not happen before the currentrow for clear reasons.
1403 so the trick is just to set the current row onto this row */
1405 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1407 /* ok , let us initialize the maxasc and maxdesc value.
1408 * This depends in LaTeX of the font of the last character
1409 * in the paragraph. The hack below is necessary because
1410 * of the possibility of open footnotes */
1412 /* Correction: only the fontsize count. The other properties
1413 are taken from the layoutfont. Nicer on the screen :) */
1415 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1416 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1418 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1419 firstpar->GetLayout());
1421 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1422 LyXFont::FONT_SIZE size = font.size();
1423 font = GetFont(bview->buffer(), par, -1);
1426 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1428 float spacing_val = 1.0;
1429 if (!row_ptr->par()->spacing.isDefault()) {
1430 spacing_val = row_ptr->par()->spacing.getValue();
1432 spacing_val = bview->buffer()->params.spacing.getValue();
1434 //lyxerr << "spacing_val = " << spacing_val << endl;
1436 int maxasc = int(lyxfont::maxAscent(font) *
1437 layout.spacing.getValue() *
1439 int maxdesc = int(lyxfont::maxDescent(font) *
1440 layout.spacing.getValue() *
1442 int pos_end = RowLast(row_ptr);
1446 // Check if any insets are larger
1447 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1448 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1449 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1450 tmpinset = row_ptr->par()->GetInset(pos);
1452 tmpinset->update(bview, tmpfont);
1453 asc = tmpinset->ascent(bview->painter(), tmpfont);
1454 desc = tmpinset->descent(bview->painter(), tmpfont);
1455 maxwidth += tmpinset->width(bview->painter(), tmpfont);
1456 maxasc = max(maxasc, asc);
1457 maxdesc = max(maxdesc, desc);
1460 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1464 // Check if any custom fonts are larger (Asger)
1465 // This is not completely correct, but we can live with the small,
1466 // cosmetic error for now.
1467 LyXFont::FONT_SIZE maxsize =
1468 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1470 if (maxsize > font.size()) {
1471 font.setSize(maxsize);
1473 asc = lyxfont::maxAscent(font);
1474 desc = lyxfont::maxDescent(font);
1482 /* table stuff -- begin*/
1483 if (row_ptr->par()->table){
1484 // stretch the rows a bit
1488 /* table stuff -- end*/
1491 // This is nicer with box insets:
1495 row_ptr->ascent_of_text(maxasc);
1497 /* is it a top line? */
1498 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1500 /* some parksips VERY EASY IMPLEMENTATION */
1501 if (bview->buffer()->params.paragraph_separation ==
1502 BufferParams::PARSEP_SKIP) {
1503 if (layout.isParagraph()
1504 && firstpar->GetDepth() == 0
1505 && firstpar->Previous())
1506 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1507 else if (firstpar->Previous()
1508 && textclasslist.Style(bview->buffer()->params.textclass,
1509 firstpar->Previous()->GetLayout()).isParagraph()
1510 && firstpar->Previous()->GetDepth() == 0)
1511 // is it right to use defskip here too? (AS)
1512 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1515 /* the paper margins */
1516 if (!row_ptr->par()->previous && bv_owner)
1517 maxasc += LYX_PAPER_MARGIN;
1519 /* add the vertical spaces, that the user added */
1520 if (firstpar->added_space_top.kind() != VSpace::NONE)
1521 maxasc += int(firstpar->added_space_top.inPixels(bview));
1523 /* do not forget the DTP-lines!
1524 * there height depends on the font of the nearest character */
1525 if (firstpar->line_top)
1526 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1529 /* and now the pagebreaks */
1530 if (firstpar->pagebreak_top)
1531 maxasc += 3 * DefaultHeight();
1533 /* this is special code for the chapter, since the label of this
1534 * layout is printed in an extra row */
1535 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1536 && bview->buffer()->params.secnumdepth >= 0) {
1537 float spacing_val = 1.0;
1538 if (!row_ptr->par()->spacing.isDefault()) {
1539 spacing_val = row_ptr->par()->spacing.getValue();
1541 spacing_val = bview->buffer()->params.spacing.getValue();
1544 labeladdon = int(lyxfont::maxDescent(labelfont) *
1545 layout.spacing.getValue() *
1547 + int(lyxfont::maxAscent(labelfont) *
1548 layout.spacing.getValue() *
1552 /* special code for the top label */
1553 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1554 || layout.labeltype == LABEL_BIBLIO
1555 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1556 && row_ptr->par()->IsFirstInSequence()
1557 && !row_ptr->par()->GetLabelstring().empty()) {
1558 float spacing_val = 1.0;
1559 if (!row_ptr->par()->spacing.isDefault()) {
1560 spacing_val = row_ptr->par()->spacing.getValue();
1562 spacing_val = bview->buffer()->params.spacing.getValue();
1566 (lyxfont::maxAscent(labelfont) *
1567 layout.spacing.getValue() *
1569 +(lyxfont::maxDescent(labelfont) *
1570 layout.spacing.getValue() *
1572 + layout.topsep * DefaultHeight()
1573 + layout.labelbottomsep * DefaultHeight());
1576 /* and now the layout spaces, for example before and after a section,
1577 * or between the items of a itemize or enumerate environment */
1579 if (!firstpar->pagebreak_top) {
1580 LyXParagraph * prev = row_ptr->par()->Previous();
1582 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1583 if (prev && prev->GetLayout() == firstpar->GetLayout()
1584 && prev->GetDepth() == firstpar->GetDepth()
1585 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1587 layoutasc = (layout.itemsep * DefaultHeight());
1589 else if (row_ptr->previous()) {
1590 tmptop = layout.topsep;
1592 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1593 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1594 row_ptr->previous()->par()->
1595 GetLayout()).bottomsep;
1598 layoutasc = (tmptop * DefaultHeight());
1600 else if (row_ptr->par()->line_top){
1601 tmptop = layout.topsep;
1604 layoutasc = (tmptop * DefaultHeight());
1607 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1609 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1610 prev->GetLayout()).parsep * DefaultHeight());
1613 if (firstpar->Previous()
1614 && firstpar->Previous()->GetDepth() == 0
1615 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1618 else if (firstpar->Previous()){
1619 maxasc += int(layout.parsep * DefaultHeight());
1625 /* is it a bottom line? */
1626 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1627 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1629 /* the paper margins */
1630 if (!par->next && bv_owner)
1631 maxdesc += LYX_PAPER_MARGIN;
1633 /* add the vertical spaces, that the user added */
1634 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1635 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1637 /* do not forget the DTP-lines!
1638 * there height depends on the font of the nearest character */
1639 if (firstpar->line_bottom)
1640 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1641 par, par->Last() - 1));
1643 /* and now the pagebreaks */
1644 if (firstpar->pagebreak_bottom)
1645 maxdesc += 3 * DefaultHeight();
1647 /* and now the layout spaces, for example before and after a section,
1648 * or between the items of a itemize or enumerate environment */
1649 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1650 LyXParagraph * nextpar = row_ptr->par()->Next();
1651 LyXParagraph * comparepar = row_ptr->par();
1655 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1656 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1657 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1658 if (comparepar->GetLayout()!= nextpar->GetLayout()
1659 || nextpar->GetLabelWidthString() !=
1660 comparepar->GetLabelWidthString())
1661 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1663 if (unusual > usual)
1664 layoutdesc = unusual;
1668 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1670 if (comparepar->GetLayout()!= nextpar->GetLayout()
1671 || nextpar->GetLabelWidthString() !=
1672 comparepar->GetLabelWidthString())
1673 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1678 /* incalculate the layout spaces */
1679 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1680 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1683 /* table stuff -- begin*/
1684 if (row_ptr->par()->table){
1685 maxasc += row_ptr->par()->table->
1686 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1688 /* table stuff -- end*/
1690 /* calculate the new height of the text */
1691 height -= row_ptr->height();
1693 row_ptr->height(maxasc + maxdesc + labeladdon);
1694 row_ptr->baseline(maxasc + labeladdon);
1696 height += row_ptr->height();
1698 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
1699 row_ptr->width(maxwidth+x);
1702 width = max(0,workWidth(bview));
1704 if (r->width() > width)
1712 /* Appends the implicit specified paragraph behind the specified row,
1713 * start at the implicit given position */
1714 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1716 bool not_ready = true;
1718 // The last character position of a paragraph is an invariant so we can
1719 // safely get it here. (Asger)
1720 int lastposition = row->par()->Last();
1723 // Get the next breakpoint
1724 int z = NextBreakPoint(bview, row, workWidth(bview));
1728 // Insert the new row
1729 if (z < lastposition) {
1731 InsertRow(row, row->par(), z);
1738 // Set the dimensions of the row
1739 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1740 SetHeightOfRow(bview, tmprow);
1742 } while (not_ready);
1746 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1748 bool not_ready = true;
1751 /* get the next breakpoint */
1752 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1755 if (z < row->par()->Last() ) {
1756 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1759 InsertRow(row, row->par(), z);
1765 if (row->pos() == z)
1766 not_ready = false; // the rest will not change
1772 /* if there are some rows too much, delete them */
1773 /* only if you broke the whole paragraph! */
1774 Row * tmprow2 = row;
1775 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1776 tmprow2 = tmprow2->next();
1778 while (tmprow2 != row) {
1779 tmprow2 = tmprow2->previous();
1780 RemoveRow(tmprow2->next());
1785 /* set the dimensions of the row */
1786 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1787 SetHeightOfRow(bview, tmprow);
1788 } while (not_ready);
1792 // this is just a little changed version of break again
1793 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1795 // get the next breakpoint
1796 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1799 if (z < row->par()->Last() ) {
1801 || (row->next() && row->next()->par() != row->par())) {
1802 /* insert a new row */
1804 InsertRow(row, row->par(), z);
1810 if (row->pos() != z)
1814 // if there are some rows too much, delete them
1815 // only if you broke the whole paragraph!
1816 Row * tmprow2 = row;
1817 while (tmprow2->next()
1818 && tmprow2->next()->par() == row->par()) {
1819 tmprow2 = tmprow2->next();
1821 while (tmprow2 != row) {
1822 tmprow2 = tmprow2->previous();
1823 RemoveRow(tmprow2->next());
1827 // set the dimensions of the row
1828 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1829 SetHeightOfRow(bview, tmprow);
1833 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1835 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1836 cursor.par()->GetLayout());
1838 /* table stuff -- begin */
1839 if (cursor.par()->table) {
1840 // breaking of tables is only allowed at the beginning or the end */
1841 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1842 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1843 return; // no breaking of tables allowed
1845 /* table stuff -- end */
1847 // this is only allowed, if the current paragraph is not empty or caption
1848 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1850 layout.labeltype!= LABEL_SENSITIVE)
1853 SetUndo(bview->buffer(), Undo::INSERT,
1854 cursor.par()->ParFromPos(cursor.pos())->previous,
1855 cursor.par()->ParFromPos(cursor.pos())->next);
1858 /* table stuff -- begin */
1859 if (cursor.par()->table) {
1860 int cell = NumberOfCell(cursor.par(), cursor.pos());
1861 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1862 SetCursor(bview, cursor.par(), cursor.par()->size());
1864 /* table stuff -- end */
1866 // please break always behind a space
1867 if (cursor.pos() < cursor.par()->Last()
1868 && cursor.par()->IsLineSeparator(cursor.pos()))
1869 cursor.pos(cursor.pos() + 1);
1871 // break the paragraph
1875 keep_layout = layout.isEnvironment();
1876 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1879 /* table stuff -- begin */
1880 if (cursor.par()->table){
1881 // the table should stay with the contents
1883 cursor.par()->Next()->table = cursor.par()->table;
1884 cursor.par()->table = 0;
1887 /* table stuff -- end */
1889 // well this is the caption hack since one caption is really enough
1890 if (layout.labeltype == LABEL_SENSITIVE) {
1892 // set to standard-layout
1893 cursor.par()->SetLayout(bview->buffer()->params, 0);
1895 // set to standard-layout
1896 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1899 /* if the cursor is at the beginning of a row without prior newline,
1901 * This touches only the screen-update. Otherwise we would may have
1902 * an empty row on the screen */
1903 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1904 cursor.row()->pos() == cursor.pos()) {
1908 status = LyXText::NEED_MORE_REFRESH;
1909 refresh_row = cursor.row();
1910 refresh_y = cursor.y() - cursor.row()->baseline();
1912 // Do not forget the special right address boxes
1913 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1914 while (refresh_row->previous() &&
1915 refresh_row->previous()->par() == refresh_row->par()) {
1916 refresh_row = refresh_row->previous();
1917 refresh_y -= refresh_row->height();
1920 RemoveParagraph(cursor.row());
1922 // set the dimensions of the cursor row
1923 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1925 SetHeightOfRow(bview, cursor.row());
1927 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1928 && cursor.par()->Next()->IsNewline(0))
1929 cursor.par()->Next()->Erase(0);
1931 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1933 UpdateCounters(bview, cursor.row()->previous());
1935 /* This check is necessary. Otherwise the new empty paragraph will
1936 * be deleted automatically. And it is more friendly for the user! */
1938 SetCursor(bview, cursor.par()->Next(), 0);
1940 SetCursor(bview, cursor.par(), 0);
1942 if (cursor.row()->next())
1943 BreakAgain(bview, cursor.row()->next());
1950 void LyXText::OpenFootnote(BufferView * bview)
1952 LyXParagraph * endpar,* tmppar;
1955 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1957 /* if there is no footnote in this paragraph, just return. */
1959 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1962 /* ok, move the cursor right before the footnote */
1964 /* just a little faster than using CursorRight() */
1966 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1967 cursor.pos(cursor.pos() + 1);
1970 /* now the cursor is at the beginning of the physical par */
1971 SetCursor(bview, cursor.par(),
1972 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1974 /* the cursor must be exactly before the footnote */
1975 par = cursor.par()->ParFromPos(cursor.pos());
1977 status = LyXText::NEED_MORE_REFRESH;
1978 refresh_row = cursor.row();
1979 refresh_y = cursor.y() - cursor.row()->baseline();
1981 tmppar = cursor.par();
1982 endpar = cursor.par()->Next();
1985 tmppar->OpenFootnote(cursor.pos());
1986 RemoveParagraph(row);
1987 /* set the dimensions of the cursor row */
1988 row->fill(Fill(bview, row, workWidth(bview)));
1989 SetHeightOfRow(bview, row);
1990 // CHECK See comment on top of text.C
1991 tmppar = tmppar->Next();
1993 while (tmppar != endpar) {
1995 InsertParagraph(bview, tmppar, row);
1996 while (row->next() && row->next()->par() == tmppar)
1998 tmppar = tmppar->Next();
2001 SetCursor(bview, par->next, 0);
2002 sel_cursor = cursor;
2008 /* table stuff -- begin*/
2010 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
2012 if (!cursor.par()->table)
2013 return; /* this should never happen */
2015 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2016 SetUndo(bview->buffer(), Undo::FINISH,
2017 cursor.par()->ParFromPos(cursor.pos())->previous,
2018 cursor.par()->ParFromPos(cursor.pos())->next);
2021 case LyXTable::SET_PWIDTH:
2022 cursor.par()->table->SetPWidth(actCell, val);
2024 case LyXTable::SET_SPECIAL_COLUMN:
2025 case LyXTable::SET_SPECIAL_MULTI:
2026 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2031 RedoParagraph(bview);
2035 void LyXText::TableFeatures(BufferView * bview, int feature) const
2038 int setAlign = LYX_ALIGN_LEFT;
2042 if (!cursor.par()->table)
2043 return; /* this should never happen */
2045 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2046 SetUndo(bview->buffer(), Undo::FINISH,
2047 cursor.par()->ParFromPos(cursor.pos())->previous,
2048 cursor.par()->ParFromPos(cursor.pos())->next);
2051 case LyXTable::ALIGN_LEFT:
2052 setAlign= LYX_ALIGN_LEFT;
2054 case LyXTable::ALIGN_RIGHT:
2055 setAlign= LYX_ALIGN_RIGHT;
2057 case LyXTable::ALIGN_CENTER:
2058 setAlign= LYX_ALIGN_CENTER;
2064 case LyXTable::APPEND_ROW: {
2065 LyXParagraph::size_type pos = cursor.pos();
2067 /* move to the next row */
2068 int cell_org = actCell;
2069 int cell = cell_org;
2071 // if there is a ContRow following this row I have to add
2072 // the row after the ContRow's
2073 if ((pos < cursor.par()->Last()) &&
2074 cursor.par()->table->RowHasContRow(cell_org)) {
2075 while((pos < cursor.par()->Last()) &&
2076 !cursor.par()->table->IsContRow(cell)) {
2077 while (pos < cursor.par()->Last() &&
2078 !cursor.par()->IsNewline(pos))
2080 if (pos < cursor.par()->Last())
2084 while((pos < cursor.par()->Last()) &&
2085 cursor.par()->table->IsContRow(cell)) {
2086 while (pos < cursor.par()->Last() &&
2087 !cursor.par()->IsNewline(pos))
2089 if (pos < cursor.par()->Last())
2094 if (pos < cursor.par()->Last())
2097 while (pos < cursor.par()->Last() &&
2098 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2099 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2101 if (pos < cursor.par()->Last())
2106 /* insert the new cells */
2107 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2108 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2109 LyXFont font(LyXFont::ALL_INHERIT,lang);
2110 for (int i = 0; i < number; ++i) {
2111 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2114 /* append the row into the table */
2115 cursor.par()->table->AppendRow(cell_org);
2116 RedoParagraph(bview);
2119 case LyXTable::APPEND_CONT_ROW: {
2120 LyXParagraph::size_type pos = cursor.pos();
2121 /* move to the next row */
2122 int cell_org = actCell;
2123 int cell = cell_org;
2125 // if there is already a controw but not for this cell
2126 // the AppendContRow sets only the right values but does
2127 // not actually add a row
2128 if (cursor.par()->table->RowHasContRow(cell_org) &&
2129 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2130 cursor.par()->table->AppendContRow(cell_org);
2131 RedoParagraph(bview);
2134 while (pos < cursor.par()->Last() &&
2136 || !cursor.par()->table->IsFirstCell(cell))){
2137 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2139 if (pos < cursor.par()->Last())
2144 /* insert the new cells */
2145 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2146 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2147 LyXFont font(LyXFont::ALL_INHERIT,lang);
2148 for (int i = 0; i < number; ++i) {
2149 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2152 /* append the row into the table */
2153 cursor.par()->table->AppendContRow(cell_org);
2154 RedoParagraph(bview);
2157 case LyXTable::APPEND_COLUMN: {
2158 LyXParagraph::size_type pos = 0;
2159 int cell_org = actCell;
2161 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2162 LyXFont font(LyXFont::ALL_INHERIT,lang);
2164 if (pos && (cursor.par()->IsNewline(pos-1))){
2165 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2166 cursor.par()->InsertChar(pos,
2167 LyXParagraph::META_NEWLINE,
2169 if (pos <= cursor.pos())
2170 cursor.pos(cursor.pos() + 1);
2176 } while (pos <= cursor.par()->Last());
2177 /* remember that the very last cell doesn't end with a newline.
2178 This saves one byte memory per table ;-) */
2179 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2180 LyXParagraph::size_type last = cursor.par()->Last();
2181 cursor.par()->InsertChar(last,
2182 LyXParagraph::META_NEWLINE, font);
2185 /* append the column into the table */
2186 cursor.par()->table->AppendColumn(cell_org);
2188 RedoParagraph(bview);
2191 case LyXTable::DELETE_ROW:
2192 if (bview->the_locking_inset)
2193 bview->unlockInset(bview->the_locking_inset);
2194 RemoveTableRow(cursor);
2195 RedoParagraph(bview);
2198 case LyXTable::DELETE_COLUMN: {
2199 LyXParagraph::size_type pos = 0;
2200 int cell_org = actCell;
2202 if (bview->the_locking_inset)
2203 bview->unlockInset(bview->the_locking_inset);
2205 if (!pos || (cursor.par()->IsNewline(pos-1))){
2206 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2208 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2209 cursor.par()->Erase(pos);
2210 if (pos < cursor.par()->Last())
2211 cursor.par()->Erase(pos);
2213 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2214 --pos; // because of pos++ below
2219 } while (pos <= cursor.par()->Last());
2221 /* delete the column from the table */
2222 cursor.par()->table->DeleteColumn(cell_org);
2224 /* set the cursor to the beginning of the table, where else? */
2226 RedoParagraph(bview);
2229 case LyXTable::TOGGLE_LINE_TOP:
2230 lineSet = !cursor.par()->table->TopLine(actCell);
2232 cursor.par()->table->SetTopLine(actCell, lineSet);
2234 LyXParagraph::size_type i;
2236 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2237 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2238 cursor.par()->table->SetTopLine(n, lineSet);
2243 RedoParagraph(bview);
2246 case LyXTable::TOGGLE_LINE_BOTTOM:
2247 lineSet = !cursor.par()->table->BottomLine(actCell);
2249 cursor.par()->table->SetBottomLine(actCell, lineSet);
2251 LyXParagraph::size_type i;
2253 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2254 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2255 cursor.par()->table->SetBottomLine(n, lineSet);
2260 RedoParagraph(bview);
2263 case LyXTable::TOGGLE_LINE_LEFT:
2264 lineSet = !cursor.par()->table->LeftLine(actCell);
2266 cursor.par()->table->SetLeftLine(actCell, lineSet);
2268 LyXParagraph::size_type i;
2270 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2271 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2272 cursor.par()->table->SetLeftLine(n, lineSet);
2277 RedoParagraph(bview);
2280 case LyXTable::TOGGLE_LINE_RIGHT:
2281 lineSet = !cursor.par()->table->RightLine(actCell);
2283 cursor.par()->table->SetRightLine(actCell, lineSet);
2286 LyXParagraph::size_type i = sel_start_cursor.pos();
2287 for (; i <= sel_end_cursor.pos(); ++i) {
2288 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2289 cursor.par()->table->SetRightLine(n, lineSet);
2294 RedoParagraph(bview);
2297 case LyXTable::ALIGN_LEFT:
2298 case LyXTable::ALIGN_RIGHT:
2299 case LyXTable::ALIGN_CENTER:
2301 cursor.par()->table->SetAlignment(actCell, setAlign);
2304 LyXParagraph::size_type i = sel_start_cursor.pos();
2305 for (; i <= sel_end_cursor.pos(); ++i) {
2306 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2307 cursor.par()->table->SetAlignment(n, setAlign);
2312 RedoParagraph(bview);
2315 case LyXTable::DELETE_TABLE:
2316 SetCursorIntern(bview, cursor.par(), 0);
2317 delete cursor.par()->table;
2318 cursor.par()->table = 0;
2319 // temporary: Should put table in simple_cut_buffer (with before and after
2320 // dummy-paragraph !!
2321 // not necessar anymore with UNDO :)
2322 for (LyXParagraph::size_type i =
2323 cursor.par()->size() - 1; i >= 0; --i)
2324 cursor.par()->Erase(i);
2325 RedoParagraph(bview);
2328 case LyXTable::MULTICOLUMN: {
2330 // check wether we are completly in a multicol
2331 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2332 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2333 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2334 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2338 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2339 LyXParagraph::size_type pos = cursor.pos();
2340 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2342 for (; newlines; --newlines)
2343 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2344 RedoParagraph(bview);
2348 // selection must be in one row (or no selection)
2350 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2353 RedoParagraph(bview);
2357 if (sel_start_cursor.row() == sel_end_cursor.row()){
2358 LyXParagraph::size_type i;
2360 for (i = sel_start_cursor.pos();
2361 i < sel_end_cursor.pos(); ++i){
2362 if (sel_start_cursor.par()->IsNewline(i)){
2363 sel_start_cursor.par()->Erase(i);
2364 // check for double-blanks
2365 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2367 (i < sel_start_cursor.par()->Last()
2368 && !sel_start_cursor.par()->IsLineSeparator(i)))
2369 sel_start_cursor.par()->InsertChar(i, ' ');
2371 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2377 cursor.par()->table->
2378 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2379 sel_start_cursor.pos()),
2381 cursor.pos(sel_start_cursor.pos());
2382 RedoParagraph(bview);
2386 WriteAlert(_("Impossible Operation!"),
2387 _("Multicolumns can only be horizontally."),
2394 case LyXTable::SET_ALL_LINES:
2396 case LyXTable::UNSET_ALL_LINES:
2398 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2402 LyXParagraph::size_type i;
2404 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2405 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2406 cursor.par()->table->SetAllLines(n, setLines);
2411 RedoParagraph(bview);
2413 case LyXTable::SET_LONGTABLE:
2414 cursor.par()->table->SetLongTable(true);
2416 case LyXTable::UNSET_LONGTABLE:
2417 cursor.par()->table->SetLongTable(false);
2419 case LyXTable::SET_ROTATE_TABLE:
2420 cursor.par()->table->SetRotateTable(true);
2422 case LyXTable::UNSET_ROTATE_TABLE:
2423 cursor.par()->table->SetRotateTable(false);
2425 case LyXTable::SET_ROTATE_CELL:
2427 cursor.par()->table->SetRotateCell(actCell, true);
2429 LyXParagraph::size_type i;
2431 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2432 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2433 cursor.par()->table->SetRotateCell(n, true);
2439 case LyXTable::UNSET_ROTATE_CELL:
2441 cursor.par()->table->SetRotateCell(actCell, false);
2444 LyXParagraph::size_type i = sel_start_cursor.pos();
2445 for (; i <= sel_end_cursor.pos(); ++i) {
2446 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2447 cursor.par()->table->SetRotateCell(n, false);
2453 case LyXTable::SET_LINEBREAKS:
2454 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2456 cursor.par()->table->SetLinebreaks(actCell, what);
2458 LyXParagraph::size_type i;
2460 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2461 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2462 cursor.par()->table->SetLinebreaks(n, what);
2468 case LyXTable::SET_LTFIRSTHEAD:
2469 cursor.par()->table->SetLTHead(actCell, true);
2471 case LyXTable::SET_LTHEAD:
2472 cursor.par()->table->SetLTHead(actCell, false);
2474 case LyXTable::SET_LTFOOT:
2475 cursor.par()->table->SetLTFoot(actCell, false);
2477 case LyXTable::SET_LTLASTFOOT:
2478 cursor.par()->table->SetLTFoot(actCell, true);
2480 case LyXTable::SET_LTNEWPAGE:
2481 what = !cursor.par()->table->LTNewPage(actCell);
2482 cursor.par()->table->SetLTNewPage(actCell, what);
2488 void LyXText::InsertCharInTable(BufferView * bview, char c)
2493 bool jumped_over_space;
2495 /* first check, if there will be two blanks together or a blank at
2496 * the beginning of a paragraph.
2497 * I decided to handle blanks like normal characters, the main
2498 * difference are the special checks when calculating the row.fill
2499 * (blank does not count at the end of a row) and the check here */
2501 LyXFont realtmpfont = real_current_font;
2502 LyXFont rawtmpfont = current_font; /* store the current font.
2503 * This is because of the use
2504 * of cursor movements. The moving
2505 * cursor would refresh the
2508 // Get the font that is used to calculate the baselineskip
2509 LyXParagraph::size_type const lastpos =
2510 cursor.par()->Last();
2511 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2514 jumped_over_space = false;
2515 if (IsLineSeparatorChar(c)) {
2516 if ((cursor.pos() > 0 &&
2517 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2518 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2519 || (cursor.pos() == 0 &&
2520 !(cursor.par()->Previous()
2521 && cursor.par()->Previous()->footnoteflag
2522 == LyXParagraph::OPEN_FOOTNOTE)))
2524 } else if (IsNewlineChar(c)) {
2525 if (!IsEmptyTableCell()) {
2526 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2533 y = cursor.y() - row->baseline();
2534 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2535 * already inserted the character */
2536 cursor.par()->InsertChar(cursor.pos(), c);
2537 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2539 if (!jumped_over_space) {
2540 /* refresh the positions */
2542 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2543 tmprow = tmprow->next();
2544 tmprow->pos(tmprow->pos() + 1);
2548 cursor.pos(cursor.pos() + 1);
2550 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2552 current_font = rawtmpfont;
2553 real_current_font = realtmpfont;
2555 /* check, whether the last character's font has changed. */
2556 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2557 && rawparfont != rawtmpfont)
2558 RedoHeightOfParagraph(bview, cursor);
2562 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2563 LyXParagraph::size_type pos)
2566 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2567 par->GetInset(pos) && par->GetInset(pos)->display()){
2568 par->GetInset(pos)->display(false);
2572 Row * row = GetRow(par, pos, y);
2574 int tmpheight = row->height();
2575 SetHeightOfRow(bview, row);
2577 LyXParagraph::size_type tmp_pos = pos;
2578 /* update the table information */
2579 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2581 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2582 WidthOfCell(bview, par, tmp_pos))) {
2583 LyXCursor tmpcursor = cursor;
2584 SetCursorIntern(bview, par, pos, false);
2585 /* make a complete redraw */
2586 RedoDrawingOfParagraph(bview, cursor);
2590 /* redraw only the row */
2591 LyXCursor tmpcursor = cursor;
2592 SetCursorIntern(bview, par, pos);
2593 //CHECK See comment on top of text.C
2595 refresh_x = cursor.x();
2597 refresh_pos = cursor.pos();
2600 if (tmpheight == row->height())
2601 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2603 status = LyXText::NEED_MORE_REFRESH;
2605 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2610 void LyXText::BackspaceInTable(BufferView * bview)
2612 Row * tmprow, * row;
2615 LyXFont rawtmpfont = current_font;
2616 LyXFont realtmpfont = real_current_font;
2618 // Get the font that is used to calculate the baselineskip
2619 int const lastpos = cursor.par()->Last();
2620 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2623 if (cursor.pos() == 0) {
2624 /* no pasting of table paragraphs */
2628 /* this is the code for a normal backspace, not pasting
2630 SetUndo(bview->buffer(), Undo::DELETE,
2631 cursor.par()->ParFromPos(cursor.pos())->previous,
2632 cursor.par()->ParFromPos(cursor.pos())->next);
2634 CursorLeftIntern(bview);
2636 /* some insets are undeletable here */
2637 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2638 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2643 y = cursor.y() - row->baseline();
2645 /* some special code when deleting a newline. */
2646 if (cursor.par()->IsNewline(cursor.pos())) {
2650 cursor.par()->Erase(cursor.pos());
2652 /* refresh the positions */
2654 while (tmprow->next()
2655 && tmprow->next()->par() == row->par()) {
2656 tmprow = tmprow->next();
2657 tmprow->pos(tmprow->pos() - 1);
2661 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2663 /* check, wether the last characters font has changed. */
2664 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2665 && rawparfont != rawtmpfont)
2666 RedoHeightOfParagraph(bview, cursor);
2668 /* restore the current font
2669 * That is what a user expects! */
2670 current_font = rawtmpfont;
2671 real_current_font = realtmpfont;
2673 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2675 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2676 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2679 /* table stuff -- end*/
2683 // Just a macro to make some thing easier.
2684 void LyXText::RedoParagraph(BufferView * bview) const
2687 RedoParagraphs(bview, cursor, cursor.par()->Next());
2688 SetCursorIntern(bview, cursor.par(), cursor.pos());
2692 /* insert a character, moves all the following breaks in the
2693 * same Paragraph one to the right and make a rebreak */
2694 void LyXText::InsertChar(BufferView * bview, char c)
2696 SetUndo(bview->buffer(), Undo::INSERT,
2697 cursor.par()->ParFromPos(cursor.pos())->previous,
2698 cursor.par()->ParFromPos(cursor.pos())->next);
2700 // When the free-spacing option is set for the current layout,
2701 // disable the double-space checking
2704 textclasslist.Style(bview->buffer()->params.textclass,
2705 cursor.row()->par()->GetLayout()).free_spacing;
2708 /* table stuff -- begin*/
2709 if (cursor.par()->table) {
2710 InsertCharInTable(bview, c);
2714 /* table stuff -- end*/
2716 /* First check, if there will be two blanks together or a blank at
2717 the beginning of a paragraph.
2718 I decided to handle blanks like normal characters, the main
2719 difference are the special checks when calculating the row.fill
2720 (blank does not count at the end of a row) and the check here */
2722 // The bug is triggered when we type in a description environment:
2723 // The current_font is not changed when we go from label to main text
2724 // and it should (along with realtmpfont) when we type the space.
2725 // CHECK There is a bug here! (Asger)
2727 LyXFont realtmpfont = real_current_font;
2728 LyXFont rawtmpfont = current_font; /* store the current font.
2729 * This is because of the use
2730 * of cursor movements. The moving
2731 * cursor would refresh the
2734 // Get the font that is used to calculate the baselineskip
2735 LyXParagraph::size_type lastpos = cursor.par()->Last();
2736 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2739 bool jumped_over_space = false;
2741 if (!freeSpacing && IsLineSeparatorChar(c)) {
2742 if ((cursor.pos() > 0
2743 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2744 || (cursor.pos() > 0
2745 && cursor.par()->IsNewline(cursor.pos() - 1))
2746 || (cursor.pos() == 0
2747 && !(cursor.par()->Previous()
2748 && cursor.par()->Previous()->footnoteflag
2749 == LyXParagraph::OPEN_FOOTNOTE))) {
2750 if (cursor.pos() == 0 )
2751 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2753 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2757 } else if (IsNewlineChar(c)) {
2758 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2759 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2763 /* No newline at first position
2764 * of a paragraph or behind labels.
2765 * TeX does not allow that. */
2767 if (cursor.pos() < cursor.par()->Last() &&
2768 cursor.par()->IsLineSeparator(cursor.pos()))
2769 // newline always after a blank!
2770 CursorRightIntern(bview);
2771 cursor.row()->fill(-1); // to force a new break
2774 // the display inset stuff
2775 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2776 && cursor.row()->par()->GetInset(cursor.row()->pos())
2777 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2778 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2779 cursor.row()->fill(-1); // to force a new break
2781 // get the cursor row fist
2782 Row * row = cursor.row();
2783 long y = cursor.y() - row->baseline();
2784 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2785 * already insertet the character */
2786 cursor.par()->InsertChar(cursor.pos(), c);
2787 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2789 if (!jumped_over_space) {
2790 // refresh the positions
2792 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2793 tmprow = tmprow->next();
2794 tmprow->pos(tmprow->pos() + 1);
2798 // Is there a break one row above
2799 if ((cursor.par()->IsLineSeparator(cursor.pos())
2800 || cursor.par()->IsNewline(cursor.pos())
2801 || cursor.row()->fill() == -1)
2802 && row->previous() && row->previous()->par() == row->par()) {
2803 LyXParagraph::size_type z = NextBreakPoint(bview,
2806 if ( z >= row->pos()) {
2809 // set the dimensions of the row above
2810 row->previous()->fill(Fill(bview,
2814 SetHeightOfRow(bview, row->previous());
2816 y -= row->previous()->height();
2818 refresh_row = row->previous();
2819 status = LyXText::NEED_MORE_REFRESH;
2821 BreakAgainOneRow(bview, row);
2823 current_font = rawtmpfont;
2824 real_current_font = realtmpfont;
2825 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2826 false, cursor.boundary());
2827 // cursor MUST be in row now.
2829 if (row->next() && row->next()->par() == row->par())
2830 need_break_row = row->next();
2834 // check, wether the last characters font has changed.
2835 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2836 && rawparfont != rawtmpfont)
2837 RedoHeightOfParagraph(bview, cursor);
2844 // recalculate the fill of the row
2845 if (row->fill() >= 0) /* needed because a newline
2846 * will set fill to -1. Otherwise
2847 * we would not get a rebreak! */
2848 row->fill(Fill(bview, row, workWidth(bview)));
2849 if (row->fill() < 0 ) {
2852 refresh_x = cursor.x();
2853 refresh_pos = cursor.pos();
2854 status = LyXText::NEED_MORE_REFRESH;
2855 BreakAgainOneRow(bview, row);
2856 // will the cursor be in another row now?
2857 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2858 if (row->next() && row->next()->par() == row->par())
2859 // this should always be true
2861 BreakAgainOneRow(bview, row);
2863 current_font = rawtmpfont;
2864 real_current_font = realtmpfont;
2866 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2868 if (row->next() && row->next()->par() == row->par())
2869 need_break_row = row->next();
2874 refresh_x = cursor.x();
2876 refresh_pos = cursor.pos();
2878 int tmpheight = row->height();
2879 SetHeightOfRow(bview, row);
2880 if (tmpheight == row->height())
2881 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2883 status = LyXText::NEED_MORE_REFRESH;
2885 current_font = rawtmpfont;
2886 real_current_font = realtmpfont;
2887 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2891 // check, wether the last characters font has changed.
2892 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2893 && rawparfont != rawtmpfont) {
2894 RedoHeightOfParagraph(bview, cursor);
2896 // now the special right address boxes
2897 if (textclasslist.Style(bview->buffer()->params.textclass,
2898 cursor.par()->GetLayout()).margintype
2899 == MARGIN_RIGHT_ADDRESS_BOX) {
2900 RedoDrawingOfParagraph(bview, cursor);
2908 void LyXText::charInserted()
2910 // Here we could call FinishUndo for every 20 characters inserted.
2911 // This is from my experience how emacs does it.
2912 static unsigned int counter = 0;
2922 void LyXText::PrepareToPrint(BufferView * bview,
2923 Row * row, float & x,
2924 float & fill_separator,
2926 float & fill_label_hfill,
2931 float w = row->fill();
2933 fill_label_hfill = 0;
2935 fill_label_hfill = 0;
2938 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2941 x = RightMargin(bview->buffer(), row);
2942 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2943 LyXFont font(LyXFont::ALL_SANE);
2944 font.setSize(LyXFont::SIZE_SMALL);
2945 x += lyxfont::width("Mwide-figM", font);
2949 if (workWidth(bview) > 0)
2950 x = LeftMargin(bview, row);
2954 // is there a manual margin with a manual label
2955 if (textclasslist.Style(bview->buffer()->params.textclass,
2956 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2957 && textclasslist.Style(bview->buffer()->params.textclass,
2958 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2960 /* one more since labels are left aligned */
2961 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2962 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2963 fill_label_hfill = LabelFill(bview, row) / nlh;
2967 // are there any hfills in the row?
2968 float nh = NumberOfHfills(bview->buffer(), row);
2971 /* table stuff -- begin*/
2972 if (row->par()->table) {
2973 w = workWidth(bview) - row->par()->table->WidthOfTable()
2974 - x - RightMargin(bview->buffer(), row);
2975 nh = 0; /* ignore hfills in tables */
2977 /* table stuff -- end*/
2982 // is it block, flushleft or flushright?
2983 // set x how you need it
2985 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2986 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2988 align = row->par()->FirstPhysicalPar()->align;
2990 // center displayed insets
2991 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2992 && row->par()->GetInset(row->pos())
2993 && row->par()->GetInset(row->pos())->display())
2994 align = LYX_ALIGN_CENTER;
2997 case LYX_ALIGN_BLOCK:
2998 ns = NumberOfSeparators(bview->buffer(), row);
2999 if (ns && row->next() && row->next()->par() == row->par() &&
3000 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
3001 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
3002 && row->next()->par()->GetInset(row->next()->pos())
3003 && row->next()->par()->GetInset(row->next()->pos())->display())
3005 fill_separator = w / ns;
3009 case LYX_ALIGN_RIGHT:
3012 case LYX_ALIGN_CENTER:
3020 ComputeBidiTables(bview->buffer(), row);
3022 LyXParagraph::size_type main_body =
3023 BeginningOfMainBody(bview->buffer(), row->par());
3024 LyXParagraph::size_type last = RowLast(row);
3026 if (main_body > 0 &&
3027 (main_body-1 > last ||
3028 !row->par()->IsLineSeparator(main_body-1))) {
3029 LyXLayout const & layout =
3030 textclasslist.Style(bview->buffer()->params.textclass,
3031 row->par()->GetLayout());
3032 x += lyxfont::width(layout.labelsep,
3033 GetFont(bview->buffer(), row->par(), -2));
3034 if (main_body-1 <= last)
3035 x += fill_label_hfill;
3040 /* important for the screen */
3043 /* the cursor set functions have a special mechanism. When they
3044 * realize, that you left an empty paragraph, they will delete it.
3045 * They also delete the corresponding row */
3047 void LyXText::CursorRightOneWord(BufferView * bview) const
3049 // treat floats, HFills and Insets as words
3050 LyXCursor tmpcursor = cursor;
3051 // CHECK See comment on top of text.C
3053 if (tmpcursor.pos() == tmpcursor.par()->Last()
3054 && tmpcursor.par()->Next()) {
3055 tmpcursor.par(tmpcursor.par()->Next());
3060 // Skip through initial nonword stuff.
3061 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3062 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3064 // printf("Current pos1 %d", tmpcursor.pos()) ;
3065 tmpcursor.pos(tmpcursor.pos() + 1);
3068 // Advance through word.
3069 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3070 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3072 // printf("Current pos2 %d", tmpcursor.pos()) ;
3073 tmpcursor.pos(tmpcursor.pos() + 1);
3077 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3081 void LyXText::CursorTab(BufferView * bview) const
3084 if (cursor.par()->table) {
3085 int cell = NumberOfCell(cursor.par(), cursor.pos());
3086 while(cursor.par()->table->IsContRow(cell)) {
3088 cell = NumberOfCell(cursor.par(), cursor.pos());
3090 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3091 TableFeatures(bview, LyXTable::APPEND_ROW);
3094 LyXCursor tmpcursor = cursor;
3095 while (tmpcursor.pos() < tmpcursor.par()->Last()
3096 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3097 tmpcursor.pos(tmpcursor.pos() + 1);
3099 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3100 if (tmpcursor.par()->Next()) {
3101 tmpcursor.par(tmpcursor.par()->Next());
3105 tmpcursor.pos(tmpcursor.pos() + 1);
3106 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3108 if (cursor.par()->table) {
3109 int cell = NumberOfCell(cursor.par(), cursor.pos());
3110 while (cursor.par()->table->IsContRow(cell) &&
3111 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3113 while (tmpcursor.pos() < tmpcursor.par()->Last()
3114 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3115 tmpcursor.pos(tmpcursor.pos() + 1);
3117 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3118 if (tmpcursor.par()->Next()) {
3119 tmpcursor.par(tmpcursor.par()->Next());
3123 tmpcursor.pos(tmpcursor.pos() + 1);
3124 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3125 cell = NumberOfCell(cursor.par(), cursor.pos());
3132 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3133 of prior word, not to end of next prior word. */
3135 void LyXText::CursorLeftOneWord(BufferView * bview) const
3137 // treat HFills, floats and Insets as words
3138 LyXCursor tmpcursor = cursor;
3139 while (tmpcursor.pos()
3140 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3141 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3142 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3143 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3144 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3145 tmpcursor.pos(tmpcursor.pos() - 1);
3148 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3149 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3150 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3151 tmpcursor.pos(tmpcursor.pos() - 1);
3152 } else if (!tmpcursor.pos()) {
3153 if (tmpcursor.par()->Previous()){
3154 tmpcursor.par(tmpcursor.par()->Previous());
3155 tmpcursor.pos(tmpcursor.par()->Last());
3157 } else { // Here, tmpcursor != 0
3158 while (tmpcursor.pos() > 0 &&
3159 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3160 tmpcursor.pos(tmpcursor.pos() - 1);
3162 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3165 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3168 void LyXText::SelectWord(BufferView * bview)
3170 // Move cursor to the beginning, when not already there.
3172 && !cursor.par()->IsSeparator(cursor.pos()-1)
3173 && !cursor.par()->IsKomma(cursor.pos()-1) )
3174 CursorLeftOneWord(bview);
3176 // set the sel cursor
3177 sel_cursor = cursor;
3179 while ( cursor.pos() < cursor.par()->Last()
3180 && !cursor.par()->IsSeparator(cursor.pos())
3181 && !cursor.par()->IsKomma(cursor.pos()) )
3182 cursor.pos(cursor.pos() + 1);
3183 SetCursor(bview, cursor.par(), cursor.pos() );
3185 // finally set the selection
3190 /* -------> Select the word currently under the cursor when:
3191 1: no selection is currently set,
3192 2: the cursor is not at the borders of the word. */
3194 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3197 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3198 && !cursor.par()->IsSeparator(cursor.pos())
3199 && !cursor.par()->IsKomma(cursor.pos())
3200 && !cursor.par()->IsSeparator(cursor.pos() -1)
3201 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3209 // This function is only used by the spellchecker for NextWord().
3210 // It doesn't handle LYX_ACCENTs and probably never will.
3211 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3213 LyXParagraph * tmppar = cursor.par();
3215 // If this is not the very first word, skip rest of
3216 // current word because we are probably in the middle
3217 // of a word if there is text here.
3218 if (cursor.pos() || cursor.par()->previous) {
3219 while (cursor.pos() < cursor.par()->Last()
3220 && cursor.par()->IsLetter(cursor.pos()))
3221 cursor.pos(cursor.pos() + 1);
3223 // Now, skip until we have real text (will jump paragraphs)
3224 while ((cursor.par()->Last() > cursor.pos()
3225 && (!cursor.par()->IsLetter(cursor.pos())
3226 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3227 .latex() == LyXFont::ON))
3228 || (cursor.par()->Last() == cursor.pos()
3229 && cursor.par()->Next())){
3230 if (cursor.pos() == cursor.par()->Last()) {
3231 cursor.par(cursor.par()->Next());
3234 cursor.pos(cursor.pos() + 1);
3237 // Update the value if we changed paragraphs
3238 if (cursor.par() != tmppar){
3239 SetCursor(bview, cursor.par(), cursor.pos());
3240 value = float(cursor.y())/float(height);
3243 // Start the selection from here
3244 sel_cursor = cursor;
3247 std::ostringstream latex;
3251 // and find the end of the word
3252 // (optional hyphens are part of a 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 && latex.str() // protect against null pointers
3262 && string(latex.str(), 3) == "\\-" // this is not nice at all
3265 cursor.pos(cursor.pos() + 1);
3267 #ifndef HAVE_SSTREAM
3268 delete [] latex.str();
3270 // Finally, we copy the word to a string and return it
3273 if (sel_cursor.pos() < cursor.pos()) {
3274 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3275 LyXParagraph::size_type i, j;
3276 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3277 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3278 str[j++] = cursor.par()->GetChar(i);
3286 // This one is also only for the spellchecker
3287 void LyXText::SelectSelectedWord(BufferView * bview)
3289 // move cursor to the beginning
3290 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3292 // set the sel cursor
3293 sel_cursor = cursor;
3296 std::ostringstream latex;
3301 // now find the end of the word
3302 while (cursor.pos() < cursor.par()->Last()
3303 && (cursor.par()->IsLetter(cursor.pos())
3304 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3305 && cursor.par()->GetInset(cursor.pos()) != 0
3306 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3308 && latex.str() == "\\-"
3310 && string(latex.str(), 3) == "\\-"
3313 cursor.pos(cursor.pos() + 1);
3315 #ifndef HAVE_SSTREAM
3316 delete [] latex.str();
3318 SetCursor(bview, cursor.par(), cursor.pos());
3320 // finally set the selection
3325 /* -------> Delete from cursor up to the end of the current or next word. */
3326 void LyXText::DeleteWordForward(BufferView * bview)
3328 if (!cursor.par()->Last())
3331 LyXCursor tmpcursor = cursor;
3332 tmpcursor.row(0); //Â ??
3333 selection = true; // to avoid deletion
3334 CursorRightOneWord(bview);
3335 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3336 sel_cursor = cursor;
3340 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3341 CutSelection(bview);
3346 /* -------> Delete from cursor to start of current or prior word. */
3347 void LyXText::DeleteWordBackward(BufferView * bview)
3349 if (!cursor.par()->Last())
3352 LyXCursor tmpcursor = cursor;
3353 tmpcursor.row(0); // ??
3354 selection = true; // to avoid deletion
3355 CursorLeftOneWord(bview);
3356 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3357 sel_cursor = cursor;
3360 CutSelection(bview);
3365 /* -------> Kill to end of line. */
3366 void LyXText::DeleteLineForward(BufferView * bview)
3368 if (!cursor.par()->Last())
3369 // Paragraph is empty, so we just go to the right
3372 LyXCursor tmpcursor = cursor;
3373 // We can't store the row over a regular SetCursor
3374 // so we set it to 0 and reset it afterwards.
3375 tmpcursor.row(0); //Â ??
3376 selection = true; // to avoid deletion
3378 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3379 sel_cursor = cursor;
3382 // What is this test for ??? (JMarc)
3384 DeleteWordForward(bview);
3386 CutSelection(bview);
3392 // Change the case of a word at cursor position.
3393 // This function directly manipulates LyXParagraph::text because there
3394 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3395 // that it is correct. I guess part of it should be moved to
3396 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3397 // it does not access outside of the allocated array as the older
3398 // version did. (JMarc)
3399 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3401 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3403 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3405 LyXParagraph::size_type tmppos =
3406 cursor.par()->PositionInParFromPos(cursor.pos());
3407 while (tmppos < tmppar->size()) {
3408 unsigned char c = tmppar->GetChar(tmppos);
3409 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3411 if (c != LyXParagraph::META_INSET) {
3413 case text_lowercase:
3416 case text_capitalization:
3418 action = text_lowercase;
3420 case text_uppercase:
3426 //tmppar->text[tmppos] = c;
3427 tmppar->SetChar(tmppos, c);
3430 CheckParagraph(bview, tmppar, tmppos);
3431 CursorRightOneWord(bview);
3435 void LyXText::Delete(BufferView * bview)
3437 // this is a very easy implementation
3439 LyXCursor old_cursor = cursor;
3440 int old_cur_par_id = old_cursor.par()->id();
3441 int old_cur_par_prev_id = old_cursor.par()->previous ?
3442 old_cursor.par()->previous->id() : 0;
3444 // just move to the right
3445 CursorRightIntern(bview);
3447 // CHECK Look at the comment here.
3448 // This check is not very good...
3449 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3450 // and that can very well delete the par or par->previous in
3451 // old_cursor. Will a solution where we compare paragraph id's
3453 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3454 == old_cur_par_prev_id
3455 && cursor.par()->id() != old_cur_par_id)
3456 return; // delete-empty-paragraph-mechanism has done it
3458 // if you had success make a backspace
3459 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3460 LyXCursor tmpcursor = cursor;
3461 cursor = old_cursor; // to make sure undo gets the right cursor position
3462 SetUndo(bview->buffer(), Undo::DELETE,
3463 cursor.par()->ParFromPos(cursor.pos())->previous,
3464 cursor.par()->ParFromPos(cursor.pos())->next);
3471 void LyXText::Backspace(BufferView * bview)
3474 /* table stuff -- begin */
3475 if (cursor.par()->table) {
3476 BackspaceInTable(bview);
3479 /* table stuff -- end */
3481 // LyXFont rawtmpfont = current_font;
3482 // LyXFont realtmpfont = real_current_font;
3483 // We don't need the above variables as calling to SetCursor() with third
3484 // argument eqaul to false, will not change current_font & real_current_font
3486 // Get the font that is used to calculate the baselineskip
3487 LyXParagraph::size_type lastpos = cursor.par()->Last();
3488 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3491 if (cursor.pos() == 0) {
3492 // The cursor is at the beginning of a paragraph, so the the backspace
3493 // will collapse two paragraphs into one.
3495 // we may paste some paragraphs
3497 // is it an empty paragraph?
3500 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3501 && !(cursor.par()->Next()
3502 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3503 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3504 // This is an empty paragraph and we delete it just by moving the cursor one step
3505 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3506 // of the paragraph.
3508 if (cursor.par()->previous) {
3509 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3510 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3511 && cursor.par()->footnoteflag == tmppar->footnoteflag
3512 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3513 // Inherit botom DTD from the paragraph below.
3514 // (the one we are deleting)
3515 tmppar->line_bottom = cursor.par()->line_bottom;
3516 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3517 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3520 CursorLeftIntern(bview);
3522 // the layout things can change the height of a row !
3523 int tmpheight = cursor.row()->height();
3524 SetHeightOfRow(bview, cursor.row());
3525 if (cursor.row()->height() != tmpheight) {
3526 refresh_y = cursor.y() - cursor.row()->baseline();
3527 refresh_row = cursor.row();
3528 status = LyXText::NEED_MORE_REFRESH;
3534 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3535 SetUndo(bview->buffer(), Undo::DELETE,
3536 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3537 cursor.par()->ParFromPos(cursor.pos())->next);
3540 LyXParagraph * tmppar = cursor.par();
3541 Row * tmprow = cursor.row();
3543 // We used to do CursorLeftIntern() here, but it is
3544 // not a good idea since it triggers the auto-delete
3545 // mechanism. So we do a CursorLeftIntern()-lite,
3546 // without the dreaded mechanism. (JMarc)
3547 if (cursor.par()->Previous()) {
3548 // steps into the above paragraph.
3549 SetCursorIntern(bview, cursor.par()->Previous(),
3550 cursor.par()->Previous()->Last(), false);
3553 /* Pasting is not allowed, if the paragraphs have different
3554 layout. I think it is a real bug of all other
3555 word processors to allow it. It confuses the user.
3556 Even so with a footnote paragraph and a non-footnote
3557 paragraph. I will not allow pasting in this case,
3558 because the user would be confused if the footnote behaves
3559 different wether it is open or closed.
3561 Correction: Pasting is always allowed with standard-layout
3563 if (cursor.par() != tmppar
3564 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3565 || tmppar->GetLayout() == 0 /*standard*/)
3566 && cursor.par()->footnoteflag == tmppar->footnoteflag
3568 /* table stuff -- begin*/
3569 && !cursor.par()->table /* no pasting of tables */
3570 /* table stuff -- end*/
3572 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3574 RemoveParagraph(tmprow);
3576 cursor.par()->PasteParagraph(bview->buffer()->params);
3578 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3579 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3580 // strangely enough it seems that commenting out the line above removes
3581 // most or all of the segfaults. I will however also try to move the
3582 // two Remove... lines in front of the PasteParagraph too.
3585 cursor.pos(cursor.pos() - 1);
3587 status = LyXText::NEED_MORE_REFRESH;
3588 refresh_row = cursor.row();
3589 refresh_y = cursor.y() - cursor.row()->baseline();
3591 // remove the lost paragraph
3592 // This one is not safe, since the paragraph that the tmprow and the
3593 // following rows belong to has been deleted by the PasteParagraph
3594 // above. The question is... could this be moved in front of the
3596 //RemoveParagraph(tmprow);
3597 //RemoveRow(tmprow);
3599 // This rebuilds the rows.
3600 AppendParagraph(bview, cursor.row());
3601 UpdateCounters(bview, cursor.row());
3603 // the row may have changed, block, hfills etc.
3604 SetCursor(bview, cursor.par(), cursor.pos(), false);
3607 /* this is the code for a normal backspace, not pasting
3609 SetUndo(bview->buffer(), Undo::DELETE,
3610 cursor.par()->ParFromPos(cursor.pos())->previous,
3611 cursor.par()->ParFromPos(cursor.pos())->next);
3612 // We used to do CursorLeftIntern() here, but it is
3613 // not a good idea since it triggers the auto-delete
3614 // mechanism. So we do a CursorLeftIntern()-lite,
3615 // without the dreaded mechanism. (JMarc)
3616 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3617 false, cursor.boundary());
3619 // some insets are undeletable here
3620 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3621 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3623 // force complete redo when erasing display insets
3624 // this is a cruel method but safe..... Matthias
3625 if (cursor.par()->GetInset(cursor.pos())->display() ||
3626 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
3627 cursor.par()->Erase(cursor.pos());
3628 RedoParagraph(bview);
3633 Row * row = cursor.row();
3634 long y = cursor.y() - row->baseline();
3635 LyXParagraph::size_type z;
3636 /* remember that a space at the end of a row doesnt count
3637 * when calculating the fill */
3638 if (cursor.pos() < RowLast(row) ||
3639 !cursor.par()->IsLineSeparator(cursor.pos())) {
3640 row->fill(row->fill() + SingleWidth(bview,
3645 /* some special code when deleting a newline. This is similar
3646 * to the behavior when pasting paragraphs */
3647 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3648 cursor.par()->Erase(cursor.pos());
3649 // refresh the positions
3651 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3652 tmprow = tmprow->next();
3653 tmprow->pos(tmprow->pos() - 1);
3655 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3656 cursor.pos(cursor.pos() - 1);
3658 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3659 cursor.par()->InsertChar(cursor.pos(), ' ');
3660 // refresh the positions
3662 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3663 tmprow = tmprow->next();
3664 tmprow->pos(tmprow->pos() + 1);
3668 cursor.par()->Erase(cursor.pos());
3670 // refresh the positions
3672 while (tmprow->next()
3673 && tmprow->next()->par() == row->par()) {
3674 tmprow = tmprow->next();
3675 tmprow->pos(tmprow->pos() - 1);
3678 // delete newlines at the beginning of paragraphs
3679 while (cursor.par()->Last() &&
3680 cursor.par()->IsNewline(cursor.pos()) &&
3681 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3683 cursor.par()->Erase(cursor.pos());
3684 // refresh the positions
3686 while (tmprow->next() &&
3687 tmprow->next()->par() == row->par()) {
3688 tmprow = tmprow->next();
3689 tmprow->pos(tmprow->pos() - 1);
3694 // is there a break one row above
3695 if (row->previous() && row->previous()->par() == row->par()) {
3696 z = NextBreakPoint(bview, row->previous(),
3698 if ( z >= row->pos()) {
3701 Row * tmprow = row->previous();
3703 // maybe the current row is now empty
3704 if (row->pos() >= row->par()->Last()) {
3709 BreakAgainOneRow(bview, row);
3710 if (row->next() && row->next()->par() == row->par())
3711 need_break_row = row->next();
3716 // set the dimensions of the row above
3717 y -= tmprow->height();
3718 tmprow->fill(Fill(bview, tmprow,
3720 SetHeightOfRow(bview, tmprow);
3723 refresh_row = tmprow;
3724 status = LyXText::NEED_MORE_REFRESH;
3725 SetCursor(bview, cursor.par(), cursor.pos(),
3726 false, cursor.boundary());
3727 //current_font = rawtmpfont;
3728 //real_current_font = realtmpfont;
3729 // check, whether the last character's font has changed.
3731 cursor.par()->GetFontSettings(bview->buffer()->params,
3732 cursor.par()->Last() - 1))
3733 RedoHeightOfParagraph(bview, cursor);
3738 // break the cursor row again
3739 z = NextBreakPoint(bview, row, workWidth(bview));
3741 if (z != RowLast(row) ||
3742 (row->next() && row->next()->par() == row->par() &&
3743 RowLast(row) == row->par()->Last() - 1)){
3745 /* it can happen that a paragraph loses one row
3746 * without a real breakup. This is when a word
3747 * is to long to be broken. Well, I don t care this
3749 if (row->next() && row->next()->par() == row->par() &&
3750 RowLast(row) == row->par()->Last() - 1)
3751 RemoveRow(row->next());
3755 status = LyXText::NEED_MORE_REFRESH;
3757 BreakAgainOneRow(bview, row);
3758 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3759 // cursor MUST be in row now
3761 if (row->next() && row->next()->par() == row->par())
3762 need_break_row = row->next();
3766 // set the dimensions of the row
3767 row->fill(Fill(bview, row, workWidth(bview)));
3768 int tmpheight = row->height();
3769 SetHeightOfRow(bview, row);
3770 if (tmpheight == row->height())
3771 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3773 status = LyXText::NEED_MORE_REFRESH;
3776 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3780 // current_font = rawtmpfont;
3781 // real_current_font = realtmpfont;
3783 lastpos = cursor.par()->Last();
3784 if (cursor.pos() == lastpos) {
3785 SetCurrentFont(bview);
3786 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3787 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3790 // check, wether the last characters font has changed.
3792 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3793 RedoHeightOfParagraph(bview, cursor);
3795 // now the special right address boxes
3796 if (textclasslist.Style(bview->buffer()->params.textclass,
3797 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3798 RedoDrawingOfParagraph(bview, cursor);
3804 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3805 Row * row_ptr, long y, bool cleared)
3807 /* returns a printed row */
3808 Painter & pain = bview->painter();
3810 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3811 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3813 LyXParagraph::size_type vpos, pos;
3815 int y_top, y_bottom;
3816 float fill_separator, fill_hfill, fill_label_hfill;
3818 LyXFont font(LyXFont::ALL_SANE);
3820 if (row_ptr->height() <= 0) {
3821 lyxerr << "LYX_ERROR: row.height: "
3822 << row_ptr->height() << endl;
3825 PrepareToPrint(bview, row_ptr, x, fill_separator,
3826 fill_hfill, fill_label_hfill);
3828 if (inset_owner && (x < 0))
3832 // clear the area where we want to paint/print
3834 ww = bview->workWidth();
3836 bool clear_area = true;
3839 if ((last == row_ptr->pos()) &&
3840 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3841 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3843 clear_area = inset->doClearArea();
3845 if (cleared) { // we don't need to clear it's already done!!!
3847 } else if (clear_area) {
3850 w = inset_owner->width(bview->painter(), font);
3853 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3854 } else if (inset != 0) {
3855 int h = row_ptr->baseline() - inset->ascent(pain, font);
3859 w = inset_owner->width(bview->painter(), font);
3862 pain.fillRectangle(x_offset, y_offset, w, h);
3867 /* selection code */
3868 if (bidi_same_direction) {
3869 if (sel_start_cursor.row() == row_ptr &&
3870 sel_end_cursor.row() == row_ptr) {
3871 if (sel_start_cursor.x() < sel_end_cursor.x())
3872 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3874 sel_end_cursor.x() - sel_start_cursor.x(),
3878 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3880 sel_start_cursor.x() - sel_end_cursor.x(),
3883 } else if (sel_start_cursor.row() == row_ptr) {
3885 pain.fillRectangle(x_offset, y_offset,
3886 sel_start_cursor.x(),
3890 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3892 ww - sel_start_cursor.x(),
3895 } else if (sel_end_cursor.row() == row_ptr) {
3897 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3899 ww - sel_end_cursor.x(),
3903 pain.fillRectangle(x_offset, y_offset,
3907 } else if (y > long(sel_start_cursor.y())
3908 && y < long(sel_end_cursor.y())) {
3909 pain.fillRectangle(x_offset, y_offset, ww,
3913 } else if ( sel_start_cursor.row() != row_ptr &&
3914 sel_end_cursor.row() != row_ptr &&
3915 y > long(sel_start_cursor.y())
3916 && y < long(sel_end_cursor.y())) {
3917 pain.fillRectangle(x_offset, y_offset, ww,
3920 } else if (sel_start_cursor.row() == row_ptr ||
3921 sel_end_cursor.row() == row_ptr) {
3925 if (row_ptr->par()->table) {
3926 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3927 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3930 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3931 (sel_end_cursor.row() != row_ptr && is_rtl))
3932 pain.fillRectangle(x_offset, y_offset,
3937 if (row_ptr->par()->table) {
3939 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3940 pos = vis2log(vpos);
3941 float old_tmpx = tmpx;
3942 if (row_ptr->par()->IsNewline(pos)) {
3943 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3946 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3948 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3950 if ( (sel_start_cursor.row() != row_ptr ||
3951 sel_start_cursor.pos() <= pos) &&
3952 (sel_end_cursor.row() != row_ptr ||
3953 pos < sel_end_cursor.pos()) )
3954 pain.fillRectangle(x_offset + int(old_tmpx),
3956 int(tmpx - old_tmpx + 1),
3962 LyXParagraph::size_type main_body =
3963 BeginningOfMainBody(bview->buffer(),
3966 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3967 pos = vis2log(vpos);
3968 float old_tmpx = tmpx;
3969 if (main_body > 0 && pos == main_body-1) {
3970 tmpx += fill_label_hfill +
3971 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3972 row_ptr->par()->GetLayout()).labelsep,
3973 GetFont(bview->buffer(),row_ptr->par(), -2));
3974 if (row_ptr->par()->IsLineSeparator(main_body-1))
3975 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3977 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3978 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3979 if (pos >= main_body)
3982 tmpx += fill_label_hfill;
3984 else if (row_ptr->par()->IsSeparator(pos)) {
3985 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3986 if (pos >= main_body)
3987 tmpx += fill_separator;
3989 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3991 if ( (sel_start_cursor.row() != row_ptr ||
3992 sel_start_cursor.pos() <= pos) &&
3993 (sel_end_cursor.row() != row_ptr ||
3994 pos < sel_end_cursor.pos()) )
3995 pain.fillRectangle(x_offset + int(old_tmpx),
3997 int(tmpx - old_tmpx + 1),
4004 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
4005 (sel_end_cursor.row() != row_ptr && !is_rtl) )
4006 pain.fillRectangle(x_offset + int(tmpx),
4016 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4017 LyXFont font(LyXFont::ALL_SANE);
4018 font.setSize(LyXFont::SIZE_FOOTNOTE);
4019 font.setColor(LColor::footnote);
4021 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
4022 if (row_ptr->previous() &&
4023 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4025 switch (row_ptr->par()->footnotekind) {
4026 case LyXParagraph::MARGIN:
4029 case LyXParagraph::FIG:
4032 case LyXParagraph::TAB:
4035 case LyXParagraph::WIDE_FIG:
4038 case LyXParagraph::WIDE_TAB:
4041 case LyXParagraph::ALGORITHM:
4044 case LyXParagraph::FOOTNOTE:
4049 pain.fillRectangle(LYX_PAPER_MARGIN,
4051 box_x - LYX_PAPER_MARGIN,
4052 int(lyxfont::maxAscent(font)
4053 + lyxfont::maxDescent(font)),
4054 LColor::footnotebg);
4056 pain.line(LYX_PAPER_MARGIN, y_offset,
4057 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4058 LColor::footnoteframe);
4060 pain.text(LYX_PAPER_MARGIN,
4061 y_offset + int(lyxfont::maxAscent(font)) + 1,
4064 pain.line(LYX_PAPER_MARGIN, y_offset,
4066 y_offset + int(lyxfont::maxAscent(font)
4067 + lyxfont::maxDescent(font)),
4068 LColor::footnoteframe);
4070 pain.line(LYX_PAPER_MARGIN,
4071 y_offset + int(lyxfont::maxAscent(font)
4072 + lyxfont::maxDescent(font)) + 1,
4074 y_offset + int(lyxfont::maxAscent(font)
4075 + lyxfont::maxDescent(font)) + 1,
4076 LColor::footnoteframe);
4080 /* draw the open floats in a red box */
4081 pain.line(box_x, y_offset,
4082 box_x, y_offset + row_ptr->height(),
4083 LColor::footnoteframe);
4085 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4087 workWidth(bview) - LYX_PAPER_MARGIN,
4088 y_offset + row_ptr->height(),
4089 LColor::footnoteframe);
4092 // Draw appendix lines
4093 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4095 pain.line(1, y_offset,
4096 1, y_offset + row_ptr->height(),
4097 LColor::appendixline);
4098 pain.line(workWidth(bview) - 2, y_offset,
4099 workWidth(bview) - 2,
4100 y_offset + row_ptr->height(),
4101 LColor::appendixline);
4104 // Draw minipage line
4105 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4107 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4109 y_offset + row_ptr->height() - 1,
4110 LColor::minipageline);
4113 int depth = p->GetDepth();
4114 for (int i = 1; i <= depth; ++i) {
4115 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4116 pain.line(line_x, y_offset, line_x,
4117 y_offset + row_ptr->height() - 1,
4120 } else if (row_ptr->previous() &&
4121 row_ptr->previous()->par()->footnoteflag
4122 == LyXParagraph::OPEN_FOOTNOTE) {
4123 LyXFont font(LyXFont::ALL_SANE);
4124 font.setSize(LyXFont::SIZE_FOOTNOTE);
4126 int box_x = LYX_PAPER_MARGIN;
4127 box_x += lyxfont::width(" wide-tab ", font);
4129 pain.line(box_x, y_offset,
4130 workWidth(bview) - LYX_PAPER_MARGIN,
4131 y_offset, LColor::footnote);
4134 // Draw appendix lines
4135 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4136 if (firstpar->appendix){
4137 pain.line(1, y_offset,
4138 1, y_offset + row_ptr->height(),
4139 LColor::appendixline);
4140 pain.line(ww - 2, y_offset,
4141 ww - 2, y_offset + row_ptr->height(),
4142 LColor::appendixline);
4145 // Draw minipage line
4146 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4148 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4149 LYX_PAPER_MARGIN/5 + box_x,
4150 y_offset + row_ptr->height() - 1,
4151 LColor::minipageline);
4154 int depth = firstpar->GetDepth();
4158 if (row_ptr->next())
4159 if (row_ptr->par()->footnoteflag ==
4160 row_ptr->next()->par()->footnoteflag)
4161 next_depth = row_ptr->next()->par()->GetDepth();
4162 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4165 if (row_ptr->previous())
4166 if (row_ptr->par()->footnoteflag ==
4167 row_ptr->previous()->par()->footnoteflag)
4168 prev_depth = row_ptr->previous()->par()->GetDepth();
4169 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4172 for (int i = 1; i <= depth; ++i) {
4173 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4174 pain.line(line_x, y_offset, line_x,
4175 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4179 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4182 pain.fillRectangle(line_x,
4183 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4184 LYX_PAPER_MARGIN / 5, 2,
4190 LyXLayout const & layout =
4191 textclasslist.Style(bview->buffer()->params.textclass,
4192 row_ptr->par()->GetLayout());
4195 y_bottom = row_ptr->height();
4197 /* is it a first row? */
4198 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4200 /* start of appendix? */
4201 if (row_ptr->par()->start_of_appendix){
4202 pain.line(1, y_offset,
4204 LColor::appendixline);
4207 /* think about the margins */
4208 if (!row_ptr->previous() && bv_owner)
4209 y_top += LYX_PAPER_MARGIN;
4211 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4213 pb_font.setColor(LColor::pagebreak).decSize();
4214 int w = 0, a = 0, d = 0;
4215 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4217 y_offset + y_top + 2 * DefaultHeight(),
4219 Painter::line_onoffdash)
4222 _("Page Break (top)"),
4225 LColor::background, false, w, a, d);
4226 pain.rectText((ww - w)/2,
4227 y_offset + y_top + 2 * DefaultHeight() + d,
4228 _("Page Break (top)"),
4231 LColor::background);
4232 y_top += 3 * DefaultHeight();
4235 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4236 /* draw a vfill top */
4237 pain.line(0, y_offset + 2 + y_top,
4238 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4241 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4243 y_offset + y_top + 3 * DefaultHeight(),
4246 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4247 LYX_PAPER_MARGIN / 2,
4248 y_offset + y_top + 3 * DefaultHeight(),
4251 y_top += 3 * DefaultHeight();
4254 /* think about user added space */
4255 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4257 /* think about the parskip */
4258 /* some parskips VERY EASY IMPLEMENTATION */
4259 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4260 if (layout.latextype == LATEX_PARAGRAPH
4261 && firstpar->GetDepth() == 0
4262 && firstpar->Previous())
4263 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4264 else if (firstpar->Previous()
4265 && textclasslist.Style(bview->buffer()->params.textclass,
4266 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4267 && firstpar->Previous()->GetDepth() == 0)
4268 // is it right to use defskip here, too? (AS)
4269 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4272 if (row_ptr->par()->line_top) { /* draw a top line */
4273 y_top += lyxfont::ascent('x',
4274 GetFont(bview->buffer(),
4275 row_ptr->par(), 0));
4277 pain.line(0, y_offset + y_top,
4278 ww, y_offset + y_top,
4280 Painter::line_solid,
4281 Painter::line_thick);
4283 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4284 row_ptr->par(), 0));
4287 /* should we print a label? */
4288 if (layout.labeltype >= LABEL_STATIC
4289 && (layout.labeltype != LABEL_STATIC
4290 || layout.latextype != LATEX_ENVIRONMENT
4291 || row_ptr->par()->IsFirstInSequence())) {
4292 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4293 if (!row_ptr->par()->GetLabelstring().empty()) {
4295 string tmpstring = row_ptr->par()->GetLabelstring();
4297 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4298 if (bview->buffer()->params.secnumdepth >= 0) {
4299 /* this is special code for the chapter layout. This is printed in
4300 * an extra row and has a pagebreak at the top. */
4301 float spacing_val = 1.0;
4302 if (!row_ptr->par()->spacing.isDefault()) {
4303 spacing_val = row_ptr->par()->spacing.getValue();
4305 spacing_val = bview->buffer()->params.spacing.getValue();
4308 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4309 + int(layout.parsep) * DefaultHeight();
4311 tmpx = ww - LeftMargin(bview, row_ptr) -
4312 lyxfont::width(tmpstring, font);
4313 pain.text(int(tmpx),
4314 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4319 tmpx = ww - LeftMargin(bview, row_ptr)
4320 + lyxfont::width(layout.labelsep, font);
4321 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4322 LyXFont font(LyXFont::ALL_SANE);
4323 font.setSize(LyXFont::SIZE_SMALL);
4324 tmpx += lyxfont::width("Mwide-fixM", font);
4327 tmpx = x - lyxfont::width(layout.labelsep, font)
4328 - lyxfont::width(tmpstring, font);
4331 pain.text(int(tmpx),
4332 y_offset + row_ptr->baseline(),
4336 /* the labels at the top of an environment. More or less for bibliography */
4337 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4338 layout.labeltype == LABEL_BIBLIO ||
4339 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4340 if (row_ptr->par()->IsFirstInSequence()) {
4341 font = GetFont(bview->buffer(),
4342 row_ptr->par(), -2);
4343 if (!row_ptr->par()->GetLabelstring().empty()) {
4344 string tmpstring = row_ptr->par()->GetLabelstring();
4345 float spacing_val = 1.0;
4346 if (!row_ptr->par()->spacing.isDefault()) {
4347 spacing_val = row_ptr->par()->spacing.getValue();
4349 spacing_val = bview->buffer()->params.spacing.getValue();
4352 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4353 + (layout.labelbottomsep * DefaultHeight()));
4356 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4357 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4358 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4359 tmpx -= lyxfont::width(tmpstring, font) / 2;
4361 tmpx = ww - LeftMargin(bview, row_ptr) -
4362 lyxfont::width(tmpstring, font);
4363 pain.text(int(tmpx),
4364 y_offset + row_ptr->baseline()
4365 - row_ptr->ascent_of_text()
4371 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4372 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4374 tmpx = ww - LeftMargin(bview, row_ptr)
4375 + lyxfont::width(layout.labelsep, font);
4377 tmpx = x - lyxfont::width(layout.labelsep, font)
4378 - row_ptr->par()->bibkey->width(bview->painter(), font);
4379 row_ptr->par()->bibkey->draw(bview, font,
4380 y_offset + row_ptr->baseline(),
4385 /* is it a last row? */
4386 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4387 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4388 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4390 /* think about the margins */
4391 if (!row_ptr->next() && bv_owner)
4392 y_bottom -= LYX_PAPER_MARGIN;
4394 /* draw a bottom pagebreak */
4395 if (firstpar->pagebreak_bottom) {
4397 pb_font.setColor(LColor::pagebreak).decSize();
4398 int w = 0, a = 0, d = 0;
4400 y_offset + y_bottom - 2 * DefaultHeight(),
4402 y_offset + y_bottom - 2 * DefaultHeight(),
4404 Painter::line_onoffdash)
4407 _("Page Break (bottom)"),
4410 LColor::background, false, w, a, d);
4411 pain.rectText((ww - w) / 2,
4412 y_offset + y_top + 2 * DefaultHeight() + d,
4413 _("Page Break (bottom)"),
4416 LColor::background);
4417 y_bottom -= 3 * DefaultHeight();
4420 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4421 /* draw a vfill bottom */
4422 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4424 y_offset + y_bottom - 3 * DefaultHeight(),
4426 pain.line(0, y_offset + y_bottom - 2,
4428 y_offset + y_bottom - 2,
4430 pain.line(LYX_PAPER_MARGIN / 2,
4431 y_offset + y_bottom - 3 * DefaultHeight(),
4432 LYX_PAPER_MARGIN / 2,
4433 y_offset + y_bottom - 2,
4435 y_bottom -= 3 * DefaultHeight();
4438 /* think about user added space */
4439 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4441 if (firstpar->line_bottom) {
4442 /* draw a bottom line */
4443 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4444 par, par->Last() - 1));
4445 pain.line(0, y_offset + y_bottom,
4446 ww, y_offset + y_bottom,
4447 LColor::topline, Painter::line_solid,
4448 Painter::line_thick);
4449 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4450 par, par->Last() - 1));
4454 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4457 case END_LABEL_FILLED_BOX:
4459 LyXFont font = GetFont(bview->buffer(),
4460 row_ptr->par(), last);
4461 int size = int(0.75 * lyxfont::maxAscent(font));
4462 int y = (y_offset + row_ptr->baseline()) - size;
4463 int x = is_rtl ? LYX_PAPER_MARGIN
4464 : ww - LYX_PAPER_MARGIN - size;
4465 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4467 LyXFont font(LyXFont::ALL_SANE);
4468 font.setSize(LyXFont::SIZE_SMALL);
4469 x += lyxfont::width("Mwide-figM", font);
4471 x -= LYX_PAPER_MARGIN/2;
4472 if (row_ptr->fill() <= size)
4473 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4474 if (endlabel == END_LABEL_BOX) {
4475 pain.line(x, y, x, y + size,
4477 pain.line(x + size, y, x + size , y + size,
4479 pain.line(x, y, x + size, y,
4481 pain.line(x, y + size, x + size, y + size,
4484 pain.fillRectangle(x, y, size, size,
4488 case END_LABEL_STATIC:
4490 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4491 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4492 layout).endlabelstring();
4493 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4494 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4495 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4496 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4499 case END_LABEL_NO_LABEL:
4504 /* draw the text in the pixmap */
4506 vpos = row_ptr->pos();
4508 /* table stuff -- begin*/
4509 if (row_ptr->par()->table) {
4511 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4513 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4515 while (vpos <= last) {
4516 pos = vis2log(vpos);
4517 if (row_ptr->par()->IsNewline(pos)) {
4519 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4520 /* draw the table lines, still very simple */
4521 on_off = !row_ptr->par()->table->TopLine(cell);
4523 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4524 !row_ptr->par()->table->IsContRow(cell))
4525 pain.line(int(x_old),
4526 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4528 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4530 on_off ? Painter::line_onoffdash : Painter::line_solid);
4532 on_off = !row_ptr->par()->table->BottomLine(cell);
4533 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4534 row_ptr->par()->table->VeryLastRow(cell))
4536 pain.line(int(x_old),
4537 y_offset + y_bottom - 1,
4539 y_offset + y_bottom - 1,
4541 on_off ? Painter::line_onoffdash : Painter::line_solid);
4543 on_off = !row_ptr->par()->table->LeftLine(cell);
4545 pain.line(int(x_old),
4546 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4548 y_offset + y_bottom - 1,
4550 on_off ? Painter::line_onoffdash : Painter::line_solid);
4552 on_off = !row_ptr->par()->table->RightLine(cell);
4554 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4555 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4556 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4557 y_offset + y_bottom - 1,
4559 on_off ? Painter::line_onoffdash : Painter::line_solid);
4562 /* take care about the alignment and other spaces */
4564 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4565 if (row_ptr->par()->table->IsFirstCell(cell))
4566 --cell; // little hack, sorry
4568 } else if (row_ptr->par()->IsHfill(pos)) {
4572 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4574 y_offset + row_ptr->baseline(),
4579 } else if (row_ptr->par()->IsSeparator(pos)) {
4581 x+= SingleWidth(bview,
4582 row_ptr->par(), pos);
4585 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4588 /* do not forget the very last cell. This has no NEWLINE so
4589 * ignored by the code above*/
4590 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4591 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4592 on_off = !row_ptr->par()->table->TopLine(cell);
4594 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4595 !row_ptr->par()->table->IsContRow(cell))
4597 pain.line(int(x_old),
4598 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4600 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4602 on_off ? Painter::line_onoffdash : Painter::line_solid);
4603 on_off = !row_ptr->par()->table->BottomLine(cell);
4604 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4605 row_ptr->par()->table->VeryLastRow(cell))
4607 pain.line(int(x_old),
4608 y_offset + y_bottom - 1,
4610 y_offset + y_bottom - 1,
4612 on_off ? Painter::line_onoffdash : Painter::line_solid);
4614 on_off = !row_ptr->par()->table->LeftLine(cell);
4616 pain.line(int(x_old),
4617 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4619 y_offset + y_bottom - 1,
4621 on_off ? Painter::line_onoffdash : Painter::line_solid);
4623 on_off = !row_ptr->par()->table->RightLine(cell);
4625 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4626 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4627 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4628 y_offset + y_bottom - 1,
4630 on_off ? Painter::line_onoffdash : Painter::line_solid);
4633 /* table stuff -- end*/
4635 LyXParagraph::size_type main_body =
4636 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4637 if (main_body > 0 &&
4638 (main_body-1 > last ||
4639 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4642 while (vpos <= last) {
4643 pos = vis2log(vpos);
4644 if (main_body > 0 && pos == main_body - 1) {
4645 x += fill_label_hfill
4646 + lyxfont::width(layout.labelsep,
4647 GetFont(bview->buffer(),
4648 row_ptr->par(), -2))
4649 - SingleWidth(bview,
4654 if (row_ptr->par() ->IsHfill(pos)) {
4657 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4659 y_offset + row_ptr->baseline(),
4662 if (HfillExpansion(bview->buffer(),
4664 if (pos >= main_body) {
4666 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4667 int(x + fill_hfill),
4668 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4670 Painter::line_onoffdash);
4674 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4675 int(x + fill_label_hfill),
4676 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4678 Painter::line_onoffdash);
4680 x += fill_label_hfill;
4683 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4685 y_offset + row_ptr->baseline(),
4690 } else if (row_ptr->par()->IsSeparator(pos)) {
4691 x += SingleWidth(bview,
4692 row_ptr->par(), pos);
4693 if (pos >= main_body)
4694 x += fill_separator;
4697 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4705 int LyXText::DefaultHeight() const
4707 LyXFont font(LyXFont::ALL_SANE);
4708 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4712 /* returns the column near the specified x-coordinate of the row
4713 * x is set to the real beginning of this column */
4714 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4715 bool & boundary) const
4718 float fill_separator, fill_hfill, fill_label_hfill;
4720 PrepareToPrint(bview, row, tmpx, fill_separator,
4721 fill_hfill, fill_label_hfill);
4723 LyXParagraph::size_type vc = row->pos();
4724 LyXParagraph::size_type last = RowLastPrintable(row);
4725 LyXParagraph::size_type c = 0;
4726 LyXLayout const & layout =
4727 textclasslist.Style(bview->buffer()->params.textclass,
4728 row->par()->GetLayout());
4729 bool left_side = false;
4732 /* table stuff -- begin */
4733 if (row->par()->table) {
4734 //the last row doesn't need a newline at the end
4735 if (row->next() && row->next()->par() == row->par()
4736 && row->par()->IsNewline(last))
4738 int cell = NumberOfCell(row->par(), row->pos());
4739 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4740 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4741 float last_tmpx = tmpx;
4742 while (vc <= last && tmpx <= x) {
4745 if (row->par()->IsNewline(c)) {
4748 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4749 cell_x += row->par()->table->WidthOfColumn(cell);
4754 tmpx += SingleWidth(bview, row->par(), c);
4758 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4759 (tmpx + last_tmpx) / 2 > x) {
4764 /* table stuff -- end*/
4766 LyXParagraph::size_type
4767 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4768 float last_tmpx = tmpx;
4770 if (main_body > 0 &&
4771 (main_body-1 > last ||
4772 !row->par()->IsLineSeparator(main_body - 1)))
4775 while (vc <= last && tmpx <= x) {
4778 if (main_body > 0 && c == main_body-1) {
4779 tmpx += fill_label_hfill +
4780 lyxfont::width(layout.labelsep,
4781 GetFont(bview->buffer(), row->par(), -2));
4782 if (row->par()->IsLineSeparator(main_body - 1))
4783 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4786 if (HfillExpansion(bview->buffer(), row, c)) {
4787 x += SingleWidth(bview, row->par(), c);
4791 tmpx += fill_label_hfill;
4793 else if (row->par()->IsSeparator(c)) {
4794 tmpx += SingleWidth(bview, row->par(), c);
4796 tmpx+= fill_separator;
4798 tmpx += SingleWidth(bview, row->par(), c);
4802 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4811 if (vc > last + 1) // This shouldn't happen.
4816 if (row->pos() > last) // Row is empty?
4818 else if (vc == row->pos() ||
4820 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4822 if (bidi_level(c) % 2 == 1)
4825 c = vis2log(vc - 1);
4826 bool rtl = (bidi_level(c) % 2 == 1);
4827 if (left_side == rtl) {
4829 boundary = IsBoundary(bview->buffer(), row->par(), c);
4833 if (!row->par()->table && row->pos() <= last && c > last
4834 && row->par()->IsNewline(last)) {
4835 if (bidi_level(last) % 2 == 0)
4836 tmpx -= SingleWidth(bview, row->par(), last);
4838 tmpx += SingleWidth(bview, row->par(), last);
4849 /* turn the selection into a new environment. If there is no selection,
4850 * create an empty environment */
4851 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4852 LyXParagraph::footnote_kind kind)
4854 /* no footnoteenvironment in a footnoteenvironment */
4855 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4856 WriteAlert(_("Impossible operation"),
4857 _("You can't insert a float in a float!"),
4861 /* no marginpars in minipages */
4862 if (kind == LyXParagraph::MARGIN
4863 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4864 WriteAlert(_("Impossible operation"),
4865 _("You can't insert a marginpar in a minipage!"),
4870 /* this doesnt make sense, if there is no selection */
4871 bool dummy_selection = false;
4873 sel_start_cursor = cursor; /* dummy selection */
4874 sel_end_cursor = cursor;
4875 dummy_selection = true;
4878 LyXParagraph * tmppar;
4881 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4882 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4886 /* a test to make sure there is not already a footnote
4887 * in the selection. */
4889 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4891 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4892 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4893 tmppar = tmppar->next;
4895 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4896 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4897 WriteAlert(_("Impossible operation"),
4898 _("Float would include float!"),
4903 /* ok we have a selection. This is always between sel_start_cursor
4904 * and sel_end cursor */
4906 SetUndo(bview->buffer(), Undo::FINISH,
4907 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4908 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4910 if (sel_end_cursor.pos() > 0
4911 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4912 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4913 /* please break before a space at the end */
4914 if (sel_start_cursor.par() == sel_end_cursor.par()
4915 && sel_start_cursor.pos() > sel_end_cursor.pos())
4916 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4918 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4920 sel_end_cursor.par(sel_end_cursor.par()->Next());
4921 sel_end_cursor.pos(0);
4923 // don't forget to insert a dummy layout paragraph if necessary
4924 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4925 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4926 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4927 sel_end_cursor.par(sel_end_cursor.par()->next);
4930 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4932 cursor = sel_end_cursor;
4934 /* please break behind a space, if there is one. The space should
4936 if (sel_start_cursor.pos() > 0
4937 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4938 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4939 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4940 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4943 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4944 sel_start_cursor.pos());
4945 tmppar = sel_start_cursor.par()->Next();
4947 if (dummy_selection) {
4949 if (kind == LyXParagraph::TAB
4950 || kind == LyXParagraph::FIG
4951 || kind == LyXParagraph::WIDE_TAB
4952 || kind == LyXParagraph::WIDE_FIG
4953 || kind == LyXParagraph::ALGORITHM) {
4954 pair<bool, LyXTextClass::size_type> lres =
4955 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4957 LyXTextClass::size_type lay;
4963 lay = 0; // use default layout "Standard" (0)
4965 tmppar->SetLayout(bview->buffer()->params, lay);
4968 if (sel_start_cursor.pos() > 0) {
4969 /* the footnote-environment should begin with a standard layout.
4970 * Imagine you insert a footnote within an enumeration, you
4971 * certainly do not want an enumerated footnote! */
4974 /* this is a exception the user would sometimes expect, I hope */
4975 sel_start_cursor.par()->Clear();
4979 while (tmppar != sel_end_cursor.par()) {
4980 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4981 tmppar->footnotekind = kind;
4982 tmppar = tmppar->Next();
4985 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4987 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4994 // returns pointer to a specified row
4995 Row * LyXText::GetRow(LyXParagraph * par,
4996 LyXParagraph::size_type pos, long & y) const
4998 Row * tmprow = firstrow;
5001 // find the first row of the specified paragraph
5002 while (tmprow->next() && tmprow->par() != par) {
5003 y += tmprow->height();
5004 tmprow = tmprow->next();
5007 // now find the wanted row
5008 while (tmprow->pos() < pos
5010 && tmprow->next()->par() == par
5011 && tmprow->next()->pos() <= pos) {
5012 y += tmprow->height();
5013 tmprow = tmprow->next();