1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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"
40 static const int LYX_PAPER_MARGIN = 20;
44 extern int bibitemMaxWidth(Painter &, LyXFont const &);
46 #define FIX_DOUBLE_SPACE 1
48 static int iso885968x[] = {
49 0xbc, // 0xa8 = fathatan
50 0xbd, // 0xa9 = dammatan
51 0xbe, // 0xaa = kasratan
55 0xde, // 0xae = shadda
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf
62 0xc2, // 0xc2 = ligature madda
63 0xc3, // 0xc3 = ligature hamza on alef
64 0xc4, // 0xc4 = ligature hamza on waw
65 0xc5, // 0xc5 = ligature hamza under alef
66 0xc0, // 0xc6 = ligature hamza on ya
69 0xc9, // 0xc9 = taa marbuta
88 0,0,0,0,0, // 0xdb- 0xdf
99 0xe9, // 0xe9 = alef maksura
103 bool is_arabic(unsigned char c)
105 return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8];
108 unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const
111 (form == FORM_INITIAL || form == FORM_MEDIAL) )
112 return iso885968x[c-0xa8];
117 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
118 LyXParagraph::size_type pos) const
123 bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1)));
124 if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1)))
126 return TransformChar(c,FORM_MEDIAL);
128 return TransformChar(c,FORM_INITIAL);
131 return TransformChar(c,FORM_FINAL);
133 return TransformChar(c,FORM_ISOLATED);
136 // This is the comments that some of the warnings below refers to.
137 // There are some issues in this file and I don't think they are
138 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
139 // this is a problem that has been here almost from day one and that a
140 // larger userbase with differenct access patters triggers the bad
141 // behaviour. (segfaults.) What I think happen is: In several places
142 // we store the paragraph in the current cursor and then moves the
143 // cursor. This movement of the cursor will delete paragraph at the
144 // old position if it is now empty. This will make the temporary
145 // pointer to the old cursor paragraph invalid and dangerous to use.
146 // And is some cases this will trigger a segfault. I have marked some
147 // of the cases where this happens with a warning, but I am sure there
148 // are others in this file and in text2.C. There is also a note in
149 // Delete() that you should read. In Delete I store the paragraph->id
150 // instead of a pointer to the paragraph. I am pretty sure this faulty
151 // use of temporary pointers to paragraphs that might have gotten
152 // invalidated (through a cursor movement) before they are used, are
153 // the cause of the strange crashes we get reported often.
155 // It is very tiresom to change this code, especially when it is as
156 // hard to read as it is. Help to fix all the cases where this is done
157 // would be greately appreciated.
161 int LyXText::SingleWidth(LyXParagraph * par,
162 LyXParagraph::size_type pos) const
164 char c = par->GetChar(pos);
165 return SingleWidth(par, pos, c);
169 int LyXText::SingleWidth(LyXParagraph * par,
170 LyXParagraph::size_type pos, char c) const
172 LyXFont font = GetFont(par, pos);
174 // The most common case is handled first (Asger)
175 if (IsPrintable(c)) {
176 if (lyxrc.rtl_support && lyxrc.font_norm == "iso8859-6.8x")
177 c = TransformChar(c, par, pos);
178 return font.width(c);
180 } else if (IsHfillChar(c)) {
181 return 3; /* Because of the representation
182 * as vertical lines */
183 } else if (c == LyXParagraph::META_FOOTNOTE ||
184 c == LyXParagraph::META_MARGIN ||
185 c == LyXParagraph::META_FIG ||
186 c == LyXParagraph::META_TAB ||
187 c == LyXParagraph::META_WIDE_FIG ||
188 c == LyXParagraph::META_WIDE_TAB ||
189 c == LyXParagraph::META_ALGORITHM) {
192 case LyXParagraph::META_MARGIN:
195 case LyXParagraph::META_FIG:
198 case LyXParagraph::META_TAB:
201 case LyXParagraph::META_ALGORITHM:
204 case LyXParagraph::META_WIDE_FIG:
207 case LyXParagraph::META_WIDE_TAB:
210 case LyXParagraph::META_FOOTNOTE:
216 return font.stringWidth(fs);
217 } else if (c == LyXParagraph::META_INSET) {
218 Inset * tmpinset= par->GetInset(pos);
220 return par->GetInset(pos)->width(owner_->painter(),
225 } else if (IsSeparatorChar(c))
227 else if (IsNewlineChar(c))
229 return font.width(c);
233 // Returns the paragraph position of the last character in the specified row
234 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
237 return row->par->Last() - 1;
238 else if (row->next->par != row->par)
239 return row->par->Last() - 1;
241 return row->next->pos - 1;
248 void LyXText::ComputeBidiTables(Row * row) const
251 if (!lyxrc.rtl_support) {
255 LyXParagraph::size_type last = RowLast(row);
256 bidi_start = row->pos;
258 if (bidi_start > last) {
263 if (last + 2 - bidi_start >
264 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
265 LyXParagraph::size_type new_size =
266 (last + 2 - bidi_start < 500) ?
267 500 : 2 * (last + 2 - bidi_start);
268 log2vis_list.resize(new_size);
269 vis2log_list.resize(new_size);
272 vis2log_list[last + 1 - bidi_start] = -1;
273 log2vis_list[last + 1 - bidi_start] = -1;
275 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
276 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
277 && row->par->IsLineSeparator(main_body - 1)) {
278 // This is needed in case there is a direction change in
279 // the label which is continued into the main body
280 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
281 ComputeBidiTablesFromTo(row, bidi_start,
283 log2vis_list[main_body - 1 - bidi_start] =
285 vis2log_list[main_body - 1 - bidi_start] =
287 if (main_body <= last)
288 ComputeBidiTablesFromTo(row,
291 ComputeBidiTablesFromTo(row, bidi_start,
293 last - main_body + 2);
294 log2vis_list[main_body - 1 - bidi_start] =
295 last - main_body + 1 + bidi_start;
296 vis2log_list[last - main_body + 1 - bidi_start] =
298 if (main_body <= last)
299 ComputeBidiTablesFromTo(row, main_body,
303 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
307 void LyXText::ComputeBidiTablesFromTo(Row * row,
308 LyXParagraph::size_type from,
309 LyXParagraph::size_type to,
310 LyXParagraph::size_type offset) const
312 LyXParagraph::size_type vpos, old_lpos, stack[2];
313 LyXDirection par_direction = row->par->getParDirection();
314 LyXDirection direction = par_direction;
315 LyXParagraph::size_type lpos = from;
319 if (row->par->getLetterDirection(lpos) == direction) {
320 log2vis_list[lpos - bidi_start] = direction;
324 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
325 && row->par->getFont(lpos).isRightToLeft()
326 && row->par->getFont(lpos).latex() == LyXFont::ON
328 // The last check is needed when the
330 stack[level++] = lpos;
332 old_lpos = stack[--level];
333 log2vis_list[old_lpos - bidi_start] =
334 log2vis_list[lpos - bidi_start] =
335 (old_lpos - lpos) * direction;
338 direction = static_cast<LyXDirection>(-direction);
343 old_lpos = stack[--level];
344 log2vis_list[old_lpos - bidi_start] =
345 (old_lpos - (to + 1)) * direction;
346 direction = static_cast<LyXDirection>(-direction);
349 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
352 for (lpos = from; lpos <= to; ++lpos) {
353 vpos += log2vis_list[lpos - bidi_start];
354 vis2log_list[vpos - bidi_start] = lpos;
355 log2vis_list[lpos - bidi_start] = vpos;
360 void LyXText::draw(Row const * row,
361 LyXParagraph::size_type & vpos,
362 int offset, float & x)
364 Painter & pain = owner_->painter();
366 LyXParagraph::size_type pos = vis2log(vpos);
367 char c = row->par->GetChar(pos);
369 if (IsNewlineChar(c)) {
371 // Draw end-of-line marker
372 LyXFont font = GetFont(row->par, pos);
373 int wid = font.width('n');
374 int asc = font.maxAscent();
375 int y = offset + row->baseline;
378 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
379 xp[0] = int(x + wid * 0.375);
380 yp[0] = int(y - 0.875 * asc * 0.75);
383 yp[1] = int(y - 0.500 * asc * 0.75);
385 xp[2] = int(x + wid * 0.375);
386 yp[2] = int(y - 0.125 * asc * 0.75);
388 pain.lines(xp, yp, 3, LColor::eolmarker);
391 yp[0] = int(y - 0.500 * asc * 0.75);
393 xp[1] = int(x + wid);
394 yp[1] = int(y - 0.500 * asc * 0.75);
396 xp[2] = int(x + wid);
397 yp[2] = int(y - asc * 0.75);
399 pain.lines(xp, yp, 3, LColor::eolmarker);
401 xp[0] = int(x + wid * 0.625);
402 yp[0] = int(y - 0.875 * asc * 0.75);
404 xp[1] = int(x + wid);
405 yp[1] = int(y - 0.500 * asc * 0.75);
407 xp[2] = int(x + wid * 0.625);
408 yp[2] = int(y - 0.125 * asc * 0.75);
410 pain.lines(xp, yp, 3, LColor::eolmarker);
412 xp[0] = int(x + wid);
413 yp[0] = int(y - 0.500 * asc * 0.75);
416 yp[1] = int(y - 0.500 * asc * 0.75);
419 yp[2] = int(y - asc * 0.75);
421 pain.lines(xp, yp, 3, LColor::eolmarker);
427 LyXFont font = GetFont(row->par, pos);
428 LyXFont font2 = font;
430 if (c == LyXParagraph::META_FOOTNOTE
431 || c == LyXParagraph::META_MARGIN
432 || c == LyXParagraph::META_FIG
433 || c == LyXParagraph::META_TAB
434 || c == LyXParagraph::META_WIDE_FIG
435 || c == LyXParagraph::META_WIDE_TAB
436 || c == LyXParagraph::META_ALGORITHM) {
439 case LyXParagraph::META_MARGIN:
441 // Draw a sign at the left margin!
443 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
444 offset + row->baseline, "!", 1, font);
446 case LyXParagraph::META_FIG:
449 case LyXParagraph::META_TAB:
452 case LyXParagraph::META_ALGORITHM:
455 case LyXParagraph::META_WIDE_FIG:
458 case LyXParagraph::META_WIDE_TAB:
461 case LyXParagraph::META_FOOTNOTE:
468 // calculate the position of the footnotemark
469 int y = (row->baseline - font2.maxAscent()
472 font.setColor(LColor::footnote);
476 // draw it and set new x position
478 pain.text(int(x), offset + y, fs, font);
479 x += pain.width(fs, font);
480 pain.line(int(tmpx), offset + row->baseline,
481 int(x), offset + row->baseline,
486 } else if (c == LyXParagraph::META_INSET) {
487 Inset * tmpinset = row->par->GetInset(pos);
489 tmpinset->draw(owner_->painter(), font,
490 offset + row->baseline, x);
496 /* usual characters, no insets */
498 // Collect character that we can draw in one command
500 // This is dirty, but fast. Notice that it will never be too small.
501 // For the record, I'll note that Microsoft Word has a limit
502 // of 768 here. We have none :-) (Asger)
503 // Ok. I am the first to admit that the use of std::string will be
504 // a tiny bit slower than using a POD char array. However, I claim
505 // that this slowdown is so small that it is close to inperceptive.
506 // So IMHO we should go with the easier and clearer implementation.
507 // And even if 1024 is a large number here it might overflow, string
508 // will only overflow if the machine is out of memory...
509 bool do_transform = (lyxrc.rtl_support && lyxrc.font_norm == "iso8859-6.8x");
511 c = TransformChar(c, row->par, pos);
512 static string textstring;
516 LyXParagraph::size_type last = RowLast(row);
518 while (vpos <= last &&
519 (pos = vis2log(vpos)) >= 0
520 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
521 && font2 == GetFont(row->par, pos)) {
523 c = TransformChar(c, row->par, pos);
529 // Draw text and set the new x position
530 pain.text(int(x), offset + row->baseline, textstring, font);
531 x += pain.width(textstring, font);
533 // what about underbars?
534 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
535 pain.line(tmpx, offset + row->baseline + 2,
536 x, offset + row->baseline + 2);
540 // If we want ulem.sty support, drawing
541 // routines should go here. (Asger)
542 // Why shouldn't LyXFont::drawText handle it internally?
546 // Returns the left beginning of the text.
547 // This information cannot be taken from the layouts-objekt, because in
548 // LaTeX the beginning of the text fits in some cases (for example sections)
549 // exactly the label-width.
550 int LyXText::LeftMargin(Row const * row) const
552 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
553 row->par->GetLayout());
555 string parindent = layout.parindent;
557 /* table stuff -- begin */
560 /* table stuff -- end */
562 int x = LYX_PAPER_MARGIN;
564 x += textclasslist.TextClass(parameters->textclass)
566 .signedStringWidth(textclasslist
567 .TextClass(parameters->textclass)
570 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
571 LyXFont font(LyXFont::ALL_SANE);
572 font.setSize(LyXFont::SIZE_SMALL);
573 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
576 // this is the way, LyX handles the LaTeX-Environments.
577 // I have had this idea very late, so it seems to be a
578 // later added hack and this is true
579 if (!row->par->GetDepth()) {
580 if (!row->par->GetLayout()) {
581 // find the previous same level paragraph
582 if (row->par->FirstPhysicalPar()->Previous()) {
583 LyXParagraph * newpar = row->par
584 ->DepthHook(row->par->GetDepth());
586 textclasslist.Style(parameters->textclass,
593 // find the next level paragraph
595 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
597 // make a corresponding row. Needed to call LeftMargin()
599 // check wether it is a sufficent paragraph
600 if (newpar && newpar->footnoteflag == row->par->footnoteflag
602 .Style(parameters->textclass,
603 newpar->GetLayout()).isEnvironment()) {
605 dummyrow.par = newpar;
606 dummyrow.pos = newpar->Last();
607 x = LeftMargin(&dummyrow);
609 // this is no longer an error, because this function
610 // is used to clear impossible depths after changing
611 // a layout. Since there is always a redo,
612 // LeftMargin() is always called
613 row->par->FirstPhysicalPar()->depth = 0;
616 if (newpar && !row->par->GetLayout()) {
617 if (newpar->FirstPhysicalPar()->noindent)
620 parindent = textclasslist
621 .Style(parameters->textclass,
622 newpar->GetLayout()).parindent;
627 LyXFont labelfont = GetFont(row->par, -2);
628 switch (layout.margintype) {
630 if (!layout.leftmargin.empty()) {
632 .TextClass(parameters->textclass)
634 .signedStringWidth(layout.leftmargin);
636 if (!row->par->GetLabestring().empty()) {
637 x += labelfont.signedStringWidth(layout.labelindent);
638 x += labelfont.stringWidth(row->par->GetLabestring());
639 x += labelfont.stringWidth(layout.labelsep);
643 x += labelfont.signedStringWidth(layout.labelindent);
644 if (row->pos >= BeginningOfMainBody(row->par)) {
645 if (!row->par->GetLabelWidthString().empty()) {
647 .stringWidth(row->par
648 ->GetLabelWidthString());
649 x += labelfont.stringWidth(layout.labelsep);
654 x += textclasslist.TextClass(parameters->textclass)
655 .defaultfont().signedStringWidth(layout.leftmargin) * 4
656 / (row->par->GetDepth() + 4);
658 case MARGIN_FIRST_DYNAMIC:
659 if (layout.labeltype == LABEL_MANUAL) {
660 if (row->pos >= BeginningOfMainBody(row->par)) {
662 .signedStringWidth(layout.leftmargin);
665 .signedStringWidth(layout.labelindent);
668 // Special case to fix problems with
670 || (layout.labeltype == LABEL_STATIC
671 && layout.latextype == LATEX_ENVIRONMENT
672 && ! row->par->IsFirstInSequence())) {
673 x += labelfont.signedStringWidth(layout.leftmargin);
674 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
675 && layout.labeltype != LABEL_BIBLIO
676 && layout.labeltype !=
677 LABEL_CENTERED_TOP_ENVIRONMENT) {
678 x += labelfont.signedStringWidth(layout.labelindent);
679 x += labelfont.stringWidth(layout.labelsep);
680 x += labelfont.stringWidth(row->par->GetLabestring());
684 case MARGIN_RIGHT_ADDRESS_BOX:
686 // ok, a terrible hack. The left margin depends on the widest
687 // row in this paragraph. Do not care about footnotes, they
688 // are *NOT* allowed in the LaTeX realisation of this layout.
690 // find the first row of this paragraph
691 Row const * tmprow = row;
692 while (tmprow->previous && tmprow->previous->par == row->par)
693 tmprow = tmprow->previous;
695 int minfill = tmprow->fill;
696 while (tmprow->next && tmprow->next->par == row->par) {
697 tmprow = tmprow->next;
698 if (tmprow->fill < minfill)
699 minfill = tmprow->fill;
702 x += textclasslist.TextClass(parameters->textclass)
703 .defaultfont().signedStringWidth(layout.leftmargin);
708 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
709 if (!row->par->pextra_widthp.empty()) {
711 atoi(row->par->pextra_widthp.c_str()) / 100;
712 } else if (!row->par->pextra_width.empty()) {
713 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
716 xx = paperwidth * 80 / 100;
718 } else { // should not happen
719 LyXFont font(LyXFont::ALL_SANE);
720 x += font.stringWidth("XXXXXX");
724 int align; // wrong type
725 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
726 align = layout.align;
728 align = row->par->FirstPhysicalPar()->align;
730 // set the correct parindent
732 if ((layout.labeltype == LABEL_NO_LABEL
733 || layout.labeltype == LABEL_TOP_ENVIRONMENT
734 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
735 || (layout.labeltype == LABEL_STATIC
736 && layout.latextype == LATEX_ENVIRONMENT
737 && ! row->par->IsFirstInSequence()))
738 && row->par == row->par->FirstPhysicalPar()
739 && align == LYX_ALIGN_BLOCK
740 && !row->par->noindent
741 && (row->par->layout ||
742 parameters->paragraph_separation ==
743 BufferParams::PARSEP_INDENT))
744 x += textclasslist.TextClass(parameters->textclass)
745 .defaultfont().signedStringWidth(parindent);
746 else if (layout.labeltype == LABEL_BIBLIO) {
747 // ale970405 Right width for bibitems
748 x += bibitemMaxWidth(owner_->painter(),
750 .TextClass(parameters
759 int LyXText::RightMargin(Row const * row) const
761 LyXLayout const & layout =
762 textclasslist.Style(parameters->textclass,
763 row->par->GetLayout());
765 int x = LYX_PAPER_MARGIN
767 .TextClass(parameters->textclass)
769 .signedStringWidth(textclasslist
770 .TextClass(parameters->textclass)
773 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
774 x += LYX_PAPER_MARGIN / 2;
777 // this is the way, LyX handles the LaTeX-Environments.
778 // I have had this idea very late, so it seems to be a
779 // later added hack and this is true
780 if (row->par->GetDepth()) {
781 // find the next level paragraph
783 LyXParagraph * newpar = row->par;
786 newpar = newpar->FirstPhysicalPar()->Previous();
788 newpar = newpar->FirstPhysicalPar();
789 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
790 && newpar->footnoteflag == row->par->footnoteflag);
792 // make a corresponding row. Needed to call LeftMargin()
794 // check wether it is a sufficent paragraph
795 if (newpar && newpar->footnoteflag == row->par->footnoteflag
796 && textclasslist.Style(parameters->textclass,
800 dummyrow.par = newpar;
802 x = RightMargin(&dummyrow);
804 // this is no longer an error, because this function
805 // is used to clear impossible depths after changing
806 // a layout. Since there is always a redo,
807 // LeftMargin() is always called
808 row->par->FirstPhysicalPar()->depth = 0;
812 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
813 x += textclasslist.TextClass(parameters->textclass)
815 .signedStringWidth(layout.rightmargin) * 4
816 / (row->par->GetDepth() + 4);
821 int LyXText::LabelEnd (Row const * row) const
823 if (textclasslist.Style(parameters->textclass,
824 row->par->GetLayout()).margintype
828 tmprow.pos = row->par->Last();
829 return LeftMargin(&tmprow); /* just the beginning
832 return 0; /* LabelEnd is only needed, if the
833 layout fills a flushleft
838 /* table stuff -- begin*/
839 int LyXText::NumberOfCell(LyXParagraph * par,
840 LyXParagraph::size_type pos) const
843 LyXParagraph::size_type tmp_pos = 0;
844 while (tmp_pos < pos) {
845 if (par->IsNewline(tmp_pos))
853 int LyXText::WidthOfCell(LyXParagraph * par,
854 LyXParagraph::size_type & pos) const
857 while (pos < par->Last() && !par->IsNewline(pos)) {
858 w += SingleWidth(par, pos);
861 if (par->IsNewline(pos))
867 bool LyXText::HitInTable(Row * row, int x) const
870 float fill_separator, fill_hfill, fill_label_hfill;
871 if (!row->par->table)
873 PrepareToPrint(row, tmpx, fill_separator,
874 fill_hfill, fill_label_hfill, false);
875 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
879 bool LyXText::MouseHitInTable(int x, long y) const
881 Row * row = GetRowNearY(y);
882 return HitInTable(row, x);
886 /* table stuff -- end*/
889 // get the next breakpoint in a given paragraph
890 LyXParagraph::size_type
891 LyXText::NextBreakPoint(Row const * row, int width) const
893 LyXParagraph * par = row->par;
894 LyXParagraph::size_type pos = row->pos;
896 /* table stuff -- begin*/
898 while (pos < par->size()
899 && (!par->IsNewline(pos)
900 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
901 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
902 par->GetInset(pos) && par->GetInset(pos)->display()){
903 par->GetInset(pos)->display(false);
909 /* table stuff -- end*/
911 // position of the last possible breakpoint
912 // -1 isn't a suitable value, but a flag
913 LyXParagraph::size_type last_separator = -1;
914 width -= RightMargin(row);
916 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
917 LyXLayout const & layout =
918 textclasslist.Style(parameters->textclass, par->GetLayout());
919 LyXParagraph::size_type i = pos;
921 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
922 /* special code for right address boxes, only newlines count */
923 while (i < par->Last()) {
924 if (par->IsNewline(i)) {
926 i = par->Last() - 1; // this means break
928 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
929 par->GetInset(i) && par->GetInset(i)->display()){
930 par->GetInset(i)->display(false);
935 // Last position is an invariant
936 LyXParagraph::size_type const last =
938 // this is the usual handling
939 int x = LeftMargin(row);
940 while (x < width && i < last) {
941 char c = par->GetChar(i);
942 if (IsNewlineChar(c)) {
944 x = width; // this means break
945 } else if (c == LyXParagraph::META_INSET &&
946 par->GetInset(i) && par->GetInset(i)->display()){
947 // check wether a Display() inset is
948 // valid here. if not, change it to
950 if (layout.isCommand()
951 || (layout.labeltype == LABEL_MANUAL
952 && i < BeginningOfMainBody(par))){
953 // display istn't allowd
954 par->GetInset(i)->display(false);
955 x += SingleWidth(par, i, c);
957 // inset is display. So break the line here
961 if (IsLineSeparatorChar(par->GetChar(i+1)))
964 last_separator = last; // to avoid extra rows
966 last_separator = i - 1;
967 x = width; // this means break
970 if (IsLineSeparatorChar(c))
972 x += SingleWidth(par, i, c);
975 if (i == main_body) {
976 x += GetFont(par, -2).stringWidth(layout.labelsep);
977 if (par->IsLineSeparator(i - 1))
978 x-= SingleWidth(par, i - 1);
979 int left_margin = LabelEnd(row);
984 // end of paragraph is always a suitable separator
985 if (i == last && x < width)
989 // well, if last_separator is still 0, the line isn't breakable.
990 // don't care and cut simply at the end
991 if (last_separator < 0) {
995 // manual labels cannot be broken in LaTeX, do not care
996 if (main_body && last_separator < main_body)
997 last_separator = main_body - 1;
999 return last_separator;
1003 // returns the minimum space a row needs on the screen in pixel
1004 int LyXText::Fill(Row const * row, int paper_width) const
1007 // get the pure distance
1008 LyXParagraph::size_type last = RowLast(row);
1009 /* table stuff -- begin */
1010 if (row->par->table) {
1011 // for tables FILL does calculate the widthes of each cell in
1013 LyXParagraph::size_type pos = row->pos;
1014 int cell = NumberOfCell(row->par, pos);
1017 row->par->table->SetWidthOfCell(cell,
1018 WidthOfCell(row->par,
1021 } while (pos <= last && !row->par->table->IsFirstCell(cell));
1022 // don't forget the very last table cell without characters
1023 if (cell == row->par->table->GetNumberOfCells() - 1)
1024 row->par->table->SetWidthOfCell(cell,
1025 WidthOfCell(row->par,
1028 return 0; /* width of table cannot be returned since
1029 * we cannot guarantee its correct value at
1032 /* table stuff -- end*/
1034 // if the row ends with newline, this newline will not be relevant
1035 //if (last >= 0 && row->par->IsNewline(last))
1038 // if the row ends with a space, this space will not be relevant
1039 if (last >= 0 && row->par->IsLineSeparator(last))
1042 // special handling of the right address boxes
1043 if (textclasslist.Style(parameters->textclass,
1044 row->par->GetLayout()).margintype
1045 == MARGIN_RIGHT_ADDRESS_BOX) {
1046 int tmpfill = row->fill;
1047 row->fill = 0; // the minfill in MarginLeft()
1048 w = LeftMargin(row);
1049 row->fill = tmpfill;
1051 w = LeftMargin(row);
1053 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1054 row->par->GetLayout());
1055 LyXParagraph::size_type main_body =
1056 BeginningOfMainBody(row->par);
1057 LyXParagraph::size_type i = row->pos;
1060 if (main_body > 0 && i == main_body) {
1061 w += GetFont(row->par, -2).
1062 stringWidth(layout.labelsep);
1063 if (row->par->IsLineSeparator(i - 1))
1064 w -= SingleWidth(row->par, i - 1);
1065 int left_margin = LabelEnd(row);
1066 if (w < left_margin)
1069 w += SingleWidth(row->par, i);
1072 if (main_body > 0 && main_body > last) {
1073 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
1074 if (last >= 0 && row->par->IsLineSeparator(last))
1075 w -= SingleWidth(row->par, last);
1076 int left_margin = LabelEnd(row);
1077 if (w < left_margin)
1081 fill = paper_width - w - RightMargin(row);
1086 // returns the minimum space a manual label needs on the screen in pixel
1087 int LyXText::LabelFill(Row const * row) const
1089 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1090 // -1 because a label ends either with a space that is in the label,
1091 // or with the beginning of a footnote that is outside the label.
1093 // I don't understand this code in depth, but sometimes "last" is
1094 // less than 0 and this causes a crash. This fix seems to work
1095 // correctly, but I bet the real error is elsewhere. The bug is
1096 // triggered when you have an open footnote in a paragraph
1097 // environment with a manual label. (Asger)
1098 if (last < 0) last = 0;
1100 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1107 w += SingleWidth(row->par, i);
1112 if (!row->par->labelwidthstring.empty()) {
1113 fill = GetFont(row->par, -2)
1114 .stringWidth(row->par->labelwidthstring) - w;
1124 // returns the number of separators in the specified row. The separator
1125 // on the very last column doesnt count
1126 int LyXText::NumberOfSeparators(Row const * row) const
1128 int last = RowLast(row);
1129 int p = max(row->pos, BeginningOfMainBody(row->par));
1131 for (; p < last; ++p) {
1132 if (row->par->IsSeparator(p)) {
1140 // returns the number of hfills in the specified row. The LyX-Hfill is
1141 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1142 // ignored. This is *MUCH* more usefull than not to ignore!
1143 int LyXText::NumberOfHfills(Row const * row) const
1145 int last = RowLast(row);
1146 int first = row->pos;
1147 if (first) { /* hfill *DO* count at the beginning
1149 while(first <= last && row->par->IsHfill(first))
1153 first = max(first, BeginningOfMainBody(row->par));
1155 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1156 if (row->par->IsHfill(p)) {
1164 // like NumberOfHfills, but only those in the manual label!
1165 int LyXText::NumberOfLabelHfills(Row const * row) const
1167 LyXParagraph::size_type last = RowLast(row);
1168 LyXParagraph::size_type first = row->pos;
1169 if (first) { /* hfill *DO* count at the beginning
1171 while(first < last && row->par->IsHfill(first))
1175 last = min(last, BeginningOfMainBody(row->par));
1177 for (LyXParagraph::size_type p = first;
1178 p < last; ++p) { // last, because the end is ignored!
1179 if (row->par->IsHfill(p)) {
1187 // returns true, if a expansion is needed.
1188 // Rules are given by LaTeX
1189 bool LyXText::HfillExpansion(Row const * row_ptr,
1190 LyXParagraph::size_type pos) const
1192 // by the way, is it a hfill?
1193 if (!row_ptr->par->IsHfill(pos))
1196 // at the end of a row it does not count
1197 if (pos >= RowLast(row_ptr))
1200 // at the beginning of a row it does not count, if it is not
1201 // the first row of a paragaph
1205 // in some labels it does not count
1206 if (textclasslist.Style(parameters->textclass,
1207 row_ptr->par->GetLayout()).margintype
1209 && pos < BeginningOfMainBody(row_ptr->par))
1212 // if there is anything between the first char of the row and
1213 // the sepcified position that is not a newline and not a hfill,
1214 // the hfill will count, otherwise not
1215 LyXParagraph::size_type i = row_ptr->pos;
1216 while (i < pos && (row_ptr->par->IsNewline(i)
1217 || row_ptr->par->IsHfill(i)))
1224 void LyXText::SetHeightOfRow(Row * row_ptr) const
1226 /* get the maximum ascent and the maximum descent */
1228 float layoutasc = 0;
1229 float layoutdesc = 0;
1234 /* this must not happen before the currentrow for clear reasons.
1235 so the trick is just to set the current row onto this row */
1237 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1239 /* ok , let us initialize the maxasc and maxdesc value.
1240 * This depends in LaTeX of the font of the last character
1241 * in the paragraph. The hack below is necessary because
1242 * of the possibility of open footnotes */
1244 /* Correction: only the fontsize count. The other properties
1245 are taken from the layoutfont. Nicer on the screen :) */
1247 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1248 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1250 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1251 firstpar->GetLayout());
1253 LyXFont font = GetFont(par, par->Last()-1);
1254 LyXFont::FONT_SIZE size = font.size();
1255 font = GetFont(par, -1);
1258 LyXFont labelfont = GetFont(par, -2);
1260 int maxasc = int(font.maxAscent() *
1261 layout.spacing.getValue() *
1262 parameters->spacing.getValue());
1263 int maxdesc = int(font.maxDescent() *
1264 layout.spacing.getValue() *
1265 parameters->spacing.getValue());
1267 int pos_end = RowLast(row_ptr);
1271 // Check if any insets are larger
1272 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1273 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1274 tmpfont = GetFont(row_ptr->par, pos);
1275 tmpinset = row_ptr->par->GetInset(pos);
1277 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1278 desc = tmpinset->descent(owner_->painter(), tmpfont);
1287 // Check if any custom fonts are larger (Asger)
1288 // This is not completely correct, but we can live with the small,
1289 // cosmetic error for now.
1290 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1292 if (maxsize > font.size()) {
1293 font.setSize(maxsize);
1295 asc = font.maxAscent();
1296 desc = font.maxDescent();
1303 /* table stuff -- begin*/
1304 if (row_ptr->par->table){
1305 // stretch the rows a bit
1309 /* table stuff -- end*/
1311 // This is nicer with box insets:
1315 row_ptr->ascent_of_text = maxasc;
1317 /* is it a top line? */
1318 if (row_ptr->pos == 0
1319 && row_ptr->par == firstpar) {
1321 /* some parksips VERY EASY IMPLEMENTATION */
1322 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1323 if (layout.isParagraph()
1324 && firstpar->GetDepth() == 0
1325 && firstpar->Previous())
1326 maxasc += parameters->getDefSkip().inPixels(owner_);
1327 else if (firstpar->Previous()
1328 && textclasslist.Style(parameters->textclass,
1329 firstpar->Previous()->GetLayout()).isParagraph()
1330 && firstpar->Previous()->GetDepth() == 0)
1331 // is it right to use defskip here too? (AS)
1332 maxasc += parameters->getDefSkip().inPixels(owner_);
1335 /* the paper margins */
1336 if (!row_ptr->par->previous)
1337 maxasc += LYX_PAPER_MARGIN;
1339 /* add the vertical spaces, that the user added */
1340 if (firstpar->added_space_top.kind() != VSpace::NONE)
1341 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1343 /* do not forget the DTP-lines!
1344 * there height depends on the font of the nearest character */
1345 if (firstpar->line_top)
1346 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1348 /* and now the pagebreaks */
1349 if (firstpar->pagebreak_top)
1350 maxasc += 3 * DefaultHeight();
1352 /* this is special code for the chapter, since the label of this
1353 * layout is printed in an extra row */
1354 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1355 && parameters->secnumdepth>= 0) {
1356 labeladdon = int(labelfont.maxDescent() *
1357 layout.spacing.getValue() *
1358 parameters->spacing.getValue())
1359 + int(labelfont.maxAscent() *
1360 layout.spacing.getValue() *
1361 parameters->spacing.getValue());
1364 /* special code for the top label */
1365 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1366 || layout.labeltype == LABEL_BIBLIO
1367 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1368 && row_ptr->par->IsFirstInSequence()
1369 && !row_ptr->par->GetLabestring().empty()) {
1371 (labelfont.maxAscent() *
1372 layout.spacing.getValue() *
1373 parameters->spacing.getValue())
1374 +(labelfont.maxDescent() *
1375 layout.spacing.getValue() *
1376 parameters->spacing.getValue())
1377 + layout.topsep * DefaultHeight()
1378 + layout.labelbottomsep * DefaultHeight());
1381 /* and now the layout spaces, for example before and after a section,
1382 * or between the items of a itemize or enumerate environment */
1384 if (!firstpar->pagebreak_top) {
1385 LyXParagraph * prev = row_ptr->par->Previous();
1387 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1388 if (prev && prev->GetLayout() == firstpar->GetLayout()
1389 && prev->GetDepth() == firstpar->GetDepth()
1390 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1392 layoutasc = (layout.itemsep * DefaultHeight());
1394 else if (row_ptr->previous) {
1395 tmptop = layout.topsep;
1397 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1398 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1401 layoutasc = (tmptop * DefaultHeight());
1403 else if (row_ptr->par->line_top){
1404 tmptop = layout.topsep;
1407 layoutasc = (tmptop * DefaultHeight());
1410 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1412 maxasc += int(textclasslist.Style(parameters->textclass,
1413 prev->GetLayout()).parsep * DefaultHeight());
1416 if (firstpar->Previous()
1417 && firstpar->Previous()->GetDepth() == 0
1418 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1421 else if (firstpar->Previous()){
1422 maxasc += int(layout.parsep * DefaultHeight());
1428 /* is it a bottom line? */
1429 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1430 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1432 /* the paper margins */
1434 maxdesc += LYX_PAPER_MARGIN;
1436 /* add the vertical spaces, that the user added */
1437 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1438 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1440 /* do not forget the DTP-lines!
1441 * there height depends on the font of the nearest character */
1442 if (firstpar->line_bottom)
1443 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1445 /* and now the pagebreaks */
1446 if (firstpar->pagebreak_bottom)
1447 maxdesc += 3 * DefaultHeight();
1449 /* and now the layout spaces, for example before and after a section,
1450 * or between the items of a itemize or enumerate environment */
1451 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1452 LyXParagraph * nextpar = row_ptr->par->Next();
1453 LyXParagraph * comparepar = row_ptr->par;
1457 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1458 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1459 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1460 if (comparepar->GetLayout()!= nextpar->GetLayout()
1461 || nextpar->GetLabelWidthString() !=
1462 comparepar->GetLabelWidthString())
1463 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1465 if (unusual > usual)
1466 layoutdesc = unusual;
1470 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1472 if (comparepar->GetLayout()!= nextpar->GetLayout()
1473 || nextpar->GetLabelWidthString() !=
1474 comparepar->GetLabelWidthString())
1475 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1480 /* incalculate the layout spaces */
1481 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1482 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1484 /* table stuff -- begin*/
1485 if (row_ptr->par->table){
1486 maxasc += row_ptr->par->table->
1487 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1489 /* table stuff -- end*/
1491 /* calculate the new height of the text */
1492 height -= row_ptr->height;
1494 row_ptr->height = maxasc + maxdesc + labeladdon;
1495 row_ptr->baseline = maxasc + labeladdon;
1497 height += row_ptr->height;
1501 /* Appends the implicit specified paragraph behind the specified row,
1502 * start at the implicit given position */
1503 void LyXText::AppendParagraph(Row * row) const
1505 bool not_ready = true;
1507 // The last character position of a paragraph is an invariant so we can
1508 // safely get it here. (Asger)
1509 int lastposition = row->par->Last();
1512 // Get the next breakpoint
1513 int z = NextBreakPoint(row, paperwidth);
1517 // Insert the new row
1518 if (z < lastposition) {
1520 InsertRow(row, row->par, z);
1527 // Set the dimensions of the row
1528 tmprow->fill = Fill(tmprow, paperwidth);
1529 SetHeightOfRow(tmprow);
1531 } while (not_ready);
1535 void LyXText::BreakAgain(Row * row) const
1537 bool not_ready = true;
1540 /* get the next breakpoint */
1541 LyXParagraph::size_type z =
1542 NextBreakPoint(row, paperwidth);
1545 if (z < row->par->Last() ) {
1546 if (!row->next || (row->next && row->next->par != row->par)) {
1549 InsertRow(row, row->par, z);
1556 not_ready = false; // the rest will not change
1562 /* if there are some rows too much, delete them */
1563 /* only if you broke the whole paragraph! */
1564 Row * tmprow2 = row;
1565 while (tmprow2->next && tmprow2->next->par == row->par) {
1566 tmprow2 = tmprow2->next;
1568 while (tmprow2 != row) {
1569 tmprow2 = tmprow2->previous;
1570 RemoveRow(tmprow2->next);
1575 /* set the dimensions of the row */
1576 tmprow->fill = Fill(tmprow, paperwidth);
1577 SetHeightOfRow(tmprow);
1578 } while (not_ready);
1582 /* this is just a little changed version of break again */
1583 void LyXText::BreakAgainOneRow(Row * row)
1585 /* get the next breakpoint */
1586 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1589 if (z < row->par->Last() ) {
1590 if (!row->next || (row->next && row->next->par != row->par)) {
1591 /* insert a new row */
1593 InsertRow(row, row->par, z);
1605 /* if there are some rows too much, delete them */
1606 /* only if you broke the whole paragraph! */
1607 Row * tmprow2 = row;
1608 while (tmprow2->next && tmprow2->next->par == row->par) {
1609 tmprow2 = tmprow2->next;
1611 while (tmprow2 != row) {
1612 tmprow2 = tmprow2->previous;
1613 RemoveRow(tmprow2->next);
1617 /* set the dimensions of the row */
1618 tmprow->fill = Fill(tmprow, paperwidth);
1619 SetHeightOfRow(tmprow);
1623 void LyXText::BreakParagraph(char keep_layout)
1625 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1626 cursor.par->GetLayout());
1628 /* table stuff -- begin */
1629 if (cursor.par->table) {
1630 // breaking of tables is only allowed at the beginning or the end */
1631 if (cursor.pos && cursor.pos < cursor.par->size() &&
1632 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1633 return; // no breaking of tables allowed
1635 /* table stuff -- end */
1637 // this is only allowed, if the current paragraph is not empty or caption
1638 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1640 layout.labeltype!= LABEL_SENSITIVE)
1643 SetUndo(Undo::INSERT,
1644 cursor.par->ParFromPos(cursor.pos)->previous,
1645 cursor.par->ParFromPos(cursor.pos)->next);
1647 /* table stuff -- begin */
1648 if (cursor.par->table) {
1649 int cell = NumberOfCell(cursor.par, cursor.pos);
1650 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1651 SetCursor(cursor.par, cursor.par->size());
1653 /* table stuff -- end */
1655 // please break always behind a space
1656 if (cursor.pos < cursor.par->Last()
1657 && cursor.par->IsLineSeparator(cursor.pos))
1660 // break the paragraph
1664 keep_layout = layout.isEnvironment();
1665 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1667 /* table stuff -- begin */
1668 if (cursor.par->table){
1669 // the table should stay with the contents
1671 cursor.par->Next()->table = cursor.par->table;
1672 cursor.par->table = 0;
1675 /* table stuff -- end */
1677 // well this is the caption hack since one caption is really enough
1678 if (layout.labeltype == LABEL_SENSITIVE){
1680 cursor.par->SetLayout(0); // set to standard-layout
1682 cursor.par->Next()->SetLayout(0); // set to standard-layout
1685 /* if the cursor is at the beginning of a row without prior newline,
1687 * This touches only the screen-update. Otherwise we would may have
1688 * an empty row on the screen */
1689 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1690 cursor.row->pos == cursor.pos) {
1694 status = LyXText::NEED_MORE_REFRESH;
1695 refresh_row = cursor.row;
1696 refresh_y = cursor.y - cursor.row->baseline;
1698 // Do not forget the special right address boxes
1699 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1700 while (refresh_row->previous &&
1701 refresh_row->previous->par == refresh_row->par) {
1702 refresh_row = refresh_row->previous;
1703 refresh_y -= refresh_row->height;
1706 RemoveParagraph(cursor.row);
1708 // set the dimensions of the cursor row
1709 cursor.row->fill = Fill(cursor.row, paperwidth);
1711 SetHeightOfRow(cursor.row);
1713 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1714 && cursor.par->Next()->IsNewline(0))
1715 cursor.par->Next()->Erase(0);
1717 InsertParagraph(cursor.par->Next(), cursor.row);
1719 UpdateCounters(cursor.row->previous);
1721 /* This check is necessary. Otherwise the new empty paragraph will
1722 * be deleted automatically. And it is more friendly for the user! */
1724 SetCursor(cursor.par->Next(), 0);
1726 SetCursor(cursor.par, 0);
1728 if (cursor.row->next)
1729 BreakAgain(cursor.row->next);
1735 void LyXText::OpenFootnote()
1737 LyXParagraph * endpar,* tmppar;
1740 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1742 /* if there is no footnote in this paragraph, just return. */
1744 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1747 /* ok, move the cursor right before the footnote */
1749 /* just a little faster than using CursorRight() */
1750 for (cursor.pos = 0;
1751 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1752 /* now the cursor is at the beginning of the physical par */
1753 SetCursor(cursor.par,
1754 cursor.pos + cursor.par->ParFromPos(cursor.pos)->size());
1756 /* the cursor must be exactly before the footnote */
1757 par = cursor.par->ParFromPos(cursor.pos);
1759 status = LyXText::NEED_MORE_REFRESH;
1760 refresh_row = cursor.row;
1761 refresh_y = cursor.y - cursor.row->baseline;
1763 tmppar = cursor.par;
1764 endpar = cursor.par->Next();
1767 tmppar->OpenFootnote(cursor.pos);
1768 RemoveParagraph(row);
1769 /* set the dimensions of the cursor row */
1770 row->fill = Fill(row, paperwidth);
1771 SetHeightOfRow(row);
1772 #warning See comment on top of text.C
1773 tmppar = tmppar->Next();
1775 while (tmppar != endpar) {
1777 InsertParagraph(tmppar, row);
1778 while (row->next && row->next->par == tmppar)
1780 tmppar = tmppar->Next();
1783 SetCursor(par->next, 0);
1784 sel_cursor = cursor;
1788 /* table stuff -- begin*/
1790 void LyXText::TableFeatures(int feature, string const & val) const
1792 if (!cursor.par->table)
1793 return; /* this should never happen */
1795 int actCell = NumberOfCell(cursor.par, cursor.pos);
1796 SetUndo(Undo::FINISH,
1797 cursor.par->ParFromPos(cursor.pos)->previous,
1798 cursor.par->ParFromPos(cursor.pos)->next);
1801 case LyXTable::SET_PWIDTH:
1802 cursor.par->table->SetPWidth(actCell, val);
1804 case LyXTable::SET_SPECIAL_COLUMN:
1805 case LyXTable::SET_SPECIAL_MULTI:
1806 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1815 void LyXText::TableFeatures(int feature) const
1818 int setAlign = LYX_ALIGN_LEFT;
1822 if (!cursor.par->table)
1823 return; /* this should never happen */
1825 int actCell = NumberOfCell(cursor.par, cursor.pos);
1826 SetUndo(Undo::FINISH,
1827 cursor.par->ParFromPos(cursor.pos)->previous,
1828 cursor.par->ParFromPos(cursor.pos)->next);
1831 case LyXTable::ALIGN_LEFT:
1832 setAlign= LYX_ALIGN_LEFT;
1834 case LyXTable::ALIGN_RIGHT:
1835 setAlign= LYX_ALIGN_RIGHT;
1837 case LyXTable::ALIGN_CENTER:
1838 setAlign= LYX_ALIGN_CENTER;
1844 case LyXTable::APPEND_ROW: {
1845 LyXParagraph::size_type pos = cursor.pos;
1847 /* move to the next row */
1848 int cell_org = actCell;
1849 int cell = cell_org;
1851 // if there is a ContRow following this row I have to add
1852 // the row after the ContRow's
1853 if ((pos < cursor.par->Last()) &&
1854 cursor.par->table->RowHasContRow(cell_org)) {
1855 while((pos < cursor.par->Last()) &&
1856 !cursor.par->table->IsContRow(cell)) {
1857 while (pos < cursor.par->Last() &&
1858 !cursor.par->IsNewline(pos))
1860 if (pos < cursor.par->Last())
1864 while((pos < cursor.par->Last()) &&
1865 cursor.par->table->IsContRow(cell)) {
1866 while (pos < cursor.par->Last() &&
1867 !cursor.par->IsNewline(pos))
1869 if (pos < cursor.par->Last())
1874 if (pos < cursor.par->Last())
1877 while (pos < cursor.par->Last() &&
1878 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1879 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1881 if (pos < cursor.par->Last())
1886 /* insert the new cells */
1887 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1888 Language const * lang = cursor.par->getParLanguage();
1889 LyXFont font(LyXFont::ALL_INHERIT,lang);
1890 for (int i = 0; i < number; ++i) {
1891 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1892 cursor.par->SetFont(pos, font);
1895 /* append the row into the table */
1896 cursor.par->table->AppendRow(cell_org);
1900 case LyXTable::APPEND_CONT_ROW: {
1901 LyXParagraph::size_type pos = cursor.pos;
1902 /* move to the next row */
1903 int cell_org = actCell;
1904 int cell = cell_org;
1906 // if there is already a controw but not for this cell
1907 // the AppendContRow sets only the right values but does
1908 // not actually add a row
1909 if (cursor.par->table->RowHasContRow(cell_org) &&
1910 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1911 cursor.par->table->AppendContRow(cell_org);
1915 while (pos < cursor.par->Last() &&
1917 || !cursor.par->table->IsFirstCell(cell))){
1918 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1920 if (pos < cursor.par->Last())
1925 /* insert the new cells */
1926 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1927 Language const * lang = cursor.par->getParLanguage();
1928 LyXFont font(LyXFont::ALL_INHERIT,lang);
1929 for (int i = 0; i < number; ++i) {
1930 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1931 cursor.par->SetFont(pos, font);
1934 /* append the row into the table */
1935 cursor.par->table->AppendContRow(cell_org);
1939 case LyXTable::APPEND_COLUMN: {
1940 LyXParagraph::size_type pos = 0;
1941 int cell_org = actCell;
1943 Language const * lang = cursor.par->getParLanguage();
1944 LyXFont font(LyXFont::ALL_INHERIT,lang);
1946 if (pos && (cursor.par->IsNewline(pos-1))){
1947 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1948 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1949 cursor.par->SetFont(pos, font);
1950 if (pos <= cursor.pos)
1957 } while (pos <= cursor.par->Last());
1958 /* remember that the very last cell doesn't end with a newline.
1959 This saves one byte memory per table ;-) */
1960 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1961 LyXParagraph::size_type last = cursor.par->Last();
1962 cursor.par->InsertChar(last, LyXParagraph::META_NEWLINE);
1963 cursor.par->SetFont(last, font);
1966 /* append the column into the table */
1967 cursor.par->table->AppendColumn(cell_org);
1972 case LyXTable::DELETE_ROW:
1973 if (owner_->the_locking_inset)
1974 owner_->unlockInset(owner_->the_locking_inset);
1975 RemoveTableRow(&cursor);
1979 case LyXTable::DELETE_COLUMN: {
1980 LyXParagraph::size_type pos = 0;
1981 int cell_org = actCell;
1983 if (owner_->the_locking_inset)
1984 owner_->unlockInset(owner_->the_locking_inset);
1986 if (!pos || (cursor.par->IsNewline(pos-1))){
1987 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1989 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1990 cursor.par->Erase(pos);
1991 if (pos < cursor.par->Last())
1992 cursor.par->Erase(pos);
1994 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1995 --pos; // because of pos++ below
2000 } while (pos <= cursor.par->Last());
2002 /* delete the column from the table */
2003 cursor.par->table->DeleteColumn(cell_org);
2005 /* set the cursor to the beginning of the table, where else? */
2010 case LyXTable::TOGGLE_LINE_TOP:
2011 lineSet = !cursor.par->table->TopLine(actCell);
2013 cursor.par->table->SetTopLine(actCell, lineSet);
2015 LyXParagraph::size_type i;
2017 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2018 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2019 cursor.par->table->SetTopLine(n, lineSet);
2027 case LyXTable::TOGGLE_LINE_BOTTOM:
2028 lineSet = !cursor.par->table->BottomLine(actCell);
2030 cursor.par->table->SetBottomLine(actCell, lineSet);
2032 LyXParagraph::size_type i;
2034 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2035 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2036 cursor.par->table->SetBottomLine(n, lineSet);
2044 case LyXTable::TOGGLE_LINE_LEFT:
2045 lineSet = !cursor.par->table->LeftLine(actCell);
2047 cursor.par->table->SetLeftLine(actCell, lineSet);
2049 LyXParagraph::size_type i;
2051 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2052 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2053 cursor.par->table->SetLeftLine(n, lineSet);
2061 case LyXTable::TOGGLE_LINE_RIGHT:
2062 lineSet = !cursor.par->table->RightLine(actCell);
2064 cursor.par->table->SetRightLine(actCell, lineSet);
2067 LyXParagraph::size_type i = sel_start_cursor.pos;
2068 for (; i <= sel_end_cursor.pos; ++i) {
2069 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2070 cursor.par->table->SetRightLine(n, lineSet);
2078 case LyXTable::ALIGN_LEFT:
2079 case LyXTable::ALIGN_RIGHT:
2080 case LyXTable::ALIGN_CENTER:
2082 cursor.par->table->SetAlignment(actCell, setAlign);
2085 LyXParagraph::size_type i = sel_start_cursor.pos;
2086 for (; i <= sel_end_cursor.pos; ++i) {
2087 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2088 cursor.par->table->SetAlignment(n, setAlign);
2096 case LyXTable::DELETE_TABLE:
2097 SetCursorIntern(cursor.par, 0);
2098 delete cursor.par->table;
2099 cursor.par->table = 0;
2100 // temporary: Should put table in simple_cut_buffer (with before and after
2101 // dummy-paragraph !!
2102 // not necessar anymore with UNDO :)
2103 for (LyXParagraph::size_type i =
2104 cursor.par->size() - 1; i >= 0; --i)
2105 cursor.par->Erase(i);
2109 case LyXTable::MULTICOLUMN: {
2111 // check wether we are completly in a multicol
2112 int multicol = cursor.par->table->IsMultiColumn(actCell);
2113 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2114 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2115 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2119 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2120 LyXParagraph::size_type pos = cursor.pos;
2121 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2123 for (; newlines; --newlines)
2124 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2129 // selection must be in one row (or no selection)
2131 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2138 if (sel_start_cursor.row == sel_end_cursor.row){
2139 LyXParagraph::size_type i;
2141 for (i = sel_start_cursor.pos;
2142 i < sel_end_cursor.pos; ++i){
2143 if (sel_start_cursor.par->IsNewline(i)){
2144 sel_start_cursor.par->Erase(i);
2145 // check for double-blanks
2146 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2148 (i < sel_start_cursor.par->Last()
2149 && !sel_start_cursor.par->IsLineSeparator(i)))
2150 sel_start_cursor.par->InsertChar(i, ' ');
2152 sel_end_cursor.pos--;
2159 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2160 sel_start_cursor.pos),
2162 cursor.pos = sel_start_cursor.pos;
2167 WriteAlert(_("Impossible Operation!"),
2168 _("Multicolumns can only be horizontally."),
2175 case LyXTable::SET_ALL_LINES:
2177 case LyXTable::UNSET_ALL_LINES:
2179 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2183 LyXParagraph::size_type i;
2185 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2186 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2187 cursor.par->table->SetAllLines(n, setLines);
2194 case LyXTable::SET_LONGTABLE:
2195 cursor.par->table->SetLongTable(true);
2197 case LyXTable::UNSET_LONGTABLE:
2198 cursor.par->table->SetLongTable(false);
2200 case LyXTable::SET_ROTATE_TABLE:
2201 cursor.par->table->SetRotateTable(true);
2203 case LyXTable::UNSET_ROTATE_TABLE:
2204 cursor.par->table->SetRotateTable(false);
2206 case LyXTable::SET_ROTATE_CELL:
2208 cursor.par->table->SetRotateCell(actCell, true);
2210 LyXParagraph::size_type i;
2212 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2213 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2214 cursor.par->table->SetRotateCell(n, true);
2220 case LyXTable::UNSET_ROTATE_CELL:
2222 cursor.par->table->SetRotateCell(actCell, false);
2225 LyXParagraph::size_type i = sel_start_cursor.pos;
2226 for (; i <= sel_end_cursor.pos; ++i) {
2227 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2228 cursor.par->table->SetRotateCell(n, false);
2234 case LyXTable::SET_LINEBREAKS:
2235 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2237 cursor.par->table->SetLinebreaks(actCell, what);
2239 LyXParagraph::size_type i;
2241 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2242 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2243 cursor.par->table->SetLinebreaks(n, what);
2249 case LyXTable::SET_LTFIRSTHEAD:
2250 cursor.par->table->SetLTHead(actCell, true);
2252 case LyXTable::SET_LTHEAD:
2253 cursor.par->table->SetLTHead(actCell, false);
2255 case LyXTable::SET_LTFOOT:
2256 cursor.par->table->SetLTFoot(actCell, false);
2258 case LyXTable::SET_LTLASTFOOT:
2259 cursor.par->table->SetLTFoot(actCell, true);
2261 case LyXTable::SET_LTNEWPAGE:
2262 what = !cursor.par->table->LTNewPage(actCell);
2263 cursor.par->table->SetLTNewPage(actCell, what);
2269 void LyXText::InsertCharInTable(char c)
2274 bool jumped_over_space;
2276 /* first check, if there will be two blanks together or a blank at
2277 * the beginning of a paragraph.
2278 * I decided to handle blanks like normal characters, the main
2279 * difference are the special checks when calculating the row.fill
2280 * (blank does not count at the end of a row) and the check here */
2282 LyXFont realtmpfont = real_current_font;
2283 LyXFont rawtmpfont = current_font; /* store the current font.
2284 * This is because of the use
2285 * of cursor movements. The moving
2286 * cursor would refresh the
2289 // Get the font that is used to calculate the baselineskip
2290 LyXParagraph::size_type const lastpos =
2292 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2294 jumped_over_space = false;
2295 if (IsLineSeparatorChar(c)) {
2297 #ifndef FIX_DOUBLE_SPACE
2298 /* avoid double blanks but insert the new blank because
2299 * of a possible font change */
2300 if (cursor.pos < lastpos &&
2301 cursor.par->IsLineSeparator(cursor.pos)) {
2302 cursor.par->Erase(cursor.pos);
2303 jumped_over_space = true;
2306 if ((cursor.pos > 0 &&
2307 cursor.par->IsLineSeparator(cursor.pos - 1))
2308 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2309 || (cursor.pos == 0 &&
2310 !(cursor.par->Previous()
2311 && cursor.par->Previous()->footnoteflag
2312 == LyXParagraph::OPEN_FOOTNOTE)))
2314 } else if (IsNewlineChar(c)) {
2315 if (!IsEmptyTableCell()) {
2316 TableFeatures(LyXTable::APPEND_CONT_ROW);
2323 y = cursor.y - row->baseline;
2324 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2325 * already inserted the character */
2326 cursor.par->InsertChar(cursor.pos, c);
2327 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2329 if (!jumped_over_space) {
2330 /* refresh the positions */
2332 while (tmprow->next && tmprow->next->par == row->par) {
2333 tmprow = tmprow->next;
2340 CheckParagraphInTable(cursor.par, cursor.pos);
2342 current_font = rawtmpfont;
2343 real_current_font = realtmpfont;
2345 /* check, whether the last character's font has changed. */
2346 if (cursor.pos && cursor.pos == cursor.par->Last()
2347 && rawparfont != rawtmpfont)
2348 RedoHeightOfParagraph(cursor);
2352 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2353 LyXParagraph::size_type pos)
2356 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2357 par->GetInset(pos) && par->GetInset(pos)->display()){
2358 par->GetInset(pos)->display(false);
2362 Row * row = GetRow(par, pos, y);
2364 int tmpheight = row->height;
2365 SetHeightOfRow(row);
2367 LyXParagraph::size_type tmp_pos = pos;
2368 /* update the table information */
2369 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2371 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2372 WidthOfCell(par, tmp_pos))) {
2373 LyXCursor tmpcursor = cursor;
2374 SetCursorIntern(par, pos);
2375 /* make a complete redraw */
2376 RedoDrawingOfParagraph(cursor);
2380 /* redraw only the row */
2381 LyXCursor tmpcursor = cursor;
2382 SetCursorIntern(par, pos);
2383 #warning See comment on top of text.C
2385 refresh_x = cursor.x;
2387 refresh_pos = cursor.pos;
2390 if (tmpheight == row->height)
2391 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2393 status = LyXText::NEED_MORE_REFRESH;
2395 SetCursorIntern(cursor.par, cursor.pos);
2399 void LyXText::BackspaceInTable()
2401 Row * tmprow, * row;
2404 LyXFont rawtmpfont = current_font;
2405 LyXFont realtmpfont = real_current_font;
2407 // Get the font that is used to calculate the baselineskip
2408 int const lastpos = cursor.par->Last();
2409 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2411 if (cursor.pos == 0) {
2412 /* no pasting of table paragraphs */
2416 /* this is the code for a normal backspace, not pasting
2418 SetUndo(Undo::DELETE,
2419 cursor.par->ParFromPos(cursor.pos)->previous,
2420 cursor.par->ParFromPos(cursor.pos)->next);
2424 /* some insets are undeletable here */
2425 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2426 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2431 y = cursor.y - row->baseline;
2433 /* some special code when deleting a newline. */
2434 if (cursor.par->IsNewline(cursor.pos)) {
2439 cursor.par->Erase(cursor.pos);
2441 /* refresh the positions */
2443 while (tmprow->next && tmprow->next->par == row->par) {
2444 tmprow = tmprow->next;
2448 #ifndef FIX_DOUBLE_SPACE
2449 /* delete superfluous blanks */
2450 if (cursor.pos < cursor.par->Last() - 1 &&
2451 (cursor.par->IsLineSeparator(cursor.pos))) {
2453 if (cursor.pos == BeginningOfMainBody(cursor.par)
2455 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2456 cursor.par->Erase(cursor.pos);
2457 /* refresh the positions */
2459 while (tmprow->next &&
2460 tmprow->next->par == row->par) {
2461 tmprow = tmprow->next;
2464 if (cursor.pos) /* move one character left */
2471 CheckParagraphInTable(cursor.par, cursor.pos);
2473 /* check, wether the last characters font has changed. */
2474 if (cursor.pos && cursor.pos == cursor.par->Last()
2475 && rawparfont != rawtmpfont)
2476 RedoHeightOfParagraph(cursor);
2478 /* restore the current font
2479 * That is what a user expects! */
2480 current_font = rawtmpfont;
2481 real_current_font = realtmpfont;
2483 SetCursorIntern(cursor.par, cursor.pos);
2486 /* table stuff -- end*/
2489 /* just a macro to make some thing easier. */
2490 void LyXText::RedoParagraph() const
2493 // I suspect this version will work
2496 RedoParagraphs(cursor, cursor.par->Next());
2497 SetCursorIntern(cursor.par, cursor.pos);
2499 LyXCursor tmpcursor = cursor;
2501 RedoParagraphs(cursor, cursor.par->Next());
2502 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2507 /* insert a character, moves all the following breaks in the
2508 * same Paragraph one to the right and make a rebreak */
2509 void LyXText::InsertChar(char c)
2511 SetUndo(Undo::INSERT,
2512 cursor.par->ParFromPos(cursor.pos)->previous,
2513 cursor.par->ParFromPos(cursor.pos)->next);
2515 /* When the free-spacing option is set for the current layout,
2516 * disable the double-space checking */
2519 textclasslist.Style(parameters->textclass,
2520 cursor.row->par->GetLayout()).free_spacing;
2522 /* table stuff -- begin*/
2523 if (cursor.par->table) {
2524 InsertCharInTable(c);
2528 /* table stuff -- end*/
2530 /* First check, if there will be two blanks together or a blank at
2531 the beginning of a paragraph.
2532 I decided to handle blanks like normal characters, the main
2533 difference are the special checks when calculating the row.fill
2534 (blank does not count at the end of a row) and the check here */
2536 // The bug is triggered when we type in a description environment:
2537 // The current_font is not changed when we go from label to main text
2538 // and it should (along with realtmpfont) when we type the space.
2539 #ifdef WITH_WARNINGS
2540 #warning There is a bug here! (Asger)
2543 LyXFont realtmpfont = real_current_font;
2544 LyXFont rawtmpfont = current_font; /* store the current font.
2545 * This is because of the use
2546 * of cursor movements. The moving
2547 * cursor would refresh the
2550 // Get the font that is used to calculate the baselineskip
2551 LyXParagraph::size_type lastpos = cursor.par->Last();
2552 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2554 bool jumped_over_space = false;
2556 if (!freeSpacing && IsLineSeparatorChar(c)) {
2557 #ifndef FIX_DOUBLE_SPACE
2558 if (cursor.pos < lastpos
2559 && cursor.par->IsLineSeparator(cursor.pos)) {
2560 /* the user inserted a space before a space. So we
2561 * will just make a CursorRight. BUT: The font of this
2562 * space should be set to current font. That is why
2563 * we need to rebreak perhaps. If there is a protected
2564 * blank at the end of a row we have to force
2567 owner_->owner()->getMiniBuffer()
2568 ->Set(_("You cannot type two spaces this way. "
2569 " Please read the Tutorial."));
2571 // How can this ever happen?
2572 if (cursor.pos == RowLast(cursor.row)
2573 && !IsLineSeparatorChar(c))
2574 cursor.row->fill = -1; // force rebreak
2575 cursor.par->Erase(cursor.pos);
2576 jumped_over_space = true;
2578 // Seems to me that this works just as well.
2586 && cursor.par->IsLineSeparator(cursor.pos - 1))
2588 && cursor.par->IsNewline(cursor.pos - 1))
2590 && !(cursor.par->Previous()
2591 && cursor.par->Previous()->footnoteflag
2592 == LyXParagraph::OPEN_FOOTNOTE))) {
2593 if (cursor.pos == 0 )
2594 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2596 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2600 } else if (IsNewlineChar(c)) {
2601 if (cursor.par->FirstPhysicalPar() == cursor.par
2602 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2606 /* No newline at first position
2607 * of a paragraph or behind labels.
2608 * TeX does not allow that. */
2610 if (cursor.pos < cursor.par->Last() &&
2611 cursor.par->IsLineSeparator(cursor.pos))
2612 CursorRightIntern(); // newline always after a blank!
2613 cursor.row->fill = -1; // to force a new break
2616 // the display inset stuff
2617 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2618 && cursor.row->par->GetInset(cursor.row->pos)
2619 && cursor.row->par->GetInset(cursor.row->pos)->display())
2620 cursor.row->fill = -1; // to force a new break
2622 // get the cursor row fist
2623 Row * row = cursor.row;
2624 long y = cursor.y - row->baseline;
2625 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2626 * already insertet the character */
2627 cursor.par->InsertChar(cursor.pos, c);
2628 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2630 if (!jumped_over_space) {
2631 // refresh the positions
2633 while (tmprow->next && tmprow->next->par == row->par) {
2634 tmprow = tmprow->next;
2639 // Is there a break one row above
2640 if ((cursor.par->IsLineSeparator(cursor.pos)
2641 || cursor.par->IsNewline(cursor.pos)
2642 || cursor.row->fill == -1)
2643 && row->previous && row->previous->par == row->par) {
2644 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2646 if ( z >= row->pos) {
2649 // set the dimensions of the row above
2650 row->previous->fill = Fill(row->previous, paperwidth);
2652 SetHeightOfRow(row->previous);
2654 y -= row->previous->height;
2656 refresh_row = row->previous;
2657 status = LyXText::NEED_MORE_REFRESH;
2659 BreakAgainOneRow(row);
2661 current_font = rawtmpfont;
2662 real_current_font = realtmpfont;
2663 SetCursor(cursor.par, cursor.pos + 1, false);
2664 /* cursor MUST be in row now */
2666 if (row->next && row->next->par == row->par)
2667 need_break_row = row->next;
2671 // check, wether the last characters font has changed.
2672 if (cursor.pos && cursor.pos == cursor.par->Last()
2673 && rawparfont != rawtmpfont)
2674 RedoHeightOfParagraph(cursor);
2681 /* recalculate the fill of the row */
2682 if (row->fill >= 0) /* needed because a newline
2683 * will set fill to -1. Otherwise
2684 * we would not get a rebreak! */
2685 row->fill = Fill(row, paperwidth);
2686 if (row->fill < 0 ) {
2689 refresh_x = cursor.x;
2690 refresh_pos = cursor.pos;
2691 status = LyXText::NEED_MORE_REFRESH;
2692 BreakAgainOneRow(row);
2693 /* will the cursor be in another row now? */
2694 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2695 if (row->next && row->next->par == row->par)
2699 BreakAgainOneRow(row);
2701 current_font = rawtmpfont;
2702 real_current_font = realtmpfont;
2703 SetCursor(cursor.par, cursor.pos + 1, false);
2704 if (row->next && row->next->par == row->par)
2705 need_break_row = row->next;
2710 refresh_x = cursor.x;
2712 refresh_pos = cursor.pos;
2714 int tmpheight = row->height;
2715 SetHeightOfRow(row);
2716 if (tmpheight == row->height)
2717 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2719 status = LyXText::NEED_MORE_REFRESH;
2721 current_font = rawtmpfont;
2722 real_current_font = realtmpfont;
2723 SetCursor(cursor.par, cursor.pos + 1, false);
2726 /* check, wether the last characters font has changed. */
2727 if (cursor.pos && cursor.pos == cursor.par->Last()
2728 && rawparfont != rawtmpfont) {
2729 RedoHeightOfParagraph(cursor);
2731 /* now the special right address boxes */
2732 if (textclasslist.Style(parameters->textclass,
2733 cursor.par->GetLayout()).margintype
2734 == MARGIN_RIGHT_ADDRESS_BOX) {
2735 RedoDrawingOfParagraph(cursor);
2743 void LyXText::charInserted()
2745 // Here we could call FinishUndo for every 20 characters inserted.
2746 // This is from my experience how emacs does it.
2747 static unsigned int counter = 0;
2756 void LyXText::PrepareToPrint(Row * row, float & x,
2757 float & fill_separator,
2759 float & fill_label_hfill,
2764 float w = row->fill;
2766 fill_label_hfill = 0;
2768 fill_label_hfill = 0;
2770 LyXDirection direction = row->par->getParDirection();
2772 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2773 x = RightMargin(row);
2774 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2775 LyXFont font(LyXFont::ALL_SANE);
2776 font.setSize(LyXFont::SIZE_SMALL);
2777 x += font.textWidth("Mwide-figM", 10);
2781 x = LeftMargin(row);
2783 /* is there a manual margin with a manual label */
2784 if (textclasslist.Style(parameters->textclass,
2785 row->par->GetLayout()).margintype == MARGIN_MANUAL
2786 && textclasslist.Style(parameters->textclass,
2787 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2789 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2790 * are left aligned*/
2791 if (nlh && !row->par->GetLabelWidthString().empty()) {
2792 fill_label_hfill = LabelFill(row) / nlh;
2796 /* are there any hfills in the row? */
2797 nh = NumberOfHfills(row);
2799 /* table stuff -- begin*/
2800 if (row->par->table) {
2801 w = paperwidth - row->par->table->WidthOfTable()
2802 - x - RightMargin(row);
2803 nh = 0; /* ignore hfills in tables */
2805 /* table stuff -- end*/
2810 /* is it block, flushleft or flushright?
2811 * set x how you need it */
2813 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2814 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2816 align = row->par->FirstPhysicalPar()->align;
2818 /* center displayed insets */
2819 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2820 && row->par->GetInset(row->pos)
2821 && row->par->GetInset(row->pos)->display())
2822 align = LYX_ALIGN_CENTER;
2825 case LYX_ALIGN_BLOCK:
2826 ns = NumberOfSeparators(row);
2827 if (ns && row->next && row->next->par == row->par &&
2828 !(row->next->par->IsNewline(row->next->pos-1))
2829 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2830 && row->next->par->GetInset(row->next->pos)
2831 && row->next->par->GetInset(row->next->pos)->display())
2833 fill_separator = w / ns;
2834 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2837 case LYX_ALIGN_RIGHT:
2840 case LYX_ALIGN_CENTER:
2848 ComputeBidiTables(row);
2849 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2850 LyXParagraph::size_type main_body =
2851 BeginningOfMainBody(row->par);
2852 LyXParagraph::size_type last = RowLast(row);
2854 if (row->pos <= last
2856 && last != vis2log(last)
2857 && row->par->IsLineSeparator(last)) {
2858 if (!(main_body > 0 && main_body-1 == last))
2859 x -= fill_separator+SingleWidth(row->par,last);
2860 } else if (main_body > 0 &&
2861 (main_body-1 > last ||
2862 !row->par->IsLineSeparator(main_body-1))) {
2863 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2864 row->par->GetLayout());
2865 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2866 if (main_body-1 <= last)
2867 x += fill_label_hfill;
2872 /* important for the screen */
2875 /* the cursor set functions have a special mechanism. When they
2876 * realize, that you left an empty paragraph, they will delete it.
2877 * They also delete the corresponding row */
2879 void LyXText::CursorRightOneWord() const
2881 // treat floats, HFills and Insets as words
2882 LyXCursor tmpcursor = cursor;
2883 #warning See comment on top of text.C
2885 if (tmpcursor.pos == tmpcursor.par->Last()
2886 && tmpcursor.par->Next())
2888 tmpcursor.par = tmpcursor.par->Next();
2893 // Skip through initial nonword stuff.
2894 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2895 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2897 // printf("Current pos1 %d", tmpcursor.pos) ;
2901 // Advance through word.
2902 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2903 tmpcursor.par->IsWord( tmpcursor.pos ) )
2905 // printf("Current pos2 %d", tmpcursor.pos) ;
2910 SetCursor(tmpcursor.par, tmpcursor.pos);
2914 void LyXText::CursorTab() const
2916 if (cursor.par->table) {
2917 int cell = NumberOfCell(cursor.par, cursor.pos);
2918 while(cursor.par->table->IsContRow(cell)) {
2920 cell = NumberOfCell(cursor.par, cursor.pos);
2922 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2923 TableFeatures(LyXTable::APPEND_ROW);
2925 LyXCursor tmpcursor = cursor;
2926 while (tmpcursor.pos < tmpcursor.par->Last()
2927 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2930 if (tmpcursor.pos == tmpcursor.par->Last()){
2931 if (tmpcursor.par->Next()) {
2932 tmpcursor.par = tmpcursor.par->Next();
2938 SetCursor(tmpcursor.par, tmpcursor.pos);
2939 if (cursor.par->table) {
2940 int cell = NumberOfCell(cursor.par, cursor.pos);
2941 while (cursor.par->table->IsContRow(cell) &&
2942 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2944 while (tmpcursor.pos < tmpcursor.par->Last()
2945 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2948 if (tmpcursor.pos == tmpcursor.par->Last()){
2949 if (tmpcursor.par->Next()) {
2950 tmpcursor.par = tmpcursor.par->Next();
2956 SetCursor(tmpcursor.par, tmpcursor.pos);
2957 cell = NumberOfCell(cursor.par, cursor.pos);
2963 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2964 of prior word, not to end of next prior word. */
2966 void LyXText::CursorLeftOneWord() const
2968 // treat HFills, floats and Insets as words
2969 LyXCursor tmpcursor = cursor;
2970 while (tmpcursor.pos
2971 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2972 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2973 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2974 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2975 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2979 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2980 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2981 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2983 } else if (!tmpcursor.pos) {
2984 if (tmpcursor.par->Previous()){
2985 tmpcursor.par = tmpcursor.par->Previous();
2986 tmpcursor.pos = tmpcursor.par->Last();
2988 } else { // Here, tmpcursor != 0
2989 while (tmpcursor.pos > 0 &&
2990 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2993 SetCursor(tmpcursor.par, tmpcursor.pos);
2996 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2999 void LyXText::SelectWord()
3001 /* Move cursor to the beginning, when not already there. */
3003 && !cursor.par->IsSeparator(cursor.pos-1)
3004 && !cursor.par->IsKomma(cursor.pos-1) )
3005 CursorLeftOneWord();
3007 /* set the sel cursor */
3008 sel_cursor = cursor;
3010 while ( cursor.pos < cursor.par->Last()
3011 && !cursor.par->IsSeparator(cursor.pos)
3012 && !cursor.par->IsKomma(cursor.pos) )
3014 SetCursor( cursor.par, cursor.pos );
3016 /* finally set the selection */
3021 /* -------> Select the word currently under the cursor when:
3022 1: no selection is currently set,
3023 2: the cursor is not at the borders of the word. */
3025 int LyXText::SelectWordWhenUnderCursor()
3027 if ( selection ) return 0;
3028 if ( cursor.pos < cursor.par->Last()
3029 && !cursor.par->IsSeparator(cursor.pos)
3030 && !cursor.par->IsKomma(cursor.pos)
3032 && !cursor.par->IsSeparator(cursor.pos -1)
3033 && !cursor.par->IsKomma(cursor.pos -1) ) {
3041 // This function is only used by the spellchecker for NextWord().
3042 // It doesn't handle LYX_ACCENTs and probably never will.
3043 char * LyXText::SelectNextWord(float & value)
3045 LyXParagraph * tmppar = cursor.par;
3047 // If this is not the very first word, skip rest of
3048 // current word because we are probably in the middle
3049 // of a word if there is text here.
3050 if (cursor.pos || cursor.par->previous) {
3051 while (cursor.pos < cursor.par->Last()
3052 && cursor.par->IsLetter(cursor.pos))
3055 // Now, skip until we have real text (will jump paragraphs)
3056 while ((cursor.par->Last() > cursor.pos
3057 && (!cursor.par->IsLetter(cursor.pos)
3058 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
3059 || (cursor.par->Last() == cursor.pos
3060 && cursor.par->Next())){
3061 if (cursor.pos == cursor.par->Last()) {
3062 cursor.par = cursor.par->Next();
3069 // Update the value if we changed paragraphs
3070 if (cursor.par != tmppar){
3071 SetCursor(cursor.par, cursor.pos);
3072 value = float(cursor.y)/float(height);
3075 /* Start the selection from here */
3076 sel_cursor = cursor;
3079 ostringstream latex;
3083 /* and find the end of the word
3084 (optional hyphens are part of a word) */
3085 while (cursor.pos < cursor.par->Last()
3086 && (cursor.par->IsLetter(cursor.pos))
3087 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3088 && cursor.par->GetInset(cursor.pos) != 0
3089 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
3091 && latex.str() == "\\-"
3093 && string(latex.str(), 3) == "\\-" // this is not nice at all
3098 #ifndef HAVE_SSTREAM
3099 delete [] latex.str();
3101 // Finally, we copy the word to a string and return it
3104 if (sel_cursor.pos < cursor.pos) {
3105 str = new char [cursor.pos - sel_cursor.pos + 2];
3106 LyXParagraph::size_type i, j;
3107 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3108 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3109 str[j++] = cursor.par->GetChar(i);
3117 // This one is also only for the spellchecker
3118 void LyXText::SelectSelectedWord()
3120 /* move cursor to the beginning */
3121 SetCursor(sel_cursor.par, sel_cursor.pos);
3123 /* set the sel cursor */
3124 sel_cursor = cursor;
3127 ostringstream latex;
3132 /* now find the end of the word */
3133 while (cursor.pos < cursor.par->Last()
3134 && (cursor.par->IsLetter(cursor.pos)
3135 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3136 && cursor.par->GetInset(cursor.pos) != 0
3137 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0, false) == 0
3139 && latex.str() == "\\-"
3141 && string(latex.str(), 3) == "\\-"
3146 #ifndef HAVE_SSTREAM
3147 delete [] latex.str();
3149 SetCursor(cursor.par, cursor.pos);
3151 /* finally set the selection */
3156 /* -------> Delete from cursor up to the end of the current or next word. */
3157 void LyXText::DeleteWordForward()
3159 LyXCursor tmpcursor = cursor;
3161 if (!cursor.par->Last())
3163 #warning See comment on top of text.C
3165 /* -------> Skip initial non-word stuff. */
3166 while ( cursor.pos < cursor.par->Last()
3167 && (cursor.par->IsSeparator(cursor.pos)
3168 || cursor.par->IsKomma(cursor.pos)) )
3171 SetCursorIntern(cursor.par, cursor.pos);
3172 selection = True; // to avoid deletion
3173 CursorRightOneWord();
3174 sel_cursor = cursor;
3178 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3184 /* -------> Delete from cursor to start of current or prior word. */
3185 void LyXText::DeleteWordBackward()
3187 LyXCursor tmpcursor = cursor;
3188 if (!cursor.par->Last())
3190 #warning See comment on top of text.C
3192 selection = true; // to avoid deletion
3193 CursorLeftOneWord();
3194 sel_cursor = cursor;
3202 /* -------> Kill to end of line. */
3203 void LyXText::DeleteLineForward()
3205 LyXCursor tmpcursor = cursor;
3206 if (!cursor.par->Last())
3208 #warning See comment on top of text.C
3211 sel_cursor = cursor;
3214 if (selection == false) {
3215 DeleteWordForward();
3223 // Change the case of a word at cursor position. The meaning of action
3225 // 0 change to lowercase
3226 // 1 capitalize word
3227 // 2 change to uppercase
3228 // This function directly manipulates LyXParagraph::text because there
3229 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3230 // that it is correct. I guess part of it should be moved to
3231 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3232 // it does not access outside of the allocated array as the older
3233 // version did. (JMarc)
3234 void LyXText::ChangeWordCase(LyXText::TextCase action)
3236 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3238 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3240 LyXParagraph::size_type tmppos =
3241 cursor.par->PositionInParFromPos(cursor.pos);
3242 while (tmppos < tmppar->size()) {
3243 //unsigned char c = tmppar->text[tmppos];
3244 unsigned char c = tmppar->GetChar(tmppos);
3245 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3247 if (c != LyXParagraph::META_INSET) {
3249 case text_lowercase:
3252 case text_capitalization:
3254 action = text_lowercase;
3256 case text_uppercase:
3262 //tmppar->text[tmppos] = c;
3263 tmppar->SetChar(tmppos, c);
3266 CheckParagraph(tmppar, tmppos);
3267 CursorRightOneWord();
3271 void LyXText::Delete()
3273 // this is a very easy implementation
3275 LyXCursor old_cursor = cursor;
3276 int old_cur_par_id = old_cursor.par->id();
3277 int old_cur_par_prev_id = old_cursor.par->previous ?
3278 old_cursor.par->previous->id() : 0;
3280 // just move to the right
3281 CursorRightIntern();
3283 #warning Look at the comment here.
3284 // This check is not very good...
3285 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3286 // and that can very well delete the par or par->previous in
3287 // old_cursor. Will a solution where we compare paragraph id's
3290 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3291 == old_cur_par_prev_id
3292 && cursor.par->id() != old_cur_par_id)
3293 return; // delete-empty-paragraph-mechanism has done it
3295 if (cursor.par->previous == old_cursor.par->previous
3296 && cursor.par != old_cursor.par)
3297 return; // delete-empty-paragraph-mechanism has done it
3299 // if you had success make a backspace
3300 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3301 LyXCursor tmpcursor = cursor;
3302 cursor = old_cursor; // to make sure undo gets the right cursor position
3303 SetUndo(Undo::DELETE,
3304 cursor.par->ParFromPos(cursor.pos)->previous,
3305 cursor.par->ParFromPos(cursor.pos)->next);
3312 void LyXText::Backspace()
3314 DebugTracer trc1("LyXText::Backspace");
3316 /* table stuff -- begin */
3317 if (cursor.par->table) {
3321 /* table stuff -- end */
3323 LyXFont rawtmpfont = current_font;
3324 LyXFont realtmpfont = real_current_font;
3326 // Get the font that is used to calculate the baselineskip
3327 int const lastpos = cursor.par->Last();
3328 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3330 if (cursor.pos == 0) {
3331 DebugTracer trc("LyXText::Backspace cursor.pos == 0");
3333 // The cursor is at the beginning of a paragraph, so the the backspace
3334 // will collapse two paragraphs into one.
3336 // we may paste some paragraphs
3338 // is it an empty paragraph?
3341 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3342 && !(cursor.par->Next()
3343 && cursor.par->footnoteflag == LyXParagraph::NO_FOOTNOTE
3344 && cursor.par->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
3345 // This is an empty paragraph and we delete it just by moving the curosr one step
3346 // left and let the DeleteEmptyParagraphMechanism handle the actual deleteion
3347 // of the paragraph.
3349 if (cursor.par->previous) {
3350 LyXParagraph * tmppar = cursor.par->previous->FirstPhysicalPar();
3351 if (cursor.par->GetLayout() == tmppar->GetLayout()
3352 && cursor.par->footnoteflag == tmppar->footnoteflag
3353 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3354 // Inherit botom DTD from the paragraph below.
3355 // (the one we are deleting)
3356 tmppar->line_bottom = cursor.par->line_bottom;
3357 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3358 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3363 // the layout things can change the height of a row !
3364 int tmpheight = cursor.row->height;
3365 SetHeightOfRow(cursor.row);
3366 if (cursor.row->height != tmpheight) {
3367 refresh_y = cursor.y - cursor.row->baseline;
3368 refresh_row = cursor.row;
3369 status = LyXText::NEED_MORE_REFRESH;
3375 if (cursor.par->ParFromPos(cursor.pos)->previous){
3376 SetUndo(Undo::DELETE,
3377 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3378 cursor.par->ParFromPos(cursor.pos)->next);
3381 LyXParagraph * tmppar = cursor.par;
3382 Row * tmprow = cursor.row;
3384 // We used to do CursorLeftIntern() here, but it is
3385 // not a good idea since it triggers the auto-delete
3386 // mechanism. So we do a CursorLeftIntern()-lite,
3387 // without the dreaded mechanism. (JMarc)
3388 if (cursor.pos > 0) {
3389 SetCursorIntern(cursor.par, cursor.pos - 1);
3391 else if (cursor.par->Previous()) {
3392 // steps into the above paragraph.
3393 SetCursorIntern(cursor.par->Previous(),
3394 cursor.par->Previous()->Last());
3398 #warning See comment on top of text.C
3399 /* Pasting is not allowed, if the paragraphs have different
3400 layout. I think it is a real bug of all other
3401 word processors to allow it. It confuses the user.
3402 Even so with a footnote paragraph and a non-footnote
3403 paragraph. I will not allow pasting in this case,
3404 because the user would be confused if the footnote behaves
3405 different wether it is open or closed.
3407 Correction: Pasting is always allowed with standard-layout
3409 if (cursor.par != tmppar
3410 && (cursor.par->GetLayout() == tmppar->GetLayout()
3411 || tmppar->GetLayout() == 0 /*standard*/)
3412 && cursor.par->footnoteflag == tmppar->footnoteflag
3413 /* table stuff -- begin*/
3414 && !cursor.par->table /* no pasting of tables */
3415 /* table stuff -- end*/
3416 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3418 RemoveParagraph(tmprow);
3420 cursor.par->PasteParagraph();
3422 if (!cursor.pos || !cursor.par->IsSeparator(cursor.pos - 1))
3423 ; //cursor.par->InsertChar(cursor.pos, ' ');
3424 // strangely enough it seems that commenting out the line above removes
3425 // most or all of the segfaults. I will however also try to move the
3426 // two Remove... lines in front of the PasteParagraph too.
3431 status = LyXText::NEED_MORE_REFRESH;
3432 refresh_row = cursor.row;
3433 refresh_y = cursor.y - cursor.row->baseline;
3435 // remove the lost paragraph
3436 // This one is not safe, since the paragraph that the tmprow and the
3437 // following rows belong to has been deleted by the PasteParagraph
3438 // above. The question is... could this be moved in front of the
3440 //RemoveParagraph(tmprow);
3441 //RemoveRow(tmprow);
3443 AppendParagraph(cursor.row); // This rebuilds the rows.
3444 UpdateCounters(cursor.row);
3446 // the row may have changed, block, hfills etc.
3447 SetCursor(cursor.par, cursor.pos);
3450 DebugTracer trc("LyXText::Backspace normal backspace");
3452 /* this is the code for a normal backspace, not pasting
3454 SetUndo(Undo::DELETE,
3455 cursor.par->ParFromPos(cursor.pos)->previous,
3456 cursor.par->ParFromPos(cursor.pos)->next);
3459 // some insets are undeletable here
3460 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3461 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3463 // force complete redo when erasing display insets
3464 // this is a cruel mathod but save..... Matthias
3465 if (cursor.par->GetInset(cursor.pos)->display()){
3466 cursor.par->Erase(cursor.pos);
3472 Row * row = cursor.row;
3473 long y = cursor.y - row->baseline;
3474 LyXParagraph::size_type z;
3475 /* remember that a space at the end of a row doesnt count
3476 * when calculating the fill */
3477 if (cursor.pos < RowLast(row) ||
3478 !cursor.par->IsLineSeparator(cursor.pos)) {
3479 row->fill += SingleWidth(cursor.par, cursor.pos);
3482 /* some special code when deleting a newline. This is similar
3483 * to the behavior when pasting paragraphs */
3484 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3485 cursor.par->Erase(cursor.pos);
3486 // refresh the positions
3488 while (tmprow->next && tmprow->next->par == row->par) {
3489 tmprow = tmprow->next;
3492 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3495 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3496 cursor.par->InsertChar(cursor.pos, ' ');
3497 // refresh the positions
3499 while (tmprow->next && tmprow->next->par == row->par) {
3500 tmprow = tmprow->next;
3505 cursor.par->Erase(cursor.pos);
3507 // refresh the positions
3509 while (tmprow->next && tmprow->next->par == row->par) {
3510 tmprow = tmprow->next;
3514 #ifndef FIX_DOUBLE_SPACE
3515 // delete superfluous blanks
3516 if (cursor.pos < cursor.par->Last() - 1 &&
3517 (cursor.par->IsLineSeparator(cursor.pos))) {
3519 if (cursor.pos == BeginningOfMainBody(cursor.par)
3521 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3522 cursor.par->Erase(cursor.pos);
3523 // refresh the positions
3525 while (tmprow->next &&
3526 tmprow->next->par == row->par) {
3527 tmprow = tmprow->next;
3530 if (cursor.pos) // move one character left
3536 // delete newlines at the beginning of paragraphs
3537 while (cursor.par->Last() &&
3538 cursor.par->IsNewline(cursor.pos) &&
3539 cursor.pos == BeginningOfMainBody(cursor.par)) {
3540 cursor.par->Erase(cursor.pos);
3541 // refresh the positions
3543 while (tmprow->next &&
3544 tmprow->next->par == row->par) {
3545 tmprow = tmprow->next;
3551 // is there a break one row above
3552 if (row->previous && row->previous->par == row->par) {
3553 z = NextBreakPoint(row->previous, paperwidth);
3554 if ( z >= row->pos) {
3557 Row * tmprow = row->previous;
3559 // maybe the current row is now empty
3560 if (row->pos >= row->par->Last()) {
3565 BreakAgainOneRow(row);
3566 if (row->next && row->next->par == row->par)
3567 need_break_row = row->next;
3572 // set the dimensions of the row above
3573 y -= tmprow->height;
3574 tmprow->fill = Fill(tmprow, paperwidth);
3575 SetHeightOfRow(tmprow);
3578 refresh_row = tmprow;
3579 status = LyXText::NEED_MORE_REFRESH;
3580 current_font = rawtmpfont;
3581 real_current_font = realtmpfont;
3582 SetCursor(cursor.par, cursor.pos, false);
3583 // check, whether the last character's font has changed.
3584 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3585 if (rawparfont != rawtmpfont)
3586 RedoHeightOfParagraph(cursor);
3591 // break the cursor row again
3592 z = NextBreakPoint(row, paperwidth);
3594 if (z != RowLast(row) ||
3595 (row->next && row->next->par == row->par &&
3596 RowLast(row) == row->par->Last() - 1)){
3598 /* it can happen that a paragraph loses one row
3599 * without a real breakup. This is when a word
3600 * is to long to be broken. Well, I don t care this
3602 if (row->next && row->next->par == row->par &&
3603 RowLast(row) == row->par->Last() - 1)
3604 RemoveRow(row->next);
3608 status = LyXText::NEED_MORE_REFRESH;
3610 BreakAgainOneRow(row);
3611 current_font = rawtmpfont;
3612 real_current_font = realtmpfont;
3613 SetCursor(cursor.par, cursor.pos, false);
3614 // cursor MUST be in row now
3616 if (row->next && row->next->par == row->par)
3617 need_break_row = row->next;
3621 // set the dimensions of the row
3622 row->fill = Fill(row, paperwidth);
3623 int tmpheight = row->height;
3624 SetHeightOfRow(row);
3625 if (tmpheight == row->height)
3626 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3628 status = LyXText::NEED_MORE_REFRESH;
3631 current_font = rawtmpfont;
3632 real_current_font = realtmpfont;
3633 SetCursor(cursor.par, cursor.pos, false);
3636 DebugTracer trc2("LyXText::Backspace wrap up");
3638 // restore the current font
3639 // That is what a user expects!
3640 current_font = rawtmpfont;
3641 real_current_font = realtmpfont;
3643 // check, wether the last characters font has changed.
3644 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3645 if (rawparfont != rawtmpfont) {
3646 RedoHeightOfParagraph(cursor);
3648 // now the special right address boxes
3649 if (textclasslist.Style(parameters->textclass,
3650 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3651 RedoDrawingOfParagraph(cursor);
3657 void LyXText::GetVisibleRow(int offset,
3658 Row * row_ptr, long y)
3660 /* returns a printed row */
3661 Painter & pain = owner_->painter();
3663 LyXDirection direction = row_ptr->par->getParDirection();
3664 LyXParagraph::size_type vpos, pos, pos_end;
3666 int y_top, y_bottom;
3667 float fill_separator, fill_hfill, fill_label_hfill;
3668 LyXParagraph * par, * firstpar;
3671 if (row_ptr->height <= 0) {
3672 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3675 PrepareToPrint(row_ptr, x, fill_separator,
3676 fill_hfill, fill_label_hfill);
3678 /* initialize the pixmap */
3680 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3683 /* selection code */
3684 if (sel_start_cursor.row == row_ptr &&
3685 sel_end_cursor.row == row_ptr) {
3686 if (sel_start_cursor.x < sel_end_cursor.x)
3687 pain.fillRectangle(sel_start_cursor.x, offset,
3688 sel_end_cursor.x - sel_start_cursor.x,
3692 pain.fillRectangle(sel_end_cursor.x, offset,
3693 sel_start_cursor.x - sel_end_cursor.x,
3696 } else if (sel_start_cursor.row == row_ptr) {
3697 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3698 pain.fillRectangle(sel_start_cursor.x, offset,
3699 paperwidth - sel_start_cursor.x,
3703 pain.fillRectangle(0, offset,
3707 } else if (sel_end_cursor.row == row_ptr) {
3708 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3709 pain.fillRectangle(0, offset,
3714 pain.fillRectangle(sel_end_cursor.x, offset,
3715 paperwidth - sel_end_cursor.x,
3719 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3720 pain.fillRectangle(0, offset,
3721 paperwidth, row_ptr->height,
3726 if (row_ptr->par->appendix){
3727 pain.line(1, offset,
3728 1, offset + row_ptr->height,
3729 LColor::appendixline);
3730 pain.line(paperwidth - 2, offset,
3731 paperwidth - 2, offset + row_ptr->height,
3732 LColor::appendixline);
3735 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3736 /* draw a marker at the left margin! */
3737 LyXFont font = GetFont(row_ptr->par, 0);
3738 int asc = font.maxAscent();
3739 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3740 int y1 = (offset + row_ptr->baseline);
3741 int y2 = (offset + row_ptr->baseline) - asc;
3742 pain.line(x, y1, x, y2, LColor::minipageline);
3744 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3745 LyXFont font(LyXFont::ALL_SANE);
3746 font.setSize(LyXFont::SIZE_FOOTNOTE);
3747 font.setColor(LColor::footnote);
3749 int box_x = LYX_PAPER_MARGIN;
3750 box_x += font.textWidth(" wide-tab ", 10);
3751 if (row_ptr->previous &&
3752 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3754 switch (row_ptr->par->footnotekind) {
3755 case LyXParagraph::MARGIN:
3758 case LyXParagraph::FIG:
3761 case LyXParagraph::TAB:
3764 case LyXParagraph::WIDE_FIG:
3767 case LyXParagraph::WIDE_TAB:
3770 case LyXParagraph::ALGORITHM:
3773 case LyXParagraph::FOOTNOTE:
3778 pain.fillRectangle(LYX_PAPER_MARGIN,
3780 box_x - LYX_PAPER_MARGIN,
3781 int(font.maxAscent()
3782 + font.maxDescent()),
3783 LColor::footnotebg);
3785 pain.line(LYX_PAPER_MARGIN, offset,
3786 paperwidth - LYX_PAPER_MARGIN, offset,
3787 LColor::footnoteframe);
3789 pain.text(LYX_PAPER_MARGIN,
3790 offset + int(font.maxAscent()) + 1,
3793 pain.line(LYX_PAPER_MARGIN, offset,
3795 offset + int(font.maxAscent()
3796 + font.maxDescent()),
3797 LColor::footnoteframe);
3799 pain.line(LYX_PAPER_MARGIN,
3800 offset + int(font.maxAscent()
3801 + font.maxDescent()) + 1,
3803 offset + int(font.maxAscent()
3804 + font.maxDescent()) + 1,
3805 LColor::footnoteframe);
3809 /* draw the open floats in a red box */
3810 pain.line(box_x, offset,
3811 box_x, offset + row_ptr->height,
3812 LColor::footnoteframe);
3814 pain.line(paperwidth - LYX_PAPER_MARGIN,
3816 paperwidth - LYX_PAPER_MARGIN,
3817 offset + row_ptr->height,
3818 LColor::footnoteframe);
3819 } else if (row_ptr->previous &&
3820 row_ptr->previous->par->footnoteflag
3821 == LyXParagraph::OPEN_FOOTNOTE) {
3822 LyXFont font(LyXFont::ALL_SANE);
3823 font.setSize(LyXFont::SIZE_FOOTNOTE);
3825 int box_x = LYX_PAPER_MARGIN;
3826 box_x += font.textWidth(" wide-tab ", 10);
3828 pain.line(box_x, offset,
3829 paperwidth - LYX_PAPER_MARGIN,
3830 offset, LColor::footnote);
3833 LyXLayout const & layout =
3834 textclasslist.Style(parameters->textclass,
3835 row_ptr->par->GetLayout());
3836 firstpar = row_ptr->par->FirstPhysicalPar();
3839 y_bottom = row_ptr->height;
3841 /* is it a first row? */
3842 if (row_ptr->pos == 0
3843 && row_ptr->par == firstpar) {
3845 /* start of appendix? */
3846 if (row_ptr->par->start_of_appendix){
3847 pain.line(1, offset,
3848 paperwidth - 2, offset,
3849 LColor::appendixline);
3852 /* think about the margins */
3853 if (!row_ptr->previous)
3854 y_top += LYX_PAPER_MARGIN;
3856 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3858 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3860 offset + y_top + 2 * DefaultHeight(),
3861 LColor::pagebreak, Painter::line_onoffdash);
3864 pb_font.setColor(LColor::pagebreak).decSize();
3865 int w = 0, a = 0, d = 0;
3866 pain.line(0, offset + y_top + 2*DefaultHeight(),
3868 offset + y_top + 2*DefaultHeight(),
3870 Painter::line_onoffdash)
3873 _("Page Break (top)"),
3876 LColor::background, false, w, a, d);
3877 pain.rectText((paperwidth - w)/2,
3878 offset +y_top + 2*DefaultHeight() +d,
3879 _("Page Break (top)"),
3882 LColor::background);
3884 y_top += 3 * DefaultHeight();
3887 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3888 /* draw a vfill top */
3889 pain.line(0, offset + 2 + y_top,
3890 LYX_PAPER_MARGIN, offset + 2 + y_top,
3893 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3895 offset + y_top + 3 * DefaultHeight(),
3898 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3899 LYX_PAPER_MARGIN / 2,
3900 offset + y_top + 3 * DefaultHeight(),
3903 y_top += 3 * DefaultHeight();
3906 /* think about user added space */
3907 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3909 /* think about the parskip */
3910 /* some parskips VERY EASY IMPLEMENTATION */
3911 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3912 if (layout.latextype == LATEX_PARAGRAPH
3913 && firstpar->GetDepth() == 0
3914 && firstpar->Previous())
3915 y_top += parameters->getDefSkip().inPixels(owner_);
3916 else if (firstpar->Previous()
3917 && textclasslist.Style(parameters->textclass,
3918 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3919 && firstpar->Previous()->GetDepth() == 0)
3920 // is it right to use defskip here, too? (AS)
3921 y_top += parameters->getDefSkip().inPixels(owner_);
3924 if (row_ptr->par->line_top) { /* draw a top line */
3925 y_top += GetFont(row_ptr->par, 0).ascent('x');
3927 pain.line(0, offset + y_top,
3928 paperwidth, offset + y_top,
3930 Painter::line_solid,
3931 Painter::line_thick);
3933 y_top += GetFont(row_ptr->par, 0).ascent('x');
3936 /* should we print a label? */
3937 if (layout.labeltype >= LABEL_STATIC
3938 && (layout.labeltype != LABEL_STATIC
3939 || layout.latextype != LATEX_ENVIRONMENT
3940 || row_ptr->par->IsFirstInSequence())) {
3941 font = GetFont(row_ptr->par, -2);
3942 if (!row_ptr->par->GetLabestring().empty()) {
3944 string tmpstring = row_ptr->par->GetLabestring();
3946 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3947 if (parameters->secnumdepth >= 0){
3948 /* this is special code for the chapter layout. This is printed in
3949 * an extra row and has a pagebreak at the top. */
3950 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3951 + int(layout.parsep) * DefaultHeight();
3952 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3953 tmpx = paperwidth - LeftMargin(row_ptr) -
3954 font.stringWidth(tmpstring);
3955 pain.text(int(tmpx),
3956 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3960 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3961 tmpx = x - font.stringWidth(layout.labelsep)
3962 - font.stringWidth(tmpstring);
3964 tmpx = paperwidth - LeftMargin(row_ptr)
3965 + font.stringWidth(layout.labelsep);
3966 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3967 LyXFont font(LyXFont::ALL_SANE);
3968 font.setSize(LyXFont::SIZE_SMALL);
3969 tmpx += font.textWidth("Mwide-figM", 10);
3973 pain.text(int(tmpx),
3974 offset + row_ptr->baseline,
3978 /* the labels at the top of an environment. More or less for bibliography */
3979 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3980 layout.labeltype == LABEL_BIBLIO ||
3981 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3982 if (row_ptr->par->IsFirstInSequence()) {
3983 font = GetFont(row_ptr->par, -2);
3984 if (!row_ptr->par->GetLabestring().empty()) {
3985 string tmpstring = row_ptr->par->GetLabestring();
3987 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3988 + (layout.labelbottomsep * DefaultHeight()));
3991 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3992 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3993 ? x : LeftMargin(row_ptr) )
3994 + paperwidth - RightMargin(row_ptr) ) / 2;
3995 tmpx -= (font.stringWidth(tmpstring)/2);
3996 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3997 tmpx = paperwidth - LeftMargin(row_ptr) -
3998 font.stringWidth(tmpstring);
3999 pain.text(int(tmpx),
4000 offset + row_ptr->baseline
4001 - row_ptr->ascent_of_text
4007 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
4008 font = GetFont(row_ptr->par, -1);
4009 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4010 tmpx = x - font.stringWidth(layout.labelsep)
4011 - row_ptr->par->bibkey->width(owner_->painter(), font);
4013 tmpx = paperwidth - LeftMargin(row_ptr)
4014 + font.stringWidth(layout.labelsep);
4015 row_ptr->par->bibkey->draw(owner_->painter(),
4017 offset + row_ptr->baseline,
4022 /* is it a last row? */
4023 par = row_ptr->par->LastPhysicalPar();
4024 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
4025 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
4027 /* think about the margins */
4029 y_bottom -= LYX_PAPER_MARGIN;
4031 /* draw a bottom pagebreak */
4032 if (firstpar->pagebreak_bottom) {
4034 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
4036 offset + y_bottom - 2 * DefaultHeight(),
4037 LColor::pagebreak, Painter::line_onoffdash);
4040 pb_font.setColor(LColor::pagebreak).decSize();
4041 int w = 0, a = 0, d = 0;
4043 offset + y_bottom - 2 * DefaultHeight(),
4045 offset + y_bottom - 2 * DefaultHeight(),
4047 Painter::line_onoffdash)
4050 _("Page Break (bottom)"),
4053 LColor::background, false, w, a, d);
4054 pain.rectText((paperwidth - w)/2,
4055 offset +y_top + 2*DefaultHeight() +d,
4056 _("Page Break (bottom)"),
4059 LColor::background);
4061 y_bottom -= 3 * DefaultHeight();
4064 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4065 /* draw a vfill bottom */
4066 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
4068 offset + y_bottom - 3 * DefaultHeight(),
4070 pain.line(0, offset + y_bottom - 2,
4072 offset + y_bottom - 2,
4074 pain.line(LYX_PAPER_MARGIN / 2,
4075 offset + y_bottom - 3 * DefaultHeight(),
4076 LYX_PAPER_MARGIN / 2,
4077 offset + y_bottom - 2,
4079 y_bottom -= 3* DefaultHeight();
4082 /* think about user added space */
4083 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
4085 if (firstpar->line_bottom) {
4086 /* draw a bottom line */
4087 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4088 pain.line(0, offset + y_bottom,
4089 paperwidth, offset + y_bottom,
4090 LColor::topline, Painter::line_solid,
4091 Painter::line_thick);
4092 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4096 int endlabel = row_ptr->par->GetEndLabel();
4097 if (endlabel == END_LABEL_BOX ||
4098 endlabel == END_LABEL_FILLED_BOX) {
4099 LyXFont font = GetFont(row_ptr->par, RowLast(row_ptr));
4100 int size = int(0.75*font.maxAscent());
4101 int y = (offset + row_ptr->baseline) - size;
4102 int x = (direction == LYX_DIR_LEFT_TO_RIGHT)
4103 ? paperwidth - LYX_PAPER_MARGIN - size
4105 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
4106 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4107 x -= LYX_PAPER_MARGIN/2;
4109 LyXFont font(LyXFont::ALL_SANE);
4110 font.setSize(LyXFont::SIZE_SMALL);
4111 x += font.textWidth("Mwide-figM", 10);
4113 if (row_ptr->fill <= size)
4114 x += (size - row_ptr->fill + 1) * direction;
4115 if (endlabel == END_LABEL_BOX) {
4116 pain.line(x, y, x, y + size,
4118 pain.line(x + size, y, x + size , y + size,
4120 pain.line(x, y, x + size, y,
4122 pain.line(x, y + size, x + size, y + size,
4125 pain.fillRectangle(x, y, size, size,
4130 /* draw the text in the pixmap */
4131 pos_end = RowLast(row_ptr);
4133 vpos = row_ptr->pos;
4134 /* table stuff -- begin*/
4135 if (row_ptr->par->table) {
4137 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
4139 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4141 while (vpos <= pos_end) {
4142 pos = vis2log(vpos);
4143 if (row_ptr->par->IsNewline(pos)) {
4145 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4146 /* draw the table lines, still very simple */
4147 on_off = !row_ptr->par->table->TopLine(cell);
4149 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4150 !row_ptr->par->table->IsContRow(cell))
4151 pain.line(int(x_old),
4152 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4154 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4156 on_off ? Painter::line_onoffdash : Painter::line_solid);
4158 on_off = !row_ptr->par->table->BottomLine(cell);
4159 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4160 row_ptr->par->table->VeryLastRow(cell))
4162 pain.line(int(x_old),
4163 offset + y_bottom - 1,
4165 offset + y_bottom - 1,
4167 on_off ? Painter::line_onoffdash : Painter::line_solid);
4169 on_off = !row_ptr->par->table->LeftLine(cell);
4171 pain.line(int(x_old),
4172 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4174 offset + y_bottom - 1,
4176 on_off ? Painter::line_onoffdash : Painter::line_solid);
4178 on_off = !row_ptr->par->table->RightLine(cell);
4180 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4181 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4182 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4183 offset + y_bottom - 1,
4185 on_off ? Painter::line_onoffdash : Painter::line_solid);
4188 /* take care about the alignment and other spaces */
4190 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4191 if (row_ptr->par->table->IsFirstCell(cell))
4192 --cell; // little hack, sorry
4194 } else if (row_ptr->par->IsHfill(pos)) {
4198 offset + row_ptr->baseline - DefaultHeight() / 2,
4200 offset + row_ptr->baseline,
4205 } else if (row_ptr->par->IsSeparator(pos)) {
4207 x+= SingleWidth(row_ptr->par, pos);
4208 #warning Think about this.
4210 /* -------> Only draw protected spaces when
4211 * not in free-spacing mode. */
4212 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4213 pain.line(int(tmpx),
4214 offset + row_ptr->baseline - 3,
4216 offset + row_ptr->baseline - 1,
4219 pain.line(int(tmpx),
4220 offset + row_ptr->baseline - 1,
4222 offset + row_ptr->baseline - 1,
4225 pain.line(int(x - 2),
4226 offset + row_ptr->baseline - 3,
4228 offset + row_ptr->baseline - 1,
4231 /* what about underbars? */
4232 font = GetFont(row_ptr->par, pos);
4233 if (font.underbar() == LyXFont::ON
4234 && font.latex() != LyXFont::ON) {
4235 pain.line(int(tmpx),
4236 offset + row_ptr->baseline + 2,
4238 offset + row_ptr->baseline + 2);
4244 draw(row_ptr, vpos, offset, x);
4247 /* do not forget the very last cell. This has no NEWLINE so
4248 * ignored by the code above*/
4249 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4250 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4251 on_off = !row_ptr->par->table->TopLine(cell);
4253 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4254 !row_ptr->par->table->IsContRow(cell))
4256 pain.line(int(x_old),
4257 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4259 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4261 on_off ? Painter::line_onoffdash : Painter::line_solid);
4262 on_off = !row_ptr->par->table->BottomLine(cell);
4263 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4264 row_ptr->par->table->VeryLastRow(cell))
4266 pain.line(int(x_old),
4267 offset + y_bottom - 1,
4269 offset + y_bottom - 1,
4271 on_off ? Painter::line_onoffdash : Painter::line_solid);
4273 on_off = !row_ptr->par->table->LeftLine(cell);
4275 pain.line(int(x_old),
4276 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4278 offset + y_bottom - 1,
4280 on_off ? Painter::line_onoffdash : Painter::line_solid);
4282 on_off = !row_ptr->par->table->RightLine(cell);
4284 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4285 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4286 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4287 offset + y_bottom - 1,
4289 on_off ? Painter::line_onoffdash : Painter::line_solid);
4292 /* table stuff -- end*/
4293 LyXParagraph::size_type main_body =
4294 BeginningOfMainBody(row_ptr->par);
4295 if (main_body > 0 &&
4296 (main_body-1 > pos_end ||
4297 !row_ptr->par->IsLineSeparator(main_body-1)))
4300 while (vpos <= pos_end) {
4301 pos = vis2log(vpos);
4302 if (main_body > 0 && pos == main_body-1) {
4303 x += fill_label_hfill
4304 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4305 - SingleWidth(row_ptr->par, main_body-1);
4308 if (row_ptr->par->IsHfill(pos)) {
4311 offset + row_ptr->baseline - DefaultHeight() / 2,
4313 offset + row_ptr->baseline,
4316 if (HfillExpansion(row_ptr, pos)) {
4317 if (pos >= main_body) {
4319 offset + row_ptr->baseline - DefaultHeight() / 4,
4320 int(x + fill_hfill),
4321 offset + row_ptr->baseline - DefaultHeight() / 4,
4323 Painter::line_onoffdash);
4327 offset + row_ptr->baseline - DefaultHeight() / 4,
4328 int(x + fill_label_hfill),
4329 offset + row_ptr->baseline - DefaultHeight() / 4,
4331 Painter::line_onoffdash);
4333 x += fill_label_hfill;
4336 offset + row_ptr->baseline - DefaultHeight() / 2,
4338 offset + row_ptr->baseline,
4343 } else if (row_ptr->par->IsSeparator(pos)) {
4345 x+= SingleWidth(row_ptr->par, pos);
4346 if (pos >= main_body)
4348 #warning Think about this
4350 /* -------> Only draw protected spaces when
4351 * not in free-spacing mode. */
4352 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4354 pain.line(int(tmpx),
4355 offset + row_ptr->baseline - 3,
4357 offset + row_ptr->baseline - 1,
4360 pain.line(int(tmpx),
4361 offset + row_ptr->baseline - 1,
4363 offset + row_ptr->baseline - 1,
4366 pain.line(int(x - 2),
4367 offset + row_ptr->baseline - 3,
4369 offset + row_ptr->baseline - 1,
4372 /* what about underbars? */
4373 font = GetFont(row_ptr->par, pos);
4374 if (font.underbar() == LyXFont::ON
4375 && font.latex() != LyXFont::ON) {
4376 pain.line(int(tmpx),
4377 offset + row_ptr->baseline + 2,
4379 offset + row_ptr->baseline + 2);
4385 draw(row_ptr, vpos, offset, x);
4391 int LyXText::DefaultHeight() const
4393 LyXFont font(LyXFont::ALL_SANE);
4394 return int(font.maxAscent() + font.maxDescent() * 1.5);
4398 /* returns the column near the specified x-coordinate of the row
4399 * x is set to the real beginning of this column */
4400 int LyXText::GetColumnNearX(Row * row, int & x) const
4403 float fill_separator, fill_hfill, fill_label_hfill;
4405 PrepareToPrint(row, tmpx, fill_separator,
4406 fill_hfill, fill_label_hfill);
4408 LyXDirection direction = row->par->getParDirection();
4409 LyXParagraph::size_type vc = row->pos;
4410 LyXParagraph::size_type last = RowLast(row);
4411 LyXParagraph::size_type c = 0;
4413 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4414 row->par->GetLayout());
4415 /* table stuff -- begin */
4416 if (row->par->table) {
4417 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4418 && row->par->IsNewline(last))
4420 int cell = NumberOfCell(row->par, row->pos);
4423 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4425 && (c = vis2log(vc)) >= 0
4426 && tmpx + (SingleWidth(row->par, c)/2) <= x
4428 if (row->par->IsNewline(c)) {
4429 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4430 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4433 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4438 tmpx += SingleWidth(row->par, c);
4443 /* table stuff -- end*/
4444 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4445 float last_tmpx = tmpx;
4447 if (main_body > 0 &&
4448 (main_body-1 > last ||
4449 !row->par->IsLineSeparator(main_body-1)))
4452 while (vc <= last && tmpx <= x) {
4455 if (main_body > 0 && c == main_body-1) {
4456 tmpx += fill_label_hfill +
4457 GetFont(row->par, -2).stringWidth(layout.labelsep);
4458 if (row->par->IsLineSeparator(main_body-1))
4459 tmpx -= SingleWidth(row->par, main_body-1);
4462 tmpx += SingleWidth(row->par, c);
4463 if (HfillExpansion(row, c)) {
4467 tmpx += fill_label_hfill;
4469 else if (c >= main_body
4470 && row->par->IsSeparator(c)) {
4471 tmpx+= fill_separator;
4476 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4481 /* make sure that a last space in a row doesnt count */
4482 if (row->pos <= last
4483 && !(!row->next || row->next->par != row->par))
4484 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4485 && row->par->IsLineSeparator(vis2log(last)) ) {
4487 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4488 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4490 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4492 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4494 if (row->pos > last) // Row is empty?
4496 else if (vc > last ||
4497 (row->par->table && vc > row->pos && row->par->IsNewline(vc)) ){
4498 int pos = (vc > last+1) ? last : vc - 1;
4500 if (row->par->getLetterDirection(c) == LYX_DIR_LEFT_TO_RIGHT)
4504 LyXDirection direction = row->par->getLetterDirection(c);
4505 if (vc > row->pos && row->par->IsLineSeparator(c)
4506 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4508 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4512 if (!row->par->table && row->pos <= last && c > last
4513 && row->par->IsNewline(last)) {
4514 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4515 tmpx -= SingleWidth(row->par, last);
4517 tmpx += SingleWidth(row->par, last);
4527 /* turn the selection into a new environment. If there is no selection,
4528 * create an empty environment */
4529 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4531 /* no footnoteenvironment in a footnoteenvironment */
4532 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4533 WriteAlert(_("Impossible operation"),
4534 _("You can't insert a float in a float!"),
4538 /* no marginpars in minipages */
4539 if (kind == LyXParagraph::MARGIN
4540 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4541 WriteAlert(_("Impossible operation"),
4542 _("You can't insert a marginpar in a minipage!"),
4547 /* this doesnt make sense, if there is no selection */
4548 bool dummy_selection = false;
4550 sel_start_cursor = cursor; /* dummy selection */
4551 sel_end_cursor = cursor;
4552 dummy_selection = true;
4555 LyXParagraph *tmppar;
4557 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4558 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4562 /* a test to make sure there is not already a footnote
4563 * in the selection. */
4565 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4567 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4568 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4569 tmppar = tmppar->next;
4571 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4572 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4573 WriteAlert(_("Impossible operation"),
4574 _("Float would include float!"),
4579 /* ok we have a selection. This is always between sel_start_cursor
4580 * and sel_end cursor */
4582 SetUndo(Undo::FINISH,
4583 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4584 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4586 if (sel_end_cursor.pos > 0
4587 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4588 sel_end_cursor.pos--; /* please break before a space at
4590 if (sel_start_cursor.par == sel_end_cursor.par
4591 && sel_start_cursor.pos > sel_end_cursor.pos)
4592 sel_start_cursor.pos--;
4594 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4596 sel_end_cursor.par = sel_end_cursor.par->Next();
4597 sel_end_cursor.pos = 0;
4599 // don't forget to insert a dummy layout paragraph if necessary
4600 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4601 sel_end_cursor.par->BreakParagraphConservative(0);
4602 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4603 sel_end_cursor.par = sel_end_cursor.par->next;
4606 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4608 cursor = sel_end_cursor;
4610 /* please break behind a space, if there is one. The space should
4612 if (sel_start_cursor.pos > 0
4613 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4614 sel_start_cursor.pos--;
4615 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4616 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4619 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4620 tmppar = sel_start_cursor.par->Next();
4622 if (dummy_selection) {
4624 if (kind == LyXParagraph::TAB
4625 || kind == LyXParagraph::FIG
4626 || kind == LyXParagraph::WIDE_TAB
4627 || kind == LyXParagraph::WIDE_FIG
4628 || kind == LyXParagraph::ALGORITHM) {
4629 pair<bool, LyXTextClass::size_type> lres =
4630 textclasslist.NumberOfLayout(parameters->textclass,
4632 LyXTextClass::size_type lay;
4638 lay = 0; // use default layout "Standard" (0)
4640 tmppar->SetLayout(lay);
4644 if (sel_start_cursor.pos > 0) {
4645 /* the footnote-environment should begin with a standard layout.
4646 * Imagine you insert a footnote within an enumeration, you
4647 * certainly do not want an enumerated footnote! */
4651 /* this is a exception the user would sometimes expect, I hope */
4652 sel_start_cursor.par->Clear();
4656 while (tmppar != sel_end_cursor.par) {
4657 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4658 tmppar->footnotekind = kind;
4659 tmppar = tmppar->Next();
4662 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4664 SetCursor(sel_start_cursor.par->Next(), 0);
4670 // returns pointer to a specified row
4671 Row * LyXText::GetRow(LyXParagraph * par,
4672 LyXParagraph::size_type pos, long & y) const
4677 if (par == currentrow->par
4678 || par == currentrow->par->Previous()) {
4679 // do not dereference par, it may have been deleted
4680 // already! (Matthias)
4682 // Walk backwards as long as the previous
4683 // rows par is not par
4684 while (currentrow->previous
4685 && currentrow->previous->par != par) {
4686 currentrow = currentrow->previous;
4687 currentrow_y -= currentrow->height;
4689 // Walk backwards as long as the previous
4690 // rows par _is_ par
4691 while (currentrow->previous
4692 && currentrow->previous->par == par) {
4693 currentrow = currentrow->previous;
4694 currentrow_y -= currentrow->height;
4698 tmprow = currentrow;
4700 // find the first row of the specified paragraph
4702 && tmprow->par != par) {
4703 y += tmprow->height;
4704 tmprow = tmprow->next;
4707 if (tmprow->par == par){
4708 // now find the wanted row
4709 while (tmprow->pos < pos
4711 && tmprow->next->par == par
4712 && tmprow->next->pos <= pos) {
4713 y += tmprow->height;
4714 tmprow = tmprow->next;
4716 currentrow = tmprow;
4724 // find the first row of the specified paragraph
4725 while (tmprow->next && tmprow->par != par) {
4726 y += tmprow->height;
4727 tmprow = tmprow->next;
4730 // now find the wanted row
4731 while (tmprow->pos < pos
4733 && tmprow->next->par == par
4734 && tmprow->next->pos <= pos) {
4735 y += tmprow->height;
4736 tmprow = tmprow->next;
4739 currentrow = tmprow;