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. */
2395 #warning think about this
2397 bool freeSpacingBo =
2398 textclasslist.Style(parameters->textclass,
2399 cursor.row->par->GetLayout()).free_spacing;
2401 // Thinkee: (not done)
2402 // It seems that we should insert a InsetSpecialChar, do we really
2403 // have to? I don't know the free spacing politics too deeply.
2404 // Some others should have a look at this.
2405 if (freeSpacingBo && IsLineSeparatorChar(c)
2406 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1))) {
2407 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2411 /* table stuff -- begin*/
2412 if (cursor.par->table) {
2413 InsertCharInTable(c);
2417 /* table stuff -- end*/
2419 /* First check, if there will be two blanks together or a blank at
2420 the beginning of a paragraph.
2421 I decided to handle blanks like normal characters, the main
2422 difference are the special checks when calculating the row.fill
2423 (blank does not count at the end of a row) and the check here */
2425 // The bug is triggered when we type in a description environment:
2426 // The current_font is not changed when we go from label to main text
2427 // and it should (along with realtmpfont) when we type the space.
2428 #ifdef WITH_WARNINGS
2429 #warning There is a bug here! (Asger)
2432 LyXFont realtmpfont = real_current_font;
2433 LyXFont rawtmpfont = current_font; /* store the current font.
2434 * This is because of the use
2435 * of cursor movements. The moving
2436 * cursor would refresh the
2439 // Get the font that is used to calculate the baselineskip
2440 LyXParagraph::size_type lastpos = cursor.par->Last();
2441 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2443 bool jumped_over_space = false;
2445 if (IsLineSeparatorChar(c)) {
2446 #ifndef FIX_DOUBLE_SPACE
2447 if (cursor.pos < lastpos
2448 && cursor.par->IsLineSeparator(cursor.pos)) {
2449 /* the user inserted a space before a space. So we
2450 * will just make a CursorRight. BUT: The font of this
2451 * space should be set to current font. That is why
2452 * we need to rebreak perhaps. If there is a protected
2453 * blank at the end of a row we have to force
2456 owner_->owner()->getMiniBuffer()
2457 ->Set(_("You cannot type two spaces this way. "
2458 " Please read the Tutorial."));
2460 // How can this ever happen?
2461 if (cursor.pos == RowLast(cursor.row)
2462 && !IsLineSeparatorChar(c))
2463 cursor.row->fill = -1; // force rebreak
2464 cursor.par->Erase(cursor.pos);
2465 jumped_over_space = true;
2467 // Seems to me that this works just as well.
2475 && cursor.par->IsLineSeparator(cursor.pos - 1))
2477 && cursor.par->IsNewline(cursor.pos - 1))
2479 && !(cursor.par->Previous()
2480 && cursor.par->Previous()->footnoteflag
2481 == LyXParagraph::OPEN_FOOTNOTE))) {
2482 if (cursor.pos == 0 )
2483 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2485 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2489 } else if (IsNewlineChar(c)) {
2490 if (cursor.par->FirstPhysicalPar() == cursor.par
2491 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2495 /* No newline at first position
2496 * of a paragraph or behind labels.
2497 * TeX does not allow that. */
2499 if (cursor.pos < cursor.par->Last() &&
2500 cursor.par->IsLineSeparator(cursor.pos))
2501 CursorRightIntern(); // newline always after a blank!
2502 cursor.row->fill = -1; // to force a new break
2505 // the display inset stuff
2506 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2507 && cursor.row->par->GetInset(cursor.row->pos)
2508 && cursor.row->par->GetInset(cursor.row->pos)->display())
2509 cursor.row->fill = -1; // to force a new break
2511 // get the cursor row fist
2512 Row * row = cursor.row;
2513 long y = cursor.y - row->baseline;
2514 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2515 * already insertet the character */
2516 cursor.par->InsertChar(cursor.pos, c);
2517 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2519 if (!jumped_over_space) {
2520 // refresh the positions
2522 while (tmprow->next && tmprow->next->par == row->par) {
2523 tmprow = tmprow->next;
2528 // Is there a break one row above
2529 if ((cursor.par->IsLineSeparator(cursor.pos)
2530 || cursor.par->IsNewline(cursor.pos)
2531 || cursor.row->fill == -1)
2532 && row->previous && row->previous->par == row->par) {
2533 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2535 if ( z >= row->pos) {
2538 // set the dimensions of the row above
2539 row->previous->fill = Fill(row->previous, paperwidth);
2541 SetHeightOfRow(row->previous);
2543 y -= row->previous->height;
2545 refresh_row = row->previous;
2546 status = LyXText::NEED_MORE_REFRESH;
2548 BreakAgainOneRow(row);
2550 current_font = rawtmpfont;
2551 real_current_font = realtmpfont;
2552 SetCursor(cursor.par, cursor.pos + 1, false);
2553 /* cursor MUST be in row now */
2555 if (row->next && row->next->par == row->par)
2556 need_break_row = row->next;
2560 // check, wether the last characters font has changed.
2561 if (cursor.pos && cursor.pos == cursor.par->Last()
2562 && rawparfont != rawtmpfont)
2563 RedoHeightOfParagraph(cursor);
2570 /* recalculate the fill of the row */
2571 if (row->fill >= 0) /* needed because a newline
2572 * will set fill to -1. Otherwise
2573 * we would not get a rebreak! */
2574 row->fill = Fill(row, paperwidth);
2575 if (row->fill < 0 ) {
2578 refresh_x = cursor.x;
2579 refresh_pos = cursor.pos;
2580 status = LyXText::NEED_MORE_REFRESH;
2581 BreakAgainOneRow(row);
2582 /* will the cursor be in another row now? */
2583 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2584 if (row->next && row->next->par == row->par)
2588 BreakAgainOneRow(row);
2590 current_font = rawtmpfont;
2591 real_current_font = realtmpfont;
2592 SetCursor(cursor.par, cursor.pos + 1, false);
2593 if (row->next && row->next->par == row->par)
2594 need_break_row = row->next;
2599 refresh_x = cursor.x;
2601 refresh_pos = cursor.pos;
2603 int tmpheight = row->height;
2604 SetHeightOfRow(row);
2605 if (tmpheight == row->height)
2606 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2608 status = LyXText::NEED_MORE_REFRESH;
2610 current_font = rawtmpfont;
2611 real_current_font = realtmpfont;
2612 SetCursor(cursor.par, cursor.pos + 1, false);
2615 /* check, wether the last characters font has changed. */
2616 if (cursor.pos && cursor.pos == cursor.par->Last()
2617 && rawparfont != rawtmpfont) {
2618 RedoHeightOfParagraph(cursor);
2620 /* now the special right address boxes */
2621 if (textclasslist.Style(parameters->textclass,
2622 cursor.par->GetLayout()).margintype
2623 == MARGIN_RIGHT_ADDRESS_BOX) {
2624 RedoDrawingOfParagraph(cursor);
2632 void LyXText::charInserted()
2634 // Here we could call FinishUndo for every 20 characters inserted.
2635 // This is from my experience how emacs does it.
2636 static unsigned int counter = 0;
2645 void LyXText::PrepareToPrint(Row * row, float & x,
2646 float & fill_separator,
2648 float & fill_label_hfill,
2653 float w = row->fill;
2655 fill_label_hfill = 0;
2657 fill_label_hfill = 0;
2659 LyXDirection direction = row->par->getParDirection();
2661 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2662 x = RightMargin(row);
2663 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2664 LyXFont font(LyXFont::ALL_SANE);
2665 font.setSize(LyXFont::SIZE_SMALL);
2666 x += font.textWidth("Mwide-figM", 10);
2670 x = LeftMargin(row);
2672 /* is there a manual margin with a manual label */
2673 if (textclasslist.Style(parameters->textclass,
2674 row->par->GetLayout()).margintype == MARGIN_MANUAL
2675 && textclasslist.Style(parameters->textclass,
2676 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2678 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2679 * are left aligned*/
2680 if (nlh && !row->par->GetLabelWidthString().empty()) {
2681 fill_label_hfill = LabelFill(row) / nlh;
2685 /* are there any hfills in the row? */
2686 nh = NumberOfHfills(row);
2688 /* table stuff -- begin*/
2689 if (row->par->table) {
2690 w = paperwidth - row->par->table->WidthOfTable()
2691 - x - RightMargin(row);
2692 nh = 0; /* ignore hfills in tables */
2694 /* table stuff -- end*/
2699 /* is it block, flushleft or flushright?
2700 * set x how you need it */
2702 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2703 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2705 align = row->par->FirstPhysicalPar()->align;
2707 /* center displayed insets */
2708 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2709 && row->par->GetInset(row->pos)
2710 && row->par->GetInset(row->pos)->display())
2711 align = LYX_ALIGN_CENTER;
2714 case LYX_ALIGN_BLOCK:
2715 ns = NumberOfSeparators(row);
2716 if (ns && row->next && row->next->par == row->par &&
2717 !(row->next->par->IsNewline(row->next->pos-1))
2718 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2719 && row->next->par->GetInset(row->next->pos)
2720 && row->next->par->GetInset(row->next->pos)->display())
2722 fill_separator = w / ns;
2723 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2726 case LYX_ALIGN_RIGHT:
2729 case LYX_ALIGN_CENTER:
2737 ComputeBidiTables(row);
2738 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2739 LyXParagraph::size_type main_body =
2740 BeginningOfMainBody(row->par);
2741 LyXParagraph::size_type last = RowLast(row);
2743 if (row->pos <= last
2745 && last != vis2log(last)
2746 && row->par->IsLineSeparator(last)) {
2747 if (!(main_body > 0 && main_body-1 == last))
2748 x -= fill_separator+SingleWidth(row->par,last);
2749 } else if (main_body > 0 &&
2750 (main_body-1 > last ||
2751 !row->par->IsLineSeparator(main_body-1))) {
2752 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2753 row->par->GetLayout());
2754 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2755 if (main_body-1 <= last)
2756 x += fill_label_hfill;
2761 /* important for the screen */
2764 /* the cursor set functions have a special mechanism. When they
2765 * realize, that you left an empty paragraph, they will delete it.
2766 * They also delete the corresponding row */
2768 void LyXText::CursorRightOneWord() const
2770 // treat floats, HFills and Insets as words
2771 LyXCursor tmpcursor = cursor;
2773 if (tmpcursor.pos == tmpcursor.par->Last()
2774 && tmpcursor.par->Next())
2776 tmpcursor.par = tmpcursor.par->Next();
2781 // Skip through initial nonword stuff.
2782 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2783 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2785 // printf("Current pos1 %d", tmpcursor.pos) ;
2789 // Advance through word.
2790 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2791 tmpcursor.par->IsWord( tmpcursor.pos ) )
2793 // printf("Current pos2 %d", tmpcursor.pos) ;
2798 SetCursor(tmpcursor.par, tmpcursor.pos);
2802 void LyXText::CursorTab() const
2804 if (cursor.par->table) {
2805 int cell = NumberOfCell(cursor.par, cursor.pos);
2806 while(cursor.par->table->IsContRow(cell)) {
2808 cell = NumberOfCell(cursor.par, cursor.pos);
2810 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2811 TableFeatures(LyXTable::APPEND_ROW);
2813 LyXCursor tmpcursor = cursor;
2814 while (tmpcursor.pos < tmpcursor.par->Last()
2815 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2818 if (tmpcursor.pos == tmpcursor.par->Last()){
2819 if (tmpcursor.par->Next()) {
2820 tmpcursor.par = tmpcursor.par->Next();
2826 SetCursor(tmpcursor.par, tmpcursor.pos);
2827 if (cursor.par->table) {
2828 int cell = NumberOfCell(cursor.par, cursor.pos);
2829 while (cursor.par->table->IsContRow(cell) &&
2830 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2832 while (tmpcursor.pos < tmpcursor.par->Last()
2833 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2836 if (tmpcursor.pos == tmpcursor.par->Last()){
2837 if (tmpcursor.par->Next()) {
2838 tmpcursor.par = tmpcursor.par->Next();
2844 SetCursor(tmpcursor.par, tmpcursor.pos);
2845 cell = NumberOfCell(cursor.par, cursor.pos);
2851 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2852 of prior word, not to end of next prior word. */
2854 void LyXText::CursorLeftOneWord() const
2856 // treat HFills, floats and Insets as words
2857 LyXCursor tmpcursor = cursor;
2858 while (tmpcursor.pos
2859 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2860 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2861 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2862 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2863 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2867 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2868 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2869 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2871 } else if (!tmpcursor.pos) {
2872 if (tmpcursor.par->Previous()){
2873 tmpcursor.par = tmpcursor.par->Previous();
2874 tmpcursor.pos = tmpcursor.par->Last();
2876 } else { // Here, tmpcursor != 0
2877 while (tmpcursor.pos > 0 &&
2878 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2881 SetCursor(tmpcursor.par, tmpcursor.pos);
2884 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2887 void LyXText::SelectWord()
2889 /* Move cursor to the beginning, when not already there. */
2891 && !cursor.par->IsSeparator(cursor.pos-1)
2892 && !cursor.par->IsKomma(cursor.pos-1) )
2893 CursorLeftOneWord();
2895 /* set the sel cursor */
2896 sel_cursor = cursor;
2898 while ( cursor.pos < cursor.par->Last()
2899 && !cursor.par->IsSeparator(cursor.pos)
2900 && !cursor.par->IsKomma(cursor.pos) )
2902 SetCursor( cursor.par, cursor.pos );
2904 /* finally set the selection */
2909 /* -------> Select the word currently under the cursor when:
2910 1: no selection is currently set,
2911 2: the cursor is not at the borders of the word. */
2913 int LyXText::SelectWordWhenUnderCursor()
2915 if ( selection ) return 0;
2916 if ( cursor.pos < cursor.par->Last()
2917 && !cursor.par->IsSeparator(cursor.pos)
2918 && !cursor.par->IsKomma(cursor.pos)
2920 && !cursor.par->IsSeparator(cursor.pos -1)
2921 && !cursor.par->IsKomma(cursor.pos -1) ) {
2929 // This function is only used by the spellchecker for NextWord().
2930 // It doesn't handle LYX_ACCENTs and probably never will.
2931 char * LyXText::SelectNextWord(float & value)
2933 LyXParagraph * tmppar = cursor.par;
2935 // If this is not the very first word, skip rest of
2936 // current word because we are probably in the middle
2937 // of a word if there is text here.
2938 if (cursor.pos || cursor.par->previous) {
2939 while (cursor.pos < cursor.par->Last()
2940 && cursor.par->IsLetter(cursor.pos))
2943 // Now, skip until we have real text (will jump paragraphs)
2944 while ((cursor.par->Last() > cursor.pos
2945 && (!cursor.par->IsLetter(cursor.pos)
2946 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2947 || (cursor.par->Last() == cursor.pos
2948 && cursor.par->Next())){
2949 if (cursor.pos == cursor.par->Last()) {
2950 cursor.par = cursor.par->Next();
2957 // Update the value if we changed paragraphs
2958 if (cursor.par != tmppar){
2959 SetCursor(cursor.par, cursor.pos);
2960 value = float(cursor.y)/float(height);
2963 /* Start the selection from here */
2964 sel_cursor = cursor;
2966 #ifdef USE_OSTREAM_ONLY
2968 ostringstream latex;
2975 /* and find the end of the word
2976 (optional hyphens are part of a word) */
2977 while (cursor.pos < cursor.par->Last()
2978 && (cursor.par->IsLetter(cursor.pos))
2979 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
2980 && cursor.par->GetInset(cursor.pos) != 0
2981 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0
2982 #ifdef USE_OSTREAM_ONLY
2984 && latex.str() == "\\-"
2986 && string(latex.str(), 3) == "\\-" // this is not nice at all
2994 #ifdef USE_OSTREAM_ONLY
2995 #ifndef HAVE_SSTREAM
2996 delete [] latex.str();
2999 // Finally, we copy the word to a string and return it
3002 if (sel_cursor.pos < cursor.pos) {
3003 str = new char [cursor.pos - sel_cursor.pos + 2];
3004 LyXParagraph::size_type i, j;
3005 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3006 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3007 str[j++] = cursor.par->GetChar(i);
3015 // This one is also only for the spellchecker
3016 void LyXText::SelectSelectedWord()
3018 /* move cursor to the beginning */
3019 SetCursor(sel_cursor.par, sel_cursor.pos);
3021 /* set the sel cursor */
3022 sel_cursor = cursor;
3024 #ifdef USE_OSTREAM_ONLY
3026 ostringstream latex;
3034 /* now find the end of the word */
3035 while (cursor.pos < cursor.par->Last()
3036 && (cursor.par->IsLetter(cursor.pos)
3037 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3038 && cursor.par->GetInset(cursor.pos) != 0
3039 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0
3040 #ifdef USE_OSTREAM_ONLY
3042 && latex.str() == "\\-"
3044 && string(latex.str(), 3) == "\\-"
3052 #ifdef USE_OSTREAM_ONLY
3053 #ifndef HAVE_SSTREAM
3054 delete [] latex.str();
3057 SetCursor(cursor.par, cursor.pos);
3059 /* finally set the selection */
3064 /* -------> Delete from cursor up to the end of the current or next word. */
3065 void LyXText::DeleteWordForward()
3067 LyXCursor tmpcursor = cursor;
3069 if (!cursor.par->Last())
3072 /* -------> Skip initial non-word stuff. */
3073 while ( cursor.pos < cursor.par->Last()
3074 && (cursor.par->IsSeparator(cursor.pos)
3075 || cursor.par->IsKomma(cursor.pos)) )
3078 SetCursorIntern(cursor.par, cursor.pos);
3079 selection = True; // to avoid deletion
3080 CursorRightOneWord();
3081 sel_cursor = cursor;
3085 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3091 /* -------> Delete from cursor to start of current or prior word. */
3092 void LyXText::DeleteWordBackward()
3094 LyXCursor tmpcursor = cursor;
3095 if (!cursor.par->Last())
3098 selection = true; // to avoid deletion
3099 CursorLeftOneWord();
3100 sel_cursor = cursor;
3108 /* -------> Kill to end of line. */
3109 void LyXText::DeleteLineForward()
3111 LyXCursor tmpcursor = cursor;
3112 if (!cursor.par->Last())
3116 sel_cursor = cursor;
3119 if (selection == false) {
3120 DeleteWordForward();
3128 // Change the case of a word at cursor position. The meaning of action
3130 // 0 change to lowercase
3131 // 1 capitalize word
3132 // 2 change to uppercase
3133 // This function directly manipulates LyXParagraph::text because there
3134 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3135 // that it is correct. I guess part of it should be moved to
3136 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3137 // it does not access outside of the allocated array as the older
3138 // version did. (JMarc)
3139 void LyXText::ChangeWordCase(LyXText::TextCase action)
3141 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3143 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3145 LyXParagraph::size_type tmppos =
3146 cursor.par->PositionInParFromPos(cursor.pos);
3147 while (tmppos < tmppar->size()) {
3148 unsigned char c = tmppar->text[tmppos];
3149 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3151 if (c != LyXParagraph::META_INSET) {
3153 case text_lowercase:
3156 case text_capitalization:
3158 action = text_lowercase;
3160 case text_uppercase:
3166 tmppar->text[tmppos] = c;
3169 CheckParagraph(tmppar, tmppos);
3170 CursorRightOneWord();
3174 void LyXText::Delete()
3176 // this is a very easy implementation
3178 LyXCursor old_cursor = cursor;
3179 int old_cur_par_id = old_cursor.par->id();
3180 int old_cur_par_prev_id = old_cursor.par->previous ?
3181 old_cursor.par->previous->id() : 0;
3183 // just move to the right
3184 CursorRightIntern();
3186 // This check is not very good...
3187 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3188 // and that can very well delete the par or par->previous in
3189 // old_cursor. Will a solution where we compare paragraph id's
3192 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3193 == old_cur_par_prev_id
3194 && cursor.par->id() != old_cur_par_id)
3195 return; // delete-empty-paragraph-mechanism has done it
3197 if (cursor.par->previous == old_cursor.par->previous
3198 && cursor.par != old_cursor.par)
3199 return; // delete-empty-paragraph-mechanism has done it
3201 // if you had success make a backspace
3202 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3203 LyXCursor tmpcursor = cursor;
3204 cursor = old_cursor; // to make sure undo gets the right cursor position
3205 SetUndo(Undo::DELETE,
3206 cursor.par->ParFromPos(cursor.pos)->previous,
3207 cursor.par->ParFromPos(cursor.pos)->next);
3214 void LyXText::Backspace()
3216 LyXParagraph * tmppar;
3217 Row * tmprow, * row;
3221 /* table stuff -- begin */
3222 if (cursor.par->table) {
3226 /* table stuff -- end */
3228 LyXFont rawtmpfont = current_font;
3229 LyXFont realtmpfont = real_current_font;
3231 // Get the font that is used to calculate the baselineskip
3232 int const lastpos = cursor.par->Last();
3233 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3235 if (cursor.pos == 0) {
3236 // we may paste some paragraphs
3238 // is it an empty paragraph?
3241 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3242 && !(cursor.par->Next()
3243 && cursor.par->footnoteflag ==
3244 LyXParagraph::NO_FOOTNOTE
3245 && cursor.par->Next()->footnoteflag ==
3246 LyXParagraph::OPEN_FOOTNOTE)) {
3248 if (cursor.par->previous) {
3249 tmppar = cursor.par->previous->FirstPhysicalPar();
3250 if (cursor.par->GetLayout() == tmppar->GetLayout()
3251 && cursor.par->footnoteflag == tmppar->footnoteflag
3252 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3254 tmppar->line_bottom = cursor.par->line_bottom;
3255 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3256 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3261 // the layout things can change the height of a row !
3262 tmpheight = cursor.row->height;
3263 SetHeightOfRow(cursor.row);
3264 if (cursor.row->height != tmpheight) {
3265 refresh_y = cursor.y - cursor.row->baseline;
3266 refresh_row = cursor.row;
3267 status = LyXText::NEED_MORE_REFRESH;
3272 if (cursor.par->ParFromPos(cursor.pos)->previous){
3273 SetUndo(Undo::DELETE,
3274 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3275 cursor.par->ParFromPos(cursor.pos)->next);
3277 tmppar = cursor.par;
3278 tmprow = cursor.row;
3280 /* Pasting is not allowed, if the paragraphs have different
3281 layout. I think it is a real bug of all other
3282 word processors to allow it. It confuses the user.
3283 Even so with a footnote paragraph and a non-footnote
3284 paragraph. I will not allow pasting in this case,
3285 because the user would be confused if the footnote behaves
3286 different wether it is open or closed.
3288 Correction: Pasting is always allowed with standard-layout
3290 if (cursor.par != tmppar
3291 && (cursor.par->GetLayout() == tmppar->GetLayout()
3292 || !tmppar->GetLayout())
3293 && cursor.par->footnoteflag == tmppar->footnoteflag
3294 /* table stuff -- begin*/
3295 && !cursor.par->table /* no pasting of tables */
3296 /* table stuff -- end*/
3297 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3299 cursor.par->PasteParagraph();
3302 cursor.par->IsSeparator(cursor.pos - 1)))
3303 cursor.par->InsertChar(cursor.pos, ' ');
3308 status = LyXText::NEED_MORE_REFRESH;
3309 refresh_row = cursor.row;
3310 refresh_y = cursor.y - cursor.row->baseline;
3312 // remove the lost paragraph
3313 RemoveParagraph(tmprow);
3316 AppendParagraph(cursor.row);
3317 UpdateCounters(cursor.row);
3319 // the row may have changed, block, hfills etc.
3320 SetCursor(cursor.par, cursor.pos);
3323 /* this is the code for a normal backspace, not pasting
3325 SetUndo(Undo::DELETE,
3326 cursor.par->ParFromPos(cursor.pos)->previous,
3327 cursor.par->ParFromPos(cursor.pos)->next);
3330 // some insets are undeletable here
3331 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3332 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3334 // force complete redo when erasing display insets
3335 // this is a cruel mathod but save..... Matthias
3336 if (cursor.par->GetInset(cursor.pos)->display()){
3337 cursor.par->Erase(cursor.pos);
3344 y = cursor.y - row->baseline;
3345 LyXParagraph::size_type z;
3346 /* remember that a space at the end of a row doesnt count
3347 * when calculating the fill */
3348 if (cursor.pos < RowLast(row) ||
3349 !cursor.par->IsLineSeparator(cursor.pos)) {
3350 row->fill += SingleWidth(cursor.par, cursor.pos);
3353 /* some special code when deleting a newline. This is similar
3354 * to the behavior when pasting paragraphs */
3355 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3356 cursor.par->Erase(cursor.pos);
3357 // refresh the positions
3359 while (tmprow->next && tmprow->next->par == row->par) {
3360 tmprow = tmprow->next;
3363 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3366 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3367 cursor.par->InsertChar(cursor.pos, ' ');
3368 // refresh the positions
3370 while (tmprow->next && tmprow->next->par == row->par) {
3371 tmprow = tmprow->next;
3376 cursor.par->Erase(cursor.pos);
3378 // refresh the positions
3380 while (tmprow->next && tmprow->next->par == row->par) {
3381 tmprow = tmprow->next;
3385 #ifndef FIX_DOUBLE_SPACE
3386 // delete superfluous blanks
3387 if (cursor.pos < cursor.par->Last() - 1 &&
3388 (cursor.par->IsLineSeparator(cursor.pos))) {
3390 if (cursor.pos == BeginningOfMainBody(cursor.par)
3392 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3393 cursor.par->Erase(cursor.pos);
3394 // refresh the positions
3396 while (tmprow->next &&
3397 tmprow->next->par == row->par) {
3398 tmprow = tmprow->next;
3401 if (cursor.pos) // move one character left
3407 // delete newlines at the beginning of paragraphs
3408 while (cursor.par->Last() &&
3409 cursor.par->IsNewline(cursor.pos) &&
3410 cursor.pos == BeginningOfMainBody(cursor.par)) {
3411 cursor.par->Erase(cursor.pos);
3412 // refresh the positions
3414 while (tmprow->next &&
3415 tmprow->next->par == row->par) {
3416 tmprow = tmprow->next;
3422 // is there a break one row above
3423 if (row->previous && row->previous->par == row->par) {
3424 z = NextBreakPoint(row->previous, paperwidth);
3425 if ( z >= row->pos) {
3428 tmprow = row->previous;
3430 // maybe the current row is now empty
3431 if (row->pos >= row->par->Last()) {
3436 BreakAgainOneRow(row);
3437 if (row->next && row->next->par == row->par)
3438 need_break_row = row->next;
3443 // set the dimensions of the row above
3444 y -= tmprow->height;
3445 tmprow->fill = Fill(tmprow, paperwidth);
3446 SetHeightOfRow(tmprow);
3449 refresh_row = tmprow;
3450 status = LyXText::NEED_MORE_REFRESH;
3451 current_font = rawtmpfont;
3452 real_current_font = realtmpfont;
3453 SetCursor(cursor.par, cursor.pos, false);
3454 // check, whether the last character's font has changed.
3455 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3456 if (rawparfont != rawtmpfont)
3457 RedoHeightOfParagraph(cursor);
3462 // break the cursor row again
3463 z = NextBreakPoint(row, paperwidth);
3465 if (z != RowLast(row) ||
3466 (row->next && row->next->par == row->par &&
3467 RowLast(row) == row->par->Last() - 1)){
3469 /* it can happen that a paragraph loses one row
3470 * without a real breakup. This is when a word
3471 * is to long to be broken. Well, I don t care this
3473 if (row->next && row->next->par == row->par &&
3474 RowLast(row) == row->par->Last() - 1)
3475 RemoveRow(row->next);
3479 status = LyXText::NEED_MORE_REFRESH;
3481 BreakAgainOneRow(row);
3482 current_font = rawtmpfont;
3483 real_current_font = realtmpfont;
3484 SetCursor(cursor.par, cursor.pos, false);
3485 // cursor MUST be in row now
3487 if (row->next && row->next->par == row->par)
3488 need_break_row = row->next;
3492 // set the dimensions of the row
3493 row->fill = Fill(row, paperwidth);
3494 int tmpheight = row->height;
3495 SetHeightOfRow(row);
3496 if (tmpheight == row->height)
3497 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3499 status = LyXText::NEED_MORE_REFRESH;
3502 current_font = rawtmpfont;
3503 real_current_font = realtmpfont;
3504 SetCursor(cursor.par, cursor.pos, false);
3508 // restore the current font
3509 // That is what a user expects!
3510 current_font = rawtmpfont;
3511 real_current_font = realtmpfont;
3513 // check, wether the last characters font has changed.
3514 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3515 if (rawparfont != rawtmpfont) {
3516 RedoHeightOfParagraph(cursor);
3518 // now the special right address boxes
3519 if (textclasslist.Style(parameters->textclass,
3520 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3521 RedoDrawingOfParagraph(cursor);
3527 void LyXText::GetVisibleRow(int offset,
3528 Row * row_ptr, long y)
3530 /* returns a printed row */
3531 Painter & pain = owner_->painter();
3533 LyXDirection direction = row_ptr->par->getParDirection();
3534 LyXParagraph::size_type vpos, pos, pos_end;
3536 int y_top, y_bottom;
3537 float fill_separator, fill_hfill, fill_label_hfill;
3538 LyXParagraph * par, * firstpar;
3541 if (row_ptr->height <= 0) {
3542 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3545 PrepareToPrint(row_ptr, x, fill_separator,
3546 fill_hfill, fill_label_hfill);
3548 /* initialize the pixmap */
3550 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3553 /* selection code */
3554 if (sel_start_cursor.row == row_ptr &&
3555 sel_end_cursor.row == row_ptr) {
3556 if (sel_start_cursor.x < sel_end_cursor.x)
3557 pain.fillRectangle(sel_start_cursor.x, offset,
3558 sel_end_cursor.x - sel_start_cursor.x,
3562 pain.fillRectangle(sel_end_cursor.x, offset,
3563 sel_start_cursor.x - sel_end_cursor.x,
3566 } else if (sel_start_cursor.row == row_ptr) {
3567 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3568 pain.fillRectangle(sel_start_cursor.x, offset,
3569 paperwidth - sel_start_cursor.x,
3573 pain.fillRectangle(0, offset,
3577 } else if (sel_end_cursor.row == row_ptr) {
3578 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3579 pain.fillRectangle(0, offset,
3584 pain.fillRectangle(sel_end_cursor.x, offset,
3585 paperwidth - sel_end_cursor.x,
3589 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3590 pain.fillRectangle(0, offset,
3591 paperwidth, row_ptr->height,
3596 if (row_ptr->par->appendix){
3597 pain.line(1, offset,
3598 1, offset + row_ptr->height,
3599 LColor::appendixline);
3600 pain.line(paperwidth - 2, offset,
3601 paperwidth - 2, offset + row_ptr->height,
3602 LColor::appendixline);
3605 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3606 /* draw a marker at the left margin! */
3607 LyXFont font = GetFont(row_ptr->par, 0);
3608 int asc = font.maxAscent();
3609 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3610 int y1 = (offset + row_ptr->baseline);
3611 int y2 = (offset + row_ptr->baseline) - asc;
3612 pain.line(x, y1, x, y2, LColor::minipageline);
3614 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3615 LyXFont font(LyXFont::ALL_SANE);
3616 font.setSize(LyXFont::SIZE_FOOTNOTE);
3617 font.setColor(LColor::footnote);
3619 int box_x = LYX_PAPER_MARGIN;
3620 box_x += font.textWidth(" wide-tab ", 10);
3621 if (row_ptr->previous &&
3622 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3624 switch (row_ptr->par->footnotekind) {
3625 case LyXParagraph::MARGIN:
3628 case LyXParagraph::FIG:
3631 case LyXParagraph::TAB:
3634 case LyXParagraph::WIDE_FIG:
3637 case LyXParagraph::WIDE_TAB:
3640 case LyXParagraph::ALGORITHM:
3643 case LyXParagraph::FOOTNOTE:
3648 pain.fillRectangle(LYX_PAPER_MARGIN,
3650 box_x - LYX_PAPER_MARGIN,
3651 int(font.maxAscent()
3652 + font.maxDescent()),
3653 LColor::footnotebg);
3655 pain.line(LYX_PAPER_MARGIN, offset,
3656 paperwidth - LYX_PAPER_MARGIN, offset,
3657 LColor::footnoteframe);
3659 pain.text(LYX_PAPER_MARGIN,
3660 offset + int(font.maxAscent()) + 1,
3663 pain.line(LYX_PAPER_MARGIN, offset,
3665 offset + int(font.maxAscent()
3666 + font.maxDescent()),
3667 LColor::footnoteframe);
3669 pain.line(LYX_PAPER_MARGIN,
3670 offset + int(font.maxAscent()
3671 + font.maxDescent()) + 1,
3673 offset + int(font.maxAscent()
3674 + font.maxDescent()) + 1,
3675 LColor::footnoteframe);
3679 /* draw the open floats in a red box */
3680 pain.line(box_x, offset,
3681 box_x, offset + row_ptr->height,
3682 LColor::footnoteframe);
3684 pain.line(paperwidth - LYX_PAPER_MARGIN,
3686 paperwidth - LYX_PAPER_MARGIN,
3687 offset + row_ptr->height,
3688 LColor::footnoteframe);
3689 } else if (row_ptr->previous &&
3690 row_ptr->previous->par->footnoteflag
3691 == LyXParagraph::OPEN_FOOTNOTE) {
3692 LyXFont font(LyXFont::ALL_SANE);
3693 font.setSize(LyXFont::SIZE_FOOTNOTE);
3695 int box_x = LYX_PAPER_MARGIN;
3696 box_x += font.textWidth(" wide-tab ", 10);
3698 pain.line(box_x, offset,
3699 paperwidth - LYX_PAPER_MARGIN,
3700 offset, LColor::footnote);
3703 LyXLayout const & layout =
3704 textclasslist.Style(parameters->textclass,
3705 row_ptr->par->GetLayout());
3706 firstpar = row_ptr->par->FirstPhysicalPar();
3709 y_bottom = row_ptr->height;
3711 /* is it a first row? */
3712 if (row_ptr->pos == 0
3713 && row_ptr->par == firstpar) {
3715 /* start of appendix? */
3716 if (row_ptr->par->start_of_appendix){
3717 pain.line(1, offset,
3718 paperwidth - 2, offset,
3719 LColor::appendixline);
3722 /* think about the margins */
3723 if (!row_ptr->previous)
3724 y_top += LYX_PAPER_MARGIN;
3726 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3727 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3729 offset + y_top + 2 * DefaultHeight(),
3730 LColor::pagebreak, Painter::line_onoffdash);
3731 y_top += 3 * DefaultHeight();
3734 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3735 /* draw a vfill top */
3736 pain.line(0, offset + 2 + y_top,
3737 LYX_PAPER_MARGIN, offset + 2 + y_top,
3740 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3742 offset + y_top + 3 * DefaultHeight(),
3745 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3746 LYX_PAPER_MARGIN / 2,
3747 offset + y_top + 3 * DefaultHeight(),
3750 y_top += 3 * DefaultHeight();
3753 /* think about user added space */
3754 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3756 /* think about the parskip */
3757 /* some parskips VERY EASY IMPLEMENTATION */
3758 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3759 if (layout.latextype == LATEX_PARAGRAPH
3760 && firstpar->GetDepth() == 0
3761 && firstpar->Previous())
3762 y_top += parameters->getDefSkip().inPixels(owner_);
3763 else if (firstpar->Previous()
3764 && textclasslist.Style(parameters->textclass,
3765 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3766 && firstpar->Previous()->GetDepth() == 0)
3767 // is it right to use defskip here, too? (AS)
3768 y_top += parameters->getDefSkip().inPixels(owner_);
3771 if (row_ptr->par->line_top) { /* draw a top line */
3772 y_top += GetFont(row_ptr->par, 0).ascent('x');
3774 pain.line(0, offset + y_top,
3775 paperwidth, offset + y_top,
3777 Painter::line_solid,
3778 Painter::line_thick);
3780 y_top += GetFont(row_ptr->par, 0).ascent('x');
3783 /* should we print a label? */
3784 if (layout.labeltype >= LABEL_STATIC
3785 && (layout.labeltype != LABEL_STATIC
3786 || layout.latextype != LATEX_ENVIRONMENT
3787 || row_ptr->par->IsFirstInSequence())) {
3788 font = GetFont(row_ptr->par, -2);
3789 if (!row_ptr->par->GetLabestring().empty()) {
3791 string tmpstring = row_ptr->par->GetLabestring();
3793 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3794 if (parameters->secnumdepth >= 0){
3795 /* this is special code for the chapter layout. This is printed in
3796 * an extra row and has a pagebreak at the top. */
3797 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3798 + int(layout.parsep) * DefaultHeight();
3799 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3800 tmpx = paperwidth - LeftMargin(row_ptr) -
3801 font.stringWidth(tmpstring);
3802 pain.text(int(tmpx),
3803 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3807 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3808 tmpx = x - font.stringWidth(layout.labelsep)
3809 - font.stringWidth(tmpstring);
3811 tmpx = paperwidth - LeftMargin(row_ptr)
3812 + font.stringWidth(layout.labelsep);
3813 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3814 LyXFont font(LyXFont::ALL_SANE);
3815 font.setSize(LyXFont::SIZE_SMALL);
3816 tmpx += font.textWidth("Mwide-figM", 10);
3820 pain.text(int(tmpx),
3821 offset + row_ptr->baseline,
3825 /* the labels at the top of an environment. More or less for bibliography */
3826 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3827 layout.labeltype == LABEL_BIBLIO ||
3828 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3829 if (row_ptr->par->IsFirstInSequence()) {
3830 font = GetFont(row_ptr->par, -2);
3831 if (!row_ptr->par->GetLabestring().empty()) {
3832 string tmpstring = row_ptr->par->GetLabestring();
3834 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3835 + (layout.labelbottomsep * DefaultHeight()));
3838 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3839 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3840 ? x : LeftMargin(row_ptr) )
3841 + paperwidth - RightMargin(row_ptr) ) / 2;
3842 tmpx -= (font.stringWidth(tmpstring)/2);
3843 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3844 tmpx = paperwidth - LeftMargin(row_ptr) -
3845 font.stringWidth(tmpstring);
3846 pain.text(int(tmpx),
3847 offset + row_ptr->baseline
3848 - row_ptr->ascent_of_text
3854 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3855 font = GetFont(row_ptr->par, -1);
3856 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3857 tmpx = x - font.stringWidth(layout.labelsep)
3858 - row_ptr->par->bibkey->width(owner_->painter(), font);
3860 tmpx = paperwidth - LeftMargin(row_ptr)
3861 + font.stringWidth(layout.labelsep);
3862 row_ptr->par->bibkey->draw(owner_->painter(),
3864 offset + row_ptr->baseline,
3869 /* is it a last row? */
3870 par = row_ptr->par->LastPhysicalPar();
3871 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3872 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3874 /* think about the margins */
3876 y_bottom -= LYX_PAPER_MARGIN;
3878 /* draw a bottom pagebreak */
3879 if (firstpar->pagebreak_bottom) {
3880 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3882 offset + y_bottom - 2 * DefaultHeight(),
3883 LColor::pagebreak, Painter::line_onoffdash);
3884 y_bottom -= 3 * DefaultHeight();
3887 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3888 /* draw a vfill bottom */
3889 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3891 offset + y_bottom - 3 * DefaultHeight(),
3893 pain.line(0, offset + y_bottom - 2,
3895 offset + y_bottom - 2,
3897 pain.line(LYX_PAPER_MARGIN / 2,
3898 offset + y_bottom - 3 * DefaultHeight(),
3899 LYX_PAPER_MARGIN / 2,
3900 offset + y_bottom - 2,
3902 y_bottom -= 3* DefaultHeight();
3905 /* think about user added space */
3906 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3908 if (firstpar->line_bottom) {
3909 /* draw a bottom line */
3910 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3911 pain.line(0, offset + y_bottom,
3912 paperwidth, offset + y_bottom,
3913 LColor::topline, Painter::line_solid,
3914 Painter::line_thick);
3915 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3919 /* draw the text in the pixmap */
3920 pos_end = RowLast(row_ptr);
3922 vpos = row_ptr->pos;
3923 /* table stuff -- begin*/
3924 if (row_ptr->par->table) {
3926 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3928 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3930 while (vpos <= pos_end) {
3931 pos = vis2log(vpos);
3932 if (row_ptr->par->IsNewline(pos)) {
3934 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3935 /* draw the table lines, still very simple */
3936 on_off = !row_ptr->par->table->TopLine(cell);
3938 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3939 !row_ptr->par->table->IsContRow(cell))
3940 pain.line(int(x_old),
3941 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3943 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3945 on_off ? Painter::line_onoffdash : Painter::line_solid);
3947 on_off = !row_ptr->par->table->BottomLine(cell);
3948 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3949 row_ptr->par->table->VeryLastRow(cell))
3951 pain.line(int(x_old),
3952 offset + y_bottom - 1,
3954 offset + y_bottom - 1,
3956 on_off ? Painter::line_onoffdash : Painter::line_solid);
3958 on_off = !row_ptr->par->table->LeftLine(cell);
3960 pain.line(int(x_old),
3961 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3963 offset + y_bottom - 1,
3965 on_off ? Painter::line_onoffdash : Painter::line_solid);
3967 on_off = !row_ptr->par->table->RightLine(cell);
3969 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3970 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3971 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3972 offset + y_bottom - 1,
3974 on_off ? Painter::line_onoffdash : Painter::line_solid);
3977 /* take care about the alignment and other spaces */
3979 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3980 if (row_ptr->par->table->IsFirstCell(cell))
3981 --cell; // little hack, sorry
3983 } else if (row_ptr->par->IsHfill(pos)) {
3987 offset + row_ptr->baseline - DefaultHeight() / 2,
3989 offset + row_ptr->baseline,
3994 } else if (row_ptr->par->IsSeparator(pos)) {
3996 x+= SingleWidth(row_ptr->par, pos);
3997 #warning Think about this.
3999 /* -------> Only draw protected spaces when
4000 * not in free-spacing mode. */
4001 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4002 pain.line(int(tmpx),
4003 offset + row_ptr->baseline - 3,
4005 offset + row_ptr->baseline - 1,
4008 pain.line(int(tmpx),
4009 offset + row_ptr->baseline - 1,
4011 offset + row_ptr->baseline - 1,
4014 pain.line(int(x - 2),
4015 offset + row_ptr->baseline - 3,
4017 offset + row_ptr->baseline - 1,
4020 /* what about underbars? */
4021 font = GetFont(row_ptr->par, pos);
4022 if (font.underbar() == LyXFont::ON
4023 && font.latex() != LyXFont::ON) {
4024 pain.line(int(tmpx),
4025 offset + row_ptr->baseline + 2,
4027 offset + row_ptr->baseline + 2);
4033 draw(row_ptr, vpos, offset, x);
4036 /* do not forget the very last cell. This has no NEWLINE so
4037 * ignored by the code above*/
4038 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4039 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4040 on_off = !row_ptr->par->table->TopLine(cell);
4042 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4043 !row_ptr->par->table->IsContRow(cell))
4045 pain.line(int(x_old),
4046 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4048 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4050 on_off ? Painter::line_onoffdash : Painter::line_solid);
4051 on_off = !row_ptr->par->table->BottomLine(cell);
4052 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4053 row_ptr->par->table->VeryLastRow(cell))
4055 pain.line(int(x_old),
4056 offset + y_bottom - 1,
4058 offset + y_bottom - 1,
4060 on_off ? Painter::line_onoffdash : Painter::line_solid);
4062 on_off = !row_ptr->par->table->LeftLine(cell);
4064 pain.line(int(x_old),
4065 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4067 offset + y_bottom - 1,
4069 on_off ? Painter::line_onoffdash : Painter::line_solid);
4071 on_off = !row_ptr->par->table->RightLine(cell);
4073 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4074 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4075 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4076 offset + y_bottom - 1,
4078 on_off ? Painter::line_onoffdash : Painter::line_solid);
4081 /* table stuff -- end*/
4082 LyXParagraph::size_type main_body =
4083 BeginningOfMainBody(row_ptr->par);
4084 if (main_body > 0 &&
4085 (main_body-1 > pos_end ||
4086 !row_ptr->par->IsLineSeparator(main_body-1)))
4089 while (vpos <= pos_end) {
4090 pos = vis2log(vpos);
4091 if (main_body > 0 && pos == main_body-1) {
4092 x += fill_label_hfill
4093 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4094 - SingleWidth(row_ptr->par, main_body-1);
4097 if (row_ptr->par->IsHfill(pos)) {
4100 offset + row_ptr->baseline - DefaultHeight() / 2,
4102 offset + row_ptr->baseline,
4105 if (HfillExpansion(row_ptr, pos)) {
4106 if (pos >= main_body) {
4108 offset + row_ptr->baseline - DefaultHeight() / 4,
4109 int(x + fill_hfill),
4110 offset + row_ptr->baseline - DefaultHeight() / 4,
4112 Painter::line_onoffdash);
4116 offset + row_ptr->baseline - DefaultHeight() / 4,
4117 int(x + fill_label_hfill),
4118 offset + row_ptr->baseline - DefaultHeight() / 4,
4120 Painter::line_onoffdash);
4122 x += fill_label_hfill;
4125 offset + row_ptr->baseline - DefaultHeight() / 2,
4127 offset + row_ptr->baseline,
4132 } else if (row_ptr->par->IsSeparator(pos)) {
4134 x+= SingleWidth(row_ptr->par, pos);
4135 if (pos >= main_body)
4137 #warning Think about this
4139 /* -------> Only draw protected spaces when
4140 * not in free-spacing mode. */
4141 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4143 pain.line(int(tmpx),
4144 offset + row_ptr->baseline - 3,
4146 offset + row_ptr->baseline - 1,
4149 pain.line(int(tmpx),
4150 offset + row_ptr->baseline - 1,
4152 offset + row_ptr->baseline - 1,
4155 pain.line(int(x - 2),
4156 offset + row_ptr->baseline - 3,
4158 offset + row_ptr->baseline - 1,
4161 /* what about underbars? */
4162 font = GetFont(row_ptr->par, pos);
4163 if (font.underbar() == LyXFont::ON
4164 && font.latex() != LyXFont::ON) {
4165 pain.line(int(tmpx),
4166 offset + row_ptr->baseline + 2,
4168 offset + row_ptr->baseline + 2);
4174 draw(row_ptr, vpos, offset, x);
4180 int LyXText::DefaultHeight() const
4182 LyXFont font(LyXFont::ALL_SANE);
4183 return int(font.maxAscent() + font.maxDescent() * 1.5);
4187 /* returns the column near the specified x-coordinate of the row
4188 * x is set to the real beginning of this column */
4189 int LyXText::GetColumnNearX(Row * row, int & x) const
4192 float fill_separator, fill_hfill, fill_label_hfill;
4194 PrepareToPrint(row, tmpx, fill_separator,
4195 fill_hfill, fill_label_hfill);
4197 LyXDirection direction = row->par->getParDirection();
4198 LyXParagraph::size_type vc = row->pos;
4199 LyXParagraph::size_type last = RowLast(row);
4200 LyXParagraph::size_type c = 0;
4202 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4203 row->par->GetLayout());
4204 /* table stuff -- begin */
4205 if (row->par->table) {
4206 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4207 && row->par->IsNewline(last))
4209 int cell = NumberOfCell(row->par, row->pos);
4212 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4214 && (c = vis2log(vc)) >= 0
4215 && tmpx + (SingleWidth(row->par, c)/2) <= x
4217 if (row->par->IsNewline(c)) {
4218 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4219 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4222 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4227 tmpx += SingleWidth(row->par, c);
4232 /* table stuff -- end*/
4233 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4234 float last_tmpx = tmpx;
4236 if (main_body > 0 &&
4237 (main_body-1 > last ||
4238 !row->par->IsLineSeparator(main_body-1)))
4241 while (vc <= last && tmpx <= x) {
4244 if (main_body > 0 && c == main_body-1) {
4245 tmpx += fill_label_hfill +
4246 GetFont(row->par, -2).stringWidth(layout.labelsep);
4247 if (row->par->IsLineSeparator(main_body-1))
4248 tmpx -= SingleWidth(row->par, main_body-1);
4251 tmpx += SingleWidth(row->par, c);
4252 if (HfillExpansion(row, c)) {
4256 tmpx += fill_label_hfill;
4258 else if (c >= main_body
4259 && row->par->IsSeparator(c)) {
4260 tmpx+= fill_separator;
4265 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4270 /* make sure that a last space in a row doesnt count */
4271 if (row->pos <= last
4272 && !(!row->next || row->next->par != row->par))
4273 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4274 && row->par->IsLineSeparator(vis2log(last)) ) {
4276 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4277 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4279 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4281 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4284 if (row->pos > last) // Row is empty?
4286 else if (vc <= last) {
4288 LyXDirection direction = row->par->getLetterDirection(c);
4289 if (vc > row->pos && row->par->IsLineSeparator(c)
4290 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4292 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4295 c = vis2log(last)+1;
4296 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4300 if (!row->par->table && row->pos <= last && c > last
4301 && row->par->IsNewline(last)) {
4302 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4303 tmpx -= SingleWidth(row->par, last);
4305 tmpx += SingleWidth(row->par, last);
4315 /* turn the selection into a new environment. If there is no selection,
4316 * create an empty environment */
4317 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4319 /* no footnoteenvironment in a footnoteenvironment */
4320 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4321 WriteAlert(_("Impossible operation"),
4322 _("You can't insert a float in a float!"),
4326 /* no marginpars in minipages */
4327 if (kind == LyXParagraph::MARGIN
4328 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4329 WriteAlert(_("Impossible operation"),
4330 _("You can't insert a marginpar in a minipage!"),
4335 /* this doesnt make sense, if there is no selection */
4336 bool dummy_selection = false;
4338 sel_start_cursor = cursor; /* dummy selection */
4339 sel_end_cursor = cursor;
4340 dummy_selection = true;
4343 LyXParagraph *tmppar;
4345 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4346 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4350 /* a test to make sure there is not already a footnote
4351 * in the selection. */
4353 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4355 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4356 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4357 tmppar = tmppar->next;
4359 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4360 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4361 WriteAlert(_("Impossible operation"),
4362 _("Float would include float!"),
4367 /* ok we have a selection. This is always between sel_start_cursor
4368 * and sel_end cursor */
4370 SetUndo(Undo::FINISH,
4371 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4372 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4374 if (sel_end_cursor.pos > 0
4375 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4376 sel_end_cursor.pos--; /* please break before a space at
4378 if (sel_start_cursor.par == sel_end_cursor.par
4379 && sel_start_cursor.pos > sel_end_cursor.pos)
4380 sel_start_cursor.pos--;
4382 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4384 sel_end_cursor.par = sel_end_cursor.par->Next();
4385 sel_end_cursor.pos = 0;
4387 // don't forget to insert a dummy layout paragraph if necessary
4388 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4389 sel_end_cursor.par->BreakParagraphConservative(0);
4390 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4391 sel_end_cursor.par = sel_end_cursor.par->next;
4394 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4396 cursor = sel_end_cursor;
4398 /* please break behind a space, if there is one. The space should
4400 if (sel_start_cursor.pos > 0
4401 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4402 sel_start_cursor.pos--;
4403 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4404 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4407 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4408 tmppar = sel_start_cursor.par->Next();
4410 if (dummy_selection) {
4412 if (kind == LyXParagraph::TAB
4413 || kind == LyXParagraph::FIG
4414 || kind == LyXParagraph::WIDE_TAB
4415 || kind == LyXParagraph::WIDE_FIG
4416 || kind == LyXParagraph::ALGORITHM) {
4417 pair<bool, LyXTextClass::size_type> lres =
4418 textclasslist.NumberOfLayout(parameters->textclass,
4420 LyXTextClass::size_type lay;
4426 lay = 0; // use default layout "Standard" (0)
4428 tmppar->SetLayout(lay);
4432 if (sel_start_cursor.pos > 0) {
4433 /* the footnote-environment should begin with a standard layout.
4434 * Imagine you insert a footnote within an enumeration, you
4435 * certainly do not want an enumerated footnote! */
4439 /* this is a exception the user would sometimes expect, I hope */
4440 sel_start_cursor.par->Clear();
4444 while (tmppar != sel_end_cursor.par) {
4445 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4446 tmppar->footnotekind = kind;
4447 tmppar = tmppar->Next();
4450 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4452 SetCursor(sel_start_cursor.par->Next(), 0);
4458 // returns pointer to a specified row
4459 Row * LyXText::GetRow(LyXParagraph * par,
4460 LyXParagraph::size_type pos, long & y) const
4465 if (par == currentrow->par
4466 || par == currentrow->par->Previous()) {
4467 // do not dereference par, it may have been deleted
4468 // already! (Matthias)
4470 // Walk backwards as long as the previous
4471 // rows par is not par
4472 while (currentrow->previous
4473 && currentrow->previous->par != par) {
4474 currentrow = currentrow->previous;
4475 currentrow_y -= currentrow->height;
4477 // Walk backwards as long as the previous
4478 // rows par _is_ par
4479 while (currentrow->previous
4480 && currentrow->previous->par == par) {
4481 currentrow = currentrow->previous;
4482 currentrow_y -= currentrow->height;
4486 tmprow = currentrow;
4488 // find the first row of the specified paragraph
4490 && tmprow->par != par) {
4491 y += tmprow->height;
4492 tmprow = tmprow->next;
4495 if (tmprow->par == par){
4496 // now find the wanted row
4497 while (tmprow->pos < pos
4499 && tmprow->next->par == par
4500 && tmprow->next->pos <= pos) {
4501 y += tmprow->height;
4502 tmprow = tmprow->next;
4504 currentrow = tmprow;
4512 // find the first row of the specified paragraph
4513 while (tmprow->next && tmprow->par != par) {
4514 y += tmprow->height;
4515 tmprow = tmprow->next;
4518 // now find the wanted row
4519 while (tmprow->pos < pos
4521 && tmprow->next->par == par
4522 && tmprow->next->pos <= pos) {
4523 y += tmprow->height;
4524 tmprow = tmprow->next;
4527 currentrow = tmprow;