1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #pragma implementation "table.h"
21 #include "lyxparagraph.h"
23 #include "support/textutils.h"
24 #include "insets/insetbib.h"
25 #include "insets/insettext.h"
26 #include "lyx_gui_misc.h"
28 #include "bufferparams.h"
30 #include "minibuffer.h"
44 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(Painter &, LyXFont const &);
47 static int iso885968x[] = {
48 0xbc, // 0xa8 = fathatan
49 0xbd, // 0xa9 = dammatan
50 0xbe, // 0xaa = kasratan
54 0xde, // 0xae = shadda
57 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
61 0xc2, // 0xc2 = ligature madda
62 0xc3, // 0xc3 = ligature hamza on alef
63 0xc4, // 0xc4 = ligature hamza on waw
64 0xc5, // 0xc5 = ligature hamza under alef
65 0xc0, // 0xc6 = ligature hamza on ya
68 0xc9, // 0xc9 = taa marbuta
87 0,0,0,0,0, // 0xdb- 0xdf
98 0xe9, // 0xe9 = alef maksura
104 bool is_arabic(unsigned char c)
106 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
111 bool is_nikud(unsigned char c)
113 return 192 <= c && c <= 210;
117 int LyXText::workWidth(BufferView * bview) const
121 return inset_owner->getMaxWidth(bview->painter(), inset_owner);
123 LyXFont font(LyXFont::ALL_SANE);
124 return inset_owner->width(bview->painter(), font);
127 return bview->workWidth();
130 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
133 (form == FORM_INITIAL || form == FORM_MEDIAL) )
134 return iso885968x[c-0xa8];
140 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
141 LyXParagraph::size_type pos) const
145 return c + (0xb0 - '0');
149 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
150 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
152 return TransformChar(c,FORM_MEDIAL);
154 return TransformChar(c,FORM_INITIAL);
157 return TransformChar(c,FORM_FINAL);
159 return TransformChar(c,FORM_ISOLATED);
162 // This is the comments that some of the warnings below refers to.
163 // There are some issues in this file and I don't think they are
164 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
165 // this is a problem that has been here almost from day one and that a
166 // larger userbase with differenct access patters triggers the bad
167 // behaviour. (segfaults.) What I think happen is: In several places
168 // we store the paragraph in the current cursor and then moves the
169 // cursor. This movement of the cursor will delete paragraph at the
170 // old position if it is now empty. This will make the temporary
171 // pointer to the old cursor paragraph invalid and dangerous to use.
172 // And is some cases this will trigger a segfault. I have marked some
173 // of the cases where this happens with a warning, but I am sure there
174 // are others in this file and in text2.C. There is also a note in
175 // Delete() that you should read. In Delete I store the paragraph->id
176 // instead of a pointer to the paragraph. I am pretty sure this faulty
177 // use of temporary pointers to paragraphs that might have gotten
178 // invalidated (through a cursor movement) before they are used, are
179 // the cause of the strange crashes we get reported often.
181 // It is very tiresom to change this code, especially when it is as
182 // hard to read as it is. Help to fix all the cases where this is done
183 // would be greately appreciated.
187 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
188 LyXParagraph::size_type pos) const
190 char c = par->GetChar(pos);
191 return SingleWidth(bview, par, pos, c);
195 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
196 LyXParagraph::size_type pos, char c) const
198 LyXFont font = GetFont(bview->buffer(), par, pos);
200 // The most common case is handled first (Asger)
201 if (IsPrintable(c)) {
202 if (font.language()->RightToLeft()) {
203 if (font.language()->lang() == "arabic" &&
204 lyxrc.font_norm == "iso8859-6.8x")
205 c = TransformChar(c, par, pos);
206 else if (font.language()->lang() == "hebrew" &&
210 return lyxfont::width(c, font);
212 } else if (IsHfillChar(c)) {
213 return 3; /* Because of the representation
214 * as vertical lines */
215 } else if (c == LyXParagraph::META_FOOTNOTE ||
216 c == LyXParagraph::META_MARGIN ||
217 c == LyXParagraph::META_FIG ||
218 c == LyXParagraph::META_TAB ||
219 c == LyXParagraph::META_WIDE_FIG ||
220 c == LyXParagraph::META_WIDE_TAB ||
221 c == LyXParagraph::META_ALGORITHM) {
224 case LyXParagraph::META_MARGIN:
227 case LyXParagraph::META_FIG:
230 case LyXParagraph::META_TAB:
233 case LyXParagraph::META_ALGORITHM:
236 case LyXParagraph::META_WIDE_FIG:
239 case LyXParagraph::META_WIDE_TAB:
242 case LyXParagraph::META_FOOTNOTE:
248 return lyxfont::width(fs, font);
249 } else if (c == LyXParagraph::META_INSET) {
250 Inset * tmpinset = par->GetInset(pos);
252 tmpinset->update(bview, font);
253 return tmpinset->width(bview->painter(), font);
257 } else if (IsSeparatorChar(c))
259 else if (IsNewlineChar(c))
261 return lyxfont::width(c, font);
265 // Returns the paragraph position of the last character in the specified row
266 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
268 if (row->next() == 0)
269 return row->par()->Last() - 1;
270 else if (row->next()->par() != row->par())
271 return row->par()->Last() - 1;
273 return row->next()->pos() - 1;
277 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
279 LyXParagraph::size_type last = RowLast(row);
280 if (last >= row->pos()
282 && row->next()->par() == row->par()
283 && row->par()->IsSeparator(last))
290 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
292 bidi_same_direction = true;
293 if (!lyxrc.rtl_support) {
298 bidi_start = row->pos();
299 bidi_end = RowLastPrintable(row);
301 if (bidi_start > bidi_end) {
306 if (bidi_end + 2 - bidi_start >
307 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
308 LyXParagraph::size_type new_size =
309 (bidi_end + 2 - bidi_start < 500) ?
310 500 : 2 * (bidi_end + 2 - bidi_start);
311 log2vis_list.resize(new_size);
312 vis2log_list.resize(new_size);
313 bidi_levels.resize(new_size);
316 vis2log_list[bidi_end + 1 - bidi_start] = -1;
317 log2vis_list[bidi_end + 1 - bidi_start] = -1;
319 LyXParagraph::size_type stack[2];
320 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
324 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
326 for (LyXParagraph::size_type lpos = bidi_start;
327 lpos <= bidi_end; ++lpos) {
328 bool is_space = row->par()->IsLineSeparator(lpos);
329 LyXParagraph::size_type pos =
330 (is_space && lpos + 1 <= bidi_end &&
331 !row->par()->IsLineSeparator(lpos + 1) &&
333 || !row->par()->IsNewline(lpos + 1)) )
335 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
336 bool new_rtl = font.isVisibleRightToLeft();
337 bool new_rtl0 = font.isRightToLeft();
341 if (row->par()->table && row->par()->IsNewline(lpos)) {
343 new_rtl = new_rtl0 = false;
346 if (lpos == main_body - 1
347 && row->pos() < main_body - 1
348 && row->par()->IsLineSeparator(lpos)) {
349 new_level = (rtl_par) ? 1 : 0;
350 new_rtl = new_rtl0 = rtl_par;
352 new_level = (new_rtl) ? 1 : 2;
354 new_level = (rtl_par) ? 2 : 0;
356 if (is_space && new_level >= level) {
362 int new_level2 = new_level;
364 if (level == new_level && rtl0 != new_rtl0) {
366 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
367 } else if (level < new_level) {
368 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
369 if (new_level > rtl_par)
370 bidi_same_direction = false;
372 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
375 bidi_levels[lpos - bidi_start] = new_level;
377 while (level > new_level2) {
378 LyXParagraph::size_type old_lpos =
380 int delta = lpos - old_lpos - 1;
383 log2vis_list[lpos - bidi_start] += delta;
384 log2vis_list[old_lpos - bidi_start] += delta;
386 while (level < new_level)
387 stack[level++] = lpos;
391 LyXParagraph::size_type old_lpos = stack[--level];
392 int delta = bidi_end - old_lpos;
395 log2vis_list[old_lpos - bidi_start] += delta;
398 LyXParagraph::size_type vpos = bidi_start - 1;
399 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
400 vpos += log2vis_list[lpos - bidi_start];
401 vis2log_list[vpos - bidi_start] = lpos;
402 log2vis_list[lpos - bidi_start] = vpos;
407 // This method requires a previous call to ComputeBidiTables()
408 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
409 LyXParagraph::size_type pos) const
411 if (!lyxrc.rtl_support)
412 return false; // This is just for speedup
414 if (!bidi_InRange(pos - 1) ||
415 (par->table && par->IsNewline(pos-1)) )
418 bool rtl = bidi_level(pos - 1) % 2;
420 if (pos == par->Last() ||
421 (par->table && par->IsNewline(pos)))
422 rtl2 = par->isRightToLeftPar(buf->params);
423 else if (bidi_InRange(pos))
424 rtl2 = bidi_level(pos) % 2;
428 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
429 LyXParagraph::size_type pos,
430 LyXFont const & font) const
432 if (!lyxrc.rtl_support)
433 return false; // This is just for speedup
435 bool rtl = font.isVisibleRightToLeft();
437 if (pos == par->Last() ||
438 (par->table && par->IsNewline(pos)))
439 rtl2 = par->isRightToLeftPar(buf->params);
440 else if (bidi_InRange(pos))
441 rtl2 = bidi_level(pos) % 2;
446 void LyXText::draw(BufferView * bview, Row const * row,
447 LyXParagraph::size_type & vpos,
448 int offset, float & x)
450 Painter & pain = bview->painter();
452 LyXParagraph::size_type pos = vis2log(vpos);
453 char c = row->par()->GetChar(pos);
456 if (IsNewlineChar(c)) {
458 // Draw end-of-line marker
459 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
460 int wid = lyxfont::width('n', font);
461 int asc = lyxfont::maxAscent(font);
462 int y = offset + row->baseline();
465 if (bidi_level(pos) % 2 == 0) {
466 xp[0] = int(x + wid * 0.375);
467 yp[0] = int(y - 0.875 * asc * 0.75);
470 yp[1] = int(y - 0.500 * asc * 0.75);
472 xp[2] = int(x + wid * 0.375);
473 yp[2] = int(y - 0.125 * asc * 0.75);
475 pain.lines(xp, yp, 3, LColor::eolmarker);
478 yp[0] = int(y - 0.500 * asc * 0.75);
480 xp[1] = int(x + wid);
481 yp[1] = int(y - 0.500 * asc * 0.75);
483 xp[2] = int(x + wid);
484 yp[2] = int(y - asc * 0.75);
486 pain.lines(xp, yp, 3, LColor::eolmarker);
488 xp[0] = int(x + wid * 0.625);
489 yp[0] = int(y - 0.875 * asc * 0.75);
491 xp[1] = int(x + wid);
492 yp[1] = int(y - 0.500 * asc * 0.75);
494 xp[2] = int(x + wid * 0.625);
495 yp[2] = int(y - 0.125 * asc * 0.75);
497 pain.lines(xp, yp, 3, LColor::eolmarker);
499 xp[0] = int(x + wid);
500 yp[0] = int(y - 0.500 * asc * 0.75);
503 yp[1] = int(y - 0.500 * asc * 0.75);
506 yp[2] = int(y - asc * 0.75);
508 pain.lines(xp, yp, 3, LColor::eolmarker);
514 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
515 LyXFont font2 = font;
517 if (c == LyXParagraph::META_FOOTNOTE
518 || c == LyXParagraph::META_MARGIN
519 || c == LyXParagraph::META_FIG
520 || c == LyXParagraph::META_TAB
521 || c == LyXParagraph::META_WIDE_FIG
522 || c == LyXParagraph::META_WIDE_TAB
523 || c == LyXParagraph::META_ALGORITHM) {
526 case LyXParagraph::META_MARGIN:
529 case LyXParagraph::META_FIG:
532 case LyXParagraph::META_TAB:
535 case LyXParagraph::META_ALGORITHM:
538 case LyXParagraph::META_WIDE_FIG:
541 case LyXParagraph::META_WIDE_TAB:
544 case LyXParagraph::META_FOOTNOTE:
551 // calculate the position of the footnotemark
552 int y = (row->baseline() - lyxfont::maxAscent(font2)
553 + lyxfont::maxAscent(font));
555 font.setColor(LColor::footnote);
557 // draw it and set new x position
559 pain.text(int(x), offset + y, fs, font);
560 x += lyxfont::width(fs, font);
561 pain.line(int(tmpx), offset + row->baseline(),
562 int(x), offset + row->baseline(),
567 } else if (c == LyXParagraph::META_INSET) {
568 Inset const * tmpinset = row->par()->GetInset(pos);
570 tmpinset->draw(bview, font, offset+row->baseline(), x);
574 if (lyxrc.mark_foreign_language &&
575 font.language() != bview->buffer()->params.language_info) {
576 int y = offset + row->height() - 1;
577 pain.line(int(tmpx), y, int(x), y,
584 /* usual characters, no insets */
586 // Collect character that we can draw in one command
588 // This is dirty, but fast. Notice that it will never be too small.
589 // For the record, I'll note that Microsoft Word has a limit
590 // of 768 here. We have none :-) (Asger)
591 // Ok. I am the first to admit that the use of std::string will be
592 // a tiny bit slower than using a POD char array. However, I claim
593 // that this slowdown is so small that it is close to inperceptive.
594 // So IMHO we should go with the easier and clearer implementation.
595 // And even if 1024 is a large number here it might overflow, string
596 // will only overflow if the machine is out of memory...
597 static string textstring;
601 LyXParagraph::size_type last = RowLastPrintable(row);
603 if (font.language()->lang() == "hebrew") {
605 LyXParagraph::size_type vpos2 = vpos;
606 int width = lyxfont::width(c, font2);
608 while (vpos2 <= last &&
609 (pos = vis2log(vpos2)) >= 0
610 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
613 if (static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
615 int width2 = SingleWidth(bview, row->par(), pos, c);
616 dx = (c == 'ø' || c == 'ã')
617 ? width2 - width : (width2 - width) / 2;
620 pain.text(int(x) + dx, offset + row->baseline(),
623 while (vpos <= last &&
624 (pos = vis2log(vpos)) >= 0
625 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
627 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
631 // Draw text and set the new x position
632 pain.text(int(x), offset + row->baseline(),
634 x += lyxfont::width(textstring, font);
636 } else if (font.language()->lang() == "arabic" &&
637 lyxrc.font_norm == "iso8859-6.8x") {
638 textstring = TransformChar(c, row->par(), pos);
639 while (vpos <= last &&
640 (pos = vis2log(vpos)) >= 0
641 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
642 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
643 c = TransformChar(c, row->par(), pos);
647 // Draw text and set the new x position
648 pain.text(int(x), offset + row->baseline(), textstring, font);
649 x += lyxfont::width(textstring, font);
651 while (vpos <= last &&
652 (pos = vis2log(vpos)) >= 0
653 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
654 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
658 // Draw text and set the new x position
659 pain.text(int(x), offset + row->baseline(), textstring, font);
660 x += lyxfont::width(textstring, font);
663 // what about underbars?
664 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
665 pain.line(int(tmpx), offset + row->baseline() + 2,
666 int(x), offset + row->baseline() + 2);
668 } else if (lyxrc.mark_foreign_language &&
669 font.language() != bview->buffer()->params.language_info) {
670 int y = offset + row->height() - 1;
671 pain.line(int(tmpx), y, int(x), y,
675 // If we want ulem.sty support, drawing
676 // routines should go here. (Asger)
677 // Why shouldn't LyXFont::drawText handle it internally?
681 // Returns the left beginning of the text.
682 // This information cannot be taken from the layouts-objekt, because in
683 // LaTeX the beginning of the text fits in some cases (for example sections)
684 // exactly the label-width.
685 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
687 LyXLayout const & layout =
688 textclasslist.Style(bview->buffer()->params.textclass,
689 row->par()->GetLayout());
691 string parindent = layout.parindent;
694 /* table stuff -- begin */
695 if (row->par()->table)
697 /* table stuff -- end */
699 int x = LYX_PAPER_MARGIN;
701 x += lyxfont::signedWidth(textclasslist
702 .TextClass(bview->buffer()->params.textclass)
705 .TextClass(bview->buffer()->params.textclass)
708 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
709 LyXFont font(LyXFont::ALL_SANE);
710 font.setSize(LyXFont::SIZE_SMALL);
711 x += lyxfont::width("Mwide-figM", font)
712 + LYX_PAPER_MARGIN/2;
715 // this is the way, LyX handles the LaTeX-Environments.
716 // I have had this idea very late, so it seems to be a
717 // later added hack and this is true
718 if (!row->par()->GetDepth()) {
719 if (!row->par()->GetLayout()) {
720 // find the previous same level paragraph
721 if (row->par()->FirstPhysicalPar()->Previous()) {
722 LyXParagraph * newpar = row->par()
723 ->DepthHook(row->par()->GetDepth());
725 textclasslist.Style(bview->buffer()->params.textclass,
732 // find the next level paragraph
734 LyXParagraph * newpar =
735 row->par()->DepthHook(row->par()->GetDepth()-1);
737 // make a corresponding row. Needed to call LeftMargin()
739 // check wether it is a sufficent paragraph
740 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
742 .Style(bview->buffer()->params.textclass,
743 newpar->GetLayout()).isEnvironment()) {
745 dummyrow.par(newpar);
746 dummyrow.pos(newpar->Last());
747 x = LeftMargin(bview, &dummyrow);
749 // this is no longer an error, because this function
750 // is used to clear impossible depths after changing
751 // a layout. Since there is always a redo,
752 // LeftMargin() is always called
753 row->par()->FirstPhysicalPar()->depth = 0;
756 if (newpar && !row->par()->GetLayout()) {
757 if (newpar->FirstPhysicalPar()->noindent)
760 parindent = textclasslist
761 .Style(bview->buffer()->params.textclass,
762 newpar->GetLayout()).parindent;
767 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
768 switch (layout.margintype) {
770 if (!layout.leftmargin.empty()) {
771 x += lyxfont::signedWidth(layout.leftmargin,
773 .TextClass(bview->buffer()->params.
777 if (!row->par()->GetLabelstring().empty()) {
778 x += lyxfont::signedWidth(layout.labelindent,
780 x += lyxfont::width(row->par()->GetLabelstring(),
782 x += lyxfont::width(layout.labelsep, labelfont);
786 x += lyxfont::signedWidth(layout.labelindent, labelfont);
787 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
788 if (!row->par()->GetLabelWidthString().empty()) {
789 x += lyxfont::width(row->par()->GetLabelWidthString(),
791 x += lyxfont::width(layout.labelsep, labelfont);
796 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
797 / (row->par()->GetDepth() + 4);
799 case MARGIN_FIRST_DYNAMIC:
800 if (layout.labeltype == LABEL_MANUAL) {
801 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
802 x += lyxfont::signedWidth(layout.leftmargin,
805 x += lyxfont::signedWidth(layout.labelindent,
808 } else if (row->pos()
809 // Special case to fix problems with
811 || (layout.labeltype == LABEL_STATIC
812 && layout.latextype == LATEX_ENVIRONMENT
813 && ! row->par()->IsFirstInSequence())) {
814 x += lyxfont::signedWidth(layout.leftmargin,
816 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
817 && layout.labeltype != LABEL_BIBLIO
818 && layout.labeltype !=
819 LABEL_CENTERED_TOP_ENVIRONMENT) {
820 x += lyxfont::signedWidth(layout.labelindent,
822 x += lyxfont::width(layout.labelsep, labelfont);
823 x += lyxfont::width(row->par()->GetLabelstring(),
828 case MARGIN_RIGHT_ADDRESS_BOX:
830 // ok, a terrible hack. The left margin depends on the widest
831 // row in this paragraph. Do not care about footnotes, they
832 // are *NOT* allowed in the LaTeX realisation of this layout.
834 // find the first row of this paragraph
835 Row const * tmprow = row;
836 while (tmprow->previous()
837 && tmprow->previous()->par() == row->par())
838 tmprow = tmprow->previous();
840 int minfill = tmprow->fill();
841 while (tmprow->next() && tmprow->next()->par() == row->par()) {
842 tmprow = tmprow->next();
843 if (tmprow->fill() < minfill)
844 minfill = tmprow->fill();
847 x += lyxfont::signedWidth(layout.leftmargin,
849 .TextClass(bview->buffer()->params.textclass)
855 if ((workWidth(bview) > 0) &&
856 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
858 if (!row->par()->pextra_widthp.empty()) {
859 x += workWidth(bview) *
860 atoi(row->par()->pextra_widthp.c_str()) / 100;
861 } else if (!row->par()->pextra_width.empty()) {
862 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
863 if (xx > workWidth(bview))
864 xx = workWidth(bview) * 80 / 100;
866 } else { // should not happen
867 LyXFont font(LyXFont::ALL_SANE);
868 x += lyxfont::width("XXXXXX", font);
872 int align; // wrong type
873 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
874 align = layout.align;
876 align = row->par()->FirstPhysicalPar()->align;
878 // set the correct parindent
879 if (row->pos() == 0) {
880 if ((layout.labeltype == LABEL_NO_LABEL
881 || layout.labeltype == LABEL_TOP_ENVIRONMENT
882 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
883 || (layout.labeltype == LABEL_STATIC
884 && layout.latextype == LATEX_ENVIRONMENT
885 && ! row->par()->IsFirstInSequence()))
886 && row->par() == row->par()->FirstPhysicalPar()
887 && align == LYX_ALIGN_BLOCK
888 && !row->par()->noindent
889 && (row->par()->layout ||
890 bview->buffer()->params.paragraph_separation ==
891 BufferParams::PARSEP_INDENT))
892 x += lyxfont::signedWidth(parindent,
894 .TextClass(bview->buffer()->params
897 else if (layout.labeltype == LABEL_BIBLIO) {
898 // ale970405 Right width for bibitems
899 x += bibitemMaxWidth(bview->painter(),
901 .TextClass(bview->buffer()->params
910 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
912 LyXLayout const & layout =
913 textclasslist.Style(buf->params.textclass,
914 row->par()->GetLayout());
916 int x = LYX_PAPER_MARGIN
917 + lyxfont::signedWidth(textclasslist
918 .TextClass(buf->params.textclass)
921 .TextClass(buf->params.textclass)
924 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
925 x += LYX_PAPER_MARGIN / 2;
928 // this is the way, LyX handles the LaTeX-Environments.
929 // I have had this idea very late, so it seems to be a
930 // later added hack and this is true
931 if (row->par()->GetDepth()) {
932 // find the next level paragraph
934 LyXParagraph * newpar = row->par();
937 newpar = newpar->FirstPhysicalPar()->Previous();
939 newpar = newpar->FirstPhysicalPar();
940 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
941 && newpar->footnoteflag == row->par()->footnoteflag);
943 // make a corresponding row. Needed to call LeftMargin()
945 // check wether it is a sufficent paragraph
946 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
947 && textclasslist.Style(buf->params.textclass,
951 dummyrow.par(newpar);
953 x = RightMargin(buf, &dummyrow);
955 // this is no longer an error, because this function
956 // is used to clear impossible depths after changing
957 // a layout. Since there is always a redo,
958 // LeftMargin() is always called
959 row->par()->FirstPhysicalPar()->depth = 0;
963 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
964 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
965 .TextClass(buf->params.textclass)
966 .defaultfont()) * 4 / (row->par()->GetDepth()
972 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
974 if (textclasslist.Style(bview->buffer()->params.textclass,
975 row->par()->GetLayout()).margintype
979 tmprow.pos(row->par()->Last());
980 return LeftMargin(bview, &tmprow); /* just the beginning
983 return 0; /* LabelEnd is only needed, if the
984 layout fills a flushleft
989 /* table stuff -- begin*/
990 int LyXText::NumberOfCell(LyXParagraph * par,
991 LyXParagraph::size_type pos) const
994 LyXParagraph::size_type tmp_pos = 0;
995 while (tmp_pos < pos) {
996 if (par->IsNewline(tmp_pos))
1004 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
1005 LyXParagraph::size_type & pos) const
1008 while (pos < par->Last() && !par->IsNewline(pos)) {
1009 w += SingleWidth(bview, par, pos);
1012 if (par->IsNewline(pos))
1019 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
1022 float fill_separator, fill_hfill, fill_label_hfill;
1023 if (!row->par()->table)
1025 PrepareToPrint(bview, row, tmpx, fill_separator,
1026 fill_hfill, fill_label_hfill, false);
1027 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
1032 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
1034 Row * row = GetRowNearY(y);
1035 return HitInTable(bview, row, x);
1039 /* table stuff -- end*/
1042 // get the next breakpoint in a given paragraph
1043 LyXParagraph::size_type
1044 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1046 LyXParagraph * par = row->par();
1047 LyXParagraph::size_type pos = row->pos();
1052 /* table stuff -- begin*/
1054 while (pos < par->size()
1055 && (!par->IsNewline(pos)
1056 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1057 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1058 par->GetInset(pos) && par->GetInset(pos)->display()){
1059 par->GetInset(pos)->display(false);
1065 /* table stuff -- end*/
1067 // position of the last possible breakpoint
1068 // -1 isn't a suitable value, but a flag
1069 LyXParagraph::size_type last_separator = -1;
1070 width -= RightMargin(bview->buffer(), row);
1072 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1073 LyXLayout const & layout =
1074 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1075 LyXParagraph::size_type i = pos;
1077 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1078 /* special code for right address boxes, only newlines count */
1079 while (i < par->Last()) {
1080 if (par->IsNewline(i)) {
1082 i = par->Last() - 1; // this means break
1084 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1085 par->GetInset(i) && par->GetInset(i)->display()){
1086 par->GetInset(i)->display(false);
1091 // Last position is an invariant
1092 LyXParagraph::size_type const last =
1094 // this is the usual handling
1095 int x = LeftMargin(bview, row);
1096 while (x < width && i < last) {
1097 char c = par->GetChar(i);
1098 if (IsNewlineChar(c)) {
1100 x = width; // this means break
1101 } else if (c == LyXParagraph::META_INSET &&
1102 par->GetInset(i) && par->GetInset(i)->display()){
1103 // check wether a Display() inset is
1104 // valid here. if not, change it to
1106 if (layout.isCommand()
1107 || (layout.labeltype == LABEL_MANUAL
1108 && i < BeginningOfMainBody(bview->buffer(), par))){
1109 // display istn't allowd
1110 par->GetInset(i)->display(false);
1111 x += SingleWidth(bview, par, i, c);
1113 // inset is display. So break the line here
1117 if (IsLineSeparatorChar(par->GetChar(i+1)))
1120 last_separator = last; // to avoid extra rows
1122 last_separator = i - 1;
1123 x = width; // this means break
1126 if (IsLineSeparatorChar(c))
1128 x += SingleWidth(bview, par, i, c);
1131 if (i == main_body) {
1132 x += lyxfont::width(layout.labelsep,
1133 GetFont(bview->buffer(), par, -2));
1134 if (par->IsLineSeparator(i - 1))
1135 x-= SingleWidth(bview, par, i - 1);
1136 int left_margin = LabelEnd(bview, row);
1137 if (x < left_margin)
1141 // end of paragraph is always a suitable separator
1142 if (i == last && x < width)
1146 // well, if last_separator is still 0, the line isn't breakable.
1147 // don't care and cut simply at the end
1148 if (last_separator < 0) {
1152 // manual labels cannot be broken in LaTeX, do not care
1153 if (main_body && last_separator < main_body)
1154 last_separator = main_body - 1;
1156 return last_separator;
1160 // returns the minimum space a row needs on the screen in pixel
1161 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1163 if (paper_width < 0)
1167 // get the pure distance
1168 LyXParagraph::size_type last = RowLastPrintable(row);
1170 /* table stuff -- begin */
1171 if (row->par()->table) {
1172 // for tables FILL does calculate the widthes of each cell in
1174 LyXParagraph::size_type pos = row->pos();
1175 int cell = NumberOfCell(row->par(), pos);
1178 row->par()->table->SetWidthOfCell(cell,
1183 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1184 // don't forget the very last table cell without characters
1185 if (cell == row->par()->table->GetNumberOfCells() - 1)
1186 row->par()->table->SetWidthOfCell(cell,
1191 return 0; /* width of table cannot be returned since
1192 * we cannot guarantee its correct value at
1195 /* table stuff -- end*/
1198 // special handling of the right address boxes
1199 if (textclasslist.Style(bview->buffer()->params.textclass,
1200 row->par()->GetLayout()).margintype
1201 == MARGIN_RIGHT_ADDRESS_BOX) {
1202 int tmpfill = row->fill();
1203 row->fill(0); // the minfill in MarginLeft()
1204 w = LeftMargin(bview, row);
1207 w = LeftMargin(bview, row);
1209 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1210 row->par()->GetLayout());
1211 LyXParagraph::size_type main_body =
1212 BeginningOfMainBody(bview->buffer(), row->par());
1213 LyXParagraph::size_type i = row->pos();
1216 if (main_body > 0 && i == main_body) {
1217 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1218 if (row->par()->IsLineSeparator(i - 1))
1219 w -= SingleWidth(bview, row->par(), i - 1);
1220 int left_margin = LabelEnd(bview, row);
1221 if (w < left_margin)
1224 w += SingleWidth(bview, row->par(), i);
1227 if (main_body > 0 && main_body > last) {
1228 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1229 if (last >= 0 && row->par()->IsLineSeparator(last))
1230 w -= SingleWidth(bview, row->par(), last);
1231 int left_margin = LabelEnd(bview, row);
1232 if (w < left_margin)
1236 fill = paper_width - w - RightMargin(bview->buffer(), row);
1241 // returns the minimum space a manual label needs on the screen in pixel
1242 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1244 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1245 // -1 because a label ends either with a space that is in the label,
1246 // or with the beginning of a footnote that is outside the label.
1248 // I don't understand this code in depth, but sometimes "last" is
1249 // less than 0 and this causes a crash. This fix seems to work
1250 // correctly, but I bet the real error is elsewhere. The bug is
1251 // triggered when you have an open footnote in a paragraph
1252 // environment with a manual label. (Asger)
1253 if (last < 0) last = 0;
1255 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1262 w += SingleWidth(bview, row->par(), i);
1267 if (!row->par()->labelwidthstring.empty()) {
1268 fill = max(lyxfont::width(row->par()->labelwidthstring,
1269 GetFont(bview->buffer(), row->par(), -2)) - w,
1277 // returns the number of separators in the specified row. The separator
1278 // on the very last column doesnt count
1279 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1281 int last = RowLast(row);
1282 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1284 for (; p < last; ++p) {
1285 if (row->par()->IsSeparator(p)) {
1293 // returns the number of hfills in the specified row. The LyX-Hfill is
1294 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1295 // ignored. This is *MUCH* more usefull than not to ignore!
1296 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1298 int last = RowLast(row);
1299 int first = row->pos();
1300 if (first) { /* hfill *DO* count at the beginning
1302 while(first <= last && row->par()->IsHfill(first))
1306 first = max(first, BeginningOfMainBody(buf, row->par()));
1308 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1309 if (row->par()->IsHfill(p)) {
1317 // like NumberOfHfills, but only those in the manual label!
1318 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1320 LyXParagraph::size_type last = RowLast(row);
1321 LyXParagraph::size_type first = row->pos();
1322 if (first) { /* hfill *DO* count at the beginning
1324 while(first < last && row->par()->IsHfill(first))
1328 last = min(last, BeginningOfMainBody(buf, row->par()));
1330 for (LyXParagraph::size_type p = first;
1331 p < last; ++p) { // last, because the end is ignored!
1332 if (row->par()->IsHfill(p)) {
1340 // returns true, if a expansion is needed.
1341 // Rules are given by LaTeX
1342 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1343 LyXParagraph::size_type pos) const
1345 // by the way, is it a hfill?
1346 if (!row_ptr->par()->IsHfill(pos))
1349 // at the end of a row it does not count
1350 if (pos >= RowLast(row_ptr))
1353 // at the beginning of a row it does not count, if it is not
1354 // the first row of a paragaph
1355 if (!row_ptr->pos())
1358 // in some labels it does not count
1359 if (textclasslist.Style(buf->params.textclass,
1360 row_ptr->par()->GetLayout()).margintype
1362 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1365 // if there is anything between the first char of the row and
1366 // the sepcified position that is not a newline and not a hfill,
1367 // the hfill will count, otherwise not
1368 LyXParagraph::size_type i = row_ptr->pos();
1369 while (i < pos && (row_ptr->par()->IsNewline(i)
1370 || row_ptr->par()->IsHfill(i)))
1377 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1379 /* get the maximum ascent and the maximum descent */
1380 int asc = 0, desc = 0, pos = 0;
1381 float layoutasc = 0;
1382 float layoutdesc = 0;
1385 Inset * tmpinset = 0;
1387 /* this must not happen before the currentrow for clear reasons.
1388 so the trick is just to set the current row onto this row */
1390 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1392 /* ok , let us initialize the maxasc and maxdesc value.
1393 * This depends in LaTeX of the font of the last character
1394 * in the paragraph. The hack below is necessary because
1395 * of the possibility of open footnotes */
1397 /* Correction: only the fontsize count. The other properties
1398 are taken from the layoutfont. Nicer on the screen :) */
1400 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1401 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1403 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1404 firstpar->GetLayout());
1406 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1407 LyXFont::FONT_SIZE size = font.size();
1408 font = GetFont(bview->buffer(), par, -1);
1411 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1413 float spacing_val = 1.0;
1414 if (!row_ptr->par()->spacing.isDefault()) {
1415 spacing_val = row_ptr->par()->spacing.getValue();
1417 spacing_val = bview->buffer()->params.spacing.getValue();
1419 //lyxerr << "spacing_val = " << spacing_val << endl;
1421 int maxasc = int(lyxfont::maxAscent(font) *
1422 layout.spacing.getValue() *
1424 int maxdesc = int(lyxfont::maxDescent(font) *
1425 layout.spacing.getValue() *
1427 int pos_end = RowLast(row_ptr);
1431 // Check if any insets are larger
1432 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1433 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1434 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1435 tmpinset = row_ptr->par()->GetInset(pos);
1437 tmpinset->update(bview, tmpfont);
1438 asc = tmpinset->ascent(bview->painter(), tmpfont);
1439 desc = tmpinset->descent(bview->painter(), tmpfont);
1440 maxwidth += tmpinset->width(bview->painter(), tmpfont);
1441 maxasc = max(maxasc, asc);
1442 maxdesc = max(maxdesc, desc);
1445 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1449 // Check if any custom fonts are larger (Asger)
1450 // This is not completely correct, but we can live with the small,
1451 // cosmetic error for now.
1452 LyXFont::FONT_SIZE maxsize =
1453 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1455 if (maxsize > font.size()) {
1456 font.setSize(maxsize);
1458 asc = lyxfont::maxAscent(font);
1459 desc = lyxfont::maxDescent(font);
1467 /* table stuff -- begin*/
1468 if (row_ptr->par()->table){
1469 // stretch the rows a bit
1473 /* table stuff -- end*/
1476 // This is nicer with box insets:
1480 row_ptr->ascent_of_text(maxasc);
1482 /* is it a top line? */
1483 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1485 /* some parksips VERY EASY IMPLEMENTATION */
1486 if (bview->buffer()->params.paragraph_separation ==
1487 BufferParams::PARSEP_SKIP) {
1488 if (layout.isParagraph()
1489 && firstpar->GetDepth() == 0
1490 && firstpar->Previous())
1491 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1492 else if (firstpar->Previous()
1493 && textclasslist.Style(bview->buffer()->params.textclass,
1494 firstpar->Previous()->GetLayout()).isParagraph()
1495 && firstpar->Previous()->GetDepth() == 0)
1496 // is it right to use defskip here too? (AS)
1497 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1500 /* the paper margins */
1501 if (!row_ptr->par()->previous && bv_owner)
1502 maxasc += LYX_PAPER_MARGIN;
1504 /* add the vertical spaces, that the user added */
1505 if (firstpar->added_space_top.kind() != VSpace::NONE)
1506 maxasc += int(firstpar->added_space_top.inPixels(bview));
1508 /* do not forget the DTP-lines!
1509 * there height depends on the font of the nearest character */
1510 if (firstpar->line_top)
1511 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1514 /* and now the pagebreaks */
1515 if (firstpar->pagebreak_top)
1516 maxasc += 3 * DefaultHeight();
1518 /* this is special code for the chapter, since the label of this
1519 * layout is printed in an extra row */
1520 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1521 && bview->buffer()->params.secnumdepth >= 0) {
1522 float spacing_val = 1.0;
1523 if (!row_ptr->par()->spacing.isDefault()) {
1524 spacing_val = row_ptr->par()->spacing.getValue();
1526 spacing_val = bview->buffer()->params.spacing.getValue();
1529 labeladdon = int(lyxfont::maxDescent(labelfont) *
1530 layout.spacing.getValue() *
1532 + int(lyxfont::maxAscent(labelfont) *
1533 layout.spacing.getValue() *
1537 /* special code for the top label */
1538 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1539 || layout.labeltype == LABEL_BIBLIO
1540 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1541 && row_ptr->par()->IsFirstInSequence()
1542 && !row_ptr->par()->GetLabelstring().empty()) {
1543 float spacing_val = 1.0;
1544 if (!row_ptr->par()->spacing.isDefault()) {
1545 spacing_val = row_ptr->par()->spacing.getValue();
1547 spacing_val = bview->buffer()->params.spacing.getValue();
1551 (lyxfont::maxAscent(labelfont) *
1552 layout.spacing.getValue() *
1554 +(lyxfont::maxDescent(labelfont) *
1555 layout.spacing.getValue() *
1557 + layout.topsep * DefaultHeight()
1558 + layout.labelbottomsep * DefaultHeight());
1561 /* and now the layout spaces, for example before and after a section,
1562 * or between the items of a itemize or enumerate environment */
1564 if (!firstpar->pagebreak_top) {
1565 LyXParagraph * prev = row_ptr->par()->Previous();
1567 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1568 if (prev && prev->GetLayout() == firstpar->GetLayout()
1569 && prev->GetDepth() == firstpar->GetDepth()
1570 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1572 layoutasc = (layout.itemsep * DefaultHeight());
1574 else if (row_ptr->previous()) {
1575 tmptop = layout.topsep;
1577 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1578 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1579 row_ptr->previous()->par()->
1580 GetLayout()).bottomsep;
1583 layoutasc = (tmptop * DefaultHeight());
1585 else if (row_ptr->par()->line_top){
1586 tmptop = layout.topsep;
1589 layoutasc = (tmptop * DefaultHeight());
1592 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1594 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1595 prev->GetLayout()).parsep * DefaultHeight());
1598 if (firstpar->Previous()
1599 && firstpar->Previous()->GetDepth() == 0
1600 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1603 else if (firstpar->Previous()){
1604 maxasc += int(layout.parsep * DefaultHeight());
1610 /* is it a bottom line? */
1611 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1612 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1614 /* the paper margins */
1615 if (!par->next && bv_owner)
1616 maxdesc += LYX_PAPER_MARGIN;
1618 /* add the vertical spaces, that the user added */
1619 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1620 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1622 /* do not forget the DTP-lines!
1623 * there height depends on the font of the nearest character */
1624 if (firstpar->line_bottom)
1625 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1626 par, par->Last() - 1));
1628 /* and now the pagebreaks */
1629 if (firstpar->pagebreak_bottom)
1630 maxdesc += 3 * DefaultHeight();
1632 /* and now the layout spaces, for example before and after a section,
1633 * or between the items of a itemize or enumerate environment */
1634 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1635 LyXParagraph * nextpar = row_ptr->par()->Next();
1636 LyXParagraph * comparepar = row_ptr->par();
1640 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1641 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1642 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1643 if (comparepar->GetLayout()!= nextpar->GetLayout()
1644 || nextpar->GetLabelWidthString() !=
1645 comparepar->GetLabelWidthString())
1646 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1648 if (unusual > usual)
1649 layoutdesc = unusual;
1653 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1655 if (comparepar->GetLayout()!= nextpar->GetLayout()
1656 || nextpar->GetLabelWidthString() !=
1657 comparepar->GetLabelWidthString())
1658 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1663 /* incalculate the layout spaces */
1664 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1665 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1668 /* table stuff -- begin*/
1669 if (row_ptr->par()->table){
1670 maxasc += row_ptr->par()->table->
1671 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1673 /* table stuff -- end*/
1675 /* calculate the new height of the text */
1676 height -= row_ptr->height();
1678 row_ptr->height(maxasc + maxdesc + labeladdon);
1679 row_ptr->baseline(maxasc + labeladdon);
1681 height += row_ptr->height();
1686 /* Appends the implicit specified paragraph behind the specified row,
1687 * start at the implicit given position */
1688 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1690 bool not_ready = true;
1692 // The last character position of a paragraph is an invariant so we can
1693 // safely get it here. (Asger)
1694 int lastposition = row->par()->Last();
1697 // Get the next breakpoint
1698 int z = NextBreakPoint(bview, row, workWidth(bview));
1702 // Insert the new row
1703 if (z < lastposition) {
1705 InsertRow(row, row->par(), z);
1712 // Set the dimensions of the row
1713 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1714 SetHeightOfRow(bview, tmprow);
1716 } while (not_ready);
1720 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1722 bool not_ready = true;
1725 /* get the next breakpoint */
1726 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1729 if (z < row->par()->Last() ) {
1730 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1733 InsertRow(row, row->par(), z);
1739 if (row->pos() == z)
1740 not_ready = false; // the rest will not change
1746 /* if there are some rows too much, delete them */
1747 /* only if you broke the whole paragraph! */
1748 Row * tmprow2 = row;
1749 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1750 tmprow2 = tmprow2->next();
1752 while (tmprow2 != row) {
1753 tmprow2 = tmprow2->previous();
1754 RemoveRow(tmprow2->next());
1759 /* set the dimensions of the row */
1760 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1761 SetHeightOfRow(bview, tmprow);
1762 } while (not_ready);
1766 // this is just a little changed version of break again
1767 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1769 // get the next breakpoint
1770 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1773 if (z < row->par()->Last() ) {
1775 || (row->next() && row->next()->par() != row->par())) {
1776 /* insert a new row */
1778 InsertRow(row, row->par(), z);
1784 if (row->pos() != z)
1788 // if there are some rows too much, delete them
1789 // only if you broke the whole paragraph!
1790 Row * tmprow2 = row;
1791 while (tmprow2->next()
1792 && tmprow2->next()->par() == row->par()) {
1793 tmprow2 = tmprow2->next();
1795 while (tmprow2 != row) {
1796 tmprow2 = tmprow2->previous();
1797 RemoveRow(tmprow2->next());
1801 // set the dimensions of the row
1802 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1803 SetHeightOfRow(bview, tmprow);
1807 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1809 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1810 cursor.par()->GetLayout());
1812 /* table stuff -- begin */
1813 if (cursor.par()->table) {
1814 // breaking of tables is only allowed at the beginning or the end */
1815 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1816 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1817 return; // no breaking of tables allowed
1819 /* table stuff -- end */
1821 // this is only allowed, if the current paragraph is not empty or caption
1822 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1824 layout.labeltype!= LABEL_SENSITIVE)
1827 SetUndo(bview->buffer(), Undo::INSERT,
1828 cursor.par()->ParFromPos(cursor.pos())->previous,
1829 cursor.par()->ParFromPos(cursor.pos())->next);
1832 /* table stuff -- begin */
1833 if (cursor.par()->table) {
1834 int cell = NumberOfCell(cursor.par(), cursor.pos());
1835 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1836 SetCursor(bview, cursor.par(), cursor.par()->size());
1838 /* table stuff -- end */
1840 // please break always behind a space
1841 if (cursor.pos() < cursor.par()->Last()
1842 && cursor.par()->IsLineSeparator(cursor.pos()))
1843 cursor.pos(cursor.pos() + 1);
1845 // break the paragraph
1849 keep_layout = layout.isEnvironment();
1850 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1853 /* table stuff -- begin */
1854 if (cursor.par()->table){
1855 // the table should stay with the contents
1857 cursor.par()->Next()->table = cursor.par()->table;
1858 cursor.par()->table = 0;
1861 /* table stuff -- end */
1863 // well this is the caption hack since one caption is really enough
1864 if (layout.labeltype == LABEL_SENSITIVE) {
1866 // set to standard-layout
1867 cursor.par()->SetLayout(bview->buffer()->params, 0);
1869 // set to standard-layout
1870 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1873 /* if the cursor is at the beginning of a row without prior newline,
1875 * This touches only the screen-update. Otherwise we would may have
1876 * an empty row on the screen */
1877 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1878 cursor.row()->pos() == cursor.pos()) {
1882 status = LyXText::NEED_MORE_REFRESH;
1883 refresh_row = cursor.row();
1884 refresh_y = cursor.y() - cursor.row()->baseline();
1886 // Do not forget the special right address boxes
1887 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1888 while (refresh_row->previous() &&
1889 refresh_row->previous()->par() == refresh_row->par()) {
1890 refresh_row = refresh_row->previous();
1891 refresh_y -= refresh_row->height();
1894 RemoveParagraph(cursor.row());
1896 // set the dimensions of the cursor row
1897 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1899 SetHeightOfRow(bview, cursor.row());
1901 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1902 && cursor.par()->Next()->IsNewline(0))
1903 cursor.par()->Next()->Erase(0);
1905 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1907 UpdateCounters(bview, cursor.row()->previous());
1909 /* This check is necessary. Otherwise the new empty paragraph will
1910 * be deleted automatically. And it is more friendly for the user! */
1912 SetCursor(bview, cursor.par()->Next(), 0);
1914 SetCursor(bview, cursor.par(), 0);
1916 if (cursor.row()->next())
1917 BreakAgain(bview, cursor.row()->next());
1923 void LyXText::OpenFootnote(BufferView * bview)
1925 LyXParagraph * endpar,* tmppar;
1928 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1930 /* if there is no footnote in this paragraph, just return. */
1932 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1935 /* ok, move the cursor right before the footnote */
1937 /* just a little faster than using CursorRight() */
1939 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1940 cursor.pos(cursor.pos() + 1);
1943 /* now the cursor is at the beginning of the physical par */
1944 SetCursor(bview, cursor.par(),
1945 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1947 /* the cursor must be exactly before the footnote */
1948 par = cursor.par()->ParFromPos(cursor.pos());
1950 status = LyXText::NEED_MORE_REFRESH;
1951 refresh_row = cursor.row();
1952 refresh_y = cursor.y() - cursor.row()->baseline();
1954 tmppar = cursor.par();
1955 endpar = cursor.par()->Next();
1958 tmppar->OpenFootnote(cursor.pos());
1959 RemoveParagraph(row);
1960 /* set the dimensions of the cursor row */
1961 row->fill(Fill(bview, row, workWidth(bview)));
1962 SetHeightOfRow(bview, row);
1963 // CHECK See comment on top of text.C
1964 tmppar = tmppar->Next();
1966 while (tmppar != endpar) {
1968 InsertParagraph(bview, tmppar, row);
1969 while (row->next() && row->next()->par() == tmppar)
1971 tmppar = tmppar->Next();
1974 SetCursor(bview, par->next, 0);
1975 sel_cursor = cursor;
1979 /* table stuff -- begin*/
1981 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
1983 if (!cursor.par()->table)
1984 return; /* this should never happen */
1986 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1987 SetUndo(bview->buffer(), Undo::FINISH,
1988 cursor.par()->ParFromPos(cursor.pos())->previous,
1989 cursor.par()->ParFromPos(cursor.pos())->next);
1992 case LyXTable::SET_PWIDTH:
1993 cursor.par()->table->SetPWidth(actCell, val);
1995 case LyXTable::SET_SPECIAL_COLUMN:
1996 case LyXTable::SET_SPECIAL_MULTI:
1997 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2002 RedoParagraph(bview);
2006 void LyXText::TableFeatures(BufferView * bview, int feature) const
2009 int setAlign = LYX_ALIGN_LEFT;
2013 if (!cursor.par()->table)
2014 return; /* this should never happen */
2016 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2017 SetUndo(bview->buffer(), Undo::FINISH,
2018 cursor.par()->ParFromPos(cursor.pos())->previous,
2019 cursor.par()->ParFromPos(cursor.pos())->next);
2022 case LyXTable::ALIGN_LEFT:
2023 setAlign= LYX_ALIGN_LEFT;
2025 case LyXTable::ALIGN_RIGHT:
2026 setAlign= LYX_ALIGN_RIGHT;
2028 case LyXTable::ALIGN_CENTER:
2029 setAlign= LYX_ALIGN_CENTER;
2035 case LyXTable::APPEND_ROW: {
2036 LyXParagraph::size_type pos = cursor.pos();
2038 /* move to the next row */
2039 int cell_org = actCell;
2040 int cell = cell_org;
2042 // if there is a ContRow following this row I have to add
2043 // the row after the ContRow's
2044 if ((pos < cursor.par()->Last()) &&
2045 cursor.par()->table->RowHasContRow(cell_org)) {
2046 while((pos < cursor.par()->Last()) &&
2047 !cursor.par()->table->IsContRow(cell)) {
2048 while (pos < cursor.par()->Last() &&
2049 !cursor.par()->IsNewline(pos))
2051 if (pos < cursor.par()->Last())
2055 while((pos < cursor.par()->Last()) &&
2056 cursor.par()->table->IsContRow(cell)) {
2057 while (pos < cursor.par()->Last() &&
2058 !cursor.par()->IsNewline(pos))
2060 if (pos < cursor.par()->Last())
2065 if (pos < cursor.par()->Last())
2068 while (pos < cursor.par()->Last() &&
2069 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2070 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2072 if (pos < cursor.par()->Last())
2077 /* insert the new cells */
2078 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2079 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2080 LyXFont font(LyXFont::ALL_INHERIT,lang);
2081 for (int i = 0; i < number; ++i) {
2082 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2083 cursor.par()->SetFont(pos, font);
2086 /* append the row into the table */
2087 cursor.par()->table->AppendRow(cell_org);
2088 RedoParagraph(bview);
2091 case LyXTable::APPEND_CONT_ROW: {
2092 LyXParagraph::size_type pos = cursor.pos();
2093 /* move to the next row */
2094 int cell_org = actCell;
2095 int cell = cell_org;
2097 // if there is already a controw but not for this cell
2098 // the AppendContRow sets only the right values but does
2099 // not actually add a row
2100 if (cursor.par()->table->RowHasContRow(cell_org) &&
2101 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2102 cursor.par()->table->AppendContRow(cell_org);
2103 RedoParagraph(bview);
2106 while (pos < cursor.par()->Last() &&
2108 || !cursor.par()->table->IsFirstCell(cell))){
2109 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2111 if (pos < cursor.par()->Last())
2116 /* insert the new cells */
2117 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2118 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2119 LyXFont font(LyXFont::ALL_INHERIT,lang);
2120 for (int i = 0; i < number; ++i) {
2121 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2122 cursor.par()->SetFont(pos, font);
2125 /* append the row into the table */
2126 cursor.par()->table->AppendContRow(cell_org);
2127 RedoParagraph(bview);
2130 case LyXTable::APPEND_COLUMN: {
2131 LyXParagraph::size_type pos = 0;
2132 int cell_org = actCell;
2134 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2135 LyXFont font(LyXFont::ALL_INHERIT,lang);
2137 if (pos && (cursor.par()->IsNewline(pos-1))){
2138 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2139 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2140 cursor.par()->SetFont(pos, font);
2141 if (pos <= cursor.pos())
2142 cursor.pos(cursor.pos() + 1);
2148 } while (pos <= cursor.par()->Last());
2149 /* remember that the very last cell doesn't end with a newline.
2150 This saves one byte memory per table ;-) */
2151 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2152 LyXParagraph::size_type last = cursor.par()->Last();
2153 cursor.par()->InsertChar(last, LyXParagraph::META_NEWLINE);
2154 cursor.par()->SetFont(last, font);
2157 /* append the column into the table */
2158 cursor.par()->table->AppendColumn(cell_org);
2160 RedoParagraph(bview);
2163 case LyXTable::DELETE_ROW:
2164 if (bview->the_locking_inset)
2165 bview->unlockInset(bview->the_locking_inset);
2166 RemoveTableRow(cursor);
2167 RedoParagraph(bview);
2170 case LyXTable::DELETE_COLUMN: {
2171 LyXParagraph::size_type pos = 0;
2172 int cell_org = actCell;
2174 if (bview->the_locking_inset)
2175 bview->unlockInset(bview->the_locking_inset);
2177 if (!pos || (cursor.par()->IsNewline(pos-1))){
2178 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2180 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2181 cursor.par()->Erase(pos);
2182 if (pos < cursor.par()->Last())
2183 cursor.par()->Erase(pos);
2185 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2186 --pos; // because of pos++ below
2191 } while (pos <= cursor.par()->Last());
2193 /* delete the column from the table */
2194 cursor.par()->table->DeleteColumn(cell_org);
2196 /* set the cursor to the beginning of the table, where else? */
2198 RedoParagraph(bview);
2201 case LyXTable::TOGGLE_LINE_TOP:
2202 lineSet = !cursor.par()->table->TopLine(actCell);
2204 cursor.par()->table->SetTopLine(actCell, lineSet);
2206 LyXParagraph::size_type i;
2208 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2209 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2210 cursor.par()->table->SetTopLine(n, lineSet);
2215 RedoParagraph(bview);
2218 case LyXTable::TOGGLE_LINE_BOTTOM:
2219 lineSet = !cursor.par()->table->BottomLine(actCell);
2221 cursor.par()->table->SetBottomLine(actCell, lineSet);
2223 LyXParagraph::size_type i;
2225 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2226 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2227 cursor.par()->table->SetBottomLine(n, lineSet);
2232 RedoParagraph(bview);
2235 case LyXTable::TOGGLE_LINE_LEFT:
2236 lineSet = !cursor.par()->table->LeftLine(actCell);
2238 cursor.par()->table->SetLeftLine(actCell, lineSet);
2240 LyXParagraph::size_type i;
2242 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2243 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2244 cursor.par()->table->SetLeftLine(n, lineSet);
2249 RedoParagraph(bview);
2252 case LyXTable::TOGGLE_LINE_RIGHT:
2253 lineSet = !cursor.par()->table->RightLine(actCell);
2255 cursor.par()->table->SetRightLine(actCell, lineSet);
2258 LyXParagraph::size_type i = sel_start_cursor.pos();
2259 for (; i <= sel_end_cursor.pos(); ++i) {
2260 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2261 cursor.par()->table->SetRightLine(n, lineSet);
2266 RedoParagraph(bview);
2269 case LyXTable::ALIGN_LEFT:
2270 case LyXTable::ALIGN_RIGHT:
2271 case LyXTable::ALIGN_CENTER:
2273 cursor.par()->table->SetAlignment(actCell, setAlign);
2276 LyXParagraph::size_type i = sel_start_cursor.pos();
2277 for (; i <= sel_end_cursor.pos(); ++i) {
2278 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2279 cursor.par()->table->SetAlignment(n, setAlign);
2284 RedoParagraph(bview);
2287 case LyXTable::DELETE_TABLE:
2288 SetCursorIntern(bview, cursor.par(), 0);
2289 delete cursor.par()->table;
2290 cursor.par()->table = 0;
2291 // temporary: Should put table in simple_cut_buffer (with before and after
2292 // dummy-paragraph !!
2293 // not necessar anymore with UNDO :)
2294 for (LyXParagraph::size_type i =
2295 cursor.par()->size() - 1; i >= 0; --i)
2296 cursor.par()->Erase(i);
2297 RedoParagraph(bview);
2300 case LyXTable::MULTICOLUMN: {
2302 // check wether we are completly in a multicol
2303 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2304 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2305 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2306 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2310 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2311 LyXParagraph::size_type pos = cursor.pos();
2312 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2314 for (; newlines; --newlines)
2315 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2316 RedoParagraph(bview);
2320 // selection must be in one row (or no selection)
2322 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2325 RedoParagraph(bview);
2329 if (sel_start_cursor.row() == sel_end_cursor.row()){
2330 LyXParagraph::size_type i;
2332 for (i = sel_start_cursor.pos();
2333 i < sel_end_cursor.pos(); ++i){
2334 if (sel_start_cursor.par()->IsNewline(i)){
2335 sel_start_cursor.par()->Erase(i);
2336 // check for double-blanks
2337 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2339 (i < sel_start_cursor.par()->Last()
2340 && !sel_start_cursor.par()->IsLineSeparator(i)))
2341 sel_start_cursor.par()->InsertChar(i, ' ');
2343 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2349 cursor.par()->table->
2350 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2351 sel_start_cursor.pos()),
2353 cursor.pos(sel_start_cursor.pos());
2354 RedoParagraph(bview);
2358 WriteAlert(_("Impossible Operation!"),
2359 _("Multicolumns can only be horizontally."),
2366 case LyXTable::SET_ALL_LINES:
2368 case LyXTable::UNSET_ALL_LINES:
2370 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2374 LyXParagraph::size_type i;
2376 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2377 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2378 cursor.par()->table->SetAllLines(n, setLines);
2383 RedoParagraph(bview);
2385 case LyXTable::SET_LONGTABLE:
2386 cursor.par()->table->SetLongTable(true);
2388 case LyXTable::UNSET_LONGTABLE:
2389 cursor.par()->table->SetLongTable(false);
2391 case LyXTable::SET_ROTATE_TABLE:
2392 cursor.par()->table->SetRotateTable(true);
2394 case LyXTable::UNSET_ROTATE_TABLE:
2395 cursor.par()->table->SetRotateTable(false);
2397 case LyXTable::SET_ROTATE_CELL:
2399 cursor.par()->table->SetRotateCell(actCell, true);
2401 LyXParagraph::size_type i;
2403 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2404 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2405 cursor.par()->table->SetRotateCell(n, true);
2411 case LyXTable::UNSET_ROTATE_CELL:
2413 cursor.par()->table->SetRotateCell(actCell, false);
2416 LyXParagraph::size_type i = sel_start_cursor.pos();
2417 for (; i <= sel_end_cursor.pos(); ++i) {
2418 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2419 cursor.par()->table->SetRotateCell(n, false);
2425 case LyXTable::SET_LINEBREAKS:
2426 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2428 cursor.par()->table->SetLinebreaks(actCell, what);
2430 LyXParagraph::size_type i;
2432 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2433 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2434 cursor.par()->table->SetLinebreaks(n, what);
2440 case LyXTable::SET_LTFIRSTHEAD:
2441 cursor.par()->table->SetLTHead(actCell, true);
2443 case LyXTable::SET_LTHEAD:
2444 cursor.par()->table->SetLTHead(actCell, false);
2446 case LyXTable::SET_LTFOOT:
2447 cursor.par()->table->SetLTFoot(actCell, false);
2449 case LyXTable::SET_LTLASTFOOT:
2450 cursor.par()->table->SetLTFoot(actCell, true);
2452 case LyXTable::SET_LTNEWPAGE:
2453 what = !cursor.par()->table->LTNewPage(actCell);
2454 cursor.par()->table->SetLTNewPage(actCell, what);
2460 void LyXText::InsertCharInTable(BufferView * bview, char c)
2465 bool jumped_over_space;
2467 /* first check, if there will be two blanks together or a blank at
2468 * the beginning of a paragraph.
2469 * I decided to handle blanks like normal characters, the main
2470 * difference are the special checks when calculating the row.fill
2471 * (blank does not count at the end of a row) and the check here */
2473 LyXFont realtmpfont = real_current_font;
2474 LyXFont rawtmpfont = current_font; /* store the current font.
2475 * This is because of the use
2476 * of cursor movements. The moving
2477 * cursor would refresh the
2480 // Get the font that is used to calculate the baselineskip
2481 LyXParagraph::size_type const lastpos =
2482 cursor.par()->Last();
2483 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2486 jumped_over_space = false;
2487 if (IsLineSeparatorChar(c)) {
2488 if ((cursor.pos() > 0 &&
2489 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2490 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2491 || (cursor.pos() == 0 &&
2492 !(cursor.par()->Previous()
2493 && cursor.par()->Previous()->footnoteflag
2494 == LyXParagraph::OPEN_FOOTNOTE)))
2496 } else if (IsNewlineChar(c)) {
2497 if (!IsEmptyTableCell()) {
2498 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2505 y = cursor.y() - row->baseline();
2506 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2507 * already inserted the character */
2508 cursor.par()->InsertChar(cursor.pos(), c);
2509 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2511 if (!jumped_over_space) {
2512 /* refresh the positions */
2514 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2515 tmprow = tmprow->next();
2516 tmprow->pos(tmprow->pos() + 1);
2520 cursor.pos(cursor.pos() + 1);
2522 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2524 current_font = rawtmpfont;
2525 real_current_font = realtmpfont;
2527 /* check, whether the last character's font has changed. */
2528 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2529 && rawparfont != rawtmpfont)
2530 RedoHeightOfParagraph(bview, cursor);
2534 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2535 LyXParagraph::size_type pos)
2538 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2539 par->GetInset(pos) && par->GetInset(pos)->display()){
2540 par->GetInset(pos)->display(false);
2544 Row * row = GetRow(par, pos, y);
2546 int tmpheight = row->height();
2547 SetHeightOfRow(bview, row);
2549 LyXParagraph::size_type tmp_pos = pos;
2550 /* update the table information */
2551 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2553 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2554 WidthOfCell(bview, par, tmp_pos))) {
2555 LyXCursor tmpcursor = cursor;
2556 SetCursorIntern(bview, par, pos, false);
2557 /* make a complete redraw */
2558 RedoDrawingOfParagraph(bview, cursor);
2562 /* redraw only the row */
2563 LyXCursor tmpcursor = cursor;
2564 SetCursorIntern(bview, par, pos);
2565 //CHECK See comment on top of text.C
2567 refresh_x = cursor.x();
2569 refresh_pos = cursor.pos();
2572 if (tmpheight == row->height())
2573 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2575 status = LyXText::NEED_MORE_REFRESH;
2577 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2582 void LyXText::BackspaceInTable(BufferView * bview)
2584 Row * tmprow, * row;
2587 LyXFont rawtmpfont = current_font;
2588 LyXFont realtmpfont = real_current_font;
2590 // Get the font that is used to calculate the baselineskip
2591 int const lastpos = cursor.par()->Last();
2592 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2595 if (cursor.pos() == 0) {
2596 /* no pasting of table paragraphs */
2600 /* this is the code for a normal backspace, not pasting
2602 SetUndo(bview->buffer(), Undo::DELETE,
2603 cursor.par()->ParFromPos(cursor.pos())->previous,
2604 cursor.par()->ParFromPos(cursor.pos())->next);
2606 CursorLeftIntern(bview);
2608 /* some insets are undeletable here */
2609 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2610 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2615 y = cursor.y() - row->baseline();
2617 /* some special code when deleting a newline. */
2618 if (cursor.par()->IsNewline(cursor.pos())) {
2622 cursor.par()->Erase(cursor.pos());
2624 /* refresh the positions */
2626 while (tmprow->next()
2627 && tmprow->next()->par() == row->par()) {
2628 tmprow = tmprow->next();
2629 tmprow->pos(tmprow->pos() - 1);
2633 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2635 /* check, wether the last characters font has changed. */
2636 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2637 && rawparfont != rawtmpfont)
2638 RedoHeightOfParagraph(bview, cursor);
2640 /* restore the current font
2641 * That is what a user expects! */
2642 current_font = rawtmpfont;
2643 real_current_font = realtmpfont;
2645 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2647 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2648 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2651 /* table stuff -- end*/
2654 // Just a macro to make some thing easier.
2655 void LyXText::RedoParagraph(BufferView * bview) const
2658 RedoParagraphs(bview, cursor, cursor.par()->Next());
2659 SetCursorIntern(bview, cursor.par(), cursor.pos());
2663 /* insert a character, moves all the following breaks in the
2664 * same Paragraph one to the right and make a rebreak */
2665 void LyXText::InsertChar(BufferView * bview, char c)
2667 SetUndo(bview->buffer(), Undo::INSERT,
2668 cursor.par()->ParFromPos(cursor.pos())->previous,
2669 cursor.par()->ParFromPos(cursor.pos())->next);
2671 // When the free-spacing option is set for the current layout,
2672 // disable the double-space checking
2675 textclasslist.Style(bview->buffer()->params.textclass,
2676 cursor.row()->par()->GetLayout()).free_spacing;
2679 /* table stuff -- begin*/
2680 if (cursor.par()->table) {
2681 InsertCharInTable(bview, c);
2685 /* table stuff -- end*/
2687 /* First check, if there will be two blanks together or a blank at
2688 the beginning of a paragraph.
2689 I decided to handle blanks like normal characters, the main
2690 difference are the special checks when calculating the row.fill
2691 (blank does not count at the end of a row) and the check here */
2693 // The bug is triggered when we type in a description environment:
2694 // The current_font is not changed when we go from label to main text
2695 // and it should (along with realtmpfont) when we type the space.
2696 // CHECK There is a bug here! (Asger)
2698 LyXFont realtmpfont = real_current_font;
2699 LyXFont rawtmpfont = current_font; /* store the current font.
2700 * This is because of the use
2701 * of cursor movements. The moving
2702 * cursor would refresh the
2705 // Get the font that is used to calculate the baselineskip
2706 LyXParagraph::size_type lastpos = cursor.par()->Last();
2707 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2710 bool jumped_over_space = false;
2712 if (!freeSpacing && IsLineSeparatorChar(c)) {
2713 if ((cursor.pos() > 0
2714 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2715 || (cursor.pos() > 0
2716 && cursor.par()->IsNewline(cursor.pos() - 1))
2717 || (cursor.pos() == 0
2718 && !(cursor.par()->Previous()
2719 && cursor.par()->Previous()->footnoteflag
2720 == LyXParagraph::OPEN_FOOTNOTE))) {
2721 if (cursor.pos() == 0 )
2722 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2724 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2728 } else if (IsNewlineChar(c)) {
2729 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2730 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2734 /* No newline at first position
2735 * of a paragraph or behind labels.
2736 * TeX does not allow that. */
2738 if (cursor.pos() < cursor.par()->Last() &&
2739 cursor.par()->IsLineSeparator(cursor.pos()))
2740 // newline always after a blank!
2741 CursorRightIntern(bview);
2742 cursor.row()->fill(-1); // to force a new break
2745 // the display inset stuff
2746 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2747 && cursor.row()->par()->GetInset(cursor.row()->pos())
2748 && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
2749 cursor.row()->fill(-1); // to force a new break
2751 // get the cursor row fist
2752 Row * row = cursor.row();
2753 long y = cursor.y() - row->baseline();
2754 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2755 * already insertet the character */
2756 cursor.par()->InsertChar(cursor.pos(), c);
2757 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2759 if (!jumped_over_space) {
2760 // refresh the positions
2762 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2763 tmprow = tmprow->next();
2764 tmprow->pos(tmprow->pos() + 1);
2768 // Is there a break one row above
2769 if ((cursor.par()->IsLineSeparator(cursor.pos())
2770 || cursor.par()->IsNewline(cursor.pos())
2771 || cursor.row()->fill() == -1)
2772 && row->previous() && row->previous()->par() == row->par()) {
2773 LyXParagraph::size_type z = NextBreakPoint(bview,
2776 if ( z >= row->pos()) {
2779 // set the dimensions of the row above
2780 row->previous()->fill(Fill(bview,
2784 SetHeightOfRow(bview, row->previous());
2786 y -= row->previous()->height();
2788 refresh_row = row->previous();
2789 status = LyXText::NEED_MORE_REFRESH;
2791 BreakAgainOneRow(bview, row);
2793 current_font = rawtmpfont;
2794 real_current_font = realtmpfont;
2795 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2796 false, cursor.boundary());
2797 // cursor MUST be in row now.
2799 if (row->next() && row->next()->par() == row->par())
2800 need_break_row = row->next();
2804 // check, wether the last characters font has changed.
2805 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2806 && rawparfont != rawtmpfont)
2807 RedoHeightOfParagraph(bview, cursor);
2814 // recalculate the fill of the row
2815 if (row->fill() >= 0) /* needed because a newline
2816 * will set fill to -1. Otherwise
2817 * we would not get a rebreak! */
2818 row->fill(Fill(bview, row, workWidth(bview)));
2819 if (row->fill() < 0 ) {
2822 refresh_x = cursor.x();
2823 refresh_pos = cursor.pos();
2824 status = LyXText::NEED_MORE_REFRESH;
2825 BreakAgainOneRow(bview, row);
2826 // will the cursor be in another row now?
2827 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2828 if (row->next() && row->next()->par() == row->par())
2829 // this should always be true
2831 BreakAgainOneRow(bview, row);
2833 current_font = rawtmpfont;
2834 real_current_font = realtmpfont;
2836 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2838 if (row->next() && row->next()->par() == row->par())
2839 need_break_row = row->next();
2844 refresh_x = cursor.x();
2846 refresh_pos = cursor.pos();
2848 int tmpheight = row->height();
2849 SetHeightOfRow(bview, row);
2850 if (tmpheight == row->height())
2851 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2853 status = LyXText::NEED_MORE_REFRESH;
2855 current_font = rawtmpfont;
2856 real_current_font = realtmpfont;
2857 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2861 // check, wether the last characters font has changed.
2862 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2863 && rawparfont != rawtmpfont) {
2864 RedoHeightOfParagraph(bview, cursor);
2866 // now the special right address boxes
2867 if (textclasslist.Style(bview->buffer()->params.textclass,
2868 cursor.par()->GetLayout()).margintype
2869 == MARGIN_RIGHT_ADDRESS_BOX) {
2870 RedoDrawingOfParagraph(bview, cursor);
2878 void LyXText::charInserted()
2880 // Here we could call FinishUndo for every 20 characters inserted.
2881 // This is from my experience how emacs does it.
2882 static unsigned int counter = 0;
2891 void LyXText::PrepareToPrint(BufferView * bview,
2892 Row * row, float & x,
2893 float & fill_separator,
2895 float & fill_label_hfill,
2900 float w = row->fill();
2902 fill_label_hfill = 0;
2904 fill_label_hfill = 0;
2906 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2909 x = RightMargin(bview->buffer(), row);
2910 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2911 LyXFont font(LyXFont::ALL_SANE);
2912 font.setSize(LyXFont::SIZE_SMALL);
2913 x += lyxfont::width("Mwide-figM", font);
2915 } else if (workWidth(bview) > 0)
2916 x = LeftMargin(bview, row);
2920 // is there a manual margin with a manual label
2921 if (textclasslist.Style(bview->buffer()->params.textclass,
2922 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2923 && textclasslist.Style(bview->buffer()->params.textclass,
2924 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2926 /* one more since labels are left aligned */
2927 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2928 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2929 fill_label_hfill = LabelFill(bview, row) / nlh;
2933 // are there any hfills in the row?
2934 float nh = NumberOfHfills(bview->buffer(), row);
2937 /* table stuff -- begin*/
2938 if (row->par()->table) {
2939 w = workWidth(bview) - row->par()->table->WidthOfTable()
2940 - x - RightMargin(bview->buffer(), row);
2941 nh = 0; /* ignore hfills in tables */
2943 /* table stuff -- end*/
2948 // is it block, flushleft or flushright?
2949 // set x how you need it
2951 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2952 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2954 align = row->par()->FirstPhysicalPar()->align;
2956 // center displayed insets
2957 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2958 && row->par()->GetInset(row->pos())
2959 && row->par()->GetInset(row->pos())->display())
2960 align = LYX_ALIGN_CENTER;
2963 case LYX_ALIGN_BLOCK:
2964 ns = NumberOfSeparators(bview->buffer(), row);
2965 if (ns && row->next() && row->next()->par() == row->par() &&
2966 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2967 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2968 && row->next()->par()->GetInset(row->next()->pos())
2969 && row->next()->par()->GetInset(row->next()->pos())->display())
2971 fill_separator = w / ns;
2975 case LYX_ALIGN_RIGHT:
2978 case LYX_ALIGN_CENTER:
2986 ComputeBidiTables(bview->buffer(), row);
2988 LyXParagraph::size_type main_body =
2989 BeginningOfMainBody(bview->buffer(), row->par());
2990 LyXParagraph::size_type last = RowLast(row);
2992 if (main_body > 0 &&
2993 (main_body-1 > last ||
2994 !row->par()->IsLineSeparator(main_body-1))) {
2995 LyXLayout const & layout =
2996 textclasslist.Style(bview->buffer()->params.textclass,
2997 row->par()->GetLayout());
2998 x += lyxfont::width(layout.labelsep,
2999 GetFont(bview->buffer(), row->par(), -2));
3000 if (main_body-1 <= last)
3001 x += fill_label_hfill;
3006 /* important for the screen */
3009 /* the cursor set functions have a special mechanism. When they
3010 * realize, that you left an empty paragraph, they will delete it.
3011 * They also delete the corresponding row */
3013 void LyXText::CursorRightOneWord(BufferView * bview) const
3015 // treat floats, HFills and Insets as words
3016 LyXCursor tmpcursor = cursor;
3017 // CHECK See comment on top of text.C
3019 if (tmpcursor.pos() == tmpcursor.par()->Last()
3020 && tmpcursor.par()->Next()) {
3021 tmpcursor.par(tmpcursor.par()->Next());
3026 // Skip through initial nonword stuff.
3027 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3028 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3030 // printf("Current pos1 %d", tmpcursor.pos()) ;
3031 tmpcursor.pos(tmpcursor.pos() + 1);
3034 // Advance through word.
3035 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3036 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3038 // printf("Current pos2 %d", tmpcursor.pos()) ;
3039 tmpcursor.pos(tmpcursor.pos() + 1);
3043 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3047 void LyXText::CursorTab(BufferView * bview) const
3050 if (cursor.par()->table) {
3051 int cell = NumberOfCell(cursor.par(), cursor.pos());
3052 while(cursor.par()->table->IsContRow(cell)) {
3054 cell = NumberOfCell(cursor.par(), cursor.pos());
3056 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3057 TableFeatures(bview, LyXTable::APPEND_ROW);
3060 LyXCursor tmpcursor = cursor;
3061 while (tmpcursor.pos() < tmpcursor.par()->Last()
3062 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3063 tmpcursor.pos(tmpcursor.pos() + 1);
3065 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3066 if (tmpcursor.par()->Next()) {
3067 tmpcursor.par(tmpcursor.par()->Next());
3071 tmpcursor.pos(tmpcursor.pos() + 1);
3072 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3074 if (cursor.par()->table) {
3075 int cell = NumberOfCell(cursor.par(), cursor.pos());
3076 while (cursor.par()->table->IsContRow(cell) &&
3077 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3079 while (tmpcursor.pos() < tmpcursor.par()->Last()
3080 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3081 tmpcursor.pos(tmpcursor.pos() + 1);
3083 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3084 if (tmpcursor.par()->Next()) {
3085 tmpcursor.par(tmpcursor.par()->Next());
3089 tmpcursor.pos(tmpcursor.pos() + 1);
3090 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3091 cell = NumberOfCell(cursor.par(), cursor.pos());
3098 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3099 of prior word, not to end of next prior word. */
3101 void LyXText::CursorLeftOneWord(BufferView * bview) const
3103 // treat HFills, floats and Insets as words
3104 LyXCursor tmpcursor = cursor;
3105 while (tmpcursor.pos()
3106 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3107 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3108 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3109 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3110 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3111 tmpcursor.pos(tmpcursor.pos() - 1);
3114 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3115 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3116 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3117 tmpcursor.pos(tmpcursor.pos() - 1);
3118 } else if (!tmpcursor.pos()) {
3119 if (tmpcursor.par()->Previous()){
3120 tmpcursor.par(tmpcursor.par()->Previous());
3121 tmpcursor.pos(tmpcursor.par()->Last());
3123 } else { // Here, tmpcursor != 0
3124 while (tmpcursor.pos() > 0 &&
3125 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3126 tmpcursor.pos(tmpcursor.pos() - 1);
3128 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3131 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3134 void LyXText::SelectWord(BufferView * bview)
3136 // Move cursor to the beginning, when not already there.
3138 && !cursor.par()->IsSeparator(cursor.pos()-1)
3139 && !cursor.par()->IsKomma(cursor.pos()-1) )
3140 CursorLeftOneWord(bview);
3142 // set the sel cursor
3143 sel_cursor = cursor;
3145 while ( cursor.pos() < cursor.par()->Last()
3146 && !cursor.par()->IsSeparator(cursor.pos())
3147 && !cursor.par()->IsKomma(cursor.pos()) )
3148 cursor.pos(cursor.pos() + 1);
3149 SetCursor(bview, cursor.par(), cursor.pos() );
3151 // finally set the selection
3156 /* -------> Select the word currently under the cursor when:
3157 1: no selection is currently set,
3158 2: the cursor is not at the borders of the word. */
3160 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3163 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3164 && !cursor.par()->IsSeparator(cursor.pos())
3165 && !cursor.par()->IsKomma(cursor.pos())
3166 && !cursor.par()->IsSeparator(cursor.pos() -1)
3167 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3175 // This function is only used by the spellchecker for NextWord().
3176 // It doesn't handle LYX_ACCENTs and probably never will.
3177 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3179 LyXParagraph * tmppar = cursor.par();
3181 // If this is not the very first word, skip rest of
3182 // current word because we are probably in the middle
3183 // of a word if there is text here.
3184 if (cursor.pos() || cursor.par()->previous) {
3185 while (cursor.pos() < cursor.par()->Last()
3186 && cursor.par()->IsLetter(cursor.pos()))
3187 cursor.pos(cursor.pos() + 1);
3189 // Now, skip until we have real text (will jump paragraphs)
3190 while ((cursor.par()->Last() > cursor.pos()
3191 && (!cursor.par()->IsLetter(cursor.pos())
3192 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3193 .latex() == LyXFont::ON))
3194 || (cursor.par()->Last() == cursor.pos()
3195 && cursor.par()->Next())){
3196 if (cursor.pos() == cursor.par()->Last()) {
3197 cursor.par(cursor.par()->Next());
3200 cursor.pos(cursor.pos() + 1);
3203 // Update the value if we changed paragraphs
3204 if (cursor.par() != tmppar){
3205 SetCursor(bview, cursor.par(), cursor.pos());
3206 value = float(cursor.y())/float(height);
3209 // Start the selection from here
3210 sel_cursor = cursor;
3213 std::ostringstream latex;
3217 // and find the end of the word
3218 // (optional hyphens are part of a word)
3219 while (cursor.pos() < cursor.par()->Last()
3220 && (cursor.par()->IsLetter(cursor.pos()))
3221 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3222 && cursor.par()->GetInset(cursor.pos()) != 0
3223 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3225 && latex.str() == "\\-"
3227 && latex.str() // protect against null pointers
3228 && string(latex.str(), 3) == "\\-" // this is not nice at all
3231 cursor.pos(cursor.pos() + 1);
3233 #ifndef HAVE_SSTREAM
3234 delete [] latex.str();
3236 // Finally, we copy the word to a string and return it
3239 if (sel_cursor.pos() < cursor.pos()) {
3240 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3241 LyXParagraph::size_type i, j;
3242 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3243 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3244 str[j++] = cursor.par()->GetChar(i);
3252 // This one is also only for the spellchecker
3253 void LyXText::SelectSelectedWord(BufferView * bview)
3255 // move cursor to the beginning
3256 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3258 // set the sel cursor
3259 sel_cursor = cursor;
3262 std::ostringstream latex;
3267 // now find the end of the word
3268 while (cursor.pos() < cursor.par()->Last()
3269 && (cursor.par()->IsLetter(cursor.pos())
3270 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3271 && cursor.par()->GetInset(cursor.pos()) != 0
3272 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3274 && latex.str() == "\\-"
3276 && string(latex.str(), 3) == "\\-"
3279 cursor.pos(cursor.pos() + 1);
3281 #ifndef HAVE_SSTREAM
3282 delete [] latex.str();
3284 SetCursor(bview, cursor.par(), cursor.pos());
3286 // finally set the selection
3291 /* -------> Delete from cursor up to the end of the current or next word. */
3292 void LyXText::DeleteWordForward(BufferView * bview)
3294 if (!cursor.par()->Last())
3297 LyXCursor tmpcursor = cursor;
3298 tmpcursor.row(0); //Â ??
3299 selection = true; // to avoid deletion
3300 CursorRightOneWord(bview);
3301 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3302 sel_cursor = cursor;
3306 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3307 CutSelection(bview);
3312 /* -------> Delete from cursor to start of current or prior word. */
3313 void LyXText::DeleteWordBackward(BufferView * bview)
3315 if (!cursor.par()->Last())
3318 LyXCursor tmpcursor = cursor;
3319 tmpcursor.row(0); // ??
3320 selection = true; // to avoid deletion
3321 CursorLeftOneWord(bview);
3322 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3323 sel_cursor = cursor;
3326 CutSelection(bview);
3331 /* -------> Kill to end of line. */
3332 void LyXText::DeleteLineForward(BufferView * bview)
3334 if (!cursor.par()->Last())
3335 // Paragraph is empty, so we just go to the right
3338 LyXCursor tmpcursor = cursor;
3339 // We can't store the row over a regular SetCursor
3340 // so we set it to 0 and reset it afterwards.
3341 tmpcursor.row(0); //Â ??
3342 selection = true; // to avoid deletion
3344 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3345 sel_cursor = cursor;
3348 // What is this test for ??? (JMarc)
3350 DeleteWordForward(bview);
3352 CutSelection(bview);
3358 // Change the case of a word at cursor position.
3359 // This function directly manipulates LyXParagraph::text because there
3360 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3361 // that it is correct. I guess part of it should be moved to
3362 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3363 // it does not access outside of the allocated array as the older
3364 // version did. (JMarc)
3365 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3367 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3369 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3371 LyXParagraph::size_type tmppos =
3372 cursor.par()->PositionInParFromPos(cursor.pos());
3373 while (tmppos < tmppar->size()) {
3374 unsigned char c = tmppar->GetChar(tmppos);
3375 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3377 if (c != LyXParagraph::META_INSET) {
3379 case text_lowercase:
3382 case text_capitalization:
3384 action = text_lowercase;
3386 case text_uppercase:
3392 //tmppar->text[tmppos] = c;
3393 tmppar->SetChar(tmppos, c);
3396 CheckParagraph(bview, tmppar, tmppos);
3397 CursorRightOneWord(bview);
3401 void LyXText::Delete(BufferView * bview)
3403 // this is a very easy implementation
3405 LyXCursor old_cursor = cursor;
3406 int old_cur_par_id = old_cursor.par()->id();
3407 int old_cur_par_prev_id = old_cursor.par()->previous ?
3408 old_cursor.par()->previous->id() : 0;
3410 // just move to the right
3411 CursorRightIntern(bview);
3413 // CHECK Look at the comment here.
3414 // This check is not very good...
3415 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3416 // and that can very well delete the par or par->previous in
3417 // old_cursor. Will a solution where we compare paragraph id's
3419 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3420 == old_cur_par_prev_id
3421 && cursor.par()->id() != old_cur_par_id)
3422 return; // delete-empty-paragraph-mechanism has done it
3424 // if you had success make a backspace
3425 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3426 LyXCursor tmpcursor = cursor;
3427 cursor = old_cursor; // to make sure undo gets the right cursor position
3428 SetUndo(bview->buffer(), Undo::DELETE,
3429 cursor.par()->ParFromPos(cursor.pos())->previous,
3430 cursor.par()->ParFromPos(cursor.pos())->next);
3437 void LyXText::Backspace(BufferView * bview)
3440 /* table stuff -- begin */
3441 if (cursor.par()->table) {
3442 BackspaceInTable(bview);
3445 /* table stuff -- end */
3447 // LyXFont rawtmpfont = current_font;
3448 // LyXFont realtmpfont = real_current_font;
3449 // We don't need the above variables as calling to SetCursor() with third
3450 // argument eqaul to false, will not change current_font & real_current_font
3452 // Get the font that is used to calculate the baselineskip
3453 LyXParagraph::size_type lastpos = cursor.par()->Last();
3454 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3457 if (cursor.pos() == 0) {
3458 // The cursor is at the beginning of a paragraph, so the the backspace
3459 // will collapse two paragraphs into one.
3461 // we may paste some paragraphs
3463 // is it an empty paragraph?
3466 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3467 && !(cursor.par()->Next()
3468 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3469 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3470 // This is an empty paragraph and we delete it just by moving the cursor one step
3471 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3472 // of the paragraph.
3474 if (cursor.par()->previous) {
3475 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3476 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3477 && cursor.par()->footnoteflag == tmppar->footnoteflag
3478 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3479 // Inherit botom DTD from the paragraph below.
3480 // (the one we are deleting)
3481 tmppar->line_bottom = cursor.par()->line_bottom;
3482 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3483 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3486 CursorLeftIntern(bview);
3488 // the layout things can change the height of a row !
3489 int tmpheight = cursor.row()->height();
3490 SetHeightOfRow(bview, cursor.row());
3491 if (cursor.row()->height() != tmpheight) {
3492 refresh_y = cursor.y() - cursor.row()->baseline();
3493 refresh_row = cursor.row();
3494 status = LyXText::NEED_MORE_REFRESH;
3500 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3501 SetUndo(bview->buffer(), Undo::DELETE,
3502 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3503 cursor.par()->ParFromPos(cursor.pos())->next);
3506 LyXParagraph * tmppar = cursor.par();
3507 Row * tmprow = cursor.row();
3509 // We used to do CursorLeftIntern() here, but it is
3510 // not a good idea since it triggers the auto-delete
3511 // mechanism. So we do a CursorLeftIntern()-lite,
3512 // without the dreaded mechanism. (JMarc)
3513 if (cursor.par()->Previous()) {
3514 // steps into the above paragraph.
3515 SetCursorIntern(bview, cursor.par()->Previous(),
3516 cursor.par()->Previous()->Last(), false);
3519 /* Pasting is not allowed, if the paragraphs have different
3520 layout. I think it is a real bug of all other
3521 word processors to allow it. It confuses the user.
3522 Even so with a footnote paragraph and a non-footnote
3523 paragraph. I will not allow pasting in this case,
3524 because the user would be confused if the footnote behaves
3525 different wether it is open or closed.
3527 Correction: Pasting is always allowed with standard-layout
3529 if (cursor.par() != tmppar
3530 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3531 || tmppar->GetLayout() == 0 /*standard*/)
3532 && cursor.par()->footnoteflag == tmppar->footnoteflag
3534 /* table stuff -- begin*/
3535 && !cursor.par()->table /* no pasting of tables */
3536 /* table stuff -- end*/
3538 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3540 RemoveParagraph(tmprow);
3542 cursor.par()->PasteParagraph(bview->buffer()->params);
3544 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3545 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3546 // strangely enough it seems that commenting out the line above removes
3547 // most or all of the segfaults. I will however also try to move the
3548 // two Remove... lines in front of the PasteParagraph too.
3551 cursor.pos(cursor.pos() - 1);
3553 status = LyXText::NEED_MORE_REFRESH;
3554 refresh_row = cursor.row();
3555 refresh_y = cursor.y() - cursor.row()->baseline();
3557 // remove the lost paragraph
3558 // This one is not safe, since the paragraph that the tmprow and the
3559 // following rows belong to has been deleted by the PasteParagraph
3560 // above. The question is... could this be moved in front of the
3562 //RemoveParagraph(tmprow);
3563 //RemoveRow(tmprow);
3565 // This rebuilds the rows.
3566 AppendParagraph(bview, cursor.row());
3567 UpdateCounters(bview, cursor.row());
3569 // the row may have changed, block, hfills etc.
3570 SetCursor(bview, cursor.par(), cursor.pos(), false);
3573 /* this is the code for a normal backspace, not pasting
3575 SetUndo(bview->buffer(), Undo::DELETE,
3576 cursor.par()->ParFromPos(cursor.pos())->previous,
3577 cursor.par()->ParFromPos(cursor.pos())->next);
3578 // We used to do CursorLeftIntern() here, but it is
3579 // not a good idea since it triggers the auto-delete
3580 // mechanism. So we do a CursorLeftIntern()-lite,
3581 // without the dreaded mechanism. (JMarc)
3582 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3583 false, cursor.boundary());
3585 // some insets are undeletable here
3586 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3587 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3589 // force complete redo when erasing display insets
3590 // this is a cruel method but safe..... Matthias
3591 if (cursor.par()->GetInset(cursor.pos())->display()){
3592 cursor.par()->Erase(cursor.pos());
3593 RedoParagraph(bview);
3598 Row * row = cursor.row();
3599 long y = cursor.y() - row->baseline();
3600 LyXParagraph::size_type z;
3601 /* remember that a space at the end of a row doesnt count
3602 * when calculating the fill */
3603 if (cursor.pos() < RowLast(row) ||
3604 !cursor.par()->IsLineSeparator(cursor.pos())) {
3605 row->fill(row->fill() + SingleWidth(bview,
3610 /* some special code when deleting a newline. This is similar
3611 * to the behavior when pasting paragraphs */
3612 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3613 cursor.par()->Erase(cursor.pos());
3614 // refresh the positions
3616 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3617 tmprow = tmprow->next();
3618 tmprow->pos(tmprow->pos() - 1);
3620 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3621 cursor.pos(cursor.pos() - 1);
3623 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3624 cursor.par()->InsertChar(cursor.pos(), ' ');
3625 // refresh the positions
3627 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3628 tmprow = tmprow->next();
3629 tmprow->pos(tmprow->pos() + 1);
3633 cursor.par()->Erase(cursor.pos());
3635 // refresh the positions
3637 while (tmprow->next()
3638 && tmprow->next()->par() == row->par()) {
3639 tmprow = tmprow->next();
3640 tmprow->pos(tmprow->pos() - 1);
3643 // delete newlines at the beginning of paragraphs
3644 while (cursor.par()->Last() &&
3645 cursor.par()->IsNewline(cursor.pos()) &&
3646 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3648 cursor.par()->Erase(cursor.pos());
3649 // refresh the positions
3651 while (tmprow->next() &&
3652 tmprow->next()->par() == row->par()) {
3653 tmprow = tmprow->next();
3654 tmprow->pos(tmprow->pos() - 1);
3659 // is there a break one row above
3660 if (row->previous() && row->previous()->par() == row->par()) {
3661 z = NextBreakPoint(bview, row->previous(),
3663 if ( z >= row->pos()) {
3666 Row * tmprow = row->previous();
3668 // maybe the current row is now empty
3669 if (row->pos() >= row->par()->Last()) {
3674 BreakAgainOneRow(bview, row);
3675 if (row->next() && row->next()->par() == row->par())
3676 need_break_row = row->next();
3681 // set the dimensions of the row above
3682 y -= tmprow->height();
3683 tmprow->fill(Fill(bview, tmprow,
3685 SetHeightOfRow(bview, tmprow);
3688 refresh_row = tmprow;
3689 status = LyXText::NEED_MORE_REFRESH;
3690 SetCursor(bview, cursor.par(), cursor.pos(),
3691 false, cursor.boundary());
3692 //current_font = rawtmpfont;
3693 //real_current_font = realtmpfont;
3694 // check, whether the last character's font has changed.
3696 cursor.par()->GetFontSettings(bview->buffer()->params,
3697 cursor.par()->Last() - 1))
3698 RedoHeightOfParagraph(bview, cursor);
3703 // break the cursor row again
3704 z = NextBreakPoint(bview, row, workWidth(bview));
3706 if (z != RowLast(row) ||
3707 (row->next() && row->next()->par() == row->par() &&
3708 RowLast(row) == row->par()->Last() - 1)){
3710 /* it can happen that a paragraph loses one row
3711 * without a real breakup. This is when a word
3712 * is to long to be broken. Well, I don t care this
3714 if (row->next() && row->next()->par() == row->par() &&
3715 RowLast(row) == row->par()->Last() - 1)
3716 RemoveRow(row->next());
3720 status = LyXText::NEED_MORE_REFRESH;
3722 BreakAgainOneRow(bview, row);
3723 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3724 // cursor MUST be in row now
3726 if (row->next() && row->next()->par() == row->par())
3727 need_break_row = row->next();
3731 // set the dimensions of the row
3732 row->fill(Fill(bview, row, workWidth(bview)));
3733 int tmpheight = row->height();
3734 SetHeightOfRow(bview, row);
3735 if (tmpheight == row->height())
3736 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3738 status = LyXText::NEED_MORE_REFRESH;
3741 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3745 // current_font = rawtmpfont;
3746 // real_current_font = realtmpfont;
3748 lastpos = cursor.par()->Last();
3749 if (cursor.pos() == lastpos) {
3750 SetCurrentFont(bview);
3751 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3752 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3755 // check, wether the last characters font has changed.
3757 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3758 RedoHeightOfParagraph(bview, cursor);
3760 // now the special right address boxes
3761 if (textclasslist.Style(bview->buffer()->params.textclass,
3762 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3763 RedoDrawingOfParagraph(bview, cursor);
3769 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3770 Row * row_ptr, long y)
3772 /* returns a printed row */
3773 Painter & pain = bview->painter();
3775 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3776 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3778 LyXParagraph::size_type vpos, pos;
3780 int y_top, y_bottom;
3781 float fill_separator, fill_hfill, fill_label_hfill;
3783 LyXFont font(LyXFont::ALL_SANE);
3785 if (row_ptr->height() <= 0) {
3786 lyxerr << "LYX_ERROR: row.height: "
3787 << row_ptr->height() << endl;
3790 PrepareToPrint(bview, row_ptr, x, fill_separator,
3791 fill_hfill, fill_label_hfill);
3795 // clear the area where we want to paint/print
3798 ww = inset_owner->width(bview->painter(), font) - 1;
3800 ww = bview->workWidth();
3802 bool clear_area = true;
3804 if ((last == row_ptr->pos()) &&
3805 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3806 (row_ptr->par()->GetInset(row_ptr->pos())))
3808 clear_area = row_ptr->par()->GetInset(row_ptr->pos())->doClearArea();
3811 pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height());
3814 /* selection code */
3815 if (bidi_same_direction) {
3816 if (sel_start_cursor.row() == row_ptr &&
3817 sel_end_cursor.row() == row_ptr) {
3818 if (sel_start_cursor.x() < sel_end_cursor.x())
3819 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3821 sel_end_cursor.x() - sel_start_cursor.x(),
3825 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3827 sel_start_cursor.x() - sel_end_cursor.x(),
3830 } else if (sel_start_cursor.row() == row_ptr) {
3832 pain.fillRectangle(x_offset, y_offset,
3833 sel_start_cursor.x(),
3837 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3839 ww - sel_start_cursor.x(),
3842 } else if (sel_end_cursor.row() == row_ptr) {
3844 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3846 ww - sel_end_cursor.x(),
3850 pain.fillRectangle(x_offset, y_offset,
3854 } else if (y > long(sel_start_cursor.y())
3855 && y < long(sel_end_cursor.y())) {
3856 pain.fillRectangle(x_offset, y_offset, ww,
3860 } else if ( sel_start_cursor.row() != row_ptr &&
3861 sel_end_cursor.row() != row_ptr &&
3862 y > long(sel_start_cursor.y())
3863 && y < long(sel_end_cursor.y())) {
3864 pain.fillRectangle(x_offset, y_offset, ww,
3867 } else if (sel_start_cursor.row() == row_ptr ||
3868 sel_end_cursor.row() == row_ptr) {
3872 if (row_ptr->par()->table) {
3873 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3874 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3877 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3878 (sel_end_cursor.row() != row_ptr && is_rtl))
3879 pain.fillRectangle(x_offset, y_offset,
3884 if (row_ptr->par()->table) {
3886 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3887 pos = vis2log(vpos);
3888 float old_tmpx = tmpx;
3889 if (row_ptr->par()->IsNewline(pos)) {
3890 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3893 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3895 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3897 if ( (sel_start_cursor.row() != row_ptr ||
3898 sel_start_cursor.pos() <= pos) &&
3899 (sel_end_cursor.row() != row_ptr ||
3900 pos < sel_end_cursor.pos()) )
3901 pain.fillRectangle(x_offset + int(old_tmpx),
3903 int(tmpx - old_tmpx + 1),
3909 LyXParagraph::size_type main_body =
3910 BeginningOfMainBody(bview->buffer(),
3913 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3914 pos = vis2log(vpos);
3915 float old_tmpx = tmpx;
3916 if (main_body > 0 && pos == main_body-1) {
3917 tmpx += fill_label_hfill +
3918 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3919 row_ptr->par()->GetLayout()).labelsep,
3920 GetFont(bview->buffer(),row_ptr->par(), -2));
3921 if (row_ptr->par()->IsLineSeparator(main_body-1))
3922 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3924 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3925 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3926 if (pos >= main_body)
3929 tmpx += fill_label_hfill;
3931 else if (row_ptr->par()->IsSeparator(pos)) {
3932 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3933 if (pos >= main_body)
3934 tmpx += fill_separator;
3936 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3938 if ( (sel_start_cursor.row() != row_ptr ||
3939 sel_start_cursor.pos() <= pos) &&
3940 (sel_end_cursor.row() != row_ptr ||
3941 pos < sel_end_cursor.pos()) )
3942 pain.fillRectangle(x_offset + int(old_tmpx),
3944 int(tmpx - old_tmpx + 1),
3951 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3952 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3953 pain.fillRectangle(x_offset + int(tmpx),
3962 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3963 LyXFont font(LyXFont::ALL_SANE);
3964 font.setSize(LyXFont::SIZE_FOOTNOTE);
3965 font.setColor(LColor::footnote);
3967 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3968 if (row_ptr->previous() &&
3969 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3971 switch (row_ptr->par()->footnotekind) {
3972 case LyXParagraph::MARGIN:
3975 case LyXParagraph::FIG:
3978 case LyXParagraph::TAB:
3981 case LyXParagraph::WIDE_FIG:
3984 case LyXParagraph::WIDE_TAB:
3987 case LyXParagraph::ALGORITHM:
3990 case LyXParagraph::FOOTNOTE:
3995 pain.fillRectangle(LYX_PAPER_MARGIN,
3997 box_x - LYX_PAPER_MARGIN,
3998 int(lyxfont::maxAscent(font)
3999 + lyxfont::maxDescent(font)),
4000 LColor::footnotebg);
4002 pain.line(LYX_PAPER_MARGIN, y_offset,
4003 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4004 LColor::footnoteframe);
4006 pain.text(LYX_PAPER_MARGIN,
4007 y_offset + int(lyxfont::maxAscent(font)) + 1,
4010 pain.line(LYX_PAPER_MARGIN, y_offset,
4012 y_offset + int(lyxfont::maxAscent(font)
4013 + lyxfont::maxDescent(font)),
4014 LColor::footnoteframe);
4016 pain.line(LYX_PAPER_MARGIN,
4017 y_offset + int(lyxfont::maxAscent(font)
4018 + lyxfont::maxDescent(font)) + 1,
4020 y_offset + int(lyxfont::maxAscent(font)
4021 + lyxfont::maxDescent(font)) + 1,
4022 LColor::footnoteframe);
4026 /* draw the open floats in a red box */
4027 pain.line(box_x, y_offset,
4028 box_x, y_offset + row_ptr->height(),
4029 LColor::footnoteframe);
4031 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4033 workWidth(bview) - LYX_PAPER_MARGIN,
4034 y_offset + row_ptr->height(),
4035 LColor::footnoteframe);
4038 // Draw appendix lines
4039 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4041 pain.line(1, y_offset,
4042 1, y_offset + row_ptr->height(),
4043 LColor::appendixline);
4044 pain.line(workWidth(bview) - 2, y_offset,
4045 workWidth(bview) - 2,
4046 y_offset + row_ptr->height(),
4047 LColor::appendixline);
4050 // Draw minipage line
4051 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4053 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4055 y_offset + row_ptr->height() - 1,
4056 LColor::minipageline);
4059 int depth = p->GetDepth();
4060 for (int i = 1; i <= depth; ++i) {
4061 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4062 pain.line(line_x, y_offset, line_x,
4063 y_offset + row_ptr->height() - 1,
4066 } else if (row_ptr->previous() &&
4067 row_ptr->previous()->par()->footnoteflag
4068 == LyXParagraph::OPEN_FOOTNOTE) {
4069 LyXFont font(LyXFont::ALL_SANE);
4070 font.setSize(LyXFont::SIZE_FOOTNOTE);
4072 int box_x = LYX_PAPER_MARGIN;
4073 box_x += lyxfont::width(" wide-tab ", font);
4075 pain.line(box_x, y_offset,
4076 workWidth(bview) - LYX_PAPER_MARGIN,
4077 y_offset, LColor::footnote);
4080 // Draw appendix lines
4081 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4082 if (firstpar->appendix){
4083 pain.line(1, y_offset,
4084 1, y_offset + row_ptr->height(),
4085 LColor::appendixline);
4086 pain.line(ww - 2, y_offset,
4087 ww - 2, y_offset + row_ptr->height(),
4088 LColor::appendixline);
4091 // Draw minipage line
4092 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4094 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4095 LYX_PAPER_MARGIN/5 + box_x,
4096 y_offset + row_ptr->height() - 1,
4097 LColor::minipageline);
4100 int depth = firstpar->GetDepth();
4104 if (row_ptr->next())
4105 if (row_ptr->par()->footnoteflag ==
4106 row_ptr->next()->par()->footnoteflag)
4107 next_depth = row_ptr->next()->par()->GetDepth();
4108 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4111 if (row_ptr->previous())
4112 if (row_ptr->par()->footnoteflag ==
4113 row_ptr->previous()->par()->footnoteflag)
4114 prev_depth = row_ptr->previous()->par()->GetDepth();
4115 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4118 for (int i = 1; i <= depth; ++i) {
4119 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4120 pain.line(line_x, y_offset, line_x,
4121 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4125 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4128 pain.fillRectangle(line_x,
4129 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4130 LYX_PAPER_MARGIN / 5, 2,
4136 LyXLayout const & layout =
4137 textclasslist.Style(bview->buffer()->params.textclass,
4138 row_ptr->par()->GetLayout());
4141 y_bottom = row_ptr->height();
4143 /* is it a first row? */
4144 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4146 /* start of appendix? */
4147 if (row_ptr->par()->start_of_appendix){
4148 pain.line(1, y_offset,
4150 LColor::appendixline);
4153 /* think about the margins */
4154 if (!row_ptr->previous() && bv_owner)
4155 y_top += LYX_PAPER_MARGIN;
4157 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4159 pb_font.setColor(LColor::pagebreak).decSize();
4160 int w = 0, a = 0, d = 0;
4161 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4163 y_offset + y_top + 2 * DefaultHeight(),
4165 Painter::line_onoffdash)
4168 _("Page Break (top)"),
4171 LColor::background, false, w, a, d);
4172 pain.rectText((ww - w)/2,
4173 y_offset + y_top + 2 * DefaultHeight() + d,
4174 _("Page Break (top)"),
4177 LColor::background);
4178 y_top += 3 * DefaultHeight();
4181 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4182 /* draw a vfill top */
4183 pain.line(0, y_offset + 2 + y_top,
4184 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4187 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4189 y_offset + y_top + 3 * DefaultHeight(),
4192 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4193 LYX_PAPER_MARGIN / 2,
4194 y_offset + y_top + 3 * DefaultHeight(),
4197 y_top += 3 * DefaultHeight();
4200 /* think about user added space */
4201 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4203 /* think about the parskip */
4204 /* some parskips VERY EASY IMPLEMENTATION */
4205 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4206 if (layout.latextype == LATEX_PARAGRAPH
4207 && firstpar->GetDepth() == 0
4208 && firstpar->Previous())
4209 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4210 else if (firstpar->Previous()
4211 && textclasslist.Style(bview->buffer()->params.textclass,
4212 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4213 && firstpar->Previous()->GetDepth() == 0)
4214 // is it right to use defskip here, too? (AS)
4215 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4218 if (row_ptr->par()->line_top) { /* draw a top line */
4219 y_top += lyxfont::ascent('x',
4220 GetFont(bview->buffer(),
4221 row_ptr->par(), 0));
4223 pain.line(0, y_offset + y_top,
4224 ww, y_offset + y_top,
4226 Painter::line_solid,
4227 Painter::line_thick);
4229 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4230 row_ptr->par(), 0));
4233 /* should we print a label? */
4234 if (layout.labeltype >= LABEL_STATIC
4235 && (layout.labeltype != LABEL_STATIC
4236 || layout.latextype != LATEX_ENVIRONMENT
4237 || row_ptr->par()->IsFirstInSequence())) {
4238 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4239 if (!row_ptr->par()->GetLabelstring().empty()) {
4241 string tmpstring = row_ptr->par()->GetLabelstring();
4243 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4244 if (bview->buffer()->params.secnumdepth >= 0) {
4245 /* this is special code for the chapter layout. This is printed in
4246 * an extra row and has a pagebreak at the top. */
4247 float spacing_val = 1.0;
4248 if (!row_ptr->par()->spacing.isDefault()) {
4249 spacing_val = row_ptr->par()->spacing.getValue();
4251 spacing_val = bview->buffer()->params.spacing.getValue();
4254 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4255 + int(layout.parsep) * DefaultHeight();
4257 tmpx = ww - LeftMargin(bview, row_ptr) -
4258 lyxfont::width(tmpstring, font);
4259 pain.text(int(tmpx),
4260 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4265 tmpx = ww - LeftMargin(bview, row_ptr)
4266 + lyxfont::width(layout.labelsep, font);
4267 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4268 LyXFont font(LyXFont::ALL_SANE);
4269 font.setSize(LyXFont::SIZE_SMALL);
4270 tmpx += lyxfont::width("Mwide-fixM", font);
4273 tmpx = x - lyxfont::width(layout.labelsep, font)
4274 - lyxfont::width(tmpstring, font);
4277 pain.text(int(tmpx),
4278 y_offset + row_ptr->baseline(),
4282 /* the labels at the top of an environment. More or less for bibliography */
4283 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4284 layout.labeltype == LABEL_BIBLIO ||
4285 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4286 if (row_ptr->par()->IsFirstInSequence()) {
4287 font = GetFont(bview->buffer(),
4288 row_ptr->par(), -2);
4289 if (!row_ptr->par()->GetLabelstring().empty()) {
4290 string tmpstring = row_ptr->par()->GetLabelstring();
4291 float spacing_val = 1.0;
4292 if (!row_ptr->par()->spacing.isDefault()) {
4293 spacing_val = row_ptr->par()->spacing.getValue();
4295 spacing_val = bview->buffer()->params.spacing.getValue();
4298 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4299 + (layout.labelbottomsep * DefaultHeight()));
4302 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4303 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4304 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4305 tmpx -= lyxfont::width(tmpstring, font) / 2;
4307 tmpx = ww - LeftMargin(bview, row_ptr) -
4308 lyxfont::width(tmpstring, font);
4309 pain.text(int(tmpx),
4310 y_offset + row_ptr->baseline()
4311 - row_ptr->ascent_of_text()
4317 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4318 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4320 tmpx = ww - LeftMargin(bview, row_ptr)
4321 + lyxfont::width(layout.labelsep, font);
4323 tmpx = x - lyxfont::width(layout.labelsep, font)
4324 - row_ptr->par()->bibkey->width(bview->painter(), font);
4325 row_ptr->par()->bibkey->draw(bview, font,
4326 y_offset + row_ptr->baseline(),
4331 /* is it a last row? */
4332 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4333 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4334 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4336 /* think about the margins */
4337 if (!row_ptr->next() && bv_owner)
4338 y_bottom -= LYX_PAPER_MARGIN;
4340 /* draw a bottom pagebreak */
4341 if (firstpar->pagebreak_bottom) {
4343 pb_font.setColor(LColor::pagebreak).decSize();
4344 int w = 0, a = 0, d = 0;
4346 y_offset + y_bottom - 2 * DefaultHeight(),
4348 y_offset + y_bottom - 2 * DefaultHeight(),
4350 Painter::line_onoffdash)
4353 _("Page Break (bottom)"),
4356 LColor::background, false, w, a, d);
4357 pain.rectText((ww - w) / 2,
4358 y_offset + y_top + 2 * DefaultHeight() + d,
4359 _("Page Break (bottom)"),
4362 LColor::background);
4363 y_bottom -= 3 * DefaultHeight();
4366 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4367 /* draw a vfill bottom */
4368 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4370 y_offset + y_bottom - 3 * DefaultHeight(),
4372 pain.line(0, y_offset + y_bottom - 2,
4374 y_offset + y_bottom - 2,
4376 pain.line(LYX_PAPER_MARGIN / 2,
4377 y_offset + y_bottom - 3 * DefaultHeight(),
4378 LYX_PAPER_MARGIN / 2,
4379 y_offset + y_bottom - 2,
4381 y_bottom -= 3 * DefaultHeight();
4384 /* think about user added space */
4385 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4387 if (firstpar->line_bottom) {
4388 /* draw a bottom line */
4389 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4390 par, par->Last() - 1));
4391 pain.line(0, y_offset + y_bottom,
4392 ww, y_offset + y_bottom,
4393 LColor::topline, Painter::line_solid,
4394 Painter::line_thick);
4395 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4396 par, par->Last() - 1));
4400 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4403 case END_LABEL_FILLED_BOX:
4405 LyXFont font = GetFont(bview->buffer(),
4406 row_ptr->par(), last);
4407 int size = int(0.75 * lyxfont::maxAscent(font));
4408 int y = (y_offset + row_ptr->baseline()) - size;
4409 int x = is_rtl ? LYX_PAPER_MARGIN
4410 : ww - LYX_PAPER_MARGIN - size;
4411 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4413 LyXFont font(LyXFont::ALL_SANE);
4414 font.setSize(LyXFont::SIZE_SMALL);
4415 x += lyxfont::width("Mwide-figM", font);
4417 x -= LYX_PAPER_MARGIN/2;
4418 if (row_ptr->fill() <= size)
4419 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4420 if (endlabel == END_LABEL_BOX) {
4421 pain.line(x, y, x, y + size,
4423 pain.line(x + size, y, x + size , y + size,
4425 pain.line(x, y, x + size, y,
4427 pain.line(x, y + size, x + size, y + size,
4430 pain.fillRectangle(x, y, size, size,
4434 case END_LABEL_STATIC:
4436 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4437 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4438 layout).endlabelstring();
4439 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4440 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4441 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4442 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4445 case END_LABEL_NO_LABEL:
4450 /* draw the text in the pixmap */
4452 vpos = row_ptr->pos();
4454 /* table stuff -- begin*/
4455 if (row_ptr->par()->table) {
4457 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4459 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4461 while (vpos <= last) {
4462 pos = vis2log(vpos);
4463 if (row_ptr->par()->IsNewline(pos)) {
4465 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4466 /* draw the table lines, still very simple */
4467 on_off = !row_ptr->par()->table->TopLine(cell);
4469 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4470 !row_ptr->par()->table->IsContRow(cell))
4471 pain.line(int(x_old),
4472 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4474 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4476 on_off ? Painter::line_onoffdash : Painter::line_solid);
4478 on_off = !row_ptr->par()->table->BottomLine(cell);
4479 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4480 row_ptr->par()->table->VeryLastRow(cell))
4482 pain.line(int(x_old),
4483 y_offset + y_bottom - 1,
4485 y_offset + y_bottom - 1,
4487 on_off ? Painter::line_onoffdash : Painter::line_solid);
4489 on_off = !row_ptr->par()->table->LeftLine(cell);
4491 pain.line(int(x_old),
4492 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4494 y_offset + y_bottom - 1,
4496 on_off ? Painter::line_onoffdash : Painter::line_solid);
4498 on_off = !row_ptr->par()->table->RightLine(cell);
4500 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4501 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4502 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4503 y_offset + y_bottom - 1,
4505 on_off ? Painter::line_onoffdash : Painter::line_solid);
4508 /* take care about the alignment and other spaces */
4510 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4511 if (row_ptr->par()->table->IsFirstCell(cell))
4512 --cell; // little hack, sorry
4514 } else if (row_ptr->par()->IsHfill(pos)) {
4518 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4520 y_offset + row_ptr->baseline(),
4525 } else if (row_ptr->par()->IsSeparator(pos)) {
4527 x+= SingleWidth(bview,
4528 row_ptr->par(), pos);
4531 draw(bview, row_ptr, vpos, y_offset, x);
4534 /* do not forget the very last cell. This has no NEWLINE so
4535 * ignored by the code above*/
4536 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4537 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4538 on_off = !row_ptr->par()->table->TopLine(cell);
4540 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4541 !row_ptr->par()->table->IsContRow(cell))
4543 pain.line(int(x_old),
4544 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4546 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4548 on_off ? Painter::line_onoffdash : Painter::line_solid);
4549 on_off = !row_ptr->par()->table->BottomLine(cell);
4550 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4551 row_ptr->par()->table->VeryLastRow(cell))
4553 pain.line(int(x_old),
4554 y_offset + y_bottom - 1,
4556 y_offset + y_bottom - 1,
4558 on_off ? Painter::line_onoffdash : Painter::line_solid);
4560 on_off = !row_ptr->par()->table->LeftLine(cell);
4562 pain.line(int(x_old),
4563 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4565 y_offset + y_bottom - 1,
4567 on_off ? Painter::line_onoffdash : Painter::line_solid);
4569 on_off = !row_ptr->par()->table->RightLine(cell);
4571 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4572 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4573 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4574 y_offset + y_bottom - 1,
4576 on_off ? Painter::line_onoffdash : Painter::line_solid);
4579 /* table stuff -- end*/
4581 LyXParagraph::size_type main_body =
4582 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4583 if (main_body > 0 &&
4584 (main_body-1 > last ||
4585 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4588 while (vpos <= last) {
4589 pos = vis2log(vpos);
4590 if (main_body > 0 && pos == main_body - 1) {
4591 x += fill_label_hfill
4592 + lyxfont::width(layout.labelsep,
4593 GetFont(bview->buffer(),
4594 row_ptr->par(), -2))
4595 - SingleWidth(bview,
4600 if (row_ptr->par() ->IsHfill(pos)) {
4603 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4605 y_offset + row_ptr->baseline(),
4608 if (HfillExpansion(bview->buffer(),
4610 if (pos >= main_body) {
4612 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4613 int(x + fill_hfill),
4614 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4616 Painter::line_onoffdash);
4620 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4621 int(x + fill_label_hfill),
4622 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4624 Painter::line_onoffdash);
4626 x += fill_label_hfill;
4629 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4631 y_offset + row_ptr->baseline(),
4636 } else if (row_ptr->par()->IsSeparator(pos)) {
4637 x += SingleWidth(bview,
4638 row_ptr->par(), pos);
4639 if (pos >= main_body)
4640 x += fill_separator;
4643 draw(bview, row_ptr, vpos, y_offset, x);
4651 int LyXText::DefaultHeight() const
4653 LyXFont font(LyXFont::ALL_SANE);
4654 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4658 /* returns the column near the specified x-coordinate of the row
4659 * x is set to the real beginning of this column */
4660 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4661 bool & boundary) const
4664 float fill_separator, fill_hfill, fill_label_hfill;
4666 PrepareToPrint(bview, row, tmpx, fill_separator,
4667 fill_hfill, fill_label_hfill);
4669 LyXParagraph::size_type vc = row->pos();
4670 LyXParagraph::size_type last = RowLastPrintable(row);
4671 LyXParagraph::size_type c = 0;
4672 LyXLayout const & layout =
4673 textclasslist.Style(bview->buffer()->params.textclass,
4674 row->par()->GetLayout());
4675 bool left_side = false;
4678 /* table stuff -- begin */
4679 if (row->par()->table) {
4680 //the last row doesn't need a newline at the end
4681 if (row->next() && row->next()->par() == row->par()
4682 && row->par()->IsNewline(last))
4684 int cell = NumberOfCell(row->par(), row->pos());
4685 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4686 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4687 float last_tmpx = tmpx;
4688 while (vc <= last && tmpx <= x) {
4691 if (row->par()->IsNewline(c)) {
4694 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4695 cell_x += row->par()->table->WidthOfColumn(cell);
4700 tmpx += SingleWidth(bview, row->par(), c);
4704 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4705 (tmpx + last_tmpx) / 2 > x) {
4710 /* table stuff -- end*/
4712 LyXParagraph::size_type
4713 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4714 float last_tmpx = tmpx;
4716 if (main_body > 0 &&
4717 (main_body-1 > last ||
4718 !row->par()->IsLineSeparator(main_body - 1)))
4721 while (vc <= last && tmpx <= x) {
4724 if (main_body > 0 && c == main_body-1) {
4725 tmpx += fill_label_hfill +
4726 lyxfont::width(layout.labelsep,
4727 GetFont(bview->buffer(), row->par(), -2));
4728 if (row->par()->IsLineSeparator(main_body - 1))
4729 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4732 if (HfillExpansion(bview->buffer(), row, c)) {
4733 x += SingleWidth(bview, row->par(), c);
4737 tmpx += fill_label_hfill;
4739 else if (row->par()->IsSeparator(c)) {
4740 tmpx += SingleWidth(bview, row->par(), c);
4742 tmpx+= fill_separator;
4744 tmpx += SingleWidth(bview, row->par(), c);
4748 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4757 if (vc > last + 1) // This shouldn't happen.
4762 if (row->pos() > last) // Row is empty?
4764 else if (vc == row->pos() ||
4766 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4768 if (bidi_level(c) % 2 == 1)
4771 c = vis2log(vc - 1);
4772 bool rtl = (bidi_level(c) % 2 == 1);
4773 if (left_side == rtl) {
4775 boundary = IsBoundary(bview->buffer(), row->par(), c);
4779 if (!row->par()->table && row->pos() <= last && c > last
4780 && row->par()->IsNewline(last)) {
4781 if (bidi_level(last) % 2 == 0)
4782 tmpx -= SingleWidth(bview, row->par(), last);
4784 tmpx += SingleWidth(bview, row->par(), last);
4794 /* turn the selection into a new environment. If there is no selection,
4795 * create an empty environment */
4796 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4797 LyXParagraph::footnote_kind kind)
4799 /* no footnoteenvironment in a footnoteenvironment */
4800 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4801 WriteAlert(_("Impossible operation"),
4802 _("You can't insert a float in a float!"),
4806 /* no marginpars in minipages */
4807 if (kind == LyXParagraph::MARGIN
4808 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4809 WriteAlert(_("Impossible operation"),
4810 _("You can't insert a marginpar in a minipage!"),
4815 /* this doesnt make sense, if there is no selection */
4816 bool dummy_selection = false;
4818 sel_start_cursor = cursor; /* dummy selection */
4819 sel_end_cursor = cursor;
4820 dummy_selection = true;
4823 LyXParagraph * tmppar;
4826 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4827 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4831 /* a test to make sure there is not already a footnote
4832 * in the selection. */
4834 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4836 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4837 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4838 tmppar = tmppar->next;
4840 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4841 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4842 WriteAlert(_("Impossible operation"),
4843 _("Float would include float!"),
4848 /* ok we have a selection. This is always between sel_start_cursor
4849 * and sel_end cursor */
4851 SetUndo(bview->buffer(), Undo::FINISH,
4852 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4853 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4855 if (sel_end_cursor.pos() > 0
4856 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4857 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4858 /* please break before a space at the end */
4859 if (sel_start_cursor.par() == sel_end_cursor.par()
4860 && sel_start_cursor.pos() > sel_end_cursor.pos())
4861 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4863 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4865 sel_end_cursor.par(sel_end_cursor.par()->Next());
4866 sel_end_cursor.pos(0);
4868 // don't forget to insert a dummy layout paragraph if necessary
4869 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4870 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4871 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4872 sel_end_cursor.par(sel_end_cursor.par()->next);
4875 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4877 cursor = sel_end_cursor;
4879 /* please break behind a space, if there is one. The space should
4881 if (sel_start_cursor.pos() > 0
4882 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4883 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4884 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4885 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4888 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4889 sel_start_cursor.pos());
4890 tmppar = sel_start_cursor.par()->Next();
4892 if (dummy_selection) {
4894 if (kind == LyXParagraph::TAB
4895 || kind == LyXParagraph::FIG
4896 || kind == LyXParagraph::WIDE_TAB
4897 || kind == LyXParagraph::WIDE_FIG
4898 || kind == LyXParagraph::ALGORITHM) {
4899 pair<bool, LyXTextClass::size_type> lres =
4900 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4902 LyXTextClass::size_type lay;
4908 lay = 0; // use default layout "Standard" (0)
4910 tmppar->SetLayout(bview->buffer()->params, lay);
4913 if (sel_start_cursor.pos() > 0) {
4914 /* the footnote-environment should begin with a standard layout.
4915 * Imagine you insert a footnote within an enumeration, you
4916 * certainly do not want an enumerated footnote! */
4919 /* this is a exception the user would sometimes expect, I hope */
4920 sel_start_cursor.par()->Clear();
4924 while (tmppar != sel_end_cursor.par()) {
4925 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4926 tmppar->footnotekind = kind;
4927 tmppar = tmppar->Next();
4930 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4932 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4938 // returns pointer to a specified row
4939 Row * LyXText::GetRow(LyXParagraph * par,
4940 LyXParagraph::size_type pos, long & y) const
4942 Row * tmprow = firstrow;
4945 // find the first row of the specified paragraph
4946 while (tmprow->next() && tmprow->par() != par) {
4947 y += tmprow->height();
4948 tmprow = tmprow->next();
4951 // now find the wanted row
4952 while (tmprow->pos() < pos
4954 && tmprow->next()->par() == par
4955 && tmprow->next()->pos() <= pos) {
4956 y += tmprow->height();
4957 tmprow = tmprow->next();