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? */
1633 row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1635 row_ptr->par() == par
1637 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1639 /* the paper margins */
1640 if (!par->next && bv_owner)
1641 maxdesc += LYX_PAPER_MARGIN;
1643 /* add the vertical spaces, that the user added */
1644 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1645 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1647 /* do not forget the DTP-lines!
1648 * there height depends on the font of the nearest character */
1649 if (firstpar->line_bottom)
1650 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1651 par, par->Last() - 1));
1653 /* and now the pagebreaks */
1654 if (firstpar->pagebreak_bottom)
1655 maxdesc += 3 * DefaultHeight();
1657 /* and now the layout spaces, for example before and after a section,
1658 * or between the items of a itemize or enumerate environment */
1659 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1660 LyXParagraph * nextpar = row_ptr->par()->Next();
1661 LyXParagraph * comparepar = row_ptr->par();
1665 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1666 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1667 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1668 if (comparepar->GetLayout()!= nextpar->GetLayout()
1669 || nextpar->GetLabelWidthString() !=
1670 comparepar->GetLabelWidthString())
1671 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1673 if (unusual > usual)
1674 layoutdesc = unusual;
1678 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1680 if (comparepar->GetLayout()!= nextpar->GetLayout()
1681 || nextpar->GetLabelWidthString() !=
1682 comparepar->GetLabelWidthString())
1683 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1688 /* incalculate the layout spaces */
1689 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1690 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1693 /* table stuff -- begin*/
1694 if (row_ptr->par()->table){
1695 maxasc += row_ptr->par()->table->
1696 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1698 /* table stuff -- end*/
1700 /* calculate the new height of the text */
1701 height -= row_ptr->height();
1703 row_ptr->height(maxasc + maxdesc + labeladdon);
1704 row_ptr->baseline(maxasc + labeladdon);
1706 height += row_ptr->height();
1708 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
1709 row_ptr->width(int(maxwidth + x));
1712 width = max(0,workWidth(bview));
1714 if (r->width() > width)
1722 /* Appends the implicit specified paragraph behind the specified row,
1723 * start at the implicit given position */
1724 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1726 bool not_ready = true;
1728 // The last character position of a paragraph is an invariant so we can
1729 // safely get it here. (Asger)
1730 int lastposition = row->par()->Last();
1733 // Get the next breakpoint
1734 int z = NextBreakPoint(bview, row, workWidth(bview));
1738 // Insert the new row
1739 if (z < lastposition) {
1741 InsertRow(row, row->par(), z);
1748 // Set the dimensions of the row
1749 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1750 SetHeightOfRow(bview, tmprow);
1752 } while (not_ready);
1756 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1758 bool not_ready = true;
1761 /* get the next breakpoint */
1762 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1765 if (z < row->par()->Last() ) {
1766 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1769 InsertRow(row, row->par(), z);
1775 if (row->pos() == z)
1776 not_ready = false; // the rest will not change
1782 /* if there are some rows too much, delete them */
1783 /* only if you broke the whole paragraph! */
1784 Row * tmprow2 = row;
1785 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1786 tmprow2 = tmprow2->next();
1788 while (tmprow2 != row) {
1789 tmprow2 = tmprow2->previous();
1790 RemoveRow(tmprow2->next());
1795 /* set the dimensions of the row */
1796 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1797 SetHeightOfRow(bview, tmprow);
1798 } while (not_ready);
1802 // this is just a little changed version of break again
1803 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1805 // get the next breakpoint
1806 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1809 if (z < row->par()->Last() ) {
1811 || (row->next() && row->next()->par() != row->par())) {
1812 /* insert a new row */
1814 InsertRow(row, row->par(), z);
1820 if (row->pos() != z)
1824 // if there are some rows too much, delete them
1825 // only if you broke the whole paragraph!
1826 Row * tmprow2 = row;
1827 while (tmprow2->next()
1828 && tmprow2->next()->par() == row->par()) {
1829 tmprow2 = tmprow2->next();
1831 while (tmprow2 != row) {
1832 tmprow2 = tmprow2->previous();
1833 RemoveRow(tmprow2->next());
1837 // set the dimensions of the row
1838 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1839 SetHeightOfRow(bview, tmprow);
1843 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1845 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1846 cursor.par()->GetLayout());
1848 /* table stuff -- begin */
1849 if (cursor.par()->table) {
1850 // breaking of tables is only allowed at the beginning or the end */
1851 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1852 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1853 return; // no breaking of tables allowed
1855 /* table stuff -- end */
1857 // this is only allowed, if the current paragraph is not empty or caption
1858 if ((cursor.par()->Last() <= 0
1860 && !cursor.par()->IsDummy()
1864 layout.labeltype!= LABEL_SENSITIVE)
1867 SetUndo(bview->buffer(), Undo::INSERT,
1869 cursor.par()->ParFromPos(cursor.pos())->previous,
1870 cursor.par()->ParFromPos(cursor.pos())->next
1872 cursor.par()->previous,
1878 /* table stuff -- begin */
1879 if (cursor.par()->table) {
1880 int cell = NumberOfCell(cursor.par(), cursor.pos());
1881 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1882 SetCursor(bview, cursor.par(), cursor.par()->size());
1884 /* table stuff -- end */
1886 // please break always behind a space
1887 if (cursor.pos() < cursor.par()->Last()
1888 && cursor.par()->IsLineSeparator(cursor.pos()))
1889 cursor.pos(cursor.pos() + 1);
1891 // break the paragraph
1895 keep_layout = layout.isEnvironment();
1896 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1899 /* table stuff -- begin */
1900 if (cursor.par()->table){
1901 // the table should stay with the contents
1903 cursor.par()->Next()->table = cursor.par()->table;
1904 cursor.par()->table = 0;
1907 /* table stuff -- end */
1909 // well this is the caption hack since one caption is really enough
1910 if (layout.labeltype == LABEL_SENSITIVE) {
1912 // set to standard-layout
1913 cursor.par()->SetLayout(bview->buffer()->params, 0);
1915 // set to standard-layout
1916 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1919 /* if the cursor is at the beginning of a row without prior newline,
1921 * This touches only the screen-update. Otherwise we would may have
1922 * an empty row on the screen */
1923 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1924 cursor.row()->pos() == cursor.pos()) {
1928 status = LyXText::NEED_MORE_REFRESH;
1929 refresh_row = cursor.row();
1930 refresh_y = cursor.y() - cursor.row()->baseline();
1932 // Do not forget the special right address boxes
1933 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1934 while (refresh_row->previous() &&
1935 refresh_row->previous()->par() == refresh_row->par()) {
1936 refresh_row = refresh_row->previous();
1937 refresh_y -= refresh_row->height();
1940 RemoveParagraph(cursor.row());
1942 // set the dimensions of the cursor row
1943 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1945 SetHeightOfRow(bview, cursor.row());
1949 !cursor.par()->Next()->table &&
1951 cursor.par()->Next()->Last()
1952 && cursor.par()->Next()->IsNewline(0))
1953 cursor.par()->Next()->Erase(0);
1955 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1957 UpdateCounters(bview, cursor.row()->previous());
1959 /* This check is necessary. Otherwise the new empty paragraph will
1960 * be deleted automatically. And it is more friendly for the user! */
1962 SetCursor(bview, cursor.par()->Next(), 0);
1964 SetCursor(bview, cursor.par(), 0);
1966 if (cursor.row()->next())
1967 BreakAgain(bview, cursor.row()->next());
1974 void LyXText::OpenFootnote(BufferView * bview)
1976 LyXParagraph * endpar,* tmppar;
1979 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1981 /* if there is no footnote in this paragraph, just return. */
1983 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1986 /* ok, move the cursor right before the footnote */
1988 /* just a little faster than using CursorRight() */
1990 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1991 cursor.pos(cursor.pos() + 1);
1994 /* now the cursor is at the beginning of the physical par */
1995 SetCursor(bview, cursor.par(),
1996 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1998 /* the cursor must be exactly before the footnote */
1999 par = cursor.par()->ParFromPos(cursor.pos());
2001 status = LyXText::NEED_MORE_REFRESH;
2002 refresh_row = cursor.row();
2003 refresh_y = cursor.y() - cursor.row()->baseline();
2005 tmppar = cursor.par();
2006 endpar = cursor.par()->Next();
2009 tmppar->OpenFootnote(cursor.pos());
2010 RemoveParagraph(row);
2011 /* set the dimensions of the cursor row */
2012 row->fill(Fill(bview, row, workWidth(bview)));
2013 SetHeightOfRow(bview, row);
2014 // CHECK See comment on top of text.C
2015 tmppar = tmppar->Next();
2017 while (tmppar != endpar) {
2019 InsertParagraph(bview, tmppar, row);
2020 while (row->next() && row->next()->par() == tmppar)
2022 tmppar = tmppar->Next();
2025 SetCursor(bview, par->next, 0);
2026 sel_cursor = cursor;
2032 /* table stuff -- begin*/
2034 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
2036 if (!cursor.par()->table)
2037 return; /* this should never happen */
2039 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2040 SetUndo(bview->buffer(), Undo::FINISH,
2041 cursor.par()->ParFromPos(cursor.pos())->previous,
2042 cursor.par()->ParFromPos(cursor.pos())->next);
2045 case LyXTable::SET_PWIDTH:
2046 cursor.par()->table->SetPWidth(actCell, val);
2048 case LyXTable::SET_SPECIAL_COLUMN:
2049 case LyXTable::SET_SPECIAL_MULTI:
2050 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2055 RedoParagraph(bview);
2059 void LyXText::TableFeatures(BufferView * bview, int feature) const
2062 int setAlign = LYX_ALIGN_LEFT;
2066 if (!cursor.par()->table)
2067 return; /* this should never happen */
2069 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2070 SetUndo(bview->buffer(), Undo::FINISH,
2071 cursor.par()->ParFromPos(cursor.pos())->previous,
2072 cursor.par()->ParFromPos(cursor.pos())->next);
2075 case LyXTable::ALIGN_LEFT:
2076 setAlign= LYX_ALIGN_LEFT;
2078 case LyXTable::ALIGN_RIGHT:
2079 setAlign= LYX_ALIGN_RIGHT;
2081 case LyXTable::ALIGN_CENTER:
2082 setAlign= LYX_ALIGN_CENTER;
2088 case LyXTable::APPEND_ROW: {
2089 LyXParagraph::size_type pos = cursor.pos();
2091 /* move to the next row */
2092 int cell_org = actCell;
2093 int cell = cell_org;
2095 // if there is a ContRow following this row I have to add
2096 // the row after the ContRow's
2097 if ((pos < cursor.par()->Last()) &&
2098 cursor.par()->table->RowHasContRow(cell_org)) {
2099 while((pos < cursor.par()->Last()) &&
2100 !cursor.par()->table->IsContRow(cell)) {
2101 while (pos < cursor.par()->Last() &&
2102 !cursor.par()->IsNewline(pos))
2104 if (pos < cursor.par()->Last())
2108 while((pos < cursor.par()->Last()) &&
2109 cursor.par()->table->IsContRow(cell)) {
2110 while (pos < cursor.par()->Last() &&
2111 !cursor.par()->IsNewline(pos))
2113 if (pos < cursor.par()->Last())
2118 if (pos < cursor.par()->Last())
2121 while (pos < cursor.par()->Last() &&
2122 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2123 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2125 if (pos < cursor.par()->Last())
2130 /* insert the new cells */
2131 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2132 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2133 LyXFont font(LyXFont::ALL_INHERIT,lang);
2134 for (int i = 0; i < number; ++i) {
2135 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2138 /* append the row into the table */
2139 cursor.par()->table->AppendRow(cell_org);
2140 RedoParagraph(bview);
2143 case LyXTable::APPEND_CONT_ROW: {
2144 LyXParagraph::size_type pos = cursor.pos();
2145 /* move to the next row */
2146 int cell_org = actCell;
2147 int cell = cell_org;
2149 // if there is already a controw but not for this cell
2150 // the AppendContRow sets only the right values but does
2151 // not actually add a row
2152 if (cursor.par()->table->RowHasContRow(cell_org) &&
2153 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2154 cursor.par()->table->AppendContRow(cell_org);
2155 RedoParagraph(bview);
2158 while (pos < cursor.par()->Last() &&
2160 || !cursor.par()->table->IsFirstCell(cell))){
2161 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2163 if (pos < cursor.par()->Last())
2168 /* insert the new cells */
2169 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2170 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2171 LyXFont font(LyXFont::ALL_INHERIT,lang);
2172 for (int i = 0; i < number; ++i) {
2173 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2176 /* append the row into the table */
2177 cursor.par()->table->AppendContRow(cell_org);
2178 RedoParagraph(bview);
2181 case LyXTable::APPEND_COLUMN: {
2182 LyXParagraph::size_type pos = 0;
2183 int cell_org = actCell;
2185 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2186 LyXFont font(LyXFont::ALL_INHERIT,lang);
2188 if (pos && (cursor.par()->IsNewline(pos-1))){
2189 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2190 cursor.par()->InsertChar(pos,
2191 LyXParagraph::META_NEWLINE,
2193 if (pos <= cursor.pos())
2194 cursor.pos(cursor.pos() + 1);
2200 } while (pos <= cursor.par()->Last());
2201 /* remember that the very last cell doesn't end with a newline.
2202 This saves one byte memory per table ;-) */
2203 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2204 LyXParagraph::size_type last = cursor.par()->Last();
2205 cursor.par()->InsertChar(last,
2206 LyXParagraph::META_NEWLINE, font);
2209 /* append the column into the table */
2210 cursor.par()->table->AppendColumn(cell_org);
2212 RedoParagraph(bview);
2215 case LyXTable::DELETE_ROW:
2216 if (bview->the_locking_inset)
2217 bview->unlockInset(bview->the_locking_inset);
2218 RemoveTableRow(cursor);
2219 RedoParagraph(bview);
2222 case LyXTable::DELETE_COLUMN: {
2223 LyXParagraph::size_type pos = 0;
2224 int cell_org = actCell;
2226 if (bview->the_locking_inset)
2227 bview->unlockInset(bview->the_locking_inset);
2229 if (!pos || (cursor.par()->IsNewline(pos-1))){
2230 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2232 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2233 cursor.par()->Erase(pos);
2234 if (pos < cursor.par()->Last())
2235 cursor.par()->Erase(pos);
2237 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2238 --pos; // because of pos++ below
2243 } while (pos <= cursor.par()->Last());
2245 /* delete the column from the table */
2246 cursor.par()->table->DeleteColumn(cell_org);
2248 /* set the cursor to the beginning of the table, where else? */
2250 RedoParagraph(bview);
2253 case LyXTable::TOGGLE_LINE_TOP:
2254 lineSet = !cursor.par()->table->TopLine(actCell);
2256 cursor.par()->table->SetTopLine(actCell, lineSet);
2258 LyXParagraph::size_type i;
2260 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2261 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2262 cursor.par()->table->SetTopLine(n, lineSet);
2267 RedoParagraph(bview);
2270 case LyXTable::TOGGLE_LINE_BOTTOM:
2271 lineSet = !cursor.par()->table->BottomLine(actCell);
2273 cursor.par()->table->SetBottomLine(actCell, lineSet);
2275 LyXParagraph::size_type i;
2277 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2278 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2279 cursor.par()->table->SetBottomLine(n, lineSet);
2284 RedoParagraph(bview);
2287 case LyXTable::TOGGLE_LINE_LEFT:
2288 lineSet = !cursor.par()->table->LeftLine(actCell);
2290 cursor.par()->table->SetLeftLine(actCell, lineSet);
2292 LyXParagraph::size_type i;
2294 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2295 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2296 cursor.par()->table->SetLeftLine(n, lineSet);
2301 RedoParagraph(bview);
2304 case LyXTable::TOGGLE_LINE_RIGHT:
2305 lineSet = !cursor.par()->table->RightLine(actCell);
2307 cursor.par()->table->SetRightLine(actCell, lineSet);
2310 LyXParagraph::size_type i = sel_start_cursor.pos();
2311 for (; i <= sel_end_cursor.pos(); ++i) {
2312 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2313 cursor.par()->table->SetRightLine(n, lineSet);
2318 RedoParagraph(bview);
2321 case LyXTable::ALIGN_LEFT:
2322 case LyXTable::ALIGN_RIGHT:
2323 case LyXTable::ALIGN_CENTER:
2325 cursor.par()->table->SetAlignment(actCell, setAlign);
2328 LyXParagraph::size_type i = sel_start_cursor.pos();
2329 for (; i <= sel_end_cursor.pos(); ++i) {
2330 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2331 cursor.par()->table->SetAlignment(n, setAlign);
2336 RedoParagraph(bview);
2339 case LyXTable::DELETE_TABLE:
2340 SetCursorIntern(bview, cursor.par(), 0);
2341 delete cursor.par()->table;
2342 cursor.par()->table = 0;
2343 // temporary: Should put table in simple_cut_buffer (with before and after
2344 // dummy-paragraph !!
2345 // not necessar anymore with UNDO :)
2346 for (LyXParagraph::size_type i =
2347 cursor.par()->size() - 1; i >= 0; --i)
2348 cursor.par()->Erase(i);
2349 RedoParagraph(bview);
2352 case LyXTable::MULTICOLUMN: {
2354 // check wether we are completly in a multicol
2355 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2356 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2357 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2358 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2362 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2363 LyXParagraph::size_type pos = cursor.pos();
2364 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2366 for (; newlines; --newlines)
2367 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2368 RedoParagraph(bview);
2372 // selection must be in one row (or no selection)
2374 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2377 RedoParagraph(bview);
2381 if (sel_start_cursor.row() == sel_end_cursor.row()){
2382 LyXParagraph::size_type i;
2384 for (i = sel_start_cursor.pos();
2385 i < sel_end_cursor.pos(); ++i){
2386 if (sel_start_cursor.par()->IsNewline(i)){
2387 sel_start_cursor.par()->Erase(i);
2388 // check for double-blanks
2389 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2391 (i < sel_start_cursor.par()->Last()
2392 && !sel_start_cursor.par()->IsLineSeparator(i)))
2393 sel_start_cursor.par()->InsertChar(i, ' ');
2395 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2401 cursor.par()->table->
2402 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2403 sel_start_cursor.pos()),
2405 cursor.pos(sel_start_cursor.pos());
2406 RedoParagraph(bview);
2410 WriteAlert(_("Impossible Operation!"),
2411 _("Multicolumns can only be horizontally."),
2418 case LyXTable::SET_ALL_LINES:
2420 case LyXTable::UNSET_ALL_LINES:
2422 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2426 LyXParagraph::size_type i;
2428 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2429 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2430 cursor.par()->table->SetAllLines(n, setLines);
2435 RedoParagraph(bview);
2437 case LyXTable::SET_LONGTABLE:
2438 cursor.par()->table->SetLongTable(true);
2440 case LyXTable::UNSET_LONGTABLE:
2441 cursor.par()->table->SetLongTable(false);
2443 case LyXTable::SET_ROTATE_TABLE:
2444 cursor.par()->table->SetRotateTable(true);
2446 case LyXTable::UNSET_ROTATE_TABLE:
2447 cursor.par()->table->SetRotateTable(false);
2449 case LyXTable::SET_ROTATE_CELL:
2451 cursor.par()->table->SetRotateCell(actCell, true);
2453 LyXParagraph::size_type i;
2455 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2456 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2457 cursor.par()->table->SetRotateCell(n, true);
2463 case LyXTable::UNSET_ROTATE_CELL:
2465 cursor.par()->table->SetRotateCell(actCell, false);
2468 LyXParagraph::size_type i = sel_start_cursor.pos();
2469 for (; i <= sel_end_cursor.pos(); ++i) {
2470 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2471 cursor.par()->table->SetRotateCell(n, false);
2477 case LyXTable::SET_LINEBREAKS:
2478 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2480 cursor.par()->table->SetLinebreaks(actCell, what);
2482 LyXParagraph::size_type i;
2484 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2485 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2486 cursor.par()->table->SetLinebreaks(n, what);
2492 case LyXTable::SET_LTFIRSTHEAD:
2493 cursor.par()->table->SetLTHead(actCell, true);
2495 case LyXTable::SET_LTHEAD:
2496 cursor.par()->table->SetLTHead(actCell, false);
2498 case LyXTable::SET_LTFOOT:
2499 cursor.par()->table->SetLTFoot(actCell, false);
2501 case LyXTable::SET_LTLASTFOOT:
2502 cursor.par()->table->SetLTFoot(actCell, true);
2504 case LyXTable::SET_LTNEWPAGE:
2505 what = !cursor.par()->table->LTNewPage(actCell);
2506 cursor.par()->table->SetLTNewPage(actCell, what);
2512 void LyXText::InsertCharInTable(BufferView * bview, char c)
2517 bool jumped_over_space;
2519 /* first check, if there will be two blanks together or a blank at
2520 * the beginning of a paragraph.
2521 * I decided to handle blanks like normal characters, the main
2522 * difference are the special checks when calculating the row.fill
2523 * (blank does not count at the end of a row) and the check here */
2525 LyXFont realtmpfont = real_current_font;
2526 LyXFont rawtmpfont = current_font; /* store the current font.
2527 * This is because of the use
2528 * of cursor movements. The moving
2529 * cursor would refresh the
2532 // Get the font that is used to calculate the baselineskip
2533 LyXParagraph::size_type const lastpos =
2534 cursor.par()->Last();
2535 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2538 jumped_over_space = false;
2539 if (IsLineSeparatorChar(c)) {
2540 if ((cursor.pos() > 0 &&
2541 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2542 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2543 || (cursor.pos() == 0
2545 && !(cursor.par()->Previous()
2546 && cursor.par()->Previous()->footnoteflag
2547 == LyXParagraph::OPEN_FOOTNOTE)
2551 } else if (IsNewlineChar(c)) {
2552 if (!IsEmptyTableCell()) {
2553 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2560 y = cursor.y() - row->baseline();
2561 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2562 * already inserted the character */
2563 cursor.par()->InsertChar(cursor.pos(), c);
2564 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2566 if (!jumped_over_space) {
2567 /* refresh the positions */
2569 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2570 tmprow = tmprow->next();
2571 tmprow->pos(tmprow->pos() + 1);
2575 cursor.pos(cursor.pos() + 1);
2577 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2579 current_font = rawtmpfont;
2580 real_current_font = realtmpfont;
2582 /* check, whether the last character's font has changed. */
2583 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2584 && rawparfont != rawtmpfont)
2585 RedoHeightOfParagraph(bview, cursor);
2589 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2590 LyXParagraph::size_type pos)
2593 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2594 par->GetInset(pos) && par->GetInset(pos)->display()){
2595 par->GetInset(pos)->display(false);
2599 Row * row = GetRow(par, pos, y);
2601 int tmpheight = row->height();
2602 SetHeightOfRow(bview, row);
2604 LyXParagraph::size_type tmp_pos = pos;
2605 /* update the table information */
2606 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2608 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2609 WidthOfCell(bview, par, tmp_pos))) {
2610 LyXCursor tmpcursor = cursor;
2611 SetCursorIntern(bview, par, pos, false);
2612 /* make a complete redraw */
2613 RedoDrawingOfParagraph(bview, cursor);
2617 /* redraw only the row */
2618 LyXCursor tmpcursor = cursor;
2619 SetCursorIntern(bview, par, pos);
2620 //CHECK See comment on top of text.C
2622 refresh_x = cursor.x();
2624 refresh_pos = cursor.pos();
2627 if (tmpheight == row->height())
2628 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2630 status = LyXText::NEED_MORE_REFRESH;
2632 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2637 void LyXText::BackspaceInTable(BufferView * bview)
2639 Row * tmprow, * row;
2642 LyXFont rawtmpfont = current_font;
2643 LyXFont realtmpfont = real_current_font;
2645 // Get the font that is used to calculate the baselineskip
2646 int const lastpos = cursor.par()->Last();
2647 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2650 if (cursor.pos() == 0) {
2651 /* no pasting of table paragraphs */
2655 /* this is the code for a normal backspace, not pasting
2657 SetUndo(bview->buffer(), Undo::DELETE,
2658 cursor.par()->ParFromPos(cursor.pos())->previous,
2659 cursor.par()->ParFromPos(cursor.pos())->next);
2661 CursorLeftIntern(bview);
2663 /* some insets are undeletable here */
2664 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2665 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2670 y = cursor.y() - row->baseline();
2672 /* some special code when deleting a newline. */
2673 if (cursor.par()->IsNewline(cursor.pos())) {
2677 cursor.par()->Erase(cursor.pos());
2679 /* refresh the positions */
2681 while (tmprow->next()
2682 && tmprow->next()->par() == row->par()) {
2683 tmprow = tmprow->next();
2684 tmprow->pos(tmprow->pos() - 1);
2688 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2690 /* check, wether the last characters font has changed. */
2691 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2692 && rawparfont != rawtmpfont)
2693 RedoHeightOfParagraph(bview, cursor);
2695 /* restore the current font
2696 * That is what a user expects! */
2697 current_font = rawtmpfont;
2698 real_current_font = realtmpfont;
2700 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2702 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2703 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2706 /* table stuff -- end*/
2710 // Just a macro to make some thing easier.
2711 void LyXText::RedoParagraph(BufferView * bview) const
2714 RedoParagraphs(bview, cursor, cursor.par()->Next());
2715 SetCursorIntern(bview, cursor.par(), cursor.pos());
2719 /* insert a character, moves all the following breaks in the
2720 * same Paragraph one to the right and make a rebreak */
2721 void LyXText::InsertChar(BufferView * bview, char c)
2723 SetUndo(bview->buffer(), Undo::INSERT,
2725 cursor.par()->ParFromPos(cursor.pos())->previous,
2726 cursor.par()->ParFromPos(cursor.pos())->next
2728 cursor.par()->previous,
2733 // When the free-spacing option is set for the current layout,
2734 // disable the double-space checking
2737 textclasslist.Style(bview->buffer()->params.textclass,
2738 cursor.row()->par()->GetLayout()).free_spacing;
2741 /* table stuff -- begin*/
2742 if (cursor.par()->table) {
2743 InsertCharInTable(bview, c);
2747 /* table stuff -- end*/
2749 /* First check, if there will be two blanks together or a blank at
2750 the beginning of a paragraph.
2751 I decided to handle blanks like normal characters, the main
2752 difference are the special checks when calculating the row.fill
2753 (blank does not count at the end of a row) and the check here */
2755 // The bug is triggered when we type in a description environment:
2756 // The current_font is not changed when we go from label to main text
2757 // and it should (along with realtmpfont) when we type the space.
2758 // CHECK There is a bug here! (Asger)
2760 LyXFont realtmpfont = real_current_font;
2761 LyXFont rawtmpfont = current_font; /* store the current font.
2762 * This is because of the use
2763 * of cursor movements. The moving
2764 * cursor would refresh the
2767 // Get the font that is used to calculate the baselineskip
2768 LyXParagraph::size_type lastpos = cursor.par()->Last();
2769 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2772 bool jumped_over_space = false;
2774 if (!freeSpacing && IsLineSeparatorChar(c)) {
2775 if ((cursor.pos() > 0
2776 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2777 || (cursor.pos() > 0
2778 && cursor.par()->IsNewline(cursor.pos() - 1))
2779 || (cursor.pos() == 0
2781 && !(cursor.par()->Previous()
2782 && cursor.par()->Previous()->footnoteflag
2783 == LyXParagraph::OPEN_FOOTNOTE)
2786 if (cursor.pos() == 0 )
2787 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2789 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2793 } else if (IsNewlineChar(c)) {
2795 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2797 if (cursor.par() == cursor.par()
2799 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2803 /* No newline at first position
2804 * of a paragraph or behind labels.
2805 * TeX does not allow that. */
2807 if (cursor.pos() < cursor.par()->Last() &&
2808 cursor.par()->IsLineSeparator(cursor.pos()))
2809 // newline always after a blank!
2810 CursorRightIntern(bview);
2811 cursor.row()->fill(-1); // to force a new break
2814 // the display inset stuff
2815 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2816 && cursor.row()->par()->GetInset(cursor.row()->pos())
2817 && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
2818 cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
2819 cursor.row()->fill(-1); // to force a new break
2821 // get the cursor row fist
2822 Row * row = cursor.row();
2823 long y = cursor.y() - row->baseline();
2824 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2825 * already insertet the character */
2826 cursor.par()->InsertChar(cursor.pos(), c);
2827 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2829 if (!jumped_over_space) {
2830 // refresh the positions
2832 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2833 tmprow = tmprow->next();
2834 tmprow->pos(tmprow->pos() + 1);
2838 // Is there a break one row above
2839 if ((cursor.par()->IsLineSeparator(cursor.pos())
2840 || cursor.par()->IsNewline(cursor.pos())
2841 || cursor.row()->fill() == -1)
2842 && row->previous() && row->previous()->par() == row->par()) {
2843 LyXParagraph::size_type z = NextBreakPoint(bview,
2846 if ( z >= row->pos()) {
2849 // set the dimensions of the row above
2850 row->previous()->fill(Fill(bview,
2854 SetHeightOfRow(bview, row->previous());
2856 y -= row->previous()->height();
2858 refresh_row = row->previous();
2859 status = LyXText::NEED_MORE_REFRESH;
2861 BreakAgainOneRow(bview, row);
2863 current_font = rawtmpfont;
2864 real_current_font = realtmpfont;
2865 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2866 false, cursor.boundary());
2867 // cursor MUST be in row now.
2869 if (row->next() && row->next()->par() == row->par())
2870 need_break_row = row->next();
2874 // check, wether the last characters font has changed.
2875 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2876 && rawparfont != rawtmpfont)
2877 RedoHeightOfParagraph(bview, cursor);
2884 // recalculate the fill of the row
2885 if (row->fill() >= 0) /* needed because a newline
2886 * will set fill to -1. Otherwise
2887 * we would not get a rebreak! */
2888 row->fill(Fill(bview, row, workWidth(bview)));
2889 if (row->fill() < 0 ) {
2892 refresh_x = cursor.x();
2893 refresh_pos = cursor.pos();
2894 status = LyXText::NEED_MORE_REFRESH;
2895 BreakAgainOneRow(bview, row);
2896 // will the cursor be in another row now?
2897 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2898 if (row->next() && row->next()->par() == row->par())
2899 // this should always be true
2901 BreakAgainOneRow(bview, row);
2903 current_font = rawtmpfont;
2904 real_current_font = realtmpfont;
2906 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2908 if (row->next() && row->next()->par() == row->par())
2909 need_break_row = row->next();
2914 refresh_x = cursor.x();
2916 refresh_pos = cursor.pos();
2918 int tmpheight = row->height();
2919 SetHeightOfRow(bview, row);
2920 if (tmpheight == row->height())
2921 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2923 status = LyXText::NEED_MORE_REFRESH;
2925 current_font = rawtmpfont;
2926 real_current_font = realtmpfont;
2927 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2931 // check, wether the last characters font has changed.
2932 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2933 && rawparfont != rawtmpfont) {
2934 RedoHeightOfParagraph(bview, cursor);
2936 // now the special right address boxes
2937 if (textclasslist.Style(bview->buffer()->params.textclass,
2938 cursor.par()->GetLayout()).margintype
2939 == MARGIN_RIGHT_ADDRESS_BOX) {
2940 RedoDrawingOfParagraph(bview, cursor);
2948 void LyXText::charInserted()
2950 // Here we could call FinishUndo for every 20 characters inserted.
2951 // This is from my experience how emacs does it.
2952 static unsigned int counter = 0;
2962 void LyXText::PrepareToPrint(BufferView * bview,
2963 Row * row, float & x,
2964 float & fill_separator,
2966 float & fill_label_hfill,
2971 float w = row->fill();
2973 fill_label_hfill = 0;
2975 fill_label_hfill = 0;
2977 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2981 x = RightMargin(bview->buffer(), row);
2982 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2983 LyXFont font(LyXFont::ALL_SANE);
2984 font.setSize(LyXFont::SIZE_SMALL);
2985 x += lyxfont::width("Mwide-figM", font);
2989 if (workWidth(bview) > 0)
2990 x = LeftMargin(bview, row);
2994 // is there a manual margin with a manual label
2995 if (textclasslist.Style(bview->buffer()->params.textclass,
2996 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2997 && textclasslist.Style(bview->buffer()->params.textclass,
2998 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
3000 /* one more since labels are left aligned */
3001 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
3002 if (nlh && !row->par()->GetLabelWidthString().empty()) {
3003 fill_label_hfill = LabelFill(bview, row) / nlh;
3007 // are there any hfills in the row?
3008 float nh = NumberOfHfills(bview->buffer(), row);
3011 /* table stuff -- begin*/
3012 if (row->par()->table) {
3013 w = workWidth(bview) - row->par()->table->WidthOfTable()
3014 - x - RightMargin(bview->buffer(), row);
3015 nh = 0; /* ignore hfills in tables */
3017 /* table stuff -- end*/
3022 // is it block, flushleft or flushright?
3023 // set x how you need it
3026 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
3027 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
3029 align = row->par()->FirstPhysicalPar()->align;
3031 if (row->par()->align == LYX_ALIGN_LAYOUT)
3032 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
3034 align = row->par()->align;
3037 // center displayed insets
3038 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
3039 && row->par()->GetInset(row->pos())
3040 && row->par()->GetInset(row->pos())->display())
3041 align = LYX_ALIGN_CENTER;
3044 case LYX_ALIGN_BLOCK:
3045 ns = NumberOfSeparators(bview->buffer(), row);
3046 if (ns && row->next() && row->next()->par() == row->par() &&
3047 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
3048 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
3049 && row->next()->par()->GetInset(row->next()->pos())
3050 && row->next()->par()->GetInset(row->next()->pos())->display())
3052 fill_separator = w / ns;
3056 case LYX_ALIGN_RIGHT:
3059 case LYX_ALIGN_CENTER:
3067 ComputeBidiTables(bview->buffer(), row);
3069 LyXParagraph::size_type main_body =
3070 BeginningOfMainBody(bview->buffer(), row->par());
3071 LyXParagraph::size_type last = RowLast(row);
3073 if (main_body > 0 &&
3074 (main_body-1 > last ||
3075 !row->par()->IsLineSeparator(main_body-1))) {
3076 LyXLayout const & layout =
3077 textclasslist.Style(bview->buffer()->params.textclass,
3078 row->par()->GetLayout());
3079 x += lyxfont::width(layout.labelsep,
3080 GetFont(bview->buffer(), row->par(), -2));
3081 if (main_body-1 <= last)
3082 x += fill_label_hfill;
3087 /* important for the screen */
3090 /* the cursor set functions have a special mechanism. When they
3091 * realize, that you left an empty paragraph, they will delete it.
3092 * They also delete the corresponding row */
3094 void LyXText::CursorRightOneWord(BufferView * bview) const
3096 // treat floats, HFills and Insets as words
3097 LyXCursor tmpcursor = cursor;
3098 // CHECK See comment on top of text.C
3100 if (tmpcursor.pos() == tmpcursor.par()->Last()
3101 && tmpcursor.par()->Next()) {
3102 tmpcursor.par(tmpcursor.par()->Next());
3107 // Skip through initial nonword stuff.
3108 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3109 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3111 // printf("Current pos1 %d", tmpcursor.pos()) ;
3112 tmpcursor.pos(tmpcursor.pos() + 1);
3115 // Advance through word.
3116 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3117 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3119 // printf("Current pos2 %d", tmpcursor.pos()) ;
3120 tmpcursor.pos(tmpcursor.pos() + 1);
3124 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3128 void LyXText::CursorTab(BufferView * bview) const
3131 if (cursor.par()->table) {
3132 int cell = NumberOfCell(cursor.par(), cursor.pos());
3133 while(cursor.par()->table->IsContRow(cell)) {
3135 cell = NumberOfCell(cursor.par(), cursor.pos());
3137 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3138 TableFeatures(bview, LyXTable::APPEND_ROW);
3141 LyXCursor tmpcursor = cursor;
3142 while (tmpcursor.pos() < tmpcursor.par()->Last()
3143 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3144 tmpcursor.pos(tmpcursor.pos() + 1);
3146 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3147 if (tmpcursor.par()->Next()) {
3148 tmpcursor.par(tmpcursor.par()->Next());
3152 tmpcursor.pos(tmpcursor.pos() + 1);
3153 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3155 if (cursor.par()->table) {
3156 int cell = NumberOfCell(cursor.par(), cursor.pos());
3157 while (cursor.par()->table->IsContRow(cell) &&
3158 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3160 while (tmpcursor.pos() < tmpcursor.par()->Last()
3161 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3162 tmpcursor.pos(tmpcursor.pos() + 1);
3164 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3165 if (tmpcursor.par()->Next()) {
3166 tmpcursor.par(tmpcursor.par()->Next());
3170 tmpcursor.pos(tmpcursor.pos() + 1);
3171 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3172 cell = NumberOfCell(cursor.par(), cursor.pos());
3179 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3180 of prior word, not to end of next prior word. */
3182 void LyXText::CursorLeftOneWord(BufferView * bview) const
3184 // treat HFills, floats and Insets as words
3185 LyXCursor tmpcursor = cursor;
3186 while (tmpcursor.pos()
3187 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3188 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3189 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3191 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3193 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3194 tmpcursor.pos(tmpcursor.pos() - 1);
3197 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3199 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3201 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3202 tmpcursor.pos(tmpcursor.pos() - 1);
3203 } else if (!tmpcursor.pos()) {
3204 if (tmpcursor.par()->Previous()){
3205 tmpcursor.par(tmpcursor.par()->Previous());
3206 tmpcursor.pos(tmpcursor.par()->Last());
3208 } else { // Here, tmpcursor != 0
3209 while (tmpcursor.pos() > 0 &&
3210 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3211 tmpcursor.pos(tmpcursor.pos() - 1);
3213 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3216 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3219 void LyXText::SelectWord(BufferView * bview)
3221 // Move cursor to the beginning, when not already there.
3223 && !cursor.par()->IsSeparator(cursor.pos()-1)
3224 && !cursor.par()->IsKomma(cursor.pos()-1) )
3225 CursorLeftOneWord(bview);
3227 // set the sel cursor
3228 sel_cursor = cursor;
3230 while ( cursor.pos() < cursor.par()->Last()
3231 && !cursor.par()->IsSeparator(cursor.pos())
3232 && !cursor.par()->IsKomma(cursor.pos()) )
3233 cursor.pos(cursor.pos() + 1);
3234 SetCursor(bview, cursor.par(), cursor.pos() );
3236 // finally set the selection
3241 /* -------> Select the word currently under the cursor when:
3242 1: no selection is currently set,
3243 2: the cursor is not at the borders of the word. */
3245 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3248 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3249 && !cursor.par()->IsSeparator(cursor.pos())
3250 && !cursor.par()->IsKomma(cursor.pos())
3251 && !cursor.par()->IsSeparator(cursor.pos() -1)
3252 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3260 // This function is only used by the spellchecker for NextWord().
3261 // It doesn't handle LYX_ACCENTs and probably never will.
3262 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3264 LyXParagraph * tmppar = cursor.par();
3266 // If this is not the very first word, skip rest of
3267 // current word because we are probably in the middle
3268 // of a word if there is text here.
3269 if (cursor.pos() || cursor.par()->previous) {
3270 while (cursor.pos() < cursor.par()->Last()
3271 && cursor.par()->IsLetter(cursor.pos()))
3272 cursor.pos(cursor.pos() + 1);
3274 // Now, skip until we have real text (will jump paragraphs)
3275 while ((cursor.par()->Last() > cursor.pos()
3276 && (!cursor.par()->IsLetter(cursor.pos())
3277 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3278 .latex() == LyXFont::ON))
3279 || (cursor.par()->Last() == cursor.pos()
3280 && cursor.par()->Next())){
3281 if (cursor.pos() == cursor.par()->Last()) {
3282 cursor.par(cursor.par()->Next());
3285 cursor.pos(cursor.pos() + 1);
3288 // Update the value if we changed paragraphs
3289 if (cursor.par() != tmppar){
3290 SetCursor(bview, cursor.par(), cursor.pos());
3291 value = float(cursor.y())/float(height);
3294 // Start the selection from here
3295 sel_cursor = cursor;
3298 std::ostringstream latex;
3302 // and find the end of the word
3303 // (optional hyphens are part of a word)
3304 while (cursor.pos() < cursor.par()->Last()
3305 && (cursor.par()->IsLetter(cursor.pos()))
3306 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3307 && cursor.par()->GetInset(cursor.pos()) != 0
3308 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3310 && latex.str() == "\\-"
3312 && latex.str() // protect against null pointers
3313 && string(latex.str(), 3) == "\\-" // this is not nice at all
3316 cursor.pos(cursor.pos() + 1);
3318 #ifndef HAVE_SSTREAM
3319 delete [] latex.str();
3321 // Finally, we copy the word to a string and return it
3324 if (sel_cursor.pos() < cursor.pos()) {
3325 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3326 LyXParagraph::size_type i, j;
3327 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3328 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3329 str[j++] = cursor.par()->GetChar(i);
3337 // This one is also only for the spellchecker
3338 void LyXText::SelectSelectedWord(BufferView * bview)
3340 // move cursor to the beginning
3341 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3343 // set the sel cursor
3344 sel_cursor = cursor;
3347 std::ostringstream latex;
3352 // now find the end of the word
3353 while (cursor.pos() < cursor.par()->Last()
3354 && (cursor.par()->IsLetter(cursor.pos())
3355 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3356 && cursor.par()->GetInset(cursor.pos()) != 0
3357 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3359 && latex.str() == "\\-"
3361 && string(latex.str(), 3) == "\\-"
3364 cursor.pos(cursor.pos() + 1);
3366 #ifndef HAVE_SSTREAM
3367 delete [] latex.str();
3369 SetCursor(bview, cursor.par(), cursor.pos());
3371 // finally set the selection
3376 /* -------> Delete from cursor up to the end of the current or next word. */
3377 void LyXText::DeleteWordForward(BufferView * bview)
3379 if (!cursor.par()->Last())
3382 LyXCursor tmpcursor = cursor;
3383 tmpcursor.row(0); //Â ??
3384 selection = true; // to avoid deletion
3385 CursorRightOneWord(bview);
3386 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3387 sel_cursor = cursor;
3391 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3392 CutSelection(bview);
3397 /* -------> Delete from cursor to start of current or prior word. */
3398 void LyXText::DeleteWordBackward(BufferView * bview)
3400 if (!cursor.par()->Last())
3403 LyXCursor tmpcursor = cursor;
3404 tmpcursor.row(0); // ??
3405 selection = true; // to avoid deletion
3406 CursorLeftOneWord(bview);
3407 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3408 sel_cursor = cursor;
3411 CutSelection(bview);
3416 /* -------> Kill to end of line. */
3417 void LyXText::DeleteLineForward(BufferView * bview)
3419 if (!cursor.par()->Last())
3420 // Paragraph is empty, so we just go to the right
3423 LyXCursor tmpcursor = cursor;
3424 // We can't store the row over a regular SetCursor
3425 // so we set it to 0 and reset it afterwards.
3426 tmpcursor.row(0); //Â ??
3427 selection = true; // to avoid deletion
3429 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3430 sel_cursor = cursor;
3433 // What is this test for ??? (JMarc)
3435 DeleteWordForward(bview);
3437 CutSelection(bview);
3443 // Change the case of a word at cursor position.
3444 // This function directly manipulates LyXParagraph::text because there
3445 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3446 // that it is correct. I guess part of it should be moved to
3447 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3448 // it does not access outside of the allocated array as the older
3449 // version did. (JMarc)
3450 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3453 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3455 LyXParagraph * tmppar = cursor.par();
3458 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3461 LyXParagraph::size_type tmppos =
3462 cursor.par()->PositionInParFromPos(cursor.pos());
3464 LyXParagraph::size_type tmppos = cursor.pos();
3466 while (tmppos < tmppar->size()) {
3467 unsigned char c = tmppar->GetChar(tmppos);
3468 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3470 if (c != LyXParagraph::META_INSET) {
3472 case text_lowercase:
3475 case text_capitalization:
3477 action = text_lowercase;
3479 case text_uppercase:
3485 //tmppar->text[tmppos] = c;
3486 tmppar->SetChar(tmppos, c);
3489 CheckParagraph(bview, tmppar, tmppos);
3490 CursorRightOneWord(bview);
3494 void LyXText::Delete(BufferView * bview)
3496 // this is a very easy implementation
3498 LyXCursor old_cursor = cursor;
3499 int old_cur_par_id = old_cursor.par()->id();
3500 int old_cur_par_prev_id = old_cursor.par()->previous ?
3501 old_cursor.par()->previous->id() : 0;
3503 // just move to the right
3504 CursorRightIntern(bview);
3506 // CHECK Look at the comment here.
3507 // This check is not very good...
3508 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3509 // and that can very well delete the par or par->previous in
3510 // old_cursor. Will a solution where we compare paragraph id's
3512 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3513 == old_cur_par_prev_id
3514 && cursor.par()->id() != old_cur_par_id)
3515 return; // delete-empty-paragraph-mechanism has done it
3517 // if you had success make a backspace
3518 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3519 LyXCursor tmpcursor = cursor;
3520 cursor = old_cursor; // to make sure undo gets the right cursor position
3521 SetUndo(bview->buffer(), Undo::DELETE,
3523 cursor.par()->ParFromPos(cursor.pos())->previous,
3524 cursor.par()->ParFromPos(cursor.pos())->next
3526 cursor.par()->previous,
3536 void LyXText::Backspace(BufferView * bview)
3539 /* table stuff -- begin */
3540 if (cursor.par()->table) {
3541 BackspaceInTable(bview);
3544 /* table stuff -- end */
3546 // LyXFont rawtmpfont = current_font;
3547 // LyXFont realtmpfont = real_current_font;
3548 // We don't need the above variables as calling to SetCursor() with third
3549 // argument eqaul to false, will not change current_font & real_current_font
3551 // Get the font that is used to calculate the baselineskip
3552 LyXParagraph::size_type lastpos = cursor.par()->Last();
3553 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3556 if (cursor.pos() == 0) {
3557 // The cursor is at the beginning of a paragraph, so the the backspace
3558 // will collapse two paragraphs into one.
3560 // we may paste some paragraphs
3562 // is it an empty paragraph?
3565 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3567 && !(cursor.par()->Next()
3568 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3569 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
3572 // This is an empty paragraph and we delete it just by moving the cursor one step
3573 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3574 // of the paragraph.
3576 if (cursor.par()->previous) {
3578 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3580 LyXParagraph * tmppar = cursor.par()->previous;
3582 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3584 && cursor.par()->footnoteflag == tmppar->footnoteflag
3586 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3587 // Inherit botom DTD from the paragraph below.
3588 // (the one we are deleting)
3589 tmppar->line_bottom = cursor.par()->line_bottom;
3590 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3591 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3594 CursorLeftIntern(bview);
3596 // the layout things can change the height of a row !
3597 int tmpheight = cursor.row()->height();
3598 SetHeightOfRow(bview, cursor.row());
3599 if (cursor.row()->height() != tmpheight) {
3600 refresh_y = cursor.y() - cursor.row()->baseline();
3601 refresh_row = cursor.row();
3602 status = LyXText::NEED_MORE_REFRESH;
3609 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3610 SetUndo(bview->buffer(), Undo::DELETE,
3611 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3612 cursor.par()->ParFromPos(cursor.pos())->next);
3615 if (cursor.par()->previous) {
3616 SetUndo(bview->buffer(), Undo::DELETE,
3617 cursor.par()->previous->previous,
3618 cursor.par()->next);
3622 LyXParagraph * tmppar = cursor.par();
3623 Row * tmprow = cursor.row();
3625 // We used to do CursorLeftIntern() here, but it is
3626 // not a good idea since it triggers the auto-delete
3627 // mechanism. So we do a CursorLeftIntern()-lite,
3628 // without the dreaded mechanism. (JMarc)
3629 if (cursor.par()->Previous()) {
3630 // steps into the above paragraph.
3631 SetCursorIntern(bview, cursor.par()->Previous(),
3632 cursor.par()->Previous()->Last(), false);
3635 /* Pasting is not allowed, if the paragraphs have different
3636 layout. I think it is a real bug of all other
3637 word processors to allow it. It confuses the user.
3638 Even so with a footnote paragraph and a non-footnote
3639 paragraph. I will not allow pasting in this case,
3640 because the user would be confused if the footnote behaves
3641 different wether it is open or closed.
3643 Correction: Pasting is always allowed with standard-layout
3645 if (cursor.par() != tmppar
3646 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3647 || tmppar->GetLayout() == 0 /*standard*/)
3649 && cursor.par()->footnoteflag == tmppar->footnoteflag
3652 /* table stuff -- begin*/
3653 && !cursor.par()->table /* no pasting of tables */
3654 /* table stuff -- end*/
3656 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3658 RemoveParagraph(tmprow);
3660 cursor.par()->PasteParagraph(bview->buffer()->params);
3662 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3663 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3664 // strangely enough it seems that commenting out the line above removes
3665 // most or all of the segfaults. I will however also try to move the
3666 // two Remove... lines in front of the PasteParagraph too.
3669 cursor.pos(cursor.pos() - 1);
3671 status = LyXText::NEED_MORE_REFRESH;
3672 refresh_row = cursor.row();
3673 refresh_y = cursor.y() - cursor.row()->baseline();
3675 // remove the lost paragraph
3676 // This one is not safe, since the paragraph that the tmprow and the
3677 // following rows belong to has been deleted by the PasteParagraph
3678 // above. The question is... could this be moved in front of the
3680 //RemoveParagraph(tmprow);
3681 //RemoveRow(tmprow);
3683 // This rebuilds the rows.
3684 AppendParagraph(bview, cursor.row());
3685 UpdateCounters(bview, cursor.row());
3687 // the row may have changed, block, hfills etc.
3688 SetCursor(bview, cursor.par(), cursor.pos(), false);
3691 /* this is the code for a normal backspace, not pasting
3693 SetUndo(bview->buffer(), Undo::DELETE,
3695 cursor.par()->ParFromPos(cursor.pos())->previous,
3696 cursor.par()->ParFromPos(cursor.pos())->next
3698 cursor.par()->previous,
3702 // We used to do CursorLeftIntern() here, but it is
3703 // not a good idea since it triggers the auto-delete
3704 // mechanism. So we do a CursorLeftIntern()-lite,
3705 // without the dreaded mechanism. (JMarc)
3706 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3707 false, cursor.boundary());
3709 // some insets are undeletable here
3710 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3711 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3713 // force complete redo when erasing display insets
3714 // this is a cruel method but safe..... Matthias
3715 if (cursor.par()->GetInset(cursor.pos())->display() ||
3716 cursor.par()->GetInset(cursor.pos())->needFullRow()) {
3717 cursor.par()->Erase(cursor.pos());
3718 RedoParagraph(bview);
3723 Row * row = cursor.row();
3724 long y = cursor.y() - row->baseline();
3725 LyXParagraph::size_type z;
3726 /* remember that a space at the end of a row doesnt count
3727 * when calculating the fill */
3728 if (cursor.pos() < RowLast(row) ||
3729 !cursor.par()->IsLineSeparator(cursor.pos())) {
3730 row->fill(row->fill() + SingleWidth(bview,
3735 /* some special code when deleting a newline. This is similar
3736 * to the behavior when pasting paragraphs */
3737 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3738 cursor.par()->Erase(cursor.pos());
3739 // refresh the positions
3741 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3742 tmprow = tmprow->next();
3743 tmprow->pos(tmprow->pos() - 1);
3745 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3746 cursor.pos(cursor.pos() - 1);
3748 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3749 cursor.par()->InsertChar(cursor.pos(), ' ');
3750 // refresh the positions
3752 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3753 tmprow = tmprow->next();
3754 tmprow->pos(tmprow->pos() + 1);
3758 cursor.par()->Erase(cursor.pos());
3760 // refresh the positions
3762 while (tmprow->next()
3763 && tmprow->next()->par() == row->par()) {
3764 tmprow = tmprow->next();
3765 tmprow->pos(tmprow->pos() - 1);
3768 // delete newlines at the beginning of paragraphs
3769 while (cursor.par()->Last() &&
3770 cursor.par()->IsNewline(cursor.pos()) &&
3771 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3773 cursor.par()->Erase(cursor.pos());
3774 // refresh the positions
3776 while (tmprow->next() &&
3777 tmprow->next()->par() == row->par()) {
3778 tmprow = tmprow->next();
3779 tmprow->pos(tmprow->pos() - 1);
3784 // is there a break one row above
3785 if (row->previous() && row->previous()->par() == row->par()) {
3786 z = NextBreakPoint(bview, row->previous(),
3788 if ( z >= row->pos()) {
3791 Row * tmprow = row->previous();
3793 // maybe the current row is now empty
3794 if (row->pos() >= row->par()->Last()) {
3799 BreakAgainOneRow(bview, row);
3800 if (row->next() && row->next()->par() == row->par())
3801 need_break_row = row->next();
3806 // set the dimensions of the row above
3807 y -= tmprow->height();
3808 tmprow->fill(Fill(bview, tmprow,
3810 SetHeightOfRow(bview, tmprow);
3813 refresh_row = tmprow;
3814 status = LyXText::NEED_MORE_REFRESH;
3815 SetCursor(bview, cursor.par(), cursor.pos(),
3816 false, cursor.boundary());
3817 //current_font = rawtmpfont;
3818 //real_current_font = realtmpfont;
3819 // check, whether the last character's font has changed.
3821 cursor.par()->GetFontSettings(bview->buffer()->params,
3822 cursor.par()->Last() - 1))
3823 RedoHeightOfParagraph(bview, cursor);
3828 // break the cursor row again
3829 if (row->next() && row->next()->par() == row->par() &&
3830 (RowLast(row) == row->par()->Last() - 1 ||
3831 NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
3833 /* it can happen that a paragraph loses one row
3834 * without a real breakup. This is when a word
3835 * is to long to be broken. Well, I don t care this
3837 if (RowLast(row) == row->par()->Last() - 1)
3838 RemoveRow(row->next());
3842 status = LyXText::NEED_MORE_REFRESH;
3844 BreakAgainOneRow(bview, row);
3845 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3846 // cursor MUST be in row now
3848 need_break_row = row->next();
3850 // set the dimensions of the row
3851 row->fill(Fill(bview, row, workWidth(bview)));
3852 int tmpheight = row->height();
3853 SetHeightOfRow(bview, row);
3854 if (tmpheight == row->height())
3855 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3857 status = LyXText::NEED_MORE_REFRESH;
3860 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3864 // current_font = rawtmpfont;
3865 // real_current_font = realtmpfont;
3867 lastpos = cursor.par()->Last();
3868 if (cursor.pos() == lastpos) {
3869 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3870 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3871 SetCurrentFont(bview);
3874 // check, wether the last characters font has changed.
3876 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3877 RedoHeightOfParagraph(bview, cursor);
3879 // now the special right address boxes
3880 if (textclasslist.Style(bview->buffer()->params.textclass,
3881 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3882 RedoDrawingOfParagraph(bview, cursor);
3888 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3889 Row * row_ptr, long y, bool cleared)
3891 /* returns a printed row */
3892 Painter & pain = bview->painter();
3894 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3895 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3897 LyXParagraph::size_type vpos, pos;
3899 int y_top, y_bottom;
3900 float fill_separator, fill_hfill, fill_label_hfill;
3902 LyXFont font(LyXFont::ALL_SANE);
3904 if (row_ptr->height() <= 0) {
3905 lyxerr << "LYX_ERROR: row.height: "
3906 << row_ptr->height() << endl;
3909 PrepareToPrint(bview, row_ptr, x, fill_separator,
3910 fill_hfill, fill_label_hfill);
3912 if (inset_owner && (x < 0))
3916 // clear the area where we want to paint/print
3918 ww = bview->workWidth();
3920 bool clear_area = true;
3923 if ((last == row_ptr->pos()) &&
3924 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3925 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3927 clear_area = inset->doClearArea();
3929 if (cleared) { // we don't need to clear it's already done!!!
3931 } else if (clear_area) {
3934 w = inset_owner->width(bview, font);
3937 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3938 } else if (inset != 0) {
3939 int h = row_ptr->baseline() - inset->ascent(bview, font);
3943 w = inset_owner->width(bview, font);
3946 pain.fillRectangle(x_offset, y_offset, w, h);
3948 h += inset->ascent(bview, font) + inset->descent(bview, font);
3949 if ((row_ptr->height() - h) > 0) {
3952 w = inset_owner->width(bview, font);
3955 pain.fillRectangle(x_offset,h, w, row_ptr->height()-h);
3957 if (!inset_owner && !inset->display() && !inset->needFullRow())
3959 int w = inset->width(bview, font) + int(x);
3960 pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
3967 w = inset_owner->width(bview, font);
3970 /* selection code */
3971 if (bidi_same_direction) {
3972 if (sel_start_cursor.row() == row_ptr &&
3973 sel_end_cursor.row() == row_ptr) {
3974 if (sel_start_cursor.x() < sel_end_cursor.x())
3975 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3977 sel_end_cursor.x() - sel_start_cursor.x(),
3981 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3983 sel_start_cursor.x() - sel_end_cursor.x(),
3986 } else if (sel_start_cursor.row() == row_ptr) {
3988 pain.fillRectangle(x_offset, y_offset,
3989 sel_start_cursor.x(),
3993 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3995 w - sel_start_cursor.x(),
3998 } else if (sel_end_cursor.row() == row_ptr) {
4000 pain.fillRectangle(x_offset + sel_end_cursor.x(),
4002 w - sel_end_cursor.x(),
4006 pain.fillRectangle(x_offset, y_offset,
4010 } else if (y > long(sel_start_cursor.y())
4011 && y < long(sel_end_cursor.y())) {
4012 pain.fillRectangle(x_offset, y_offset, w,
4016 } else if ( sel_start_cursor.row() != row_ptr &&
4017 sel_end_cursor.row() != row_ptr &&
4018 y > long(sel_start_cursor.y())
4019 && y < long(sel_end_cursor.y())) {
4020 pain.fillRectangle(x_offset, y_offset, w,
4023 } else if (sel_start_cursor.row() == row_ptr ||
4024 sel_end_cursor.row() == row_ptr) {
4028 if (row_ptr->par()->table) {
4029 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4030 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4033 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
4034 (sel_end_cursor.row() != row_ptr && is_rtl))
4035 pain.fillRectangle(x_offset, y_offset,
4040 if (row_ptr->par()->table) {
4042 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
4043 pos = vis2log(vpos);
4044 float old_tmpx = tmpx;
4045 if (row_ptr->par()->IsNewline(pos)) {
4046 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4049 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4051 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4053 if ( (sel_start_cursor.row() != row_ptr ||
4054 sel_start_cursor.pos() <= pos) &&
4055 (sel_end_cursor.row() != row_ptr ||
4056 pos < sel_end_cursor.pos()) )
4057 pain.fillRectangle(x_offset + int(old_tmpx),
4059 int(tmpx - old_tmpx + 1),
4065 LyXParagraph::size_type main_body =
4066 BeginningOfMainBody(bview->buffer(),
4069 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
4070 pos = vis2log(vpos);
4071 float old_tmpx = tmpx;
4072 if (main_body > 0 && pos == main_body-1) {
4073 tmpx += fill_label_hfill +
4074 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
4075 row_ptr->par()->GetLayout()).labelsep,
4076 GetFont(bview->buffer(),row_ptr->par(), -2));
4077 if (row_ptr->par()->IsLineSeparator(main_body-1))
4078 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
4080 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
4081 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4082 if (pos >= main_body)
4085 tmpx += fill_label_hfill;
4087 else if (row_ptr->par()->IsSeparator(pos)) {
4088 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4089 if (pos >= main_body)
4090 tmpx += fill_separator;
4092 tmpx += SingleWidth(bview, row_ptr->par(), pos);
4094 if ( (sel_start_cursor.row() != row_ptr ||
4095 sel_start_cursor.pos() <= pos) &&
4096 (sel_end_cursor.row() != row_ptr ||
4097 pos < sel_end_cursor.pos()) )
4098 pain.fillRectangle(x_offset + int(old_tmpx),
4100 int(tmpx - old_tmpx + 1),
4107 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
4108 (sel_end_cursor.row() != row_ptr && !is_rtl) )
4109 pain.fillRectangle(x_offset + int(tmpx),
4119 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4120 LyXFont font(LyXFont::ALL_SANE);
4121 font.setSize(LyXFont::SIZE_FOOTNOTE);
4122 font.setColor(LColor::footnote);
4124 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
4125 if (row_ptr->previous() &&
4126 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4128 switch (row_ptr->par()->footnotekind) {
4129 case LyXParagraph::MARGIN:
4132 case LyXParagraph::FIG:
4135 case LyXParagraph::TAB:
4138 case LyXParagraph::WIDE_FIG:
4141 case LyXParagraph::WIDE_TAB:
4144 case LyXParagraph::ALGORITHM:
4147 case LyXParagraph::FOOTNOTE:
4152 pain.fillRectangle(LYX_PAPER_MARGIN,
4154 box_x - LYX_PAPER_MARGIN,
4155 int(lyxfont::maxAscent(font)
4156 + lyxfont::maxDescent(font)),
4157 LColor::footnotebg);
4159 pain.line(LYX_PAPER_MARGIN, y_offset,
4160 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4161 LColor::footnoteframe);
4163 pain.text(LYX_PAPER_MARGIN,
4164 y_offset + int(lyxfont::maxAscent(font)) + 1,
4167 pain.line(LYX_PAPER_MARGIN, y_offset,
4169 y_offset + int(lyxfont::maxAscent(font)
4170 + lyxfont::maxDescent(font)),
4171 LColor::footnoteframe);
4173 pain.line(LYX_PAPER_MARGIN,
4174 y_offset + int(lyxfont::maxAscent(font)
4175 + lyxfont::maxDescent(font)) + 1,
4177 y_offset + int(lyxfont::maxAscent(font)
4178 + lyxfont::maxDescent(font)) + 1,
4179 LColor::footnoteframe);
4183 /* draw the open floats in a red box */
4184 pain.line(box_x, y_offset,
4185 box_x, y_offset + row_ptr->height(),
4186 LColor::footnoteframe);
4188 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4190 workWidth(bview) - LYX_PAPER_MARGIN,
4191 y_offset + row_ptr->height(),
4192 LColor::footnoteframe);
4195 // Draw appendix lines
4196 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4198 pain.line(1, y_offset,
4199 1, y_offset + row_ptr->height(),
4200 LColor::appendixline);
4201 pain.line(workWidth(bview) - 2, y_offset,
4202 workWidth(bview) - 2,
4203 y_offset + row_ptr->height(),
4204 LColor::appendixline);
4207 // Draw minipage line
4208 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4210 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4212 y_offset + row_ptr->height() - 1,
4213 LColor::minipageline);
4216 int depth = p->GetDepth();
4217 for (int i = 1; i <= depth; ++i) {
4218 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4219 pain.line(line_x, y_offset, line_x,
4220 y_offset + row_ptr->height() - 1,
4223 } else if (row_ptr->previous() &&
4224 row_ptr->previous()->par()->footnoteflag
4225 == LyXParagraph::OPEN_FOOTNOTE) {
4226 LyXFont font(LyXFont::ALL_SANE);
4227 font.setSize(LyXFont::SIZE_FOOTNOTE);
4229 int box_x = LYX_PAPER_MARGIN;
4230 box_x += lyxfont::width(" wide-tab ", font);
4232 pain.line(box_x, y_offset,
4233 workWidth(bview) - LYX_PAPER_MARGIN,
4234 y_offset, LColor::footnote);
4237 // Draw appendix lines
4239 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4241 LyXParagraph * firstpar = row_ptr->par();
4243 if (firstpar->appendix){
4244 pain.line(1, y_offset,
4245 1, y_offset + row_ptr->height(),
4246 LColor::appendixline);
4247 pain.line(ww - 2, y_offset,
4248 ww - 2, y_offset + row_ptr->height(),
4249 LColor::appendixline);
4252 // Draw minipage line
4253 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4255 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4256 LYX_PAPER_MARGIN/5 + box_x,
4257 y_offset + row_ptr->height() - 1,
4258 LColor::minipageline);
4261 int depth = firstpar->GetDepth();
4265 if (row_ptr->next())
4267 if (row_ptr->par()->footnoteflag ==
4268 row_ptr->next()->par()->footnoteflag)
4269 next_depth = row_ptr->next()->par()->GetDepth();
4270 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4273 next_depth = row_ptr->next()->par()->GetDepth();
4275 if (row_ptr->previous())
4277 if (row_ptr->par()->footnoteflag ==
4278 row_ptr->previous()->par()->footnoteflag)
4279 prev_depth = row_ptr->previous()->par()->GetDepth();
4280 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4283 prev_depth = row_ptr->previous()->par()->GetDepth();
4286 for (int i = 1; i <= depth; ++i) {
4287 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4288 pain.line(line_x, y_offset, line_x,
4289 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4293 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4296 pain.fillRectangle(line_x,
4297 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4298 LYX_PAPER_MARGIN / 5, 2,
4304 LyXLayout const & layout =
4305 textclasslist.Style(bview->buffer()->params.textclass,
4306 row_ptr->par()->GetLayout());
4309 y_bottom = row_ptr->height();
4311 /* is it a first row? */
4312 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4314 /* start of appendix? */
4315 if (row_ptr->par()->start_of_appendix){
4316 pain.line(1, y_offset,
4318 LColor::appendixline);
4321 /* think about the margins */
4322 if (!row_ptr->previous() && bv_owner)
4323 y_top += LYX_PAPER_MARGIN;
4325 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4327 pb_font.setColor(LColor::pagebreak).decSize();
4328 int w = 0, a = 0, d = 0;
4329 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4331 y_offset + y_top + 2 * DefaultHeight(),
4333 Painter::line_onoffdash)
4336 _("Page Break (top)"),
4339 LColor::background, false, w, a, d);
4340 pain.rectText((ww - w)/2,
4341 y_offset + y_top + 2 * DefaultHeight() + d,
4342 _("Page Break (top)"),
4345 LColor::background);
4346 y_top += 3 * DefaultHeight();
4349 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4350 /* draw a vfill top */
4351 pain.line(0, y_offset + 2 + y_top,
4352 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4355 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4357 y_offset + y_top + 3 * DefaultHeight(),
4360 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4361 LYX_PAPER_MARGIN / 2,
4362 y_offset + y_top + 3 * DefaultHeight(),
4365 y_top += 3 * DefaultHeight();
4368 /* think about user added space */
4369 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4371 /* think about the parskip */
4372 /* some parskips VERY EASY IMPLEMENTATION */
4373 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4374 if (layout.latextype == LATEX_PARAGRAPH
4375 && firstpar->GetDepth() == 0
4376 && firstpar->Previous())
4377 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4378 else if (firstpar->Previous()
4379 && textclasslist.Style(bview->buffer()->params.textclass,
4380 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4381 && firstpar->Previous()->GetDepth() == 0)
4382 // is it right to use defskip here, too? (AS)
4383 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4386 if (row_ptr->par()->line_top) { /* draw a top line */
4387 y_top += lyxfont::ascent('x',
4388 GetFont(bview->buffer(),
4389 row_ptr->par(), 0));
4391 pain.line(0, y_offset + y_top,
4392 ww, y_offset + y_top,
4394 Painter::line_solid,
4395 Painter::line_thick);
4397 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4398 row_ptr->par(), 0));
4401 /* should we print a label? */
4402 if (layout.labeltype >= LABEL_STATIC
4403 && (layout.labeltype != LABEL_STATIC
4404 || layout.latextype != LATEX_ENVIRONMENT
4405 || row_ptr->par()->IsFirstInSequence())) {
4406 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4407 if (!row_ptr->par()->GetLabelstring().empty()) {
4409 string tmpstring = row_ptr->par()->GetLabelstring();
4411 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4412 if (bview->buffer()->params.secnumdepth >= 0) {
4413 /* this is special code for the chapter layout. This is printed in
4414 * an extra row and has a pagebreak at the top. */
4415 float spacing_val = 1.0;
4416 if (!row_ptr->par()->spacing.isDefault()) {
4417 spacing_val = row_ptr->par()->spacing.getValue();
4419 spacing_val = bview->buffer()->params.spacing.getValue();
4422 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4423 + int(layout.parsep) * DefaultHeight();
4425 tmpx = ww - LeftMargin(bview, row_ptr) -
4426 lyxfont::width(tmpstring, font);
4427 pain.text(int(tmpx),
4428 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4433 tmpx = ww - LeftMargin(bview, row_ptr)
4434 + lyxfont::width(layout.labelsep, font);
4436 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4437 LyXFont font(LyXFont::ALL_SANE);
4438 font.setSize(LyXFont::SIZE_SMALL);
4439 tmpx += lyxfont::width("Mwide-fixM", font);
4443 tmpx = x - lyxfont::width(layout.labelsep, font)
4444 - lyxfont::width(tmpstring, font);
4447 pain.text(int(tmpx),
4448 y_offset + row_ptr->baseline(),
4452 /* the labels at the top of an environment. More or less for bibliography */
4453 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4454 layout.labeltype == LABEL_BIBLIO ||
4455 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4456 if (row_ptr->par()->IsFirstInSequence()) {
4457 font = GetFont(bview->buffer(),
4458 row_ptr->par(), -2);
4459 if (!row_ptr->par()->GetLabelstring().empty()) {
4460 string tmpstring = row_ptr->par()->GetLabelstring();
4461 float spacing_val = 1.0;
4462 if (!row_ptr->par()->spacing.isDefault()) {
4463 spacing_val = row_ptr->par()->spacing.getValue();
4465 spacing_val = bview->buffer()->params.spacing.getValue();
4468 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4469 + (layout.labelbottomsep * DefaultHeight()));
4472 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4473 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4474 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4475 tmpx -= lyxfont::width(tmpstring, font) / 2;
4477 tmpx = ww - LeftMargin(bview, row_ptr) -
4478 lyxfont::width(tmpstring, font);
4479 pain.text(int(tmpx),
4480 y_offset + row_ptr->baseline()
4481 - row_ptr->ascent_of_text()
4487 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4488 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4490 tmpx = ww - LeftMargin(bview, row_ptr)
4491 + lyxfont::width(layout.labelsep, font);
4493 tmpx = x - lyxfont::width(layout.labelsep, font)
4494 - row_ptr->par()->bibkey->width(bview, font);
4495 row_ptr->par()->bibkey->draw(bview, font,
4496 y_offset + row_ptr->baseline(),
4501 /* is it a last row? */
4503 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4505 LyXParagraph * par = row_ptr->par();
4509 (row_ptr->par()->ParFromPos(last + 1) == par)
4511 (row_ptr->par() == par)
4513 && (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4515 /* think about the margins */
4516 if (!row_ptr->next() && bv_owner)
4517 y_bottom -= LYX_PAPER_MARGIN;
4519 /* draw a bottom pagebreak */
4520 if (firstpar->pagebreak_bottom) {
4522 pb_font.setColor(LColor::pagebreak).decSize();
4523 int w = 0, a = 0, d = 0;
4525 y_offset + y_bottom - 2 * DefaultHeight(),
4527 y_offset + y_bottom - 2 * DefaultHeight(),
4529 Painter::line_onoffdash)
4532 _("Page Break (bottom)"),
4535 LColor::background, false, w, a, d);
4536 pain.rectText((ww - w) / 2,
4537 y_offset + y_top + 2 * DefaultHeight() + d,
4538 _("Page Break (bottom)"),
4541 LColor::background);
4542 y_bottom -= 3 * DefaultHeight();
4545 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4546 /* draw a vfill bottom */
4547 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4549 y_offset + y_bottom - 3 * DefaultHeight(),
4551 pain.line(0, y_offset + y_bottom - 2,
4553 y_offset + y_bottom - 2,
4555 pain.line(LYX_PAPER_MARGIN / 2,
4556 y_offset + y_bottom - 3 * DefaultHeight(),
4557 LYX_PAPER_MARGIN / 2,
4558 y_offset + y_bottom - 2,
4560 y_bottom -= 3 * DefaultHeight();
4563 /* think about user added space */
4564 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4566 if (firstpar->line_bottom) {
4567 /* draw a bottom line */
4568 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4569 par, par->Last() - 1));
4570 pain.line(0, y_offset + y_bottom,
4571 ww, y_offset + y_bottom,
4572 LColor::topline, Painter::line_solid,
4573 Painter::line_thick);
4574 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4575 par, par->Last() - 1));
4579 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4582 case END_LABEL_FILLED_BOX:
4584 LyXFont font = GetFont(bview->buffer(),
4585 row_ptr->par(), last);
4586 int size = int(0.75 * lyxfont::maxAscent(font));
4587 int y = (y_offset + row_ptr->baseline()) - size;
4588 int x = is_rtl ? LYX_PAPER_MARGIN
4589 : ww - LYX_PAPER_MARGIN - size;
4591 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4593 LyXFont font(LyXFont::ALL_SANE);
4594 font.setSize(LyXFont::SIZE_SMALL);
4595 x += lyxfont::width("Mwide-figM", font);
4597 x -= LYX_PAPER_MARGIN/2;
4599 if (row_ptr->fill() <= size)
4600 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4601 if (endlabel == END_LABEL_BOX) {
4602 pain.line(x, y, x, y + size,
4604 pain.line(x + size, y, x + size , y + size,
4606 pain.line(x, y, x + size, y,
4608 pain.line(x, y + size, x + size, y + size,
4611 pain.fillRectangle(x, y, size, size,
4615 case END_LABEL_STATIC:
4617 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4618 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4619 layout).endlabelstring();
4620 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4621 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4622 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4623 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4626 case END_LABEL_NO_LABEL:
4631 /* draw the text in the pixmap */
4633 vpos = row_ptr->pos();
4635 /* table stuff -- begin*/
4636 if (row_ptr->par()->table) {
4638 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4640 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4642 while (vpos <= last) {
4643 pos = vis2log(vpos);
4644 if (row_ptr->par()->IsNewline(pos)) {
4646 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4647 /* draw the table lines, still very simple */
4648 on_off = !row_ptr->par()->table->TopLine(cell);
4650 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4651 !row_ptr->par()->table->IsContRow(cell))
4652 pain.line(int(x_old),
4653 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4655 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4657 on_off ? Painter::line_onoffdash : Painter::line_solid);
4659 on_off = !row_ptr->par()->table->BottomLine(cell);
4660 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4661 row_ptr->par()->table->VeryLastRow(cell))
4663 pain.line(int(x_old),
4664 y_offset + y_bottom - 1,
4666 y_offset + y_bottom - 1,
4668 on_off ? Painter::line_onoffdash : Painter::line_solid);
4670 on_off = !row_ptr->par()->table->LeftLine(cell);
4672 pain.line(int(x_old),
4673 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4675 y_offset + y_bottom - 1,
4677 on_off ? Painter::line_onoffdash : Painter::line_solid);
4679 on_off = !row_ptr->par()->table->RightLine(cell);
4681 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4682 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4683 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4684 y_offset + y_bottom - 1,
4686 on_off ? Painter::line_onoffdash : Painter::line_solid);
4689 /* take care about the alignment and other spaces */
4691 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4692 if (row_ptr->par()->table->IsFirstCell(cell))
4693 --cell; // little hack, sorry
4695 } else if (row_ptr->par()->IsHfill(pos)) {
4699 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4701 y_offset + row_ptr->baseline(),
4706 } else if (row_ptr->par()->IsSeparator(pos)) {
4708 x+= SingleWidth(bview,
4709 row_ptr->par(), pos);
4712 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4715 /* do not forget the very last cell. This has no NEWLINE so
4716 * ignored by the code above*/
4717 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4718 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4719 on_off = !row_ptr->par()->table->TopLine(cell);
4721 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4722 !row_ptr->par()->table->IsContRow(cell))
4724 pain.line(int(x_old),
4725 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4727 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4729 on_off ? Painter::line_onoffdash : Painter::line_solid);
4730 on_off = !row_ptr->par()->table->BottomLine(cell);
4731 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4732 row_ptr->par()->table->VeryLastRow(cell))
4734 pain.line(int(x_old),
4735 y_offset + y_bottom - 1,
4737 y_offset + y_bottom - 1,
4739 on_off ? Painter::line_onoffdash : Painter::line_solid);
4741 on_off = !row_ptr->par()->table->LeftLine(cell);
4743 pain.line(int(x_old),
4744 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4746 y_offset + y_bottom - 1,
4748 on_off ? Painter::line_onoffdash : Painter::line_solid);
4750 on_off = !row_ptr->par()->table->RightLine(cell);
4752 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4753 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4754 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4755 y_offset + y_bottom - 1,
4757 on_off ? Painter::line_onoffdash : Painter::line_solid);
4760 /* table stuff -- end*/
4762 LyXParagraph::size_type main_body =
4763 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4764 if (main_body > 0 &&
4765 (main_body-1 > last ||
4766 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4769 while (vpos <= last) {
4770 pos = vis2log(vpos);
4771 if (main_body > 0 && pos == main_body - 1) {
4772 x += fill_label_hfill
4773 + lyxfont::width(layout.labelsep,
4774 GetFont(bview->buffer(),
4775 row_ptr->par(), -2))
4776 - SingleWidth(bview,
4781 if (row_ptr->par() ->IsHfill(pos)) {
4784 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4786 y_offset + row_ptr->baseline(),
4789 if (HfillExpansion(bview->buffer(),
4791 if (pos >= main_body) {
4793 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4794 int(x + fill_hfill),
4795 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4797 Painter::line_onoffdash);
4801 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4802 int(x + fill_label_hfill),
4803 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4805 Painter::line_onoffdash);
4807 x += fill_label_hfill;
4810 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4812 y_offset + row_ptr->baseline(),
4817 } else if (row_ptr->par()->IsSeparator(pos)) {
4818 x += SingleWidth(bview,
4819 row_ptr->par(), pos);
4820 if (pos >= main_body)
4821 x += fill_separator;
4824 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4832 int LyXText::DefaultHeight() const
4834 LyXFont font(LyXFont::ALL_SANE);
4835 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4839 /* returns the column near the specified x-coordinate of the row
4840 * x is set to the real beginning of this column */
4841 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4842 bool & boundary) const
4845 float fill_separator, fill_hfill, fill_label_hfill;
4847 PrepareToPrint(bview, row, tmpx, fill_separator,
4848 fill_hfill, fill_label_hfill);
4850 LyXParagraph::size_type vc = row->pos();
4851 LyXParagraph::size_type last = RowLastPrintable(row);
4852 LyXParagraph::size_type c = 0;
4853 LyXLayout const & layout =
4854 textclasslist.Style(bview->buffer()->params.textclass,
4855 row->par()->GetLayout());
4856 bool left_side = false;
4859 /* table stuff -- begin */
4860 if (row->par()->table) {
4861 //the last row doesn't need a newline at the end
4862 if (row->next() && row->next()->par() == row->par()
4863 && row->par()->IsNewline(last))
4865 int cell = NumberOfCell(row->par(), row->pos());
4866 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4867 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4868 float last_tmpx = tmpx;
4869 while (vc <= last && tmpx <= x) {
4872 if (row->par()->IsNewline(c)) {
4875 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4876 cell_x += row->par()->table->WidthOfColumn(cell);
4881 tmpx += SingleWidth(bview, row->par(), c);
4885 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4886 (tmpx + last_tmpx) / 2 > x) {
4891 /* table stuff -- end*/
4893 LyXParagraph::size_type
4894 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4895 float last_tmpx = tmpx;
4897 if (main_body > 0 &&
4898 (main_body-1 > last ||
4899 !row->par()->IsLineSeparator(main_body - 1)))
4902 while (vc <= last && tmpx <= x) {
4905 if (main_body > 0 && c == main_body-1) {
4906 tmpx += fill_label_hfill +
4907 lyxfont::width(layout.labelsep,
4908 GetFont(bview->buffer(), row->par(), -2));
4909 if (row->par()->IsLineSeparator(main_body - 1))
4910 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4913 if (HfillExpansion(bview->buffer(), row, c)) {
4914 x += SingleWidth(bview, row->par(), c);
4918 tmpx += fill_label_hfill;
4920 else if (row->par()->IsSeparator(c)) {
4921 tmpx += SingleWidth(bview, row->par(), c);
4923 tmpx+= fill_separator;
4925 tmpx += SingleWidth(bview, row->par(), c);
4929 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4937 if (vc > last + 1) // This shouldn't happen.
4941 #if 0 // currently unused
4942 bool lastrow = (!row->next() || row->next()->par() != row->par());
4943 bool rtl = (lastrow)
4944 ? row->par()->isRightToLeftPar(bview->buffer()->params)
4948 if (row->pos() > last) // Row is empty?
4950 #warning This is wrong, please have a look Dekel (Jug)
4953 ( (rtl && vc == row->pos()&& x < tmpx - 5) ||
4954 (!rtl && vc == last + 1 && x > tmpx + 5) ))
4957 else if (vc == row->pos()
4959 || (row->par()->table
4960 && vc <= last && row->par()->IsNewline(vc-1))
4964 if (bidi_level(c) % 2 == 1)
4967 c = vis2log(vc - 1);
4968 bool rtl = (bidi_level(c) % 2 == 1);
4969 if (left_side == rtl) {
4971 boundary = IsBoundary(bview->buffer(), row->par(), c);
4977 !row->par()->table &&
4979 row->pos() <= last && c > last
4980 && row->par()->IsNewline(last)) {
4981 if (bidi_level(last) % 2 == 0)
4982 tmpx -= SingleWidth(bview, row->par(), last);
4984 tmpx += SingleWidth(bview, row->par(), last);
4995 /* turn the selection into a new environment. If there is no selection,
4996 * create an empty environment */
4997 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4998 LyXParagraph::footnote_kind kind)
5000 /* no footnoteenvironment in a footnoteenvironment */
5001 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5002 WriteAlert(_("Impossible operation"),
5003 _("You can't insert a float in a float!"),
5007 /* no marginpars in minipages */
5008 if (kind == LyXParagraph::MARGIN
5009 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
5010 WriteAlert(_("Impossible operation"),
5011 _("You can't insert a marginpar in a minipage!"),
5016 /* this doesnt make sense, if there is no selection */
5017 bool dummy_selection = false;
5019 sel_start_cursor = cursor; /* dummy selection */
5020 sel_end_cursor = cursor;
5021 dummy_selection = true;
5024 LyXParagraph * tmppar;
5027 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
5028 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
5032 /* a test to make sure there is not already a footnote
5033 * in the selection. */
5035 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
5037 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
5038 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
5039 tmppar = tmppar->next;
5041 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
5042 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5043 WriteAlert(_("Impossible operation"),
5044 _("Float would include float!"),
5049 /* ok we have a selection. This is always between sel_start_cursor
5050 * and sel_end cursor */
5052 SetUndo(bview->buffer(), Undo::FINISH,
5053 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
5054 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
5056 if (sel_end_cursor.pos() > 0
5057 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
5058 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
5059 /* please break before a space at the end */
5060 if (sel_start_cursor.par() == sel_end_cursor.par()
5061 && sel_start_cursor.pos() > sel_end_cursor.pos())
5062 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
5064 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
5066 sel_end_cursor.par(sel_end_cursor.par()->Next());
5067 sel_end_cursor.pos(0);
5069 // don't forget to insert a dummy layout paragraph if necessary
5070 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
5071 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
5072 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
5073 sel_end_cursor.par(sel_end_cursor.par()->next);
5076 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
5078 cursor = sel_end_cursor;
5080 /* please break behind a space, if there is one. The space should
5082 if (sel_start_cursor.pos() > 0
5083 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
5084 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
5085 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
5086 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
5089 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
5090 sel_start_cursor.pos());
5091 tmppar = sel_start_cursor.par()->Next();
5093 if (dummy_selection) {
5095 if (kind == LyXParagraph::TAB
5096 || kind == LyXParagraph::FIG
5097 || kind == LyXParagraph::WIDE_TAB
5098 || kind == LyXParagraph::WIDE_FIG
5099 || kind == LyXParagraph::ALGORITHM) {
5100 pair<bool, LyXTextClass::size_type> lres =
5101 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
5103 LyXTextClass::size_type lay;
5109 lay = 0; // use default layout "Standard" (0)
5111 tmppar->SetLayout(bview->buffer()->params, lay);
5114 if (sel_start_cursor.pos() > 0) {
5115 /* the footnote-environment should begin with a standard layout.
5116 * Imagine you insert a footnote within an enumeration, you
5117 * certainly do not want an enumerated footnote! */
5120 /* this is a exception the user would sometimes expect, I hope */
5121 sel_start_cursor.par()->Clear();
5125 while (tmppar != sel_end_cursor.par()) {
5126 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
5127 tmppar->footnotekind = kind;
5128 tmppar = tmppar->Next();
5131 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
5133 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
5140 // returns pointer to a specified row
5141 Row * LyXText::GetRow(LyXParagraph * par,
5142 LyXParagraph::size_type pos, long & y) const
5144 Row * tmprow = firstrow;
5147 // find the first row of the specified paragraph
5148 while (tmprow->next() && tmprow->par() != par) {
5149 y += tmprow->height();
5150 tmprow = tmprow->next();
5153 // now find the wanted row
5154 while (tmprow->pos() < pos
5156 && tmprow->next()->par() == par
5157 && tmprow->next()->pos() <= pos) {
5158 y += tmprow->height();
5159 tmprow = tmprow->next();