1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #pragma implementation "table.h"
21 #include "lyxparagraph.h"
23 #include "support/textutils.h"
24 #include "insets/insetbib.h"
25 #include "insets/insettext.h"
26 #include "lyx_gui_misc.h"
28 #include "bufferparams.h"
30 #include "minibuffer.h"
45 static const int LYX_PAPER_MARGIN = 20;
46 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
49 int LyXText::workWidth(BufferView * bview) const
52 return inset_owner->textWidth(bview->painter());
54 return bview->workWidth();
58 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
59 LyXParagraph::size_type pos) const
61 if (!Encoding::is_arabic(c))
62 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c))
63 return c + (0xb0 - '0');
67 unsigned char prev_char = pos > 0 ? par->GetChar(pos-1) : ' ';
68 unsigned char next_char = ' ';
69 for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i)
70 if (!Encoding::IsComposeChar_arabic(par->GetChar(i))) {
71 next_char = par->GetChar(i);
75 if (Encoding::is_arabic(next_char))
76 if (Encoding::is_arabic(prev_char))
77 return Encoding::TransformChar(c, Encoding::FORM_MEDIAL);
79 return Encoding::TransformChar(c, Encoding::FORM_INITIAL);
81 if (Encoding::is_arabic(prev_char))
82 return Encoding::TransformChar(c, Encoding::FORM_FINAL);
84 return Encoding::TransformChar(c, Encoding::FORM_ISOLATED);
87 // This is the comments that some of the warnings below refers to.
88 // There are some issues in this file and I don't think they are
89 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
90 // this is a problem that has been here almost from day one and that a
91 // larger userbase with differenct access patters triggers the bad
92 // behaviour. (segfaults.) What I think happen is: In several places
93 // we store the paragraph in the current cursor and then moves the
94 // cursor. This movement of the cursor will delete paragraph at the
95 // old position if it is now empty. This will make the temporary
96 // pointer to the old cursor paragraph invalid and dangerous to use.
97 // And is some cases this will trigger a segfault. I have marked some
98 // of the cases where this happens with a warning, but I am sure there
99 // are others in this file and in text2.C. There is also a note in
100 // Delete() that you should read. In Delete I store the paragraph->id
101 // instead of a pointer to the paragraph. I am pretty sure this faulty
102 // use of temporary pointers to paragraphs that might have gotten
103 // invalidated (through a cursor movement) before they are used, are
104 // the cause of the strange crashes we get reported often.
106 // It is very tiresom to change this code, especially when it is as
107 // hard to read as it is. Help to fix all the cases where this is done
108 // would be greately appreciated.
112 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
113 LyXParagraph::size_type pos) const
115 char c = par->GetChar(pos);
116 return SingleWidth(bview, par, pos, c);
120 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
121 LyXParagraph::size_type pos, char c) const
123 LyXFont font = GetFont(bview->buffer(), par, pos);
125 // The most common case is handled first (Asger)
126 if (IsPrintable(c)) {
127 if (font.language()->RightToLeft()) {
128 if (font.language()->lang() == "arabic" &&
129 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
130 lyxrc.font_norm_type == LyXRC::ISO_10646_1))
131 if (Encoding::IsComposeChar_arabic(c))
134 c = TransformChar(c, par, pos);
135 else if (font.language()->lang() == "hebrew" &&
136 Encoding::IsComposeChar_hebrew(c))
139 return lyxfont::width(c, font);
141 } else if (IsHfillChar(c)) {
142 return 3; /* Because of the representation
143 * as vertical lines */
145 } else if (c == LyXParagraph::META_FOOTNOTE ||
146 c == LyXParagraph::META_MARGIN ||
147 c == LyXParagraph::META_FIG ||
148 c == LyXParagraph::META_TAB ||
149 c == LyXParagraph::META_WIDE_FIG ||
150 c == LyXParagraph::META_WIDE_TAB ||
151 c == LyXParagraph::META_ALGORITHM) {
154 case LyXParagraph::META_MARGIN:
157 case LyXParagraph::META_FIG:
160 case LyXParagraph::META_TAB:
163 case LyXParagraph::META_ALGORITHM:
166 case LyXParagraph::META_WIDE_FIG:
169 case LyXParagraph::META_WIDE_TAB:
172 case LyXParagraph::META_FOOTNOTE:
178 return lyxfont::width(fs, font);
180 } else if (c == LyXParagraph::META_INSET) {
181 Inset * tmpinset = par->GetInset(pos);
183 tmpinset->update(bview, font);
184 return tmpinset->width(bview, font);
188 } else if (IsSeparatorChar(c))
190 else if (IsNewlineChar(c))
192 return lyxfont::width(c, font);
196 // Returns the paragraph position of the last character in the specified row
197 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
199 if (row->next() == 0)
200 return row->par()->Last() - 1;
201 else if (row->next()->par() != row->par())
202 return row->par()->Last() - 1;
204 return row->next()->pos() - 1;
208 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
210 LyXParagraph::size_type last = RowLast(row);
211 if (last >= row->pos()
213 && row->next()->par() == row->par()
214 && row->par()->IsSeparator(last))
221 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
223 bidi_same_direction = true;
224 if (!lyxrc.rtl_support) {
229 bidi_start = row->pos();
230 bidi_end = RowLastPrintable(row);
232 if (bidi_start > bidi_end) {
237 if (bidi_end + 2 - bidi_start >
238 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
239 LyXParagraph::size_type new_size =
240 (bidi_end + 2 - bidi_start < 500) ?
241 500 : 2 * (bidi_end + 2 - bidi_start);
242 log2vis_list.resize(new_size);
243 vis2log_list.resize(new_size);
244 bidi_levels.resize(new_size);
247 vis2log_list[bidi_end + 1 - bidi_start] = -1;
248 log2vis_list[bidi_end + 1 - bidi_start] = -1;
250 LyXParagraph::size_type stack[2];
251 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
255 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
257 for (LyXParagraph::size_type lpos = bidi_start;
258 lpos <= bidi_end; ++lpos) {
259 bool is_space = row->par()->IsLineSeparator(lpos);
260 LyXParagraph::size_type pos =
261 (is_space && lpos + 1 <= bidi_end &&
262 !row->par()->IsLineSeparator(lpos + 1) &&
265 !row->par()->table ||
267 !row->par()->IsNewline(lpos + 1)) )
269 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
270 bool new_rtl = font.isVisibleRightToLeft();
271 bool new_rtl0 = font.isRightToLeft();
275 if (row->par()->table && row->par()->IsNewline(lpos)) {
277 new_rtl = new_rtl0 = false;
280 if (lpos == main_body - 1
281 && row->pos() < main_body - 1
282 && row->par()->IsLineSeparator(lpos)) {
283 new_level = (rtl_par) ? 1 : 0;
284 new_rtl = new_rtl0 = rtl_par;
286 new_level = (new_rtl) ? 1 : 2;
288 new_level = (rtl_par) ? 2 : 0;
290 if (is_space && new_level >= level) {
296 int new_level2 = new_level;
298 if (level == new_level && rtl0 != new_rtl0) {
300 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
301 } else if (level < new_level) {
302 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
303 if (new_level > rtl_par)
304 bidi_same_direction = false;
306 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
309 bidi_levels[lpos - bidi_start] = new_level;
311 while (level > new_level2) {
312 LyXParagraph::size_type old_lpos =
314 int delta = lpos - old_lpos - 1;
317 log2vis_list[lpos - bidi_start] += delta;
318 log2vis_list[old_lpos - bidi_start] += delta;
320 while (level < new_level)
321 stack[level++] = lpos;
325 LyXParagraph::size_type old_lpos = stack[--level];
326 int delta = bidi_end - old_lpos;
329 log2vis_list[old_lpos - bidi_start] += delta;
332 LyXParagraph::size_type vpos = bidi_start - 1;
333 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
334 vpos += log2vis_list[lpos - bidi_start];
335 vis2log_list[vpos - bidi_start] = lpos;
336 log2vis_list[lpos - bidi_start] = vpos;
341 // This method requires a previous call to ComputeBidiTables()
342 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
343 LyXParagraph::size_type pos) const
345 if (!lyxrc.rtl_support)
346 return false; // This is just for speedup
348 if (!bidi_InRange(pos - 1)
350 || (par->table && par->IsNewline(pos-1))
355 bool rtl = bidi_level(pos - 1) % 2;
357 if (pos == par->Last()
359 || (par->table && par->IsNewline(pos))
362 rtl2 = par->isRightToLeftPar(buf->params);
363 else if (bidi_InRange(pos))
364 rtl2 = bidi_level(pos) % 2;
369 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
370 LyXParagraph::size_type pos,
371 LyXFont const & font) const
373 if (!lyxrc.rtl_support)
374 return false; // This is just for speedup
376 bool rtl = font.isVisibleRightToLeft();
378 if (pos == par->Last()
380 || (par->table && par->IsNewline(pos))
383 rtl2 = par->isRightToLeftPar(buf->params);
384 else if (bidi_InRange(pos))
385 rtl2 = bidi_level(pos) % 2;
390 void LyXText::draw(BufferView * bview, Row const * row,
391 LyXParagraph::size_type & vpos,
392 int offset, float & x, bool cleared)
394 Painter & pain = bview->painter();
396 LyXParagraph::size_type pos = vis2log(vpos);
397 char c = row->par()->GetChar(pos);
400 if (IsNewlineChar(c)) {
402 // Draw end-of-line marker
403 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
404 int wid = lyxfont::width('n', font);
405 int asc = lyxfont::maxAscent(font);
406 int y = offset + row->baseline();
409 if (bidi_level(pos) % 2 == 0) {
410 xp[0] = int(x + wid * 0.375);
411 yp[0] = int(y - 0.875 * asc * 0.75);
414 yp[1] = int(y - 0.500 * asc * 0.75);
416 xp[2] = int(x + wid * 0.375);
417 yp[2] = int(y - 0.125 * asc * 0.75);
419 pain.lines(xp, yp, 3, LColor::eolmarker);
422 yp[0] = int(y - 0.500 * asc * 0.75);
424 xp[1] = int(x + wid);
425 yp[1] = int(y - 0.500 * asc * 0.75);
427 xp[2] = int(x + wid);
428 yp[2] = int(y - asc * 0.75);
430 pain.lines(xp, yp, 3, LColor::eolmarker);
432 xp[0] = int(x + wid * 0.625);
433 yp[0] = int(y - 0.875 * asc * 0.75);
435 xp[1] = int(x + wid);
436 yp[1] = int(y - 0.500 * asc * 0.75);
438 xp[2] = int(x + wid * 0.625);
439 yp[2] = int(y - 0.125 * asc * 0.75);
441 pain.lines(xp, yp, 3, LColor::eolmarker);
443 xp[0] = int(x + wid);
444 yp[0] = int(y - 0.500 * asc * 0.75);
447 yp[1] = int(y - 0.500 * asc * 0.75);
450 yp[2] = int(y - asc * 0.75);
452 pain.lines(xp, yp, 3, LColor::eolmarker);
458 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
459 LyXFont font2 = font;
461 if (c == LyXParagraph::META_FOOTNOTE
462 || c == LyXParagraph::META_MARGIN
463 || c == LyXParagraph::META_FIG
464 || c == LyXParagraph::META_TAB
465 || c == LyXParagraph::META_WIDE_FIG
466 || c == LyXParagraph::META_WIDE_TAB
467 || c == LyXParagraph::META_ALGORITHM) {
470 case LyXParagraph::META_MARGIN:
473 case LyXParagraph::META_FIG:
476 case LyXParagraph::META_TAB:
479 case LyXParagraph::META_ALGORITHM:
482 case LyXParagraph::META_WIDE_FIG:
485 case LyXParagraph::META_WIDE_TAB:
488 case LyXParagraph::META_FOOTNOTE:
495 // calculate the position of the footnotemark
496 int y = (row->baseline() - lyxfont::maxAscent(font2)
497 + lyxfont::maxAscent(font));
499 font.setColor(LColor::footnote);
501 // draw it and set new x position
503 pain.text(int(x), offset + y, fs, font);
504 x += lyxfont::width(fs, font);
505 pain.line(int(tmpx), offset + row->baseline(),
506 int(x), offset + row->baseline(),
513 if (c == LyXParagraph::META_INSET) {
514 Inset * tmpinset = row->par()->GetInset(pos);
516 // tmpinset->update(bview, font, false);
517 tmpinset->draw(bview, font, offset+row->baseline(), x,
519 if (status == CHANGED_IN_DRAW)
520 UpdateInset(bview, tmpinset);
524 if (lyxrc.mark_foreign_language &&
525 font.language() != bview->buffer()->params.language_info) {
526 int y = offset + row->height() - 1;
527 pain.line(int(tmpx), y, int(x), y,
534 /* usual characters, no insets */
536 // Collect character that we can draw in one command
538 // This is dirty, but fast. Notice that it will never be too small.
539 // For the record, I'll note that Microsoft Word has a limit
540 // of 768 here. We have none :-) (Asger)
541 // Ok. I am the first to admit that the use of std::string will be
542 // a tiny bit slower than using a POD char array. However, I claim
543 // that this slowdown is so small that it is close to inperceptive.
544 // So IMHO we should go with the easier and clearer implementation.
545 // And even if 1024 is a large number here it might overflow, string
546 // will only overflow if the machine is out of memory...
547 static string textstring;
551 LyXParagraph::size_type last = RowLastPrintable(row);
553 if (font.language()->lang() == "hebrew") {
554 if (Encoding::IsComposeChar_hebrew(c)) {
555 int width = lyxfont::width(c, font2);
557 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
558 c = row->par()->GetChar(i);
559 if (!Encoding::IsComposeChar_hebrew(c)) {
560 if (IsPrintableNonspace(c)) {
561 int width2 = SingleWidth(bview, row->par(), i, c);
562 dx = (c == 'ø' || c == 'ã') // dalet / resh
563 ? width2 - width : (width2 - width) / 2;
569 pain.text(int(x) + dx, offset + row->baseline(),
572 while (vpos <= last &&
573 (pos = vis2log(vpos)) >= 0
574 && IsPrintableNonspace(c = row->par()->GetChar(pos))
575 && !Encoding::IsComposeChar_hebrew(c)
576 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
580 // Draw text and set the new x position
581 pain.text(int(x), offset + row->baseline(),
583 x += lyxfont::width(textstring, font);
585 } else if (font.language()->lang() == "arabic" &&
586 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
587 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
588 if (Encoding::IsComposeChar_arabic(c)) {
589 c = TransformChar(c, row->par(), pos);
591 int width = lyxfont::width(c, font2);
593 for (LyXParagraph::size_type i = pos-1; i >= 0; --i) {
594 c = row->par()->GetChar(i);
595 if (!Encoding::IsComposeChar_arabic(c)) {
596 if (IsPrintableNonspace(c)) {
597 int width2 = SingleWidth(bview, row->par(), i, c);
598 dx = (width2 - width) / 2;
604 pain.text(int(x) + dx, offset + row->baseline(),
607 textstring = TransformChar(c, row->par(), pos);
608 while (vpos <= last &&
609 (pos = vis2log(vpos)) >= 0
610 && IsPrintableNonspace(c = row->par()->GetChar(pos))
611 && !Encoding::IsComposeChar_arabic(c)
612 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
613 c = TransformChar(c, row->par(), pos);
617 // Draw text and set the new x position
618 pain.text(int(x), offset + row->baseline(),
620 x += lyxfont::width(textstring, font);
623 while (vpos <= last &&
624 (pos = vis2log(vpos)) >= 0
625 && IsPrintableNonspace(c = row->par()->GetChar(pos))
626 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
630 // Draw text and set the new x position
631 pain.text(int(x), offset + row->baseline(), textstring, font);
632 x += lyxfont::width(textstring, font);
635 if (lyxrc.mark_foreign_language &&
636 font.language() != bview->buffer()->params.language_info) {
637 int y = offset + row->height() - 1;
638 pain.line(int(tmpx), y, int(x), y,
642 // If we want ulem.sty support, drawing
643 // routines should go here. (Asger)
644 // Why shouldn't LyXFont::drawText handle it internally?
648 // Returns the left beginning of the text.
649 // This information cannot be taken from the layouts-objekt, because in
650 // LaTeX the beginning of the text fits in some cases (for example sections)
651 // exactly the label-width.
652 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
654 LyXLayout const & layout =
655 textclasslist.Style(bview->buffer()->params.textclass,
656 row->par()->GetLayout());
658 string parindent = layout.parindent;
661 /* table stuff -- begin */
662 if (row->par()->table)
664 /* table stuff -- end */
666 int x = LYX_PAPER_MARGIN;
668 x += lyxfont::signedWidth(textclasslist
669 .TextClass(bview->buffer()->params.textclass)
672 .TextClass(bview->buffer()->params.textclass)
675 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
676 LyXFont font(LyXFont::ALL_SANE);
677 font.setSize(LyXFont::SIZE_SMALL);
678 x += lyxfont::width("Mwide-figM", font)
679 + LYX_PAPER_MARGIN/2;
682 // this is the way, LyX handles the LaTeX-Environments.
683 // I have had this idea very late, so it seems to be a
684 // later added hack and this is true
685 if (!row->par()->GetDepth()) {
686 if (!row->par()->GetLayout()) {
687 // find the previous same level paragraph
689 if (row->par()->FirstPhysicalPar()->Previous()) {
691 if (row->par()->Previous()) {
693 LyXParagraph * newpar = row->par()
694 ->DepthHook(row->par()->GetDepth());
696 textclasslist.Style(bview->buffer()->params.textclass,
703 // find the next level paragraph
705 LyXParagraph * newpar =
706 row->par()->DepthHook(row->par()->GetDepth()-1);
708 // make a corresponding row. Needed to call LeftMargin()
710 // check wether it is a sufficent paragraph
713 && newpar->footnoteflag == row->par()->footnoteflag
716 .Style(bview->buffer()->params.textclass,
717 newpar->GetLayout()).isEnvironment()) {
719 dummyrow.par(newpar);
720 dummyrow.pos(newpar->Last());
721 x = LeftMargin(bview, &dummyrow);
723 // this is no longer an error, because this function
724 // is used to clear impossible depths after changing
725 // a layout. Since there is always a redo,
726 // LeftMargin() is always called
728 row->par()->FirstPhysicalPar()->depth = 0;
730 row->par()->depth = 0;
734 if (newpar && !row->par()->GetLayout()) {
736 if (newpar->FirstPhysicalPar()->noindent)
738 if (newpar->noindent)
742 parindent = textclasslist
743 .Style(bview->buffer()->params.textclass,
744 newpar->GetLayout()).parindent;
749 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
750 switch (layout.margintype) {
752 if (!layout.leftmargin.empty()) {
753 x += lyxfont::signedWidth(layout.leftmargin,
755 .TextClass(bview->buffer()->params.
759 if (!row->par()->GetLabelstring().empty()) {
760 x += lyxfont::signedWidth(layout.labelindent,
762 x += lyxfont::width(row->par()->GetLabelstring(),
764 x += lyxfont::width(layout.labelsep, labelfont);
768 x += lyxfont::signedWidth(layout.labelindent, labelfont);
769 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
770 if (!row->par()->GetLabelWidthString().empty()) {
771 x += lyxfont::width(row->par()->GetLabelWidthString(),
773 x += lyxfont::width(layout.labelsep, labelfont);
778 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
779 / (row->par()->GetDepth() + 4);
781 case MARGIN_FIRST_DYNAMIC:
782 if (layout.labeltype == LABEL_MANUAL) {
783 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
784 x += lyxfont::signedWidth(layout.leftmargin,
787 x += lyxfont::signedWidth(layout.labelindent,
790 } else if (row->pos()
791 // Special case to fix problems with
793 || (layout.labeltype == LABEL_STATIC
794 && layout.latextype == LATEX_ENVIRONMENT
795 && ! row->par()->IsFirstInSequence())) {
796 x += lyxfont::signedWidth(layout.leftmargin,
798 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
799 && layout.labeltype != LABEL_BIBLIO
800 && layout.labeltype !=
801 LABEL_CENTERED_TOP_ENVIRONMENT) {
802 x += lyxfont::signedWidth(layout.labelindent,
804 x += lyxfont::width(layout.labelsep, labelfont);
805 x += lyxfont::width(row->par()->GetLabelstring(),
810 case MARGIN_RIGHT_ADDRESS_BOX:
812 // ok, a terrible hack. The left margin depends on the widest
813 // row in this paragraph. Do not care about footnotes, they
814 // are *NOT* allowed in the LaTeX realisation of this layout.
816 // find the first row of this paragraph
817 Row const * tmprow = row;
818 while (tmprow->previous()
819 && tmprow->previous()->par() == row->par())
820 tmprow = tmprow->previous();
822 int minfill = tmprow->fill();
823 while (tmprow->next() && tmprow->next()->par() == row->par()) {
824 tmprow = tmprow->next();
825 if (tmprow->fill() < minfill)
826 minfill = tmprow->fill();
829 x += lyxfont::signedWidth(layout.leftmargin,
831 .TextClass(bview->buffer()->params.textclass)
837 if ((workWidth(bview) > 0) &&
838 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
840 if (!row->par()->pextra_widthp.empty()) {
841 x += workWidth(bview) *
842 atoi(row->par()->pextra_widthp.c_str()) / 100;
843 } else if (!row->par()->pextra_width.empty()) {
844 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
845 if (xx > workWidth(bview))
846 xx = workWidth(bview) * 80 / 100;
848 } else { // should not happen
849 LyXFont font(LyXFont::ALL_SANE);
850 x += lyxfont::width("XXXXXX", font);
854 int align; // wrong type
856 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
857 align = layout.align;
859 align = row->par()->FirstPhysicalPar()->align;
861 if (row->par()->align == LYX_ALIGN_LAYOUT)
862 align = layout.align;
864 align = row->par()->align;
866 // set the correct parindent
867 if (row->pos() == 0) {
868 if ((layout.labeltype == LABEL_NO_LABEL
869 || layout.labeltype == LABEL_TOP_ENVIRONMENT
870 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
871 || (layout.labeltype == LABEL_STATIC
872 && layout.latextype == LATEX_ENVIRONMENT
873 && ! row->par()->IsFirstInSequence()))
875 && row->par() == row->par()->FirstPhysicalPar()
877 && align == LYX_ALIGN_BLOCK
878 && !row->par()->noindent
879 && (row->par()->layout ||
880 bview->buffer()->params.paragraph_separation ==
881 BufferParams::PARSEP_INDENT))
882 x += lyxfont::signedWidth(parindent,
884 .TextClass(bview->buffer()->params
887 else if (layout.labeltype == LABEL_BIBLIO) {
888 // ale970405 Right width for bibitems
889 x += bibitemMaxWidth(bview,textclasslist
890 .TextClass(bview->buffer()->params
899 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
901 LyXLayout const & layout =
902 textclasslist.Style(buf->params.textclass,
903 row->par()->GetLayout());
905 int x = LYX_PAPER_MARGIN
906 + lyxfont::signedWidth(textclasslist
907 .TextClass(buf->params.textclass)
910 .TextClass(buf->params.textclass)
914 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
915 x += LYX_PAPER_MARGIN / 2;
918 // this is the way, LyX handles the LaTeX-Environments.
919 // I have had this idea very late, so it seems to be a
920 // later added hack and this is true
921 if (row->par()->GetDepth()) {
922 // find the next level paragraph
924 LyXParagraph * newpar = row->par();
928 newpar = newpar->FirstPhysicalPar()->Previous();
930 newpar = newpar->FirstPhysicalPar();
931 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
932 && newpar->footnoteflag == row->par()->footnoteflag);
935 newpar = newpar->Previous();
937 && newpar->GetDepth() >= row->par()->GetDepth());
940 // make a corresponding row. Needed to call LeftMargin()
942 // check wether it is a sufficent paragraph
945 && 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
960 row->par()->FirstPhysicalPar()->depth = 0;
962 row->par()->depth = 0;
967 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
968 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
969 .TextClass(buf->params.textclass)
970 .defaultfont()) * 4 / (row->par()->GetDepth()
976 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
978 if (textclasslist.Style(bview->buffer()->params.textclass,
979 row->par()->GetLayout()).margintype
983 tmprow.pos(row->par()->Last());
984 return LeftMargin(bview, &tmprow); /* just the beginning
987 return 0; /* LabelEnd is only needed, if the
988 layout fills a flushleft
994 /* table stuff -- begin*/
995 int LyXText::NumberOfCell(LyXParagraph * par,
996 LyXParagraph::size_type pos) const
999 LyXParagraph::size_type tmp_pos = 0;
1000 while (tmp_pos < pos) {
1001 if (par->IsNewline(tmp_pos))
1009 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
1010 LyXParagraph::size_type & pos) const
1013 while (pos < par->Last() && !par->IsNewline(pos)) {
1014 w += SingleWidth(bview, par, pos);
1017 if (par->IsNewline(pos))
1023 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
1026 float fill_separator, fill_hfill, fill_label_hfill;
1027 if (!row->par()->table)
1029 PrepareToPrint(bview, row, tmpx, fill_separator,
1030 fill_hfill, fill_label_hfill, false);
1031 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
1035 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
1037 Row * row = GetRowNearY(y);
1038 return HitInTable(bview, row, x);
1042 /* table stuff -- end*/
1046 // get the next breakpoint in a given paragraph
1047 LyXParagraph::size_type
1048 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1050 LyXParagraph * par = row->par();
1051 LyXParagraph::size_type pos = row->pos();
1056 /* table stuff -- begin*/
1058 while (pos < par->size()
1059 && (!par->IsNewline(pos)
1060 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1061 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1062 par->GetInset(pos) && par->GetInset(pos)->display()){
1063 par->GetInset(pos)->display(false);
1069 /* table stuff -- end*/
1071 // position of the last possible breakpoint
1072 // -1 isn't a suitable value, but a flag
1073 LyXParagraph::size_type last_separator = -1;
1074 width -= RightMargin(bview->buffer(), row);
1076 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1077 LyXLayout const & layout =
1078 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1079 LyXParagraph::size_type i = pos;
1081 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1082 /* special code for right address boxes, only newlines count */
1083 while (i < par->Last()) {
1084 if (par->IsNewline(i)) {
1086 i = par->Last() - 1; // this means break
1088 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1089 par->GetInset(i) && par->GetInset(i)->display()){
1090 par->GetInset(i)->display(false);
1095 // Last position is an invariant
1096 LyXParagraph::size_type const last =
1098 // this is the usual handling
1099 int x = LeftMargin(bview, row);
1100 bool doitonetime = true;
1101 while (doitonetime || ((x < width) && (i < last))) {
1102 doitonetime = false;
1103 char c = par->GetChar(i);
1104 if (IsNewlineChar(c)) {
1106 x = width; // this means break
1107 } else if (c == LyXParagraph::META_INSET &&
1110 // check wether a Display() inset is
1111 // valid here. if not, change it to
1113 if (par->GetInset(i)->display() &&
1114 (layout.isCommand() ||
1115 ((layout.labeltype == LABEL_MANUAL) &&
1116 (i < BeginningOfMainBody(bview->buffer(), par))))) {
1117 // display istn't allowd
1118 par->GetInset(i)->display(false);
1119 x += SingleWidth(bview, par, i, c);
1120 } else if (par->GetInset(i)->display() ||
1121 par->GetInset(i)->needFullRow()) {
1122 // So break the line here
1126 if (IsLineSeparatorChar(par->GetChar(i+1)))
1129 last_separator = last; // to avoid extra rows
1131 last_separator = i - 1;
1132 x = width; // this means break
1138 x += SingleWidth(bview, par, i, c);
1142 if (IsLineSeparatorChar(c))
1144 x += SingleWidth(bview, par, i, c);
1147 if (i == main_body) {
1148 x += lyxfont::width(layout.labelsep,
1149 GetFont(bview->buffer(), par, -2));
1150 if (par->IsLineSeparator(i - 1))
1151 x-= SingleWidth(bview, par, i - 1);
1152 int left_margin = LabelEnd(bview, row);
1153 if (x < left_margin)
1157 // end of paragraph is always a suitable separator
1158 if (i == last && x < width)
1162 // well, if last_separator is still 0, the line isn't breakable.
1163 // don't care and cut simply at the end
1164 if (last_separator < 0) {
1168 // manual labels cannot be broken in LaTeX, do not care
1169 if (main_body && last_separator < main_body)
1170 last_separator = main_body - 1;
1172 return last_separator;
1176 // returns the minimum space a row needs on the screen in pixel
1177 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1179 if (paper_width < 0)
1183 // get the pure distance
1184 LyXParagraph::size_type last = RowLastPrintable(row);
1186 /* table stuff -- begin */
1187 if (row->par()->table) {
1188 // for tables FILL does calculate the widthes of each cell in
1190 LyXParagraph::size_type pos = row->pos();
1191 int cell = NumberOfCell(row->par(), pos);
1194 row->par()->table->SetWidthOfCell(cell,
1199 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1200 // don't forget the very last table cell without characters
1201 if (cell == row->par()->table->GetNumberOfCells() - 1)
1202 row->par()->table->SetWidthOfCell(cell,
1207 return 0; /* width of table cannot be returned since
1208 * we cannot guarantee its correct value at
1211 /* table stuff -- end*/
1214 // special handling of the right address boxes
1215 if (textclasslist.Style(bview->buffer()->params.textclass,
1216 row->par()->GetLayout()).margintype
1217 == MARGIN_RIGHT_ADDRESS_BOX) {
1218 int tmpfill = row->fill();
1219 row->fill(0); // the minfill in MarginLeft()
1220 w = LeftMargin(bview, row);
1223 w = LeftMargin(bview, row);
1225 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1226 row->par()->GetLayout());
1227 LyXParagraph::size_type main_body =
1228 BeginningOfMainBody(bview->buffer(), row->par());
1229 LyXParagraph::size_type i = row->pos();
1232 if (main_body > 0 && i == main_body) {
1233 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1234 if (row->par()->IsLineSeparator(i - 1))
1235 w -= SingleWidth(bview, row->par(), i - 1);
1236 int left_margin = LabelEnd(bview, row);
1237 if (w < left_margin)
1240 w += SingleWidth(bview, row->par(), i);
1243 if (main_body > 0 && main_body > last) {
1244 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1245 if (last >= 0 && row->par()->IsLineSeparator(last))
1246 w -= SingleWidth(bview, row->par(), last);
1247 int left_margin = LabelEnd(bview, row);
1248 if (w < left_margin)
1252 fill = paper_width - w - RightMargin(bview->buffer(), row);
1257 // returns the minimum space a manual label needs on the screen in pixel
1258 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1260 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1261 // -1 because a label ends either with a space that is in the label,
1262 // or with the beginning of a footnote that is outside the label.
1264 // I don't understand this code in depth, but sometimes "last" is
1265 // less than 0 and this causes a crash. This fix seems to work
1266 // correctly, but I bet the real error is elsewhere. The bug is
1267 // triggered when you have an open footnote in a paragraph
1268 // environment with a manual label. (Asger)
1269 if (last < 0) last = 0;
1271 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1278 w += SingleWidth(bview, row->par(), i);
1283 if (!row->par()->labelwidthstring.empty()) {
1284 fill = max(lyxfont::width(row->par()->labelwidthstring,
1285 GetFont(bview->buffer(), row->par(), -2)) - w,
1293 // returns the number of separators in the specified row. The separator
1294 // on the very last column doesnt count
1295 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1297 int last = RowLast(row);
1298 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1300 for (; p < last; ++p) {
1301 if (row->par()->IsSeparator(p)) {
1309 // returns the number of hfills in the specified row. The LyX-Hfill is
1310 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1311 // ignored. This is *MUCH* more usefull than not to ignore!
1312 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1314 int last = RowLast(row);
1315 int first = row->pos();
1316 if (first) { /* hfill *DO* count at the beginning
1318 while(first <= last && row->par()->IsHfill(first))
1322 first = max(first, BeginningOfMainBody(buf, row->par()));
1324 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1325 if (row->par()->IsHfill(p)) {
1333 // like NumberOfHfills, but only those in the manual label!
1334 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1336 LyXParagraph::size_type last = RowLast(row);
1337 LyXParagraph::size_type first = row->pos();
1338 if (first) { /* hfill *DO* count at the beginning
1340 while(first < last && row->par()->IsHfill(first))
1344 last = min(last, BeginningOfMainBody(buf, row->par()));
1346 for (LyXParagraph::size_type p = first;
1347 p < last; ++p) { // last, because the end is ignored!
1348 if (row->par()->IsHfill(p)) {
1356 // returns true, if a expansion is needed.
1357 // Rules are given by LaTeX
1358 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1359 LyXParagraph::size_type pos) const
1361 // by the way, is it a hfill?
1362 if (!row_ptr->par()->IsHfill(pos))
1365 // at the end of a row it does not count
1366 if (pos >= RowLast(row_ptr))
1369 // at the beginning of a row it does not count, if it is not
1370 // the first row of a paragaph
1371 if (!row_ptr->pos())
1374 // in some labels it does not count
1375 if (textclasslist.Style(buf->params.textclass,
1376 row_ptr->par()->GetLayout()).margintype
1378 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1381 // if there is anything between the first char of the row and
1382 // the sepcified position that is not a newline and not a hfill,
1383 // the hfill will count, otherwise not
1384 LyXParagraph::size_type i = row_ptr->pos();
1385 while (i < pos && (row_ptr->par()->IsNewline(i)
1386 || row_ptr->par()->IsHfill(i)))
1393 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1395 /* get the maximum ascent and the maximum descent */
1396 int asc = 0, desc = 0, pos = 0;
1397 float layoutasc = 0;
1398 float layoutdesc = 0;
1401 Inset * tmpinset = 0;
1403 /* this must not happen before the currentrow for clear reasons.
1404 so the trick is just to set the current row onto this row */
1406 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1408 /* ok , let us initialize the maxasc and maxdesc value.
1409 * This depends in LaTeX of the font of the last character
1410 * in the paragraph. The hack below is necessary because
1411 * of the possibility of open footnotes */
1413 /* Correction: only the fontsize count. The other properties
1414 are taken from the layoutfont. Nicer on the screen :) */
1416 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1417 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1419 LyXParagraph * par = row_ptr->par();
1420 LyXParagraph * firstpar = row_ptr->par();
1423 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1424 firstpar->GetLayout());
1426 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1427 LyXFont::FONT_SIZE size = font.size();
1428 font = GetFont(bview->buffer(), par, -1);
1431 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1433 float spacing_val = 1.0;
1434 if (!row_ptr->par()->spacing.isDefault()) {
1435 spacing_val = row_ptr->par()->spacing.getValue();
1437 spacing_val = bview->buffer()->params.spacing.getValue();
1439 //lyxerr << "spacing_val = " << spacing_val << endl;
1441 int maxasc = int(lyxfont::maxAscent(font) *
1442 layout.spacing.getValue() *
1444 int maxdesc = int(lyxfont::maxDescent(font) *
1445 layout.spacing.getValue() *
1447 int pos_end = RowLast(row_ptr);
1451 // Check if any insets are larger
1452 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1453 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1454 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1455 tmpinset = row_ptr->par()->GetInset(pos);
1457 tmpinset->update(bview, tmpfont);
1458 asc = tmpinset->ascent(bview, tmpfont);
1459 desc = tmpinset->descent(bview, tmpfont);
1460 maxwidth += tmpinset->width(bview, tmpfont);
1461 maxasc = max(maxasc, asc);
1462 maxdesc = max(maxdesc, desc);
1465 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1469 // Check if any custom fonts are larger (Asger)
1470 // This is not completely correct, but we can live with the small,
1471 // cosmetic error for now.
1472 LyXFont::FONT_SIZE maxsize =
1473 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1475 if (maxsize > font.size()) {
1476 font.setSize(maxsize);
1478 asc = lyxfont::maxAscent(font);
1479 desc = lyxfont::maxDescent(font);
1487 /* table stuff -- begin*/
1488 if (row_ptr->par()->table){
1489 // stretch the rows a bit
1493 /* table stuff -- end*/
1496 // This is nicer with box insets:
1500 row_ptr->ascent_of_text(maxasc);
1502 /* is it a top line? */
1503 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1505 /* some parksips VERY EASY IMPLEMENTATION */
1506 if (bview->buffer()->params.paragraph_separation ==
1507 BufferParams::PARSEP_SKIP) {
1508 if (layout.isParagraph()
1509 && firstpar->GetDepth() == 0
1510 && firstpar->Previous())
1511 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1512 else if (firstpar->Previous()
1513 && textclasslist.Style(bview->buffer()->params.textclass,
1514 firstpar->Previous()->GetLayout()).isParagraph()
1515 && firstpar->Previous()->GetDepth() == 0)
1516 // is it right to use defskip here too? (AS)
1517 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1520 /* the paper margins */
1521 if (!row_ptr->par()->previous && bv_owner)
1522 maxasc += LYX_PAPER_MARGIN;
1524 /* add the vertical spaces, that the user added */
1525 if (firstpar->added_space_top.kind() != VSpace::NONE)
1526 maxasc += int(firstpar->added_space_top.inPixels(bview));
1528 /* do not forget the DTP-lines!
1529 * there height depends on the font of the nearest character */
1530 if (firstpar->line_top)
1531 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1534 /* and now the pagebreaks */
1535 if (firstpar->pagebreak_top)
1536 maxasc += 3 * DefaultHeight();
1538 /* this is special code for the chapter, since the label of this
1539 * layout is printed in an extra row */
1540 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1541 && bview->buffer()->params.secnumdepth >= 0) {
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();
1549 labeladdon = int(lyxfont::maxDescent(labelfont) *
1550 layout.spacing.getValue() *
1552 + int(lyxfont::maxAscent(labelfont) *
1553 layout.spacing.getValue() *
1557 /* special code for the top label */
1558 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1559 || layout.labeltype == LABEL_BIBLIO
1560 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1561 && row_ptr->par()->IsFirstInSequence()
1562 && !row_ptr->par()->GetLabelstring().empty()) {
1563 float spacing_val = 1.0;
1564 if (!row_ptr->par()->spacing.isDefault()) {
1565 spacing_val = row_ptr->par()->spacing.getValue();
1567 spacing_val = bview->buffer()->params.spacing.getValue();
1571 (lyxfont::maxAscent(labelfont) *
1572 layout.spacing.getValue() *
1574 +(lyxfont::maxDescent(labelfont) *
1575 layout.spacing.getValue() *
1577 + layout.topsep * DefaultHeight()
1578 + layout.labelbottomsep * DefaultHeight());
1581 /* and now the layout spaces, for example before and after a section,
1582 * or between the items of a itemize or enumerate environment */
1584 if (!firstpar->pagebreak_top) {
1585 LyXParagraph * prev = row_ptr->par()->Previous();
1587 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1588 if (prev && prev->GetLayout() == firstpar->GetLayout()
1589 && prev->GetDepth() == firstpar->GetDepth()
1590 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1592 layoutasc = (layout.itemsep * DefaultHeight());
1594 else if (row_ptr->previous()) {
1595 tmptop = layout.topsep;
1597 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1598 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1599 row_ptr->previous()->par()->
1600 GetLayout()).bottomsep;
1603 layoutasc = (tmptop * DefaultHeight());
1605 else if (row_ptr->par()->line_top){
1606 tmptop = layout.topsep;
1609 layoutasc = (tmptop * DefaultHeight());
1612 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1614 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1615 prev->GetLayout()).parsep * DefaultHeight());
1618 if (firstpar->Previous()
1619 && firstpar->Previous()->GetDepth() == 0
1620 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1623 else if (firstpar->Previous()){
1624 maxasc += int(layout.parsep * DefaultHeight());
1630 /* is it a bottom line? */
1631 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1632 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1634 /* the paper margins */
1635 if (!par->next && bv_owner)
1636 maxdesc += LYX_PAPER_MARGIN;
1638 /* add the vertical spaces, that the user added */
1639 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1640 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1642 /* do not forget the DTP-lines!
1643 * there height depends on the font of the nearest character */
1644 if (firstpar->line_bottom)
1645 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1646 par, par->Last() - 1));
1648 /* and now the pagebreaks */
1649 if (firstpar->pagebreak_bottom)
1650 maxdesc += 3 * DefaultHeight();
1652 /* and now the layout spaces, for example before and after a section,
1653 * or between the items of a itemize or enumerate environment */
1654 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1655 LyXParagraph * nextpar = row_ptr->par()->Next();
1656 LyXParagraph * comparepar = row_ptr->par();
1660 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1661 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1662 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1663 if (comparepar->GetLayout()!= nextpar->GetLayout()
1664 || nextpar->GetLabelWidthString() !=
1665 comparepar->GetLabelWidthString())
1666 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1668 if (unusual > usual)
1669 layoutdesc = unusual;
1673 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1675 if (comparepar->GetLayout()!= nextpar->GetLayout()
1676 || nextpar->GetLabelWidthString() !=
1677 comparepar->GetLabelWidthString())
1678 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1683 /* incalculate the layout spaces */
1684 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1685 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1688 /* table stuff -- begin*/
1689 if (row_ptr->par()->table){
1690 maxasc += row_ptr->par()->table->
1691 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1693 /* table stuff -- end*/
1695 /* calculate the new height of the text */
1696 height -= row_ptr->height();
1698 row_ptr->height(maxasc + maxdesc + labeladdon);
1699 row_ptr->baseline(maxasc + labeladdon);
1701 height += row_ptr->height();
1703 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1704 row_ptr->width(maxwidth+x);
1707 width = max(0,workWidth(bview));
1709 if (r->width() > width)
1717 /* Appends the implicit specified paragraph behind the specified row,
1718 * start at the implicit given position */
1719 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1721 bool not_ready = true;
1723 // The last character position of a paragraph is an invariant so we can
1724 // safely get it here. (Asger)
1725 int lastposition = row->par()->Last();
1728 // Get the next breakpoint
1729 int z = NextBreakPoint(bview, row, workWidth(bview));
1733 // Insert the new row
1734 if (z < lastposition) {
1736 InsertRow(row, row->par(), z);
1743 // Set the dimensions of the row
1744 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1745 SetHeightOfRow(bview, tmprow);
1747 } while (not_ready);
1751 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1753 bool not_ready = true;
1756 /* get the next breakpoint */
1757 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1760 if (z < row->par()->Last() ) {
1761 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1764 InsertRow(row, row->par(), z);
1770 if (row->pos() == z)
1771 not_ready = false; // the rest will not change
1777 /* if there are some rows too much, delete them */
1778 /* only if you broke the whole paragraph! */
1779 Row * tmprow2 = row;
1780 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1781 tmprow2 = tmprow2->next();
1783 while (tmprow2 != row) {
1784 tmprow2 = tmprow2->previous();
1785 RemoveRow(tmprow2->next());
1790 /* set the dimensions of the row */
1791 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1792 SetHeightOfRow(bview, tmprow);
1793 } while (not_ready);
1797 // this is just a little changed version of break again
1798 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1800 // get the next breakpoint
1801 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1804 if (z < row->par()->Last() ) {
1806 || (row->next() && row->next()->par() != row->par())) {
1807 /* insert a new row */
1809 InsertRow(row, row->par(), z);
1815 if (row->pos() != z)
1819 // if there are some rows too much, delete them
1820 // only if you broke the whole paragraph!
1821 Row * tmprow2 = row;
1822 while (tmprow2->next()
1823 && tmprow2->next()->par() == row->par()) {
1824 tmprow2 = tmprow2->next();
1826 while (tmprow2 != row) {
1827 tmprow2 = tmprow2->previous();
1828 RemoveRow(tmprow2->next());
1832 // set the dimensions of the row
1833 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1834 SetHeightOfRow(bview, tmprow);
1838 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1840 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1841 cursor.par()->GetLayout());
1843 /* table stuff -- begin */
1844 if (cursor.par()->table) {
1845 // breaking of tables is only allowed at the beginning or the end */
1846 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1847 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1848 return; // no breaking of tables allowed
1850 /* table stuff -- end */
1852 // this is only allowed, if the current paragraph is not empty or caption
1853 if ((cursor.par()->Last() <= 0
1855 && !cursor.par()->IsDummy()
1859 layout.labeltype!= LABEL_SENSITIVE)
1862 SetUndo(bview->buffer(), Undo::INSERT,
1863 cursor.par()->ParFromPos(cursor.pos())->previous,
1864 cursor.par()->ParFromPos(cursor.pos())->next);
1867 /* table stuff -- begin */
1868 if (cursor.par()->table) {
1869 int cell = NumberOfCell(cursor.par(), cursor.pos());
1870 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1871 SetCursor(bview, cursor.par(), cursor.par()->size());
1873 /* table stuff -- end */
1875 // please break always behind a space
1876 if (cursor.pos() < cursor.par()->Last()
1877 && cursor.par()->IsLineSeparator(cursor.pos()))
1878 cursor.pos(cursor.pos() + 1);
1880 // break the paragraph
1884 keep_layout = layout.isEnvironment();
1885 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1888 /* table stuff -- begin */
1889 if (cursor.par()->table){
1890 // the table should stay with the contents
1892 cursor.par()->Next()->table = cursor.par()->table;
1893 cursor.par()->table = 0;
1896 /* table stuff -- end */
1898 // well this is the caption hack since one caption is really enough
1899 if (layout.labeltype == LABEL_SENSITIVE) {
1901 // set to standard-layout
1902 cursor.par()->SetLayout(bview->buffer()->params, 0);
1904 // set to standard-layout
1905 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1908 /* if the cursor is at the beginning of a row without prior newline,
1910 * This touches only the screen-update. Otherwise we would may have
1911 * an empty row on the screen */
1912 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1913 cursor.row()->pos() == cursor.pos()) {
1917 status = LyXText::NEED_MORE_REFRESH;
1918 refresh_row = cursor.row();
1919 refresh_y = cursor.y() - cursor.row()->baseline();
1921 // Do not forget the special right address boxes
1922 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1923 while (refresh_row->previous() &&
1924 refresh_row->previous()->par() == refresh_row->par()) {
1925 refresh_row = refresh_row->previous();
1926 refresh_y -= refresh_row->height();
1929 RemoveParagraph(cursor.row());
1931 // set the dimensions of the cursor row
1932 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1934 SetHeightOfRow(bview, cursor.row());
1938 !cursor.par()->Next()->table &&
1940 cursor.par()->Next()->Last()
1941 && cursor.par()->Next()->IsNewline(0))
1942 cursor.par()->Next()->Erase(0);
1944 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1946 UpdateCounters(bview, cursor.row()->previous());
1948 /* This check is necessary. Otherwise the new empty paragraph will
1949 * be deleted automatically. And it is more friendly for the user! */
1951 SetCursor(bview, cursor.par()->Next(), 0);
1953 SetCursor(bview, cursor.par(), 0);
1955 if (cursor.row()->next())
1956 BreakAgain(bview, cursor.row()->next());
1963 void LyXText::OpenFootnote(BufferView * bview)
1965 LyXParagraph * endpar,* tmppar;
1968 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1970 /* if there is no footnote in this paragraph, just return. */
1972 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1975 /* ok, move the cursor right before the footnote */
1977 /* just a little faster than using CursorRight() */
1979 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1980 cursor.pos(cursor.pos() + 1);
1983 /* now the cursor is at the beginning of the physical par */
1984 SetCursor(bview, cursor.par(),
1985 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1987 /* the cursor must be exactly before the footnote */
1988 par = cursor.par()->ParFromPos(cursor.pos());
1990 status = LyXText::NEED_MORE_REFRESH;
1991 refresh_row = cursor.row();
1992 refresh_y = cursor.y() - cursor.row()->baseline();
1994 tmppar = cursor.par();
1995 endpar = cursor.par()->Next();
1998 tmppar->OpenFootnote(cursor.pos());
1999 RemoveParagraph(row);
2000 /* set the dimensions of the cursor row */
2001 row->fill(Fill(bview, row, workWidth(bview)));
2002 SetHeightOfRow(bview, row);
2003 // CHECK See comment on top of text.C
2004 tmppar = tmppar->Next();
2006 while (tmppar != endpar) {
2008 InsertParagraph(bview, tmppar, row);
2009 while (row->next() && row->next()->par() == tmppar)
2011 tmppar = tmppar->Next();
2014 SetCursor(bview, par->next, 0);
2015 sel_cursor = cursor;
2021 /* table stuff -- begin*/
2023 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
2025 if (!cursor.par()->table)
2026 return; /* this should never happen */
2028 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2029 SetUndo(bview->buffer(), Undo::FINISH,
2030 cursor.par()->ParFromPos(cursor.pos())->previous,
2031 cursor.par()->ParFromPos(cursor.pos())->next);
2034 case LyXTable::SET_PWIDTH:
2035 cursor.par()->table->SetPWidth(actCell, val);
2037 case LyXTable::SET_SPECIAL_COLUMN:
2038 case LyXTable::SET_SPECIAL_MULTI:
2039 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2044 RedoParagraph(bview);
2048 void LyXText::TableFeatures(BufferView * bview, int feature) const
2051 int setAlign = LYX_ALIGN_LEFT;
2055 if (!cursor.par()->table)
2056 return; /* this should never happen */
2058 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2059 SetUndo(bview->buffer(), Undo::FINISH,
2060 cursor.par()->ParFromPos(cursor.pos())->previous,
2061 cursor.par()->ParFromPos(cursor.pos())->next);
2064 case LyXTable::ALIGN_LEFT:
2065 setAlign= LYX_ALIGN_LEFT;
2067 case LyXTable::ALIGN_RIGHT:
2068 setAlign= LYX_ALIGN_RIGHT;
2070 case LyXTable::ALIGN_CENTER:
2071 setAlign= LYX_ALIGN_CENTER;
2077 case LyXTable::APPEND_ROW: {
2078 LyXParagraph::size_type pos = cursor.pos();
2080 /* move to the next row */
2081 int cell_org = actCell;
2082 int cell = cell_org;
2084 // if there is a ContRow following this row I have to add
2085 // the row after the ContRow's
2086 if ((pos < cursor.par()->Last()) &&
2087 cursor.par()->table->RowHasContRow(cell_org)) {
2088 while((pos < cursor.par()->Last()) &&
2089 !cursor.par()->table->IsContRow(cell)) {
2090 while (pos < cursor.par()->Last() &&
2091 !cursor.par()->IsNewline(pos))
2093 if (pos < cursor.par()->Last())
2097 while((pos < cursor.par()->Last()) &&
2098 cursor.par()->table->IsContRow(cell)) {
2099 while (pos < cursor.par()->Last() &&
2100 !cursor.par()->IsNewline(pos))
2102 if (pos < cursor.par()->Last())
2107 if (pos < cursor.par()->Last())
2110 while (pos < cursor.par()->Last() &&
2111 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2112 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2114 if (pos < cursor.par()->Last())
2119 /* insert the new cells */
2120 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2121 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2122 LyXFont font(LyXFont::ALL_INHERIT,lang);
2123 for (int i = 0; i < number; ++i) {
2124 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2127 /* append the row into the table */
2128 cursor.par()->table->AppendRow(cell_org);
2129 RedoParagraph(bview);
2132 case LyXTable::APPEND_CONT_ROW: {
2133 LyXParagraph::size_type pos = cursor.pos();
2134 /* move to the next row */
2135 int cell_org = actCell;
2136 int cell = cell_org;
2138 // if there is already a controw but not for this cell
2139 // the AppendContRow sets only the right values but does
2140 // not actually add a row
2141 if (cursor.par()->table->RowHasContRow(cell_org) &&
2142 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2143 cursor.par()->table->AppendContRow(cell_org);
2144 RedoParagraph(bview);
2147 while (pos < cursor.par()->Last() &&
2149 || !cursor.par()->table->IsFirstCell(cell))){
2150 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2152 if (pos < cursor.par()->Last())
2157 /* insert the new cells */
2158 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2159 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2160 LyXFont font(LyXFont::ALL_INHERIT,lang);
2161 for (int i = 0; i < number; ++i) {
2162 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2165 /* append the row into the table */
2166 cursor.par()->table->AppendContRow(cell_org);
2167 RedoParagraph(bview);
2170 case LyXTable::APPEND_COLUMN: {
2171 LyXParagraph::size_type pos = 0;
2172 int cell_org = actCell;
2174 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2175 LyXFont font(LyXFont::ALL_INHERIT,lang);
2177 if (pos && (cursor.par()->IsNewline(pos-1))){
2178 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2179 cursor.par()->InsertChar(pos,
2180 LyXParagraph::META_NEWLINE,
2182 if (pos <= cursor.pos())
2183 cursor.pos(cursor.pos() + 1);
2189 } while (pos <= cursor.par()->Last());
2190 /* remember that the very last cell doesn't end with a newline.
2191 This saves one byte memory per table ;-) */
2192 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2193 LyXParagraph::size_type last = cursor.par()->Last();
2194 cursor.par()->InsertChar(last,
2195 LyXParagraph::META_NEWLINE, font);
2198 /* append the column into the table */
2199 cursor.par()->table->AppendColumn(cell_org);
2201 RedoParagraph(bview);
2204 case LyXTable::DELETE_ROW:
2205 if (bview->the_locking_inset)
2206 bview->unlockInset(bview->the_locking_inset);
2207 RemoveTableRow(cursor);
2208 RedoParagraph(bview);
2211 case LyXTable::DELETE_COLUMN: {
2212 LyXParagraph::size_type pos = 0;
2213 int cell_org = actCell;
2215 if (bview->the_locking_inset)
2216 bview->unlockInset(bview->the_locking_inset);
2218 if (!pos || (cursor.par()->IsNewline(pos-1))){
2219 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2221 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2222 cursor.par()->Erase(pos);
2223 if (pos < cursor.par()->Last())
2224 cursor.par()->Erase(pos);
2226 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2227 --pos; // because of pos++ below
2232 } while (pos <= cursor.par()->Last());
2234 /* delete the column from the table */
2235 cursor.par()->table->DeleteColumn(cell_org);
2237 /* set the cursor to the beginning of the table, where else? */
2239 RedoParagraph(bview);
2242 case LyXTable::TOGGLE_LINE_TOP:
2243 lineSet = !cursor.par()->table->TopLine(actCell);
2245 cursor.par()->table->SetTopLine(actCell, lineSet);
2247 LyXParagraph::size_type i;
2249 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2250 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2251 cursor.par()->table->SetTopLine(n, lineSet);
2256 RedoParagraph(bview);
2259 case LyXTable::TOGGLE_LINE_BOTTOM:
2260 lineSet = !cursor.par()->table->BottomLine(actCell);
2262 cursor.par()->table->SetBottomLine(actCell, lineSet);
2264 LyXParagraph::size_type i;
2266 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2267 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2268 cursor.par()->table->SetBottomLine(n, lineSet);
2273 RedoParagraph(bview);
2276 case LyXTable::TOGGLE_LINE_LEFT:
2277 lineSet = !cursor.par()->table->LeftLine(actCell);
2279 cursor.par()->table->SetLeftLine(actCell, lineSet);
2281 LyXParagraph::size_type i;
2283 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2284 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2285 cursor.par()->table->SetLeftLine(n, lineSet);
2290 RedoParagraph(bview);
2293 case LyXTable::TOGGLE_LINE_RIGHT:
2294 lineSet = !cursor.par()->table->RightLine(actCell);
2296 cursor.par()->table->SetRightLine(actCell, lineSet);
2299 LyXParagraph::size_type i = sel_start_cursor.pos();
2300 for (; i <= sel_end_cursor.pos(); ++i) {
2301 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2302 cursor.par()->table->SetRightLine(n, lineSet);
2307 RedoParagraph(bview);
2310 case LyXTable::ALIGN_LEFT:
2311 case LyXTable::ALIGN_RIGHT:
2312 case LyXTable::ALIGN_CENTER:
2314 cursor.par()->table->SetAlignment(actCell, setAlign);
2317 LyXParagraph::size_type i = sel_start_cursor.pos();
2318 for (; i <= sel_end_cursor.pos(); ++i) {
2319 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2320 cursor.par()->table->SetAlignment(n, setAlign);
2325 RedoParagraph(bview);
2328 case LyXTable::DELETE_TABLE:
2329 SetCursorIntern(bview, cursor.par(), 0);
2330 delete cursor.par()->table;
2331 cursor.par()->table = 0;
2332 // temporary: Should put table in simple_cut_buffer (with before and after
2333 // dummy-paragraph !!
2334 // not necessar anymore with UNDO :)
2335 for (LyXParagraph::size_type i =
2336 cursor.par()->size() - 1; i >= 0; --i)
2337 cursor.par()->Erase(i);
2338 RedoParagraph(bview);
2341 case LyXTable::MULTICOLUMN: {
2343 // check wether we are completly in a multicol
2344 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2345 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2346 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2347 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2351 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2352 LyXParagraph::size_type pos = cursor.pos();
2353 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2355 for (; newlines; --newlines)
2356 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2357 RedoParagraph(bview);
2361 // selection must be in one row (or no selection)
2363 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2366 RedoParagraph(bview);
2370 if (sel_start_cursor.row() == sel_end_cursor.row()){
2371 LyXParagraph::size_type i;
2373 for (i = sel_start_cursor.pos();
2374 i < sel_end_cursor.pos(); ++i){
2375 if (sel_start_cursor.par()->IsNewline(i)){
2376 sel_start_cursor.par()->Erase(i);
2377 // check for double-blanks
2378 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2380 (i < sel_start_cursor.par()->Last()
2381 && !sel_start_cursor.par()->IsLineSeparator(i)))
2382 sel_start_cursor.par()->InsertChar(i, ' ');
2384 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2390 cursor.par()->table->
2391 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2392 sel_start_cursor.pos()),
2394 cursor.pos(sel_start_cursor.pos());
2395 RedoParagraph(bview);
2399 WriteAlert(_("Impossible Operation!"),
2400 _("Multicolumns can only be horizontally."),
2407 case LyXTable::SET_ALL_LINES:
2409 case LyXTable::UNSET_ALL_LINES:
2411 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2415 LyXParagraph::size_type i;
2417 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2418 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2419 cursor.par()->table->SetAllLines(n, setLines);
2424 RedoParagraph(bview);
2426 case LyXTable::SET_LONGTABLE:
2427 cursor.par()->table->SetLongTable(true);
2429 case LyXTable::UNSET_LONGTABLE:
2430 cursor.par()->table->SetLongTable(false);
2432 case LyXTable::SET_ROTATE_TABLE:
2433 cursor.par()->table->SetRotateTable(true);
2435 case LyXTable::UNSET_ROTATE_TABLE:
2436 cursor.par()->table->SetRotateTable(false);
2438 case LyXTable::SET_ROTATE_CELL:
2440 cursor.par()->table->SetRotateCell(actCell, true);
2442 LyXParagraph::size_type i;
2444 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2445 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2446 cursor.par()->table->SetRotateCell(n, true);
2452 case LyXTable::UNSET_ROTATE_CELL:
2454 cursor.par()->table->SetRotateCell(actCell, false);
2457 LyXParagraph::size_type i = sel_start_cursor.pos();
2458 for (; i <= sel_end_cursor.pos(); ++i) {
2459 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2460 cursor.par()->table->SetRotateCell(n, false);
2466 case LyXTable::SET_LINEBREAKS:
2467 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2469 cursor.par()->table->SetLinebreaks(actCell, what);
2471 LyXParagraph::size_type i;
2473 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2474 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2475 cursor.par()->table->SetLinebreaks(n, what);
2481 case LyXTable::SET_LTFIRSTHEAD:
2482 cursor.par()->table->SetLTHead(actCell, true);
2484 case LyXTable::SET_LTHEAD:
2485 cursor.par()->table->SetLTHead(actCell, false);
2487 case LyXTable::SET_LTFOOT:
2488 cursor.par()->table->SetLTFoot(actCell, false);
2490 case LyXTable::SET_LTLASTFOOT:
2491 cursor.par()->table->SetLTFoot(actCell, true);
2493 case LyXTable::SET_LTNEWPAGE:
2494 what = !cursor.par()->table->LTNewPage(actCell);
2495 cursor.par()->table->SetLTNewPage(actCell, what);
2501 void LyXText::InsertCharInTable(BufferView * bview, char c)
2506 bool jumped_over_space;
2508 /* first check, if there will be two blanks together or a blank at
2509 * the beginning of a paragraph.
2510 * I decided to handle blanks like normal characters, the main
2511 * difference are the special checks when calculating the row.fill
2512 * (blank does not count at the end of a row) and the check here */
2514 LyXFont realtmpfont = real_current_font;
2515 LyXFont rawtmpfont = current_font; /* store the current font.
2516 * This is because of the use
2517 * of cursor movements. The moving
2518 * cursor would refresh the
2521 // Get the font that is used to calculate the baselineskip
2522 LyXParagraph::size_type const lastpos =
2523 cursor.par()->Last();
2524 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2527 jumped_over_space = false;
2528 if (IsLineSeparatorChar(c)) {
2529 if ((cursor.pos() > 0 &&
2530 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2531 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2532 || (cursor.pos() == 0
2534 && !(cursor.par()->Previous()
2535 && cursor.par()->Previous()->footnoteflag
2536 == LyXParagraph::OPEN_FOOTNOTE)
2540 } else if (IsNewlineChar(c)) {
2541 if (!IsEmptyTableCell()) {
2542 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2549 y = cursor.y() - row->baseline();
2550 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2551 * already inserted the character */
2552 cursor.par()->InsertChar(cursor.pos(), c);
2553 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2555 if (!jumped_over_space) {
2556 /* refresh the positions */
2558 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2559 tmprow = tmprow->next();
2560 tmprow->pos(tmprow->pos() + 1);
2564 cursor.pos(cursor.pos() + 1);
2566 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2568 current_font = rawtmpfont;
2569 real_current_font = realtmpfont;
2571 /* check, whether the last character's font has changed. */
2572 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2573 && rawparfont != rawtmpfont)
2574 RedoHeightOfParagraph(bview, cursor);
2578 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2579 LyXParagraph::size_type pos)
2582 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2583 par->GetInset(pos) && par->GetInset(pos)->display()){
2584 par->GetInset(pos)->display(false);
2588 Row * row = GetRow(par, pos, y);
2590 int tmpheight = row->height();
2591 SetHeightOfRow(bview, row);
2593 LyXParagraph::size_type tmp_pos = pos;
2594 /* update the table information */
2595 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2597 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2598 WidthOfCell(bview, par, tmp_pos))) {
2599 LyXCursor tmpcursor = cursor;
2600 SetCursorIntern(bview, par, pos, false);
2601 /* make a complete redraw */
2602 RedoDrawingOfParagraph(bview, cursor);
2606 /* redraw only the row */
2607 LyXCursor tmpcursor = cursor;
2608 SetCursorIntern(bview, par, pos);
2609 //CHECK See comment on top of text.C
2611 refresh_x = cursor.x();
2613 refresh_pos = cursor.pos();
2616 if (tmpheight == row->height())
2617 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2619 status = LyXText::NEED_MORE_REFRESH;
2621 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2626 void LyXText::BackspaceInTable(BufferView * bview)
2628 Row * tmprow, * row;
2631 LyXFont rawtmpfont = current_font;
2632 LyXFont realtmpfont = real_current_font;
2634 // Get the font that is used to calculate the baselineskip
2635 int const lastpos = cursor.par()->Last();
2636 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2639 if (cursor.pos() == 0) {
2640 /* no pasting of table paragraphs */
2644 /* this is the code for a normal backspace, not pasting
2646 SetUndo(bview->buffer(), Undo::DELETE,
2647 cursor.par()->ParFromPos(cursor.pos())->previous,
2648 cursor.par()->ParFromPos(cursor.pos())->next);
2650 CursorLeftIntern(bview);
2652 /* some insets are undeletable here */
2653 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2654 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2659 y = cursor.y() - row->baseline();
2661 /* some special code when deleting a newline. */
2662 if (cursor.par()->IsNewline(cursor.pos())) {
2666 cursor.par()->Erase(cursor.pos());
2668 /* refresh the positions */
2670 while (tmprow->next()
2671 && tmprow->next()->par() == row->par()) {
2672 tmprow = tmprow->next();
2673 tmprow->pos(tmprow->pos() - 1);
2677 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2679 /* check, wether the last characters font has changed. */
2680 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2681 && rawparfont != rawtmpfont)
2682 RedoHeightOfParagraph(bview, cursor);
2684 /* restore the current font
2685 * That is what a user expects! */
2686 current_font = rawtmpfont;
2687 real_current_font = realtmpfont;
2689 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2691 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2692 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2695 /* table stuff -- end*/
2699 // Just a macro to make some thing easier.
2700 void LyXText::RedoParagraph(BufferView * bview) const
2703 RedoParagraphs(bview, cursor, cursor.par()->Next());
2704 SetCursorIntern(bview, cursor.par(), cursor.pos());
2708 /* insert a character, moves all the following breaks in the
2709 * same Paragraph one to the right and make a rebreak */
2710 void LyXText::InsertChar(BufferView * bview, char c)
2712 SetUndo(bview->buffer(), Undo::INSERT,
2713 cursor.par()->ParFromPos(cursor.pos())->previous,
2714 cursor.par()->ParFromPos(cursor.pos())->next);
2716 // When the free-spacing option is set for the current layout,
2717 // disable the double-space checking
2720 textclasslist.Style(bview->buffer()->params.textclass,
2721 cursor.row()->par()->GetLayout()).free_spacing;
2724 /* table stuff -- begin*/
2725 if (cursor.par()->table) {
2726 InsertCharInTable(bview, c);
2730 /* table stuff -- end*/
2732 /* First check, if there will be two blanks together or a blank at
2733 the beginning of a paragraph.
2734 I decided to handle blanks like normal characters, the main
2735 difference are the special checks when calculating the row.fill
2736 (blank does not count at the end of a row) and the check here */
2738 // The bug is triggered when we type in a description environment:
2739 // The current_font is not changed when we go from label to main text
2740 // and it should (along with realtmpfont) when we type the space.
2741 // CHECK There is a bug here! (Asger)
2743 LyXFont realtmpfont = real_current_font;
2744 LyXFont rawtmpfont = current_font; /* store the current font.
2745 * This is because of the use
2746 * of cursor movements. The moving
2747 * cursor would refresh the
2750 // Get the font that is used to calculate the baselineskip
2751 LyXParagraph::size_type lastpos = cursor.par()->Last();
2752 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2755 bool jumped_over_space = false;
2757 if (!freeSpacing && IsLineSeparatorChar(c)) {
2758 if ((cursor.pos() > 0
2759 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2760 || (cursor.pos() > 0
2761 && cursor.par()->IsNewline(cursor.pos() - 1))
2762 || (cursor.pos() == 0
2764 && !(cursor.par()->Previous()
2765 && cursor.par()->Previous()->footnoteflag
2766 == LyXParagraph::OPEN_FOOTNOTE)
2769 if (cursor.pos() == 0 )
2770 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2772 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2776 } else if (IsNewlineChar(c)) {
2778 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2780 if (cursor.par() == cursor.par()
2782 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2786 /* No newline at first position
2787 * of a paragraph or behind labels.
2788 * TeX does not allow that. */
2790 if (cursor.pos() < cursor.par()->Last() &&
2791 cursor.par()->IsLineSeparator(cursor.pos()))
2792 // newline always after a blank!
2793 CursorRightIntern(bview);
2794 cursor.row()->fill(-1); // to force a new break
2797 // the display inset stuff
2798 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2799 && cursor.row()->par()->GetInset(cursor.row()->pos())
2800 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2801 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2802 cursor.row()->fill(-1); // to force a new break
2804 // get the cursor row fist
2805 Row * row = cursor.row();
2806 long y = cursor.y() - row->baseline();
2807 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2808 * already insertet the character */
2809 cursor.par()->InsertChar(cursor.pos(), c);
2810 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2812 if (!jumped_over_space) {
2813 // refresh the positions
2815 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2816 tmprow = tmprow->next();
2817 tmprow->pos(tmprow->pos() + 1);
2821 // Is there a break one row above
2822 if ((cursor.par()->IsLineSeparator(cursor.pos())
2823 || cursor.par()->IsNewline(cursor.pos())
2824 || cursor.row()->fill() == -1)
2825 && row->previous() && row->previous()->par() == row->par()) {
2826 LyXParagraph::size_type z = NextBreakPoint(bview,
2829 if ( z >= row->pos()) {
2832 // set the dimensions of the row above
2833 row->previous()->fill(Fill(bview,
2837 SetHeightOfRow(bview, row->previous());
2839 y -= row->previous()->height();
2841 refresh_row = row->previous();
2842 status = LyXText::NEED_MORE_REFRESH;
2844 BreakAgainOneRow(bview, row);
2846 current_font = rawtmpfont;
2847 real_current_font = realtmpfont;
2848 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2849 false, cursor.boundary());
2850 // cursor MUST be in row now.
2852 if (row->next() && row->next()->par() == row->par())
2853 need_break_row = row->next();
2857 // check, wether the last characters font has changed.
2858 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2859 && rawparfont != rawtmpfont)
2860 RedoHeightOfParagraph(bview, cursor);
2867 // recalculate the fill of the row
2868 if (row->fill() >= 0) /* needed because a newline
2869 * will set fill to -1. Otherwise
2870 * we would not get a rebreak! */
2871 row->fill(Fill(bview, row, workWidth(bview)));
2872 if (row->fill() < 0 ) {
2875 refresh_x = cursor.x();
2876 refresh_pos = cursor.pos();
2877 status = LyXText::NEED_MORE_REFRESH;
2878 BreakAgainOneRow(bview, row);
2879 // will the cursor be in another row now?
2880 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2881 if (row->next() && row->next()->par() == row->par())
2882 // this should always be true
2884 BreakAgainOneRow(bview, row);
2886 current_font = rawtmpfont;
2887 real_current_font = realtmpfont;
2889 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2891 if (row->next() && row->next()->par() == row->par())
2892 need_break_row = row->next();
2897 refresh_x = cursor.x();
2899 refresh_pos = cursor.pos();
2901 int tmpheight = row->height();
2902 SetHeightOfRow(bview, row);
2903 if (tmpheight == row->height())
2904 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2906 status = LyXText::NEED_MORE_REFRESH;
2908 current_font = rawtmpfont;
2909 real_current_font = realtmpfont;
2910 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2914 // check, wether the last characters font has changed.
2915 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2916 && rawparfont != rawtmpfont) {
2917 RedoHeightOfParagraph(bview, cursor);
2919 // now the special right address boxes
2920 if (textclasslist.Style(bview->buffer()->params.textclass,
2921 cursor.par()->GetLayout()).margintype
2922 == MARGIN_RIGHT_ADDRESS_BOX) {
2923 RedoDrawingOfParagraph(bview, cursor);
2931 void LyXText::charInserted()
2933 // Here we could call FinishUndo for every 20 characters inserted.
2934 // This is from my experience how emacs does it.
2935 static unsigned int counter = 0;
2945 void LyXText::PrepareToPrint(BufferView * bview,
2946 Row * row, float & x,
2947 float & fill_separator,
2949 float & fill_label_hfill,
2954 float w = row->fill();
2956 fill_label_hfill = 0;
2958 fill_label_hfill = 0;
2960 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2964 x = RightMargin(bview->buffer(), row);
2965 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2966 LyXFont font(LyXFont::ALL_SANE);
2967 font.setSize(LyXFont::SIZE_SMALL);
2968 x += lyxfont::width("Mwide-figM", font);
2972 if (workWidth(bview) > 0)
2973 x = LeftMargin(bview, row);
2977 // is there a manual margin with a manual label
2978 if (textclasslist.Style(bview->buffer()->params.textclass,
2979 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2980 && textclasslist.Style(bview->buffer()->params.textclass,
2981 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2983 /* one more since labels are left aligned */
2984 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2985 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2986 fill_label_hfill = LabelFill(bview, row) / nlh;
2990 // are there any hfills in the row?
2991 float nh = NumberOfHfills(bview->buffer(), row);
2994 /* table stuff -- begin*/
2995 if (row->par()->table) {
2996 w = workWidth(bview) - row->par()->table->WidthOfTable()
2997 - x - RightMargin(bview->buffer(), row);
2998 nh = 0; /* ignore hfills in tables */
3000 /* table stuff -- end*/
3005 // is it block, flushleft or flushright?
3006 // set x how you need it
3009 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
3010 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
3012 align = row->par()->FirstPhysicalPar()->align;
3014 if (row->par()->align == LYX_ALIGN_LAYOUT)
3015 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
3017 align = row->par()->align;
3020 // center displayed insets
3021 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
3022 && row->par()->GetInset(row->pos())
3023 && row->par()->GetInset(row->pos())->display())
3024 align = LYX_ALIGN_CENTER;
3027 case LYX_ALIGN_BLOCK:
3028 ns = NumberOfSeparators(bview->buffer(), row);
3029 if (ns && row->next() && row->next()->par() == row->par() &&
3030 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
3031 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
3032 && row->next()->par()->GetInset(row->next()->pos())
3033 && row->next()->par()->GetInset(row->next()->pos())->display())
3035 fill_separator = w / ns;
3039 case LYX_ALIGN_RIGHT:
3042 case LYX_ALIGN_CENTER:
3050 ComputeBidiTables(bview->buffer(), row);
3052 LyXParagraph::size_type main_body =
3053 BeginningOfMainBody(bview->buffer(), row->par());
3054 LyXParagraph::size_type last = RowLast(row);
3056 if (main_body > 0 &&
3057 (main_body-1 > last ||
3058 !row->par()->IsLineSeparator(main_body-1))) {
3059 LyXLayout const & layout =
3060 textclasslist.Style(bview->buffer()->params.textclass,
3061 row->par()->GetLayout());
3062 x += lyxfont::width(layout.labelsep,
3063 GetFont(bview->buffer(), row->par(), -2));
3064 if (main_body-1 <= last)
3065 x += fill_label_hfill;
3070 /* important for the screen */
3073 /* the cursor set functions have a special mechanism. When they
3074 * realize, that you left an empty paragraph, they will delete it.
3075 * They also delete the corresponding row */
3077 void LyXText::CursorRightOneWord(BufferView * bview) const
3079 // treat floats, HFills and Insets as words
3080 LyXCursor tmpcursor = cursor;
3081 // CHECK See comment on top of text.C
3083 if (tmpcursor.pos() == tmpcursor.par()->Last()
3084 && tmpcursor.par()->Next()) {
3085 tmpcursor.par(tmpcursor.par()->Next());
3090 // Skip through initial nonword stuff.
3091 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3092 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3094 // printf("Current pos1 %d", tmpcursor.pos()) ;
3095 tmpcursor.pos(tmpcursor.pos() + 1);
3098 // Advance through word.
3099 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3100 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3102 // printf("Current pos2 %d", tmpcursor.pos()) ;
3103 tmpcursor.pos(tmpcursor.pos() + 1);
3107 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3111 void LyXText::CursorTab(BufferView * bview) const
3114 if (cursor.par()->table) {
3115 int cell = NumberOfCell(cursor.par(), cursor.pos());
3116 while(cursor.par()->table->IsContRow(cell)) {
3118 cell = NumberOfCell(cursor.par(), cursor.pos());
3120 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3121 TableFeatures(bview, LyXTable::APPEND_ROW);
3124 LyXCursor tmpcursor = cursor;
3125 while (tmpcursor.pos() < tmpcursor.par()->Last()
3126 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3127 tmpcursor.pos(tmpcursor.pos() + 1);
3129 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3130 if (tmpcursor.par()->Next()) {
3131 tmpcursor.par(tmpcursor.par()->Next());
3135 tmpcursor.pos(tmpcursor.pos() + 1);
3136 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3138 if (cursor.par()->table) {
3139 int cell = NumberOfCell(cursor.par(), cursor.pos());
3140 while (cursor.par()->table->IsContRow(cell) &&
3141 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3143 while (tmpcursor.pos() < tmpcursor.par()->Last()
3144 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3145 tmpcursor.pos(tmpcursor.pos() + 1);
3147 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3148 if (tmpcursor.par()->Next()) {
3149 tmpcursor.par(tmpcursor.par()->Next());
3153 tmpcursor.pos(tmpcursor.pos() + 1);
3154 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3155 cell = NumberOfCell(cursor.par(), cursor.pos());
3162 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3163 of prior word, not to end of next prior word. */
3165 void LyXText::CursorLeftOneWord(BufferView * bview) const
3167 // treat HFills, floats and Insets as words
3168 LyXCursor tmpcursor = cursor;
3169 while (tmpcursor.pos()
3170 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3171 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3172 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3174 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3176 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3177 tmpcursor.pos(tmpcursor.pos() - 1);
3180 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3182 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3184 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3185 tmpcursor.pos(tmpcursor.pos() - 1);
3186 } else if (!tmpcursor.pos()) {
3187 if (tmpcursor.par()->Previous()){
3188 tmpcursor.par(tmpcursor.par()->Previous());
3189 tmpcursor.pos(tmpcursor.par()->Last());
3191 } else { // Here, tmpcursor != 0
3192 while (tmpcursor.pos() > 0 &&
3193 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3194 tmpcursor.pos(tmpcursor.pos() - 1);
3196 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3199 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3202 void LyXText::SelectWord(BufferView * bview)
3204 // Move cursor to the beginning, when not already there.
3206 && !cursor.par()->IsSeparator(cursor.pos()-1)
3207 && !cursor.par()->IsKomma(cursor.pos()-1) )
3208 CursorLeftOneWord(bview);
3210 // set the sel cursor
3211 sel_cursor = cursor;
3213 while ( cursor.pos() < cursor.par()->Last()
3214 && !cursor.par()->IsSeparator(cursor.pos())
3215 && !cursor.par()->IsKomma(cursor.pos()) )
3216 cursor.pos(cursor.pos() + 1);
3217 SetCursor(bview, cursor.par(), cursor.pos() );
3219 // finally set the selection
3224 /* -------> Select the word currently under the cursor when:
3225 1: no selection is currently set,
3226 2: the cursor is not at the borders of the word. */
3228 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3231 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3232 && !cursor.par()->IsSeparator(cursor.pos())
3233 && !cursor.par()->IsKomma(cursor.pos())
3234 && !cursor.par()->IsSeparator(cursor.pos() -1)
3235 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3243 // This function is only used by the spellchecker for NextWord().
3244 // It doesn't handle LYX_ACCENTs and probably never will.
3245 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3247 LyXParagraph * tmppar = cursor.par();
3249 // If this is not the very first word, skip rest of
3250 // current word because we are probably in the middle
3251 // of a word if there is text here.
3252 if (cursor.pos() || cursor.par()->previous) {
3253 while (cursor.pos() < cursor.par()->Last()
3254 && cursor.par()->IsLetter(cursor.pos()))
3255 cursor.pos(cursor.pos() + 1);
3257 // Now, skip until we have real text (will jump paragraphs)
3258 while ((cursor.par()->Last() > cursor.pos()
3259 && (!cursor.par()->IsLetter(cursor.pos())
3260 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3261 .latex() == LyXFont::ON))
3262 || (cursor.par()->Last() == cursor.pos()
3263 && cursor.par()->Next())){
3264 if (cursor.pos() == cursor.par()->Last()) {
3265 cursor.par(cursor.par()->Next());
3268 cursor.pos(cursor.pos() + 1);
3271 // Update the value if we changed paragraphs
3272 if (cursor.par() != tmppar){
3273 SetCursor(bview, cursor.par(), cursor.pos());
3274 value = float(cursor.y())/float(height);
3277 // Start the selection from here
3278 sel_cursor = cursor;
3281 std::ostringstream latex;
3285 // and find the end of the word
3286 // (optional hyphens are part of a word)
3287 while (cursor.pos() < cursor.par()->Last()
3288 && (cursor.par()->IsLetter(cursor.pos()))
3289 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3290 && cursor.par()->GetInset(cursor.pos()) != 0
3291 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3293 && latex.str() == "\\-"
3295 && latex.str() // protect against null pointers
3296 && string(latex.str(), 3) == "\\-" // this is not nice at all
3299 cursor.pos(cursor.pos() + 1);
3301 #ifndef HAVE_SSTREAM
3302 delete [] latex.str();
3304 // Finally, we copy the word to a string and return it
3307 if (sel_cursor.pos() < cursor.pos()) {
3308 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3309 LyXParagraph::size_type i, j;
3310 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3311 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3312 str[j++] = cursor.par()->GetChar(i);
3320 // This one is also only for the spellchecker
3321 void LyXText::SelectSelectedWord(BufferView * bview)
3323 // move cursor to the beginning
3324 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3326 // set the sel cursor
3327 sel_cursor = cursor;
3330 std::ostringstream latex;
3335 // now find the end of the word
3336 while (cursor.pos() < cursor.par()->Last()
3337 && (cursor.par()->IsLetter(cursor.pos())
3338 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3339 && cursor.par()->GetInset(cursor.pos()) != 0
3340 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3342 && latex.str() == "\\-"
3344 && string(latex.str(), 3) == "\\-"
3347 cursor.pos(cursor.pos() + 1);
3349 #ifndef HAVE_SSTREAM
3350 delete [] latex.str();
3352 SetCursor(bview, cursor.par(), cursor.pos());
3354 // finally set the selection
3359 /* -------> Delete from cursor up to the end of the current or next word. */
3360 void LyXText::DeleteWordForward(BufferView * bview)
3362 if (!cursor.par()->Last())
3365 LyXCursor tmpcursor = cursor;
3366 tmpcursor.row(0); //Â ??
3367 selection = true; // to avoid deletion
3368 CursorRightOneWord(bview);
3369 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3370 sel_cursor = cursor;
3374 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3375 CutSelection(bview);
3380 /* -------> Delete from cursor to start of current or prior word. */
3381 void LyXText::DeleteWordBackward(BufferView * bview)
3383 if (!cursor.par()->Last())
3386 LyXCursor tmpcursor = cursor;
3387 tmpcursor.row(0); // ??
3388 selection = true; // to avoid deletion
3389 CursorLeftOneWord(bview);
3390 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3391 sel_cursor = cursor;
3394 CutSelection(bview);
3399 /* -------> Kill to end of line. */
3400 void LyXText::DeleteLineForward(BufferView * bview)
3402 if (!cursor.par()->Last())
3403 // Paragraph is empty, so we just go to the right
3406 LyXCursor tmpcursor = cursor;
3407 // We can't store the row over a regular SetCursor
3408 // so we set it to 0 and reset it afterwards.
3409 tmpcursor.row(0); //Â ??
3410 selection = true; // to avoid deletion
3412 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3413 sel_cursor = cursor;
3416 // What is this test for ??? (JMarc)
3418 DeleteWordForward(bview);
3420 CutSelection(bview);
3426 // Change the case of a word at cursor position.
3427 // This function directly manipulates LyXParagraph::text because there
3428 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3429 // that it is correct. I guess part of it should be moved to
3430 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3431 // it does not access outside of the allocated array as the older
3432 // version did. (JMarc)
3433 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3435 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3437 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3439 LyXParagraph::size_type tmppos =
3440 cursor.par()->PositionInParFromPos(cursor.pos());
3441 while (tmppos < tmppar->size()) {
3442 unsigned char c = tmppar->GetChar(tmppos);
3443 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3445 if (c != LyXParagraph::META_INSET) {
3447 case text_lowercase:
3450 case text_capitalization:
3452 action = text_lowercase;
3454 case text_uppercase:
3460 //tmppar->text[tmppos] = c;
3461 tmppar->SetChar(tmppos, c);
3464 CheckParagraph(bview, tmppar, tmppos);
3465 CursorRightOneWord(bview);
3469 void LyXText::Delete(BufferView * bview)
3471 // this is a very easy implementation
3473 LyXCursor old_cursor = cursor;
3474 int old_cur_par_id = old_cursor.par()->id();
3475 int old_cur_par_prev_id = old_cursor.par()->previous ?
3476 old_cursor.par()->previous->id() : 0;
3478 // just move to the right
3479 CursorRightIntern(bview);
3481 // CHECK Look at the comment here.
3482 // This check is not very good...
3483 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3484 // and that can very well delete the par or par->previous in
3485 // old_cursor. Will a solution where we compare paragraph id's
3487 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3488 == old_cur_par_prev_id
3489 && cursor.par()->id() != old_cur_par_id)
3490 return; // delete-empty-paragraph-mechanism has done it
3492 // if you had success make a backspace
3493 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3494 LyXCursor tmpcursor = cursor;
3495 cursor = old_cursor; // to make sure undo gets the right cursor position
3496 SetUndo(bview->buffer(), Undo::DELETE,
3497 cursor.par()->ParFromPos(cursor.pos())->previous,
3498 cursor.par()->ParFromPos(cursor.pos())->next);
3505 void LyXText::Backspace(BufferView * bview)
3508 /* table stuff -- begin */
3509 if (cursor.par()->table) {
3510 BackspaceInTable(bview);
3513 /* table stuff -- end */
3515 // LyXFont rawtmpfont = current_font;
3516 // LyXFont realtmpfont = real_current_font;
3517 // We don't need the above variables as calling to SetCursor() with third
3518 // argument eqaul to false, will not change current_font & real_current_font
3520 // Get the font that is used to calculate the baselineskip
3521 LyXParagraph::size_type lastpos = cursor.par()->Last();
3522 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3525 if (cursor.pos() == 0) {
3526 // The cursor is at the beginning of a paragraph, so the the backspace
3527 // will collapse two paragraphs into one.
3529 // we may paste some paragraphs
3531 // is it an empty paragraph?
3534 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3536 && !(cursor.par()->Next()
3537 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3538 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3541 // This is an empty paragraph and we delete it just by moving the cursor one step
3542 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3543 // of the paragraph.
3545 if (cursor.par()->previous) {
3547 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3549 LyXParagraph * tmppar = cursor.par()->previous;
3551 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3553 && cursor.par()->footnoteflag == tmppar->footnoteflag
3555 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3556 // Inherit botom DTD from the paragraph below.
3557 // (the one we are deleting)
3558 tmppar->line_bottom = cursor.par()->line_bottom;
3559 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3560 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3563 CursorLeftIntern(bview);
3565 // the layout things can change the height of a row !
3566 int tmpheight = cursor.row()->height();
3567 SetHeightOfRow(bview, cursor.row());
3568 if (cursor.row()->height() != tmpheight) {
3569 refresh_y = cursor.y() - cursor.row()->baseline();
3570 refresh_row = cursor.row();
3571 status = LyXText::NEED_MORE_REFRESH;
3577 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3578 SetUndo(bview->buffer(), Undo::DELETE,
3579 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3580 cursor.par()->ParFromPos(cursor.pos())->next);
3583 LyXParagraph * tmppar = cursor.par();
3584 Row * tmprow = cursor.row();
3586 // We used to do CursorLeftIntern() here, but it is
3587 // not a good idea since it triggers the auto-delete
3588 // mechanism. So we do a CursorLeftIntern()-lite,
3589 // without the dreaded mechanism. (JMarc)
3590 if (cursor.par()->Previous()) {
3591 // steps into the above paragraph.
3592 SetCursorIntern(bview, cursor.par()->Previous(),
3593 cursor.par()->Previous()->Last(), false);
3596 /* Pasting is not allowed, if the paragraphs have different
3597 layout. I think it is a real bug of all other
3598 word processors to allow it. It confuses the user.
3599 Even so with a footnote paragraph and a non-footnote
3600 paragraph. I will not allow pasting in this case,
3601 because the user would be confused if the footnote behaves
3602 different wether it is open or closed.
3604 Correction: Pasting is always allowed with standard-layout
3606 if (cursor.par() != tmppar
3607 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3608 || tmppar->GetLayout() == 0 /*standard*/)
3610 && cursor.par()->footnoteflag == tmppar->footnoteflag
3613 /* table stuff -- begin*/
3614 && !cursor.par()->table /* no pasting of tables */
3615 /* table stuff -- end*/
3617 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3619 RemoveParagraph(tmprow);
3621 cursor.par()->PasteParagraph(bview->buffer()->params);
3623 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3624 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3625 // strangely enough it seems that commenting out the line above removes
3626 // most or all of the segfaults. I will however also try to move the
3627 // two Remove... lines in front of the PasteParagraph too.
3630 cursor.pos(cursor.pos() - 1);
3632 status = LyXText::NEED_MORE_REFRESH;
3633 refresh_row = cursor.row();
3634 refresh_y = cursor.y() - cursor.row()->baseline();
3636 // remove the lost paragraph
3637 // This one is not safe, since the paragraph that the tmprow and the
3638 // following rows belong to has been deleted by the PasteParagraph
3639 // above. The question is... could this be moved in front of the
3641 //RemoveParagraph(tmprow);
3642 //RemoveRow(tmprow);
3644 // This rebuilds the rows.
3645 AppendParagraph(bview, cursor.row());
3646 UpdateCounters(bview, cursor.row());
3648 // the row may have changed, block, hfills etc.
3649 SetCursor(bview, cursor.par(), cursor.pos(), false);
3652 /* this is the code for a normal backspace, not pasting
3654 SetUndo(bview->buffer(), Undo::DELETE,
3655 cursor.par()->ParFromPos(cursor.pos())->previous,
3656 cursor.par()->ParFromPos(cursor.pos())->next);
3657 // We used to do CursorLeftIntern() here, but it is
3658 // not a good idea since it triggers the auto-delete
3659 // mechanism. So we do a CursorLeftIntern()-lite,
3660 // without the dreaded mechanism. (JMarc)
3661 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3662 false, cursor.boundary());
3664 // some insets are undeletable here
3665 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3666 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3668 // force complete redo when erasing display insets
3669 // this is a cruel method but safe..... Matthias
3670 if (cursor.par()->GetInset(cursor.pos())->display() ||
3671 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
3672 cursor.par()->Erase(cursor.pos());
3673 RedoParagraph(bview);
3678 Row * row = cursor.row();
3679 long y = cursor.y() - row->baseline();
3680 LyXParagraph::size_type z;
3681 /* remember that a space at the end of a row doesnt count
3682 * when calculating the fill */
3683 if (cursor.pos() < RowLast(row) ||
3684 !cursor.par()->IsLineSeparator(cursor.pos())) {
3685 row->fill(row->fill() + SingleWidth(bview,
3690 /* some special code when deleting a newline. This is similar
3691 * to the behavior when pasting paragraphs */
3692 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3693 cursor.par()->Erase(cursor.pos());
3694 // refresh the positions
3696 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3697 tmprow = tmprow->next();
3698 tmprow->pos(tmprow->pos() - 1);
3700 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3701 cursor.pos(cursor.pos() - 1);
3703 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3704 cursor.par()->InsertChar(cursor.pos(), ' ');
3705 // refresh the positions
3707 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3708 tmprow = tmprow->next();
3709 tmprow->pos(tmprow->pos() + 1);
3713 cursor.par()->Erase(cursor.pos());
3715 // refresh the positions
3717 while (tmprow->next()
3718 && tmprow->next()->par() == row->par()) {
3719 tmprow = tmprow->next();
3720 tmprow->pos(tmprow->pos() - 1);
3723 // delete newlines at the beginning of paragraphs
3724 while (cursor.par()->Last() &&
3725 cursor.par()->IsNewline(cursor.pos()) &&
3726 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3728 cursor.par()->Erase(cursor.pos());
3729 // refresh the positions
3731 while (tmprow->next() &&
3732 tmprow->next()->par() == row->par()) {
3733 tmprow = tmprow->next();
3734 tmprow->pos(tmprow->pos() - 1);
3739 // is there a break one row above
3740 if (row->previous() && row->previous()->par() == row->par()) {
3741 z = NextBreakPoint(bview, row->previous(),
3743 if ( z >= row->pos()) {
3746 Row * tmprow = row->previous();
3748 // maybe the current row is now empty
3749 if (row->pos() >= row->par()->Last()) {
3754 BreakAgainOneRow(bview, row);
3755 if (row->next() && row->next()->par() == row->par())
3756 need_break_row = row->next();
3761 // set the dimensions of the row above
3762 y -= tmprow->height();
3763 tmprow->fill(Fill(bview, tmprow,
3765 SetHeightOfRow(bview, tmprow);
3768 refresh_row = tmprow;
3769 status = LyXText::NEED_MORE_REFRESH;
3770 SetCursor(bview, cursor.par(), cursor.pos(),
3771 false, cursor.boundary());
3772 //current_font = rawtmpfont;
3773 //real_current_font = realtmpfont;
3774 // check, whether the last character's font has changed.
3776 cursor.par()->GetFontSettings(bview->buffer()->params,
3777 cursor.par()->Last() - 1))
3778 RedoHeightOfParagraph(bview, cursor);
3783 // break the cursor row again
3784 if (row->next() && row->next()->par() == row->par() &&
3785 (RowLast(row) == row->par()->Last() - 1 ||
3786 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
3788 /* it can happen that a paragraph loses one row
3789 * without a real breakup. This is when a word
3790 * is to long to be broken. Well, I don t care this
3792 if (RowLast(row) == row->par()->Last() - 1)
3793 RemoveRow(row->next());
3797 status = LyXText::NEED_MORE_REFRESH;
3799 BreakAgainOneRow(bview, row);
3800 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3801 // cursor MUST be in row now
3803 need_break_row = row->next();
3805 // set the dimensions of the row
3806 row->fill(Fill(bview, row, workWidth(bview)));
3807 int tmpheight = row->height();
3808 SetHeightOfRow(bview, row);
3809 if (tmpheight == row->height())
3810 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3812 status = LyXText::NEED_MORE_REFRESH;
3815 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3819 // current_font = rawtmpfont;
3820 // real_current_font = realtmpfont;
3822 lastpos = cursor.par()->Last();
3823 if (cursor.pos() == lastpos) {
3824 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3825 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3826 SetCurrentFont(bview);
3829 // check, wether the last characters font has changed.
3831 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3832 RedoHeightOfParagraph(bview, cursor);
3834 // now the special right address boxes
3835 if (textclasslist.Style(bview->buffer()->params.textclass,
3836 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3837 RedoDrawingOfParagraph(bview, cursor);
3843 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3844 Row * row_ptr, long y, bool cleared)
3846 /* returns a printed row */
3847 Painter & pain = bview->painter();
3849 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3850 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3852 LyXParagraph::size_type vpos, pos;
3854 int y_top, y_bottom;
3855 float fill_separator, fill_hfill, fill_label_hfill;
3857 LyXFont font(LyXFont::ALL_SANE);
3859 if (row_ptr->height() <= 0) {
3860 lyxerr << "LYX_ERROR: row.height: "
3861 << row_ptr->height() << endl;
3864 PrepareToPrint(bview, row_ptr, x, fill_separator,
3865 fill_hfill, fill_label_hfill);
3867 if (inset_owner && (x < 0))
3871 // clear the area where we want to paint/print
3873 ww = bview->workWidth();
3875 bool clear_area = true;
3878 if ((last == row_ptr->pos()) &&
3879 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3880 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3882 clear_area = inset->doClearArea();
3884 if (cleared) { // we don't need to clear it's already done!!!
3886 } else if (clear_area) {
3889 w = inset_owner->width(bview, font);
3892 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3893 } else if (inset != 0) {
3894 int h = row_ptr->baseline() - inset->ascent(bview, font);
3898 w = inset_owner->width(bview, font);
3901 pain.fillRectangle(x_offset, y_offset, w, h);
3903 h += inset->ascent(bview, font) + inset->descent(bview, font);
3904 if ((row_ptr->height() - h) > 0) {
3907 w = inset_owner->width(bview, font);
3910 pain.fillRectangle(x_offset,h, w, row_ptr->height()-h);
3912 if (!inset_owner && !inset->display() && !inset->needFullRow())
3914 int w = inset->width(bview, font) + int(x);
3915 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3922 w = inset_owner->width(bview, font);
3925 /* selection code */
3926 if (bidi_same_direction) {
3927 if (sel_start_cursor.row() == row_ptr &&
3928 sel_end_cursor.row() == row_ptr) {
3929 if (sel_start_cursor.x() < sel_end_cursor.x())
3930 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3932 sel_end_cursor.x() - sel_start_cursor.x(),
3936 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3938 sel_start_cursor.x() - sel_end_cursor.x(),
3941 } else if (sel_start_cursor.row() == row_ptr) {
3943 pain.fillRectangle(x_offset, y_offset,
3944 sel_start_cursor.x(),
3948 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3950 w - sel_start_cursor.x(),
3953 } else if (sel_end_cursor.row() == row_ptr) {
3955 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3957 w - sel_end_cursor.x(),
3961 pain.fillRectangle(x_offset, y_offset,
3965 } else if (y > long(sel_start_cursor.y())
3966 && y < long(sel_end_cursor.y())) {
3967 pain.fillRectangle(x_offset, y_offset, w,
3971 } else if ( sel_start_cursor.row() != row_ptr &&
3972 sel_end_cursor.row() != row_ptr &&
3973 y > long(sel_start_cursor.y())
3974 && y < long(sel_end_cursor.y())) {
3975 pain.fillRectangle(x_offset, y_offset, w,
3978 } else if (sel_start_cursor.row() == row_ptr ||
3979 sel_end_cursor.row() == row_ptr) {
3983 if (row_ptr->par()->table) {
3984 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3985 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3988 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3989 (sel_end_cursor.row() != row_ptr && is_rtl))
3990 pain.fillRectangle(x_offset, y_offset,
3995 if (row_ptr->par()->table) {
3997 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3998 pos = vis2log(vpos);
3999 float old_tmpx = tmpx;
4000 if (row_ptr->par()->IsNewline(pos)) {
4001 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4004 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4006 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4008 if ( (sel_start_cursor.row() != row_ptr ||
4009 sel_start_cursor.pos() <= pos) &&
4010 (sel_end_cursor.row() != row_ptr ||
4011 pos < sel_end_cursor.pos()) )
4012 pain.fillRectangle(x_offset + int(old_tmpx),
4014 int(tmpx - old_tmpx + 1),
4020 LyXParagraph::size_type main_body =
4021 BeginningOfMainBody(bview->buffer(),
4024 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
4025 pos = vis2log(vpos);
4026 float old_tmpx = tmpx;
4027 if (main_body > 0 && pos == main_body-1) {
4028 tmpx += fill_label_hfill +
4029 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
4030 row_ptr->par()->GetLayout()).labelsep,
4031 GetFont(bview->buffer(),row_ptr->par(), -2));
4032 if (row_ptr->par()->IsLineSeparator(main_body-1))
4033 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
4035 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
4036 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4037 if (pos >= main_body)
4040 tmpx += fill_label_hfill;
4042 else if (row_ptr->par()->IsSeparator(pos)) {
4043 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4044 if (pos >= main_body)
4045 tmpx += fill_separator;
4047 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4049 if ( (sel_start_cursor.row() != row_ptr ||
4050 sel_start_cursor.pos() <= pos) &&
4051 (sel_end_cursor.row() != row_ptr ||
4052 pos < sel_end_cursor.pos()) )
4053 pain.fillRectangle(x_offset + int(old_tmpx),
4055 int(tmpx - old_tmpx + 1),
4062 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
4063 (sel_end_cursor.row() != row_ptr && !is_rtl) )
4064 pain.fillRectangle(x_offset + int(tmpx),
4074 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4075 LyXFont font(LyXFont::ALL_SANE);
4076 font.setSize(LyXFont::SIZE_FOOTNOTE);
4077 font.setColor(LColor::footnote);
4079 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
4080 if (row_ptr->previous() &&
4081 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4083 switch (row_ptr->par()->footnotekind) {
4084 case LyXParagraph::MARGIN:
4087 case LyXParagraph::FIG:
4090 case LyXParagraph::TAB:
4093 case LyXParagraph::WIDE_FIG:
4096 case LyXParagraph::WIDE_TAB:
4099 case LyXParagraph::ALGORITHM:
4102 case LyXParagraph::FOOTNOTE:
4107 pain.fillRectangle(LYX_PAPER_MARGIN,
4109 box_x - LYX_PAPER_MARGIN,
4110 int(lyxfont::maxAscent(font)
4111 + lyxfont::maxDescent(font)),
4112 LColor::footnotebg);
4114 pain.line(LYX_PAPER_MARGIN, y_offset,
4115 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4116 LColor::footnoteframe);
4118 pain.text(LYX_PAPER_MARGIN,
4119 y_offset + int(lyxfont::maxAscent(font)) + 1,
4122 pain.line(LYX_PAPER_MARGIN, y_offset,
4124 y_offset + int(lyxfont::maxAscent(font)
4125 + lyxfont::maxDescent(font)),
4126 LColor::footnoteframe);
4128 pain.line(LYX_PAPER_MARGIN,
4129 y_offset + int(lyxfont::maxAscent(font)
4130 + lyxfont::maxDescent(font)) + 1,
4132 y_offset + int(lyxfont::maxAscent(font)
4133 + lyxfont::maxDescent(font)) + 1,
4134 LColor::footnoteframe);
4138 /* draw the open floats in a red box */
4139 pain.line(box_x, y_offset,
4140 box_x, y_offset + row_ptr->height(),
4141 LColor::footnoteframe);
4143 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4145 workWidth(bview) - LYX_PAPER_MARGIN,
4146 y_offset + row_ptr->height(),
4147 LColor::footnoteframe);
4150 // Draw appendix lines
4151 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4153 pain.line(1, y_offset,
4154 1, y_offset + row_ptr->height(),
4155 LColor::appendixline);
4156 pain.line(workWidth(bview) - 2, y_offset,
4157 workWidth(bview) - 2,
4158 y_offset + row_ptr->height(),
4159 LColor::appendixline);
4162 // Draw minipage line
4163 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4165 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4167 y_offset + row_ptr->height() - 1,
4168 LColor::minipageline);
4171 int depth = p->GetDepth();
4172 for (int i = 1; i <= depth; ++i) {
4173 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4174 pain.line(line_x, y_offset, line_x,
4175 y_offset + row_ptr->height() - 1,
4178 } else if (row_ptr->previous() &&
4179 row_ptr->previous()->par()->footnoteflag
4180 == LyXParagraph::OPEN_FOOTNOTE) {
4181 LyXFont font(LyXFont::ALL_SANE);
4182 font.setSize(LyXFont::SIZE_FOOTNOTE);
4184 int box_x = LYX_PAPER_MARGIN;
4185 box_x += lyxfont::width(" wide-tab ", font);
4187 pain.line(box_x, y_offset,
4188 workWidth(bview) - LYX_PAPER_MARGIN,
4189 y_offset, LColor::footnote);
4192 // Draw appendix lines
4194 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4196 LyXParagraph * firstpar = row_ptr->par();
4198 if (firstpar->appendix){
4199 pain.line(1, y_offset,
4200 1, y_offset + row_ptr->height(),
4201 LColor::appendixline);
4202 pain.line(ww - 2, y_offset,
4203 ww - 2, y_offset + row_ptr->height(),
4204 LColor::appendixline);
4207 // Draw minipage line
4208 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4210 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4211 LYX_PAPER_MARGIN/5 + box_x,
4212 y_offset + row_ptr->height() - 1,
4213 LColor::minipageline);
4216 int depth = firstpar->GetDepth();
4220 if (row_ptr->next())
4222 if (row_ptr->par()->footnoteflag ==
4223 row_ptr->next()->par()->footnoteflag)
4224 next_depth = row_ptr->next()->par()->GetDepth();
4225 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4228 next_depth = row_ptr->next()->par()->GetDepth();
4230 if (row_ptr->previous())
4232 if (row_ptr->par()->footnoteflag ==
4233 row_ptr->previous()->par()->footnoteflag)
4234 prev_depth = row_ptr->previous()->par()->GetDepth();
4235 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4238 prev_depth = row_ptr->previous()->par()->GetDepth();
4241 for (int i = 1; i <= depth; ++i) {
4242 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4243 pain.line(line_x, y_offset, line_x,
4244 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4248 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4251 pain.fillRectangle(line_x,
4252 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4253 LYX_PAPER_MARGIN / 5, 2,
4259 LyXLayout const & layout =
4260 textclasslist.Style(bview->buffer()->params.textclass,
4261 row_ptr->par()->GetLayout());
4264 y_bottom = row_ptr->height();
4266 /* is it a first row? */
4267 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4269 /* start of appendix? */
4270 if (row_ptr->par()->start_of_appendix){
4271 pain.line(1, y_offset,
4273 LColor::appendixline);
4276 /* think about the margins */
4277 if (!row_ptr->previous() && bv_owner)
4278 y_top += LYX_PAPER_MARGIN;
4280 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4282 pb_font.setColor(LColor::pagebreak).decSize();
4283 int w = 0, a = 0, d = 0;
4284 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4286 y_offset + y_top + 2 * DefaultHeight(),
4288 Painter::line_onoffdash)
4291 _("Page Break (top)"),
4294 LColor::background, false, w, a, d);
4295 pain.rectText((ww - w)/2,
4296 y_offset + y_top + 2 * DefaultHeight() + d,
4297 _("Page Break (top)"),
4300 LColor::background);
4301 y_top += 3 * DefaultHeight();
4304 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4305 /* draw a vfill top */
4306 pain.line(0, y_offset + 2 + y_top,
4307 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4310 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4312 y_offset + y_top + 3 * DefaultHeight(),
4315 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4316 LYX_PAPER_MARGIN / 2,
4317 y_offset + y_top + 3 * DefaultHeight(),
4320 y_top += 3 * DefaultHeight();
4323 /* think about user added space */
4324 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4326 /* think about the parskip */
4327 /* some parskips VERY EASY IMPLEMENTATION */
4328 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4329 if (layout.latextype == LATEX_PARAGRAPH
4330 && firstpar->GetDepth() == 0
4331 && firstpar->Previous())
4332 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4333 else if (firstpar->Previous()
4334 && textclasslist.Style(bview->buffer()->params.textclass,
4335 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4336 && firstpar->Previous()->GetDepth() == 0)
4337 // is it right to use defskip here, too? (AS)
4338 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4341 if (row_ptr->par()->line_top) { /* draw a top line */
4342 y_top += lyxfont::ascent('x',
4343 GetFont(bview->buffer(),
4344 row_ptr->par(), 0));
4346 pain.line(0, y_offset + y_top,
4347 ww, y_offset + y_top,
4349 Painter::line_solid,
4350 Painter::line_thick);
4352 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4353 row_ptr->par(), 0));
4356 /* should we print a label? */
4357 if (layout.labeltype >= LABEL_STATIC
4358 && (layout.labeltype != LABEL_STATIC
4359 || layout.latextype != LATEX_ENVIRONMENT
4360 || row_ptr->par()->IsFirstInSequence())) {
4361 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4362 if (!row_ptr->par()->GetLabelstring().empty()) {
4364 string tmpstring = row_ptr->par()->GetLabelstring();
4366 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4367 if (bview->buffer()->params.secnumdepth >= 0) {
4368 /* this is special code for the chapter layout. This is printed in
4369 * an extra row and has a pagebreak at the top. */
4370 float spacing_val = 1.0;
4371 if (!row_ptr->par()->spacing.isDefault()) {
4372 spacing_val = row_ptr->par()->spacing.getValue();
4374 spacing_val = bview->buffer()->params.spacing.getValue();
4377 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4378 + int(layout.parsep) * DefaultHeight();
4380 tmpx = ww - LeftMargin(bview, row_ptr) -
4381 lyxfont::width(tmpstring, font);
4382 pain.text(int(tmpx),
4383 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4388 tmpx = ww - LeftMargin(bview, row_ptr)
4389 + lyxfont::width(layout.labelsep, font);
4391 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4392 LyXFont font(LyXFont::ALL_SANE);
4393 font.setSize(LyXFont::SIZE_SMALL);
4394 tmpx += lyxfont::width("Mwide-fixM", font);
4398 tmpx = x - lyxfont::width(layout.labelsep, font)
4399 - lyxfont::width(tmpstring, font);
4402 pain.text(int(tmpx),
4403 y_offset + row_ptr->baseline(),
4407 /* the labels at the top of an environment. More or less for bibliography */
4408 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4409 layout.labeltype == LABEL_BIBLIO ||
4410 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4411 if (row_ptr->par()->IsFirstInSequence()) {
4412 font = GetFont(bview->buffer(),
4413 row_ptr->par(), -2);
4414 if (!row_ptr->par()->GetLabelstring().empty()) {
4415 string tmpstring = row_ptr->par()->GetLabelstring();
4416 float spacing_val = 1.0;
4417 if (!row_ptr->par()->spacing.isDefault()) {
4418 spacing_val = row_ptr->par()->spacing.getValue();
4420 spacing_val = bview->buffer()->params.spacing.getValue();
4423 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4424 + (layout.labelbottomsep * DefaultHeight()));
4427 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4428 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4429 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4430 tmpx -= lyxfont::width(tmpstring, font) / 2;
4432 tmpx = ww - LeftMargin(bview, row_ptr) -
4433 lyxfont::width(tmpstring, font);
4434 pain.text(int(tmpx),
4435 y_offset + row_ptr->baseline()
4436 - row_ptr->ascent_of_text()
4442 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4443 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4445 tmpx = ww - LeftMargin(bview, row_ptr)
4446 + lyxfont::width(layout.labelsep, font);
4448 tmpx = x - lyxfont::width(layout.labelsep, font)
4449 - row_ptr->par()->bibkey->width(bview, font);
4450 row_ptr->par()->bibkey->draw(bview, font,
4451 y_offset + row_ptr->baseline(),
4456 /* is it a last row? */
4458 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4460 LyXParagraph * par = row_ptr->par();
4462 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4463 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4465 /* think about the margins */
4466 if (!row_ptr->next() && bv_owner)
4467 y_bottom -= LYX_PAPER_MARGIN;
4469 /* draw a bottom pagebreak */
4470 if (firstpar->pagebreak_bottom) {
4472 pb_font.setColor(LColor::pagebreak).decSize();
4473 int w = 0, a = 0, d = 0;
4475 y_offset + y_bottom - 2 * DefaultHeight(),
4477 y_offset + y_bottom - 2 * DefaultHeight(),
4479 Painter::line_onoffdash)
4482 _("Page Break (bottom)"),
4485 LColor::background, false, w, a, d);
4486 pain.rectText((ww - w) / 2,
4487 y_offset + y_top + 2 * DefaultHeight() + d,
4488 _("Page Break (bottom)"),
4491 LColor::background);
4492 y_bottom -= 3 * DefaultHeight();
4495 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4496 /* draw a vfill bottom */
4497 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4499 y_offset + y_bottom - 3 * DefaultHeight(),
4501 pain.line(0, y_offset + y_bottom - 2,
4503 y_offset + y_bottom - 2,
4505 pain.line(LYX_PAPER_MARGIN / 2,
4506 y_offset + y_bottom - 3 * DefaultHeight(),
4507 LYX_PAPER_MARGIN / 2,
4508 y_offset + y_bottom - 2,
4510 y_bottom -= 3 * DefaultHeight();
4513 /* think about user added space */
4514 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4516 if (firstpar->line_bottom) {
4517 /* draw a bottom line */
4518 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4519 par, par->Last() - 1));
4520 pain.line(0, y_offset + y_bottom,
4521 ww, y_offset + y_bottom,
4522 LColor::topline, Painter::line_solid,
4523 Painter::line_thick);
4524 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4525 par, par->Last() - 1));
4529 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4532 case END_LABEL_FILLED_BOX:
4534 LyXFont font = GetFont(bview->buffer(),
4535 row_ptr->par(), last);
4536 int size = int(0.75 * lyxfont::maxAscent(font));
4537 int y = (y_offset + row_ptr->baseline()) - size;
4538 int x = is_rtl ? LYX_PAPER_MARGIN
4539 : ww - LYX_PAPER_MARGIN - size;
4541 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4543 LyXFont font(LyXFont::ALL_SANE);
4544 font.setSize(LyXFont::SIZE_SMALL);
4545 x += lyxfont::width("Mwide-figM", font);
4547 x -= LYX_PAPER_MARGIN/2;
4549 if (row_ptr->fill() <= size)
4550 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4551 if (endlabel == END_LABEL_BOX) {
4552 pain.line(x, y, x, y + size,
4554 pain.line(x + size, y, x + size , y + size,
4556 pain.line(x, y, x + size, y,
4558 pain.line(x, y + size, x + size, y + size,
4561 pain.fillRectangle(x, y, size, size,
4565 case END_LABEL_STATIC:
4567 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4568 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4569 layout).endlabelstring();
4570 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4571 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4572 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4573 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4576 case END_LABEL_NO_LABEL:
4581 /* draw the text in the pixmap */
4583 vpos = row_ptr->pos();
4585 /* table stuff -- begin*/
4586 if (row_ptr->par()->table) {
4588 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4590 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4592 while (vpos <= last) {
4593 pos = vis2log(vpos);
4594 if (row_ptr->par()->IsNewline(pos)) {
4596 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4597 /* draw the table lines, still very simple */
4598 on_off = !row_ptr->par()->table->TopLine(cell);
4600 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4601 !row_ptr->par()->table->IsContRow(cell))
4602 pain.line(int(x_old),
4603 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4605 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4607 on_off ? Painter::line_onoffdash : Painter::line_solid);
4609 on_off = !row_ptr->par()->table->BottomLine(cell);
4610 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4611 row_ptr->par()->table->VeryLastRow(cell))
4613 pain.line(int(x_old),
4614 y_offset + y_bottom - 1,
4616 y_offset + y_bottom - 1,
4618 on_off ? Painter::line_onoffdash : Painter::line_solid);
4620 on_off = !row_ptr->par()->table->LeftLine(cell);
4622 pain.line(int(x_old),
4623 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4625 y_offset + y_bottom - 1,
4627 on_off ? Painter::line_onoffdash : Painter::line_solid);
4629 on_off = !row_ptr->par()->table->RightLine(cell);
4631 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4632 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4633 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4634 y_offset + y_bottom - 1,
4636 on_off ? Painter::line_onoffdash : Painter::line_solid);
4639 /* take care about the alignment and other spaces */
4641 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4642 if (row_ptr->par()->table->IsFirstCell(cell))
4643 --cell; // little hack, sorry
4645 } else if (row_ptr->par()->IsHfill(pos)) {
4649 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4651 y_offset + row_ptr->baseline(),
4656 } else if (row_ptr->par()->IsSeparator(pos)) {
4658 x+= SingleWidth(bview,
4659 row_ptr->par(), pos);
4662 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4665 /* do not forget the very last cell. This has no NEWLINE so
4666 * ignored by the code above*/
4667 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4668 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4669 on_off = !row_ptr->par()->table->TopLine(cell);
4671 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4672 !row_ptr->par()->table->IsContRow(cell))
4674 pain.line(int(x_old),
4675 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4677 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4679 on_off ? Painter::line_onoffdash : Painter::line_solid);
4680 on_off = !row_ptr->par()->table->BottomLine(cell);
4681 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4682 row_ptr->par()->table->VeryLastRow(cell))
4684 pain.line(int(x_old),
4685 y_offset + y_bottom - 1,
4687 y_offset + y_bottom - 1,
4689 on_off ? Painter::line_onoffdash : Painter::line_solid);
4691 on_off = !row_ptr->par()->table->LeftLine(cell);
4693 pain.line(int(x_old),
4694 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4696 y_offset + y_bottom - 1,
4698 on_off ? Painter::line_onoffdash : Painter::line_solid);
4700 on_off = !row_ptr->par()->table->RightLine(cell);
4702 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4703 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4704 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4705 y_offset + y_bottom - 1,
4707 on_off ? Painter::line_onoffdash : Painter::line_solid);
4710 /* table stuff -- end*/
4712 LyXParagraph::size_type main_body =
4713 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4714 if (main_body > 0 &&
4715 (main_body-1 > last ||
4716 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4719 while (vpos <= last) {
4720 pos = vis2log(vpos);
4721 if (main_body > 0 && pos == main_body - 1) {
4722 x += fill_label_hfill
4723 + lyxfont::width(layout.labelsep,
4724 GetFont(bview->buffer(),
4725 row_ptr->par(), -2))
4726 - SingleWidth(bview,
4731 if (row_ptr->par() ->IsHfill(pos)) {
4734 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4736 y_offset + row_ptr->baseline(),
4739 if (HfillExpansion(bview->buffer(),
4741 if (pos >= main_body) {
4743 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4744 int(x + fill_hfill),
4745 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4747 Painter::line_onoffdash);
4751 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4752 int(x + fill_label_hfill),
4753 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4755 Painter::line_onoffdash);
4757 x += fill_label_hfill;
4760 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4762 y_offset + row_ptr->baseline(),
4767 } else if (row_ptr->par()->IsSeparator(pos)) {
4768 x += SingleWidth(bview,
4769 row_ptr->par(), pos);
4770 if (pos >= main_body)
4771 x += fill_separator;
4774 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4782 int LyXText::DefaultHeight() const
4784 LyXFont font(LyXFont::ALL_SANE);
4785 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4789 /* returns the column near the specified x-coordinate of the row
4790 * x is set to the real beginning of this column */
4791 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4792 bool & boundary) const
4795 float fill_separator, fill_hfill, fill_label_hfill;
4797 PrepareToPrint(bview, row, tmpx, fill_separator,
4798 fill_hfill, fill_label_hfill);
4800 LyXParagraph::size_type vc = row->pos();
4801 LyXParagraph::size_type last = RowLastPrintable(row);
4802 LyXParagraph::size_type c = 0;
4803 LyXLayout const & layout =
4804 textclasslist.Style(bview->buffer()->params.textclass,
4805 row->par()->GetLayout());
4806 bool left_side = false;
4809 /* table stuff -- begin */
4810 if (row->par()->table) {
4811 //the last row doesn't need a newline at the end
4812 if (row->next() && row->next()->par() == row->par()
4813 && row->par()->IsNewline(last))
4815 int cell = NumberOfCell(row->par(), row->pos());
4816 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4817 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4818 float last_tmpx = tmpx;
4819 while (vc <= last && tmpx <= x) {
4822 if (row->par()->IsNewline(c)) {
4825 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4826 cell_x += row->par()->table->WidthOfColumn(cell);
4831 tmpx += SingleWidth(bview, row->par(), c);
4835 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4836 (tmpx + last_tmpx) / 2 > x) {
4841 /* table stuff -- end*/
4843 LyXParagraph::size_type
4844 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4845 float last_tmpx = tmpx;
4847 if (main_body > 0 &&
4848 (main_body-1 > last ||
4849 !row->par()->IsLineSeparator(main_body - 1)))
4852 while (vc <= last && tmpx <= x) {
4855 if (main_body > 0 && c == main_body-1) {
4856 tmpx += fill_label_hfill +
4857 lyxfont::width(layout.labelsep,
4858 GetFont(bview->buffer(), row->par(), -2));
4859 if (row->par()->IsLineSeparator(main_body - 1))
4860 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4863 if (HfillExpansion(bview->buffer(), row, c)) {
4864 x += SingleWidth(bview, row->par(), c);
4868 tmpx += fill_label_hfill;
4870 else if (row->par()->IsSeparator(c)) {
4871 tmpx += SingleWidth(bview, row->par(), c);
4873 tmpx+= fill_separator;
4875 tmpx += SingleWidth(bview, row->par(), c);
4879 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4887 if (vc > last + 1) // This shouldn't happen.
4891 #if 0 // currently unused
4892 bool lastrow = (!row->next() || row->next()->par() != row->par());
4893 bool rtl = (lastrow)
4894 ? row->par()->isRightToLeftPar(bview->buffer()->params)
4898 if (row->pos() > last) // Row is empty?
4900 #warning This is wrong, please have a look Dekel (Jug)
4903 ( (rtl && vc == row->pos()&& x < tmpx - 5) ||
4904 (!rtl && vc == last + 1 && x > tmpx + 5) ))
4907 else if (vc == row->pos()
4909 || (row->par()->table
4910 && vc <= last && row->par()->IsNewline(vc-1))
4914 if (bidi_level(c) % 2 == 1)
4917 c = vis2log(vc - 1);
4918 bool rtl = (bidi_level(c) % 2 == 1);
4919 if (left_side == rtl) {
4921 boundary = IsBoundary(bview->buffer(), row->par(), c);
4927 !row->par()->table &&
4929 row->pos() <= last && c > last
4930 && row->par()->IsNewline(last)) {
4931 if (bidi_level(last) % 2 == 0)
4932 tmpx -= SingleWidth(bview, row->par(), last);
4934 tmpx += SingleWidth(bview, row->par(), last);
4945 /* turn the selection into a new environment. If there is no selection,
4946 * create an empty environment */
4947 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4948 LyXParagraph::footnote_kind kind)
4950 /* no footnoteenvironment in a footnoteenvironment */
4951 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4952 WriteAlert(_("Impossible operation"),
4953 _("You can't insert a float in a float!"),
4957 /* no marginpars in minipages */
4958 if (kind == LyXParagraph::MARGIN
4959 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4960 WriteAlert(_("Impossible operation"),
4961 _("You can't insert a marginpar in a minipage!"),
4966 /* this doesnt make sense, if there is no selection */
4967 bool dummy_selection = false;
4969 sel_start_cursor = cursor; /* dummy selection */
4970 sel_end_cursor = cursor;
4971 dummy_selection = true;
4974 LyXParagraph * tmppar;
4977 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4978 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4982 /* a test to make sure there is not already a footnote
4983 * in the selection. */
4985 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4987 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4988 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4989 tmppar = tmppar->next;
4991 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4992 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4993 WriteAlert(_("Impossible operation"),
4994 _("Float would include float!"),
4999 /* ok we have a selection. This is always between sel_start_cursor
5000 * and sel_end cursor */
5002 SetUndo(bview->buffer(), Undo::FINISH,
5003 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
5004 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
5006 if (sel_end_cursor.pos() > 0
5007 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
5008 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
5009 /* please break before a space at the end */
5010 if (sel_start_cursor.par() == sel_end_cursor.par()
5011 && sel_start_cursor.pos() > sel_end_cursor.pos())
5012 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
5014 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
5016 sel_end_cursor.par(sel_end_cursor.par()->Next());
5017 sel_end_cursor.pos(0);
5019 // don't forget to insert a dummy layout paragraph if necessary
5020 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
5021 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
5022 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
5023 sel_end_cursor.par(sel_end_cursor.par()->next);
5026 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
5028 cursor = sel_end_cursor;
5030 /* please break behind a space, if there is one. The space should
5032 if (sel_start_cursor.pos() > 0
5033 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
5034 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
5035 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
5036 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
5039 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
5040 sel_start_cursor.pos());
5041 tmppar = sel_start_cursor.par()->Next();
5043 if (dummy_selection) {
5045 if (kind == LyXParagraph::TAB
5046 || kind == LyXParagraph::FIG
5047 || kind == LyXParagraph::WIDE_TAB
5048 || kind == LyXParagraph::WIDE_FIG
5049 || kind == LyXParagraph::ALGORITHM) {
5050 pair<bool, LyXTextClass::size_type> lres =
5051 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
5053 LyXTextClass::size_type lay;
5059 lay = 0; // use default layout "Standard" (0)
5061 tmppar->SetLayout(bview->buffer()->params, lay);
5064 if (sel_start_cursor.pos() > 0) {
5065 /* the footnote-environment should begin with a standard layout.
5066 * Imagine you insert a footnote within an enumeration, you
5067 * certainly do not want an enumerated footnote! */
5070 /* this is a exception the user would sometimes expect, I hope */
5071 sel_start_cursor.par()->Clear();
5075 while (tmppar != sel_end_cursor.par()) {
5076 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
5077 tmppar->footnotekind = kind;
5078 tmppar = tmppar->Next();
5081 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
5083 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
5090 // returns pointer to a specified row
5091 Row * LyXText::GetRow(LyXParagraph * par,
5092 LyXParagraph::size_type pos, long & y) const
5094 Row * tmprow = firstrow;
5097 // find the first row of the specified paragraph
5098 while (tmprow->next() && tmprow->par() != par) {
5099 y += tmprow->height();
5100 tmprow = tmprow->next();
5103 // now find the wanted row
5104 while (tmprow->pos() < pos
5106 && tmprow->next()->par() == par
5107 && tmprow->next()->pos() <= pos) {
5108 y += tmprow->height();
5109 tmprow = tmprow->next();