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 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "insets/insetbib.h"
24 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "minibuffer.h"
42 static const int LYX_PAPER_MARGIN = 20;
46 extern int bibitemMaxWidth(Painter &, LyXFont const &);
48 static int iso885968x[] = {
49 0xbc, // 0xa8 = fathatan
50 0xbd, // 0xa9 = dammatan
51 0xbe, // 0xaa = kasratan
55 0xde, // 0xae = shadda
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
62 0xc2, // 0xc2 = ligature madda
63 0xc3, // 0xc3 = ligature hamza on alef
64 0xc4, // 0xc4 = ligature hamza on waw
65 0xc5, // 0xc5 = ligature hamza under alef
66 0xc0, // 0xc6 = ligature hamza on ya
69 0xc9, // 0xc9 = taa marbuta
88 0,0,0,0,0, // 0xdb- 0xdf
99 0xe9, // 0xe9 = alef maksura
104 bool is_arabic(unsigned char c)
106 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
110 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
113 (form == FORM_INITIAL || form == FORM_MEDIAL) )
114 return iso885968x[c-0xa8];
120 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
121 LyXParagraph::size_type pos) const
125 return c + (0xb0 - '0');
129 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
130 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
132 return TransformChar(c,FORM_MEDIAL);
134 return TransformChar(c,FORM_INITIAL);
137 return TransformChar(c,FORM_FINAL);
139 return TransformChar(c,FORM_ISOLATED);
142 // This is the comments that some of the warnings below refers to.
143 // There are some issues in this file and I don't think they are
144 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
145 // this is a problem that has been here almost from day one and that a
146 // larger userbase with differenct access patters triggers the bad
147 // behaviour. (segfaults.) What I think happen is: In several places
148 // we store the paragraph in the current cursor and then moves the
149 // cursor. This movement of the cursor will delete paragraph at the
150 // old position if it is now empty. This will make the temporary
151 // pointer to the old cursor paragraph invalid and dangerous to use.
152 // And is some cases this will trigger a segfault. I have marked some
153 // of the cases where this happens with a warning, but I am sure there
154 // are others in this file and in text2.C. There is also a note in
155 // Delete() that you should read. In Delete I store the paragraph->id
156 // instead of a pointer to the paragraph. I am pretty sure this faulty
157 // use of temporary pointers to paragraphs that might have gotten
158 // invalidated (through a cursor movement) before they are used, are
159 // the cause of the strange crashes we get reported often.
161 // It is very tiresom to change this code, especially when it is as
162 // hard to read as it is. Help to fix all the cases where this is done
163 // would be greately appreciated.
167 int LyXText::SingleWidth(LyXParagraph * par,
168 LyXParagraph::size_type pos) const
170 char c = par->GetChar(pos);
171 return SingleWidth(par, pos, c);
175 int LyXText::SingleWidth(LyXParagraph * par,
176 LyXParagraph::size_type pos, char c) const
178 LyXFont font = GetFont(par, pos);
180 // The most common case is handled first (Asger)
181 if (IsPrintable(c)) {
182 if (font.language()->lang == "arabic" &&
183 lyxrc.font_norm == "iso8859-6.8x")
184 c = TransformChar(c, par, pos);
185 return lyxfont::width(c, font);
187 } else if (IsHfillChar(c)) {
188 return 3; /* Because of the representation
189 * as vertical lines */
190 } else if (c == LyXParagraph::META_FOOTNOTE ||
191 c == LyXParagraph::META_MARGIN ||
192 c == LyXParagraph::META_FIG ||
193 c == LyXParagraph::META_TAB ||
194 c == LyXParagraph::META_WIDE_FIG ||
195 c == LyXParagraph::META_WIDE_TAB ||
196 c == LyXParagraph::META_ALGORITHM) {
199 case LyXParagraph::META_MARGIN:
202 case LyXParagraph::META_FIG:
205 case LyXParagraph::META_TAB:
208 case LyXParagraph::META_ALGORITHM:
211 case LyXParagraph::META_WIDE_FIG:
214 case LyXParagraph::META_WIDE_TAB:
217 case LyXParagraph::META_FOOTNOTE:
223 return lyxfont::width(fs, font);
224 } else if (c == LyXParagraph::META_INSET) {
225 Inset * tmpinset= par->GetInset(pos);
227 return par->GetInset(pos)->width(owner_->painter(),
232 } else if (IsSeparatorChar(c))
234 else if (IsNewlineChar(c))
236 return lyxfont::width(c, font);
240 // Returns the paragraph position of the last character in the specified row
241 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
244 return row->par->Last() - 1;
245 else if (row->next->par != row->par)
246 return row->par->Last() - 1;
248 return row->next->pos - 1;
252 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
254 LyXParagraph::size_type last = RowLast(row);
255 if (last >= row->pos && row->next && row->next->par == row->par &&
256 row->par->IsSeparator(last))
263 void LyXText::ComputeBidiTables(Row * row) const
265 bidi_same_direction = true;
266 if (!lyxrc.rtl_support) {
270 LyXParagraph::size_type last = RowLastPrintable(row);
271 bidi_start = row->pos;
273 if (bidi_start > last) {
278 if (last + 2 - bidi_start >
279 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
280 LyXParagraph::size_type new_size =
281 (last + 2 - bidi_start < 500) ?
282 500 : 2 * (last + 2 - bidi_start);
283 log2vis_list.resize(new_size);
284 vis2log_list.resize(new_size);
285 bidi_levels.resize(new_size);
288 vis2log_list[last + 1 - bidi_start] = -1;
289 log2vis_list[last + 1 - bidi_start] = -1;
291 LyXParagraph::size_type stack[2];
292 bool rtl_par = row->par->getParLanguage()->RightToLeft;
296 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
298 for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) {
299 bool is_space = row->par->IsLineSeparator(lpos);
300 LyXParagraph::size_type pos =
301 (is_space && lpos+1 <= last &&
302 (!row->par->table || !row->par->IsNewline(lpos+1)) )
304 LyXFont font = row->par->GetFontSettings(pos);
305 bool new_rtl = font.isVisibleRightToLeft();
306 bool new_rtl0 = font.isRightToLeft();
309 if (row->par->table && row->par->IsNewline(lpos)) {
311 new_rtl = new_rtl0 = false;
312 } else if (lpos == main_body - 1 && row->pos < main_body - 1 &&
313 row->par->IsLineSeparator(lpos)) {
314 new_level = (rtl_par) ? 1 : 0;
315 new_rtl = new_rtl0 = rtl_par;
317 new_level = (new_rtl) ? 1 : 2;
319 new_level = (rtl_par) ? 2 : 0;
321 if (is_space && new_level >= level) {
327 int new_level2 = new_level;
329 if (level == new_level && rtl0 != new_rtl0) {
331 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
332 } else if (level < new_level) {
333 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
334 if (new_level > rtl_par)
335 bidi_same_direction = false;
337 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
340 bidi_levels[lpos - bidi_start] = new_level;
342 while (level > new_level2) {
343 LyXParagraph::size_type old_lpos =
345 int delta = lpos - old_lpos - 1;
348 log2vis_list[lpos - bidi_start] += delta;
349 log2vis_list[old_lpos - bidi_start] += delta;
351 while (level < new_level)
352 stack[level++] = lpos;
356 LyXParagraph::size_type old_lpos = stack[--level];
357 int delta = last - old_lpos;
360 log2vis_list[old_lpos - bidi_start] += delta;
363 LyXParagraph::size_type vpos = bidi_start - 1;
364 for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) {
365 vpos += log2vis_list[lpos - bidi_start];
366 vis2log_list[vpos - bidi_start] = lpos;
367 log2vis_list[lpos - bidi_start] = vpos;
372 void LyXText::draw(Row const * row,
373 LyXParagraph::size_type & vpos,
374 int offset, float & x)
376 Painter & pain = owner_->painter();
378 LyXParagraph::size_type pos = vis2log(vpos);
379 char c = row->par->GetChar(pos);
381 if (IsNewlineChar(c)) {
383 // Draw end-of-line marker
384 LyXFont font = GetFont(row->par, pos);
385 int wid = lyxfont::width('n', font);
386 int asc = lyxfont::maxAscent(font);
387 int y = offset + row->baseline;
390 if (bidi_level(pos) % 2 == 0) {
391 xp[0] = int(x + wid * 0.375);
392 yp[0] = int(y - 0.875 * asc * 0.75);
395 yp[1] = int(y - 0.500 * asc * 0.75);
397 xp[2] = int(x + wid * 0.375);
398 yp[2] = int(y - 0.125 * asc * 0.75);
400 pain.lines(xp, yp, 3, LColor::eolmarker);
403 yp[0] = int(y - 0.500 * asc * 0.75);
405 xp[1] = int(x + wid);
406 yp[1] = int(y - 0.500 * asc * 0.75);
408 xp[2] = int(x + wid);
409 yp[2] = int(y - asc * 0.75);
411 pain.lines(xp, yp, 3, LColor::eolmarker);
413 xp[0] = int(x + wid * 0.625);
414 yp[0] = int(y - 0.875 * asc * 0.75);
416 xp[1] = int(x + wid);
417 yp[1] = int(y - 0.500 * asc * 0.75);
419 xp[2] = int(x + wid * 0.625);
420 yp[2] = int(y - 0.125 * asc * 0.75);
422 pain.lines(xp, yp, 3, LColor::eolmarker);
424 xp[0] = int(x + wid);
425 yp[0] = int(y - 0.500 * asc * 0.75);
428 yp[1] = int(y - 0.500 * asc * 0.75);
431 yp[2] = int(y - asc * 0.75);
433 pain.lines(xp, yp, 3, LColor::eolmarker);
439 LyXFont font = GetFont(row->par, pos);
440 LyXFont font2 = font;
442 if (c == LyXParagraph::META_FOOTNOTE
443 || c == LyXParagraph::META_MARGIN
444 || c == LyXParagraph::META_FIG
445 || c == LyXParagraph::META_TAB
446 || c == LyXParagraph::META_WIDE_FIG
447 || c == LyXParagraph::META_WIDE_TAB
448 || c == LyXParagraph::META_ALGORITHM) {
451 case LyXParagraph::META_MARGIN:
453 // Draw a sign at the left margin!
455 .text((LYX_PAPER_MARGIN - lyxfont::width('!', font))/2,
456 offset + row->baseline, "!", 1, font);
458 case LyXParagraph::META_FIG:
461 case LyXParagraph::META_TAB:
464 case LyXParagraph::META_ALGORITHM:
467 case LyXParagraph::META_WIDE_FIG:
470 case LyXParagraph::META_WIDE_TAB:
473 case LyXParagraph::META_FOOTNOTE:
480 // calculate the position of the footnotemark
481 int y = (row->baseline - lyxfont::maxAscent(font2)
482 + lyxfont::maxAscent(font));
484 font.setColor(LColor::footnote);
488 // draw it and set new x position
490 pain.text(int(x), offset + y, fs, font);
491 x += lyxfont::width(fs, font);
492 pain.line(int(tmpx), offset + row->baseline,
493 int(x), offset + row->baseline,
498 } else if (c == LyXParagraph::META_INSET) {
499 Inset * tmpinset = row->par->GetInset(pos);
501 tmpinset->draw(owner_->painter(), font,
502 offset + row->baseline, x);
508 /* usual characters, no insets */
510 // Collect character that we can draw in one command
512 // This is dirty, but fast. Notice that it will never be too small.
513 // For the record, I'll note that Microsoft Word has a limit
514 // of 768 here. We have none :-) (Asger)
515 // Ok. I am the first to admit that the use of std::string will be
516 // a tiny bit slower than using a POD char array. However, I claim
517 // that this slowdown is so small that it is close to inperceptive.
518 // So IMHO we should go with the easier and clearer implementation.
519 // And even if 1024 is a large number here it might overflow, string
520 // will only overflow if the machine is out of memory...
522 font2.language()->lang == "arabic" &&
523 lyxrc.font_norm == "iso8859-6.8x";
525 c = TransformChar(c, row->par, pos);
526 static string textstring;
530 LyXParagraph::size_type last = RowLastPrintable(row);
532 while (vpos <= last &&
533 (pos = vis2log(vpos)) >= 0
534 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
535 && font2 == GetFont(row->par, pos)) {
537 c = TransformChar(c, row->par, pos);
543 // Draw text and set the new x position
544 pain.text(int(x), offset + row->baseline, textstring, font);
545 x += lyxfont::width(textstring, font);
547 // what about underbars?
548 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
549 pain.line(tmpx, offset + row->baseline + 2,
550 x, offset + row->baseline + 2);
554 // If we want ulem.sty support, drawing
555 // routines should go here. (Asger)
556 // Why shouldn't LyXFont::drawText handle it internally?
560 // Returns the left beginning of the text.
561 // This information cannot be taken from the layouts-objekt, because in
562 // LaTeX the beginning of the text fits in some cases (for example sections)
563 // exactly the label-width.
564 int LyXText::LeftMargin(Row const * row) const
566 LyXLayout const & layout =
567 textclasslist.Style(buffer->params.textclass,
568 row->par->GetLayout());
570 string parindent = layout.parindent;
572 /* table stuff -- begin */
575 /* table stuff -- end */
577 int x = LYX_PAPER_MARGIN;
579 x += lyxfont::signedWidth(textclasslist
580 .TextClass(buffer->params.textclass)
583 .TextClass(buffer->params.textclass)
586 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
587 LyXFont font(LyXFont::ALL_SANE);
588 font.setSize(LyXFont::SIZE_SMALL);
589 x += lyxfont::width("Mwide-figM", font)
590 + LYX_PAPER_MARGIN/2;
593 // this is the way, LyX handles the LaTeX-Environments.
594 // I have had this idea very late, so it seems to be a
595 // later added hack and this is true
596 if (!row->par->GetDepth()) {
597 if (!row->par->GetLayout()) {
598 // find the previous same level paragraph
599 if (row->par->FirstPhysicalPar()->Previous()) {
600 LyXParagraph * newpar = row->par
601 ->DepthHook(row->par->GetDepth());
603 textclasslist.Style(buffer->params.textclass,
610 // find the next level paragraph
612 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
614 // make a corresponding row. Needed to call LeftMargin()
616 // check wether it is a sufficent paragraph
617 if (newpar && newpar->footnoteflag == row->par->footnoteflag
619 .Style(buffer->params.textclass,
620 newpar->GetLayout()).isEnvironment()) {
622 dummyrow.par = newpar;
623 dummyrow.pos = newpar->Last();
624 x = LeftMargin(&dummyrow);
626 // this is no longer an error, because this function
627 // is used to clear impossible depths after changing
628 // a layout. Since there is always a redo,
629 // LeftMargin() is always called
630 row->par->FirstPhysicalPar()->depth = 0;
633 if (newpar && !row->par->GetLayout()) {
634 if (newpar->FirstPhysicalPar()->noindent)
637 parindent = textclasslist
638 .Style(buffer->params.textclass,
639 newpar->GetLayout()).parindent;
644 LyXFont labelfont = GetFont(row->par, -2);
645 switch (layout.margintype) {
647 if (!layout.leftmargin.empty()) {
648 x += lyxfont::signedWidth(layout.leftmargin,
650 .TextClass(buffer->params.
654 if (!row->par->GetLabelstring().empty()) {
655 x += lyxfont::signedWidth(layout.labelindent,
657 x += lyxfont::width(row->par->GetLabelstring(), labelfont);
658 x += lyxfont::width(layout.labelsep, labelfont);
662 x += lyxfont::signedWidth(layout.labelindent, labelfont);
663 if (row->pos >= BeginningOfMainBody(row->par)) {
664 if (!row->par->GetLabelWidthString().empty()) {
665 x += lyxfont::width(row->par->GetLabelWidthString(),
667 x += lyxfont::width(layout.labelsep, labelfont);
672 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(buffer->params.textclass).defaultfont()) * 4
673 / (row->par->GetDepth() + 4);
675 case MARGIN_FIRST_DYNAMIC:
676 if (layout.labeltype == LABEL_MANUAL) {
677 if (row->pos >= BeginningOfMainBody(row->par)) {
678 x += lyxfont::signedWidth(layout.leftmargin, labelfont);
680 x += lyxfont::signedWidth(layout.labelindent, labelfont);
683 // Special case to fix problems with
685 || (layout.labeltype == LABEL_STATIC
686 && layout.latextype == LATEX_ENVIRONMENT
687 && ! row->par->IsFirstInSequence())) {
688 x += lyxfont::signedWidth(layout.leftmargin, labelfont);
689 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
690 && layout.labeltype != LABEL_BIBLIO
691 && layout.labeltype !=
692 LABEL_CENTERED_TOP_ENVIRONMENT) {
693 x += lyxfont::signedWidth(layout.labelindent,
695 x += lyxfont::width(layout.labelsep, labelfont);
696 x += lyxfont::width(row->par->GetLabelstring(), labelfont);
700 case MARGIN_RIGHT_ADDRESS_BOX:
702 // ok, a terrible hack. The left margin depends on the widest
703 // row in this paragraph. Do not care about footnotes, they
704 // are *NOT* allowed in the LaTeX realisation of this layout.
706 // find the first row of this paragraph
707 Row const * tmprow = row;
708 while (tmprow->previous && tmprow->previous->par == row->par)
709 tmprow = tmprow->previous;
711 int minfill = tmprow->fill;
712 while (tmprow->next && tmprow->next->par == row->par) {
713 tmprow = tmprow->next;
714 if (tmprow->fill < minfill)
715 minfill = tmprow->fill;
718 x += lyxfont::signedWidth(layout.leftmargin,
720 .TextClass(buffer->params.textclass)
726 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
727 if (!row->par->pextra_widthp.empty()) {
729 atoi(row->par->pextra_widthp.c_str()) / 100;
730 } else if (!row->par->pextra_width.empty()) {
731 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
734 xx = paperwidth * 80 / 100;
736 } else { // should not happen
737 LyXFont font(LyXFont::ALL_SANE);
738 x += lyxfont::width("XXXXXX", font);
742 int align; // wrong type
743 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
744 align = layout.align;
746 align = row->par->FirstPhysicalPar()->align;
748 // set the correct parindent
750 if ((layout.labeltype == LABEL_NO_LABEL
751 || layout.labeltype == LABEL_TOP_ENVIRONMENT
752 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
753 || (layout.labeltype == LABEL_STATIC
754 && layout.latextype == LATEX_ENVIRONMENT
755 && ! row->par->IsFirstInSequence()))
756 && row->par == row->par->FirstPhysicalPar()
757 && align == LYX_ALIGN_BLOCK
758 && !row->par->noindent
759 && (row->par->layout ||
760 buffer->params.paragraph_separation ==
761 BufferParams::PARSEP_INDENT))
762 x += lyxfont::signedWidth(parindent,
764 .TextClass(buffer->params
767 else if (layout.labeltype == LABEL_BIBLIO) {
768 // ale970405 Right width for bibitems
769 x += bibitemMaxWidth(owner_->painter(),
771 .TextClass(buffer->params
780 int LyXText::RightMargin(Row const * row) const
782 LyXLayout const & layout =
783 textclasslist.Style(buffer->params.textclass,
784 row->par->GetLayout());
786 int x = LYX_PAPER_MARGIN
787 + lyxfont::signedWidth(textclasslist
788 .TextClass(buffer->params.textclass)
791 .TextClass(buffer->params.textclass)
794 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
795 x += LYX_PAPER_MARGIN / 2;
798 // this is the way, LyX handles the LaTeX-Environments.
799 // I have had this idea very late, so it seems to be a
800 // later added hack and this is true
801 if (row->par->GetDepth()) {
802 // find the next level paragraph
804 LyXParagraph * newpar = row->par;
807 newpar = newpar->FirstPhysicalPar()->Previous();
809 newpar = newpar->FirstPhysicalPar();
810 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
811 && newpar->footnoteflag == row->par->footnoteflag);
813 // make a corresponding row. Needed to call LeftMargin()
815 // check wether it is a sufficent paragraph
816 if (newpar && newpar->footnoteflag == row->par->footnoteflag
817 && textclasslist.Style(buffer->params.textclass,
821 dummyrow.par = newpar;
823 x = RightMargin(&dummyrow);
825 // this is no longer an error, because this function
826 // is used to clear impossible depths after changing
827 // a layout. Since there is always a redo,
828 // LeftMargin() is always called
829 row->par->FirstPhysicalPar()->depth = 0;
833 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
834 x += lyxfont::signedWidth(layout.rightmargin, textclasslist.TextClass(buffer->params.textclass).defaultfont()) * 4
835 / (row->par->GetDepth() + 4);
840 int LyXText::LabelEnd (Row const * row) const
842 if (textclasslist.Style(buffer->params.textclass,
843 row->par->GetLayout()).margintype
847 tmprow.pos = row->par->Last();
848 return LeftMargin(&tmprow); /* just the beginning
851 return 0; /* LabelEnd is only needed, if the
852 layout fills a flushleft
857 /* table stuff -- begin*/
858 int LyXText::NumberOfCell(LyXParagraph * par,
859 LyXParagraph::size_type pos) const
862 LyXParagraph::size_type tmp_pos = 0;
863 while (tmp_pos < pos) {
864 if (par->IsNewline(tmp_pos))
872 int LyXText::WidthOfCell(LyXParagraph * par,
873 LyXParagraph::size_type & pos) const
876 while (pos < par->Last() && !par->IsNewline(pos)) {
877 w += SingleWidth(par, pos);
880 if (par->IsNewline(pos))
886 bool LyXText::HitInTable(Row * row, int x) const
889 float fill_separator, fill_hfill, fill_label_hfill;
890 if (!row->par->table)
892 PrepareToPrint(row, tmpx, fill_separator,
893 fill_hfill, fill_label_hfill, false);
894 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
898 bool LyXText::MouseHitInTable(int x, long y) const
900 Row * row = GetRowNearY(y);
901 return HitInTable(row, x);
905 /* table stuff -- end*/
908 // get the next breakpoint in a given paragraph
909 LyXParagraph::size_type
910 LyXText::NextBreakPoint(Row const * row, int width) const
912 LyXParagraph * par = row->par;
913 LyXParagraph::size_type pos = row->pos;
915 /* table stuff -- begin*/
917 while (pos < par->size()
918 && (!par->IsNewline(pos)
919 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
920 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
921 par->GetInset(pos) && par->GetInset(pos)->display()){
922 par->GetInset(pos)->display(false);
928 /* table stuff -- end*/
930 // position of the last possible breakpoint
931 // -1 isn't a suitable value, but a flag
932 LyXParagraph::size_type last_separator = -1;
933 width -= RightMargin(row);
935 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
936 LyXLayout const & layout =
937 textclasslist.Style(buffer->params.textclass, par->GetLayout());
938 LyXParagraph::size_type i = pos;
940 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
941 /* special code for right address boxes, only newlines count */
942 while (i < par->Last()) {
943 if (par->IsNewline(i)) {
945 i = par->Last() - 1; // this means break
947 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
948 par->GetInset(i) && par->GetInset(i)->display()){
949 par->GetInset(i)->display(false);
954 // Last position is an invariant
955 LyXParagraph::size_type const last =
957 // this is the usual handling
958 int x = LeftMargin(row);
959 while (x < width && i < last) {
960 char c = par->GetChar(i);
961 if (IsNewlineChar(c)) {
963 x = width; // this means break
964 } else if (c == LyXParagraph::META_INSET &&
965 par->GetInset(i) && par->GetInset(i)->display()){
966 // check wether a Display() inset is
967 // valid here. if not, change it to
969 if (layout.isCommand()
970 || (layout.labeltype == LABEL_MANUAL
971 && i < BeginningOfMainBody(par))){
972 // display istn't allowd
973 par->GetInset(i)->display(false);
974 x += SingleWidth(par, i, c);
976 // inset is display. So break the line here
980 if (IsLineSeparatorChar(par->GetChar(i+1)))
983 last_separator = last; // to avoid extra rows
985 last_separator = i - 1;
986 x = width; // this means break
989 if (IsLineSeparatorChar(c))
991 x += SingleWidth(par, i, c);
994 if (i == main_body) {
995 x += lyxfont::width(layout.labelsep,
997 if (par->IsLineSeparator(i - 1))
998 x-= SingleWidth(par, i - 1);
999 int left_margin = LabelEnd(row);
1000 if (x < left_margin)
1004 // end of paragraph is always a suitable separator
1005 if (i == last && x < width)
1009 // well, if last_separator is still 0, the line isn't breakable.
1010 // don't care and cut simply at the end
1011 if (last_separator < 0) {
1015 // manual labels cannot be broken in LaTeX, do not care
1016 if (main_body && last_separator < main_body)
1017 last_separator = main_body - 1;
1019 return last_separator;
1023 // returns the minimum space a row needs on the screen in pixel
1024 int LyXText::Fill(Row const * row, int paper_width) const
1027 // get the pure distance
1028 LyXParagraph::size_type last = RowLastPrintable(row);
1029 /* table stuff -- begin */
1030 if (row->par->table) {
1031 // for tables FILL does calculate the widthes of each cell in
1033 LyXParagraph::size_type pos = row->pos;
1034 int cell = NumberOfCell(row->par, pos);
1037 row->par->table->SetWidthOfCell(cell,
1038 WidthOfCell(row->par,
1041 } while (pos <= last && !row->par->table->IsFirstCell(cell));
1042 // don't forget the very last table cell without characters
1043 if (cell == row->par->table->GetNumberOfCells() - 1)
1044 row->par->table->SetWidthOfCell(cell,
1045 WidthOfCell(row->par,
1048 return 0; /* width of table cannot be returned since
1049 * we cannot guarantee its correct value at
1052 /* table stuff -- end*/
1054 // special handling of the right address boxes
1055 if (textclasslist.Style(buffer->params.textclass,
1056 row->par->GetLayout()).margintype
1057 == MARGIN_RIGHT_ADDRESS_BOX) {
1058 int tmpfill = row->fill;
1059 row->fill = 0; // the minfill in MarginLeft()
1060 w = LeftMargin(row);
1061 row->fill = tmpfill;
1063 w = LeftMargin(row);
1065 LyXLayout const & layout = textclasslist.Style(buffer->params.textclass,
1066 row->par->GetLayout());
1067 LyXParagraph::size_type main_body =
1068 BeginningOfMainBody(row->par);
1069 LyXParagraph::size_type i = row->pos;
1072 if (main_body > 0 && i == main_body) {
1073 w += lyxfont::width(layout.labelsep, GetFont(row->par, -2));
1074 if (row->par->IsLineSeparator(i - 1))
1075 w -= SingleWidth(row->par, i - 1);
1076 int left_margin = LabelEnd(row);
1077 if (w < left_margin)
1080 w += SingleWidth(row->par, i);
1083 if (main_body > 0 && main_body > last) {
1084 w += lyxfont::width(layout.labelsep, GetFont(row->par, -2));
1085 if (last >= 0 && row->par->IsLineSeparator(last))
1086 w -= SingleWidth(row->par, last);
1087 int left_margin = LabelEnd(row);
1088 if (w < left_margin)
1092 fill = paper_width - w - RightMargin(row);
1097 // returns the minimum space a manual label needs on the screen in pixel
1098 int LyXText::LabelFill(Row const * row) const
1100 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1101 // -1 because a label ends either with a space that is in the label,
1102 // or with the beginning of a footnote that is outside the label.
1104 // I don't understand this code in depth, but sometimes "last" is
1105 // less than 0 and this causes a crash. This fix seems to work
1106 // correctly, but I bet the real error is elsewhere. The bug is
1107 // triggered when you have an open footnote in a paragraph
1108 // environment with a manual label. (Asger)
1109 if (last < 0) last = 0;
1111 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1118 w += SingleWidth(row->par, i);
1123 if (!row->par->labelwidthstring.empty()) {
1124 fill = max(lyxfont::width(row->par->labelwidthstring,
1125 GetFont(row->par, -2)) - w,
1133 // returns the number of separators in the specified row. The separator
1134 // on the very last column doesnt count
1135 int LyXText::NumberOfSeparators(Row const * row) const
1137 int last = RowLast(row);
1138 int p = max(row->pos, BeginningOfMainBody(row->par));
1140 for (; p < last; ++p) {
1141 if (row->par->IsSeparator(p)) {
1149 // returns the number of hfills in the specified row. The LyX-Hfill is
1150 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1151 // ignored. This is *MUCH* more usefull than not to ignore!
1152 int LyXText::NumberOfHfills(Row const * row) const
1154 int last = RowLast(row);
1155 int first = row->pos;
1156 if (first) { /* hfill *DO* count at the beginning
1158 while(first <= last && row->par->IsHfill(first))
1162 first = max(first, BeginningOfMainBody(row->par));
1164 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1165 if (row->par->IsHfill(p)) {
1173 // like NumberOfHfills, but only those in the manual label!
1174 int LyXText::NumberOfLabelHfills(Row const * row) const
1176 LyXParagraph::size_type last = RowLast(row);
1177 LyXParagraph::size_type first = row->pos;
1178 if (first) { /* hfill *DO* count at the beginning
1180 while(first < last && row->par->IsHfill(first))
1184 last = min(last, BeginningOfMainBody(row->par));
1186 for (LyXParagraph::size_type p = first;
1187 p < last; ++p) { // last, because the end is ignored!
1188 if (row->par->IsHfill(p)) {
1196 // returns true, if a expansion is needed.
1197 // Rules are given by LaTeX
1198 bool LyXText::HfillExpansion(Row const * row_ptr,
1199 LyXParagraph::size_type pos) const
1201 // by the way, is it a hfill?
1202 if (!row_ptr->par->IsHfill(pos))
1205 // at the end of a row it does not count
1206 if (pos >= RowLast(row_ptr))
1209 // at the beginning of a row it does not count, if it is not
1210 // the first row of a paragaph
1214 // in some labels it does not count
1215 if (textclasslist.Style(buffer->params.textclass,
1216 row_ptr->par->GetLayout()).margintype
1218 && pos < BeginningOfMainBody(row_ptr->par))
1221 // if there is anything between the first char of the row and
1222 // the sepcified position that is not a newline and not a hfill,
1223 // the hfill will count, otherwise not
1224 LyXParagraph::size_type i = row_ptr->pos;
1225 while (i < pos && (row_ptr->par->IsNewline(i)
1226 || row_ptr->par->IsHfill(i)))
1233 void LyXText::SetHeightOfRow(Row * row_ptr) const
1235 /* get the maximum ascent and the maximum descent */
1237 float layoutasc = 0;
1238 float layoutdesc = 0;
1243 /* this must not happen before the currentrow for clear reasons.
1244 so the trick is just to set the current row onto this row */
1246 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1248 /* ok , let us initialize the maxasc and maxdesc value.
1249 * This depends in LaTeX of the font of the last character
1250 * in the paragraph. The hack below is necessary because
1251 * of the possibility of open footnotes */
1253 /* Correction: only the fontsize count. The other properties
1254 are taken from the layoutfont. Nicer on the screen :) */
1256 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1257 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1259 LyXLayout const & layout = textclasslist.Style(buffer->params.textclass,
1260 firstpar->GetLayout());
1262 LyXFont font = GetFont(par, par->Last() - 1);
1263 LyXFont::FONT_SIZE size = font.size();
1264 font = GetFont(par, -1);
1267 LyXFont labelfont = GetFont(par, -2);
1269 float spacing_val = 1.0;
1270 if (!row_ptr->par->spacing.isDefault()) {
1271 spacing_val = row_ptr->par->spacing.getValue();
1273 spacing_val = buffer->params.spacing.getValue();
1275 //lyxerr << "spacing_val = " << spacing_val << endl;
1277 int maxasc = int(lyxfont::maxAscent(font) *
1278 layout.spacing.getValue() *
1280 int maxdesc = int(lyxfont::maxDescent(font) *
1281 layout.spacing.getValue() *
1284 int pos_end = RowLast(row_ptr);
1288 // Check if any insets are larger
1289 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1290 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1291 tmpfont = GetFont(row_ptr->par, pos);
1292 tmpinset = row_ptr->par->GetInset(pos);
1294 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1295 desc = tmpinset->descent(owner_->painter(), tmpfont);
1304 // Check if any custom fonts are larger (Asger)
1305 // This is not completely correct, but we can live with the small,
1306 // cosmetic error for now.
1307 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1309 if (maxsize > font.size()) {
1310 font.setSize(maxsize);
1312 asc = lyxfont::maxAscent(font);
1313 desc = lyxfont::maxDescent(font);
1320 /* table stuff -- begin*/
1321 if (row_ptr->par->table){
1322 // stretch the rows a bit
1326 /* table stuff -- end*/
1328 // This is nicer with box insets:
1332 row_ptr->ascent_of_text = maxasc;
1334 /* is it a top line? */
1335 if (row_ptr->pos == 0
1336 && row_ptr->par == firstpar) {
1338 /* some parksips VERY EASY IMPLEMENTATION */
1339 if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
1340 if (layout.isParagraph()
1341 && firstpar->GetDepth() == 0
1342 && firstpar->Previous())
1343 maxasc += buffer->params.getDefSkip().inPixels(owner_);
1344 else if (firstpar->Previous()
1345 && textclasslist.Style(buffer->params.textclass,
1346 firstpar->Previous()->GetLayout()).isParagraph()
1347 && firstpar->Previous()->GetDepth() == 0)
1348 // is it right to use defskip here too? (AS)
1349 maxasc += buffer->params.getDefSkip().inPixels(owner_);
1352 /* the paper margins */
1353 if (!row_ptr->par->previous)
1354 maxasc += LYX_PAPER_MARGIN;
1356 /* add the vertical spaces, that the user added */
1357 if (firstpar->added_space_top.kind() != VSpace::NONE)
1358 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1360 /* do not forget the DTP-lines!
1361 * there height depends on the font of the nearest character */
1362 if (firstpar->line_top)
1363 maxasc += 2 * lyxfont::ascent('x', GetFont(firstpar, 0));
1365 /* and now the pagebreaks */
1366 if (firstpar->pagebreak_top)
1367 maxasc += 3 * DefaultHeight();
1369 /* this is special code for the chapter, since the label of this
1370 * layout is printed in an extra row */
1371 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1372 && buffer->params.secnumdepth >= 0) {
1373 float spacing_val = 1.0;
1374 if (!row_ptr->par->spacing.isDefault()) {
1375 spacing_val = row_ptr->par->spacing.getValue();
1377 spacing_val = buffer->params.spacing.getValue();
1380 labeladdon = int(lyxfont::maxDescent(labelfont) *
1381 layout.spacing.getValue() *
1383 + int(lyxfont::maxAscent(labelfont) *
1384 layout.spacing.getValue() *
1388 /* special code for the top label */
1389 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1390 || layout.labeltype == LABEL_BIBLIO
1391 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1392 && row_ptr->par->IsFirstInSequence()
1393 && !row_ptr->par->GetLabelstring().empty()) {
1394 float spacing_val = 1.0;
1395 if (!row_ptr->par->spacing.isDefault()) {
1396 spacing_val = row_ptr->par->spacing.getValue();
1398 spacing_val = buffer->params.spacing.getValue();
1402 (lyxfont::maxAscent(labelfont) *
1403 layout.spacing.getValue() *
1405 +(lyxfont::maxDescent(labelfont) *
1406 layout.spacing.getValue() *
1408 + layout.topsep * DefaultHeight()
1409 + layout.labelbottomsep * DefaultHeight());
1412 /* and now the layout spaces, for example before and after a section,
1413 * or between the items of a itemize or enumerate environment */
1415 if (!firstpar->pagebreak_top) {
1416 LyXParagraph * prev = row_ptr->par->Previous();
1418 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1419 if (prev && prev->GetLayout() == firstpar->GetLayout()
1420 && prev->GetDepth() == firstpar->GetDepth()
1421 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1423 layoutasc = (layout.itemsep * DefaultHeight());
1425 else if (row_ptr->previous) {
1426 tmptop = layout.topsep;
1428 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1429 tmptop-= textclasslist.Style(buffer->params.textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1432 layoutasc = (tmptop * DefaultHeight());
1434 else if (row_ptr->par->line_top){
1435 tmptop = layout.topsep;
1438 layoutasc = (tmptop * DefaultHeight());
1441 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1443 maxasc += int(textclasslist.Style(buffer->params.textclass,
1444 prev->GetLayout()).parsep * DefaultHeight());
1447 if (firstpar->Previous()
1448 && firstpar->Previous()->GetDepth() == 0
1449 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1452 else if (firstpar->Previous()){
1453 maxasc += int(layout.parsep * DefaultHeight());
1459 /* is it a bottom line? */
1460 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1461 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1463 /* the paper margins */
1465 maxdesc += LYX_PAPER_MARGIN;
1467 /* add the vertical spaces, that the user added */
1468 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1469 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1471 /* do not forget the DTP-lines!
1472 * there height depends on the font of the nearest character */
1473 if (firstpar->line_bottom)
1474 maxdesc += 2 * lyxfont::ascent('x', GetFont(par, par->Last() - 1));
1476 /* and now the pagebreaks */
1477 if (firstpar->pagebreak_bottom)
1478 maxdesc += 3 * DefaultHeight();
1480 /* and now the layout spaces, for example before and after a section,
1481 * or between the items of a itemize or enumerate environment */
1482 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1483 LyXParagraph * nextpar = row_ptr->par->Next();
1484 LyXParagraph * comparepar = row_ptr->par;
1488 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1489 usual = (textclasslist.Style(buffer->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1490 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1491 if (comparepar->GetLayout()!= nextpar->GetLayout()
1492 || nextpar->GetLabelWidthString() !=
1493 comparepar->GetLabelWidthString())
1494 unusual = (textclasslist.Style(buffer->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1496 if (unusual > usual)
1497 layoutdesc = unusual;
1501 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1503 if (comparepar->GetLayout()!= nextpar->GetLayout()
1504 || nextpar->GetLabelWidthString() !=
1505 comparepar->GetLabelWidthString())
1506 layoutdesc = int(textclasslist.Style(buffer->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1511 /* incalculate the layout spaces */
1512 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1513 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1515 /* table stuff -- begin*/
1516 if (row_ptr->par->table){
1517 maxasc += row_ptr->par->table->
1518 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1520 /* table stuff -- end*/
1522 /* calculate the new height of the text */
1523 height -= row_ptr->height;
1525 row_ptr->height = maxasc + maxdesc + labeladdon;
1526 row_ptr->baseline = maxasc + labeladdon;
1528 height += row_ptr->height;
1532 /* Appends the implicit specified paragraph behind the specified row,
1533 * start at the implicit given position */
1534 void LyXText::AppendParagraph(Row * row) const
1536 bool not_ready = true;
1538 // The last character position of a paragraph is an invariant so we can
1539 // safely get it here. (Asger)
1540 int lastposition = row->par->Last();
1543 // Get the next breakpoint
1544 int z = NextBreakPoint(row, paperwidth);
1548 // Insert the new row
1549 if (z < lastposition) {
1551 InsertRow(row, row->par, z);
1558 // Set the dimensions of the row
1559 tmprow->fill = Fill(tmprow, paperwidth);
1560 SetHeightOfRow(tmprow);
1562 } while (not_ready);
1566 void LyXText::BreakAgain(Row * row) const
1568 bool not_ready = true;
1571 /* get the next breakpoint */
1572 LyXParagraph::size_type z =
1573 NextBreakPoint(row, paperwidth);
1576 if (z < row->par->Last() ) {
1577 if (!row->next || (row->next && row->next->par != row->par)) {
1580 InsertRow(row, row->par, z);
1587 not_ready = false; // the rest will not change
1593 /* if there are some rows too much, delete them */
1594 /* only if you broke the whole paragraph! */
1595 Row * tmprow2 = row;
1596 while (tmprow2->next && tmprow2->next->par == row->par) {
1597 tmprow2 = tmprow2->next;
1599 while (tmprow2 != row) {
1600 tmprow2 = tmprow2->previous;
1601 RemoveRow(tmprow2->next);
1606 /* set the dimensions of the row */
1607 tmprow->fill = Fill(tmprow, paperwidth);
1608 SetHeightOfRow(tmprow);
1609 } while (not_ready);
1613 /* this is just a little changed version of break again */
1614 void LyXText::BreakAgainOneRow(Row * row)
1616 /* get the next breakpoint */
1617 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1620 if (z < row->par->Last() ) {
1621 if (!row->next || (row->next && row->next->par != row->par)) {
1622 /* insert a new row */
1624 InsertRow(row, row->par, z);
1636 /* if there are some rows too much, delete them */
1637 /* only if you broke the whole paragraph! */
1638 Row * tmprow2 = row;
1639 while (tmprow2->next && tmprow2->next->par == row->par) {
1640 tmprow2 = tmprow2->next;
1642 while (tmprow2 != row) {
1643 tmprow2 = tmprow2->previous;
1644 RemoveRow(tmprow2->next);
1648 /* set the dimensions of the row */
1649 tmprow->fill = Fill(tmprow, paperwidth);
1650 SetHeightOfRow(tmprow);
1654 void LyXText::BreakParagraph(char keep_layout)
1656 LyXLayout const & layout = textclasslist.Style(buffer->params.textclass,
1657 cursor.par->GetLayout());
1659 /* table stuff -- begin */
1660 if (cursor.par->table) {
1661 // breaking of tables is only allowed at the beginning or the end */
1662 if (cursor.pos && cursor.pos < cursor.par->size() &&
1663 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1664 return; // no breaking of tables allowed
1666 /* table stuff -- end */
1668 // this is only allowed, if the current paragraph is not empty or caption
1669 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1671 layout.labeltype!= LABEL_SENSITIVE)
1674 SetUndo(Undo::INSERT,
1675 cursor.par->ParFromPos(cursor.pos)->previous,
1676 cursor.par->ParFromPos(cursor.pos)->next);
1678 /* table stuff -- begin */
1679 if (cursor.par->table) {
1680 int cell = NumberOfCell(cursor.par, cursor.pos);
1681 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1682 SetCursor(cursor.par, cursor.par->size());
1684 /* table stuff -- end */
1686 // please break always behind a space
1687 if (cursor.pos < cursor.par->Last()
1688 && cursor.par->IsLineSeparator(cursor.pos))
1691 // break the paragraph
1695 keep_layout = layout.isEnvironment();
1696 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1698 /* table stuff -- begin */
1699 if (cursor.par->table){
1700 // the table should stay with the contents
1702 cursor.par->Next()->table = cursor.par->table;
1703 cursor.par->table = 0;
1706 /* table stuff -- end */
1708 // well this is the caption hack since one caption is really enough
1709 if (layout.labeltype == LABEL_SENSITIVE) {
1711 cursor.par->SetLayout(0); // set to standard-layout
1713 cursor.par->Next()->SetLayout(0); // set to standard-layout
1716 /* if the cursor is at the beginning of a row without prior newline,
1718 * This touches only the screen-update. Otherwise we would may have
1719 * an empty row on the screen */
1720 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1721 cursor.row->pos == cursor.pos) {
1725 status = LyXText::NEED_MORE_REFRESH;
1726 refresh_row = cursor.row;
1727 refresh_y = cursor.y - cursor.row->baseline;
1729 // Do not forget the special right address boxes
1730 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1731 while (refresh_row->previous &&
1732 refresh_row->previous->par == refresh_row->par) {
1733 refresh_row = refresh_row->previous;
1734 refresh_y -= refresh_row->height;
1737 RemoveParagraph(cursor.row);
1739 // set the dimensions of the cursor row
1740 cursor.row->fill = Fill(cursor.row, paperwidth);
1742 SetHeightOfRow(cursor.row);
1744 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1745 && cursor.par->Next()->IsNewline(0))
1746 cursor.par->Next()->Erase(0);
1748 InsertParagraph(cursor.par->Next(), cursor.row);
1750 UpdateCounters(cursor.row->previous);
1752 /* This check is necessary. Otherwise the new empty paragraph will
1753 * be deleted automatically. And it is more friendly for the user! */
1755 SetCursor(cursor.par->Next(), 0);
1757 SetCursor(cursor.par, 0);
1759 if (cursor.row->next)
1760 BreakAgain(cursor.row->next);
1766 void LyXText::OpenFootnote()
1768 LyXParagraph * endpar,* tmppar;
1771 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1773 /* if there is no footnote in this paragraph, just return. */
1775 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1778 /* ok, move the cursor right before the footnote */
1780 /* just a little faster than using CursorRight() */
1781 for (cursor.pos = 0;
1782 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1783 /* now the cursor is at the beginning of the physical par */
1784 SetCursor(cursor.par,
1785 cursor.pos + cursor.par->ParFromPos(cursor.pos)->size());
1787 /* the cursor must be exactly before the footnote */
1788 par = cursor.par->ParFromPos(cursor.pos);
1790 status = LyXText::NEED_MORE_REFRESH;
1791 refresh_row = cursor.row;
1792 refresh_y = cursor.y - cursor.row->baseline;
1794 tmppar = cursor.par;
1795 endpar = cursor.par->Next();
1798 tmppar->OpenFootnote(cursor.pos);
1799 RemoveParagraph(row);
1800 /* set the dimensions of the cursor row */
1801 row->fill = Fill(row, paperwidth);
1802 SetHeightOfRow(row);
1803 // CHECK See comment on top of text.C
1804 tmppar = tmppar->Next();
1806 while (tmppar != endpar) {
1808 InsertParagraph(tmppar, row);
1809 while (row->next && row->next->par == tmppar)
1811 tmppar = tmppar->Next();
1814 SetCursor(par->next, 0);
1815 sel_cursor = cursor;
1819 /* table stuff -- begin*/
1821 void LyXText::TableFeatures(int feature, string const & val) const
1823 if (!cursor.par->table)
1824 return; /* this should never happen */
1826 int actCell = NumberOfCell(cursor.par, cursor.pos);
1827 SetUndo(Undo::FINISH,
1828 cursor.par->ParFromPos(cursor.pos)->previous,
1829 cursor.par->ParFromPos(cursor.pos)->next);
1832 case LyXTable::SET_PWIDTH:
1833 cursor.par->table->SetPWidth(actCell, val);
1835 case LyXTable::SET_SPECIAL_COLUMN:
1836 case LyXTable::SET_SPECIAL_MULTI:
1837 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1846 void LyXText::TableFeatures(int feature) const
1849 int setAlign = LYX_ALIGN_LEFT;
1853 if (!cursor.par->table)
1854 return; /* this should never happen */
1856 int actCell = NumberOfCell(cursor.par, cursor.pos);
1857 SetUndo(Undo::FINISH,
1858 cursor.par->ParFromPos(cursor.pos)->previous,
1859 cursor.par->ParFromPos(cursor.pos)->next);
1862 case LyXTable::ALIGN_LEFT:
1863 setAlign= LYX_ALIGN_LEFT;
1865 case LyXTable::ALIGN_RIGHT:
1866 setAlign= LYX_ALIGN_RIGHT;
1868 case LyXTable::ALIGN_CENTER:
1869 setAlign= LYX_ALIGN_CENTER;
1875 case LyXTable::APPEND_ROW: {
1876 LyXParagraph::size_type pos = cursor.pos;
1878 /* move to the next row */
1879 int cell_org = actCell;
1880 int cell = cell_org;
1882 // if there is a ContRow following this row I have to add
1883 // the row after the ContRow's
1884 if ((pos < cursor.par->Last()) &&
1885 cursor.par->table->RowHasContRow(cell_org)) {
1886 while((pos < cursor.par->Last()) &&
1887 !cursor.par->table->IsContRow(cell)) {
1888 while (pos < cursor.par->Last() &&
1889 !cursor.par->IsNewline(pos))
1891 if (pos < cursor.par->Last())
1895 while((pos < cursor.par->Last()) &&
1896 cursor.par->table->IsContRow(cell)) {
1897 while (pos < cursor.par->Last() &&
1898 !cursor.par->IsNewline(pos))
1900 if (pos < cursor.par->Last())
1905 if (pos < cursor.par->Last())
1908 while (pos < cursor.par->Last() &&
1909 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1910 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1912 if (pos < cursor.par->Last())
1917 /* insert the new cells */
1918 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1919 Language const * lang = cursor.par->getParLanguage();
1920 LyXFont font(LyXFont::ALL_INHERIT,lang);
1921 for (int i = 0; i < number; ++i) {
1922 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1923 cursor.par->SetFont(pos, font);
1926 /* append the row into the table */
1927 cursor.par->table->AppendRow(cell_org);
1931 case LyXTable::APPEND_CONT_ROW: {
1932 LyXParagraph::size_type pos = cursor.pos;
1933 /* move to the next row */
1934 int cell_org = actCell;
1935 int cell = cell_org;
1937 // if there is already a controw but not for this cell
1938 // the AppendContRow sets only the right values but does
1939 // not actually add a row
1940 if (cursor.par->table->RowHasContRow(cell_org) &&
1941 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1942 cursor.par->table->AppendContRow(cell_org);
1946 while (pos < cursor.par->Last() &&
1948 || !cursor.par->table->IsFirstCell(cell))){
1949 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1951 if (pos < cursor.par->Last())
1956 /* insert the new cells */
1957 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1958 Language const * lang = cursor.par->getParLanguage();
1959 LyXFont font(LyXFont::ALL_INHERIT,lang);
1960 for (int i = 0; i < number; ++i) {
1961 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1962 cursor.par->SetFont(pos, font);
1965 /* append the row into the table */
1966 cursor.par->table->AppendContRow(cell_org);
1970 case LyXTable::APPEND_COLUMN: {
1971 LyXParagraph::size_type pos = 0;
1972 int cell_org = actCell;
1974 Language const * lang = cursor.par->getParLanguage();
1975 LyXFont font(LyXFont::ALL_INHERIT,lang);
1977 if (pos && (cursor.par->IsNewline(pos-1))){
1978 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1979 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1980 cursor.par->SetFont(pos, font);
1981 if (pos <= cursor.pos)
1988 } while (pos <= cursor.par->Last());
1989 /* remember that the very last cell doesn't end with a newline.
1990 This saves one byte memory per table ;-) */
1991 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1992 LyXParagraph::size_type last = cursor.par->Last();
1993 cursor.par->InsertChar(last, LyXParagraph::META_NEWLINE);
1994 cursor.par->SetFont(last, font);
1997 /* append the column into the table */
1998 cursor.par->table->AppendColumn(cell_org);
2003 case LyXTable::DELETE_ROW:
2004 if (owner_->the_locking_inset)
2005 owner_->unlockInset(owner_->the_locking_inset);
2006 RemoveTableRow(&cursor);
2010 case LyXTable::DELETE_COLUMN: {
2011 LyXParagraph::size_type pos = 0;
2012 int cell_org = actCell;
2014 if (owner_->the_locking_inset)
2015 owner_->unlockInset(owner_->the_locking_inset);
2017 if (!pos || (cursor.par->IsNewline(pos-1))){
2018 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2020 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2021 cursor.par->Erase(pos);
2022 if (pos < cursor.par->Last())
2023 cursor.par->Erase(pos);
2025 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
2026 --pos; // because of pos++ below
2031 } while (pos <= cursor.par->Last());
2033 /* delete the column from the table */
2034 cursor.par->table->DeleteColumn(cell_org);
2036 /* set the cursor to the beginning of the table, where else? */
2041 case LyXTable::TOGGLE_LINE_TOP:
2042 lineSet = !cursor.par->table->TopLine(actCell);
2044 cursor.par->table->SetTopLine(actCell, lineSet);
2046 LyXParagraph::size_type i;
2048 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2049 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2050 cursor.par->table->SetTopLine(n, lineSet);
2058 case LyXTable::TOGGLE_LINE_BOTTOM:
2059 lineSet = !cursor.par->table->BottomLine(actCell);
2061 cursor.par->table->SetBottomLine(actCell, lineSet);
2063 LyXParagraph::size_type i;
2065 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2066 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2067 cursor.par->table->SetBottomLine(n, lineSet);
2075 case LyXTable::TOGGLE_LINE_LEFT:
2076 lineSet = !cursor.par->table->LeftLine(actCell);
2078 cursor.par->table->SetLeftLine(actCell, lineSet);
2080 LyXParagraph::size_type i;
2082 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2083 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2084 cursor.par->table->SetLeftLine(n, lineSet);
2092 case LyXTable::TOGGLE_LINE_RIGHT:
2093 lineSet = !cursor.par->table->RightLine(actCell);
2095 cursor.par->table->SetRightLine(actCell, lineSet);
2098 LyXParagraph::size_type i = sel_start_cursor.pos;
2099 for (; i <= sel_end_cursor.pos; ++i) {
2100 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2101 cursor.par->table->SetRightLine(n, lineSet);
2109 case LyXTable::ALIGN_LEFT:
2110 case LyXTable::ALIGN_RIGHT:
2111 case LyXTable::ALIGN_CENTER:
2113 cursor.par->table->SetAlignment(actCell, setAlign);
2116 LyXParagraph::size_type i = sel_start_cursor.pos;
2117 for (; i <= sel_end_cursor.pos; ++i) {
2118 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2119 cursor.par->table->SetAlignment(n, setAlign);
2127 case LyXTable::DELETE_TABLE:
2128 SetCursorIntern(cursor.par, 0);
2129 delete cursor.par->table;
2130 cursor.par->table = 0;
2131 // temporary: Should put table in simple_cut_buffer (with before and after
2132 // dummy-paragraph !!
2133 // not necessar anymore with UNDO :)
2134 for (LyXParagraph::size_type i =
2135 cursor.par->size() - 1; i >= 0; --i)
2136 cursor.par->Erase(i);
2140 case LyXTable::MULTICOLUMN: {
2142 // check wether we are completly in a multicol
2143 int multicol = cursor.par->table->IsMultiColumn(actCell);
2144 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2145 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2146 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2150 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2151 LyXParagraph::size_type pos = cursor.pos;
2152 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2154 for (; newlines; --newlines)
2155 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2160 // selection must be in one row (or no selection)
2162 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2169 if (sel_start_cursor.row == sel_end_cursor.row){
2170 LyXParagraph::size_type i;
2172 for (i = sel_start_cursor.pos;
2173 i < sel_end_cursor.pos; ++i){
2174 if (sel_start_cursor.par->IsNewline(i)){
2175 sel_start_cursor.par->Erase(i);
2176 // check for double-blanks
2177 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2179 (i < sel_start_cursor.par->Last()
2180 && !sel_start_cursor.par->IsLineSeparator(i)))
2181 sel_start_cursor.par->InsertChar(i, ' ');
2183 sel_end_cursor.pos--;
2190 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2191 sel_start_cursor.pos),
2193 cursor.pos = sel_start_cursor.pos;
2198 WriteAlert(_("Impossible Operation!"),
2199 _("Multicolumns can only be horizontally."),
2206 case LyXTable::SET_ALL_LINES:
2208 case LyXTable::UNSET_ALL_LINES:
2210 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2214 LyXParagraph::size_type i;
2216 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2217 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2218 cursor.par->table->SetAllLines(n, setLines);
2225 case LyXTable::SET_LONGTABLE:
2226 cursor.par->table->SetLongTable(true);
2228 case LyXTable::UNSET_LONGTABLE:
2229 cursor.par->table->SetLongTable(false);
2231 case LyXTable::SET_ROTATE_TABLE:
2232 cursor.par->table->SetRotateTable(true);
2234 case LyXTable::UNSET_ROTATE_TABLE:
2235 cursor.par->table->SetRotateTable(false);
2237 case LyXTable::SET_ROTATE_CELL:
2239 cursor.par->table->SetRotateCell(actCell, true);
2241 LyXParagraph::size_type i;
2243 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2244 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2245 cursor.par->table->SetRotateCell(n, true);
2251 case LyXTable::UNSET_ROTATE_CELL:
2253 cursor.par->table->SetRotateCell(actCell, false);
2256 LyXParagraph::size_type i = sel_start_cursor.pos;
2257 for (; i <= sel_end_cursor.pos; ++i) {
2258 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2259 cursor.par->table->SetRotateCell(n, false);
2265 case LyXTable::SET_LINEBREAKS:
2266 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2268 cursor.par->table->SetLinebreaks(actCell, what);
2270 LyXParagraph::size_type i;
2272 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2273 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2274 cursor.par->table->SetLinebreaks(n, what);
2280 case LyXTable::SET_LTFIRSTHEAD:
2281 cursor.par->table->SetLTHead(actCell, true);
2283 case LyXTable::SET_LTHEAD:
2284 cursor.par->table->SetLTHead(actCell, false);
2286 case LyXTable::SET_LTFOOT:
2287 cursor.par->table->SetLTFoot(actCell, false);
2289 case LyXTable::SET_LTLASTFOOT:
2290 cursor.par->table->SetLTFoot(actCell, true);
2292 case LyXTable::SET_LTNEWPAGE:
2293 what = !cursor.par->table->LTNewPage(actCell);
2294 cursor.par->table->SetLTNewPage(actCell, what);
2300 void LyXText::InsertCharInTable(char c)
2305 bool jumped_over_space;
2307 /* first check, if there will be two blanks together or a blank at
2308 * the beginning of a paragraph.
2309 * I decided to handle blanks like normal characters, the main
2310 * difference are the special checks when calculating the row.fill
2311 * (blank does not count at the end of a row) and the check here */
2313 LyXFont realtmpfont = real_current_font;
2314 LyXFont rawtmpfont = current_font; /* store the current font.
2315 * This is because of the use
2316 * of cursor movements. The moving
2317 * cursor would refresh the
2320 // Get the font that is used to calculate the baselineskip
2321 LyXParagraph::size_type const lastpos =
2323 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2325 jumped_over_space = false;
2326 if (IsLineSeparatorChar(c)) {
2327 if ((cursor.pos > 0 &&
2328 cursor.par->IsLineSeparator(cursor.pos - 1))
2329 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2330 || (cursor.pos == 0 &&
2331 !(cursor.par->Previous()
2332 && cursor.par->Previous()->footnoteflag
2333 == LyXParagraph::OPEN_FOOTNOTE)))
2335 } else if (IsNewlineChar(c)) {
2336 if (!IsEmptyTableCell()) {
2337 TableFeatures(LyXTable::APPEND_CONT_ROW);
2344 y = cursor.y - row->baseline;
2345 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2346 * already inserted the character */
2347 cursor.par->InsertChar(cursor.pos, c);
2348 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2350 if (!jumped_over_space) {
2351 /* refresh the positions */
2353 while (tmprow->next && tmprow->next->par == row->par) {
2354 tmprow = tmprow->next;
2361 CheckParagraphInTable(cursor.par, cursor.pos);
2363 current_font = rawtmpfont;
2364 real_current_font = realtmpfont;
2366 /* check, whether the last character's font has changed. */
2367 if (cursor.pos && cursor.pos == cursor.par->Last()
2368 && rawparfont != rawtmpfont)
2369 RedoHeightOfParagraph(cursor);
2373 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2374 LyXParagraph::size_type pos)
2377 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2378 par->GetInset(pos) && par->GetInset(pos)->display()){
2379 par->GetInset(pos)->display(false);
2383 Row * row = GetRow(par, pos, y);
2385 int tmpheight = row->height;
2386 SetHeightOfRow(row);
2388 LyXParagraph::size_type tmp_pos = pos;
2389 /* update the table information */
2390 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2392 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2393 WidthOfCell(par, tmp_pos))) {
2394 LyXCursor tmpcursor = cursor;
2395 SetCursorIntern(par, pos);
2396 /* make a complete redraw */
2397 RedoDrawingOfParagraph(cursor);
2401 /* redraw only the row */
2402 LyXCursor tmpcursor = cursor;
2403 SetCursorIntern(par, pos);
2404 //CHECK See comment on top of text.C
2406 refresh_x = cursor.x;
2408 refresh_pos = cursor.pos;
2411 if (tmpheight == row->height)
2412 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2414 status = LyXText::NEED_MORE_REFRESH;
2416 SetCursorIntern(cursor.par, cursor.pos);
2420 void LyXText::BackspaceInTable()
2422 Row * tmprow, * row;
2425 LyXFont rawtmpfont = current_font;
2426 LyXFont realtmpfont = real_current_font;
2428 // Get the font that is used to calculate the baselineskip
2429 int const lastpos = cursor.par->Last();
2430 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2432 if (cursor.pos == 0) {
2433 /* no pasting of table paragraphs */
2437 /* this is the code for a normal backspace, not pasting
2439 SetUndo(Undo::DELETE,
2440 cursor.par->ParFromPos(cursor.pos)->previous,
2441 cursor.par->ParFromPos(cursor.pos)->next);
2445 /* some insets are undeletable here */
2446 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2447 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2452 y = cursor.y - row->baseline;
2454 /* some special code when deleting a newline. */
2455 if (cursor.par->IsNewline(cursor.pos)) {
2459 cursor.par->Erase(cursor.pos);
2461 /* refresh the positions */
2463 while (tmprow->next && tmprow->next->par == row->par) {
2464 tmprow = tmprow->next;
2469 CheckParagraphInTable(cursor.par, cursor.pos);
2471 /* check, wether the last characters font has changed. */
2472 if (cursor.pos && cursor.pos == cursor.par->Last()
2473 && rawparfont != rawtmpfont)
2474 RedoHeightOfParagraph(cursor);
2476 /* restore the current font
2477 * That is what a user expects! */
2478 current_font = rawtmpfont;
2479 real_current_font = realtmpfont;
2481 SetCursorIntern(cursor.par, cursor.pos);
2484 /* table stuff -- end*/
2487 /* just a macro to make some thing easier. */
2488 void LyXText::RedoParagraph() const
2491 RedoParagraphs(cursor, cursor.par->Next());
2492 SetCursorIntern(cursor.par, cursor.pos);
2496 /* insert a character, moves all the following breaks in the
2497 * same Paragraph one to the right and make a rebreak */
2498 void LyXText::InsertChar(char c)
2500 SetUndo(Undo::INSERT,
2501 cursor.par->ParFromPos(cursor.pos)->previous,
2502 cursor.par->ParFromPos(cursor.pos)->next);
2504 /* When the free-spacing option is set for the current layout,
2505 * disable the double-space checking */
2508 textclasslist.Style(buffer->params.textclass,
2509 cursor.row->par->GetLayout()).free_spacing;
2511 /* table stuff -- begin*/
2512 if (cursor.par->table) {
2513 InsertCharInTable(c);
2517 /* table stuff -- end*/
2519 /* First check, if there will be two blanks together or a blank at
2520 the beginning of a paragraph.
2521 I decided to handle blanks like normal characters, the main
2522 difference are the special checks when calculating the row.fill
2523 (blank does not count at the end of a row) and the check here */
2525 // The bug is triggered when we type in a description environment:
2526 // The current_font is not changed when we go from label to main text
2527 // and it should (along with realtmpfont) when we type the space.
2528 // CHECK There is a bug here! (Asger)
2530 LyXFont realtmpfont = real_current_font;
2531 LyXFont rawtmpfont = current_font; /* store the current font.
2532 * This is because of the use
2533 * of cursor movements. The moving
2534 * cursor would refresh the
2537 // Get the font that is used to calculate the baselineskip
2538 LyXParagraph::size_type lastpos = cursor.par->Last();
2539 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2541 bool jumped_over_space = false;
2543 if (!freeSpacing && IsLineSeparatorChar(c)) {
2545 && cursor.par->IsLineSeparator(cursor.pos - 1))
2547 && cursor.par->IsNewline(cursor.pos - 1))
2549 && !(cursor.par->Previous()
2550 && cursor.par->Previous()->footnoteflag
2551 == LyXParagraph::OPEN_FOOTNOTE))) {
2552 if (cursor.pos == 0 )
2553 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2555 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2559 } else if (IsNewlineChar(c)) {
2560 if (cursor.par->FirstPhysicalPar() == cursor.par
2561 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2565 /* No newline at first position
2566 * of a paragraph or behind labels.
2567 * TeX does not allow that. */
2569 if (cursor.pos < cursor.par->Last() &&
2570 cursor.par->IsLineSeparator(cursor.pos))
2571 CursorRightIntern(); // newline always after a blank!
2572 cursor.row->fill = -1; // to force a new break
2575 // the display inset stuff
2576 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2577 && cursor.row->par->GetInset(cursor.row->pos)
2578 && cursor.row->par->GetInset(cursor.row->pos)->display())
2579 cursor.row->fill = -1; // to force a new break
2581 // get the cursor row fist
2582 Row * row = cursor.row;
2583 long y = cursor.y - row->baseline;
2584 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2585 * already insertet the character */
2586 cursor.par->InsertChar(cursor.pos, c);
2587 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2589 if (!jumped_over_space) {
2590 // refresh the positions
2592 while (tmprow->next && tmprow->next->par == row->par) {
2593 tmprow = tmprow->next;
2598 // Is there a break one row above
2599 if ((cursor.par->IsLineSeparator(cursor.pos)
2600 || cursor.par->IsNewline(cursor.pos)
2601 || cursor.row->fill == -1)
2602 && row->previous && row->previous->par == row->par) {
2603 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2605 if ( z >= row->pos) {
2608 // set the dimensions of the row above
2609 row->previous->fill = Fill(row->previous, paperwidth);
2611 SetHeightOfRow(row->previous);
2613 y -= row->previous->height;
2615 refresh_row = row->previous;
2616 status = LyXText::NEED_MORE_REFRESH;
2618 BreakAgainOneRow(row);
2620 current_font = rawtmpfont;
2621 real_current_font = realtmpfont;
2622 SetCursor(cursor.par, cursor.pos + 1, false);
2623 /* cursor MUST be in row now */
2625 if (row->next && row->next->par == row->par)
2626 need_break_row = row->next;
2630 // check, wether the last characters font has changed.
2631 if (cursor.pos && cursor.pos == cursor.par->Last()
2632 && rawparfont != rawtmpfont)
2633 RedoHeightOfParagraph(cursor);
2640 /* recalculate the fill of the row */
2641 if (row->fill >= 0) /* needed because a newline
2642 * will set fill to -1. Otherwise
2643 * we would not get a rebreak! */
2644 row->fill = Fill(row, paperwidth);
2645 if (row->fill < 0 ) {
2648 refresh_x = cursor.x;
2649 refresh_pos = cursor.pos;
2650 status = LyXText::NEED_MORE_REFRESH;
2651 BreakAgainOneRow(row);
2652 /* will the cursor be in another row now? */
2653 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2654 if (row->next && row->next->par == row->par)
2658 BreakAgainOneRow(row);
2660 current_font = rawtmpfont;
2661 real_current_font = realtmpfont;
2662 SetCursor(cursor.par, cursor.pos + 1, false);
2663 if (row->next && row->next->par == row->par)
2664 need_break_row = row->next;
2669 refresh_x = cursor.x;
2671 refresh_pos = cursor.pos;
2673 int tmpheight = row->height;
2674 SetHeightOfRow(row);
2675 if (tmpheight == row->height)
2676 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2678 status = LyXText::NEED_MORE_REFRESH;
2680 current_font = rawtmpfont;
2681 real_current_font = realtmpfont;
2682 SetCursor(cursor.par, cursor.pos + 1, false);
2685 /* check, wether the last characters font has changed. */
2686 if (cursor.pos && cursor.pos == cursor.par->Last()
2687 && rawparfont != rawtmpfont) {
2688 RedoHeightOfParagraph(cursor);
2690 /* now the special right address boxes */
2691 if (textclasslist.Style(buffer->params.textclass,
2692 cursor.par->GetLayout()).margintype
2693 == MARGIN_RIGHT_ADDRESS_BOX) {
2694 RedoDrawingOfParagraph(cursor);
2702 void LyXText::charInserted()
2704 // Here we could call FinishUndo for every 20 characters inserted.
2705 // This is from my experience how emacs does it.
2706 static unsigned int counter = 0;
2715 void LyXText::PrepareToPrint(Row * row, float & x,
2716 float & fill_separator,
2718 float & fill_label_hfill,
2723 float w = row->fill;
2725 fill_label_hfill = 0;
2727 fill_label_hfill = 0;
2729 bool is_rtl = row->par->isRightToLeftPar();
2732 x = RightMargin(row);
2733 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2734 LyXFont font(LyXFont::ALL_SANE);
2735 font.setSize(LyXFont::SIZE_SMALL);
2736 x += lyxfont::width("Mwide-figM", font);
2739 x = LeftMargin(row);
2741 /* is there a manual margin with a manual label */
2742 if (textclasslist.Style(buffer->params.textclass,
2743 row->par->GetLayout()).margintype == MARGIN_MANUAL
2744 && textclasslist.Style(buffer->params.textclass,
2745 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2747 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2748 * are left aligned*/
2749 if (nlh && !row->par->GetLabelWidthString().empty()) {
2750 fill_label_hfill = LabelFill(row) / nlh;
2754 /* are there any hfills in the row? */
2755 nh = NumberOfHfills(row);
2757 /* table stuff -- begin*/
2758 if (row->par->table) {
2759 w = paperwidth - row->par->table->WidthOfTable()
2760 - x - RightMargin(row);
2761 nh = 0; /* ignore hfills in tables */
2763 /* table stuff -- end*/
2768 /* is it block, flushleft or flushright?
2769 * set x how you need it */
2771 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2772 align = textclasslist.Style(buffer->params.textclass, row->par->GetLayout()).align;
2774 align = row->par->FirstPhysicalPar()->align;
2776 /* center displayed insets */
2777 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2778 && row->par->GetInset(row->pos)
2779 && row->par->GetInset(row->pos)->display())
2780 align = LYX_ALIGN_CENTER;
2783 case LYX_ALIGN_BLOCK:
2784 ns = NumberOfSeparators(row);
2785 if (ns && row->next && row->next->par == row->par &&
2786 !(row->next->par->IsNewline(row->next->pos-1))
2787 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2788 && row->next->par->GetInset(row->next->pos)
2789 && row->next->par->GetInset(row->next->pos)->display())
2791 fill_separator = w / ns;
2795 case LYX_ALIGN_RIGHT:
2798 case LYX_ALIGN_CENTER:
2806 ComputeBidiTables(row);
2808 LyXParagraph::size_type main_body =
2809 BeginningOfMainBody(row->par);
2810 LyXParagraph::size_type last = RowLast(row);
2812 if (main_body > 0 &&
2813 (main_body-1 > last ||
2814 !row->par->IsLineSeparator(main_body-1))) {
2815 LyXLayout const & layout = textclasslist.Style(buffer->params.textclass,
2816 row->par->GetLayout());
2817 x += lyxfont::width(layout.labelsep,
2818 GetFont(row->par, -2));
2819 if (main_body-1 <= last)
2820 x += fill_label_hfill;
2825 /* important for the screen */
2828 /* the cursor set functions have a special mechanism. When they
2829 * realize, that you left an empty paragraph, they will delete it.
2830 * They also delete the corresponding row */
2832 void LyXText::CursorRightOneWord() const
2834 // treat floats, HFills and Insets as words
2835 LyXCursor tmpcursor = cursor;
2836 // CHECK See comment on top of text.C
2838 if (tmpcursor.pos == tmpcursor.par->Last()
2839 && tmpcursor.par->Next())
2841 tmpcursor.par = tmpcursor.par->Next();
2846 // Skip through initial nonword stuff.
2847 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2848 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2850 // printf("Current pos1 %d", tmpcursor.pos) ;
2854 // Advance through word.
2855 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2856 tmpcursor.par->IsWord( tmpcursor.pos ) )
2858 // printf("Current pos2 %d", tmpcursor.pos) ;
2863 SetCursor(tmpcursor.par, tmpcursor.pos);
2867 void LyXText::CursorTab() const
2869 if (cursor.par->table) {
2870 int cell = NumberOfCell(cursor.par, cursor.pos);
2871 while(cursor.par->table->IsContRow(cell)) {
2873 cell = NumberOfCell(cursor.par, cursor.pos);
2875 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2876 TableFeatures(LyXTable::APPEND_ROW);
2878 LyXCursor tmpcursor = cursor;
2879 while (tmpcursor.pos < tmpcursor.par->Last()
2880 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2883 if (tmpcursor.pos == tmpcursor.par->Last()){
2884 if (tmpcursor.par->Next()) {
2885 tmpcursor.par = tmpcursor.par->Next();
2891 SetCursor(tmpcursor.par, tmpcursor.pos);
2892 if (cursor.par->table) {
2893 int cell = NumberOfCell(cursor.par, cursor.pos);
2894 while (cursor.par->table->IsContRow(cell) &&
2895 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2897 while (tmpcursor.pos < tmpcursor.par->Last()
2898 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2901 if (tmpcursor.pos == tmpcursor.par->Last()){
2902 if (tmpcursor.par->Next()) {
2903 tmpcursor.par = tmpcursor.par->Next();
2909 SetCursor(tmpcursor.par, tmpcursor.pos);
2910 cell = NumberOfCell(cursor.par, cursor.pos);
2916 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2917 of prior word, not to end of next prior word. */
2919 void LyXText::CursorLeftOneWord() const
2921 // treat HFills, floats and Insets as words
2922 LyXCursor tmpcursor = cursor;
2923 while (tmpcursor.pos
2924 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2925 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2926 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2927 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2928 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2932 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2933 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2934 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2936 } else if (!tmpcursor.pos) {
2937 if (tmpcursor.par->Previous()){
2938 tmpcursor.par = tmpcursor.par->Previous();
2939 tmpcursor.pos = tmpcursor.par->Last();
2941 } else { // Here, tmpcursor != 0
2942 while (tmpcursor.pos > 0 &&
2943 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2946 SetCursor(tmpcursor.par, tmpcursor.pos);
2949 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2952 void LyXText::SelectWord()
2954 /* Move cursor to the beginning, when not already there. */
2956 && !cursor.par->IsSeparator(cursor.pos-1)
2957 && !cursor.par->IsKomma(cursor.pos-1) )
2958 CursorLeftOneWord();
2960 /* set the sel cursor */
2961 sel_cursor = cursor;
2963 while ( cursor.pos < cursor.par->Last()
2964 && !cursor.par->IsSeparator(cursor.pos)
2965 && !cursor.par->IsKomma(cursor.pos) )
2967 SetCursor( cursor.par, cursor.pos );
2969 /* finally set the selection */
2974 /* -------> Select the word currently under the cursor when:
2975 1: no selection is currently set,
2976 2: the cursor is not at the borders of the word. */
2978 bool LyXText::SelectWordWhenUnderCursor()
2981 cursor.pos > 0 && cursor.pos < cursor.par->Last()
2982 && !cursor.par->IsSeparator(cursor.pos)
2983 && !cursor.par->IsKomma(cursor.pos)
2984 && !cursor.par->IsSeparator(cursor.pos -1)
2985 && !cursor.par->IsKomma(cursor.pos -1) ) {
2993 // This function is only used by the spellchecker for NextWord().
2994 // It doesn't handle LYX_ACCENTs and probably never will.
2995 char * LyXText::SelectNextWord(float & value)
2997 LyXParagraph * tmppar = cursor.par;
2999 // If this is not the very first word, skip rest of
3000 // current word because we are probably in the middle
3001 // of a word if there is text here.
3002 if (cursor.pos || cursor.par->previous) {
3003 while (cursor.pos < cursor.par->Last()
3004 && cursor.par->IsLetter(cursor.pos))
3007 // Now, skip until we have real text (will jump paragraphs)
3008 while ((cursor.par->Last() > cursor.pos
3009 && (!cursor.par->IsLetter(cursor.pos)
3010 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
3011 || (cursor.par->Last() == cursor.pos
3012 && cursor.par->Next())){
3013 if (cursor.pos == cursor.par->Last()) {
3014 cursor.par = cursor.par->Next();
3021 // Update the value if we changed paragraphs
3022 if (cursor.par != tmppar){
3023 SetCursor(cursor.par, cursor.pos);
3024 value = float(cursor.y)/float(height);
3027 /* Start the selection from here */
3028 sel_cursor = cursor;
3031 std::ostringstream latex;
3035 /* and find the end of the word
3036 (optional hyphens are part of a word) */
3037 while (cursor.pos < cursor.par->Last()
3038 && (cursor.par->IsLetter(cursor.pos))
3039 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3040 && cursor.par->GetInset(cursor.pos) != 0
3041 && cursor.par->GetInset(cursor.pos)->Latex(latex, false, false) == 0
3043 && latex.str() == "\\-"
3045 && string(latex.str(), 3) == "\\-" // this is not nice at all
3050 #ifndef HAVE_SSTREAM
3051 delete [] latex.str();
3053 // Finally, we copy the word to a string and return it
3056 if (sel_cursor.pos < cursor.pos) {
3057 str = new char [cursor.pos - sel_cursor.pos + 2];
3058 LyXParagraph::size_type i, j;
3059 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3060 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3061 str[j++] = cursor.par->GetChar(i);
3069 // This one is also only for the spellchecker
3070 void LyXText::SelectSelectedWord()
3072 /* move cursor to the beginning */
3073 SetCursor(sel_cursor.par, sel_cursor.pos);
3075 /* set the sel cursor */
3076 sel_cursor = cursor;
3079 std::ostringstream latex;
3084 /* now find the end of the word */
3085 while (cursor.pos < cursor.par->Last()
3086 && (cursor.par->IsLetter(cursor.pos)
3087 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3088 && cursor.par->GetInset(cursor.pos) != 0
3089 && cursor.par->GetInset(cursor.pos)->Latex(latex, false, false) == 0
3091 && latex.str() == "\\-"
3093 && string(latex.str(), 3) == "\\-"
3098 #ifndef HAVE_SSTREAM
3099 delete [] latex.str();
3101 SetCursor(cursor.par, cursor.pos);
3103 /* finally set the selection */
3108 /* -------> Delete from cursor up to the end of the current or next word. */
3109 void LyXText::DeleteWordForward()
3111 LyXCursor tmpcursor = cursor;
3113 if (!cursor.par->Last())
3115 // CHECK See comment on top of text.C
3117 /* -------> Skip initial non-word stuff. */
3118 while ( cursor.pos < cursor.par->Last()
3119 && (cursor.par->IsSeparator(cursor.pos)
3120 || cursor.par->IsKomma(cursor.pos)) )
3123 SetCursorIntern(cursor.par, cursor.pos);
3124 selection = True; // to avoid deletion
3125 CursorRightOneWord();
3126 sel_cursor = cursor;
3130 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3136 /* -------> Delete from cursor to start of current or prior word. */
3137 void LyXText::DeleteWordBackward()
3139 LyXCursor tmpcursor = cursor;
3140 if (!cursor.par->Last())
3142 // CHECK See comment on top of text.C
3144 selection = true; // to avoid deletion
3145 CursorLeftOneWord();
3146 sel_cursor = cursor;
3154 /* -------> Kill to end of line. */
3155 void LyXText::DeleteLineForward()
3157 LyXCursor tmpcursor = cursor;
3158 if (!cursor.par->Last())
3160 // CHECK See comment on top of text.C
3163 sel_cursor = cursor;
3166 if (selection == false) {
3167 DeleteWordForward();
3175 // Change the case of a word at cursor position. The meaning of action
3177 // 0 change to lowercase
3178 // 1 capitalize word
3179 // 2 change to uppercase
3180 // This function directly manipulates LyXParagraph::text because there
3181 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3182 // that it is correct. I guess part of it should be moved to
3183 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3184 // it does not access outside of the allocated array as the older
3185 // version did. (JMarc)
3186 void LyXText::ChangeWordCase(LyXText::TextCase action)
3188 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3190 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3192 LyXParagraph::size_type tmppos =
3193 cursor.par->PositionInParFromPos(cursor.pos);
3194 while (tmppos < tmppar->size()) {
3195 unsigned char c = tmppar->GetChar(tmppos);
3196 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3198 if (c != LyXParagraph::META_INSET) {
3200 case text_lowercase:
3203 case text_capitalization:
3205 action = text_lowercase;
3207 case text_uppercase:
3213 //tmppar->text[tmppos] = c;
3214 tmppar->SetChar(tmppos, c);
3217 CheckParagraph(tmppar, tmppos);
3218 CursorRightOneWord();
3222 void LyXText::Delete()
3224 // this is a very easy implementation
3226 LyXCursor old_cursor = cursor;
3227 int old_cur_par_id = old_cursor.par->id();
3228 int old_cur_par_prev_id = old_cursor.par->previous ?
3229 old_cursor.par->previous->id() : 0;
3231 // just move to the right
3232 CursorRightIntern();
3234 // CHECK Look at the comment here.
3235 // This check is not very good...
3236 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3237 // and that can very well delete the par or par->previous in
3238 // old_cursor. Will a solution where we compare paragraph id's
3240 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3241 == old_cur_par_prev_id
3242 && cursor.par->id() != old_cur_par_id)
3243 return; // delete-empty-paragraph-mechanism has done it
3245 // if you had success make a backspace
3246 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3247 LyXCursor tmpcursor = cursor;
3248 cursor = old_cursor; // to make sure undo gets the right cursor position
3249 SetUndo(Undo::DELETE,
3250 cursor.par->ParFromPos(cursor.pos)->previous,
3251 cursor.par->ParFromPos(cursor.pos)->next);
3258 void LyXText::Backspace()
3260 /* table stuff -- begin */
3261 if (cursor.par->table) {
3265 /* table stuff -- end */
3267 LyXFont rawtmpfont = current_font;
3268 LyXFont realtmpfont = real_current_font;
3270 // Get the font that is used to calculate the baselineskip
3271 int const lastpos = cursor.par->Last();
3272 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3274 if (cursor.pos == 0) {
3275 // The cursor is at the beginning of a paragraph, so the the backspace
3276 // will collapse two paragraphs into one.
3278 // we may paste some paragraphs
3280 // is it an empty paragraph?
3283 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3284 && !(cursor.par->Next()
3285 && cursor.par->footnoteflag == LyXParagraph::NO_FOOTNOTE
3286 && cursor.par->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3287 // This is an empty paragraph and we delete it just by moving the cursor one step
3288 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3289 // of the paragraph.
3291 if (cursor.par->previous) {
3292 LyXParagraph * tmppar = cursor.par->previous->FirstPhysicalPar();
3293 if (cursor.par->GetLayout() == tmppar->GetLayout()
3294 && cursor.par->footnoteflag == tmppar->footnoteflag
3295 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3296 // Inherit botom DTD from the paragraph below.
3297 // (the one we are deleting)
3298 tmppar->line_bottom = cursor.par->line_bottom;
3299 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3300 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3305 // the layout things can change the height of a row !
3306 int tmpheight = cursor.row->height;
3307 SetHeightOfRow(cursor.row);
3308 if (cursor.row->height != tmpheight) {
3309 refresh_y = cursor.y - cursor.row->baseline;
3310 refresh_row = cursor.row;
3311 status = LyXText::NEED_MORE_REFRESH;
3317 if (cursor.par->ParFromPos(cursor.pos)->previous){
3318 SetUndo(Undo::DELETE,
3319 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3320 cursor.par->ParFromPos(cursor.pos)->next);
3323 LyXParagraph * tmppar = cursor.par;
3324 Row * tmprow = cursor.row;
3326 // We used to do CursorLeftIntern() here, but it is
3327 // not a good idea since it triggers the auto-delete
3328 // mechanism. So we do a CursorLeftIntern()-lite,
3329 // without the dreaded mechanism. (JMarc)
3330 if (cursor.par->Previous()) {
3331 // steps into the above paragraph.
3332 SetCursorIntern(cursor.par->Previous(),
3333 cursor.par->Previous()->Last());
3336 /* Pasting is not allowed, if the paragraphs have different
3337 layout. I think it is a real bug of all other
3338 word processors to allow it. It confuses the user.
3339 Even so with a footnote paragraph and a non-footnote
3340 paragraph. I will not allow pasting in this case,
3341 because the user would be confused if the footnote behaves
3342 different wether it is open or closed.
3344 Correction: Pasting is always allowed with standard-layout
3346 if (cursor.par != tmppar
3347 && (cursor.par->GetLayout() == tmppar->GetLayout()
3348 || tmppar->GetLayout() == 0 /*standard*/)
3349 && cursor.par->footnoteflag == tmppar->footnoteflag
3350 /* table stuff -- begin*/
3351 && !cursor.par->table /* no pasting of tables */
3352 /* table stuff -- end*/
3353 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3355 RemoveParagraph(tmprow);
3357 cursor.par->PasteParagraph();
3359 if (!cursor.pos || !cursor.par->IsSeparator(cursor.pos - 1))
3360 ; //cursor.par->InsertChar(cursor.pos, ' ');
3361 // strangely enough it seems that commenting out the line above removes
3362 // most or all of the segfaults. I will however also try to move the
3363 // two Remove... lines in front of the PasteParagraph too.
3368 status = LyXText::NEED_MORE_REFRESH;
3369 refresh_row = cursor.row;
3370 refresh_y = cursor.y - cursor.row->baseline;
3372 // remove the lost paragraph
3373 // This one is not safe, since the paragraph that the tmprow and the
3374 // following rows belong to has been deleted by the PasteParagraph
3375 // above. The question is... could this be moved in front of the
3377 //RemoveParagraph(tmprow);
3378 //RemoveRow(tmprow);
3380 AppendParagraph(cursor.row); // This rebuilds the rows.
3381 UpdateCounters(cursor.row);
3383 // the row may have changed, block, hfills etc.
3384 SetCursor(cursor.par, cursor.pos);
3387 /* this is the code for a normal backspace, not pasting
3389 SetUndo(Undo::DELETE,
3390 cursor.par->ParFromPos(cursor.pos)->previous,
3391 cursor.par->ParFromPos(cursor.pos)->next);
3392 // We used to do CursorLeftIntern() here, but it is
3393 // not a good idea since it triggers the auto-delete
3394 // mechanism. So we do a CursorLeftIntern()-lite,
3395 // without the dreaded mechanism. (JMarc)
3396 SetCursorIntern(cursor.par, cursor.pos - 1);
3398 // some insets are undeletable here
3399 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3400 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3402 // force complete redo when erasing display insets
3403 // this is a cruel method but safe..... Matthias
3404 if (cursor.par->GetInset(cursor.pos)->display()){
3405 cursor.par->Erase(cursor.pos);
3411 Row * row = cursor.row;
3412 long y = cursor.y - row->baseline;
3413 LyXParagraph::size_type z;
3414 /* remember that a space at the end of a row doesnt count
3415 * when calculating the fill */
3416 if (cursor.pos < RowLast(row) ||
3417 !cursor.par->IsLineSeparator(cursor.pos)) {
3418 row->fill += SingleWidth(cursor.par, cursor.pos);
3421 /* some special code when deleting a newline. This is similar
3422 * to the behavior when pasting paragraphs */
3423 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3424 cursor.par->Erase(cursor.pos);
3425 // refresh the positions
3427 while (tmprow->next && tmprow->next->par == row->par) {
3428 tmprow = tmprow->next;
3431 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3434 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3435 cursor.par->InsertChar(cursor.pos, ' ');
3436 // refresh the positions
3438 while (tmprow->next && tmprow->next->par == row->par) {
3439 tmprow = tmprow->next;
3444 cursor.par->Erase(cursor.pos);
3446 // refresh the positions
3448 while (tmprow->next && tmprow->next->par == row->par) {
3449 tmprow = tmprow->next;
3453 // delete newlines at the beginning of paragraphs
3454 while (cursor.par->Last() &&
3455 cursor.par->IsNewline(cursor.pos) &&
3456 cursor.pos == BeginningOfMainBody(cursor.par)) {
3457 cursor.par->Erase(cursor.pos);
3458 // refresh the positions
3460 while (tmprow->next &&
3461 tmprow->next->par == row->par) {
3462 tmprow = tmprow->next;
3468 // is there a break one row above
3469 if (row->previous && row->previous->par == row->par) {
3470 z = NextBreakPoint(row->previous, paperwidth);
3471 if ( z >= row->pos) {
3474 Row * tmprow = row->previous;
3476 // maybe the current row is now empty
3477 if (row->pos >= row->par->Last()) {
3482 BreakAgainOneRow(row);
3483 if (row->next && row->next->par == row->par)
3484 need_break_row = row->next;
3489 // set the dimensions of the row above
3490 y -= tmprow->height;
3491 tmprow->fill = Fill(tmprow, paperwidth);
3492 SetHeightOfRow(tmprow);
3495 refresh_row = tmprow;
3496 status = LyXText::NEED_MORE_REFRESH;
3497 current_font = rawtmpfont;
3498 real_current_font = realtmpfont;
3499 SetCursor(cursor.par, cursor.pos, false);
3500 // check, whether the last character's font has changed.
3501 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3502 if (rawparfont != rawtmpfont)
3503 RedoHeightOfParagraph(cursor);
3508 // break the cursor row again
3509 z = NextBreakPoint(row, paperwidth);
3511 if (z != RowLast(row) ||
3512 (row->next && row->next->par == row->par &&
3513 RowLast(row) == row->par->Last() - 1)){
3515 /* it can happen that a paragraph loses one row
3516 * without a real breakup. This is when a word
3517 * is to long to be broken. Well, I don t care this
3519 if (row->next && row->next->par == row->par &&
3520 RowLast(row) == row->par->Last() - 1)
3521 RemoveRow(row->next);
3525 status = LyXText::NEED_MORE_REFRESH;
3527 BreakAgainOneRow(row);
3528 current_font = rawtmpfont;
3529 real_current_font = realtmpfont;
3530 SetCursor(cursor.par, cursor.pos, false);
3531 // cursor MUST be in row now
3533 if (row->next && row->next->par == row->par)
3534 need_break_row = row->next;
3538 // set the dimensions of the row
3539 row->fill = Fill(row, paperwidth);
3540 int tmpheight = row->height;
3541 SetHeightOfRow(row);
3542 if (tmpheight == row->height)
3543 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3545 status = LyXText::NEED_MORE_REFRESH;
3548 current_font = rawtmpfont;
3549 real_current_font = realtmpfont;
3550 SetCursor(cursor.par, cursor.pos, false);
3553 // restore the current font
3554 // That is what a user expects!
3555 current_font = rawtmpfont;
3556 real_current_font = realtmpfont;
3558 // check, wether the last characters font has changed.
3559 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3560 if (rawparfont != rawtmpfont) {
3561 RedoHeightOfParagraph(cursor);
3563 // now the special right address boxes
3564 if (textclasslist.Style(buffer->params.textclass,
3565 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3566 RedoDrawingOfParagraph(cursor);
3572 void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y)
3574 /* returns a printed row */
3575 Painter & pain = owner_->painter();
3577 bool is_rtl = row_ptr->par->isRightToLeftPar();
3578 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3580 LyXParagraph::size_type vpos, pos;
3582 int y_top, y_bottom;
3583 float fill_separator, fill_hfill, fill_label_hfill;
3584 LyXParagraph * par, * firstpar;
3587 if (row_ptr->height <= 0) {
3588 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3591 PrepareToPrint(row_ptr, x, fill_separator,
3592 fill_hfill, fill_label_hfill);
3594 // clear the area where we want to paint/print
3595 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3598 /* selection code */
3599 if (bidi_same_direction) {
3600 if (sel_start_cursor.row == row_ptr &&
3601 sel_end_cursor.row == row_ptr) {
3602 if (sel_start_cursor.x < sel_end_cursor.x)
3603 pain.fillRectangle(sel_start_cursor.x, offset,
3604 sel_end_cursor.x - sel_start_cursor.x,
3608 pain.fillRectangle(sel_end_cursor.x, offset,
3609 sel_start_cursor.x - sel_end_cursor.x,
3612 } else if (sel_start_cursor.row == row_ptr) {
3614 pain.fillRectangle(0, offset,
3619 pain.fillRectangle(sel_start_cursor.x, offset,
3620 paperwidth - sel_start_cursor.x,
3623 } else if (sel_end_cursor.row == row_ptr) {
3625 pain.fillRectangle(sel_end_cursor.x, offset,
3626 paperwidth - sel_end_cursor.x,
3630 pain.fillRectangle(0, offset,
3634 } else if (y > long(sel_start_cursor.y)
3635 && y < long(sel_end_cursor.y)) {
3636 pain.fillRectangle(0, offset,
3637 paperwidth, row_ptr->height,
3640 } else if ( sel_start_cursor.row != row_ptr &&
3641 sel_end_cursor.row != row_ptr &&
3642 y > long(sel_start_cursor.y)
3643 && y < long(sel_end_cursor.y)) {
3644 pain.fillRectangle(0, offset,
3645 paperwidth, row_ptr->height,
3647 } else if (sel_start_cursor.row == row_ptr ||
3648 sel_end_cursor.row == row_ptr) {
3651 if (row_ptr->par->table) {
3652 cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3653 tmpx += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3655 if ( (sel_start_cursor.row != row_ptr && !is_rtl) ||
3656 (sel_end_cursor.row != row_ptr && is_rtl))
3657 pain.fillRectangle(0, offset,
3658 tmpx, row_ptr->height,
3660 if (row_ptr->par->table) {
3662 for (vpos = row_ptr->pos; vpos <= last; ++vpos) {
3663 pos = vis2log(vpos);
3664 float old_tmpx = tmpx;
3665 if (row_ptr->par->IsNewline(pos)) {
3666 tmpx = x_old + row_ptr->par->table->WidthOfColumn(cell);
3669 tmpx += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3671 tmpx += SingleWidth(row_ptr->par, pos);
3673 if ( (sel_start_cursor.row != row_ptr ||
3674 sel_start_cursor.pos <= pos) &&
3675 (sel_end_cursor.row != row_ptr ||
3676 pos < sel_end_cursor.pos) )
3677 pain.fillRectangle(old_tmpx, offset,
3678 tmpx - old_tmpx + 1,
3683 LyXParagraph::size_type main_body =
3684 BeginningOfMainBody(row_ptr->par);
3686 for (vpos = row_ptr->pos; vpos <= last; ++vpos) {
3687 pos = vis2log(vpos);
3688 float old_tmpx = tmpx;
3689 if (main_body > 0 && pos == main_body-1) {
3690 tmpx += fill_label_hfill +
3691 lyxfont::width(textclasslist.Style(buffer->params.textclass,
3692 row_ptr->par->GetLayout()).labelsep,
3693 GetFont(row_ptr->par, -2));
3694 if (row_ptr->par->IsLineSeparator(main_body-1))
3695 tmpx -= SingleWidth(row_ptr->par, main_body-1);
3697 if (HfillExpansion(row_ptr, pos)) {
3698 tmpx += SingleWidth(row_ptr->par, pos);
3699 if (pos >= main_body)
3702 tmpx += fill_label_hfill;
3704 else if (row_ptr->par->IsSeparator(pos)) {
3705 tmpx += SingleWidth(row_ptr->par, pos);
3706 if (pos >= main_body)
3707 tmpx += fill_separator;
3709 tmpx += SingleWidth(row_ptr->par, pos);
3711 if ( (sel_start_cursor.row != row_ptr ||
3712 sel_start_cursor.pos <= pos) &&
3713 (sel_end_cursor.row != row_ptr ||
3714 pos < sel_end_cursor.pos) )
3715 pain.fillRectangle(old_tmpx, offset,
3716 tmpx - old_tmpx + 1,
3721 if ( (sel_start_cursor.row != row_ptr && is_rtl) ||
3722 (sel_end_cursor.row != row_ptr && !is_rtl) )
3723 pain.fillRectangle(tmpx, offset,
3730 if (row_ptr->par->appendix){
3731 pain.line(1, offset,
3732 1, offset + row_ptr->height,
3733 LColor::appendixline);
3734 pain.line(paperwidth - 2, offset,
3735 paperwidth - 2, offset + row_ptr->height,
3736 LColor::appendixline);
3739 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3740 /* draw a marker at the left margin! */
3741 LyXFont font = GetFont(row_ptr->par, 0);
3742 int asc = lyxfont::maxAscent(font);
3743 int x = (LYX_PAPER_MARGIN - lyxfont::width('|', font)) / 2;
3744 int y1 = (offset + row_ptr->baseline);
3745 int y2 = (offset + row_ptr->baseline) - asc;
3746 pain.line(x, y1, x, y2, LColor::minipageline);
3748 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3749 LyXFont font(LyXFont::ALL_SANE);
3750 font.setSize(LyXFont::SIZE_FOOTNOTE);
3751 font.setColor(LColor::footnote);
3753 int box_x = LYX_PAPER_MARGIN;
3754 box_x += lyxfont::width(" wide-tab ", font);
3755 if (row_ptr->previous &&
3756 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3758 switch (row_ptr->par->footnotekind) {
3759 case LyXParagraph::MARGIN:
3762 case LyXParagraph::FIG:
3765 case LyXParagraph::TAB:
3768 case LyXParagraph::WIDE_FIG:
3771 case LyXParagraph::WIDE_TAB:
3774 case LyXParagraph::ALGORITHM:
3777 case LyXParagraph::FOOTNOTE:
3782 pain.fillRectangle(LYX_PAPER_MARGIN,
3784 box_x - LYX_PAPER_MARGIN,
3785 int(lyxfont::maxAscent(font)
3786 + lyxfont::maxDescent(font)),
3787 LColor::footnotebg);
3789 pain.line(LYX_PAPER_MARGIN, offset,
3790 paperwidth - LYX_PAPER_MARGIN, offset,
3791 LColor::footnoteframe);
3793 pain.text(LYX_PAPER_MARGIN,
3794 offset + int(lyxfont::maxAscent(font)) + 1,
3797 pain.line(LYX_PAPER_MARGIN, offset,
3799 offset + int(lyxfont::maxAscent(font)
3800 + lyxfont::maxDescent(font)),
3801 LColor::footnoteframe);
3803 pain.line(LYX_PAPER_MARGIN,
3804 offset + int(lyxfont::maxAscent(font)
3805 + lyxfont::maxDescent(font)) + 1,
3807 offset + int(lyxfont::maxAscent(font)
3808 + lyxfont::maxDescent(font)) + 1,
3809 LColor::footnoteframe);
3813 /* draw the open floats in a red box */
3814 pain.line(box_x, offset,
3815 box_x, offset + row_ptr->height,
3816 LColor::footnoteframe);
3818 pain.line(paperwidth - LYX_PAPER_MARGIN,
3820 paperwidth - LYX_PAPER_MARGIN,
3821 offset + row_ptr->height,
3822 LColor::footnoteframe);
3823 } else if (row_ptr->previous &&
3824 row_ptr->previous->par->footnoteflag
3825 == LyXParagraph::OPEN_FOOTNOTE) {
3826 LyXFont font(LyXFont::ALL_SANE);
3827 font.setSize(LyXFont::SIZE_FOOTNOTE);
3829 int box_x = LYX_PAPER_MARGIN;
3830 box_x += lyxfont::width(" wide-tab ", font);
3832 pain.line(box_x, offset,
3833 paperwidth - LYX_PAPER_MARGIN,
3834 offset, LColor::footnote);
3837 LyXLayout const & layout =
3838 textclasslist.Style(buffer->params.textclass,
3839 row_ptr->par->GetLayout());
3840 firstpar = row_ptr->par->FirstPhysicalPar();
3843 y_bottom = row_ptr->height;
3845 /* is it a first row? */
3846 if (row_ptr->pos == 0
3847 && row_ptr->par == firstpar) {
3849 /* start of appendix? */
3850 if (row_ptr->par->start_of_appendix){
3851 pain.line(1, offset,
3852 paperwidth - 2, offset,
3853 LColor::appendixline);
3856 /* think about the margins */
3857 if (!row_ptr->previous)
3858 y_top += LYX_PAPER_MARGIN;
3860 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3862 pb_font.setColor(LColor::pagebreak).decSize();
3863 int w = 0, a = 0, d = 0;
3864 pain.line(0, offset + y_top + 2*DefaultHeight(),
3866 offset + y_top + 2*DefaultHeight(),
3868 Painter::line_onoffdash)
3871 _("Page Break (top)"),
3874 LColor::background, false, w, a, d);
3875 pain.rectText((paperwidth - w)/2,
3876 offset +y_top + 2*DefaultHeight() +d,
3877 _("Page Break (top)"),
3880 LColor::background);
3881 y_top += 3 * DefaultHeight();
3884 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3885 /* draw a vfill top */
3886 pain.line(0, offset + 2 + y_top,
3887 LYX_PAPER_MARGIN, offset + 2 + y_top,
3890 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3892 offset + y_top + 3 * DefaultHeight(),
3895 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3896 LYX_PAPER_MARGIN / 2,
3897 offset + y_top + 3 * DefaultHeight(),
3900 y_top += 3 * DefaultHeight();
3903 /* think about user added space */
3904 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3906 /* think about the parskip */
3907 /* some parskips VERY EASY IMPLEMENTATION */
3908 if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
3909 if (layout.latextype == LATEX_PARAGRAPH
3910 && firstpar->GetDepth() == 0
3911 && firstpar->Previous())
3912 y_top += buffer->params.getDefSkip().inPixels(owner_);
3913 else if (firstpar->Previous()
3914 && textclasslist.Style(buffer->params.textclass,
3915 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3916 && firstpar->Previous()->GetDepth() == 0)
3917 // is it right to use defskip here, too? (AS)
3918 y_top += buffer->params.getDefSkip().inPixels(owner_);
3921 if (row_ptr->par->line_top) { /* draw a top line */
3922 y_top += lyxfont::ascent('x', GetFont(row_ptr->par, 0));
3924 pain.line(0, offset + y_top,
3925 paperwidth, offset + y_top,
3927 Painter::line_solid,
3928 Painter::line_thick);
3930 y_top += lyxfont::ascent('x', GetFont(row_ptr->par, 0));
3933 /* should we print a label? */
3934 if (layout.labeltype >= LABEL_STATIC
3935 && (layout.labeltype != LABEL_STATIC
3936 || layout.latextype != LATEX_ENVIRONMENT
3937 || row_ptr->par->IsFirstInSequence())) {
3938 font = GetFont(row_ptr->par, -2);
3939 if (!row_ptr->par->GetLabelstring().empty()) {
3941 string tmpstring = row_ptr->par->GetLabelstring();
3943 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3944 if (buffer->params.secnumdepth >= 0) {
3945 /* this is special code for the chapter layout. This is printed in
3946 * an extra row and has a pagebreak at the top. */
3947 float spacing_val = 1.0;
3948 if (!row_ptr->par->spacing.isDefault()) {
3949 spacing_val = row_ptr->par->spacing.getValue();
3951 spacing_val = buffer->params.spacing.getValue();
3954 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
3955 + int(layout.parsep) * DefaultHeight();
3957 tmpx = paperwidth - LeftMargin(row_ptr) -
3958 lyxfont::width(tmpstring, font);
3959 pain.text(int(tmpx),
3960 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3965 tmpx = paperwidth - LeftMargin(row_ptr)
3966 + lyxfont::width(layout.labelsep, font);
3967 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3968 LyXFont font(LyXFont::ALL_SANE);
3969 font.setSize(LyXFont::SIZE_SMALL);
3970 tmpx += lyxfont::width("Mwide-fixM", font);
3973 tmpx = x - lyxfont::width(layout.labelsep, font)
3974 - lyxfont::width(tmpstring, font);
3977 pain.text(int(tmpx),
3978 offset + row_ptr->baseline,
3982 /* the labels at the top of an environment. More or less for bibliography */
3983 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3984 layout.labeltype == LABEL_BIBLIO ||
3985 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3986 if (row_ptr->par->IsFirstInSequence()) {
3987 font = GetFont(row_ptr->par, -2);
3988 if (!row_ptr->par->GetLabelstring().empty()) {
3989 string tmpstring = row_ptr->par->GetLabelstring();
3990 float spacing_val = 1.0;
3991 if (!row_ptr->par->spacing.isDefault()) {
3992 spacing_val = row_ptr->par->spacing.getValue();
3994 spacing_val = buffer->params.spacing.getValue();
3997 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
3998 + (layout.labelbottomsep * DefaultHeight()));
4001 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4002 tmpx = ( (is_rtl ? LeftMargin(row_ptr) : x)
4003 + paperwidth - RightMargin(row_ptr) ) / 2;
4004 tmpx -= lyxfont::width(tmpstring, font) / 2;
4006 tmpx = paperwidth - LeftMargin(row_ptr) -
4007 lyxfont::width(tmpstring, font);
4008 pain.text(int(tmpx),
4009 offset + row_ptr->baseline
4010 - row_ptr->ascent_of_text
4016 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
4017 font = GetFont(row_ptr->par, -1);
4019 tmpx = paperwidth - LeftMargin(row_ptr)
4020 + lyxfont::width(layout.labelsep, font);
4022 tmpx = x - lyxfont::width(layout.labelsep, font)
4023 - row_ptr->par->bibkey->width(owner_->painter(), font);
4024 row_ptr->par->bibkey->draw(pain,
4026 offset + row_ptr->baseline,
4031 /* is it a last row? */
4032 par = row_ptr->par->LastPhysicalPar();
4033 if (row_ptr->par->ParFromPos(last + 1) == par
4034 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
4036 /* think about the margins */
4038 y_bottom -= LYX_PAPER_MARGIN;
4040 /* draw a bottom pagebreak */
4041 if (firstpar->pagebreak_bottom) {
4043 pb_font.setColor(LColor::pagebreak).decSize();
4044 int w = 0, a = 0, d = 0;
4046 offset + y_bottom - 2 * DefaultHeight(),
4048 offset + y_bottom - 2 * DefaultHeight(),
4050 Painter::line_onoffdash)
4053 _("Page Break (bottom)"),
4056 LColor::background, false, w, a, d);
4057 pain.rectText((paperwidth - w)/2,
4058 offset +y_top + 2*DefaultHeight() +d,
4059 _("Page Break (bottom)"),
4062 LColor::background);
4063 y_bottom -= 3 * DefaultHeight();
4066 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4067 /* draw a vfill bottom */
4068 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
4070 offset + y_bottom - 3 * DefaultHeight(),
4072 pain.line(0, offset + y_bottom - 2,
4074 offset + y_bottom - 2,
4076 pain.line(LYX_PAPER_MARGIN / 2,
4077 offset + y_bottom - 3 * DefaultHeight(),
4078 LYX_PAPER_MARGIN / 2,
4079 offset + y_bottom - 2,
4081 y_bottom -= 3* DefaultHeight();
4084 /* think about user added space */
4085 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
4087 if (firstpar->line_bottom) {
4088 /* draw a bottom line */
4089 y_bottom -= lyxfont::ascent('x', GetFont(par, par->Last() - 1));
4090 pain.line(0, offset + y_bottom,
4091 paperwidth, offset + y_bottom,
4092 LColor::topline, Painter::line_solid,
4093 Painter::line_thick);
4094 y_bottom -= lyxfont::ascent('x', GetFont(par, par->Last() - 1));
4098 int endlabel = row_ptr->par->GetEndLabel();
4099 if (endlabel == END_LABEL_BOX ||
4100 endlabel == END_LABEL_FILLED_BOX) {
4101 LyXFont font = GetFont(row_ptr->par, last);
4102 int size = int(0.75 * lyxfont::maxAscent(font));
4103 int y = (offset + row_ptr->baseline) - size;
4104 int x = is_rtl ? LYX_PAPER_MARGIN
4105 : paperwidth - LYX_PAPER_MARGIN - size;
4106 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4108 LyXFont font(LyXFont::ALL_SANE);
4109 font.setSize(LyXFont::SIZE_SMALL);
4110 x += lyxfont::width("Mwide-figM", font);
4112 x -= LYX_PAPER_MARGIN/2;
4113 if (row_ptr->fill <= size)
4114 x += (size - row_ptr->fill + 1) * (is_rtl ? -1 : 1);
4115 if (endlabel == END_LABEL_BOX) {
4116 pain.line(x, y, x, y + size,
4118 pain.line(x + size, y, x + size , y + size,
4120 pain.line(x, y, x + size, y,
4122 pain.line(x, y + size, x + size, y + size,
4125 pain.fillRectangle(x, y, size, size,
4130 /* draw the text in the pixmap */
4132 vpos = row_ptr->pos;
4133 /* table stuff -- begin*/
4134 if (row_ptr->par->table) {
4136 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
4138 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4140 while (vpos <= last) {
4141 pos = vis2log(vpos);
4142 if (row_ptr->par->IsNewline(pos)) {
4144 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4145 /* draw the table lines, still very simple */
4146 on_off = !row_ptr->par->table->TopLine(cell);
4148 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4149 !row_ptr->par->table->IsContRow(cell))
4150 pain.line(int(x_old),
4151 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4153 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4155 on_off ? Painter::line_onoffdash : Painter::line_solid);
4157 on_off = !row_ptr->par->table->BottomLine(cell);
4158 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4159 row_ptr->par->table->VeryLastRow(cell))
4161 pain.line(int(x_old),
4162 offset + y_bottom - 1,
4164 offset + y_bottom - 1,
4166 on_off ? Painter::line_onoffdash : Painter::line_solid);
4168 on_off = !row_ptr->par->table->LeftLine(cell);
4170 pain.line(int(x_old),
4171 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4173 offset + y_bottom - 1,
4175 on_off ? Painter::line_onoffdash : Painter::line_solid);
4177 on_off = !row_ptr->par->table->RightLine(cell);
4179 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4180 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4181 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4182 offset + y_bottom - 1,
4184 on_off ? Painter::line_onoffdash : Painter::line_solid);
4187 /* take care about the alignment and other spaces */
4189 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4190 if (row_ptr->par->table->IsFirstCell(cell))
4191 --cell; // little hack, sorry
4193 } else if (row_ptr->par->IsHfill(pos)) {
4197 offset + row_ptr->baseline - DefaultHeight() / 2,
4199 offset + row_ptr->baseline,
4204 } else if (row_ptr->par->IsSeparator(pos)) {
4206 x+= SingleWidth(row_ptr->par, pos);
4209 draw(row_ptr, vpos, offset, x);
4212 /* do not forget the very last cell. This has no NEWLINE so
4213 * ignored by the code above*/
4214 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4215 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4216 on_off = !row_ptr->par->table->TopLine(cell);
4218 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4219 !row_ptr->par->table->IsContRow(cell))
4221 pain.line(int(x_old),
4222 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4224 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4226 on_off ? Painter::line_onoffdash : Painter::line_solid);
4227 on_off = !row_ptr->par->table->BottomLine(cell);
4228 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4229 row_ptr->par->table->VeryLastRow(cell))
4231 pain.line(int(x_old),
4232 offset + y_bottom - 1,
4234 offset + y_bottom - 1,
4236 on_off ? Painter::line_onoffdash : Painter::line_solid);
4238 on_off = !row_ptr->par->table->LeftLine(cell);
4240 pain.line(int(x_old),
4241 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4243 offset + y_bottom - 1,
4245 on_off ? Painter::line_onoffdash : Painter::line_solid);
4247 on_off = !row_ptr->par->table->RightLine(cell);
4249 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4250 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4251 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4252 offset + y_bottom - 1,
4254 on_off ? Painter::line_onoffdash : Painter::line_solid);
4257 /* table stuff -- end*/
4258 LyXParagraph::size_type main_body =
4259 BeginningOfMainBody(row_ptr->par);
4260 if (main_body > 0 &&
4261 (main_body-1 > last ||
4262 !row_ptr->par->IsLineSeparator(main_body-1)))
4265 while (vpos <= last) {
4266 pos = vis2log(vpos);
4267 if (main_body > 0 && pos == main_body-1) {
4268 x += fill_label_hfill
4269 + lyxfont::width(layout.labelsep, GetFont(row_ptr->par, -2))
4270 - SingleWidth(row_ptr->par, main_body-1);
4273 if (row_ptr->par->IsHfill(pos)) {
4276 offset + row_ptr->baseline - DefaultHeight() / 2,
4278 offset + row_ptr->baseline,
4281 if (HfillExpansion(row_ptr, pos)) {
4282 if (pos >= main_body) {
4284 offset + row_ptr->baseline - DefaultHeight() / 4,
4285 int(x + fill_hfill),
4286 offset + row_ptr->baseline - DefaultHeight() / 4,
4288 Painter::line_onoffdash);
4292 offset + row_ptr->baseline - DefaultHeight() / 4,
4293 int(x + fill_label_hfill),
4294 offset + row_ptr->baseline - DefaultHeight() / 4,
4296 Painter::line_onoffdash);
4298 x += fill_label_hfill;
4301 offset + row_ptr->baseline - DefaultHeight() / 2,
4303 offset + row_ptr->baseline,
4308 } else if (row_ptr->par->IsSeparator(pos)) {
4309 x += SingleWidth(row_ptr->par, pos);
4310 if (pos >= main_body)
4311 x += fill_separator;
4314 draw(row_ptr, vpos, offset, x);
4320 int LyXText::DefaultHeight() const
4322 LyXFont font(LyXFont::ALL_SANE);
4323 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4327 /* returns the column near the specified x-coordinate of the row
4328 * x is set to the real beginning of this column */
4329 int LyXText::GetColumnNearX(Row * row, int & x) const
4332 float fill_separator, fill_hfill, fill_label_hfill;
4334 PrepareToPrint(row, tmpx, fill_separator,
4335 fill_hfill, fill_label_hfill);
4337 LyXParagraph::size_type vc = row->pos;
4338 LyXParagraph::size_type last = RowLastPrintable(row);
4339 LyXParagraph::size_type c = 0;
4340 LyXLayout const & layout = textclasslist.Style(buffer->params.textclass,
4341 row->par->GetLayout());
4342 /* table stuff -- begin */
4343 if (row->par->table) {
4344 //the last row doesn't need a newline at the end
4345 if (row->next && row->next->par == row->par
4346 && row->par->IsNewline(last))
4348 int cell = NumberOfCell(row->par, row->pos);
4351 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4353 && (c = vis2log(vc)) >= 0
4354 && tmpx + (SingleWidth(row->par, c)/2) <= x
4356 if (row->par->IsNewline(c)) {
4357 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4358 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4361 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4366 tmpx += SingleWidth(row->par, c);
4371 /* table stuff -- end*/
4372 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4373 float last_tmpx = tmpx;
4375 if (main_body > 0 &&
4376 (main_body-1 > last ||
4377 !row->par->IsLineSeparator(main_body-1)))
4380 while (vc <= last && tmpx <= x) {
4383 if (main_body > 0 && c == main_body-1) {
4384 tmpx += fill_label_hfill +
4385 lyxfont::width(layout.labelsep,
4386 GetFont(row->par, -2));
4387 if (row->par->IsLineSeparator(main_body-1))
4388 tmpx -= SingleWidth(row->par, main_body-1);
4391 if (HfillExpansion(row, c)) {
4392 x += SingleWidth(row->par, c);
4396 tmpx += fill_label_hfill;
4398 else if (row->par->IsSeparator(c)) {
4399 tmpx += SingleWidth(row->par, c);
4401 tmpx+= fill_separator;
4403 tmpx += SingleWidth(row->par, c);
4407 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4413 if (vc > last + 1) // This shouldn't happen.
4416 if (row->pos > last) // Row is empty?
4418 else if (vc > last ||
4419 (vc - 1 >= row->pos &&
4420 ( (row->par->IsSeparator(vis2log(vc)) && vis2log(vc) != last)
4421 || (row->par->table && row->par->IsNewline(vc) )
4423 c = vis2log(vc - 1);
4424 if (bidi_level(c) % 2 == 0)
4428 if (bidi_level(c) % 2 == 1)
4432 if (!row->par->table && row->pos <= last && c > last
4433 && row->par->IsNewline(last)) {
4434 if (bidi_level(last) % 2 == 0)
4435 tmpx -= SingleWidth(row->par, last);
4437 tmpx += SingleWidth(row->par, last);
4447 /* turn the selection into a new environment. If there is no selection,
4448 * create an empty environment */
4449 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4451 /* no footnoteenvironment in a footnoteenvironment */
4452 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4453 WriteAlert(_("Impossible operation"),
4454 _("You can't insert a float in a float!"),
4458 /* no marginpars in minipages */
4459 if (kind == LyXParagraph::MARGIN
4460 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4461 WriteAlert(_("Impossible operation"),
4462 _("You can't insert a marginpar in a minipage!"),
4467 /* this doesnt make sense, if there is no selection */
4468 bool dummy_selection = false;
4470 sel_start_cursor = cursor; /* dummy selection */
4471 sel_end_cursor = cursor;
4472 dummy_selection = true;
4475 LyXParagraph *tmppar;
4477 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4478 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4482 /* a test to make sure there is not already a footnote
4483 * in the selection. */
4485 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4487 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4488 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4489 tmppar = tmppar->next;
4491 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4492 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4493 WriteAlert(_("Impossible operation"),
4494 _("Float would include float!"),
4499 /* ok we have a selection. This is always between sel_start_cursor
4500 * and sel_end cursor */
4502 SetUndo(Undo::FINISH,
4503 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4504 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4506 if (sel_end_cursor.pos > 0
4507 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4508 sel_end_cursor.pos--; /* please break before a space at
4510 if (sel_start_cursor.par == sel_end_cursor.par
4511 && sel_start_cursor.pos > sel_end_cursor.pos)
4512 sel_start_cursor.pos--;
4514 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4516 sel_end_cursor.par = sel_end_cursor.par->Next();
4517 sel_end_cursor.pos = 0;
4519 // don't forget to insert a dummy layout paragraph if necessary
4520 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4521 sel_end_cursor.par->BreakParagraphConservative(0);
4522 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4523 sel_end_cursor.par = sel_end_cursor.par->next;
4526 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4528 cursor = sel_end_cursor;
4530 /* please break behind a space, if there is one. The space should
4532 if (sel_start_cursor.pos > 0
4533 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4534 sel_start_cursor.pos--;
4535 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4536 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4539 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4540 tmppar = sel_start_cursor.par->Next();
4542 if (dummy_selection) {
4544 if (kind == LyXParagraph::TAB
4545 || kind == LyXParagraph::FIG
4546 || kind == LyXParagraph::WIDE_TAB
4547 || kind == LyXParagraph::WIDE_FIG
4548 || kind == LyXParagraph::ALGORITHM) {
4549 pair<bool, LyXTextClass::size_type> lres =
4550 textclasslist.NumberOfLayout(buffer->params.textclass,
4552 LyXTextClass::size_type lay;
4558 lay = 0; // use default layout "Standard" (0)
4560 tmppar->SetLayout(lay);
4564 if (sel_start_cursor.pos > 0) {
4565 /* the footnote-environment should begin with a standard layout.
4566 * Imagine you insert a footnote within an enumeration, you
4567 * certainly do not want an enumerated footnote! */
4571 /* this is a exception the user would sometimes expect, I hope */
4572 sel_start_cursor.par->Clear();
4576 while (tmppar != sel_end_cursor.par) {
4577 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4578 tmppar->footnotekind = kind;
4579 tmppar = tmppar->Next();
4582 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4584 SetCursor(sel_start_cursor.par->Next(), 0);
4590 // returns pointer to a specified row
4591 Row * LyXText::GetRow(LyXParagraph * par,
4592 LyXParagraph::size_type pos, long & y) const
4594 Row * tmprow = firstrow;
4597 // find the first row of the specified paragraph
4598 while (tmprow->next && tmprow->par != par) {
4599 y += tmprow->height;
4600 tmprow = tmprow->next;
4603 // now find the wanted row
4604 while (tmprow->pos < pos
4606 && tmprow->next->par == par
4607 && tmprow->next->pos <= pos) {
4608 y += tmprow->height;
4609 tmprow = tmprow->next;