1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #pragma implementation "table.h"
21 #include "lyxparagraph.h"
23 #include "support/textutils.h"
24 #include "insets/insetbib.h"
25 #include "insets/insettext.h"
26 #include "lyx_gui_misc.h"
28 #include "bufferparams.h"
30 #include "minibuffer.h"
44 static const int LYX_PAPER_MARGIN = 20;
45 extern int bibitemMaxWidth(Painter &, LyXFont const &);
47 static int iso885968x[] = {
48 0xbc, // 0xa8 = fathatan
49 0xbd, // 0xa9 = dammatan
50 0xbe, // 0xaa = kasratan
54 0xde, // 0xae = shadda
57 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
61 0xc2, // 0xc2 = ligature madda
62 0xc3, // 0xc3 = ligature hamza on alef
63 0xc4, // 0xc4 = ligature hamza on waw
64 0xc5, // 0xc5 = ligature hamza under alef
65 0xc0, // 0xc6 = ligature hamza on ya
68 0xc9, // 0xc9 = taa marbuta
87 0,0,0,0,0, // 0xdb- 0xdf
98 0xe9, // 0xe9 = alef maksura
104 bool is_arabic(unsigned char c)
106 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
111 bool is_nikud(unsigned char c)
113 return 192 <= c && c <= 210;
117 int LyXText::workWidth(BufferView * bview) const
120 return inset_owner->textWidth(bview->painter());
122 return bview->workWidth();
125 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
128 (form == FORM_INITIAL || form == FORM_MEDIAL) )
129 return iso885968x[c-0xa8];
135 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
136 LyXParagraph::size_type pos) const
140 return c + (0xb0 - '0');
144 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
145 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
147 return TransformChar(c,FORM_MEDIAL);
149 return TransformChar(c,FORM_INITIAL);
152 return TransformChar(c,FORM_FINAL);
154 return TransformChar(c,FORM_ISOLATED);
157 // This is the comments that some of the warnings below refers to.
158 // There are some issues in this file and I don't think they are
159 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
160 // this is a problem that has been here almost from day one and that a
161 // larger userbase with differenct access patters triggers the bad
162 // behaviour. (segfaults.) What I think happen is: In several places
163 // we store the paragraph in the current cursor and then moves the
164 // cursor. This movement of the cursor will delete paragraph at the
165 // old position if it is now empty. This will make the temporary
166 // pointer to the old cursor paragraph invalid and dangerous to use.
167 // And is some cases this will trigger a segfault. I have marked some
168 // of the cases where this happens with a warning, but I am sure there
169 // are others in this file and in text2.C. There is also a note in
170 // Delete() that you should read. In Delete I store the paragraph->id
171 // instead of a pointer to the paragraph. I am pretty sure this faulty
172 // use of temporary pointers to paragraphs that might have gotten
173 // invalidated (through a cursor movement) before they are used, are
174 // the cause of the strange crashes we get reported often.
176 // It is very tiresom to change this code, especially when it is as
177 // hard to read as it is. Help to fix all the cases where this is done
178 // would be greately appreciated.
182 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
183 LyXParagraph::size_type pos) const
185 char c = par->GetChar(pos);
186 return SingleWidth(bview, par, pos, c);
190 int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
191 LyXParagraph::size_type pos, char c) const
193 LyXFont font = GetFont(bview->buffer(), par, pos);
195 // The most common case is handled first (Asger)
196 if (IsPrintable(c)) {
197 if (font.language()->RightToLeft()) {
198 if (font.language()->lang() == "arabic" &&
199 lyxrc.font_norm == "iso8859-6.8x")
200 c = TransformChar(c, par, pos);
201 else if (font.language()->lang() == "hebrew" &&
205 return lyxfont::width(c, font);
207 } else if (IsHfillChar(c)) {
208 return 3; /* Because of the representation
209 * as vertical lines */
211 } else if (c == LyXParagraph::META_FOOTNOTE ||
212 c == LyXParagraph::META_MARGIN ||
213 c == LyXParagraph::META_FIG ||
214 c == LyXParagraph::META_TAB ||
215 c == LyXParagraph::META_WIDE_FIG ||
216 c == LyXParagraph::META_WIDE_TAB ||
217 c == LyXParagraph::META_ALGORITHM) {
220 case LyXParagraph::META_MARGIN:
223 case LyXParagraph::META_FIG:
226 case LyXParagraph::META_TAB:
229 case LyXParagraph::META_ALGORITHM:
232 case LyXParagraph::META_WIDE_FIG:
235 case LyXParagraph::META_WIDE_TAB:
238 case LyXParagraph::META_FOOTNOTE:
244 return lyxfont::width(fs, font);
246 } else if (c == LyXParagraph::META_INSET) {
247 Inset * tmpinset = par->GetInset(pos);
249 tmpinset->update(bview, font);
250 return tmpinset->width(bview->painter(), font);
254 } else if (IsSeparatorChar(c))
256 else if (IsNewlineChar(c))
258 return lyxfont::width(c, font);
262 // Returns the paragraph position of the last character in the specified row
263 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
265 if (row->next() == 0)
266 return row->par()->Last() - 1;
267 else if (row->next()->par() != row->par())
268 return row->par()->Last() - 1;
270 return row->next()->pos() - 1;
274 LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const
276 LyXParagraph::size_type last = RowLast(row);
277 if (last >= row->pos()
279 && row->next()->par() == row->par()
280 && row->par()->IsSeparator(last))
287 void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
289 bidi_same_direction = true;
290 if (!lyxrc.rtl_support) {
295 bidi_start = row->pos();
296 bidi_end = RowLastPrintable(row);
298 if (bidi_start > bidi_end) {
303 if (bidi_end + 2 - bidi_start >
304 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
305 LyXParagraph::size_type new_size =
306 (bidi_end + 2 - bidi_start < 500) ?
307 500 : 2 * (bidi_end + 2 - bidi_start);
308 log2vis_list.resize(new_size);
309 vis2log_list.resize(new_size);
310 bidi_levels.resize(new_size);
313 vis2log_list[bidi_end + 1 - bidi_start] = -1;
314 log2vis_list[bidi_end + 1 - bidi_start] = -1;
316 LyXParagraph::size_type stack[2];
317 bool rtl_par = row->par()->getParLanguage(buf->params)->RightToLeft();
321 LyXParagraph::size_type main_body = BeginningOfMainBody(buf, row->par());
323 for (LyXParagraph::size_type lpos = bidi_start;
324 lpos <= bidi_end; ++lpos) {
325 bool is_space = row->par()->IsLineSeparator(lpos);
326 LyXParagraph::size_type pos =
327 (is_space && lpos + 1 <= bidi_end &&
328 !row->par()->IsLineSeparator(lpos + 1) &&
330 || !row->par()->IsNewline(lpos + 1)) )
332 LyXFont font = row->par()->GetFontSettings(buf->params, pos);
333 bool new_rtl = font.isVisibleRightToLeft();
334 bool new_rtl0 = font.isRightToLeft();
338 if (row->par()->table && row->par()->IsNewline(lpos)) {
340 new_rtl = new_rtl0 = false;
343 if (lpos == main_body - 1
344 && row->pos() < main_body - 1
345 && row->par()->IsLineSeparator(lpos)) {
346 new_level = (rtl_par) ? 1 : 0;
347 new_rtl = new_rtl0 = rtl_par;
349 new_level = (new_rtl) ? 1 : 2;
351 new_level = (rtl_par) ? 2 : 0;
353 if (is_space && new_level >= level) {
359 int new_level2 = new_level;
361 if (level == new_level && rtl0 != new_rtl0) {
363 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
364 } else if (level < new_level) {
365 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
366 if (new_level > rtl_par)
367 bidi_same_direction = false;
369 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
372 bidi_levels[lpos - bidi_start] = new_level;
374 while (level > new_level2) {
375 LyXParagraph::size_type old_lpos =
377 int delta = lpos - old_lpos - 1;
380 log2vis_list[lpos - bidi_start] += delta;
381 log2vis_list[old_lpos - bidi_start] += delta;
383 while (level < new_level)
384 stack[level++] = lpos;
388 LyXParagraph::size_type old_lpos = stack[--level];
389 int delta = bidi_end - old_lpos;
392 log2vis_list[old_lpos - bidi_start] += delta;
395 LyXParagraph::size_type vpos = bidi_start - 1;
396 for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
397 vpos += log2vis_list[lpos - bidi_start];
398 vis2log_list[vpos - bidi_start] = lpos;
399 log2vis_list[lpos - bidi_start] = vpos;
404 // This method requires a previous call to ComputeBidiTables()
405 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
406 LyXParagraph::size_type pos) const
408 if (!lyxrc.rtl_support)
409 return false; // This is just for speedup
411 if (!bidi_InRange(pos - 1) ||
412 (par->table && par->IsNewline(pos-1)) )
415 bool rtl = bidi_level(pos - 1) % 2;
417 if (pos == par->Last() ||
418 (par->table && par->IsNewline(pos)))
419 rtl2 = par->isRightToLeftPar(buf->params);
420 else if (bidi_InRange(pos))
421 rtl2 = bidi_level(pos) % 2;
426 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
427 LyXParagraph::size_type pos,
428 LyXFont const & font) const
430 if (!lyxrc.rtl_support)
431 return false; // This is just for speedup
433 bool rtl = font.isVisibleRightToLeft();
435 if (pos == par->Last() ||
436 (par->table && par->IsNewline(pos)))
437 rtl2 = par->isRightToLeftPar(buf->params);
438 else if (bidi_InRange(pos))
439 rtl2 = bidi_level(pos) % 2;
444 void LyXText::draw(BufferView * bview, Row const * row,
445 LyXParagraph::size_type & vpos,
446 int offset, float & x, bool cleared)
448 Painter & pain = bview->painter();
450 LyXParagraph::size_type pos = vis2log(vpos);
451 char c = row->par()->GetChar(pos);
454 if (IsNewlineChar(c)) {
456 // Draw end-of-line marker
457 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
458 int wid = lyxfont::width('n', font);
459 int asc = lyxfont::maxAscent(font);
460 int y = offset + row->baseline();
463 if (bidi_level(pos) % 2 == 0) {
464 xp[0] = int(x + wid * 0.375);
465 yp[0] = int(y - 0.875 * asc * 0.75);
468 yp[1] = int(y - 0.500 * asc * 0.75);
470 xp[2] = int(x + wid * 0.375);
471 yp[2] = int(y - 0.125 * asc * 0.75);
473 pain.lines(xp, yp, 3, LColor::eolmarker);
476 yp[0] = int(y - 0.500 * asc * 0.75);
478 xp[1] = int(x + wid);
479 yp[1] = int(y - 0.500 * asc * 0.75);
481 xp[2] = int(x + wid);
482 yp[2] = int(y - asc * 0.75);
484 pain.lines(xp, yp, 3, LColor::eolmarker);
486 xp[0] = int(x + wid * 0.625);
487 yp[0] = int(y - 0.875 * asc * 0.75);
489 xp[1] = int(x + wid);
490 yp[1] = int(y - 0.500 * asc * 0.75);
492 xp[2] = int(x + wid * 0.625);
493 yp[2] = int(y - 0.125 * asc * 0.75);
495 pain.lines(xp, yp, 3, LColor::eolmarker);
497 xp[0] = int(x + wid);
498 yp[0] = int(y - 0.500 * asc * 0.75);
501 yp[1] = int(y - 0.500 * asc * 0.75);
504 yp[2] = int(y - asc * 0.75);
506 pain.lines(xp, yp, 3, LColor::eolmarker);
512 LyXFont font = GetFont(bview->buffer(), row->par(), pos);
513 LyXFont font2 = font;
515 if (c == LyXParagraph::META_FOOTNOTE
516 || c == LyXParagraph::META_MARGIN
517 || c == LyXParagraph::META_FIG
518 || c == LyXParagraph::META_TAB
519 || c == LyXParagraph::META_WIDE_FIG
520 || c == LyXParagraph::META_WIDE_TAB
521 || c == LyXParagraph::META_ALGORITHM) {
524 case LyXParagraph::META_MARGIN:
527 case LyXParagraph::META_FIG:
530 case LyXParagraph::META_TAB:
533 case LyXParagraph::META_ALGORITHM:
536 case LyXParagraph::META_WIDE_FIG:
539 case LyXParagraph::META_WIDE_TAB:
542 case LyXParagraph::META_FOOTNOTE:
549 // calculate the position of the footnotemark
550 int y = (row->baseline() - lyxfont::maxAscent(font2)
551 + lyxfont::maxAscent(font));
553 font.setColor(LColor::footnote);
555 // draw it and set new x position
557 pain.text(int(x), offset + y, fs, font);
558 x += lyxfont::width(fs, font);
559 pain.line(int(tmpx), offset + row->baseline(),
560 int(x), offset + row->baseline(),
567 if (c == LyXParagraph::META_INSET) {
568 Inset const * tmpinset = row->par()->GetInset(pos);
570 tmpinset->draw(bview, font, offset+row->baseline(), x,
575 if (lyxrc.mark_foreign_language &&
576 font.language() != bview->buffer()->params.language_info) {
577 int y = offset + row->height() - 1;
578 pain.line(int(tmpx), y, int(x), y,
585 /* usual characters, no insets */
587 // Collect character that we can draw in one command
589 // This is dirty, but fast. Notice that it will never be too small.
590 // For the record, I'll note that Microsoft Word has a limit
591 // of 768 here. We have none :-) (Asger)
592 // Ok. I am the first to admit that the use of std::string will be
593 // a tiny bit slower than using a POD char array. However, I claim
594 // that this slowdown is so small that it is close to inperceptive.
595 // So IMHO we should go with the easier and clearer implementation.
596 // And even if 1024 is a large number here it might overflow, string
597 // will only overflow if the machine is out of memory...
598 static string textstring;
602 LyXParagraph::size_type last = RowLastPrintable(row);
604 if (font.language()->lang() == "hebrew") {
606 LyXParagraph::size_type vpos2 = vpos;
607 int width = lyxfont::width(c, font2);
609 while (vpos2 <= last &&
610 (pos = vis2log(vpos2)) >= 0
611 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
614 if (static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
616 int width2 = SingleWidth(bview, row->par(), pos, c);
617 dx = (c == 'ø' || c == 'ã')
618 ? width2 - width : (width2 - width) / 2;
621 pain.text(int(x) + dx, offset + row->baseline(),
624 while (vpos <= last &&
625 (pos = vis2log(vpos)) >= 0
626 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
628 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
632 // Draw text and set the new x position
633 pain.text(int(x), offset + row->baseline(),
635 x += lyxfont::width(textstring, font);
637 } else if (font.language()->lang() == "arabic" &&
638 lyxrc.font_norm == "iso8859-6.8x") {
639 textstring = TransformChar(c, row->par(), pos);
640 while (vpos <= last &&
641 (pos = vis2log(vpos)) >= 0
642 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
643 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
644 c = TransformChar(c, row->par(), pos);
648 // Draw text and set the new x position
649 pain.text(int(x), offset + row->baseline(), textstring, font);
650 x += lyxfont::width(textstring, font);
652 while (vpos <= last &&
653 (pos = vis2log(vpos)) >= 0
654 && static_cast<unsigned char>(c = row->par()->GetChar(pos)) > ' '
655 && font2 == GetFont(bview->buffer(), row->par(), pos)) {
659 // Draw text and set the new x position
660 pain.text(int(x), offset + row->baseline(), textstring, font);
661 x += lyxfont::width(textstring, font);
664 // what about underbars?
665 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
666 pain.line(int(tmpx), offset + row->baseline() + 2,
667 int(x), offset + row->baseline() + 2);
669 } else if (lyxrc.mark_foreign_language &&
670 font.language() != bview->buffer()->params.language_info) {
671 int y = offset + row->height() - 1;
672 pain.line(int(tmpx), y, int(x), y,
676 // If we want ulem.sty support, drawing
677 // routines should go here. (Asger)
678 // Why shouldn't LyXFont::drawText handle it internally?
682 // Returns the left beginning of the text.
683 // This information cannot be taken from the layouts-objekt, because in
684 // LaTeX the beginning of the text fits in some cases (for example sections)
685 // exactly the label-width.
686 int LyXText::LeftMargin(BufferView * bview, Row const * row) const
688 LyXLayout const & layout =
689 textclasslist.Style(bview->buffer()->params.textclass,
690 row->par()->GetLayout());
692 string parindent = layout.parindent;
695 /* table stuff -- begin */
696 if (row->par()->table)
698 /* table stuff -- end */
700 int x = LYX_PAPER_MARGIN;
702 x += lyxfont::signedWidth(textclasslist
703 .TextClass(bview->buffer()->params.textclass)
706 .TextClass(bview->buffer()->params.textclass)
709 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
710 LyXFont font(LyXFont::ALL_SANE);
711 font.setSize(LyXFont::SIZE_SMALL);
712 x += lyxfont::width("Mwide-figM", font)
713 + LYX_PAPER_MARGIN/2;
716 // this is the way, LyX handles the LaTeX-Environments.
717 // I have had this idea very late, so it seems to be a
718 // later added hack and this is true
719 if (!row->par()->GetDepth()) {
720 if (!row->par()->GetLayout()) {
721 // find the previous same level paragraph
722 if (row->par()->FirstPhysicalPar()->Previous()) {
723 LyXParagraph * newpar = row->par()
724 ->DepthHook(row->par()->GetDepth());
726 textclasslist.Style(bview->buffer()->params.textclass,
733 // find the next level paragraph
735 LyXParagraph * newpar =
736 row->par()->DepthHook(row->par()->GetDepth()-1);
738 // make a corresponding row. Needed to call LeftMargin()
740 // check wether it is a sufficent paragraph
741 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
743 .Style(bview->buffer()->params.textclass,
744 newpar->GetLayout()).isEnvironment()) {
746 dummyrow.par(newpar);
747 dummyrow.pos(newpar->Last());
748 x = LeftMargin(bview, &dummyrow);
750 // this is no longer an error, because this function
751 // is used to clear impossible depths after changing
752 // a layout. Since there is always a redo,
753 // LeftMargin() is always called
754 row->par()->FirstPhysicalPar()->depth = 0;
757 if (newpar && !row->par()->GetLayout()) {
758 if (newpar->FirstPhysicalPar()->noindent)
761 parindent = textclasslist
762 .Style(bview->buffer()->params.textclass,
763 newpar->GetLayout()).parindent;
768 LyXFont labelfont = GetFont(bview->buffer(), row->par(), -2);
769 switch (layout.margintype) {
771 if (!layout.leftmargin.empty()) {
772 x += lyxfont::signedWidth(layout.leftmargin,
774 .TextClass(bview->buffer()->params.
778 if (!row->par()->GetLabelstring().empty()) {
779 x += lyxfont::signedWidth(layout.labelindent,
781 x += lyxfont::width(row->par()->GetLabelstring(),
783 x += lyxfont::width(layout.labelsep, labelfont);
787 x += lyxfont::signedWidth(layout.labelindent, labelfont);
788 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
789 if (!row->par()->GetLabelWidthString().empty()) {
790 x += lyxfont::width(row->par()->GetLabelWidthString(),
792 x += lyxfont::width(layout.labelsep, labelfont);
797 x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
798 / (row->par()->GetDepth() + 4);
800 case MARGIN_FIRST_DYNAMIC:
801 if (layout.labeltype == LABEL_MANUAL) {
802 if (row->pos() >= BeginningOfMainBody(bview->buffer(), row->par())) {
803 x += lyxfont::signedWidth(layout.leftmargin,
806 x += lyxfont::signedWidth(layout.labelindent,
809 } else if (row->pos()
810 // Special case to fix problems with
812 || (layout.labeltype == LABEL_STATIC
813 && layout.latextype == LATEX_ENVIRONMENT
814 && ! row->par()->IsFirstInSequence())) {
815 x += lyxfont::signedWidth(layout.leftmargin,
817 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
818 && layout.labeltype != LABEL_BIBLIO
819 && layout.labeltype !=
820 LABEL_CENTERED_TOP_ENVIRONMENT) {
821 x += lyxfont::signedWidth(layout.labelindent,
823 x += lyxfont::width(layout.labelsep, labelfont);
824 x += lyxfont::width(row->par()->GetLabelstring(),
829 case MARGIN_RIGHT_ADDRESS_BOX:
831 // ok, a terrible hack. The left margin depends on the widest
832 // row in this paragraph. Do not care about footnotes, they
833 // are *NOT* allowed in the LaTeX realisation of this layout.
835 // find the first row of this paragraph
836 Row const * tmprow = row;
837 while (tmprow->previous()
838 && tmprow->previous()->par() == row->par())
839 tmprow = tmprow->previous();
841 int minfill = tmprow->fill();
842 while (tmprow->next() && tmprow->next()->par() == row->par()) {
843 tmprow = tmprow->next();
844 if (tmprow->fill() < minfill)
845 minfill = tmprow->fill();
848 x += lyxfont::signedWidth(layout.leftmargin,
850 .TextClass(bview->buffer()->params.textclass)
856 if ((workWidth(bview) > 0) &&
857 (row->par()->pextra_type == LyXParagraph::PEXTRA_INDENT))
859 if (!row->par()->pextra_widthp.empty()) {
860 x += workWidth(bview) *
861 atoi(row->par()->pextra_widthp.c_str()) / 100;
862 } else if (!row->par()->pextra_width.empty()) {
863 int xx = VSpace(row->par()->pextra_width).inPixels(bview);
864 if (xx > workWidth(bview))
865 xx = workWidth(bview) * 80 / 100;
867 } else { // should not happen
868 LyXFont font(LyXFont::ALL_SANE);
869 x += lyxfont::width("XXXXXX", font);
873 int align; // wrong type
874 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
875 align = layout.align;
877 align = row->par()->FirstPhysicalPar()->align;
879 // set the correct parindent
880 if (row->pos() == 0) {
881 if ((layout.labeltype == LABEL_NO_LABEL
882 || layout.labeltype == LABEL_TOP_ENVIRONMENT
883 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
884 || (layout.labeltype == LABEL_STATIC
885 && layout.latextype == LATEX_ENVIRONMENT
886 && ! row->par()->IsFirstInSequence()))
887 && row->par() == row->par()->FirstPhysicalPar()
888 && align == LYX_ALIGN_BLOCK
889 && !row->par()->noindent
890 && (row->par()->layout ||
891 bview->buffer()->params.paragraph_separation ==
892 BufferParams::PARSEP_INDENT))
893 x += lyxfont::signedWidth(parindent,
895 .TextClass(bview->buffer()->params
898 else if (layout.labeltype == LABEL_BIBLIO) {
899 // ale970405 Right width for bibitems
900 x += bibitemMaxWidth(bview->painter(),
902 .TextClass(bview->buffer()->params
911 int LyXText::RightMargin(Buffer const * buf, Row const * row) const
913 LyXLayout const & layout =
914 textclasslist.Style(buf->params.textclass,
915 row->par()->GetLayout());
917 int x = LYX_PAPER_MARGIN
918 + lyxfont::signedWidth(textclasslist
919 .TextClass(buf->params.textclass)
922 .TextClass(buf->params.textclass)
926 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
927 x += LYX_PAPER_MARGIN / 2;
930 // this is the way, LyX handles the LaTeX-Environments.
931 // I have had this idea very late, so it seems to be a
932 // later added hack and this is true
933 if (row->par()->GetDepth()) {
934 // find the next level paragraph
936 LyXParagraph * newpar = row->par();
939 newpar = newpar->FirstPhysicalPar()->Previous();
941 newpar = newpar->FirstPhysicalPar();
942 } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
943 && newpar->footnoteflag == row->par()->footnoteflag);
945 // make a corresponding row. Needed to call LeftMargin()
947 // check wether it is a sufficent paragraph
948 if (newpar && newpar->footnoteflag == row->par()->footnoteflag
949 && textclasslist.Style(buf->params.textclass,
953 dummyrow.par(newpar);
955 x = RightMargin(buf, &dummyrow);
957 // this is no longer an error, because this function
958 // is used to clear impossible depths after changing
959 // a layout. Since there is always a redo,
960 // LeftMargin() is always called
961 row->par()->FirstPhysicalPar()->depth = 0;
965 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
966 x += lyxfont::signedWidth(layout.rightmargin, textclasslist
967 .TextClass(buf->params.textclass)
968 .defaultfont()) * 4 / (row->par()->GetDepth()
974 int LyXText::LabelEnd (BufferView * bview, Row const * row) const
976 if (textclasslist.Style(bview->buffer()->params.textclass,
977 row->par()->GetLayout()).margintype
981 tmprow.pos(row->par()->Last());
982 return LeftMargin(bview, &tmprow); /* just the beginning
985 return 0; /* LabelEnd is only needed, if the
986 layout fills a flushleft
992 /* table stuff -- begin*/
993 int LyXText::NumberOfCell(LyXParagraph * par,
994 LyXParagraph::size_type pos) const
997 LyXParagraph::size_type tmp_pos = 0;
998 while (tmp_pos < pos) {
999 if (par->IsNewline(tmp_pos))
1007 int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
1008 LyXParagraph::size_type & pos) const
1011 while (pos < par->Last() && !par->IsNewline(pos)) {
1012 w += SingleWidth(bview, par, pos);
1015 if (par->IsNewline(pos))
1021 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
1024 float fill_separator, fill_hfill, fill_label_hfill;
1025 if (!row->par()->table)
1027 PrepareToPrint(bview, row, tmpx, fill_separator,
1028 fill_hfill, fill_label_hfill, false);
1029 return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
1033 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
1035 Row * row = GetRowNearY(y);
1036 return HitInTable(bview, row, x);
1040 /* table stuff -- end*/
1044 // get the next breakpoint in a given paragraph
1045 LyXParagraph::size_type
1046 LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
1048 LyXParagraph * par = row->par();
1049 LyXParagraph::size_type pos = row->pos();
1054 /* table stuff -- begin*/
1056 while (pos < par->size()
1057 && (!par->IsNewline(pos)
1058 || !par->table->IsFirstCell(NumberOfCell(par, pos + 1)))) {
1059 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1060 par->GetInset(pos) && par->GetInset(pos)->display()){
1061 par->GetInset(pos)->display(false);
1067 /* table stuff -- end*/
1069 // position of the last possible breakpoint
1070 // -1 isn't a suitable value, but a flag
1071 LyXParagraph::size_type last_separator = -1;
1072 width -= RightMargin(bview->buffer(), row);
1074 LyXParagraph::size_type main_body = BeginningOfMainBody(bview->buffer(), par);
1075 LyXLayout const & layout =
1076 textclasslist.Style(bview->buffer()->params.textclass, par->GetLayout());
1077 LyXParagraph::size_type i = pos;
1079 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1080 /* special code for right address boxes, only newlines count */
1081 while (i < par->Last()) {
1082 if (par->IsNewline(i)) {
1084 i = par->Last() - 1; // this means break
1086 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1087 par->GetInset(i) && par->GetInset(i)->display()){
1088 par->GetInset(i)->display(false);
1093 // Last position is an invariant
1094 LyXParagraph::size_type const last =
1096 // this is the usual handling
1097 int x = LeftMargin(bview, row);
1098 while (x < width && i < last) {
1099 char c = par->GetChar(i);
1100 if (IsNewlineChar(c)) {
1102 x = width; // this means break
1103 } else if (c == LyXParagraph::META_INSET &&
1104 par->GetInset(i) && par->GetInset(i)->display()){
1105 // check wether a Display() inset is
1106 // valid here. if not, change it to
1108 if (layout.isCommand()
1109 || (layout.labeltype == LABEL_MANUAL
1110 && i < BeginningOfMainBody(bview->buffer(), par))){
1111 // display istn't allowd
1112 par->GetInset(i)->display(false);
1113 x += SingleWidth(bview, par, i, c);
1115 // inset is display. So break the line here
1119 if (IsLineSeparatorChar(par->GetChar(i+1)))
1122 last_separator = last; // to avoid extra rows
1124 last_separator = i - 1;
1125 x = width; // this means break
1128 if (IsLineSeparatorChar(c))
1130 x += SingleWidth(bview, par, i, c);
1133 if (i == main_body) {
1134 x += lyxfont::width(layout.labelsep,
1135 GetFont(bview->buffer(), par, -2));
1136 if (par->IsLineSeparator(i - 1))
1137 x-= SingleWidth(bview, par, i - 1);
1138 int left_margin = LabelEnd(bview, row);
1139 if (x < left_margin)
1143 // end of paragraph is always a suitable separator
1144 if (i == last && x < width)
1148 // well, if last_separator is still 0, the line isn't breakable.
1149 // don't care and cut simply at the end
1150 if (last_separator < 0) {
1154 // manual labels cannot be broken in LaTeX, do not care
1155 if (main_body && last_separator < main_body)
1156 last_separator = main_body - 1;
1158 return last_separator;
1162 // returns the minimum space a row needs on the screen in pixel
1163 int LyXText::Fill(BufferView * bview, Row * row, int paper_width) const
1165 if (paper_width < 0)
1169 // get the pure distance
1170 LyXParagraph::size_type last = RowLastPrintable(row);
1172 /* table stuff -- begin */
1173 if (row->par()->table) {
1174 // for tables FILL does calculate the widthes of each cell in
1176 LyXParagraph::size_type pos = row->pos();
1177 int cell = NumberOfCell(row->par(), pos);
1180 row->par()->table->SetWidthOfCell(cell,
1185 } while (pos <= last && !row->par()->table->IsFirstCell(cell));
1186 // don't forget the very last table cell without characters
1187 if (cell == row->par()->table->GetNumberOfCells() - 1)
1188 row->par()->table->SetWidthOfCell(cell,
1193 return 0; /* width of table cannot be returned since
1194 * we cannot guarantee its correct value at
1197 /* table stuff -- end*/
1200 // special handling of the right address boxes
1201 if (textclasslist.Style(bview->buffer()->params.textclass,
1202 row->par()->GetLayout()).margintype
1203 == MARGIN_RIGHT_ADDRESS_BOX) {
1204 int tmpfill = row->fill();
1205 row->fill(0); // the minfill in MarginLeft()
1206 w = LeftMargin(bview, row);
1209 w = LeftMargin(bview, row);
1211 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1212 row->par()->GetLayout());
1213 LyXParagraph::size_type main_body =
1214 BeginningOfMainBody(bview->buffer(), row->par());
1215 LyXParagraph::size_type i = row->pos();
1218 if (main_body > 0 && i == main_body) {
1219 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1220 if (row->par()->IsLineSeparator(i - 1))
1221 w -= SingleWidth(bview, row->par(), i - 1);
1222 int left_margin = LabelEnd(bview, row);
1223 if (w < left_margin)
1226 w += SingleWidth(bview, row->par(), i);
1229 if (main_body > 0 && main_body > last) {
1230 w += lyxfont::width(layout.labelsep, GetFont(bview->buffer(), row->par(), -2));
1231 if (last >= 0 && row->par()->IsLineSeparator(last))
1232 w -= SingleWidth(bview, row->par(), last);
1233 int left_margin = LabelEnd(bview, row);
1234 if (w < left_margin)
1238 fill = paper_width - w - RightMargin(bview->buffer(), row);
1243 // returns the minimum space a manual label needs on the screen in pixel
1244 int LyXText::LabelFill(BufferView * bview, Row const * row) const
1246 LyXParagraph::size_type last = BeginningOfMainBody(bview->buffer(), row->par())-1;
1247 // -1 because a label ends either with a space that is in the label,
1248 // or with the beginning of a footnote that is outside the label.
1250 // I don't understand this code in depth, but sometimes "last" is
1251 // less than 0 and this causes a crash. This fix seems to work
1252 // correctly, but I bet the real error is elsewhere. The bug is
1253 // triggered when you have an open footnote in a paragraph
1254 // environment with a manual label. (Asger)
1255 if (last < 0) last = 0;
1257 if (row->par()->IsLineSeparator(last)) /* a sepearator at this end
1264 w += SingleWidth(bview, row->par(), i);
1269 if (!row->par()->labelwidthstring.empty()) {
1270 fill = max(lyxfont::width(row->par()->labelwidthstring,
1271 GetFont(bview->buffer(), row->par(), -2)) - w,
1279 // returns the number of separators in the specified row. The separator
1280 // on the very last column doesnt count
1281 int LyXText::NumberOfSeparators(Buffer const * buf, Row const * row) const
1283 int last = RowLast(row);
1284 int p = max(row->pos(), BeginningOfMainBody(buf, row->par()));
1286 for (; p < last; ++p) {
1287 if (row->par()->IsSeparator(p)) {
1295 // returns the number of hfills in the specified row. The LyX-Hfill is
1296 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1297 // ignored. This is *MUCH* more usefull than not to ignore!
1298 int LyXText::NumberOfHfills(Buffer const * buf, Row const * row) const
1300 int last = RowLast(row);
1301 int first = row->pos();
1302 if (first) { /* hfill *DO* count at the beginning
1304 while(first <= last && row->par()->IsHfill(first))
1308 first = max(first, BeginningOfMainBody(buf, row->par()));
1310 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1311 if (row->par()->IsHfill(p)) {
1319 // like NumberOfHfills, but only those in the manual label!
1320 int LyXText::NumberOfLabelHfills(Buffer const * buf, Row const * row) const
1322 LyXParagraph::size_type last = RowLast(row);
1323 LyXParagraph::size_type first = row->pos();
1324 if (first) { /* hfill *DO* count at the beginning
1326 while(first < last && row->par()->IsHfill(first))
1330 last = min(last, BeginningOfMainBody(buf, row->par()));
1332 for (LyXParagraph::size_type p = first;
1333 p < last; ++p) { // last, because the end is ignored!
1334 if (row->par()->IsHfill(p)) {
1342 // returns true, if a expansion is needed.
1343 // Rules are given by LaTeX
1344 bool LyXText::HfillExpansion(Buffer const * buf, Row const * row_ptr,
1345 LyXParagraph::size_type pos) const
1347 // by the way, is it a hfill?
1348 if (!row_ptr->par()->IsHfill(pos))
1351 // at the end of a row it does not count
1352 if (pos >= RowLast(row_ptr))
1355 // at the beginning of a row it does not count, if it is not
1356 // the first row of a paragaph
1357 if (!row_ptr->pos())
1360 // in some labels it does not count
1361 if (textclasslist.Style(buf->params.textclass,
1362 row_ptr->par()->GetLayout()).margintype
1364 && pos < BeginningOfMainBody(buf, row_ptr->par()))
1367 // if there is anything between the first char of the row and
1368 // the sepcified position that is not a newline and not a hfill,
1369 // the hfill will count, otherwise not
1370 LyXParagraph::size_type i = row_ptr->pos();
1371 while (i < pos && (row_ptr->par()->IsNewline(i)
1372 || row_ptr->par()->IsHfill(i)))
1379 void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
1381 /* get the maximum ascent and the maximum descent */
1382 int asc = 0, desc = 0, pos = 0;
1383 float layoutasc = 0;
1384 float layoutdesc = 0;
1387 Inset * tmpinset = 0;
1389 /* this must not happen before the currentrow for clear reasons.
1390 so the trick is just to set the current row onto this row */
1392 GetRow(row_ptr->par(), row_ptr->pos(), unused_y);
1394 /* ok , let us initialize the maxasc and maxdesc value.
1395 * This depends in LaTeX of the font of the last character
1396 * in the paragraph. The hack below is necessary because
1397 * of the possibility of open footnotes */
1399 /* Correction: only the fontsize count. The other properties
1400 are taken from the layoutfont. Nicer on the screen :) */
1402 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
1403 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
1405 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1406 firstpar->GetLayout());
1408 LyXFont font = GetFont(bview->buffer(), par, par->Last() - 1);
1409 LyXFont::FONT_SIZE size = font.size();
1410 font = GetFont(bview->buffer(), par, -1);
1413 LyXFont labelfont = GetFont(bview->buffer(), par, -2);
1415 float spacing_val = 1.0;
1416 if (!row_ptr->par()->spacing.isDefault()) {
1417 spacing_val = row_ptr->par()->spacing.getValue();
1419 spacing_val = bview->buffer()->params.spacing.getValue();
1421 //lyxerr << "spacing_val = " << spacing_val << endl;
1423 int maxasc = int(lyxfont::maxAscent(font) *
1424 layout.spacing.getValue() *
1426 int maxdesc = int(lyxfont::maxDescent(font) *
1427 layout.spacing.getValue() *
1429 int pos_end = RowLast(row_ptr);
1433 // Check if any insets are larger
1434 for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
1435 if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
1436 tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
1437 tmpinset = row_ptr->par()->GetInset(pos);
1439 tmpinset->update(bview, tmpfont);
1440 asc = tmpinset->ascent(bview->painter(), tmpfont);
1441 desc = tmpinset->descent(bview->painter(), tmpfont);
1442 maxwidth += tmpinset->width(bview->painter(), tmpfont);
1443 maxasc = max(maxasc, asc);
1444 maxdesc = max(maxdesc, desc);
1447 maxwidth += SingleWidth(bview, row_ptr->par(), pos);
1451 // Check if any custom fonts are larger (Asger)
1452 // This is not completely correct, but we can live with the small,
1453 // cosmetic error for now.
1454 LyXFont::FONT_SIZE maxsize =
1455 row_ptr->par()->HighestFontInRange(row_ptr->pos(),
1457 if (maxsize > font.size()) {
1458 font.setSize(maxsize);
1460 asc = lyxfont::maxAscent(font);
1461 desc = lyxfont::maxDescent(font);
1469 /* table stuff -- begin*/
1470 if (row_ptr->par()->table){
1471 // stretch the rows a bit
1475 /* table stuff -- end*/
1478 // This is nicer with box insets:
1482 row_ptr->ascent_of_text(maxasc);
1484 /* is it a top line? */
1485 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
1487 /* some parksips VERY EASY IMPLEMENTATION */
1488 if (bview->buffer()->params.paragraph_separation ==
1489 BufferParams::PARSEP_SKIP) {
1490 if (layout.isParagraph()
1491 && firstpar->GetDepth() == 0
1492 && firstpar->Previous())
1493 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1494 else if (firstpar->Previous()
1495 && textclasslist.Style(bview->buffer()->params.textclass,
1496 firstpar->Previous()->GetLayout()).isParagraph()
1497 && firstpar->Previous()->GetDepth() == 0)
1498 // is it right to use defskip here too? (AS)
1499 maxasc += bview->buffer()->params.getDefSkip().inPixels(bview);
1502 /* the paper margins */
1503 if (!row_ptr->par()->previous && bv_owner)
1504 maxasc += LYX_PAPER_MARGIN;
1506 /* add the vertical spaces, that the user added */
1507 if (firstpar->added_space_top.kind() != VSpace::NONE)
1508 maxasc += int(firstpar->added_space_top.inPixels(bview));
1510 /* do not forget the DTP-lines!
1511 * there height depends on the font of the nearest character */
1512 if (firstpar->line_top)
1513 maxasc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1516 /* and now the pagebreaks */
1517 if (firstpar->pagebreak_top)
1518 maxasc += 3 * DefaultHeight();
1520 /* this is special code for the chapter, since the label of this
1521 * layout is printed in an extra row */
1522 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1523 && bview->buffer()->params.secnumdepth >= 0) {
1524 float spacing_val = 1.0;
1525 if (!row_ptr->par()->spacing.isDefault()) {
1526 spacing_val = row_ptr->par()->spacing.getValue();
1528 spacing_val = bview->buffer()->params.spacing.getValue();
1531 labeladdon = int(lyxfont::maxDescent(labelfont) *
1532 layout.spacing.getValue() *
1534 + int(lyxfont::maxAscent(labelfont) *
1535 layout.spacing.getValue() *
1539 /* special code for the top label */
1540 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1541 || layout.labeltype == LABEL_BIBLIO
1542 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1543 && row_ptr->par()->IsFirstInSequence()
1544 && !row_ptr->par()->GetLabelstring().empty()) {
1545 float spacing_val = 1.0;
1546 if (!row_ptr->par()->spacing.isDefault()) {
1547 spacing_val = row_ptr->par()->spacing.getValue();
1549 spacing_val = bview->buffer()->params.spacing.getValue();
1553 (lyxfont::maxAscent(labelfont) *
1554 layout.spacing.getValue() *
1556 +(lyxfont::maxDescent(labelfont) *
1557 layout.spacing.getValue() *
1559 + layout.topsep * DefaultHeight()
1560 + layout.labelbottomsep * DefaultHeight());
1563 /* and now the layout spaces, for example before and after a section,
1564 * or between the items of a itemize or enumerate environment */
1566 if (!firstpar->pagebreak_top) {
1567 LyXParagraph * prev = row_ptr->par()->Previous();
1569 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth());
1570 if (prev && prev->GetLayout() == firstpar->GetLayout()
1571 && prev->GetDepth() == firstpar->GetDepth()
1572 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1574 layoutasc = (layout.itemsep * DefaultHeight());
1576 else if (row_ptr->previous()) {
1577 tmptop = layout.topsep;
1579 if (row_ptr->previous()->par()->GetDepth() >= row_ptr->par()->GetDepth())
1580 tmptop -= textclasslist.Style(bview->buffer()->params.textclass,
1581 row_ptr->previous()->par()->
1582 GetLayout()).bottomsep;
1585 layoutasc = (tmptop * DefaultHeight());
1587 else if (row_ptr->par()->line_top){
1588 tmptop = layout.topsep;
1591 layoutasc = (tmptop * DefaultHeight());
1594 prev = row_ptr->par()->DepthHook(row_ptr->par()->GetDepth()-1);
1596 maxasc += int(textclasslist.Style(bview->buffer()->params.textclass,
1597 prev->GetLayout()).parsep * DefaultHeight());
1600 if (firstpar->Previous()
1601 && firstpar->Previous()->GetDepth() == 0
1602 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1605 else if (firstpar->Previous()){
1606 maxasc += int(layout.parsep * DefaultHeight());
1612 /* is it a bottom line? */
1613 if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
1614 && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {
1616 /* the paper margins */
1617 if (!par->next && bv_owner)
1618 maxdesc += LYX_PAPER_MARGIN;
1620 /* add the vertical spaces, that the user added */
1621 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1622 maxdesc += int(firstpar->added_space_bottom.inPixels(bview));
1624 /* do not forget the DTP-lines!
1625 * there height depends on the font of the nearest character */
1626 if (firstpar->line_bottom)
1627 maxdesc += 2 * lyxfont::ascent('x', GetFont(bview->buffer(),
1628 par, par->Last() - 1));
1630 /* and now the pagebreaks */
1631 if (firstpar->pagebreak_bottom)
1632 maxdesc += 3 * DefaultHeight();
1634 /* and now the layout spaces, for example before and after a section,
1635 * or between the items of a itemize or enumerate environment */
1636 if (!firstpar->pagebreak_bottom && row_ptr->par()->Next()) {
1637 LyXParagraph * nextpar = row_ptr->par()->Next();
1638 LyXParagraph * comparepar = row_ptr->par();
1642 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1643 usual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1644 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1645 if (comparepar->GetLayout()!= nextpar->GetLayout()
1646 || nextpar->GetLabelWidthString() !=
1647 comparepar->GetLabelWidthString())
1648 unusual = (textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1650 if (unusual > usual)
1651 layoutdesc = unusual;
1655 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1657 if (comparepar->GetLayout()!= nextpar->GetLayout()
1658 || nextpar->GetLabelWidthString() !=
1659 comparepar->GetLabelWidthString())
1660 layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1665 /* incalculate the layout spaces */
1666 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1667 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1670 /* table stuff -- begin*/
1671 if (row_ptr->par()->table){
1672 maxasc += row_ptr->par()->table->
1673 AdditionalHeight(NumberOfCell(row_ptr->par(), row_ptr->pos()));
1675 /* table stuff -- end*/
1677 /* calculate the new height of the text */
1678 height -= row_ptr->height();
1680 row_ptr->height(maxasc + maxdesc + labeladdon);
1681 row_ptr->baseline(maxasc + labeladdon);
1683 height += row_ptr->height();
1685 PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
1686 row_ptr->width(maxwidth+x);
1691 if (r->width() > width)
1699 /* Appends the implicit specified paragraph behind the specified row,
1700 * start at the implicit given position */
1701 void LyXText::AppendParagraph(BufferView * bview, Row * row) const
1703 bool not_ready = true;
1705 // The last character position of a paragraph is an invariant so we can
1706 // safely get it here. (Asger)
1707 int lastposition = row->par()->Last();
1710 // Get the next breakpoint
1711 int z = NextBreakPoint(bview, row, workWidth(bview));
1715 // Insert the new row
1716 if (z < lastposition) {
1718 InsertRow(row, row->par(), z);
1725 // Set the dimensions of the row
1726 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1727 SetHeightOfRow(bview, tmprow);
1729 } while (not_ready);
1733 void LyXText::BreakAgain(BufferView * bview, Row * row) const
1735 bool not_ready = true;
1738 /* get the next breakpoint */
1739 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1742 if (z < row->par()->Last() ) {
1743 if (!row->next() || (row->next() && row->next()->par() != row->par())) {
1746 InsertRow(row, row->par(), z);
1752 if (row->pos() == z)
1753 not_ready = false; // the rest will not change
1759 /* if there are some rows too much, delete them */
1760 /* only if you broke the whole paragraph! */
1761 Row * tmprow2 = row;
1762 while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
1763 tmprow2 = tmprow2->next();
1765 while (tmprow2 != row) {
1766 tmprow2 = tmprow2->previous();
1767 RemoveRow(tmprow2->next());
1772 /* set the dimensions of the row */
1773 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1774 SetHeightOfRow(bview, tmprow);
1775 } while (not_ready);
1779 // this is just a little changed version of break again
1780 void LyXText::BreakAgainOneRow(BufferView * bview, Row * row)
1782 // get the next breakpoint
1783 LyXParagraph::size_type z = NextBreakPoint(bview, row, workWidth(bview));
1786 if (z < row->par()->Last() ) {
1788 || (row->next() && row->next()->par() != row->par())) {
1789 /* insert a new row */
1791 InsertRow(row, row->par(), z);
1797 if (row->pos() != z)
1801 // if there are some rows too much, delete them
1802 // only if you broke the whole paragraph!
1803 Row * tmprow2 = row;
1804 while (tmprow2->next()
1805 && tmprow2->next()->par() == row->par()) {
1806 tmprow2 = tmprow2->next();
1808 while (tmprow2 != row) {
1809 tmprow2 = tmprow2->previous();
1810 RemoveRow(tmprow2->next());
1814 // set the dimensions of the row
1815 tmprow->fill(Fill(bview, tmprow, workWidth(bview)));
1816 SetHeightOfRow(bview, tmprow);
1820 void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
1822 LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
1823 cursor.par()->GetLayout());
1825 /* table stuff -- begin */
1826 if (cursor.par()->table) {
1827 // breaking of tables is only allowed at the beginning or the end */
1828 if (cursor.pos() && cursor.pos() < cursor.par()->size() &&
1829 !cursor.par()->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par(), cursor.pos())))
1830 return; // no breaking of tables allowed
1832 /* table stuff -- end */
1834 // this is only allowed, if the current paragraph is not empty or caption
1835 if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
1837 layout.labeltype!= LABEL_SENSITIVE)
1840 SetUndo(bview->buffer(), Undo::INSERT,
1841 cursor.par()->ParFromPos(cursor.pos())->previous,
1842 cursor.par()->ParFromPos(cursor.pos())->next);
1845 /* table stuff -- begin */
1846 if (cursor.par()->table) {
1847 int cell = NumberOfCell(cursor.par(), cursor.pos());
1848 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
1849 SetCursor(bview, cursor.par(), cursor.par()->size());
1851 /* table stuff -- end */
1853 // please break always behind a space
1854 if (cursor.pos() < cursor.par()->Last()
1855 && cursor.par()->IsLineSeparator(cursor.pos()))
1856 cursor.pos(cursor.pos() + 1);
1858 // break the paragraph
1862 keep_layout = layout.isEnvironment();
1863 cursor.par()->BreakParagraph(bview->buffer()->params, cursor.pos(),
1866 /* table stuff -- begin */
1867 if (cursor.par()->table){
1868 // the table should stay with the contents
1870 cursor.par()->Next()->table = cursor.par()->table;
1871 cursor.par()->table = 0;
1874 /* table stuff -- end */
1876 // well this is the caption hack since one caption is really enough
1877 if (layout.labeltype == LABEL_SENSITIVE) {
1879 // set to standard-layout
1880 cursor.par()->SetLayout(bview->buffer()->params, 0);
1882 // set to standard-layout
1883 cursor.par()->Next()->SetLayout(bview->buffer()->params, 0);
1886 /* if the cursor is at the beginning of a row without prior newline,
1888 * This touches only the screen-update. Otherwise we would may have
1889 * an empty row on the screen */
1890 if (cursor.pos() && !cursor.row()->par()->IsNewline(cursor.row()->pos() - 1) &&
1891 cursor.row()->pos() == cursor.pos()) {
1895 status = LyXText::NEED_MORE_REFRESH;
1896 refresh_row = cursor.row();
1897 refresh_y = cursor.y() - cursor.row()->baseline();
1899 // Do not forget the special right address boxes
1900 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1901 while (refresh_row->previous() &&
1902 refresh_row->previous()->par() == refresh_row->par()) {
1903 refresh_row = refresh_row->previous();
1904 refresh_y -= refresh_row->height();
1907 RemoveParagraph(cursor.row());
1909 // set the dimensions of the cursor row
1910 cursor.row()->fill(Fill(bview, cursor.row(), workWidth(bview)));
1912 SetHeightOfRow(bview, cursor.row());
1914 while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
1915 && cursor.par()->Next()->IsNewline(0))
1916 cursor.par()->Next()->Erase(0);
1918 InsertParagraph(bview, cursor.par()->Next(), cursor.row());
1920 UpdateCounters(bview, cursor.row()->previous());
1922 /* This check is necessary. Otherwise the new empty paragraph will
1923 * be deleted automatically. And it is more friendly for the user! */
1925 SetCursor(bview, cursor.par()->Next(), 0);
1927 SetCursor(bview, cursor.par(), 0);
1929 if (cursor.row()->next())
1930 BreakAgain(bview, cursor.row()->next());
1937 void LyXText::OpenFootnote(BufferView * bview)
1939 LyXParagraph * endpar,* tmppar;
1942 LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
1944 /* if there is no footnote in this paragraph, just return. */
1946 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1949 /* ok, move the cursor right before the footnote */
1951 /* just a little faster than using CursorRight() */
1953 cursor.par()->ParFromPos(cursor.pos()) != par;) {
1954 cursor.pos(cursor.pos() + 1);
1957 /* now the cursor is at the beginning of the physical par */
1958 SetCursor(bview, cursor.par(),
1959 cursor.pos() + cursor.par()->ParFromPos(cursor.pos())->size());
1961 /* the cursor must be exactly before the footnote */
1962 par = cursor.par()->ParFromPos(cursor.pos());
1964 status = LyXText::NEED_MORE_REFRESH;
1965 refresh_row = cursor.row();
1966 refresh_y = cursor.y() - cursor.row()->baseline();
1968 tmppar = cursor.par();
1969 endpar = cursor.par()->Next();
1972 tmppar->OpenFootnote(cursor.pos());
1973 RemoveParagraph(row);
1974 /* set the dimensions of the cursor row */
1975 row->fill(Fill(bview, row, workWidth(bview)));
1976 SetHeightOfRow(bview, row);
1977 // CHECK See comment on top of text.C
1978 tmppar = tmppar->Next();
1980 while (tmppar != endpar) {
1982 InsertParagraph(bview, tmppar, row);
1983 while (row->next() && row->next()->par() == tmppar)
1985 tmppar = tmppar->Next();
1988 SetCursor(bview, par->next, 0);
1989 sel_cursor = cursor;
1995 /* table stuff -- begin*/
1997 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
1999 if (!cursor.par()->table)
2000 return; /* this should never happen */
2002 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2003 SetUndo(bview->buffer(), Undo::FINISH,
2004 cursor.par()->ParFromPos(cursor.pos())->previous,
2005 cursor.par()->ParFromPos(cursor.pos())->next);
2008 case LyXTable::SET_PWIDTH:
2009 cursor.par()->table->SetPWidth(actCell, val);
2011 case LyXTable::SET_SPECIAL_COLUMN:
2012 case LyXTable::SET_SPECIAL_MULTI:
2013 cursor.par()->table->SetAlignSpecial(actCell, val, feature);
2018 RedoParagraph(bview);
2022 void LyXText::TableFeatures(BufferView * bview, int feature) const
2025 int setAlign = LYX_ALIGN_LEFT;
2029 if (!cursor.par()->table)
2030 return; /* this should never happen */
2032 int actCell = NumberOfCell(cursor.par(), cursor.pos());
2033 SetUndo(bview->buffer(), Undo::FINISH,
2034 cursor.par()->ParFromPos(cursor.pos())->previous,
2035 cursor.par()->ParFromPos(cursor.pos())->next);
2038 case LyXTable::ALIGN_LEFT:
2039 setAlign= LYX_ALIGN_LEFT;
2041 case LyXTable::ALIGN_RIGHT:
2042 setAlign= LYX_ALIGN_RIGHT;
2044 case LyXTable::ALIGN_CENTER:
2045 setAlign= LYX_ALIGN_CENTER;
2051 case LyXTable::APPEND_ROW: {
2052 LyXParagraph::size_type pos = cursor.pos();
2054 /* move to the next row */
2055 int cell_org = actCell;
2056 int cell = cell_org;
2058 // if there is a ContRow following this row I have to add
2059 // the row after the ContRow's
2060 if ((pos < cursor.par()->Last()) &&
2061 cursor.par()->table->RowHasContRow(cell_org)) {
2062 while((pos < cursor.par()->Last()) &&
2063 !cursor.par()->table->IsContRow(cell)) {
2064 while (pos < cursor.par()->Last() &&
2065 !cursor.par()->IsNewline(pos))
2067 if (pos < cursor.par()->Last())
2071 while((pos < cursor.par()->Last()) &&
2072 cursor.par()->table->IsContRow(cell)) {
2073 while (pos < cursor.par()->Last() &&
2074 !cursor.par()->IsNewline(pos))
2076 if (pos < cursor.par()->Last())
2081 if (pos < cursor.par()->Last())
2084 while (pos < cursor.par()->Last() &&
2085 (cell == cell_org || !cursor.par()->table->IsFirstCell(cell))){
2086 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2088 if (pos < cursor.par()->Last())
2093 /* insert the new cells */
2094 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2095 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2096 LyXFont font(LyXFont::ALL_INHERIT,lang);
2097 for (int i = 0; i < number; ++i) {
2099 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2101 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2102 cursor.par()->SetFont(pos, font);
2106 /* append the row into the table */
2107 cursor.par()->table->AppendRow(cell_org);
2108 RedoParagraph(bview);
2111 case LyXTable::APPEND_CONT_ROW: {
2112 LyXParagraph::size_type pos = cursor.pos();
2113 /* move to the next row */
2114 int cell_org = actCell;
2115 int cell = cell_org;
2117 // if there is already a controw but not for this cell
2118 // the AppendContRow sets only the right values but does
2119 // not actually add a row
2120 if (cursor.par()->table->RowHasContRow(cell_org) &&
2121 (cursor.par()->table->CellHasContRow(cell_org)<0)) {
2122 cursor.par()->table->AppendContRow(cell_org);
2123 RedoParagraph(bview);
2126 while (pos < cursor.par()->Last() &&
2128 || !cursor.par()->table->IsFirstCell(cell))){
2129 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2131 if (pos < cursor.par()->Last())
2136 /* insert the new cells */
2137 int number = cursor.par()->table->NumberOfCellsInRow(cell_org);
2138 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2139 LyXFont font(LyXFont::ALL_INHERIT,lang);
2140 for (int i = 0; i < number; ++i) {
2142 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
2144 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2145 cursor.par()->SetFont(pos, font);
2149 /* append the row into the table */
2150 cursor.par()->table->AppendContRow(cell_org);
2151 RedoParagraph(bview);
2154 case LyXTable::APPEND_COLUMN: {
2155 LyXParagraph::size_type pos = 0;
2156 int cell_org = actCell;
2158 Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
2159 LyXFont font(LyXFont::ALL_INHERIT,lang);
2161 if (pos && (cursor.par()->IsNewline(pos-1))){
2162 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2164 cursor.par()->InsertChar(pos,
2165 LyXParagraph::META_NEWLINE,
2168 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2169 cursor.par()->SetFont(pos, font);
2171 if (pos <= cursor.pos())
2172 cursor.pos(cursor.pos() + 1);
2178 } while (pos <= cursor.par()->Last());
2179 /* remember that the very last cell doesn't end with a newline.
2180 This saves one byte memory per table ;-) */
2181 if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
2182 LyXParagraph::size_type last = cursor.par()->Last();
2184 cursor.par()->InsertChar(last,
2185 LyXParagraph::META_NEWLINE, font);
2187 cursor.par()->InsertChar(last, LyXParagraph::META_NEWLINE);
2188 cursor.par()->SetFont(last, font);
2192 /* append the column into the table */
2193 cursor.par()->table->AppendColumn(cell_org);
2195 RedoParagraph(bview);
2198 case LyXTable::DELETE_ROW:
2199 if (bview->the_locking_inset)
2200 bview->unlockInset(bview->the_locking_inset);
2201 RemoveTableRow(cursor);
2202 RedoParagraph(bview);
2205 case LyXTable::DELETE_COLUMN: {
2206 LyXParagraph::size_type pos = 0;
2207 int cell_org = actCell;
2209 if (bview->the_locking_inset)
2210 bview->unlockInset(bview->the_locking_inset);
2212 if (!pos || (cursor.par()->IsNewline(pos-1))){
2213 if (cursor.par()->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2215 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2216 cursor.par()->Erase(pos);
2217 if (pos < cursor.par()->Last())
2218 cursor.par()->Erase(pos);
2220 cursor.par()->Erase(pos - 1); // the missing newline at the end of a table
2221 --pos; // because of pos++ below
2226 } while (pos <= cursor.par()->Last());
2228 /* delete the column from the table */
2229 cursor.par()->table->DeleteColumn(cell_org);
2231 /* set the cursor to the beginning of the table, where else? */
2233 RedoParagraph(bview);
2236 case LyXTable::TOGGLE_LINE_TOP:
2237 lineSet = !cursor.par()->table->TopLine(actCell);
2239 cursor.par()->table->SetTopLine(actCell, lineSet);
2241 LyXParagraph::size_type i;
2243 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2244 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2245 cursor.par()->table->SetTopLine(n, lineSet);
2250 RedoParagraph(bview);
2253 case LyXTable::TOGGLE_LINE_BOTTOM:
2254 lineSet = !cursor.par()->table->BottomLine(actCell);
2256 cursor.par()->table->SetBottomLine(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->SetBottomLine(n, lineSet);
2267 RedoParagraph(bview);
2270 case LyXTable::TOGGLE_LINE_LEFT:
2271 lineSet = !cursor.par()->table->LeftLine(actCell);
2273 cursor.par()->table->SetLeftLine(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->SetLeftLine(n, lineSet);
2284 RedoParagraph(bview);
2287 case LyXTable::TOGGLE_LINE_RIGHT:
2288 lineSet = !cursor.par()->table->RightLine(actCell);
2290 cursor.par()->table->SetRightLine(actCell, lineSet);
2293 LyXParagraph::size_type i = sel_start_cursor.pos();
2294 for (; i <= sel_end_cursor.pos(); ++i) {
2295 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2296 cursor.par()->table->SetRightLine(n, lineSet);
2301 RedoParagraph(bview);
2304 case LyXTable::ALIGN_LEFT:
2305 case LyXTable::ALIGN_RIGHT:
2306 case LyXTable::ALIGN_CENTER:
2308 cursor.par()->table->SetAlignment(actCell, setAlign);
2311 LyXParagraph::size_type i = sel_start_cursor.pos();
2312 for (; i <= sel_end_cursor.pos(); ++i) {
2313 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2314 cursor.par()->table->SetAlignment(n, setAlign);
2319 RedoParagraph(bview);
2322 case LyXTable::DELETE_TABLE:
2323 SetCursorIntern(bview, cursor.par(), 0);
2324 delete cursor.par()->table;
2325 cursor.par()->table = 0;
2326 // temporary: Should put table in simple_cut_buffer (with before and after
2327 // dummy-paragraph !!
2328 // not necessar anymore with UNDO :)
2329 for (LyXParagraph::size_type i =
2330 cursor.par()->size() - 1; i >= 0; --i)
2331 cursor.par()->Erase(i);
2332 RedoParagraph(bview);
2335 case LyXTable::MULTICOLUMN: {
2337 // check wether we are completly in a multicol
2338 int multicol = cursor.par()->table->IsMultiColumn(actCell);
2339 if (multicol && selection && sel_start_cursor.row() == sel_end_cursor.row()) {
2340 multicol = NumberOfCell(sel_start_cursor.par(), sel_start_cursor.pos())
2341 == NumberOfCell(sel_end_cursor.par(), sel_end_cursor.pos());
2345 int newlines = cursor.par()->table->UnsetMultiColumn(actCell);
2346 LyXParagraph::size_type pos = cursor.pos();
2347 while (pos < cursor.par()->Last() && !cursor.par()->IsNewline(pos))
2349 for (; newlines; --newlines)
2350 cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
2351 RedoParagraph(bview);
2355 // selection must be in one row (or no selection)
2357 cursor.par()->table->SetMultiColumn(NumberOfCell(cursor.par(),
2360 RedoParagraph(bview);
2364 if (sel_start_cursor.row() == sel_end_cursor.row()){
2365 LyXParagraph::size_type i;
2367 for (i = sel_start_cursor.pos();
2368 i < sel_end_cursor.pos(); ++i){
2369 if (sel_start_cursor.par()->IsNewline(i)){
2370 sel_start_cursor.par()->Erase(i);
2371 // check for double-blanks
2372 if ((i && !sel_start_cursor.par()->IsLineSeparator(i-1))
2374 (i < sel_start_cursor.par()->Last()
2375 && !sel_start_cursor.par()->IsLineSeparator(i)))
2376 sel_start_cursor.par()->InsertChar(i, ' ');
2378 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
2384 cursor.par()->table->
2385 SetMultiColumn(NumberOfCell(sel_start_cursor.par(),
2386 sel_start_cursor.pos()),
2388 cursor.pos(sel_start_cursor.pos());
2389 RedoParagraph(bview);
2393 WriteAlert(_("Impossible Operation!"),
2394 _("Multicolumns can only be horizontally."),
2401 case LyXTable::SET_ALL_LINES:
2403 case LyXTable::UNSET_ALL_LINES:
2405 cursor.par()->table->SetAllLines(NumberOfCell(cursor.par(),
2409 LyXParagraph::size_type i;
2411 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2412 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2413 cursor.par()->table->SetAllLines(n, setLines);
2418 RedoParagraph(bview);
2420 case LyXTable::SET_LONGTABLE:
2421 cursor.par()->table->SetLongTable(true);
2423 case LyXTable::UNSET_LONGTABLE:
2424 cursor.par()->table->SetLongTable(false);
2426 case LyXTable::SET_ROTATE_TABLE:
2427 cursor.par()->table->SetRotateTable(true);
2429 case LyXTable::UNSET_ROTATE_TABLE:
2430 cursor.par()->table->SetRotateTable(false);
2432 case LyXTable::SET_ROTATE_CELL:
2434 cursor.par()->table->SetRotateCell(actCell, true);
2436 LyXParagraph::size_type i;
2438 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i){
2439 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2440 cursor.par()->table->SetRotateCell(n, true);
2446 case LyXTable::UNSET_ROTATE_CELL:
2448 cursor.par()->table->SetRotateCell(actCell, false);
2451 LyXParagraph::size_type i = sel_start_cursor.pos();
2452 for (; i <= sel_end_cursor.pos(); ++i) {
2453 if ((n= NumberOfCell(sel_start_cursor.par(), i)) != m) {
2454 cursor.par()->table->SetRotateCell(n, false);
2460 case LyXTable::SET_LINEBREAKS:
2461 what = !cursor.par()->table->Linebreaks(cursor.par()->table->FirstVirtualCell(actCell));
2463 cursor.par()->table->SetLinebreaks(actCell, what);
2465 LyXParagraph::size_type i;
2467 for (i = sel_start_cursor.pos(); i <= sel_end_cursor.pos(); ++i) {
2468 if ((n = NumberOfCell(sel_start_cursor.par(), i)) != m) {
2469 cursor.par()->table->SetLinebreaks(n, what);
2475 case LyXTable::SET_LTFIRSTHEAD:
2476 cursor.par()->table->SetLTHead(actCell, true);
2478 case LyXTable::SET_LTHEAD:
2479 cursor.par()->table->SetLTHead(actCell, false);
2481 case LyXTable::SET_LTFOOT:
2482 cursor.par()->table->SetLTFoot(actCell, false);
2484 case LyXTable::SET_LTLASTFOOT:
2485 cursor.par()->table->SetLTFoot(actCell, true);
2487 case LyXTable::SET_LTNEWPAGE:
2488 what = !cursor.par()->table->LTNewPage(actCell);
2489 cursor.par()->table->SetLTNewPage(actCell, what);
2495 void LyXText::InsertCharInTable(BufferView * bview, char c)
2500 bool jumped_over_space;
2502 /* first check, if there will be two blanks together or a blank at
2503 * the beginning of a paragraph.
2504 * I decided to handle blanks like normal characters, the main
2505 * difference are the special checks when calculating the row.fill
2506 * (blank does not count at the end of a row) and the check here */
2508 LyXFont realtmpfont = real_current_font;
2509 LyXFont rawtmpfont = current_font; /* store the current font.
2510 * This is because of the use
2511 * of cursor movements. The moving
2512 * cursor would refresh the
2515 // Get the font that is used to calculate the baselineskip
2516 LyXParagraph::size_type const lastpos =
2517 cursor.par()->Last();
2518 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2521 jumped_over_space = false;
2522 if (IsLineSeparatorChar(c)) {
2523 if ((cursor.pos() > 0 &&
2524 cursor.par()->IsLineSeparator(cursor.pos() - 1))
2525 || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
2526 || (cursor.pos() == 0 &&
2527 !(cursor.par()->Previous()
2528 && cursor.par()->Previous()->footnoteflag
2529 == LyXParagraph::OPEN_FOOTNOTE)))
2531 } else if (IsNewlineChar(c)) {
2532 if (!IsEmptyTableCell()) {
2533 TableFeatures(bview, LyXTable::APPEND_CONT_ROW);
2540 y = cursor.y() - row->baseline();
2541 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2542 * already inserted the character */
2543 cursor.par()->InsertChar(cursor.pos(), c);
2544 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2546 if (!jumped_over_space) {
2547 /* refresh the positions */
2549 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2550 tmprow = tmprow->next();
2551 tmprow->pos(tmprow->pos() + 1);
2555 cursor.pos(cursor.pos() + 1);
2557 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2559 current_font = rawtmpfont;
2560 real_current_font = realtmpfont;
2562 /* check, whether the last character's font has changed. */
2563 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2564 && rawparfont != rawtmpfont)
2565 RedoHeightOfParagraph(bview, cursor);
2569 void LyXText::CheckParagraphInTable(BufferView * bview, LyXParagraph * par,
2570 LyXParagraph::size_type pos)
2573 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2574 par->GetInset(pos) && par->GetInset(pos)->display()){
2575 par->GetInset(pos)->display(false);
2579 Row * row = GetRow(par, pos, y);
2581 int tmpheight = row->height();
2582 SetHeightOfRow(bview, row);
2584 LyXParagraph::size_type tmp_pos = pos;
2585 /* update the table information */
2586 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2588 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2589 WidthOfCell(bview, par, tmp_pos))) {
2590 LyXCursor tmpcursor = cursor;
2591 SetCursorIntern(bview, par, pos, false);
2592 /* make a complete redraw */
2593 RedoDrawingOfParagraph(bview, cursor);
2597 /* redraw only the row */
2598 LyXCursor tmpcursor = cursor;
2599 SetCursorIntern(bview, par, pos);
2600 //CHECK See comment on top of text.C
2602 refresh_x = cursor.x();
2604 refresh_pos = cursor.pos();
2607 if (tmpheight == row->height())
2608 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2610 status = LyXText::NEED_MORE_REFRESH;
2612 SetCursorIntern(bview, cursor.par(), cursor.pos(), false,
2617 void LyXText::BackspaceInTable(BufferView * bview)
2619 Row * tmprow, * row;
2622 LyXFont rawtmpfont = current_font;
2623 LyXFont realtmpfont = real_current_font;
2625 // Get the font that is used to calculate the baselineskip
2626 int const lastpos = cursor.par()->Last();
2627 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2630 if (cursor.pos() == 0) {
2631 /* no pasting of table paragraphs */
2635 /* this is the code for a normal backspace, not pasting
2637 SetUndo(bview->buffer(), Undo::DELETE,
2638 cursor.par()->ParFromPos(cursor.pos())->previous,
2639 cursor.par()->ParFromPos(cursor.pos())->next);
2641 CursorLeftIntern(bview);
2643 /* some insets are undeletable here */
2644 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
2645 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
2650 y = cursor.y() - row->baseline();
2652 /* some special code when deleting a newline. */
2653 if (cursor.par()->IsNewline(cursor.pos())) {
2657 cursor.par()->Erase(cursor.pos());
2659 /* refresh the positions */
2661 while (tmprow->next()
2662 && tmprow->next()->par() == row->par()) {
2663 tmprow = tmprow->next();
2664 tmprow->pos(tmprow->pos() - 1);
2668 CheckParagraphInTable(bview, cursor.par(), cursor.pos());
2670 /* check, wether the last characters font has changed. */
2671 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2672 && rawparfont != rawtmpfont)
2673 RedoHeightOfParagraph(bview, cursor);
2675 /* restore the current font
2676 * That is what a user expects! */
2677 current_font = rawtmpfont;
2678 real_current_font = realtmpfont;
2680 SetCursorIntern(bview, cursor.par(), cursor.pos(), true,
2682 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
2683 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
2686 /* table stuff -- end*/
2690 // Just a macro to make some thing easier.
2691 void LyXText::RedoParagraph(BufferView * bview) const
2694 RedoParagraphs(bview, cursor, cursor.par()->Next());
2695 SetCursorIntern(bview, cursor.par(), cursor.pos());
2699 /* insert a character, moves all the following breaks in the
2700 * same Paragraph one to the right and make a rebreak */
2701 void LyXText::InsertChar(BufferView * bview, char c)
2703 SetUndo(bview->buffer(), Undo::INSERT,
2704 cursor.par()->ParFromPos(cursor.pos())->previous,
2705 cursor.par()->ParFromPos(cursor.pos())->next);
2707 // When the free-spacing option is set for the current layout,
2708 // disable the double-space checking
2711 textclasslist.Style(bview->buffer()->params.textclass,
2712 cursor.row()->par()->GetLayout()).free_spacing;
2715 /* table stuff -- begin*/
2716 if (cursor.par()->table) {
2717 InsertCharInTable(bview, c);
2721 /* table stuff -- end*/
2723 /* First check, if there will be two blanks together or a blank at
2724 the beginning of a paragraph.
2725 I decided to handle blanks like normal characters, the main
2726 difference are the special checks when calculating the row.fill
2727 (blank does not count at the end of a row) and the check here */
2729 // The bug is triggered when we type in a description environment:
2730 // The current_font is not changed when we go from label to main text
2731 // and it should (along with realtmpfont) when we type the space.
2732 // CHECK There is a bug here! (Asger)
2734 LyXFont realtmpfont = real_current_font;
2735 LyXFont rawtmpfont = current_font; /* store the current font.
2736 * This is because of the use
2737 * of cursor movements. The moving
2738 * cursor would refresh the
2741 // Get the font that is used to calculate the baselineskip
2742 LyXParagraph::size_type lastpos = cursor.par()->Last();
2743 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
2746 bool jumped_over_space = false;
2748 if (!freeSpacing && IsLineSeparatorChar(c)) {
2749 if ((cursor.pos() > 0
2750 && cursor.par()->IsLineSeparator(cursor.pos() - 1))
2751 || (cursor.pos() > 0
2752 && cursor.par()->IsNewline(cursor.pos() - 1))
2753 || (cursor.pos() == 0
2754 && !(cursor.par()->Previous()
2755 && cursor.par()->Previous()->footnoteflag
2756 == LyXParagraph::OPEN_FOOTNOTE))) {
2757 if (cursor.pos() == 0 )
2758 bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2760 bview->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2764 } else if (IsNewlineChar(c)) {
2765 if (cursor.par()->FirstPhysicalPar() == cursor.par()
2766 && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
2770 /* No newline at first position
2771 * of a paragraph or behind labels.
2772 * TeX does not allow that. */
2774 if (cursor.pos() < cursor.par()->Last() &&
2775 cursor.par()->IsLineSeparator(cursor.pos()))
2776 // newline always after a blank!
2777 CursorRightIntern(bview);
2778 cursor.row()->fill(-1); // to force a new break
2781 // the display inset stuff
2782 if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
2783 && cursor.row()->par()->GetInset(cursor.row()->pos())
2784 && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
2785 cursor.row()->fill(-1); // to force a new break
2787 // get the cursor row fist
2788 Row * row = cursor.row();
2789 long y = cursor.y() - row->baseline();
2790 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2791 * already insertet the character */
2792 cursor.par()->InsertChar(cursor.pos(), c);
2793 SetCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
2795 if (!jumped_over_space) {
2796 // refresh the positions
2798 while (tmprow->next() && tmprow->next()->par() == row->par()) {
2799 tmprow = tmprow->next();
2800 tmprow->pos(tmprow->pos() + 1);
2804 // Is there a break one row above
2805 if ((cursor.par()->IsLineSeparator(cursor.pos())
2806 || cursor.par()->IsNewline(cursor.pos())
2807 || cursor.row()->fill() == -1)
2808 && row->previous() && row->previous()->par() == row->par()) {
2809 LyXParagraph::size_type z = NextBreakPoint(bview,
2812 if ( z >= row->pos()) {
2815 // set the dimensions of the row above
2816 row->previous()->fill(Fill(bview,
2820 SetHeightOfRow(bview, row->previous());
2822 y -= row->previous()->height();
2824 refresh_row = row->previous();
2825 status = LyXText::NEED_MORE_REFRESH;
2827 BreakAgainOneRow(bview, row);
2829 current_font = rawtmpfont;
2830 real_current_font = realtmpfont;
2831 SetCursor(bview, cursor.par(), cursor.pos() + 1,
2832 false, cursor.boundary());
2833 // cursor MUST be in row now.
2835 if (row->next() && row->next()->par() == row->par())
2836 need_break_row = row->next();
2840 // check, wether the last characters font has changed.
2841 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2842 && rawparfont != rawtmpfont)
2843 RedoHeightOfParagraph(bview, cursor);
2850 // recalculate the fill of the row
2851 if (row->fill() >= 0) /* needed because a newline
2852 * will set fill to -1. Otherwise
2853 * we would not get a rebreak! */
2854 row->fill(Fill(bview, row, workWidth(bview)));
2855 if (row->fill() < 0 ) {
2858 refresh_x = cursor.x();
2859 refresh_pos = cursor.pos();
2860 status = LyXText::NEED_MORE_REFRESH;
2861 BreakAgainOneRow(bview, row);
2862 // will the cursor be in another row now?
2863 if (RowLast(row) <= cursor.pos() + 1 && row->next()) {
2864 if (row->next() && row->next()->par() == row->par())
2865 // this should always be true
2867 BreakAgainOneRow(bview, row);
2869 current_font = rawtmpfont;
2870 real_current_font = realtmpfont;
2872 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2874 if (row->next() && row->next()->par() == row->par())
2875 need_break_row = row->next();
2880 refresh_x = cursor.x();
2882 refresh_pos = cursor.pos();
2884 int tmpheight = row->height();
2885 SetHeightOfRow(bview, row);
2886 if (tmpheight == row->height())
2887 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2889 status = LyXText::NEED_MORE_REFRESH;
2891 current_font = rawtmpfont;
2892 real_current_font = realtmpfont;
2893 SetCursor(bview, cursor.par(), cursor.pos() + 1, false,
2897 // check, wether the last characters font has changed.
2898 if (cursor.pos() && cursor.pos() == cursor.par()->Last()
2899 && rawparfont != rawtmpfont) {
2900 RedoHeightOfParagraph(bview, cursor);
2902 // now the special right address boxes
2903 if (textclasslist.Style(bview->buffer()->params.textclass,
2904 cursor.par()->GetLayout()).margintype
2905 == MARGIN_RIGHT_ADDRESS_BOX) {
2906 RedoDrawingOfParagraph(bview, cursor);
2914 void LyXText::charInserted()
2916 // Here we could call FinishUndo for every 20 characters inserted.
2917 // This is from my experience how emacs does it.
2918 static unsigned int counter = 0;
2928 void LyXText::PrepareToPrint(BufferView * bview,
2929 Row * row, float & x,
2930 float & fill_separator,
2932 float & fill_label_hfill,
2937 float w = row->fill();
2939 fill_label_hfill = 0;
2941 fill_label_hfill = 0;
2944 bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
2947 x = RightMargin(bview->buffer(), row);
2948 if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2949 LyXFont font(LyXFont::ALL_SANE);
2950 font.setSize(LyXFont::SIZE_SMALL);
2951 x += lyxfont::width("Mwide-figM", font);
2955 if (workWidth(bview) > 0)
2956 x = LeftMargin(bview, row);
2960 // is there a manual margin with a manual label
2961 if (textclasslist.Style(bview->buffer()->params.textclass,
2962 row->par()->GetLayout()).margintype == MARGIN_MANUAL
2963 && textclasslist.Style(bview->buffer()->params.textclass,
2964 row->par()->GetLayout()).labeltype == LABEL_MANUAL) {
2966 /* one more since labels are left aligned */
2967 nlh = NumberOfLabelHfills(bview->buffer(), row) + 1;
2968 if (nlh && !row->par()->GetLabelWidthString().empty()) {
2969 fill_label_hfill = LabelFill(bview, row) / nlh;
2973 // are there any hfills in the row?
2974 float nh = NumberOfHfills(bview->buffer(), row);
2977 /* table stuff -- begin*/
2978 if (row->par()->table) {
2979 w = workWidth(bview) - row->par()->table->WidthOfTable()
2980 - x - RightMargin(bview->buffer(), row);
2981 nh = 0; /* ignore hfills in tables */
2983 /* table stuff -- end*/
2988 // is it block, flushleft or flushright?
2989 // set x how you need it
2991 if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2992 align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
2994 align = row->par()->FirstPhysicalPar()->align;
2996 // center displayed insets
2997 if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
2998 && row->par()->GetInset(row->pos())
2999 && row->par()->GetInset(row->pos())->display())
3000 align = LYX_ALIGN_CENTER;
3003 case LYX_ALIGN_BLOCK:
3004 ns = NumberOfSeparators(bview->buffer(), row);
3005 if (ns && row->next() && row->next()->par() == row->par() &&
3006 !(row->next()->par()->IsNewline(row->next()->pos() - 1))
3007 && !(row->next()->par()->GetChar(row->next()->pos()) == LyXParagraph::META_INSET
3008 && row->next()->par()->GetInset(row->next()->pos())
3009 && row->next()->par()->GetInset(row->next()->pos())->display())
3011 fill_separator = w / ns;
3015 case LYX_ALIGN_RIGHT:
3018 case LYX_ALIGN_CENTER:
3026 ComputeBidiTables(bview->buffer(), row);
3028 LyXParagraph::size_type main_body =
3029 BeginningOfMainBody(bview->buffer(), row->par());
3030 LyXParagraph::size_type last = RowLast(row);
3032 if (main_body > 0 &&
3033 (main_body-1 > last ||
3034 !row->par()->IsLineSeparator(main_body-1))) {
3035 LyXLayout const & layout =
3036 textclasslist.Style(bview->buffer()->params.textclass,
3037 row->par()->GetLayout());
3038 x += lyxfont::width(layout.labelsep,
3039 GetFont(bview->buffer(), row->par(), -2));
3040 if (main_body-1 <= last)
3041 x += fill_label_hfill;
3046 /* important for the screen */
3049 /* the cursor set functions have a special mechanism. When they
3050 * realize, that you left an empty paragraph, they will delete it.
3051 * They also delete the corresponding row */
3053 void LyXText::CursorRightOneWord(BufferView * bview) const
3055 // treat floats, HFills and Insets as words
3056 LyXCursor tmpcursor = cursor;
3057 // CHECK See comment on top of text.C
3059 if (tmpcursor.pos() == tmpcursor.par()->Last()
3060 && tmpcursor.par()->Next()) {
3061 tmpcursor.par(tmpcursor.par()->Next());
3066 // Skip through initial nonword stuff.
3067 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3068 ! tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3070 // printf("Current pos1 %d", tmpcursor.pos()) ;
3071 tmpcursor.pos(tmpcursor.pos() + 1);
3074 // Advance through word.
3075 while ( tmpcursor.pos() < tmpcursor.par()->Last() &&
3076 tmpcursor.par()->IsWord( tmpcursor.pos() ) )
3078 // printf("Current pos2 %d", tmpcursor.pos()) ;
3079 tmpcursor.pos(tmpcursor.pos() + 1);
3083 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3087 void LyXText::CursorTab(BufferView * bview) const
3090 if (cursor.par()->table) {
3091 int cell = NumberOfCell(cursor.par(), cursor.pos());
3092 while(cursor.par()->table->IsContRow(cell)) {
3094 cell = NumberOfCell(cursor.par(), cursor.pos());
3096 if (cursor.par()->table->ShouldBeVeryLastCell(cell))
3097 TableFeatures(bview, LyXTable::APPEND_ROW);
3100 LyXCursor tmpcursor = cursor;
3101 while (tmpcursor.pos() < tmpcursor.par()->Last()
3102 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3103 tmpcursor.pos(tmpcursor.pos() + 1);
3105 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3106 if (tmpcursor.par()->Next()) {
3107 tmpcursor.par(tmpcursor.par()->Next());
3111 tmpcursor.pos(tmpcursor.pos() + 1);
3112 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3114 if (cursor.par()->table) {
3115 int cell = NumberOfCell(cursor.par(), cursor.pos());
3116 while (cursor.par()->table->IsContRow(cell) &&
3117 !cursor.par()->table->ShouldBeVeryLastCell(cell)) {
3119 while (tmpcursor.pos() < tmpcursor.par()->Last()
3120 && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
3121 tmpcursor.pos(tmpcursor.pos() + 1);
3123 if (tmpcursor.pos() == tmpcursor.par()->Last()){
3124 if (tmpcursor.par()->Next()) {
3125 tmpcursor.par(tmpcursor.par()->Next());
3129 tmpcursor.pos(tmpcursor.pos() + 1);
3130 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3131 cell = NumberOfCell(cursor.par(), cursor.pos());
3138 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3139 of prior word, not to end of next prior word. */
3141 void LyXText::CursorLeftOneWord(BufferView * bview) const
3143 // treat HFills, floats and Insets as words
3144 LyXCursor tmpcursor = cursor;
3145 while (tmpcursor.pos()
3146 && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1)
3147 || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
3148 && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
3149 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3150 || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
3151 tmpcursor.pos(tmpcursor.pos() - 1);
3154 && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
3155 || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
3156 || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
3157 tmpcursor.pos(tmpcursor.pos() - 1);
3158 } else if (!tmpcursor.pos()) {
3159 if (tmpcursor.par()->Previous()){
3160 tmpcursor.par(tmpcursor.par()->Previous());
3161 tmpcursor.pos(tmpcursor.par()->Last());
3163 } else { // Here, tmpcursor != 0
3164 while (tmpcursor.pos() > 0 &&
3165 tmpcursor.par()->IsWord(tmpcursor.pos()-1) )
3166 tmpcursor.pos(tmpcursor.pos() - 1);
3168 SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
3171 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3174 void LyXText::SelectWord(BufferView * bview)
3176 // Move cursor to the beginning, when not already there.
3178 && !cursor.par()->IsSeparator(cursor.pos()-1)
3179 && !cursor.par()->IsKomma(cursor.pos()-1) )
3180 CursorLeftOneWord(bview);
3182 // set the sel cursor
3183 sel_cursor = cursor;
3185 while ( cursor.pos() < cursor.par()->Last()
3186 && !cursor.par()->IsSeparator(cursor.pos())
3187 && !cursor.par()->IsKomma(cursor.pos()) )
3188 cursor.pos(cursor.pos() + 1);
3189 SetCursor(bview, cursor.par(), cursor.pos() );
3191 // finally set the selection
3196 /* -------> Select the word currently under the cursor when:
3197 1: no selection is currently set,
3198 2: the cursor is not at the borders of the word. */
3200 bool LyXText::SelectWordWhenUnderCursor(BufferView * bview)
3203 cursor.pos() > 0 && cursor.pos() < cursor.par()->Last()
3204 && !cursor.par()->IsSeparator(cursor.pos())
3205 && !cursor.par()->IsKomma(cursor.pos())
3206 && !cursor.par()->IsSeparator(cursor.pos() -1)
3207 && !cursor.par()->IsKomma(cursor.pos() -1) ) {
3215 // This function is only used by the spellchecker for NextWord().
3216 // It doesn't handle LYX_ACCENTs and probably never will.
3217 char * LyXText::SelectNextWord(BufferView * bview, float & value)
3219 LyXParagraph * tmppar = cursor.par();
3221 // If this is not the very first word, skip rest of
3222 // current word because we are probably in the middle
3223 // of a word if there is text here.
3224 if (cursor.pos() || cursor.par()->previous) {
3225 while (cursor.pos() < cursor.par()->Last()
3226 && cursor.par()->IsLetter(cursor.pos()))
3227 cursor.pos(cursor.pos() + 1);
3229 // Now, skip until we have real text (will jump paragraphs)
3230 while ((cursor.par()->Last() > cursor.pos()
3231 && (!cursor.par()->IsLetter(cursor.pos())
3232 || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
3233 .latex() == LyXFont::ON))
3234 || (cursor.par()->Last() == cursor.pos()
3235 && cursor.par()->Next())){
3236 if (cursor.pos() == cursor.par()->Last()) {
3237 cursor.par(cursor.par()->Next());
3240 cursor.pos(cursor.pos() + 1);
3243 // Update the value if we changed paragraphs
3244 if (cursor.par() != tmppar){
3245 SetCursor(bview, cursor.par(), cursor.pos());
3246 value = float(cursor.y())/float(height);
3249 // Start the selection from here
3250 sel_cursor = cursor;
3253 std::ostringstream latex;
3257 // and find the end of the word
3258 // (optional hyphens are part of a word)
3259 while (cursor.pos() < cursor.par()->Last()
3260 && (cursor.par()->IsLetter(cursor.pos()))
3261 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3262 && cursor.par()->GetInset(cursor.pos()) != 0
3263 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3265 && latex.str() == "\\-"
3267 && latex.str() // protect against null pointers
3268 && string(latex.str(), 3) == "\\-" // this is not nice at all
3271 cursor.pos(cursor.pos() + 1);
3273 #ifndef HAVE_SSTREAM
3274 delete [] latex.str();
3276 // Finally, we copy the word to a string and return it
3279 if (sel_cursor.pos() < cursor.pos()) {
3280 str = new char [cursor.pos() - sel_cursor.pos() + 2];
3281 LyXParagraph::size_type i, j;
3282 for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) {
3283 if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET)
3284 str[j++] = cursor.par()->GetChar(i);
3292 // This one is also only for the spellchecker
3293 void LyXText::SelectSelectedWord(BufferView * bview)
3295 // move cursor to the beginning
3296 SetCursor(bview, sel_cursor.par(), sel_cursor.pos());
3298 // set the sel cursor
3299 sel_cursor = cursor;
3302 std::ostringstream latex;
3307 // now find the end of the word
3308 while (cursor.pos() < cursor.par()->Last()
3309 && (cursor.par()->IsLetter(cursor.pos())
3310 || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
3311 && cursor.par()->GetInset(cursor.pos()) != 0
3312 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
3314 && latex.str() == "\\-"
3316 && string(latex.str(), 3) == "\\-"
3319 cursor.pos(cursor.pos() + 1);
3321 #ifndef HAVE_SSTREAM
3322 delete [] latex.str();
3324 SetCursor(bview, cursor.par(), cursor.pos());
3326 // finally set the selection
3331 /* -------> Delete from cursor up to the end of the current or next word. */
3332 void LyXText::DeleteWordForward(BufferView * bview)
3334 if (!cursor.par()->Last())
3337 LyXCursor tmpcursor = cursor;
3338 tmpcursor.row(0); //Â ??
3339 selection = true; // to avoid deletion
3340 CursorRightOneWord(bview);
3341 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3342 sel_cursor = cursor;
3346 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3347 CutSelection(bview);
3352 /* -------> Delete from cursor to start of current or prior word. */
3353 void LyXText::DeleteWordBackward(BufferView * bview)
3355 if (!cursor.par()->Last())
3358 LyXCursor tmpcursor = cursor;
3359 tmpcursor.row(0); // ??
3360 selection = true; // to avoid deletion
3361 CursorLeftOneWord(bview);
3362 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3363 sel_cursor = cursor;
3366 CutSelection(bview);
3371 /* -------> Kill to end of line. */
3372 void LyXText::DeleteLineForward(BufferView * bview)
3374 if (!cursor.par()->Last())
3375 // Paragraph is empty, so we just go to the right
3378 LyXCursor tmpcursor = cursor;
3379 // We can't store the row over a regular SetCursor
3380 // so we set it to 0 and reset it afterwards.
3381 tmpcursor.row(0); //Â ??
3382 selection = true; // to avoid deletion
3384 SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
3385 sel_cursor = cursor;
3388 // What is this test for ??? (JMarc)
3390 DeleteWordForward(bview);
3392 CutSelection(bview);
3398 // Change the case of a word at cursor position.
3399 // This function directly manipulates LyXParagraph::text because there
3400 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3401 // that it is correct. I guess part of it should be moved to
3402 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3403 // it does not access outside of the allocated array as the older
3404 // version did. (JMarc)
3405 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action)
3407 LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
3409 SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next);
3411 LyXParagraph::size_type tmppos =
3412 cursor.par()->PositionInParFromPos(cursor.pos());
3413 while (tmppos < tmppar->size()) {
3414 unsigned char c = tmppar->GetChar(tmppos);
3415 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3417 if (c != LyXParagraph::META_INSET) {
3419 case text_lowercase:
3422 case text_capitalization:
3424 action = text_lowercase;
3426 case text_uppercase:
3432 //tmppar->text[tmppos] = c;
3433 tmppar->SetChar(tmppos, c);
3436 CheckParagraph(bview, tmppar, tmppos);
3437 CursorRightOneWord(bview);
3441 void LyXText::Delete(BufferView * bview)
3443 // this is a very easy implementation
3445 LyXCursor old_cursor = cursor;
3446 int old_cur_par_id = old_cursor.par()->id();
3447 int old_cur_par_prev_id = old_cursor.par()->previous ?
3448 old_cursor.par()->previous->id() : 0;
3450 // just move to the right
3451 CursorRightIntern(bview);
3453 // CHECK Look at the comment here.
3454 // This check is not very good...
3455 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3456 // and that can very well delete the par or par->previous in
3457 // old_cursor. Will a solution where we compare paragraph id's
3459 if ((cursor.par()->previous ? cursor.par()->previous->id() : 0)
3460 == old_cur_par_prev_id
3461 && cursor.par()->id() != old_cur_par_id)
3462 return; // delete-empty-paragraph-mechanism has done it
3464 // if you had success make a backspace
3465 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
3466 LyXCursor tmpcursor = cursor;
3467 cursor = old_cursor; // to make sure undo gets the right cursor position
3468 SetUndo(bview->buffer(), Undo::DELETE,
3469 cursor.par()->ParFromPos(cursor.pos())->previous,
3470 cursor.par()->ParFromPos(cursor.pos())->next);
3477 void LyXText::Backspace(BufferView * bview)
3480 /* table stuff -- begin */
3481 if (cursor.par()->table) {
3482 BackspaceInTable(bview);
3485 /* table stuff -- end */
3487 // LyXFont rawtmpfont = current_font;
3488 // LyXFont realtmpfont = real_current_font;
3489 // We don't need the above variables as calling to SetCursor() with third
3490 // argument eqaul to false, will not change current_font & real_current_font
3492 // Get the font that is used to calculate the baselineskip
3493 LyXParagraph::size_type lastpos = cursor.par()->Last();
3494 LyXFont rawparfont = cursor.par()->GetFontSettings(bview->buffer()->params,
3497 if (cursor.pos() == 0) {
3498 // The cursor is at the beginning of a paragraph, so the the backspace
3499 // will collapse two paragraphs into one.
3501 // we may paste some paragraphs
3503 // is it an empty paragraph?
3506 || (lastpos == 1 && cursor.par()->IsSeparator(0)))
3507 && !(cursor.par()->Next()
3508 && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
3509 && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3510 // This is an empty paragraph and we delete it just by moving the cursor one step
3511 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
3512 // of the paragraph.
3514 if (cursor.par()->previous) {
3515 LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
3516 if (cursor.par()->GetLayout() == tmppar->GetLayout()
3517 && cursor.par()->footnoteflag == tmppar->footnoteflag
3518 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3519 // Inherit botom DTD from the paragraph below.
3520 // (the one we are deleting)
3521 tmppar->line_bottom = cursor.par()->line_bottom;
3522 tmppar->added_space_bottom = cursor.par()->added_space_bottom;
3523 tmppar->pagebreak_bottom = cursor.par()->pagebreak_bottom;
3526 CursorLeftIntern(bview);
3528 // the layout things can change the height of a row !
3529 int tmpheight = cursor.row()->height();
3530 SetHeightOfRow(bview, cursor.row());
3531 if (cursor.row()->height() != tmpheight) {
3532 refresh_y = cursor.y() - cursor.row()->baseline();
3533 refresh_row = cursor.row();
3534 status = LyXText::NEED_MORE_REFRESH;
3540 if (cursor.par()->ParFromPos(cursor.pos())->previous){
3541 SetUndo(bview->buffer(), Undo::DELETE,
3542 cursor.par()->ParFromPos(cursor.pos())->previous->previous,
3543 cursor.par()->ParFromPos(cursor.pos())->next);
3546 LyXParagraph * tmppar = cursor.par();
3547 Row * tmprow = cursor.row();
3549 // We used to do CursorLeftIntern() here, but it is
3550 // not a good idea since it triggers the auto-delete
3551 // mechanism. So we do a CursorLeftIntern()-lite,
3552 // without the dreaded mechanism. (JMarc)
3553 if (cursor.par()->Previous()) {
3554 // steps into the above paragraph.
3555 SetCursorIntern(bview, cursor.par()->Previous(),
3556 cursor.par()->Previous()->Last(), false);
3559 /* Pasting is not allowed, if the paragraphs have different
3560 layout. I think it is a real bug of all other
3561 word processors to allow it. It confuses the user.
3562 Even so with a footnote paragraph and a non-footnote
3563 paragraph. I will not allow pasting in this case,
3564 because the user would be confused if the footnote behaves
3565 different wether it is open or closed.
3567 Correction: Pasting is always allowed with standard-layout
3569 if (cursor.par() != tmppar
3570 && (cursor.par()->GetLayout() == tmppar->GetLayout()
3571 || tmppar->GetLayout() == 0 /*standard*/)
3572 && cursor.par()->footnoteflag == tmppar->footnoteflag
3574 /* table stuff -- begin*/
3575 && !cursor.par()->table /* no pasting of tables */
3576 /* table stuff -- end*/
3578 && cursor.par()->GetAlign() == tmppar->GetAlign()) {
3580 RemoveParagraph(tmprow);
3582 cursor.par()->PasteParagraph(bview->buffer()->params);
3584 if (!cursor.pos() || !cursor.par()->IsSeparator(cursor.pos() - 1))
3585 ; //cursor.par()->InsertChar(cursor.pos(), ' ');
3586 // strangely enough it seems that commenting out the line above removes
3587 // most or all of the segfaults. I will however also try to move the
3588 // two Remove... lines in front of the PasteParagraph too.
3591 cursor.pos(cursor.pos() - 1);
3593 status = LyXText::NEED_MORE_REFRESH;
3594 refresh_row = cursor.row();
3595 refresh_y = cursor.y() - cursor.row()->baseline();
3597 // remove the lost paragraph
3598 // This one is not safe, since the paragraph that the tmprow and the
3599 // following rows belong to has been deleted by the PasteParagraph
3600 // above. The question is... could this be moved in front of the
3602 //RemoveParagraph(tmprow);
3603 //RemoveRow(tmprow);
3605 // This rebuilds the rows.
3606 AppendParagraph(bview, cursor.row());
3607 UpdateCounters(bview, cursor.row());
3609 // the row may have changed, block, hfills etc.
3610 SetCursor(bview, cursor.par(), cursor.pos(), false);
3613 /* this is the code for a normal backspace, not pasting
3615 SetUndo(bview->buffer(), Undo::DELETE,
3616 cursor.par()->ParFromPos(cursor.pos())->previous,
3617 cursor.par()->ParFromPos(cursor.pos())->next);
3618 // We used to do CursorLeftIntern() here, but it is
3619 // not a good idea since it triggers the auto-delete
3620 // mechanism. So we do a CursorLeftIntern()-lite,
3621 // without the dreaded mechanism. (JMarc)
3622 SetCursorIntern(bview, cursor.par(), cursor.pos()- 1,
3623 false, cursor.boundary());
3625 // some insets are undeletable here
3626 if (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
3627 if (!cursor.par()->GetInset(cursor.pos())->Deletable())
3629 // force complete redo when erasing display insets
3630 // this is a cruel method but safe..... Matthias
3631 if (cursor.par()->GetInset(cursor.pos())->display()){
3632 cursor.par()->Erase(cursor.pos());
3633 RedoParagraph(bview);
3638 Row * row = cursor.row();
3639 long y = cursor.y() - row->baseline();
3640 LyXParagraph::size_type z;
3641 /* remember that a space at the end of a row doesnt count
3642 * when calculating the fill */
3643 if (cursor.pos() < RowLast(row) ||
3644 !cursor.par()->IsLineSeparator(cursor.pos())) {
3645 row->fill(row->fill() + SingleWidth(bview,
3650 /* some special code when deleting a newline. This is similar
3651 * to the behavior when pasting paragraphs */
3652 if (cursor.pos() && cursor.par()->IsNewline(cursor.pos())) {
3653 cursor.par()->Erase(cursor.pos());
3654 // refresh the positions
3656 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3657 tmprow = tmprow->next();
3658 tmprow->pos(tmprow->pos() - 1);
3660 if (cursor.par()->IsLineSeparator(cursor.pos() - 1))
3661 cursor.pos(cursor.pos() - 1);
3663 if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
3664 cursor.par()->InsertChar(cursor.pos(), ' ');
3665 // refresh the positions
3667 while (tmprow->next() && tmprow->next()->par() == row->par()) {
3668 tmprow = tmprow->next();
3669 tmprow->pos(tmprow->pos() + 1);
3673 cursor.par()->Erase(cursor.pos());
3675 // refresh the positions
3677 while (tmprow->next()
3678 && tmprow->next()->par() == row->par()) {
3679 tmprow = tmprow->next();
3680 tmprow->pos(tmprow->pos() - 1);
3683 // delete newlines at the beginning of paragraphs
3684 while (cursor.par()->Last() &&
3685 cursor.par()->IsNewline(cursor.pos()) &&
3686 cursor.pos() == BeginningOfMainBody(bview->buffer(),
3688 cursor.par()->Erase(cursor.pos());
3689 // refresh the positions
3691 while (tmprow->next() &&
3692 tmprow->next()->par() == row->par()) {
3693 tmprow = tmprow->next();
3694 tmprow->pos(tmprow->pos() - 1);
3699 // is there a break one row above
3700 if (row->previous() && row->previous()->par() == row->par()) {
3701 z = NextBreakPoint(bview, row->previous(),
3703 if ( z >= row->pos()) {
3706 Row * tmprow = row->previous();
3708 // maybe the current row is now empty
3709 if (row->pos() >= row->par()->Last()) {
3714 BreakAgainOneRow(bview, row);
3715 if (row->next() && row->next()->par() == row->par())
3716 need_break_row = row->next();
3721 // set the dimensions of the row above
3722 y -= tmprow->height();
3723 tmprow->fill(Fill(bview, tmprow,
3725 SetHeightOfRow(bview, tmprow);
3728 refresh_row = tmprow;
3729 status = LyXText::NEED_MORE_REFRESH;
3730 SetCursor(bview, cursor.par(), cursor.pos(),
3731 false, cursor.boundary());
3732 //current_font = rawtmpfont;
3733 //real_current_font = realtmpfont;
3734 // check, whether the last character's font has changed.
3736 cursor.par()->GetFontSettings(bview->buffer()->params,
3737 cursor.par()->Last() - 1))
3738 RedoHeightOfParagraph(bview, cursor);
3743 // break the cursor row again
3744 z = NextBreakPoint(bview, row, workWidth(bview));
3746 if (z != RowLast(row) ||
3747 (row->next() && row->next()->par() == row->par() &&
3748 RowLast(row) == row->par()->Last() - 1)){
3750 /* it can happen that a paragraph loses one row
3751 * without a real breakup. This is when a word
3752 * is to long to be broken. Well, I don t care this
3754 if (row->next() && row->next()->par() == row->par() &&
3755 RowLast(row) == row->par()->Last() - 1)
3756 RemoveRow(row->next());
3760 status = LyXText::NEED_MORE_REFRESH;
3762 BreakAgainOneRow(bview, row);
3763 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3764 // cursor MUST be in row now
3766 if (row->next() && row->next()->par() == row->par())
3767 need_break_row = row->next();
3771 // set the dimensions of the row
3772 row->fill(Fill(bview, row, workWidth(bview)));
3773 int tmpheight = row->height();
3774 SetHeightOfRow(bview, row);
3775 if (tmpheight == row->height())
3776 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3778 status = LyXText::NEED_MORE_REFRESH;
3781 SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
3785 // current_font = rawtmpfont;
3786 // real_current_font = realtmpfont;
3788 lastpos = cursor.par()->Last();
3789 if (cursor.pos() == lastpos) {
3790 SetCurrentFont(bview);
3791 if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
3792 SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
3795 // check, wether the last characters font has changed.
3797 cursor.par()->GetFontSettings(bview->buffer()->params, lastpos - 1)) {
3798 RedoHeightOfParagraph(bview, cursor);
3800 // now the special right address boxes
3801 if (textclasslist.Style(bview->buffer()->params.textclass,
3802 cursor.par()->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3803 RedoDrawingOfParagraph(bview, cursor);
3809 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
3810 Row * row_ptr, long y)
3812 /* returns a printed row */
3813 Painter & pain = bview->painter();
3815 bool is_rtl = row_ptr->par()->isRightToLeftPar(bview->buffer()->params);
3816 LyXParagraph::size_type last = RowLastPrintable(row_ptr);
3818 LyXParagraph::size_type vpos, pos;
3820 int y_top, y_bottom;
3821 float fill_separator, fill_hfill, fill_label_hfill;
3823 LyXFont font(LyXFont::ALL_SANE);
3825 if (row_ptr->height() <= 0) {
3826 lyxerr << "LYX_ERROR: row.height: "
3827 << row_ptr->height() << endl;
3830 PrepareToPrint(bview, row_ptr, x, fill_separator,
3831 fill_hfill, fill_label_hfill);
3835 // clear the area where we want to paint/print
3837 ww = bview->workWidth();
3839 bool clear_area = true;
3842 if ((last == row_ptr->pos()) &&
3843 (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
3844 (inset=row_ptr->par()->GetInset(row_ptr->pos())))
3846 clear_area = inset->doClearArea();
3851 w = inset_owner->width(bview->painter(), font);
3854 pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
3855 } else if (inset != 0) {
3856 int h = row_ptr->baseline() - inset->ascent(pain, font);
3860 w = inset_owner->width(bview->painter(), font);
3863 pain.fillRectangle(x_offset, y_offset, w, h);
3868 /* selection code */
3869 if (bidi_same_direction) {
3870 if (sel_start_cursor.row() == row_ptr &&
3871 sel_end_cursor.row() == row_ptr) {
3872 if (sel_start_cursor.x() < sel_end_cursor.x())
3873 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3875 sel_end_cursor.x() - sel_start_cursor.x(),
3879 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3881 sel_start_cursor.x() - sel_end_cursor.x(),
3884 } else if (sel_start_cursor.row() == row_ptr) {
3886 pain.fillRectangle(x_offset, y_offset,
3887 sel_start_cursor.x(),
3891 pain.fillRectangle(x_offset + sel_start_cursor.x(),
3893 ww - sel_start_cursor.x(),
3896 } else if (sel_end_cursor.row() == row_ptr) {
3898 pain.fillRectangle(x_offset + sel_end_cursor.x(),
3900 ww - sel_end_cursor.x(),
3904 pain.fillRectangle(x_offset, y_offset,
3908 } else if (y > long(sel_start_cursor.y())
3909 && y < long(sel_end_cursor.y())) {
3910 pain.fillRectangle(x_offset, y_offset, ww,
3914 } else if ( sel_start_cursor.row() != row_ptr &&
3915 sel_end_cursor.row() != row_ptr &&
3916 y > long(sel_start_cursor.y())
3917 && y < long(sel_end_cursor.y())) {
3918 pain.fillRectangle(x_offset, y_offset, ww,
3921 } else if (sel_start_cursor.row() == row_ptr ||
3922 sel_end_cursor.row() == row_ptr) {
3926 if (row_ptr->par()->table) {
3927 cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
3928 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3931 if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
3932 (sel_end_cursor.row() != row_ptr && is_rtl))
3933 pain.fillRectangle(x_offset, y_offset,
3938 if (row_ptr->par()->table) {
3940 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3941 pos = vis2log(vpos);
3942 float old_tmpx = tmpx;
3943 if (row_ptr->par()->IsNewline(pos)) {
3944 tmpx = x_old + row_ptr->par()->table->WidthOfColumn(cell);
3947 tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
3949 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3951 if ( (sel_start_cursor.row() != row_ptr ||
3952 sel_start_cursor.pos() <= pos) &&
3953 (sel_end_cursor.row() != row_ptr ||
3954 pos < sel_end_cursor.pos()) )
3955 pain.fillRectangle(x_offset + int(old_tmpx),
3957 int(tmpx - old_tmpx + 1),
3963 LyXParagraph::size_type main_body =
3964 BeginningOfMainBody(bview->buffer(),
3967 for (vpos = row_ptr->pos(); vpos <= last; ++vpos) {
3968 pos = vis2log(vpos);
3969 float old_tmpx = tmpx;
3970 if (main_body > 0 && pos == main_body-1) {
3971 tmpx += fill_label_hfill +
3972 lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
3973 row_ptr->par()->GetLayout()).labelsep,
3974 GetFont(bview->buffer(),row_ptr->par(), -2));
3975 if (row_ptr->par()->IsLineSeparator(main_body-1))
3976 tmpx -= SingleWidth(bview, row_ptr->par(), main_body-1);
3978 if (HfillExpansion(bview->buffer(), row_ptr, pos)) {
3979 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3980 if (pos >= main_body)
3983 tmpx += fill_label_hfill;
3985 else if (row_ptr->par()->IsSeparator(pos)) {
3986 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3987 if (pos >= main_body)
3988 tmpx += fill_separator;
3990 tmpx += SingleWidth(bview, row_ptr->par(), pos);
3992 if ( (sel_start_cursor.row() != row_ptr ||
3993 sel_start_cursor.pos() <= pos) &&
3994 (sel_end_cursor.row() != row_ptr ||
3995 pos < sel_end_cursor.pos()) )
3996 pain.fillRectangle(x_offset + int(old_tmpx),
3998 int(tmpx - old_tmpx + 1),
4005 if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
4006 (sel_end_cursor.row() != row_ptr && !is_rtl) )
4007 pain.fillRectangle(x_offset + int(tmpx),
4017 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4018 LyXFont font(LyXFont::ALL_SANE);
4019 font.setSize(LyXFont::SIZE_FOOTNOTE);
4020 font.setColor(LColor::footnote);
4022 box_x = LYX_PAPER_MARGIN + lyxfont::width(" wide-tab ", font);
4023 if (row_ptr->previous() &&
4024 row_ptr->previous()->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4026 switch (row_ptr->par()->footnotekind) {
4027 case LyXParagraph::MARGIN:
4030 case LyXParagraph::FIG:
4033 case LyXParagraph::TAB:
4036 case LyXParagraph::WIDE_FIG:
4039 case LyXParagraph::WIDE_TAB:
4042 case LyXParagraph::ALGORITHM:
4045 case LyXParagraph::FOOTNOTE:
4050 pain.fillRectangle(LYX_PAPER_MARGIN,
4052 box_x - LYX_PAPER_MARGIN,
4053 int(lyxfont::maxAscent(font)
4054 + lyxfont::maxDescent(font)),
4055 LColor::footnotebg);
4057 pain.line(LYX_PAPER_MARGIN, y_offset,
4058 workWidth(bview) - LYX_PAPER_MARGIN, y_offset,
4059 LColor::footnoteframe);
4061 pain.text(LYX_PAPER_MARGIN,
4062 y_offset + int(lyxfont::maxAscent(font)) + 1,
4065 pain.line(LYX_PAPER_MARGIN, y_offset,
4067 y_offset + int(lyxfont::maxAscent(font)
4068 + lyxfont::maxDescent(font)),
4069 LColor::footnoteframe);
4071 pain.line(LYX_PAPER_MARGIN,
4072 y_offset + int(lyxfont::maxAscent(font)
4073 + lyxfont::maxDescent(font)) + 1,
4075 y_offset + int(lyxfont::maxAscent(font)
4076 + lyxfont::maxDescent(font)) + 1,
4077 LColor::footnoteframe);
4081 /* draw the open floats in a red box */
4082 pain.line(box_x, y_offset,
4083 box_x, y_offset + row_ptr->height(),
4084 LColor::footnoteframe);
4086 pain.line(workWidth(bview) - LYX_PAPER_MARGIN,
4088 workWidth(bview) - LYX_PAPER_MARGIN,
4089 y_offset + row_ptr->height(),
4090 LColor::footnoteframe);
4093 // Draw appendix lines
4094 LyXParagraph * p = row_ptr->par()->PreviousBeforeFootnote()->FirstPhysicalPar();
4096 pain.line(1, y_offset,
4097 1, y_offset + row_ptr->height(),
4098 LColor::appendixline);
4099 pain.line(workWidth(bview) - 2, y_offset,
4100 workWidth(bview) - 2,
4101 y_offset + row_ptr->height(),
4102 LColor::appendixline);
4105 // Draw minipage line
4106 bool minipage = p->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4108 pain.line(LYX_PAPER_MARGIN/5, y_offset,
4110 y_offset + row_ptr->height() - 1,
4111 LColor::minipageline);
4114 int depth = p->GetDepth();
4115 for (int i = 1; i <= depth; ++i) {
4116 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage);
4117 pain.line(line_x, y_offset, line_x,
4118 y_offset + row_ptr->height() - 1,
4121 } else if (row_ptr->previous() &&
4122 row_ptr->previous()->par()->footnoteflag
4123 == LyXParagraph::OPEN_FOOTNOTE) {
4124 LyXFont font(LyXFont::ALL_SANE);
4125 font.setSize(LyXFont::SIZE_FOOTNOTE);
4127 int box_x = LYX_PAPER_MARGIN;
4128 box_x += lyxfont::width(" wide-tab ", font);
4130 pain.line(box_x, y_offset,
4131 workWidth(bview) - LYX_PAPER_MARGIN,
4132 y_offset, LColor::footnote);
4135 // Draw appendix lines
4136 LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
4137 if (firstpar->appendix){
4138 pain.line(1, y_offset,
4139 1, y_offset + row_ptr->height(),
4140 LColor::appendixline);
4141 pain.line(ww - 2, y_offset,
4142 ww - 2, y_offset + row_ptr->height(),
4143 LColor::appendixline);
4146 // Draw minipage line
4147 bool minipage = firstpar->pextra_type == LyXParagraph::PEXTRA_MINIPAGE;
4149 pain.line(LYX_PAPER_MARGIN/5 + box_x, y_offset,
4150 LYX_PAPER_MARGIN/5 + box_x,
4151 y_offset + row_ptr->height() - 1,
4152 LColor::minipageline);
4155 int depth = firstpar->GetDepth();
4159 if (row_ptr->next())
4160 if (row_ptr->par()->footnoteflag ==
4161 row_ptr->next()->par()->footnoteflag)
4162 next_depth = row_ptr->next()->par()->GetDepth();
4163 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4166 if (row_ptr->previous())
4167 if (row_ptr->par()->footnoteflag ==
4168 row_ptr->previous()->par()->footnoteflag)
4169 prev_depth = row_ptr->previous()->par()->GetDepth();
4170 else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
4173 for (int i = 1; i <= depth; ++i) {
4174 int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
4175 pain.line(line_x, y_offset, line_x,
4176 y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
4180 pain.fillRectangle(line_x, y_offset, LYX_PAPER_MARGIN / 5, 2,
4183 pain.fillRectangle(line_x,
4184 y_offset + row_ptr->height() - 2 - (i - next_depth - 1) * 3,
4185 LYX_PAPER_MARGIN / 5, 2,
4191 LyXLayout const & layout =
4192 textclasslist.Style(bview->buffer()->params.textclass,
4193 row_ptr->par()->GetLayout());
4196 y_bottom = row_ptr->height();
4198 /* is it a first row? */
4199 if (!row_ptr->pos() && (row_ptr->par() == firstpar)) {
4201 /* start of appendix? */
4202 if (row_ptr->par()->start_of_appendix){
4203 pain.line(1, y_offset,
4205 LColor::appendixline);
4208 /* think about the margins */
4209 if (!row_ptr->previous() && bv_owner)
4210 y_top += LYX_PAPER_MARGIN;
4212 if (row_ptr->par()->pagebreak_top){ /* draw a top pagebreak */
4214 pb_font.setColor(LColor::pagebreak).decSize();
4215 int w = 0, a = 0, d = 0;
4216 pain.line(0, y_offset + y_top + 2*DefaultHeight(),
4218 y_offset + y_top + 2 * DefaultHeight(),
4220 Painter::line_onoffdash)
4223 _("Page Break (top)"),
4226 LColor::background, false, w, a, d);
4227 pain.rectText((ww - w)/2,
4228 y_offset + y_top + 2 * DefaultHeight() + d,
4229 _("Page Break (top)"),
4232 LColor::background);
4233 y_top += 3 * DefaultHeight();
4236 if (row_ptr->par()->added_space_top.kind() == VSpace::VFILL) {
4237 /* draw a vfill top */
4238 pain.line(0, y_offset + 2 + y_top,
4239 LYX_PAPER_MARGIN, y_offset + 2 + y_top,
4242 pain.line(0, y_offset + y_top + 3 * DefaultHeight(),
4244 y_offset + y_top + 3 * DefaultHeight(),
4247 pain.line(LYX_PAPER_MARGIN / 2, y_offset + 2 + y_top,
4248 LYX_PAPER_MARGIN / 2,
4249 y_offset + y_top + 3 * DefaultHeight(),
4252 y_top += 3 * DefaultHeight();
4255 /* think about user added space */
4256 y_top += int(row_ptr->par()->added_space_top.inPixels(bview));
4258 /* think about the parskip */
4259 /* some parskips VERY EASY IMPLEMENTATION */
4260 if (bview->buffer()->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
4261 if (layout.latextype == LATEX_PARAGRAPH
4262 && firstpar->GetDepth() == 0
4263 && firstpar->Previous())
4264 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4265 else if (firstpar->Previous()
4266 && textclasslist.Style(bview->buffer()->params.textclass,
4267 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4268 && firstpar->Previous()->GetDepth() == 0)
4269 // is it right to use defskip here, too? (AS)
4270 y_top += bview->buffer()->params.getDefSkip().inPixels(bview);
4273 if (row_ptr->par()->line_top) { /* draw a top line */
4274 y_top += lyxfont::ascent('x',
4275 GetFont(bview->buffer(),
4276 row_ptr->par(), 0));
4278 pain.line(0, y_offset + y_top,
4279 ww, y_offset + y_top,
4281 Painter::line_solid,
4282 Painter::line_thick);
4284 y_top += lyxfont::ascent('x',GetFont(bview->buffer(),
4285 row_ptr->par(), 0));
4288 /* should we print a label? */
4289 if (layout.labeltype >= LABEL_STATIC
4290 && (layout.labeltype != LABEL_STATIC
4291 || layout.latextype != LATEX_ENVIRONMENT
4292 || row_ptr->par()->IsFirstInSequence())) {
4293 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4294 if (!row_ptr->par()->GetLabelstring().empty()) {
4296 string tmpstring = row_ptr->par()->GetLabelstring();
4298 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4299 if (bview->buffer()->params.secnumdepth >= 0) {
4300 /* this is special code for the chapter layout. This is printed in
4301 * an extra row and has a pagebreak at the top. */
4302 float spacing_val = 1.0;
4303 if (!row_ptr->par()->spacing.isDefault()) {
4304 spacing_val = row_ptr->par()->spacing.getValue();
4306 spacing_val = bview->buffer()->params.spacing.getValue();
4309 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
4310 + int(layout.parsep) * DefaultHeight();
4312 tmpx = ww - LeftMargin(bview, row_ptr) -
4313 lyxfont::width(tmpstring, font);
4314 pain.text(int(tmpx),
4315 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text() - maxdesc,
4320 tmpx = ww - LeftMargin(bview, row_ptr)
4321 + lyxfont::width(layout.labelsep, font);
4322 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4323 LyXFont font(LyXFont::ALL_SANE);
4324 font.setSize(LyXFont::SIZE_SMALL);
4325 tmpx += lyxfont::width("Mwide-fixM", font);
4328 tmpx = x - lyxfont::width(layout.labelsep, font)
4329 - lyxfont::width(tmpstring, font);
4332 pain.text(int(tmpx),
4333 y_offset + row_ptr->baseline(),
4337 /* the labels at the top of an environment. More or less for bibliography */
4338 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4339 layout.labeltype == LABEL_BIBLIO ||
4340 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4341 if (row_ptr->par()->IsFirstInSequence()) {
4342 font = GetFont(bview->buffer(),
4343 row_ptr->par(), -2);
4344 if (!row_ptr->par()->GetLabelstring().empty()) {
4345 string tmpstring = row_ptr->par()->GetLabelstring();
4346 float spacing_val = 1.0;
4347 if (!row_ptr->par()->spacing.isDefault()) {
4348 spacing_val = row_ptr->par()->spacing.getValue();
4350 spacing_val = bview->buffer()->params.spacing.getValue();
4353 maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
4354 + (layout.labelbottomsep * DefaultHeight()));
4357 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4358 tmpx = ( (is_rtl ? LeftMargin(bview, row_ptr) : x)
4359 + ww - RightMargin(bview->buffer(), row_ptr) ) / 2;
4360 tmpx -= lyxfont::width(tmpstring, font) / 2;
4362 tmpx = ww - LeftMargin(bview, row_ptr) -
4363 lyxfont::width(tmpstring, font);
4364 pain.text(int(tmpx),
4365 y_offset + row_ptr->baseline()
4366 - row_ptr->ascent_of_text()
4372 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
4373 font = GetFont(bview->buffer(), row_ptr->par(), -1);
4375 tmpx = ww - LeftMargin(bview, row_ptr)
4376 + lyxfont::width(layout.labelsep, font);
4378 tmpx = x - lyxfont::width(layout.labelsep, font)
4379 - row_ptr->par()->bibkey->width(bview->painter(), font);
4380 row_ptr->par()->bibkey->draw(bview, font,
4381 y_offset + row_ptr->baseline(),
4386 /* is it a last row? */
4387 LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
4388 if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
4389 (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
4391 /* think about the margins */
4392 if (!row_ptr->next() && bv_owner)
4393 y_bottom -= LYX_PAPER_MARGIN;
4395 /* draw a bottom pagebreak */
4396 if (firstpar->pagebreak_bottom) {
4398 pb_font.setColor(LColor::pagebreak).decSize();
4399 int w = 0, a = 0, d = 0;
4401 y_offset + y_bottom - 2 * DefaultHeight(),
4403 y_offset + y_bottom - 2 * DefaultHeight(),
4405 Painter::line_onoffdash)
4408 _("Page Break (bottom)"),
4411 LColor::background, false, w, a, d);
4412 pain.rectText((ww - w) / 2,
4413 y_offset + y_top + 2 * DefaultHeight() + d,
4414 _("Page Break (bottom)"),
4417 LColor::background);
4418 y_bottom -= 3 * DefaultHeight();
4421 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4422 /* draw a vfill bottom */
4423 pain.line(0, y_offset + y_bottom - 3 * DefaultHeight(),
4425 y_offset + y_bottom - 3 * DefaultHeight(),
4427 pain.line(0, y_offset + y_bottom - 2,
4429 y_offset + y_bottom - 2,
4431 pain.line(LYX_PAPER_MARGIN / 2,
4432 y_offset + y_bottom - 3 * DefaultHeight(),
4433 LYX_PAPER_MARGIN / 2,
4434 y_offset + y_bottom - 2,
4436 y_bottom -= 3 * DefaultHeight();
4439 /* think about user added space */
4440 y_bottom -= int(firstpar->added_space_bottom.inPixels(bview));
4442 if (firstpar->line_bottom) {
4443 /* draw a bottom line */
4444 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4445 par, par->Last() - 1));
4446 pain.line(0, y_offset + y_bottom,
4447 ww, y_offset + y_bottom,
4448 LColor::topline, Painter::line_solid,
4449 Painter::line_thick);
4450 y_bottom -= lyxfont::ascent('x', GetFont(bview->buffer(),
4451 par, par->Last() - 1));
4455 int endlabel = row_ptr->par()->GetEndLabel(bview->buffer()->params);
4458 case END_LABEL_FILLED_BOX:
4460 LyXFont font = GetFont(bview->buffer(),
4461 row_ptr->par(), last);
4462 int size = int(0.75 * lyxfont::maxAscent(font));
4463 int y = (y_offset + row_ptr->baseline()) - size;
4464 int x = is_rtl ? LYX_PAPER_MARGIN
4465 : ww - LYX_PAPER_MARGIN - size;
4466 if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4468 LyXFont font(LyXFont::ALL_SANE);
4469 font.setSize(LyXFont::SIZE_SMALL);
4470 x += lyxfont::width("Mwide-figM", font);
4472 x -= LYX_PAPER_MARGIN/2;
4473 if (row_ptr->fill() <= size)
4474 x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
4475 if (endlabel == END_LABEL_BOX) {
4476 pain.line(x, y, x, y + size,
4478 pain.line(x + size, y, x + size , y + size,
4480 pain.line(x, y, x + size, y,
4482 pain.line(x, y + size, x + size, y + size,
4485 pain.fillRectangle(x, y, size, size,
4489 case END_LABEL_STATIC:
4491 LyXTextClass::LayoutList::size_type layout = row_ptr->par()->GetLayout();
4492 string tmpstring = textclasslist.Style(bview->buffer()->params.textclass,
4493 layout).endlabelstring();
4494 font = GetFont(bview->buffer(), row_ptr->par(), -2);
4495 int tmpx = is_rtl ? int(x) - lyxfont::width(tmpstring, font)
4496 : ww - RightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
4497 pain.text( tmpx, y_offset + row_ptr->baseline(), tmpstring, font);
4500 case END_LABEL_NO_LABEL:
4505 /* draw the text in the pixmap */
4507 vpos = row_ptr->pos();
4509 /* table stuff -- begin*/
4510 if (row_ptr->par()->table) {
4512 int cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
4514 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4516 while (vpos <= last) {
4517 pos = vis2log(vpos);
4518 if (row_ptr->par()->IsNewline(pos)) {
4520 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4521 /* draw the table lines, still very simple */
4522 on_off = !row_ptr->par()->table->TopLine(cell);
4524 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4525 !row_ptr->par()->table->IsContRow(cell))
4526 pain.line(int(x_old),
4527 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4529 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4531 on_off ? Painter::line_onoffdash : Painter::line_solid);
4533 on_off = !row_ptr->par()->table->BottomLine(cell);
4534 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4535 row_ptr->par()->table->VeryLastRow(cell))
4537 pain.line(int(x_old),
4538 y_offset + y_bottom - 1,
4540 y_offset + y_bottom - 1,
4542 on_off ? Painter::line_onoffdash : Painter::line_solid);
4544 on_off = !row_ptr->par()->table->LeftLine(cell);
4546 pain.line(int(x_old),
4547 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4549 y_offset + y_bottom - 1,
4551 on_off ? Painter::line_onoffdash : Painter::line_solid);
4553 on_off = !row_ptr->par()->table->RightLine(cell);
4555 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4556 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4557 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4558 y_offset + y_bottom - 1,
4560 on_off ? Painter::line_onoffdash : Painter::line_solid);
4563 /* take care about the alignment and other spaces */
4565 x += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
4566 if (row_ptr->par()->table->IsFirstCell(cell))
4567 --cell; // little hack, sorry
4569 } else if (row_ptr->par()->IsHfill(pos)) {
4573 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4575 y_offset + row_ptr->baseline(),
4580 } else if (row_ptr->par()->IsSeparator(pos)) {
4582 x+= SingleWidth(bview,
4583 row_ptr->par(), pos);
4586 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4589 /* do not forget the very last cell. This has no NEWLINE so
4590 * ignored by the code above*/
4591 if (cell == row_ptr->par()->table->GetNumberOfCells() - 1) {
4592 x = x_old + row_ptr->par()->table->WidthOfColumn(cell);
4593 on_off = !row_ptr->par()->table->TopLine(cell);
4595 !row_ptr->par()->table->TopAlreadyDrawed(cell)) &&
4596 !row_ptr->par()->table->IsContRow(cell))
4598 pain.line(int(x_old),
4599 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4601 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4603 on_off ? Painter::line_onoffdash : Painter::line_solid);
4604 on_off = !row_ptr->par()->table->BottomLine(cell);
4605 if ((!on_off && !row_ptr->par()->table->RowHasContRow(cell)) ||
4606 row_ptr->par()->table->VeryLastRow(cell))
4608 pain.line(int(x_old),
4609 y_offset + y_bottom - 1,
4611 y_offset + y_bottom - 1,
4613 on_off ? Painter::line_onoffdash : Painter::line_solid);
4615 on_off = !row_ptr->par()->table->LeftLine(cell);
4617 pain.line(int(x_old),
4618 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4620 y_offset + y_bottom - 1,
4622 on_off ? Painter::line_onoffdash : Painter::line_solid);
4624 on_off = !row_ptr->par()->table->RightLine(cell);
4626 pain.line(int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4627 y_offset + row_ptr->baseline() - row_ptr->ascent_of_text(),
4628 int(x) - row_ptr->par()->table->AdditionalWidth(cell),
4629 y_offset + y_bottom - 1,
4631 on_off ? Painter::line_onoffdash : Painter::line_solid);
4634 /* table stuff -- end*/
4636 LyXParagraph::size_type main_body =
4637 BeginningOfMainBody(bview->buffer(), row_ptr->par());
4638 if (main_body > 0 &&
4639 (main_body-1 > last ||
4640 !row_ptr->par()->IsLineSeparator(main_body - 1)))
4643 while (vpos <= last) {
4644 pos = vis2log(vpos);
4645 if (main_body > 0 && pos == main_body - 1) {
4646 x += fill_label_hfill
4647 + lyxfont::width(layout.labelsep,
4648 GetFont(bview->buffer(),
4649 row_ptr->par(), -2))
4650 - SingleWidth(bview,
4655 if (row_ptr->par() ->IsHfill(pos)) {
4658 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4660 y_offset + row_ptr->baseline(),
4663 if (HfillExpansion(bview->buffer(),
4665 if (pos >= main_body) {
4667 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4668 int(x + fill_hfill),
4669 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4671 Painter::line_onoffdash);
4675 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4676 int(x + fill_label_hfill),
4677 y_offset + row_ptr->baseline() - DefaultHeight() / 4,
4679 Painter::line_onoffdash);
4681 x += fill_label_hfill;
4684 y_offset + row_ptr->baseline() - DefaultHeight() / 2,
4686 y_offset + row_ptr->baseline(),
4691 } else if (row_ptr->par()->IsSeparator(pos)) {
4692 x += SingleWidth(bview,
4693 row_ptr->par(), pos);
4694 if (pos >= main_body)
4695 x += fill_separator;
4698 draw(bview, row_ptr, vpos, y_offset, x, clear_area);
4706 int LyXText::DefaultHeight() const
4708 LyXFont font(LyXFont::ALL_SANE);
4709 return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
4713 /* returns the column near the specified x-coordinate of the row
4714 * x is set to the real beginning of this column */
4715 int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
4716 bool & boundary) const
4719 float fill_separator, fill_hfill, fill_label_hfill;
4721 PrepareToPrint(bview, row, tmpx, fill_separator,
4722 fill_hfill, fill_label_hfill);
4724 LyXParagraph::size_type vc = row->pos();
4725 LyXParagraph::size_type last = RowLastPrintable(row);
4726 LyXParagraph::size_type c = 0;
4727 LyXLayout const & layout =
4728 textclasslist.Style(bview->buffer()->params.textclass,
4729 row->par()->GetLayout());
4730 bool left_side = false;
4733 /* table stuff -- begin */
4734 if (row->par()->table) {
4735 //the last row doesn't need a newline at the end
4736 if (row->next() && row->next()->par() == row->par()
4737 && row->par()->IsNewline(last))
4739 int cell = NumberOfCell(row->par(), row->pos());
4740 float cell_x = tmpx + row->par()->table->WidthOfColumn(cell);
4741 tmpx += row->par()->table->GetBeginningOfTextInCell(cell);
4742 float last_tmpx = tmpx;
4743 while (vc <= last && tmpx <= x) {
4746 if (row->par()->IsNewline(c)) {
4749 tmpx = cell_x + row->par()->table->GetBeginningOfTextInCell(cell);
4750 cell_x += row->par()->table->WidthOfColumn(cell);
4755 tmpx += SingleWidth(bview, row->par(), c);
4759 if (vc > row->pos() && !row->par()->IsNewline(c) &&
4760 (tmpx + last_tmpx) / 2 > x) {
4765 /* table stuff -- end*/
4767 LyXParagraph::size_type
4768 main_body = BeginningOfMainBody(bview->buffer(), row->par());
4769 float last_tmpx = tmpx;
4771 if (main_body > 0 &&
4772 (main_body-1 > last ||
4773 !row->par()->IsLineSeparator(main_body - 1)))
4776 while (vc <= last && tmpx <= x) {
4779 if (main_body > 0 && c == main_body-1) {
4780 tmpx += fill_label_hfill +
4781 lyxfont::width(layout.labelsep,
4782 GetFont(bview->buffer(), row->par(), -2));
4783 if (row->par()->IsLineSeparator(main_body - 1))
4784 tmpx -= SingleWidth(bview, row->par(), main_body-1);
4787 if (HfillExpansion(bview->buffer(), row, c)) {
4788 x += SingleWidth(bview, row->par(), c);
4792 tmpx += fill_label_hfill;
4794 else if (row->par()->IsSeparator(c)) {
4795 tmpx += SingleWidth(bview, row->par(), c);
4797 tmpx+= fill_separator;
4799 tmpx += SingleWidth(bview, row->par(), c);
4803 if (vc > row->pos() && (tmpx + last_tmpx) / 2 > x) {
4812 if (vc > last + 1) // This shouldn't happen.
4817 if (row->pos() > last) // Row is empty?
4819 else if (vc == row->pos() ||
4821 && vc <= last && row->par()->IsNewline(vc-1)) ) {
4823 if (bidi_level(c) % 2 == 1)
4826 c = vis2log(vc - 1);
4827 bool rtl = (bidi_level(c) % 2 == 1);
4828 if (left_side == rtl) {
4830 boundary = IsBoundary(bview->buffer(), row->par(), c);
4834 if (!row->par()->table && row->pos() <= last && c > last
4835 && row->par()->IsNewline(last)) {
4836 if (bidi_level(last) % 2 == 0)
4837 tmpx -= SingleWidth(bview, row->par(), last);
4839 tmpx += SingleWidth(bview, row->par(), last);
4850 /* turn the selection into a new environment. If there is no selection,
4851 * create an empty environment */
4852 void LyXText::InsertFootnoteEnvironment(BufferView * bview,
4853 LyXParagraph::footnote_kind kind)
4855 /* no footnoteenvironment in a footnoteenvironment */
4856 if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4857 WriteAlert(_("Impossible operation"),
4858 _("You can't insert a float in a float!"),
4862 /* no marginpars in minipages */
4863 if (kind == LyXParagraph::MARGIN
4864 && cursor.par()->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4865 WriteAlert(_("Impossible operation"),
4866 _("You can't insert a marginpar in a minipage!"),
4871 /* this doesnt make sense, if there is no selection */
4872 bool dummy_selection = false;
4874 sel_start_cursor = cursor; /* dummy selection */
4875 sel_end_cursor = cursor;
4876 dummy_selection = true;
4879 LyXParagraph * tmppar;
4882 if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
4883 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4887 /* a test to make sure there is not already a footnote
4888 * in the selection. */
4890 tmppar = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
4892 while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()) &&
4893 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4894 tmppar = tmppar->next;
4896 if (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
4897 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4898 WriteAlert(_("Impossible operation"),
4899 _("Float would include float!"),
4904 /* ok we have a selection. This is always between sel_start_cursor
4905 * and sel_end cursor */
4907 SetUndo(bview->buffer(), Undo::FINISH,
4908 sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous,
4909 sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next);
4911 if (sel_end_cursor.pos() > 0
4912 && sel_end_cursor.par()->IsLineSeparator(sel_end_cursor.pos() - 1))
4913 sel_end_cursor.pos(sel_end_cursor.pos() - 1);
4914 /* please break before a space at the end */
4915 if (sel_start_cursor.par() == sel_end_cursor.par()
4916 && sel_start_cursor.pos() > sel_end_cursor.pos())
4917 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4919 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, sel_end_cursor.pos());
4921 sel_end_cursor.par(sel_end_cursor.par()->Next());
4922 sel_end_cursor.pos(0);
4924 // don't forget to insert a dummy layout paragraph if necessary
4925 if (sel_start_cursor.par()->GetLayout() != sel_end_cursor.par()->layout){
4926 sel_end_cursor.par()->BreakParagraphConservative(bview->buffer()->params, 0);
4927 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4928 sel_end_cursor.par(sel_end_cursor.par()->next);
4931 sel_end_cursor.par()->layout = LYX_DUMMY_LAYOUT;
4933 cursor = sel_end_cursor;
4935 /* please break behind a space, if there is one. The space should
4937 if (sel_start_cursor.pos() > 0
4938 && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos() - 1))
4939 sel_start_cursor.pos(sel_start_cursor.pos() - 1);
4940 if (sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())) {
4941 sel_start_cursor.par()->Erase(sel_start_cursor.pos());
4944 sel_start_cursor.par()->BreakParagraphConservative(bview->buffer()->params,
4945 sel_start_cursor.pos());
4946 tmppar = sel_start_cursor.par()->Next();
4948 if (dummy_selection) {
4950 if (kind == LyXParagraph::TAB
4951 || kind == LyXParagraph::FIG
4952 || kind == LyXParagraph::WIDE_TAB
4953 || kind == LyXParagraph::WIDE_FIG
4954 || kind == LyXParagraph::ALGORITHM) {
4955 pair<bool, LyXTextClass::size_type> lres =
4956 textclasslist.NumberOfLayout(bview->buffer()->params.textclass,
4958 LyXTextClass::size_type lay;
4964 lay = 0; // use default layout "Standard" (0)
4966 tmppar->SetLayout(bview->buffer()->params, lay);
4969 if (sel_start_cursor.pos() > 0) {
4970 /* the footnote-environment should begin with a standard layout.
4971 * Imagine you insert a footnote within an enumeration, you
4972 * certainly do not want an enumerated footnote! */
4975 /* this is a exception the user would sometimes expect, I hope */
4976 sel_start_cursor.par()->Clear();
4980 while (tmppar != sel_end_cursor.par()) {
4981 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4982 tmppar->footnotekind = kind;
4983 tmppar = tmppar->Next();
4986 RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->Next());
4988 SetCursor(bview, sel_start_cursor.par()->Next(), 0);
4995 // returns pointer to a specified row
4996 Row * LyXText::GetRow(LyXParagraph * par,
4997 LyXParagraph::size_type pos, long & y) const
4999 Row * tmprow = firstrow;
5002 // find the first row of the specified paragraph
5003 while (tmprow->next() && tmprow->par() != par) {
5004 y += tmprow->height();
5005 tmprow = tmprow->next();
5008 // now find the wanted row
5009 while (tmprow->pos() < pos
5011 && tmprow->next()->par() == par
5012 && tmprow->next()->pos() <= pos) {
5013 y += tmprow->height();
5014 tmprow = tmprow->next();