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 #warning think about this
2396 bool freeSpacingBo =
2397 textclasslist.Style(parameters->textclass,
2398 cursor.row->par->GetLayout()).free_spacing;
2400 if (freeSpacingBo && IsLineSeparatorChar(c)
2401 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1))) {
2402 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2406 /* table stuff -- begin*/
2407 if (cursor.par->table) {
2408 InsertCharInTable(c);
2412 /* table stuff -- end*/
2414 /* First check, if there will be two blanks together or a blank at
2415 the beginning of a paragraph.
2416 I decided to handle blanks like normal characters, the main
2417 difference are the special checks when calculating the row.fill
2418 (blank does not count at the end of a row) and the check here */
2420 // The bug is triggered when we type in a description environment:
2421 // The current_font is not changed when we go from label to main text
2422 // and it should (along with realtmpfont) when we type the space.
2423 #ifdef WITH_WARNINGS
2424 #warning There is a bug here! (Asger)
2427 LyXFont realtmpfont = real_current_font;
2428 LyXFont rawtmpfont = current_font; /* store the current font.
2429 * This is because of the use
2430 * of cursor movements. The moving
2431 * cursor would refresh the
2434 // Get the font that is used to calculate the baselineskip
2435 LyXParagraph::size_type lastpos = cursor.par->Last();
2436 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2438 bool jumped_over_space = false;
2440 if (IsLineSeparatorChar(c)) {
2441 #ifndef FIX_DOUBLE_SPACE
2442 if (cursor.pos < lastpos
2443 && cursor.par->IsLineSeparator(cursor.pos)) {
2444 /* the user inserted a space before a space. So we
2445 * will just make a CursorRight. BUT: The font of this
2446 * space should be set to current font. That is why
2447 * we need to rebreak perhaps. If there is a protected
2448 * blank at the end of a row we have to force
2451 owner_->owner()->getMiniBuffer()
2452 ->Set(_("You cannot type two spaces this way. "
2453 " Please read the Tutorial."));
2455 // How can this ever happen?
2456 if (cursor.pos == RowLast(cursor.row)
2457 && !IsLineSeparatorChar(c))
2458 cursor.row->fill = -1; // force rebreak
2459 cursor.par->Erase(cursor.pos);
2460 jumped_over_space = true;
2462 // Seems to me that this works just as well.
2470 && cursor.par->IsLineSeparator(cursor.pos - 1))
2472 && cursor.par->IsNewline(cursor.pos - 1))
2474 && !(cursor.par->Previous()
2475 && cursor.par->Previous()->footnoteflag
2476 == LyXParagraph::OPEN_FOOTNOTE))) {
2477 if (cursor.pos == 0 )
2478 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2480 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2484 } else if (IsNewlineChar(c)) {
2485 if (cursor.par->FirstPhysicalPar() == cursor.par
2486 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2490 /* No newline at first position
2491 * of a paragraph or behind labels.
2492 * TeX does not allow that. */
2494 if (cursor.pos < cursor.par->Last() &&
2495 cursor.par->IsLineSeparator(cursor.pos))
2496 CursorRightIntern(); // newline always after a blank!
2497 cursor.row->fill = -1; // to force a new break
2500 // the display inset stuff
2501 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2502 && cursor.row->par->GetInset(cursor.row->pos)
2503 && cursor.row->par->GetInset(cursor.row->pos)->display())
2504 cursor.row->fill = -1; // to force a new break
2506 // get the cursor row fist
2507 Row * row = cursor.row;
2508 long y = cursor.y - row->baseline;
2509 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2510 * already insertet the character */
2511 cursor.par->InsertChar(cursor.pos, c);
2512 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2514 if (!jumped_over_space) {
2515 // refresh the positions
2517 while (tmprow->next && tmprow->next->par == row->par) {
2518 tmprow = tmprow->next;
2523 // Is there a break one row above
2524 if ((cursor.par->IsLineSeparator(cursor.pos)
2525 || cursor.par->IsNewline(cursor.pos)
2526 || cursor.row->fill == -1)
2527 && row->previous && row->previous->par == row->par) {
2528 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2530 if ( z >= row->pos) {
2533 // set the dimensions of the row above
2534 row->previous->fill = Fill(row->previous, paperwidth);
2536 SetHeightOfRow(row->previous);
2538 y -= row->previous->height;
2540 refresh_row = row->previous;
2541 status = LyXText::NEED_MORE_REFRESH;
2543 BreakAgainOneRow(row);
2545 current_font = rawtmpfont;
2546 real_current_font = realtmpfont;
2547 SetCursor(cursor.par, cursor.pos + 1, false);
2548 /* cursor MUST be in row now */
2550 if (row->next && row->next->par == row->par)
2551 need_break_row = row->next;
2555 // check, wether the last characters font has changed.
2556 if (cursor.pos && cursor.pos == cursor.par->Last()
2557 && rawparfont != rawtmpfont)
2558 RedoHeightOfParagraph(cursor);
2565 /* recalculate the fill of the row */
2566 if (row->fill >= 0) /* needed because a newline
2567 * will set fill to -1. Otherwise
2568 * we would not get a rebreak! */
2569 row->fill = Fill(row, paperwidth);
2570 if (row->fill < 0 ) {
2573 refresh_x = cursor.x;
2574 refresh_pos = cursor.pos;
2575 status = LyXText::NEED_MORE_REFRESH;
2576 BreakAgainOneRow(row);
2577 /* will the cursor be in another row now? */
2578 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2579 if (row->next && row->next->par == row->par)
2583 BreakAgainOneRow(row);
2585 current_font = rawtmpfont;
2586 real_current_font = realtmpfont;
2587 SetCursor(cursor.par, cursor.pos + 1, false);
2588 if (row->next && row->next->par == row->par)
2589 need_break_row = row->next;
2594 refresh_x = cursor.x;
2596 refresh_pos = cursor.pos;
2598 int tmpheight = row->height;
2599 SetHeightOfRow(row);
2600 if (tmpheight == row->height)
2601 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2603 status = LyXText::NEED_MORE_REFRESH;
2605 current_font = rawtmpfont;
2606 real_current_font = realtmpfont;
2607 SetCursor(cursor.par, cursor.pos + 1, false);
2610 /* check, wether the last characters font has changed. */
2611 if (cursor.pos && cursor.pos == cursor.par->Last()
2612 && rawparfont != rawtmpfont) {
2613 RedoHeightOfParagraph(cursor);
2615 /* now the special right address boxes */
2616 if (textclasslist.Style(parameters->textclass,
2617 cursor.par->GetLayout()).margintype
2618 == MARGIN_RIGHT_ADDRESS_BOX) {
2619 RedoDrawingOfParagraph(cursor);
2627 void LyXText::charInserted()
2629 // Here we could call FinishUndo for every 20 characters inserted.
2630 // This is from my experience how emacs does it.
2631 static unsigned int counter = 0;
2640 void LyXText::PrepareToPrint(Row * row, float & x,
2641 float & fill_separator,
2643 float & fill_label_hfill,
2648 float w = row->fill;
2650 fill_label_hfill = 0;
2652 fill_label_hfill = 0;
2654 LyXDirection direction = row->par->getParDirection();
2656 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2657 x = RightMargin(row);
2658 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2659 LyXFont font(LyXFont::ALL_SANE);
2660 font.setSize(LyXFont::SIZE_SMALL);
2661 x += font.textWidth("Mwide-figM", 10);
2665 x = LeftMargin(row);
2667 /* is there a manual margin with a manual label */
2668 if (textclasslist.Style(parameters->textclass,
2669 row->par->GetLayout()).margintype == MARGIN_MANUAL
2670 && textclasslist.Style(parameters->textclass,
2671 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2673 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2674 * are left aligned*/
2675 if (nlh && !row->par->GetLabelWidthString().empty()) {
2676 fill_label_hfill = LabelFill(row) / nlh;
2680 /* are there any hfills in the row? */
2681 nh = NumberOfHfills(row);
2683 /* table stuff -- begin*/
2684 if (row->par->table) {
2685 w = paperwidth - row->par->table->WidthOfTable()
2686 - x - RightMargin(row);
2687 nh = 0; /* ignore hfills in tables */
2689 /* table stuff -- end*/
2694 /* is it block, flushleft or flushright?
2695 * set x how you need it */
2697 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2698 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2700 align = row->par->FirstPhysicalPar()->align;
2702 /* center displayed insets */
2703 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2704 && row->par->GetInset(row->pos)
2705 && row->par->GetInset(row->pos)->display())
2706 align = LYX_ALIGN_CENTER;
2709 case LYX_ALIGN_BLOCK:
2710 ns = NumberOfSeparators(row);
2711 if (ns && row->next && row->next->par == row->par &&
2712 !(row->next->par->IsNewline(row->next->pos-1))
2713 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2714 && row->next->par->GetInset(row->next->pos)
2715 && row->next->par->GetInset(row->next->pos)->display())
2717 fill_separator = w / ns;
2718 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2721 case LYX_ALIGN_RIGHT:
2724 case LYX_ALIGN_CENTER:
2732 ComputeBidiTables(row);
2733 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2734 LyXParagraph::size_type main_body =
2735 BeginningOfMainBody(row->par);
2736 LyXParagraph::size_type last = RowLast(row);
2738 if (row->pos <= last
2740 && last != vis2log(last)
2741 && row->par->IsLineSeparator(last)) {
2742 if (!(main_body > 0 && main_body-1 == last))
2743 x -= fill_separator+SingleWidth(row->par,last);
2744 } else if (main_body > 0 &&
2745 (main_body-1 > last ||
2746 !row->par->IsLineSeparator(main_body-1))) {
2747 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2748 row->par->GetLayout());
2749 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2750 if (main_body-1 <= last)
2751 x += fill_label_hfill;
2756 /* important for the screen */
2759 /* the cursor set functions have a special mechanism. When they
2760 * realize, that you left an empty paragraph, they will delete it.
2761 * They also delete the corresponding row */
2763 void LyXText::CursorRightOneWord() const
2765 // treat floats, HFills and Insets as words
2766 LyXCursor tmpcursor = cursor;
2768 if (tmpcursor.pos == tmpcursor.par->Last()
2769 && tmpcursor.par->Next())
2771 tmpcursor.par = tmpcursor.par->Next();
2776 // Skip through initial nonword stuff.
2777 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2778 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2780 // printf("Current pos1 %d", tmpcursor.pos) ;
2784 // Advance through word.
2785 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2786 tmpcursor.par->IsWord( tmpcursor.pos ) )
2788 // printf("Current pos2 %d", tmpcursor.pos) ;
2793 SetCursor(tmpcursor.par, tmpcursor.pos);
2797 void LyXText::CursorTab() const
2799 if (cursor.par->table) {
2800 int cell = NumberOfCell(cursor.par, cursor.pos);
2801 while(cursor.par->table->IsContRow(cell)) {
2803 cell = NumberOfCell(cursor.par, cursor.pos);
2805 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2806 TableFeatures(LyXTable::APPEND_ROW);
2808 LyXCursor tmpcursor = cursor;
2809 while (tmpcursor.pos < tmpcursor.par->Last()
2810 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2813 if (tmpcursor.pos == tmpcursor.par->Last()){
2814 if (tmpcursor.par->Next()) {
2815 tmpcursor.par = tmpcursor.par->Next();
2821 SetCursor(tmpcursor.par, tmpcursor.pos);
2822 if (cursor.par->table) {
2823 int cell = NumberOfCell(cursor.par, cursor.pos);
2824 while (cursor.par->table->IsContRow(cell) &&
2825 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2827 while (tmpcursor.pos < tmpcursor.par->Last()
2828 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2831 if (tmpcursor.pos == tmpcursor.par->Last()){
2832 if (tmpcursor.par->Next()) {
2833 tmpcursor.par = tmpcursor.par->Next();
2839 SetCursor(tmpcursor.par, tmpcursor.pos);
2840 cell = NumberOfCell(cursor.par, cursor.pos);
2846 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2847 of prior word, not to end of next prior word. */
2849 void LyXText::CursorLeftOneWord() const
2851 // treat HFills, floats and Insets as words
2852 LyXCursor tmpcursor = cursor;
2853 while (tmpcursor.pos
2854 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2855 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2856 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2857 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2858 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2862 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2863 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2864 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2866 } else if (!tmpcursor.pos) {
2867 if (tmpcursor.par->Previous()){
2868 tmpcursor.par = tmpcursor.par->Previous();
2869 tmpcursor.pos = tmpcursor.par->Last();
2871 } else { // Here, tmpcursor != 0
2872 while (tmpcursor.pos > 0 &&
2873 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2876 SetCursor(tmpcursor.par, tmpcursor.pos);
2879 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2882 void LyXText::SelectWord()
2884 /* Move cursor to the beginning, when not already there. */
2886 && !cursor.par->IsSeparator(cursor.pos-1)
2887 && !cursor.par->IsKomma(cursor.pos-1) )
2888 CursorLeftOneWord();
2890 /* set the sel cursor */
2891 sel_cursor = cursor;
2893 while ( cursor.pos < cursor.par->Last()
2894 && !cursor.par->IsSeparator(cursor.pos)
2895 && !cursor.par->IsKomma(cursor.pos) )
2897 SetCursor( cursor.par, cursor.pos );
2899 /* finally set the selection */
2904 /* -------> Select the word currently under the cursor when:
2905 1: no selection is currently set,
2906 2: the cursor is not at the borders of the word. */
2908 int LyXText::SelectWordWhenUnderCursor()
2910 if ( selection ) return 0;
2911 if ( cursor.pos < cursor.par->Last()
2912 && !cursor.par->IsSeparator(cursor.pos)
2913 && !cursor.par->IsKomma(cursor.pos)
2915 && !cursor.par->IsSeparator(cursor.pos -1)
2916 && !cursor.par->IsKomma(cursor.pos -1) ) {
2924 // This function is only used by the spellchecker for NextWord().
2925 // It doesn't handle LYX_ACCENTs and probably never will.
2926 char * LyXText::SelectNextWord(float & value)
2928 LyXParagraph * tmppar = cursor.par;
2930 // If this is not the very first word, skip rest of
2931 // current word because we are probably in the middle
2932 // of a word if there is text here.
2933 if (cursor.pos || cursor.par->previous) {
2934 while (cursor.pos < cursor.par->Last()
2935 && cursor.par->IsLetter(cursor.pos))
2938 // Now, skip until we have real text (will jump paragraphs)
2939 while ((cursor.par->Last() > cursor.pos
2940 && (!cursor.par->IsLetter(cursor.pos)
2941 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2942 || (cursor.par->Last() == cursor.pos
2943 && cursor.par->Next())){
2944 if (cursor.pos == cursor.par->Last()) {
2945 cursor.par = cursor.par->Next();
2952 // Update the value if we changed paragraphs
2953 if (cursor.par != tmppar){
2954 SetCursor(cursor.par, cursor.pos);
2955 value = float(cursor.y)/float(height);
2958 /* Start the selection from here */
2959 sel_cursor = cursor;
2963 /* and find the end of the word
2964 (optional hyphens are part of a word) */
2965 while (cursor.pos < cursor.par->Last()
2966 && (cursor.par->IsLetter(cursor.pos))
2967 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2968 cursor.par->GetInset(cursor.pos) != 0 &&
2969 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2973 // Finally, we copy the word to a string and return it
2976 if (sel_cursor.pos < cursor.pos) {
2977 str = new char [cursor.pos - sel_cursor.pos + 2];
2978 LyXParagraph::size_type i, j;
2979 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2980 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
2981 str[j++] = cursor.par->GetChar(i);
2989 // This one is also only for the spellchecker
2990 void LyXText::SelectSelectedWord()
2992 /* move cursor to the beginning */
2993 SetCursor(sel_cursor.par, sel_cursor.pos);
2995 /* set the sel cursor */
2996 sel_cursor = cursor;
3000 /* now find the end of the word */
3001 while (cursor.pos < cursor.par->Last()
3002 && (cursor.par->IsLetter(cursor.pos)
3003 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3004 cursor.par->GetInset(cursor.pos) != 0 &&
3005 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3009 SetCursor(cursor.par, cursor.pos);
3011 /* finally set the selection */
3016 /* -------> Delete from cursor up to the end of the current or next word. */
3017 void LyXText::DeleteWordForward()
3019 LyXCursor tmpcursor = cursor;
3021 if (!cursor.par->Last())
3024 /* -------> Skip initial non-word stuff. */
3025 while ( cursor.pos < cursor.par->Last()
3026 && (cursor.par->IsSeparator(cursor.pos)
3027 || cursor.par->IsKomma(cursor.pos)) )
3030 SetCursorIntern(cursor.par, cursor.pos);
3031 selection = True; // to avoid deletion
3032 CursorRightOneWord();
3033 sel_cursor = cursor;
3037 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3043 /* -------> Delete from cursor to start of current or prior word. */
3044 void LyXText::DeleteWordBackward()
3046 LyXCursor tmpcursor = cursor;
3047 if (!cursor.par->Last())
3050 selection = true; // to avoid deletion
3051 CursorLeftOneWord();
3052 sel_cursor = cursor;
3060 /* -------> Kill to end of line. */
3061 void LyXText::DeleteLineForward()
3063 LyXCursor tmpcursor = cursor;
3064 if (!cursor.par->Last())
3068 sel_cursor = cursor;
3071 if (selection == false) {
3072 DeleteWordForward();
3080 // Change the case of a word at cursor position. The meaning of action
3082 // 0 change to lowercase
3083 // 1 capitalize word
3084 // 2 change to uppercase
3085 // This function directly manipulates LyXParagraph::text because there
3086 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3087 // that it is correct. I guess part of it should be moved to
3088 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3089 // it does not access outside of the allocated array as the older
3090 // version did. (JMarc)
3091 void LyXText::ChangeWordCase(LyXText::TextCase action)
3093 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3095 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3097 LyXParagraph::size_type tmppos =
3098 cursor.par->PositionInParFromPos(cursor.pos);
3099 while (tmppos < tmppar->size()) {
3100 unsigned char c = tmppar->text[tmppos];
3101 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3103 if (c != LyXParagraph::META_INSET) {
3105 case text_lowercase:
3108 case text_capitalization:
3110 action = text_lowercase;
3112 case text_uppercase:
3118 tmppar->text[tmppos] = c;
3121 CheckParagraph(tmppar, tmppos);
3122 CursorRightOneWord();
3126 void LyXText::Delete()
3128 // this is a very easy implementation
3130 LyXCursor old_cursor = cursor;
3131 int old_cur_par_id = old_cursor.par->id();
3132 int old_cur_par_prev_id = old_cursor.par->previous ?
3133 old_cursor.par->previous->id() : 0;
3135 // just move to the right
3136 CursorRightIntern();
3138 // This check is not very good...
3139 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3140 // and that can very well delete the par or par->previous in
3141 // old_cursor. Will a solution where we compare paragraph id's
3144 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3145 == old_cur_par_prev_id
3146 && cursor.par->id() != old_cur_par_id)
3147 return; // delete-empty-paragraph-mechanism has done it
3149 if (cursor.par->previous == old_cursor.par->previous
3150 && cursor.par != old_cursor.par)
3151 return; // delete-empty-paragraph-mechanism has done it
3153 // if you had success make a backspace
3154 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3155 LyXCursor tmpcursor = cursor;
3156 cursor = old_cursor; // to make sure undo gets the right cursor position
3157 SetUndo(Undo::DELETE,
3158 cursor.par->ParFromPos(cursor.pos)->previous,
3159 cursor.par->ParFromPos(cursor.pos)->next);
3166 void LyXText::Backspace()
3168 LyXParagraph * tmppar;
3169 Row * tmprow, * row;
3173 /* table stuff -- begin */
3174 if (cursor.par->table) {
3178 /* table stuff -- end */
3180 LyXFont rawtmpfont = current_font;
3181 LyXFont realtmpfont = real_current_font;
3183 // Get the font that is used to calculate the baselineskip
3184 int const lastpos = cursor.par->Last();
3185 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3187 if (cursor.pos == 0) {
3188 // we may paste some paragraphs
3190 // is it an empty paragraph?
3193 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3194 && !(cursor.par->Next()
3195 && cursor.par->footnoteflag ==
3196 LyXParagraph::NO_FOOTNOTE
3197 && cursor.par->Next()->footnoteflag ==
3198 LyXParagraph::OPEN_FOOTNOTE)) {
3200 if (cursor.par->previous) {
3201 tmppar = cursor.par->previous->FirstPhysicalPar();
3202 if (cursor.par->GetLayout() == tmppar->GetLayout()
3203 && cursor.par->footnoteflag == tmppar->footnoteflag
3204 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3206 tmppar->line_bottom = cursor.par->line_bottom;
3207 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3208 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3213 // the layout things can change the height of a row !
3214 tmpheight = cursor.row->height;
3215 SetHeightOfRow(cursor.row);
3216 if (cursor.row->height != tmpheight) {
3217 refresh_y = cursor.y - cursor.row->baseline;
3218 refresh_row = cursor.row;
3219 status = LyXText::NEED_MORE_REFRESH;
3224 if (cursor.par->ParFromPos(cursor.pos)->previous){
3225 SetUndo(Undo::DELETE,
3226 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3227 cursor.par->ParFromPos(cursor.pos)->next);
3229 tmppar = cursor.par;
3230 tmprow = cursor.row;
3232 /* Pasting is not allowed, if the paragraphs have different
3233 layout. I think it is a real bug of all other
3234 word processors to allow it. It confuses the user.
3235 Even so with a footnote paragraph and a non-footnote
3236 paragraph. I will not allow pasting in this case,
3237 because the user would be confused if the footnote behaves
3238 different wether it is open or closed.
3240 Correction: Pasting is always allowed with standard-layout
3242 if (cursor.par != tmppar
3243 && (cursor.par->GetLayout() == tmppar->GetLayout()
3244 || !tmppar->GetLayout())
3245 && cursor.par->footnoteflag == tmppar->footnoteflag
3246 /* table stuff -- begin*/
3247 && !cursor.par->table /* no pasting of tables */
3248 /* table stuff -- end*/
3249 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3251 cursor.par->PasteParagraph();
3254 cursor.par->IsSeparator(cursor.pos - 1)))
3255 cursor.par->InsertChar(cursor.pos, ' ');
3260 status = LyXText::NEED_MORE_REFRESH;
3261 refresh_row = cursor.row;
3262 refresh_y = cursor.y - cursor.row->baseline;
3264 // remove the lost paragraph
3265 RemoveParagraph(tmprow);
3268 AppendParagraph(cursor.row);
3269 UpdateCounters(cursor.row);
3271 // the row may have changed, block, hfills etc.
3272 SetCursor(cursor.par, cursor.pos);
3275 /* this is the code for a normal backspace, not pasting
3277 SetUndo(Undo::DELETE,
3278 cursor.par->ParFromPos(cursor.pos)->previous,
3279 cursor.par->ParFromPos(cursor.pos)->next);
3282 // some insets are undeletable here
3283 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3284 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3286 // force complete redo when erasing display insets
3287 // this is a cruel mathod but save..... Matthias
3288 if (cursor.par->GetInset(cursor.pos)->display()){
3289 cursor.par->Erase(cursor.pos);
3296 y = cursor.y - row->baseline;
3297 LyXParagraph::size_type z;
3298 /* remember that a space at the end of a row doesnt count
3299 * when calculating the fill */
3300 if (cursor.pos < RowLast(row) ||
3301 !cursor.par->IsLineSeparator(cursor.pos)) {
3302 row->fill += SingleWidth(cursor.par, cursor.pos);
3305 /* some special code when deleting a newline. This is similar
3306 * to the behavior when pasting paragraphs */
3307 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3308 cursor.par->Erase(cursor.pos);
3309 // refresh the positions
3311 while (tmprow->next && tmprow->next->par == row->par) {
3312 tmprow = tmprow->next;
3315 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3318 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3319 cursor.par->InsertChar(cursor.pos, ' ');
3320 // refresh the positions
3322 while (tmprow->next && tmprow->next->par == row->par) {
3323 tmprow = tmprow->next;
3328 cursor.par->Erase(cursor.pos);
3330 // refresh the positions
3332 while (tmprow->next && tmprow->next->par == row->par) {
3333 tmprow = tmprow->next;
3337 #ifndef FIX_DOUBLE_SPACE
3338 // delete superfluous blanks
3339 if (cursor.pos < cursor.par->Last() - 1 &&
3340 (cursor.par->IsLineSeparator(cursor.pos))) {
3342 if (cursor.pos == BeginningOfMainBody(cursor.par)
3344 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3345 cursor.par->Erase(cursor.pos);
3346 // refresh the positions
3348 while (tmprow->next &&
3349 tmprow->next->par == row->par) {
3350 tmprow = tmprow->next;
3353 if (cursor.pos) // move one character left
3359 // delete newlines at the beginning of paragraphs
3360 while (cursor.par->Last() &&
3361 cursor.par->IsNewline(cursor.pos) &&
3362 cursor.pos == BeginningOfMainBody(cursor.par)) {
3363 cursor.par->Erase(cursor.pos);
3364 // refresh the positions
3366 while (tmprow->next &&
3367 tmprow->next->par == row->par) {
3368 tmprow = tmprow->next;
3374 // is there a break one row above
3375 if (row->previous && row->previous->par == row->par) {
3376 z = NextBreakPoint(row->previous, paperwidth);
3377 if ( z >= row->pos) {
3380 tmprow = row->previous;
3382 // maybe the current row is now empty
3383 if (row->pos >= row->par->Last()) {
3388 BreakAgainOneRow(row);
3389 if (row->next && row->next->par == row->par)
3390 need_break_row = row->next;
3395 // set the dimensions of the row above
3396 y -= tmprow->height;
3397 tmprow->fill = Fill(tmprow, paperwidth);
3398 SetHeightOfRow(tmprow);
3401 refresh_row = tmprow;
3402 status = LyXText::NEED_MORE_REFRESH;
3403 current_font = rawtmpfont;
3404 real_current_font = realtmpfont;
3405 SetCursor(cursor.par, cursor.pos, false);
3406 // check, whether the last character's font has changed.
3407 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3408 if (rawparfont != rawtmpfont)
3409 RedoHeightOfParagraph(cursor);
3414 // break the cursor row again
3415 z = NextBreakPoint(row, paperwidth);
3417 if (z != RowLast(row) ||
3418 (row->next && row->next->par == row->par &&
3419 RowLast(row) == row->par->Last() - 1)){
3421 /* it can happen that a paragraph loses one row
3422 * without a real breakup. This is when a word
3423 * is to long to be broken. Well, I don t care this
3425 if (row->next && row->next->par == row->par &&
3426 RowLast(row) == row->par->Last() - 1)
3427 RemoveRow(row->next);
3431 status = LyXText::NEED_MORE_REFRESH;
3433 BreakAgainOneRow(row);
3434 current_font = rawtmpfont;
3435 real_current_font = realtmpfont;
3436 SetCursor(cursor.par, cursor.pos, false);
3437 // cursor MUST be in row now
3439 if (row->next && row->next->par == row->par)
3440 need_break_row = row->next;
3444 // set the dimensions of the row
3445 row->fill = Fill(row, paperwidth);
3446 int tmpheight = row->height;
3447 SetHeightOfRow(row);
3448 if (tmpheight == row->height)
3449 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3451 status = LyXText::NEED_MORE_REFRESH;
3454 current_font = rawtmpfont;
3455 real_current_font = realtmpfont;
3456 SetCursor(cursor.par, cursor.pos, false);
3460 // restore the current font
3461 // That is what a user expects!
3462 current_font = rawtmpfont;
3463 real_current_font = realtmpfont;
3465 // check, wether the last characters font has changed.
3466 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3467 if (rawparfont != rawtmpfont) {
3468 RedoHeightOfParagraph(cursor);
3470 // now the special right address boxes
3471 if (textclasslist.Style(parameters->textclass,
3472 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3473 RedoDrawingOfParagraph(cursor);
3479 void LyXText::GetVisibleRow(int offset,
3480 Row * row_ptr, long y)
3482 /* returns a printed row */
3483 Painter & pain = owner_->painter();
3485 LyXDirection direction = row_ptr->par->getParDirection();
3486 LyXParagraph::size_type vpos, pos, pos_end;
3488 int y_top, y_bottom;
3489 float fill_separator, fill_hfill, fill_label_hfill;
3490 LyXParagraph * par, * firstpar;
3493 if (row_ptr->height <= 0) {
3494 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3497 PrepareToPrint(row_ptr, x, fill_separator,
3498 fill_hfill, fill_label_hfill);
3500 /* initialize the pixmap */
3502 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3505 /* selection code */
3506 if (sel_start_cursor.row == row_ptr &&
3507 sel_end_cursor.row == row_ptr) {
3508 if (sel_start_cursor.x < sel_end_cursor.x)
3509 pain.fillRectangle(sel_start_cursor.x, offset,
3510 sel_end_cursor.x - sel_start_cursor.x,
3514 pain.fillRectangle(sel_end_cursor.x, offset,
3515 sel_start_cursor.x - sel_end_cursor.x,
3518 } else if (sel_start_cursor.row == row_ptr) {
3519 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3520 pain.fillRectangle(sel_start_cursor.x, offset,
3521 paperwidth - sel_start_cursor.x,
3525 pain.fillRectangle(0, offset,
3529 } else if (sel_end_cursor.row == row_ptr) {
3530 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3531 pain.fillRectangle(0, offset,
3536 pain.fillRectangle(sel_end_cursor.x, offset,
3537 paperwidth - sel_end_cursor.x,
3541 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3542 pain.fillRectangle(0, offset,
3543 paperwidth, row_ptr->height,
3548 if (row_ptr->par->appendix){
3549 pain.line(1, offset,
3550 1, offset + row_ptr->height,
3551 LColor::appendixline);
3552 pain.line(paperwidth - 2, offset,
3553 paperwidth - 2, offset + row_ptr->height,
3554 LColor::appendixline);
3557 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3558 /* draw a marker at the left margin! */
3559 LyXFont font = GetFont(row_ptr->par, 0);
3560 int asc = font.maxAscent();
3561 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3562 int y1 = (offset + row_ptr->baseline);
3563 int y2 = (offset + row_ptr->baseline) - asc;
3564 pain.line(x, y1, x, y2, LColor::minipageline);
3566 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3567 LyXFont font(LyXFont::ALL_SANE);
3568 font.setSize(LyXFont::SIZE_FOOTNOTE);
3569 font.setColor(LColor::footnote);
3571 int box_x = LYX_PAPER_MARGIN;
3572 box_x += font.textWidth(" wide-tab ", 10);
3573 if (row_ptr->previous &&
3574 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3576 switch (row_ptr->par->footnotekind) {
3577 case LyXParagraph::MARGIN:
3580 case LyXParagraph::FIG:
3583 case LyXParagraph::TAB:
3586 case LyXParagraph::WIDE_FIG:
3589 case LyXParagraph::WIDE_TAB:
3592 case LyXParagraph::ALGORITHM:
3595 case LyXParagraph::FOOTNOTE:
3600 pain.fillRectangle(LYX_PAPER_MARGIN,
3602 box_x - LYX_PAPER_MARGIN,
3603 int(font.maxAscent()
3604 + font.maxDescent()),
3605 LColor::footnotebg);
3607 pain.line(LYX_PAPER_MARGIN, offset,
3608 paperwidth - LYX_PAPER_MARGIN, offset,
3609 LColor::footnoteframe);
3611 pain.text(LYX_PAPER_MARGIN,
3612 offset + int(font.maxAscent()) + 1,
3615 pain.line(LYX_PAPER_MARGIN, offset,
3617 offset + int(font.maxAscent()
3618 + font.maxDescent()),
3619 LColor::footnoteframe);
3621 pain.line(LYX_PAPER_MARGIN,
3622 offset + int(font.maxAscent()
3623 + font.maxDescent()) + 1,
3625 offset + int(font.maxAscent()
3626 + font.maxDescent()) + 1,
3627 LColor::footnoteframe);
3631 /* draw the open floats in a red box */
3632 pain.line(box_x, offset,
3633 box_x, offset + row_ptr->height,
3634 LColor::footnoteframe);
3636 pain.line(paperwidth - LYX_PAPER_MARGIN,
3638 paperwidth - LYX_PAPER_MARGIN,
3639 offset + row_ptr->height,
3640 LColor::footnoteframe);
3641 } else if (row_ptr->previous &&
3642 row_ptr->previous->par->footnoteflag
3643 == LyXParagraph::OPEN_FOOTNOTE) {
3644 LyXFont font(LyXFont::ALL_SANE);
3645 font.setSize(LyXFont::SIZE_FOOTNOTE);
3647 int box_x = LYX_PAPER_MARGIN;
3648 box_x += font.textWidth(" wide-tab ", 10);
3650 pain.line(box_x, offset,
3651 paperwidth - LYX_PAPER_MARGIN,
3652 offset, LColor::footnote);
3655 LyXLayout const & layout =
3656 textclasslist.Style(parameters->textclass,
3657 row_ptr->par->GetLayout());
3658 firstpar = row_ptr->par->FirstPhysicalPar();
3661 y_bottom = row_ptr->height;
3663 /* is it a first row? */
3664 if (row_ptr->pos == 0
3665 && row_ptr->par == firstpar) {
3667 /* start of appendix? */
3668 if (row_ptr->par->start_of_appendix){
3669 pain.line(1, offset,
3670 paperwidth - 2, offset,
3671 LColor::appendixline);
3674 /* think about the margins */
3675 if (!row_ptr->previous)
3676 y_top += LYX_PAPER_MARGIN;
3678 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3679 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3681 offset + y_top + 2 * DefaultHeight(),
3682 LColor::pagebreak, Painter::line_onoffdash);
3683 y_top += 3 * DefaultHeight();
3686 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3687 /* draw a vfill top */
3688 pain.line(0, offset + 2 + y_top,
3689 LYX_PAPER_MARGIN, offset + 2 + y_top,
3692 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3694 offset + y_top + 3 * DefaultHeight(),
3697 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3698 LYX_PAPER_MARGIN / 2,
3699 offset + y_top + 3 * DefaultHeight(),
3702 y_top += 3 * DefaultHeight();
3705 /* think about user added space */
3706 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3708 /* think about the parskip */
3709 /* some parskips VERY EASY IMPLEMENTATION */
3710 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3711 if (layout.latextype == LATEX_PARAGRAPH
3712 && firstpar->GetDepth() == 0
3713 && firstpar->Previous())
3714 y_top += parameters->getDefSkip().inPixels(owner_);
3715 else if (firstpar->Previous()
3716 && textclasslist.Style(parameters->textclass,
3717 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3718 && firstpar->Previous()->GetDepth() == 0)
3719 // is it right to use defskip here, too? (AS)
3720 y_top += parameters->getDefSkip().inPixels(owner_);
3723 if (row_ptr->par->line_top) { /* draw a top line */
3724 y_top += GetFont(row_ptr->par, 0).ascent('x');
3726 pain.line(0, offset + y_top,
3727 paperwidth, offset + y_top,
3729 Painter::line_solid,
3730 Painter::line_thick);
3732 y_top += GetFont(row_ptr->par, 0).ascent('x');
3735 /* should we print a label? */
3736 if (layout.labeltype >= LABEL_STATIC
3737 && (layout.labeltype != LABEL_STATIC
3738 || layout.latextype != LATEX_ENVIRONMENT
3739 || row_ptr->par->IsFirstInSequence())) {
3740 font = GetFont(row_ptr->par, -2);
3741 if (!row_ptr->par->GetLabestring().empty()) {
3743 string tmpstring = row_ptr->par->GetLabestring();
3745 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3746 if (parameters->secnumdepth >= 0){
3747 /* this is special code for the chapter layout. This is printed in
3748 * an extra row and has a pagebreak at the top. */
3749 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3750 + int(layout.parsep) * DefaultHeight();
3751 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3752 tmpx = paperwidth - LeftMargin(row_ptr) -
3753 font.stringWidth(tmpstring);
3754 pain.text(int(tmpx),
3755 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3759 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3760 tmpx = x - font.stringWidth(layout.labelsep)
3761 - font.stringWidth(tmpstring);
3763 tmpx = paperwidth - LeftMargin(row_ptr)
3764 + font.stringWidth(layout.labelsep);
3765 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3766 LyXFont font(LyXFont::ALL_SANE);
3767 font.setSize(LyXFont::SIZE_SMALL);
3768 tmpx += font.textWidth("Mwide-figM", 10);
3772 pain.text(int(tmpx),
3773 offset + row_ptr->baseline,
3777 /* the labels at the top of an environment. More or less for bibliography */
3778 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3779 layout.labeltype == LABEL_BIBLIO ||
3780 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3781 if (row_ptr->par->IsFirstInSequence()) {
3782 font = GetFont(row_ptr->par, -2);
3783 if (!row_ptr->par->GetLabestring().empty()) {
3784 string tmpstring = row_ptr->par->GetLabestring();
3786 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3787 + (layout.labelbottomsep * DefaultHeight()));
3790 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3791 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3792 ? x : LeftMargin(row_ptr) )
3793 + paperwidth - RightMargin(row_ptr) ) / 2;
3794 tmpx -= (font.stringWidth(tmpstring)/2);
3795 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3796 tmpx = paperwidth - LeftMargin(row_ptr) -
3797 font.stringWidth(tmpstring);
3798 pain.text(int(tmpx),
3799 offset + row_ptr->baseline
3800 - row_ptr->ascent_of_text
3806 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3807 font = GetFont(row_ptr->par, -1);
3808 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3809 tmpx = x - font.stringWidth(layout.labelsep)
3810 - row_ptr->par->bibkey->width(owner_->painter(), font);
3812 tmpx = paperwidth - LeftMargin(row_ptr)
3813 + font.stringWidth(layout.labelsep);
3814 row_ptr->par->bibkey->draw(owner_->painter(),
3816 offset + row_ptr->baseline,
3821 /* is it a last row? */
3822 par = row_ptr->par->LastPhysicalPar();
3823 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3824 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3826 /* think about the margins */
3828 y_bottom -= LYX_PAPER_MARGIN;
3830 /* draw a bottom pagebreak */
3831 if (firstpar->pagebreak_bottom) {
3832 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3834 offset + y_bottom - 2 * DefaultHeight(),
3835 LColor::pagebreak, Painter::line_onoffdash);
3836 y_bottom -= 3 * DefaultHeight();
3839 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3840 /* draw a vfill bottom */
3841 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3843 offset + y_bottom - 3 * DefaultHeight(),
3845 pain.line(0, offset + y_bottom - 2,
3847 offset + y_bottom - 2,
3849 pain.line(LYX_PAPER_MARGIN / 2,
3850 offset + y_bottom - 3 * DefaultHeight(),
3851 LYX_PAPER_MARGIN / 2,
3852 offset + y_bottom - 2,
3854 y_bottom -= 3* DefaultHeight();
3857 /* think about user added space */
3858 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3860 if (firstpar->line_bottom) {
3861 /* draw a bottom line */
3862 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3863 pain.line(0, offset + y_bottom,
3864 paperwidth, offset + y_bottom,
3865 LColor::topline, Painter::line_solid,
3866 Painter::line_thick);
3867 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3871 /* draw the text in the pixmap */
3872 pos_end = RowLast(row_ptr);
3874 vpos = row_ptr->pos;
3875 /* table stuff -- begin*/
3876 if (row_ptr->par->table) {
3878 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3880 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3882 while (vpos <= pos_end) {
3883 pos = vis2log(vpos);
3884 if (row_ptr->par->IsNewline(pos)) {
3886 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3887 /* draw the table lines, still very simple */
3888 on_off = !row_ptr->par->table->TopLine(cell);
3890 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3891 !row_ptr->par->table->IsContRow(cell))
3892 pain.line(int(x_old),
3893 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3895 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3897 on_off ? Painter::line_onoffdash : Painter::line_solid);
3899 on_off = !row_ptr->par->table->BottomLine(cell);
3900 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3901 row_ptr->par->table->VeryLastRow(cell))
3903 pain.line(int(x_old),
3904 offset + y_bottom - 1,
3906 offset + y_bottom - 1,
3908 on_off ? Painter::line_onoffdash : Painter::line_solid);
3910 on_off = !row_ptr->par->table->LeftLine(cell);
3912 pain.line(int(x_old),
3913 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3915 offset + y_bottom - 1,
3917 on_off ? Painter::line_onoffdash : Painter::line_solid);
3919 on_off = !row_ptr->par->table->RightLine(cell);
3921 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3922 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3923 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3924 offset + y_bottom - 1,
3926 on_off ? Painter::line_onoffdash : Painter::line_solid);
3929 /* take care about the alignment and other spaces */
3931 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3932 if (row_ptr->par->table->IsFirstCell(cell))
3933 --cell; // little hack, sorry
3935 } else if (row_ptr->par->IsHfill(pos)) {
3939 offset + row_ptr->baseline - DefaultHeight() / 2,
3941 offset + row_ptr->baseline,
3946 } else if (row_ptr->par->IsSeparator(pos)) {
3948 x+= SingleWidth(row_ptr->par, pos);
3949 #warning Think about this.
3951 /* -------> Only draw protected spaces when
3952 * not in free-spacing mode. */
3953 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3954 pain.line(int(tmpx),
3955 offset + row_ptr->baseline - 3,
3957 offset + row_ptr->baseline - 1,
3960 pain.line(int(tmpx),
3961 offset + row_ptr->baseline - 1,
3963 offset + row_ptr->baseline - 1,
3966 pain.line(int(x - 2),
3967 offset + row_ptr->baseline - 3,
3969 offset + row_ptr->baseline - 1,
3972 /* what about underbars? */
3973 font = GetFont(row_ptr->par, pos);
3974 if (font.underbar() == LyXFont::ON
3975 && font.latex() != LyXFont::ON) {
3976 pain.line(int(tmpx),
3977 offset + row_ptr->baseline + 2,
3979 offset + row_ptr->baseline + 2);
3985 draw(row_ptr, vpos, offset, x);
3988 /* do not forget the very last cell. This has no NEWLINE so
3989 * ignored by the code above*/
3990 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3991 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3992 on_off = !row_ptr->par->table->TopLine(cell);
3994 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3995 !row_ptr->par->table->IsContRow(cell))
3997 pain.line(int(x_old),
3998 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4000 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4002 on_off ? Painter::line_onoffdash : Painter::line_solid);
4003 on_off = !row_ptr->par->table->BottomLine(cell);
4004 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4005 row_ptr->par->table->VeryLastRow(cell))
4007 pain.line(int(x_old),
4008 offset + y_bottom - 1,
4010 offset + y_bottom - 1,
4012 on_off ? Painter::line_onoffdash : Painter::line_solid);
4014 on_off = !row_ptr->par->table->LeftLine(cell);
4016 pain.line(int(x_old),
4017 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4019 offset + y_bottom - 1,
4021 on_off ? Painter::line_onoffdash : Painter::line_solid);
4023 on_off = !row_ptr->par->table->RightLine(cell);
4025 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4026 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4027 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4028 offset + y_bottom - 1,
4030 on_off ? Painter::line_onoffdash : Painter::line_solid);
4033 /* table stuff -- end*/
4034 LyXParagraph::size_type main_body =
4035 BeginningOfMainBody(row_ptr->par);
4036 if (main_body > 0 &&
4037 (main_body-1 > pos_end ||
4038 !row_ptr->par->IsLineSeparator(main_body-1)))
4041 while (vpos <= pos_end) {
4042 pos = vis2log(vpos);
4043 if (main_body > 0 && pos == main_body-1) {
4044 x += fill_label_hfill
4045 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4046 - SingleWidth(row_ptr->par, main_body-1);
4049 if (row_ptr->par->IsHfill(pos)) {
4052 offset + row_ptr->baseline - DefaultHeight() / 2,
4054 offset + row_ptr->baseline,
4057 if (HfillExpansion(row_ptr, pos)) {
4058 if (pos >= main_body) {
4060 offset + row_ptr->baseline - DefaultHeight() / 4,
4061 int(x + fill_hfill),
4062 offset + row_ptr->baseline - DefaultHeight() / 4,
4064 Painter::line_onoffdash);
4068 offset + row_ptr->baseline - DefaultHeight() / 4,
4069 int(x + fill_label_hfill),
4070 offset + row_ptr->baseline - DefaultHeight() / 4,
4072 Painter::line_onoffdash);
4074 x += fill_label_hfill;
4077 offset + row_ptr->baseline - DefaultHeight() / 2,
4079 offset + row_ptr->baseline,
4084 } else if (row_ptr->par->IsSeparator(pos)) {
4086 x+= SingleWidth(row_ptr->par, pos);
4087 if (pos >= main_body)
4089 #warning Think about this
4091 /* -------> Only draw protected spaces when
4092 * not in free-spacing mode. */
4093 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4095 pain.line(int(tmpx),
4096 offset + row_ptr->baseline - 3,
4098 offset + row_ptr->baseline - 1,
4101 pain.line(int(tmpx),
4102 offset + row_ptr->baseline - 1,
4104 offset + row_ptr->baseline - 1,
4107 pain.line(int(x - 2),
4108 offset + row_ptr->baseline - 3,
4110 offset + row_ptr->baseline - 1,
4113 /* what about underbars? */
4114 font = GetFont(row_ptr->par, pos);
4115 if (font.underbar() == LyXFont::ON
4116 && font.latex() != LyXFont::ON) {
4117 pain.line(int(tmpx),
4118 offset + row_ptr->baseline + 2,
4120 offset + row_ptr->baseline + 2);
4126 draw(row_ptr, vpos, offset, x);
4132 int LyXText::DefaultHeight() const
4134 LyXFont font(LyXFont::ALL_SANE);
4135 return int(font.maxAscent() + font.maxDescent() * 1.5);
4139 /* returns the column near the specified x-coordinate of the row
4140 * x is set to the real beginning of this column */
4141 int LyXText::GetColumnNearX(Row * row, int & x) const
4144 float fill_separator, fill_hfill, fill_label_hfill;
4146 PrepareToPrint(row, tmpx, fill_separator,
4147 fill_hfill, fill_label_hfill);
4149 LyXDirection direction = row->par->getParDirection();
4150 LyXParagraph::size_type vc = row->pos;
4151 LyXParagraph::size_type last = RowLast(row);
4152 LyXParagraph::size_type c;
4154 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4155 row->par->GetLayout());
4156 /* table stuff -- begin */
4157 if (row->par->table) {
4158 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4159 && row->par->IsNewline(last))
4161 int cell = NumberOfCell(row->par, row->pos);
4164 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4166 && (c = vis2log(vc)) >= 0
4167 && tmpx + (SingleWidth(row->par, c)/2) <= x
4169 if (row->par->IsNewline(c)) {
4170 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4171 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4174 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4179 tmpx += SingleWidth(row->par, c);
4184 /* table stuff -- end*/
4185 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4186 float last_tmpx = tmpx;
4188 if (main_body > 0 &&
4189 (main_body-1 > last ||
4190 !row->par->IsLineSeparator(main_body-1)))
4193 while (vc <= last && tmpx <= x) {
4196 if (main_body > 0 && c == main_body-1) {
4197 tmpx += fill_label_hfill +
4198 GetFont(row->par, -2).stringWidth(layout.labelsep);
4199 if (row->par->IsLineSeparator(main_body-1))
4200 tmpx -= SingleWidth(row->par, main_body-1);
4203 tmpx += SingleWidth(row->par, c);
4204 if (HfillExpansion(row, c)) {
4208 tmpx += fill_label_hfill;
4210 else if (c >= main_body
4211 && row->par->IsSeparator(c)) {
4212 tmpx+= fill_separator;
4217 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4222 /* make sure that a last space in a row doesnt count */
4223 if (row->pos <= last
4224 && !(!row->next || row->next->par != row->par))
4225 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4226 && row->par->IsLineSeparator(vis2log(last)) ) {
4228 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4229 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4231 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4233 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4236 if (row->pos > last) // Row is empty?
4238 else if (vc <= last) {
4240 LyXDirection direction = row->par->getLetterDirection(c);
4241 if (vc > row->pos && row->par->IsLineSeparator(c)
4242 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4244 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4247 c = vis2log(last)+1;
4248 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4252 if (!row->par->table && row->pos <= last && c > last
4253 && row->par->IsNewline(last)) {
4254 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4255 tmpx -= SingleWidth(row->par, last);
4257 tmpx += SingleWidth(row->par, last);
4267 /* turn the selection into a new environment. If there is no selection,
4268 * create an empty environment */
4269 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4271 /* no footnoteenvironment in a footnoteenvironment */
4272 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4273 WriteAlert(_("Impossible operation"),
4274 _("You can't insert a float in a float!"),
4278 /* no marginpars in minipages */
4279 if (kind == LyXParagraph::MARGIN
4280 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4281 WriteAlert(_("Impossible operation"),
4282 _("You can't insert a marginpar in a minipage!"),
4287 /* this doesnt make sense, if there is no selection */
4288 bool dummy_selection = false;
4290 sel_start_cursor = cursor; /* dummy selection */
4291 sel_end_cursor = cursor;
4292 dummy_selection = true;
4295 LyXParagraph *tmppar;
4297 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4298 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4302 /* a test to make sure there is not already a footnote
4303 * in the selection. */
4305 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4307 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4308 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4309 tmppar = tmppar->next;
4311 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4312 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4313 WriteAlert(_("Impossible operation"),
4314 _("Float would include float!"),
4319 /* ok we have a selection. This is always between sel_start_cursor
4320 * and sel_end cursor */
4322 SetUndo(Undo::FINISH,
4323 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4324 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4326 if (sel_end_cursor.pos > 0
4327 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4328 sel_end_cursor.pos--; /* please break before a space at
4330 if (sel_start_cursor.par == sel_end_cursor.par
4331 && sel_start_cursor.pos > sel_end_cursor.pos)
4332 sel_start_cursor.pos--;
4334 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4336 sel_end_cursor.par = sel_end_cursor.par->Next();
4337 sel_end_cursor.pos = 0;
4339 // don't forget to insert a dummy layout paragraph if necessary
4340 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4341 sel_end_cursor.par->BreakParagraphConservative(0);
4342 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4343 sel_end_cursor.par = sel_end_cursor.par->next;
4346 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4348 cursor = sel_end_cursor;
4350 /* please break behind a space, if there is one. The space should
4352 if (sel_start_cursor.pos > 0
4353 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4354 sel_start_cursor.pos--;
4355 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4356 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4359 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4360 tmppar = sel_start_cursor.par->Next();
4362 if (dummy_selection) {
4364 if (kind == LyXParagraph::TAB
4365 || kind == LyXParagraph::FIG
4366 || kind == LyXParagraph::WIDE_TAB
4367 || kind == LyXParagraph::WIDE_FIG
4368 || kind == LyXParagraph::ALGORITHM) {
4369 pair<bool, LyXTextClass::size_type> lres =
4370 textclasslist.NumberOfLayout(parameters->textclass,
4372 LyXTextClass::size_type lay;
4378 lay = 0; // use default layout "Standard" (0)
4380 tmppar->SetLayout(lay);
4384 if (sel_start_cursor.pos > 0) {
4385 /* the footnote-environment should begin with a standard layout.
4386 * Imagine you insert a footnote within an enumeration, you
4387 * certainly do not want an enumerated footnote! */
4391 /* this is a exception the user would sometimes expect, I hope */
4392 sel_start_cursor.par->Clear();
4396 while (tmppar != sel_end_cursor.par) {
4397 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4398 tmppar->footnotekind = kind;
4399 tmppar = tmppar->Next();
4402 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4404 SetCursor(sel_start_cursor.par->Next(), 0);
4410 // returns pointer to a specified row
4411 Row * LyXText::GetRow(LyXParagraph * par,
4412 LyXParagraph::size_type pos, long & y) const
4417 if (par == currentrow->par
4418 || par == currentrow->par->Previous()) {
4419 // do not dereference par, it may have been deleted
4420 // already! (Matthias)
4422 // Walk backwards as long as the previous
4423 // rows par is not par
4424 while (currentrow->previous
4425 && currentrow->previous->par != par) {
4426 currentrow = currentrow->previous;
4427 currentrow_y -= currentrow->height;
4429 // Walk backwards as long as the previous
4430 // rows par _is_ par
4431 while (currentrow->previous
4432 && currentrow->previous->par == par) {
4433 currentrow = currentrow->previous;
4434 currentrow_y -= currentrow->height;
4438 tmprow = currentrow;
4440 // find the first row of the specified paragraph
4442 && tmprow->par != par) {
4443 y += tmprow->height;
4444 tmprow = tmprow->next;
4447 if (tmprow->par == par){
4448 // now find the wanted row
4449 while (tmprow->pos < pos
4451 && tmprow->next->par == par
4452 && tmprow->next->pos <= pos) {
4453 y += tmprow->height;
4454 tmprow = tmprow->next;
4456 currentrow = tmprow;
4464 // find the first row of the specified paragraph
4465 while (tmprow->next && tmprow->par != par) {
4466 y += tmprow->height;
4467 tmprow = tmprow->next;
4470 // now find the wanted row
4471 while (tmprow->pos < pos
4473 && tmprow->next->par == par
4474 && tmprow->next->pos <= pos) {
4475 y += tmprow->height;
4476 tmprow = tmprow->next;
4479 currentrow = tmprow;