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 // This is the comments that some of the warnings below refers to.
48 // There are some issues in this file and I don't think they are
49 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
50 // this is a problem that has been here almost from day one and that a
51 // larger userbase with differenct access patters triggers the bad
52 // behaviour. (segfaults.) What I think happen is: In several places
53 // we store the paragraph in the current cursor and then moves the
54 // cursor. This movement of the cursor will delete paragraph at the
55 // old position if it is now empty. This will make the temporary
56 // pointer to the old cursor paragraph invalid and dangerous to use.
57 // And is some cases this will trigger a segfault. I have marked some
58 // of the cases where this happens with a warning, but I am sure there
59 // are others in this file and in text2.C. There is also a note in
60 // Delete() that you should read. In Delete I store the paragraph->id
61 // instead of a pointer to the paragraph. I am pretty sure this faulty
62 // use of temporary pointers to paragraphs that might have gotten
63 // invalidated (through a cursor movement) before they are used, are
64 // the cause of the strange crashes we get reported often.
66 // It is very tiresom to change this code, especially when it is as
67 // hard to read as it is. Help to fix all the cases where this is done
68 // would be greately appreciated.
72 int LyXText::SingleWidth(LyXParagraph * par,
73 LyXParagraph::size_type pos) const
75 char c = par->GetChar(pos);
76 return SingleWidth(par, pos, c);
80 int LyXText::SingleWidth(LyXParagraph * par,
81 LyXParagraph::size_type pos, char c) const
83 LyXFont font = GetFont(par, pos);
85 // The most common case is handled first (Asger)
89 } else if (IsHfillChar(c)) {
90 return 3; /* Because of the representation
91 * as vertical lines */
92 } else if (c == LyXParagraph::META_FOOTNOTE ||
93 c == LyXParagraph::META_MARGIN ||
94 c == LyXParagraph::META_FIG ||
95 c == LyXParagraph::META_TAB ||
96 c == LyXParagraph::META_WIDE_FIG ||
97 c == LyXParagraph::META_WIDE_TAB ||
98 c == LyXParagraph::META_ALGORITHM) {
101 case LyXParagraph::META_MARGIN:
104 case LyXParagraph::META_FIG:
107 case LyXParagraph::META_TAB:
110 case LyXParagraph::META_ALGORITHM:
113 case LyXParagraph::META_WIDE_FIG:
116 case LyXParagraph::META_WIDE_TAB:
119 case LyXParagraph::META_FOOTNOTE:
125 return font.stringWidth(fs);
126 } else if (c == LyXParagraph::META_INSET) {
127 Inset * tmpinset= par->GetInset(pos);
129 return par->GetInset(pos)->width(owner_->painter(),
134 } else if (IsSeparatorChar(c))
136 else if (IsNewlineChar(c))
138 return font.width(c);
142 // Returns the paragraph position of the last character in the specified row
143 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
146 return row->par->Last() - 1;
147 else if (row->next->par != row->par)
148 return row->par->Last() - 1;
150 return row->next->pos - 1;
157 void LyXText::ComputeBidiTables(Row * row) const
160 if (!lyxrc->rtl_support) {
164 LyXParagraph::size_type last = RowLast(row);
165 bidi_start = row->pos;
167 if (bidi_start > last) {
172 if (last + 2 - bidi_start >
173 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
174 LyXParagraph::size_type new_size =
175 (last + 2 - bidi_start < 500) ?
176 500 : 2 * (last + 2 - bidi_start);
177 log2vis_list.resize(new_size);
178 vis2log_list.resize(new_size);
181 vis2log_list[last + 1 - bidi_start] = -1;
182 log2vis_list[last + 1 - bidi_start] = -1;
184 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
185 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
186 && row->par->IsLineSeparator(main_body - 1)) {
187 // This is needed in case there is a direction change in
188 // the label which is continued into the main body
189 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
190 ComputeBidiTablesFromTo(row, bidi_start,
192 log2vis_list[main_body - 1 - bidi_start] =
194 vis2log_list[main_body - 1 - bidi_start] =
196 if (main_body <= last)
197 ComputeBidiTablesFromTo(row,
200 ComputeBidiTablesFromTo(row, bidi_start,
202 last - main_body + 2);
203 log2vis_list[main_body - 1 - bidi_start] =
204 last - main_body + 1 + bidi_start;
205 vis2log_list[last - main_body + 1 - bidi_start] =
207 if (main_body <= last)
208 ComputeBidiTablesFromTo(row, main_body,
212 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
216 void LyXText::ComputeBidiTablesFromTo(Row * row,
217 LyXParagraph::size_type from,
218 LyXParagraph::size_type to,
219 LyXParagraph::size_type offset) const
221 LyXParagraph::size_type vpos, old_lpos, stack[2];
222 LyXDirection par_direction = row->par->getParDirection();
223 LyXDirection direction = par_direction;
224 LyXParagraph::size_type lpos = from;
228 if (row->par->getLetterDirection(lpos) == direction) {
229 log2vis_list[lpos - bidi_start] = direction;
233 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
234 && row->par->getFont(lpos).direction() ==
236 && row->par->getFont(lpos).latex() ==
238 // The last check is needed when the
240 stack[level++] = lpos;
242 old_lpos = stack[--level];
243 log2vis_list[old_lpos - bidi_start] =
244 log2vis_list[lpos - bidi_start] =
245 (old_lpos - lpos) * direction;
248 direction = static_cast<LyXDirection>(-direction);
253 old_lpos = stack[--level];
254 log2vis_list[old_lpos - bidi_start] =
255 (old_lpos - (to + 1)) * direction;
256 direction = static_cast<LyXDirection>(-direction);
259 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
262 for (lpos = from; lpos <= to; ++lpos) {
263 vpos += log2vis_list[lpos - bidi_start];
264 vis2log_list[vpos - bidi_start] = lpos;
265 log2vis_list[lpos - bidi_start] = vpos;
270 void LyXText::draw(Row const * row,
271 LyXParagraph::size_type & vpos,
272 int offset, float & x)
274 Painter & pain = owner_->painter();
276 LyXParagraph::size_type pos = vis2log(vpos);
277 char c = row->par->GetChar(pos);
279 if (IsNewlineChar(c)) {
281 // Draw end-of-line marker
282 LyXFont font = GetFont(row->par, pos);
283 int wid = font.width('n');
284 int asc = font.maxAscent();
285 int y = offset + row->baseline;
288 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
289 xp[0] = int(x + wid * 0.375);
290 yp[0] = int(y - 0.875 * asc * 0.75);
293 yp[1] = int(y - 0.500 * asc * 0.75);
295 xp[2] = int(x + wid * 0.375);
296 yp[2] = int(y - 0.125 * asc * 0.75);
298 pain.lines(xp, yp, 3, LColor::eolmarker);
301 yp[0] = int(y - 0.500 * asc * 0.75);
303 xp[1] = int(x + wid);
304 yp[1] = int(y - 0.500 * asc * 0.75);
306 xp[2] = int(x + wid);
307 yp[2] = int(y - asc * 0.75);
309 pain.lines(xp, yp, 3, LColor::eolmarker);
311 xp[0] = int(x + wid * 0.625);
312 yp[0] = int(y - 0.875 * asc * 0.75);
314 xp[1] = int(x + wid);
315 yp[1] = int(y - 0.500 * asc * 0.75);
317 xp[2] = int(x + wid * 0.625);
318 yp[2] = int(y - 0.125 * asc * 0.75);
320 pain.lines(xp, yp, 3, LColor::eolmarker);
322 xp[0] = int(x + wid);
323 yp[0] = int(y - 0.500 * asc * 0.75);
326 yp[1] = int(y - 0.500 * asc * 0.75);
329 yp[2] = int(y - asc * 0.75);
331 pain.lines(xp, yp, 3, LColor::eolmarker);
337 LyXFont font = GetFont(row->par, pos);
338 LyXFont font2 = font;
340 if (c == LyXParagraph::META_FOOTNOTE
341 || c == LyXParagraph::META_MARGIN
342 || c == LyXParagraph::META_FIG
343 || c == LyXParagraph::META_TAB
344 || c == LyXParagraph::META_WIDE_FIG
345 || c == LyXParagraph::META_WIDE_TAB
346 || c == LyXParagraph::META_ALGORITHM) {
349 case LyXParagraph::META_MARGIN:
351 // Draw a sign at the left margin!
353 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
354 offset + row->baseline, "!", 1, font);
356 case LyXParagraph::META_FIG:
359 case LyXParagraph::META_TAB:
362 case LyXParagraph::META_ALGORITHM:
365 case LyXParagraph::META_WIDE_FIG:
368 case LyXParagraph::META_WIDE_TAB:
371 case LyXParagraph::META_FOOTNOTE:
378 // calculate the position of the footnotemark
379 int y = (row->baseline - font2.maxAscent()
382 font.setColor(LColor::footnote);
386 // draw it and set new x position
388 pain.text(int(x), offset + y, fs, font);
389 x += pain.width(fs, font);
390 pain.line(int(tmpx), offset + row->baseline,
391 int(x), offset + row->baseline,
396 } else if (c == LyXParagraph::META_INSET) {
397 Inset * tmpinset = row->par->GetInset(pos);
399 tmpinset->draw(owner_->painter(), font,
400 offset + row->baseline, x);
406 /* usual characters, no insets */
408 // Collect character that we can draw in one command
410 // This is dirty, but fast. Notice that it will never be too small.
411 // For the record, I'll note that Microsoft Word has a limit
412 // of 768 here. We have none :-) (Asger)
413 // Ok. I am the first to admit that the use of std::string will be
414 // a tiny bit slower than using a POD char array. However, I claim
415 // that this slowdown is so small that it is close to inperceptive.
416 // So IMHO we should go with the easier and clearer implementation.
417 // And even if 1024 is a large number here it might overflow, string
418 // will only overflow if the machine is out of memory...
419 static string textstring;
423 LyXParagraph::size_type last = RowLast(row);
425 while (vpos <= last &&
426 (pos = vis2log(vpos)) >= 0
427 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
428 && font2 == GetFont(row->par, pos)) {
434 // Draw text and set the new x position
435 pain.text(int(x), offset + row->baseline, textstring, font);
436 x += pain.width(textstring, font);
438 // what about underbars?
439 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
440 pain.line(tmpx, offset + row->baseline + 2,
441 x, offset + row->baseline + 2);
445 // If we want ulem.sty support, drawing
446 // routines should go here. (Asger)
447 // Why shouldn't LyXFont::drawText handle it internally?
451 // Returns the left beginning of the text.
452 // This information cannot be taken from the layouts-objekt, because in
453 // LaTeX the beginning of the text fits in some cases (for example sections)
454 // exactly the label-width.
455 int LyXText::LeftMargin(Row const * row) const
457 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
458 row->par->GetLayout());
460 string parindent = layout.parindent;
462 /* table stuff -- begin */
465 /* table stuff -- end */
467 int x = LYX_PAPER_MARGIN;
469 x += textclasslist.TextClass(parameters->textclass)
471 .signedStringWidth(textclasslist
472 .TextClass(parameters->textclass)
475 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
476 LyXFont font(LyXFont::ALL_SANE);
477 font.setSize(LyXFont::SIZE_SMALL);
478 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
481 // this is the way, LyX handles the LaTeX-Environments.
482 // I have had this idea very late, so it seems to be a
483 // later added hack and this is true
484 if (!row->par->GetDepth()) {
485 if (!row->par->GetLayout()) {
486 // find the previous same level paragraph
487 if (row->par->FirstPhysicalPar()->Previous()) {
488 LyXParagraph * newpar = row->par
489 ->DepthHook(row->par->GetDepth());
491 textclasslist.Style(parameters->textclass,
498 // find the next level paragraph
500 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
502 // make a corresponding row. Needed to call LeftMargin()
504 // check wether it is a sufficent paragraph
505 if (newpar && newpar->footnoteflag == row->par->footnoteflag
507 .Style(parameters->textclass,
508 newpar->GetLayout()).isEnvironment()) {
510 dummyrow.par = newpar;
511 dummyrow.pos = newpar->Last();
512 x = LeftMargin(&dummyrow);
514 // this is no longer an error, because this function
515 // is used to clear impossible depths after changing
516 // a layout. Since there is always a redo,
517 // LeftMargin() is always called
518 row->par->FirstPhysicalPar()->depth = 0;
521 if (newpar && !row->par->GetLayout()) {
522 if (newpar->FirstPhysicalPar()->noindent)
525 parindent = textclasslist
526 .Style(parameters->textclass,
527 newpar->GetLayout()).parindent;
532 LyXFont labelfont = GetFont(row->par, -2);
533 switch (layout.margintype) {
535 if (!layout.leftmargin.empty()) {
537 .TextClass(parameters->textclass)
539 .signedStringWidth(layout.leftmargin);
541 if (!row->par->GetLabestring().empty()) {
542 x += labelfont.signedStringWidth(layout.labelindent);
543 x += labelfont.stringWidth(row->par->GetLabestring());
544 x += labelfont.stringWidth(layout.labelsep);
548 x += labelfont.signedStringWidth(layout.labelindent);
549 if (row->pos >= BeginningOfMainBody(row->par)) {
550 if (!row->par->GetLabelWidthString().empty()) {
552 .stringWidth(row->par
553 ->GetLabelWidthString());
554 x += labelfont.stringWidth(layout.labelsep);
559 x += textclasslist.TextClass(parameters->textclass)
560 .defaultfont().signedStringWidth(layout.leftmargin) * 4
561 / (row->par->GetDepth() + 4);
563 case MARGIN_FIRST_DYNAMIC:
564 if (layout.labeltype == LABEL_MANUAL) {
565 if (row->pos >= BeginningOfMainBody(row->par)) {
567 .signedStringWidth(layout.leftmargin);
570 .signedStringWidth(layout.labelindent);
573 // Special case to fix problems with
575 || (layout.labeltype == LABEL_STATIC
576 && layout.latextype == LATEX_ENVIRONMENT
577 && ! row->par->IsFirstInSequence())) {
578 x += labelfont.signedStringWidth(layout.leftmargin);
579 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
580 && layout.labeltype != LABEL_BIBLIO
581 && layout.labeltype !=
582 LABEL_CENTERED_TOP_ENVIRONMENT) {
583 x += labelfont.signedStringWidth(layout.labelindent);
584 x += labelfont.stringWidth(layout.labelsep);
585 x += labelfont.stringWidth(row->par->GetLabestring());
589 case MARGIN_RIGHT_ADDRESS_BOX:
591 // ok, a terrible hack. The left margin depends on the widest
592 // row in this paragraph. Do not care about footnotes, they
593 // are *NOT* allowed in the LaTeX realisation of this layout.
595 // find the first row of this paragraph
596 Row const * tmprow = row;
597 while (tmprow->previous && tmprow->previous->par == row->par)
598 tmprow = tmprow->previous;
600 int minfill = tmprow->fill;
601 while (tmprow->next && tmprow->next->par == row->par) {
602 tmprow = tmprow->next;
603 if (tmprow->fill < minfill)
604 minfill = tmprow->fill;
607 x += textclasslist.TextClass(parameters->textclass)
608 .defaultfont().signedStringWidth(layout.leftmargin);
613 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
614 if (!row->par->pextra_widthp.empty()) {
616 atoi(row->par->pextra_widthp.c_str()) / 100;
617 } else if (!row->par->pextra_width.empty()) {
618 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
621 xx = paperwidth * 80 / 100;
623 } else { // should not happen
624 LyXFont font(LyXFont::ALL_SANE);
625 x += font.stringWidth("XXXXXX");
629 int align; // wrong type
630 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
631 align = layout.align;
633 align = row->par->FirstPhysicalPar()->align;
635 // set the correct parindent
637 if ((layout.labeltype == LABEL_NO_LABEL
638 || layout.labeltype == LABEL_TOP_ENVIRONMENT
639 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
640 || (layout.labeltype == LABEL_STATIC
641 && layout.latextype == LATEX_ENVIRONMENT
642 && ! row->par->IsFirstInSequence()))
643 && row->par == row->par->FirstPhysicalPar()
644 && align == LYX_ALIGN_BLOCK
645 && !row->par->noindent
646 && (row->par->layout ||
647 parameters->paragraph_separation ==
648 BufferParams::PARSEP_INDENT))
649 x += textclasslist.TextClass(parameters->textclass)
650 .defaultfont().signedStringWidth(parindent);
651 else if (layout.labeltype == LABEL_BIBLIO) {
652 // ale970405 Right width for bibitems
653 x += bibitemMaxWidth(owner_->painter(),
655 .TextClass(parameters
664 int LyXText::RightMargin(Row const * row) const
666 LyXLayout const & layout =
667 textclasslist.Style(parameters->textclass,
668 row->par->GetLayout());
670 int x = LYX_PAPER_MARGIN
672 .TextClass(parameters->textclass)
674 .signedStringWidth(textclasslist
675 .TextClass(parameters->textclass)
678 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
679 x += LYX_PAPER_MARGIN / 2;
682 // this is the way, LyX handles the LaTeX-Environments.
683 // I have had this idea very late, so it seems to be a
684 // later added hack and this is true
685 if (row->par->GetDepth()) {
686 // find the next level paragraph
688 LyXParagraph * newpar = row->par;
691 newpar = newpar->FirstPhysicalPar()->Previous();
693 newpar = newpar->FirstPhysicalPar();
694 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
695 && newpar->footnoteflag == row->par->footnoteflag);
697 // make a corresponding row. Needed to call LeftMargin()
699 // check wether it is a sufficent paragraph
700 if (newpar && newpar->footnoteflag == row->par->footnoteflag
701 && textclasslist.Style(parameters->textclass,
705 dummyrow.par = newpar;
707 x = RightMargin(&dummyrow);
709 // this is no longer an error, because this function
710 // is used to clear impossible depths after changing
711 // a layout. Since there is always a redo,
712 // LeftMargin() is always called
713 row->par->FirstPhysicalPar()->depth = 0;
717 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
718 x += textclasslist.TextClass(parameters->textclass)
720 .signedStringWidth(layout.rightmargin) * 4
721 / (row->par->GetDepth() + 4);
726 int LyXText::LabelEnd (Row const * row) const
728 if (textclasslist.Style(parameters->textclass,
729 row->par->GetLayout()).margintype
733 tmprow.pos = row->par->Last();
734 return LeftMargin(&tmprow); /* just the beginning
737 return 0; /* LabelEnd is only needed, if the
738 layout fills a flushleft
743 /* table stuff -- begin*/
744 int LyXText::NumberOfCell(LyXParagraph * par,
745 LyXParagraph::size_type pos) const
748 LyXParagraph::size_type tmp_pos = 0;
749 while (tmp_pos < pos) {
750 if (par->IsNewline(tmp_pos))
758 int LyXText::WidthOfCell(LyXParagraph * par,
759 LyXParagraph::size_type & pos) const
762 while (pos < par->Last() && !par->IsNewline(pos)) {
763 w += SingleWidth(par, pos);
766 if (par->IsNewline(pos))
772 bool LyXText::HitInTable(Row * row, int x) const
775 float fill_separator, fill_hfill, fill_label_hfill;
776 if (!row->par->table)
778 PrepareToPrint(row, tmpx, fill_separator,
779 fill_hfill, fill_label_hfill, false);
780 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
784 bool LyXText::MouseHitInTable(int x, long y) const
786 Row * row = GetRowNearY(y);
787 return HitInTable(row, x);
791 /* table stuff -- end*/
794 // get the next breakpoint in a given paragraph
795 LyXParagraph::size_type
796 LyXText::NextBreakPoint(Row const * row, int width) const
798 LyXParagraph * par = row->par;
799 LyXParagraph::size_type pos = row->pos;
801 /* table stuff -- begin*/
803 while (pos < par->size()
804 && (!par->IsNewline(pos)
805 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
806 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
807 par->GetInset(pos) && par->GetInset(pos)->display()){
808 par->GetInset(pos)->display(false);
814 /* table stuff -- end*/
816 // position of the last possible breakpoint
817 // -1 isn't a suitable value, but a flag
818 LyXParagraph::size_type last_separator = -1;
819 int left_margin = LabelEnd(row);
820 width -= RightMargin(row);
822 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
823 LyXLayout const & layout =
824 textclasslist.Style(parameters->textclass, par->GetLayout());
825 LyXParagraph::size_type i = pos;
827 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
828 /* special code for right address boxes, only newlines count */
829 while (i < par->Last()) {
830 if (par->IsNewline(i)) {
832 i = par->Last() - 1; // this means break
834 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
835 par->GetInset(i) && par->GetInset(i)->display()){
836 par->GetInset(i)->display(false);
841 // Last position is an invariant
842 LyXParagraph::size_type const last =
844 // this is the usual handling
845 int x = LeftMargin(row);
846 while (x < width && i < last) {
847 char c = par->GetChar(i);
848 if (IsNewlineChar(c)) {
850 x = width; // this means break
851 } else if (c == LyXParagraph::META_INSET &&
852 par->GetInset(i) && par->GetInset(i)->display()){
853 // check wether a Display() inset is
854 // valid here. if not, change it to
856 if (layout.isCommand()
857 || (layout.labeltype == LABEL_MANUAL
858 && i < BeginningOfMainBody(par))){
859 // display istn't allowd
860 par->GetInset(i)->display(false);
861 x += SingleWidth(par, i, c);
863 // inset is display. So break the line here
867 if (IsLineSeparatorChar(par->GetChar(i+1)))
870 last_separator = last; // to avoid extra rows
872 last_separator = i - 1;
873 x = width; // this means break
876 if (IsLineSeparatorChar(c))
878 x += SingleWidth(par, i, c);
881 if (i == main_body) {
882 x += GetFont(par, -2).stringWidth(layout.labelsep);
883 if (par->IsLineSeparator(i - 1))
884 x-= SingleWidth(par, i - 1);
889 // end of paragraph is always a suitable separator
890 if (i == last && x < width)
894 // well, if last_separator is still 0, the line isn't breakable.
895 // don't care and cut simply at the end
896 if (last_separator < 0) {
900 // manual labels cannot be broken in LaTeX, do not care
901 if (main_body && last_separator < main_body)
902 last_separator = main_body - 1;
904 return last_separator;
908 // returns the minimum space a row needs on the screen in pixel
909 int LyXText::Fill(Row const * row, int paper_width) const
912 // get the pure distance
913 LyXParagraph::size_type last = RowLast(row);
914 /* table stuff -- begin */
915 if (row->par->table) {
916 // for tables FILL does calculate the widthes of each cell in
918 LyXParagraph::size_type pos = row->pos;
919 int cell = NumberOfCell(row->par, pos);
922 row->par->table->SetWidthOfCell(cell,
923 WidthOfCell(row->par,
926 } while (pos <= last && !row->par->table->IsFirstCell(cell));
927 // don't forget the very last table cell without characters
928 if (cell == row->par->table->GetNumberOfCells() - 1)
929 row->par->table->SetWidthOfCell(cell,
930 WidthOfCell(row->par,
933 return 0; /* width of table cannot be returned since
934 * we cannot guarantee its correct value at
937 /* table stuff -- end*/
939 int left_margin = LabelEnd(row);
941 // if the row ends with newline, this newline will not be relevant
942 //if (last >= 0 && row->par->IsNewline(last))
945 // if the row ends with a space, this space will not be relevant
946 if (last >= 0 && row->par->IsLineSeparator(last))
949 // special handling of the right address boxes
950 if (textclasslist.Style(parameters->textclass,
951 row->par->GetLayout()).margintype
952 == MARGIN_RIGHT_ADDRESS_BOX) {
953 int tmpfill = row->fill;
954 row->fill = 0; // the minfill in MarginLeft()
960 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
961 row->par->GetLayout());
962 LyXParagraph::size_type main_body =
963 BeginningOfMainBody(row->par);
964 LyXParagraph::size_type i = row->pos;
967 if (main_body > 0 && i == main_body) {
968 w += GetFont(row->par, -2).
969 stringWidth(layout.labelsep);
970 if (row->par->IsLineSeparator(i - 1))
971 w -= SingleWidth(row->par, i - 1);
975 w += SingleWidth(row->par, i);
978 if (main_body > 0 && main_body > last) {
979 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
980 if (last >= 0 && row->par->IsLineSeparator(last))
981 w -= SingleWidth(row->par, last);
986 fill = paper_width - w - RightMargin(row);
991 // returns the minimum space a manual label needs on the screen in pixel
992 int LyXText::LabelFill(Row const * row) const
994 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
995 // -1 because a label ends either with a space that is in the label,
996 // or with the beginning of a footnote that is outside the label.
998 // I don't understand this code in depth, but sometimes "last" is
999 // less than 0 and this causes a crash. This fix seems to work
1000 // correctly, but I bet the real error is elsewhere. The bug is
1001 // triggered when you have an open footnote in a paragraph
1002 // environment with a manual label. (Asger)
1003 if (last < 0) last = 0;
1005 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1012 w += SingleWidth(row->par, i);
1017 if (!row->par->labelwidthstring.empty()) {
1018 fill = GetFont(row->par, -2)
1019 .stringWidth(row->par->labelwidthstring) - w;
1029 // returns the number of separators in the specified row. The separator
1030 // on the very last column doesnt count
1031 int LyXText::NumberOfSeparators(Row const * row) const
1033 int last = RowLast(row);
1034 int p = max(row->pos, BeginningOfMainBody(row->par));
1036 for (; p < last; ++p) {
1037 if (row->par->IsSeparator(p)) {
1045 // returns the number of hfills in the specified row. The LyX-Hfill is
1046 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1047 // ignored. This is *MUCH* more usefull than not to ignore!
1048 int LyXText::NumberOfHfills(Row const * row) const
1050 int last = RowLast(row);
1051 int first = row->pos;
1052 if (first) { /* hfill *DO* count at the beginning
1054 while(first <= last && row->par->IsHfill(first))
1058 first = max(first, BeginningOfMainBody(row->par));
1060 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1061 if (row->par->IsHfill(p)) {
1069 // like NumberOfHfills, but only those in the manual label!
1070 int LyXText::NumberOfLabelHfills(Row const * row) const
1072 LyXParagraph::size_type last = RowLast(row);
1073 LyXParagraph::size_type first = row->pos;
1074 if (first) { /* hfill *DO* count at the beginning
1076 while(first < last && row->par->IsHfill(first))
1080 last = min(last, BeginningOfMainBody(row->par));
1082 for (LyXParagraph::size_type p = first;
1083 p < last; ++p) { // last, because the end is ignored!
1084 if (row->par->IsHfill(p)) {
1092 // returns true, if a expansion is needed.
1093 // Rules are given by LaTeX
1094 bool LyXText::HfillExpansion(Row const * row_ptr,
1095 LyXParagraph::size_type pos) const
1097 // by the way, is it a hfill?
1098 if (!row_ptr->par->IsHfill(pos))
1101 // at the end of a row it does not count
1102 if (pos >= RowLast(row_ptr))
1105 // at the beginning of a row it does not count, if it is not
1106 // the first row of a paragaph
1110 // in some labels it does not count
1111 if (textclasslist.Style(parameters->textclass,
1112 row_ptr->par->GetLayout()).margintype
1114 && pos < BeginningOfMainBody(row_ptr->par))
1117 // if there is anything between the first char of the row and
1118 // the sepcified position that is not a newline and not a hfill,
1119 // the hfill will count, otherwise not
1120 LyXParagraph::size_type i = row_ptr->pos;
1121 while (i < pos && (row_ptr->par->IsNewline(i)
1122 || row_ptr->par->IsHfill(i)))
1129 void LyXText::SetHeightOfRow(Row * row_ptr) const
1131 /* get the maximum ascent and the maximum descent */
1133 float layoutasc = 0;
1134 float layoutdesc = 0;
1139 /* this must not happen before the currentrow for clear reasons.
1140 so the trick is just to set the current row onto this row */
1142 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1144 /* ok , let us initialize the maxasc and maxdesc value.
1145 * This depends in LaTeX of the font of the last character
1146 * in the paragraph. The hack below is necessary because
1147 * of the possibility of open footnotes */
1149 /* Correction: only the fontsize count. The other properties
1150 are taken from the layoutfont. Nicer on the screen :) */
1152 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1153 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1155 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1156 firstpar->GetLayout());
1158 LyXFont font = GetFont(par, par->Last()-1);
1159 LyXFont::FONT_SIZE size = font.size();
1160 font = GetFont(par, -1);
1163 LyXFont labelfont = GetFont(par, -2);
1165 int maxasc = int(font.maxAscent() *
1166 layout.spacing.getValue() *
1167 parameters->spacing.getValue());
1168 int maxdesc = int(font.maxDescent() *
1169 layout.spacing.getValue() *
1170 parameters->spacing.getValue());
1172 int pos_end = RowLast(row_ptr);
1176 // Check if any insets are larger
1177 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1178 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1179 tmpfont = GetFont(row_ptr->par, pos);
1180 tmpinset = row_ptr->par->GetInset(pos);
1182 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1183 desc = tmpinset->descent(owner_->painter(), tmpfont);
1192 // Check if any custom fonts are larger (Asger)
1193 // This is not completely correct, but we can live with the small,
1194 // cosmetic error for now.
1195 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1197 if (maxsize > font.size()) {
1198 font.setSize(maxsize);
1200 asc = font.maxAscent();
1201 desc = font.maxDescent();
1208 /* table stuff -- begin*/
1209 if (row_ptr->par->table){
1210 // stretch the rows a bit
1214 /* table stuff -- end*/
1216 // This is nicer with box insets:
1220 row_ptr->ascent_of_text = maxasc;
1222 /* is it a top line? */
1223 if (row_ptr->pos == 0
1224 && row_ptr->par == firstpar) {
1226 /* some parksips VERY EASY IMPLEMENTATION */
1227 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1228 if (layout.isParagraph()
1229 && firstpar->GetDepth() == 0
1230 && firstpar->Previous())
1231 maxasc += parameters->getDefSkip().inPixels(owner_);
1232 else if (firstpar->Previous()
1233 && textclasslist.Style(parameters->textclass,
1234 firstpar->Previous()->GetLayout()).isParagraph()
1235 && firstpar->Previous()->GetDepth() == 0)
1236 // is it right to use defskip here too? (AS)
1237 maxasc += parameters->getDefSkip().inPixels(owner_);
1240 /* the paper margins */
1241 if (!row_ptr->par->previous)
1242 maxasc += LYX_PAPER_MARGIN;
1244 /* add the vertical spaces, that the user added */
1245 if (firstpar->added_space_top.kind() != VSpace::NONE)
1246 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1248 /* do not forget the DTP-lines!
1249 * there height depends on the font of the nearest character */
1250 if (firstpar->line_top)
1251 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1253 /* and now the pagebreaks */
1254 if (firstpar->pagebreak_top)
1255 maxasc += 3 * DefaultHeight();
1257 /* this is special code for the chapter, since the label of this
1258 * layout is printed in an extra row */
1259 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1260 && parameters->secnumdepth>= 0) {
1261 labeladdon = int(labelfont.maxDescent() *
1262 layout.spacing.getValue() *
1263 parameters->spacing.getValue())
1264 + int(labelfont.maxAscent() *
1265 layout.spacing.getValue() *
1266 parameters->spacing.getValue());
1269 /* special code for the top label */
1270 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1271 || layout.labeltype == LABEL_BIBLIO
1272 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1273 && row_ptr->par->IsFirstInSequence()
1274 && !row_ptr->par->GetLabestring().empty()) {
1276 (labelfont.maxAscent() *
1277 layout.spacing.getValue() *
1278 parameters->spacing.getValue())
1279 +(labelfont.maxDescent() *
1280 layout.spacing.getValue() *
1281 parameters->spacing.getValue())
1282 + layout.topsep * DefaultHeight()
1283 + layout.labelbottomsep * DefaultHeight());
1286 /* and now the layout spaces, for example before and after a section,
1287 * or between the items of a itemize or enumerate environment */
1289 if (!firstpar->pagebreak_top) {
1290 LyXParagraph * prev = row_ptr->par->Previous();
1292 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1293 if (prev && prev->GetLayout() == firstpar->GetLayout()
1294 && prev->GetDepth() == firstpar->GetDepth()
1295 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1297 layoutasc = (layout.itemsep * DefaultHeight());
1299 else if (row_ptr->previous) {
1300 tmptop = layout.topsep;
1302 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1303 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1306 layoutasc = (tmptop * DefaultHeight());
1308 else if (row_ptr->par->line_top){
1309 tmptop = layout.topsep;
1312 layoutasc = (tmptop * DefaultHeight());
1315 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1317 maxasc += int(textclasslist.Style(parameters->textclass,
1318 prev->GetLayout()).parsep * DefaultHeight());
1321 if (firstpar->Previous()
1322 && firstpar->Previous()->GetDepth() == 0
1323 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1326 else if (firstpar->Previous()){
1327 maxasc += int(layout.parsep * DefaultHeight());
1333 /* is it a bottom line? */
1334 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1335 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1337 /* the paper margins */
1339 maxdesc += LYX_PAPER_MARGIN;
1341 /* add the vertical spaces, that the user added */
1342 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1343 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1345 /* do not forget the DTP-lines!
1346 * there height depends on the font of the nearest character */
1347 if (firstpar->line_bottom)
1348 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1350 /* and now the pagebreaks */
1351 if (firstpar->pagebreak_bottom)
1352 maxdesc += 3 * DefaultHeight();
1354 /* and now the layout spaces, for example before and after a section,
1355 * or between the items of a itemize or enumerate environment */
1356 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1357 LyXParagraph * nextpar = row_ptr->par->Next();
1358 LyXParagraph * comparepar = row_ptr->par;
1362 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1363 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1364 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1365 if (comparepar->GetLayout()!= nextpar->GetLayout()
1366 || nextpar->GetLabelWidthString() !=
1367 comparepar->GetLabelWidthString())
1368 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1370 if (unusual > usual)
1371 layoutdesc = unusual;
1375 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1377 if (comparepar->GetLayout()!= nextpar->GetLayout()
1378 || nextpar->GetLabelWidthString() !=
1379 comparepar->GetLabelWidthString())
1380 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1385 /* incalculate the layout spaces */
1386 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1387 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1389 /* table stuff -- begin*/
1390 if (row_ptr->par->table){
1391 maxasc += row_ptr->par->table->
1392 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1394 /* table stuff -- end*/
1396 /* calculate the new height of the text */
1397 height -= row_ptr->height;
1399 row_ptr->height = maxasc + maxdesc + labeladdon;
1400 row_ptr->baseline = maxasc + labeladdon;
1402 height += row_ptr->height;
1406 /* Appends the implicit specified paragraph behind the specified row,
1407 * start at the implicit given position */
1408 void LyXText::AppendParagraph(Row * row) const
1410 bool not_ready = true;
1412 // The last character position of a paragraph is an invariant so we can
1413 // safely get it here. (Asger)
1414 int lastposition = row->par->Last();
1417 // Get the next breakpoint
1418 int z = NextBreakPoint(row, paperwidth);
1422 // Insert the new row
1423 if (z < lastposition) {
1425 InsertRow(row, row->par, z);
1432 // Set the dimensions of the row
1433 tmprow->fill = Fill(tmprow, paperwidth);
1434 SetHeightOfRow(tmprow);
1436 } while (not_ready);
1440 void LyXText::BreakAgain(Row * row) const
1442 bool not_ready = true;
1445 /* get the next breakpoint */
1446 LyXParagraph::size_type z =
1447 NextBreakPoint(row, paperwidth);
1450 if (z < row->par->Last() ) {
1451 if (!row->next || (row->next && row->next->par != row->par)) {
1454 InsertRow(row, row->par, z);
1461 not_ready = false; // the rest will not change
1467 /* if there are some rows too much, delete them */
1468 /* only if you broke the whole paragraph! */
1469 Row * tmprow2 = row;
1470 while (tmprow2->next && tmprow2->next->par == row->par) {
1471 tmprow2 = tmprow2->next;
1473 while (tmprow2 != row) {
1474 tmprow2 = tmprow2->previous;
1475 RemoveRow(tmprow2->next);
1480 /* set the dimensions of the row */
1481 tmprow->fill = Fill(tmprow, paperwidth);
1482 SetHeightOfRow(tmprow);
1483 } while (not_ready);
1487 /* this is just a little changed version of break again */
1488 void LyXText::BreakAgainOneRow(Row * row)
1490 /* get the next breakpoint */
1491 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1494 if (z < row->par->Last() ) {
1495 if (!row->next || (row->next && row->next->par != row->par)) {
1496 /* insert a new row */
1498 InsertRow(row, row->par, z);
1510 /* if there are some rows too much, delete them */
1511 /* only if you broke the whole paragraph! */
1512 Row * tmprow2 = row;
1513 while (tmprow2->next && tmprow2->next->par == row->par) {
1514 tmprow2 = tmprow2->next;
1516 while (tmprow2 != row) {
1517 tmprow2 = tmprow2->previous;
1518 RemoveRow(tmprow2->next);
1522 /* set the dimensions of the row */
1523 tmprow->fill = Fill(tmprow, paperwidth);
1524 SetHeightOfRow(tmprow);
1528 void LyXText::BreakParagraph(char keep_layout)
1530 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1531 cursor.par->GetLayout());
1533 /* table stuff -- begin */
1534 if (cursor.par->table) {
1535 // breaking of tables is only allowed at the beginning or the end */
1536 if (cursor.pos && cursor.pos < cursor.par->size() &&
1537 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1538 return; // no breaking of tables allowed
1540 /* table stuff -- end */
1542 // this is only allowed, if the current paragraph is not empty or caption
1543 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1545 layout.labeltype!= LABEL_SENSITIVE)
1548 SetUndo(Undo::INSERT,
1549 cursor.par->ParFromPos(cursor.pos)->previous,
1550 cursor.par->ParFromPos(cursor.pos)->next);
1552 /* table stuff -- begin */
1553 if (cursor.par->table) {
1554 int cell = NumberOfCell(cursor.par, cursor.pos);
1555 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1556 SetCursor(cursor.par, cursor.par->text.size());
1558 /* table stuff -- end */
1560 // please break always behind a space
1561 if (cursor.pos < cursor.par->Last()
1562 && cursor.par->IsLineSeparator(cursor.pos))
1565 // break the paragraph
1569 keep_layout = layout.isEnvironment();
1570 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1572 /* table stuff -- begin */
1573 if (cursor.par->table){
1574 // the table should stay with the contents
1576 cursor.par->Next()->table = cursor.par->table;
1577 cursor.par->table = 0;
1580 /* table stuff -- end */
1582 // well this is the caption hack since one caption is really enough
1583 if (layout.labeltype == LABEL_SENSITIVE){
1585 cursor.par->SetLayout(0); // set to standard-layout
1587 cursor.par->Next()->SetLayout(0); // set to standard-layout
1590 /* if the cursor is at the beginning of a row without prior newline,
1592 * This touches only the screen-update. Otherwise we would may have
1593 * an empty row on the screen */
1594 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1595 cursor.row->pos == cursor.pos) {
1599 status = LyXText::NEED_MORE_REFRESH;
1600 refresh_row = cursor.row;
1601 refresh_y = cursor.y - cursor.row->baseline;
1603 // Do not forget the special right address boxes
1604 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1605 while (refresh_row->previous &&
1606 refresh_row->previous->par == refresh_row->par) {
1607 refresh_row = refresh_row->previous;
1608 refresh_y -= refresh_row->height;
1611 RemoveParagraph(cursor.row);
1613 // set the dimensions of the cursor row
1614 cursor.row->fill = Fill(cursor.row, paperwidth);
1616 SetHeightOfRow(cursor.row);
1618 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1619 && cursor.par->Next()->IsNewline(0))
1620 cursor.par->Next()->Erase(0);
1622 InsertParagraph(cursor.par->Next(), cursor.row);
1624 UpdateCounters(cursor.row->previous);
1626 /* This check is necessary. Otherwise the new empty paragraph will
1627 * be deleted automatically. And it is more friendly for the user! */
1629 SetCursor(cursor.par->Next(), 0);
1631 SetCursor(cursor.par, 0);
1633 if (cursor.row->next)
1634 BreakAgain(cursor.row->next);
1640 void LyXText::OpenFootnote()
1642 LyXParagraph * endpar,* tmppar;
1645 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1647 /* if there is no footnote in this paragraph, just return. */
1649 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1652 /* ok, move the cursor right before the footnote */
1654 /* just a little faster than using CursorRight() */
1655 for (cursor.pos = 0;
1656 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1657 /* now the cursor is at the beginning of the physical par */
1658 SetCursor(cursor.par,
1659 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1661 /* the cursor must be exactly before the footnote */
1662 par = cursor.par->ParFromPos(cursor.pos);
1664 status = LyXText::NEED_MORE_REFRESH;
1665 refresh_row = cursor.row;
1666 refresh_y = cursor.y - cursor.row->baseline;
1668 tmppar = cursor.par;
1669 endpar = cursor.par->Next();
1672 tmppar->OpenFootnote(cursor.pos);
1673 RemoveParagraph(row);
1674 /* set the dimensions of the cursor row */
1675 row->fill = Fill(row, paperwidth);
1676 SetHeightOfRow(row);
1677 #warning See comment on top of text.C
1678 tmppar = tmppar->Next();
1680 while (tmppar != endpar) {
1682 InsertParagraph(tmppar, row);
1683 while (row->next && row->next->par == tmppar)
1685 tmppar = tmppar->Next();
1688 SetCursor(par->next, 0);
1689 sel_cursor = cursor;
1693 /* table stuff -- begin*/
1695 void LyXText::TableFeatures(int feature, string const & val) const
1697 if (!cursor.par->table)
1698 return; /* this should never happen */
1700 int actCell = NumberOfCell(cursor.par, cursor.pos);
1701 SetUndo(Undo::FINISH,
1702 cursor.par->ParFromPos(cursor.pos)->previous,
1703 cursor.par->ParFromPos(cursor.pos)->next);
1706 case LyXTable::SET_PWIDTH:
1707 cursor.par->table->SetPWidth(actCell, val);
1709 case LyXTable::SET_SPECIAL_COLUMN:
1710 case LyXTable::SET_SPECIAL_MULTI:
1711 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1720 void LyXText::TableFeatures(int feature) const
1723 int setAlign = LYX_ALIGN_LEFT;
1727 if (!cursor.par->table)
1728 return; /* this should never happen */
1730 int actCell = NumberOfCell(cursor.par, cursor.pos);
1731 SetUndo(Undo::FINISH,
1732 cursor.par->ParFromPos(cursor.pos)->previous,
1733 cursor.par->ParFromPos(cursor.pos)->next);
1736 case LyXTable::ALIGN_LEFT:
1737 setAlign= LYX_ALIGN_LEFT;
1739 case LyXTable::ALIGN_RIGHT:
1740 setAlign= LYX_ALIGN_RIGHT;
1742 case LyXTable::ALIGN_CENTER:
1743 setAlign= LYX_ALIGN_CENTER;
1749 case LyXTable::APPEND_ROW: {
1750 LyXParagraph::size_type pos = cursor.pos;
1752 /* move to the next row */
1753 int cell_org = actCell;
1754 int cell = cell_org;
1756 // if there is a ContRow following this row I have to add
1757 // the row after the ContRow's
1758 if ((pos < cursor.par->Last()) &&
1759 cursor.par->table->RowHasContRow(cell_org)) {
1760 while((pos < cursor.par->Last()) &&
1761 !cursor.par->table->IsContRow(cell)) {
1762 while (pos < cursor.par->Last() &&
1763 !cursor.par->IsNewline(pos))
1765 if (pos < cursor.par->Last())
1769 while((pos < cursor.par->Last()) &&
1770 cursor.par->table->IsContRow(cell)) {
1771 while (pos < cursor.par->Last() &&
1772 !cursor.par->IsNewline(pos))
1774 if (pos < cursor.par->Last())
1779 if (pos < cursor.par->Last())
1782 while (pos < cursor.par->Last() &&
1783 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1784 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1786 if (pos < cursor.par->Last())
1791 /* insert the new cells */
1792 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1793 for (int i = 0; i < number; ++i)
1794 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1796 /* append the row into the table */
1797 cursor.par->table->AppendRow(cell_org);
1801 case LyXTable::APPEND_CONT_ROW: {
1802 LyXParagraph::size_type pos = cursor.pos;
1803 /* move to the next row */
1804 int cell_org = actCell;
1805 int cell = cell_org;
1807 // if there is already a controw but not for this cell
1808 // the AppendContRow sets only the right values but does
1809 // not actually add a row
1810 if (cursor.par->table->RowHasContRow(cell_org) &&
1811 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1812 cursor.par->table->AppendContRow(cell_org);
1816 while (pos < cursor.par->Last() &&
1818 || !cursor.par->table->IsFirstCell(cell))){
1819 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1821 if (pos < cursor.par->Last())
1826 /* insert the new cells */
1827 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1828 for (int i = 0; i < number; ++i)
1829 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1831 /* append the row into the table */
1832 cursor.par->table->AppendContRow(cell_org);
1836 case LyXTable::APPEND_COLUMN: {
1837 LyXParagraph::size_type pos = 0;
1838 int cell_org = actCell;
1841 if (pos && (cursor.par->IsNewline(pos-1))){
1842 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1843 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1844 if (pos <= cursor.pos)
1851 } while (pos <= cursor.par->Last());
1852 /* remember that the very last cell doesn't end with a newline.
1853 This saves one byte memory per table ;-) */
1854 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1855 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1857 /* append the column into the table */
1858 cursor.par->table->AppendColumn(cell_org);
1863 case LyXTable::DELETE_ROW:
1864 if (owner_->the_locking_inset)
1865 owner_->unlockInset(owner_->the_locking_inset);
1866 RemoveTableRow(&cursor);
1870 case LyXTable::DELETE_COLUMN: {
1871 LyXParagraph::size_type pos = 0;
1872 int cell_org = actCell;
1874 if (owner_->the_locking_inset)
1875 owner_->unlockInset(owner_->the_locking_inset);
1877 if (!pos || (cursor.par->IsNewline(pos-1))){
1878 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1880 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1881 cursor.par->Erase(pos);
1882 if (pos < cursor.par->Last())
1883 cursor.par->Erase(pos);
1885 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1886 --pos; // because of pos++ below
1891 } while (pos <= cursor.par->Last());
1893 /* delete the column from the table */
1894 cursor.par->table->DeleteColumn(cell_org);
1896 /* set the cursor to the beginning of the table, where else? */
1901 case LyXTable::TOGGLE_LINE_TOP:
1902 lineSet = !cursor.par->table->TopLine(actCell);
1904 cursor.par->table->SetTopLine(actCell, lineSet);
1906 LyXParagraph::size_type i;
1908 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1909 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1910 cursor.par->table->SetTopLine(n, lineSet);
1918 case LyXTable::TOGGLE_LINE_BOTTOM:
1919 lineSet = !cursor.par->table->BottomLine(actCell);
1921 cursor.par->table->SetBottomLine(actCell, lineSet);
1923 LyXParagraph::size_type i;
1925 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1926 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1927 cursor.par->table->SetBottomLine(n, lineSet);
1935 case LyXTable::TOGGLE_LINE_LEFT:
1936 lineSet = !cursor.par->table->LeftLine(actCell);
1938 cursor.par->table->SetLeftLine(actCell, lineSet);
1940 LyXParagraph::size_type i;
1942 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1943 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1944 cursor.par->table->SetLeftLine(n, lineSet);
1952 case LyXTable::TOGGLE_LINE_RIGHT:
1953 lineSet = !cursor.par->table->RightLine(actCell);
1955 cursor.par->table->SetRightLine(actCell, lineSet);
1958 LyXParagraph::size_type i = sel_start_cursor.pos;
1959 for (; i <= sel_end_cursor.pos; ++i) {
1960 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1961 cursor.par->table->SetRightLine(n, lineSet);
1969 case LyXTable::ALIGN_LEFT:
1970 case LyXTable::ALIGN_RIGHT:
1971 case LyXTable::ALIGN_CENTER:
1973 cursor.par->table->SetAlignment(actCell, setAlign);
1976 LyXParagraph::size_type i = sel_start_cursor.pos;
1977 for (; i <= sel_end_cursor.pos; ++i) {
1978 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1979 cursor.par->table->SetAlignment(n, setAlign);
1987 case LyXTable::DELETE_TABLE:
1988 SetCursorIntern(cursor.par, 0);
1989 delete cursor.par->table;
1990 cursor.par->table = 0;
1991 // temporary: Should put table in simple_cut_buffer (with before and after
1992 // dummy-paragraph !!
1993 // not necessar anymore with UNDO :)
1994 for (LyXParagraph::size_type i =
1995 cursor.par->text.size() - 1; i >= 0; --i)
1996 cursor.par->Erase(i);
2000 case LyXTable::MULTICOLUMN: {
2002 // check wether we are completly in a multicol
2003 int multicol = cursor.par->table->IsMultiColumn(actCell);
2004 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2005 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2006 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2010 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2011 LyXParagraph::size_type pos = cursor.pos;
2012 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2014 for (; newlines; --newlines)
2015 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2020 // selection must be in one row (or no selection)
2022 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2029 if (sel_start_cursor.row == sel_end_cursor.row){
2030 LyXParagraph::size_type i;
2032 for (i = sel_start_cursor.pos;
2033 i < sel_end_cursor.pos; ++i){
2034 if (sel_start_cursor.par->IsNewline(i)){
2035 sel_start_cursor.par->Erase(i);
2036 // check for double-blanks
2037 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2039 (i < sel_start_cursor.par->Last()
2040 && !sel_start_cursor.par->IsLineSeparator(i)))
2041 sel_start_cursor.par->InsertChar(i, ' ');
2043 sel_end_cursor.pos--;
2050 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2051 sel_start_cursor.pos),
2053 cursor.pos = sel_start_cursor.pos;
2058 WriteAlert(_("Impossible Operation!"),
2059 _("Multicolumns can only be horizontally."),
2066 case LyXTable::SET_ALL_LINES:
2068 case LyXTable::UNSET_ALL_LINES:
2070 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2074 LyXParagraph::size_type i;
2076 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2077 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2078 cursor.par->table->SetAllLines(n, setLines);
2085 case LyXTable::SET_LONGTABLE:
2086 cursor.par->table->SetLongTable(true);
2088 case LyXTable::UNSET_LONGTABLE:
2089 cursor.par->table->SetLongTable(false);
2091 case LyXTable::SET_ROTATE_TABLE:
2092 cursor.par->table->SetRotateTable(true);
2094 case LyXTable::UNSET_ROTATE_TABLE:
2095 cursor.par->table->SetRotateTable(false);
2097 case LyXTable::SET_ROTATE_CELL:
2099 cursor.par->table->SetRotateCell(actCell, true);
2101 LyXParagraph::size_type i;
2103 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2104 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2105 cursor.par->table->SetRotateCell(n, true);
2111 case LyXTable::UNSET_ROTATE_CELL:
2113 cursor.par->table->SetRotateCell(actCell, false);
2116 LyXParagraph::size_type i = sel_start_cursor.pos;
2117 for (; i <= sel_end_cursor.pos; ++i) {
2118 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2119 cursor.par->table->SetRotateCell(n, false);
2125 case LyXTable::SET_LINEBREAKS:
2126 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2128 cursor.par->table->SetLinebreaks(actCell, what);
2130 LyXParagraph::size_type i;
2132 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2133 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2134 cursor.par->table->SetLinebreaks(n, what);
2140 case LyXTable::SET_LTFIRSTHEAD:
2141 cursor.par->table->SetLTHead(actCell, true);
2143 case LyXTable::SET_LTHEAD:
2144 cursor.par->table->SetLTHead(actCell, false);
2146 case LyXTable::SET_LTFOOT:
2147 cursor.par->table->SetLTFoot(actCell, false);
2149 case LyXTable::SET_LTLASTFOOT:
2150 cursor.par->table->SetLTFoot(actCell, true);
2152 case LyXTable::SET_LTNEWPAGE:
2153 what = !cursor.par->table->LTNewPage(actCell);
2154 cursor.par->table->SetLTNewPage(actCell, what);
2160 void LyXText::InsertCharInTable(char c)
2165 bool jumped_over_space;
2167 /* first check, if there will be two blanks together or a blank at
2168 * the beginning of a paragraph.
2169 * I decided to handle blanks like normal characters, the main
2170 * difference are the special checks when calculating the row.fill
2171 * (blank does not count at the end of a row) and the check here */
2173 LyXFont realtmpfont = real_current_font;
2174 LyXFont rawtmpfont = current_font; /* store the current font.
2175 * This is because of the use
2176 * of cursor movements. The moving
2177 * cursor would refresh the
2180 // Get the font that is used to calculate the baselineskip
2181 LyXParagraph::size_type const lastpos =
2183 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2185 jumped_over_space = false;
2186 if (IsLineSeparatorChar(c)) {
2188 #ifndef FIX_DOUBLE_SPACE
2189 /* avoid double blanks but insert the new blank because
2190 * of a possible font change */
2191 if (cursor.pos < lastpos &&
2192 cursor.par->IsLineSeparator(cursor.pos)) {
2193 cursor.par->Erase(cursor.pos);
2194 jumped_over_space = true;
2197 if ((cursor.pos > 0 &&
2198 cursor.par->IsLineSeparator(cursor.pos - 1))
2199 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2200 || (cursor.pos == 0 &&
2201 !(cursor.par->Previous()
2202 && cursor.par->Previous()->footnoteflag
2203 == LyXParagraph::OPEN_FOOTNOTE)))
2205 } else if (IsNewlineChar(c)) {
2206 if (!IsEmptyTableCell()) {
2207 TableFeatures(LyXTable::APPEND_CONT_ROW);
2214 y = cursor.y - row->baseline;
2215 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2216 * already inserted the character */
2217 cursor.par->InsertChar(cursor.pos, c);
2218 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2220 if (!jumped_over_space) {
2221 /* refresh the positions */
2223 while (tmprow->next && tmprow->next->par == row->par) {
2224 tmprow = tmprow->next;
2231 CheckParagraphInTable(cursor.par, cursor.pos);
2233 current_font = rawtmpfont;
2234 real_current_font = realtmpfont;
2236 /* check, whether the last character's font has changed. */
2237 if (cursor.pos && cursor.pos == cursor.par->Last()
2238 && rawparfont != rawtmpfont)
2239 RedoHeightOfParagraph(cursor);
2243 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2244 LyXParagraph::size_type pos)
2247 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2248 par->GetInset(pos) && par->GetInset(pos)->display()){
2249 par->GetInset(pos)->display(false);
2253 Row * row = GetRow(par, pos, y);
2255 int tmpheight = row->height;
2256 SetHeightOfRow(row);
2258 LyXParagraph::size_type tmp_pos = pos;
2259 /* update the table information */
2260 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2262 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2263 WidthOfCell(par, tmp_pos))) {
2264 LyXCursor tmpcursor = cursor;
2265 SetCursorIntern(par, pos);
2266 /* make a complete redraw */
2267 RedoDrawingOfParagraph(cursor);
2271 /* redraw only the row */
2272 LyXCursor tmpcursor = cursor;
2273 SetCursorIntern(par, pos);
2274 #warning See comment on top of text.C
2276 refresh_x = cursor.x;
2278 refresh_pos = cursor.pos;
2281 if (tmpheight == row->height)
2282 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2284 status = LyXText::NEED_MORE_REFRESH;
2286 SetCursorIntern(cursor.par, cursor.pos);
2290 void LyXText::BackspaceInTable()
2292 Row * tmprow, * row;
2295 LyXFont rawtmpfont = current_font;
2296 LyXFont realtmpfont = real_current_font;
2298 // Get the font that is used to calculate the baselineskip
2299 int const lastpos = cursor.par->Last();
2300 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2302 if (cursor.pos == 0) {
2303 /* no pasting of table paragraphs */
2307 /* this is the code for a normal backspace, not pasting
2309 SetUndo(Undo::DELETE,
2310 cursor.par->ParFromPos(cursor.pos)->previous,
2311 cursor.par->ParFromPos(cursor.pos)->next);
2315 /* some insets are undeletable here */
2316 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2317 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2322 y = cursor.y - row->baseline;
2324 /* some special code when deleting a newline. */
2325 if (cursor.par->IsNewline(cursor.pos)) {
2330 cursor.par->Erase(cursor.pos);
2332 /* refresh the positions */
2334 while (tmprow->next && tmprow->next->par == row->par) {
2335 tmprow = tmprow->next;
2339 #ifndef FIX_DOUBLE_SPACE
2340 /* delete superfluous blanks */
2341 if (cursor.pos < cursor.par->Last() - 1 &&
2342 (cursor.par->IsLineSeparator(cursor.pos))) {
2344 if (cursor.pos == BeginningOfMainBody(cursor.par)
2346 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2347 cursor.par->Erase(cursor.pos);
2348 /* refresh the positions */
2350 while (tmprow->next &&
2351 tmprow->next->par == row->par) {
2352 tmprow = tmprow->next;
2355 if (cursor.pos) /* move one character left */
2362 CheckParagraphInTable(cursor.par, cursor.pos);
2364 /* check, wether the last characters font has changed. */
2365 if (cursor.pos && cursor.pos == cursor.par->Last()
2366 && rawparfont != rawtmpfont)
2367 RedoHeightOfParagraph(cursor);
2369 /* restore the current font
2370 * That is what a user expects! */
2371 current_font = rawtmpfont;
2372 real_current_font = realtmpfont;
2374 SetCursorIntern(cursor.par, cursor.pos);
2377 /* table stuff -- end*/
2380 /* just a macro to make some thing easier. */
2381 void LyXText::RedoParagraph() const
2384 // I suspect this version will work
2387 RedoParagraphs(cursor, cursor.par->Next());
2388 SetCursorIntern(cursor.par, cursor.pos);
2390 LyXCursor tmpcursor = cursor;
2392 RedoParagraphs(cursor, cursor.par->Next());
2393 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2398 /* insert a character, moves all the following breaks in the
2399 * same Paragraph one to the right and make a rebreak */
2400 void LyXText::InsertChar(char c)
2402 SetUndo(Undo::INSERT,
2403 cursor.par->ParFromPos(cursor.pos)->previous,
2404 cursor.par->ParFromPos(cursor.pos)->next);
2406 /* When the free-spacing option is set for the current layout,
2407 * disable the double-space checking */
2410 textclasslist.Style(parameters->textclass,
2411 cursor.row->par->GetLayout()).free_spacing;
2413 /* table stuff -- begin*/
2414 if (cursor.par->table) {
2415 InsertCharInTable(c);
2419 /* table stuff -- end*/
2421 /* First check, if there will be two blanks together or a blank at
2422 the beginning of a paragraph.
2423 I decided to handle blanks like normal characters, the main
2424 difference are the special checks when calculating the row.fill
2425 (blank does not count at the end of a row) and the check here */
2427 // The bug is triggered when we type in a description environment:
2428 // The current_font is not changed when we go from label to main text
2429 // and it should (along with realtmpfont) when we type the space.
2430 #ifdef WITH_WARNINGS
2431 #warning There is a bug here! (Asger)
2434 LyXFont realtmpfont = real_current_font;
2435 LyXFont rawtmpfont = current_font; /* store the current font.
2436 * This is because of the use
2437 * of cursor movements. The moving
2438 * cursor would refresh the
2441 // Get the font that is used to calculate the baselineskip
2442 LyXParagraph::size_type lastpos = cursor.par->Last();
2443 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2445 bool jumped_over_space = false;
2447 if (!freeSpacing && IsLineSeparatorChar(c)) {
2448 #ifndef FIX_DOUBLE_SPACE
2449 if (cursor.pos < lastpos
2450 && cursor.par->IsLineSeparator(cursor.pos)) {
2451 /* the user inserted a space before a space. So we
2452 * will just make a CursorRight. BUT: The font of this
2453 * space should be set to current font. That is why
2454 * we need to rebreak perhaps. If there is a protected
2455 * blank at the end of a row we have to force
2458 owner_->owner()->getMiniBuffer()
2459 ->Set(_("You cannot type two spaces this way. "
2460 " Please read the Tutorial."));
2462 // How can this ever happen?
2463 if (cursor.pos == RowLast(cursor.row)
2464 && !IsLineSeparatorChar(c))
2465 cursor.row->fill = -1; // force rebreak
2466 cursor.par->Erase(cursor.pos);
2467 jumped_over_space = true;
2469 // Seems to me that this works just as well.
2477 && cursor.par->IsLineSeparator(cursor.pos - 1))
2479 && cursor.par->IsNewline(cursor.pos - 1))
2481 && !(cursor.par->Previous()
2482 && cursor.par->Previous()->footnoteflag
2483 == LyXParagraph::OPEN_FOOTNOTE))) {
2484 if (cursor.pos == 0 )
2485 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2487 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2491 } else if (IsNewlineChar(c)) {
2492 if (cursor.par->FirstPhysicalPar() == cursor.par
2493 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2497 /* No newline at first position
2498 * of a paragraph or behind labels.
2499 * TeX does not allow that. */
2501 if (cursor.pos < cursor.par->Last() &&
2502 cursor.par->IsLineSeparator(cursor.pos))
2503 CursorRightIntern(); // newline always after a blank!
2504 cursor.row->fill = -1; // to force a new break
2507 // the display inset stuff
2508 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2509 && cursor.row->par->GetInset(cursor.row->pos)
2510 && cursor.row->par->GetInset(cursor.row->pos)->display())
2511 cursor.row->fill = -1; // to force a new break
2513 // get the cursor row fist
2514 Row * row = cursor.row;
2515 long y = cursor.y - row->baseline;
2516 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2517 * already insertet the character */
2518 cursor.par->InsertChar(cursor.pos, c);
2519 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2521 if (!jumped_over_space) {
2522 // refresh the positions
2524 while (tmprow->next && tmprow->next->par == row->par) {
2525 tmprow = tmprow->next;
2530 // Is there a break one row above
2531 if ((cursor.par->IsLineSeparator(cursor.pos)
2532 || cursor.par->IsNewline(cursor.pos)
2533 || cursor.row->fill == -1)
2534 && row->previous && row->previous->par == row->par) {
2535 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2537 if ( z >= row->pos) {
2540 // set the dimensions of the row above
2541 row->previous->fill = Fill(row->previous, paperwidth);
2543 SetHeightOfRow(row->previous);
2545 y -= row->previous->height;
2547 refresh_row = row->previous;
2548 status = LyXText::NEED_MORE_REFRESH;
2550 BreakAgainOneRow(row);
2552 current_font = rawtmpfont;
2553 real_current_font = realtmpfont;
2554 SetCursor(cursor.par, cursor.pos + 1, false);
2555 /* cursor MUST be in row now */
2557 if (row->next && row->next->par == row->par)
2558 need_break_row = row->next;
2562 // check, wether the last characters font has changed.
2563 if (cursor.pos && cursor.pos == cursor.par->Last()
2564 && rawparfont != rawtmpfont)
2565 RedoHeightOfParagraph(cursor);
2572 /* recalculate the fill of the row */
2573 if (row->fill >= 0) /* needed because a newline
2574 * will set fill to -1. Otherwise
2575 * we would not get a rebreak! */
2576 row->fill = Fill(row, paperwidth);
2577 if (row->fill < 0 ) {
2580 refresh_x = cursor.x;
2581 refresh_pos = cursor.pos;
2582 status = LyXText::NEED_MORE_REFRESH;
2583 BreakAgainOneRow(row);
2584 /* will the cursor be in another row now? */
2585 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2586 if (row->next && row->next->par == row->par)
2590 BreakAgainOneRow(row);
2592 current_font = rawtmpfont;
2593 real_current_font = realtmpfont;
2594 SetCursor(cursor.par, cursor.pos + 1, false);
2595 if (row->next && row->next->par == row->par)
2596 need_break_row = row->next;
2601 refresh_x = cursor.x;
2603 refresh_pos = cursor.pos;
2605 int tmpheight = row->height;
2606 SetHeightOfRow(row);
2607 if (tmpheight == row->height)
2608 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2610 status = LyXText::NEED_MORE_REFRESH;
2612 current_font = rawtmpfont;
2613 real_current_font = realtmpfont;
2614 SetCursor(cursor.par, cursor.pos + 1, false);
2617 /* check, wether the last characters font has changed. */
2618 if (cursor.pos && cursor.pos == cursor.par->Last()
2619 && rawparfont != rawtmpfont) {
2620 RedoHeightOfParagraph(cursor);
2622 /* now the special right address boxes */
2623 if (textclasslist.Style(parameters->textclass,
2624 cursor.par->GetLayout()).margintype
2625 == MARGIN_RIGHT_ADDRESS_BOX) {
2626 RedoDrawingOfParagraph(cursor);
2634 void LyXText::charInserted()
2636 // Here we could call FinishUndo for every 20 characters inserted.
2637 // This is from my experience how emacs does it.
2638 static unsigned int counter = 0;
2647 void LyXText::PrepareToPrint(Row * row, float & x,
2648 float & fill_separator,
2650 float & fill_label_hfill,
2655 float w = row->fill;
2657 fill_label_hfill = 0;
2659 fill_label_hfill = 0;
2661 LyXDirection direction = row->par->getParDirection();
2663 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2664 x = RightMargin(row);
2665 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2666 LyXFont font(LyXFont::ALL_SANE);
2667 font.setSize(LyXFont::SIZE_SMALL);
2668 x += font.textWidth("Mwide-figM", 10);
2672 x = LeftMargin(row);
2674 /* is there a manual margin with a manual label */
2675 if (textclasslist.Style(parameters->textclass,
2676 row->par->GetLayout()).margintype == MARGIN_MANUAL
2677 && textclasslist.Style(parameters->textclass,
2678 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2680 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2681 * are left aligned*/
2682 if (nlh && !row->par->GetLabelWidthString().empty()) {
2683 fill_label_hfill = LabelFill(row) / nlh;
2687 /* are there any hfills in the row? */
2688 nh = NumberOfHfills(row);
2690 /* table stuff -- begin*/
2691 if (row->par->table) {
2692 w = paperwidth - row->par->table->WidthOfTable()
2693 - x - RightMargin(row);
2694 nh = 0; /* ignore hfills in tables */
2696 /* table stuff -- end*/
2701 /* is it block, flushleft or flushright?
2702 * set x how you need it */
2704 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2705 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2707 align = row->par->FirstPhysicalPar()->align;
2709 /* center displayed insets */
2710 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2711 && row->par->GetInset(row->pos)
2712 && row->par->GetInset(row->pos)->display())
2713 align = LYX_ALIGN_CENTER;
2716 case LYX_ALIGN_BLOCK:
2717 ns = NumberOfSeparators(row);
2718 if (ns && row->next && row->next->par == row->par &&
2719 !(row->next->par->IsNewline(row->next->pos-1))
2720 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2721 && row->next->par->GetInset(row->next->pos)
2722 && row->next->par->GetInset(row->next->pos)->display())
2724 fill_separator = w / ns;
2725 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2728 case LYX_ALIGN_RIGHT:
2731 case LYX_ALIGN_CENTER:
2739 ComputeBidiTables(row);
2740 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2741 LyXParagraph::size_type main_body =
2742 BeginningOfMainBody(row->par);
2743 LyXParagraph::size_type last = RowLast(row);
2745 if (row->pos <= last
2747 && last != vis2log(last)
2748 && row->par->IsLineSeparator(last)) {
2749 if (!(main_body > 0 && main_body-1 == last))
2750 x -= fill_separator+SingleWidth(row->par,last);
2751 } else if (main_body > 0 &&
2752 (main_body-1 > last ||
2753 !row->par->IsLineSeparator(main_body-1))) {
2754 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2755 row->par->GetLayout());
2756 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2757 if (main_body-1 <= last)
2758 x += fill_label_hfill;
2763 /* important for the screen */
2766 /* the cursor set functions have a special mechanism. When they
2767 * realize, that you left an empty paragraph, they will delete it.
2768 * They also delete the corresponding row */
2770 void LyXText::CursorRightOneWord() const
2772 // treat floats, HFills and Insets as words
2773 LyXCursor tmpcursor = cursor;
2774 #warning See comment on top of text.C
2776 if (tmpcursor.pos == tmpcursor.par->Last()
2777 && tmpcursor.par->Next())
2779 tmpcursor.par = tmpcursor.par->Next();
2784 // Skip through initial nonword stuff.
2785 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2786 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2788 // printf("Current pos1 %d", tmpcursor.pos) ;
2792 // Advance through word.
2793 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2794 tmpcursor.par->IsWord( tmpcursor.pos ) )
2796 // printf("Current pos2 %d", tmpcursor.pos) ;
2801 SetCursor(tmpcursor.par, tmpcursor.pos);
2805 void LyXText::CursorTab() const
2807 if (cursor.par->table) {
2808 int cell = NumberOfCell(cursor.par, cursor.pos);
2809 while(cursor.par->table->IsContRow(cell)) {
2811 cell = NumberOfCell(cursor.par, cursor.pos);
2813 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2814 TableFeatures(LyXTable::APPEND_ROW);
2816 LyXCursor tmpcursor = cursor;
2817 while (tmpcursor.pos < tmpcursor.par->Last()
2818 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2821 if (tmpcursor.pos == tmpcursor.par->Last()){
2822 if (tmpcursor.par->Next()) {
2823 tmpcursor.par = tmpcursor.par->Next();
2829 SetCursor(tmpcursor.par, tmpcursor.pos);
2830 if (cursor.par->table) {
2831 int cell = NumberOfCell(cursor.par, cursor.pos);
2832 while (cursor.par->table->IsContRow(cell) &&
2833 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2835 while (tmpcursor.pos < tmpcursor.par->Last()
2836 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2839 if (tmpcursor.pos == tmpcursor.par->Last()){
2840 if (tmpcursor.par->Next()) {
2841 tmpcursor.par = tmpcursor.par->Next();
2847 SetCursor(tmpcursor.par, tmpcursor.pos);
2848 cell = NumberOfCell(cursor.par, cursor.pos);
2854 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2855 of prior word, not to end of next prior word. */
2857 void LyXText::CursorLeftOneWord() const
2859 // treat HFills, floats and Insets as words
2860 LyXCursor tmpcursor = cursor;
2861 while (tmpcursor.pos
2862 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2863 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2864 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2865 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2866 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2870 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2871 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2872 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2874 } else if (!tmpcursor.pos) {
2875 if (tmpcursor.par->Previous()){
2876 tmpcursor.par = tmpcursor.par->Previous();
2877 tmpcursor.pos = tmpcursor.par->Last();
2879 } else { // Here, tmpcursor != 0
2880 while (tmpcursor.pos > 0 &&
2881 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2884 SetCursor(tmpcursor.par, tmpcursor.pos);
2887 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2890 void LyXText::SelectWord()
2892 /* Move cursor to the beginning, when not already there. */
2894 && !cursor.par->IsSeparator(cursor.pos-1)
2895 && !cursor.par->IsKomma(cursor.pos-1) )
2896 CursorLeftOneWord();
2898 /* set the sel cursor */
2899 sel_cursor = cursor;
2901 while ( cursor.pos < cursor.par->Last()
2902 && !cursor.par->IsSeparator(cursor.pos)
2903 && !cursor.par->IsKomma(cursor.pos) )
2905 SetCursor( cursor.par, cursor.pos );
2907 /* finally set the selection */
2912 /* -------> Select the word currently under the cursor when:
2913 1: no selection is currently set,
2914 2: the cursor is not at the borders of the word. */
2916 int LyXText::SelectWordWhenUnderCursor()
2918 if ( selection ) return 0;
2919 if ( cursor.pos < cursor.par->Last()
2920 && !cursor.par->IsSeparator(cursor.pos)
2921 && !cursor.par->IsKomma(cursor.pos)
2923 && !cursor.par->IsSeparator(cursor.pos -1)
2924 && !cursor.par->IsKomma(cursor.pos -1) ) {
2932 // This function is only used by the spellchecker for NextWord().
2933 // It doesn't handle LYX_ACCENTs and probably never will.
2934 char * LyXText::SelectNextWord(float & value)
2936 LyXParagraph * tmppar = cursor.par;
2938 // If this is not the very first word, skip rest of
2939 // current word because we are probably in the middle
2940 // of a word if there is text here.
2941 if (cursor.pos || cursor.par->previous) {
2942 while (cursor.pos < cursor.par->Last()
2943 && cursor.par->IsLetter(cursor.pos))
2946 // Now, skip until we have real text (will jump paragraphs)
2947 while ((cursor.par->Last() > cursor.pos
2948 && (!cursor.par->IsLetter(cursor.pos)
2949 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2950 || (cursor.par->Last() == cursor.pos
2951 && cursor.par->Next())){
2952 if (cursor.pos == cursor.par->Last()) {
2953 cursor.par = cursor.par->Next();
2960 // Update the value if we changed paragraphs
2961 if (cursor.par != tmppar){
2962 SetCursor(cursor.par, cursor.pos);
2963 value = float(cursor.y)/float(height);
2966 /* Start the selection from here */
2967 sel_cursor = cursor;
2970 ostringstream latex;
2974 /* and find the end of the word
2975 (optional hyphens are part of a word) */
2976 while (cursor.pos < cursor.par->Last()
2977 && (cursor.par->IsLetter(cursor.pos))
2978 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
2979 && cursor.par->GetInset(cursor.pos) != 0
2980 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
2982 && latex.str() == "\\-"
2984 && string(latex.str(), 3) == "\\-" // this is not nice at all
2989 #ifndef HAVE_SSTREAM
2990 delete [] latex.str();
2992 // Finally, we copy the word to a string and return it
2995 if (sel_cursor.pos < cursor.pos) {
2996 str = new char [cursor.pos - sel_cursor.pos + 2];
2997 LyXParagraph::size_type i, j;
2998 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2999 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3000 str[j++] = cursor.par->GetChar(i);
3008 // This one is also only for the spellchecker
3009 void LyXText::SelectSelectedWord()
3011 /* move cursor to the beginning */
3012 SetCursor(sel_cursor.par, sel_cursor.pos);
3014 /* set the sel cursor */
3015 sel_cursor = cursor;
3018 ostringstream latex;
3023 /* now find the end of the word */
3024 while (cursor.pos < cursor.par->Last()
3025 && (cursor.par->IsLetter(cursor.pos)
3026 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3027 && cursor.par->GetInset(cursor.pos) != 0
3028 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
3030 && latex.str() == "\\-"
3032 && string(latex.str(), 3) == "\\-"
3037 #ifndef HAVE_SSTREAM
3038 delete [] latex.str();
3040 SetCursor(cursor.par, cursor.pos);
3042 /* finally set the selection */
3047 /* -------> Delete from cursor up to the end of the current or next word. */
3048 void LyXText::DeleteWordForward()
3050 LyXCursor tmpcursor = cursor;
3052 if (!cursor.par->Last())
3054 #warning See comment on top of text.C
3056 /* -------> Skip initial non-word stuff. */
3057 while ( cursor.pos < cursor.par->Last()
3058 && (cursor.par->IsSeparator(cursor.pos)
3059 || cursor.par->IsKomma(cursor.pos)) )
3062 SetCursorIntern(cursor.par, cursor.pos);
3063 selection = True; // to avoid deletion
3064 CursorRightOneWord();
3065 sel_cursor = cursor;
3069 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3075 /* -------> Delete from cursor to start of current or prior word. */
3076 void LyXText::DeleteWordBackward()
3078 LyXCursor tmpcursor = cursor;
3079 if (!cursor.par->Last())
3081 #warning See comment on top of text.C
3083 selection = true; // to avoid deletion
3084 CursorLeftOneWord();
3085 sel_cursor = cursor;
3093 /* -------> Kill to end of line. */
3094 void LyXText::DeleteLineForward()
3096 LyXCursor tmpcursor = cursor;
3097 if (!cursor.par->Last())
3099 #warning See comment on top of text.C
3102 sel_cursor = cursor;
3105 if (selection == false) {
3106 DeleteWordForward();
3114 // Change the case of a word at cursor position. The meaning of action
3116 // 0 change to lowercase
3117 // 1 capitalize word
3118 // 2 change to uppercase
3119 // This function directly manipulates LyXParagraph::text because there
3120 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3121 // that it is correct. I guess part of it should be moved to
3122 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3123 // it does not access outside of the allocated array as the older
3124 // version did. (JMarc)
3125 void LyXText::ChangeWordCase(LyXText::TextCase action)
3127 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3129 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3131 LyXParagraph::size_type tmppos =
3132 cursor.par->PositionInParFromPos(cursor.pos);
3133 while (tmppos < tmppar->size()) {
3134 unsigned char c = tmppar->text[tmppos];
3135 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3137 if (c != LyXParagraph::META_INSET) {
3139 case text_lowercase:
3142 case text_capitalization:
3144 action = text_lowercase;
3146 case text_uppercase:
3152 tmppar->text[tmppos] = c;
3155 CheckParagraph(tmppar, tmppos);
3156 CursorRightOneWord();
3160 void LyXText::Delete()
3162 // this is a very easy implementation
3164 LyXCursor old_cursor = cursor;
3165 int old_cur_par_id = old_cursor.par->id();
3166 int old_cur_par_prev_id = old_cursor.par->previous ?
3167 old_cursor.par->previous->id() : 0;
3169 // just move to the right
3170 CursorRightIntern();
3172 #warning Look at the comment here.
3173 // This check is not very good...
3174 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3175 // and that can very well delete the par or par->previous in
3176 // old_cursor. Will a solution where we compare paragraph id's
3179 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3180 == old_cur_par_prev_id
3181 && cursor.par->id() != old_cur_par_id)
3182 return; // delete-empty-paragraph-mechanism has done it
3184 if (cursor.par->previous == old_cursor.par->previous
3185 && cursor.par != old_cursor.par)
3186 return; // delete-empty-paragraph-mechanism has done it
3188 // if you had success make a backspace
3189 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3190 LyXCursor tmpcursor = cursor;
3191 cursor = old_cursor; // to make sure undo gets the right cursor position
3192 SetUndo(Undo::DELETE,
3193 cursor.par->ParFromPos(cursor.pos)->previous,
3194 cursor.par->ParFromPos(cursor.pos)->next);
3201 void LyXText::Backspace()
3203 LyXParagraph * tmppar;
3204 Row * tmprow, * row;
3208 /* table stuff -- begin */
3209 if (cursor.par->table) {
3213 /* table stuff -- end */
3215 LyXFont rawtmpfont = current_font;
3216 LyXFont realtmpfont = real_current_font;
3218 // Get the font that is used to calculate the baselineskip
3219 int const lastpos = cursor.par->Last();
3220 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3222 if (cursor.pos == 0) {
3223 // we may paste some paragraphs
3225 // is it an empty paragraph?
3228 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3229 && !(cursor.par->Next()
3230 && cursor.par->footnoteflag ==
3231 LyXParagraph::NO_FOOTNOTE
3232 && cursor.par->Next()->footnoteflag ==
3233 LyXParagraph::OPEN_FOOTNOTE)) {
3235 if (cursor.par->previous) {
3236 tmppar = cursor.par->previous->FirstPhysicalPar();
3237 if (cursor.par->GetLayout() == tmppar->GetLayout()
3238 && cursor.par->footnoteflag == tmppar->footnoteflag
3239 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3241 tmppar->line_bottom = cursor.par->line_bottom;
3242 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3243 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3248 // the layout things can change the height of a row !
3249 tmpheight = cursor.row->height;
3250 SetHeightOfRow(cursor.row);
3251 if (cursor.row->height != tmpheight) {
3252 refresh_y = cursor.y - cursor.row->baseline;
3253 refresh_row = cursor.row;
3254 status = LyXText::NEED_MORE_REFRESH;
3259 if (cursor.par->ParFromPos(cursor.pos)->previous){
3260 SetUndo(Undo::DELETE,
3261 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3262 cursor.par->ParFromPos(cursor.pos)->next);
3264 tmppar = cursor.par;
3265 tmprow = cursor.row;
3267 #warning See comment on top of text.C
3268 /* Pasting is not allowed, if the paragraphs have different
3269 layout. I think it is a real bug of all other
3270 word processors to allow it. It confuses the user.
3271 Even so with a footnote paragraph and a non-footnote
3272 paragraph. I will not allow pasting in this case,
3273 because the user would be confused if the footnote behaves
3274 different wether it is open or closed.
3276 Correction: Pasting is always allowed with standard-layout
3278 if (cursor.par != tmppar
3279 && (cursor.par->GetLayout() == tmppar->GetLayout()
3280 || !tmppar->GetLayout())
3281 && cursor.par->footnoteflag == tmppar->footnoteflag
3282 /* table stuff -- begin*/
3283 && !cursor.par->table /* no pasting of tables */
3284 /* table stuff -- end*/
3285 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3287 cursor.par->PasteParagraph();
3290 cursor.par->IsSeparator(cursor.pos - 1)))
3291 cursor.par->InsertChar(cursor.pos, ' ');
3296 status = LyXText::NEED_MORE_REFRESH;
3297 refresh_row = cursor.row;
3298 refresh_y = cursor.y - cursor.row->baseline;
3300 // remove the lost paragraph
3301 RemoveParagraph(tmprow);
3304 AppendParagraph(cursor.row);
3305 UpdateCounters(cursor.row);
3307 // the row may have changed, block, hfills etc.
3308 SetCursor(cursor.par, cursor.pos);
3311 /* this is the code for a normal backspace, not pasting
3313 SetUndo(Undo::DELETE,
3314 cursor.par->ParFromPos(cursor.pos)->previous,
3315 cursor.par->ParFromPos(cursor.pos)->next);
3318 // some insets are undeletable here
3319 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3320 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3322 // force complete redo when erasing display insets
3323 // this is a cruel mathod but save..... Matthias
3324 if (cursor.par->GetInset(cursor.pos)->display()){
3325 cursor.par->Erase(cursor.pos);
3332 y = cursor.y - row->baseline;
3333 LyXParagraph::size_type z;
3334 /* remember that a space at the end of a row doesnt count
3335 * when calculating the fill */
3336 if (cursor.pos < RowLast(row) ||
3337 !cursor.par->IsLineSeparator(cursor.pos)) {
3338 row->fill += SingleWidth(cursor.par, cursor.pos);
3341 /* some special code when deleting a newline. This is similar
3342 * to the behavior when pasting paragraphs */
3343 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3344 cursor.par->Erase(cursor.pos);
3345 // refresh the positions
3347 while (tmprow->next && tmprow->next->par == row->par) {
3348 tmprow = tmprow->next;
3351 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3354 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3355 cursor.par->InsertChar(cursor.pos, ' ');
3356 // refresh the positions
3358 while (tmprow->next && tmprow->next->par == row->par) {
3359 tmprow = tmprow->next;
3364 cursor.par->Erase(cursor.pos);
3366 // refresh the positions
3368 while (tmprow->next && tmprow->next->par == row->par) {
3369 tmprow = tmprow->next;
3373 #ifndef FIX_DOUBLE_SPACE
3374 // delete superfluous blanks
3375 if (cursor.pos < cursor.par->Last() - 1 &&
3376 (cursor.par->IsLineSeparator(cursor.pos))) {
3378 if (cursor.pos == BeginningOfMainBody(cursor.par)
3380 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3381 cursor.par->Erase(cursor.pos);
3382 // refresh the positions
3384 while (tmprow->next &&
3385 tmprow->next->par == row->par) {
3386 tmprow = tmprow->next;
3389 if (cursor.pos) // move one character left
3395 // delete newlines at the beginning of paragraphs
3396 while (cursor.par->Last() &&
3397 cursor.par->IsNewline(cursor.pos) &&
3398 cursor.pos == BeginningOfMainBody(cursor.par)) {
3399 cursor.par->Erase(cursor.pos);
3400 // refresh the positions
3402 while (tmprow->next &&
3403 tmprow->next->par == row->par) {
3404 tmprow = tmprow->next;
3410 // is there a break one row above
3411 if (row->previous && row->previous->par == row->par) {
3412 z = NextBreakPoint(row->previous, paperwidth);
3413 if ( z >= row->pos) {
3416 tmprow = row->previous;
3418 // maybe the current row is now empty
3419 if (row->pos >= row->par->Last()) {
3424 BreakAgainOneRow(row);
3425 if (row->next && row->next->par == row->par)
3426 need_break_row = row->next;
3431 // set the dimensions of the row above
3432 y -= tmprow->height;
3433 tmprow->fill = Fill(tmprow, paperwidth);
3434 SetHeightOfRow(tmprow);
3437 refresh_row = tmprow;
3438 status = LyXText::NEED_MORE_REFRESH;
3439 current_font = rawtmpfont;
3440 real_current_font = realtmpfont;
3441 SetCursor(cursor.par, cursor.pos, false);
3442 // check, whether the last character's font has changed.
3443 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3444 if (rawparfont != rawtmpfont)
3445 RedoHeightOfParagraph(cursor);
3450 // break the cursor row again
3451 z = NextBreakPoint(row, paperwidth);
3453 if (z != RowLast(row) ||
3454 (row->next && row->next->par == row->par &&
3455 RowLast(row) == row->par->Last() - 1)){
3457 /* it can happen that a paragraph loses one row
3458 * without a real breakup. This is when a word
3459 * is to long to be broken. Well, I don t care this
3461 if (row->next && row->next->par == row->par &&
3462 RowLast(row) == row->par->Last() - 1)
3463 RemoveRow(row->next);
3467 status = LyXText::NEED_MORE_REFRESH;
3469 BreakAgainOneRow(row);
3470 current_font = rawtmpfont;
3471 real_current_font = realtmpfont;
3472 SetCursor(cursor.par, cursor.pos, false);
3473 // cursor MUST be in row now
3475 if (row->next && row->next->par == row->par)
3476 need_break_row = row->next;
3480 // set the dimensions of the row
3481 row->fill = Fill(row, paperwidth);
3482 int tmpheight = row->height;
3483 SetHeightOfRow(row);
3484 if (tmpheight == row->height)
3485 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3487 status = LyXText::NEED_MORE_REFRESH;
3490 current_font = rawtmpfont;
3491 real_current_font = realtmpfont;
3492 SetCursor(cursor.par, cursor.pos, false);
3496 // restore the current font
3497 // That is what a user expects!
3498 current_font = rawtmpfont;
3499 real_current_font = realtmpfont;
3501 // check, wether the last characters font has changed.
3502 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3503 if (rawparfont != rawtmpfont) {
3504 RedoHeightOfParagraph(cursor);
3506 // now the special right address boxes
3507 if (textclasslist.Style(parameters->textclass,
3508 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3509 RedoDrawingOfParagraph(cursor);
3515 void LyXText::GetVisibleRow(int offset,
3516 Row * row_ptr, long y)
3518 /* returns a printed row */
3519 Painter & pain = owner_->painter();
3521 LyXDirection direction = row_ptr->par->getParDirection();
3522 LyXParagraph::size_type vpos, pos, pos_end;
3524 int y_top, y_bottom;
3525 float fill_separator, fill_hfill, fill_label_hfill;
3526 LyXParagraph * par, * firstpar;
3529 if (row_ptr->height <= 0) {
3530 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3533 PrepareToPrint(row_ptr, x, fill_separator,
3534 fill_hfill, fill_label_hfill);
3536 /* initialize the pixmap */
3538 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3541 /* selection code */
3542 if (sel_start_cursor.row == row_ptr &&
3543 sel_end_cursor.row == row_ptr) {
3544 if (sel_start_cursor.x < sel_end_cursor.x)
3545 pain.fillRectangle(sel_start_cursor.x, offset,
3546 sel_end_cursor.x - sel_start_cursor.x,
3550 pain.fillRectangle(sel_end_cursor.x, offset,
3551 sel_start_cursor.x - sel_end_cursor.x,
3554 } else if (sel_start_cursor.row == row_ptr) {
3555 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3556 pain.fillRectangle(sel_start_cursor.x, offset,
3557 paperwidth - sel_start_cursor.x,
3561 pain.fillRectangle(0, offset,
3565 } else if (sel_end_cursor.row == row_ptr) {
3566 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3567 pain.fillRectangle(0, offset,
3572 pain.fillRectangle(sel_end_cursor.x, offset,
3573 paperwidth - sel_end_cursor.x,
3577 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3578 pain.fillRectangle(0, offset,
3579 paperwidth, row_ptr->height,
3584 if (row_ptr->par->appendix){
3585 pain.line(1, offset,
3586 1, offset + row_ptr->height,
3587 LColor::appendixline);
3588 pain.line(paperwidth - 2, offset,
3589 paperwidth - 2, offset + row_ptr->height,
3590 LColor::appendixline);
3593 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3594 /* draw a marker at the left margin! */
3595 LyXFont font = GetFont(row_ptr->par, 0);
3596 int asc = font.maxAscent();
3597 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3598 int y1 = (offset + row_ptr->baseline);
3599 int y2 = (offset + row_ptr->baseline) - asc;
3600 pain.line(x, y1, x, y2, LColor::minipageline);
3602 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3603 LyXFont font(LyXFont::ALL_SANE);
3604 font.setSize(LyXFont::SIZE_FOOTNOTE);
3605 font.setColor(LColor::footnote);
3607 int box_x = LYX_PAPER_MARGIN;
3608 box_x += font.textWidth(" wide-tab ", 10);
3609 if (row_ptr->previous &&
3610 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3612 switch (row_ptr->par->footnotekind) {
3613 case LyXParagraph::MARGIN:
3616 case LyXParagraph::FIG:
3619 case LyXParagraph::TAB:
3622 case LyXParagraph::WIDE_FIG:
3625 case LyXParagraph::WIDE_TAB:
3628 case LyXParagraph::ALGORITHM:
3631 case LyXParagraph::FOOTNOTE:
3636 pain.fillRectangle(LYX_PAPER_MARGIN,
3638 box_x - LYX_PAPER_MARGIN,
3639 int(font.maxAscent()
3640 + font.maxDescent()),
3641 LColor::footnotebg);
3643 pain.line(LYX_PAPER_MARGIN, offset,
3644 paperwidth - LYX_PAPER_MARGIN, offset,
3645 LColor::footnoteframe);
3647 pain.text(LYX_PAPER_MARGIN,
3648 offset + int(font.maxAscent()) + 1,
3651 pain.line(LYX_PAPER_MARGIN, offset,
3653 offset + int(font.maxAscent()
3654 + font.maxDescent()),
3655 LColor::footnoteframe);
3657 pain.line(LYX_PAPER_MARGIN,
3658 offset + int(font.maxAscent()
3659 + font.maxDescent()) + 1,
3661 offset + int(font.maxAscent()
3662 + font.maxDescent()) + 1,
3663 LColor::footnoteframe);
3667 /* draw the open floats in a red box */
3668 pain.line(box_x, offset,
3669 box_x, offset + row_ptr->height,
3670 LColor::footnoteframe);
3672 pain.line(paperwidth - LYX_PAPER_MARGIN,
3674 paperwidth - LYX_PAPER_MARGIN,
3675 offset + row_ptr->height,
3676 LColor::footnoteframe);
3677 } else if (row_ptr->previous &&
3678 row_ptr->previous->par->footnoteflag
3679 == LyXParagraph::OPEN_FOOTNOTE) {
3680 LyXFont font(LyXFont::ALL_SANE);
3681 font.setSize(LyXFont::SIZE_FOOTNOTE);
3683 int box_x = LYX_PAPER_MARGIN;
3684 box_x += font.textWidth(" wide-tab ", 10);
3686 pain.line(box_x, offset,
3687 paperwidth - LYX_PAPER_MARGIN,
3688 offset, LColor::footnote);
3691 LyXLayout const & layout =
3692 textclasslist.Style(parameters->textclass,
3693 row_ptr->par->GetLayout());
3694 firstpar = row_ptr->par->FirstPhysicalPar();
3697 y_bottom = row_ptr->height;
3699 /* is it a first row? */
3700 if (row_ptr->pos == 0
3701 && row_ptr->par == firstpar) {
3703 /* start of appendix? */
3704 if (row_ptr->par->start_of_appendix){
3705 pain.line(1, offset,
3706 paperwidth - 2, offset,
3707 LColor::appendixline);
3710 /* think about the margins */
3711 if (!row_ptr->previous)
3712 y_top += LYX_PAPER_MARGIN;
3714 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3716 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3718 offset + y_top + 2 * DefaultHeight(),
3719 LColor::pagebreak, Painter::line_onoffdash);
3722 pb_font.setColor(LColor::pagebreak).decSize();
3723 int w = 0, a = 0, d = 0;
3724 pain.line(0, offset + y_top + 2*DefaultHeight(),
3726 offset + y_top + 2*DefaultHeight(),
3728 Painter::line_onoffdash)
3731 _("Page Break (top)"),
3734 LColor::background, false, w, a, d);
3735 pain.rectText((paperwidth - w)/2,
3736 offset +y_top + 2*DefaultHeight() +d,
3737 _("Page Break (top)"),
3740 LColor::background);
3742 y_top += 3 * DefaultHeight();
3745 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3746 /* draw a vfill top */
3747 pain.line(0, offset + 2 + y_top,
3748 LYX_PAPER_MARGIN, offset + 2 + y_top,
3751 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3753 offset + y_top + 3 * DefaultHeight(),
3756 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3757 LYX_PAPER_MARGIN / 2,
3758 offset + y_top + 3 * DefaultHeight(),
3761 y_top += 3 * DefaultHeight();
3764 /* think about user added space */
3765 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3767 /* think about the parskip */
3768 /* some parskips VERY EASY IMPLEMENTATION */
3769 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3770 if (layout.latextype == LATEX_PARAGRAPH
3771 && firstpar->GetDepth() == 0
3772 && firstpar->Previous())
3773 y_top += parameters->getDefSkip().inPixels(owner_);
3774 else if (firstpar->Previous()
3775 && textclasslist.Style(parameters->textclass,
3776 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3777 && firstpar->Previous()->GetDepth() == 0)
3778 // is it right to use defskip here, too? (AS)
3779 y_top += parameters->getDefSkip().inPixels(owner_);
3782 if (row_ptr->par->line_top) { /* draw a top line */
3783 y_top += GetFont(row_ptr->par, 0).ascent('x');
3785 pain.line(0, offset + y_top,
3786 paperwidth, offset + y_top,
3788 Painter::line_solid,
3789 Painter::line_thick);
3791 y_top += GetFont(row_ptr->par, 0).ascent('x');
3794 /* should we print a label? */
3795 if (layout.labeltype >= LABEL_STATIC
3796 && (layout.labeltype != LABEL_STATIC
3797 || layout.latextype != LATEX_ENVIRONMENT
3798 || row_ptr->par->IsFirstInSequence())) {
3799 font = GetFont(row_ptr->par, -2);
3800 if (!row_ptr->par->GetLabestring().empty()) {
3802 string tmpstring = row_ptr->par->GetLabestring();
3804 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3805 if (parameters->secnumdepth >= 0){
3806 /* this is special code for the chapter layout. This is printed in
3807 * an extra row and has a pagebreak at the top. */
3808 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3809 + int(layout.parsep) * DefaultHeight();
3810 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3811 tmpx = paperwidth - LeftMargin(row_ptr) -
3812 font.stringWidth(tmpstring);
3813 pain.text(int(tmpx),
3814 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3818 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3819 tmpx = x - font.stringWidth(layout.labelsep)
3820 - font.stringWidth(tmpstring);
3822 tmpx = paperwidth - LeftMargin(row_ptr)
3823 + font.stringWidth(layout.labelsep);
3824 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3825 LyXFont font(LyXFont::ALL_SANE);
3826 font.setSize(LyXFont::SIZE_SMALL);
3827 tmpx += font.textWidth("Mwide-figM", 10);
3831 pain.text(int(tmpx),
3832 offset + row_ptr->baseline,
3836 /* the labels at the top of an environment. More or less for bibliography */
3837 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3838 layout.labeltype == LABEL_BIBLIO ||
3839 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3840 if (row_ptr->par->IsFirstInSequence()) {
3841 font = GetFont(row_ptr->par, -2);
3842 if (!row_ptr->par->GetLabestring().empty()) {
3843 string tmpstring = row_ptr->par->GetLabestring();
3845 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3846 + (layout.labelbottomsep * DefaultHeight()));
3849 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3850 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3851 ? x : LeftMargin(row_ptr) )
3852 + paperwidth - RightMargin(row_ptr) ) / 2;
3853 tmpx -= (font.stringWidth(tmpstring)/2);
3854 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3855 tmpx = paperwidth - LeftMargin(row_ptr) -
3856 font.stringWidth(tmpstring);
3857 pain.text(int(tmpx),
3858 offset + row_ptr->baseline
3859 - row_ptr->ascent_of_text
3865 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3866 font = GetFont(row_ptr->par, -1);
3867 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3868 tmpx = x - font.stringWidth(layout.labelsep)
3869 - row_ptr->par->bibkey->width(owner_->painter(), font);
3871 tmpx = paperwidth - LeftMargin(row_ptr)
3872 + font.stringWidth(layout.labelsep);
3873 row_ptr->par->bibkey->draw(owner_->painter(),
3875 offset + row_ptr->baseline,
3880 /* is it a last row? */
3881 par = row_ptr->par->LastPhysicalPar();
3882 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3883 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3885 /* think about the margins */
3887 y_bottom -= LYX_PAPER_MARGIN;
3889 /* draw a bottom pagebreak */
3890 if (firstpar->pagebreak_bottom) {
3892 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3894 offset + y_bottom - 2 * DefaultHeight(),
3895 LColor::pagebreak, Painter::line_onoffdash);
3898 pb_font.setColor(LColor::pagebreak).decSize();
3899 int w = 0, a = 0, d = 0;
3901 offset + y_bottom - 2 * DefaultHeight(),
3903 offset + y_bottom - 2 * DefaultHeight(),
3905 Painter::line_onoffdash)
3908 _("Page Break (bottom)"),
3911 LColor::background, false, w, a, d);
3912 pain.rectText((paperwidth - w)/2,
3913 offset +y_top + 2*DefaultHeight() +d,
3914 _("Page Break (bottom)"),
3917 LColor::background);
3919 y_bottom -= 3 * DefaultHeight();
3922 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3923 /* draw a vfill bottom */
3924 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3926 offset + y_bottom - 3 * DefaultHeight(),
3928 pain.line(0, offset + y_bottom - 2,
3930 offset + y_bottom - 2,
3932 pain.line(LYX_PAPER_MARGIN / 2,
3933 offset + y_bottom - 3 * DefaultHeight(),
3934 LYX_PAPER_MARGIN / 2,
3935 offset + y_bottom - 2,
3937 y_bottom -= 3* DefaultHeight();
3940 /* think about user added space */
3941 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3943 if (firstpar->line_bottom) {
3944 /* draw a bottom line */
3945 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3946 pain.line(0, offset + y_bottom,
3947 paperwidth, offset + y_bottom,
3948 LColor::topline, Painter::line_solid,
3949 Painter::line_thick);
3950 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3954 /* draw the text in the pixmap */
3955 pos_end = RowLast(row_ptr);
3957 vpos = row_ptr->pos;
3958 /* table stuff -- begin*/
3959 if (row_ptr->par->table) {
3961 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3963 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3965 while (vpos <= pos_end) {
3966 pos = vis2log(vpos);
3967 if (row_ptr->par->IsNewline(pos)) {
3969 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3970 /* draw the table lines, still very simple */
3971 on_off = !row_ptr->par->table->TopLine(cell);
3973 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3974 !row_ptr->par->table->IsContRow(cell))
3975 pain.line(int(x_old),
3976 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3978 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3980 on_off ? Painter::line_onoffdash : Painter::line_solid);
3982 on_off = !row_ptr->par->table->BottomLine(cell);
3983 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3984 row_ptr->par->table->VeryLastRow(cell))
3986 pain.line(int(x_old),
3987 offset + y_bottom - 1,
3989 offset + y_bottom - 1,
3991 on_off ? Painter::line_onoffdash : Painter::line_solid);
3993 on_off = !row_ptr->par->table->LeftLine(cell);
3995 pain.line(int(x_old),
3996 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3998 offset + y_bottom - 1,
4000 on_off ? Painter::line_onoffdash : Painter::line_solid);
4002 on_off = !row_ptr->par->table->RightLine(cell);
4004 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4005 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4006 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4007 offset + y_bottom - 1,
4009 on_off ? Painter::line_onoffdash : Painter::line_solid);
4012 /* take care about the alignment and other spaces */
4014 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4015 if (row_ptr->par->table->IsFirstCell(cell))
4016 --cell; // little hack, sorry
4018 } else if (row_ptr->par->IsHfill(pos)) {
4022 offset + row_ptr->baseline - DefaultHeight() / 2,
4024 offset + row_ptr->baseline,
4029 } else if (row_ptr->par->IsSeparator(pos)) {
4031 x+= SingleWidth(row_ptr->par, pos);
4032 #warning Think about this.
4034 /* -------> Only draw protected spaces when
4035 * not in free-spacing mode. */
4036 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4037 pain.line(int(tmpx),
4038 offset + row_ptr->baseline - 3,
4040 offset + row_ptr->baseline - 1,
4043 pain.line(int(tmpx),
4044 offset + row_ptr->baseline - 1,
4046 offset + row_ptr->baseline - 1,
4049 pain.line(int(x - 2),
4050 offset + row_ptr->baseline - 3,
4052 offset + row_ptr->baseline - 1,
4055 /* what about underbars? */
4056 font = GetFont(row_ptr->par, pos);
4057 if (font.underbar() == LyXFont::ON
4058 && font.latex() != LyXFont::ON) {
4059 pain.line(int(tmpx),
4060 offset + row_ptr->baseline + 2,
4062 offset + row_ptr->baseline + 2);
4068 draw(row_ptr, vpos, offset, x);
4071 /* do not forget the very last cell. This has no NEWLINE so
4072 * ignored by the code above*/
4073 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4074 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4075 on_off = !row_ptr->par->table->TopLine(cell);
4077 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4078 !row_ptr->par->table->IsContRow(cell))
4080 pain.line(int(x_old),
4081 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4083 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4085 on_off ? Painter::line_onoffdash : Painter::line_solid);
4086 on_off = !row_ptr->par->table->BottomLine(cell);
4087 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4088 row_ptr->par->table->VeryLastRow(cell))
4090 pain.line(int(x_old),
4091 offset + y_bottom - 1,
4093 offset + y_bottom - 1,
4095 on_off ? Painter::line_onoffdash : Painter::line_solid);
4097 on_off = !row_ptr->par->table->LeftLine(cell);
4099 pain.line(int(x_old),
4100 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4102 offset + y_bottom - 1,
4104 on_off ? Painter::line_onoffdash : Painter::line_solid);
4106 on_off = !row_ptr->par->table->RightLine(cell);
4108 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4109 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4110 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4111 offset + y_bottom - 1,
4113 on_off ? Painter::line_onoffdash : Painter::line_solid);
4116 /* table stuff -- end*/
4117 LyXParagraph::size_type main_body =
4118 BeginningOfMainBody(row_ptr->par);
4119 if (main_body > 0 &&
4120 (main_body-1 > pos_end ||
4121 !row_ptr->par->IsLineSeparator(main_body-1)))
4124 while (vpos <= pos_end) {
4125 pos = vis2log(vpos);
4126 if (main_body > 0 && pos == main_body-1) {
4127 x += fill_label_hfill
4128 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4129 - SingleWidth(row_ptr->par, main_body-1);
4132 if (row_ptr->par->IsHfill(pos)) {
4135 offset + row_ptr->baseline - DefaultHeight() / 2,
4137 offset + row_ptr->baseline,
4140 if (HfillExpansion(row_ptr, pos)) {
4141 if (pos >= main_body) {
4143 offset + row_ptr->baseline - DefaultHeight() / 4,
4144 int(x + fill_hfill),
4145 offset + row_ptr->baseline - DefaultHeight() / 4,
4147 Painter::line_onoffdash);
4151 offset + row_ptr->baseline - DefaultHeight() / 4,
4152 int(x + fill_label_hfill),
4153 offset + row_ptr->baseline - DefaultHeight() / 4,
4155 Painter::line_onoffdash);
4157 x += fill_label_hfill;
4160 offset + row_ptr->baseline - DefaultHeight() / 2,
4162 offset + row_ptr->baseline,
4167 } else if (row_ptr->par->IsSeparator(pos)) {
4169 x+= SingleWidth(row_ptr->par, pos);
4170 if (pos >= main_body)
4172 #warning Think about this
4174 /* -------> Only draw protected spaces when
4175 * not in free-spacing mode. */
4176 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4178 pain.line(int(tmpx),
4179 offset + row_ptr->baseline - 3,
4181 offset + row_ptr->baseline - 1,
4184 pain.line(int(tmpx),
4185 offset + row_ptr->baseline - 1,
4187 offset + row_ptr->baseline - 1,
4190 pain.line(int(x - 2),
4191 offset + row_ptr->baseline - 3,
4193 offset + row_ptr->baseline - 1,
4196 /* what about underbars? */
4197 font = GetFont(row_ptr->par, pos);
4198 if (font.underbar() == LyXFont::ON
4199 && font.latex() != LyXFont::ON) {
4200 pain.line(int(tmpx),
4201 offset + row_ptr->baseline + 2,
4203 offset + row_ptr->baseline + 2);
4209 draw(row_ptr, vpos, offset, x);
4215 int LyXText::DefaultHeight() const
4217 LyXFont font(LyXFont::ALL_SANE);
4218 return int(font.maxAscent() + font.maxDescent() * 1.5);
4222 /* returns the column near the specified x-coordinate of the row
4223 * x is set to the real beginning of this column */
4224 int LyXText::GetColumnNearX(Row * row, int & x) const
4227 float fill_separator, fill_hfill, fill_label_hfill;
4229 PrepareToPrint(row, tmpx, fill_separator,
4230 fill_hfill, fill_label_hfill);
4232 LyXDirection direction = row->par->getParDirection();
4233 LyXParagraph::size_type vc = row->pos;
4234 LyXParagraph::size_type last = RowLast(row);
4235 LyXParagraph::size_type c = 0;
4237 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4238 row->par->GetLayout());
4239 /* table stuff -- begin */
4240 if (row->par->table) {
4241 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4242 && row->par->IsNewline(last))
4244 int cell = NumberOfCell(row->par, row->pos);
4247 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4249 && (c = vis2log(vc)) >= 0
4250 && tmpx + (SingleWidth(row->par, c)/2) <= x
4252 if (row->par->IsNewline(c)) {
4253 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4254 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4257 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4262 tmpx += SingleWidth(row->par, c);
4267 /* table stuff -- end*/
4268 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4269 float last_tmpx = tmpx;
4271 if (main_body > 0 &&
4272 (main_body-1 > last ||
4273 !row->par->IsLineSeparator(main_body-1)))
4276 while (vc <= last && tmpx <= x) {
4279 if (main_body > 0 && c == main_body-1) {
4280 tmpx += fill_label_hfill +
4281 GetFont(row->par, -2).stringWidth(layout.labelsep);
4282 if (row->par->IsLineSeparator(main_body-1))
4283 tmpx -= SingleWidth(row->par, main_body-1);
4286 tmpx += SingleWidth(row->par, c);
4287 if (HfillExpansion(row, c)) {
4291 tmpx += fill_label_hfill;
4293 else if (c >= main_body
4294 && row->par->IsSeparator(c)) {
4295 tmpx+= fill_separator;
4300 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4305 /* make sure that a last space in a row doesnt count */
4306 if (row->pos <= last
4307 && !(!row->next || row->next->par != row->par))
4308 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4309 && row->par->IsLineSeparator(vis2log(last)) ) {
4311 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4312 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4314 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4316 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4319 if (row->pos > last) // Row is empty?
4321 else if (vc <= last) {
4323 LyXDirection direction = row->par->getLetterDirection(c);
4324 if (vc > row->pos && row->par->IsLineSeparator(c)
4325 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4327 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4330 c = vis2log(last)+1;
4331 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4335 if (!row->par->table && row->pos <= last && c > last
4336 && row->par->IsNewline(last)) {
4337 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4338 tmpx -= SingleWidth(row->par, last);
4340 tmpx += SingleWidth(row->par, last);
4350 /* turn the selection into a new environment. If there is no selection,
4351 * create an empty environment */
4352 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4354 /* no footnoteenvironment in a footnoteenvironment */
4355 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4356 WriteAlert(_("Impossible operation"),
4357 _("You can't insert a float in a float!"),
4361 /* no marginpars in minipages */
4362 if (kind == LyXParagraph::MARGIN
4363 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4364 WriteAlert(_("Impossible operation"),
4365 _("You can't insert a marginpar in a minipage!"),
4370 /* this doesnt make sense, if there is no selection */
4371 bool dummy_selection = false;
4373 sel_start_cursor = cursor; /* dummy selection */
4374 sel_end_cursor = cursor;
4375 dummy_selection = true;
4378 LyXParagraph *tmppar;
4380 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4381 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4385 /* a test to make sure there is not already a footnote
4386 * in the selection. */
4388 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4390 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4391 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4392 tmppar = tmppar->next;
4394 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4395 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4396 WriteAlert(_("Impossible operation"),
4397 _("Float would include float!"),
4402 /* ok we have a selection. This is always between sel_start_cursor
4403 * and sel_end cursor */
4405 SetUndo(Undo::FINISH,
4406 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4407 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4409 if (sel_end_cursor.pos > 0
4410 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4411 sel_end_cursor.pos--; /* please break before a space at
4413 if (sel_start_cursor.par == sel_end_cursor.par
4414 && sel_start_cursor.pos > sel_end_cursor.pos)
4415 sel_start_cursor.pos--;
4417 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4419 sel_end_cursor.par = sel_end_cursor.par->Next();
4420 sel_end_cursor.pos = 0;
4422 // don't forget to insert a dummy layout paragraph if necessary
4423 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4424 sel_end_cursor.par->BreakParagraphConservative(0);
4425 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4426 sel_end_cursor.par = sel_end_cursor.par->next;
4429 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4431 cursor = sel_end_cursor;
4433 /* please break behind a space, if there is one. The space should
4435 if (sel_start_cursor.pos > 0
4436 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4437 sel_start_cursor.pos--;
4438 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4439 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4442 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4443 tmppar = sel_start_cursor.par->Next();
4445 if (dummy_selection) {
4447 if (kind == LyXParagraph::TAB
4448 || kind == LyXParagraph::FIG
4449 || kind == LyXParagraph::WIDE_TAB
4450 || kind == LyXParagraph::WIDE_FIG
4451 || kind == LyXParagraph::ALGORITHM) {
4452 pair<bool, LyXTextClass::size_type> lres =
4453 textclasslist.NumberOfLayout(parameters->textclass,
4455 LyXTextClass::size_type lay;
4461 lay = 0; // use default layout "Standard" (0)
4463 tmppar->SetLayout(lay);
4467 if (sel_start_cursor.pos > 0) {
4468 /* the footnote-environment should begin with a standard layout.
4469 * Imagine you insert a footnote within an enumeration, you
4470 * certainly do not want an enumerated footnote! */
4474 /* this is a exception the user would sometimes expect, I hope */
4475 sel_start_cursor.par->Clear();
4479 while (tmppar != sel_end_cursor.par) {
4480 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4481 tmppar->footnotekind = kind;
4482 tmppar = tmppar->Next();
4485 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4487 SetCursor(sel_start_cursor.par->Next(), 0);
4493 // returns pointer to a specified row
4494 Row * LyXText::GetRow(LyXParagraph * par,
4495 LyXParagraph::size_type pos, long & y) const
4500 if (par == currentrow->par
4501 || par == currentrow->par->Previous()) {
4502 // do not dereference par, it may have been deleted
4503 // already! (Matthias)
4505 // Walk backwards as long as the previous
4506 // rows par is not par
4507 while (currentrow->previous
4508 && currentrow->previous->par != par) {
4509 currentrow = currentrow->previous;
4510 currentrow_y -= currentrow->height;
4512 // Walk backwards as long as the previous
4513 // rows par _is_ par
4514 while (currentrow->previous
4515 && currentrow->previous->par == par) {
4516 currentrow = currentrow->previous;
4517 currentrow_y -= currentrow->height;
4521 tmprow = currentrow;
4523 // find the first row of the specified paragraph
4525 && tmprow->par != par) {
4526 y += tmprow->height;
4527 tmprow = tmprow->next;
4530 if (tmprow->par == par){
4531 // now find the wanted row
4532 while (tmprow->pos < pos
4534 && tmprow->next->par == par
4535 && tmprow->next->pos <= pos) {
4536 y += tmprow->height;
4537 tmprow = tmprow->next;
4539 currentrow = tmprow;
4547 // find the first row of the specified paragraph
4548 while (tmprow->next && tmprow->par != par) {
4549 y += tmprow->height;
4550 tmprow = tmprow->next;
4553 // now find the wanted row
4554 while (tmprow->pos < pos
4556 && tmprow->next->par == par
4557 && tmprow->next->pos <= pos) {
4558 y += tmprow->height;
4559 tmprow = tmprow->next;
4562 currentrow = tmprow;