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 "lyx_gui_misc.h"
27 #include "bufferparams.h"
29 #include "minibuffer.h"
43 static const int LYX_PAPER_MARGIN = 20;
44 extern int bibitemMaxWidth(Painter &, LyXFont const &);
46 static int iso885968x[] = {
47 0xbc, // 0xa8 = fathatan
48 0xbd, // 0xa9 = dammatan
49 0xbe, // 0xaa = kasratan
53 0xde, // 0xae = shadda
56 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
60 0xc2, // 0xc2 = ligature madda
61 0xc3, // 0xc3 = ligature hamza on alef
62 0xc4, // 0xc4 = ligature hamza on waw
63 0xc5, // 0xc5 = ligature hamza under alef
64 0xc0, // 0xc6 = ligature hamza on ya
67 0xc9, // 0xc9 = taa marbuta
86 0,0,0,0,0, // 0xdb- 0xdf
97 0xe9, // 0xe9 = alef maksura
103 bool is_arabic(unsigned char c)
105 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
110 bool is_nikud(unsigned char c)
112 return 192 <= c && c <= 210;
116 int LyXText::workWidth(BufferView * bview) const
120 return inset_owner->getMaxWidth(bview->painter(), inset_owner);
122 LyXFont font(LyXFont::ALL_SANE);
123 return inset_owner->width(bview->painter(), font);
126 return bview->workWidth();
129 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
132 (form == FORM_INITIAL || form == FORM_MEDIAL) )
133 return iso885968x[c-0xa8];
139 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
140 LyXParagraph::size_type pos) const
144 return c + (0xb0 - '0');
148 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
149 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
151 return TransformChar(c,FORM_MEDIAL);
153 return TransformChar(c,FORM_INITIAL);
156 return TransformChar(c,FORM_FINAL);
158 return TransformChar(c,FORM_ISOLATED);
161 // This is the comments that some of the warnings below refers to.
162 // There are some issues in this file and I don't think they are
163 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
164 // this is a problem that has been here almost from day one and that a
165 // larger userbase with differenct access patters triggers the bad
166 // behaviour. (segfaults.) What I think happen is: In several places
167 // we store the paragraph in the current cursor and then moves the
168 // cursor. This movement of the cursor will delete paragraph at the
169 // old position if it is now empty. This will make the temporary
170 // pointer to the old cursor paragraph invalid and dangerous to use.
171 // And is some cases this will trigger a segfault. I have marked some
172 // of the cases where this happens with a warning, but I am sure there
173 // are others in this file and in text2.C. There is also a note in
174 // Delete() that you should read. In Delete I store the paragraph->id
175 // instead of a pointer to the paragraph. I am pretty sure this faulty
176 // use of temporary pointers to paragraphs that might have gotten
177 // invalidated (through a cursor movement) before they are used, are
178 // the cause of the strange crashes we get reported often.
180 // It is very tiresom to change this code, especially when it is as
181 // hard to read as it is. Help to fix all the cases where this is done
182 // would be greately appreciated.
186 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
187 LyXParagraph::size_type pos) const
189 char c = par->GetChar(pos);
190 return SingleWidth(bview, par, pos, c);
194 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
195 LyXParagraph::size_type pos, char c) const
197 LyXFont font = GetFont(bview->buffer(), par, pos);
199 // The most common case is handled first (Asger)
200 if (IsPrintable(c)) {
201 if (font.language()->RightToLeft()) {
202 if (font.language()->lang() == "arabic" &&
203 lyxrc.font_norm == "iso8859-6.8x")
204 c = TransformChar(c, par, pos);
205 else if (font.language()->lang() == "hebrew" &&
209 return lyxfont::width(c, font);
211 } else if (IsHfillChar(c)) {
212 return 3; /* Because of the representation
213 * as vertical lines */
214 } else if (c == LyXParagraph::META_FOOTNOTE ||
215 c == LyXParagraph::META_MARGIN ||
216 c == LyXParagraph::META_FIG ||
217 c == LyXParagraph::META_TAB ||
218 c == LyXParagraph::META_WIDE_FIG ||
219 c == LyXParagraph::META_WIDE_TAB ||
220 c == LyXParagraph::META_ALGORITHM) {
223 case LyXParagraph::META_MARGIN:
226 case LyXParagraph::META_FIG:
229 case LyXParagraph::META_TAB:
232 case LyXParagraph::META_ALGORITHM:
235 case LyXParagraph::META_WIDE_FIG:
238 case LyXParagraph::META_WIDE_TAB:
241 case LyXParagraph::META_FOOTNOTE:
247 return lyxfont::width(fs, font);
248 } else if (c == LyXParagraph::META_INSET) {
249 Inset * tmpinset= par->GetInset(pos);
251 return par->GetInset(pos)->width(bview->painter(),
256 } else if (IsSeparatorChar(c))
258 else if (IsNewlineChar(c))
260 return lyxfont::width(c, font);
264 // Returns the paragraph position of the last character in the specified row
265 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
267 if (row->next() == 0)
268 return row->par()->Last() - 1;
269 else if (row->next()->par() != row->par())
270 return row->par()->Last() - 1;
272 return row->next()->pos() - 1;
276 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
278 LyXParagraph::size_type last = RowLast(row);
279 if (last >= row->pos()
281 && row->next()->par() == row->par()
282 && row->par()->IsSeparator(last))
289 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
291 bidi_same_direction = true;
292 if (!lyxrc.rtl_support) {
297 bidi_start = row->pos();
298 bidi_end = RowLastPrintable(row);
300 if (bidi_start > bidi_end) {
305 if (bidi_end + 2 - bidi_start >
306 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
307 LyXParagraph::size_type new_size =
308 (bidi_end + 2 - bidi_start < 500) ?
309 500 : 2 * (bidi_end + 2 - bidi_start);
310 log2vis_list.resize(new_size);
311 vis2log_list.resize(new_size);
312 bidi_levels.resize(new_size);
315 vis2log_list[bidi_end + 1 - bidi_start] = -1;
316 log2vis_list[bidi_end + 1 - bidi_start] = -1;
318 LyXParagraph::size_type stack[2];
319 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
323 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
325 for (LyXParagraph::size_type lpos = bidi_start;
326 lpos <= bidi_end; ++lpos) {
327 bool is_space = row->par()->IsLineSeparator(lpos);
328 LyXParagraph::size_type pos =
329 (is_space && lpos + 1 <= bidi_end &&
330 !row->par()->IsLineSeparator(lpos + 1) &&
332 || !row->par()->IsNewline(lpos + 1)) )
334 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
335 bool new_rtl = font.isVisibleRightToLeft();
336 bool new_rtl0 = font.isRightToLeft();
340 if (row->par()->table && row->par()->IsNewline(lpos)) {
342 new_rtl = new_rtl0 = false;
345 if (lpos == main_body - 1
346 && row->pos() < main_body - 1
347 && row->par()->IsLineSeparator(lpos)) {
348 new_level = (rtl_par) ? 1 : 0;
349 new_rtl = new_rtl0 = rtl_par;
351 new_level = (new_rtl) ? 1 : 2;
353 new_level = (rtl_par) ? 2 : 0;
355 if (is_space && new_level >= level) {
361 int new_level2 = new_level;
363 if (level == new_level && rtl0 != new_rtl0) {
365 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
366 } else if (level < new_level) {
367 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
368 if (new_level > rtl_par)
369 bidi_same_direction = false;
371 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
374 bidi_levels[lpos - bidi_start] = new_level;
376 while (level > new_level2) {
377 LyXParagraph::size_type old_lpos =
379 int delta = lpos - old_lpos - 1;
382 log2vis_list[lpos - bidi_start] += delta;
383 log2vis_list[old_lpos - bidi_start] += delta;
385 while (level < new_level)
386 stack[level++] = lpos;
390 LyXParagraph::size_type old_lpos = stack[--level];
391 int delta = bidi_end - old_lpos;
394 log2vis_list[old_lpos - bidi_start] += delta;
397 LyXParagraph::size_type vpos = bidi_start - 1;
398 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
399 vpos += log2vis_list[lpos - bidi_start];
400 vis2log_list[vpos - bidi_start] = lpos;
401 log2vis_list[lpos - bidi_start] = vpos;
406 // This method requires a previous call to ComputeBidiTables()
407 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
408 LyXParagraph::size_type pos) const
410 if (!lyxrc.rtl_support)
411 return false; // This is just for speedup
413 if (!bidi_InRange(pos - 1) ||
414 (par->table && par->IsNewline(pos-1)) )
417 bool rtl = bidi_level(pos - 1) % 2;
419 if (pos == par->Last() ||
420 (par->table && par->IsNewline(pos)))
421 rtl2 = par->isRightToLeftPar(buf->params);
422 else if (bidi_InRange(pos))
423 rtl2 = bidi_level(pos) % 2;
427 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
428 LyXParagraph::size_type pos,
429 LyXFont const & font) const
431 if (!lyxrc.rtl_support)
432 return false; // This is just for speedup
434 bool rtl = font.isVisibleRightToLeft();
436 if (pos == par->Last() ||
437 (par->table && par->IsNewline(pos)))
438 rtl2 = par->isRightToLeftPar(buf->params);
439 else if (bidi_InRange(pos))
440 rtl2 = bidi_level(pos) % 2;
445 void LyXText::draw(BufferView * bview, Row const * row,
446 LyXParagraph::size_type & vpos,
447 int offset, float & x)
449 Painter & pain = bview->painter();
451 LyXParagraph::size_type pos = vis2log(vpos);
452 char c = row->par()->GetChar(pos);
455 if (IsNewlineChar(c)) {
457 // Draw end-of-line marker
458 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
459 int wid = lyxfont::width('n', font);
460 int asc = lyxfont::maxAscent(font);
461 int y = offset + row->baseline();
464 if (bidi_level(pos) % 2 == 0) {
465 xp[0] = int(x + wid * 0.375);
466 yp[0] = int(y - 0.875 * asc * 0.75);
469 yp[1] = int(y - 0.500 * asc * 0.75);
471 xp[2] = int(x + wid * 0.375);
472 yp[2] = int(y - 0.125 * asc * 0.75);
474 pain.lines(xp, yp, 3, LColor::eolmarker);
477 yp[0] = int(y - 0.500 * asc * 0.75);
479 xp[1] = int(x + wid);
480 yp[1] = int(y - 0.500 * asc * 0.75);
482 xp[2] = int(x + wid);
483 yp[2] = int(y - asc * 0.75);
485 pain.lines(xp, yp, 3, LColor::eolmarker);
487 xp[0] = int(x + wid * 0.625);
488 yp[0] = int(y - 0.875 * asc * 0.75);
490 xp[1] = int(x + wid);
491 yp[1] = int(y - 0.500 * asc * 0.75);
493 xp[2] = int(x + wid * 0.625);
494 yp[2] = int(y - 0.125 * asc * 0.75);
496 pain.lines(xp, yp, 3, LColor::eolmarker);
498 xp[0] = int(x + wid);
499 yp[0] = int(y - 0.500 * asc * 0.75);
502 yp[1] = int(y - 0.500 * asc * 0.75);
505 yp[2] = int(y - asc * 0.75);
507 pain.lines(xp, yp, 3, LColor::eolmarker);
513 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
514 LyXFont font2 = font;
516 if (c == LyXParagraph::META_FOOTNOTE
517 || c == LyXParagraph::META_MARGIN
518 || c == LyXParagraph::META_FIG
519 || c == LyXParagraph::META_TAB
520 || c == LyXParagraph::META_WIDE_FIG
521 || c == LyXParagraph::META_WIDE_TAB
522 || c == LyXParagraph::META_ALGORITHM) {
525 case LyXParagraph::META_MARGIN:
528 case LyXParagraph::META_FIG:
531 case LyXParagraph::META_TAB:
534 case LyXParagraph::META_ALGORITHM:
537 case LyXParagraph::META_WIDE_FIG:
540 case LyXParagraph::META_WIDE_TAB:
543 case LyXParagraph::META_FOOTNOTE:
550 // calculate the position of the footnotemark
551 int y = (row->baseline() - lyxfont::maxAscent(font2)
552 + lyxfont::maxAscent(font));
554 font.setColor(LColor::footnote);
556 // draw it and set new x position
558 pain.text(int(x), offset + y, fs, font);
559 x += lyxfont::width(fs, font);
560 pain.line(int(tmpx), offset + row->baseline(),
561 int(x), offset + row->baseline(),
566 } else if (c == LyXParagraph::META_INSET) {
567 Inset const * tmpinset = row->par()->GetInset(pos);
569 tmpinset->draw(bview->painter(), font,
570 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() *
1428 int pos_end = RowLast(row_ptr);
1432 // Check if any insets are larger
1433 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1434 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1435 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1436 tmpinset = row_ptr->par()->GetInset(pos);
1438 asc = tmpinset->ascent(bview->painter(), tmpfont);
1439 desc = tmpinset->descent(bview->painter(), tmpfont);
1448 // Check if any custom fonts are larger (Asger)
1449 // This is not completely correct, but we can live with the small,
1450 // cosmetic error for now.
1451 LyXFont::FONT_SIZE maxsize =
1452 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1454 if (maxsize > font.size()) {
1455 font.setSize(maxsize);
1457 asc = lyxfont::maxAscent(font);
1458 desc = lyxfont::maxDescent(font);
1466 /* table stuff -- begin*/
1467 if (row_ptr->par()->table){
1468 // stretch the rows a bit
1472 /* table stuff -- end*/
1475 // This is nicer with box insets:
1479 row_ptr->ascent_of_text(maxasc);
1481 /* is it a top line? */
1482 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1484 /* some parksips VERY EASY IMPLEMENTATION */
1485 if (bview->buffer()->params.paragraph_separation ==
1486 BufferParams::PARSEP_SKIP) {
1487 if (layout.isParagraph()
1488 && firstpar->GetDepth() == 0
1489 && firstpar->Previous())
1490 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1491 else if (firstpar->Previous()
1492 && textclasslist.Style(bview->buffer()->params.textclass,
1493 firstpar->Previous()->GetLayout()).isParagraph()
1494 && firstpar->Previous()->GetDepth() == 0)
1495 // is it right to use defskip here too? (AS)
1496 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1499 /* the paper margins */
1500 if (!row_ptr->par()->previous && bv_owner)
1501 maxasc += LYX_PAPER_MARGIN;
1503 /* add the vertical spaces, that the user added */
1504 if (firstpar->added_space_top.kind() != VSpace::NONE)
1505 maxasc += int(firstpar->added_space_top.inPixels(bview));
1507 /* do not forget the DTP-lines!
1508 * there height depends on the font of the nearest character */
1509 if (firstpar->line_top)
1510 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1513 /* and now the pagebreaks */
1514 if (firstpar->pagebreak_top)
1515 maxasc += 3 * DefaultHeight();
1517 /* this is special code for the chapter, since the label of this
1518 * layout is printed in an extra row */
1519 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1520 && bview->buffer()->params.secnumdepth >= 0) {
1521 float spacing_val = 1.0;
1522 if (!row_ptr->par()->spacing.isDefault()) {
1523 spacing_val = row_ptr->par()->spacing.getValue();
1525 spacing_val = bview->buffer()->params.spacing.getValue();
1528 labeladdon = int(lyxfont::maxDescent(labelfont) *
1529 layout.spacing.getValue() *
1531 + int(lyxfont::maxAscent(labelfont) *
1532 layout.spacing.getValue() *
1536 /* special code for the top label */
1537 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1538 || layout.labeltype == LABEL_BIBLIO
1539 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1540 && row_ptr->par()->IsFirstInSequence()
1541 && !row_ptr->par()->GetLabelstring().empty()) {
1542 float spacing_val = 1.0;
1543 if (!row_ptr->par()->spacing.isDefault()) {
1544 spacing_val = row_ptr->par()->spacing.getValue();
1546 spacing_val = bview->buffer()->params.spacing.getValue();
1550 (lyxfont::maxAscent(labelfont) *
1551 layout.spacing.getValue() *
1553 +(lyxfont::maxDescent(labelfont) *
1554 layout.spacing.getValue() *
1556 + layout.topsep * DefaultHeight()
1557 + layout.labelbottomsep * DefaultHeight());
1560 /* and now the layout spaces, for example before and after a section,
1561 * or between the items of a itemize or enumerate environment */
1563 if (!firstpar->pagebreak_top) {
1564 LyXParagraph * prev = row_ptr->par()->Previous();
1566 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1567 if (prev && prev->GetLayout() == firstpar->GetLayout()
1568 && prev->GetDepth() == firstpar->GetDepth()
1569 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1571 layoutasc = (layout.itemsep * DefaultHeight());
1573 else if (row_ptr->previous()) {
1574 tmptop = layout.topsep;
1576 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1577 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1578 row_ptr->previous()->par()->
1579 GetLayout()).bottomsep;
1582 layoutasc = (tmptop * DefaultHeight());
1584 else if (row_ptr->par()->line_top){
1585 tmptop = layout.topsep;
1588 layoutasc = (tmptop * DefaultHeight());
1591 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1593 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1594 prev->GetLayout()).parsep * DefaultHeight());
1597 if (firstpar->Previous()
1598 && firstpar->Previous()->GetDepth() == 0
1599 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1602 else if (firstpar->Previous()){
1603 maxasc += int(layout.parsep * DefaultHeight());
1609 /* is it a bottom line? */
1610 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1611 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1613 /* the paper margins */
1614 if (!par->next && bv_owner)
1615 maxdesc += LYX_PAPER_MARGIN;
1617 /* add the vertical spaces, that the user added */
1618 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1619 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1621 /* do not forget the DTP-lines!
1622 * there height depends on the font of the nearest character */
1623 if (firstpar->line_bottom)
1624 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1625 par, par->Last() - 1));
1627 /* and now the pagebreaks */
1628 if (firstpar->pagebreak_bottom)
1629 maxdesc += 3 * DefaultHeight();
1631 /* and now the layout spaces, for example before and after a section,
1632 * or between the items of a itemize or enumerate environment */
1633 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1634 LyXParagraph * nextpar = row_ptr->par()->Next();
1635 LyXParagraph * comparepar = row_ptr->par();
1639 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1640 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1641 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1642 if (comparepar->GetLayout()!= nextpar->GetLayout()
1643 || nextpar->GetLabelWidthString() !=
1644 comparepar->GetLabelWidthString())
1645 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1647 if (unusual > usual)
1648 layoutdesc = unusual;
1652 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1654 if (comparepar->GetLayout()!= nextpar->GetLayout()
1655 || nextpar->GetLabelWidthString() !=
1656 comparepar->GetLabelWidthString())
1657 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1662 /* incalculate the layout spaces */
1663 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1664 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1667 /* table stuff -- begin*/
1668 if (row_ptr->par()->table){
1669 maxasc += row_ptr->par()->table->
1670 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1672 /* table stuff -- end*/
1674 /* calculate the new height of the text */
1675 height -= row_ptr->height();
1677 row_ptr->height(maxasc + maxdesc + labeladdon);
1678 row_ptr->baseline(maxasc + labeladdon);
1680 height += row_ptr->height();
1684 /* Appends the implicit specified paragraph behind the specified row,
1685 * start at the implicit given position */
1686 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1688 bool not_ready = true;
1690 // The last character position of a paragraph is an invariant so we can
1691 // safely get it here. (Asger)
1692 int lastposition = row->par()->Last();
1695 // Get the next breakpoint
1696 int z = NextBreakPoint(bview, row, workWidth(bview));
1700 // Insert the new row
1701 if (z < lastposition) {
1703 InsertRow(row, row->par(), z);
1710 // Set the dimensions of the row
1711 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1712 SetHeightOfRow(bview, tmprow);
1714 } while (not_ready);
1718 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1720 bool not_ready = true;
1723 /* get the next breakpoint */
1724 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1727 if (z < row->par()->Last() ) {
1728 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1731 InsertRow(row, row->par(), z);
1737 if (row->pos() == z)
1738 not_ready = false; // the rest will not change
1744 /* if there are some rows too much, delete them */
1745 /* only if you broke the whole paragraph! */
1746 Row * tmprow2 = row;
1747 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1748 tmprow2 = tmprow2->next();
1750 while (tmprow2 != row) {
1751 tmprow2 = tmprow2->previous();
1752 RemoveRow(tmprow2->next());
1757 /* set the dimensions of the row */
1758 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1759 SetHeightOfRow(bview, tmprow);
1760 } while (not_ready);
1764 // this is just a little changed version of break again
1765 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1767 // get the next breakpoint
1768 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1771 if (z < row->par()->Last() ) {
1773 || (row->next() && row->next()->par() != row->par())) {
1774 /* insert a new row */
1776 InsertRow(row, row->par(), z);
1782 if (row->pos() != z)
1786 // if there are some rows too much, delete them
1787 // only if you broke the whole paragraph!
1788 Row * tmprow2 = row;
1789 while (tmprow2->next()
1790 && tmprow2->next()->par() == row->par()) {
1791 tmprow2 = tmprow2->next();
1793 while (tmprow2 != row) {
1794 tmprow2 = tmprow2->previous();
1795 RemoveRow(tmprow2->next());
1799 // set the dimensions of the row
1800 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1801 SetHeightOfRow(bview, tmprow);
1805 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1807 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1808 cursor.par()->GetLayout());
1810 /* table stuff -- begin */
1811 if (cursor.par()->table) {
1812 // breaking of tables is only allowed at the beginning or the end */
1813 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1814 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1815 return; // no breaking of tables allowed
1817 /* table stuff -- end */
1819 // this is only allowed, if the current paragraph is not empty or caption
1820 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1822 layout.labeltype!= LABEL_SENSITIVE)
1825 SetUndo(bview->buffer(), Undo::INSERT,
1826 cursor.par()->ParFromPos(cursor.pos())->previous,
1827 cursor.par()->ParFromPos(cursor.pos())->next);
1830 /* table stuff -- begin */
1831 if (cursor.par()->table) {
1832 int cell = NumberOfCell(cursor.par(), cursor.pos());
1833 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1834 SetCursor(bview, cursor.par(), cursor.par()->size());
1836 /* table stuff -- end */
1838 // please break always behind a space
1839 if (cursor.pos() < cursor.par()->Last()
1840 && cursor.par()->IsLineSeparator(cursor.pos()))
1841 cursor.pos(cursor.pos() + 1);
1843 // break the paragraph
1847 keep_layout = layout.isEnvironment();
1848 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1851 /* table stuff -- begin */
1852 if (cursor.par()->table){
1853 // the table should stay with the contents
1855 cursor.par()->Next()->table = cursor.par()->table;
1856 cursor.par()->table = 0;
1859 /* table stuff -- end */
1861 // well this is the caption hack since one caption is really enough
1862 if (layout.labeltype == LABEL_SENSITIVE) {
1864 // set to standard-layout
1865 cursor.par()->SetLayout(bview->buffer()->params, 0);
1867 // set to standard-layout
1868 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1871 /* if the cursor is at the beginning of a row without prior newline,
1873 * This touches only the screen-update. Otherwise we would may have
1874 * an empty row on the screen */
1875 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1876 cursor.row()->pos() == cursor.pos()) {
1880 status = LyXText::NEED_MORE_REFRESH;
1881 refresh_row = cursor.row();
1882 refresh_y = cursor.y() - cursor.row()->baseline();
1884 // Do not forget the special right address boxes
1885 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1886 while (refresh_row->previous() &&
1887 refresh_row->previous()->par() == refresh_row->par()) {
1888 refresh_row = refresh_row->previous();
1889 refresh_y -= refresh_row->height();
1892 RemoveParagraph(cursor.row());
1894 // set the dimensions of the cursor row
1895 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1897 SetHeightOfRow(bview, cursor.row());
1899 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1900 && cursor.par()->Next()->IsNewline(0))
1901 cursor.par()->Next()->Erase(0);
1903 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1905 UpdateCounters(bview, cursor.row()->previous());
1907 /* This check is necessary. Otherwise the new empty paragraph will
1908 * be deleted automatically. And it is more friendly for the user! */
1910 SetCursor(bview, cursor.par()->Next(), 0);
1912 SetCursor(bview, cursor.par(), 0);
1914 if (cursor.row()->next())
1915 BreakAgain(bview, cursor.row()->next());
1921 void LyXText::OpenFootnote(BufferView * bview)
1923 LyXParagraph * endpar,* tmppar;
1926 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1928 /* if there is no footnote in this paragraph, just return. */
1930 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1933 /* ok, move the cursor right before the footnote */
1935 /* just a little faster than using CursorRight() */
1937 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1938 cursor.pos(cursor.pos() + 1);
1941 /* now the cursor is at the beginning of the physical par */
1942 SetCursor(bview, cursor.par(),
1943 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1945 /* the cursor must be exactly before the footnote */
1946 par = cursor.par()->ParFromPos(cursor.pos());
1948 status = LyXText::NEED_MORE_REFRESH;
1949 refresh_row = cursor.row();
1950 refresh_y = cursor.y() - cursor.row()->baseline();
1952 tmppar = cursor.par();
1953 endpar = cursor.par()->Next();
1956 tmppar->OpenFootnote(cursor.pos());
1957 RemoveParagraph(row);
1958 /* set the dimensions of the cursor row */
1959 row->fill(Fill(bview, row, workWidth(bview)));
1960 SetHeightOfRow(bview, row);
1961 // CHECK See comment on top of text.C
1962 tmppar = tmppar->Next();
1964 while (tmppar != endpar) {
1966 InsertParagraph(bview, tmppar, row);
1967 while (row->next() && row->next()->par() == tmppar)
1969 tmppar = tmppar->Next();
1972 SetCursor(bview, par->next, 0);
1973 sel_cursor = cursor;
1977 /* table stuff -- begin*/
1979 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
1981 if (!cursor.par()->table)
1982 return; /* this should never happen */
1984 int actCell = NumberOfCell(cursor.par(), cursor.pos());
1985 SetUndo(bview->buffer(), Undo::FINISH,
1986 cursor.par()->ParFromPos(cursor.pos())->previous,
1987 cursor.par()->ParFromPos(cursor.pos())->next);
1990 case LyXTable::SET_PWIDTH:
1991 cursor.par()->table->SetPWidth(actCell, val);
1993 case LyXTable::SET_SPECIAL_COLUMN:
1994 case LyXTable::SET_SPECIAL_MULTI:
1995 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2000 RedoParagraph(bview);
2004 void LyXText::TableFeatures(BufferView * bview, int feature) const
2007 int setAlign = LYX_ALIGN_LEFT;
2011 if (!cursor.par()->table)
2012 return; /* this should never happen */
2014 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2015 SetUndo(bview->buffer(), Undo::FINISH,
2016 cursor.par()->ParFromPos(cursor.pos())->previous,
2017 cursor.par()->ParFromPos(cursor.pos())->next);
2020 case LyXTable::ALIGN_LEFT:
2021 setAlign= LYX_ALIGN_LEFT;
2023 case LyXTable::ALIGN_RIGHT:
2024 setAlign= LYX_ALIGN_RIGHT;
2026 case LyXTable::ALIGN_CENTER:
2027 setAlign= LYX_ALIGN_CENTER;
2033 case LyXTable::APPEND_ROW: {
2034 LyXParagraph::size_type pos = cursor.pos();
2036 /* move to the next row */
2037 int cell_org = actCell;
2038 int cell = cell_org;
2040 // if there is a ContRow following this row I have to add
2041 // the row after the ContRow's
2042 if ((pos < cursor.par()->Last()) &&
2043 cursor.par()->table->RowHasContRow(cell_org)) {
2044 while((pos < cursor.par()->Last()) &&
2045 !cursor.par()->table->IsContRow(cell)) {
2046 while (pos < cursor.par()->Last() &&
2047 !cursor.par()->IsNewline(pos))
2049 if (pos < cursor.par()->Last())
2053 while((pos < cursor.par()->Last()) &&
2054 cursor.par()->table->IsContRow(cell)) {
2055 while (pos < cursor.par()->Last() &&
2056 !cursor.par()->IsNewline(pos))
2058 if (pos < cursor.par()->Last())
2063 if (pos < cursor.par()->Last())
2066 while (pos < cursor.par()->Last() &&
2067 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2068 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2070 if (pos < cursor.par()->Last())
2075 /* insert the new cells */
2076 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2077 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2078 LyXFont font(LyXFont::ALL_INHERIT,lang);
2079 for (int i = 0; i < number; ++i) {
2080 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2081 cursor.par()->SetFont(pos, font);
2084 /* append the row into the table */
2085 cursor.par()->table->AppendRow(cell_org);
2086 RedoParagraph(bview);
2089 case LyXTable::APPEND_CONT_ROW: {
2090 LyXParagraph::size_type pos = cursor.pos();
2091 /* move to the next row */
2092 int cell_org = actCell;
2093 int cell = cell_org;
2095 // if there is already a controw but not for this cell
2096 // the AppendContRow sets only the right values but does
2097 // not actually add a row
2098 if (cursor.par()->table->RowHasContRow(cell_org) &&
2099 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2100 cursor.par()->table->AppendContRow(cell_org);
2101 RedoParagraph(bview);
2104 while (pos < cursor.par()->Last() &&
2106 || !cursor.par()->table->IsFirstCell(cell))){
2107 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2109 if (pos < cursor.par()->Last())
2114 /* insert the new cells */
2115 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2116 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2117 LyXFont font(LyXFont::ALL_INHERIT,lang);
2118 for (int i = 0; i < number; ++i) {
2119 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2120 cursor.par()->SetFont(pos, font);
2123 /* append the row into the table */
2124 cursor.par()->table->AppendContRow(cell_org);
2125 RedoParagraph(bview);
2128 case LyXTable::APPEND_COLUMN: {
2129 LyXParagraph::size_type pos = 0;
2130 int cell_org = actCell;
2132 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2133 LyXFont font(LyXFont::ALL_INHERIT,lang);
2135 if (pos && (cursor.par()->IsNewline(pos-1))){
2136 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2137 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2138 cursor.par()->SetFont(pos, font);
2139 if (pos <= cursor.pos())
2140 cursor.pos(cursor.pos() + 1);
2146 } while (pos <= cursor.par()->Last());
2147 /* remember that the very last cell doesn't end with a newline.
2148 This saves one byte memory per table ;-) */
2149 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2150 LyXParagraph::size_type last = cursor.par()->Last();
2151 cursor.par()->InsertChar(last, LyXParagraph::META_NEWLINE);
2152 cursor.par()->SetFont(last, font);
2155 /* append the column into the table */
2156 cursor.par()->table->AppendColumn(cell_org);
2158 RedoParagraph(bview);
2161 case LyXTable::DELETE_ROW:
2162 if (bview->the_locking_inset)
2163 bview->unlockInset(bview->the_locking_inset);
2164 RemoveTableRow(cursor);
2165 RedoParagraph(bview);
2168 case LyXTable::DELETE_COLUMN: {
2169 LyXParagraph::size_type pos = 0;
2170 int cell_org = actCell;
2172 if (bview->the_locking_inset)
2173 bview->unlockInset(bview->the_locking_inset);
2175 if (!pos || (cursor.par()->IsNewline(pos-1))){
2176 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2178 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2179 cursor.par()->Erase(pos);
2180 if (pos < cursor.par()->Last())
2181 cursor.par()->Erase(pos);
2183 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2184 --pos; // because of pos++ below
2189 } while (pos <= cursor.par()->Last());
2191 /* delete the column from the table */
2192 cursor.par()->table->DeleteColumn(cell_org);
2194 /* set the cursor to the beginning of the table, where else? */
2196 RedoParagraph(bview);
2199 case LyXTable::TOGGLE_LINE_TOP:
2200 lineSet = !cursor.par()->table->TopLine(actCell);
2202 cursor.par()->table->SetTopLine(actCell, lineSet);
2204 LyXParagraph::size_type i;
2206 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2207 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2208 cursor.par()->table->SetTopLine(n, lineSet);
2213 RedoParagraph(bview);
2216 case LyXTable::TOGGLE_LINE_BOTTOM:
2217 lineSet = !cursor.par()->table->BottomLine(actCell);
2219 cursor.par()->table->SetBottomLine(actCell, lineSet);
2221 LyXParagraph::size_type i;
2223 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2224 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2225 cursor.par()->table->SetBottomLine(n, lineSet);
2230 RedoParagraph(bview);
2233 case LyXTable::TOGGLE_LINE_LEFT:
2234 lineSet = !cursor.par()->table->LeftLine(actCell);
2236 cursor.par()->table->SetLeftLine(actCell, lineSet);
2238 LyXParagraph::size_type i;
2240 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2241 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2242 cursor.par()->table->SetLeftLine(n, lineSet);
2247 RedoParagraph(bview);
2250 case LyXTable::TOGGLE_LINE_RIGHT:
2251 lineSet = !cursor.par()->table->RightLine(actCell);
2253 cursor.par()->table->SetRightLine(actCell, lineSet);
2256 LyXParagraph::size_type i = sel_start_cursor.pos();
2257 for (; i <= sel_end_cursor.pos(); ++i) {
2258 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2259 cursor.par()->table->SetRightLine(n, lineSet);
2264 RedoParagraph(bview);
2267 case LyXTable::ALIGN_LEFT:
2268 case LyXTable::ALIGN_RIGHT:
2269 case LyXTable::ALIGN_CENTER:
2271 cursor.par()->table->SetAlignment(actCell, setAlign);
2274 LyXParagraph::size_type i = sel_start_cursor.pos();
2275 for (; i <= sel_end_cursor.pos(); ++i) {
2276 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2277 cursor.par()->table->SetAlignment(n, setAlign);
2282 RedoParagraph(bview);
2285 case LyXTable::DELETE_TABLE:
2286 SetCursorIntern(bview, cursor.par(), 0);
2287 delete cursor.par()->table;
2288 cursor.par()->table = 0;
2289 // temporary: Should put table in simple_cut_buffer (with before and after
2290 // dummy-paragraph !!
2291 // not necessar anymore with UNDO :)
2292 for (LyXParagraph::size_type i =
2293 cursor.par()->size() - 1; i >= 0; --i)
2294 cursor.par()->Erase(i);
2295 RedoParagraph(bview);
2298 case LyXTable::MULTICOLUMN: {
2300 // check wether we are completly in a multicol
2301 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2302 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2303 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2304 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2308 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2309 LyXParagraph::size_type pos = cursor.pos();
2310 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2312 for (; newlines; --newlines)
2313 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2314 RedoParagraph(bview);
2318 // selection must be in one row (or no selection)
2320 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2323 RedoParagraph(bview);
2327 if (sel_start_cursor.row() == sel_end_cursor.row()){
2328 LyXParagraph::size_type i;
2330 for (i = sel_start_cursor.pos();
2331 i < sel_end_cursor.pos(); ++i){
2332 if (sel_start_cursor.par()->IsNewline(i)){
2333 sel_start_cursor.par()->Erase(i);
2334 // check for double-blanks
2335 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2337 (i < sel_start_cursor.par()->Last()
2338 && !sel_start_cursor.par()->IsLineSeparator(i)))
2339 sel_start_cursor.par()->InsertChar(i, ' ');
2341 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2347 cursor.par()->table->
2348 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2349 sel_start_cursor.pos()),
2351 cursor.pos(sel_start_cursor.pos());
2352 RedoParagraph(bview);
2356 WriteAlert(_("Impossible Operation!"),
2357 _("Multicolumns can only be horizontally."),
2364 case LyXTable::SET_ALL_LINES:
2366 case LyXTable::UNSET_ALL_LINES:
2368 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2372 LyXParagraph::size_type i;
2374 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2375 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2376 cursor.par()->table->SetAllLines(n, setLines);
2381 RedoParagraph(bview);
2383 case LyXTable::SET_LONGTABLE:
2384 cursor.par()->table->SetLongTable(true);
2386 case LyXTable::UNSET_LONGTABLE:
2387 cursor.par()->table->SetLongTable(false);
2389 case LyXTable::SET_ROTATE_TABLE:
2390 cursor.par()->table->SetRotateTable(true);
2392 case LyXTable::UNSET_ROTATE_TABLE:
2393 cursor.par()->table->SetRotateTable(false);
2395 case LyXTable::SET_ROTATE_CELL:
2397 cursor.par()->table->SetRotateCell(actCell, true);
2399 LyXParagraph::size_type i;
2401 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2402 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2403 cursor.par()->table->SetRotateCell(n, true);
2409 case LyXTable::UNSET_ROTATE_CELL:
2411 cursor.par()->table->SetRotateCell(actCell, false);
2414 LyXParagraph::size_type i = sel_start_cursor.pos();
2415 for (; i <= sel_end_cursor.pos(); ++i) {
2416 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2417 cursor.par()->table->SetRotateCell(n, false);
2423 case LyXTable::SET_LINEBREAKS:
2424 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2426 cursor.par()->table->SetLinebreaks(actCell, what);
2428 LyXParagraph::size_type i;
2430 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2431 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2432 cursor.par()->table->SetLinebreaks(n, what);
2438 case LyXTable::SET_LTFIRSTHEAD:
2439 cursor.par()->table->SetLTHead(actCell, true);
2441 case LyXTable::SET_LTHEAD:
2442 cursor.par()->table->SetLTHead(actCell, false);
2444 case LyXTable::SET_LTFOOT:
2445 cursor.par()->table->SetLTFoot(actCell, false);
2447 case LyXTable::SET_LTLASTFOOT:
2448 cursor.par()->table->SetLTFoot(actCell, true);
2450 case LyXTable::SET_LTNEWPAGE:
2451 what = !cursor.par()->table->LTNewPage(actCell);
2452 cursor.par()->table->SetLTNewPage(actCell, what);
2458 void LyXText::InsertCharInTable(BufferView * bview, char c)
2463 bool jumped_over_space;
2465 /* first check, if there will be two blanks together or a blank at
2466 * the beginning of a paragraph.
2467 * I decided to handle blanks like normal characters, the main
2468 * difference are the special checks when calculating the row.fill
2469 * (blank does not count at the end of a row) and the check here */
2471 LyXFont realtmpfont = real_current_font;
2472 LyXFont rawtmpfont = current_font; /* store the current font.
2473 * This is because of the use
2474 * of cursor movements. The moving
2475 * cursor would refresh the
2478 // Get the font that is used to calculate the baselineskip
2479 LyXParagraph::size_type const lastpos =
2480 cursor.par()->Last();
2481 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2484 jumped_over_space = false;
2485 if (IsLineSeparatorChar(c)) {
2486 if ((cursor.pos() > 0 &&
2487 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2488 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2489 || (cursor.pos() == 0 &&
2490 !(cursor.par()->Previous()
2491 && cursor.par()->Previous()->footnoteflag
2492 == LyXParagraph::OPEN_FOOTNOTE)))
2494 } else if (IsNewlineChar(c)) {
2495 if (!IsEmptyTableCell()) {
2496 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2503 y = cursor.y() - row->baseline();
2504 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2505 * already inserted the character */
2506 cursor.par()->InsertChar(cursor.pos(), c);
2507 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2509 if (!jumped_over_space) {
2510 /* refresh the positions */
2512 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2513 tmprow = tmprow->next();
2514 tmprow->pos(tmprow->pos() + 1);
2518 cursor.pos(cursor.pos() + 1);
2520 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2522 current_font = rawtmpfont;
2523 real_current_font = realtmpfont;
2525 /* check, whether the last character's font has changed. */
2526 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2527 && rawparfont != rawtmpfont)
2528 RedoHeightOfParagraph(bview, cursor);
2532 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2533 LyXParagraph::size_type pos)
2536 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2537 par->GetInset(pos) && par->GetInset(pos)->display()){
2538 par->GetInset(pos)->display(false);
2542 Row * row = GetRow(par, pos, y);
2544 int tmpheight = row->height();
2545 SetHeightOfRow(bview, row);
2547 LyXParagraph::size_type tmp_pos = pos;
2548 /* update the table information */
2549 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2551 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2552 WidthOfCell(bview, par, tmp_pos))) {
2553 LyXCursor tmpcursor = cursor;
2554 SetCursorIntern(bview, par, pos, false);
2555 /* make a complete redraw */
2556 RedoDrawingOfParagraph(bview, cursor);
2560 /* redraw only the row */
2561 LyXCursor tmpcursor = cursor;
2562 SetCursorIntern(bview, par, pos);
2563 //CHECK See comment on top of text.C
2565 refresh_x = cursor.x();
2567 refresh_pos = cursor.pos();
2570 if (tmpheight == row->height())
2571 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2573 status = LyXText::NEED_MORE_REFRESH;
2575 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2580 void LyXText::BackspaceInTable(BufferView * bview)
2582 Row * tmprow, * row;
2585 LyXFont rawtmpfont = current_font;
2586 LyXFont realtmpfont = real_current_font;
2588 // Get the font that is used to calculate the baselineskip
2589 int const lastpos = cursor.par()->Last();
2590 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2593 if (cursor.pos() == 0) {
2594 /* no pasting of table paragraphs */
2598 /* this is the code for a normal backspace, not pasting
2600 SetUndo(bview->buffer(), Undo::DELETE,
2601 cursor.par()->ParFromPos(cursor.pos())->previous,
2602 cursor.par()->ParFromPos(cursor.pos())->next);
2604 CursorLeftIntern(bview);
2606 /* some insets are undeletable here */
2607 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2608 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2613 y = cursor.y() - row->baseline();
2615 /* some special code when deleting a newline. */
2616 if (cursor.par()->IsNewline(cursor.pos())) {
2620 cursor.par()->Erase(cursor.pos());
2622 /* refresh the positions */
2624 while (tmprow->next()
2625 && tmprow->next()->par() == row->par()) {
2626 tmprow = tmprow->next();
2627 tmprow->pos(tmprow->pos() - 1);
2631 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2633 /* check, wether the last characters font has changed. */
2634 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2635 && rawparfont != rawtmpfont)
2636 RedoHeightOfParagraph(bview, cursor);
2638 /* restore the current font
2639 * That is what a user expects! */
2640 current_font = rawtmpfont;
2641 real_current_font = realtmpfont;
2643 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2645 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2646 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2649 /* table stuff -- end*/
2652 // Just a macro to make some thing easier.
2653 void LyXText::RedoParagraph(BufferView * bview) const
2656 RedoParagraphs(bview, cursor, cursor.par()->Next());
2657 SetCursorIntern(bview, cursor.par(), cursor.pos());
2661 /* insert a character, moves all the following breaks in the
2662 * same Paragraph one to the right and make a rebreak */
2663 void LyXText::InsertChar(BufferView * bview, char c)
2665 SetUndo(bview->buffer(), Undo::INSERT,
2666 cursor.par()->ParFromPos(cursor.pos())->previous,
2667 cursor.par()->ParFromPos(cursor.pos())->next);
2669 // When the free-spacing option is set for the current layout,
2670 // disable the double-space checking
2673 textclasslist.Style(bview->buffer()->params.textclass,
2674 cursor.row()->par()->GetLayout()).free_spacing;
2677 /* table stuff -- begin*/
2678 if (cursor.par()->table) {
2679 InsertCharInTable(bview, c);
2683 /* table stuff -- end*/
2685 /* First check, if there will be two blanks together or a blank at
2686 the beginning of a paragraph.
2687 I decided to handle blanks like normal characters, the main
2688 difference are the special checks when calculating the row.fill
2689 (blank does not count at the end of a row) and the check here */
2691 // The bug is triggered when we type in a description environment:
2692 // The current_font is not changed when we go from label to main text
2693 // and it should (along with realtmpfont) when we type the space.
2694 // CHECK There is a bug here! (Asger)
2696 LyXFont realtmpfont = real_current_font;
2697 LyXFont rawtmpfont = current_font; /* store the current font.
2698 * This is because of the use
2699 * of cursor movements. The moving
2700 * cursor would refresh the
2703 // Get the font that is used to calculate the baselineskip
2704 LyXParagraph::size_type lastpos = cursor.par()->Last();
2705 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2708 bool jumped_over_space = false;
2710 if (!freeSpacing && IsLineSeparatorChar(c)) {
2711 if ((cursor.pos() > 0
2712 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2713 || (cursor.pos() > 0
2714 && cursor.par()->IsNewline(cursor.pos() - 1))
2715 || (cursor.pos() == 0
2716 && !(cursor.par()->Previous()
2717 && cursor.par()->Previous()->footnoteflag
2718 == LyXParagraph::OPEN_FOOTNOTE))) {
2719 if (cursor.pos() == 0 )
2720 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2722 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2726 } else if (IsNewlineChar(c)) {
2727 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2728 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2732 /* No newline at first position
2733 * of a paragraph or behind labels.
2734 * TeX does not allow that. */
2736 if (cursor.pos() < cursor.par()->Last() &&
2737 cursor.par()->IsLineSeparator(cursor.pos()))
2738 // newline always after a blank!
2739 CursorRightIntern(bview);
2740 cursor.row()->fill(-1); // to force a new break
2743 // the display inset stuff
2744 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2745 && cursor.row()->par()->GetInset(cursor.row()->pos())
2746 && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
2747 cursor.row()->fill(-1); // to force a new break
2749 // get the cursor row fist
2750 Row * row = cursor.row();
2751 long y = cursor.y() - row->baseline();
2752 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2753 * already insertet the character */
2754 cursor.par()->InsertChar(cursor.pos(), c);
2755 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2757 if (!jumped_over_space) {
2758 // refresh the positions
2760 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2761 tmprow = tmprow->next();
2762 tmprow->pos(tmprow->pos() + 1);
2766 // Is there a break one row above
2767 if ((cursor.par()->IsLineSeparator(cursor.pos())
2768 || cursor.par()->IsNewline(cursor.pos())
2769 || cursor.row()->fill() == -1)
2770 && row->previous() && row->previous()->par() == row->par()) {
2771 LyXParagraph::size_type z = NextBreakPoint(bview,
2774 if ( z >= row->pos()) {
2777 // set the dimensions of the row above
2778 row->previous()->fill(Fill(bview,
2782 SetHeightOfRow(bview, row->previous());
2784 y -= row->previous()->height();
2786 refresh_row = row->previous();
2787 status = LyXText::NEED_MORE_REFRESH;
2789 BreakAgainOneRow(bview, row);
2791 current_font = rawtmpfont;
2792 real_current_font = realtmpfont;
2793 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2794 false, cursor.boundary());
2795 // cursor MUST be in row now.
2797 if (row->next() && row->next()->par() == row->par())
2798 need_break_row = row->next();
2802 // check, wether the last characters font has changed.
2803 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2804 && rawparfont != rawtmpfont)
2805 RedoHeightOfParagraph(bview, cursor);
2812 // recalculate the fill of the row
2813 if (row->fill() >= 0) /* needed because a newline
2814 * will set fill to -1. Otherwise
2815 * we would not get a rebreak! */
2816 row->fill(Fill(bview, row, workWidth(bview)));
2817 if (row->fill() < 0 ) {
2820 refresh_x = cursor.x();
2821 refresh_pos = cursor.pos();
2822 status = LyXText::NEED_MORE_REFRESH;
2823 BreakAgainOneRow(bview, row);
2824 // will the cursor be in another row now?
2825 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2826 if (row->next() && row->next()->par() == row->par())
2827 // this should always be true
2829 BreakAgainOneRow(bview, row);
2831 current_font = rawtmpfont;
2832 real_current_font = realtmpfont;
2834 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2836 if (row->next() && row->next()->par() == row->par())
2837 need_break_row = row->next();
2842 refresh_x = cursor.x();
2844 refresh_pos = cursor.pos();
2846 int tmpheight = row->height();
2847 SetHeightOfRow(bview, row);
2848 if (tmpheight == row->height())
2849 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2851 status = LyXText::NEED_MORE_REFRESH;
2853 current_font = rawtmpfont;
2854 real_current_font = realtmpfont;
2855 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2859 // check, wether the last characters font has changed.
2860 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2861 && rawparfont != rawtmpfont) {
2862 RedoHeightOfParagraph(bview, cursor);
2864 // now the special right address boxes
2865 if (textclasslist.Style(bview->buffer()->params.textclass,
2866 cursor.par()->GetLayout()).margintype
2867 == MARGIN_RIGHT_ADDRESS_BOX) {
2868 RedoDrawingOfParagraph(bview, cursor);
2876 void LyXText::charInserted()
2878 // Here we could call FinishUndo for every 20 characters inserted.
2879 // This is from my experience how emacs does it.
2880 static unsigned int counter = 0;
2889 void LyXText::PrepareToPrint(BufferView * bview,
2890 Row * row, float & x,
2891 float & fill_separator,
2893 float & fill_label_hfill,
2898 float w = row->fill();
2900 fill_label_hfill = 0;
2902 fill_label_hfill = 0;
2904 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2907 x = RightMargin(bview->buffer(), row);
2908 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2909 LyXFont font(LyXFont::ALL_SANE);
2910 font.setSize(LyXFont::SIZE_SMALL);
2911 x += lyxfont::width("Mwide-figM", font);
2913 } else if (workWidth(bview) > 0)
2914 x = LeftMargin(bview, row);
2918 // is there a manual margin with a manual label
2919 if (textclasslist.Style(bview->buffer()->params.textclass,
2920 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2921 && textclasslist.Style(bview->buffer()->params.textclass,
2922 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2924 /* one more since labels are left aligned */
2925 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2926 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2927 fill_label_hfill = LabelFill(bview, row) / nlh;
2931 // are there any hfills in the row?
2932 float nh = NumberOfHfills(bview->buffer(), row);
2935 /* table stuff -- begin*/
2936 if (row->par()->table) {
2937 w = workWidth(bview) - row->par()->table->WidthOfTable()
2938 - x - RightMargin(bview->buffer(), row);
2939 nh = 0; /* ignore hfills in tables */
2941 /* table stuff -- end*/
2946 // is it block, flushleft or flushright?
2947 // set x how you need it
2949 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2950 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2952 align = row->par()->FirstPhysicalPar()->align;
2954 // center displayed insets
2955 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2956 && row->par()->GetInset(row->pos())
2957 && row->par()->GetInset(row->pos())->display())
2958 align = LYX_ALIGN_CENTER;
2961 case LYX_ALIGN_BLOCK:
2962 ns = NumberOfSeparators(bview->buffer(), row);
2963 if (ns && row->next() && row->next()->par() == row->par() &&
2964 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
2965 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
2966 && row->next()->par()->GetInset(row->next()->pos())
2967 && row->next()->par()->GetInset(row->next()->pos())->display())
2969 fill_separator = w / ns;
2973 case LYX_ALIGN_RIGHT:
2976 case LYX_ALIGN_CENTER:
2984 ComputeBidiTables(bview->buffer(), row);
2986 LyXParagraph::size_type main_body =
2987 BeginningOfMainBody(bview->buffer(), row->par());
2988 LyXParagraph::size_type last = RowLast(row);
2990 if (main_body > 0 &&
2991 (main_body-1 > last ||
2992 !row->par()->IsLineSeparator(main_body-1))) {
2993 LyXLayout const & layout =
2994 textclasslist.Style(bview->buffer()->params.textclass,
2995 row->par()->GetLayout());
2996 x += lyxfont::width(layout.labelsep,
2997 GetFont(bview->buffer(), row->par(), -2));
2998 if (main_body-1 <= last)
2999 x += fill_label_hfill;
3004 /* important for the screen */
3007 /* the cursor set functions have a special mechanism. When they
3008 * realize, that you left an empty paragraph, they will delete it.
3009 * They also delete the corresponding row */
3011 void LyXText::CursorRightOneWord(BufferView * bview) const
3013 // treat floats, HFills and Insets as words
3014 LyXCursor tmpcursor = cursor;
3015 // CHECK See comment on top of text.C
3017 if (tmpcursor.pos() == tmpcursor.par()->Last()
3018 && tmpcursor.par()->Next()) {
3019 tmpcursor.par(tmpcursor.par()->Next());
3024 // Skip through initial nonword stuff.
3025 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3026 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3028 // printf("Current pos1 %d", tmpcursor.pos()) ;
3029 tmpcursor.pos(tmpcursor.pos() + 1);
3032 // Advance through word.
3033 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3034 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3036 // printf("Current pos2 %d", tmpcursor.pos()) ;
3037 tmpcursor.pos(tmpcursor.pos() + 1);
3041 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3045 void LyXText::CursorTab(BufferView * bview) const
3048 if (cursor.par()->table) {
3049 int cell = NumberOfCell(cursor.par(), cursor.pos());
3050 while(cursor.par()->table->IsContRow(cell)) {
3052 cell = NumberOfCell(cursor.par(), cursor.pos());
3054 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3055 TableFeatures(bview, LyXTable::APPEND_ROW);
3058 LyXCursor tmpcursor = cursor;
3059 while (tmpcursor.pos() < tmpcursor.par()->Last()
3060 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3061 tmpcursor.pos(tmpcursor.pos() + 1);
3063 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3064 if (tmpcursor.par()->Next()) {
3065 tmpcursor.par(tmpcursor.par()->Next());
3069 tmpcursor.pos(tmpcursor.pos() + 1);
3070 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3072 if (cursor.par()->table) {
3073 int cell = NumberOfCell(cursor.par(), cursor.pos());
3074 while (cursor.par()->table->IsContRow(cell) &&
3075 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3077 while (tmpcursor.pos() < tmpcursor.par()->Last()
3078 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3079 tmpcursor.pos(tmpcursor.pos() + 1);
3081 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3082 if (tmpcursor.par()->Next()) {
3083 tmpcursor.par(tmpcursor.par()->Next());
3087 tmpcursor.pos(tmpcursor.pos() + 1);
3088 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3089 cell = NumberOfCell(cursor.par(), cursor.pos());
3096 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3097 of prior word, not to end of next prior word. */
3099 void LyXText::CursorLeftOneWord(BufferView * bview) const
3101 // treat HFills, floats and Insets as words
3102 LyXCursor tmpcursor = cursor;
3103 while (tmpcursor.pos()
3104 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3105 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3106 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3107 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3108 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3109 tmpcursor.pos(tmpcursor.pos() - 1);
3112 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3113 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3114 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3115 tmpcursor.pos(tmpcursor.pos() - 1);
3116 } else if (!tmpcursor.pos()) {
3117 if (tmpcursor.par()->Previous()){
3118 tmpcursor.par(tmpcursor.par()->Previous());
3119 tmpcursor.pos(tmpcursor.par()->Last());
3121 } else { // Here, tmpcursor != 0
3122 while (tmpcursor.pos() > 0 &&
3123 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3124 tmpcursor.pos(tmpcursor.pos() - 1);
3126 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3129 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3132 void LyXText::SelectWord(BufferView * bview)
3134 // Move cursor to the beginning, when not already there.
3136 && !cursor.par()->IsSeparator(cursor.pos()-1)
3137 && !cursor.par()->IsKomma(cursor.pos()-1) )
3138 CursorLeftOneWord(bview);
3140 // set the sel cursor
3141 sel_cursor = cursor;
3143 while ( cursor.pos() < cursor.par()->Last()
3144 && !cursor.par()->IsSeparator(cursor.pos())
3145 && !cursor.par()->IsKomma(cursor.pos()) )
3146 cursor.pos(cursor.pos() + 1);
3147 SetCursor(bview, cursor.par(), cursor.pos() );
3149 // finally set the selection
3150 SetSelection(bview);
3154 /* -------> Select the word currently under the cursor when:
3155 1: no selection is currently set,
3156 2: the cursor is not at the borders of the word. */
3158 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3161 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3162 && !cursor.par()->IsSeparator(cursor.pos())
3163 && !cursor.par()->IsKomma(cursor.pos())
3164 && !cursor.par()->IsSeparator(cursor.pos() -1)
3165 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3173 // This function is only used by the spellchecker for NextWord().
3174 // It doesn't handle LYX_ACCENTs and probably never will.
3175 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3177 LyXParagraph * tmppar = cursor.par();
3179 // If this is not the very first word, skip rest of
3180 // current word because we are probably in the middle
3181 // of a word if there is text here.
3182 if (cursor.pos() || cursor.par()->previous) {
3183 while (cursor.pos() < cursor.par()->Last()
3184 && cursor.par()->IsLetter(cursor.pos()))
3185 cursor.pos(cursor.pos() + 1);
3187 // Now, skip until we have real text (will jump paragraphs)
3188 while ((cursor.par()->Last() > cursor.pos()
3189 && (!cursor.par()->IsLetter(cursor.pos())
3190 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3191 .latex() == LyXFont::ON))
3192 || (cursor.par()->Last() == cursor.pos()
3193 && cursor.par()->Next())){
3194 if (cursor.pos() == cursor.par()->Last()) {
3195 cursor.par(cursor.par()->Next());
3198 cursor.pos(cursor.pos() + 1);
3201 // Update the value if we changed paragraphs
3202 if (cursor.par() != tmppar){
3203 SetCursor(bview, cursor.par(), cursor.pos());
3204 value = float(cursor.y())/float(height);
3207 // Start the selection from here
3208 sel_cursor = cursor;
3211 std::ostringstream latex;
3215 // and find the end of the word
3216 // (optional hyphens are part of a word)
3217 while (cursor.pos() < cursor.par()->Last()
3218 && (cursor.par()->IsLetter(cursor.pos()))
3219 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3220 && cursor.par()->GetInset(cursor.pos()) != 0
3221 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3223 && latex.str() == "\\-"
3225 && string(latex.str(), 3) == "\\-" // this is not nice at all
3228 cursor.pos(cursor.pos() + 1);
3230 #ifndef HAVE_SSTREAM
3231 delete [] latex.str();
3233 // Finally, we copy the word to a string and return it
3236 if (sel_cursor.pos() < cursor.pos()) {
3237 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3238 LyXParagraph::size_type i, j;
3239 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3240 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3241 str[j++] = cursor.par()->GetChar(i);
3249 // This one is also only for the spellchecker
3250 void LyXText::SelectSelectedWord(BufferView * bview)
3252 // move cursor to the beginning
3253 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3255 // set the sel cursor
3256 sel_cursor = cursor;
3259 std::ostringstream latex;
3264 // now find the end of the word
3265 while (cursor.pos() < cursor.par()->Last()
3266 && (cursor.par()->IsLetter(cursor.pos())
3267 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3268 && cursor.par()->GetInset(cursor.pos()) != 0
3269 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3271 && latex.str() == "\\-"
3273 && string(latex.str(), 3) == "\\-"
3276 cursor.pos(cursor.pos() + 1);
3278 #ifndef HAVE_SSTREAM
3279 delete [] latex.str();
3281 SetCursor(bview, cursor.par(), cursor.pos());
3283 // finally set the selection
3284 SetSelection(bview);
3288 /* -------> Delete from cursor up to the end of the current or next word. */
3289 void LyXText::DeleteWordForward(BufferView * bview)
3291 if (!cursor.par()->Last())
3294 LyXCursor tmpcursor = cursor;
3295 tmpcursor.row(0); //Â ??
3296 selection = true; // to avoid deletion
3297 CursorRightOneWord(bview);
3298 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3299 sel_cursor = cursor;
3301 SetSelection(bview);
3303 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3304 CutSelection(bview);
3309 /* -------> Delete from cursor to start of current or prior word. */
3310 void LyXText::DeleteWordBackward(BufferView * bview)
3312 if (!cursor.par()->Last())
3315 LyXCursor tmpcursor = cursor;
3316 tmpcursor.row(0); // ??
3317 selection = true; // to avoid deletion
3318 CursorLeftOneWord(bview);
3319 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3320 sel_cursor = cursor;
3322 SetSelection(bview);
3323 CutSelection(bview);
3328 /* -------> Kill to end of line. */
3329 void LyXText::DeleteLineForward(BufferView * bview)
3331 if (!cursor.par()->Last())
3332 // Paragraph is empty, so we just go to the right
3335 LyXCursor tmpcursor = cursor;
3336 // We can't store the row over a regular SetCursor
3337 // so we set it to 0 and reset it afterwards.
3338 tmpcursor.row(0); //Â ??
3339 selection = true; // to avoid deletion
3341 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3342 sel_cursor = cursor;
3344 SetSelection(bview);
3345 // What is this test for ??? (JMarc)
3347 DeleteWordForward(bview);
3349 CutSelection(bview);
3355 // Change the case of a word at cursor position.
3356 // This function directly manipulates LyXParagraph::text because there
3357 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3358 // that it is correct. I guess part of it should be moved to
3359 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3360 // it does not access outside of the allocated array as the older
3361 // version did. (JMarc)
3362 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3364 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3366 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3368 LyXParagraph::size_type tmppos =
3369 cursor.par()->PositionInParFromPos(cursor.pos());
3370 while (tmppos < tmppar->size()) {
3371 unsigned char c = tmppar->GetChar(tmppos);
3372 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3374 if (c != LyXParagraph::META_INSET) {
3376 case text_lowercase:
3379 case text_capitalization:
3381 action = text_lowercase;
3383 case text_uppercase:
3389 //tmppar->text[tmppos] = c;
3390 tmppar->SetChar(tmppos, c);
3393 CheckParagraph(bview, tmppar, tmppos);
3394 CursorRightOneWord(bview);
3398 void LyXText::Delete(BufferView * bview)
3400 // this is a very easy implementation
3402 LyXCursor old_cursor = cursor;
3403 int old_cur_par_id = old_cursor.par()->id();
3404 int old_cur_par_prev_id = old_cursor.par()->previous ?
3405 old_cursor.par()->previous->id() : 0;
3407 // just move to the right
3408 CursorRightIntern(bview);
3410 // CHECK Look at the comment here.
3411 // This check is not very good...
3412 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3413 // and that can very well delete the par or par->previous in
3414 // old_cursor. Will a solution where we compare paragraph id's
3416 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3417 == old_cur_par_prev_id
3418 && cursor.par()->id() != old_cur_par_id)
3419 return; // delete-empty-paragraph-mechanism has done it
3421 // if you had success make a backspace
3422 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3423 LyXCursor tmpcursor = cursor;
3424 cursor = old_cursor; // to make sure undo gets the right cursor position
3425 SetUndo(bview->buffer(), Undo::DELETE,
3426 cursor.par()->ParFromPos(cursor.pos())->previous,
3427 cursor.par()->ParFromPos(cursor.pos())->next);
3434 void LyXText::Backspace(BufferView * bview)
3437 /* table stuff -- begin */
3438 if (cursor.par()->table) {
3439 BackspaceInTable(bview);
3442 /* table stuff -- end */
3444 // LyXFont rawtmpfont = current_font;
3445 // LyXFont realtmpfont = real_current_font;
3446 // We don't need the above variables as calling to SetCursor() with third
3447 // argument eqaul to false, will not change current_font & real_current_font
3449 // Get the font that is used to calculate the baselineskip
3450 LyXParagraph::size_type lastpos = cursor.par()->Last();
3451 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3454 if (cursor.pos() == 0) {
3455 // The cursor is at the beginning of a paragraph, so the the backspace
3456 // will collapse two paragraphs into one.
3458 // we may paste some paragraphs
3460 // is it an empty paragraph?
3463 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3464 && !(cursor.par()->Next()
3465 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3466 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3467 // This is an empty paragraph and we delete it just by moving the cursor one step
3468 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3469 // of the paragraph.
3471 if (cursor.par()->previous) {
3472 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3473 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3474 && cursor.par()->footnoteflag == tmppar->footnoteflag
3475 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3476 // Inherit botom DTD from the paragraph below.
3477 // (the one we are deleting)
3478 tmppar->line_bottom = cursor.par()->line_bottom;
3479 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3480 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3483 CursorLeftIntern(bview);
3485 // the layout things can change the height of a row !
3486 int tmpheight = cursor.row()->height();
3487 SetHeightOfRow(bview, cursor.row());
3488 if (cursor.row()->height() != tmpheight) {
3489 refresh_y = cursor.y() - cursor.row()->baseline();
3490 refresh_row = cursor.row();
3491 status = LyXText::NEED_MORE_REFRESH;
3497 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3498 SetUndo(bview->buffer(), Undo::DELETE,
3499 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3500 cursor.par()->ParFromPos(cursor.pos())->next);
3503 LyXParagraph * tmppar = cursor.par();
3504 Row * tmprow = cursor.row();
3506 // We used to do CursorLeftIntern() here, but it is
3507 // not a good idea since it triggers the auto-delete
3508 // mechanism. So we do a CursorLeftIntern()-lite,
3509 // without the dreaded mechanism. (JMarc)
3510 if (cursor.par()->Previous()) {
3511 // steps into the above paragraph.
3512 SetCursorIntern(bview, cursor.par()->Previous(),
3513 cursor.par()->Previous()->Last(), false);
3516 /* Pasting is not allowed, if the paragraphs have different
3517 layout. I think it is a real bug of all other
3518 word processors to allow it. It confuses the user.
3519 Even so with a footnote paragraph and a non-footnote
3520 paragraph. I will not allow pasting in this case,
3521 because the user would be confused if the footnote behaves
3522 different wether it is open or closed.
3524 Correction: Pasting is always allowed with standard-layout
3526 if (cursor.par() != tmppar
3527 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3528 || tmppar->GetLayout() == 0 /*standard*/)
3529 && cursor.par()->footnoteflag == tmppar->footnoteflag
3531 /* table stuff -- begin*/
3532 && !cursor.par()->table /* no pasting of tables */
3533 /* table stuff -- end*/
3535 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3537 RemoveParagraph(tmprow);
3539 cursor.par()->PasteParagraph(bview->buffer()->params);
3541 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3542 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3543 // strangely enough it seems that commenting out the line above removes
3544 // most or all of the segfaults. I will however also try to move the
3545 // two Remove... lines in front of the PasteParagraph too.
3548 cursor.pos(cursor.pos() - 1);
3550 status = LyXText::NEED_MORE_REFRESH;
3551 refresh_row = cursor.row();
3552 refresh_y = cursor.y() - cursor.row()->baseline();
3554 // remove the lost paragraph
3555 // This one is not safe, since the paragraph that the tmprow and the
3556 // following rows belong to has been deleted by the PasteParagraph
3557 // above. The question is... could this be moved in front of the
3559 //RemoveParagraph(tmprow);
3560 //RemoveRow(tmprow);
3562 // This rebuilds the rows.
3563 AppendParagraph(bview, cursor.row());
3564 UpdateCounters(bview, cursor.row());
3566 // the row may have changed, block, hfills etc.
3567 SetCursor(bview, cursor.par(), cursor.pos(), false);
3570 /* this is the code for a normal backspace, not pasting
3572 SetUndo(bview->buffer(), Undo::DELETE,
3573 cursor.par()->ParFromPos(cursor.pos())->previous,
3574 cursor.par()->ParFromPos(cursor.pos())->next);
3575 // We used to do CursorLeftIntern() here, but it is
3576 // not a good idea since it triggers the auto-delete
3577 // mechanism. So we do a CursorLeftIntern()-lite,
3578 // without the dreaded mechanism. (JMarc)
3579 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3580 false, cursor.boundary());
3582 // some insets are undeletable here
3583 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3584 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3586 // force complete redo when erasing display insets
3587 // this is a cruel method but safe..... Matthias
3588 if (cursor.par()->GetInset(cursor.pos())->display()){
3589 cursor.par()->Erase(cursor.pos());
3590 RedoParagraph(bview);
3595 Row * row = cursor.row();
3596 long y = cursor.y() - row->baseline();
3597 LyXParagraph::size_type z;
3598 /* remember that a space at the end of a row doesnt count
3599 * when calculating the fill */
3600 if (cursor.pos() < RowLast(row) ||
3601 !cursor.par()->IsLineSeparator(cursor.pos())) {
3602 row->fill(row->fill() + SingleWidth(bview,
3607 /* some special code when deleting a newline. This is similar
3608 * to the behavior when pasting paragraphs */
3609 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3610 cursor.par()->Erase(cursor.pos());
3611 // refresh the positions
3613 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3614 tmprow = tmprow->next();
3615 tmprow->pos(tmprow->pos() - 1);
3617 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3618 cursor.pos(cursor.pos() - 1);
3620 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3621 cursor.par()->InsertChar(cursor.pos(), ' ');
3622 // refresh the positions
3624 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3625 tmprow = tmprow->next();
3626 tmprow->pos(tmprow->pos() + 1);
3630 cursor.par()->Erase(cursor.pos());
3632 // refresh the positions
3634 while (tmprow->next()
3635 && tmprow->next()->par() == row->par()) {
3636 tmprow = tmprow->next();
3637 tmprow->pos(tmprow->pos() - 1);
3640 // delete newlines at the beginning of paragraphs
3641 while (cursor.par()->Last() &&
3642 cursor.par()->IsNewline(cursor.pos()) &&
3643 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3645 cursor.par()->Erase(cursor.pos());
3646 // refresh the positions
3648 while (tmprow->next() &&
3649 tmprow->next()->par() == row->par()) {
3650 tmprow = tmprow->next();
3651 tmprow->pos(tmprow->pos() - 1);
3656 // is there a break one row above
3657 if (row->previous() && row->previous()->par() == row->par()) {
3658 z = NextBreakPoint(bview, row->previous(),
3660 if ( z >= row->pos()) {
3663 Row * tmprow = row->previous();
3665 // maybe the current row is now empty
3666 if (row->pos() >= row->par()->Last()) {
3671 BreakAgainOneRow(bview, row);
3672 if (row->next() && row->next()->par() == row->par())
3673 need_break_row = row->next();
3678 // set the dimensions of the row above
3679 y -= tmprow->height();
3680 tmprow->fill(Fill(bview, tmprow,
3682 SetHeightOfRow(bview, tmprow);
3685 refresh_row = tmprow;
3686 status = LyXText::NEED_MORE_REFRESH;
3687 SetCursor(bview, cursor.par(), cursor.pos(),
3688 false, cursor.boundary());
3689 //current_font = rawtmpfont;
3690 //real_current_font = realtmpfont;
3691 // check, whether the last character's font has changed.
3693 cursor.par()->GetFontSettings(bview->buffer()->params,
3694 cursor.par()->Last() - 1))
3695 RedoHeightOfParagraph(bview, cursor);
3700 // break the cursor row again
3701 z = NextBreakPoint(bview, row, workWidth(bview));
3703 if (z != RowLast(row) ||
3704 (row->next() && row->next()->par() == row->par() &&
3705 RowLast(row) == row->par()->Last() - 1)){
3707 /* it can happen that a paragraph loses one row
3708 * without a real breakup. This is when a word
3709 * is to long to be broken. Well, I don t care this
3711 if (row->next() && row->next()->par() == row->par() &&
3712 RowLast(row) == row->par()->Last() - 1)
3713 RemoveRow(row->next());
3717 status = LyXText::NEED_MORE_REFRESH;
3719 BreakAgainOneRow(bview, row);
3720 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3721 // cursor MUST be in row now
3723 if (row->next() && row->next()->par() == row->par())
3724 need_break_row = row->next();
3728 // set the dimensions of the row
3729 row->fill(Fill(bview, row, workWidth(bview)));
3730 int tmpheight = row->height();
3731 SetHeightOfRow(bview, row);
3732 if (tmpheight == row->height())
3733 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3735 status = LyXText::NEED_MORE_REFRESH;
3738 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3742 // current_font = rawtmpfont;
3743 // real_current_font = realtmpfont;
3745 lastpos = cursor.par()->Last();
3746 if (cursor.pos() == lastpos) {
3747 SetCurrentFont(bview);
3748 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3749 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3752 // check, wether the last characters font has changed.
3754 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3755 RedoHeightOfParagraph(bview, cursor);
3757 // now the special right address boxes
3758 if (textclasslist.Style(bview->buffer()->params.textclass,
3759 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3760 RedoDrawingOfParagraph(bview, cursor);
3766 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3767 Row * row_ptr, long y)
3769 /* returns a printed row */
3770 Painter & pain = bview->painter();
3772 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3773 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3775 LyXParagraph::size_type vpos, pos;
3777 int y_top, y_bottom;
3778 float fill_separator, fill_hfill, fill_label_hfill;
3782 if (row_ptr->height() <= 0) {
3783 lyxerr << "LYX_ERROR: row.height: "
3784 << row_ptr->height() << endl;
3787 PrepareToPrint(bview, row_ptr, x, fill_separator,
3788 fill_hfill, fill_label_hfill);
3792 // clear the area where we want to paint/print
3793 int ww = workWidth(bview);
3795 ww = bview->workWidth();
3797 pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height());
3800 /* selection code */
3801 if (bidi_same_direction) {
3802 if (sel_start_cursor.row() == row_ptr &&
3803 sel_end_cursor.row() == row_ptr) {
3804 if (sel_start_cursor.x() < sel_end_cursor.x())
3805 pain.fillRectangle(sel_start_cursor.x(), y_offset,
3806 sel_end_cursor.x() - sel_start_cursor.x(),
3810 pain.fillRectangle(sel_end_cursor.x(), y_offset,
3811 sel_start_cursor.x() - sel_end_cursor.x(),
3814 } else if (sel_start_cursor.row() == row_ptr) {
3816 pain.fillRectangle(0, y_offset,
3817 sel_start_cursor.x(),
3821 pain.fillRectangle(sel_start_cursor.x(), y_offset,
3822 ww - sel_start_cursor.x(),
3825 } else if (sel_end_cursor.row() == row_ptr) {
3827 pain.fillRectangle(sel_end_cursor.x(), y_offset,
3828 ww - sel_end_cursor.x(),
3832 pain.fillRectangle(0, y_offset,
3836 } else if (y > long(sel_start_cursor.y())
3837 && y < long(sel_end_cursor.y())) {
3838 pain.fillRectangle(0, y_offset,
3839 ww, row_ptr->height(),
3842 } else if ( sel_start_cursor.row() != row_ptr &&
3843 sel_end_cursor.row() != row_ptr &&
3844 y > long(sel_start_cursor.y())
3845 && y < long(sel_end_cursor.y())) {
3846 pain.fillRectangle(0, y_offset, ww, row_ptr->height(),
3848 } else if (sel_start_cursor.row() == row_ptr ||
3849 sel_end_cursor.row() == row_ptr) {
3853 if (row_ptr->par()->table) {
3854 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3855 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3858 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3859 (sel_end_cursor.row() != row_ptr && is_rtl))
3860 pain.fillRectangle(0, y_offset,
3865 if (row_ptr->par()->table) {
3867 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3868 pos = vis2log(vpos);
3869 float old_tmpx = tmpx;
3870 if (row_ptr->par()->IsNewline(pos)) {
3871 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3874 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3876 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3878 if ( (sel_start_cursor.row() != row_ptr ||
3879 sel_start_cursor.pos() <= pos) &&
3880 (sel_end_cursor.row() != row_ptr ||
3881 pos < sel_end_cursor.pos()) )
3882 pain.fillRectangle(int(old_tmpx), y_offset,
3883 int(tmpx - old_tmpx + 1),
3889 LyXParagraph::size_type main_body =
3890 BeginningOfMainBody(bview->buffer(),
3893 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3894 pos = vis2log(vpos);
3895 float old_tmpx = tmpx;
3896 if (main_body > 0 && pos == main_body-1) {
3897 tmpx += fill_label_hfill +
3898 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3899 row_ptr->par()->GetLayout()).labelsep,
3900 GetFont(bview->buffer(),row_ptr->par(), -2));
3901 if (row_ptr->par()->IsLineSeparator(main_body-1))
3902 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3904 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3905 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3906 if (pos >= main_body)
3909 tmpx += fill_label_hfill;
3911 else if (row_ptr->par()->IsSeparator(pos)) {
3912 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3913 if (pos >= main_body)
3914 tmpx += fill_separator;
3916 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3918 if ( (sel_start_cursor.row() != row_ptr ||
3919 sel_start_cursor.pos() <= pos) &&
3920 (sel_end_cursor.row() != row_ptr ||
3921 pos < sel_end_cursor.pos()) )
3922 pain.fillRectangle(int(old_tmpx), y_offset,
3923 int(tmpx - old_tmpx + 1),
3930 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
3931 (sel_end_cursor.row() != row_ptr && !is_rtl) )
3932 pain.fillRectangle(int(tmpx), y_offset,
3940 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3941 LyXFont font(LyXFont::ALL_SANE);
3942 font.setSize(LyXFont::SIZE_FOOTNOTE);
3943 font.setColor(LColor::footnote);
3945 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
3946 if (row_ptr->previous() &&
3947 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3949 switch (row_ptr->par()->footnotekind) {
3950 case LyXParagraph::MARGIN:
3953 case LyXParagraph::FIG:
3956 case LyXParagraph::TAB:
3959 case LyXParagraph::WIDE_FIG:
3962 case LyXParagraph::WIDE_TAB:
3965 case LyXParagraph::ALGORITHM:
3968 case LyXParagraph::FOOTNOTE:
3973 pain.fillRectangle(LYX_PAPER_MARGIN,
3975 box_x - LYX_PAPER_MARGIN,
3976 int(lyxfont::maxAscent(font)
3977 + lyxfont::maxDescent(font)),
3978 LColor::footnotebg);
3980 pain.line(LYX_PAPER_MARGIN, y_offset,
3981 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
3982 LColor::footnoteframe);
3984 pain.text(LYX_PAPER_MARGIN,
3985 y_offset + int(lyxfont::maxAscent(font)) + 1,
3988 pain.line(LYX_PAPER_MARGIN, y_offset,
3990 y_offset + int(lyxfont::maxAscent(font)
3991 + lyxfont::maxDescent(font)),
3992 LColor::footnoteframe);
3994 pain.line(LYX_PAPER_MARGIN,
3995 y_offset + int(lyxfont::maxAscent(font)
3996 + lyxfont::maxDescent(font)) + 1,
3998 y_offset + int(lyxfont::maxAscent(font)
3999 + lyxfont::maxDescent(font)) + 1,
4000 LColor::footnoteframe);
4004 /* draw the open floats in a red box */
4005 pain.line(box_x, y_offset,
4006 box_x, y_offset + row_ptr->height(),
4007 LColor::footnoteframe);
4009 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4011 workWidth(bview) - LYX_PAPER_MARGIN,
4012 y_offset + row_ptr->height(),
4013 LColor::footnoteframe);
4016 // Draw appendix lines
4017 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4019 pain.line(1, y_offset,
4020 1, y_offset + row_ptr->height(),
4021 LColor::appendixline);
4022 pain.line(workWidth(bview) - 2, y_offset,
4023 workWidth(bview) - 2,
4024 y_offset + row_ptr->height(),
4025 LColor::appendixline);
4028 // Draw minipage line
4029 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4031 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4033 y_offset + row_ptr->height() - 1,
4034 LColor::minipageline);
4037 int depth = p->GetDepth();
4038 for (int i = 1; i <= depth; ++i) {
4039 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4040 pain.line(line_x, y_offset, line_x,
4041 y_offset + row_ptr->height() - 1,
4044 } else if (row_ptr->previous() &&
4045 row_ptr->previous()->par()->footnoteflag
4046 == LyXParagraph::OPEN_FOOTNOTE) {
4047 LyXFont font(LyXFont::ALL_SANE);
4048 font.setSize(LyXFont::SIZE_FOOTNOTE);
4050 int box_x = LYX_PAPER_MARGIN;
4051 box_x += lyxfont::width(" wide-tab ", font);
4053 pain.line(box_x, y_offset,
4054 workWidth(bview) - LYX_PAPER_MARGIN,
4055 y_offset, LColor::footnote);
4058 // Draw appendix lines
4059 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4060 if (firstpar->appendix){
4061 pain.line(1, y_offset,
4062 1, y_offset + row_ptr->height(),
4063 LColor::appendixline);
4064 pain.line(ww - 2, y_offset,
4065 ww - 2, y_offset + row_ptr->height(),
4066 LColor::appendixline);
4069 // Draw minipage line
4070 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4072 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4073 LYX_PAPER_MARGIN/5 + box_x,
4074 y_offset + row_ptr->height() - 1,
4075 LColor::minipageline);
4078 int depth = firstpar->GetDepth();
4082 if (row_ptr->next())
4083 if (row_ptr->par()->footnoteflag ==
4084 row_ptr->next()->par()->footnoteflag)
4085 next_depth = row_ptr->next()->par()->GetDepth();
4086 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4089 if (row_ptr->previous())
4090 if (row_ptr->par()->footnoteflag ==
4091 row_ptr->previous()->par()->footnoteflag)
4092 prev_depth = row_ptr->previous()->par()->GetDepth();
4093 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4096 for (int i = 1; i <= depth; ++i) {
4097 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4098 pain.line(line_x, y_offset, line_x,
4099 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4103 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4106 pain.fillRectangle(line_x,
4107 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4108 LYX_PAPER_MARGIN / 5, 2,
4114 LyXLayout const & layout =
4115 textclasslist.Style(bview->buffer()->params.textclass,
4116 row_ptr->par()->GetLayout());
4119 y_bottom = row_ptr->height();
4121 /* is it a first row? */
4122 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4124 /* start of appendix? */
4125 if (row_ptr->par()->start_of_appendix){
4126 pain.line(1, y_offset,
4128 LColor::appendixline);
4131 /* think about the margins */
4132 if (!row_ptr->previous() && bv_owner)
4133 y_top += LYX_PAPER_MARGIN;
4135 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4137 pb_font.setColor(LColor::pagebreak).decSize();
4138 int w = 0, a = 0, d = 0;
4139 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4141 y_offset + y_top + 2 * DefaultHeight(),
4143 Painter::line_onoffdash)
4146 _("Page Break (top)"),
4149 LColor::background, false, w, a, d);
4150 pain.rectText((ww - w)/2,
4151 y_offset + y_top + 2 * DefaultHeight() + d,
4152 _("Page Break (top)"),
4155 LColor::background);
4156 y_top += 3 * DefaultHeight();
4159 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4160 /* draw a vfill top */
4161 pain.line(0, y_offset + 2 + y_top,
4162 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4165 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4167 y_offset + y_top + 3 * DefaultHeight(),
4170 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4171 LYX_PAPER_MARGIN / 2,
4172 y_offset + y_top + 3 * DefaultHeight(),
4175 y_top += 3 * DefaultHeight();
4178 /* think about user added space */
4179 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4181 /* think about the parskip */
4182 /* some parskips VERY EASY IMPLEMENTATION */
4183 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4184 if (layout.latextype == LATEX_PARAGRAPH
4185 && firstpar->GetDepth() == 0
4186 && firstpar->Previous())
4187 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4188 else if (firstpar->Previous()
4189 && textclasslist.Style(bview->buffer()->params.textclass,
4190 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4191 && firstpar->Previous()->GetDepth() == 0)
4192 // is it right to use defskip here, too? (AS)
4193 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4196 if (row_ptr->par()->line_top) { /* draw a top line */
4197 y_top += lyxfont::ascent('x',
4198 GetFont(bview->buffer(),
4199 row_ptr->par(), 0));
4201 pain.line(0, y_offset + y_top,
4202 ww, y_offset + y_top,
4204 Painter::line_solid,
4205 Painter::line_thick);
4207 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4208 row_ptr->par(), 0));
4211 /* should we print a label? */
4212 if (layout.labeltype >= LABEL_STATIC
4213 && (layout.labeltype != LABEL_STATIC
4214 || layout.latextype != LATEX_ENVIRONMENT
4215 || row_ptr->par()->IsFirstInSequence())) {
4216 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4217 if (!row_ptr->par()->GetLabelstring().empty()) {
4219 string tmpstring = row_ptr->par()->GetLabelstring();
4221 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4222 if (bview->buffer()->params.secnumdepth >= 0) {
4223 /* this is special code for the chapter layout. This is printed in
4224 * an extra row and has a pagebreak at the top. */
4225 float spacing_val = 1.0;
4226 if (!row_ptr->par()->spacing.isDefault()) {
4227 spacing_val = row_ptr->par()->spacing.getValue();
4229 spacing_val = bview->buffer()->params.spacing.getValue();
4232 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4233 + int(layout.parsep) * DefaultHeight();
4235 tmpx = ww - LeftMargin(bview, row_ptr) -
4236 lyxfont::width(tmpstring, font);
4237 pain.text(int(tmpx),
4238 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4243 tmpx = ww - LeftMargin(bview, row_ptr)
4244 + lyxfont::width(layout.labelsep, font);
4245 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4246 LyXFont font(LyXFont::ALL_SANE);
4247 font.setSize(LyXFont::SIZE_SMALL);
4248 tmpx += lyxfont::width("Mwide-fixM", font);
4251 tmpx = x - lyxfont::width(layout.labelsep, font)
4252 - lyxfont::width(tmpstring, font);
4255 pain.text(int(tmpx),
4256 y_offset + row_ptr->baseline(),
4260 /* the labels at the top of an environment. More or less for bibliography */
4261 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4262 layout.labeltype == LABEL_BIBLIO ||
4263 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4264 if (row_ptr->par()->IsFirstInSequence()) {
4265 font = GetFont(bview->buffer(),
4266 row_ptr->par(), -2);
4267 if (!row_ptr->par()->GetLabelstring().empty()) {
4268 string tmpstring = row_ptr->par()->GetLabelstring();
4269 float spacing_val = 1.0;
4270 if (!row_ptr->par()->spacing.isDefault()) {
4271 spacing_val = row_ptr->par()->spacing.getValue();
4273 spacing_val = bview->buffer()->params.spacing.getValue();
4276 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4277 + (layout.labelbottomsep * DefaultHeight()));
4280 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4281 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4282 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4283 tmpx -= lyxfont::width(tmpstring, font) / 2;
4285 tmpx = ww - LeftMargin(bview, row_ptr) -
4286 lyxfont::width(tmpstring, font);
4287 pain.text(int(tmpx),
4288 y_offset + row_ptr->baseline()
4289 - row_ptr->ascent_of_text()
4295 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4296 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4298 tmpx = ww - LeftMargin(bview, row_ptr)
4299 + lyxfont::width(layout.labelsep, font);
4301 tmpx = x - lyxfont::width(layout.labelsep, font)
4302 - row_ptr->par()->bibkey->width(bview->painter(), font);
4303 row_ptr->par()->bibkey->draw(pain,
4305 y_offset + row_ptr->baseline(),
4310 /* is it a last row? */
4311 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4312 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4313 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4315 /* think about the margins */
4316 if (!row_ptr->next() && bv_owner)
4317 y_bottom -= LYX_PAPER_MARGIN;
4319 /* draw a bottom pagebreak */
4320 if (firstpar->pagebreak_bottom) {
4322 pb_font.setColor(LColor::pagebreak).decSize();
4323 int w = 0, a = 0, d = 0;
4325 y_offset + y_bottom - 2 * DefaultHeight(),
4327 y_offset + y_bottom - 2 * DefaultHeight(),
4329 Painter::line_onoffdash)
4332 _("Page Break (bottom)"),
4335 LColor::background, false, w, a, d);
4336 pain.rectText((ww - w) / 2,
4337 y_offset + y_top + 2 * DefaultHeight() + d,
4338 _("Page Break (bottom)"),
4341 LColor::background);
4342 y_bottom -= 3 * DefaultHeight();
4345 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4346 /* draw a vfill bottom */
4347 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4349 y_offset + y_bottom - 3 * DefaultHeight(),
4351 pain.line(0, y_offset + y_bottom - 2,
4353 y_offset + y_bottom - 2,
4355 pain.line(LYX_PAPER_MARGIN / 2,
4356 y_offset + y_bottom - 3 * DefaultHeight(),
4357 LYX_PAPER_MARGIN / 2,
4358 y_offset + y_bottom - 2,
4360 y_bottom -= 3 * DefaultHeight();
4363 /* think about user added space */
4364 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4366 if (firstpar->line_bottom) {
4367 /* draw a bottom line */
4368 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4369 par, par->Last() - 1));
4370 pain.line(0, y_offset + y_bottom,
4371 ww, y_offset + y_bottom,
4372 LColor::topline, Painter::line_solid,
4373 Painter::line_thick);
4374 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4375 par, par->Last() - 1));
4379 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4382 case END_LABEL_FILLED_BOX:
4384 LyXFont font = GetFont(bview->buffer(),
4385 row_ptr->par(), last);
4386 int size = int(0.75 * lyxfont::maxAscent(font));
4387 int y = (y_offset + row_ptr->baseline()) - size;
4388 int x = is_rtl ? LYX_PAPER_MARGIN
4389 : ww - LYX_PAPER_MARGIN - size;
4390 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4392 LyXFont font(LyXFont::ALL_SANE);
4393 font.setSize(LyXFont::SIZE_SMALL);
4394 x += lyxfont::width("Mwide-figM", font);
4396 x -= LYX_PAPER_MARGIN/2;
4397 if (row_ptr->fill() <= size)
4398 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4399 if (endlabel == END_LABEL_BOX) {
4400 pain.line(x, y, x, y + size,
4402 pain.line(x + size, y, x + size , y + size,
4404 pain.line(x, y, x + size, y,
4406 pain.line(x, y + size, x + size, y + size,
4409 pain.fillRectangle(x, y, size, size,
4413 case END_LABEL_STATIC:
4415 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4416 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4417 layout).endlabelstring();
4418 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4419 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4420 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4421 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4424 case END_LABEL_NO_LABEL:
4429 /* draw the text in the pixmap */
4431 vpos = row_ptr->pos();
4433 /* table stuff -- begin*/
4434 if (row_ptr->par()->table) {
4436 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4438 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4440 while (vpos <= last) {
4441 pos = vis2log(vpos);
4442 if (row_ptr->par()->IsNewline(pos)) {
4444 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4445 /* draw the table lines, still very simple */
4446 on_off = !row_ptr->par()->table->TopLine(cell);
4448 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4449 !row_ptr->par()->table->IsContRow(cell))
4450 pain.line(int(x_old),
4451 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4453 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4455 on_off ? Painter::line_onoffdash : Painter::line_solid);
4457 on_off = !row_ptr->par()->table->BottomLine(cell);
4458 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4459 row_ptr->par()->table->VeryLastRow(cell))
4461 pain.line(int(x_old),
4462 y_offset + y_bottom - 1,
4464 y_offset + y_bottom - 1,
4466 on_off ? Painter::line_onoffdash : Painter::line_solid);
4468 on_off = !row_ptr->par()->table->LeftLine(cell);
4470 pain.line(int(x_old),
4471 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4473 y_offset + y_bottom - 1,
4475 on_off ? Painter::line_onoffdash : Painter::line_solid);
4477 on_off = !row_ptr->par()->table->RightLine(cell);
4479 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4480 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4481 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4482 y_offset + y_bottom - 1,
4484 on_off ? Painter::line_onoffdash : Painter::line_solid);
4487 /* take care about the alignment and other spaces */
4489 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4490 if (row_ptr->par()->table->IsFirstCell(cell))
4491 --cell; // little hack, sorry
4493 } else if (row_ptr->par()->IsHfill(pos)) {
4497 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4499 y_offset + row_ptr->baseline(),
4504 } else if (row_ptr->par()->IsSeparator(pos)) {
4506 x+= SingleWidth(bview,
4507 row_ptr->par(), pos);
4510 draw(bview, row_ptr, vpos, y_offset, x);
4513 /* do not forget the very last cell. This has no NEWLINE so
4514 * ignored by the code above*/
4515 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4516 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4517 on_off = !row_ptr->par()->table->TopLine(cell);
4519 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4520 !row_ptr->par()->table->IsContRow(cell))
4522 pain.line(int(x_old),
4523 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4525 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4527 on_off ? Painter::line_onoffdash : Painter::line_solid);
4528 on_off = !row_ptr->par()->table->BottomLine(cell);
4529 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4530 row_ptr->par()->table->VeryLastRow(cell))
4532 pain.line(int(x_old),
4533 y_offset + y_bottom - 1,
4535 y_offset + y_bottom - 1,
4537 on_off ? Painter::line_onoffdash : Painter::line_solid);
4539 on_off = !row_ptr->par()->table->LeftLine(cell);
4541 pain.line(int(x_old),
4542 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4544 y_offset + y_bottom - 1,
4546 on_off ? Painter::line_onoffdash : Painter::line_solid);
4548 on_off = !row_ptr->par()->table->RightLine(cell);
4550 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4551 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4552 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4553 y_offset + y_bottom - 1,
4555 on_off ? Painter::line_onoffdash : Painter::line_solid);
4558 /* table stuff -- end*/
4560 LyXParagraph::size_type main_body =
4561 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4562 if (main_body > 0 &&
4563 (main_body-1 > last ||
4564 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4567 while (vpos <= last) {
4568 pos = vis2log(vpos);
4569 if (main_body > 0 && pos == main_body - 1) {
4570 x += fill_label_hfill
4571 + lyxfont::width(layout.labelsep,
4572 GetFont(bview->buffer(),
4573 row_ptr->par(), -2))
4574 - SingleWidth(bview,
4579 if (row_ptr->par() ->IsHfill(pos)) {
4582 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4584 y_offset + row_ptr->baseline(),
4587 if (HfillExpansion(bview->buffer(),
4589 if (pos >= main_body) {
4591 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4592 int(x + fill_hfill),
4593 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4595 Painter::line_onoffdash);
4599 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4600 int(x + fill_label_hfill),
4601 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4603 Painter::line_onoffdash);
4605 x += fill_label_hfill;
4608 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4610 y_offset + row_ptr->baseline(),
4615 } else if (row_ptr->par()->IsSeparator(pos)) {
4616 x += SingleWidth(bview,
4617 row_ptr->par(), pos);
4618 if (pos >= main_body)
4619 x += fill_separator;
4622 draw(bview, row_ptr, vpos, y_offset, x);
4627 // Jürgen!!! FIX This! (NOW!!!) (please)
4628 width = max(x - x_offset, float(width));
4632 int LyXText::DefaultHeight() const
4634 LyXFont font(LyXFont::ALL_SANE);
4635 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4639 /* returns the column near the specified x-coordinate of the row
4640 * x is set to the real beginning of this column */
4641 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4642 bool & boundary) const
4645 float fill_separator, fill_hfill, fill_label_hfill;
4647 PrepareToPrint(bview, row, tmpx, fill_separator,
4648 fill_hfill, fill_label_hfill);
4650 LyXParagraph::size_type vc = row->pos();
4651 LyXParagraph::size_type last = RowLastPrintable(row);
4652 LyXParagraph::size_type c = 0;
4653 LyXLayout const & layout =
4654 textclasslist.Style(bview->buffer()->params.textclass,
4655 row->par()->GetLayout());
4656 bool left_side = false;
4659 /* table stuff -- begin */
4660 if (row->par()->table) {
4661 //the last row doesn't need a newline at the end
4662 if (row->next() && row->next()->par() == row->par()
4663 && row->par()->IsNewline(last))
4665 int cell = NumberOfCell(row->par(), row->pos());
4666 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4667 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4668 float last_tmpx = tmpx;
4669 while (vc <= last && tmpx <= x) {
4672 if (row->par()->IsNewline(c)) {
4675 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4676 cell_x += row->par()->table->WidthOfColumn(cell);
4681 tmpx += SingleWidth(bview, row->par(), c);
4685 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4686 (tmpx + last_tmpx) / 2 > x) {
4691 /* table stuff -- end*/
4693 LyXParagraph::size_type
4694 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4695 float last_tmpx = tmpx;
4697 if (main_body > 0 &&
4698 (main_body-1 > last ||
4699 !row->par()->IsLineSeparator(main_body - 1)))
4702 while (vc <= last && tmpx <= x) {
4705 if (main_body > 0 && c == main_body-1) {
4706 tmpx += fill_label_hfill +
4707 lyxfont::width(layout.labelsep,
4708 GetFont(bview->buffer(), row->par(), -2));
4709 if (row->par()->IsLineSeparator(main_body - 1))
4710 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4713 if (HfillExpansion(bview->buffer(), row, c)) {
4714 x += SingleWidth(bview, row->par(), c);
4718 tmpx += fill_label_hfill;
4720 else if (row->par()->IsSeparator(c)) {
4721 tmpx += SingleWidth(bview, row->par(), c);
4723 tmpx+= fill_separator;
4725 tmpx += SingleWidth(bview, row->par(), c);
4729 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4738 if (vc > last + 1) // This shouldn't happen.
4743 if (row->pos() > last) // Row is empty?
4745 else if (vc == row->pos() ||
4747 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4749 if (bidi_level(c) % 2 == 1)
4752 c = vis2log(vc - 1);
4753 bool rtl = (bidi_level(c) % 2 == 1);
4754 if (left_side == rtl) {
4756 boundary = IsBoundary(bview->buffer(), row->par(), c);
4760 if (!row->par()->table && row->pos() <= last && c > last
4761 && row->par()->IsNewline(last)) {
4762 if (bidi_level(last) % 2 == 0)
4763 tmpx -= SingleWidth(bview, row->par(), last);
4765 tmpx += SingleWidth(bview, row->par(), last);
4775 /* turn the selection into a new environment. If there is no selection,
4776 * create an empty environment */
4777 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4778 LyXParagraph::footnote_kind kind)
4780 /* no footnoteenvironment in a footnoteenvironment */
4781 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4782 WriteAlert(_("Impossible operation"),
4783 _("You can't insert a float in a float!"),
4787 /* no marginpars in minipages */
4788 if (kind == LyXParagraph::MARGIN
4789 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4790 WriteAlert(_("Impossible operation"),
4791 _("You can't insert a marginpar in a minipage!"),
4796 /* this doesnt make sense, if there is no selection */
4797 bool dummy_selection = false;
4799 sel_start_cursor = cursor; /* dummy selection */
4800 sel_end_cursor = cursor;
4801 dummy_selection = true;
4804 LyXParagraph * tmppar;
4807 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4808 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4812 /* a test to make sure there is not already a footnote
4813 * in the selection. */
4815 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4817 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4818 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4819 tmppar = tmppar->next;
4821 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4822 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4823 WriteAlert(_("Impossible operation"),
4824 _("Float would include float!"),
4829 /* ok we have a selection. This is always between sel_start_cursor
4830 * and sel_end cursor */
4832 SetUndo(bview->buffer(), Undo::FINISH,
4833 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4834 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4836 if (sel_end_cursor.pos() > 0
4837 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4838 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4839 /* please break before a space at the end */
4840 if (sel_start_cursor.par() == sel_end_cursor.par()
4841 && sel_start_cursor.pos() > sel_end_cursor.pos())
4842 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4844 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4846 sel_end_cursor.par(sel_end_cursor.par()->Next());
4847 sel_end_cursor.pos(0);
4849 // don't forget to insert a dummy layout paragraph if necessary
4850 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4851 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4852 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4853 sel_end_cursor.par(sel_end_cursor.par()->next);
4856 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4858 cursor = sel_end_cursor;
4860 /* please break behind a space, if there is one. The space should
4862 if (sel_start_cursor.pos() > 0
4863 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4864 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4865 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4866 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4869 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4870 sel_start_cursor.pos());
4871 tmppar = sel_start_cursor.par()->Next();
4873 if (dummy_selection) {
4875 if (kind == LyXParagraph::TAB
4876 || kind == LyXParagraph::FIG
4877 || kind == LyXParagraph::WIDE_TAB
4878 || kind == LyXParagraph::WIDE_FIG
4879 || kind == LyXParagraph::ALGORITHM) {
4880 pair<bool, LyXTextClass::size_type> lres =
4881 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4883 LyXTextClass::size_type lay;
4889 lay = 0; // use default layout "Standard" (0)
4891 tmppar->SetLayout(bview->buffer()->params, lay);
4894 if (sel_start_cursor.pos() > 0) {
4895 /* the footnote-environment should begin with a standard layout.
4896 * Imagine you insert a footnote within an enumeration, you
4897 * certainly do not want an enumerated footnote! */
4900 /* this is a exception the user would sometimes expect, I hope */
4901 sel_start_cursor.par()->Clear();
4905 while (tmppar != sel_end_cursor.par()) {
4906 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4907 tmppar->footnotekind = kind;
4908 tmppar = tmppar->Next();
4911 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4913 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4919 // returns pointer to a specified row
4920 Row * LyXText::GetRow(LyXParagraph * par,
4921 LyXParagraph::size_type pos, long & y) const
4923 Row * tmprow = firstrow;
4926 // find the first row of the specified paragraph
4927 while (tmprow->next() && tmprow->par() != par) {
4928 y += tmprow->height();
4929 tmprow = tmprow->next();
4932 // now find the wanted row
4933 while (tmprow->pos() < pos
4935 && tmprow->next()->par() == par
4936 && tmprow->next()->pos() <= pos) {
4937 y += tmprow->height();
4938 tmprow = tmprow->next();