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 #define FIX_DOUBLE_SPACE 1
50 static int iso885968x[] = {
51 0xbc, // 0xa8 = fathatan
52 0xbd, // 0xa9 = dammatan
53 0xbe, // 0xaa = kasratan
57 0xde, // 0xae = shadda
60 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
64 0xc2, // 0xc2 = ligature madda
65 0xc3, // 0xc3 = ligature hamza on alef
66 0xc4, // 0xc4 = ligature hamza on waw
67 0xc5, // 0xc5 = ligature hamza under alef
68 0xc0, // 0xc6 = ligature hamza on ya
71 0xc9, // 0xc9 = taa marbuta
90 0,0,0,0,0, // 0xdb- 0xdf
101 0xe9, // 0xe9 = alef maksura
106 bool is_arabic(unsigned char c)
108 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
112 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
115 (form == FORM_INITIAL || form == FORM_MEDIAL) )
116 return iso885968x[c-0xa8];
122 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
123 LyXParagraph::size_type pos) const
127 return c + (0xb0 - '0');
131 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
132 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
134 return TransformChar(c,FORM_MEDIAL);
136 return TransformChar(c,FORM_INITIAL);
139 return TransformChar(c,FORM_FINAL);
141 return TransformChar(c,FORM_ISOLATED);
144 // This is the comments that some of the warnings below refers to.
145 // There are some issues in this file and I don't think they are
146 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
147 // this is a problem that has been here almost from day one and that a
148 // larger userbase with differenct access patters triggers the bad
149 // behaviour. (segfaults.) What I think happen is: In several places
150 // we store the paragraph in the current cursor and then moves the
151 // cursor. This movement of the cursor will delete paragraph at the
152 // old position if it is now empty. This will make the temporary
153 // pointer to the old cursor paragraph invalid and dangerous to use.
154 // And is some cases this will trigger a segfault. I have marked some
155 // of the cases where this happens with a warning, but I am sure there
156 // are others in this file and in text2.C. There is also a note in
157 // Delete() that you should read. In Delete I store the paragraph->id
158 // instead of a pointer to the paragraph. I am pretty sure this faulty
159 // use of temporary pointers to paragraphs that might have gotten
160 // invalidated (through a cursor movement) before they are used, are
161 // the cause of the strange crashes we get reported often.
163 // It is very tiresom to change this code, especially when it is as
164 // hard to read as it is. Help to fix all the cases where this is done
165 // would be greately appreciated.
169 int LyXText::SingleWidth(LyXParagraph * par,
170 LyXParagraph::size_type pos) const
172 char c = par->GetChar(pos);
173 return SingleWidth(par, pos, c);
177 int LyXText::SingleWidth(LyXParagraph * par,
178 LyXParagraph::size_type pos, char c) const
180 LyXFont font = GetFont(par, pos);
182 // The most common case is handled first (Asger)
183 if (IsPrintable(c)) {
184 if (font.language()->lang == "arabic" &&
185 lyxrc.font_norm == "iso8859-6.8x")
186 c = TransformChar(c, par, pos);
187 return lyxfont::width(c, font);
189 } else if (IsHfillChar(c)) {
190 return 3; /* Because of the representation
191 * as vertical lines */
192 } else if (c == LyXParagraph::META_FOOTNOTE ||
193 c == LyXParagraph::META_MARGIN ||
194 c == LyXParagraph::META_FIG ||
195 c == LyXParagraph::META_TAB ||
196 c == LyXParagraph::META_WIDE_FIG ||
197 c == LyXParagraph::META_WIDE_TAB ||
198 c == LyXParagraph::META_ALGORITHM) {
201 case LyXParagraph::META_MARGIN:
204 case LyXParagraph::META_FIG:
207 case LyXParagraph::META_TAB:
210 case LyXParagraph::META_ALGORITHM:
213 case LyXParagraph::META_WIDE_FIG:
216 case LyXParagraph::META_WIDE_TAB:
219 case LyXParagraph::META_FOOTNOTE:
225 return lyxfont::width(fs, font);
226 } else if (c == LyXParagraph::META_INSET) {
227 Inset * tmpinset= par->GetInset(pos);
229 return par->GetInset(pos)->width(owner_->painter(),
234 } else if (IsSeparatorChar(c))
236 else if (IsNewlineChar(c))
238 return lyxfont::width(c, font);
242 // Returns the paragraph position of the last character in the specified row
243 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
246 return row->par->Last() - 1;
247 else if (row->next->par != row->par)
248 return row->par->Last() - 1;
250 return row->next->pos - 1;
254 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
256 LyXParagraph::size_type last = RowLast(row);
257 if (last >= row->pos && row->next && row->next->par == row->par &&
258 row->par->IsSeparator(last))
265 void LyXText::ComputeBidiTables(Row * row) const
267 bidi_same_direction = true;
268 if (!lyxrc.rtl_support) {
272 LyXParagraph::size_type last = RowLastPrintable(row);
273 bidi_start = row->pos;
275 if (bidi_start > last) {
280 if (last + 2 - bidi_start >
281 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
282 LyXParagraph::size_type new_size =
283 (last + 2 - bidi_start < 500) ?
284 500 : 2 * (last + 2 - bidi_start);
285 log2vis_list.resize(new_size);
286 vis2log_list.resize(new_size);
287 bidi_levels.resize(new_size);
290 vis2log_list[last + 1 - bidi_start] = -1;
291 log2vis_list[last + 1 - bidi_start] = -1;
293 LyXParagraph::size_type stack[2];
294 bool rtl_par = row->par->getParLanguage()->RightToLeft;
298 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
300 for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) {
301 bool is_space = row->par->IsLineSeparator(lpos);
302 LyXParagraph::size_type pos =
303 (is_space && lpos+1 <= last &&
304 (!row->par->table || !row->par->IsNewline(lpos+1)) )
306 LyXFont font = row->par->GetFontSettings(pos);
307 bool new_rtl = font.isVisibleRightToLeft();
308 bool new_rtl0 = font.isRightToLeft();
311 if (row->par->table && row->par->IsNewline(lpos)) {
313 new_rtl = new_rtl0 = false;
314 } else if (lpos == main_body - 1 && row->pos < main_body - 1 &&
315 row->par->IsLineSeparator(lpos)) {
316 new_level = (rtl_par) ? 1 : 0;
317 new_rtl = new_rtl0 = rtl_par;
319 new_level = (new_rtl) ? 1 : 2;
321 new_level = (rtl_par) ? 2 : 0;
323 if (is_space && new_level >= level) {
329 int new_level2 = new_level;
331 if (level == new_level && rtl0 != new_rtl0) {
333 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
334 } else if (level < new_level) {
335 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
336 if (new_level > rtl_par)
337 bidi_same_direction = false;
339 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
342 bidi_levels[lpos - bidi_start] = new_level;
344 while (level > new_level2) {
345 LyXParagraph::size_type old_lpos =
347 int delta = lpos - old_lpos - 1;
350 log2vis_list[lpos - bidi_start] += delta;
351 log2vis_list[old_lpos - bidi_start] += delta;
353 while (level < new_level)
354 stack[level++] = lpos;
358 LyXParagraph::size_type old_lpos = stack[--level];
359 int delta = last - old_lpos;
362 log2vis_list[old_lpos - bidi_start] += delta;
365 LyXParagraph::size_type vpos = bidi_start - 1;
366 for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) {
367 vpos += log2vis_list[lpos - bidi_start];
368 vis2log_list[vpos - bidi_start] = lpos;
369 log2vis_list[lpos - bidi_start] = vpos;
374 void LyXText::draw(Row const * row,
375 LyXParagraph::size_type & vpos,
376 int offset, float & x)
378 Painter & pain = owner_->painter();
380 LyXParagraph::size_type pos = vis2log(vpos);
381 char c = row->par->GetChar(pos);
383 if (IsNewlineChar(c)) {
385 // Draw end-of-line marker
386 LyXFont font = GetFont(row->par, pos);
387 int wid = lyxfont::width('n', font);
388 int asc = lyxfont::maxAscent(font);
389 int y = offset + row->baseline;
392 if (bidi_level(pos) % 2 == 0) {
393 xp[0] = int(x + wid * 0.375);
394 yp[0] = int(y - 0.875 * asc * 0.75);
397 yp[1] = int(y - 0.500 * asc * 0.75);
399 xp[2] = int(x + wid * 0.375);
400 yp[2] = int(y - 0.125 * asc * 0.75);
402 pain.lines(xp, yp, 3, LColor::eolmarker);
405 yp[0] = int(y - 0.500 * asc * 0.75);
407 xp[1] = int(x + wid);
408 yp[1] = int(y - 0.500 * asc * 0.75);
410 xp[2] = int(x + wid);
411 yp[2] = int(y - asc * 0.75);
413 pain.lines(xp, yp, 3, LColor::eolmarker);
415 xp[0] = int(x + wid * 0.625);
416 yp[0] = int(y - 0.875 * asc * 0.75);
418 xp[1] = int(x + wid);
419 yp[1] = int(y - 0.500 * asc * 0.75);
421 xp[2] = int(x + wid * 0.625);
422 yp[2] = int(y - 0.125 * asc * 0.75);
424 pain.lines(xp, yp, 3, LColor::eolmarker);
426 xp[0] = int(x + wid);
427 yp[0] = int(y - 0.500 * asc * 0.75);
430 yp[1] = int(y - 0.500 * asc * 0.75);
433 yp[2] = int(y - asc * 0.75);
435 pain.lines(xp, yp, 3, LColor::eolmarker);
441 LyXFont font = GetFont(row->par, pos);
442 LyXFont font2 = font;
444 if (c == LyXParagraph::META_FOOTNOTE
445 || c == LyXParagraph::META_MARGIN
446 || c == LyXParagraph::META_FIG
447 || c == LyXParagraph::META_TAB
448 || c == LyXParagraph::META_WIDE_FIG
449 || c == LyXParagraph::META_WIDE_TAB
450 || c == LyXParagraph::META_ALGORITHM) {
453 case LyXParagraph::META_MARGIN:
455 // Draw a sign at the left margin!
457 .text((LYX_PAPER_MARGIN - lyxfont::width('!', font))/2,
458 offset + row->baseline, "!", 1, font);
460 case LyXParagraph::META_FIG:
463 case LyXParagraph::META_TAB:
466 case LyXParagraph::META_ALGORITHM:
469 case LyXParagraph::META_WIDE_FIG:
472 case LyXParagraph::META_WIDE_TAB:
475 case LyXParagraph::META_FOOTNOTE:
482 // calculate the position of the footnotemark
483 int y = (row->baseline - lyxfont::maxAscent(font2)
484 + lyxfont::maxAscent(font));
486 font.setColor(LColor::footnote);
490 // draw it and set new x position
492 pain.text(int(x), offset + y, fs, font);
493 x += lyxfont::width(fs, font);
494 pain.line(int(tmpx), offset + row->baseline,
495 int(x), offset + row->baseline,
500 } else if (c == LyXParagraph::META_INSET) {
501 Inset * tmpinset = row->par->GetInset(pos);
503 tmpinset->draw(owner_->painter(), font,
504 offset + row->baseline, x);
510 /* usual characters, no insets */
512 // Collect character that we can draw in one command
514 // This is dirty, but fast. Notice that it will never be too small.
515 // For the record, I'll note that Microsoft Word has a limit
516 // of 768 here. We have none :-) (Asger)
517 // Ok. I am the first to admit that the use of std::string will be
518 // a tiny bit slower than using a POD char array. However, I claim
519 // that this slowdown is so small that it is close to inperceptive.
520 // So IMHO we should go with the easier and clearer implementation.
521 // And even if 1024 is a large number here it might overflow, string
522 // will only overflow if the machine is out of memory...
524 font2.language()->lang == "arabic" &&
525 lyxrc.font_norm == "iso8859-6.8x";
527 c = TransformChar(c, row->par, pos);
528 static string textstring;
532 LyXParagraph::size_type last = RowLastPrintable(row);
534 while (vpos <= last &&
535 (pos = vis2log(vpos)) >= 0
536 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
537 && font2 == GetFont(row->par, pos)) {
539 c = TransformChar(c, row->par, pos);
545 // Draw text and set the new x position
546 pain.text(int(x), offset + row->baseline, textstring, font);
547 x += lyxfont::width(textstring, font);
549 // what about underbars?
550 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
551 pain.line(tmpx, offset + row->baseline + 2,
552 x, offset + row->baseline + 2);
556 // If we want ulem.sty support, drawing
557 // routines should go here. (Asger)
558 // Why shouldn't LyXFont::drawText handle it internally?
562 // Returns the left beginning of the text.
563 // This information cannot be taken from the layouts-objekt, because in
564 // LaTeX the beginning of the text fits in some cases (for example sections)
565 // exactly the label-width.
566 int LyXText::LeftMargin(Row const * row) const
568 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
569 row->par->GetLayout());
571 string parindent = layout.parindent;
573 /* table stuff -- begin */
576 /* table stuff -- end */
578 int x = LYX_PAPER_MARGIN;
580 x += lyxfont::signedWidth(textclasslist
581 .TextClass(bparams->textclass)
584 .TextClass(bparams->textclass)
587 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
588 LyXFont font(LyXFont::ALL_SANE);
589 font.setSize(LyXFont::SIZE_SMALL);
590 x += lyxfont::width("Mwide-figM", font)
591 + LYX_PAPER_MARGIN/2;
594 // this is the way, LyX handles the LaTeX-Environments.
595 // I have had this idea very late, so it seems to be a
596 // later added hack and this is true
597 if (!row->par->GetDepth()) {
598 if (!row->par->GetLayout()) {
599 // find the previous same level paragraph
600 if (row->par->FirstPhysicalPar()->Previous()) {
601 LyXParagraph * newpar = row->par
602 ->DepthHook(row->par->GetDepth());
604 textclasslist.Style(bparams->textclass,
611 // find the next level paragraph
613 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
615 // make a corresponding row. Needed to call LeftMargin()
617 // check wether it is a sufficent paragraph
618 if (newpar && newpar->footnoteflag == row->par->footnoteflag
620 .Style(bparams->textclass,
621 newpar->GetLayout()).isEnvironment()) {
623 dummyrow.par = newpar;
624 dummyrow.pos = newpar->Last();
625 x = LeftMargin(&dummyrow);
627 // this is no longer an error, because this function
628 // is used to clear impossible depths after changing
629 // a layout. Since there is always a redo,
630 // LeftMargin() is always called
631 row->par->FirstPhysicalPar()->depth = 0;
634 if (newpar && !row->par->GetLayout()) {
635 if (newpar->FirstPhysicalPar()->noindent)
638 parindent = textclasslist
639 .Style(bparams->textclass,
640 newpar->GetLayout()).parindent;
645 LyXFont labelfont = GetFont(row->par, -2);
646 switch (layout.margintype) {
648 if (!layout.leftmargin.empty()) {
649 x += lyxfont::signedWidth(layout.leftmargin,
655 if (!row->par->GetLabelstring().empty()) {
656 x += lyxfont::signedWidth(layout.labelindent,
658 x += lyxfont::width(row->par->GetLabelstring(), labelfont);
659 x += lyxfont::width(layout.labelsep, labelfont);
663 x += lyxfont::signedWidth(layout.labelindent, labelfont);
664 if (row->pos >= BeginningOfMainBody(row->par)) {
665 if (!row->par->GetLabelWidthString().empty()) {
666 x += lyxfont::width(row->par->GetLabelWidthString(),
668 x += lyxfont::width(layout.labelsep, labelfont);
673 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bparams->textclass).defaultfont()) * 4
674 / (row->par->GetDepth() + 4);
676 case MARGIN_FIRST_DYNAMIC:
677 if (layout.labeltype == LABEL_MANUAL) {
678 if (row->pos >= BeginningOfMainBody(row->par)) {
679 x += lyxfont::signedWidth(layout.leftmargin, labelfont);
681 x += lyxfont::signedWidth(layout.labelindent, labelfont);
684 // Special case to fix problems with
686 || (layout.labeltype == LABEL_STATIC
687 && layout.latextype == LATEX_ENVIRONMENT
688 && ! row->par->IsFirstInSequence())) {
689 x += lyxfont::signedWidth(layout.leftmargin, labelfont);
690 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
691 && layout.labeltype != LABEL_BIBLIO
692 && layout.labeltype !=
693 LABEL_CENTERED_TOP_ENVIRONMENT) {
694 x += lyxfont::signedWidth(layout.labelindent,
696 x += lyxfont::width(layout.labelsep, labelfont);
697 x += lyxfont::width(row->par->GetLabelstring(), labelfont);
701 case MARGIN_RIGHT_ADDRESS_BOX:
703 // ok, a terrible hack. The left margin depends on the widest
704 // row in this paragraph. Do not care about footnotes, they
705 // are *NOT* allowed in the LaTeX realisation of this layout.
707 // find the first row of this paragraph
708 Row const * tmprow = row;
709 while (tmprow->previous && tmprow->previous->par == row->par)
710 tmprow = tmprow->previous;
712 int minfill = tmprow->fill;
713 while (tmprow->next && tmprow->next->par == row->par) {
714 tmprow = tmprow->next;
715 if (tmprow->fill < minfill)
716 minfill = tmprow->fill;
719 x += lyxfont::signedWidth(layout.leftmargin,
721 .TextClass(bparams->textclass)
727 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
728 if (!row->par->pextra_widthp.empty()) {
730 atoi(row->par->pextra_widthp.c_str()) / 100;
731 } else if (!row->par->pextra_width.empty()) {
732 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
735 xx = paperwidth * 80 / 100;
737 } else { // should not happen
738 LyXFont font(LyXFont::ALL_SANE);
739 x += lyxfont::width("XXXXXX", font);
743 int align; // wrong type
744 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
745 align = layout.align;
747 align = row->par->FirstPhysicalPar()->align;
749 // set the correct parindent
751 if ((layout.labeltype == LABEL_NO_LABEL
752 || layout.labeltype == LABEL_TOP_ENVIRONMENT
753 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
754 || (layout.labeltype == LABEL_STATIC
755 && layout.latextype == LATEX_ENVIRONMENT
756 && ! row->par->IsFirstInSequence()))
757 && row->par == row->par->FirstPhysicalPar()
758 && align == LYX_ALIGN_BLOCK
759 && !row->par->noindent
760 && (row->par->layout ||
761 bparams->paragraph_separation ==
762 BufferParams::PARSEP_INDENT))
763 x += lyxfont::signedWidth(parindent,
768 else if (layout.labeltype == LABEL_BIBLIO) {
769 // ale970405 Right width for bibitems
770 x += bibitemMaxWidth(owner_->painter(),
781 int LyXText::RightMargin(Row const * row) const
783 LyXLayout const & layout =
784 textclasslist.Style(bparams->textclass,
785 row->par->GetLayout());
787 int x = LYX_PAPER_MARGIN
788 + lyxfont::signedWidth(textclasslist
789 .TextClass(bparams->textclass)
792 .TextClass(bparams->textclass)
795 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
796 x += LYX_PAPER_MARGIN / 2;
799 // this is the way, LyX handles the LaTeX-Environments.
800 // I have had this idea very late, so it seems to be a
801 // later added hack and this is true
802 if (row->par->GetDepth()) {
803 // find the next level paragraph
805 LyXParagraph * newpar = row->par;
808 newpar = newpar->FirstPhysicalPar()->Previous();
810 newpar = newpar->FirstPhysicalPar();
811 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
812 && newpar->footnoteflag == row->par->footnoteflag);
814 // make a corresponding row. Needed to call LeftMargin()
816 // check wether it is a sufficent paragraph
817 if (newpar && newpar->footnoteflag == row->par->footnoteflag
818 && textclasslist.Style(bparams->textclass,
822 dummyrow.par = newpar;
824 x = RightMargin(&dummyrow);
826 // this is no longer an error, because this function
827 // is used to clear impossible depths after changing
828 // a layout. Since there is always a redo,
829 // LeftMargin() is always called
830 row->par->FirstPhysicalPar()->depth = 0;
834 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
835 x += lyxfont::signedWidth(layout.rightmargin, textclasslist.TextClass(bparams->textclass).defaultfont()) * 4
836 / (row->par->GetDepth() + 4);
841 int LyXText::LabelEnd (Row const * row) const
843 if (textclasslist.Style(bparams->textclass,
844 row->par->GetLayout()).margintype
848 tmprow.pos = row->par->Last();
849 return LeftMargin(&tmprow); /* just the beginning
852 return 0; /* LabelEnd is only needed, if the
853 layout fills a flushleft
858 /* table stuff -- begin*/
859 int LyXText::NumberOfCell(LyXParagraph * par,
860 LyXParagraph::size_type pos) const
863 LyXParagraph::size_type tmp_pos = 0;
864 while (tmp_pos < pos) {
865 if (par->IsNewline(tmp_pos))
873 int LyXText::WidthOfCell(LyXParagraph * par,
874 LyXParagraph::size_type & pos) const
877 while (pos < par->Last() && !par->IsNewline(pos)) {
878 w += SingleWidth(par, pos);
881 if (par->IsNewline(pos))
887 bool LyXText::HitInTable(Row * row, int x) const
890 float fill_separator, fill_hfill, fill_label_hfill;
891 if (!row->par->table)
893 PrepareToPrint(row, tmpx, fill_separator,
894 fill_hfill, fill_label_hfill, false);
895 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
899 bool LyXText::MouseHitInTable(int x, long y) const
901 Row * row = GetRowNearY(y);
902 return HitInTable(row, x);
906 /* table stuff -- end*/
909 // get the next breakpoint in a given paragraph
910 LyXParagraph::size_type
911 LyXText::NextBreakPoint(Row const * row, int width) const
913 LyXParagraph * par = row->par;
914 LyXParagraph::size_type pos = row->pos;
916 /* table stuff -- begin*/
918 while (pos < par->size()
919 && (!par->IsNewline(pos)
920 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
921 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
922 par->GetInset(pos) && par->GetInset(pos)->display()){
923 par->GetInset(pos)->display(false);
929 /* table stuff -- end*/
931 // position of the last possible breakpoint
932 // -1 isn't a suitable value, but a flag
933 LyXParagraph::size_type last_separator = -1;
934 width -= RightMargin(row);
936 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
937 LyXLayout const & layout =
938 textclasslist.Style(bparams->textclass, par->GetLayout());
939 LyXParagraph::size_type i = pos;
941 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
942 /* special code for right address boxes, only newlines count */
943 while (i < par->Last()) {
944 if (par->IsNewline(i)) {
946 i = par->Last() - 1; // this means break
948 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
949 par->GetInset(i) && par->GetInset(i)->display()){
950 par->GetInset(i)->display(false);
955 // Last position is an invariant
956 LyXParagraph::size_type const last =
958 // this is the usual handling
959 int x = LeftMargin(row);
960 while (x < width && i < last) {
961 char c = par->GetChar(i);
962 if (IsNewlineChar(c)) {
964 x = width; // this means break
965 } else if (c == LyXParagraph::META_INSET &&
966 par->GetInset(i) && par->GetInset(i)->display()){
967 // check wether a Display() inset is
968 // valid here. if not, change it to
970 if (layout.isCommand()
971 || (layout.labeltype == LABEL_MANUAL
972 && i < BeginningOfMainBody(par))){
973 // display istn't allowd
974 par->GetInset(i)->display(false);
975 x += SingleWidth(par, i, c);
977 // inset is display. So break the line here
981 if (IsLineSeparatorChar(par->GetChar(i+1)))
984 last_separator = last; // to avoid extra rows
986 last_separator = i - 1;
987 x = width; // this means break
990 if (IsLineSeparatorChar(c))
992 x += SingleWidth(par, i, c);
995 if (i == main_body) {
996 x += lyxfont::width(layout.labelsep,
998 if (par->IsLineSeparator(i - 1))
999 x-= SingleWidth(par, i - 1);
1000 int left_margin = LabelEnd(row);
1001 if (x < left_margin)
1005 // end of paragraph is always a suitable separator
1006 if (i == last && x < width)
1010 // well, if last_separator is still 0, the line isn't breakable.
1011 // don't care and cut simply at the end
1012 if (last_separator < 0) {
1016 // manual labels cannot be broken in LaTeX, do not care
1017 if (main_body && last_separator < main_body)
1018 last_separator = main_body - 1;
1020 return last_separator;
1024 // returns the minimum space a row needs on the screen in pixel
1025 int LyXText::Fill(Row const * row, int paper_width) const
1028 // get the pure distance
1029 LyXParagraph::size_type last = RowLastPrintable(row);
1030 /* table stuff -- begin */
1031 if (row->par->table) {
1032 // for tables FILL does calculate the widthes of each cell in
1034 LyXParagraph::size_type pos = row->pos;
1035 int cell = NumberOfCell(row->par, pos);
1038 row->par->table->SetWidthOfCell(cell,
1039 WidthOfCell(row->par,
1042 } while (pos <= last && !row->par->table->IsFirstCell(cell));
1043 // don't forget the very last table cell without characters
1044 if (cell == row->par->table->GetNumberOfCells() - 1)
1045 row->par->table->SetWidthOfCell(cell,
1046 WidthOfCell(row->par,
1049 return 0; /* width of table cannot be returned since
1050 * we cannot guarantee its correct value at
1053 /* table stuff -- end*/
1055 // special handling of the right address boxes
1056 if (textclasslist.Style(bparams->textclass,
1057 row->par->GetLayout()).margintype
1058 == MARGIN_RIGHT_ADDRESS_BOX) {
1059 int tmpfill = row->fill;
1060 row->fill = 0; // the minfill in MarginLeft()
1061 w = LeftMargin(row);
1062 row->fill = tmpfill;
1064 w = LeftMargin(row);
1066 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
1067 row->par->GetLayout());
1068 LyXParagraph::size_type main_body =
1069 BeginningOfMainBody(row->par);
1070 LyXParagraph::size_type i = row->pos;
1073 if (main_body > 0 && i == main_body) {
1074 w += lyxfont::width(layout.labelsep, GetFont(row->par, -2));
1075 if (row->par->IsLineSeparator(i - 1))
1076 w -= SingleWidth(row->par, i - 1);
1077 int left_margin = LabelEnd(row);
1078 if (w < left_margin)
1081 w += SingleWidth(row->par, i);
1084 if (main_body > 0 && main_body > last) {
1085 w += lyxfont::width(layout.labelsep, GetFont(row->par, -2));
1086 if (last >= 0 && row->par->IsLineSeparator(last))
1087 w -= SingleWidth(row->par, last);
1088 int left_margin = LabelEnd(row);
1089 if (w < left_margin)
1093 fill = paper_width - w - RightMargin(row);
1098 // returns the minimum space a manual label needs on the screen in pixel
1099 int LyXText::LabelFill(Row const * row) const
1101 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1102 // -1 because a label ends either with a space that is in the label,
1103 // or with the beginning of a footnote that is outside the label.
1105 // I don't understand this code in depth, but sometimes "last" is
1106 // less than 0 and this causes a crash. This fix seems to work
1107 // correctly, but I bet the real error is elsewhere. The bug is
1108 // triggered when you have an open footnote in a paragraph
1109 // environment with a manual label. (Asger)
1110 if (last < 0) last = 0;
1112 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1119 w += SingleWidth(row->par, i);
1124 if (!row->par->labelwidthstring.empty()) {
1125 fill = max(lyxfont::width(row->par->labelwidthstring,
1126 GetFont(row->par, -2)) - w,
1134 // returns the number of separators in the specified row. The separator
1135 // on the very last column doesnt count
1136 int LyXText::NumberOfSeparators(Row const * row) const
1138 int last = RowLast(row);
1139 int p = max(row->pos, BeginningOfMainBody(row->par));
1141 for (; p < last; ++p) {
1142 if (row->par->IsSeparator(p)) {
1150 // returns the number of hfills in the specified row. The LyX-Hfill is
1151 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1152 // ignored. This is *MUCH* more usefull than not to ignore!
1153 int LyXText::NumberOfHfills(Row const * row) const
1155 int last = RowLast(row);
1156 int first = row->pos;
1157 if (first) { /* hfill *DO* count at the beginning
1159 while(first <= last && row->par->IsHfill(first))
1163 first = max(first, BeginningOfMainBody(row->par));
1165 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1166 if (row->par->IsHfill(p)) {
1174 // like NumberOfHfills, but only those in the manual label!
1175 int LyXText::NumberOfLabelHfills(Row const * row) const
1177 LyXParagraph::size_type last = RowLast(row);
1178 LyXParagraph::size_type first = row->pos;
1179 if (first) { /* hfill *DO* count at the beginning
1181 while(first < last && row->par->IsHfill(first))
1185 last = min(last, BeginningOfMainBody(row->par));
1187 for (LyXParagraph::size_type p = first;
1188 p < last; ++p) { // last, because the end is ignored!
1189 if (row->par->IsHfill(p)) {
1197 // returns true, if a expansion is needed.
1198 // Rules are given by LaTeX
1199 bool LyXText::HfillExpansion(Row const * row_ptr,
1200 LyXParagraph::size_type pos) const
1202 // by the way, is it a hfill?
1203 if (!row_ptr->par->IsHfill(pos))
1206 // at the end of a row it does not count
1207 if (pos >= RowLast(row_ptr))
1210 // at the beginning of a row it does not count, if it is not
1211 // the first row of a paragaph
1215 // in some labels it does not count
1216 if (textclasslist.Style(bparams->textclass,
1217 row_ptr->par->GetLayout()).margintype
1219 && pos < BeginningOfMainBody(row_ptr->par))
1222 // if there is anything between the first char of the row and
1223 // the sepcified position that is not a newline and not a hfill,
1224 // the hfill will count, otherwise not
1225 LyXParagraph::size_type i = row_ptr->pos;
1226 while (i < pos && (row_ptr->par->IsNewline(i)
1227 || row_ptr->par->IsHfill(i)))
1234 void LyXText::SetHeightOfRow(Row * row_ptr) const
1236 /* get the maximum ascent and the maximum descent */
1238 float layoutasc = 0;
1239 float layoutdesc = 0;
1244 /* this must not happen before the currentrow for clear reasons.
1245 so the trick is just to set the current row onto this row */
1247 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1249 /* ok , let us initialize the maxasc and maxdesc value.
1250 * This depends in LaTeX of the font of the last character
1251 * in the paragraph. The hack below is necessary because
1252 * of the possibility of open footnotes */
1254 /* Correction: only the fontsize count. The other properties
1255 are taken from the layoutfont. Nicer on the screen :) */
1257 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1258 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1260 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
1261 firstpar->GetLayout());
1263 LyXFont font = GetFont(par, par->Last() - 1);
1264 LyXFont::FONT_SIZE size = font.size();
1265 font = GetFont(par, -1);
1268 LyXFont labelfont = GetFont(par, -2);
1270 float spacing_val = 1.0;
1271 if (!row_ptr->par->spacing.isDefault()) {
1272 spacing_val = row_ptr->par->spacing.getValue();
1274 spacing_val = bparams->spacing.getValue();
1276 lyxerr << "spacing_val = " << spacing_val << endl;
1278 int maxasc = int(lyxfont::maxAscent(font) *
1279 layout.spacing.getValue() *
1281 int maxdesc = int(lyxfont::maxDescent(font) *
1282 layout.spacing.getValue() *
1285 int pos_end = RowLast(row_ptr);
1289 // Check if any insets are larger
1290 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1291 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1292 tmpfont = GetFont(row_ptr->par, pos);
1293 tmpinset = row_ptr->par->GetInset(pos);
1295 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1296 desc = tmpinset->descent(owner_->painter(), tmpfont);
1305 // Check if any custom fonts are larger (Asger)
1306 // This is not completely correct, but we can live with the small,
1307 // cosmetic error for now.
1308 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1310 if (maxsize > font.size()) {
1311 font.setSize(maxsize);
1313 asc = lyxfont::maxAscent(font);
1314 desc = lyxfont::maxDescent(font);
1321 /* table stuff -- begin*/
1322 if (row_ptr->par->table){
1323 // stretch the rows a bit
1327 /* table stuff -- end*/
1329 // This is nicer with box insets:
1333 row_ptr->ascent_of_text = maxasc;
1335 /* is it a top line? */
1336 if (row_ptr->pos == 0
1337 && row_ptr->par == firstpar) {
1339 /* some parksips VERY EASY IMPLEMENTATION */
1340 if (bparams->paragraph_separation == BufferParams::PARSEP_SKIP) {
1341 if (layout.isParagraph()
1342 && firstpar->GetDepth() == 0
1343 && firstpar->Previous())
1344 maxasc += bparams->getDefSkip().inPixels(owner_);
1345 else if (firstpar->Previous()
1346 && textclasslist.Style(bparams->textclass,
1347 firstpar->Previous()->GetLayout()).isParagraph()
1348 && firstpar->Previous()->GetDepth() == 0)
1349 // is it right to use defskip here too? (AS)
1350 maxasc += bparams->getDefSkip().inPixels(owner_);
1353 /* the paper margins */
1354 if (!row_ptr->par->previous)
1355 maxasc += LYX_PAPER_MARGIN;
1357 /* add the vertical spaces, that the user added */
1358 if (firstpar->added_space_top.kind() != VSpace::NONE)
1359 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1361 /* do not forget the DTP-lines!
1362 * there height depends on the font of the nearest character */
1363 if (firstpar->line_top)
1364 maxasc += 2 * lyxfont::ascent('x', GetFont(firstpar, 0));
1366 /* and now the pagebreaks */
1367 if (firstpar->pagebreak_top)
1368 maxasc += 3 * DefaultHeight();
1370 /* this is special code for the chapter, since the label of this
1371 * layout is printed in an extra row */
1372 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1373 && bparams->secnumdepth>= 0) {
1374 float spacing_val = 1.0;
1375 if (!row_ptr->par->spacing.isDefault()) {
1376 spacing_val = row_ptr->par->spacing.getValue();
1378 spacing_val = bparams->spacing.getValue();
1381 labeladdon = int(lyxfont::maxDescent(labelfont) *
1382 layout.spacing.getValue() *
1384 + int(lyxfont::maxAscent(labelfont) *
1385 layout.spacing.getValue() *
1389 /* special code for the top label */
1390 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1391 || layout.labeltype == LABEL_BIBLIO
1392 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1393 && row_ptr->par->IsFirstInSequence()
1394 && !row_ptr->par->GetLabelstring().empty()) {
1395 float spacing_val = 1.0;
1396 if (!row_ptr->par->spacing.isDefault()) {
1397 spacing_val = row_ptr->par->spacing.getValue();
1399 spacing_val = bparams->spacing.getValue();
1403 (lyxfont::maxAscent(labelfont) *
1404 layout.spacing.getValue() *
1406 +(lyxfont::maxDescent(labelfont) *
1407 layout.spacing.getValue() *
1409 + layout.topsep * DefaultHeight()
1410 + layout.labelbottomsep * DefaultHeight());
1413 /* and now the layout spaces, for example before and after a section,
1414 * or between the items of a itemize or enumerate environment */
1416 if (!firstpar->pagebreak_top) {
1417 LyXParagraph * prev = row_ptr->par->Previous();
1419 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1420 if (prev && prev->GetLayout() == firstpar->GetLayout()
1421 && prev->GetDepth() == firstpar->GetDepth()
1422 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1424 layoutasc = (layout.itemsep * DefaultHeight());
1426 else if (row_ptr->previous) {
1427 tmptop = layout.topsep;
1429 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1430 tmptop-= textclasslist.Style(bparams->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1433 layoutasc = (tmptop * DefaultHeight());
1435 else if (row_ptr->par->line_top){
1436 tmptop = layout.topsep;
1439 layoutasc = (tmptop * DefaultHeight());
1442 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1444 maxasc += int(textclasslist.Style(bparams->textclass,
1445 prev->GetLayout()).parsep * DefaultHeight());
1448 if (firstpar->Previous()
1449 && firstpar->Previous()->GetDepth() == 0
1450 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1453 else if (firstpar->Previous()){
1454 maxasc += int(layout.parsep * DefaultHeight());
1460 /* is it a bottom line? */
1461 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1462 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1464 /* the paper margins */
1466 maxdesc += LYX_PAPER_MARGIN;
1468 /* add the vertical spaces, that the user added */
1469 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1470 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1472 /* do not forget the DTP-lines!
1473 * there height depends on the font of the nearest character */
1474 if (firstpar->line_bottom)
1475 maxdesc += 2 * lyxfont::ascent('x', GetFont(par, par->Last() - 1));
1477 /* and now the pagebreaks */
1478 if (firstpar->pagebreak_bottom)
1479 maxdesc += 3 * DefaultHeight();
1481 /* and now the layout spaces, for example before and after a section,
1482 * or between the items of a itemize or enumerate environment */
1483 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1484 LyXParagraph * nextpar = row_ptr->par->Next();
1485 LyXParagraph * comparepar = row_ptr->par;
1489 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1490 usual = (textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1491 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1492 if (comparepar->GetLayout()!= nextpar->GetLayout()
1493 || nextpar->GetLabelWidthString() !=
1494 comparepar->GetLabelWidthString())
1495 unusual = (textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1497 if (unusual > usual)
1498 layoutdesc = unusual;
1502 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1504 if (comparepar->GetLayout()!= nextpar->GetLayout()
1505 || nextpar->GetLabelWidthString() !=
1506 comparepar->GetLabelWidthString())
1507 layoutdesc = int(textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1512 /* incalculate the layout spaces */
1513 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1514 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1516 /* table stuff -- begin*/
1517 if (row_ptr->par->table){
1518 maxasc += row_ptr->par->table->
1519 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1521 /* table stuff -- end*/
1523 /* calculate the new height of the text */
1524 height -= row_ptr->height;
1526 row_ptr->height = maxasc + maxdesc + labeladdon;
1527 row_ptr->baseline = maxasc + labeladdon;
1529 height += row_ptr->height;
1533 /* Appends the implicit specified paragraph behind the specified row,
1534 * start at the implicit given position */
1535 void LyXText::AppendParagraph(Row * row) const
1537 bool not_ready = true;
1539 // The last character position of a paragraph is an invariant so we can
1540 // safely get it here. (Asger)
1541 int lastposition = row->par->Last();
1544 // Get the next breakpoint
1545 int z = NextBreakPoint(row, paperwidth);
1549 // Insert the new row
1550 if (z < lastposition) {
1552 InsertRow(row, row->par, z);
1559 // Set the dimensions of the row
1560 tmprow->fill = Fill(tmprow, paperwidth);
1561 SetHeightOfRow(tmprow);
1563 } while (not_ready);
1567 void LyXText::BreakAgain(Row * row) const
1569 bool not_ready = true;
1572 /* get the next breakpoint */
1573 LyXParagraph::size_type z =
1574 NextBreakPoint(row, paperwidth);
1577 if (z < row->par->Last() ) {
1578 if (!row->next || (row->next && row->next->par != row->par)) {
1581 InsertRow(row, row->par, z);
1588 not_ready = false; // the rest will not change
1594 /* if there are some rows too much, delete them */
1595 /* only if you broke the whole paragraph! */
1596 Row * tmprow2 = row;
1597 while (tmprow2->next && tmprow2->next->par == row->par) {
1598 tmprow2 = tmprow2->next;
1600 while (tmprow2 != row) {
1601 tmprow2 = tmprow2->previous;
1602 RemoveRow(tmprow2->next);
1607 /* set the dimensions of the row */
1608 tmprow->fill = Fill(tmprow, paperwidth);
1609 SetHeightOfRow(tmprow);
1610 } while (not_ready);
1614 /* this is just a little changed version of break again */
1615 void LyXText::BreakAgainOneRow(Row * row)
1617 /* get the next breakpoint */
1618 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1621 if (z < row->par->Last() ) {
1622 if (!row->next || (row->next && row->next->par != row->par)) {
1623 /* insert a new row */
1625 InsertRow(row, row->par, z);
1637 /* if there are some rows too much, delete them */
1638 /* only if you broke the whole paragraph! */
1639 Row * tmprow2 = row;
1640 while (tmprow2->next && tmprow2->next->par == row->par) {
1641 tmprow2 = tmprow2->next;
1643 while (tmprow2 != row) {
1644 tmprow2 = tmprow2->previous;
1645 RemoveRow(tmprow2->next);
1649 /* set the dimensions of the row */
1650 tmprow->fill = Fill(tmprow, paperwidth);
1651 SetHeightOfRow(tmprow);
1655 void LyXText::BreakParagraph(char keep_layout)
1657 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
1658 cursor.par->GetLayout());
1660 /* table stuff -- begin */
1661 if (cursor.par->table) {
1662 // breaking of tables is only allowed at the beginning or the end */
1663 if (cursor.pos && cursor.pos < cursor.par->size() &&
1664 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1665 return; // no breaking of tables allowed
1667 /* table stuff -- end */
1669 // this is only allowed, if the current paragraph is not empty or caption
1670 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1672 layout.labeltype!= LABEL_SENSITIVE)
1675 SetUndo(Undo::INSERT,
1676 cursor.par->ParFromPos(cursor.pos)->previous,
1677 cursor.par->ParFromPos(cursor.pos)->next);
1679 /* table stuff -- begin */
1680 if (cursor.par->table) {
1681 int cell = NumberOfCell(cursor.par, cursor.pos);
1682 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1683 SetCursor(cursor.par, cursor.par->size());
1685 /* table stuff -- end */
1687 // please break always behind a space
1688 if (cursor.pos < cursor.par->Last()
1689 && cursor.par->IsLineSeparator(cursor.pos))
1692 // break the paragraph
1696 keep_layout = layout.isEnvironment();
1697 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1699 /* table stuff -- begin */
1700 if (cursor.par->table){
1701 // the table should stay with the contents
1703 cursor.par->Next()->table = cursor.par->table;
1704 cursor.par->table = 0;
1707 /* table stuff -- end */
1709 // well this is the caption hack since one caption is really enough
1710 if (layout.labeltype == LABEL_SENSITIVE) {
1712 cursor.par->SetLayout(0); // set to standard-layout
1714 cursor.par->Next()->SetLayout(0); // set to standard-layout
1717 /* if the cursor is at the beginning of a row without prior newline,
1719 * This touches only the screen-update. Otherwise we would may have
1720 * an empty row on the screen */
1721 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1722 cursor.row->pos == cursor.pos) {
1726 status = LyXText::NEED_MORE_REFRESH;
1727 refresh_row = cursor.row;
1728 refresh_y = cursor.y - cursor.row->baseline;
1730 // Do not forget the special right address boxes
1731 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1732 while (refresh_row->previous &&
1733 refresh_row->previous->par == refresh_row->par) {
1734 refresh_row = refresh_row->previous;
1735 refresh_y -= refresh_row->height;
1738 RemoveParagraph(cursor.row);
1740 // set the dimensions of the cursor row
1741 cursor.row->fill = Fill(cursor.row, paperwidth);
1743 SetHeightOfRow(cursor.row);
1745 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1746 && cursor.par->Next()->IsNewline(0))
1747 cursor.par->Next()->Erase(0);
1749 InsertParagraph(cursor.par->Next(), cursor.row);
1751 UpdateCounters(cursor.row->previous);
1753 /* This check is necessary. Otherwise the new empty paragraph will
1754 * be deleted automatically. And it is more friendly for the user! */
1756 SetCursor(cursor.par->Next(), 0);
1758 SetCursor(cursor.par, 0);
1760 if (cursor.row->next)
1761 BreakAgain(cursor.row->next);
1767 void LyXText::OpenFootnote()
1769 LyXParagraph * endpar,* tmppar;
1772 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1774 /* if there is no footnote in this paragraph, just return. */
1776 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1779 /* ok, move the cursor right before the footnote */
1781 /* just a little faster than using CursorRight() */
1782 for (cursor.pos = 0;
1783 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1784 /* now the cursor is at the beginning of the physical par */
1785 SetCursor(cursor.par,
1786 cursor.pos + cursor.par->ParFromPos(cursor.pos)->size());
1788 /* the cursor must be exactly before the footnote */
1789 par = cursor.par->ParFromPos(cursor.pos);
1791 status = LyXText::NEED_MORE_REFRESH;
1792 refresh_row = cursor.row;
1793 refresh_y = cursor.y - cursor.row->baseline;
1795 tmppar = cursor.par;
1796 endpar = cursor.par->Next();
1799 tmppar->OpenFootnote(cursor.pos);
1800 RemoveParagraph(row);
1801 /* set the dimensions of the cursor row */
1802 row->fill = Fill(row, paperwidth);
1803 SetHeightOfRow(row);
1804 #warning See comment on top of text.C
1805 tmppar = tmppar->Next();
1807 while (tmppar != endpar) {
1809 InsertParagraph(tmppar, row);
1810 while (row->next && row->next->par == tmppar)
1812 tmppar = tmppar->Next();
1815 SetCursor(par->next, 0);
1816 sel_cursor = cursor;
1820 /* table stuff -- begin*/
1822 void LyXText::TableFeatures(int feature, string const & val) const
1824 if (!cursor.par->table)
1825 return; /* this should never happen */
1827 int actCell = NumberOfCell(cursor.par, cursor.pos);
1828 SetUndo(Undo::FINISH,
1829 cursor.par->ParFromPos(cursor.pos)->previous,
1830 cursor.par->ParFromPos(cursor.pos)->next);
1833 case LyXTable::SET_PWIDTH:
1834 cursor.par->table->SetPWidth(actCell, val);
1836 case LyXTable::SET_SPECIAL_COLUMN:
1837 case LyXTable::SET_SPECIAL_MULTI:
1838 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1847 void LyXText::TableFeatures(int feature) const
1850 int setAlign = LYX_ALIGN_LEFT;
1854 if (!cursor.par->table)
1855 return; /* this should never happen */
1857 int actCell = NumberOfCell(cursor.par, cursor.pos);
1858 SetUndo(Undo::FINISH,
1859 cursor.par->ParFromPos(cursor.pos)->previous,
1860 cursor.par->ParFromPos(cursor.pos)->next);
1863 case LyXTable::ALIGN_LEFT:
1864 setAlign= LYX_ALIGN_LEFT;
1866 case LyXTable::ALIGN_RIGHT:
1867 setAlign= LYX_ALIGN_RIGHT;
1869 case LyXTable::ALIGN_CENTER:
1870 setAlign= LYX_ALIGN_CENTER;
1876 case LyXTable::APPEND_ROW: {
1877 LyXParagraph::size_type pos = cursor.pos;
1879 /* move to the next row */
1880 int cell_org = actCell;
1881 int cell = cell_org;
1883 // if there is a ContRow following this row I have to add
1884 // the row after the ContRow's
1885 if ((pos < cursor.par->Last()) &&
1886 cursor.par->table->RowHasContRow(cell_org)) {
1887 while((pos < cursor.par->Last()) &&
1888 !cursor.par->table->IsContRow(cell)) {
1889 while (pos < cursor.par->Last() &&
1890 !cursor.par->IsNewline(pos))
1892 if (pos < cursor.par->Last())
1896 while((pos < cursor.par->Last()) &&
1897 cursor.par->table->IsContRow(cell)) {
1898 while (pos < cursor.par->Last() &&
1899 !cursor.par->IsNewline(pos))
1901 if (pos < cursor.par->Last())
1906 if (pos < cursor.par->Last())
1909 while (pos < cursor.par->Last() &&
1910 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1911 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1913 if (pos < cursor.par->Last())
1918 /* insert the new cells */
1919 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1920 Language const * lang = cursor.par->getParLanguage();
1921 LyXFont font(LyXFont::ALL_INHERIT,lang);
1922 for (int i = 0; i < number; ++i) {
1923 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1924 cursor.par->SetFont(pos, font);
1927 /* append the row into the table */
1928 cursor.par->table->AppendRow(cell_org);
1932 case LyXTable::APPEND_CONT_ROW: {
1933 LyXParagraph::size_type pos = cursor.pos;
1934 /* move to the next row */
1935 int cell_org = actCell;
1936 int cell = cell_org;
1938 // if there is already a controw but not for this cell
1939 // the AppendContRow sets only the right values but does
1940 // not actually add a row
1941 if (cursor.par->table->RowHasContRow(cell_org) &&
1942 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1943 cursor.par->table->AppendContRow(cell_org);
1947 while (pos < cursor.par->Last() &&
1949 || !cursor.par->table->IsFirstCell(cell))){
1950 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1952 if (pos < cursor.par->Last())
1957 /* insert the new cells */
1958 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1959 Language const * lang = cursor.par->getParLanguage();
1960 LyXFont font(LyXFont::ALL_INHERIT,lang);
1961 for (int i = 0; i < number; ++i) {
1962 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1963 cursor.par->SetFont(pos, font);
1966 /* append the row into the table */
1967 cursor.par->table->AppendContRow(cell_org);
1971 case LyXTable::APPEND_COLUMN: {
1972 LyXParagraph::size_type pos = 0;
1973 int cell_org = actCell;
1975 Language const * lang = cursor.par->getParLanguage();
1976 LyXFont font(LyXFont::ALL_INHERIT,lang);
1978 if (pos && (cursor.par->IsNewline(pos-1))){
1979 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1980 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1981 cursor.par->SetFont(pos, font);
1982 if (pos <= cursor.pos)
1989 } while (pos <= cursor.par->Last());
1990 /* remember that the very last cell doesn't end with a newline.
1991 This saves one byte memory per table ;-) */
1992 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1993 LyXParagraph::size_type last = cursor.par->Last();
1994 cursor.par->InsertChar(last, LyXParagraph::META_NEWLINE);
1995 cursor.par->SetFont(last, font);
1998 /* append the column into the table */
1999 cursor.par->table->AppendColumn(cell_org);
2004 case LyXTable::DELETE_ROW:
2005 if (owner_->the_locking_inset)
2006 owner_->unlockInset(owner_->the_locking_inset);
2007 RemoveTableRow(&cursor);
2011 case LyXTable::DELETE_COLUMN: {
2012 LyXParagraph::size_type pos = 0;
2013 int cell_org = actCell;
2015 if (owner_->the_locking_inset)
2016 owner_->unlockInset(owner_->the_locking_inset);
2018 if (!pos || (cursor.par->IsNewline(pos-1))){
2019 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2021 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2022 cursor.par->Erase(pos);
2023 if (pos < cursor.par->Last())
2024 cursor.par->Erase(pos);
2026 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
2027 --pos; // because of pos++ below
2032 } while (pos <= cursor.par->Last());
2034 /* delete the column from the table */
2035 cursor.par->table->DeleteColumn(cell_org);
2037 /* set the cursor to the beginning of the table, where else? */
2042 case LyXTable::TOGGLE_LINE_TOP:
2043 lineSet = !cursor.par->table->TopLine(actCell);
2045 cursor.par->table->SetTopLine(actCell, lineSet);
2047 LyXParagraph::size_type i;
2049 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2050 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2051 cursor.par->table->SetTopLine(n, lineSet);
2059 case LyXTable::TOGGLE_LINE_BOTTOM:
2060 lineSet = !cursor.par->table->BottomLine(actCell);
2062 cursor.par->table->SetBottomLine(actCell, lineSet);
2064 LyXParagraph::size_type i;
2066 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2067 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2068 cursor.par->table->SetBottomLine(n, lineSet);
2076 case LyXTable::TOGGLE_LINE_LEFT:
2077 lineSet = !cursor.par->table->LeftLine(actCell);
2079 cursor.par->table->SetLeftLine(actCell, lineSet);
2081 LyXParagraph::size_type i;
2083 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2084 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2085 cursor.par->table->SetLeftLine(n, lineSet);
2093 case LyXTable::TOGGLE_LINE_RIGHT:
2094 lineSet = !cursor.par->table->RightLine(actCell);
2096 cursor.par->table->SetRightLine(actCell, lineSet);
2099 LyXParagraph::size_type i = sel_start_cursor.pos;
2100 for (; i <= sel_end_cursor.pos; ++i) {
2101 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2102 cursor.par->table->SetRightLine(n, lineSet);
2110 case LyXTable::ALIGN_LEFT:
2111 case LyXTable::ALIGN_RIGHT:
2112 case LyXTable::ALIGN_CENTER:
2114 cursor.par->table->SetAlignment(actCell, setAlign);
2117 LyXParagraph::size_type i = sel_start_cursor.pos;
2118 for (; i <= sel_end_cursor.pos; ++i) {
2119 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2120 cursor.par->table->SetAlignment(n, setAlign);
2128 case LyXTable::DELETE_TABLE:
2129 SetCursorIntern(cursor.par, 0);
2130 delete cursor.par->table;
2131 cursor.par->table = 0;
2132 // temporary: Should put table in simple_cut_buffer (with before and after
2133 // dummy-paragraph !!
2134 // not necessar anymore with UNDO :)
2135 for (LyXParagraph::size_type i =
2136 cursor.par->size() - 1; i >= 0; --i)
2137 cursor.par->Erase(i);
2141 case LyXTable::MULTICOLUMN: {
2143 // check wether we are completly in a multicol
2144 int multicol = cursor.par->table->IsMultiColumn(actCell);
2145 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2146 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2147 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2151 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2152 LyXParagraph::size_type pos = cursor.pos;
2153 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2155 for (; newlines; --newlines)
2156 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2161 // selection must be in one row (or no selection)
2163 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2170 if (sel_start_cursor.row == sel_end_cursor.row){
2171 LyXParagraph::size_type i;
2173 for (i = sel_start_cursor.pos;
2174 i < sel_end_cursor.pos; ++i){
2175 if (sel_start_cursor.par->IsNewline(i)){
2176 sel_start_cursor.par->Erase(i);
2177 // check for double-blanks
2178 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2180 (i < sel_start_cursor.par->Last()
2181 && !sel_start_cursor.par->IsLineSeparator(i)))
2182 sel_start_cursor.par->InsertChar(i, ' ');
2184 sel_end_cursor.pos--;
2191 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2192 sel_start_cursor.pos),
2194 cursor.pos = sel_start_cursor.pos;
2199 WriteAlert(_("Impossible Operation!"),
2200 _("Multicolumns can only be horizontally."),
2207 case LyXTable::SET_ALL_LINES:
2209 case LyXTable::UNSET_ALL_LINES:
2211 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2215 LyXParagraph::size_type i;
2217 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2218 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2219 cursor.par->table->SetAllLines(n, setLines);
2226 case LyXTable::SET_LONGTABLE:
2227 cursor.par->table->SetLongTable(true);
2229 case LyXTable::UNSET_LONGTABLE:
2230 cursor.par->table->SetLongTable(false);
2232 case LyXTable::SET_ROTATE_TABLE:
2233 cursor.par->table->SetRotateTable(true);
2235 case LyXTable::UNSET_ROTATE_TABLE:
2236 cursor.par->table->SetRotateTable(false);
2238 case LyXTable::SET_ROTATE_CELL:
2240 cursor.par->table->SetRotateCell(actCell, true);
2242 LyXParagraph::size_type i;
2244 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2245 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2246 cursor.par->table->SetRotateCell(n, true);
2252 case LyXTable::UNSET_ROTATE_CELL:
2254 cursor.par->table->SetRotateCell(actCell, false);
2257 LyXParagraph::size_type i = sel_start_cursor.pos;
2258 for (; i <= sel_end_cursor.pos; ++i) {
2259 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2260 cursor.par->table->SetRotateCell(n, false);
2266 case LyXTable::SET_LINEBREAKS:
2267 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2269 cursor.par->table->SetLinebreaks(actCell, what);
2271 LyXParagraph::size_type i;
2273 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2274 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2275 cursor.par->table->SetLinebreaks(n, what);
2281 case LyXTable::SET_LTFIRSTHEAD:
2282 cursor.par->table->SetLTHead(actCell, true);
2284 case LyXTable::SET_LTHEAD:
2285 cursor.par->table->SetLTHead(actCell, false);
2287 case LyXTable::SET_LTFOOT:
2288 cursor.par->table->SetLTFoot(actCell, false);
2290 case LyXTable::SET_LTLASTFOOT:
2291 cursor.par->table->SetLTFoot(actCell, true);
2293 case LyXTable::SET_LTNEWPAGE:
2294 what = !cursor.par->table->LTNewPage(actCell);
2295 cursor.par->table->SetLTNewPage(actCell, what);
2301 void LyXText::InsertCharInTable(char c)
2306 bool jumped_over_space;
2308 /* first check, if there will be two blanks together or a blank at
2309 * the beginning of a paragraph.
2310 * I decided to handle blanks like normal characters, the main
2311 * difference are the special checks when calculating the row.fill
2312 * (blank does not count at the end of a row) and the check here */
2314 LyXFont realtmpfont = real_current_font;
2315 LyXFont rawtmpfont = current_font; /* store the current font.
2316 * This is because of the use
2317 * of cursor movements. The moving
2318 * cursor would refresh the
2321 // Get the font that is used to calculate the baselineskip
2322 LyXParagraph::size_type const lastpos =
2324 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2326 jumped_over_space = false;
2327 if (IsLineSeparatorChar(c)) {
2329 #ifndef FIX_DOUBLE_SPACE
2330 /* avoid double blanks but insert the new blank because
2331 * of a possible font change */
2332 if (cursor.pos < lastpos &&
2333 cursor.par->IsLineSeparator(cursor.pos)) {
2334 cursor.par->Erase(cursor.pos);
2335 jumped_over_space = true;
2338 if ((cursor.pos > 0 &&
2339 cursor.par->IsLineSeparator(cursor.pos - 1))
2340 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2341 || (cursor.pos == 0 &&
2342 !(cursor.par->Previous()
2343 && cursor.par->Previous()->footnoteflag
2344 == LyXParagraph::OPEN_FOOTNOTE)))
2346 } else if (IsNewlineChar(c)) {
2347 if (!IsEmptyTableCell()) {
2348 TableFeatures(LyXTable::APPEND_CONT_ROW);
2355 y = cursor.y - row->baseline;
2356 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2357 * already inserted the character */
2358 cursor.par->InsertChar(cursor.pos, c);
2359 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2361 if (!jumped_over_space) {
2362 /* refresh the positions */
2364 while (tmprow->next && tmprow->next->par == row->par) {
2365 tmprow = tmprow->next;
2372 CheckParagraphInTable(cursor.par, cursor.pos);
2374 current_font = rawtmpfont;
2375 real_current_font = realtmpfont;
2377 /* check, whether the last character's font has changed. */
2378 if (cursor.pos && cursor.pos == cursor.par->Last()
2379 && rawparfont != rawtmpfont)
2380 RedoHeightOfParagraph(cursor);
2384 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2385 LyXParagraph::size_type pos)
2388 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2389 par->GetInset(pos) && par->GetInset(pos)->display()){
2390 par->GetInset(pos)->display(false);
2394 Row * row = GetRow(par, pos, y);
2396 int tmpheight = row->height;
2397 SetHeightOfRow(row);
2399 LyXParagraph::size_type tmp_pos = pos;
2400 /* update the table information */
2401 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2403 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2404 WidthOfCell(par, tmp_pos))) {
2405 LyXCursor tmpcursor = cursor;
2406 SetCursorIntern(par, pos);
2407 /* make a complete redraw */
2408 RedoDrawingOfParagraph(cursor);
2412 /* redraw only the row */
2413 LyXCursor tmpcursor = cursor;
2414 SetCursorIntern(par, pos);
2415 #warning See comment on top of text.C
2417 refresh_x = cursor.x;
2419 refresh_pos = cursor.pos;
2422 if (tmpheight == row->height)
2423 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2425 status = LyXText::NEED_MORE_REFRESH;
2427 SetCursorIntern(cursor.par, cursor.pos);
2431 void LyXText::BackspaceInTable()
2433 Row * tmprow, * row;
2436 LyXFont rawtmpfont = current_font;
2437 LyXFont realtmpfont = real_current_font;
2439 // Get the font that is used to calculate the baselineskip
2440 int const lastpos = cursor.par->Last();
2441 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2443 if (cursor.pos == 0) {
2444 /* no pasting of table paragraphs */
2448 /* this is the code for a normal backspace, not pasting
2450 SetUndo(Undo::DELETE,
2451 cursor.par->ParFromPos(cursor.pos)->previous,
2452 cursor.par->ParFromPos(cursor.pos)->next);
2456 /* some insets are undeletable here */
2457 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2458 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2463 y = cursor.y - row->baseline;
2465 /* some special code when deleting a newline. */
2466 if (cursor.par->IsNewline(cursor.pos)) {
2471 cursor.par->Erase(cursor.pos);
2473 /* refresh the positions */
2475 while (tmprow->next && tmprow->next->par == row->par) {
2476 tmprow = tmprow->next;
2480 #ifndef FIX_DOUBLE_SPACE
2481 /* delete superfluous blanks */
2482 if (cursor.pos < cursor.par->Last() - 1 &&
2483 (cursor.par->IsLineSeparator(cursor.pos))) {
2485 if (cursor.pos == BeginningOfMainBody(cursor.par)
2487 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2488 cursor.par->Erase(cursor.pos);
2489 /* refresh the positions */
2491 while (tmprow->next &&
2492 tmprow->next->par == row->par) {
2493 tmprow = tmprow->next;
2496 if (cursor.pos) /* move one character left */
2503 CheckParagraphInTable(cursor.par, cursor.pos);
2505 /* check, wether the last characters font has changed. */
2506 if (cursor.pos && cursor.pos == cursor.par->Last()
2507 && rawparfont != rawtmpfont)
2508 RedoHeightOfParagraph(cursor);
2510 /* restore the current font
2511 * That is what a user expects! */
2512 current_font = rawtmpfont;
2513 real_current_font = realtmpfont;
2515 SetCursorIntern(cursor.par, cursor.pos);
2518 /* table stuff -- end*/
2521 /* just a macro to make some thing easier. */
2522 void LyXText::RedoParagraph() const
2525 // I suspect this version will work
2528 RedoParagraphs(cursor, cursor.par->Next());
2529 SetCursorIntern(cursor.par, cursor.pos);
2531 LyXCursor tmpcursor = cursor;
2533 RedoParagraphs(cursor, cursor.par->Next());
2534 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2539 /* insert a character, moves all the following breaks in the
2540 * same Paragraph one to the right and make a rebreak */
2541 void LyXText::InsertChar(char c)
2543 SetUndo(Undo::INSERT,
2544 cursor.par->ParFromPos(cursor.pos)->previous,
2545 cursor.par->ParFromPos(cursor.pos)->next);
2547 /* When the free-spacing option is set for the current layout,
2548 * disable the double-space checking */
2551 textclasslist.Style(bparams->textclass,
2552 cursor.row->par->GetLayout()).free_spacing;
2554 /* table stuff -- begin*/
2555 if (cursor.par->table) {
2556 InsertCharInTable(c);
2560 /* table stuff -- end*/
2562 /* First check, if there will be two blanks together or a blank at
2563 the beginning of a paragraph.
2564 I decided to handle blanks like normal characters, the main
2565 difference are the special checks when calculating the row.fill
2566 (blank does not count at the end of a row) and the check here */
2568 // The bug is triggered when we type in a description environment:
2569 // The current_font is not changed when we go from label to main text
2570 // and it should (along with realtmpfont) when we type the space.
2571 #ifdef WITH_WARNINGS
2572 #warning There is a bug here! (Asger)
2575 LyXFont realtmpfont = real_current_font;
2576 LyXFont rawtmpfont = current_font; /* store the current font.
2577 * This is because of the use
2578 * of cursor movements. The moving
2579 * cursor would refresh the
2582 // Get the font that is used to calculate the baselineskip
2583 LyXParagraph::size_type lastpos = cursor.par->Last();
2584 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2586 bool jumped_over_space = false;
2588 if (!freeSpacing && IsLineSeparatorChar(c)) {
2589 #ifndef FIX_DOUBLE_SPACE
2590 if (cursor.pos < lastpos
2591 && cursor.par->IsLineSeparator(cursor.pos)) {
2592 /* the user inserted a space before a space. So we
2593 * will just make a CursorRight. BUT: The font of this
2594 * space should be set to current font. That is why
2595 * we need to rebreak perhaps. If there is a protected
2596 * blank at the end of a row we have to force
2599 owner_->owner()->getMiniBuffer()
2600 ->Set(_("You cannot type two spaces this way. "
2601 " Please read the Tutorial."));
2603 // How can this ever happen?
2604 if (cursor.pos == RowLast(cursor.row)
2605 && !IsLineSeparatorChar(c))
2606 cursor.row->fill = -1; // force rebreak
2607 cursor.par->Erase(cursor.pos);
2608 jumped_over_space = true;
2610 // Seems to me that this works just as well.
2618 && cursor.par->IsLineSeparator(cursor.pos - 1))
2620 && cursor.par->IsNewline(cursor.pos - 1))
2622 && !(cursor.par->Previous()
2623 && cursor.par->Previous()->footnoteflag
2624 == LyXParagraph::OPEN_FOOTNOTE))) {
2625 if (cursor.pos == 0 )
2626 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2628 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2632 } else if (IsNewlineChar(c)) {
2633 if (cursor.par->FirstPhysicalPar() == cursor.par
2634 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2638 /* No newline at first position
2639 * of a paragraph or behind labels.
2640 * TeX does not allow that. */
2642 if (cursor.pos < cursor.par->Last() &&
2643 cursor.par->IsLineSeparator(cursor.pos))
2644 CursorRightIntern(); // newline always after a blank!
2645 cursor.row->fill = -1; // to force a new break
2648 // the display inset stuff
2649 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2650 && cursor.row->par->GetInset(cursor.row->pos)
2651 && cursor.row->par->GetInset(cursor.row->pos)->display())
2652 cursor.row->fill = -1; // to force a new break
2654 // get the cursor row fist
2655 Row * row = cursor.row;
2656 long y = cursor.y - row->baseline;
2657 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2658 * already insertet the character */
2659 cursor.par->InsertChar(cursor.pos, c);
2660 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2662 if (!jumped_over_space) {
2663 // refresh the positions
2665 while (tmprow->next && tmprow->next->par == row->par) {
2666 tmprow = tmprow->next;
2671 // Is there a break one row above
2672 if ((cursor.par->IsLineSeparator(cursor.pos)
2673 || cursor.par->IsNewline(cursor.pos)
2674 || cursor.row->fill == -1)
2675 && row->previous && row->previous->par == row->par) {
2676 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2678 if ( z >= row->pos) {
2681 // set the dimensions of the row above
2682 row->previous->fill = Fill(row->previous, paperwidth);
2684 SetHeightOfRow(row->previous);
2686 y -= row->previous->height;
2688 refresh_row = row->previous;
2689 status = LyXText::NEED_MORE_REFRESH;
2691 BreakAgainOneRow(row);
2693 current_font = rawtmpfont;
2694 real_current_font = realtmpfont;
2695 SetCursor(cursor.par, cursor.pos + 1, false);
2696 /* cursor MUST be in row now */
2698 if (row->next && row->next->par == row->par)
2699 need_break_row = row->next;
2703 // check, wether the last characters font has changed.
2704 if (cursor.pos && cursor.pos == cursor.par->Last()
2705 && rawparfont != rawtmpfont)
2706 RedoHeightOfParagraph(cursor);
2713 /* recalculate the fill of the row */
2714 if (row->fill >= 0) /* needed because a newline
2715 * will set fill to -1. Otherwise
2716 * we would not get a rebreak! */
2717 row->fill = Fill(row, paperwidth);
2718 if (row->fill < 0 ) {
2721 refresh_x = cursor.x;
2722 refresh_pos = cursor.pos;
2723 status = LyXText::NEED_MORE_REFRESH;
2724 BreakAgainOneRow(row);
2725 /* will the cursor be in another row now? */
2726 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2727 if (row->next && row->next->par == row->par)
2731 BreakAgainOneRow(row);
2733 current_font = rawtmpfont;
2734 real_current_font = realtmpfont;
2735 SetCursor(cursor.par, cursor.pos + 1, false);
2736 if (row->next && row->next->par == row->par)
2737 need_break_row = row->next;
2742 refresh_x = cursor.x;
2744 refresh_pos = cursor.pos;
2746 int tmpheight = row->height;
2747 SetHeightOfRow(row);
2748 if (tmpheight == row->height)
2749 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2751 status = LyXText::NEED_MORE_REFRESH;
2753 current_font = rawtmpfont;
2754 real_current_font = realtmpfont;
2755 SetCursor(cursor.par, cursor.pos + 1, false);
2758 /* check, wether the last characters font has changed. */
2759 if (cursor.pos && cursor.pos == cursor.par->Last()
2760 && rawparfont != rawtmpfont) {
2761 RedoHeightOfParagraph(cursor);
2763 /* now the special right address boxes */
2764 if (textclasslist.Style(bparams->textclass,
2765 cursor.par->GetLayout()).margintype
2766 == MARGIN_RIGHT_ADDRESS_BOX) {
2767 RedoDrawingOfParagraph(cursor);
2775 void LyXText::charInserted()
2777 // Here we could call FinishUndo for every 20 characters inserted.
2778 // This is from my experience how emacs does it.
2779 static unsigned int counter = 0;
2788 void LyXText::PrepareToPrint(Row * row, float & x,
2789 float & fill_separator,
2791 float & fill_label_hfill,
2796 float w = row->fill;
2798 fill_label_hfill = 0;
2800 fill_label_hfill = 0;
2802 bool is_rtl = row->par->isRightToLeftPar();
2805 x = RightMargin(row);
2806 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2807 LyXFont font(LyXFont::ALL_SANE);
2808 font.setSize(LyXFont::SIZE_SMALL);
2809 x += lyxfont::width("Mwide-figM", font);
2812 x = LeftMargin(row);
2814 /* is there a manual margin with a manual label */
2815 if (textclasslist.Style(bparams->textclass,
2816 row->par->GetLayout()).margintype == MARGIN_MANUAL
2817 && textclasslist.Style(bparams->textclass,
2818 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2820 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2821 * are left aligned*/
2822 if (nlh && !row->par->GetLabelWidthString().empty()) {
2823 fill_label_hfill = LabelFill(row) / nlh;
2827 /* are there any hfills in the row? */
2828 nh = NumberOfHfills(row);
2830 /* table stuff -- begin*/
2831 if (row->par->table) {
2832 w = paperwidth - row->par->table->WidthOfTable()
2833 - x - RightMargin(row);
2834 nh = 0; /* ignore hfills in tables */
2836 /* table stuff -- end*/
2841 /* is it block, flushleft or flushright?
2842 * set x how you need it */
2844 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2845 align = textclasslist.Style(bparams->textclass, row->par->GetLayout()).align;
2847 align = row->par->FirstPhysicalPar()->align;
2849 /* center displayed insets */
2850 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2851 && row->par->GetInset(row->pos)
2852 && row->par->GetInset(row->pos)->display())
2853 align = LYX_ALIGN_CENTER;
2856 case LYX_ALIGN_BLOCK:
2857 ns = NumberOfSeparators(row);
2858 if (ns && row->next && row->next->par == row->par &&
2859 !(row->next->par->IsNewline(row->next->pos-1))
2860 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2861 && row->next->par->GetInset(row->next->pos)
2862 && row->next->par->GetInset(row->next->pos)->display())
2864 fill_separator = w / ns;
2868 case LYX_ALIGN_RIGHT:
2871 case LYX_ALIGN_CENTER:
2879 ComputeBidiTables(row);
2881 LyXParagraph::size_type main_body =
2882 BeginningOfMainBody(row->par);
2883 LyXParagraph::size_type last = RowLast(row);
2885 if (main_body > 0 &&
2886 (main_body-1 > last ||
2887 !row->par->IsLineSeparator(main_body-1))) {
2888 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
2889 row->par->GetLayout());
2890 x += lyxfont::width(layout.labelsep,
2891 GetFont(row->par, -2));
2892 if (main_body-1 <= last)
2893 x += fill_label_hfill;
2898 /* important for the screen */
2901 /* the cursor set functions have a special mechanism. When they
2902 * realize, that you left an empty paragraph, they will delete it.
2903 * They also delete the corresponding row */
2905 void LyXText::CursorRightOneWord() const
2907 // treat floats, HFills and Insets as words
2908 LyXCursor tmpcursor = cursor;
2909 #warning See comment on top of text.C
2911 if (tmpcursor.pos == tmpcursor.par->Last()
2912 && tmpcursor.par->Next())
2914 tmpcursor.par = tmpcursor.par->Next();
2919 // Skip through initial nonword stuff.
2920 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2921 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2923 // printf("Current pos1 %d", tmpcursor.pos) ;
2927 // Advance through word.
2928 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2929 tmpcursor.par->IsWord( tmpcursor.pos ) )
2931 // printf("Current pos2 %d", tmpcursor.pos) ;
2936 SetCursor(tmpcursor.par, tmpcursor.pos);
2940 void LyXText::CursorTab() const
2942 if (cursor.par->table) {
2943 int cell = NumberOfCell(cursor.par, cursor.pos);
2944 while(cursor.par->table->IsContRow(cell)) {
2946 cell = NumberOfCell(cursor.par, cursor.pos);
2948 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2949 TableFeatures(LyXTable::APPEND_ROW);
2951 LyXCursor tmpcursor = cursor;
2952 while (tmpcursor.pos < tmpcursor.par->Last()
2953 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2956 if (tmpcursor.pos == tmpcursor.par->Last()){
2957 if (tmpcursor.par->Next()) {
2958 tmpcursor.par = tmpcursor.par->Next();
2964 SetCursor(tmpcursor.par, tmpcursor.pos);
2965 if (cursor.par->table) {
2966 int cell = NumberOfCell(cursor.par, cursor.pos);
2967 while (cursor.par->table->IsContRow(cell) &&
2968 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2970 while (tmpcursor.pos < tmpcursor.par->Last()
2971 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2974 if (tmpcursor.pos == tmpcursor.par->Last()){
2975 if (tmpcursor.par->Next()) {
2976 tmpcursor.par = tmpcursor.par->Next();
2982 SetCursor(tmpcursor.par, tmpcursor.pos);
2983 cell = NumberOfCell(cursor.par, cursor.pos);
2989 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2990 of prior word, not to end of next prior word. */
2992 void LyXText::CursorLeftOneWord() const
2994 // treat HFills, floats and Insets as words
2995 LyXCursor tmpcursor = cursor;
2996 while (tmpcursor.pos
2997 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2998 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2999 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
3000 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3001 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
3005 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
3006 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3007 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
3009 } else if (!tmpcursor.pos) {
3010 if (tmpcursor.par->Previous()){
3011 tmpcursor.par = tmpcursor.par->Previous();
3012 tmpcursor.pos = tmpcursor.par->Last();
3014 } else { // Here, tmpcursor != 0
3015 while (tmpcursor.pos > 0 &&
3016 tmpcursor.par->IsWord(tmpcursor.pos-1) )
3019 SetCursor(tmpcursor.par, tmpcursor.pos);
3022 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3025 void LyXText::SelectWord()
3027 /* Move cursor to the beginning, when not already there. */
3029 && !cursor.par->IsSeparator(cursor.pos-1)
3030 && !cursor.par->IsKomma(cursor.pos-1) )
3031 CursorLeftOneWord();
3033 /* set the sel cursor */
3034 sel_cursor = cursor;
3036 while ( cursor.pos < cursor.par->Last()
3037 && !cursor.par->IsSeparator(cursor.pos)
3038 && !cursor.par->IsKomma(cursor.pos) )
3040 SetCursor( cursor.par, cursor.pos );
3042 /* finally set the selection */
3047 /* -------> Select the word currently under the cursor when:
3048 1: no selection is currently set,
3049 2: the cursor is not at the borders of the word. */
3051 int LyXText::SelectWordWhenUnderCursor()
3053 if ( selection ) return 0;
3054 if ( cursor.pos < cursor.par->Last()
3055 && !cursor.par->IsSeparator(cursor.pos)
3056 && !cursor.par->IsKomma(cursor.pos)
3058 && !cursor.par->IsSeparator(cursor.pos -1)
3059 && !cursor.par->IsKomma(cursor.pos -1) ) {
3067 // This function is only used by the spellchecker for NextWord().
3068 // It doesn't handle LYX_ACCENTs and probably never will.
3069 char * LyXText::SelectNextWord(float & value)
3071 LyXParagraph * tmppar = cursor.par;
3073 // If this is not the very first word, skip rest of
3074 // current word because we are probably in the middle
3075 // of a word if there is text here.
3076 if (cursor.pos || cursor.par->previous) {
3077 while (cursor.pos < cursor.par->Last()
3078 && cursor.par->IsLetter(cursor.pos))
3081 // Now, skip until we have real text (will jump paragraphs)
3082 while ((cursor.par->Last() > cursor.pos
3083 && (!cursor.par->IsLetter(cursor.pos)
3084 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
3085 || (cursor.par->Last() == cursor.pos
3086 && cursor.par->Next())){
3087 if (cursor.pos == cursor.par->Last()) {
3088 cursor.par = cursor.par->Next();
3095 // Update the value if we changed paragraphs
3096 if (cursor.par != tmppar){
3097 SetCursor(cursor.par, cursor.pos);
3098 value = float(cursor.y)/float(height);
3101 /* Start the selection from here */
3102 sel_cursor = cursor;
3105 std::ostringstream latex;
3109 /* and find the end of the word
3110 (optional hyphens are part of a word) */
3111 while (cursor.pos < cursor.par->Last()
3112 && (cursor.par->IsLetter(cursor.pos))
3113 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3114 && cursor.par->GetInset(cursor.pos) != 0
3115 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
3117 && latex.str() == "\\-"
3119 && string(latex.str(), 3) == "\\-" // this is not nice at all
3124 #ifndef HAVE_SSTREAM
3125 delete [] latex.str();
3127 // Finally, we copy the word to a string and return it
3130 if (sel_cursor.pos < cursor.pos) {
3131 str = new char [cursor.pos - sel_cursor.pos + 2];
3132 LyXParagraph::size_type i, j;
3133 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3134 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3135 str[j++] = cursor.par->GetChar(i);
3143 // This one is also only for the spellchecker
3144 void LyXText::SelectSelectedWord()
3146 /* move cursor to the beginning */
3147 SetCursor(sel_cursor.par, sel_cursor.pos);
3149 /* set the sel cursor */
3150 sel_cursor = cursor;
3153 std::ostringstream latex;
3158 /* now find the end of the word */
3159 while (cursor.pos < cursor.par->Last()
3160 && (cursor.par->IsLetter(cursor.pos)
3161 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3162 && cursor.par->GetInset(cursor.pos) != 0
3163 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
3165 && latex.str() == "\\-"
3167 && string(latex.str(), 3) == "\\-"
3172 #ifndef HAVE_SSTREAM
3173 delete [] latex.str();
3175 SetCursor(cursor.par, cursor.pos);
3177 /* finally set the selection */
3182 /* -------> Delete from cursor up to the end of the current or next word. */
3183 void LyXText::DeleteWordForward()
3185 LyXCursor tmpcursor = cursor;
3187 if (!cursor.par->Last())
3189 #warning See comment on top of text.C
3191 /* -------> Skip initial non-word stuff. */
3192 while ( cursor.pos < cursor.par->Last()
3193 && (cursor.par->IsSeparator(cursor.pos)
3194 || cursor.par->IsKomma(cursor.pos)) )
3197 SetCursorIntern(cursor.par, cursor.pos);
3198 selection = True; // to avoid deletion
3199 CursorRightOneWord();
3200 sel_cursor = cursor;
3204 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3210 /* -------> Delete from cursor to start of current or prior word. */
3211 void LyXText::DeleteWordBackward()
3213 LyXCursor tmpcursor = cursor;
3214 if (!cursor.par->Last())
3216 #warning See comment on top of text.C
3218 selection = true; // to avoid deletion
3219 CursorLeftOneWord();
3220 sel_cursor = cursor;
3228 /* -------> Kill to end of line. */
3229 void LyXText::DeleteLineForward()
3231 LyXCursor tmpcursor = cursor;
3232 if (!cursor.par->Last())
3234 #warning See comment on top of text.C
3237 sel_cursor = cursor;
3240 if (selection == false) {
3241 DeleteWordForward();
3249 // Change the case of a word at cursor position. The meaning of action
3251 // 0 change to lowercase
3252 // 1 capitalize word
3253 // 2 change to uppercase
3254 // This function directly manipulates LyXParagraph::text because there
3255 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3256 // that it is correct. I guess part of it should be moved to
3257 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3258 // it does not access outside of the allocated array as the older
3259 // version did. (JMarc)
3260 void LyXText::ChangeWordCase(LyXText::TextCase action)
3262 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3264 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3266 LyXParagraph::size_type tmppos =
3267 cursor.par->PositionInParFromPos(cursor.pos);
3268 while (tmppos < tmppar->size()) {
3269 //unsigned char c = tmppar->text[tmppos];
3270 unsigned char c = tmppar->GetChar(tmppos);
3271 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3273 if (c != LyXParagraph::META_INSET) {
3275 case text_lowercase:
3278 case text_capitalization:
3280 action = text_lowercase;
3282 case text_uppercase:
3288 //tmppar->text[tmppos] = c;
3289 tmppar->SetChar(tmppos, c);
3292 CheckParagraph(tmppar, tmppos);
3293 CursorRightOneWord();
3297 void LyXText::Delete()
3299 // this is a very easy implementation
3301 LyXCursor old_cursor = cursor;
3302 int old_cur_par_id = old_cursor.par->id();
3303 int old_cur_par_prev_id = old_cursor.par->previous ?
3304 old_cursor.par->previous->id() : 0;
3306 // just move to the right
3307 CursorRightIntern();
3309 #warning Look at the comment here.
3310 // This check is not very good...
3311 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3312 // and that can very well delete the par or par->previous in
3313 // old_cursor. Will a solution where we compare paragraph id's
3316 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3317 == old_cur_par_prev_id
3318 && cursor.par->id() != old_cur_par_id)
3319 return; // delete-empty-paragraph-mechanism has done it
3321 if (cursor.par->previous == old_cursor.par->previous
3322 && cursor.par != old_cursor.par)
3323 return; // delete-empty-paragraph-mechanism has done it
3325 // if you had success make a backspace
3326 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3327 LyXCursor tmpcursor = cursor;
3328 cursor = old_cursor; // to make sure undo gets the right cursor position
3329 SetUndo(Undo::DELETE,
3330 cursor.par->ParFromPos(cursor.pos)->previous,
3331 cursor.par->ParFromPos(cursor.pos)->next);
3338 void LyXText::Backspace()
3340 /* table stuff -- begin */
3341 if (cursor.par->table) {
3345 /* table stuff -- end */
3347 LyXFont rawtmpfont = current_font;
3348 LyXFont realtmpfont = real_current_font;
3350 // Get the font that is used to calculate the baselineskip
3351 int const lastpos = cursor.par->Last();
3352 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3354 if (cursor.pos == 0) {
3355 // The cursor is at the beginning of a paragraph, so the the backspace
3356 // will collapse two paragraphs into one.
3358 // we may paste some paragraphs
3360 // is it an empty paragraph?
3363 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3364 && !(cursor.par->Next()
3365 && cursor.par->footnoteflag == LyXParagraph::NO_FOOTNOTE
3366 && cursor.par->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3367 // This is an empty paragraph and we delete it just by moving the cursor one step
3368 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3369 // of the paragraph.
3371 if (cursor.par->previous) {
3372 LyXParagraph * tmppar = cursor.par->previous->FirstPhysicalPar();
3373 if (cursor.par->GetLayout() == tmppar->GetLayout()
3374 && cursor.par->footnoteflag == tmppar->footnoteflag
3375 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3376 // Inherit botom DTD from the paragraph below.
3377 // (the one we are deleting)
3378 tmppar->line_bottom = cursor.par->line_bottom;
3379 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3380 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3385 // the layout things can change the height of a row !
3386 int tmpheight = cursor.row->height;
3387 SetHeightOfRow(cursor.row);
3388 if (cursor.row->height != tmpheight) {
3389 refresh_y = cursor.y - cursor.row->baseline;
3390 refresh_row = cursor.row;
3391 status = LyXText::NEED_MORE_REFRESH;
3397 if (cursor.par->ParFromPos(cursor.pos)->previous){
3398 SetUndo(Undo::DELETE,
3399 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3400 cursor.par->ParFromPos(cursor.pos)->next);
3403 LyXParagraph * tmppar = cursor.par;
3404 Row * tmprow = cursor.row;
3406 // We used to do CursorLeftIntern() here, but it is
3407 // not a good idea since it triggers the auto-delete
3408 // mechanism. So we do a CursorLeftIntern()-lite,
3409 // without the dreaded mechanism. (JMarc)
3410 if (cursor.par->Previous()) {
3411 // steps into the above paragraph.
3412 SetCursorIntern(cursor.par->Previous(),
3413 cursor.par->Previous()->Last());
3416 /* Pasting is not allowed, if the paragraphs have different
3417 layout. I think it is a real bug of all other
3418 word processors to allow it. It confuses the user.
3419 Even so with a footnote paragraph and a non-footnote
3420 paragraph. I will not allow pasting in this case,
3421 because the user would be confused if the footnote behaves
3422 different wether it is open or closed.
3424 Correction: Pasting is always allowed with standard-layout
3426 if (cursor.par != tmppar
3427 && (cursor.par->GetLayout() == tmppar->GetLayout()
3428 || tmppar->GetLayout() == 0 /*standard*/)
3429 && cursor.par->footnoteflag == tmppar->footnoteflag
3430 /* table stuff -- begin*/
3431 && !cursor.par->table /* no pasting of tables */
3432 /* table stuff -- end*/
3433 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3435 RemoveParagraph(tmprow);
3437 cursor.par->PasteParagraph();
3439 if (!cursor.pos || !cursor.par->IsSeparator(cursor.pos - 1))
3440 ; //cursor.par->InsertChar(cursor.pos, ' ');
3441 // strangely enough it seems that commenting out the line above removes
3442 // most or all of the segfaults. I will however also try to move the
3443 // two Remove... lines in front of the PasteParagraph too.
3448 status = LyXText::NEED_MORE_REFRESH;
3449 refresh_row = cursor.row;
3450 refresh_y = cursor.y - cursor.row->baseline;
3452 // remove the lost paragraph
3453 // This one is not safe, since the paragraph that the tmprow and the
3454 // following rows belong to has been deleted by the PasteParagraph
3455 // above. The question is... could this be moved in front of the
3457 //RemoveParagraph(tmprow);
3458 //RemoveRow(tmprow);
3460 AppendParagraph(cursor.row); // This rebuilds the rows.
3461 UpdateCounters(cursor.row);
3463 // the row may have changed, block, hfills etc.
3464 SetCursor(cursor.par, cursor.pos);
3467 /* this is the code for a normal backspace, not pasting
3469 SetUndo(Undo::DELETE,
3470 cursor.par->ParFromPos(cursor.pos)->previous,
3471 cursor.par->ParFromPos(cursor.pos)->next);
3472 // We used to do CursorLeftIntern() here, but it is
3473 // not a good idea since it triggers the auto-delete
3474 // mechanism. So we do a CursorLeftIntern()-lite,
3475 // without the dreaded mechanism. (JMarc)
3476 SetCursorIntern(cursor.par, cursor.pos - 1);
3478 // some insets are undeletable here
3479 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3480 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3482 // force complete redo when erasing display insets
3483 // this is a cruel method but safe..... Matthias
3484 if (cursor.par->GetInset(cursor.pos)->display()){
3485 cursor.par->Erase(cursor.pos);
3491 Row * row = cursor.row;
3492 long y = cursor.y - row->baseline;
3493 LyXParagraph::size_type z;
3494 /* remember that a space at the end of a row doesnt count
3495 * when calculating the fill */
3496 if (cursor.pos < RowLast(row) ||
3497 !cursor.par->IsLineSeparator(cursor.pos)) {
3498 row->fill += SingleWidth(cursor.par, cursor.pos);
3501 /* some special code when deleting a newline. This is similar
3502 * to the behavior when pasting paragraphs */
3503 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3504 cursor.par->Erase(cursor.pos);
3505 // refresh the positions
3507 while (tmprow->next && tmprow->next->par == row->par) {
3508 tmprow = tmprow->next;
3511 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3514 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3515 cursor.par->InsertChar(cursor.pos, ' ');
3516 // refresh the positions
3518 while (tmprow->next && tmprow->next->par == row->par) {
3519 tmprow = tmprow->next;
3524 cursor.par->Erase(cursor.pos);
3526 // refresh the positions
3528 while (tmprow->next && tmprow->next->par == row->par) {
3529 tmprow = tmprow->next;
3533 #ifndef FIX_DOUBLE_SPACE
3534 // delete superfluous blanks
3535 if (cursor.pos < cursor.par->Last() - 1 &&
3536 (cursor.par->IsLineSeparator(cursor.pos))) {
3538 if (cursor.pos == BeginningOfMainBody(cursor.par)
3540 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3541 cursor.par->Erase(cursor.pos);
3542 // refresh the positions
3544 while (tmprow->next &&
3545 tmprow->next->par == row->par) {
3546 tmprow = tmprow->next;
3549 if (cursor.pos) // move one character left
3555 // delete newlines at the beginning of paragraphs
3556 while (cursor.par->Last() &&
3557 cursor.par->IsNewline(cursor.pos) &&
3558 cursor.pos == BeginningOfMainBody(cursor.par)) {
3559 cursor.par->Erase(cursor.pos);
3560 // refresh the positions
3562 while (tmprow->next &&
3563 tmprow->next->par == row->par) {
3564 tmprow = tmprow->next;
3570 // is there a break one row above
3571 if (row->previous && row->previous->par == row->par) {
3572 z = NextBreakPoint(row->previous, paperwidth);
3573 if ( z >= row->pos) {
3576 Row * tmprow = row->previous;
3578 // maybe the current row is now empty
3579 if (row->pos >= row->par->Last()) {
3584 BreakAgainOneRow(row);
3585 if (row->next && row->next->par == row->par)
3586 need_break_row = row->next;
3591 // set the dimensions of the row above
3592 y -= tmprow->height;
3593 tmprow->fill = Fill(tmprow, paperwidth);
3594 SetHeightOfRow(tmprow);
3597 refresh_row = tmprow;
3598 status = LyXText::NEED_MORE_REFRESH;
3599 current_font = rawtmpfont;
3600 real_current_font = realtmpfont;
3601 SetCursor(cursor.par, cursor.pos, false);
3602 // check, whether the last character's font has changed.
3603 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3604 if (rawparfont != rawtmpfont)
3605 RedoHeightOfParagraph(cursor);
3610 // break the cursor row again
3611 z = NextBreakPoint(row, paperwidth);
3613 if (z != RowLast(row) ||
3614 (row->next && row->next->par == row->par &&
3615 RowLast(row) == row->par->Last() - 1)){
3617 /* it can happen that a paragraph loses one row
3618 * without a real breakup. This is when a word
3619 * is to long to be broken. Well, I don t care this
3621 if (row->next && row->next->par == row->par &&
3622 RowLast(row) == row->par->Last() - 1)
3623 RemoveRow(row->next);
3627 status = LyXText::NEED_MORE_REFRESH;
3629 BreakAgainOneRow(row);
3630 current_font = rawtmpfont;
3631 real_current_font = realtmpfont;
3632 SetCursor(cursor.par, cursor.pos, false);
3633 // cursor MUST be in row now
3635 if (row->next && row->next->par == row->par)
3636 need_break_row = row->next;
3640 // set the dimensions of the row
3641 row->fill = Fill(row, paperwidth);
3642 int tmpheight = row->height;
3643 SetHeightOfRow(row);
3644 if (tmpheight == row->height)
3645 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3647 status = LyXText::NEED_MORE_REFRESH;
3650 current_font = rawtmpfont;
3651 real_current_font = realtmpfont;
3652 SetCursor(cursor.par, cursor.pos, false);
3655 // restore the current font
3656 // That is what a user expects!
3657 current_font = rawtmpfont;
3658 real_current_font = realtmpfont;
3660 // check, wether the last characters font has changed.
3661 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3662 if (rawparfont != rawtmpfont) {
3663 RedoHeightOfParagraph(cursor);
3665 // now the special right address boxes
3666 if (textclasslist.Style(bparams->textclass,
3667 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3668 RedoDrawingOfParagraph(cursor);
3674 void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y)
3676 /* returns a printed row */
3677 Painter & pain = owner_->painter();
3679 bool is_rtl = row_ptr->par->isRightToLeftPar();
3680 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3682 LyXParagraph::size_type vpos, pos;
3684 int y_top, y_bottom;
3685 float fill_separator, fill_hfill, fill_label_hfill;
3686 LyXParagraph * par, * firstpar;
3689 if (row_ptr->height <= 0) {
3690 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3693 PrepareToPrint(row_ptr, x, fill_separator,
3694 fill_hfill, fill_label_hfill);
3696 /* initialize the pixmap */
3698 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3701 /* selection code */
3702 if (bidi_same_direction) {
3703 if (sel_start_cursor.row == row_ptr &&
3704 sel_end_cursor.row == row_ptr) {
3705 if (sel_start_cursor.x < sel_end_cursor.x)
3706 pain.fillRectangle(sel_start_cursor.x, offset,
3707 sel_end_cursor.x - sel_start_cursor.x,
3711 pain.fillRectangle(sel_end_cursor.x, offset,
3712 sel_start_cursor.x - sel_end_cursor.x,
3715 } else if (sel_start_cursor.row == row_ptr) {
3717 pain.fillRectangle(0, offset,
3722 pain.fillRectangle(sel_start_cursor.x, offset,
3723 paperwidth - sel_start_cursor.x,
3726 } else if (sel_end_cursor.row == row_ptr) {
3728 pain.fillRectangle(sel_end_cursor.x, offset,
3729 paperwidth - sel_end_cursor.x,
3733 pain.fillRectangle(0, offset,
3737 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3738 pain.fillRectangle(0, offset,
3739 paperwidth, row_ptr->height,
3742 } else if ( sel_start_cursor.row != row_ptr &&
3743 sel_end_cursor.row != row_ptr &&
3744 y > sel_start_cursor.y && y < sel_end_cursor.y) {
3745 pain.fillRectangle(0, offset,
3746 paperwidth, row_ptr->height,
3748 } else if (sel_start_cursor.row == row_ptr ||
3749 sel_end_cursor.row == row_ptr) {
3752 if (row_ptr->par->table) {
3753 cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3754 tmpx += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3756 if ( (sel_start_cursor.row != row_ptr && !is_rtl) ||
3757 (sel_end_cursor.row != row_ptr && is_rtl))
3758 pain.fillRectangle(0, offset,
3759 tmpx, row_ptr->height,
3761 if (row_ptr->par->table) {
3763 for (vpos = row_ptr->pos; vpos <= last; ++vpos) {
3764 pos = vis2log(vpos);
3765 float old_tmpx = tmpx;
3766 if (row_ptr->par->IsNewline(pos)) {
3767 tmpx = x_old + row_ptr->par->table->WidthOfColumn(cell);
3770 tmpx += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3772 tmpx += SingleWidth(row_ptr->par, pos);
3774 if ( (sel_start_cursor.row != row_ptr ||
3775 sel_start_cursor.pos <= pos) &&
3776 (sel_end_cursor.row != row_ptr ||
3777 pos < sel_end_cursor.pos) )
3778 pain.fillRectangle(old_tmpx, offset,
3779 tmpx - old_tmpx + 1,
3784 LyXParagraph::size_type main_body =
3785 BeginningOfMainBody(row_ptr->par);
3787 for (vpos = row_ptr->pos; vpos <= last; ++vpos) {
3788 pos = vis2log(vpos);
3789 float old_tmpx = tmpx;
3790 if (main_body > 0 && pos == main_body-1) {
3791 tmpx += fill_label_hfill +
3792 lyxfont::width(textclasslist.Style(bparams->textclass,
3793 row_ptr->par->GetLayout()).labelsep,
3794 GetFont(row_ptr->par, -2));
3795 if (row_ptr->par->IsLineSeparator(main_body-1))
3796 tmpx -= SingleWidth(row_ptr->par, main_body-1);
3798 if (HfillExpansion(row_ptr, pos)) {
3799 tmpx += SingleWidth(row_ptr->par, pos);
3800 if (pos >= main_body)
3803 tmpx += fill_label_hfill;
3805 else if (row_ptr->par->IsSeparator(pos)) {
3806 tmpx += SingleWidth(row_ptr->par, pos);
3807 if (pos >= main_body)
3808 tmpx += fill_separator;
3810 tmpx += SingleWidth(row_ptr->par, pos);
3812 if ( (sel_start_cursor.row != row_ptr ||
3813 sel_start_cursor.pos <= pos) &&
3814 (sel_end_cursor.row != row_ptr ||
3815 pos < sel_end_cursor.pos) )
3816 pain.fillRectangle(old_tmpx, offset,
3817 tmpx - old_tmpx + 1,
3822 if ( (sel_start_cursor.row != row_ptr && is_rtl) ||
3823 (sel_end_cursor.row != row_ptr && !is_rtl) )
3824 pain.fillRectangle(tmpx, offset,
3831 if (row_ptr->par->appendix){
3832 pain.line(1, offset,
3833 1, offset + row_ptr->height,
3834 LColor::appendixline);
3835 pain.line(paperwidth - 2, offset,
3836 paperwidth - 2, offset + row_ptr->height,
3837 LColor::appendixline);
3840 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3841 /* draw a marker at the left margin! */
3842 LyXFont font = GetFont(row_ptr->par, 0);
3843 int asc = lyxfont::maxAscent(font);
3844 int x = (LYX_PAPER_MARGIN - lyxfont::width('|', font)) / 2;
3845 int y1 = (offset + row_ptr->baseline);
3846 int y2 = (offset + row_ptr->baseline) - asc;
3847 pain.line(x, y1, x, y2, LColor::minipageline);
3849 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3850 LyXFont font(LyXFont::ALL_SANE);
3851 font.setSize(LyXFont::SIZE_FOOTNOTE);
3852 font.setColor(LColor::footnote);
3854 int box_x = LYX_PAPER_MARGIN;
3855 box_x += lyxfont::width(" wide-tab ", font);
3856 if (row_ptr->previous &&
3857 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3859 switch (row_ptr->par->footnotekind) {
3860 case LyXParagraph::MARGIN:
3863 case LyXParagraph::FIG:
3866 case LyXParagraph::TAB:
3869 case LyXParagraph::WIDE_FIG:
3872 case LyXParagraph::WIDE_TAB:
3875 case LyXParagraph::ALGORITHM:
3878 case LyXParagraph::FOOTNOTE:
3883 pain.fillRectangle(LYX_PAPER_MARGIN,
3885 box_x - LYX_PAPER_MARGIN,
3886 int(lyxfont::maxAscent(font)
3887 + lyxfont::maxDescent(font)),
3888 LColor::footnotebg);
3890 pain.line(LYX_PAPER_MARGIN, offset,
3891 paperwidth - LYX_PAPER_MARGIN, offset,
3892 LColor::footnoteframe);
3894 pain.text(LYX_PAPER_MARGIN,
3895 offset + int(lyxfont::maxAscent(font)) + 1,
3898 pain.line(LYX_PAPER_MARGIN, offset,
3900 offset + int(lyxfont::maxAscent(font)
3901 + lyxfont::maxDescent(font)),
3902 LColor::footnoteframe);
3904 pain.line(LYX_PAPER_MARGIN,
3905 offset + int(lyxfont::maxAscent(font)
3906 + lyxfont::maxDescent(font)) + 1,
3908 offset + int(lyxfont::maxAscent(font)
3909 + lyxfont::maxDescent(font)) + 1,
3910 LColor::footnoteframe);
3914 /* draw the open floats in a red box */
3915 pain.line(box_x, offset,
3916 box_x, offset + row_ptr->height,
3917 LColor::footnoteframe);
3919 pain.line(paperwidth - LYX_PAPER_MARGIN,
3921 paperwidth - LYX_PAPER_MARGIN,
3922 offset + row_ptr->height,
3923 LColor::footnoteframe);
3924 } else if (row_ptr->previous &&
3925 row_ptr->previous->par->footnoteflag
3926 == LyXParagraph::OPEN_FOOTNOTE) {
3927 LyXFont font(LyXFont::ALL_SANE);
3928 font.setSize(LyXFont::SIZE_FOOTNOTE);
3930 int box_x = LYX_PAPER_MARGIN;
3931 box_x += lyxfont::width(" wide-tab ", font);
3933 pain.line(box_x, offset,
3934 paperwidth - LYX_PAPER_MARGIN,
3935 offset, LColor::footnote);
3938 LyXLayout const & layout =
3939 textclasslist.Style(bparams->textclass,
3940 row_ptr->par->GetLayout());
3941 firstpar = row_ptr->par->FirstPhysicalPar();
3944 y_bottom = row_ptr->height;
3946 /* is it a first row? */
3947 if (row_ptr->pos == 0
3948 && row_ptr->par == firstpar) {
3950 /* start of appendix? */
3951 if (row_ptr->par->start_of_appendix){
3952 pain.line(1, offset,
3953 paperwidth - 2, offset,
3954 LColor::appendixline);
3957 /* think about the margins */
3958 if (!row_ptr->previous)
3959 y_top += LYX_PAPER_MARGIN;
3961 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3963 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3965 offset + y_top + 2 * DefaultHeight(),
3966 LColor::pagebreak, Painter::line_onoffdash);
3969 pb_font.setColor(LColor::pagebreak).decSize();
3970 int w = 0, a = 0, d = 0;
3971 pain.line(0, offset + y_top + 2*DefaultHeight(),
3973 offset + y_top + 2*DefaultHeight(),
3975 Painter::line_onoffdash)
3978 _("Page Break (top)"),
3981 LColor::background, false, w, a, d);
3982 pain.rectText((paperwidth - w)/2,
3983 offset +y_top + 2*DefaultHeight() +d,
3984 _("Page Break (top)"),
3987 LColor::background);
3989 y_top += 3 * DefaultHeight();
3992 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3993 /* draw a vfill top */
3994 pain.line(0, offset + 2 + y_top,
3995 LYX_PAPER_MARGIN, offset + 2 + y_top,
3998 pain.line(0, offset + y_top + 3 * DefaultHeight(),
4000 offset + y_top + 3 * DefaultHeight(),
4003 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
4004 LYX_PAPER_MARGIN / 2,
4005 offset + y_top + 3 * DefaultHeight(),
4008 y_top += 3 * DefaultHeight();
4011 /* think about user added space */
4012 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
4014 /* think about the parskip */
4015 /* some parskips VERY EASY IMPLEMENTATION */
4016 if (bparams->paragraph_separation == BufferParams::PARSEP_SKIP) {
4017 if (layout.latextype == LATEX_PARAGRAPH
4018 && firstpar->GetDepth() == 0
4019 && firstpar->Previous())
4020 y_top += bparams->getDefSkip().inPixels(owner_);
4021 else if (firstpar->Previous()
4022 && textclasslist.Style(bparams->textclass,
4023 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4024 && firstpar->Previous()->GetDepth() == 0)
4025 // is it right to use defskip here, too? (AS)
4026 y_top += bparams->getDefSkip().inPixels(owner_);
4029 if (row_ptr->par->line_top) { /* draw a top line */
4030 y_top += lyxfont::ascent('x', GetFont(row_ptr->par, 0));
4032 pain.line(0, offset + y_top,
4033 paperwidth, offset + y_top,
4035 Painter::line_solid,
4036 Painter::line_thick);
4038 y_top += lyxfont::ascent('x', GetFont(row_ptr->par, 0));
4041 /* should we print a label? */
4042 if (layout.labeltype >= LABEL_STATIC
4043 && (layout.labeltype != LABEL_STATIC
4044 || layout.latextype != LATEX_ENVIRONMENT
4045 || row_ptr->par->IsFirstInSequence())) {
4046 font = GetFont(row_ptr->par, -2);
4047 if (!row_ptr->par->GetLabelstring().empty()) {
4049 string tmpstring = row_ptr->par->GetLabelstring();
4051 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4052 if (bparams->secnumdepth >= 0){
4053 /* this is special code for the chapter layout. This is printed in
4054 * an extra row and has a pagebreak at the top. */
4055 float spacing_val = 1.0;
4056 if (!row_ptr->par->spacing.isDefault()) {
4057 spacing_val = row_ptr->par->spacing.getValue();
4059 spacing_val = bparams->spacing.getValue();
4062 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4063 + int(layout.parsep) * DefaultHeight();
4065 tmpx = paperwidth - LeftMargin(row_ptr) -
4066 lyxfont::width(tmpstring, font);
4067 pain.text(int(tmpx),
4068 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
4073 tmpx = paperwidth - LeftMargin(row_ptr)
4074 + lyxfont::width(layout.labelsep, font);
4075 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4076 LyXFont font(LyXFont::ALL_SANE);
4077 font.setSize(LyXFont::SIZE_SMALL);
4078 tmpx += lyxfont::width("Mwide-fixM", font);
4081 tmpx = x - lyxfont::width(layout.labelsep, font)
4082 - lyxfont::width(tmpstring, font);
4085 pain.text(int(tmpx),
4086 offset + row_ptr->baseline,
4090 /* the labels at the top of an environment. More or less for bibliography */
4091 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4092 layout.labeltype == LABEL_BIBLIO ||
4093 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4094 if (row_ptr->par->IsFirstInSequence()) {
4095 font = GetFont(row_ptr->par, -2);
4096 if (!row_ptr->par->GetLabelstring().empty()) {
4097 string tmpstring = row_ptr->par->GetLabelstring();
4098 float spacing_val = 1.0;
4099 if (!row_ptr->par->spacing.isDefault()) {
4100 spacing_val = row_ptr->par->spacing.getValue();
4102 spacing_val = bparams->spacing.getValue();
4105 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4106 + (layout.labelbottomsep * DefaultHeight()));
4109 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4110 tmpx = ( (is_rtl ? LeftMargin(row_ptr) : x)
4111 + paperwidth - RightMargin(row_ptr) ) / 2;
4112 tmpx -= lyxfont::width(tmpstring, font) / 2;
4114 tmpx = paperwidth - LeftMargin(row_ptr) -
4115 lyxfont::width(tmpstring, font);
4116 pain.text(int(tmpx),
4117 offset + row_ptr->baseline
4118 - row_ptr->ascent_of_text
4124 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
4125 font = GetFont(row_ptr->par, -1);
4127 tmpx = paperwidth - LeftMargin(row_ptr)
4128 + lyxfont::width(layout.labelsep, font);
4130 tmpx = x - lyxfont::width(layout.labelsep, font)
4131 - row_ptr->par->bibkey->width(owner_->painter(), font);
4132 row_ptr->par->bibkey->draw(pain,
4134 offset + row_ptr->baseline,
4139 /* is it a last row? */
4140 par = row_ptr->par->LastPhysicalPar();
4141 if (row_ptr->par->ParFromPos(last + 1) == par
4142 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
4144 /* think about the margins */
4146 y_bottom -= LYX_PAPER_MARGIN;
4148 /* draw a bottom pagebreak */
4149 if (firstpar->pagebreak_bottom) {
4151 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
4153 offset + y_bottom - 2 * DefaultHeight(),
4154 LColor::pagebreak, Painter::line_onoffdash);
4157 pb_font.setColor(LColor::pagebreak).decSize();
4158 int w = 0, a = 0, d = 0;
4160 offset + y_bottom - 2 * DefaultHeight(),
4162 offset + y_bottom - 2 * DefaultHeight(),
4164 Painter::line_onoffdash)
4167 _("Page Break (bottom)"),
4170 LColor::background, false, w, a, d);
4171 pain.rectText((paperwidth - w)/2,
4172 offset +y_top + 2*DefaultHeight() +d,
4173 _("Page Break (bottom)"),
4176 LColor::background);
4178 y_bottom -= 3 * DefaultHeight();
4181 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4182 /* draw a vfill bottom */
4183 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
4185 offset + y_bottom - 3 * DefaultHeight(),
4187 pain.line(0, offset + y_bottom - 2,
4189 offset + y_bottom - 2,
4191 pain.line(LYX_PAPER_MARGIN / 2,
4192 offset + y_bottom - 3 * DefaultHeight(),
4193 LYX_PAPER_MARGIN / 2,
4194 offset + y_bottom - 2,
4196 y_bottom -= 3* DefaultHeight();
4199 /* think about user added space */
4200 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
4202 if (firstpar->line_bottom) {
4203 /* draw a bottom line */
4204 y_bottom -= lyxfont::ascent('x', GetFont(par, par->Last() - 1));
4205 pain.line(0, offset + y_bottom,
4206 paperwidth, offset + y_bottom,
4207 LColor::topline, Painter::line_solid,
4208 Painter::line_thick);
4209 y_bottom -= lyxfont::ascent('x', GetFont(par, par->Last() - 1));
4213 int endlabel = row_ptr->par->GetEndLabel();
4214 if (endlabel == END_LABEL_BOX ||
4215 endlabel == END_LABEL_FILLED_BOX) {
4216 LyXFont font = GetFont(row_ptr->par, last);
4217 int size = int(0.75 * lyxfont::maxAscent(font));
4218 int y = (offset + row_ptr->baseline) - size;
4219 int x = is_rtl ? LYX_PAPER_MARGIN
4220 : paperwidth - LYX_PAPER_MARGIN - size;
4221 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4223 LyXFont font(LyXFont::ALL_SANE);
4224 font.setSize(LyXFont::SIZE_SMALL);
4225 x += lyxfont::width("Mwide-figM", font);
4227 x -= LYX_PAPER_MARGIN/2;
4228 if (row_ptr->fill <= size)
4229 x += (size - row_ptr->fill + 1) * (is_rtl ? -1 : 1);
4230 if (endlabel == END_LABEL_BOX) {
4231 pain.line(x, y, x, y + size,
4233 pain.line(x + size, y, x + size , y + size,
4235 pain.line(x, y, x + size, y,
4237 pain.line(x, y + size, x + size, y + size,
4240 pain.fillRectangle(x, y, size, size,
4245 /* draw the text in the pixmap */
4247 vpos = row_ptr->pos;
4248 /* table stuff -- begin*/
4249 if (row_ptr->par->table) {
4251 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
4253 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4255 while (vpos <= last) {
4256 pos = vis2log(vpos);
4257 if (row_ptr->par->IsNewline(pos)) {
4259 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4260 /* draw the table lines, still very simple */
4261 on_off = !row_ptr->par->table->TopLine(cell);
4263 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4264 !row_ptr->par->table->IsContRow(cell))
4265 pain.line(int(x_old),
4266 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4268 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4270 on_off ? Painter::line_onoffdash : Painter::line_solid);
4272 on_off = !row_ptr->par->table->BottomLine(cell);
4273 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4274 row_ptr->par->table->VeryLastRow(cell))
4276 pain.line(int(x_old),
4277 offset + y_bottom - 1,
4279 offset + y_bottom - 1,
4281 on_off ? Painter::line_onoffdash : Painter::line_solid);
4283 on_off = !row_ptr->par->table->LeftLine(cell);
4285 pain.line(int(x_old),
4286 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4288 offset + y_bottom - 1,
4290 on_off ? Painter::line_onoffdash : Painter::line_solid);
4292 on_off = !row_ptr->par->table->RightLine(cell);
4294 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4295 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4296 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4297 offset + y_bottom - 1,
4299 on_off ? Painter::line_onoffdash : Painter::line_solid);
4302 /* take care about the alignment and other spaces */
4304 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4305 if (row_ptr->par->table->IsFirstCell(cell))
4306 --cell; // little hack, sorry
4308 } else if (row_ptr->par->IsHfill(pos)) {
4312 offset + row_ptr->baseline - DefaultHeight() / 2,
4314 offset + row_ptr->baseline,
4319 } else if (row_ptr->par->IsSeparator(pos)) {
4321 x+= SingleWidth(row_ptr->par, pos);
4322 #warning Think about this.
4324 /* -------> Only draw protected spaces when
4325 * not in free-spacing mode. */
4326 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4327 pain.line(int(tmpx),
4328 offset + row_ptr->baseline - 3,
4330 offset + row_ptr->baseline - 1,
4333 pain.line(int(tmpx),
4334 offset + row_ptr->baseline - 1,
4336 offset + row_ptr->baseline - 1,
4339 pain.line(int(x - 2),
4340 offset + row_ptr->baseline - 3,
4342 offset + row_ptr->baseline - 1,
4345 /* what about underbars? */
4346 font = GetFont(row_ptr->par, pos);
4347 if (font.underbar() == LyXFont::ON
4348 && font.latex() != LyXFont::ON) {
4349 pain.line(int(tmpx),
4350 offset + row_ptr->baseline + 2,
4352 offset + row_ptr->baseline + 2);
4358 draw(row_ptr, vpos, offset, x);
4361 /* do not forget the very last cell. This has no NEWLINE so
4362 * ignored by the code above*/
4363 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4364 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4365 on_off = !row_ptr->par->table->TopLine(cell);
4367 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4368 !row_ptr->par->table->IsContRow(cell))
4370 pain.line(int(x_old),
4371 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4373 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4375 on_off ? Painter::line_onoffdash : Painter::line_solid);
4376 on_off = !row_ptr->par->table->BottomLine(cell);
4377 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4378 row_ptr->par->table->VeryLastRow(cell))
4380 pain.line(int(x_old),
4381 offset + y_bottom - 1,
4383 offset + y_bottom - 1,
4385 on_off ? Painter::line_onoffdash : Painter::line_solid);
4387 on_off = !row_ptr->par->table->LeftLine(cell);
4389 pain.line(int(x_old),
4390 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4392 offset + y_bottom - 1,
4394 on_off ? Painter::line_onoffdash : Painter::line_solid);
4396 on_off = !row_ptr->par->table->RightLine(cell);
4398 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4399 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4400 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4401 offset + y_bottom - 1,
4403 on_off ? Painter::line_onoffdash : Painter::line_solid);
4406 /* table stuff -- end*/
4407 LyXParagraph::size_type main_body =
4408 BeginningOfMainBody(row_ptr->par);
4409 if (main_body > 0 &&
4410 (main_body-1 > last ||
4411 !row_ptr->par->IsLineSeparator(main_body-1)))
4414 while (vpos <= last) {
4415 pos = vis2log(vpos);
4416 if (main_body > 0 && pos == main_body-1) {
4417 x += fill_label_hfill
4418 + lyxfont::width(layout.labelsep, GetFont(row_ptr->par, -2))
4419 - SingleWidth(row_ptr->par, main_body-1);
4422 if (row_ptr->par->IsHfill(pos)) {
4425 offset + row_ptr->baseline - DefaultHeight() / 2,
4427 offset + row_ptr->baseline,
4430 if (HfillExpansion(row_ptr, pos)) {
4431 if (pos >= main_body) {
4433 offset + row_ptr->baseline - DefaultHeight() / 4,
4434 int(x + fill_hfill),
4435 offset + row_ptr->baseline - DefaultHeight() / 4,
4437 Painter::line_onoffdash);
4441 offset + row_ptr->baseline - DefaultHeight() / 4,
4442 int(x + fill_label_hfill),
4443 offset + row_ptr->baseline - DefaultHeight() / 4,
4445 Painter::line_onoffdash);
4447 x += fill_label_hfill;
4450 offset + row_ptr->baseline - DefaultHeight() / 2,
4452 offset + row_ptr->baseline,
4457 } else if (row_ptr->par->IsSeparator(pos)) {
4461 x += SingleWidth(row_ptr->par, pos);
4462 if (pos >= main_body)
4463 x += fill_separator;
4464 #warning Think about this
4466 /* -------> Only draw protected spaces when
4467 * not in free-spacing mode. */
4468 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4470 pain.line(int(tmpx),
4471 offset + row_ptr->baseline - 3,
4473 offset + row_ptr->baseline - 1,
4476 pain.line(int(tmpx),
4477 offset + row_ptr->baseline - 1,
4479 offset + row_ptr->baseline - 1,
4482 pain.line(int(x - 2),
4483 offset + row_ptr->baseline - 3,
4485 offset + row_ptr->baseline - 1,
4488 /* what about underbars? */
4489 font = GetFont(row_ptr->par, pos);
4490 if (font.underbar() == LyXFont::ON
4491 && font.latex() != LyXFont::ON) {
4492 pain.line(int(tmpx),
4493 offset + row_ptr->baseline + 2,
4495 offset + row_ptr->baseline + 2);
4501 draw(row_ptr, vpos, offset, x);
4507 int LyXText::DefaultHeight() const
4509 LyXFont font(LyXFont::ALL_SANE);
4510 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4514 /* returns the column near the specified x-coordinate of the row
4515 * x is set to the real beginning of this column */
4516 int LyXText::GetColumnNearX(Row * row, int & x) const
4519 float fill_separator, fill_hfill, fill_label_hfill;
4521 PrepareToPrint(row, tmpx, fill_separator,
4522 fill_hfill, fill_label_hfill);
4524 LyXParagraph::size_type vc = row->pos;
4525 LyXParagraph::size_type last = RowLastPrintable(row);
4526 LyXParagraph::size_type c = 0;
4527 LyXLayout const & layout = textclasslist.Style(bparams->textclass,
4528 row->par->GetLayout());
4529 /* table stuff -- begin */
4530 if (row->par->table) {
4531 //the last row doesn't need a newline at the end
4532 if (row->next && row->next->par == row->par
4533 && row->par->IsNewline(last))
4535 int cell = NumberOfCell(row->par, row->pos);
4538 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4540 && (c = vis2log(vc)) >= 0
4541 && tmpx + (SingleWidth(row->par, c)/2) <= x
4543 if (row->par->IsNewline(c)) {
4544 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4545 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4548 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4553 tmpx += SingleWidth(row->par, c);
4558 /* table stuff -- end*/
4559 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4560 float last_tmpx = tmpx;
4562 if (main_body > 0 &&
4563 (main_body-1 > last ||
4564 !row->par->IsLineSeparator(main_body-1)))
4567 while (vc <= last && tmpx <= x) {
4570 if (main_body > 0 && c == main_body-1) {
4571 tmpx += fill_label_hfill +
4572 lyxfont::width(layout.labelsep,
4573 GetFont(row->par, -2));
4574 if (row->par->IsLineSeparator(main_body-1))
4575 tmpx -= SingleWidth(row->par, main_body-1);
4578 if (HfillExpansion(row, c)) {
4579 x += SingleWidth(row->par, c);
4583 tmpx += fill_label_hfill;
4585 else if (row->par->IsSeparator(c)) {
4586 tmpx += SingleWidth(row->par, c);
4588 tmpx+= fill_separator;
4590 tmpx += SingleWidth(row->par, c);
4594 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4600 if (vc > last + 1) // This shouldn't happen.
4603 if (row->pos > last) // Row is empty?
4605 else if (vc > last ||
4606 (vc - 1 >= row->pos &&
4607 ( (row->par->IsSeparator(vis2log(vc)) && vis2log(vc) != last)
4608 || (row->par->table && row->par->IsNewline(vc) )
4610 c = vis2log(vc - 1);
4611 if (bidi_level(c) % 2 == 0)
4615 if (bidi_level(c) % 2 == 1)
4619 if (!row->par->table && row->pos <= last && c > last
4620 && row->par->IsNewline(last)) {
4621 if (bidi_level(last) % 2 == 0)
4622 tmpx -= SingleWidth(row->par, last);
4624 tmpx += SingleWidth(row->par, last);
4634 /* turn the selection into a new environment. If there is no selection,
4635 * create an empty environment */
4636 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4638 /* no footnoteenvironment in a footnoteenvironment */
4639 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4640 WriteAlert(_("Impossible operation"),
4641 _("You can't insert a float in a float!"),
4645 /* no marginpars in minipages */
4646 if (kind == LyXParagraph::MARGIN
4647 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4648 WriteAlert(_("Impossible operation"),
4649 _("You can't insert a marginpar in a minipage!"),
4654 /* this doesnt make sense, if there is no selection */
4655 bool dummy_selection = false;
4657 sel_start_cursor = cursor; /* dummy selection */
4658 sel_end_cursor = cursor;
4659 dummy_selection = true;
4662 LyXParagraph *tmppar;
4664 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4665 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4669 /* a test to make sure there is not already a footnote
4670 * in the selection. */
4672 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4674 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4675 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4676 tmppar = tmppar->next;
4678 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4679 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4680 WriteAlert(_("Impossible operation"),
4681 _("Float would include float!"),
4686 /* ok we have a selection. This is always between sel_start_cursor
4687 * and sel_end cursor */
4689 SetUndo(Undo::FINISH,
4690 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4691 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4693 if (sel_end_cursor.pos > 0
4694 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4695 sel_end_cursor.pos--; /* please break before a space at
4697 if (sel_start_cursor.par == sel_end_cursor.par
4698 && sel_start_cursor.pos > sel_end_cursor.pos)
4699 sel_start_cursor.pos--;
4701 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4703 sel_end_cursor.par = sel_end_cursor.par->Next();
4704 sel_end_cursor.pos = 0;
4706 // don't forget to insert a dummy layout paragraph if necessary
4707 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4708 sel_end_cursor.par->BreakParagraphConservative(0);
4709 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4710 sel_end_cursor.par = sel_end_cursor.par->next;
4713 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4715 cursor = sel_end_cursor;
4717 /* please break behind a space, if there is one. The space should
4719 if (sel_start_cursor.pos > 0
4720 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4721 sel_start_cursor.pos--;
4722 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4723 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4726 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4727 tmppar = sel_start_cursor.par->Next();
4729 if (dummy_selection) {
4731 if (kind == LyXParagraph::TAB
4732 || kind == LyXParagraph::FIG
4733 || kind == LyXParagraph::WIDE_TAB
4734 || kind == LyXParagraph::WIDE_FIG
4735 || kind == LyXParagraph::ALGORITHM) {
4736 pair<bool, LyXTextClass::size_type> lres =
4737 textclasslist.NumberOfLayout(bparams->textclass,
4739 LyXTextClass::size_type lay;
4745 lay = 0; // use default layout "Standard" (0)
4747 tmppar->SetLayout(lay);
4751 if (sel_start_cursor.pos > 0) {
4752 /* the footnote-environment should begin with a standard layout.
4753 * Imagine you insert a footnote within an enumeration, you
4754 * certainly do not want an enumerated footnote! */
4758 /* this is a exception the user would sometimes expect, I hope */
4759 sel_start_cursor.par->Clear();
4763 while (tmppar != sel_end_cursor.par) {
4764 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4765 tmppar->footnotekind = kind;
4766 tmppar = tmppar->Next();
4769 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4771 SetCursor(sel_start_cursor.par->Next(), 0);
4777 // returns pointer to a specified row
4778 Row * LyXText::GetRow(LyXParagraph * par,
4779 LyXParagraph::size_type pos, long & y) const
4784 if (par == currentrow->par
4785 || par == currentrow->par->Previous()) {
4786 // do not dereference par, it may have been deleted
4787 // already! (Matthias)
4789 // Walk backwards as long as the previous
4790 // rows par is not par
4791 while (currentrow->previous
4792 && currentrow->previous->par != par) {
4793 currentrow = currentrow->previous;
4794 currentrow_y -= currentrow->height;
4796 // Walk backwards as long as the previous
4797 // rows par _is_ par
4798 while (currentrow->previous
4799 && currentrow->previous->par == par) {
4800 currentrow = currentrow->previous;
4801 currentrow_y -= currentrow->height;
4805 tmprow = currentrow;
4807 // find the first row of the specified paragraph
4809 && tmprow->par != par) {
4810 y += tmprow->height;
4811 tmprow = tmprow->next;
4814 if (tmprow->par == par){
4815 // now find the wanted row
4816 while (tmprow->pos < pos
4818 && tmprow->next->par == par
4819 && tmprow->next->pos <= pos) {
4820 y += tmprow->height;
4821 tmprow = tmprow->next;
4823 currentrow = tmprow;
4831 // find the first row of the specified paragraph
4832 while (tmprow->next && tmprow->par != par) {
4833 y += tmprow->height;
4834 tmprow = tmprow->next;
4837 // now find the wanted row
4838 while (tmprow->pos < pos
4840 && tmprow->next->par == par
4841 && tmprow->next->pos <= pos) {
4842 y += tmprow->height;
4843 tmprow = tmprow->next;
4846 currentrow = tmprow;