1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "insets/insetbib.h"
24 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "minibuffer.h"
38 static const int LYX_PAPER_MARGIN = 20;
43 extern int bibitemMaxWidth(Painter &, LyXFont const &);
45 #define FIX_DOUBLE_SPACE 1
47 int LyXText::SingleWidth(LyXParagraph * par,
48 LyXParagraph::size_type pos) const
50 char c = par->GetChar(pos);
51 return SingleWidth(par, pos, c);
55 int LyXText::SingleWidth(LyXParagraph * par,
56 LyXParagraph::size_type pos, char c) const
58 LyXFont font = GetFont(par, pos);
60 // The most common case is handled first (Asger)
64 } else if (IsHfillChar(c)) {
65 return 3; /* Because of the representation
66 * as vertical lines */
67 } else if (c == LyXParagraph::META_FOOTNOTE ||
68 c == LyXParagraph::META_MARGIN ||
69 c == LyXParagraph::META_FIG ||
70 c == LyXParagraph::META_TAB ||
71 c == LyXParagraph::META_WIDE_FIG ||
72 c == LyXParagraph::META_WIDE_TAB ||
73 c == LyXParagraph::META_ALGORITHM) {
76 case LyXParagraph::META_MARGIN:
79 case LyXParagraph::META_FIG:
82 case LyXParagraph::META_TAB:
85 case LyXParagraph::META_ALGORITHM:
88 case LyXParagraph::META_WIDE_FIG:
91 case LyXParagraph::META_WIDE_TAB:
94 case LyXParagraph::META_FOOTNOTE:
100 return font.stringWidth(fs);
101 } else if (c == LyXParagraph::META_INSET) {
102 Inset * tmpinset= par->GetInset(pos);
104 return par->GetInset(pos)->width(owner_->painter(),
109 } else if (IsSeparatorChar(c))
111 else if (IsNewlineChar(c))
113 return font.width(c);
117 // Returns the paragraph position of the last character in the specified row
118 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
121 return row->par->Last() - 1;
122 else if (row->next->par != row->par)
123 return row->par->Last() - 1;
125 return row->next->pos - 1;
132 void LyXText::ComputeBidiTables(Row * row) const
135 if (!lyxrc->rtl_support) {
139 LyXParagraph::size_type last = RowLast(row);
140 bidi_start = row->pos;
142 if (bidi_start > last) {
147 if (last + 2 - bidi_start >
148 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
149 LyXParagraph::size_type new_size =
150 (last + 2 - bidi_start < 500) ?
151 500 : 2 * (last + 2 - bidi_start);
152 log2vis_list.resize(new_size);
153 vis2log_list.resize(new_size);
156 vis2log_list[last + 1 - bidi_start] = -1;
157 log2vis_list[last + 1 - bidi_start] = -1;
159 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
160 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
161 && row->par->IsLineSeparator(main_body - 1)) {
162 // This is needed in case there is a direction change in
163 // the label which is continued into the main body
164 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
165 ComputeBidiTablesFromTo(row, bidi_start,
167 log2vis_list[main_body - 1 - bidi_start] =
169 vis2log_list[main_body - 1 - bidi_start] =
171 if (main_body <= last)
172 ComputeBidiTablesFromTo(row,
175 ComputeBidiTablesFromTo(row, bidi_start,
177 last - main_body + 2);
178 log2vis_list[main_body - 1 - bidi_start] =
179 last - main_body + 1 + bidi_start;
180 vis2log_list[last - main_body + 1 - bidi_start] =
182 if (main_body <= last)
183 ComputeBidiTablesFromTo(row, main_body,
187 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
191 void LyXText::ComputeBidiTablesFromTo(Row * row,
192 LyXParagraph::size_type from,
193 LyXParagraph::size_type to,
194 LyXParagraph::size_type offset) const
196 LyXParagraph::size_type vpos, old_lpos, stack[2];
197 LyXDirection par_direction = row->par->getParDirection();
198 LyXDirection direction = par_direction;
199 LyXParagraph::size_type lpos = from;
203 if (row->par->getLetterDirection(lpos) == direction) {
204 log2vis_list[lpos - bidi_start] = direction;
208 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
209 && row->par->getFont(lpos).direction() ==
211 && row->par->getFont(lpos).latex() ==
213 // The last check is needed when the
215 stack[level++] = lpos;
217 old_lpos = stack[--level];
218 log2vis_list[old_lpos - bidi_start] =
219 log2vis_list[lpos - bidi_start] =
220 (old_lpos - lpos) * direction;
223 direction = static_cast<LyXDirection>(-direction);
228 old_lpos = stack[--level];
229 log2vis_list[old_lpos - bidi_start] =
230 (old_lpos - (to + 1)) * direction;
231 direction = static_cast<LyXDirection>(-direction);
234 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
237 for (lpos = from; lpos <= to; ++lpos) {
238 vpos += log2vis_list[lpos - bidi_start];
239 vis2log_list[vpos - bidi_start] = lpos;
240 log2vis_list[lpos - bidi_start] = vpos;
245 void LyXText::draw(Row const * row,
246 LyXParagraph::size_type & vpos,
247 int offset, float & x)
249 Painter & pain = owner_->painter();
251 LyXParagraph::size_type pos = vis2log(vpos);
252 char c = row->par->GetChar(pos);
254 if (IsNewlineChar(c)) {
256 // Draw end-of-line marker
257 LyXFont font = GetFont(row->par, pos);
258 int wid = font.width('n');
259 int asc = font.maxAscent();
260 int y = offset + row->baseline;
263 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
264 xp[0] = int(x + wid * 0.375);
265 yp[0] = int(y - 0.875 * asc * 0.75);
268 yp[1] = int(y - 0.500 * asc * 0.75);
270 xp[2] = int(x + wid * 0.375);
271 yp[2] = int(y - 0.125 * asc * 0.75);
273 pain.lines(xp, yp, 3, LColor::eolmarker);
276 yp[0] = int(y - 0.500 * asc * 0.75);
278 xp[1] = int(x + wid);
279 yp[1] = int(y - 0.500 * asc * 0.75);
281 xp[2] = int(x + wid);
282 yp[2] = int(y - asc * 0.75);
284 pain.lines(xp, yp, 3, LColor::eolmarker);
286 xp[0] = int(x + wid * 0.625);
287 yp[0] = int(y - 0.875 * asc * 0.75);
289 xp[1] = int(x + wid);
290 yp[1] = int(y - 0.500 * asc * 0.75);
292 xp[2] = int(x + wid * 0.625);
293 yp[2] = int(y - 0.125 * asc * 0.75);
295 pain.lines(xp, yp, 3, LColor::eolmarker);
297 xp[0] = int(x + wid);
298 yp[0] = int(y - 0.500 * asc * 0.75);
301 yp[1] = int(y - 0.500 * asc * 0.75);
304 yp[2] = int(y - asc * 0.75);
306 pain.lines(xp, yp, 3, LColor::eolmarker);
312 LyXFont font = GetFont(row->par, pos);
313 LyXFont font2 = font;
315 if (c == LyXParagraph::META_FOOTNOTE
316 || c == LyXParagraph::META_MARGIN
317 || c == LyXParagraph::META_FIG
318 || c == LyXParagraph::META_TAB
319 || c == LyXParagraph::META_WIDE_FIG
320 || c == LyXParagraph::META_WIDE_TAB
321 || c == LyXParagraph::META_ALGORITHM) {
324 case LyXParagraph::META_MARGIN:
326 // Draw a sign at the left margin!
328 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
329 offset + row->baseline, "!", 1, font);
331 case LyXParagraph::META_FIG:
334 case LyXParagraph::META_TAB:
337 case LyXParagraph::META_ALGORITHM:
340 case LyXParagraph::META_WIDE_FIG:
343 case LyXParagraph::META_WIDE_TAB:
346 case LyXParagraph::META_FOOTNOTE:
353 // calculate the position of the footnotemark
354 int y = (row->baseline - font2.maxAscent()
357 font.setColor(LColor::footnote);
361 // draw it and set new x position
363 pain.text(int(x), offset + y, fs, font);
364 x += pain.width(fs, font);
365 pain.line(int(tmpx), offset + row->baseline,
366 int(x), offset + row->baseline,
371 } else if (c == LyXParagraph::META_INSET) {
372 Inset * tmpinset = row->par->GetInset(pos);
374 tmpinset->draw(owner_->painter(), font,
375 offset + row->baseline, x);
380 /* usual characters, no insets */
382 // Collect character that we can draw in one command
384 // This is dirty, but fast. Notice that it will never be too small.
385 // For the record, I'll note that Microsoft Word has a limit
386 // of 768 here. We have none :-) (Asger)
387 // Ok. I am the first to admit that the use of std::string will be
388 // a tiny bit slower than using a POD char array. However, I claim
389 // that this slowdown is so small that it is close to inperceptive.
390 // So IMHO we should go with the easier and clearer implementation.
391 // And even if 1024 is a large number here it might overflow, string
392 // will only overflow if the machine is out of memory...
393 static string textstring;
397 LyXParagraph::size_type last = RowLast(row);
399 while (vpos <= last &&
400 (pos = vis2log(vpos)) >= 0
401 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
402 && font2 == GetFont(row->par, pos)) {
408 // Draw text and set the new x position
409 pain.text(int(x), offset + row->baseline, textstring, font);
410 x += pain.width(textstring, font);
412 // what about underbars?
413 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
414 pain.line(tmpx, offset + row->baseline + 2,
415 x, offset + row->baseline + 2);
419 // If we want ulem.sty support, drawing
420 // routines should go here. (Asger)
421 // Why shouldn't LyXFont::drawText handle it internally?
425 // Returns the left beginning of the text.
426 // This information cannot be taken from the layouts-objekt, because in
427 // LaTeX the beginning of the text fits in some cases (for example sections)
428 // exactly the label-width.
429 int LyXText::LeftMargin(Row const * row) const
431 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
432 row->par->GetLayout());
434 string parindent = layout.parindent;
436 /* table stuff -- begin */
439 /* table stuff -- end */
441 int x = LYX_PAPER_MARGIN;
443 x += textclasslist.TextClass(parameters->textclass)
445 .signedStringWidth(textclasslist
446 .TextClass(parameters->textclass)
449 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
450 LyXFont font(LyXFont::ALL_SANE);
451 font.setSize(LyXFont::SIZE_SMALL);
452 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
455 // this is the way, LyX handles the LaTeX-Environments.
456 // I have had this idea very late, so it seems to be a
457 // later added hack and this is true
458 if (!row->par->GetDepth()) {
459 if (!row->par->GetLayout()) {
460 // find the previous same level paragraph
461 if (row->par->FirstPhysicalPar()->Previous()) {
462 LyXParagraph * newpar = row->par
463 ->DepthHook(row->par->GetDepth());
465 textclasslist.Style(parameters->textclass,
472 // find the next level paragraph
474 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
476 // make a corresponding row. Needed to call LeftMargin()
478 // check wether it is a sufficent paragraph
479 if (newpar && newpar->footnoteflag == row->par->footnoteflag
481 .Style(parameters->textclass,
482 newpar->GetLayout()).isEnvironment()) {
484 dummyrow.par = newpar;
485 dummyrow.pos = newpar->Last();
486 x = LeftMargin(&dummyrow);
488 // this is no longer an error, because this function
489 // is used to clear impossible depths after changing
490 // a layout. Since there is always a redo,
491 // LeftMargin() is always called
492 row->par->FirstPhysicalPar()->depth = 0;
495 if (newpar && !row->par->GetLayout()) {
496 if (newpar->FirstPhysicalPar()->noindent)
499 parindent = textclasslist
500 .Style(parameters->textclass,
501 newpar->GetLayout()).parindent;
506 LyXFont labelfont = GetFont(row->par, -2);
507 switch (layout.margintype) {
509 if (!layout.leftmargin.empty()) {
511 .TextClass(parameters->textclass)
513 .signedStringWidth(layout.leftmargin);
515 if (!row->par->GetLabestring().empty()) {
516 x += labelfont.signedStringWidth(layout.labelindent);
517 x += labelfont.stringWidth(row->par->GetLabestring());
518 x += labelfont.stringWidth(layout.labelsep);
522 x += labelfont.signedStringWidth(layout.labelindent);
523 if (row->pos >= BeginningOfMainBody(row->par)) {
524 if (!row->par->GetLabelWidthString().empty()) {
526 .stringWidth(row->par
527 ->GetLabelWidthString());
528 x += labelfont.stringWidth(layout.labelsep);
533 x += textclasslist.TextClass(parameters->textclass)
534 .defaultfont().signedStringWidth(layout.leftmargin) * 4
535 / (row->par->GetDepth() + 4);
537 case MARGIN_FIRST_DYNAMIC:
538 if (layout.labeltype == LABEL_MANUAL) {
539 if (row->pos >= BeginningOfMainBody(row->par)) {
541 .signedStringWidth(layout.leftmargin);
544 .signedStringWidth(layout.labelindent);
547 // Special case to fix problems with
549 || (layout.labeltype == LABEL_STATIC
550 && layout.latextype == LATEX_ENVIRONMENT
551 && ! row->par->IsFirstInSequence())) {
552 x += labelfont.signedStringWidth(layout.leftmargin);
553 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
554 && layout.labeltype != LABEL_BIBLIO
555 && layout.labeltype !=
556 LABEL_CENTERED_TOP_ENVIRONMENT) {
557 x += labelfont.signedStringWidth(layout.labelindent);
558 x += labelfont.stringWidth(layout.labelsep);
559 x += labelfont.stringWidth(row->par->GetLabestring());
563 case MARGIN_RIGHT_ADDRESS_BOX:
565 // ok, a terrible hack. The left margin depends on the widest
566 // row in this paragraph. Do not care about footnotes, they
567 // are *NOT* allowed in the LaTeX realisation of this layout.
569 // find the first row of this paragraph
570 Row const * tmprow = row;
571 while (tmprow->previous && tmprow->previous->par == row->par)
572 tmprow = tmprow->previous;
574 int minfill = tmprow->fill;
575 while (tmprow->next && tmprow->next->par == row->par) {
576 tmprow = tmprow->next;
577 if (tmprow->fill < minfill)
578 minfill = tmprow->fill;
581 x += textclasslist.TextClass(parameters->textclass)
582 .defaultfont().signedStringWidth(layout.leftmargin);
587 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
588 if (!row->par->pextra_widthp.empty()) {
590 atoi(row->par->pextra_widthp.c_str()) / 100;
591 } else if (!row->par->pextra_width.empty()) {
592 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
595 xx = paperwidth * 80 / 100;
597 } else { // should not happen
598 LyXFont font(LyXFont::ALL_SANE);
599 x += font.stringWidth("XXXXXX");
604 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
605 align = layout.align;
607 align = row->par->FirstPhysicalPar()->align;
609 // set the correct parindent
611 if ((layout.labeltype == LABEL_NO_LABEL
612 || layout.labeltype == LABEL_TOP_ENVIRONMENT
613 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
614 || (layout.labeltype == LABEL_STATIC
615 && layout.latextype == LATEX_ENVIRONMENT
616 && ! row->par->IsFirstInSequence()))
617 && row->par == row->par->FirstPhysicalPar()
618 && align == LYX_ALIGN_BLOCK
619 && !row->par->noindent
620 && (row->par->layout ||
621 parameters->paragraph_separation ==
622 BufferParams::PARSEP_INDENT))
623 x += textclasslist.TextClass(parameters->textclass)
624 .defaultfont().signedStringWidth(parindent);
625 else if (layout.labeltype == LABEL_BIBLIO) {
626 // ale970405 Right width for bibitems
627 x += bibitemMaxWidth(owner_->painter(),
629 .TextClass(parameters
638 int LyXText::RightMargin(Row const * row) const
640 LyXLayout const & layout =
641 textclasslist.Style(parameters->textclass,
642 row->par->GetLayout());
644 int x = LYX_PAPER_MARGIN
646 .TextClass(parameters->textclass)
648 .signedStringWidth(textclasslist
649 .TextClass(parameters->textclass)
652 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
653 x += LYX_PAPER_MARGIN / 2;
656 // this is the way, LyX handles the LaTeX-Environments.
657 // I have had this idea very late, so it seems to be a
658 // later added hack and this is true
659 if (row->par->GetDepth()) {
660 // find the next level paragraph
662 LyXParagraph * newpar = row->par;
665 newpar = newpar->FirstPhysicalPar()->Previous();
667 newpar = newpar->FirstPhysicalPar();
668 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
669 && newpar->footnoteflag == row->par->footnoteflag);
671 // make a corresponding row. Needed to call LeftMargin()
673 // check wether it is a sufficent paragraph
674 if (newpar && newpar->footnoteflag == row->par->footnoteflag
675 && textclasslist.Style(parameters->textclass,
679 dummyrow.par = newpar;
681 x = RightMargin(&dummyrow);
683 // this is no longer an error, because this function
684 // is used to clear impossible depths after changing
685 // a layout. Since there is always a redo,
686 // LeftMargin() is always called
687 row->par->FirstPhysicalPar()->depth = 0;
691 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
692 x += textclasslist.TextClass(parameters->textclass)
694 .signedStringWidth(layout.rightmargin) * 4
695 / (row->par->GetDepth() + 4);
700 int LyXText::LabelEnd (Row const * row) const
702 if (textclasslist.Style(parameters->textclass,
703 row->par->GetLayout()).margintype
707 tmprow.pos = row->par->Last();
708 return LeftMargin(&tmprow); /* just the beginning
711 return 0; /* LabelEnd is only needed, if the
712 layout fills a flushleft
717 /* table stuff -- begin*/
718 int LyXText::NumberOfCell(LyXParagraph * par,
719 LyXParagraph::size_type pos) const
722 LyXParagraph::size_type tmp_pos = 0;
723 while (tmp_pos < pos) {
724 if (par->IsNewline(tmp_pos))
732 int LyXText::WidthOfCell(LyXParagraph * par,
733 LyXParagraph::size_type & pos) const
736 while (pos < par->Last() && !par->IsNewline(pos)) {
737 w += SingleWidth(par, pos);
740 if (par->IsNewline(pos))
746 bool LyXText::HitInTable(Row * row, int x) const
749 float fill_separator, fill_hfill, fill_label_hfill;
750 if (!row->par->table)
752 PrepareToPrint(row, tmpx, fill_separator,
753 fill_hfill, fill_label_hfill, false);
754 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
758 bool LyXText::MouseHitInTable(int x, long y) const
760 Row * row = GetRowNearY(y);
761 return HitInTable(row, x);
765 /* table stuff -- end*/
768 // get the next breakpoint in a given paragraph
769 LyXParagraph::size_type
770 LyXText::NextBreakPoint(Row const * row, int width) const
772 LyXParagraph * par = row->par;
773 LyXParagraph::size_type pos = row->pos;
775 /* table stuff -- begin*/
777 while (pos < par->size()
778 && (!par->IsNewline(pos)
779 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
780 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
781 par->GetInset(pos) && par->GetInset(pos)->display()){
782 par->GetInset(pos)->display(false);
788 /* table stuff -- end*/
790 // position of the last possible breakpoint
791 // -1 isn't a suitable value, but a flag
792 LyXParagraph::size_type last_separator = -1;
793 int left_margin = LabelEnd(row);
794 width -= RightMargin(row);
796 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
797 LyXLayout const & layout =
798 textclasslist.Style(parameters->textclass, par->GetLayout());
799 LyXParagraph::size_type i = pos;
801 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
802 /* special code for right address boxes, only newlines count */
803 while (i < par->Last()) {
804 if (par->IsNewline(i)) {
806 i = par->Last() - 1; // this means break
808 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
809 par->GetInset(i) && par->GetInset(i)->display()){
810 par->GetInset(i)->display(false);
815 // Last position is an invariant
816 LyXParagraph::size_type const last =
818 // this is the usual handling
819 int x = LeftMargin(row);
820 while (x < width && i < last) {
821 char c = par->GetChar(i);
822 if (IsNewlineChar(c)) {
824 x = width; // this means break
825 } else if (c == LyXParagraph::META_INSET &&
826 par->GetInset(i) && par->GetInset(i)->display()){
827 // check wether a Display() inset is
828 // valid here. if not, change it to
830 if (layout.isCommand()
831 || (layout.labeltype == LABEL_MANUAL
832 && i < BeginningOfMainBody(par))){
833 // display istn't allowd
834 par->GetInset(i)->display(false);
835 x += SingleWidth(par, i, c);
837 // inset is display. So break the line here
841 if (IsLineSeparatorChar(par->GetChar(i+1)))
844 last_separator = last; // to avoid extra rows
846 last_separator = i - 1;
847 x = width; // this means break
850 if (IsLineSeparatorChar(c))
852 x += SingleWidth(par, i, c);
855 if (i == main_body) {
856 x += GetFont(par, -2).stringWidth(layout.labelsep);
857 if (par->IsLineSeparator(i - 1))
858 x-= SingleWidth(par, i - 1);
863 // end of paragraph is always a suitable separator
864 if (i == last && x < width)
868 // well, if last_separator is still 0, the line isn't breakable.
869 // don't care and cut simply at the end
870 if (last_separator < 0) {
874 // manual labels cannot be broken in LaTeX, do not care
875 if (main_body && last_separator < main_body)
876 last_separator = main_body - 1;
878 return last_separator;
882 // returns the minimum space a row needs on the screen in pixel
883 int LyXText::Fill(Row const * row, int paper_width) const
886 // get the pure distance
887 LyXParagraph::size_type last = RowLast(row);
888 /* table stuff -- begin */
889 if (row->par->table) {
890 // for tables FILL does calculate the widthes of each cell in
892 LyXParagraph::size_type pos = row->pos;
893 int cell = NumberOfCell(row->par, pos);
896 row->par->table->SetWidthOfCell(cell,
897 WidthOfCell(row->par,
900 } while (pos <= last && !row->par->table->IsFirstCell(cell));
901 // don't forget the very last table cell without characters
902 if (cell == row->par->table->GetNumberOfCells() - 1)
903 row->par->table->SetWidthOfCell(cell,
904 WidthOfCell(row->par,
907 return 0; /* width of table cannot be returned since
908 * we cannot guarantee its correct value at
911 /* table stuff -- end*/
913 int left_margin = LabelEnd(row);
915 // if the row ends with newline, this newline will not be relevant
916 //if (last >= 0 && row->par->IsNewline(last))
919 // if the row ends with a space, this space will not be relevant
920 if (last >= 0 && row->par->IsLineSeparator(last))
923 // special handling of the right address boxes
924 if (textclasslist.Style(parameters->textclass,
925 row->par->GetLayout()).margintype
926 == MARGIN_RIGHT_ADDRESS_BOX) {
927 int tmpfill = row->fill;
928 row->fill = 0; // the minfill in MarginLeft()
934 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
935 row->par->GetLayout());
936 LyXParagraph::size_type main_body =
937 BeginningOfMainBody(row->par);
938 LyXParagraph::size_type i = row->pos;
941 if (main_body > 0 && i == main_body) {
942 w += GetFont(row->par, -2).
943 stringWidth(layout.labelsep);
944 if (row->par->IsLineSeparator(i - 1))
945 w -= SingleWidth(row->par, i - 1);
949 w += SingleWidth(row->par, i);
952 if (main_body > 0 && main_body > last) {
953 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
954 if (last >= 0 && row->par->IsLineSeparator(last))
955 w -= SingleWidth(row->par, last);
960 fill = paper_width - w - RightMargin(row);
965 // returns the minimum space a manual label needs on the screen in pixel
966 int LyXText::LabelFill(Row const * row) const
968 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
969 // -1 because a label ends either with a space that is in the label,
970 // or with the beginning of a footnote that is outside the label.
972 // I don't understand this code in depth, but sometimes "last" is
973 // less than 0 and this causes a crash. This fix seems to work
974 // correctly, but I bet the real error is elsewhere. The bug is
975 // triggered when you have an open footnote in a paragraph
976 // environment with a manual label. (Asger)
977 if (last < 0) last = 0;
979 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
986 w += SingleWidth(row->par, i);
991 if (!row->par->labelwidthstring.empty()) {
992 fill = GetFont(row->par, -2)
993 .stringWidth(row->par->labelwidthstring) - w;
1003 // returns the number of separators in the specified row. The separator
1004 // on the very last column doesnt count
1005 int LyXText::NumberOfSeparators(Row const * row) const
1007 int last = RowLast(row);
1009 //int main_body = BeginningOfMainBody(row->par);
1010 //if (p < main_body)
1012 // I think this is equivalent to the above. (Lgb)
1013 int p = max(row->pos, BeginningOfMainBody(row->par));
1015 for (; p < last; ++p) {
1016 if (row->par->IsSeparator(p)) {
1024 // returns the number of hfills in the specified row. The LyX-Hfill is
1025 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1026 // ignored. This is *MUCH* more usefull than not to ignore!
1027 int LyXText::NumberOfHfills(Row const * row) const
1029 int last = RowLast(row);
1030 int first = row->pos;
1031 if (first) { /* hfill *DO* count at the beginning
1033 while(first <= last && row->par->IsHfill(first))
1037 //int main_body = BeginningOfMainBody(row->par);
1038 //if (first < main_body)
1039 // first = main_body;
1040 // I think this is equivalent to the above. (Lgb)
1041 first = max(first, BeginningOfMainBody(row->par));
1043 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1044 if (row->par->IsHfill(p)) {
1052 // like NumberOfHfills, but only those in the manual label!
1053 int LyXText::NumberOfLabelHfills(Row const * row) const
1055 LyXParagraph::size_type last = RowLast(row);
1056 LyXParagraph::size_type first = row->pos;
1057 if (first) { /* hfill *DO* count at the beginning
1059 while(first < last && row->par->IsHfill(first))
1062 //LyXParagraph::size_type main_body =
1063 //BeginningOfMainBody(row->par);
1064 //if (last > main_body)
1066 // I think this is eqvialent to the above. (Lgb)
1067 last = min(last, BeginningOfMainBody(row->par));
1069 for (LyXParagraph::size_type p = first;
1070 p < last; ++p) { // last, because the end is ignored!
1071 if (row->par->IsHfill(p)) {
1079 // returns true, if a expansion is needed.
1080 // Rules are given by LaTeX
1081 bool LyXText::HfillExpansion(Row const * row_ptr,
1082 LyXParagraph::size_type pos) const
1084 // by the way, is it a hfill?
1085 if (!row_ptr->par->IsHfill(pos))
1088 // at the end of a row it does not count
1089 if (pos >= RowLast(row_ptr))
1092 // at the beginning of a row it does not count, if it is not
1093 // the first row of a paragaph
1097 // in some labels it does not count
1098 if (textclasslist.Style(parameters->textclass,
1099 row_ptr->par->GetLayout()).margintype
1101 && pos < BeginningOfMainBody(row_ptr->par))
1104 // if there is anything between the first char of the row and
1105 // the sepcified position that is not a newline and not a hfill,
1106 // the hfill will count, otherwise not
1107 LyXParagraph::size_type i = row_ptr->pos;
1108 while (i < pos && (row_ptr->par->IsNewline(i)
1109 || row_ptr->par->IsHfill(i)))
1116 void LyXText::SetHeightOfRow(Row * row_ptr) const
1118 /* get the maximum ascent and the maximum descent */
1120 float layoutasc = 0;
1121 float layoutdesc = 0;
1126 /* this must not happen before the currentrow for clear reasons.
1127 so the trick is just to set the current row onto this row */
1129 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1131 /* ok , let us initialize the maxasc and maxdesc value.
1132 * This depends in LaTeX of the font of the last character
1133 * in the paragraph. The hack below is necessary because
1134 * of the possibility of open footnotes */
1136 /* Correction: only the fontsize count. The other properties
1137 are taken from the layoutfont. Nicer on the screen :) */
1139 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1140 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1142 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1143 firstpar->GetLayout());
1145 LyXFont font = GetFont(par, par->Last()-1);
1146 LyXFont::FONT_SIZE size = font.size();
1147 font = GetFont(par, -1);
1150 LyXFont labelfont = GetFont(par, -2);
1152 int maxasc = int(font.maxAscent() *
1153 layout.spacing.getValue() *
1154 parameters->spacing.getValue());
1155 int maxdesc = int(font.maxDescent() *
1156 layout.spacing.getValue() *
1157 parameters->spacing.getValue());
1159 int pos_end = RowLast(row_ptr);
1163 // Check if any insets are larger
1164 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1165 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1166 tmpfont = GetFont(row_ptr->par, pos);
1167 tmpinset = row_ptr->par->GetInset(pos);
1169 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1170 desc = tmpinset->descent(owner_->painter(), tmpfont);
1179 // Check if any custom fonts are larger (Asger)
1180 // This is not completely correct, but we can live with the small,
1181 // cosmetic error for now.
1182 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1184 if (maxsize > font.size()) {
1185 font.setSize(maxsize);
1187 asc = font.maxAscent();
1188 desc = font.maxDescent();
1195 /* table stuff -- begin*/
1196 if (row_ptr->par->table){
1197 // stretch the rows a bit
1201 /* table stuff -- end*/
1203 // This is nicer with box insets:
1207 row_ptr->ascent_of_text = maxasc;
1209 /* is it a top line? */
1210 if (row_ptr->pos == 0
1211 && row_ptr->par == firstpar) {
1213 /* some parksips VERY EASY IMPLEMENTATION */
1214 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1215 if (layout.isParagraph()
1216 && firstpar->GetDepth() == 0
1217 && firstpar->Previous())
1218 maxasc += parameters->getDefSkip().inPixels(owner_);
1219 else if (firstpar->Previous()
1220 && textclasslist.Style(parameters->textclass,
1221 firstpar->Previous()->GetLayout()).isParagraph()
1222 && firstpar->Previous()->GetDepth() == 0)
1223 // is it right to use defskip here too? (AS)
1224 maxasc += parameters->getDefSkip().inPixels(owner_);
1227 /* the paper margins */
1228 if (!row_ptr->par->previous)
1229 maxasc += LYX_PAPER_MARGIN;
1231 /* add the vertical spaces, that the user added */
1232 if (firstpar->added_space_top.kind() != VSpace::NONE)
1233 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1235 /* do not forget the DTP-lines!
1236 * there height depends on the font of the nearest character */
1237 if (firstpar->line_top)
1238 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1240 /* and now the pagebreaks */
1241 if (firstpar->pagebreak_top)
1242 maxasc += 3 * DefaultHeight();
1244 /* this is special code for the chapter, since the label of this
1245 * layout is printed in an extra row */
1246 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1247 && parameters->secnumdepth>= 0) {
1248 labeladdon = int(labelfont.maxDescent() *
1249 layout.spacing.getValue() *
1250 parameters->spacing.getValue())
1251 + int(labelfont.maxAscent() *
1252 layout.spacing.getValue() *
1253 parameters->spacing.getValue());
1256 /* special code for the top label */
1257 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1258 || layout.labeltype == LABEL_BIBLIO
1259 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1260 && row_ptr->par->IsFirstInSequence()
1261 && !row_ptr->par->GetLabestring().empty()) {
1263 (labelfont.maxAscent() *
1264 layout.spacing.getValue() *
1265 parameters->spacing.getValue())
1266 +(labelfont.maxDescent() *
1267 layout.spacing.getValue() *
1268 parameters->spacing.getValue())
1269 + layout.topsep * DefaultHeight()
1270 + layout.labelbottomsep * DefaultHeight());
1273 /* and now the layout spaces, for example before and after a section,
1274 * or between the items of a itemize or enumerate environment */
1276 if (!firstpar->pagebreak_top) {
1277 LyXParagraph * prev = row_ptr->par->Previous();
1279 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1280 if (prev && prev->GetLayout() == firstpar->GetLayout()
1281 && prev->GetDepth() == firstpar->GetDepth()
1282 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1284 layoutasc = (layout.itemsep * DefaultHeight());
1286 else if (row_ptr->previous) {
1287 tmptop = layout.topsep;
1289 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1290 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1293 layoutasc = (tmptop * DefaultHeight());
1295 else if (row_ptr->par->line_top){
1296 tmptop = layout.topsep;
1299 layoutasc = (tmptop * DefaultHeight());
1302 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1304 maxasc += int(textclasslist.Style(parameters->textclass,
1305 prev->GetLayout()).parsep * DefaultHeight());
1308 if (firstpar->Previous()
1309 && firstpar->Previous()->GetDepth() == 0
1310 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1313 else if (firstpar->Previous()){
1314 maxasc += int(layout.parsep * DefaultHeight());
1320 /* is it a bottom line? */
1321 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1322 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1324 /* the paper margins */
1326 maxdesc += LYX_PAPER_MARGIN;
1328 /* add the vertical spaces, that the user added */
1329 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1330 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1332 /* do not forget the DTP-lines!
1333 * there height depends on the font of the nearest character */
1334 if (firstpar->line_bottom)
1335 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1337 /* and now the pagebreaks */
1338 if (firstpar->pagebreak_bottom)
1339 maxdesc += 3 * DefaultHeight();
1341 /* and now the layout spaces, for example before and after a section,
1342 * or between the items of a itemize or enumerate environment */
1343 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1344 LyXParagraph * nextpar = row_ptr->par->Next();
1345 LyXParagraph * comparepar = row_ptr->par;
1349 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1350 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1351 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1352 if (comparepar->GetLayout()!= nextpar->GetLayout()
1353 || nextpar->GetLabelWidthString() !=
1354 comparepar->GetLabelWidthString())
1355 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1357 if (unusual > usual)
1358 layoutdesc = unusual;
1362 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1364 if (comparepar->GetLayout()!= nextpar->GetLayout()
1365 || nextpar->GetLabelWidthString() !=
1366 comparepar->GetLabelWidthString())
1367 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1372 /* incalculate the layout spaces */
1373 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1374 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1376 /* table stuff -- begin*/
1377 if (row_ptr->par->table){
1378 maxasc += row_ptr->par->table->
1379 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1381 /* table stuff -- end*/
1383 /* calculate the new height of the text */
1384 height -= row_ptr->height;
1386 row_ptr->height = maxasc + maxdesc + labeladdon;
1387 row_ptr->baseline = maxasc + labeladdon;
1389 height += row_ptr->height;
1393 /* Appends the implicit specified paragraph behind the specified row,
1394 * start at the implicit given position */
1395 void LyXText::AppendParagraph(Row * row) const
1397 bool not_ready = true;
1399 // The last character position of a paragraph is an invariant so we can
1400 // safely get it here. (Asger)
1401 int lastposition = row->par->Last();
1404 // Get the next breakpoint
1405 int z = NextBreakPoint(row, paperwidth);
1409 // Insert the new row
1410 if (z < lastposition) {
1412 InsertRow(row, row->par, z);
1419 // Set the dimensions of the row
1420 tmprow->fill = Fill(tmprow, paperwidth);
1421 SetHeightOfRow(tmprow);
1423 } while (not_ready);
1427 void LyXText::BreakAgain(Row * row) const
1429 bool not_ready = true;
1432 /* get the next breakpoint */
1433 LyXParagraph::size_type z =
1434 NextBreakPoint(row, paperwidth);
1437 if (z < row->par->Last() ) {
1438 if (!row->next || (row->next && row->next->par != row->par)) {
1441 InsertRow(row, row->par, z);
1448 not_ready = false; // the rest will not change
1454 /* if there are some rows too much, delete them */
1455 /* only if you broke the whole paragraph! */
1456 Row * tmprow2 = row;
1457 while (tmprow2->next && tmprow2->next->par == row->par) {
1458 tmprow2 = tmprow2->next;
1460 while (tmprow2 != row) {
1461 tmprow2 = tmprow2->previous;
1462 RemoveRow(tmprow2->next);
1467 /* set the dimensions of the row */
1468 tmprow->fill = Fill(tmprow, paperwidth);
1469 SetHeightOfRow(tmprow);
1470 } while (not_ready);
1474 /* this is just a little changed version of break again */
1475 void LyXText::BreakAgainOneRow(Row * row)
1477 /* get the next breakpoint */
1478 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1481 if (z < row->par->Last() ) {
1482 if (!row->next || (row->next && row->next->par != row->par)) {
1483 /* insert a new row */
1485 InsertRow(row, row->par, z);
1497 /* if there are some rows too much, delete them */
1498 /* only if you broke the whole paragraph! */
1499 Row * tmprow2 = row;
1500 while (tmprow2->next && tmprow2->next->par == row->par) {
1501 tmprow2 = tmprow2->next;
1503 while (tmprow2 != row) {
1504 tmprow2 = tmprow2->previous;
1505 RemoveRow(tmprow2->next);
1509 /* set the dimensions of the row */
1510 tmprow->fill = Fill(tmprow, paperwidth);
1511 SetHeightOfRow(tmprow);
1515 void LyXText::BreakParagraph(char keep_layout)
1517 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1518 cursor.par->GetLayout());
1520 /* table stuff -- begin */
1521 if (cursor.par->table) {
1522 // breaking of tables is only allowed at the beginning or the end */
1523 if (cursor.pos && cursor.pos < cursor.par->size() &&
1524 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1525 return; // no breaking of tables allowed
1527 /* table stuff -- end */
1529 // this is only allowed, if the current paragraph is not empty or caption
1530 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1532 layout.labeltype!= LABEL_SENSITIVE)
1535 SetUndo(Undo::INSERT,
1536 cursor.par->ParFromPos(cursor.pos)->previous,
1537 cursor.par->ParFromPos(cursor.pos)->next);
1539 /* table stuff -- begin */
1540 if (cursor.par->table) {
1541 int cell = NumberOfCell(cursor.par, cursor.pos);
1542 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1543 SetCursor(cursor.par, cursor.par->text.size());
1545 /* table stuff -- end */
1547 // please break always behind a space
1548 if (cursor.pos < cursor.par->Last()
1549 && cursor.par->IsLineSeparator(cursor.pos))
1552 // break the paragraph
1556 keep_layout = layout.isEnvironment();
1557 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1559 /* table stuff -- begin */
1560 if (cursor.par->table){
1561 // the table should stay with the contents
1563 cursor.par->Next()->table = cursor.par->table;
1564 cursor.par->table = 0;
1567 /* table stuff -- end */
1569 // well this is the caption hack since one caption is really enough
1570 if (layout.labeltype == LABEL_SENSITIVE){
1572 cursor.par->SetLayout(0); // set to standard-layout
1574 cursor.par->Next()->SetLayout(0); // set to standard-layout
1577 /* if the cursor is at the beginning of a row without prior newline,
1579 * This touches only the screen-update. Otherwise we would may have
1580 * an empty row on the screen */
1581 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1582 cursor.row->pos == cursor.pos) {
1586 status = LyXText::NEED_MORE_REFRESH;
1587 refresh_row = cursor.row;
1588 refresh_y = cursor.y - cursor.row->baseline;
1590 // Do not forget the special right address boxes
1591 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1592 while (refresh_row->previous &&
1593 refresh_row->previous->par == refresh_row->par) {
1594 refresh_row = refresh_row->previous;
1595 refresh_y -= refresh_row->height;
1598 RemoveParagraph(cursor.row);
1600 // set the dimensions of the cursor row
1601 cursor.row->fill = Fill(cursor.row, paperwidth);
1603 SetHeightOfRow(cursor.row);
1605 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1606 && cursor.par->Next()->IsNewline(0))
1607 cursor.par->Next()->Erase(0);
1609 InsertParagraph(cursor.par->Next(), cursor.row);
1611 UpdateCounters(cursor.row->previous);
1613 /* This check is necessary. Otherwise the new empty paragraph will
1614 * be deleted automatically. And it is more friendly for the user! */
1616 SetCursor(cursor.par->Next(), 0);
1618 SetCursor(cursor.par, 0);
1620 if (cursor.row->next)
1621 BreakAgain(cursor.row->next);
1627 void LyXText::OpenFootnote()
1629 LyXParagraph * endpar,* tmppar;
1632 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1634 /* if there is no footnote in this paragraph, just return. */
1636 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1639 /* ok, move the cursor right before the footnote */
1641 /* just a little faster than using CursorRight() */
1642 for (cursor.pos = 0;
1643 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1644 /* now the cursor is at the beginning of the physical par */
1645 SetCursor(cursor.par,
1646 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1648 /* the cursor must be exactly before the footnote */
1649 par = cursor.par->ParFromPos(cursor.pos);
1651 status = LyXText::NEED_MORE_REFRESH;
1652 refresh_row = cursor.row;
1653 refresh_y = cursor.y - cursor.row->baseline;
1655 tmppar = cursor.par;
1656 endpar = cursor.par->Next();
1659 tmppar->OpenFootnote(cursor.pos);
1660 RemoveParagraph(row);
1661 /* set the dimensions of the cursor row */
1662 row->fill = Fill(row, paperwidth);
1663 SetHeightOfRow(row);
1664 tmppar = tmppar->Next();
1666 while (tmppar != endpar) {
1668 InsertParagraph(tmppar, row);
1669 while (row->next && row->next->par == tmppar)
1671 tmppar = tmppar->Next();
1674 SetCursor(par->next, 0);
1675 sel_cursor = cursor;
1679 /* table stuff -- begin*/
1681 void LyXText::TableFeatures(int feature, string const & val) const
1683 if (!cursor.par->table)
1684 return; /* this should never happen */
1686 int actCell = NumberOfCell(cursor.par, cursor.pos);
1687 SetUndo(Undo::FINISH,
1688 cursor.par->ParFromPos(cursor.pos)->previous,
1689 cursor.par->ParFromPos(cursor.pos)->next);
1692 case LyXTable::SET_PWIDTH:
1693 cursor.par->table->SetPWidth(actCell, val);
1695 case LyXTable::SET_SPECIAL_COLUMN:
1696 case LyXTable::SET_SPECIAL_MULTI:
1697 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1706 void LyXText::TableFeatures(int feature) const
1709 int setAlign = LYX_ALIGN_LEFT;
1713 if (!cursor.par->table)
1714 return; /* this should never happen */
1716 int actCell = NumberOfCell(cursor.par, cursor.pos);
1717 SetUndo(Undo::FINISH,
1718 cursor.par->ParFromPos(cursor.pos)->previous,
1719 cursor.par->ParFromPos(cursor.pos)->next);
1722 case LyXTable::ALIGN_LEFT:
1723 setAlign= LYX_ALIGN_LEFT;
1725 case LyXTable::ALIGN_RIGHT:
1726 setAlign= LYX_ALIGN_RIGHT;
1728 case LyXTable::ALIGN_CENTER:
1729 setAlign= LYX_ALIGN_CENTER;
1735 case LyXTable::APPEND_ROW: {
1736 LyXParagraph::size_type pos = cursor.pos;
1738 /* move to the next row */
1739 int cell_org = actCell;
1740 int cell = cell_org;
1742 // if there is a ContRow following this row I have to add
1743 // the row after the ContRow's
1744 if ((pos < cursor.par->Last()) &&
1745 cursor.par->table->RowHasContRow(cell_org)) {
1746 while((pos < cursor.par->Last()) &&
1747 !cursor.par->table->IsContRow(cell)) {
1748 while (pos < cursor.par->Last() &&
1749 !cursor.par->IsNewline(pos))
1751 if (pos < cursor.par->Last())
1755 while((pos < cursor.par->Last()) &&
1756 cursor.par->table->IsContRow(cell)) {
1757 while (pos < cursor.par->Last() &&
1758 !cursor.par->IsNewline(pos))
1760 if (pos < cursor.par->Last())
1765 if (pos < cursor.par->Last())
1768 while (pos < cursor.par->Last() &&
1769 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1770 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1772 if (pos < cursor.par->Last())
1777 /* insert the new cells */
1778 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1779 for (int i = 0; i < number; ++i)
1780 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1782 /* append the row into the table */
1783 cursor.par->table->AppendRow(cell_org);
1787 case LyXTable::APPEND_CONT_ROW: {
1788 LyXParagraph::size_type pos = cursor.pos;
1789 /* move to the next row */
1790 int cell_org = actCell;
1791 int cell = cell_org;
1793 // if there is already a controw but not for this cell
1794 // the AppendContRow sets only the right values but does
1795 // not actually add a row
1796 if (cursor.par->table->RowHasContRow(cell_org) &&
1797 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1798 cursor.par->table->AppendContRow(cell_org);
1802 while (pos < cursor.par->Last() &&
1804 || !cursor.par->table->IsFirstCell(cell))){
1805 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1807 if (pos < cursor.par->Last())
1812 /* insert the new cells */
1813 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1814 for (int i = 0; i < number; ++i)
1815 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1817 /* append the row into the table */
1818 cursor.par->table->AppendContRow(cell_org);
1822 case LyXTable::APPEND_COLUMN: {
1823 LyXParagraph::size_type pos = 0;
1824 int cell_org = actCell;
1827 if (pos && (cursor.par->IsNewline(pos-1))){
1828 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1829 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1830 if (pos <= cursor.pos)
1837 } while (pos <= cursor.par->Last());
1838 /* remember that the very last cell doesn't end with a newline.
1839 This saves one byte memory per table ;-) */
1840 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1841 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1843 /* append the column into the table */
1844 cursor.par->table->AppendColumn(cell_org);
1849 case LyXTable::DELETE_ROW:
1850 if (owner_->the_locking_inset)
1851 owner_->unlockInset(owner_->the_locking_inset);
1852 RemoveTableRow(&cursor);
1856 case LyXTable::DELETE_COLUMN: {
1857 LyXParagraph::size_type pos = 0;
1858 int cell_org = actCell;
1860 if (owner_->the_locking_inset)
1861 owner_->unlockInset(owner_->the_locking_inset);
1863 if (!pos || (cursor.par->IsNewline(pos-1))){
1864 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1866 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1867 cursor.par->Erase(pos);
1868 if (pos < cursor.par->Last())
1869 cursor.par->Erase(pos);
1871 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1872 --pos; // because of pos++ below
1877 } while (pos <= cursor.par->Last());
1879 /* delete the column from the table */
1880 cursor.par->table->DeleteColumn(cell_org);
1882 /* set the cursor to the beginning of the table, where else? */
1887 case LyXTable::TOGGLE_LINE_TOP:
1888 lineSet = !cursor.par->table->TopLine(actCell);
1890 cursor.par->table->SetTopLine(actCell, lineSet);
1892 LyXParagraph::size_type i;
1894 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1895 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1896 cursor.par->table->SetTopLine(n, lineSet);
1904 case LyXTable::TOGGLE_LINE_BOTTOM:
1905 lineSet = !cursor.par->table->BottomLine(actCell);
1907 cursor.par->table->SetBottomLine(actCell, lineSet);
1909 LyXParagraph::size_type i;
1911 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1912 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1913 cursor.par->table->SetBottomLine(n, lineSet);
1921 case LyXTable::TOGGLE_LINE_LEFT:
1922 lineSet = !cursor.par->table->LeftLine(actCell);
1924 cursor.par->table->SetLeftLine(actCell, lineSet);
1926 LyXParagraph::size_type i;
1928 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1929 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1930 cursor.par->table->SetLeftLine(n, lineSet);
1938 case LyXTable::TOGGLE_LINE_RIGHT:
1939 lineSet = !cursor.par->table->RightLine(actCell);
1941 cursor.par->table->SetRightLine(actCell, lineSet);
1944 LyXParagraph::size_type i = sel_start_cursor.pos;
1945 for (; i <= sel_end_cursor.pos; ++i) {
1946 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1947 cursor.par->table->SetRightLine(n, lineSet);
1955 case LyXTable::ALIGN_LEFT:
1956 case LyXTable::ALIGN_RIGHT:
1957 case LyXTable::ALIGN_CENTER:
1959 cursor.par->table->SetAlignment(actCell, setAlign);
1962 LyXParagraph::size_type i = sel_start_cursor.pos;
1963 for (; i <= sel_end_cursor.pos; ++i) {
1964 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1965 cursor.par->table->SetAlignment(n, setAlign);
1973 case LyXTable::DELETE_TABLE:
1974 SetCursorIntern(cursor.par, 0);
1975 delete cursor.par->table;
1976 cursor.par->table = 0;
1977 // temporary: Should put table in simple_cut_buffer (with before and after
1978 // dummy-paragraph !!
1979 // not necessar anymore with UNDO :)
1980 for (LyXParagraph::size_type i =
1981 cursor.par->text.size() - 1; i >= 0; --i)
1982 cursor.par->Erase(i);
1986 case LyXTable::MULTICOLUMN: {
1988 // check wether we are completly in a multicol
1989 int multicol = cursor.par->table->IsMultiColumn(actCell);
1990 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1991 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1992 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
1996 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
1997 LyXParagraph::size_type pos = cursor.pos;
1998 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2000 for (; newlines; --newlines)
2001 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2006 // selection must be in one row (or no selection)
2008 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2015 if (sel_start_cursor.row == sel_end_cursor.row){
2016 LyXParagraph::size_type i;
2018 for (i = sel_start_cursor.pos;
2019 i < sel_end_cursor.pos; ++i){
2020 if (sel_start_cursor.par->IsNewline(i)){
2021 sel_start_cursor.par->Erase(i);
2022 // check for double-blanks
2023 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2025 (i < sel_start_cursor.par->Last()
2026 && !sel_start_cursor.par->IsLineSeparator(i)))
2027 sel_start_cursor.par->InsertChar(i, ' ');
2029 sel_end_cursor.pos--;
2036 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2037 sel_start_cursor.pos),
2039 cursor.pos = sel_start_cursor.pos;
2044 WriteAlert(_("Impossible Operation!"),
2045 _("Multicolumns can only be horizontally."),
2052 case LyXTable::SET_ALL_LINES:
2054 case LyXTable::UNSET_ALL_LINES:
2056 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2060 LyXParagraph::size_type i;
2062 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2063 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2064 cursor.par->table->SetAllLines(n, setLines);
2071 case LyXTable::SET_LONGTABLE:
2072 cursor.par->table->SetLongTable(true);
2074 case LyXTable::UNSET_LONGTABLE:
2075 cursor.par->table->SetLongTable(false);
2077 case LyXTable::SET_ROTATE_TABLE:
2078 cursor.par->table->SetRotateTable(true);
2080 case LyXTable::UNSET_ROTATE_TABLE:
2081 cursor.par->table->SetRotateTable(false);
2083 case LyXTable::SET_ROTATE_CELL:
2085 cursor.par->table->SetRotateCell(actCell, true);
2087 LyXParagraph::size_type i;
2089 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2090 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2091 cursor.par->table->SetRotateCell(n, true);
2097 case LyXTable::UNSET_ROTATE_CELL:
2099 cursor.par->table->SetRotateCell(actCell, false);
2102 LyXParagraph::size_type i = sel_start_cursor.pos;
2103 for (; i <= sel_end_cursor.pos; ++i) {
2104 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2105 cursor.par->table->SetRotateCell(n, false);
2111 case LyXTable::SET_LINEBREAKS:
2112 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2114 cursor.par->table->SetLinebreaks(actCell, what);
2116 LyXParagraph::size_type i;
2118 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2119 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2120 cursor.par->table->SetLinebreaks(n, what);
2126 case LyXTable::SET_LTFIRSTHEAD:
2127 cursor.par->table->SetLTHead(actCell, true);
2129 case LyXTable::SET_LTHEAD:
2130 cursor.par->table->SetLTHead(actCell, false);
2132 case LyXTable::SET_LTFOOT:
2133 cursor.par->table->SetLTFoot(actCell, false);
2135 case LyXTable::SET_LTLASTFOOT:
2136 cursor.par->table->SetLTFoot(actCell, true);
2138 case LyXTable::SET_LTNEWPAGE:
2139 what = !cursor.par->table->LTNewPage(actCell);
2140 cursor.par->table->SetLTNewPage(actCell, what);
2146 void LyXText::InsertCharInTable(char c)
2151 bool jumped_over_space;
2153 /* first check, if there will be two blanks together or a blank at
2154 * the beginning of a paragraph.
2155 * I decided to handle blanks like normal characters, the main
2156 * difference are the special checks when calculating the row.fill
2157 * (blank does not count at the end of a row) and the check here */
2159 LyXFont realtmpfont = real_current_font;
2160 LyXFont rawtmpfont = current_font; /* store the current font.
2161 * This is because of the use
2162 * of cursor movements. The moving
2163 * cursor would refresh the
2166 // Get the font that is used to calculate the baselineskip
2167 LyXParagraph::size_type const lastpos =
2169 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2171 jumped_over_space = false;
2172 if (IsLineSeparatorChar(c)) {
2174 #ifndef FIX_DOUBLE_SPACE
2175 /* avoid double blanks but insert the new blank because
2176 * of a possible font change */
2177 if (cursor.pos < lastpos &&
2178 cursor.par->IsLineSeparator(cursor.pos)) {
2179 cursor.par->Erase(cursor.pos);
2180 jumped_over_space = true;
2183 if ((cursor.pos > 0 &&
2184 cursor.par->IsLineSeparator(cursor.pos - 1))
2185 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2186 || (cursor.pos == 0 &&
2187 !(cursor.par->Previous()
2188 && cursor.par->Previous()->footnoteflag
2189 == LyXParagraph::OPEN_FOOTNOTE)))
2191 } else if (IsNewlineChar(c)) {
2192 if (!IsEmptyTableCell()) {
2193 TableFeatures(LyXTable::APPEND_CONT_ROW);
2200 y = cursor.y - row->baseline;
2201 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2202 * already inserted the character */
2203 cursor.par->InsertChar(cursor.pos, c);
2204 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2206 if (!jumped_over_space) {
2207 /* refresh the positions */
2209 while (tmprow->next && tmprow->next->par == row->par) {
2210 tmprow = tmprow->next;
2217 CheckParagraphInTable(cursor.par, cursor.pos);
2219 current_font = rawtmpfont;
2220 real_current_font = realtmpfont;
2222 /* check, whether the last character's font has changed. */
2223 if (cursor.pos && cursor.pos == cursor.par->Last()
2224 && rawparfont != rawtmpfont)
2225 RedoHeightOfParagraph(cursor);
2229 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2230 LyXParagraph::size_type pos)
2233 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2234 par->GetInset(pos) && par->GetInset(pos)->display()){
2235 par->GetInset(pos)->display(false);
2239 Row * row = GetRow(par, pos, y);
2241 int tmpheight = row->height;
2242 SetHeightOfRow(row);
2244 LyXParagraph::size_type tmp_pos = pos;
2245 /* update the table information */
2246 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2248 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2249 WidthOfCell(par, tmp_pos))) {
2250 LyXCursor tmpcursor = cursor;
2251 SetCursorIntern(par, pos);
2252 /* make a complete redraw */
2253 RedoDrawingOfParagraph(cursor);
2257 /* redraw only the row */
2258 LyXCursor tmpcursor = cursor;
2259 SetCursorIntern(par, pos);
2261 refresh_x = cursor.x;
2263 refresh_pos = cursor.pos;
2266 if (tmpheight == row->height)
2267 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2269 status = LyXText::NEED_MORE_REFRESH;
2271 SetCursorIntern(cursor.par, cursor.pos);
2275 void LyXText::BackspaceInTable()
2277 Row * tmprow, * row;
2280 LyXFont rawtmpfont = current_font;
2281 LyXFont realtmpfont = real_current_font;
2283 // Get the font that is used to calculate the baselineskip
2284 int const lastpos = cursor.par->Last();
2285 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2287 if (cursor.pos == 0) {
2288 /* no pasting of table paragraphs */
2292 /* this is the code for a normal backspace, not pasting
2294 SetUndo(Undo::DELETE,
2295 cursor.par->ParFromPos(cursor.pos)->previous,
2296 cursor.par->ParFromPos(cursor.pos)->next);
2300 /* some insets are undeletable here */
2301 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2302 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2307 y = cursor.y - row->baseline;
2309 /* some special code when deleting a newline. */
2310 if (cursor.par->IsNewline(cursor.pos)) {
2315 cursor.par->Erase(cursor.pos);
2317 /* refresh the positions */
2319 while (tmprow->next && tmprow->next->par == row->par) {
2320 tmprow = tmprow->next;
2324 #ifndef FIX_DOUBLE_SPACE
2325 /* delete superfluous blanks */
2326 if (cursor.pos < cursor.par->Last() - 1 &&
2327 (cursor.par->IsLineSeparator(cursor.pos))) {
2329 if (cursor.pos == BeginningOfMainBody(cursor.par)
2331 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2332 cursor.par->Erase(cursor.pos);
2333 /* refresh the positions */
2335 while (tmprow->next &&
2336 tmprow->next->par == row->par) {
2337 tmprow = tmprow->next;
2340 if (cursor.pos) /* move one character left */
2347 CheckParagraphInTable(cursor.par, cursor.pos);
2349 /* check, wether the last characters font has changed. */
2350 if (cursor.pos && cursor.pos == cursor.par->Last()
2351 && rawparfont != rawtmpfont)
2352 RedoHeightOfParagraph(cursor);
2354 /* restore the current font
2355 * That is what a user expects! */
2356 current_font = rawtmpfont;
2357 real_current_font = realtmpfont;
2359 SetCursorIntern(cursor.par, cursor.pos);
2362 /* table stuff -- end*/
2365 /* just a macro to make some thing easier. */
2366 void LyXText::RedoParagraph() const
2369 // I suspect this version will work
2372 RedoParagraphs(cursor, cursor.par->Next());
2373 SetCursorIntern(cursor.par, cursor.pos);
2375 LyXCursor tmpcursor = cursor;
2377 RedoParagraphs(cursor, cursor.par->Next());
2378 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2383 /* insert a character, moves all the following breaks in the
2384 * same Paragraph one to the right and make a rebreak */
2385 void LyXText::InsertChar(char c)
2387 SetUndo(Undo::INSERT,
2388 cursor.par->ParFromPos(cursor.pos)->previous,
2389 cursor.par->ParFromPos(cursor.pos)->next);
2391 /* When the free-spacing option is set for the current layout,
2392 * all spaces are converted to protected spaces. */
2393 bool freeSpacingBo =
2394 textclasslist.Style(parameters->textclass,
2395 cursor.row->par->GetLayout()).free_spacing;
2397 if (freeSpacingBo && IsLineSeparatorChar(c)
2398 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2399 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2401 /* table stuff -- begin*/
2402 if (cursor.par->table) {
2403 InsertCharInTable(c);
2407 /* table stuff -- end*/
2409 /* First check, if there will be two blanks together or a blank at
2410 the beginning of a paragraph.
2411 I decided to handle blanks like normal characters, the main
2412 difference are the special checks when calculating the row.fill
2413 (blank does not count at the end of a row) and the check here */
2415 // The bug is triggered when we type in a description environment:
2416 // The current_font is not changed when we go from label to main text
2417 // and it should (along with realtmpfont) when we type the space.
2418 #ifdef WITH_WARNINGS
2419 #warning There is a bug here! (Asger)
2422 LyXFont realtmpfont = real_current_font;
2423 LyXFont rawtmpfont = current_font; /* store the current font.
2424 * This is because of the use
2425 * of cursor movements. The moving
2426 * cursor would refresh the
2429 // Get the font that is used to calculate the baselineskip
2430 LyXParagraph::size_type lastpos = cursor.par->Last();
2431 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2433 bool jumped_over_space = false;
2435 if (IsLineSeparatorChar(c)) {
2436 #ifndef FIX_DOUBLE_SPACE
2437 if (cursor.pos < lastpos
2438 && cursor.par->IsLineSeparator(cursor.pos)) {
2439 /* the user inserted a space before a space. So we
2440 * will just make a CursorRight. BUT: The font of this
2441 * space should be set to current font. That is why
2442 * we need to rebreak perhaps. If there is a protected
2443 * blank at the end of a row we have to force
2446 owner_->owner()->getMiniBuffer()
2447 ->Set(_("You cannot type two spaces this way. "
2448 " Please read the Tutorial."));
2450 // How can this ever happen?
2451 if (cursor.pos == RowLast(cursor.row)
2452 && !IsLineSeparatorChar(c))
2453 cursor.row->fill = -1; // force rebreak
2454 cursor.par->Erase(cursor.pos);
2455 jumped_over_space = true;
2457 // Seems to me that this works just as well.
2465 && cursor.par->IsLineSeparator(cursor.pos - 1))
2467 && cursor.par->IsNewline(cursor.pos - 1))
2469 && !(cursor.par->Previous()
2470 && cursor.par->Previous()->footnoteflag
2471 == LyXParagraph::OPEN_FOOTNOTE))) {
2472 if (cursor.pos == 0 )
2473 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2475 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2479 } else if (IsNewlineChar(c)) {
2480 if (cursor.par->FirstPhysicalPar() == cursor.par
2481 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2485 /* No newline at first position
2486 * of a paragraph or behind labels.
2487 * TeX does not allow that. */
2489 if (cursor.pos < cursor.par->Last() &&
2490 cursor.par->IsLineSeparator(cursor.pos))
2491 CursorRightIntern(); // newline always after a blank!
2492 cursor.row->fill = -1; // to force a new break
2495 // the display inset stuff
2496 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2497 && cursor.row->par->GetInset(cursor.row->pos)
2498 && cursor.row->par->GetInset(cursor.row->pos)->display())
2499 cursor.row->fill = -1; // to force a new break
2501 // get the cursor row fist
2502 Row * row = cursor.row;
2503 long y = cursor.y - row->baseline;
2504 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2505 * already insertet the character */
2506 cursor.par->InsertChar(cursor.pos, c);
2507 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2509 if (!jumped_over_space) {
2510 // refresh the positions
2512 while (tmprow->next && tmprow->next->par == row->par) {
2513 tmprow = tmprow->next;
2518 // Is there a break one row above
2519 if ((cursor.par->IsLineSeparator(cursor.pos)
2520 || cursor.par->IsNewline(cursor.pos)
2521 || cursor.row->fill == -1)
2522 && row->previous && row->previous->par == row->par) {
2523 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2525 if ( z >= row->pos) {
2528 // set the dimensions of the row above
2529 row->previous->fill = Fill(row->previous, paperwidth);
2531 SetHeightOfRow(row->previous);
2533 y -= row->previous->height;
2535 refresh_row = row->previous;
2536 status = LyXText::NEED_MORE_REFRESH;
2538 BreakAgainOneRow(row);
2540 current_font = rawtmpfont;
2541 real_current_font = realtmpfont;
2542 SetCursor(cursor.par, cursor.pos + 1, false);
2543 /* cursor MUST be in row now */
2545 if (row->next && row->next->par == row->par)
2546 need_break_row = row->next;
2550 // check, wether the last characters font has changed.
2551 if (cursor.pos && cursor.pos == cursor.par->Last()
2552 && rawparfont != rawtmpfont)
2553 RedoHeightOfParagraph(cursor);
2560 /* recalculate the fill of the row */
2561 if (row->fill >= 0) /* needed because a newline
2562 * will set fill to -1. Otherwise
2563 * we would not get a rebreak! */
2564 row->fill = Fill(row, paperwidth);
2565 if (row->fill < 0 ) {
2568 refresh_x = cursor.x;
2569 refresh_pos = cursor.pos;
2570 status = LyXText::NEED_MORE_REFRESH;
2571 BreakAgainOneRow(row);
2572 /* will the cursor be in another row now? */
2573 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2574 if (row->next && row->next->par == row->par)
2578 BreakAgainOneRow(row);
2580 current_font = rawtmpfont;
2581 real_current_font = realtmpfont;
2582 SetCursor(cursor.par, cursor.pos + 1, false);
2583 if (row->next && row->next->par == row->par)
2584 need_break_row = row->next;
2589 refresh_x = cursor.x;
2591 refresh_pos = cursor.pos;
2593 int tmpheight = row->height;
2594 SetHeightOfRow(row);
2595 if (tmpheight == row->height)
2596 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2598 status = LyXText::NEED_MORE_REFRESH;
2600 current_font = rawtmpfont;
2601 real_current_font = realtmpfont;
2602 SetCursor(cursor.par, cursor.pos + 1, false);
2605 /* check, wether the last characters font has changed. */
2606 if (cursor.pos && cursor.pos == cursor.par->Last()
2607 && rawparfont != rawtmpfont) {
2608 RedoHeightOfParagraph(cursor);
2610 /* now the special right address boxes */
2611 if (textclasslist.Style(parameters->textclass,
2612 cursor.par->GetLayout()).margintype
2613 == MARGIN_RIGHT_ADDRESS_BOX) {
2614 RedoDrawingOfParagraph(cursor);
2622 void LyXText::charInserted()
2624 // Here we could call FinishUndo for every 20 characters inserted.
2625 // This is from my experience how emacs does it.
2626 static unsigned int counter = 0;
2635 void LyXText::PrepareToPrint(Row * row, float & x,
2636 float & fill_separator,
2638 float & fill_label_hfill,
2643 float w = row->fill;
2645 fill_label_hfill = 0;
2647 fill_label_hfill = 0;
2649 LyXDirection direction = row->par->getParDirection();
2651 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2652 x = RightMargin(row);
2653 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2654 LyXFont font(LyXFont::ALL_SANE);
2655 font.setSize(LyXFont::SIZE_SMALL);
2656 x += font.textWidth("Mwide-figM", 10);
2660 x = LeftMargin(row);
2662 /* is there a manual margin with a manual label */
2663 if (textclasslist.Style(parameters->textclass,
2664 row->par->GetLayout()).margintype == MARGIN_MANUAL
2665 && textclasslist.Style(parameters->textclass,
2666 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2668 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2669 * are left aligned*/
2670 if (nlh && !row->par->GetLabelWidthString().empty()) {
2671 fill_label_hfill = LabelFill(row) / nlh;
2675 /* are there any hfills in the row? */
2676 nh = NumberOfHfills(row);
2678 /* table stuff -- begin*/
2679 if (row->par->table) {
2680 w = paperwidth - row->par->table->WidthOfTable()
2681 - x - RightMargin(row);
2682 nh = 0; /* ignore hfills in tables */
2684 /* table stuff -- end*/
2689 /* is it block, flushleft or flushright?
2690 * set x how you need it */
2692 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2693 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2695 align = row->par->FirstPhysicalPar()->align;
2697 /* center displayed insets */
2698 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2699 && row->par->GetInset(row->pos)
2700 && row->par->GetInset(row->pos)->display())
2701 align = LYX_ALIGN_CENTER;
2704 case LYX_ALIGN_BLOCK:
2705 ns = NumberOfSeparators(row);
2706 if (ns && row->next && row->next->par == row->par &&
2707 !(row->next->par->IsNewline(row->next->pos-1))
2708 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2709 && row->next->par->GetInset(row->next->pos)
2710 && row->next->par->GetInset(row->next->pos)->display())
2712 fill_separator = w / ns;
2713 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2716 case LYX_ALIGN_RIGHT:
2719 case LYX_ALIGN_CENTER:
2727 ComputeBidiTables(row);
2728 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2729 LyXParagraph::size_type main_body =
2730 BeginningOfMainBody(row->par);
2731 LyXParagraph::size_type last = RowLast(row);
2733 if (row->pos <= last
2735 && last != vis2log(last)
2736 && row->par->IsLineSeparator(last)) {
2737 if (!(main_body > 0 && main_body-1 == last))
2738 x -= fill_separator+SingleWidth(row->par,last);
2739 } else if (main_body > 0 &&
2740 (main_body-1 > last ||
2741 !row->par->IsLineSeparator(main_body-1))) {
2742 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2743 row->par->GetLayout());
2744 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2745 if (main_body-1 <= last)
2746 x += fill_label_hfill;
2751 /* important for the screen */
2754 /* the cursor set functions have a special mechanism. When they
2755 * realize, that you left an empty paragraph, they will delete it.
2756 * They also delete the corresponding row */
2758 void LyXText::CursorRightOneWord() const
2760 // treat floats, HFills and Insets as words
2761 LyXCursor tmpcursor = cursor;
2763 if (tmpcursor.pos == tmpcursor.par->Last()
2764 && tmpcursor.par->Next())
2766 tmpcursor.par = tmpcursor.par->Next();
2771 // Skip through initial nonword stuff.
2772 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2773 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2775 // printf("Current pos1 %d", tmpcursor.pos) ;
2779 // Advance through word.
2780 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2781 tmpcursor.par->IsWord( tmpcursor.pos ) )
2783 // printf("Current pos2 %d", tmpcursor.pos) ;
2788 SetCursor(tmpcursor.par, tmpcursor.pos);
2792 void LyXText::CursorTab() const
2794 if (cursor.par->table) {
2795 int cell = NumberOfCell(cursor.par, cursor.pos);
2796 while(cursor.par->table->IsContRow(cell)) {
2798 cell = NumberOfCell(cursor.par, cursor.pos);
2800 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2801 TableFeatures(LyXTable::APPEND_ROW);
2803 LyXCursor tmpcursor = cursor;
2804 while (tmpcursor.pos < tmpcursor.par->Last()
2805 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2808 if (tmpcursor.pos == tmpcursor.par->Last()){
2809 if (tmpcursor.par->Next()) {
2810 tmpcursor.par = tmpcursor.par->Next();
2816 SetCursor(tmpcursor.par, tmpcursor.pos);
2817 if (cursor.par->table) {
2818 int cell = NumberOfCell(cursor.par, cursor.pos);
2819 while (cursor.par->table->IsContRow(cell) &&
2820 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2822 while (tmpcursor.pos < tmpcursor.par->Last()
2823 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2826 if (tmpcursor.pos == tmpcursor.par->Last()){
2827 if (tmpcursor.par->Next()) {
2828 tmpcursor.par = tmpcursor.par->Next();
2834 SetCursor(tmpcursor.par, tmpcursor.pos);
2835 cell = NumberOfCell(cursor.par, cursor.pos);
2841 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2842 of prior word, not to end of next prior word. */
2844 void LyXText::CursorLeftOneWord() const
2846 // treat HFills, floats and Insets as words
2847 LyXCursor tmpcursor = cursor;
2848 while (tmpcursor.pos
2849 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2850 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2851 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2852 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2853 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2857 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2858 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2859 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2861 } else if (!tmpcursor.pos) {
2862 if (tmpcursor.par->Previous()){
2863 tmpcursor.par = tmpcursor.par->Previous();
2864 tmpcursor.pos = tmpcursor.par->Last();
2866 } else { // Here, tmpcursor != 0
2867 while (tmpcursor.pos > 0 &&
2868 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2871 SetCursor(tmpcursor.par, tmpcursor.pos);
2874 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2877 void LyXText::SelectWord()
2879 /* Move cursor to the beginning, when not already there. */
2881 && !cursor.par->IsSeparator(cursor.pos-1)
2882 && !cursor.par->IsKomma(cursor.pos-1) )
2883 CursorLeftOneWord();
2885 /* set the sel cursor */
2886 sel_cursor = cursor;
2888 while ( cursor.pos < cursor.par->Last()
2889 && !cursor.par->IsSeparator(cursor.pos)
2890 && !cursor.par->IsKomma(cursor.pos) )
2892 SetCursor( cursor.par, cursor.pos );
2894 /* finally set the selection */
2899 /* -------> Select the word currently under the cursor when:
2900 1: no selection is currently set,
2901 2: the cursor is not at the borders of the word. */
2903 int LyXText::SelectWordWhenUnderCursor()
2905 if ( selection ) return 0;
2906 if ( cursor.pos < cursor.par->Last()
2907 && !cursor.par->IsSeparator(cursor.pos)
2908 && !cursor.par->IsKomma(cursor.pos)
2910 && !cursor.par->IsSeparator(cursor.pos -1)
2911 && !cursor.par->IsKomma(cursor.pos -1) ) {
2919 // This function is only used by the spellchecker for NextWord().
2920 // It doesn't handle LYX_ACCENTs and probably never will.
2921 char * LyXText::SelectNextWord(float & value)
2923 LyXParagraph * tmppar = cursor.par;
2925 // If this is not the very first word, skip rest of
2926 // current word because we are probably in the middle
2927 // of a word if there is text here.
2928 if (cursor.pos || cursor.par->previous) {
2929 while (cursor.pos < cursor.par->Last()
2930 && cursor.par->IsLetter(cursor.pos))
2933 // Now, skip until we have real text (will jump paragraphs)
2934 while ((cursor.par->Last() > cursor.pos
2935 && (!cursor.par->IsLetter(cursor.pos)
2936 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2937 || (cursor.par->Last() == cursor.pos
2938 && cursor.par->Next())){
2939 if (cursor.pos == cursor.par->Last()) {
2940 cursor.par = cursor.par->Next();
2947 // Update the value if we changed paragraphs
2948 if (cursor.par != tmppar){
2949 SetCursor(cursor.par, cursor.pos);
2950 value = float(cursor.y)/float(height);
2953 /* Start the selection from here */
2954 sel_cursor = cursor;
2958 /* and find the end of the word
2959 (optional hyphens are part of a word) */
2960 while (cursor.pos < cursor.par->Last()
2961 && (cursor.par->IsLetter(cursor.pos))
2962 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2963 cursor.par->GetInset(cursor.pos) != 0 &&
2964 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2968 // Finally, we copy the word to a string and return it
2971 if (sel_cursor.pos < cursor.pos) {
2972 str = new char [cursor.pos - sel_cursor.pos + 2];
2973 LyXParagraph::size_type i, j;
2974 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2975 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
2976 str[j++] = cursor.par->GetChar(i);
2984 // This one is also only for the spellchecker
2985 void LyXText::SelectSelectedWord()
2987 /* move cursor to the beginning */
2988 SetCursor(sel_cursor.par, sel_cursor.pos);
2990 /* set the sel cursor */
2991 sel_cursor = cursor;
2995 /* now find the end of the word */
2996 while (cursor.pos < cursor.par->Last()
2997 && (cursor.par->IsLetter(cursor.pos)
2998 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2999 cursor.par->GetInset(cursor.pos) != 0 &&
3000 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3004 SetCursor(cursor.par, cursor.pos);
3006 /* finally set the selection */
3011 /* -------> Delete from cursor up to the end of the current or next word. */
3012 void LyXText::DeleteWordForward()
3014 LyXCursor tmpcursor = cursor;
3016 if (!cursor.par->Last())
3019 /* -------> Skip initial non-word stuff. */
3020 while ( cursor.pos < cursor.par->Last()
3021 && (cursor.par->IsSeparator(cursor.pos)
3022 || cursor.par->IsKomma(cursor.pos)) )
3025 SetCursorIntern(cursor.par, cursor.pos);
3026 selection = True; // to avoid deletion
3027 CursorRightOneWord();
3028 sel_cursor = cursor;
3032 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3038 /* -------> Delete from cursor to start of current or prior word. */
3039 void LyXText::DeleteWordBackward()
3041 LyXCursor tmpcursor = cursor;
3042 if (!cursor.par->Last())
3045 selection = true; // to avoid deletion
3046 CursorLeftOneWord();
3047 sel_cursor = cursor;
3055 /* -------> Kill to end of line. */
3056 void LyXText::DeleteLineForward()
3058 LyXCursor tmpcursor = cursor;
3059 if (!cursor.par->Last())
3063 sel_cursor = cursor;
3066 if (selection == false) {
3067 DeleteWordForward();
3075 // Change the case of a word at cursor position. The meaning of action
3077 // 0 change to lowercase
3078 // 1 capitalize word
3079 // 2 change to uppercase
3080 // This function directly manipulates LyXParagraph::text because there
3081 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3082 // that it is correct. I guess part of it should be moved to
3083 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3084 // it does not access outside of the allocated array as the older
3085 // version did. (JMarc)
3086 void LyXText::ChangeWordCase(LyXText::TextCase action)
3088 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3090 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3092 LyXParagraph::size_type tmppos =
3093 cursor.par->PositionInParFromPos(cursor.pos);
3094 while (tmppos < tmppar->size()) {
3095 unsigned char c = tmppar->text[tmppos];
3096 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3098 if (c != LyXParagraph::META_INSET) {
3100 case text_lowercase:
3103 case text_capitalization:
3105 action = text_lowercase;
3107 case text_uppercase:
3113 tmppar->text[tmppos] = c;
3116 CheckParagraph(tmppar, tmppos);
3117 CursorRightOneWord();
3121 void LyXText::Delete()
3123 // this is a very easy implementation
3125 LyXCursor old_cursor = cursor;
3126 int old_cur_par_id = old_cursor.par->id();
3127 int old_cur_par_prev_id = old_cursor.par->previous ?
3128 old_cursor.par->previous->id() : 0;
3130 // just move to the right
3131 CursorRightIntern();
3133 // This check is not very good...
3134 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3135 // and that can very well delete the par or par->previous in
3136 // old_cursor. Will a solution where we compare paragraph id's
3139 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3140 == old_cur_par_prev_id
3141 && cursor.par->id() != old_cur_par_id)
3142 return; // delete-empty-paragraph-mechanism has done it
3144 if (cursor.par->previous == old_cursor.par->previous
3145 && cursor.par != old_cursor.par)
3146 return; // delete-empty-paragraph-mechanism has done it
3148 // if you had success make a backspace
3149 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3150 LyXCursor tmpcursor = cursor;
3151 cursor = old_cursor; // to make sure undo gets the right cursor position
3152 SetUndo(Undo::DELETE,
3153 cursor.par->ParFromPos(cursor.pos)->previous,
3154 cursor.par->ParFromPos(cursor.pos)->next);
3161 void LyXText::Backspace()
3163 LyXParagraph * tmppar;
3164 Row * tmprow, * row;
3168 /* table stuff -- begin */
3169 if (cursor.par->table) {
3173 /* table stuff -- end */
3175 LyXFont rawtmpfont = current_font;
3176 LyXFont realtmpfont = real_current_font;
3178 // Get the font that is used to calculate the baselineskip
3179 int const lastpos = cursor.par->Last();
3180 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3182 if (cursor.pos == 0) {
3183 // we may paste some paragraphs
3185 // is it an empty paragraph?
3188 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3189 && !(cursor.par->Next()
3190 && cursor.par->footnoteflag ==
3191 LyXParagraph::NO_FOOTNOTE
3192 && cursor.par->Next()->footnoteflag ==
3193 LyXParagraph::OPEN_FOOTNOTE)) {
3195 if (cursor.par->previous) {
3196 tmppar = cursor.par->previous->FirstPhysicalPar();
3197 if (cursor.par->GetLayout() == tmppar->GetLayout()
3198 && cursor.par->footnoteflag == tmppar->footnoteflag
3199 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3201 tmppar->line_bottom = cursor.par->line_bottom;
3202 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3203 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3208 // the layout things can change the height of a row !
3209 tmpheight = cursor.row->height;
3210 SetHeightOfRow(cursor.row);
3211 if (cursor.row->height != tmpheight) {
3212 refresh_y = cursor.y - cursor.row->baseline;
3213 refresh_row = cursor.row;
3214 status = LyXText::NEED_MORE_REFRESH;
3219 if (cursor.par->ParFromPos(cursor.pos)->previous){
3220 SetUndo(Undo::DELETE,
3221 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3222 cursor.par->ParFromPos(cursor.pos)->next);
3224 tmppar = cursor.par;
3225 tmprow = cursor.row;
3227 /* Pasting is not allowed, if the paragraphs have different
3228 layout. I think it is a real bug of all other
3229 word processors to allow it. It confuses the user.
3230 Even so with a footnote paragraph and a non-footnote
3231 paragraph. I will not allow pasting in this case,
3232 because the user would be confused if the footnote behaves
3233 different wether it is open or closed.
3235 Correction: Pasting is always allowed with standard-layout
3237 if (cursor.par != tmppar
3238 && (cursor.par->GetLayout() == tmppar->GetLayout()
3239 || !tmppar->GetLayout())
3240 && cursor.par->footnoteflag == tmppar->footnoteflag
3241 /* table stuff -- begin*/
3242 && !cursor.par->table /* no pasting of tables */
3243 /* table stuff -- end*/
3244 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3246 cursor.par->PasteParagraph();
3249 cursor.par->IsSeparator(cursor.pos - 1)))
3250 cursor.par->InsertChar(cursor.pos, ' ');
3255 status = LyXText::NEED_MORE_REFRESH;
3256 refresh_row = cursor.row;
3257 refresh_y = cursor.y - cursor.row->baseline;
3259 // remove the lost paragraph
3260 RemoveParagraph(tmprow);
3263 AppendParagraph(cursor.row);
3264 UpdateCounters(cursor.row);
3266 // the row may have changed, block, hfills etc.
3267 SetCursor(cursor.par, cursor.pos);
3270 /* this is the code for a normal backspace, not pasting
3272 SetUndo(Undo::DELETE,
3273 cursor.par->ParFromPos(cursor.pos)->previous,
3274 cursor.par->ParFromPos(cursor.pos)->next);
3277 // some insets are undeletable here
3278 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3279 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3281 // force complete redo when erasing display insets
3282 // this is a cruel mathod but save..... Matthias
3283 if (cursor.par->GetInset(cursor.pos)->display()){
3284 cursor.par->Erase(cursor.pos);
3291 y = cursor.y - row->baseline;
3292 LyXParagraph::size_type z;
3293 /* remember that a space at the end of a row doesnt count
3294 * when calculating the fill */
3295 if (cursor.pos < RowLast(row) ||
3296 !cursor.par->IsLineSeparator(cursor.pos)) {
3297 row->fill += SingleWidth(cursor.par, cursor.pos);
3300 /* some special code when deleting a newline. This is similar
3301 * to the behavior when pasting paragraphs */
3302 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3303 cursor.par->Erase(cursor.pos);
3304 // refresh the positions
3306 while (tmprow->next && tmprow->next->par == row->par) {
3307 tmprow = tmprow->next;
3310 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3313 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3314 cursor.par->InsertChar(cursor.pos, ' ');
3315 // refresh the positions
3317 while (tmprow->next && tmprow->next->par == row->par) {
3318 tmprow = tmprow->next;
3323 cursor.par->Erase(cursor.pos);
3325 // refresh the positions
3327 while (tmprow->next && tmprow->next->par == row->par) {
3328 tmprow = tmprow->next;
3332 #ifndef FIX_DOUBLE_SPACE
3333 // delete superfluous blanks
3334 if (cursor.pos < cursor.par->Last() - 1 &&
3335 (cursor.par->IsLineSeparator(cursor.pos))) {
3337 if (cursor.pos == BeginningOfMainBody(cursor.par)
3339 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3340 cursor.par->Erase(cursor.pos);
3341 // refresh the positions
3343 while (tmprow->next &&
3344 tmprow->next->par == row->par) {
3345 tmprow = tmprow->next;
3348 if (cursor.pos) // move one character left
3354 // delete newlines at the beginning of paragraphs
3355 while (cursor.par->Last() &&
3356 cursor.par->IsNewline(cursor.pos) &&
3357 cursor.pos == BeginningOfMainBody(cursor.par)) {
3358 cursor.par->Erase(cursor.pos);
3359 // refresh the positions
3361 while (tmprow->next &&
3362 tmprow->next->par == row->par) {
3363 tmprow = tmprow->next;
3369 // is there a break one row above
3370 if (row->previous && row->previous->par == row->par) {
3371 z = NextBreakPoint(row->previous, paperwidth);
3372 if ( z >= row->pos) {
3375 tmprow = row->previous;
3377 // maybe the current row is now empty
3378 if (row->pos >= row->par->Last()) {
3383 BreakAgainOneRow(row);
3384 if (row->next && row->next->par == row->par)
3385 need_break_row = row->next;
3390 // set the dimensions of the row above
3391 y -= tmprow->height;
3392 tmprow->fill = Fill(tmprow, paperwidth);
3393 SetHeightOfRow(tmprow);
3396 refresh_row = tmprow;
3397 status = LyXText::NEED_MORE_REFRESH;
3398 current_font = rawtmpfont;
3399 real_current_font = realtmpfont;
3400 SetCursor(cursor.par, cursor.pos, false);
3401 // check, whether the last character's font has changed.
3402 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3403 if (rawparfont != rawtmpfont)
3404 RedoHeightOfParagraph(cursor);
3409 // break the cursor row again
3410 z = NextBreakPoint(row, paperwidth);
3412 if (z != RowLast(row) ||
3413 (row->next && row->next->par == row->par &&
3414 RowLast(row) == row->par->Last() - 1)){
3416 /* it can happen that a paragraph loses one row
3417 * without a real breakup. This is when a word
3418 * is to long to be broken. Well, I don t care this
3420 if (row->next && row->next->par == row->par &&
3421 RowLast(row) == row->par->Last() - 1)
3422 RemoveRow(row->next);
3426 status = LyXText::NEED_MORE_REFRESH;
3428 BreakAgainOneRow(row);
3429 current_font = rawtmpfont;
3430 real_current_font = realtmpfont;
3431 SetCursor(cursor.par, cursor.pos, false);
3432 // cursor MUST be in row now
3434 if (row->next && row->next->par == row->par)
3435 need_break_row = row->next;
3439 // set the dimensions of the row
3440 row->fill = Fill(row, paperwidth);
3441 int tmpheight = row->height;
3442 SetHeightOfRow(row);
3443 if (tmpheight == row->height)
3444 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3446 status = LyXText::NEED_MORE_REFRESH;
3449 current_font = rawtmpfont;
3450 real_current_font = realtmpfont;
3451 SetCursor(cursor.par, cursor.pos, false);
3455 // restore the current font
3456 // That is what a user expects!
3457 current_font = rawtmpfont;
3458 real_current_font = realtmpfont;
3460 // check, wether the last characters font has changed.
3461 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3462 if (rawparfont != rawtmpfont) {
3463 RedoHeightOfParagraph(cursor);
3465 // now the special right address boxes
3466 if (textclasslist.Style(parameters->textclass,
3467 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3468 RedoDrawingOfParagraph(cursor);
3474 void LyXText::GetVisibleRow(int offset,
3475 Row * row_ptr, long y)
3477 /* returns a printed row */
3478 Painter & pain = owner_->painter();
3480 LyXDirection direction = row_ptr->par->getParDirection();
3481 LyXParagraph::size_type vpos, pos, pos_end;
3483 int y_top, y_bottom;
3484 float fill_separator, fill_hfill, fill_label_hfill;
3485 LyXParagraph * par, * firstpar;
3488 if (row_ptr->height <= 0) {
3489 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3492 PrepareToPrint(row_ptr, x, fill_separator,
3493 fill_hfill, fill_label_hfill);
3495 /* initialize the pixmap */
3497 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3500 /* selection code */
3501 if (sel_start_cursor.row == row_ptr &&
3502 sel_end_cursor.row == row_ptr) {
3503 if (sel_start_cursor.x < sel_end_cursor.x)
3504 pain.fillRectangle(sel_start_cursor.x, offset,
3505 sel_end_cursor.x - sel_start_cursor.x,
3509 pain.fillRectangle(sel_end_cursor.x, offset,
3510 sel_start_cursor.x - sel_end_cursor.x,
3513 } else if (sel_start_cursor.row == row_ptr) {
3514 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3515 pain.fillRectangle(sel_start_cursor.x, offset,
3516 paperwidth - sel_start_cursor.x,
3520 pain.fillRectangle(0, offset,
3524 } else if (sel_end_cursor.row == row_ptr) {
3525 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3526 pain.fillRectangle(0, offset,
3531 pain.fillRectangle(sel_end_cursor.x, offset,
3532 paperwidth - sel_end_cursor.x,
3536 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3537 pain.fillRectangle(0, offset,
3538 paperwidth, row_ptr->height,
3543 if (row_ptr->par->appendix){
3544 pain.line(1, offset,
3545 1, offset + row_ptr->height,
3546 LColor::appendixline);
3547 pain.line(paperwidth - 2, offset,
3548 paperwidth - 2, offset + row_ptr->height,
3549 LColor::appendixline);
3552 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3553 /* draw a marker at the left margin! */
3554 LyXFont font = GetFont(row_ptr->par, 0);
3555 int asc = font.maxAscent();
3556 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3557 int y1 = (offset + row_ptr->baseline);
3558 int y2 = (offset + row_ptr->baseline) - asc;
3559 pain.line(x, y1, x, y2, LColor::minipageline);
3561 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3562 LyXFont font(LyXFont::ALL_SANE);
3563 font.setSize(LyXFont::SIZE_FOOTNOTE);
3564 font.setColor(LColor::footnote);
3566 int box_x = LYX_PAPER_MARGIN;
3567 box_x += font.textWidth(" wide-tab ", 10);
3568 if (row_ptr->previous &&
3569 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3571 switch (row_ptr->par->footnotekind) {
3572 case LyXParagraph::MARGIN:
3575 case LyXParagraph::FIG:
3578 case LyXParagraph::TAB:
3581 case LyXParagraph::WIDE_FIG:
3584 case LyXParagraph::WIDE_TAB:
3587 case LyXParagraph::ALGORITHM:
3590 case LyXParagraph::FOOTNOTE:
3595 pain.fillRectangle(LYX_PAPER_MARGIN,
3597 box_x - LYX_PAPER_MARGIN,
3598 int(font.maxAscent()
3599 + font.maxDescent()),
3600 LColor::footnotebg);
3602 pain.line(LYX_PAPER_MARGIN, offset,
3603 paperwidth - LYX_PAPER_MARGIN, offset,
3604 LColor::footnoteframe);
3606 pain.text(LYX_PAPER_MARGIN,
3607 offset + int(font.maxAscent()) + 1,
3610 pain.line(LYX_PAPER_MARGIN, offset,
3612 offset + int(font.maxAscent()
3613 + font.maxDescent()),
3614 LColor::footnoteframe);
3616 pain.line(LYX_PAPER_MARGIN,
3617 offset + int(font.maxAscent()
3618 + font.maxDescent()) + 1,
3620 offset + int(font.maxAscent()
3621 + font.maxDescent()) + 1,
3622 LColor::footnoteframe);
3626 /* draw the open floats in a red box */
3627 pain.line(box_x, offset,
3628 box_x, offset + row_ptr->height,
3629 LColor::footnoteframe);
3631 pain.line(paperwidth - LYX_PAPER_MARGIN,
3633 paperwidth - LYX_PAPER_MARGIN,
3634 offset + row_ptr->height,
3635 LColor::footnoteframe);
3636 } else if (row_ptr->previous &&
3637 row_ptr->previous->par->footnoteflag
3638 == LyXParagraph::OPEN_FOOTNOTE) {
3639 LyXFont font(LyXFont::ALL_SANE);
3640 font.setSize(LyXFont::SIZE_FOOTNOTE);
3642 int box_x = LYX_PAPER_MARGIN;
3643 box_x += font.textWidth(" wide-tab ", 10);
3645 pain.line(box_x, offset,
3646 paperwidth - LYX_PAPER_MARGIN,
3647 offset, LColor::footnote);
3650 LyXLayout const & layout =
3651 textclasslist.Style(parameters->textclass,
3652 row_ptr->par->GetLayout());
3653 firstpar = row_ptr->par->FirstPhysicalPar();
3656 y_bottom = row_ptr->height;
3658 /* is it a first row? */
3659 if (row_ptr->pos == 0
3660 && row_ptr->par == firstpar) {
3662 /* start of appendix? */
3663 if (row_ptr->par->start_of_appendix){
3664 pain.line(1, offset,
3665 paperwidth - 2, offset,
3666 LColor::appendixline);
3669 /* think about the margins */
3670 if (!row_ptr->previous)
3671 y_top += LYX_PAPER_MARGIN;
3673 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3674 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3676 offset + y_top + 2 * DefaultHeight(),
3677 LColor::pagebreak, Painter::line_onoffdash);
3678 y_top += 3 * DefaultHeight();
3681 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3682 /* draw a vfill top */
3683 pain.line(0, offset + 2 + y_top,
3684 LYX_PAPER_MARGIN, offset + 2 + y_top,
3687 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3689 offset + y_top + 3 * DefaultHeight(),
3692 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3693 LYX_PAPER_MARGIN / 2,
3694 offset + y_top + 3 * DefaultHeight(),
3697 y_top += 3 * DefaultHeight();
3700 /* think about user added space */
3701 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3703 /* think about the parskip */
3704 /* some parskips VERY EASY IMPLEMENTATION */
3705 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3706 if (layout.latextype == LATEX_PARAGRAPH
3707 && firstpar->GetDepth() == 0
3708 && firstpar->Previous())
3709 y_top += parameters->getDefSkip().inPixels(owner_);
3710 else if (firstpar->Previous()
3711 && textclasslist.Style(parameters->textclass,
3712 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3713 && firstpar->Previous()->GetDepth() == 0)
3714 // is it right to use defskip here, too? (AS)
3715 y_top += parameters->getDefSkip().inPixels(owner_);
3718 if (row_ptr->par->line_top) { /* draw a top line */
3719 y_top += GetFont(row_ptr->par, 0).ascent('x');
3721 pain.line(0, offset + y_top,
3722 paperwidth, offset + y_top,
3724 Painter::line_solid,
3725 Painter::line_thick);
3727 y_top += GetFont(row_ptr->par, 0).ascent('x');
3730 /* should we print a label? */
3731 if (layout.labeltype >= LABEL_STATIC
3732 && (layout.labeltype != LABEL_STATIC
3733 || layout.latextype != LATEX_ENVIRONMENT
3734 || row_ptr->par->IsFirstInSequence())) {
3735 font = GetFont(row_ptr->par, -2);
3736 if (!row_ptr->par->GetLabestring().empty()) {
3738 string tmpstring = row_ptr->par->GetLabestring();
3740 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3741 if (parameters->secnumdepth >= 0){
3742 /* this is special code for the chapter layout. This is printed in
3743 * an extra row and has a pagebreak at the top. */
3744 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3745 + int(layout.parsep) * DefaultHeight();
3746 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3747 tmpx = paperwidth - LeftMargin(row_ptr) -
3748 font.stringWidth(tmpstring);
3749 pain.text(int(tmpx),
3750 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3754 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3755 tmpx = x - font.stringWidth(layout.labelsep)
3756 - font.stringWidth(tmpstring);
3758 tmpx = paperwidth - LeftMargin(row_ptr)
3759 + font.stringWidth(layout.labelsep);
3760 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3761 LyXFont font(LyXFont::ALL_SANE);
3762 font.setSize(LyXFont::SIZE_SMALL);
3763 tmpx += font.textWidth("Mwide-figM", 10);
3767 pain.text(int(tmpx),
3768 offset + row_ptr->baseline,
3772 /* the labels at the top of an environment. More or less for bibliography */
3773 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3774 layout.labeltype == LABEL_BIBLIO ||
3775 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3776 if (row_ptr->par->IsFirstInSequence()) {
3777 font = GetFont(row_ptr->par, -2);
3778 if (!row_ptr->par->GetLabestring().empty()) {
3779 string tmpstring = row_ptr->par->GetLabestring();
3781 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3782 + (layout.labelbottomsep * DefaultHeight()));
3785 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3786 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3787 ? x : LeftMargin(row_ptr) )
3788 + paperwidth - RightMargin(row_ptr) ) / 2;
3789 tmpx -= (font.stringWidth(tmpstring)/2);
3790 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3791 tmpx = paperwidth - LeftMargin(row_ptr) -
3792 font.stringWidth(tmpstring);
3793 pain.text(int(tmpx),
3794 offset + row_ptr->baseline
3795 - row_ptr->ascent_of_text
3801 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3802 font = GetFont(row_ptr->par, -1);
3803 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3804 tmpx = x - font.stringWidth(layout.labelsep)
3805 - row_ptr->par->bibkey->width(owner_->painter(), font);
3807 tmpx = paperwidth - LeftMargin(row_ptr)
3808 + font.stringWidth(layout.labelsep);
3809 row_ptr->par->bibkey->draw(owner_->painter(),
3811 offset + row_ptr->baseline,
3816 /* is it a last row? */
3817 par = row_ptr->par->LastPhysicalPar();
3818 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3819 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3821 /* think about the margins */
3823 y_bottom -= LYX_PAPER_MARGIN;
3825 /* draw a bottom pagebreak */
3826 if (firstpar->pagebreak_bottom) {
3827 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3829 offset + y_bottom - 2 * DefaultHeight(),
3830 LColor::pagebreak, Painter::line_onoffdash);
3831 y_bottom -= 3 * DefaultHeight();
3834 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3835 /* draw a vfill bottom */
3836 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3838 offset + y_bottom - 3 * DefaultHeight(),
3840 pain.line(0, offset + y_bottom - 2,
3842 offset + y_bottom - 2,
3844 pain.line(LYX_PAPER_MARGIN / 2,
3845 offset + y_bottom - 3 * DefaultHeight(),
3846 LYX_PAPER_MARGIN / 2,
3847 offset + y_bottom - 2,
3849 y_bottom -= 3* DefaultHeight();
3852 /* think about user added space */
3853 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3855 if (firstpar->line_bottom) {
3856 /* draw a bottom line */
3857 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3858 pain.line(0, offset + y_bottom,
3859 paperwidth, offset + y_bottom,
3860 LColor::topline, Painter::line_solid,
3861 Painter::line_thick);
3862 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3866 /* draw the text in the pixmap */
3867 pos_end = RowLast(row_ptr);
3869 vpos = row_ptr->pos;
3870 /* table stuff -- begin*/
3871 if (row_ptr->par->table) {
3873 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3875 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3877 while (vpos <= pos_end) {
3878 pos = vis2log(vpos);
3879 if (row_ptr->par->IsNewline(pos)) {
3881 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3882 /* draw the table lines, still very simple */
3883 on_off = !row_ptr->par->table->TopLine(cell);
3885 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3886 !row_ptr->par->table->IsContRow(cell))
3887 pain.line(int(x_old),
3888 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3890 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3892 on_off ? Painter::line_onoffdash : Painter::line_solid);
3894 on_off = !row_ptr->par->table->BottomLine(cell);
3895 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3896 row_ptr->par->table->VeryLastRow(cell))
3898 pain.line(int(x_old),
3899 offset + y_bottom - 1,
3901 offset + y_bottom - 1,
3903 on_off ? Painter::line_onoffdash : Painter::line_solid);
3905 on_off = !row_ptr->par->table->LeftLine(cell);
3907 pain.line(int(x_old),
3908 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3910 offset + y_bottom - 1,
3912 on_off ? Painter::line_onoffdash : Painter::line_solid);
3914 on_off = !row_ptr->par->table->RightLine(cell);
3916 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3917 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3918 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3919 offset + y_bottom - 1,
3921 on_off ? Painter::line_onoffdash : Painter::line_solid);
3924 /* take care about the alignment and other spaces */
3926 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3927 if (row_ptr->par->table->IsFirstCell(cell))
3928 --cell; // little hack, sorry
3930 } else if (row_ptr->par->IsHfill(pos)) {
3934 offset + row_ptr->baseline - DefaultHeight() / 2,
3936 offset + row_ptr->baseline,
3941 } else if (row_ptr->par->IsSeparator(pos)) {
3943 x+= SingleWidth(row_ptr->par, pos);
3944 /* -------> Only draw protected spaces when not in
3945 * free-spacing mode. */
3946 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3947 pain.line(int(tmpx),
3948 offset + row_ptr->baseline - 3,
3950 offset + row_ptr->baseline - 1,
3953 pain.line(int(tmpx),
3954 offset + row_ptr->baseline - 1,
3956 offset + row_ptr->baseline - 1,
3959 pain.line(int(x - 2),
3960 offset + row_ptr->baseline - 3,
3962 offset + row_ptr->baseline - 1,
3965 /* what about underbars? */
3966 font = GetFont(row_ptr->par, pos);
3967 if (font.underbar() == LyXFont::ON
3968 && font.latex() != LyXFont::ON) {
3969 pain.line(int(tmpx),
3970 offset + row_ptr->baseline + 2,
3972 offset + row_ptr->baseline + 2);
3977 draw(row_ptr, vpos, offset, x);
3980 /* do not forget the very last cell. This has no NEWLINE so
3981 * ignored by the code above*/
3982 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3983 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3984 on_off = !row_ptr->par->table->TopLine(cell);
3986 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3987 !row_ptr->par->table->IsContRow(cell))
3989 pain.line(int(x_old),
3990 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3992 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3994 on_off ? Painter::line_onoffdash : Painter::line_solid);
3995 on_off = !row_ptr->par->table->BottomLine(cell);
3996 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3997 row_ptr->par->table->VeryLastRow(cell))
3999 pain.line(int(x_old),
4000 offset + y_bottom - 1,
4002 offset + y_bottom - 1,
4004 on_off ? Painter::line_onoffdash : Painter::line_solid);
4006 on_off = !row_ptr->par->table->LeftLine(cell);
4008 pain.line(int(x_old),
4009 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4011 offset + y_bottom - 1,
4013 on_off ? Painter::line_onoffdash : Painter::line_solid);
4015 on_off = !row_ptr->par->table->RightLine(cell);
4017 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4018 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4019 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4020 offset + y_bottom - 1,
4022 on_off ? Painter::line_onoffdash : Painter::line_solid);
4025 /* table stuff -- end*/
4026 LyXParagraph::size_type main_body =
4027 BeginningOfMainBody(row_ptr->par);
4028 if (main_body > 0 &&
4029 (main_body-1 > pos_end ||
4030 !row_ptr->par->IsLineSeparator(main_body-1)))
4033 while (vpos <= pos_end) {
4034 pos = vis2log(vpos);
4035 if (main_body > 0 && pos == main_body-1) {
4036 x += fill_label_hfill
4037 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4038 - SingleWidth(row_ptr->par, main_body-1);
4041 if (row_ptr->par->IsHfill(pos)) {
4044 offset + row_ptr->baseline - DefaultHeight() / 2,
4046 offset + row_ptr->baseline,
4049 if (HfillExpansion(row_ptr, pos)) {
4050 if (pos >= main_body) {
4052 offset + row_ptr->baseline - DefaultHeight() / 4,
4053 int(x + fill_hfill),
4054 offset + row_ptr->baseline - DefaultHeight() / 4,
4056 Painter::line_onoffdash);
4060 offset + row_ptr->baseline - DefaultHeight() / 4,
4061 int(x + fill_label_hfill),
4062 offset + row_ptr->baseline - DefaultHeight() / 4,
4064 Painter::line_onoffdash);
4066 x += fill_label_hfill;
4069 offset + row_ptr->baseline - DefaultHeight() / 2,
4071 offset + row_ptr->baseline,
4076 } else if (row_ptr->par->IsSeparator(pos)) {
4078 x+= SingleWidth(row_ptr->par, pos);
4079 if (pos >= main_body)
4081 /* -------> Only draw protected spaces when not in
4082 * free-spacing mode. */
4083 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4085 pain.line(int(tmpx),
4086 offset + row_ptr->baseline - 3,
4088 offset + row_ptr->baseline - 1,
4091 pain.line(int(tmpx),
4092 offset + row_ptr->baseline - 1,
4094 offset + row_ptr->baseline - 1,
4097 pain.line(int(x - 2),
4098 offset + row_ptr->baseline - 3,
4100 offset + row_ptr->baseline - 1,
4103 /* what about underbars? */
4104 font = GetFont(row_ptr->par, pos);
4105 if (font.underbar() == LyXFont::ON
4106 && font.latex() != LyXFont::ON) {
4107 pain.line(int(tmpx),
4108 offset + row_ptr->baseline + 2,
4110 offset + row_ptr->baseline + 2);
4115 draw(row_ptr, vpos, offset, x);
4121 int LyXText::DefaultHeight() const
4123 LyXFont font(LyXFont::ALL_SANE);
4124 return int(font.maxAscent() + font.maxDescent() * 1.5);
4128 /* returns the column near the specified x-coordinate of the row
4129 * x is set to the real beginning of this column */
4130 int LyXText::GetColumnNearX(Row * row, int & x) const
4133 float fill_separator, fill_hfill, fill_label_hfill;
4135 PrepareToPrint(row, tmpx, fill_separator,
4136 fill_hfill, fill_label_hfill);
4138 LyXDirection direction = row->par->getParDirection();
4139 LyXParagraph::size_type vc = row->pos;
4140 LyXParagraph::size_type last = RowLast(row);
4141 LyXParagraph::size_type c;
4143 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4144 row->par->GetLayout());
4145 /* table stuff -- begin */
4146 if (row->par->table) {
4147 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4148 && row->par->IsNewline(last))
4150 int cell = NumberOfCell(row->par, row->pos);
4153 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4155 && (c = vis2log(vc)) >= 0
4156 && tmpx + (SingleWidth(row->par, c)/2) <= x
4158 if (row->par->IsNewline(c)) {
4159 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4160 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4163 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4168 tmpx += SingleWidth(row->par, c);
4173 /* table stuff -- end*/
4174 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4175 float last_tmpx = tmpx;
4177 if (main_body > 0 &&
4178 (main_body-1 > last ||
4179 !row->par->IsLineSeparator(main_body-1)))
4182 while (vc <= last && tmpx <= x) {
4185 if (main_body > 0 && c == main_body-1) {
4186 tmpx += fill_label_hfill +
4187 GetFont(row->par, -2).stringWidth(layout.labelsep);
4188 if (row->par->IsLineSeparator(main_body-1))
4189 tmpx -= SingleWidth(row->par, main_body-1);
4192 tmpx += SingleWidth(row->par, c);
4193 if (HfillExpansion(row, c)) {
4197 tmpx += fill_label_hfill;
4199 else if (c >= main_body
4200 && row->par->IsSeparator(c)) {
4201 tmpx+= fill_separator;
4206 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4211 /* make sure that a last space in a row doesnt count */
4212 if (row->pos <= last
4213 && !(!row->next || row->next->par != row->par))
4214 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4215 && row->par->IsLineSeparator(vis2log(last)) ) {
4217 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4218 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4220 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4222 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4225 if (row->pos > last) // Row is empty?
4227 else if (vc <= last) {
4229 LyXDirection direction = row->par->getLetterDirection(c);
4230 if (vc > row->pos && row->par->IsLineSeparator(c)
4231 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4233 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4236 c = vis2log(last)+1;
4237 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4241 if (!row->par->table && row->pos <= last && c > last
4242 && row->par->IsNewline(last)) {
4243 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4244 tmpx -= SingleWidth(row->par, last);
4246 tmpx += SingleWidth(row->par, last);
4256 /* turn the selection into a new environment. If there is no selection,
4257 * create an empty environment */
4258 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4260 /* no footnoteenvironment in a footnoteenvironment */
4261 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4262 WriteAlert(_("Impossible operation"),
4263 _("You can't insert a float in a float!"),
4267 /* no marginpars in minipages */
4268 if (kind == LyXParagraph::MARGIN
4269 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4270 WriteAlert(_("Impossible operation"),
4271 _("You can't insert a marginpar in a minipage!"),
4276 /* this doesnt make sense, if there is no selection */
4277 bool dummy_selection = false;
4279 sel_start_cursor = cursor; /* dummy selection */
4280 sel_end_cursor = cursor;
4281 dummy_selection = true;
4284 LyXParagraph *tmppar;
4286 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4287 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4291 /* a test to make sure there is not already a footnote
4292 * in the selection. */
4294 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4296 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4297 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4298 tmppar = tmppar->next;
4300 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4301 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4302 WriteAlert(_("Impossible operation"),
4303 _("Float would include float!"),
4308 /* ok we have a selection. This is always between sel_start_cursor
4309 * and sel_end cursor */
4311 SetUndo(Undo::FINISH,
4312 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4313 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4315 if (sel_end_cursor.pos > 0
4316 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4317 sel_end_cursor.pos--; /* please break before a space at
4319 if (sel_start_cursor.par == sel_end_cursor.par
4320 && sel_start_cursor.pos > sel_end_cursor.pos)
4321 sel_start_cursor.pos--;
4323 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4325 sel_end_cursor.par = sel_end_cursor.par->Next();
4326 sel_end_cursor.pos = 0;
4328 // don't forget to insert a dummy layout paragraph if necessary
4329 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4330 sel_end_cursor.par->BreakParagraphConservative(0);
4331 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4332 sel_end_cursor.par = sel_end_cursor.par->next;
4335 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4337 cursor = sel_end_cursor;
4339 /* please break behind a space, if there is one. The space should
4341 if (sel_start_cursor.pos > 0
4342 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4343 sel_start_cursor.pos--;
4344 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4345 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4348 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4349 tmppar = sel_start_cursor.par->Next();
4351 if (dummy_selection) {
4353 if (kind == LyXParagraph::TAB
4354 || kind == LyXParagraph::FIG
4355 || kind == LyXParagraph::WIDE_TAB
4356 || kind == LyXParagraph::WIDE_FIG
4357 || kind == LyXParagraph::ALGORITHM) {
4358 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4360 if (lay == -1) // layout not found
4361 // use default layout "Standard" (0)
4363 tmppar->SetLayout(lay);
4367 if (sel_start_cursor.pos > 0) {
4368 /* the footnote-environment should begin with a standard layout.
4369 * Imagine you insert a footnote within an enumeration, you
4370 * certainly do not want an enumerated footnote! */
4374 /* this is a exception the user would sometimes expect, I hope */
4375 sel_start_cursor.par->Clear();
4379 while (tmppar != sel_end_cursor.par) {
4380 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4381 tmppar->footnotekind = kind;
4382 tmppar = tmppar->Next();
4385 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4387 SetCursor(sel_start_cursor.par->Next(), 0);
4393 // returns pointer to a specified row
4394 Row * LyXText::GetRow(LyXParagraph * par,
4395 LyXParagraph::size_type pos, long & y) const
4400 if (par == currentrow->par || par == currentrow->par->Previous()) {
4401 // do not dereference par, it may have been deleted
4402 // already! (Matthias)
4403 while (currentrow->previous && currentrow->previous->par != par) {
4404 currentrow = currentrow->previous;
4405 currentrow_y -= currentrow->height;
4407 while (currentrow->previous && currentrow->previous->par == par) {
4408 currentrow = currentrow->previous;
4409 currentrow_y -= currentrow->height;
4412 tmprow = currentrow;
4414 // find the first row of the specified paragraph
4415 while (tmprow->next && (tmprow->par != par)) {
4416 y += tmprow->height;
4417 tmprow = tmprow->next;
4420 if (tmprow->par == par){
4421 // now find the wanted row
4422 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4423 tmprow->next->pos <= pos) {
4424 y += tmprow->height;
4425 tmprow = tmprow->next;
4427 currentrow = tmprow;
4434 // find the first row of the specified paragraph
4435 while (tmprow->next && (tmprow->par != par)) {
4436 y += tmprow->height;
4437 tmprow = tmprow->next;
4440 // now find the wanted row
4441 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4442 tmprow->next->pos <= pos) {
4443 y += tmprow->height;
4444 tmprow = tmprow->next;
4447 currentrow = tmprow;