1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "insets/insetbib.h"
24 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "minibuffer.h"
38 static const int LYX_PAPER_MARGIN = 20;
43 extern int bibitemMaxWidth(Painter &, LyXFont const &);
45 #define FIX_DOUBLE_SPACE 1
47 int LyXText::SingleWidth(LyXParagraph * par,
48 LyXParagraph::size_type pos) const
50 char c = par->GetChar(pos);
51 return SingleWidth(par, pos, c);
55 int LyXText::SingleWidth(LyXParagraph * par,
56 LyXParagraph::size_type pos, char c) const
58 LyXFont font = GetFont(par, pos);
60 // The most common case is handled first (Asger)
64 } else if (IsHfillChar(c)) {
65 return 3; /* Because of the representation
66 * as vertical lines */
67 } else if (c == LyXParagraph::META_FOOTNOTE ||
68 c == LyXParagraph::META_MARGIN ||
69 c == LyXParagraph::META_FIG ||
70 c == LyXParagraph::META_TAB ||
71 c == LyXParagraph::META_WIDE_FIG ||
72 c == LyXParagraph::META_WIDE_TAB ||
73 c == LyXParagraph::META_ALGORITHM) {
76 case LyXParagraph::META_MARGIN:
79 case LyXParagraph::META_FIG:
82 case LyXParagraph::META_TAB:
85 case LyXParagraph::META_ALGORITHM:
88 case LyXParagraph::META_WIDE_FIG:
91 case LyXParagraph::META_WIDE_TAB:
94 case LyXParagraph::META_FOOTNOTE:
100 return font.stringWidth(fs);
101 } else if (c == LyXParagraph::META_INSET) {
102 Inset * tmpinset= par->GetInset(pos);
104 return par->GetInset(pos)->width(owner_->painter(),
109 } else if (IsSeparatorChar(c))
111 else if (IsNewlineChar(c))
113 return font.width(c);
117 // Returns the paragraph position of the last character in the specified row
118 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
121 return row->par->Last() - 1;
122 else if (row->next->par != row->par)
123 return row->par->Last() - 1;
125 return row->next->pos - 1;
132 void LyXText::ComputeBidiTables(Row * row) const
135 if (!lyxrc->rtl_support) {
139 LyXParagraph::size_type last = RowLast(row);
140 bidi_start = row->pos;
142 if (bidi_start > last) {
147 if (last + 2 - bidi_start >
148 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
149 LyXParagraph::size_type new_size =
150 (last + 2 - bidi_start < 500) ?
151 500 : 2 * (last + 2 - bidi_start);
152 log2vis_list.resize(new_size);
153 vis2log_list.resize(new_size);
156 vis2log_list[last + 1 - bidi_start] = -1;
157 log2vis_list[last + 1 - bidi_start] = -1;
159 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
160 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
161 && row->par->IsLineSeparator(main_body - 1)) {
162 // This is needed in case there is a direction change in
163 // the label which is continued into the main body
164 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
165 ComputeBidiTablesFromTo(row, bidi_start,
167 log2vis_list[main_body - 1 - bidi_start] =
169 vis2log_list[main_body - 1 - bidi_start] =
171 if (main_body <= last)
172 ComputeBidiTablesFromTo(row,
175 ComputeBidiTablesFromTo(row, bidi_start,
177 last - main_body + 2);
178 log2vis_list[main_body - 1 - bidi_start] =
179 last - main_body + 1 + bidi_start;
180 vis2log_list[last - main_body + 1 - bidi_start] =
182 if (main_body <= last)
183 ComputeBidiTablesFromTo(row, main_body,
187 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
191 void LyXText::ComputeBidiTablesFromTo(Row * row,
192 LyXParagraph::size_type from,
193 LyXParagraph::size_type to,
194 LyXParagraph::size_type offset) const
196 LyXParagraph::size_type vpos, old_lpos, stack[2];
197 LyXDirection par_direction = row->par->getParDirection();
198 LyXDirection direction = par_direction;
199 LyXParagraph::size_type lpos = from;
203 if (row->par->getLetterDirection(lpos) == direction) {
204 log2vis_list[lpos - bidi_start] = direction;
208 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
209 && row->par->getFont(lpos).direction() ==
211 && row->par->getFont(lpos).latex() ==
213 // The last check is needed when the
215 stack[level++] = lpos;
217 old_lpos = stack[--level];
218 log2vis_list[old_lpos - bidi_start] =
219 log2vis_list[lpos - bidi_start] =
220 (old_lpos - lpos) * direction;
223 direction = static_cast<LyXDirection>(-direction);
228 old_lpos = stack[--level];
229 log2vis_list[old_lpos - bidi_start] =
230 (old_lpos - (to + 1)) * direction;
231 direction = static_cast<LyXDirection>(-direction);
234 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
237 for (lpos = from; lpos <= to; ++lpos) {
238 vpos += log2vis_list[lpos - bidi_start];
239 vis2log_list[vpos - bidi_start] = lpos;
240 log2vis_list[lpos - bidi_start] = vpos;
245 void LyXText::draw(Row const * row,
246 LyXParagraph::size_type & vpos,
247 int offset, float & x)
249 Painter & pain = owner_->painter();
251 LyXParagraph::size_type pos = vis2log(vpos);
252 char c = row->par->GetChar(pos);
254 if (IsNewlineChar(c)) {
256 // Draw end-of-line marker
257 LyXFont font = GetFont(row->par, pos);
258 int wid = font.width('n');
259 int asc = font.maxAscent();
260 int y = offset + row->baseline;
263 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
264 xp[0] = int(x + wid * 0.375);
265 yp[0] = int(y - 0.875 * asc * 0.75);
268 yp[1] = int(y - 0.500 * asc * 0.75);
270 xp[2] = int(x + wid * 0.375);
271 yp[2] = int(y - 0.125 * asc * 0.75);
273 pain.lines(xp, yp, 3, LColor::eolmarker);
276 yp[0] = int(y - 0.500 * asc * 0.75);
278 xp[1] = int(x + wid);
279 yp[1] = int(y - 0.500 * asc * 0.75);
281 xp[2] = int(x + wid);
282 yp[2] = int(y - asc * 0.75);
284 pain.lines(xp, yp, 3, LColor::eolmarker);
286 xp[0] = int(x + wid * 0.625);
287 yp[0] = int(y - 0.875 * asc * 0.75);
289 xp[1] = int(x + wid);
290 yp[1] = int(y - 0.500 * asc * 0.75);
292 xp[2] = int(x + wid * 0.625);
293 yp[2] = int(y - 0.125 * asc * 0.75);
295 pain.lines(xp, yp, 3, LColor::eolmarker);
297 xp[0] = int(x + wid);
298 yp[0] = int(y - 0.500 * asc * 0.75);
301 yp[1] = int(y - 0.500 * asc * 0.75);
304 yp[2] = int(y - asc * 0.75);
306 pain.lines(xp, yp, 3, LColor::eolmarker);
312 LyXFont font = GetFont(row->par, pos);
313 LyXFont font2 = font;
315 if (c == LyXParagraph::META_FOOTNOTE
316 || c == LyXParagraph::META_MARGIN
317 || c == LyXParagraph::META_FIG
318 || c == LyXParagraph::META_TAB
319 || c == LyXParagraph::META_WIDE_FIG
320 || c == LyXParagraph::META_WIDE_TAB
321 || c == LyXParagraph::META_ALGORITHM) {
324 case LyXParagraph::META_MARGIN:
326 // Draw a sign at the left margin!
328 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
329 offset + row->baseline, "!", 1, font);
331 case LyXParagraph::META_FIG:
334 case LyXParagraph::META_TAB:
337 case LyXParagraph::META_ALGORITHM:
340 case LyXParagraph::META_WIDE_FIG:
343 case LyXParagraph::META_WIDE_TAB:
346 case LyXParagraph::META_FOOTNOTE:
353 // calculate the position of the footnotemark
354 int y = (row->baseline - font2.maxAscent()
357 font.setColor(LColor::footnote);
361 // draw it and set new x position
363 pain.text(int(x), offset + y, fs, font);
364 x += pain.width(fs, font);
365 pain.line(int(tmpx), offset + row->baseline,
366 int(x), offset + row->baseline,
371 } else if (c == LyXParagraph::META_INSET) {
372 Inset * tmpinset = row->par->GetInset(pos);
374 tmpinset->draw(owner_->painter(), font,
375 offset + row->baseline, x);
381 /* usual characters, no insets */
383 // Collect character that we can draw in one command
385 // This is dirty, but fast. Notice that it will never be too small.
386 // For the record, I'll note that Microsoft Word has a limit
387 // of 768 here. We have none :-) (Asger)
388 // Ok. I am the first to admit that the use of std::string will be
389 // a tiny bit slower than using a POD char array. However, I claim
390 // that this slowdown is so small that it is close to inperceptive.
391 // So IMHO we should go with the easier and clearer implementation.
392 // And even if 1024 is a large number here it might overflow, string
393 // will only overflow if the machine is out of memory...
394 static string textstring;
398 LyXParagraph::size_type last = RowLast(row);
400 while (vpos <= last &&
401 (pos = vis2log(vpos)) >= 0
402 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
403 && font2 == GetFont(row->par, pos)) {
409 // Draw text and set the new x position
410 pain.text(int(x), offset + row->baseline, textstring, font);
411 x += pain.width(textstring, font);
413 // what about underbars?
414 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
415 pain.line(tmpx, offset + row->baseline + 2,
416 x, offset + row->baseline + 2);
420 // If we want ulem.sty support, drawing
421 // routines should go here. (Asger)
422 // Why shouldn't LyXFont::drawText handle it internally?
426 // Returns the left beginning of the text.
427 // This information cannot be taken from the layouts-objekt, because in
428 // LaTeX the beginning of the text fits in some cases (for example sections)
429 // exactly the label-width.
430 int LyXText::LeftMargin(Row const * row) const
432 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
433 row->par->GetLayout());
435 string parindent = layout.parindent;
437 /* table stuff -- begin */
440 /* table stuff -- end */
442 int x = LYX_PAPER_MARGIN;
444 x += textclasslist.TextClass(parameters->textclass)
446 .signedStringWidth(textclasslist
447 .TextClass(parameters->textclass)
450 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
451 LyXFont font(LyXFont::ALL_SANE);
452 font.setSize(LyXFont::SIZE_SMALL);
453 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
456 // this is the way, LyX handles the LaTeX-Environments.
457 // I have had this idea very late, so it seems to be a
458 // later added hack and this is true
459 if (!row->par->GetDepth()) {
460 if (!row->par->GetLayout()) {
461 // find the previous same level paragraph
462 if (row->par->FirstPhysicalPar()->Previous()) {
463 LyXParagraph * newpar = row->par
464 ->DepthHook(row->par->GetDepth());
466 textclasslist.Style(parameters->textclass,
473 // find the next level paragraph
475 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
477 // make a corresponding row. Needed to call LeftMargin()
479 // check wether it is a sufficent paragraph
480 if (newpar && newpar->footnoteflag == row->par->footnoteflag
482 .Style(parameters->textclass,
483 newpar->GetLayout()).isEnvironment()) {
485 dummyrow.par = newpar;
486 dummyrow.pos = newpar->Last();
487 x = LeftMargin(&dummyrow);
489 // this is no longer an error, because this function
490 // is used to clear impossible depths after changing
491 // a layout. Since there is always a redo,
492 // LeftMargin() is always called
493 row->par->FirstPhysicalPar()->depth = 0;
496 if (newpar && !row->par->GetLayout()) {
497 if (newpar->FirstPhysicalPar()->noindent)
500 parindent = textclasslist
501 .Style(parameters->textclass,
502 newpar->GetLayout()).parindent;
507 LyXFont labelfont = GetFont(row->par, -2);
508 switch (layout.margintype) {
510 if (!layout.leftmargin.empty()) {
512 .TextClass(parameters->textclass)
514 .signedStringWidth(layout.leftmargin);
516 if (!row->par->GetLabestring().empty()) {
517 x += labelfont.signedStringWidth(layout.labelindent);
518 x += labelfont.stringWidth(row->par->GetLabestring());
519 x += labelfont.stringWidth(layout.labelsep);
523 x += labelfont.signedStringWidth(layout.labelindent);
524 if (row->pos >= BeginningOfMainBody(row->par)) {
525 if (!row->par->GetLabelWidthString().empty()) {
527 .stringWidth(row->par
528 ->GetLabelWidthString());
529 x += labelfont.stringWidth(layout.labelsep);
534 x += textclasslist.TextClass(parameters->textclass)
535 .defaultfont().signedStringWidth(layout.leftmargin) * 4
536 / (row->par->GetDepth() + 4);
538 case MARGIN_FIRST_DYNAMIC:
539 if (layout.labeltype == LABEL_MANUAL) {
540 if (row->pos >= BeginningOfMainBody(row->par)) {
542 .signedStringWidth(layout.leftmargin);
545 .signedStringWidth(layout.labelindent);
548 // Special case to fix problems with
550 || (layout.labeltype == LABEL_STATIC
551 && layout.latextype == LATEX_ENVIRONMENT
552 && ! row->par->IsFirstInSequence())) {
553 x += labelfont.signedStringWidth(layout.leftmargin);
554 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
555 && layout.labeltype != LABEL_BIBLIO
556 && layout.labeltype !=
557 LABEL_CENTERED_TOP_ENVIRONMENT) {
558 x += labelfont.signedStringWidth(layout.labelindent);
559 x += labelfont.stringWidth(layout.labelsep);
560 x += labelfont.stringWidth(row->par->GetLabestring());
564 case MARGIN_RIGHT_ADDRESS_BOX:
566 // ok, a terrible hack. The left margin depends on the widest
567 // row in this paragraph. Do not care about footnotes, they
568 // are *NOT* allowed in the LaTeX realisation of this layout.
570 // find the first row of this paragraph
571 Row const * tmprow = row;
572 while (tmprow->previous && tmprow->previous->par == row->par)
573 tmprow = tmprow->previous;
575 int minfill = tmprow->fill;
576 while (tmprow->next && tmprow->next->par == row->par) {
577 tmprow = tmprow->next;
578 if (tmprow->fill < minfill)
579 minfill = tmprow->fill;
582 x += textclasslist.TextClass(parameters->textclass)
583 .defaultfont().signedStringWidth(layout.leftmargin);
588 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
589 if (!row->par->pextra_widthp.empty()) {
591 atoi(row->par->pextra_widthp.c_str()) / 100;
592 } else if (!row->par->pextra_width.empty()) {
593 int xx = VSpace(row->par->pextra_width).inPixels(owner_);
596 xx = paperwidth * 80 / 100;
598 } else { // should not happen
599 LyXFont font(LyXFont::ALL_SANE);
600 x += font.stringWidth("XXXXXX");
605 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
606 align = layout.align;
608 align = row->par->FirstPhysicalPar()->align;
610 // set the correct parindent
612 if ((layout.labeltype == LABEL_NO_LABEL
613 || layout.labeltype == LABEL_TOP_ENVIRONMENT
614 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
615 || (layout.labeltype == LABEL_STATIC
616 && layout.latextype == LATEX_ENVIRONMENT
617 && ! row->par->IsFirstInSequence()))
618 && row->par == row->par->FirstPhysicalPar()
619 && align == LYX_ALIGN_BLOCK
620 && !row->par->noindent
621 && (row->par->layout ||
622 parameters->paragraph_separation ==
623 BufferParams::PARSEP_INDENT))
624 x += textclasslist.TextClass(parameters->textclass)
625 .defaultfont().signedStringWidth(parindent);
626 else if (layout.labeltype == LABEL_BIBLIO) {
627 // ale970405 Right width for bibitems
628 x += bibitemMaxWidth(owner_->painter(),
630 .TextClass(parameters
639 int LyXText::RightMargin(Row const * row) const
641 LyXLayout const & layout =
642 textclasslist.Style(parameters->textclass,
643 row->par->GetLayout());
645 int x = LYX_PAPER_MARGIN
647 .TextClass(parameters->textclass)
649 .signedStringWidth(textclasslist
650 .TextClass(parameters->textclass)
653 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
654 x += LYX_PAPER_MARGIN / 2;
657 // this is the way, LyX handles the LaTeX-Environments.
658 // I have had this idea very late, so it seems to be a
659 // later added hack and this is true
660 if (row->par->GetDepth()) {
661 // find the next level paragraph
663 LyXParagraph * newpar = row->par;
666 newpar = newpar->FirstPhysicalPar()->Previous();
668 newpar = newpar->FirstPhysicalPar();
669 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
670 && newpar->footnoteflag == row->par->footnoteflag);
672 // make a corresponding row. Needed to call LeftMargin()
674 // check wether it is a sufficent paragraph
675 if (newpar && newpar->footnoteflag == row->par->footnoteflag
676 && textclasslist.Style(parameters->textclass,
680 dummyrow.par = newpar;
682 x = RightMargin(&dummyrow);
684 // this is no longer an error, because this function
685 // is used to clear impossible depths after changing
686 // a layout. Since there is always a redo,
687 // LeftMargin() is always called
688 row->par->FirstPhysicalPar()->depth = 0;
692 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
693 x += textclasslist.TextClass(parameters->textclass)
695 .signedStringWidth(layout.rightmargin) * 4
696 / (row->par->GetDepth() + 4);
701 int LyXText::LabelEnd (Row const * row) const
703 if (textclasslist.Style(parameters->textclass,
704 row->par->GetLayout()).margintype
708 tmprow.pos = row->par->Last();
709 return LeftMargin(&tmprow); /* just the beginning
712 return 0; /* LabelEnd is only needed, if the
713 layout fills a flushleft
718 /* table stuff -- begin*/
719 int LyXText::NumberOfCell(LyXParagraph * par,
720 LyXParagraph::size_type pos) const
723 LyXParagraph::size_type tmp_pos = 0;
724 while (tmp_pos < pos) {
725 if (par->IsNewline(tmp_pos))
733 int LyXText::WidthOfCell(LyXParagraph * par,
734 LyXParagraph::size_type & pos) const
737 while (pos < par->Last() && !par->IsNewline(pos)) {
738 w += SingleWidth(par, pos);
741 if (par->IsNewline(pos))
747 bool LyXText::HitInTable(Row * row, int x) const
750 float fill_separator, fill_hfill, fill_label_hfill;
751 if (!row->par->table)
753 PrepareToPrint(row, tmpx, fill_separator,
754 fill_hfill, fill_label_hfill, false);
755 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
759 bool LyXText::MouseHitInTable(int x, long y) const
761 Row * row = GetRowNearY(y);
762 return HitInTable(row, x);
766 /* table stuff -- end*/
769 // get the next breakpoint in a given paragraph
770 LyXParagraph::size_type
771 LyXText::NextBreakPoint(Row const * row, int width) const
773 LyXParagraph * par = row->par;
774 LyXParagraph::size_type pos = row->pos;
776 /* table stuff -- begin*/
778 while (pos < par->size()
779 && (!par->IsNewline(pos)
780 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
781 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
782 par->GetInset(pos) && par->GetInset(pos)->display()){
783 par->GetInset(pos)->display(false);
789 /* table stuff -- end*/
791 // position of the last possible breakpoint
792 // -1 isn't a suitable value, but a flag
793 LyXParagraph::size_type last_separator = -1;
794 int left_margin = LabelEnd(row);
795 width -= RightMargin(row);
797 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
798 LyXLayout const & layout =
799 textclasslist.Style(parameters->textclass, par->GetLayout());
800 LyXParagraph::size_type i = pos;
802 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
803 /* special code for right address boxes, only newlines count */
804 while (i < par->Last()) {
805 if (par->IsNewline(i)) {
807 i = par->Last() - 1; // this means break
809 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
810 par->GetInset(i) && par->GetInset(i)->display()){
811 par->GetInset(i)->display(false);
816 // Last position is an invariant
817 LyXParagraph::size_type const last =
819 // this is the usual handling
820 int x = LeftMargin(row);
821 while (x < width && i < last) {
822 char c = par->GetChar(i);
823 if (IsNewlineChar(c)) {
825 x = width; // this means break
826 } else if (c == LyXParagraph::META_INSET &&
827 par->GetInset(i) && par->GetInset(i)->display()){
828 // check wether a Display() inset is
829 // valid here. if not, change it to
831 if (layout.isCommand()
832 || (layout.labeltype == LABEL_MANUAL
833 && i < BeginningOfMainBody(par))){
834 // display istn't allowd
835 par->GetInset(i)->display(false);
836 x += SingleWidth(par, i, c);
838 // inset is display. So break the line here
842 if (IsLineSeparatorChar(par->GetChar(i+1)))
845 last_separator = last; // to avoid extra rows
847 last_separator = i - 1;
848 x = width; // this means break
851 if (IsLineSeparatorChar(c))
853 x += SingleWidth(par, i, c);
856 if (i == main_body) {
857 x += GetFont(par, -2).stringWidth(layout.labelsep);
858 if (par->IsLineSeparator(i - 1))
859 x-= SingleWidth(par, i - 1);
864 // end of paragraph is always a suitable separator
865 if (i == last && x < width)
869 // well, if last_separator is still 0, the line isn't breakable.
870 // don't care and cut simply at the end
871 if (last_separator < 0) {
875 // manual labels cannot be broken in LaTeX, do not care
876 if (main_body && last_separator < main_body)
877 last_separator = main_body - 1;
879 return last_separator;
883 // returns the minimum space a row needs on the screen in pixel
884 int LyXText::Fill(Row const * row, int paper_width) const
887 // get the pure distance
888 LyXParagraph::size_type last = RowLast(row);
889 /* table stuff -- begin */
890 if (row->par->table) {
891 // for tables FILL does calculate the widthes of each cell in
893 LyXParagraph::size_type pos = row->pos;
894 int cell = NumberOfCell(row->par, pos);
897 row->par->table->SetWidthOfCell(cell,
898 WidthOfCell(row->par,
901 } while (pos <= last && !row->par->table->IsFirstCell(cell));
902 // don't forget the very last table cell without characters
903 if (cell == row->par->table->GetNumberOfCells() - 1)
904 row->par->table->SetWidthOfCell(cell,
905 WidthOfCell(row->par,
908 return 0; /* width of table cannot be returned since
909 * we cannot guarantee its correct value at
912 /* table stuff -- end*/
914 int left_margin = LabelEnd(row);
916 // if the row ends with newline, this newline will not be relevant
917 //if (last >= 0 && row->par->IsNewline(last))
920 // if the row ends with a space, this space will not be relevant
921 if (last >= 0 && row->par->IsLineSeparator(last))
924 // special handling of the right address boxes
925 if (textclasslist.Style(parameters->textclass,
926 row->par->GetLayout()).margintype
927 == MARGIN_RIGHT_ADDRESS_BOX) {
928 int tmpfill = row->fill;
929 row->fill = 0; // the minfill in MarginLeft()
935 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
936 row->par->GetLayout());
937 LyXParagraph::size_type main_body =
938 BeginningOfMainBody(row->par);
939 LyXParagraph::size_type i = row->pos;
942 if (main_body > 0 && i == main_body) {
943 w += GetFont(row->par, -2).
944 stringWidth(layout.labelsep);
945 if (row->par->IsLineSeparator(i - 1))
946 w -= SingleWidth(row->par, i - 1);
950 w += SingleWidth(row->par, i);
953 if (main_body > 0 && main_body > last) {
954 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
955 if (last >= 0 && row->par->IsLineSeparator(last))
956 w -= SingleWidth(row->par, last);
961 fill = paper_width - w - RightMargin(row);
966 // returns the minimum space a manual label needs on the screen in pixel
967 int LyXText::LabelFill(Row const * row) const
969 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
970 // -1 because a label ends either with a space that is in the label,
971 // or with the beginning of a footnote that is outside the label.
973 // I don't understand this code in depth, but sometimes "last" is
974 // less than 0 and this causes a crash. This fix seems to work
975 // correctly, but I bet the real error is elsewhere. The bug is
976 // triggered when you have an open footnote in a paragraph
977 // environment with a manual label. (Asger)
978 if (last < 0) last = 0;
980 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
987 w += SingleWidth(row->par, i);
992 if (!row->par->labelwidthstring.empty()) {
993 fill = GetFont(row->par, -2)
994 .stringWidth(row->par->labelwidthstring) - w;
1004 // returns the number of separators in the specified row. The separator
1005 // on the very last column doesnt count
1006 int LyXText::NumberOfSeparators(Row const * row) const
1008 int last = RowLast(row);
1010 //int main_body = BeginningOfMainBody(row->par);
1011 //if (p < main_body)
1013 // I think this is equivalent to the above. (Lgb)
1014 int p = max(row->pos, BeginningOfMainBody(row->par));
1016 for (; p < last; ++p) {
1017 if (row->par->IsSeparator(p)) {
1025 // returns the number of hfills in the specified row. The LyX-Hfill is
1026 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1027 // ignored. This is *MUCH* more usefull than not to ignore!
1028 int LyXText::NumberOfHfills(Row const * row) const
1030 int last = RowLast(row);
1031 int first = row->pos;
1032 if (first) { /* hfill *DO* count at the beginning
1034 while(first <= last && row->par->IsHfill(first))
1038 //int main_body = BeginningOfMainBody(row->par);
1039 //if (first < main_body)
1040 // first = main_body;
1041 // I think this is equivalent to the above. (Lgb)
1042 first = max(first, BeginningOfMainBody(row->par));
1044 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1045 if (row->par->IsHfill(p)) {
1053 // like NumberOfHfills, but only those in the manual label!
1054 int LyXText::NumberOfLabelHfills(Row const * row) const
1056 LyXParagraph::size_type last = RowLast(row);
1057 LyXParagraph::size_type first = row->pos;
1058 if (first) { /* hfill *DO* count at the beginning
1060 while(first < last && row->par->IsHfill(first))
1063 //LyXParagraph::size_type main_body =
1064 //BeginningOfMainBody(row->par);
1065 //if (last > main_body)
1067 // I think this is eqvialent to the above. (Lgb)
1068 last = min(last, BeginningOfMainBody(row->par));
1070 for (LyXParagraph::size_type p = first;
1071 p < last; ++p) { // last, because the end is ignored!
1072 if (row->par->IsHfill(p)) {
1080 // returns true, if a expansion is needed.
1081 // Rules are given by LaTeX
1082 bool LyXText::HfillExpansion(Row const * row_ptr,
1083 LyXParagraph::size_type pos) const
1085 // by the way, is it a hfill?
1086 if (!row_ptr->par->IsHfill(pos))
1089 // at the end of a row it does not count
1090 if (pos >= RowLast(row_ptr))
1093 // at the beginning of a row it does not count, if it is not
1094 // the first row of a paragaph
1098 // in some labels it does not count
1099 if (textclasslist.Style(parameters->textclass,
1100 row_ptr->par->GetLayout()).margintype
1102 && pos < BeginningOfMainBody(row_ptr->par))
1105 // if there is anything between the first char of the row and
1106 // the sepcified position that is not a newline and not a hfill,
1107 // the hfill will count, otherwise not
1108 LyXParagraph::size_type i = row_ptr->pos;
1109 while (i < pos && (row_ptr->par->IsNewline(i)
1110 || row_ptr->par->IsHfill(i)))
1117 void LyXText::SetHeightOfRow(Row * row_ptr) const
1119 /* get the maximum ascent and the maximum descent */
1121 float layoutasc = 0;
1122 float layoutdesc = 0;
1127 /* this must not happen before the currentrow for clear reasons.
1128 so the trick is just to set the current row onto this row */
1130 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1132 /* ok , let us initialize the maxasc and maxdesc value.
1133 * This depends in LaTeX of the font of the last character
1134 * in the paragraph. The hack below is necessary because
1135 * of the possibility of open footnotes */
1137 /* Correction: only the fontsize count. The other properties
1138 are taken from the layoutfont. Nicer on the screen :) */
1140 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1141 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1143 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1144 firstpar->GetLayout());
1146 LyXFont font = GetFont(par, par->Last()-1);
1147 LyXFont::FONT_SIZE size = font.size();
1148 font = GetFont(par, -1);
1151 LyXFont labelfont = GetFont(par, -2);
1153 int maxasc = int(font.maxAscent() *
1154 layout.spacing.getValue() *
1155 parameters->spacing.getValue());
1156 int maxdesc = int(font.maxDescent() *
1157 layout.spacing.getValue() *
1158 parameters->spacing.getValue());
1160 int pos_end = RowLast(row_ptr);
1164 // Check if any insets are larger
1165 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1166 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1167 tmpfont = GetFont(row_ptr->par, pos);
1168 tmpinset = row_ptr->par->GetInset(pos);
1170 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1171 desc = tmpinset->descent(owner_->painter(), tmpfont);
1180 // Check if any custom fonts are larger (Asger)
1181 // This is not completely correct, but we can live with the small,
1182 // cosmetic error for now.
1183 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1185 if (maxsize > font.size()) {
1186 font.setSize(maxsize);
1188 asc = font.maxAscent();
1189 desc = font.maxDescent();
1196 /* table stuff -- begin*/
1197 if (row_ptr->par->table){
1198 // stretch the rows a bit
1202 /* table stuff -- end*/
1204 // This is nicer with box insets:
1208 row_ptr->ascent_of_text = maxasc;
1210 /* is it a top line? */
1211 if (row_ptr->pos == 0
1212 && row_ptr->par == firstpar) {
1214 /* some parksips VERY EASY IMPLEMENTATION */
1215 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1216 if (layout.isParagraph()
1217 && firstpar->GetDepth() == 0
1218 && firstpar->Previous())
1219 maxasc += parameters->getDefSkip().inPixels(owner_);
1220 else if (firstpar->Previous()
1221 && textclasslist.Style(parameters->textclass,
1222 firstpar->Previous()->GetLayout()).isParagraph()
1223 && firstpar->Previous()->GetDepth() == 0)
1224 // is it right to use defskip here too? (AS)
1225 maxasc += parameters->getDefSkip().inPixels(owner_);
1228 /* the paper margins */
1229 if (!row_ptr->par->previous)
1230 maxasc += LYX_PAPER_MARGIN;
1232 /* add the vertical spaces, that the user added */
1233 if (firstpar->added_space_top.kind() != VSpace::NONE)
1234 maxasc += int(firstpar->added_space_top.inPixels(owner_));
1236 /* do not forget the DTP-lines!
1237 * there height depends on the font of the nearest character */
1238 if (firstpar->line_top)
1239 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1241 /* and now the pagebreaks */
1242 if (firstpar->pagebreak_top)
1243 maxasc += 3 * DefaultHeight();
1245 /* this is special code for the chapter, since the label of this
1246 * layout is printed in an extra row */
1247 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1248 && parameters->secnumdepth>= 0) {
1249 labeladdon = int(labelfont.maxDescent() *
1250 layout.spacing.getValue() *
1251 parameters->spacing.getValue())
1252 + int(labelfont.maxAscent() *
1253 layout.spacing.getValue() *
1254 parameters->spacing.getValue());
1257 /* special code for the top label */
1258 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1259 || layout.labeltype == LABEL_BIBLIO
1260 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1261 && row_ptr->par->IsFirstInSequence()
1262 && !row_ptr->par->GetLabestring().empty()) {
1264 (labelfont.maxAscent() *
1265 layout.spacing.getValue() *
1266 parameters->spacing.getValue())
1267 +(labelfont.maxDescent() *
1268 layout.spacing.getValue() *
1269 parameters->spacing.getValue())
1270 + layout.topsep * DefaultHeight()
1271 + layout.labelbottomsep * DefaultHeight());
1274 /* and now the layout spaces, for example before and after a section,
1275 * or between the items of a itemize or enumerate environment */
1277 if (!firstpar->pagebreak_top) {
1278 LyXParagraph * prev = row_ptr->par->Previous();
1280 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1281 if (prev && prev->GetLayout() == firstpar->GetLayout()
1282 && prev->GetDepth() == firstpar->GetDepth()
1283 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1285 layoutasc = (layout.itemsep * DefaultHeight());
1287 else if (row_ptr->previous) {
1288 tmptop = layout.topsep;
1290 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1291 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1294 layoutasc = (tmptop * DefaultHeight());
1296 else if (row_ptr->par->line_top){
1297 tmptop = layout.topsep;
1300 layoutasc = (tmptop * DefaultHeight());
1303 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1305 maxasc += int(textclasslist.Style(parameters->textclass,
1306 prev->GetLayout()).parsep * DefaultHeight());
1309 if (firstpar->Previous()
1310 && firstpar->Previous()->GetDepth() == 0
1311 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1314 else if (firstpar->Previous()){
1315 maxasc += int(layout.parsep * DefaultHeight());
1321 /* is it a bottom line? */
1322 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1323 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1325 /* the paper margins */
1327 maxdesc += LYX_PAPER_MARGIN;
1329 /* add the vertical spaces, that the user added */
1330 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1331 maxdesc += int(firstpar->added_space_bottom.inPixels(owner_));
1333 /* do not forget the DTP-lines!
1334 * there height depends on the font of the nearest character */
1335 if (firstpar->line_bottom)
1336 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1338 /* and now the pagebreaks */
1339 if (firstpar->pagebreak_bottom)
1340 maxdesc += 3 * DefaultHeight();
1342 /* and now the layout spaces, for example before and after a section,
1343 * or between the items of a itemize or enumerate environment */
1344 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1345 LyXParagraph * nextpar = row_ptr->par->Next();
1346 LyXParagraph * comparepar = row_ptr->par;
1350 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1351 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1352 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1353 if (comparepar->GetLayout()!= nextpar->GetLayout()
1354 || nextpar->GetLabelWidthString() !=
1355 comparepar->GetLabelWidthString())
1356 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1358 if (unusual > usual)
1359 layoutdesc = unusual;
1363 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1365 if (comparepar->GetLayout()!= nextpar->GetLayout()
1366 || nextpar->GetLabelWidthString() !=
1367 comparepar->GetLabelWidthString())
1368 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1373 /* incalculate the layout spaces */
1374 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1375 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1377 /* table stuff -- begin*/
1378 if (row_ptr->par->table){
1379 maxasc += row_ptr->par->table->
1380 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1382 /* table stuff -- end*/
1384 /* calculate the new height of the text */
1385 height -= row_ptr->height;
1387 row_ptr->height = maxasc + maxdesc + labeladdon;
1388 row_ptr->baseline = maxasc + labeladdon;
1390 height += row_ptr->height;
1394 /* Appends the implicit specified paragraph behind the specified row,
1395 * start at the implicit given position */
1396 void LyXText::AppendParagraph(Row * row) const
1398 bool not_ready = true;
1400 // The last character position of a paragraph is an invariant so we can
1401 // safely get it here. (Asger)
1402 int lastposition = row->par->Last();
1405 // Get the next breakpoint
1406 int z = NextBreakPoint(row, paperwidth);
1410 // Insert the new row
1411 if (z < lastposition) {
1413 InsertRow(row, row->par, z);
1420 // Set the dimensions of the row
1421 tmprow->fill = Fill(tmprow, paperwidth);
1422 SetHeightOfRow(tmprow);
1424 } while (not_ready);
1428 void LyXText::BreakAgain(Row * row) const
1430 bool not_ready = true;
1433 /* get the next breakpoint */
1434 LyXParagraph::size_type z =
1435 NextBreakPoint(row, paperwidth);
1438 if (z < row->par->Last() ) {
1439 if (!row->next || (row->next && row->next->par != row->par)) {
1442 InsertRow(row, row->par, z);
1449 not_ready = false; // the rest will not change
1455 /* if there are some rows too much, delete them */
1456 /* only if you broke the whole paragraph! */
1457 Row * tmprow2 = row;
1458 while (tmprow2->next && tmprow2->next->par == row->par) {
1459 tmprow2 = tmprow2->next;
1461 while (tmprow2 != row) {
1462 tmprow2 = tmprow2->previous;
1463 RemoveRow(tmprow2->next);
1468 /* set the dimensions of the row */
1469 tmprow->fill = Fill(tmprow, paperwidth);
1470 SetHeightOfRow(tmprow);
1471 } while (not_ready);
1475 /* this is just a little changed version of break again */
1476 void LyXText::BreakAgainOneRow(Row * row)
1478 /* get the next breakpoint */
1479 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1482 if (z < row->par->Last() ) {
1483 if (!row->next || (row->next && row->next->par != row->par)) {
1484 /* insert a new row */
1486 InsertRow(row, row->par, z);
1498 /* if there are some rows too much, delete them */
1499 /* only if you broke the whole paragraph! */
1500 Row * tmprow2 = row;
1501 while (tmprow2->next && tmprow2->next->par == row->par) {
1502 tmprow2 = tmprow2->next;
1504 while (tmprow2 != row) {
1505 tmprow2 = tmprow2->previous;
1506 RemoveRow(tmprow2->next);
1510 /* set the dimensions of the row */
1511 tmprow->fill = Fill(tmprow, paperwidth);
1512 SetHeightOfRow(tmprow);
1516 void LyXText::BreakParagraph(char keep_layout)
1518 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1519 cursor.par->GetLayout());
1521 /* table stuff -- begin */
1522 if (cursor.par->table) {
1523 // breaking of tables is only allowed at the beginning or the end */
1524 if (cursor.pos && cursor.pos < cursor.par->size() &&
1525 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1526 return; // no breaking of tables allowed
1528 /* table stuff -- end */
1530 // this is only allowed, if the current paragraph is not empty or caption
1531 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1533 layout.labeltype!= LABEL_SENSITIVE)
1536 SetUndo(Undo::INSERT,
1537 cursor.par->ParFromPos(cursor.pos)->previous,
1538 cursor.par->ParFromPos(cursor.pos)->next);
1540 /* table stuff -- begin */
1541 if (cursor.par->table) {
1542 int cell = NumberOfCell(cursor.par, cursor.pos);
1543 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1544 SetCursor(cursor.par, cursor.par->text.size());
1546 /* table stuff -- end */
1548 // please break always behind a space
1549 if (cursor.pos < cursor.par->Last()
1550 && cursor.par->IsLineSeparator(cursor.pos))
1553 // break the paragraph
1557 keep_layout = layout.isEnvironment();
1558 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1560 /* table stuff -- begin */
1561 if (cursor.par->table){
1562 // the table should stay with the contents
1564 cursor.par->Next()->table = cursor.par->table;
1565 cursor.par->table = 0;
1568 /* table stuff -- end */
1570 // well this is the caption hack since one caption is really enough
1571 if (layout.labeltype == LABEL_SENSITIVE){
1573 cursor.par->SetLayout(0); // set to standard-layout
1575 cursor.par->Next()->SetLayout(0); // set to standard-layout
1578 /* if the cursor is at the beginning of a row without prior newline,
1580 * This touches only the screen-update. Otherwise we would may have
1581 * an empty row on the screen */
1582 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1583 cursor.row->pos == cursor.pos) {
1587 status = LyXText::NEED_MORE_REFRESH;
1588 refresh_row = cursor.row;
1589 refresh_y = cursor.y - cursor.row->baseline;
1591 // Do not forget the special right address boxes
1592 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1593 while (refresh_row->previous &&
1594 refresh_row->previous->par == refresh_row->par) {
1595 refresh_row = refresh_row->previous;
1596 refresh_y -= refresh_row->height;
1599 RemoveParagraph(cursor.row);
1601 // set the dimensions of the cursor row
1602 cursor.row->fill = Fill(cursor.row, paperwidth);
1604 SetHeightOfRow(cursor.row);
1606 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1607 && cursor.par->Next()->IsNewline(0))
1608 cursor.par->Next()->Erase(0);
1610 InsertParagraph(cursor.par->Next(), cursor.row);
1612 UpdateCounters(cursor.row->previous);
1614 /* This check is necessary. Otherwise the new empty paragraph will
1615 * be deleted automatically. And it is more friendly for the user! */
1617 SetCursor(cursor.par->Next(), 0);
1619 SetCursor(cursor.par, 0);
1621 if (cursor.row->next)
1622 BreakAgain(cursor.row->next);
1628 void LyXText::OpenFootnote()
1630 LyXParagraph * endpar,* tmppar;
1633 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1635 /* if there is no footnote in this paragraph, just return. */
1637 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1640 /* ok, move the cursor right before the footnote */
1642 /* just a little faster than using CursorRight() */
1643 for (cursor.pos = 0;
1644 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1645 /* now the cursor is at the beginning of the physical par */
1646 SetCursor(cursor.par,
1647 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1649 /* the cursor must be exactly before the footnote */
1650 par = cursor.par->ParFromPos(cursor.pos);
1652 status = LyXText::NEED_MORE_REFRESH;
1653 refresh_row = cursor.row;
1654 refresh_y = cursor.y - cursor.row->baseline;
1656 tmppar = cursor.par;
1657 endpar = cursor.par->Next();
1660 tmppar->OpenFootnote(cursor.pos);
1661 RemoveParagraph(row);
1662 /* set the dimensions of the cursor row */
1663 row->fill = Fill(row, paperwidth);
1664 SetHeightOfRow(row);
1665 tmppar = tmppar->Next();
1667 while (tmppar != endpar) {
1669 InsertParagraph(tmppar, row);
1670 while (row->next && row->next->par == tmppar)
1672 tmppar = tmppar->Next();
1675 SetCursor(par->next, 0);
1676 sel_cursor = cursor;
1680 /* table stuff -- begin*/
1682 void LyXText::TableFeatures(int feature, string const & val) const
1684 if (!cursor.par->table)
1685 return; /* this should never happen */
1687 int actCell = NumberOfCell(cursor.par, cursor.pos);
1688 SetUndo(Undo::FINISH,
1689 cursor.par->ParFromPos(cursor.pos)->previous,
1690 cursor.par->ParFromPos(cursor.pos)->next);
1693 case LyXTable::SET_PWIDTH:
1694 cursor.par->table->SetPWidth(actCell, val);
1696 case LyXTable::SET_SPECIAL_COLUMN:
1697 case LyXTable::SET_SPECIAL_MULTI:
1698 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1707 void LyXText::TableFeatures(int feature) const
1710 int setAlign = LYX_ALIGN_LEFT;
1714 if (!cursor.par->table)
1715 return; /* this should never happen */
1717 int actCell = NumberOfCell(cursor.par, cursor.pos);
1718 SetUndo(Undo::FINISH,
1719 cursor.par->ParFromPos(cursor.pos)->previous,
1720 cursor.par->ParFromPos(cursor.pos)->next);
1723 case LyXTable::ALIGN_LEFT:
1724 setAlign= LYX_ALIGN_LEFT;
1726 case LyXTable::ALIGN_RIGHT:
1727 setAlign= LYX_ALIGN_RIGHT;
1729 case LyXTable::ALIGN_CENTER:
1730 setAlign= LYX_ALIGN_CENTER;
1736 case LyXTable::APPEND_ROW: {
1737 LyXParagraph::size_type pos = cursor.pos;
1739 /* move to the next row */
1740 int cell_org = actCell;
1741 int cell = cell_org;
1743 // if there is a ContRow following this row I have to add
1744 // the row after the ContRow's
1745 if ((pos < cursor.par->Last()) &&
1746 cursor.par->table->RowHasContRow(cell_org)) {
1747 while((pos < cursor.par->Last()) &&
1748 !cursor.par->table->IsContRow(cell)) {
1749 while (pos < cursor.par->Last() &&
1750 !cursor.par->IsNewline(pos))
1752 if (pos < cursor.par->Last())
1756 while((pos < cursor.par->Last()) &&
1757 cursor.par->table->IsContRow(cell)) {
1758 while (pos < cursor.par->Last() &&
1759 !cursor.par->IsNewline(pos))
1761 if (pos < cursor.par->Last())
1766 if (pos < cursor.par->Last())
1769 while (pos < cursor.par->Last() &&
1770 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1771 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1773 if (pos < cursor.par->Last())
1778 /* insert the new cells */
1779 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1780 for (int i = 0; i < number; ++i)
1781 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1783 /* append the row into the table */
1784 cursor.par->table->AppendRow(cell_org);
1788 case LyXTable::APPEND_CONT_ROW: {
1789 LyXParagraph::size_type pos = cursor.pos;
1790 /* move to the next row */
1791 int cell_org = actCell;
1792 int cell = cell_org;
1794 // if there is already a controw but not for this cell
1795 // the AppendContRow sets only the right values but does
1796 // not actually add a row
1797 if (cursor.par->table->RowHasContRow(cell_org) &&
1798 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1799 cursor.par->table->AppendContRow(cell_org);
1803 while (pos < cursor.par->Last() &&
1805 || !cursor.par->table->IsFirstCell(cell))){
1806 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1808 if (pos < cursor.par->Last())
1813 /* insert the new cells */
1814 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1815 for (int i = 0; i < number; ++i)
1816 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1818 /* append the row into the table */
1819 cursor.par->table->AppendContRow(cell_org);
1823 case LyXTable::APPEND_COLUMN: {
1824 LyXParagraph::size_type pos = 0;
1825 int cell_org = actCell;
1828 if (pos && (cursor.par->IsNewline(pos-1))){
1829 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)) {
1830 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1831 if (pos <= cursor.pos)
1838 } while (pos <= cursor.par->Last());
1839 /* remember that the very last cell doesn't end with a newline.
1840 This saves one byte memory per table ;-) */
1841 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1842 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1844 /* append the column into the table */
1845 cursor.par->table->AppendColumn(cell_org);
1850 case LyXTable::DELETE_ROW:
1851 if (owner_->the_locking_inset)
1852 owner_->unlockInset(owner_->the_locking_inset);
1853 RemoveTableRow(&cursor);
1857 case LyXTable::DELETE_COLUMN: {
1858 LyXParagraph::size_type pos = 0;
1859 int cell_org = actCell;
1861 if (owner_->the_locking_inset)
1862 owner_->unlockInset(owner_->the_locking_inset);
1864 if (!pos || (cursor.par->IsNewline(pos-1))){
1865 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1867 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1868 cursor.par->Erase(pos);
1869 if (pos < cursor.par->Last())
1870 cursor.par->Erase(pos);
1872 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1873 --pos; // because of pos++ below
1878 } while (pos <= cursor.par->Last());
1880 /* delete the column from the table */
1881 cursor.par->table->DeleteColumn(cell_org);
1883 /* set the cursor to the beginning of the table, where else? */
1888 case LyXTable::TOGGLE_LINE_TOP:
1889 lineSet = !cursor.par->table->TopLine(actCell);
1891 cursor.par->table->SetTopLine(actCell, lineSet);
1893 LyXParagraph::size_type i;
1895 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1896 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1897 cursor.par->table->SetTopLine(n, lineSet);
1905 case LyXTable::TOGGLE_LINE_BOTTOM:
1906 lineSet = !cursor.par->table->BottomLine(actCell);
1908 cursor.par->table->SetBottomLine(actCell, lineSet);
1910 LyXParagraph::size_type i;
1912 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1913 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1914 cursor.par->table->SetBottomLine(n, lineSet);
1922 case LyXTable::TOGGLE_LINE_LEFT:
1923 lineSet = !cursor.par->table->LeftLine(actCell);
1925 cursor.par->table->SetLeftLine(actCell, lineSet);
1927 LyXParagraph::size_type i;
1929 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1930 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1931 cursor.par->table->SetLeftLine(n, lineSet);
1939 case LyXTable::TOGGLE_LINE_RIGHT:
1940 lineSet = !cursor.par->table->RightLine(actCell);
1942 cursor.par->table->SetRightLine(actCell, lineSet);
1945 LyXParagraph::size_type i = sel_start_cursor.pos;
1946 for (; i <= sel_end_cursor.pos; ++i) {
1947 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1948 cursor.par->table->SetRightLine(n, lineSet);
1956 case LyXTable::ALIGN_LEFT:
1957 case LyXTable::ALIGN_RIGHT:
1958 case LyXTable::ALIGN_CENTER:
1960 cursor.par->table->SetAlignment(actCell, setAlign);
1963 LyXParagraph::size_type i = sel_start_cursor.pos;
1964 for (; i <= sel_end_cursor.pos; ++i) {
1965 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1966 cursor.par->table->SetAlignment(n, setAlign);
1974 case LyXTable::DELETE_TABLE:
1975 SetCursorIntern(cursor.par, 0);
1976 delete cursor.par->table;
1977 cursor.par->table = 0;
1978 // temporary: Should put table in simple_cut_buffer (with before and after
1979 // dummy-paragraph !!
1980 // not necessar anymore with UNDO :)
1981 for (LyXParagraph::size_type i =
1982 cursor.par->text.size() - 1; i >= 0; --i)
1983 cursor.par->Erase(i);
1987 case LyXTable::MULTICOLUMN: {
1989 // check wether we are completly in a multicol
1990 int multicol = cursor.par->table->IsMultiColumn(actCell);
1991 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1992 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1993 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
1997 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
1998 LyXParagraph::size_type pos = cursor.pos;
1999 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2001 for (; newlines; --newlines)
2002 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2007 // selection must be in one row (or no selection)
2009 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2016 if (sel_start_cursor.row == sel_end_cursor.row){
2017 LyXParagraph::size_type i;
2019 for (i = sel_start_cursor.pos;
2020 i < sel_end_cursor.pos; ++i){
2021 if (sel_start_cursor.par->IsNewline(i)){
2022 sel_start_cursor.par->Erase(i);
2023 // check for double-blanks
2024 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2026 (i < sel_start_cursor.par->Last()
2027 && !sel_start_cursor.par->IsLineSeparator(i)))
2028 sel_start_cursor.par->InsertChar(i, ' ');
2030 sel_end_cursor.pos--;
2037 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2038 sel_start_cursor.pos),
2040 cursor.pos = sel_start_cursor.pos;
2045 WriteAlert(_("Impossible Operation!"),
2046 _("Multicolumns can only be horizontally."),
2053 case LyXTable::SET_ALL_LINES:
2055 case LyXTable::UNSET_ALL_LINES:
2057 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2061 LyXParagraph::size_type i;
2063 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2064 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2065 cursor.par->table->SetAllLines(n, setLines);
2072 case LyXTable::SET_LONGTABLE:
2073 cursor.par->table->SetLongTable(true);
2075 case LyXTable::UNSET_LONGTABLE:
2076 cursor.par->table->SetLongTable(false);
2078 case LyXTable::SET_ROTATE_TABLE:
2079 cursor.par->table->SetRotateTable(true);
2081 case LyXTable::UNSET_ROTATE_TABLE:
2082 cursor.par->table->SetRotateTable(false);
2084 case LyXTable::SET_ROTATE_CELL:
2086 cursor.par->table->SetRotateCell(actCell, true);
2088 LyXParagraph::size_type i;
2090 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2091 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2092 cursor.par->table->SetRotateCell(n, true);
2098 case LyXTable::UNSET_ROTATE_CELL:
2100 cursor.par->table->SetRotateCell(actCell, false);
2103 LyXParagraph::size_type i = sel_start_cursor.pos;
2104 for (; i <= sel_end_cursor.pos; ++i) {
2105 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2106 cursor.par->table->SetRotateCell(n, false);
2112 case LyXTable::SET_LINEBREAKS:
2113 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2115 cursor.par->table->SetLinebreaks(actCell, what);
2117 LyXParagraph::size_type i;
2119 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2120 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2121 cursor.par->table->SetLinebreaks(n, what);
2127 case LyXTable::SET_LTFIRSTHEAD:
2128 cursor.par->table->SetLTHead(actCell, true);
2130 case LyXTable::SET_LTHEAD:
2131 cursor.par->table->SetLTHead(actCell, false);
2133 case LyXTable::SET_LTFOOT:
2134 cursor.par->table->SetLTFoot(actCell, false);
2136 case LyXTable::SET_LTLASTFOOT:
2137 cursor.par->table->SetLTFoot(actCell, true);
2139 case LyXTable::SET_LTNEWPAGE:
2140 what = !cursor.par->table->LTNewPage(actCell);
2141 cursor.par->table->SetLTNewPage(actCell, what);
2147 void LyXText::InsertCharInTable(char c)
2152 bool jumped_over_space;
2154 /* first check, if there will be two blanks together or a blank at
2155 * the beginning of a paragraph.
2156 * I decided to handle blanks like normal characters, the main
2157 * difference are the special checks when calculating the row.fill
2158 * (blank does not count at the end of a row) and the check here */
2160 LyXFont realtmpfont = real_current_font;
2161 LyXFont rawtmpfont = current_font; /* store the current font.
2162 * This is because of the use
2163 * of cursor movements. The moving
2164 * cursor would refresh the
2167 // Get the font that is used to calculate the baselineskip
2168 LyXParagraph::size_type const lastpos =
2170 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2172 jumped_over_space = false;
2173 if (IsLineSeparatorChar(c)) {
2175 #ifndef FIX_DOUBLE_SPACE
2176 /* avoid double blanks but insert the new blank because
2177 * of a possible font change */
2178 if (cursor.pos < lastpos &&
2179 cursor.par->IsLineSeparator(cursor.pos)) {
2180 cursor.par->Erase(cursor.pos);
2181 jumped_over_space = true;
2184 if ((cursor.pos > 0 &&
2185 cursor.par->IsLineSeparator(cursor.pos - 1))
2186 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2187 || (cursor.pos == 0 &&
2188 !(cursor.par->Previous()
2189 && cursor.par->Previous()->footnoteflag
2190 == LyXParagraph::OPEN_FOOTNOTE)))
2192 } else if (IsNewlineChar(c)) {
2193 if (!IsEmptyTableCell()) {
2194 TableFeatures(LyXTable::APPEND_CONT_ROW);
2201 y = cursor.y - row->baseline;
2202 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2203 * already inserted the character */
2204 cursor.par->InsertChar(cursor.pos, c);
2205 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2207 if (!jumped_over_space) {
2208 /* refresh the positions */
2210 while (tmprow->next && tmprow->next->par == row->par) {
2211 tmprow = tmprow->next;
2218 CheckParagraphInTable(cursor.par, cursor.pos);
2220 current_font = rawtmpfont;
2221 real_current_font = realtmpfont;
2223 /* check, whether the last character's font has changed. */
2224 if (cursor.pos && cursor.pos == cursor.par->Last()
2225 && rawparfont != rawtmpfont)
2226 RedoHeightOfParagraph(cursor);
2230 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2231 LyXParagraph::size_type pos)
2234 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2235 par->GetInset(pos) && par->GetInset(pos)->display()){
2236 par->GetInset(pos)->display(false);
2240 Row * row = GetRow(par, pos, y);
2242 int tmpheight = row->height;
2243 SetHeightOfRow(row);
2245 LyXParagraph::size_type tmp_pos = pos;
2246 /* update the table information */
2247 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2249 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2250 WidthOfCell(par, tmp_pos))) {
2251 LyXCursor tmpcursor = cursor;
2252 SetCursorIntern(par, pos);
2253 /* make a complete redraw */
2254 RedoDrawingOfParagraph(cursor);
2258 /* redraw only the row */
2259 LyXCursor tmpcursor = cursor;
2260 SetCursorIntern(par, pos);
2262 refresh_x = cursor.x;
2264 refresh_pos = cursor.pos;
2267 if (tmpheight == row->height)
2268 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2270 status = LyXText::NEED_MORE_REFRESH;
2272 SetCursorIntern(cursor.par, cursor.pos);
2276 void LyXText::BackspaceInTable()
2278 Row * tmprow, * row;
2281 LyXFont rawtmpfont = current_font;
2282 LyXFont realtmpfont = real_current_font;
2284 // Get the font that is used to calculate the baselineskip
2285 int const lastpos = cursor.par->Last();
2286 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2288 if (cursor.pos == 0) {
2289 /* no pasting of table paragraphs */
2293 /* this is the code for a normal backspace, not pasting
2295 SetUndo(Undo::DELETE,
2296 cursor.par->ParFromPos(cursor.pos)->previous,
2297 cursor.par->ParFromPos(cursor.pos)->next);
2301 /* some insets are undeletable here */
2302 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2303 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2308 y = cursor.y - row->baseline;
2310 /* some special code when deleting a newline. */
2311 if (cursor.par->IsNewline(cursor.pos)) {
2316 cursor.par->Erase(cursor.pos);
2318 /* refresh the positions */
2320 while (tmprow->next && tmprow->next->par == row->par) {
2321 tmprow = tmprow->next;
2325 #ifndef FIX_DOUBLE_SPACE
2326 /* delete superfluous blanks */
2327 if (cursor.pos < cursor.par->Last() - 1 &&
2328 (cursor.par->IsLineSeparator(cursor.pos))) {
2330 if (cursor.pos == BeginningOfMainBody(cursor.par)
2332 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2333 cursor.par->Erase(cursor.pos);
2334 /* refresh the positions */
2336 while (tmprow->next &&
2337 tmprow->next->par == row->par) {
2338 tmprow = tmprow->next;
2341 if (cursor.pos) /* move one character left */
2348 CheckParagraphInTable(cursor.par, cursor.pos);
2350 /* check, wether the last characters font has changed. */
2351 if (cursor.pos && cursor.pos == cursor.par->Last()
2352 && rawparfont != rawtmpfont)
2353 RedoHeightOfParagraph(cursor);
2355 /* restore the current font
2356 * That is what a user expects! */
2357 current_font = rawtmpfont;
2358 real_current_font = realtmpfont;
2360 SetCursorIntern(cursor.par, cursor.pos);
2363 /* table stuff -- end*/
2366 /* just a macro to make some thing easier. */
2367 void LyXText::RedoParagraph() const
2370 // I suspect this version will work
2373 RedoParagraphs(cursor, cursor.par->Next());
2374 SetCursorIntern(cursor.par, cursor.pos);
2376 LyXCursor tmpcursor = cursor;
2378 RedoParagraphs(cursor, cursor.par->Next());
2379 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2384 /* insert a character, moves all the following breaks in the
2385 * same Paragraph one to the right and make a rebreak */
2386 void LyXText::InsertChar(char c)
2388 SetUndo(Undo::INSERT,
2389 cursor.par->ParFromPos(cursor.pos)->previous,
2390 cursor.par->ParFromPos(cursor.pos)->next);
2392 /* When the free-spacing option is set for the current layout,
2393 * all spaces are converted to protected spaces. */
2394 #warning think about this
2396 bool freeSpacingBo =
2397 textclasslist.Style(parameters->textclass,
2398 cursor.row->par->GetLayout()).free_spacing;
2400 if (freeSpacingBo && IsLineSeparatorChar(c)
2401 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1))) {
2402 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2406 /* table stuff -- begin*/
2407 if (cursor.par->table) {
2408 InsertCharInTable(c);
2412 /* table stuff -- end*/
2414 /* First check, if there will be two blanks together or a blank at
2415 the beginning of a paragraph.
2416 I decided to handle blanks like normal characters, the main
2417 difference are the special checks when calculating the row.fill
2418 (blank does not count at the end of a row) and the check here */
2420 // The bug is triggered when we type in a description environment:
2421 // The current_font is not changed when we go from label to main text
2422 // and it should (along with realtmpfont) when we type the space.
2423 #ifdef WITH_WARNINGS
2424 #warning There is a bug here! (Asger)
2427 LyXFont realtmpfont = real_current_font;
2428 LyXFont rawtmpfont = current_font; /* store the current font.
2429 * This is because of the use
2430 * of cursor movements. The moving
2431 * cursor would refresh the
2434 // Get the font that is used to calculate the baselineskip
2435 LyXParagraph::size_type lastpos = cursor.par->Last();
2436 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2438 bool jumped_over_space = false;
2440 if (IsLineSeparatorChar(c)) {
2441 #ifndef FIX_DOUBLE_SPACE
2442 if (cursor.pos < lastpos
2443 && cursor.par->IsLineSeparator(cursor.pos)) {
2444 /* the user inserted a space before a space. So we
2445 * will just make a CursorRight. BUT: The font of this
2446 * space should be set to current font. That is why
2447 * we need to rebreak perhaps. If there is a protected
2448 * blank at the end of a row we have to force
2451 owner_->owner()->getMiniBuffer()
2452 ->Set(_("You cannot type two spaces this way. "
2453 " Please read the Tutorial."));
2455 // How can this ever happen?
2456 if (cursor.pos == RowLast(cursor.row)
2457 && !IsLineSeparatorChar(c))
2458 cursor.row->fill = -1; // force rebreak
2459 cursor.par->Erase(cursor.pos);
2460 jumped_over_space = true;
2462 // Seems to me that this works just as well.
2470 && cursor.par->IsLineSeparator(cursor.pos - 1))
2472 && cursor.par->IsNewline(cursor.pos - 1))
2474 && !(cursor.par->Previous()
2475 && cursor.par->Previous()->footnoteflag
2476 == LyXParagraph::OPEN_FOOTNOTE))) {
2477 if (cursor.pos == 0 )
2478 owner_->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2480 owner_->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2484 } else if (IsNewlineChar(c)) {
2485 if (cursor.par->FirstPhysicalPar() == cursor.par
2486 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2490 /* No newline at first position
2491 * of a paragraph or behind labels.
2492 * TeX does not allow that. */
2494 if (cursor.pos < cursor.par->Last() &&
2495 cursor.par->IsLineSeparator(cursor.pos))
2496 CursorRightIntern(); // newline always after a blank!
2497 cursor.row->fill = -1; // to force a new break
2500 // the display inset stuff
2501 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2502 && cursor.row->par->GetInset(cursor.row->pos)
2503 && cursor.row->par->GetInset(cursor.row->pos)->display())
2504 cursor.row->fill = -1; // to force a new break
2506 // get the cursor row fist
2507 Row * row = cursor.row;
2508 long y = cursor.y - row->baseline;
2509 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2510 * already insertet the character */
2511 cursor.par->InsertChar(cursor.pos, c);
2512 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2514 if (!jumped_over_space) {
2515 // refresh the positions
2517 while (tmprow->next && tmprow->next->par == row->par) {
2518 tmprow = tmprow->next;
2523 // Is there a break one row above
2524 if ((cursor.par->IsLineSeparator(cursor.pos)
2525 || cursor.par->IsNewline(cursor.pos)
2526 || cursor.row->fill == -1)
2527 && row->previous && row->previous->par == row->par) {
2528 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2530 if ( z >= row->pos) {
2533 // set the dimensions of the row above
2534 row->previous->fill = Fill(row->previous, paperwidth);
2536 SetHeightOfRow(row->previous);
2538 y -= row->previous->height;
2540 refresh_row = row->previous;
2541 status = LyXText::NEED_MORE_REFRESH;
2543 BreakAgainOneRow(row);
2545 current_font = rawtmpfont;
2546 real_current_font = realtmpfont;
2547 SetCursor(cursor.par, cursor.pos + 1, false);
2548 /* cursor MUST be in row now */
2550 if (row->next && row->next->par == row->par)
2551 need_break_row = row->next;
2555 // check, wether the last characters font has changed.
2556 if (cursor.pos && cursor.pos == cursor.par->Last()
2557 && rawparfont != rawtmpfont)
2558 RedoHeightOfParagraph(cursor);
2565 /* recalculate the fill of the row */
2566 if (row->fill >= 0) /* needed because a newline
2567 * will set fill to -1. Otherwise
2568 * we would not get a rebreak! */
2569 row->fill = Fill(row, paperwidth);
2570 if (row->fill < 0 ) {
2573 refresh_x = cursor.x;
2574 refresh_pos = cursor.pos;
2575 status = LyXText::NEED_MORE_REFRESH;
2576 BreakAgainOneRow(row);
2577 /* will the cursor be in another row now? */
2578 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2579 if (row->next && row->next->par == row->par)
2583 BreakAgainOneRow(row);
2585 current_font = rawtmpfont;
2586 real_current_font = realtmpfont;
2587 SetCursor(cursor.par, cursor.pos + 1, false);
2588 if (row->next && row->next->par == row->par)
2589 need_break_row = row->next;
2594 refresh_x = cursor.x;
2596 refresh_pos = cursor.pos;
2598 int tmpheight = row->height;
2599 SetHeightOfRow(row);
2600 if (tmpheight == row->height)
2601 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2603 status = LyXText::NEED_MORE_REFRESH;
2605 current_font = rawtmpfont;
2606 real_current_font = realtmpfont;
2607 SetCursor(cursor.par, cursor.pos + 1, false);
2610 /* check, wether the last characters font has changed. */
2611 if (cursor.pos && cursor.pos == cursor.par->Last()
2612 && rawparfont != rawtmpfont) {
2613 RedoHeightOfParagraph(cursor);
2615 /* now the special right address boxes */
2616 if (textclasslist.Style(parameters->textclass,
2617 cursor.par->GetLayout()).margintype
2618 == MARGIN_RIGHT_ADDRESS_BOX) {
2619 RedoDrawingOfParagraph(cursor);
2627 void LyXText::charInserted()
2629 // Here we could call FinishUndo for every 20 characters inserted.
2630 // This is from my experience how emacs does it.
2631 static unsigned int counter = 0;
2640 void LyXText::PrepareToPrint(Row * row, float & x,
2641 float & fill_separator,
2643 float & fill_label_hfill,
2648 float w = row->fill;
2650 fill_label_hfill = 0;
2652 fill_label_hfill = 0;
2654 LyXDirection direction = row->par->getParDirection();
2656 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2657 x = RightMargin(row);
2658 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2659 LyXFont font(LyXFont::ALL_SANE);
2660 font.setSize(LyXFont::SIZE_SMALL);
2661 x += font.textWidth("Mwide-figM", 10);
2665 x = LeftMargin(row);
2667 /* is there a manual margin with a manual label */
2668 if (textclasslist.Style(parameters->textclass,
2669 row->par->GetLayout()).margintype == MARGIN_MANUAL
2670 && textclasslist.Style(parameters->textclass,
2671 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2673 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2674 * are left aligned*/
2675 if (nlh && !row->par->GetLabelWidthString().empty()) {
2676 fill_label_hfill = LabelFill(row) / nlh;
2680 /* are there any hfills in the row? */
2681 nh = NumberOfHfills(row);
2683 /* table stuff -- begin*/
2684 if (row->par->table) {
2685 w = paperwidth - row->par->table->WidthOfTable()
2686 - x - RightMargin(row);
2687 nh = 0; /* ignore hfills in tables */
2689 /* table stuff -- end*/
2694 /* is it block, flushleft or flushright?
2695 * set x how you need it */
2697 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2698 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2700 align = row->par->FirstPhysicalPar()->align;
2702 /* center displayed insets */
2703 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2704 && row->par->GetInset(row->pos)
2705 && row->par->GetInset(row->pos)->display())
2706 align = LYX_ALIGN_CENTER;
2709 case LYX_ALIGN_BLOCK:
2710 ns = NumberOfSeparators(row);
2711 if (ns && row->next && row->next->par == row->par &&
2712 !(row->next->par->IsNewline(row->next->pos-1))
2713 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2714 && row->next->par->GetInset(row->next->pos)
2715 && row->next->par->GetInset(row->next->pos)->display())
2717 fill_separator = w / ns;
2718 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2721 case LYX_ALIGN_RIGHT:
2724 case LYX_ALIGN_CENTER:
2732 ComputeBidiTables(row);
2733 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2734 LyXParagraph::size_type main_body =
2735 BeginningOfMainBody(row->par);
2736 LyXParagraph::size_type last = RowLast(row);
2738 if (row->pos <= last
2740 && last != vis2log(last)
2741 && row->par->IsLineSeparator(last)) {
2742 if (!(main_body > 0 && main_body-1 == last))
2743 x -= fill_separator+SingleWidth(row->par,last);
2744 } else if (main_body > 0 &&
2745 (main_body-1 > last ||
2746 !row->par->IsLineSeparator(main_body-1))) {
2747 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2748 row->par->GetLayout());
2749 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2750 if (main_body-1 <= last)
2751 x += fill_label_hfill;
2756 /* important for the screen */
2759 /* the cursor set functions have a special mechanism. When they
2760 * realize, that you left an empty paragraph, they will delete it.
2761 * They also delete the corresponding row */
2763 void LyXText::CursorRightOneWord() const
2765 // treat floats, HFills and Insets as words
2766 LyXCursor tmpcursor = cursor;
2768 if (tmpcursor.pos == tmpcursor.par->Last()
2769 && tmpcursor.par->Next())
2771 tmpcursor.par = tmpcursor.par->Next();
2776 // Skip through initial nonword stuff.
2777 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2778 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2780 // printf("Current pos1 %d", tmpcursor.pos) ;
2784 // Advance through word.
2785 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2786 tmpcursor.par->IsWord( tmpcursor.pos ) )
2788 // printf("Current pos2 %d", tmpcursor.pos) ;
2793 SetCursor(tmpcursor.par, tmpcursor.pos);
2797 void LyXText::CursorTab() const
2799 if (cursor.par->table) {
2800 int cell = NumberOfCell(cursor.par, cursor.pos);
2801 while(cursor.par->table->IsContRow(cell)) {
2803 cell = NumberOfCell(cursor.par, cursor.pos);
2805 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2806 TableFeatures(LyXTable::APPEND_ROW);
2808 LyXCursor tmpcursor = cursor;
2809 while (tmpcursor.pos < tmpcursor.par->Last()
2810 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2813 if (tmpcursor.pos == tmpcursor.par->Last()){
2814 if (tmpcursor.par->Next()) {
2815 tmpcursor.par = tmpcursor.par->Next();
2821 SetCursor(tmpcursor.par, tmpcursor.pos);
2822 if (cursor.par->table) {
2823 int cell = NumberOfCell(cursor.par, cursor.pos);
2824 while (cursor.par->table->IsContRow(cell) &&
2825 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2827 while (tmpcursor.pos < tmpcursor.par->Last()
2828 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2831 if (tmpcursor.pos == tmpcursor.par->Last()){
2832 if (tmpcursor.par->Next()) {
2833 tmpcursor.par = tmpcursor.par->Next();
2839 SetCursor(tmpcursor.par, tmpcursor.pos);
2840 cell = NumberOfCell(cursor.par, cursor.pos);
2846 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2847 of prior word, not to end of next prior word. */
2849 void LyXText::CursorLeftOneWord() const
2851 // treat HFills, floats and Insets as words
2852 LyXCursor tmpcursor = cursor;
2853 while (tmpcursor.pos
2854 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2855 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2856 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2857 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2858 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2862 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2863 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2864 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2866 } else if (!tmpcursor.pos) {
2867 if (tmpcursor.par->Previous()){
2868 tmpcursor.par = tmpcursor.par->Previous();
2869 tmpcursor.pos = tmpcursor.par->Last();
2871 } else { // Here, tmpcursor != 0
2872 while (tmpcursor.pos > 0 &&
2873 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2876 SetCursor(tmpcursor.par, tmpcursor.pos);
2879 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2882 void LyXText::SelectWord()
2884 /* Move cursor to the beginning, when not already there. */
2886 && !cursor.par->IsSeparator(cursor.pos-1)
2887 && !cursor.par->IsKomma(cursor.pos-1) )
2888 CursorLeftOneWord();
2890 /* set the sel cursor */
2891 sel_cursor = cursor;
2893 while ( cursor.pos < cursor.par->Last()
2894 && !cursor.par->IsSeparator(cursor.pos)
2895 && !cursor.par->IsKomma(cursor.pos) )
2897 SetCursor( cursor.par, cursor.pos );
2899 /* finally set the selection */
2904 /* -------> Select the word currently under the cursor when:
2905 1: no selection is currently set,
2906 2: the cursor is not at the borders of the word. */
2908 int LyXText::SelectWordWhenUnderCursor()
2910 if ( selection ) return 0;
2911 if ( cursor.pos < cursor.par->Last()
2912 && !cursor.par->IsSeparator(cursor.pos)
2913 && !cursor.par->IsKomma(cursor.pos)
2915 && !cursor.par->IsSeparator(cursor.pos -1)
2916 && !cursor.par->IsKomma(cursor.pos -1) ) {
2924 // This function is only used by the spellchecker for NextWord().
2925 // It doesn't handle LYX_ACCENTs and probably never will.
2926 char * LyXText::SelectNextWord(float & value)
2928 LyXParagraph * tmppar = cursor.par;
2930 // If this is not the very first word, skip rest of
2931 // current word because we are probably in the middle
2932 // of a word if there is text here.
2933 if (cursor.pos || cursor.par->previous) {
2934 while (cursor.pos < cursor.par->Last()
2935 && cursor.par->IsLetter(cursor.pos))
2938 // Now, skip until we have real text (will jump paragraphs)
2939 while ((cursor.par->Last() > cursor.pos
2940 && (!cursor.par->IsLetter(cursor.pos)
2941 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2942 || (cursor.par->Last() == cursor.pos
2943 && cursor.par->Next())){
2944 if (cursor.pos == cursor.par->Last()) {
2945 cursor.par = cursor.par->Next();
2952 // Update the value if we changed paragraphs
2953 if (cursor.par != tmppar){
2954 SetCursor(cursor.par, cursor.pos);
2955 value = float(cursor.y)/float(height);
2958 /* Start the selection from here */
2959 sel_cursor = cursor;
2961 #ifdef USE_OSTREAM_ONLY
2963 ostringstream latex;
2970 /* and find the end of the word
2971 (optional hyphens are part of a word) */
2972 while (cursor.pos < cursor.par->Last()
2973 && (cursor.par->IsLetter(cursor.pos))
2974 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
2975 && cursor.par->GetInset(cursor.pos) != 0
2976 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0
2977 #ifdef USE_OSTREAM_ONLY
2979 && latex.str() == "\\-"
2981 && string(latex.str(), 3) == "\\-" // this is not nice at all
2989 #ifdef USE_OSTREAM_ONLY
2990 #ifndef HAVE_SSTREAM
2991 delete [] latex.str();
2994 // Finally, we copy the word to a string and return it
2997 if (sel_cursor.pos < cursor.pos) {
2998 str = new char [cursor.pos - sel_cursor.pos + 2];
2999 LyXParagraph::size_type i, j;
3000 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3001 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3002 str[j++] = cursor.par->GetChar(i);
3010 // This one is also only for the spellchecker
3011 void LyXText::SelectSelectedWord()
3013 /* move cursor to the beginning */
3014 SetCursor(sel_cursor.par, sel_cursor.pos);
3016 /* set the sel cursor */
3017 sel_cursor = cursor;
3019 #ifdef USE_OSTREAM_ONLY
3021 ostringstream latex;
3029 /* now find the end of the word */
3030 while (cursor.pos < cursor.par->Last()
3031 && (cursor.par->IsLetter(cursor.pos)
3032 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
3033 && cursor.par->GetInset(cursor.pos) != 0
3034 && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0
3035 #ifdef USE_OSTREAM_ONLY
3037 && latex.str() == "\\-"
3039 && string(latex.str(), 3) == "\\-"
3047 #ifdef USE_OSTREAM_ONLY
3048 #ifndef HAVE_SSTREAM
3049 delete [] latex.str();
3052 SetCursor(cursor.par, cursor.pos);
3054 /* finally set the selection */
3059 /* -------> Delete from cursor up to the end of the current or next word. */
3060 void LyXText::DeleteWordForward()
3062 LyXCursor tmpcursor = cursor;
3064 if (!cursor.par->Last())
3067 /* -------> Skip initial non-word stuff. */
3068 while ( cursor.pos < cursor.par->Last()
3069 && (cursor.par->IsSeparator(cursor.pos)
3070 || cursor.par->IsKomma(cursor.pos)) )
3073 SetCursorIntern(cursor.par, cursor.pos);
3074 selection = True; // to avoid deletion
3075 CursorRightOneWord();
3076 sel_cursor = cursor;
3080 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3086 /* -------> Delete from cursor to start of current or prior word. */
3087 void LyXText::DeleteWordBackward()
3089 LyXCursor tmpcursor = cursor;
3090 if (!cursor.par->Last())
3093 selection = true; // to avoid deletion
3094 CursorLeftOneWord();
3095 sel_cursor = cursor;
3103 /* -------> Kill to end of line. */
3104 void LyXText::DeleteLineForward()
3106 LyXCursor tmpcursor = cursor;
3107 if (!cursor.par->Last())
3111 sel_cursor = cursor;
3114 if (selection == false) {
3115 DeleteWordForward();
3123 // Change the case of a word at cursor position. The meaning of action
3125 // 0 change to lowercase
3126 // 1 capitalize word
3127 // 2 change to uppercase
3128 // This function directly manipulates LyXParagraph::text because there
3129 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3130 // that it is correct. I guess part of it should be moved to
3131 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3132 // it does not access outside of the allocated array as the older
3133 // version did. (JMarc)
3134 void LyXText::ChangeWordCase(LyXText::TextCase action)
3136 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3138 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3140 LyXParagraph::size_type tmppos =
3141 cursor.par->PositionInParFromPos(cursor.pos);
3142 while (tmppos < tmppar->size()) {
3143 unsigned char c = tmppar->text[tmppos];
3144 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3146 if (c != LyXParagraph::META_INSET) {
3148 case text_lowercase:
3151 case text_capitalization:
3153 action = text_lowercase;
3155 case text_uppercase:
3161 tmppar->text[tmppos] = c;
3164 CheckParagraph(tmppar, tmppos);
3165 CursorRightOneWord();
3169 void LyXText::Delete()
3171 // this is a very easy implementation
3173 LyXCursor old_cursor = cursor;
3174 int old_cur_par_id = old_cursor.par->id();
3175 int old_cur_par_prev_id = old_cursor.par->previous ?
3176 old_cursor.par->previous->id() : 0;
3178 // just move to the right
3179 CursorRightIntern();
3181 // This check is not very good...
3182 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3183 // and that can very well delete the par or par->previous in
3184 // old_cursor. Will a solution where we compare paragraph id's
3187 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3188 == old_cur_par_prev_id
3189 && cursor.par->id() != old_cur_par_id)
3190 return; // delete-empty-paragraph-mechanism has done it
3192 if (cursor.par->previous == old_cursor.par->previous
3193 && cursor.par != old_cursor.par)
3194 return; // delete-empty-paragraph-mechanism has done it
3196 // if you had success make a backspace
3197 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3198 LyXCursor tmpcursor = cursor;
3199 cursor = old_cursor; // to make sure undo gets the right cursor position
3200 SetUndo(Undo::DELETE,
3201 cursor.par->ParFromPos(cursor.pos)->previous,
3202 cursor.par->ParFromPos(cursor.pos)->next);
3209 void LyXText::Backspace()
3211 LyXParagraph * tmppar;
3212 Row * tmprow, * row;
3216 /* table stuff -- begin */
3217 if (cursor.par->table) {
3221 /* table stuff -- end */
3223 LyXFont rawtmpfont = current_font;
3224 LyXFont realtmpfont = real_current_font;
3226 // Get the font that is used to calculate the baselineskip
3227 int const lastpos = cursor.par->Last();
3228 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3230 if (cursor.pos == 0) {
3231 // we may paste some paragraphs
3233 // is it an empty paragraph?
3236 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3237 && !(cursor.par->Next()
3238 && cursor.par->footnoteflag ==
3239 LyXParagraph::NO_FOOTNOTE
3240 && cursor.par->Next()->footnoteflag ==
3241 LyXParagraph::OPEN_FOOTNOTE)) {
3243 if (cursor.par->previous) {
3244 tmppar = cursor.par->previous->FirstPhysicalPar();
3245 if (cursor.par->GetLayout() == tmppar->GetLayout()
3246 && cursor.par->footnoteflag == tmppar->footnoteflag
3247 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3249 tmppar->line_bottom = cursor.par->line_bottom;
3250 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3251 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3256 // the layout things can change the height of a row !
3257 tmpheight = cursor.row->height;
3258 SetHeightOfRow(cursor.row);
3259 if (cursor.row->height != tmpheight) {
3260 refresh_y = cursor.y - cursor.row->baseline;
3261 refresh_row = cursor.row;
3262 status = LyXText::NEED_MORE_REFRESH;
3267 if (cursor.par->ParFromPos(cursor.pos)->previous){
3268 SetUndo(Undo::DELETE,
3269 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3270 cursor.par->ParFromPos(cursor.pos)->next);
3272 tmppar = cursor.par;
3273 tmprow = cursor.row;
3275 /* Pasting is not allowed, if the paragraphs have different
3276 layout. I think it is a real bug of all other
3277 word processors to allow it. It confuses the user.
3278 Even so with a footnote paragraph and a non-footnote
3279 paragraph. I will not allow pasting in this case,
3280 because the user would be confused if the footnote behaves
3281 different wether it is open or closed.
3283 Correction: Pasting is always allowed with standard-layout
3285 if (cursor.par != tmppar
3286 && (cursor.par->GetLayout() == tmppar->GetLayout()
3287 || !tmppar->GetLayout())
3288 && cursor.par->footnoteflag == tmppar->footnoteflag
3289 /* table stuff -- begin*/
3290 && !cursor.par->table /* no pasting of tables */
3291 /* table stuff -- end*/
3292 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3294 cursor.par->PasteParagraph();
3297 cursor.par->IsSeparator(cursor.pos - 1)))
3298 cursor.par->InsertChar(cursor.pos, ' ');
3303 status = LyXText::NEED_MORE_REFRESH;
3304 refresh_row = cursor.row;
3305 refresh_y = cursor.y - cursor.row->baseline;
3307 // remove the lost paragraph
3308 RemoveParagraph(tmprow);
3311 AppendParagraph(cursor.row);
3312 UpdateCounters(cursor.row);
3314 // the row may have changed, block, hfills etc.
3315 SetCursor(cursor.par, cursor.pos);
3318 /* this is the code for a normal backspace, not pasting
3320 SetUndo(Undo::DELETE,
3321 cursor.par->ParFromPos(cursor.pos)->previous,
3322 cursor.par->ParFromPos(cursor.pos)->next);
3325 // some insets are undeletable here
3326 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3327 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3329 // force complete redo when erasing display insets
3330 // this is a cruel mathod but save..... Matthias
3331 if (cursor.par->GetInset(cursor.pos)->display()){
3332 cursor.par->Erase(cursor.pos);
3339 y = cursor.y - row->baseline;
3340 LyXParagraph::size_type z;
3341 /* remember that a space at the end of a row doesnt count
3342 * when calculating the fill */
3343 if (cursor.pos < RowLast(row) ||
3344 !cursor.par->IsLineSeparator(cursor.pos)) {
3345 row->fill += SingleWidth(cursor.par, cursor.pos);
3348 /* some special code when deleting a newline. This is similar
3349 * to the behavior when pasting paragraphs */
3350 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3351 cursor.par->Erase(cursor.pos);
3352 // refresh the positions
3354 while (tmprow->next && tmprow->next->par == row->par) {
3355 tmprow = tmprow->next;
3358 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3361 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3362 cursor.par->InsertChar(cursor.pos, ' ');
3363 // refresh the positions
3365 while (tmprow->next && tmprow->next->par == row->par) {
3366 tmprow = tmprow->next;
3371 cursor.par->Erase(cursor.pos);
3373 // refresh the positions
3375 while (tmprow->next && tmprow->next->par == row->par) {
3376 tmprow = tmprow->next;
3380 #ifndef FIX_DOUBLE_SPACE
3381 // delete superfluous blanks
3382 if (cursor.pos < cursor.par->Last() - 1 &&
3383 (cursor.par->IsLineSeparator(cursor.pos))) {
3385 if (cursor.pos == BeginningOfMainBody(cursor.par)
3387 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3388 cursor.par->Erase(cursor.pos);
3389 // refresh the positions
3391 while (tmprow->next &&
3392 tmprow->next->par == row->par) {
3393 tmprow = tmprow->next;
3396 if (cursor.pos) // move one character left
3402 // delete newlines at the beginning of paragraphs
3403 while (cursor.par->Last() &&
3404 cursor.par->IsNewline(cursor.pos) &&
3405 cursor.pos == BeginningOfMainBody(cursor.par)) {
3406 cursor.par->Erase(cursor.pos);
3407 // refresh the positions
3409 while (tmprow->next &&
3410 tmprow->next->par == row->par) {
3411 tmprow = tmprow->next;
3417 // is there a break one row above
3418 if (row->previous && row->previous->par == row->par) {
3419 z = NextBreakPoint(row->previous, paperwidth);
3420 if ( z >= row->pos) {
3423 tmprow = row->previous;
3425 // maybe the current row is now empty
3426 if (row->pos >= row->par->Last()) {
3431 BreakAgainOneRow(row);
3432 if (row->next && row->next->par == row->par)
3433 need_break_row = row->next;
3438 // set the dimensions of the row above
3439 y -= tmprow->height;
3440 tmprow->fill = Fill(tmprow, paperwidth);
3441 SetHeightOfRow(tmprow);
3444 refresh_row = tmprow;
3445 status = LyXText::NEED_MORE_REFRESH;
3446 current_font = rawtmpfont;
3447 real_current_font = realtmpfont;
3448 SetCursor(cursor.par, cursor.pos, false);
3449 // check, whether the last character's font has changed.
3450 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3451 if (rawparfont != rawtmpfont)
3452 RedoHeightOfParagraph(cursor);
3457 // break the cursor row again
3458 z = NextBreakPoint(row, paperwidth);
3460 if (z != RowLast(row) ||
3461 (row->next && row->next->par == row->par &&
3462 RowLast(row) == row->par->Last() - 1)){
3464 /* it can happen that a paragraph loses one row
3465 * without a real breakup. This is when a word
3466 * is to long to be broken. Well, I don t care this
3468 if (row->next && row->next->par == row->par &&
3469 RowLast(row) == row->par->Last() - 1)
3470 RemoveRow(row->next);
3474 status = LyXText::NEED_MORE_REFRESH;
3476 BreakAgainOneRow(row);
3477 current_font = rawtmpfont;
3478 real_current_font = realtmpfont;
3479 SetCursor(cursor.par, cursor.pos, false);
3480 // cursor MUST be in row now
3482 if (row->next && row->next->par == row->par)
3483 need_break_row = row->next;
3487 // set the dimensions of the row
3488 row->fill = Fill(row, paperwidth);
3489 int tmpheight = row->height;
3490 SetHeightOfRow(row);
3491 if (tmpheight == row->height)
3492 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3494 status = LyXText::NEED_MORE_REFRESH;
3497 current_font = rawtmpfont;
3498 real_current_font = realtmpfont;
3499 SetCursor(cursor.par, cursor.pos, false);
3503 // restore the current font
3504 // That is what a user expects!
3505 current_font = rawtmpfont;
3506 real_current_font = realtmpfont;
3508 // check, wether the last characters font has changed.
3509 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3510 if (rawparfont != rawtmpfont) {
3511 RedoHeightOfParagraph(cursor);
3513 // now the special right address boxes
3514 if (textclasslist.Style(parameters->textclass,
3515 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3516 RedoDrawingOfParagraph(cursor);
3522 void LyXText::GetVisibleRow(int offset,
3523 Row * row_ptr, long y)
3525 /* returns a printed row */
3526 Painter & pain = owner_->painter();
3528 LyXDirection direction = row_ptr->par->getParDirection();
3529 LyXParagraph::size_type vpos, pos, pos_end;
3531 int y_top, y_bottom;
3532 float fill_separator, fill_hfill, fill_label_hfill;
3533 LyXParagraph * par, * firstpar;
3536 if (row_ptr->height <= 0) {
3537 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3540 PrepareToPrint(row_ptr, x, fill_separator,
3541 fill_hfill, fill_label_hfill);
3543 /* initialize the pixmap */
3545 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3548 /* selection code */
3549 if (sel_start_cursor.row == row_ptr &&
3550 sel_end_cursor.row == row_ptr) {
3551 if (sel_start_cursor.x < sel_end_cursor.x)
3552 pain.fillRectangle(sel_start_cursor.x, offset,
3553 sel_end_cursor.x - sel_start_cursor.x,
3557 pain.fillRectangle(sel_end_cursor.x, offset,
3558 sel_start_cursor.x - sel_end_cursor.x,
3561 } else if (sel_start_cursor.row == row_ptr) {
3562 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3563 pain.fillRectangle(sel_start_cursor.x, offset,
3564 paperwidth - sel_start_cursor.x,
3568 pain.fillRectangle(0, offset,
3572 } else if (sel_end_cursor.row == row_ptr) {
3573 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3574 pain.fillRectangle(0, offset,
3579 pain.fillRectangle(sel_end_cursor.x, offset,
3580 paperwidth - sel_end_cursor.x,
3584 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3585 pain.fillRectangle(0, offset,
3586 paperwidth, row_ptr->height,
3591 if (row_ptr->par->appendix){
3592 pain.line(1, offset,
3593 1, offset + row_ptr->height,
3594 LColor::appendixline);
3595 pain.line(paperwidth - 2, offset,
3596 paperwidth - 2, offset + row_ptr->height,
3597 LColor::appendixline);
3600 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3601 /* draw a marker at the left margin! */
3602 LyXFont font = GetFont(row_ptr->par, 0);
3603 int asc = font.maxAscent();
3604 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3605 int y1 = (offset + row_ptr->baseline);
3606 int y2 = (offset + row_ptr->baseline) - asc;
3607 pain.line(x, y1, x, y2, LColor::minipageline);
3609 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3610 LyXFont font(LyXFont::ALL_SANE);
3611 font.setSize(LyXFont::SIZE_FOOTNOTE);
3612 font.setColor(LColor::footnote);
3614 int box_x = LYX_PAPER_MARGIN;
3615 box_x += font.textWidth(" wide-tab ", 10);
3616 if (row_ptr->previous &&
3617 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3619 switch (row_ptr->par->footnotekind) {
3620 case LyXParagraph::MARGIN:
3623 case LyXParagraph::FIG:
3626 case LyXParagraph::TAB:
3629 case LyXParagraph::WIDE_FIG:
3632 case LyXParagraph::WIDE_TAB:
3635 case LyXParagraph::ALGORITHM:
3638 case LyXParagraph::FOOTNOTE:
3643 pain.fillRectangle(LYX_PAPER_MARGIN,
3645 box_x - LYX_PAPER_MARGIN,
3646 int(font.maxAscent()
3647 + font.maxDescent()),
3648 LColor::footnotebg);
3650 pain.line(LYX_PAPER_MARGIN, offset,
3651 paperwidth - LYX_PAPER_MARGIN, offset,
3652 LColor::footnoteframe);
3654 pain.text(LYX_PAPER_MARGIN,
3655 offset + int(font.maxAscent()) + 1,
3658 pain.line(LYX_PAPER_MARGIN, offset,
3660 offset + int(font.maxAscent()
3661 + font.maxDescent()),
3662 LColor::footnoteframe);
3664 pain.line(LYX_PAPER_MARGIN,
3665 offset + int(font.maxAscent()
3666 + font.maxDescent()) + 1,
3668 offset + int(font.maxAscent()
3669 + font.maxDescent()) + 1,
3670 LColor::footnoteframe);
3674 /* draw the open floats in a red box */
3675 pain.line(box_x, offset,
3676 box_x, offset + row_ptr->height,
3677 LColor::footnoteframe);
3679 pain.line(paperwidth - LYX_PAPER_MARGIN,
3681 paperwidth - LYX_PAPER_MARGIN,
3682 offset + row_ptr->height,
3683 LColor::footnoteframe);
3684 } else if (row_ptr->previous &&
3685 row_ptr->previous->par->footnoteflag
3686 == LyXParagraph::OPEN_FOOTNOTE) {
3687 LyXFont font(LyXFont::ALL_SANE);
3688 font.setSize(LyXFont::SIZE_FOOTNOTE);
3690 int box_x = LYX_PAPER_MARGIN;
3691 box_x += font.textWidth(" wide-tab ", 10);
3693 pain.line(box_x, offset,
3694 paperwidth - LYX_PAPER_MARGIN,
3695 offset, LColor::footnote);
3698 LyXLayout const & layout =
3699 textclasslist.Style(parameters->textclass,
3700 row_ptr->par->GetLayout());
3701 firstpar = row_ptr->par->FirstPhysicalPar();
3704 y_bottom = row_ptr->height;
3706 /* is it a first row? */
3707 if (row_ptr->pos == 0
3708 && row_ptr->par == firstpar) {
3710 /* start of appendix? */
3711 if (row_ptr->par->start_of_appendix){
3712 pain.line(1, offset,
3713 paperwidth - 2, offset,
3714 LColor::appendixline);
3717 /* think about the margins */
3718 if (!row_ptr->previous)
3719 y_top += LYX_PAPER_MARGIN;
3721 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3722 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3724 offset + y_top + 2 * DefaultHeight(),
3725 LColor::pagebreak, Painter::line_onoffdash);
3726 y_top += 3 * DefaultHeight();
3729 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3730 /* draw a vfill top */
3731 pain.line(0, offset + 2 + y_top,
3732 LYX_PAPER_MARGIN, offset + 2 + y_top,
3735 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3737 offset + y_top + 3 * DefaultHeight(),
3740 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3741 LYX_PAPER_MARGIN / 2,
3742 offset + y_top + 3 * DefaultHeight(),
3745 y_top += 3 * DefaultHeight();
3748 /* think about user added space */
3749 y_top += int(row_ptr->par->added_space_top.inPixels(owner_));
3751 /* think about the parskip */
3752 /* some parskips VERY EASY IMPLEMENTATION */
3753 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3754 if (layout.latextype == LATEX_PARAGRAPH
3755 && firstpar->GetDepth() == 0
3756 && firstpar->Previous())
3757 y_top += parameters->getDefSkip().inPixels(owner_);
3758 else if (firstpar->Previous()
3759 && textclasslist.Style(parameters->textclass,
3760 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3761 && firstpar->Previous()->GetDepth() == 0)
3762 // is it right to use defskip here, too? (AS)
3763 y_top += parameters->getDefSkip().inPixels(owner_);
3766 if (row_ptr->par->line_top) { /* draw a top line */
3767 y_top += GetFont(row_ptr->par, 0).ascent('x');
3769 pain.line(0, offset + y_top,
3770 paperwidth, offset + y_top,
3772 Painter::line_solid,
3773 Painter::line_thick);
3775 y_top += GetFont(row_ptr->par, 0).ascent('x');
3778 /* should we print a label? */
3779 if (layout.labeltype >= LABEL_STATIC
3780 && (layout.labeltype != LABEL_STATIC
3781 || layout.latextype != LATEX_ENVIRONMENT
3782 || row_ptr->par->IsFirstInSequence())) {
3783 font = GetFont(row_ptr->par, -2);
3784 if (!row_ptr->par->GetLabestring().empty()) {
3786 string tmpstring = row_ptr->par->GetLabestring();
3788 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3789 if (parameters->secnumdepth >= 0){
3790 /* this is special code for the chapter layout. This is printed in
3791 * an extra row and has a pagebreak at the top. */
3792 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3793 + int(layout.parsep) * DefaultHeight();
3794 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3795 tmpx = paperwidth - LeftMargin(row_ptr) -
3796 font.stringWidth(tmpstring);
3797 pain.text(int(tmpx),
3798 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3802 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3803 tmpx = x - font.stringWidth(layout.labelsep)
3804 - font.stringWidth(tmpstring);
3806 tmpx = paperwidth - LeftMargin(row_ptr)
3807 + font.stringWidth(layout.labelsep);
3808 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3809 LyXFont font(LyXFont::ALL_SANE);
3810 font.setSize(LyXFont::SIZE_SMALL);
3811 tmpx += font.textWidth("Mwide-figM", 10);
3815 pain.text(int(tmpx),
3816 offset + row_ptr->baseline,
3820 /* the labels at the top of an environment. More or less for bibliography */
3821 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3822 layout.labeltype == LABEL_BIBLIO ||
3823 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3824 if (row_ptr->par->IsFirstInSequence()) {
3825 font = GetFont(row_ptr->par, -2);
3826 if (!row_ptr->par->GetLabestring().empty()) {
3827 string tmpstring = row_ptr->par->GetLabestring();
3829 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3830 + (layout.labelbottomsep * DefaultHeight()));
3833 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3834 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3835 ? x : LeftMargin(row_ptr) )
3836 + paperwidth - RightMargin(row_ptr) ) / 2;
3837 tmpx -= (font.stringWidth(tmpstring)/2);
3838 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3839 tmpx = paperwidth - LeftMargin(row_ptr) -
3840 font.stringWidth(tmpstring);
3841 pain.text(int(tmpx),
3842 offset + row_ptr->baseline
3843 - row_ptr->ascent_of_text
3849 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3850 font = GetFont(row_ptr->par, -1);
3851 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3852 tmpx = x - font.stringWidth(layout.labelsep)
3853 - row_ptr->par->bibkey->width(owner_->painter(), font);
3855 tmpx = paperwidth - LeftMargin(row_ptr)
3856 + font.stringWidth(layout.labelsep);
3857 row_ptr->par->bibkey->draw(owner_->painter(),
3859 offset + row_ptr->baseline,
3864 /* is it a last row? */
3865 par = row_ptr->par->LastPhysicalPar();
3866 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3867 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3869 /* think about the margins */
3871 y_bottom -= LYX_PAPER_MARGIN;
3873 /* draw a bottom pagebreak */
3874 if (firstpar->pagebreak_bottom) {
3875 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3877 offset + y_bottom - 2 * DefaultHeight(),
3878 LColor::pagebreak, Painter::line_onoffdash);
3879 y_bottom -= 3 * DefaultHeight();
3882 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3883 /* draw a vfill bottom */
3884 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3886 offset + y_bottom - 3 * DefaultHeight(),
3888 pain.line(0, offset + y_bottom - 2,
3890 offset + y_bottom - 2,
3892 pain.line(LYX_PAPER_MARGIN / 2,
3893 offset + y_bottom - 3 * DefaultHeight(),
3894 LYX_PAPER_MARGIN / 2,
3895 offset + y_bottom - 2,
3897 y_bottom -= 3* DefaultHeight();
3900 /* think about user added space */
3901 y_bottom -= int(firstpar->added_space_bottom.inPixels(owner_));
3903 if (firstpar->line_bottom) {
3904 /* draw a bottom line */
3905 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3906 pain.line(0, offset + y_bottom,
3907 paperwidth, offset + y_bottom,
3908 LColor::topline, Painter::line_solid,
3909 Painter::line_thick);
3910 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3914 /* draw the text in the pixmap */
3915 pos_end = RowLast(row_ptr);
3917 vpos = row_ptr->pos;
3918 /* table stuff -- begin*/
3919 if (row_ptr->par->table) {
3921 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3923 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3925 while (vpos <= pos_end) {
3926 pos = vis2log(vpos);
3927 if (row_ptr->par->IsNewline(pos)) {
3929 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3930 /* draw the table lines, still very simple */
3931 on_off = !row_ptr->par->table->TopLine(cell);
3933 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3934 !row_ptr->par->table->IsContRow(cell))
3935 pain.line(int(x_old),
3936 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3938 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3940 on_off ? Painter::line_onoffdash : Painter::line_solid);
3942 on_off = !row_ptr->par->table->BottomLine(cell);
3943 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3944 row_ptr->par->table->VeryLastRow(cell))
3946 pain.line(int(x_old),
3947 offset + y_bottom - 1,
3949 offset + y_bottom - 1,
3951 on_off ? Painter::line_onoffdash : Painter::line_solid);
3953 on_off = !row_ptr->par->table->LeftLine(cell);
3955 pain.line(int(x_old),
3956 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3958 offset + y_bottom - 1,
3960 on_off ? Painter::line_onoffdash : Painter::line_solid);
3962 on_off = !row_ptr->par->table->RightLine(cell);
3964 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3965 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3966 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3967 offset + y_bottom - 1,
3969 on_off ? Painter::line_onoffdash : Painter::line_solid);
3972 /* take care about the alignment and other spaces */
3974 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3975 if (row_ptr->par->table->IsFirstCell(cell))
3976 --cell; // little hack, sorry
3978 } else if (row_ptr->par->IsHfill(pos)) {
3982 offset + row_ptr->baseline - DefaultHeight() / 2,
3984 offset + row_ptr->baseline,
3989 } else if (row_ptr->par->IsSeparator(pos)) {
3991 x+= SingleWidth(row_ptr->par, pos);
3992 #warning Think about this.
3994 /* -------> Only draw protected spaces when
3995 * not in free-spacing mode. */
3996 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3997 pain.line(int(tmpx),
3998 offset + row_ptr->baseline - 3,
4000 offset + row_ptr->baseline - 1,
4003 pain.line(int(tmpx),
4004 offset + row_ptr->baseline - 1,
4006 offset + row_ptr->baseline - 1,
4009 pain.line(int(x - 2),
4010 offset + row_ptr->baseline - 3,
4012 offset + row_ptr->baseline - 1,
4015 /* what about underbars? */
4016 font = GetFont(row_ptr->par, pos);
4017 if (font.underbar() == LyXFont::ON
4018 && font.latex() != LyXFont::ON) {
4019 pain.line(int(tmpx),
4020 offset + row_ptr->baseline + 2,
4022 offset + row_ptr->baseline + 2);
4028 draw(row_ptr, vpos, offset, x);
4031 /* do not forget the very last cell. This has no NEWLINE so
4032 * ignored by the code above*/
4033 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4034 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4035 on_off = !row_ptr->par->table->TopLine(cell);
4037 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4038 !row_ptr->par->table->IsContRow(cell))
4040 pain.line(int(x_old),
4041 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4043 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4045 on_off ? Painter::line_onoffdash : Painter::line_solid);
4046 on_off = !row_ptr->par->table->BottomLine(cell);
4047 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4048 row_ptr->par->table->VeryLastRow(cell))
4050 pain.line(int(x_old),
4051 offset + y_bottom - 1,
4053 offset + y_bottom - 1,
4055 on_off ? Painter::line_onoffdash : Painter::line_solid);
4057 on_off = !row_ptr->par->table->LeftLine(cell);
4059 pain.line(int(x_old),
4060 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4062 offset + y_bottom - 1,
4064 on_off ? Painter::line_onoffdash : Painter::line_solid);
4066 on_off = !row_ptr->par->table->RightLine(cell);
4068 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4069 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4070 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4071 offset + y_bottom - 1,
4073 on_off ? Painter::line_onoffdash : Painter::line_solid);
4076 /* table stuff -- end*/
4077 LyXParagraph::size_type main_body =
4078 BeginningOfMainBody(row_ptr->par);
4079 if (main_body > 0 &&
4080 (main_body-1 > pos_end ||
4081 !row_ptr->par->IsLineSeparator(main_body-1)))
4084 while (vpos <= pos_end) {
4085 pos = vis2log(vpos);
4086 if (main_body > 0 && pos == main_body-1) {
4087 x += fill_label_hfill
4088 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4089 - SingleWidth(row_ptr->par, main_body-1);
4092 if (row_ptr->par->IsHfill(pos)) {
4095 offset + row_ptr->baseline - DefaultHeight() / 2,
4097 offset + row_ptr->baseline,
4100 if (HfillExpansion(row_ptr, pos)) {
4101 if (pos >= main_body) {
4103 offset + row_ptr->baseline - DefaultHeight() / 4,
4104 int(x + fill_hfill),
4105 offset + row_ptr->baseline - DefaultHeight() / 4,
4107 Painter::line_onoffdash);
4111 offset + row_ptr->baseline - DefaultHeight() / 4,
4112 int(x + fill_label_hfill),
4113 offset + row_ptr->baseline - DefaultHeight() / 4,
4115 Painter::line_onoffdash);
4117 x += fill_label_hfill;
4120 offset + row_ptr->baseline - DefaultHeight() / 2,
4122 offset + row_ptr->baseline,
4127 } else if (row_ptr->par->IsSeparator(pos)) {
4129 x+= SingleWidth(row_ptr->par, pos);
4130 if (pos >= main_body)
4132 #warning Think about this
4134 /* -------> Only draw protected spaces when
4135 * not in free-spacing mode. */
4136 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4138 pain.line(int(tmpx),
4139 offset + row_ptr->baseline - 3,
4141 offset + row_ptr->baseline - 1,
4144 pain.line(int(tmpx),
4145 offset + row_ptr->baseline - 1,
4147 offset + row_ptr->baseline - 1,
4150 pain.line(int(x - 2),
4151 offset + row_ptr->baseline - 3,
4153 offset + row_ptr->baseline - 1,
4156 /* what about underbars? */
4157 font = GetFont(row_ptr->par, pos);
4158 if (font.underbar() == LyXFont::ON
4159 && font.latex() != LyXFont::ON) {
4160 pain.line(int(tmpx),
4161 offset + row_ptr->baseline + 2,
4163 offset + row_ptr->baseline + 2);
4169 draw(row_ptr, vpos, offset, x);
4175 int LyXText::DefaultHeight() const
4177 LyXFont font(LyXFont::ALL_SANE);
4178 return int(font.maxAscent() + font.maxDescent() * 1.5);
4182 /* returns the column near the specified x-coordinate of the row
4183 * x is set to the real beginning of this column */
4184 int LyXText::GetColumnNearX(Row * row, int & x) const
4187 float fill_separator, fill_hfill, fill_label_hfill;
4189 PrepareToPrint(row, tmpx, fill_separator,
4190 fill_hfill, fill_label_hfill);
4192 LyXDirection direction = row->par->getParDirection();
4193 LyXParagraph::size_type vc = row->pos;
4194 LyXParagraph::size_type last = RowLast(row);
4195 LyXParagraph::size_type c = 0;
4197 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4198 row->par->GetLayout());
4199 /* table stuff -- begin */
4200 if (row->par->table) {
4201 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4202 && row->par->IsNewline(last))
4204 int cell = NumberOfCell(row->par, row->pos);
4207 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4209 && (c = vis2log(vc)) >= 0
4210 && tmpx + (SingleWidth(row->par, c)/2) <= x
4212 if (row->par->IsNewline(c)) {
4213 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4214 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4217 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4222 tmpx += SingleWidth(row->par, c);
4227 /* table stuff -- end*/
4228 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4229 float last_tmpx = tmpx;
4231 if (main_body > 0 &&
4232 (main_body-1 > last ||
4233 !row->par->IsLineSeparator(main_body-1)))
4236 while (vc <= last && tmpx <= x) {
4239 if (main_body > 0 && c == main_body-1) {
4240 tmpx += fill_label_hfill +
4241 GetFont(row->par, -2).stringWidth(layout.labelsep);
4242 if (row->par->IsLineSeparator(main_body-1))
4243 tmpx -= SingleWidth(row->par, main_body-1);
4246 tmpx += SingleWidth(row->par, c);
4247 if (HfillExpansion(row, c)) {
4251 tmpx += fill_label_hfill;
4253 else if (c >= main_body
4254 && row->par->IsSeparator(c)) {
4255 tmpx+= fill_separator;
4260 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4265 /* make sure that a last space in a row doesnt count */
4266 if (row->pos <= last
4267 && !(!row->next || row->next->par != row->par))
4268 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4269 && row->par->IsLineSeparator(vis2log(last)) ) {
4271 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4272 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4274 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4276 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4279 if (row->pos > last) // Row is empty?
4281 else if (vc <= last) {
4283 LyXDirection direction = row->par->getLetterDirection(c);
4284 if (vc > row->pos && row->par->IsLineSeparator(c)
4285 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4287 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4290 c = vis2log(last)+1;
4291 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4295 if (!row->par->table && row->pos <= last && c > last
4296 && row->par->IsNewline(last)) {
4297 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4298 tmpx -= SingleWidth(row->par, last);
4300 tmpx += SingleWidth(row->par, last);
4310 /* turn the selection into a new environment. If there is no selection,
4311 * create an empty environment */
4312 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4314 /* no footnoteenvironment in a footnoteenvironment */
4315 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4316 WriteAlert(_("Impossible operation"),
4317 _("You can't insert a float in a float!"),
4321 /* no marginpars in minipages */
4322 if (kind == LyXParagraph::MARGIN
4323 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4324 WriteAlert(_("Impossible operation"),
4325 _("You can't insert a marginpar in a minipage!"),
4330 /* this doesnt make sense, if there is no selection */
4331 bool dummy_selection = false;
4333 sel_start_cursor = cursor; /* dummy selection */
4334 sel_end_cursor = cursor;
4335 dummy_selection = true;
4338 LyXParagraph *tmppar;
4340 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4341 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4345 /* a test to make sure there is not already a footnote
4346 * in the selection. */
4348 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4350 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4351 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4352 tmppar = tmppar->next;
4354 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4355 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4356 WriteAlert(_("Impossible operation"),
4357 _("Float would include float!"),
4362 /* ok we have a selection. This is always between sel_start_cursor
4363 * and sel_end cursor */
4365 SetUndo(Undo::FINISH,
4366 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4367 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4369 if (sel_end_cursor.pos > 0
4370 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4371 sel_end_cursor.pos--; /* please break before a space at
4373 if (sel_start_cursor.par == sel_end_cursor.par
4374 && sel_start_cursor.pos > sel_end_cursor.pos)
4375 sel_start_cursor.pos--;
4377 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4379 sel_end_cursor.par = sel_end_cursor.par->Next();
4380 sel_end_cursor.pos = 0;
4382 // don't forget to insert a dummy layout paragraph if necessary
4383 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4384 sel_end_cursor.par->BreakParagraphConservative(0);
4385 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4386 sel_end_cursor.par = sel_end_cursor.par->next;
4389 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4391 cursor = sel_end_cursor;
4393 /* please break behind a space, if there is one. The space should
4395 if (sel_start_cursor.pos > 0
4396 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4397 sel_start_cursor.pos--;
4398 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4399 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4402 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4403 tmppar = sel_start_cursor.par->Next();
4405 if (dummy_selection) {
4407 if (kind == LyXParagraph::TAB
4408 || kind == LyXParagraph::FIG
4409 || kind == LyXParagraph::WIDE_TAB
4410 || kind == LyXParagraph::WIDE_FIG
4411 || kind == LyXParagraph::ALGORITHM) {
4412 pair<bool, LyXTextClass::size_type> lres =
4413 textclasslist.NumberOfLayout(parameters->textclass,
4415 LyXTextClass::size_type lay;
4421 lay = 0; // use default layout "Standard" (0)
4423 tmppar->SetLayout(lay);
4427 if (sel_start_cursor.pos > 0) {
4428 /* the footnote-environment should begin with a standard layout.
4429 * Imagine you insert a footnote within an enumeration, you
4430 * certainly do not want an enumerated footnote! */
4434 /* this is a exception the user would sometimes expect, I hope */
4435 sel_start_cursor.par->Clear();
4439 while (tmppar != sel_end_cursor.par) {
4440 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4441 tmppar->footnotekind = kind;
4442 tmppar = tmppar->Next();
4445 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4447 SetCursor(sel_start_cursor.par->Next(), 0);
4453 // returns pointer to a specified row
4454 Row * LyXText::GetRow(LyXParagraph * par,
4455 LyXParagraph::size_type pos, long & y) const
4460 if (par == currentrow->par
4461 || par == currentrow->par->Previous()) {
4462 // do not dereference par, it may have been deleted
4463 // already! (Matthias)
4465 // Walk backwards as long as the previous
4466 // rows par is not par
4467 while (currentrow->previous
4468 && currentrow->previous->par != par) {
4469 currentrow = currentrow->previous;
4470 currentrow_y -= currentrow->height;
4472 // Walk backwards as long as the previous
4473 // rows par _is_ par
4474 while (currentrow->previous
4475 && currentrow->previous->par == par) {
4476 currentrow = currentrow->previous;
4477 currentrow_y -= currentrow->height;
4481 tmprow = currentrow;
4483 // find the first row of the specified paragraph
4485 && tmprow->par != par) {
4486 y += tmprow->height;
4487 tmprow = tmprow->next;
4490 if (tmprow->par == par){
4491 // now find the wanted row
4492 while (tmprow->pos < pos
4494 && tmprow->next->par == par
4495 && tmprow->next->pos <= pos) {
4496 y += tmprow->height;
4497 tmprow = tmprow->next;
4499 currentrow = tmprow;
4507 // find the first row of the specified paragraph
4508 while (tmprow->next && tmprow->par != par) {
4509 y += tmprow->height;
4510 tmprow = tmprow->next;
4513 // now find the wanted row
4514 while (tmprow->pos < pos
4516 && tmprow->next->par == par
4517 && tmprow->next->pos <= pos) {
4518 y += tmprow->height;
4519 tmprow = tmprow->next;
4522 currentrow = tmprow;