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);
381 /* usual characters, no insets */
383 // Collect character that we can draw in one command
385 // This is dirty, but fast. Notice that it will never be too small.
386 // For the record, I'll note that Microsoft Word has a limit
387 // of 768 here. We have none :-) (Asger)
388 // Ok. I am the first to admit that the use of std::string will be
389 // a tiny bit slower than using a POD char array. However, I claim
390 // that this slowdown is so small that it is close to inperceptive.
391 // So IMHO we should go with the easier and clearer implementation.
392 // And even if 1024 is a large number here it might overflow, string
393 // will only overflow if the machine is out of memory...
394 static string textstring;
398 LyXParagraph::size_type last = RowLast(row);
400 while (vpos <= last &&
401 (pos = vis2log(vpos)) >= 0
402 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
403 && font2 == GetFont(row->par, pos)) {
409 // Draw text and set the new x position
410 pain.text(int(x), offset + row->baseline, textstring, font);
411 x += pain.width(textstring, font);
413 // what about underbars?
414 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
415 pain.line(tmpx, offset + row->baseline + 2,
416 x, offset + row->baseline + 2);
420 // If we want ulem.sty support, drawing
421 // routines should go here. (Asger)
422 // Why shouldn't LyXFont::drawText handle it internally?
426 // Returns the left beginning of the text.
427 // This information cannot be taken from the layouts-objekt, because in
428 // LaTeX the beginning of the text fits in some cases (for example sections)
429 // exactly the label-width.
430 int LyXText::LeftMargin(Row const * row) const
432 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
433 row->par->GetLayout());
435 string parindent = layout.parindent;
437 /* table stuff -- begin */
440 /* table stuff -- end */
442 int x = LYX_PAPER_MARGIN;
444 x += textclasslist.TextClass(parameters->textclass)
446 .signedStringWidth(textclasslist
447 .TextClass(parameters->textclass)
450 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
451 LyXFont font(LyXFont::ALL_SANE);
452 font.setSize(LyXFont::SIZE_SMALL);
453 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
456 // this is the way, LyX handles the LaTeX-Environments.
457 // I have had this idea very late, so it seems to be a
458 // later added hack and this is true
459 if (!row->par->GetDepth()) {
460 if (!row->par->GetLayout()) {
461 // find the previous same level paragraph
462 if (row->par->FirstPhysicalPar()->Previous()) {
463 LyXParagraph * newpar = row->par
464 ->DepthHook(row->par->GetDepth());
466 textclasslist.Style(parameters->textclass,
473 // find the next level paragraph
475 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
477 // make a corresponding row. Needed to call LeftMargin()
479 // check wether it is a sufficent paragraph
480 if (newpar && newpar->footnoteflag == row->par->footnoteflag
482 .Style(parameters->textclass,
483 newpar->GetLayout()).isEnvironment()) {
485 dummyrow.par = newpar;
486 dummyrow.pos = newpar->Last();
487 x = LeftMargin(&dummyrow);
489 // this is no longer an error, because this function
490 // is used to clear impossible depths after changing
491 // a layout. Since there is always a redo,
492 // LeftMargin() is always called
493 row->par->FirstPhysicalPar()->depth = 0;
496 if (newpar && !row->par->GetLayout()) {
497 if (newpar->FirstPhysicalPar()->noindent)
500 parindent = textclasslist
501 .Style(parameters->textclass,
502 newpar->GetLayout()).parindent;
507 LyXFont labelfont = GetFont(row->par, -2);
508 switch (layout.margintype) {
510 if (!layout.leftmargin.empty()) {
512 .TextClass(parameters->textclass)
514 .signedStringWidth(layout.leftmargin);
516 if (!row->par->GetLabestring().empty()) {
517 x += labelfont.signedStringWidth(layout.labelindent);
518 x += labelfont.stringWidth(row->par->GetLabestring());
519 x += labelfont.stringWidth(layout.labelsep);
523 x += labelfont.signedStringWidth(layout.labelindent);
524 if (row->pos >= BeginningOfMainBody(row->par)) {
525 if (!row->par->GetLabelWidthString().empty()) {
527 .stringWidth(row->par
528 ->GetLabelWidthString());
529 x += labelfont.stringWidth(layout.labelsep);
534 x += textclasslist.TextClass(parameters->textclass)
535 .defaultfont().signedStringWidth(layout.leftmargin) * 4
536 / (row->par->GetDepth() + 4);
538 case MARGIN_FIRST_DYNAMIC:
539 if (layout.labeltype == LABEL_MANUAL) {
540 if (row->pos >= BeginningOfMainBody(row->par)) {
542 .signedStringWidth(layout.leftmargin);
545 .signedStringWidth(layout.labelindent);
548 // Special case to fix problems with
550 || (layout.labeltype == LABEL_STATIC
551 && layout.latextype == LATEX_ENVIRONMENT
552 && ! row->par->IsFirstInSequence())) {
553 x += labelfont.signedStringWidth(layout.leftmargin);
554 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
555 && layout.labeltype != LABEL_BIBLIO
556 && layout.labeltype !=
557 LABEL_CENTERED_TOP_ENVIRONMENT) {
558 x += labelfont.signedStringWidth(layout.labelindent);
559 x += labelfont.stringWidth(layout.labelsep);
560 x += labelfont.stringWidth(row->par->GetLabestring());
564 case MARGIN_RIGHT_ADDRESS_BOX:
566 // ok, a terrible hack. The left margin depends on the widest
567 // row in this paragraph. Do not care about footnotes, they
568 // are *NOT* allowed in the LaTeX realisation of this layout.
570 // find the first row of this paragraph
571 Row const * tmprow = row;
572 while (tmprow->previous && tmprow->previous->par == row->par)
573 tmprow = tmprow->previous;
575 int minfill = tmprow->fill;
576 while (tmprow->next && tmprow->next->par == row->par) {
577 tmprow = tmprow->next;
578 if (tmprow->fill < minfill)
579 minfill = tmprow->fill;
582 x += textclasslist.TextClass(parameters->textclass)
583 .defaultfont().signedStringWidth(layout.leftmargin);
588 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
589 if (!row->par->pextra_widthp.empty()) {
591 atoi(row->par->pextra_widthp.c_str()) / 100;
592 } else if (!row->par->pextra_width.empty()) {
593 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
596 xx = paperwidth * 80 / 100;
598 } else { // should not happen
599 LyXFont font(LyXFont::ALL_SANE);
600 x += font.stringWidth("XXXXXX");
605 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
606 align = layout.align;
608 align = row->par->FirstPhysicalPar()->align;
610 // set the correct parindent
612 if ((layout.labeltype == LABEL_NO_LABEL
613 || layout.labeltype == LABEL_TOP_ENVIRONMENT
614 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
615 || (layout.labeltype == LABEL_STATIC
616 && layout.latextype == LATEX_ENVIRONMENT
617 && ! row->par->IsFirstInSequence()))
618 && row->par == row->par->FirstPhysicalPar()
619 && align == LYX_ALIGN_BLOCK
620 && !row->par->noindent
621 && (row->par->layout ||
622 parameters->paragraph_separation ==
623 BufferParams::PARSEP_INDENT))
624 x += textclasslist.TextClass(parameters->textclass)
625 .defaultfont().signedStringWidth(parindent);
626 else if (layout.labeltype == LABEL_BIBLIO) {
627 // ale970405 Right width for bibitems
628 x += bibitemMaxWidth(owner_->painter(),
630 .TextClass(parameters
639 int LyXText::RightMargin(Row const * row) const
641 LyXLayout const & layout =
642 textclasslist.Style(parameters->textclass,
643 row->par->GetLayout());
645 int x = LYX_PAPER_MARGIN
647 .TextClass(parameters->textclass)
649 .signedStringWidth(textclasslist
650 .TextClass(parameters->textclass)
653 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
654 x += LYX_PAPER_MARGIN / 2;
657 // this is the way, LyX handles the LaTeX-Environments.
658 // I have had this idea very late, so it seems to be a
659 // later added hack and this is true
660 if (row->par->GetDepth()) {
661 // find the next level paragraph
663 LyXParagraph * newpar = row->par;
666 newpar = newpar->FirstPhysicalPar()->Previous();
668 newpar = newpar->FirstPhysicalPar();
669 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
670 && newpar->footnoteflag == row->par->footnoteflag);
672 // make a corresponding row. Needed to call LeftMargin()
674 // check wether it is a sufficent paragraph
675 if (newpar && newpar->footnoteflag == row->par->footnoteflag
676 && textclasslist.Style(parameters->textclass,
680 dummyrow.par = newpar;
682 x = RightMargin(&dummyrow);
684 // this is no longer an error, because this function
685 // is used to clear impossible depths after changing
686 // a layout. Since there is always a redo,
687 // LeftMargin() is always called
688 row->par->FirstPhysicalPar()->depth = 0;
692 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
693 x += textclasslist.TextClass(parameters->textclass)
695 .signedStringWidth(layout.rightmargin) * 4
696 / (row->par->GetDepth() + 4);
701 int LyXText::LabelEnd (Row const * row) const
703 if (textclasslist.Style(parameters->textclass,
704 row->par->GetLayout()).margintype
708 tmprow.pos = row->par->Last();
709 return LeftMargin(&tmprow); /* just the beginning
712 return 0; /* LabelEnd is only needed, if the
713 layout fills a flushleft
718 /* table stuff -- begin*/
719 int LyXText::NumberOfCell(LyXParagraph * par,
720 LyXParagraph::size_type pos) const
723 LyXParagraph::size_type tmp_pos = 0;
724 while (tmp_pos < pos) {
725 if (par->IsNewline(tmp_pos))
733 int LyXText::WidthOfCell(LyXParagraph * par,
734 LyXParagraph::size_type & pos) const
737 while (pos < par->Last() && !par->IsNewline(pos)) {
738 w += SingleWidth(par, pos);
741 if (par->IsNewline(pos))
747 bool LyXText::HitInTable(Row * row, int x) const
750 float fill_separator, fill_hfill, fill_label_hfill;
751 if (!row->par->table)
753 PrepareToPrint(row, tmpx, fill_separator,
754 fill_hfill, fill_label_hfill, false);
755 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
759 bool LyXText::MouseHitInTable(int x, long y) const
761 Row * row = GetRowNearY(y);
762 return HitInTable(row, x);
766 /* table stuff -- end*/
769 // get the next breakpoint in a given paragraph
770 LyXParagraph::size_type
771 LyXText::NextBreakPoint(Row const * row, int width) const
773 LyXParagraph * par = row->par;
774 LyXParagraph::size_type pos = row->pos;
776 /* table stuff -- begin*/
778 while (pos < par->size()
779 && (!par->IsNewline(pos)
780 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
781 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
782 par->GetInset(pos) && par->GetInset(pos)->display()){
783 par->GetInset(pos)->display(false);
789 /* table stuff -- end*/
791 // position of the last possible breakpoint
792 // -1 isn't a suitable value, but a flag
793 LyXParagraph::size_type last_separator = -1;
794 int left_margin = LabelEnd(row);
795 width -= RightMargin(row);
797 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
798 LyXLayout const & layout =
799 textclasslist.Style(parameters->textclass, par->GetLayout());
800 LyXParagraph::size_type i = pos;
802 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
803 /* special code for right address boxes, only newlines count */
804 while (i < par->Last()) {
805 if (par->IsNewline(i)) {
807 i = par->Last() - 1; // this means break
809 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
810 par->GetInset(i) && par->GetInset(i)->display()){
811 par->GetInset(i)->display(false);
816 // Last position is an invariant
817 LyXParagraph::size_type const last =
819 // this is the usual handling
820 int x = LeftMargin(row);
821 while (x < width && i < last) {
822 char c = par->GetChar(i);
823 if (IsNewlineChar(c)) {
825 x = width; // this means break
826 } else if (c == LyXParagraph::META_INSET &&
827 par->GetInset(i) && par->GetInset(i)->display()){
828 // check wether a Display() inset is
829 // valid here. if not, change it to
831 if (layout.isCommand()
832 || (layout.labeltype == LABEL_MANUAL
833 && i < BeginningOfMainBody(par))){
834 // display istn't allowd
835 par->GetInset(i)->display(false);
836 x += SingleWidth(par, i, c);
838 // inset is display. So break the line here
842 if (IsLineSeparatorChar(par->GetChar(i+1)))
845 last_separator = last; // to avoid extra rows
847 last_separator = i - 1;
848 x = width; // this means break
851 if (IsLineSeparatorChar(c))
853 x += SingleWidth(par, i, c);
856 if (i == main_body) {
857 x += GetFont(par, -2).stringWidth(layout.labelsep);
858 if (par->IsLineSeparator(i - 1))
859 x-= SingleWidth(par, i - 1);
864 // end of paragraph is always a suitable separator
865 if (i == last && x < width)
869 // well, if last_separator is still 0, the line isn't breakable.
870 // don't care and cut simply at the end
871 if (last_separator < 0) {
875 // manual labels cannot be broken in LaTeX, do not care
876 if (main_body && last_separator < main_body)
877 last_separator = main_body - 1;
879 return last_separator;
883 // returns the minimum space a row needs on the screen in pixel
884 int LyXText::Fill(Row const * row, int paper_width) const
887 // get the pure distance
888 LyXParagraph::size_type last = RowLast(row);
889 /* table stuff -- begin */
890 if (row->par->table) {
891 // for tables FILL does calculate the widthes of each cell in
893 LyXParagraph::size_type pos = row->pos;
894 int cell = NumberOfCell(row->par, pos);
897 row->par->table->SetWidthOfCell(cell,
898 WidthOfCell(row->par,
901 } while (pos <= last && !row->par->table->IsFirstCell(cell));
902 // don't forget the very last table cell without characters
903 if (cell == row->par->table->GetNumberOfCells() - 1)
904 row->par->table->SetWidthOfCell(cell,
905 WidthOfCell(row->par,
908 return 0; /* width of table cannot be returned since
909 * we cannot guarantee its correct value at
912 /* table stuff -- end*/
914 int left_margin = LabelEnd(row);
916 // if the row ends with newline, this newline will not be relevant
917 //if (last >= 0 && row->par->IsNewline(last))
920 // if the row ends with a space, this space will not be relevant
921 if (last >= 0 && row->par->IsLineSeparator(last))
924 // special handling of the right address boxes
925 if (textclasslist.Style(parameters->textclass,
926 row->par->GetLayout()).margintype
927 == MARGIN_RIGHT_ADDRESS_BOX) {
928 int tmpfill = row->fill;
929 row->fill = 0; // the minfill in MarginLeft()
935 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
936 row->par->GetLayout());
937 LyXParagraph::size_type main_body =
938 BeginningOfMainBody(row->par);
939 LyXParagraph::size_type i = row->pos;
942 if (main_body > 0 && i == main_body) {
943 w += GetFont(row->par, -2).
944 stringWidth(layout.labelsep);
945 if (row->par->IsLineSeparator(i - 1))
946 w -= SingleWidth(row->par, i - 1);
950 w += SingleWidth(row->par, i);
953 if (main_body > 0 && main_body > last) {
954 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
955 if (last >= 0 && row->par->IsLineSeparator(last))
956 w -= SingleWidth(row->par, last);
961 fill = paper_width - w - RightMargin(row);
966 // returns the minimum space a manual label needs on the screen in pixel
967 int LyXText::LabelFill(Row const * row) const
969 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
970 // -1 because a label ends either with a space that is in the label,
971 // or with the beginning of a footnote that is outside the label.
973 // I don't understand this code in depth, but sometimes "last" is
974 // less than 0 and this causes a crash. This fix seems to work
975 // correctly, but I bet the real error is elsewhere. The bug is
976 // triggered when you have an open footnote in a paragraph
977 // environment with a manual label. (Asger)
978 if (last < 0) last = 0;
980 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
987 w += SingleWidth(row->par, i);
992 if (!row->par->labelwidthstring.empty()) {
993 fill = GetFont(row->par, -2)
994 .stringWidth(row->par->labelwidthstring) - w;
1004 // returns the number of separators in the specified row. The separator
1005 // on the very last column doesnt count
1006 int LyXText::NumberOfSeparators(Row const * row) const
1008 int last = RowLast(row);
1010 //int main_body = BeginningOfMainBody(row->par);
1011 //if (p < main_body)
1013 // I think this is equivalent to the above. (Lgb)
1014 int p = max(row->pos, BeginningOfMainBody(row->par));
1016 for (; p < last; ++p) {
1017 if (row->par->IsSeparator(p)) {
1025 // returns the number of hfills in the specified row. The LyX-Hfill is
1026 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1027 // ignored. This is *MUCH* more usefull than not to ignore!
1028 int LyXText::NumberOfHfills(Row const * row) const
1030 int last = RowLast(row);
1031 int first = row->pos;
1032 if (first) { /* hfill *DO* count at the beginning
1034 while(first <= last && row->par->IsHfill(first))
1038 //int main_body = BeginningOfMainBody(row->par);
1039 //if (first < main_body)
1040 // first = main_body;
1041 // I think this is equivalent to the above. (Lgb)
1042 first = max(first, BeginningOfMainBody(row->par));
1044 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1045 if (row->par->IsHfill(p)) {
1053 // like NumberOfHfills, but only those in the manual label!
1054 int LyXText::NumberOfLabelHfills(Row const * row) const
1056 LyXParagraph::size_type last = RowLast(row);
1057 LyXParagraph::size_type first = row->pos;
1058 if (first) { /* hfill *DO* count at the beginning
1060 while(first < last && row->par->IsHfill(first))
1063 //LyXParagraph::size_type main_body =
1064 //BeginningOfMainBody(row->par);
1065 //if (last > main_body)
1067 // I think this is eqvialent to the above. (Lgb)
1068 last = min(last, BeginningOfMainBody(row->par));
1070 for (LyXParagraph::size_type p = first;
1071 p < last; ++p) { // last, because the end is ignored!
1072 if (row->par->IsHfill(p)) {
1080 // returns true, if a expansion is needed.
1081 // Rules are given by LaTeX
1082 bool LyXText::HfillExpansion(Row const * row_ptr,
1083 LyXParagraph::size_type pos) const
1085 // by the way, is it a hfill?
1086 if (!row_ptr->par->IsHfill(pos))
1089 // at the end of a row it does not count
1090 if (pos >= RowLast(row_ptr))
1093 // at the beginning of a row it does not count, if it is not
1094 // the first row of a paragaph
1098 // in some labels it does not count
1099 if (textclasslist.Style(parameters->textclass,
1100 row_ptr->par->GetLayout()).margintype
1102 && pos < BeginningOfMainBody(row_ptr->par))
1105 // if there is anything between the first char of the row and
1106 // the sepcified position that is not a newline and not a hfill,
1107 // the hfill will count, otherwise not
1108 LyXParagraph::size_type i = row_ptr->pos;
1109 while (i < pos && (row_ptr->par->IsNewline(i)
1110 || row_ptr->par->IsHfill(i)))
1117 void LyXText::SetHeightOfRow(Row * row_ptr) const
1119 /* get the maximum ascent and the maximum descent */
1121 float layoutasc = 0;
1122 float layoutdesc = 0;
1127 /* this must not happen before the currentrow for clear reasons.
1128 so the trick is just to set the current row onto this row */
1130 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1132 /* ok , let us initialize the maxasc and maxdesc value.
1133 * This depends in LaTeX of the font of the last character
1134 * in the paragraph. The hack below is necessary because
1135 * of the possibility of open footnotes */
1137 /* Correction: only the fontsize count. The other properties
1138 are taken from the layoutfont. Nicer on the screen :) */
1140 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1141 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1143 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1144 firstpar->GetLayout());
1146 LyXFont font = GetFont(par, par->Last()-1);
1147 LyXFont::FONT_SIZE size = font.size();
1148 font = GetFont(par, -1);
1151 LyXFont labelfont = GetFont(par, -2);
1153 int maxasc = int(font.maxAscent() *
1154 layout.spacing.getValue() *
1155 parameters->spacing.getValue());
1156 int maxdesc = int(font.maxDescent() *
1157 layout.spacing.getValue() *
1158 parameters->spacing.getValue());
1160 int pos_end = RowLast(row_ptr);
1164 // Check if any insets are larger
1165 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1166 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1167 tmpfont = GetFont(row_ptr->par, pos);
1168 tmpinset = row_ptr->par->GetInset(pos);
1170 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1171 desc = tmpinset->descent(owner_->painter(), tmpfont);
1180 // Check if any custom fonts are larger (Asger)
1181 // This is not completely correct, but we can live with the small,
1182 // cosmetic error for now.
1183 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1185 if (maxsize > font.size()) {
1186 font.setSize(maxsize);
1188 asc = font.maxAscent();
1189 desc = font.maxDescent();
1196 /* table stuff -- begin*/
1197 if (row_ptr->par->table){
1198 // stretch the rows a bit
1202 /* table stuff -- end*/
1204 // This is nicer with box insets:
1208 row_ptr->ascent_of_text = maxasc;
1210 /* is it a top line? */
1211 if (row_ptr->pos == 0
1212 && row_ptr->par == firstpar) {
1214 /* some parksips VERY EASY IMPLEMENTATION */
1215 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1216 if (layout.isParagraph()
1217 && firstpar->GetDepth() == 0
1218 && firstpar->Previous())
1219 maxasc += parameters->getDefSkip().inPixels(owner_);
1220 else if (firstpar->Previous()
1221 && textclasslist.Style(parameters->textclass,
1222 firstpar->Previous()->GetLayout()).isParagraph()
1223 && firstpar->Previous()->GetDepth() == 0)
1224 // is it right to use defskip here too? (AS)
1225 maxasc += parameters->getDefSkip().inPixels(owner_);
1228 /* the paper margins */
1229 if (!row_ptr->par->previous)
1230 maxasc += LYX_PAPER_MARGIN;
1232 /* add the vertical spaces, that the user added */
1233 if (firstpar->added_space_top.kind() != VSpace::NONE)
1234 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1236 /* do not forget the DTP-lines!
1237 * there height depends on the font of the nearest character */
1238 if (firstpar->line_top)
1239 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1241 /* and now the pagebreaks */
1242 if (firstpar->pagebreak_top)
1243 maxasc += 3 * DefaultHeight();
1245 /* this is special code for the chapter, since the label of this
1246 * layout is printed in an extra row */
1247 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1248 && parameters->secnumdepth>= 0) {
1249 labeladdon = int(labelfont.maxDescent() *
1250 layout.spacing.getValue() *
1251 parameters->spacing.getValue())
1252 + int(labelfont.maxAscent() *
1253 layout.spacing.getValue() *
1254 parameters->spacing.getValue());
1257 /* special code for the top label */
1258 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1259 || layout.labeltype == LABEL_BIBLIO
1260 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1261 && row_ptr->par->IsFirstInSequence()
1262 && !row_ptr->par->GetLabestring().empty()) {
1264 (labelfont.maxAscent() *
1265 layout.spacing.getValue() *
1266 parameters->spacing.getValue())
1267 +(labelfont.maxDescent() *
1268 layout.spacing.getValue() *
1269 parameters->spacing.getValue())
1270 + layout.topsep * DefaultHeight()
1271 + layout.labelbottomsep * DefaultHeight());
1274 /* and now the layout spaces, for example before and after a section,
1275 * or between the items of a itemize or enumerate environment */
1277 if (!firstpar->pagebreak_top) {
1278 LyXParagraph * prev = row_ptr->par->Previous();
1280 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1281 if (prev && prev->GetLayout() == firstpar->GetLayout()
1282 && prev->GetDepth() == firstpar->GetDepth()
1283 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1285 layoutasc = (layout.itemsep * DefaultHeight());
1287 else if (row_ptr->previous) {
1288 tmptop = layout.topsep;
1290 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1291 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1294 layoutasc = (tmptop * DefaultHeight());
1296 else if (row_ptr->par->line_top){
1297 tmptop = layout.topsep;
1300 layoutasc = (tmptop * DefaultHeight());
1303 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1305 maxasc += int(textclasslist.Style(parameters->textclass,
1306 prev->GetLayout()).parsep * DefaultHeight());
1309 if (firstpar->Previous()
1310 && firstpar->Previous()->GetDepth() == 0
1311 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1314 else if (firstpar->Previous()){
1315 maxasc += int(layout.parsep * DefaultHeight());
1321 /* is it a bottom line? */
1322 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1323 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1325 /* the paper margins */
1327 maxdesc += LYX_PAPER_MARGIN;
1329 /* add the vertical spaces, that the user added */
1330 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1331 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1333 /* do not forget the DTP-lines!
1334 * there height depends on the font of the nearest character */
1335 if (firstpar->line_bottom)
1336 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1338 /* and now the pagebreaks */
1339 if (firstpar->pagebreak_bottom)
1340 maxdesc += 3 * DefaultHeight();
1342 /* and now the layout spaces, for example before and after a section,
1343 * or between the items of a itemize or enumerate environment */
1344 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1345 LyXParagraph * nextpar = row_ptr->par->Next();
1346 LyXParagraph * comparepar = row_ptr->par;
1350 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1351 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1352 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1353 if (comparepar->GetLayout()!= nextpar->GetLayout()
1354 || nextpar->GetLabelWidthString() !=
1355 comparepar->GetLabelWidthString())
1356 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1358 if (unusual > usual)
1359 layoutdesc = unusual;
1363 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1365 if (comparepar->GetLayout()!= nextpar->GetLayout()
1366 || nextpar->GetLabelWidthString() !=
1367 comparepar->GetLabelWidthString())
1368 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1373 /* incalculate the layout spaces */
1374 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1375 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1377 /* table stuff -- begin*/
1378 if (row_ptr->par->table){
1379 maxasc += row_ptr->par->table->
1380 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1382 /* table stuff -- end*/
1384 /* calculate the new height of the text */
1385 height -= row_ptr->height;
1387 row_ptr->height = maxasc + maxdesc + labeladdon;
1388 row_ptr->baseline = maxasc + labeladdon;
1390 height += row_ptr->height;
1394 /* Appends the implicit specified paragraph behind the specified row,
1395 * start at the implicit given position */
1396 void LyXText::AppendParagraph(Row * row) const
1398 bool not_ready = true;
1400 // The last character position of a paragraph is an invariant so we can
1401 // safely get it here. (Asger)
1402 int lastposition = row->par->Last();
1405 // Get the next breakpoint
1406 int z = NextBreakPoint(row, paperwidth);
1410 // Insert the new row
1411 if (z < lastposition) {
1413 InsertRow(row, row->par, z);
1420 // Set the dimensions of the row
1421 tmprow->fill = Fill(tmprow, paperwidth);
1422 SetHeightOfRow(tmprow);
1424 } while (not_ready);
1428 void LyXText::BreakAgain(Row * row) const
1430 bool not_ready = true;
1433 /* get the next breakpoint */
1434 LyXParagraph::size_type z =
1435 NextBreakPoint(row, paperwidth);
1438 if (z < row->par->Last() ) {
1439 if (!row->next || (row->next && row->next->par != row->par)) {
1442 InsertRow(row, row->par, z);
1449 not_ready = false; // the rest will not change
1455 /* if there are some rows too much, delete them */
1456 /* only if you broke the whole paragraph! */
1457 Row * tmprow2 = row;
1458 while (tmprow2->next && tmprow2->next->par == row->par) {
1459 tmprow2 = tmprow2->next;
1461 while (tmprow2 != row) {
1462 tmprow2 = tmprow2->previous;
1463 RemoveRow(tmprow2->next);
1468 /* set the dimensions of the row */
1469 tmprow->fill = Fill(tmprow, paperwidth);
1470 SetHeightOfRow(tmprow);
1471 } while (not_ready);
1475 /* this is just a little changed version of break again */
1476 void LyXText::BreakAgainOneRow(Row * row)
1478 /* get the next breakpoint */
1479 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1482 if (z < row->par->Last() ) {
1483 if (!row->next || (row->next && row->next->par != row->par)) {
1484 /* insert a new row */
1486 InsertRow(row, row->par, z);
1498 /* if there are some rows too much, delete them */
1499 /* only if you broke the whole paragraph! */
1500 Row * tmprow2 = row;
1501 while (tmprow2->next && tmprow2->next->par == row->par) {
1502 tmprow2 = tmprow2->next;
1504 while (tmprow2 != row) {
1505 tmprow2 = tmprow2->previous;
1506 RemoveRow(tmprow2->next);
1510 /* set the dimensions of the row */
1511 tmprow->fill = Fill(tmprow, paperwidth);
1512 SetHeightOfRow(tmprow);
1516 void LyXText::BreakParagraph(char keep_layout)
1518 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1519 cursor.par->GetLayout());
1521 /* table stuff -- begin */
1522 if (cursor.par->table) {
1523 // breaking of tables is only allowed at the beginning or the end */
1524 if (cursor.pos && cursor.pos < cursor.par->size() &&
1525 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1526 return; // no breaking of tables allowed
1528 /* table stuff -- end */
1530 // this is only allowed, if the current paragraph is not empty or caption
1531 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1533 layout.labeltype!= LABEL_SENSITIVE)
1536 SetUndo(Undo::INSERT,
1537 cursor.par->ParFromPos(cursor.pos)->previous,
1538 cursor.par->ParFromPos(cursor.pos)->next);
1540 /* table stuff -- begin */
1541 if (cursor.par->table) {
1542 int cell = NumberOfCell(cursor.par, cursor.pos);
1543 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1544 SetCursor(cursor.par, cursor.par->text.size());
1546 /* table stuff -- end */
1548 // please break always behind a space
1549 if (cursor.pos < cursor.par->Last()
1550 && cursor.par->IsLineSeparator(cursor.pos))
1553 // break the paragraph
1557 keep_layout = layout.isEnvironment();
1558 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1560 /* table stuff -- begin */
1561 if (cursor.par->table){
1562 // the table should stay with the contents
1564 cursor.par->Next()->table = cursor.par->table;
1565 cursor.par->table = 0;
1568 /* table stuff -- end */
1570 // well this is the caption hack since one caption is really enough
1571 if (layout.labeltype == LABEL_SENSITIVE){
1573 cursor.par->SetLayout(0); // set to standard-layout
1575 cursor.par->Next()->SetLayout(0); // set to standard-layout
1578 /* if the cursor is at the beginning of a row without prior newline,
1580 * This touches only the screen-update. Otherwise we would may have
1581 * an empty row on the screen */
1582 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1583 cursor.row->pos == cursor.pos) {
1587 status = LyXText::NEED_MORE_REFRESH;
1588 refresh_row = cursor.row;
1589 refresh_y = cursor.y - cursor.row->baseline;
1591 // Do not forget the special right address boxes
1592 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1593 while (refresh_row->previous &&
1594 refresh_row->previous->par == refresh_row->par) {
1595 refresh_row = refresh_row->previous;
1596 refresh_y -= refresh_row->height;
1599 RemoveParagraph(cursor.row);
1601 // set the dimensions of the cursor row
1602 cursor.row->fill = Fill(cursor.row, paperwidth);
1604 SetHeightOfRow(cursor.row);
1606 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1607 && cursor.par->Next()->IsNewline(0))
1608 cursor.par->Next()->Erase(0);
1610 InsertParagraph(cursor.par->Next(), cursor.row);
1612 UpdateCounters(cursor.row->previous);
1614 /* This check is necessary. Otherwise the new empty paragraph will
1615 * be deleted automatically. And it is more friendly for the user! */
1617 SetCursor(cursor.par->Next(), 0);
1619 SetCursor(cursor.par, 0);
1621 if (cursor.row->next)
1622 BreakAgain(cursor.row->next);
1628 void LyXText::OpenFootnote()
1630 LyXParagraph * endpar,* tmppar;
1633 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1635 /* if there is no footnote in this paragraph, just return. */
1637 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1640 /* ok, move the cursor right before the footnote */
1642 /* just a little faster than using CursorRight() */
1643 for (cursor.pos = 0;
1644 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1645 /* now the cursor is at the beginning of the physical par */
1646 SetCursor(cursor.par,
1647 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1649 /* the cursor must be exactly before the footnote */
1650 par = cursor.par->ParFromPos(cursor.pos);
1652 status = LyXText::NEED_MORE_REFRESH;
1653 refresh_row = cursor.row;
1654 refresh_y = cursor.y - cursor.row->baseline;
1656 tmppar = cursor.par;
1657 endpar = cursor.par->Next();
1660 tmppar->OpenFootnote(cursor.pos);
1661 RemoveParagraph(row);
1662 /* set the dimensions of the cursor row */
1663 row->fill = Fill(row, paperwidth);
1664 SetHeightOfRow(row);
1665 tmppar = tmppar->Next();
1667 while (tmppar != endpar) {
1669 InsertParagraph(tmppar, row);
1670 while (row->next && row->next->par == tmppar)
1672 tmppar = tmppar->Next();
1675 SetCursor(par->next, 0);
1676 sel_cursor = cursor;
1680 /* table stuff -- begin*/
1682 void LyXText::TableFeatures(int feature, string const & val) const
1684 if (!cursor.par->table)
1685 return; /* this should never happen */
1687 int actCell = NumberOfCell(cursor.par, cursor.pos);
1688 SetUndo(Undo::FINISH,
1689 cursor.par->ParFromPos(cursor.pos)->previous,
1690 cursor.par->ParFromPos(cursor.pos)->next);
1693 case LyXTable::SET_PWIDTH:
1694 cursor.par->table->SetPWidth(actCell, val);
1696 case LyXTable::SET_SPECIAL_COLUMN:
1697 case LyXTable::SET_SPECIAL_MULTI:
1698 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1707 void LyXText::TableFeatures(int feature) const
1710 int setAlign = LYX_ALIGN_LEFT;
1714 if (!cursor.par->table)
1715 return; /* this should never happen */
1717 int actCell = NumberOfCell(cursor.par, cursor.pos);
1718 SetUndo(Undo::FINISH,
1719 cursor.par->ParFromPos(cursor.pos)->previous,
1720 cursor.par->ParFromPos(cursor.pos)->next);
1723 case LyXTable::ALIGN_LEFT:
1724 setAlign= LYX_ALIGN_LEFT;
1726 case LyXTable::ALIGN_RIGHT:
1727 setAlign= LYX_ALIGN_RIGHT;
1729 case LyXTable::ALIGN_CENTER:
1730 setAlign= LYX_ALIGN_CENTER;
1736 case LyXTable::APPEND_ROW: {
1737 LyXParagraph::size_type pos = cursor.pos;
1739 /* move to the next row */
1740 int cell_org = actCell;
1741 int cell = cell_org;
1743 // if there is a ContRow following this row I have to add
1744 // the row after the ContRow's
1745 if ((pos < cursor.par->Last()) &&
1746 cursor.par->table->RowHasContRow(cell_org)) {
1747 while((pos < cursor.par->Last()) &&
1748 !cursor.par->table->IsContRow(cell)) {
1749 while (pos < cursor.par->Last() &&
1750 !cursor.par->IsNewline(pos))
1752 if (pos < cursor.par->Last())
1756 while((pos < cursor.par->Last()) &&
1757 cursor.par->table->IsContRow(cell)) {
1758 while (pos < cursor.par->Last() &&
1759 !cursor.par->IsNewline(pos))
1761 if (pos < cursor.par->Last())
1766 if (pos < cursor.par->Last())
1769 while (pos < cursor.par->Last() &&
1770 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1771 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1773 if (pos < cursor.par->Last())
1778 /* insert the new cells */
1779 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1780 for (int i = 0; i < number; ++i)
1781 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1783 /* append the row into the table */
1784 cursor.par->table->AppendRow(cell_org);
1788 case LyXTable::APPEND_CONT_ROW: {
1789 LyXParagraph::size_type pos = cursor.pos;
1790 /* move to the next row */
1791 int cell_org = actCell;
1792 int cell = cell_org;
1794 // if there is already a controw but not for this cell
1795 // the AppendContRow sets only the right values but does
1796 // not actually add a row
1797 if (cursor.par->table->RowHasContRow(cell_org) &&
1798 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1799 cursor.par->table->AppendContRow(cell_org);
1803 while (pos < cursor.par->Last() &&
1805 || !cursor.par->table->IsFirstCell(cell))){
1806 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1808 if (pos < cursor.par->Last())
1813 /* insert the new cells */
1814 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1815 for (int i = 0; i < number; ++i)
1816 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1818 /* append the row into the table */
1819 cursor.par->table->AppendContRow(cell_org);
1823 case LyXTable::APPEND_COLUMN: {
1824 LyXParagraph::size_type pos = 0;
1825 int cell_org = actCell;
1828 if (pos && (cursor.par->IsNewline(pos-1))){
1829 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1830 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1831 if (pos <= cursor.pos)
1838 } while (pos <= cursor.par->Last());
1839 /* remember that the very last cell doesn't end with a newline.
1840 This saves one byte memory per table ;-) */
1841 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1842 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1844 /* append the column into the table */
1845 cursor.par->table->AppendColumn(cell_org);
1850 case LyXTable::DELETE_ROW:
1851 if (owner_->the_locking_inset)
1852 owner_->unlockInset(owner_->the_locking_inset);
1853 RemoveTableRow(&cursor);
1857 case LyXTable::DELETE_COLUMN: {
1858 LyXParagraph::size_type pos = 0;
1859 int cell_org = actCell;
1861 if (owner_->the_locking_inset)
1862 owner_->unlockInset(owner_->the_locking_inset);
1864 if (!pos || (cursor.par->IsNewline(pos-1))){
1865 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1867 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1868 cursor.par->Erase(pos);
1869 if (pos < cursor.par->Last())
1870 cursor.par->Erase(pos);
1872 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1873 --pos; // because of pos++ below
1878 } while (pos <= cursor.par->Last());
1880 /* delete the column from the table */
1881 cursor.par->table->DeleteColumn(cell_org);
1883 /* set the cursor to the beginning of the table, where else? */
1888 case LyXTable::TOGGLE_LINE_TOP:
1889 lineSet = !cursor.par->table->TopLine(actCell);
1891 cursor.par->table->SetTopLine(actCell, lineSet);
1893 LyXParagraph::size_type i;
1895 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1896 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1897 cursor.par->table->SetTopLine(n, lineSet);
1905 case LyXTable::TOGGLE_LINE_BOTTOM:
1906 lineSet = !cursor.par->table->BottomLine(actCell);
1908 cursor.par->table->SetBottomLine(actCell, lineSet);
1910 LyXParagraph::size_type i;
1912 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1913 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1914 cursor.par->table->SetBottomLine(n, lineSet);
1922 case LyXTable::TOGGLE_LINE_LEFT:
1923 lineSet = !cursor.par->table->LeftLine(actCell);
1925 cursor.par->table->SetLeftLine(actCell, lineSet);
1927 LyXParagraph::size_type i;
1929 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1930 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1931 cursor.par->table->SetLeftLine(n, lineSet);
1939 case LyXTable::TOGGLE_LINE_RIGHT:
1940 lineSet = !cursor.par->table->RightLine(actCell);
1942 cursor.par->table->SetRightLine(actCell, lineSet);
1945 LyXParagraph::size_type i = sel_start_cursor.pos;
1946 for (; i <= sel_end_cursor.pos; ++i) {
1947 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1948 cursor.par->table->SetRightLine(n, lineSet);
1956 case LyXTable::ALIGN_LEFT:
1957 case LyXTable::ALIGN_RIGHT:
1958 case LyXTable::ALIGN_CENTER:
1960 cursor.par->table->SetAlignment(actCell, setAlign);
1963 LyXParagraph::size_type i = sel_start_cursor.pos;
1964 for (; i <= sel_end_cursor.pos; ++i) {
1965 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1966 cursor.par->table->SetAlignment(n, setAlign);
1974 case LyXTable::DELETE_TABLE:
1975 SetCursorIntern(cursor.par, 0);
1976 delete cursor.par->table;
1977 cursor.par->table = 0;
1978 // temporary: Should put table in simple_cut_buffer (with before and after
1979 // dummy-paragraph !!
1980 // not necessar anymore with UNDO :)
1981 for (LyXParagraph::size_type i =
1982 cursor.par->text.size() - 1; i >= 0; --i)
1983 cursor.par->Erase(i);
1987 case LyXTable::MULTICOLUMN: {
1989 // check wether we are completly in a multicol
1990 int multicol = cursor.par->table->IsMultiColumn(actCell);
1991 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1992 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1993 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
1997 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
1998 LyXParagraph::size_type pos = cursor.pos;
1999 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2001 for (; newlines; --newlines)
2002 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2007 // selection must be in one row (or no selection)
2009 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2016 if (sel_start_cursor.row == sel_end_cursor.row){
2017 LyXParagraph::size_type i;
2019 for (i = sel_start_cursor.pos;
2020 i < sel_end_cursor.pos; ++i){
2021 if (sel_start_cursor.par->IsNewline(i)){
2022 sel_start_cursor.par->Erase(i);
2023 // check for double-blanks
2024 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2026 (i < sel_start_cursor.par->Last()
2027 && !sel_start_cursor.par->IsLineSeparator(i)))
2028 sel_start_cursor.par->InsertChar(i, ' ');
2030 sel_end_cursor.pos--;
2037 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2038 sel_start_cursor.pos),
2040 cursor.pos = sel_start_cursor.pos;
2045 WriteAlert(_("Impossible Operation!"),
2046 _("Multicolumns can only be horizontally."),
2053 case LyXTable::SET_ALL_LINES:
2055 case LyXTable::UNSET_ALL_LINES:
2057 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2061 LyXParagraph::size_type i;
2063 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2064 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2065 cursor.par->table->SetAllLines(n, setLines);
2072 case LyXTable::SET_LONGTABLE:
2073 cursor.par->table->SetLongTable(true);
2075 case LyXTable::UNSET_LONGTABLE:
2076 cursor.par->table->SetLongTable(false);
2078 case LyXTable::SET_ROTATE_TABLE:
2079 cursor.par->table->SetRotateTable(true);
2081 case LyXTable::UNSET_ROTATE_TABLE:
2082 cursor.par->table->SetRotateTable(false);
2084 case LyXTable::SET_ROTATE_CELL:
2086 cursor.par->table->SetRotateCell(actCell, true);
2088 LyXParagraph::size_type i;
2090 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2091 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2092 cursor.par->table->SetRotateCell(n, true);
2098 case LyXTable::UNSET_ROTATE_CELL:
2100 cursor.par->table->SetRotateCell(actCell, false);
2103 LyXParagraph::size_type i = sel_start_cursor.pos;
2104 for (; i <= sel_end_cursor.pos; ++i) {
2105 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2106 cursor.par->table->SetRotateCell(n, false);
2112 case LyXTable::SET_LINEBREAKS:
2113 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2115 cursor.par->table->SetLinebreaks(actCell, what);
2117 LyXParagraph::size_type i;
2119 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2120 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2121 cursor.par->table->SetLinebreaks(n, what);
2127 case LyXTable::SET_LTFIRSTHEAD:
2128 cursor.par->table->SetLTHead(actCell, true);
2130 case LyXTable::SET_LTHEAD:
2131 cursor.par->table->SetLTHead(actCell, false);
2133 case LyXTable::SET_LTFOOT:
2134 cursor.par->table->SetLTFoot(actCell, false);
2136 case LyXTable::SET_LTLASTFOOT:
2137 cursor.par->table->SetLTFoot(actCell, true);
2139 case LyXTable::SET_LTNEWPAGE:
2140 what = !cursor.par->table->LTNewPage(actCell);
2141 cursor.par->table->SetLTNewPage(actCell, what);
2147 void LyXText::InsertCharInTable(char c)
2152 bool jumped_over_space;
2154 /* first check, if there will be two blanks together or a blank at
2155 * the beginning of a paragraph.
2156 * I decided to handle blanks like normal characters, the main
2157 * difference are the special checks when calculating the row.fill
2158 * (blank does not count at the end of a row) and the check here */
2160 LyXFont realtmpfont = real_current_font;
2161 LyXFont rawtmpfont = current_font; /* store the current font.
2162 * This is because of the use
2163 * of cursor movements. The moving
2164 * cursor would refresh the
2167 // Get the font that is used to calculate the baselineskip
2168 LyXParagraph::size_type const lastpos =
2170 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2172 jumped_over_space = false;
2173 if (IsLineSeparatorChar(c)) {
2175 #ifndef FIX_DOUBLE_SPACE
2176 /* avoid double blanks but insert the new blank because
2177 * of a possible font change */
2178 if (cursor.pos < lastpos &&
2179 cursor.par->IsLineSeparator(cursor.pos)) {
2180 cursor.par->Erase(cursor.pos);
2181 jumped_over_space = true;
2184 if ((cursor.pos > 0 &&
2185 cursor.par->IsLineSeparator(cursor.pos - 1))
2186 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2187 || (cursor.pos == 0 &&
2188 !(cursor.par->Previous()
2189 && cursor.par->Previous()->footnoteflag
2190 == LyXParagraph::OPEN_FOOTNOTE)))
2192 } else if (IsNewlineChar(c)) {
2193 if (!IsEmptyTableCell()) {
2194 TableFeatures(LyXTable::APPEND_CONT_ROW);
2201 y = cursor.y - row->baseline;
2202 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2203 * already inserted the character */
2204 cursor.par->InsertChar(cursor.pos, c);
2205 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2207 if (!jumped_over_space) {
2208 /* refresh the positions */
2210 while (tmprow->next && tmprow->next->par == row->par) {
2211 tmprow = tmprow->next;
2218 CheckParagraphInTable(cursor.par, cursor.pos);
2220 current_font = rawtmpfont;
2221 real_current_font = realtmpfont;
2223 /* check, whether the last character's font has changed. */
2224 if (cursor.pos && cursor.pos == cursor.par->Last()
2225 && rawparfont != rawtmpfont)
2226 RedoHeightOfParagraph(cursor);
2230 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2231 LyXParagraph::size_type pos)
2234 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2235 par->GetInset(pos) && par->GetInset(pos)->display()){
2236 par->GetInset(pos)->display(false);
2240 Row * row = GetRow(par, pos, y);
2242 int tmpheight = row->height;
2243 SetHeightOfRow(row);
2245 LyXParagraph::size_type tmp_pos = pos;
2246 /* update the table information */
2247 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2249 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2250 WidthOfCell(par, tmp_pos))) {
2251 LyXCursor tmpcursor = cursor;
2252 SetCursorIntern(par, pos);
2253 /* make a complete redraw */
2254 RedoDrawingOfParagraph(cursor);
2258 /* redraw only the row */
2259 LyXCursor tmpcursor = cursor;
2260 SetCursorIntern(par, pos);
2262 refresh_x = cursor.x;
2264 refresh_pos = cursor.pos;
2267 if (tmpheight == row->height)
2268 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2270 status = LyXText::NEED_MORE_REFRESH;
2272 SetCursorIntern(cursor.par, cursor.pos);
2276 void LyXText::BackspaceInTable()
2278 Row * tmprow, * row;
2281 LyXFont rawtmpfont = current_font;
2282 LyXFont realtmpfont = real_current_font;
2284 // Get the font that is used to calculate the baselineskip
2285 int const lastpos = cursor.par->Last();
2286 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2288 if (cursor.pos == 0) {
2289 /* no pasting of table paragraphs */
2293 /* this is the code for a normal backspace, not pasting
2295 SetUndo(Undo::DELETE,
2296 cursor.par->ParFromPos(cursor.pos)->previous,
2297 cursor.par->ParFromPos(cursor.pos)->next);
2301 /* some insets are undeletable here */
2302 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2303 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2308 y = cursor.y - row->baseline;
2310 /* some special code when deleting a newline. */
2311 if (cursor.par->IsNewline(cursor.pos)) {
2316 cursor.par->Erase(cursor.pos);
2318 /* refresh the positions */
2320 while (tmprow->next && tmprow->next->par == row->par) {
2321 tmprow = tmprow->next;
2325 #ifndef FIX_DOUBLE_SPACE
2326 /* delete superfluous blanks */
2327 if (cursor.pos < cursor.par->Last() - 1 &&
2328 (cursor.par->IsLineSeparator(cursor.pos))) {
2330 if (cursor.pos == BeginningOfMainBody(cursor.par)
2332 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2333 cursor.par->Erase(cursor.pos);
2334 /* refresh the positions */
2336 while (tmprow->next &&
2337 tmprow->next->par == row->par) {
2338 tmprow = tmprow->next;
2341 if (cursor.pos) /* move one character left */
2348 CheckParagraphInTable(cursor.par, cursor.pos);
2350 /* check, wether the last characters font has changed. */
2351 if (cursor.pos && cursor.pos == cursor.par->Last()
2352 && rawparfont != rawtmpfont)
2353 RedoHeightOfParagraph(cursor);
2355 /* restore the current font
2356 * That is what a user expects! */
2357 current_font = rawtmpfont;
2358 real_current_font = realtmpfont;
2360 SetCursorIntern(cursor.par, cursor.pos);
2363 /* table stuff -- end*/
2366 /* just a macro to make some thing easier. */
2367 void LyXText::RedoParagraph() const
2370 // I suspect this version will work
2373 RedoParagraphs(cursor, cursor.par->Next());
2374 SetCursorIntern(cursor.par, cursor.pos);
2376 LyXCursor tmpcursor = cursor;
2378 RedoParagraphs(cursor, cursor.par->Next());
2379 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2384 /* insert a character, moves all the following breaks in the
2385 * same Paragraph one to the right and make a rebreak */
2386 void LyXText::InsertChar(char c)
2388 SetUndo(Undo::INSERT,
2389 cursor.par->ParFromPos(cursor.pos)->previous,
2390 cursor.par->ParFromPos(cursor.pos)->next);
2392 /* When the free-spacing option is set for the current layout,
2393 * all spaces are converted to protected spaces. */
2394 bool freeSpacingBo =
2395 textclasslist.Style(parameters->textclass,
2396 cursor.row->par->GetLayout()).free_spacing;
2398 if (freeSpacingBo && IsLineSeparatorChar(c)
2399 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2400 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2402 /* table stuff -- begin*/
2403 if (cursor.par->table) {
2404 InsertCharInTable(c);
2408 /* table stuff -- end*/
2410 /* First check, if there will be two blanks together or a blank at
2411 the beginning of a paragraph.
2412 I decided to handle blanks like normal characters, the main
2413 difference are the special checks when calculating the row.fill
2414 (blank does not count at the end of a row) and the check here */
2416 // The bug is triggered when we type in a description environment:
2417 // The current_font is not changed when we go from label to main text
2418 // and it should (along with realtmpfont) when we type the space.
2419 #ifdef WITH_WARNINGS
2420 #warning There is a bug here! (Asger)
2423 LyXFont realtmpfont = real_current_font;
2424 LyXFont rawtmpfont = current_font; /* store the current font.
2425 * This is because of the use
2426 * of cursor movements. The moving
2427 * cursor would refresh the
2430 // Get the font that is used to calculate the baselineskip
2431 LyXParagraph::size_type lastpos = cursor.par->Last();
2432 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2434 bool jumped_over_space = false;
2436 if (IsLineSeparatorChar(c)) {
2437 #ifndef FIX_DOUBLE_SPACE
2438 if (cursor.pos < lastpos
2439 && cursor.par->IsLineSeparator(cursor.pos)) {
2440 /* the user inserted a space before a space. So we
2441 * will just make a CursorRight. BUT: The font of this
2442 * space should be set to current font. That is why
2443 * we need to rebreak perhaps. If there is a protected
2444 * blank at the end of a row we have to force
2447 owner_->owner()->getMiniBuffer()
2448 ->Set(_("You cannot type two spaces this way. "
2449 " Please read the Tutorial."));
2451 // How can this ever happen?
2452 if (cursor.pos == RowLast(cursor.row)
2453 && !IsLineSeparatorChar(c))
2454 cursor.row->fill = -1; // force rebreak
2455 cursor.par->Erase(cursor.pos);
2456 jumped_over_space = true;
2458 // Seems to me that this works just as well.
2466 && cursor.par->IsLineSeparator(cursor.pos - 1))
2468 && cursor.par->IsNewline(cursor.pos - 1))
2470 && !(cursor.par->Previous()
2471 && cursor.par->Previous()->footnoteflag
2472 == LyXParagraph::OPEN_FOOTNOTE))) {
2473 if (cursor.pos == 0 )
2474 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2476 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2480 } else if (IsNewlineChar(c)) {
2481 if (cursor.par->FirstPhysicalPar() == cursor.par
2482 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2486 /* No newline at first position
2487 * of a paragraph or behind labels.
2488 * TeX does not allow that. */
2490 if (cursor.pos < cursor.par->Last() &&
2491 cursor.par->IsLineSeparator(cursor.pos))
2492 CursorRightIntern(); // newline always after a blank!
2493 cursor.row->fill = -1; // to force a new break
2496 // the display inset stuff
2497 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2498 && cursor.row->par->GetInset(cursor.row->pos)
2499 && cursor.row->par->GetInset(cursor.row->pos)->display())
2500 cursor.row->fill = -1; // to force a new break
2502 // get the cursor row fist
2503 Row * row = cursor.row;
2504 long y = cursor.y - row->baseline;
2505 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2506 * already insertet the character */
2507 cursor.par->InsertChar(cursor.pos, c);
2508 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2510 if (!jumped_over_space) {
2511 // refresh the positions
2513 while (tmprow->next && tmprow->next->par == row->par) {
2514 tmprow = tmprow->next;
2519 // Is there a break one row above
2520 if ((cursor.par->IsLineSeparator(cursor.pos)
2521 || cursor.par->IsNewline(cursor.pos)
2522 || cursor.row->fill == -1)
2523 && row->previous && row->previous->par == row->par) {
2524 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2526 if ( z >= row->pos) {
2529 // set the dimensions of the row above
2530 row->previous->fill = Fill(row->previous, paperwidth);
2532 SetHeightOfRow(row->previous);
2534 y -= row->previous->height;
2536 refresh_row = row->previous;
2537 status = LyXText::NEED_MORE_REFRESH;
2539 BreakAgainOneRow(row);
2541 current_font = rawtmpfont;
2542 real_current_font = realtmpfont;
2543 SetCursor(cursor.par, cursor.pos + 1, false);
2544 /* cursor MUST be in row now */
2546 if (row->next && row->next->par == row->par)
2547 need_break_row = row->next;
2551 // check, wether the last characters font has changed.
2552 if (cursor.pos && cursor.pos == cursor.par->Last()
2553 && rawparfont != rawtmpfont)
2554 RedoHeightOfParagraph(cursor);
2561 /* recalculate the fill of the row */
2562 if (row->fill >= 0) /* needed because a newline
2563 * will set fill to -1. Otherwise
2564 * we would not get a rebreak! */
2565 row->fill = Fill(row, paperwidth);
2566 if (row->fill < 0 ) {
2569 refresh_x = cursor.x;
2570 refresh_pos = cursor.pos;
2571 status = LyXText::NEED_MORE_REFRESH;
2572 BreakAgainOneRow(row);
2573 /* will the cursor be in another row now? */
2574 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2575 if (row->next && row->next->par == row->par)
2579 BreakAgainOneRow(row);
2581 current_font = rawtmpfont;
2582 real_current_font = realtmpfont;
2583 SetCursor(cursor.par, cursor.pos + 1, false);
2584 if (row->next && row->next->par == row->par)
2585 need_break_row = row->next;
2590 refresh_x = cursor.x;
2592 refresh_pos = cursor.pos;
2594 int tmpheight = row->height;
2595 SetHeightOfRow(row);
2596 if (tmpheight == row->height)
2597 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2599 status = LyXText::NEED_MORE_REFRESH;
2601 current_font = rawtmpfont;
2602 real_current_font = realtmpfont;
2603 SetCursor(cursor.par, cursor.pos + 1, false);
2606 /* check, wether the last characters font has changed. */
2607 if (cursor.pos && cursor.pos == cursor.par->Last()
2608 && rawparfont != rawtmpfont) {
2609 RedoHeightOfParagraph(cursor);
2611 /* now the special right address boxes */
2612 if (textclasslist.Style(parameters->textclass,
2613 cursor.par->GetLayout()).margintype
2614 == MARGIN_RIGHT_ADDRESS_BOX) {
2615 RedoDrawingOfParagraph(cursor);
2623 void LyXText::charInserted()
2625 // Here we could call FinishUndo for every 20 characters inserted.
2626 // This is from my experience how emacs does it.
2627 static unsigned int counter = 0;
2636 void LyXText::PrepareToPrint(Row * row, float & x,
2637 float & fill_separator,
2639 float & fill_label_hfill,
2644 float w = row->fill;
2646 fill_label_hfill = 0;
2648 fill_label_hfill = 0;
2650 LyXDirection direction = row->par->getParDirection();
2652 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2653 x = RightMargin(row);
2654 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2655 LyXFont font(LyXFont::ALL_SANE);
2656 font.setSize(LyXFont::SIZE_SMALL);
2657 x += font.textWidth("Mwide-figM", 10);
2661 x = LeftMargin(row);
2663 /* is there a manual margin with a manual label */
2664 if (textclasslist.Style(parameters->textclass,
2665 row->par->GetLayout()).margintype == MARGIN_MANUAL
2666 && textclasslist.Style(parameters->textclass,
2667 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2669 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2670 * are left aligned*/
2671 if (nlh && !row->par->GetLabelWidthString().empty()) {
2672 fill_label_hfill = LabelFill(row) / nlh;
2676 /* are there any hfills in the row? */
2677 nh = NumberOfHfills(row);
2679 /* table stuff -- begin*/
2680 if (row->par->table) {
2681 w = paperwidth - row->par->table->WidthOfTable()
2682 - x - RightMargin(row);
2683 nh = 0; /* ignore hfills in tables */
2685 /* table stuff -- end*/
2690 /* is it block, flushleft or flushright?
2691 * set x how you need it */
2693 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2694 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2696 align = row->par->FirstPhysicalPar()->align;
2698 /* center displayed insets */
2699 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2700 && row->par->GetInset(row->pos)
2701 && row->par->GetInset(row->pos)->display())
2702 align = LYX_ALIGN_CENTER;
2705 case LYX_ALIGN_BLOCK:
2706 ns = NumberOfSeparators(row);
2707 if (ns && row->next && row->next->par == row->par &&
2708 !(row->next->par->IsNewline(row->next->pos-1))
2709 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2710 && row->next->par->GetInset(row->next->pos)
2711 && row->next->par->GetInset(row->next->pos)->display())
2713 fill_separator = w / ns;
2714 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2717 case LYX_ALIGN_RIGHT:
2720 case LYX_ALIGN_CENTER:
2728 ComputeBidiTables(row);
2729 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2730 LyXParagraph::size_type main_body =
2731 BeginningOfMainBody(row->par);
2732 LyXParagraph::size_type last = RowLast(row);
2734 if (row->pos <= last
2736 && last != vis2log(last)
2737 && row->par->IsLineSeparator(last)) {
2738 if (!(main_body > 0 && main_body-1 == last))
2739 x -= fill_separator+SingleWidth(row->par,last);
2740 } else if (main_body > 0 &&
2741 (main_body-1 > last ||
2742 !row->par->IsLineSeparator(main_body-1))) {
2743 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2744 row->par->GetLayout());
2745 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2746 if (main_body-1 <= last)
2747 x += fill_label_hfill;
2752 /* important for the screen */
2755 /* the cursor set functions have a special mechanism. When they
2756 * realize, that you left an empty paragraph, they will delete it.
2757 * They also delete the corresponding row */
2759 void LyXText::CursorRightOneWord() const
2761 // treat floats, HFills and Insets as words
2762 LyXCursor tmpcursor = cursor;
2764 if (tmpcursor.pos == tmpcursor.par->Last()
2765 && tmpcursor.par->Next())
2767 tmpcursor.par = tmpcursor.par->Next();
2772 // Skip through initial nonword stuff.
2773 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2774 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2776 // printf("Current pos1 %d", tmpcursor.pos) ;
2780 // Advance through word.
2781 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2782 tmpcursor.par->IsWord( tmpcursor.pos ) )
2784 // printf("Current pos2 %d", tmpcursor.pos) ;
2789 SetCursor(tmpcursor.par, tmpcursor.pos);
2793 void LyXText::CursorTab() const
2795 if (cursor.par->table) {
2796 int cell = NumberOfCell(cursor.par, cursor.pos);
2797 while(cursor.par->table->IsContRow(cell)) {
2799 cell = NumberOfCell(cursor.par, cursor.pos);
2801 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2802 TableFeatures(LyXTable::APPEND_ROW);
2804 LyXCursor tmpcursor = cursor;
2805 while (tmpcursor.pos < tmpcursor.par->Last()
2806 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2809 if (tmpcursor.pos == tmpcursor.par->Last()){
2810 if (tmpcursor.par->Next()) {
2811 tmpcursor.par = tmpcursor.par->Next();
2817 SetCursor(tmpcursor.par, tmpcursor.pos);
2818 if (cursor.par->table) {
2819 int cell = NumberOfCell(cursor.par, cursor.pos);
2820 while (cursor.par->table->IsContRow(cell) &&
2821 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2823 while (tmpcursor.pos < tmpcursor.par->Last()
2824 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2827 if (tmpcursor.pos == tmpcursor.par->Last()){
2828 if (tmpcursor.par->Next()) {
2829 tmpcursor.par = tmpcursor.par->Next();
2835 SetCursor(tmpcursor.par, tmpcursor.pos);
2836 cell = NumberOfCell(cursor.par, cursor.pos);
2842 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2843 of prior word, not to end of next prior word. */
2845 void LyXText::CursorLeftOneWord() const
2847 // treat HFills, floats and Insets as words
2848 LyXCursor tmpcursor = cursor;
2849 while (tmpcursor.pos
2850 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2851 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2852 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2853 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2854 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2858 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2859 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2860 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2862 } else if (!tmpcursor.pos) {
2863 if (tmpcursor.par->Previous()){
2864 tmpcursor.par = tmpcursor.par->Previous();
2865 tmpcursor.pos = tmpcursor.par->Last();
2867 } else { // Here, tmpcursor != 0
2868 while (tmpcursor.pos > 0 &&
2869 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2872 SetCursor(tmpcursor.par, tmpcursor.pos);
2875 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2878 void LyXText::SelectWord()
2880 /* Move cursor to the beginning, when not already there. */
2882 && !cursor.par->IsSeparator(cursor.pos-1)
2883 && !cursor.par->IsKomma(cursor.pos-1) )
2884 CursorLeftOneWord();
2886 /* set the sel cursor */
2887 sel_cursor = cursor;
2889 while ( cursor.pos < cursor.par->Last()
2890 && !cursor.par->IsSeparator(cursor.pos)
2891 && !cursor.par->IsKomma(cursor.pos) )
2893 SetCursor( cursor.par, cursor.pos );
2895 /* finally set the selection */
2900 /* -------> Select the word currently under the cursor when:
2901 1: no selection is currently set,
2902 2: the cursor is not at the borders of the word. */
2904 int LyXText::SelectWordWhenUnderCursor()
2906 if ( selection ) return 0;
2907 if ( cursor.pos < cursor.par->Last()
2908 && !cursor.par->IsSeparator(cursor.pos)
2909 && !cursor.par->IsKomma(cursor.pos)
2911 && !cursor.par->IsSeparator(cursor.pos -1)
2912 && !cursor.par->IsKomma(cursor.pos -1) ) {
2920 // This function is only used by the spellchecker for NextWord().
2921 // It doesn't handle LYX_ACCENTs and probably never will.
2922 char * LyXText::SelectNextWord(float & value)
2924 LyXParagraph * tmppar = cursor.par;
2926 // If this is not the very first word, skip rest of
2927 // current word because we are probably in the middle
2928 // of a word if there is text here.
2929 if (cursor.pos || cursor.par->previous) {
2930 while (cursor.pos < cursor.par->Last()
2931 && cursor.par->IsLetter(cursor.pos))
2934 // Now, skip until we have real text (will jump paragraphs)
2935 while ((cursor.par->Last() > cursor.pos
2936 && (!cursor.par->IsLetter(cursor.pos)
2937 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2938 || (cursor.par->Last() == cursor.pos
2939 && cursor.par->Next())){
2940 if (cursor.pos == cursor.par->Last()) {
2941 cursor.par = cursor.par->Next();
2948 // Update the value if we changed paragraphs
2949 if (cursor.par != tmppar){
2950 SetCursor(cursor.par, cursor.pos);
2951 value = float(cursor.y)/float(height);
2954 /* Start the selection from here */
2955 sel_cursor = cursor;
2959 /* and find the end of the word
2960 (optional hyphens are part of a word) */
2961 while (cursor.pos < cursor.par->Last()
2962 && (cursor.par->IsLetter(cursor.pos))
2963 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2964 cursor.par->GetInset(cursor.pos) != 0 &&
2965 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2969 // Finally, we copy the word to a string and return it
2972 if (sel_cursor.pos < cursor.pos) {
2973 str = new char [cursor.pos - sel_cursor.pos + 2];
2974 LyXParagraph::size_type i, j;
2975 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2976 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
2977 str[j++] = cursor.par->GetChar(i);
2985 // This one is also only for the spellchecker
2986 void LyXText::SelectSelectedWord()
2988 /* move cursor to the beginning */
2989 SetCursor(sel_cursor.par, sel_cursor.pos);
2991 /* set the sel cursor */
2992 sel_cursor = cursor;
2996 /* now find the end of the word */
2997 while (cursor.pos < cursor.par->Last()
2998 && (cursor.par->IsLetter(cursor.pos)
2999 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3000 cursor.par->GetInset(cursor.pos) != 0 &&
3001 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3005 SetCursor(cursor.par, cursor.pos);
3007 /* finally set the selection */
3012 /* -------> Delete from cursor up to the end of the current or next word. */
3013 void LyXText::DeleteWordForward()
3015 LyXCursor tmpcursor = cursor;
3017 if (!cursor.par->Last())
3020 /* -------> Skip initial non-word stuff. */
3021 while ( cursor.pos < cursor.par->Last()
3022 && (cursor.par->IsSeparator(cursor.pos)
3023 || cursor.par->IsKomma(cursor.pos)) )
3026 SetCursorIntern(cursor.par, cursor.pos);
3027 selection = True; // to avoid deletion
3028 CursorRightOneWord();
3029 sel_cursor = cursor;
3033 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3039 /* -------> Delete from cursor to start of current or prior word. */
3040 void LyXText::DeleteWordBackward()
3042 LyXCursor tmpcursor = cursor;
3043 if (!cursor.par->Last())
3046 selection = true; // to avoid deletion
3047 CursorLeftOneWord();
3048 sel_cursor = cursor;
3056 /* -------> Kill to end of line. */
3057 void LyXText::DeleteLineForward()
3059 LyXCursor tmpcursor = cursor;
3060 if (!cursor.par->Last())
3064 sel_cursor = cursor;
3067 if (selection == false) {
3068 DeleteWordForward();
3076 // Change the case of a word at cursor position. The meaning of action
3078 // 0 change to lowercase
3079 // 1 capitalize word
3080 // 2 change to uppercase
3081 // This function directly manipulates LyXParagraph::text because there
3082 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3083 // that it is correct. I guess part of it should be moved to
3084 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3085 // it does not access outside of the allocated array as the older
3086 // version did. (JMarc)
3087 void LyXText::ChangeWordCase(LyXText::TextCase action)
3089 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3091 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3093 LyXParagraph::size_type tmppos =
3094 cursor.par->PositionInParFromPos(cursor.pos);
3095 while (tmppos < tmppar->size()) {
3096 unsigned char c = tmppar->text[tmppos];
3097 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3099 if (c != LyXParagraph::META_INSET) {
3101 case text_lowercase:
3104 case text_capitalization:
3106 action = text_lowercase;
3108 case text_uppercase:
3114 tmppar->text[tmppos] = c;
3117 CheckParagraph(tmppar, tmppos);
3118 CursorRightOneWord();
3122 void LyXText::Delete()
3124 // this is a very easy implementation
3126 LyXCursor old_cursor = cursor;
3127 int old_cur_par_id = old_cursor.par->id();
3128 int old_cur_par_prev_id = old_cursor.par->previous ?
3129 old_cursor.par->previous->id() : 0;
3131 // just move to the right
3132 CursorRightIntern();
3134 // This check is not very good...
3135 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3136 // and that can very well delete the par or par->previous in
3137 // old_cursor. Will a solution where we compare paragraph id's
3140 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3141 == old_cur_par_prev_id
3142 && cursor.par->id() != old_cur_par_id)
3143 return; // delete-empty-paragraph-mechanism has done it
3145 if (cursor.par->previous == old_cursor.par->previous
3146 && cursor.par != old_cursor.par)
3147 return; // delete-empty-paragraph-mechanism has done it
3149 // if you had success make a backspace
3150 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3151 LyXCursor tmpcursor = cursor;
3152 cursor = old_cursor; // to make sure undo gets the right cursor position
3153 SetUndo(Undo::DELETE,
3154 cursor.par->ParFromPos(cursor.pos)->previous,
3155 cursor.par->ParFromPos(cursor.pos)->next);
3162 void LyXText::Backspace()
3164 LyXParagraph * tmppar;
3165 Row * tmprow, * row;
3169 /* table stuff -- begin */
3170 if (cursor.par->table) {
3174 /* table stuff -- end */
3176 LyXFont rawtmpfont = current_font;
3177 LyXFont realtmpfont = real_current_font;
3179 // Get the font that is used to calculate the baselineskip
3180 int const lastpos = cursor.par->Last();
3181 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3183 if (cursor.pos == 0) {
3184 // we may paste some paragraphs
3186 // is it an empty paragraph?
3189 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3190 && !(cursor.par->Next()
3191 && cursor.par->footnoteflag ==
3192 LyXParagraph::NO_FOOTNOTE
3193 && cursor.par->Next()->footnoteflag ==
3194 LyXParagraph::OPEN_FOOTNOTE)) {
3196 if (cursor.par->previous) {
3197 tmppar = cursor.par->previous->FirstPhysicalPar();
3198 if (cursor.par->GetLayout() == tmppar->GetLayout()
3199 && cursor.par->footnoteflag == tmppar->footnoteflag
3200 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3202 tmppar->line_bottom = cursor.par->line_bottom;
3203 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3204 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3209 // the layout things can change the height of a row !
3210 tmpheight = cursor.row->height;
3211 SetHeightOfRow(cursor.row);
3212 if (cursor.row->height != tmpheight) {
3213 refresh_y = cursor.y - cursor.row->baseline;
3214 refresh_row = cursor.row;
3215 status = LyXText::NEED_MORE_REFRESH;
3220 if (cursor.par->ParFromPos(cursor.pos)->previous){
3221 SetUndo(Undo::DELETE,
3222 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3223 cursor.par->ParFromPos(cursor.pos)->next);
3225 tmppar = cursor.par;
3226 tmprow = cursor.row;
3228 /* Pasting is not allowed, if the paragraphs have different
3229 layout. I think it is a real bug of all other
3230 word processors to allow it. It confuses the user.
3231 Even so with a footnote paragraph and a non-footnote
3232 paragraph. I will not allow pasting in this case,
3233 because the user would be confused if the footnote behaves
3234 different wether it is open or closed.
3236 Correction: Pasting is always allowed with standard-layout
3238 if (cursor.par != tmppar
3239 && (cursor.par->GetLayout() == tmppar->GetLayout()
3240 || !tmppar->GetLayout())
3241 && cursor.par->footnoteflag == tmppar->footnoteflag
3242 /* table stuff -- begin*/
3243 && !cursor.par->table /* no pasting of tables */
3244 /* table stuff -- end*/
3245 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3247 cursor.par->PasteParagraph();
3250 cursor.par->IsSeparator(cursor.pos - 1)))
3251 cursor.par->InsertChar(cursor.pos, ' ');
3256 status = LyXText::NEED_MORE_REFRESH;
3257 refresh_row = cursor.row;
3258 refresh_y = cursor.y - cursor.row->baseline;
3260 // remove the lost paragraph
3261 RemoveParagraph(tmprow);
3264 AppendParagraph(cursor.row);
3265 UpdateCounters(cursor.row);
3267 // the row may have changed, block, hfills etc.
3268 SetCursor(cursor.par, cursor.pos);
3271 /* this is the code for a normal backspace, not pasting
3273 SetUndo(Undo::DELETE,
3274 cursor.par->ParFromPos(cursor.pos)->previous,
3275 cursor.par->ParFromPos(cursor.pos)->next);
3278 // some insets are undeletable here
3279 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3280 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3282 // force complete redo when erasing display insets
3283 // this is a cruel mathod but save..... Matthias
3284 if (cursor.par->GetInset(cursor.pos)->display()){
3285 cursor.par->Erase(cursor.pos);
3292 y = cursor.y - row->baseline;
3293 LyXParagraph::size_type z;
3294 /* remember that a space at the end of a row doesnt count
3295 * when calculating the fill */
3296 if (cursor.pos < RowLast(row) ||
3297 !cursor.par->IsLineSeparator(cursor.pos)) {
3298 row->fill += SingleWidth(cursor.par, cursor.pos);
3301 /* some special code when deleting a newline. This is similar
3302 * to the behavior when pasting paragraphs */
3303 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3304 cursor.par->Erase(cursor.pos);
3305 // refresh the positions
3307 while (tmprow->next && tmprow->next->par == row->par) {
3308 tmprow = tmprow->next;
3311 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3314 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3315 cursor.par->InsertChar(cursor.pos, ' ');
3316 // refresh the positions
3318 while (tmprow->next && tmprow->next->par == row->par) {
3319 tmprow = tmprow->next;
3324 cursor.par->Erase(cursor.pos);
3326 // refresh the positions
3328 while (tmprow->next && tmprow->next->par == row->par) {
3329 tmprow = tmprow->next;
3333 #ifndef FIX_DOUBLE_SPACE
3334 // delete superfluous blanks
3335 if (cursor.pos < cursor.par->Last() - 1 &&
3336 (cursor.par->IsLineSeparator(cursor.pos))) {
3338 if (cursor.pos == BeginningOfMainBody(cursor.par)
3340 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3341 cursor.par->Erase(cursor.pos);
3342 // refresh the positions
3344 while (tmprow->next &&
3345 tmprow->next->par == row->par) {
3346 tmprow = tmprow->next;
3349 if (cursor.pos) // move one character left
3355 // delete newlines at the beginning of paragraphs
3356 while (cursor.par->Last() &&
3357 cursor.par->IsNewline(cursor.pos) &&
3358 cursor.pos == BeginningOfMainBody(cursor.par)) {
3359 cursor.par->Erase(cursor.pos);
3360 // refresh the positions
3362 while (tmprow->next &&
3363 tmprow->next->par == row->par) {
3364 tmprow = tmprow->next;
3370 // is there a break one row above
3371 if (row->previous && row->previous->par == row->par) {
3372 z = NextBreakPoint(row->previous, paperwidth);
3373 if ( z >= row->pos) {
3376 tmprow = row->previous;
3378 // maybe the current row is now empty
3379 if (row->pos >= row->par->Last()) {
3384 BreakAgainOneRow(row);
3385 if (row->next && row->next->par == row->par)
3386 need_break_row = row->next;
3391 // set the dimensions of the row above
3392 y -= tmprow->height;
3393 tmprow->fill = Fill(tmprow, paperwidth);
3394 SetHeightOfRow(tmprow);
3397 refresh_row = tmprow;
3398 status = LyXText::NEED_MORE_REFRESH;
3399 current_font = rawtmpfont;
3400 real_current_font = realtmpfont;
3401 SetCursor(cursor.par, cursor.pos, false);
3402 // check, whether the last character's font has changed.
3403 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3404 if (rawparfont != rawtmpfont)
3405 RedoHeightOfParagraph(cursor);
3410 // break the cursor row again
3411 z = NextBreakPoint(row, paperwidth);
3413 if (z != RowLast(row) ||
3414 (row->next && row->next->par == row->par &&
3415 RowLast(row) == row->par->Last() - 1)){
3417 /* it can happen that a paragraph loses one row
3418 * without a real breakup. This is when a word
3419 * is to long to be broken. Well, I don t care this
3421 if (row->next && row->next->par == row->par &&
3422 RowLast(row) == row->par->Last() - 1)
3423 RemoveRow(row->next);
3427 status = LyXText::NEED_MORE_REFRESH;
3429 BreakAgainOneRow(row);
3430 current_font = rawtmpfont;
3431 real_current_font = realtmpfont;
3432 SetCursor(cursor.par, cursor.pos, false);
3433 // cursor MUST be in row now
3435 if (row->next && row->next->par == row->par)
3436 need_break_row = row->next;
3440 // set the dimensions of the row
3441 row->fill = Fill(row, paperwidth);
3442 int tmpheight = row->height;
3443 SetHeightOfRow(row);
3444 if (tmpheight == row->height)
3445 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3447 status = LyXText::NEED_MORE_REFRESH;
3450 current_font = rawtmpfont;
3451 real_current_font = realtmpfont;
3452 SetCursor(cursor.par, cursor.pos, false);
3456 // restore the current font
3457 // That is what a user expects!
3458 current_font = rawtmpfont;
3459 real_current_font = realtmpfont;
3461 // check, wether the last characters font has changed.
3462 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3463 if (rawparfont != rawtmpfont) {
3464 RedoHeightOfParagraph(cursor);
3466 // now the special right address boxes
3467 if (textclasslist.Style(parameters->textclass,
3468 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3469 RedoDrawingOfParagraph(cursor);
3475 void LyXText::GetVisibleRow(int offset,
3476 Row * row_ptr, long y)
3478 /* returns a printed row */
3479 Painter & pain = owner_->painter();
3481 LyXDirection direction = row_ptr->par->getParDirection();
3482 LyXParagraph::size_type vpos, pos, pos_end;
3484 int y_top, y_bottom;
3485 float fill_separator, fill_hfill, fill_label_hfill;
3486 LyXParagraph * par, * firstpar;
3489 if (row_ptr->height <= 0) {
3490 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3493 PrepareToPrint(row_ptr, x, fill_separator,
3494 fill_hfill, fill_label_hfill);
3496 /* initialize the pixmap */
3498 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3501 /* selection code */
3502 if (sel_start_cursor.row == row_ptr &&
3503 sel_end_cursor.row == row_ptr) {
3504 if (sel_start_cursor.x < sel_end_cursor.x)
3505 pain.fillRectangle(sel_start_cursor.x, offset,
3506 sel_end_cursor.x - sel_start_cursor.x,
3510 pain.fillRectangle(sel_end_cursor.x, offset,
3511 sel_start_cursor.x - sel_end_cursor.x,
3514 } else if (sel_start_cursor.row == row_ptr) {
3515 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3516 pain.fillRectangle(sel_start_cursor.x, offset,
3517 paperwidth - sel_start_cursor.x,
3521 pain.fillRectangle(0, offset,
3525 } else if (sel_end_cursor.row == row_ptr) {
3526 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3527 pain.fillRectangle(0, offset,
3532 pain.fillRectangle(sel_end_cursor.x, offset,
3533 paperwidth - sel_end_cursor.x,
3537 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3538 pain.fillRectangle(0, offset,
3539 paperwidth, row_ptr->height,
3544 if (row_ptr->par->appendix){
3545 pain.line(1, offset,
3546 1, offset + row_ptr->height,
3547 LColor::appendixline);
3548 pain.line(paperwidth - 2, offset,
3549 paperwidth - 2, offset + row_ptr->height,
3550 LColor::appendixline);
3553 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3554 /* draw a marker at the left margin! */
3555 LyXFont font = GetFont(row_ptr->par, 0);
3556 int asc = font.maxAscent();
3557 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3558 int y1 = (offset + row_ptr->baseline);
3559 int y2 = (offset + row_ptr->baseline) - asc;
3560 pain.line(x, y1, x, y2, LColor::minipageline);
3562 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3563 LyXFont font(LyXFont::ALL_SANE);
3564 font.setSize(LyXFont::SIZE_FOOTNOTE);
3565 font.setColor(LColor::footnote);
3567 int box_x = LYX_PAPER_MARGIN;
3568 box_x += font.textWidth(" wide-tab ", 10);
3569 if (row_ptr->previous &&
3570 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3572 switch (row_ptr->par->footnotekind) {
3573 case LyXParagraph::MARGIN:
3576 case LyXParagraph::FIG:
3579 case LyXParagraph::TAB:
3582 case LyXParagraph::WIDE_FIG:
3585 case LyXParagraph::WIDE_TAB:
3588 case LyXParagraph::ALGORITHM:
3591 case LyXParagraph::FOOTNOTE:
3596 pain.fillRectangle(LYX_PAPER_MARGIN,
3598 box_x - LYX_PAPER_MARGIN,
3599 int(font.maxAscent()
3600 + font.maxDescent()),
3601 LColor::footnotebg);
3603 pain.line(LYX_PAPER_MARGIN, offset,
3604 paperwidth - LYX_PAPER_MARGIN, offset,
3605 LColor::footnoteframe);
3607 pain.text(LYX_PAPER_MARGIN,
3608 offset + int(font.maxAscent()) + 1,
3611 pain.line(LYX_PAPER_MARGIN, offset,
3613 offset + int(font.maxAscent()
3614 + font.maxDescent()),
3615 LColor::footnoteframe);
3617 pain.line(LYX_PAPER_MARGIN,
3618 offset + int(font.maxAscent()
3619 + font.maxDescent()) + 1,
3621 offset + int(font.maxAscent()
3622 + font.maxDescent()) + 1,
3623 LColor::footnoteframe);
3627 /* draw the open floats in a red box */
3628 pain.line(box_x, offset,
3629 box_x, offset + row_ptr->height,
3630 LColor::footnoteframe);
3632 pain.line(paperwidth - LYX_PAPER_MARGIN,
3634 paperwidth - LYX_PAPER_MARGIN,
3635 offset + row_ptr->height,
3636 LColor::footnoteframe);
3637 } else if (row_ptr->previous &&
3638 row_ptr->previous->par->footnoteflag
3639 == LyXParagraph::OPEN_FOOTNOTE) {
3640 LyXFont font(LyXFont::ALL_SANE);
3641 font.setSize(LyXFont::SIZE_FOOTNOTE);
3643 int box_x = LYX_PAPER_MARGIN;
3644 box_x += font.textWidth(" wide-tab ", 10);
3646 pain.line(box_x, offset,
3647 paperwidth - LYX_PAPER_MARGIN,
3648 offset, LColor::footnote);
3651 LyXLayout const & layout =
3652 textclasslist.Style(parameters->textclass,
3653 row_ptr->par->GetLayout());
3654 firstpar = row_ptr->par->FirstPhysicalPar();
3657 y_bottom = row_ptr->height;
3659 /* is it a first row? */
3660 if (row_ptr->pos == 0
3661 && row_ptr->par == firstpar) {
3663 /* start of appendix? */
3664 if (row_ptr->par->start_of_appendix){
3665 pain.line(1, offset,
3666 paperwidth - 2, offset,
3667 LColor::appendixline);
3670 /* think about the margins */
3671 if (!row_ptr->previous)
3672 y_top += LYX_PAPER_MARGIN;
3674 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3675 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3677 offset + y_top + 2 * DefaultHeight(),
3678 LColor::pagebreak, Painter::line_onoffdash);
3679 y_top += 3 * DefaultHeight();
3682 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3683 /* draw a vfill top */
3684 pain.line(0, offset + 2 + y_top,
3685 LYX_PAPER_MARGIN, offset + 2 + y_top,
3688 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3690 offset + y_top + 3 * DefaultHeight(),
3693 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3694 LYX_PAPER_MARGIN / 2,
3695 offset + y_top + 3 * DefaultHeight(),
3698 y_top += 3 * DefaultHeight();
3701 /* think about user added space */
3702 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3704 /* think about the parskip */
3705 /* some parskips VERY EASY IMPLEMENTATION */
3706 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3707 if (layout.latextype == LATEX_PARAGRAPH
3708 && firstpar->GetDepth() == 0
3709 && firstpar->Previous())
3710 y_top += parameters->getDefSkip().inPixels(owner_);
3711 else if (firstpar->Previous()
3712 && textclasslist.Style(parameters->textclass,
3713 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3714 && firstpar->Previous()->GetDepth() == 0)
3715 // is it right to use defskip here, too? (AS)
3716 y_top += parameters->getDefSkip().inPixels(owner_);
3719 if (row_ptr->par->line_top) { /* draw a top line */
3720 y_top += GetFont(row_ptr->par, 0).ascent('x');
3722 pain.line(0, offset + y_top,
3723 paperwidth, offset + y_top,
3725 Painter::line_solid,
3726 Painter::line_thick);
3728 y_top += GetFont(row_ptr->par, 0).ascent('x');
3731 /* should we print a label? */
3732 if (layout.labeltype >= LABEL_STATIC
3733 && (layout.labeltype != LABEL_STATIC
3734 || layout.latextype != LATEX_ENVIRONMENT
3735 || row_ptr->par->IsFirstInSequence())) {
3736 font = GetFont(row_ptr->par, -2);
3737 if (!row_ptr->par->GetLabestring().empty()) {
3739 string tmpstring = row_ptr->par->GetLabestring();
3741 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3742 if (parameters->secnumdepth >= 0){
3743 /* this is special code for the chapter layout. This is printed in
3744 * an extra row and has a pagebreak at the top. */
3745 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3746 + int(layout.parsep) * DefaultHeight();
3747 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3748 tmpx = paperwidth - LeftMargin(row_ptr) -
3749 font.stringWidth(tmpstring);
3750 pain.text(int(tmpx),
3751 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3755 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3756 tmpx = x - font.stringWidth(layout.labelsep)
3757 - font.stringWidth(tmpstring);
3759 tmpx = paperwidth - LeftMargin(row_ptr)
3760 + font.stringWidth(layout.labelsep);
3761 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3762 LyXFont font(LyXFont::ALL_SANE);
3763 font.setSize(LyXFont::SIZE_SMALL);
3764 tmpx += font.textWidth("Mwide-figM", 10);
3768 pain.text(int(tmpx),
3769 offset + row_ptr->baseline,
3773 /* the labels at the top of an environment. More or less for bibliography */
3774 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3775 layout.labeltype == LABEL_BIBLIO ||
3776 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3777 if (row_ptr->par->IsFirstInSequence()) {
3778 font = GetFont(row_ptr->par, -2);
3779 if (!row_ptr->par->GetLabestring().empty()) {
3780 string tmpstring = row_ptr->par->GetLabestring();
3782 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3783 + (layout.labelbottomsep * DefaultHeight()));
3786 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3787 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3788 ? x : LeftMargin(row_ptr) )
3789 + paperwidth - RightMargin(row_ptr) ) / 2;
3790 tmpx -= (font.stringWidth(tmpstring)/2);
3791 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3792 tmpx = paperwidth - LeftMargin(row_ptr) -
3793 font.stringWidth(tmpstring);
3794 pain.text(int(tmpx),
3795 offset + row_ptr->baseline
3796 - row_ptr->ascent_of_text
3802 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3803 font = GetFont(row_ptr->par, -1);
3804 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3805 tmpx = x - font.stringWidth(layout.labelsep)
3806 - row_ptr->par->bibkey->width(owner_->painter(), font);
3808 tmpx = paperwidth - LeftMargin(row_ptr)
3809 + font.stringWidth(layout.labelsep);
3810 row_ptr->par->bibkey->draw(owner_->painter(),
3812 offset + row_ptr->baseline,
3817 /* is it a last row? */
3818 par = row_ptr->par->LastPhysicalPar();
3819 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3820 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3822 /* think about the margins */
3824 y_bottom -= LYX_PAPER_MARGIN;
3826 /* draw a bottom pagebreak */
3827 if (firstpar->pagebreak_bottom) {
3828 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3830 offset + y_bottom - 2 * DefaultHeight(),
3831 LColor::pagebreak, Painter::line_onoffdash);
3832 y_bottom -= 3 * DefaultHeight();
3835 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3836 /* draw a vfill bottom */
3837 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3839 offset + y_bottom - 3 * DefaultHeight(),
3841 pain.line(0, offset + y_bottom - 2,
3843 offset + y_bottom - 2,
3845 pain.line(LYX_PAPER_MARGIN / 2,
3846 offset + y_bottom - 3 * DefaultHeight(),
3847 LYX_PAPER_MARGIN / 2,
3848 offset + y_bottom - 2,
3850 y_bottom -= 3* DefaultHeight();
3853 /* think about user added space */
3854 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3856 if (firstpar->line_bottom) {
3857 /* draw a bottom line */
3858 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3859 pain.line(0, offset + y_bottom,
3860 paperwidth, offset + y_bottom,
3861 LColor::topline, Painter::line_solid,
3862 Painter::line_thick);
3863 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3867 /* draw the text in the pixmap */
3868 pos_end = RowLast(row_ptr);
3870 vpos = row_ptr->pos;
3871 /* table stuff -- begin*/
3872 if (row_ptr->par->table) {
3874 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3876 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3878 while (vpos <= pos_end) {
3879 pos = vis2log(vpos);
3880 if (row_ptr->par->IsNewline(pos)) {
3882 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3883 /* draw the table lines, still very simple */
3884 on_off = !row_ptr->par->table->TopLine(cell);
3886 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3887 !row_ptr->par->table->IsContRow(cell))
3888 pain.line(int(x_old),
3889 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3891 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3893 on_off ? Painter::line_onoffdash : Painter::line_solid);
3895 on_off = !row_ptr->par->table->BottomLine(cell);
3896 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3897 row_ptr->par->table->VeryLastRow(cell))
3899 pain.line(int(x_old),
3900 offset + y_bottom - 1,
3902 offset + y_bottom - 1,
3904 on_off ? Painter::line_onoffdash : Painter::line_solid);
3906 on_off = !row_ptr->par->table->LeftLine(cell);
3908 pain.line(int(x_old),
3909 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3911 offset + y_bottom - 1,
3913 on_off ? Painter::line_onoffdash : Painter::line_solid);
3915 on_off = !row_ptr->par->table->RightLine(cell);
3917 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3918 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3919 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3920 offset + y_bottom - 1,
3922 on_off ? Painter::line_onoffdash : Painter::line_solid);
3925 /* take care about the alignment and other spaces */
3927 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3928 if (row_ptr->par->table->IsFirstCell(cell))
3929 --cell; // little hack, sorry
3931 } else if (row_ptr->par->IsHfill(pos)) {
3935 offset + row_ptr->baseline - DefaultHeight() / 2,
3937 offset + row_ptr->baseline,
3942 } else if (row_ptr->par->IsSeparator(pos)) {
3944 x+= SingleWidth(row_ptr->par, pos);
3945 /* -------> Only draw protected spaces when not in
3946 * free-spacing mode. */
3947 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3948 pain.line(int(tmpx),
3949 offset + row_ptr->baseline - 3,
3951 offset + row_ptr->baseline - 1,
3954 pain.line(int(tmpx),
3955 offset + row_ptr->baseline - 1,
3957 offset + row_ptr->baseline - 1,
3960 pain.line(int(x - 2),
3961 offset + row_ptr->baseline - 3,
3963 offset + row_ptr->baseline - 1,
3966 /* what about underbars? */
3967 font = GetFont(row_ptr->par, pos);
3968 if (font.underbar() == LyXFont::ON
3969 && font.latex() != LyXFont::ON) {
3970 pain.line(int(tmpx),
3971 offset + row_ptr->baseline + 2,
3973 offset + row_ptr->baseline + 2);
3978 draw(row_ptr, vpos, offset, x);
3981 /* do not forget the very last cell. This has no NEWLINE so
3982 * ignored by the code above*/
3983 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3984 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3985 on_off = !row_ptr->par->table->TopLine(cell);
3987 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3988 !row_ptr->par->table->IsContRow(cell))
3990 pain.line(int(x_old),
3991 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3993 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3995 on_off ? Painter::line_onoffdash : Painter::line_solid);
3996 on_off = !row_ptr->par->table->BottomLine(cell);
3997 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3998 row_ptr->par->table->VeryLastRow(cell))
4000 pain.line(int(x_old),
4001 offset + y_bottom - 1,
4003 offset + y_bottom - 1,
4005 on_off ? Painter::line_onoffdash : Painter::line_solid);
4007 on_off = !row_ptr->par->table->LeftLine(cell);
4009 pain.line(int(x_old),
4010 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4012 offset + y_bottom - 1,
4014 on_off ? Painter::line_onoffdash : Painter::line_solid);
4016 on_off = !row_ptr->par->table->RightLine(cell);
4018 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4019 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4020 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4021 offset + y_bottom - 1,
4023 on_off ? Painter::line_onoffdash : Painter::line_solid);
4026 /* table stuff -- end*/
4027 LyXParagraph::size_type main_body =
4028 BeginningOfMainBody(row_ptr->par);
4029 if (main_body > 0 &&
4030 (main_body-1 > pos_end ||
4031 !row_ptr->par->IsLineSeparator(main_body-1)))
4034 while (vpos <= pos_end) {
4035 pos = vis2log(vpos);
4036 if (main_body > 0 && pos == main_body-1) {
4037 x += fill_label_hfill
4038 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4039 - SingleWidth(row_ptr->par, main_body-1);
4042 if (row_ptr->par->IsHfill(pos)) {
4045 offset + row_ptr->baseline - DefaultHeight() / 2,
4047 offset + row_ptr->baseline,
4050 if (HfillExpansion(row_ptr, pos)) {
4051 if (pos >= main_body) {
4053 offset + row_ptr->baseline - DefaultHeight() / 4,
4054 int(x + fill_hfill),
4055 offset + row_ptr->baseline - DefaultHeight() / 4,
4057 Painter::line_onoffdash);
4061 offset + row_ptr->baseline - DefaultHeight() / 4,
4062 int(x + fill_label_hfill),
4063 offset + row_ptr->baseline - DefaultHeight() / 4,
4065 Painter::line_onoffdash);
4067 x += fill_label_hfill;
4070 offset + row_ptr->baseline - DefaultHeight() / 2,
4072 offset + row_ptr->baseline,
4077 } else if (row_ptr->par->IsSeparator(pos)) {
4079 x+= SingleWidth(row_ptr->par, pos);
4080 if (pos >= main_body)
4082 /* -------> Only draw protected spaces when not in
4083 * free-spacing mode. */
4084 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4086 pain.line(int(tmpx),
4087 offset + row_ptr->baseline - 3,
4089 offset + row_ptr->baseline - 1,
4092 pain.line(int(tmpx),
4093 offset + row_ptr->baseline - 1,
4095 offset + row_ptr->baseline - 1,
4098 pain.line(int(x - 2),
4099 offset + row_ptr->baseline - 3,
4101 offset + row_ptr->baseline - 1,
4104 /* what about underbars? */
4105 font = GetFont(row_ptr->par, pos);
4106 if (font.underbar() == LyXFont::ON
4107 && font.latex() != LyXFont::ON) {
4108 pain.line(int(tmpx),
4109 offset + row_ptr->baseline + 2,
4111 offset + row_ptr->baseline + 2);
4116 draw(row_ptr, vpos, offset, x);
4122 int LyXText::DefaultHeight() const
4124 LyXFont font(LyXFont::ALL_SANE);
4125 return int(font.maxAscent() + font.maxDescent() * 1.5);
4129 /* returns the column near the specified x-coordinate of the row
4130 * x is set to the real beginning of this column */
4131 int LyXText::GetColumnNearX(Row * row, int & x) const
4134 float fill_separator, fill_hfill, fill_label_hfill;
4136 PrepareToPrint(row, tmpx, fill_separator,
4137 fill_hfill, fill_label_hfill);
4139 LyXDirection direction = row->par->getParDirection();
4140 LyXParagraph::size_type vc = row->pos;
4141 LyXParagraph::size_type last = RowLast(row);
4142 LyXParagraph::size_type c;
4144 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4145 row->par->GetLayout());
4146 /* table stuff -- begin */
4147 if (row->par->table) {
4148 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4149 && row->par->IsNewline(last))
4151 int cell = NumberOfCell(row->par, row->pos);
4154 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4156 && (c = vis2log(vc)) >= 0
4157 && tmpx + (SingleWidth(row->par, c)/2) <= x
4159 if (row->par->IsNewline(c)) {
4160 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4161 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4164 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4169 tmpx += SingleWidth(row->par, c);
4174 /* table stuff -- end*/
4175 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4176 float last_tmpx = tmpx;
4178 if (main_body > 0 &&
4179 (main_body-1 > last ||
4180 !row->par->IsLineSeparator(main_body-1)))
4183 while (vc <= last && tmpx <= x) {
4186 if (main_body > 0 && c == main_body-1) {
4187 tmpx += fill_label_hfill +
4188 GetFont(row->par, -2).stringWidth(layout.labelsep);
4189 if (row->par->IsLineSeparator(main_body-1))
4190 tmpx -= SingleWidth(row->par, main_body-1);
4193 tmpx += SingleWidth(row->par, c);
4194 if (HfillExpansion(row, c)) {
4198 tmpx += fill_label_hfill;
4200 else if (c >= main_body
4201 && row->par->IsSeparator(c)) {
4202 tmpx+= fill_separator;
4207 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4212 /* make sure that a last space in a row doesnt count */
4213 if (row->pos <= last
4214 && !(!row->next || row->next->par != row->par))
4215 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4216 && row->par->IsLineSeparator(vis2log(last)) ) {
4218 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4219 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4221 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4223 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4226 if (row->pos > last) // Row is empty?
4228 else if (vc <= last) {
4230 LyXDirection direction = row->par->getLetterDirection(c);
4231 if (vc > row->pos && row->par->IsLineSeparator(c)
4232 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4234 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4237 c = vis2log(last)+1;
4238 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4242 if (!row->par->table && row->pos <= last && c > last
4243 && row->par->IsNewline(last)) {
4244 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4245 tmpx -= SingleWidth(row->par, last);
4247 tmpx += SingleWidth(row->par, last);
4257 /* turn the selection into a new environment. If there is no selection,
4258 * create an empty environment */
4259 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4261 /* no footnoteenvironment in a footnoteenvironment */
4262 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4263 WriteAlert(_("Impossible operation"),
4264 _("You can't insert a float in a float!"),
4268 /* no marginpars in minipages */
4269 if (kind == LyXParagraph::MARGIN
4270 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4271 WriteAlert(_("Impossible operation"),
4272 _("You can't insert a marginpar in a minipage!"),
4277 /* this doesnt make sense, if there is no selection */
4278 bool dummy_selection = false;
4280 sel_start_cursor = cursor; /* dummy selection */
4281 sel_end_cursor = cursor;
4282 dummy_selection = true;
4285 LyXParagraph *tmppar;
4287 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4288 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4292 /* a test to make sure there is not already a footnote
4293 * in the selection. */
4295 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4297 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4298 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4299 tmppar = tmppar->next;
4301 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4302 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4303 WriteAlert(_("Impossible operation"),
4304 _("Float would include float!"),
4309 /* ok we have a selection. This is always between sel_start_cursor
4310 * and sel_end cursor */
4312 SetUndo(Undo::FINISH,
4313 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4314 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4316 if (sel_end_cursor.pos > 0
4317 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4318 sel_end_cursor.pos--; /* please break before a space at
4320 if (sel_start_cursor.par == sel_end_cursor.par
4321 && sel_start_cursor.pos > sel_end_cursor.pos)
4322 sel_start_cursor.pos--;
4324 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4326 sel_end_cursor.par = sel_end_cursor.par->Next();
4327 sel_end_cursor.pos = 0;
4329 // don't forget to insert a dummy layout paragraph if necessary
4330 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4331 sel_end_cursor.par->BreakParagraphConservative(0);
4332 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4333 sel_end_cursor.par = sel_end_cursor.par->next;
4336 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4338 cursor = sel_end_cursor;
4340 /* please break behind a space, if there is one. The space should
4342 if (sel_start_cursor.pos > 0
4343 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4344 sel_start_cursor.pos--;
4345 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4346 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4349 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4350 tmppar = sel_start_cursor.par->Next();
4352 if (dummy_selection) {
4354 if (kind == LyXParagraph::TAB
4355 || kind == LyXParagraph::FIG
4356 || kind == LyXParagraph::WIDE_TAB
4357 || kind == LyXParagraph::WIDE_FIG
4358 || kind == LyXParagraph::ALGORITHM) {
4359 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4361 if (lay == -1) // layout not found
4362 // use default layout "Standard" (0)
4364 tmppar->SetLayout(lay);
4368 if (sel_start_cursor.pos > 0) {
4369 /* the footnote-environment should begin with a standard layout.
4370 * Imagine you insert a footnote within an enumeration, you
4371 * certainly do not want an enumerated footnote! */
4375 /* this is a exception the user would sometimes expect, I hope */
4376 sel_start_cursor.par->Clear();
4380 while (tmppar != sel_end_cursor.par) {
4381 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4382 tmppar->footnotekind = kind;
4383 tmppar = tmppar->Next();
4386 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4388 SetCursor(sel_start_cursor.par->Next(), 0);
4394 // returns pointer to a specified row
4395 Row * LyXText::GetRow(LyXParagraph * par,
4396 LyXParagraph::size_type pos, long & y) const
4401 if (par == currentrow->par
4402 || par == currentrow->par->Previous()) {
4403 // do not dereference par, it may have been deleted
4404 // already! (Matthias)
4406 // Walk backwards as long as the previous
4407 // rows par is not par
4408 while (currentrow->previous
4409 && currentrow->previous->par != par) {
4410 currentrow = currentrow->previous;
4411 currentrow_y -= currentrow->height;
4413 // Walk backwards as long as the previous
4414 // rows par _is_ par
4415 while (currentrow->previous
4416 && currentrow->previous->par == par) {
4417 currentrow = currentrow->previous;
4418 currentrow_y -= currentrow->height;
4422 tmprow = currentrow;
4424 // find the first row of the specified paragraph
4426 && tmprow->par != par) {
4427 y += tmprow->height;
4428 tmprow = tmprow->next;
4431 if (tmprow->par == par){
4432 // now find the wanted row
4433 while (tmprow->pos < pos
4435 && tmprow->next->par == par
4436 && tmprow->next->pos <= pos) {
4437 y += tmprow->height;
4438 tmprow = tmprow->next;
4440 currentrow = tmprow;
4448 // find the first row of the specified paragraph
4449 while (tmprow->next && tmprow->par != par) {
4450 y += tmprow->height;
4451 tmprow = tmprow->next;
4454 // now find the wanted row
4455 while (tmprow->pos < pos
4457 && tmprow->next->par == par
4458 && tmprow->next->pos <= pos) {
4459 y += tmprow->height;
4460 tmprow = tmprow->next;
4463 currentrow = tmprow;